2019-05-31 17:02:26 +00:00
|
|
|
#include "common.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "rwcore.h"
|
|
|
|
|
|
|
|
#include "skeleton.h"
|
|
|
|
#include "platform.h"
|
2020-12-09 01:57:45 +00:00
|
|
|
#include "main.h"
|
2020-11-26 15:47:19 +00:00
|
|
|
#include "MemoryHeap.h"
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static RwBool DefaultVideoMode = TRUE;
|
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
RsGlobalType RsGlobal;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2020-05-11 02:55:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
RwUInt32
|
|
|
|
#else
|
|
|
|
double
|
|
|
|
#endif
|
2019-05-31 17:02:26 +00:00
|
|
|
RsTimer(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return psTimer();
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsCameraShowRaster(RwCamera * camera)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
psCameraShowRaster(camera);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsCameraBeginUpdate(RwCamera * camera)
|
|
|
|
{
|
|
|
|
return psCameraBeginUpdate(camera);
|
|
|
|
}
|
|
|
|
|
2020-08-14 15:57:23 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwImage*
|
|
|
|
RsGrabScreen(RwCamera *camera)
|
|
|
|
{
|
|
|
|
return psGrabScreen(camera);
|
|
|
|
}
|
|
|
|
|
2019-05-31 17:02:26 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsRegisterImageLoader(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
static RwBool
|
|
|
|
RsSetDebug(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsMouseSetPos(RwV2d * pos)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
psMouseSetPos(pos);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsSelectDevice(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
return psSelectDevice();
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
|
|
|
RsInputDeviceAttach(RsInputDeviceType inputDevice,
|
2019-06-02 03:00:38 +00:00
|
|
|
RsInputEventHandler inputEventHandler)
|
2019-05-31 17:02:26 +00:00
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
switch (inputDevice)
|
|
|
|
{
|
|
|
|
case rsKEYBOARD:
|
|
|
|
{
|
|
|
|
RsGlobal.keyboard.inputEventHandler = inputEventHandler;
|
|
|
|
RsGlobal.keyboard.used = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case rsMOUSE:
|
|
|
|
{
|
|
|
|
RsGlobal.mouse.inputEventHandler = inputEventHandler;
|
|
|
|
RsGlobal.mouse.used = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case rsPAD:
|
|
|
|
{
|
|
|
|
RsGlobal.pad.inputEventHandler = inputEventHandler;
|
|
|
|
RsGlobal.pad.used = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
static RwBool
|
|
|
|
rsCommandLine(RwChar *arg)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
RsEventHandler(rsFILELOAD, arg);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
static RwBool
|
|
|
|
rsPreInitCommandLine(RwChar *arg)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
if( !strcmp(arg, RWSTRING("-vms")) )
|
|
|
|
{
|
|
|
|
DefaultVideoMode = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-08-15 14:51:39 +00:00
|
|
|
#ifndef MASTER
|
|
|
|
if (!strcmp(arg, RWSTRING("-animviewer")))
|
|
|
|
{
|
2020-12-09 01:57:45 +00:00
|
|
|
gbModelViewer = TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-08-15 14:51:39 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
2019-06-02 03:00:38 +00:00
|
|
|
return FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RsEventStatus
|
|
|
|
RsKeyboardEventHandler(RsEvent event, void *param)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
if (RsGlobal.keyboard.used)
|
|
|
|
{
|
|
|
|
return RsGlobal.keyboard.inputEventHandler(event, param);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return rsEVENTNOTPROCESSED;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RsEventStatus
|
|
|
|
RsPadEventHandler(RsEvent event, void *param)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
if (RsGlobal.pad.used)
|
|
|
|
{
|
|
|
|
return RsGlobal.pad.inputEventHandler(event, param);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return rsEVENTNOTPROCESSED;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RsEventStatus
|
|
|
|
RsEventHandler(RsEvent event, void *param)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
RsEventStatus result;
|
|
|
|
RsEventStatus es;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Give the application an opportunity to override any events...
|
|
|
|
*/
|
|
|
|
es = AppEventHandler(event, param);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We never allow the app to replace the quit behaviour,
|
|
|
|
* only to intercept...
|
|
|
|
*/
|
|
|
|
if (event == rsQUITAPP)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set the flag which causes the event loop to exit...
|
|
|
|
*/
|
|
|
|
RsGlobal.quit = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (es == rsEVENTNOTPROCESSED)
|
|
|
|
{
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case rsSELECTDEVICE:
|
|
|
|
result =
|
|
|
|
(RsSelectDevice()? rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsCOMMANDLINE:
|
|
|
|
result = (rsCommandLine((RwChar *) param) ?
|
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
case rsPREINITCOMMANDLINE:
|
|
|
|
result = (rsPreInitCommandLine((RwChar *) param) ?
|
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
case rsINITDEBUG:
|
|
|
|
result =
|
|
|
|
(RsSetDebug()? rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsREGISTERIMAGELOADER:
|
|
|
|
result = (RsRegisterImageLoader()?
|
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsRWTERMINATE:
|
|
|
|
RsRwTerminate();
|
|
|
|
result = (rsEVENTPROCESSED);
|
|
|
|
break;
|
|
|
|
|
2020-05-23 09:34:40 +00:00
|
|
|
case rsRWINITIALIZE:
|
|
|
|
result = (RsRwInitialize(param) ?
|
2019-06-02 03:00:38 +00:00
|
|
|
rsEVENTPROCESSED : rsEVENTERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rsTERMINATE:
|
|
|
|
RsTerminate();
|
|
|
|
result = (rsEVENTPROCESSED);
|
|
|
|
break;
|
|
|
|
|
2020-05-23 09:34:40 +00:00
|
|
|
case rsINITIALIZE:
|
2019-06-02 03:00:38 +00:00
|
|
|
result =
|
2020-05-23 09:34:40 +00:00
|
|
|
(RsInitialize()? rsEVENTPROCESSED : rsEVENTERROR);
|
2019-06-02 03:00:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = (es);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = (es);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsRwTerminate(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
/* Close RenderWare */
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RwEngineStop();
|
|
|
|
RwEngineClose();
|
|
|
|
RwEngineTerm();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
2020-05-23 09:34:40 +00:00
|
|
|
RsRwInitialize(void *displayID)
|
2019-05-31 17:02:26 +00:00
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
RwEngineOpenParams openParams;
|
2020-04-26 10:25:03 +00:00
|
|
|
|
2020-11-26 15:47:19 +00:00
|
|
|
PUSH_MEMID(MEMID_RENDER); // NB: not popped on failed return
|
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Start RenderWare...
|
|
|
|
*/
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
if (!RwEngineInit(psGetMemoryFunctions(), 0, rsRESOURCESDEFAULTARENASIZE))
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install any platform specific file systems...
|
|
|
|
*/
|
|
|
|
psInstallFileSystem();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Initialize debug message handling...
|
|
|
|
*/
|
2019-06-30 10:53:39 +00:00
|
|
|
RsEventHandler(rsINITDEBUG, nil);
|
2019-06-02 03:00:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach all plugins...
|
|
|
|
*/
|
2019-06-30 10:53:39 +00:00
|
|
|
if (RsEventHandler(rsPLUGINATTACH, nil) == rsEVENTERROR)
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach input devices...
|
|
|
|
*/
|
2019-06-30 10:53:39 +00:00
|
|
|
if (RsEventHandler(rsINPUTDEVICEATTACH, nil) == rsEVENTERROR)
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
openParams.displayID = displayID;
|
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
if (!RwEngineOpen(&openParams))
|
|
|
|
{
|
|
|
|
RwEngineTerm();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
if (RsEventHandler(rsSELECTDEVICE, displayID) == rsEVENTERROR)
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
RwEngineClose();
|
|
|
|
RwEngineTerm();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
if (!RwEngineStart())
|
2019-06-02 03:00:38 +00:00
|
|
|
{
|
|
|
|
RwEngineClose();
|
|
|
|
RwEngineTerm();
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Register loaders for an image with a particular file extension...
|
|
|
|
*/
|
2019-06-30 10:53:39 +00:00
|
|
|
RsEventHandler(rsREGISTERIMAGELOADER, nil);
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
psNativeTextureSupport();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RwTextureSetMipmapping(FALSE);
|
2019-05-31 17:02:26 +00:00
|
|
|
RwTextureSetAutoMipmapping(FALSE);
|
|
|
|
|
2020-11-26 15:47:19 +00:00
|
|
|
POP_MEMID();
|
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return TRUE;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RsTerminate(void)
|
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
psTerminate();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
RwBool
|
2020-05-23 09:34:40 +00:00
|
|
|
RsInitialize(void)
|
2019-05-31 17:02:26 +00:00
|
|
|
{
|
2019-06-02 03:00:38 +00:00
|
|
|
/*
|
|
|
|
* Initialize Platform independent data...
|
|
|
|
*/
|
|
|
|
RwBool result;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.appName = RWSTRING("GTA3");
|
|
|
|
RsGlobal.maximumWidth = DEFAULT_SCREEN_WIDTH;
|
2019-05-31 17:02:26 +00:00
|
|
|
RsGlobal.maximumHeight = DEFAULT_SCREEN_HEIGHT;
|
|
|
|
RsGlobal.width = DEFAULT_SCREEN_WIDTH;
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.height = DEFAULT_SCREEN_HEIGHT;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
|
|
|
RsGlobal.maxFPS = 30;
|
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.quit = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/* setup the keyboard */
|
|
|
|
RsGlobal.keyboard.inputDeviceType = rsKEYBOARD;
|
2019-06-30 10:53:39 +00:00
|
|
|
RsGlobal.keyboard.inputEventHandler = nil;
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.keyboard.used = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/* setup the mouse */
|
|
|
|
RsGlobal.mouse.inputDeviceType = rsMOUSE;
|
2019-06-30 10:53:39 +00:00
|
|
|
RsGlobal.mouse.inputEventHandler = nil;
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.mouse.used = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
/* setup the pad */
|
|
|
|
RsGlobal.pad.inputDeviceType = rsPAD;
|
2019-06-30 10:53:39 +00:00
|
|
|
RsGlobal.pad.inputEventHandler = nil;
|
2019-06-02 03:00:38 +00:00
|
|
|
RsGlobal.pad.used = FALSE;
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2020-05-23 09:34:40 +00:00
|
|
|
result = psInitialize();
|
2019-05-31 17:02:26 +00:00
|
|
|
|
2019-06-02 03:00:38 +00:00
|
|
|
return result;
|
2019-05-31 17:02:26 +00:00
|
|
|
}
|