From 8a4fa58cd42b7cca4a86fe2d9913b839b554bf10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 11 May 2020 05:55:57 +0300 Subject: Linux build support --- eax/eax.h | 7 +- premake5.lua | 71 +++-- premake5Linux | Bin 0 -> 2035312 bytes src/animation/AnimBlendAssocGroup.cpp | 4 + src/animation/CutsceneMgr.cpp | 2 +- src/audio/DMAudio.cpp | 1 + src/audio/oal/aldlist.cpp | 10 +- src/audio/oal/channel.cpp | 6 +- src/audio/oal/stream.cpp | 27 +- src/audio/sampman_oal.cpp | 22 +- src/control/CarCtrl.cpp | 2 +- src/control/Phones.cpp | 8 +- src/control/Pickups.cpp | 12 +- src/control/Script.cpp | 203 +++++++------ src/core/CdStream.cpp | 10 +- src/core/CdStream.h | 6 +- src/core/CdStreamPosix.cpp | 516 ++++++++++++++++++++++++++++++++++ src/core/ControllerConfig.cpp | 29 +- src/core/FileMgr.cpp | 59 +++- src/core/Fire.cpp | 8 +- src/core/Frontend.cpp | 41 ++- src/core/Frontend.h | 1 - src/core/Game.cpp | 2 +- src/core/Streaming.cpp | 8 +- src/core/Timer.cpp | 31 +- src/core/ZoneCull.cpp | 5 +- src/core/Zones.cpp | 12 +- src/core/config.h | 11 +- src/core/main.cpp | 3 + src/core/patcher.cpp | 20 +- src/core/re3.cpp | 51 +++- src/extras/debugmenu.cpp | 3 +- src/fakerw/fake.cpp | 19 ++ src/modelinfo/VehicleModelInfo.cpp | 6 +- src/peds/Ped.cpp | 10 +- src/peds/PlayerPed.cpp | 2 +- src/render/Console.cpp | 2 +- src/render/ParticleMgr.h | 12 +- src/render/PlayerSkin.cpp | 2 +- src/render/Shadows.cpp | 6 +- src/render/Shadows.h | 12 +- src/rw/RwHelper.cpp | 40 +-- src/rw/TexRead.cpp | 1 + src/rw/VisibilityPlugins.cpp | 8 +- src/save/GenericGameStorage.cpp | 1 - src/save/PCSave.cpp | 1 - src/skel/crossplatform.cpp | 125 +++++++- src/skel/crossplatform.h | 81 +++--- src/skel/glfw/glfw.cpp | 175 ++++++++---- src/skel/platform.h | 18 +- src/skel/skeleton.cpp | 6 +- src/skel/skeleton.h | 6 +- src/skel/win/win.h | 1 - src/vehicles/Cranes.cpp | 8 +- 54 files changed, 1372 insertions(+), 361 deletions(-) create mode 100755 premake5Linux create mode 100644 src/core/CdStreamPosix.cpp diff --git a/eax/eax.h b/eax/eax.h index ecc93c15..0e2201db 100644 --- a/eax/eax.h +++ b/eax/eax.h @@ -50,8 +50,13 @@ extern "C" { #else // OPENAL +#ifndef _WIN32 + #include + #include +#else #include - +#endif + #ifndef GUID_DEFINED #define GUID_DEFINED typedef struct _GUID diff --git a/premake5.lua b/premake5.lua index fbd2e011..dc16e31e 100644 --- a/premake5.lua +++ b/premake5.lua @@ -29,6 +29,7 @@ workspace "re3" location "build" symbols "Full" staticruntime "off" + filter { "system:windows" } platforms { "win-x86-RW33_d3d8-mss", @@ -36,6 +37,11 @@ workspace "re3" "win-x86-librw_gl3_glfw-mss", } + filter { "system:linux" } + platforms { + "linux-x86-librw_gl3_glfw-oal", + } + filter "configurations:Debug" defines { "DEBUG" } @@ -45,6 +51,9 @@ workspace "re3" filter { "platforms:win*" } system "windows" + + filter { "platforms:linux*" } + system "linux" filter { "platforms:*x86*" } architecture "x86" @@ -57,30 +66,28 @@ workspace "re3" filter "platforms:*librw_gl3_glfw*" defines { "RW_GL3" } + includedirs { path.join(_OPTIONS["glfwdir"], "include") } + includedirs { path.join(_OPTIONS["glewdir"], "include") } + + filter "platforms:win*librw_gl3_glfw*" + defines { "GLEW_STATIC" } if(not _OPTIONS["with-librw"]) then libdirs { path.join(Librw, "lib/win-x86-gl3/%{cfg.buildcfg}") } end - defines { "GLEW_STATIC" } - includedirs { path.join(_OPTIONS["glfwdir"], "include") } - includedirs { path.join(_OPTIONS["glewdir"], "include") } + + filter "platforms:linux*librw_gl3_glfw*" + if(not _OPTIONS["with-librw"]) then + libdirs { path.join(Librw, "lib/linux-x86-gl3/%{cfg.buildcfg}") } + end + filter {} - - pbcommands = { - "setlocal EnableDelayedExpansion", - "set file=$(TargetPath)", - "FOR %%i IN (\"%file%\") DO (", - "set filename=%%~ni", - "set fileextension=%%~xi", - "set target=!path!!filename!!fileextension!", - "copy /y \"!file!\" \"!target!\"", - ")" } - + function setpaths (gamepath, exepath, scriptspath) scriptspath = scriptspath or "" if (gamepath) then - cmdcopy = { "set \"path=" .. gamepath .. scriptspath .. "\"" } - table.insert(cmdcopy, pbcommands) - postbuildcommands (cmdcopy) + postbuildcommands { + "{COPY} %{cfg.buildtarget.abspath} " .. gamepath .. scriptspath .. "%{cfg.buildtarget.name}" + } debugdir (gamepath) if (exepath) then debugcommand (gamepath .. exepath) @@ -111,16 +118,12 @@ project "re3" kind "WindowedApp" targetname "re3" targetdir "bin/%{cfg.platform}/%{cfg.buildcfg}" - targetextension ".exe" - characterset ("MBCS") - linkoptions "/SAFESEH:NO" - files { addSrcFiles("src") } files { addSrcFiles("src/animation") } files { addSrcFiles("src/audio") } --files { addSrcFiles("src/audio/miles") } - --files { addSrcFiles("src/audio/openal") } + --files { addSrcFiles("src/audio/oal") } files { addSrcFiles("src/control") } files { addSrcFiles("src/core") } files { addSrcFiles("src/entities") } @@ -132,7 +135,6 @@ project "re3" files { addSrcFiles("src/rw") } files { addSrcFiles("src/save") } files { addSrcFiles("src/skel") } - files { addSrcFiles("src/skel/win") } files { addSrcFiles("src/skel/glfw") } files { addSrcFiles("src/text") } files { addSrcFiles("src/vehicles") } @@ -143,6 +145,7 @@ project "re3" includedirs { "src" } includedirs { "src/animation" } includedirs { "src/audio" } + --includedirs { "src/audio/oal" } includedirs { "src/control" } includedirs { "src/core" } includedirs { "src/entities" } @@ -154,7 +157,6 @@ project "re3" includedirs { "src/rw" } includedirs { "src/save/" } includedirs { "src/skel/" } - includedirs { "src/skel/win" } includedirs { "src/skel/glfw" } includedirs { "src/text" } includedirs { "src/vehicles" } @@ -167,8 +169,22 @@ project "re3" libdirs { "milessdk/lib" } - setpaths("$(GTA_III_RE_DIR)/", "$(TargetFileName)", "") + setpaths("$(GTA_III_RE_DIR)/", "%(cfg.buildtarget.name)", "") + filter "platforms:win*" + files { addSrcFiles("src/skel/win") } + includedirs { "src/skel/win" } + linkoptions "/SAFESEH:NO" + characterset ("MBCS") + targetextension ".exe" + + filter "platforms:linux*" + targetextension ".elf" + defines { "OPENAL" } + links { "openal", "mpg123", "sndfile", "pthread" } + files { addSrcFiles("src/audio/oal") } + includedirs { "src/audio/oal" } + filter "platforms:*RW33*" staticruntime "on" includedirs { "rwsdk/include/d3d8" } @@ -194,7 +210,10 @@ project "re3" filter "platforms:*d3d9*" links { "d3d9" } - filter "platforms:*gl3_glfw*" + filter "platforms:win*gl3_glfw*" libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") } libdirs { path.join(_OPTIONS["glfwdir"], "lib-" .. string.gsub(_ACTION, "vs", "vc")) } links { "opengl32", "glew32s", "glfw3" } + + filter "platforms:linux*gl3_glfw*" + links { "GL", "GLEW", "glfw" } diff --git a/premake5Linux b/premake5Linux new file mode 100755 index 00000000..2fd412da Binary files /dev/null and b/premake5Linux differ diff --git a/src/animation/AnimBlendAssocGroup.cpp b/src/animation/AnimBlendAssocGroup.cpp index 5a6d10b4..fe419f2a 100644 --- a/src/animation/AnimBlendAssocGroup.cpp +++ b/src/animation/AnimBlendAssocGroup.cpp @@ -1,6 +1,10 @@ #include "common.h" +#if defined _WIN32 && !defined __MINGW32__ #include "ctype.h" +#else +#include +#endif #include "General.h" #include "RwHelper.h" diff --git a/src/animation/CutsceneMgr.cpp b/src/animation/CutsceneMgr.cpp index 0db54c4b..230e22fb 100644 --- a/src/animation/CutsceneMgr.cpp +++ b/src/animation/CutsceneMgr.cpp @@ -103,7 +103,7 @@ const struct { { "MT_PH2", STREAMED_SOUND_CUTSCENE_MARTY_PH2 }, { "MT_PH3", STREAMED_SOUND_CUTSCENE_MARTY_PH3 }, { "MT_PH4", STREAMED_SOUND_CUTSCENE_MARTY_PH4 }, - { NULL, NULL } + { NULL, 0 } }; int diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index f1b9707b..888081b7 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -6,6 +6,7 @@ #include "AudioScriptObject.h" #include "sampman.h" #include "Text.h" +#include "crossplatform.h" cDMAudio DMAudio; diff --git a/src/audio/oal/aldlist.cpp b/src/audio/oal/aldlist.cpp index 2c2f13a8..768ace30 100644 --- a/src/audio/oal/aldlist.cpp +++ b/src/audio/oal/aldlist.cpp @@ -23,6 +23,12 @@ */ #include "aldlist.h" + +#ifndef _WIN32 +#define _stricmp strcasecmp +#define _strnicmp strncasecmp +#endif + #ifdef AUDIO_OAL /* * Init call @@ -67,7 +73,7 @@ ALDeviceList::ALDeviceList() if ((bNewName) && (actualDeviceName != NULL) && (strlen(actualDeviceName) > 0)) { memset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO)); ALDeviceInfo.bSelected = true; - ALDeviceInfo.strDeviceName = std::string(actualDeviceName, strlen(actualDeviceName)); + ALDeviceInfo.strDeviceName.assign(actualDeviceName, strlen(actualDeviceName)); alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &ALDeviceInfo.iMajorVersion); alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &ALDeviceInfo.iMinorVersion); @@ -326,4 +332,4 @@ unsigned int ALDeviceList::GetMaxNumSources() return iSourceCount; } -#endif \ No newline at end of file +#endif diff --git a/src/audio/oal/channel.cpp b/src/audio/oal/channel.cpp index 7742a06a..6fe1d856 100644 --- a/src/audio/oal/channel.cpp +++ b/src/audio/oal/channel.cpp @@ -4,6 +4,10 @@ #include "common.h" #include "sampman.h" +#ifndef _WIN32 +#include +#endif + extern bool IsFXSupported(); CChannel::CChannel() @@ -207,4 +211,4 @@ void CChannel::UpdateReverb(ALuint slot) alSource3i(alSource, AL_AUXILIARY_SEND_FILTER, slot, 0, alFilter); } -#endif \ No newline at end of file +#endif diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp index 9bca0546..5a9c7d7d 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -4,13 +4,15 @@ #include "common.h" #include "sampman.h" -typedef long ssize_t; - #include #include - +#ifdef _WIN32 +typedef long ssize_t; #pragma comment( lib, "libsndfile-1.lib" ) #pragma comment( lib, "libmpg123.lib" ) +#else +#include "crossplatform.h" +#endif class CSndFile : public IDecoder { @@ -192,7 +194,22 @@ CStream::CStream(char *filename, ALuint &source, ALuint (&buffers)[NUM_STREAMBUF m_nPosBeforeReset(0) { - strcpy(m_aFilename, filename); +// Be case-insensitive on linux (from https://github.com/OneSadCookie/fcaseopen/) +#if !defined(_WIN32) + FILE *test = fopen(filename, "r"); + if (!test) { + char *r = (char*)alloca(strlen(filename) + 2); + if (casepath(filename, r)) + { + strcpy(m_aFilename, r); + } + } else { + fclose(test); +#else + { +#endif + strcpy(m_aFilename, filename); + } DEV("Stream %s\n", m_aFilename); @@ -517,4 +534,4 @@ void CStream::ProviderTerm() ClearBuffers(); } -#endif \ No newline at end of file +#endif diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp index bbaeae4c..64b763ec 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -5,16 +5,18 @@ #include "sampman.h" #include -#include #include "eax.h" #include "eax-util.h" +#ifdef _WIN32 +#include #include #include #include #include #include +#endif #include "oal/oal_utils.h" #include "oal/aldlist.h" @@ -31,7 +33,9 @@ //TODO: loop count //TODO: mp3 player +#ifdef _WIN32 #pragma comment( lib, "OpenAL32.lib" ) +#endif cSampleManager SampleManager; bool _bSampmanInitialised = false; @@ -61,15 +65,15 @@ struct int defaultProvider; -char SampleBankDescFilename[] = "AUDIO\\SFX.SDT"; -char SampleBankDataFilename[] = "AUDIO\\SFX.RAW"; +char SampleBankDescFilename[] = "audio/sfx.SDT"; +char SampleBankDataFilename[] = "audio/sfx.RAW"; FILE *fpSampleDescHandle; FILE *fpSampleDataHandle; bool bSampleBankLoaded [MAX_SAMPLEBANKS]; int32 nSampleBankDiscStartOffset [MAX_SAMPLEBANKS]; int32 nSampleBankSize [MAX_SAMPLEBANKS]; -int32 nSampleBankMemoryStartAddress[MAX_SAMPLEBANKS]; +uintptr nSampleBankMemoryStartAddress[MAX_SAMPLEBANKS]; int32 _nSampleDataEndOffset; int32 nPedSlotSfx [MAX_PEDSFX]; @@ -88,7 +92,7 @@ struct { ALuint buffer; ALuint timer; - + bool IsEmpty() { return timer == 0; } void Set(ALuint buf) { buffer = buf; } void Wait() { timer = 10000; } @@ -573,7 +577,7 @@ cSampleManager::Initialise(void) return false; } - nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = (int32)malloc(nSampleBankSize[SAMPLEBANK_MAIN]); + nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] = (uintptr)malloc(nSampleBankSize[SAMPLEBANK_MAIN]); ASSERT(nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] != NULL); if ( nSampleBankMemoryStartAddress[SAMPLEBANK_MAIN] == NULL ) @@ -582,7 +586,7 @@ cSampleManager::Initialise(void) return false; } - nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = (int32)malloc(PED_BLOCKSIZE*MAX_PEDSFX); + nSampleBankMemoryStartAddress[SAMPLEBANK_PED] = (uintptr)malloc(PED_BLOCKSIZE*MAX_PEDSFX); ASSERT(nSampleBankMemoryStartAddress[SAMPLEBANK_PED] != NULL); } @@ -985,7 +989,7 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank) if ( !IsSampleBankLoaded(nBank) ) return false; - int32 addr = nSampleBankMemoryStartAddress[nBank] + m_aSamples[nSfx].nOffset - m_aSamples[BankStartOffset[nBank]].nOffset; + uintptr addr = nSampleBankMemoryStartAddress[nBank] + m_aSamples[nSfx].nOffset - m_aSamples[BankStartOffset[nBank]].nOffset; if ( ALBuffers[nSfx].IsEmpty() ) { @@ -1401,4 +1405,4 @@ cSampleManager::InitialiseSampleBanks(void) return true; } -#endif \ No newline at end of file +#endif diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 71236580..fcd1e83f 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -2523,7 +2523,7 @@ CCarCtrl::RegisterVehicleOfInterest(CVehicle* pVehicle) return; } } - uint32 oldestCarWeKeepTime = UINT_MAX; + uint32 oldestCarWeKeepTime = UINT32_MAX; int oldestCarWeKeepIndex = 0; for (int i = 0; i < MAX_CARS_TO_KEEP; i++) { if (apCarsToKeep[i] && aCarsToKeepTime[i] < oldestCarWeKeepTime) { diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp index 136ef7db..ee01b6c4 100644 --- a/src/control/Phones.cpp +++ b/src/control/Phones.cpp @@ -38,7 +38,7 @@ CPed* crimeReporters[NUMPHONES] = {}; bool isPhoneAvailable(int m_phoneId) { - return gPhoneInfo.m_aPhones[m_phoneId].m_nState == PHONE_STATE_FREE && + return gPhoneInfo.m_aPhones[m_phoneId].m_nState == PHONE_STATE_FREE && (crimeReporters[m_phoneId] == nil || !crimeReporters[m_phoneId]->IsPointerValid() || !crimeReporters[m_phoneId]->bRunningToPhone || crimeReporters[m_phoneId]->m_objective > OBJECTIVE_IDLE || crimeReporters[m_phoneId]->m_nLastPedState != PED_SEEK_POS && (crimeReporters[m_phoneId]->m_nPedState != PED_MAKE_CALL && crimeReporters[m_phoneId]->m_nPedState != PED_FACE_PHONE && crimeReporters[m_phoneId]->m_nPedState != PED_SEEK_POS)); @@ -194,10 +194,10 @@ CPhoneInfo::HasMessageBeenDisplayed(int phoneId) { if (bDisplayingPhoneMessage) return false; - + int state = m_aPhones[phoneId].m_nState; - return state == PHONE_STATE_REPEATED_MESSAGE_SHOWN_ONCE || + return state == PHONE_STATE_REPEATED_MESSAGE_SHOWN_ONCE || state == PHONE_STATE_ONETIME_MESSAGE_STARTED || state == PHONE_STATE_REPEATED_MESSAGE_STARTED; } @@ -218,7 +218,7 @@ INITSAVEBUF m_aPhones[i] = ReadSaveBuf(buf); // It's saved as building pool index in save file, convert it to true entity if (m_aPhones[i].m_pEntity) { - m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((int)m_aPhones[i].m_pEntity - 1); + m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((uintptr)m_aPhones[i].m_pEntity - 1); } } VALIDATESAVEBUF(size) diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 6b56cd8f..569af776 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -630,15 +630,15 @@ CPickups::Update() float mult; if ( dist < 10.0f ) mult = 1.0f - (dist / 10.0f ); - else + else mult = 0.0f; - + CVector pos = StaticCamCoors; pos.z += (pPlayerVehicle->GetColModel()->boundingBox.GetSize().z + 2.0f) * mult; - + if ( (CTimer::GetTimeInMilliseconds() - StaticCamStartTime) > 750 ) { - TheCamera.SetCamPositionForFixedMode(pos, CVector(0.0f, 0.0f, 0.0f)); + TheCamera.SetCamPositionForFixedMode(pos, CVector(0.0f, 0.0f, 0.0f)); TheCamera.TakeControl(FindPlayerVehicle(), CCam::MODE_FIXED, JUMP_CUT, CAMCONTROL_SCRIPT); } @@ -988,7 +988,7 @@ INITSAVEBUF aPickUps[i] = ReadSaveBuf(buf); if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].m_pObject != nil) - aPickUps[i].m_pObject = CPools::GetObjectPool()->GetSlot((int32)aPickUps[i].m_pObject - 1); + aPickUps[i].m_pObject = CPools::GetObjectPool()->GetSlot((uintptr)aPickUps[i].m_pObject - 1); } CollectedPickUpIndex = ReadSaveBuf(buf); @@ -1029,7 +1029,7 @@ CPacManPickup::Update() if (FindPlayerVehicle() == nil) return; CVehicle *veh = FindPlayerVehicle(); - + if (DistanceSqr2D(FindPlayerVehicle()->GetPosition(), m_vecPosn.x, m_vecPosn.y) < 100.0f && veh->IsSphereTouchingVehicle(m_vecPosn.x, m_vecPosn.y, m_vecPosn.z, 1.5f)) { switch (m_eType) { diff --git a/src/control/Script.cpp b/src/control/Script.cpp index df3a489a..30793f55 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -131,7 +131,7 @@ int32 ScriptParams[32]; const uint32 CRunningScript::nSaveStructSize = #ifdef COMPATIBLE_SAVES - 136; + 136; #else sizeof(CRunningScript); #endif @@ -508,13 +508,14 @@ int open_script() { static int scriptToLoad = 0; +#ifdef _WIN32 if (GetAsyncKeyState('G') & 0x8000) scriptToLoad = 0; if (GetAsyncKeyState('R') & 0x8000) scriptToLoad = 1; if (GetAsyncKeyState('D') & 0x8000) scriptToLoad = 2; - +#endif switch (scriptToLoad) { case 0: return CFileMgr::OpenFile("main.scm", "rb"); case 1: return CFileMgr::OpenFile("main_freeroam.scm", "rb"); @@ -750,6 +751,8 @@ int8 CRunningScript::ProcessOneCommand() int8 CRunningScript::ProcessCommands0To99(int32 command) { + float *fScriptVar1; + int *nScriptVar1; switch (command) { case COMMAND_NOP: return 0; @@ -1358,7 +1361,7 @@ int8 CRunningScript::ProcessCommands0To99(int32 command) UpdateCompareFlag(ped->m_pMyVehicle->IsWithinArea(x1, y1, x2, y2)); if (!ScriptParams[5]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugSquare(x1, y1, x2, y2); return 0; @@ -1379,46 +1382,58 @@ int8 CRunningScript::ProcessCommands0To99(int32 command) UpdateCompareFlag(ped->IsWithinArea(x1, y1, z1, x2, y2, z2)); if (!ScriptParams[7]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugCube(x1, y1, z1, x2, y2, z2); return 0; } case COMMAND_ADD_INT_VAR_TO_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 += *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_ADD_INT_LVAR_TO_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 += *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_ADD_INT_VAR_TO_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 += *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_ADD_INT_LVAR_TO_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 += *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_ADD_FLOAT_VAR_TO_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_ADD_FLOAT_LVAR_TO_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_ADD_FLOAT_VAR_TO_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_ADD_FLOAT_LVAR_TO_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 += *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_SUB_INT_VAR_FROM_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 -= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_SUB_INT_LVAR_FROM_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 -= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_SUB_FLOAT_VAR_FROM_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_SUB_FLOAT_LVAR_FROM_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; default: assert(0); @@ -1429,66 +1444,88 @@ int8 CRunningScript::ProcessCommands0To99(int32 command) int8 CRunningScript::ProcessCommands100To199(int32 command) { + float *fScriptVar1; + int *nScriptVar1; switch (command) { case COMMAND_SUB_INT_LVAR_FROM_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 -= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_SUB_INT_VAR_FROM_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 -= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_SUB_FLOAT_LVAR_FROM_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_SUB_FLOAT_VAR_FROM_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_MULT_INT_VAR_BY_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_MULT_INT_LVAR_BY_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 *= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_MULT_INT_VAR_BY_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_MULT_INT_LVAR_BY_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 *= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_MULT_FLOAT_VAR_BY_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_MULT_FLOAT_LVAR_BY_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_MULT_FLOAT_VAR_BY_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_MULT_FLOAT_LVAR_BY_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_DIV_INT_VAR_BY_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_DIV_INT_LVAR_BY_INT_VAR: - *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *nScriptVar1 /= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_DIV_INT_VAR_BY_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_DIV_INT_LVAR_BY_INT_LVAR: - *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + nScriptVar1 = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *nScriptVar1 /= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_DIV_FLOAT_VAR_BY_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_DIV_FLOAT_LVAR_BY_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_DIV_FLOAT_VAR_BY_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_DIV_FLOAT_LVAR_BY_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_ADD_TIMED_VAL_TO_FLOAT_VAR: { @@ -1505,16 +1542,20 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) return 0; } case COMMAND_ADD_TIMED_FLOAT_VAR_TO_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_ADD_TIMED_FLOAT_LVAR_TO_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_ADD_TIMED_FLOAT_VAR_TO_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_ADD_TIMED_FLOAT_LVAR_TO_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_SUB_TIMED_VAL_FROM_FLOAT_VAR: { @@ -1531,16 +1572,20 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) return 0; } case COMMAND_SUB_TIMED_FLOAT_VAR_FROM_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_SUB_TIMED_FLOAT_LVAR_FROM_FLOAT_VAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + *fScriptVar1 -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_SUB_TIMED_FLOAT_VAR_FROM_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); return 0; case COMMAND_SUB_TIMED_FLOAT_LVAR_FROM_FLOAT_LVAR: - *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + fScriptVar1 = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); + *fScriptVar1 -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL); return 0; case COMMAND_SET_VAR_INT_TO_VAR_INT: { @@ -1897,7 +1942,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) UpdateCompareFlag(ped->IsWithinArea(x1, y1, x2, y2)); if (!ScriptParams[5]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugSquare(x1, y1, x2, y2); return 0; @@ -1924,7 +1969,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) UpdateCompareFlag(ped->IsWithinArea(x1, y1, z1, x2, y2, z2)); if (!ScriptParams[7]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugCube(x1, y1, z1, x2, y2, z2); return 0; @@ -2136,7 +2181,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) UpdateCompareFlag(vehicle->IsWithinArea(x1, y1, x2, y2)); if (!ScriptParams[5]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugSquare(x1, y1, x2, y2); return 0; @@ -2155,7 +2200,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) UpdateCompareFlag(vehicle->IsWithinArea(x1, y1, z1, x2, y2, z2)); if (!ScriptParams[7]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugCube(x1, y1, z1, x2, y2, z2); return 0; @@ -2240,7 +2285,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) case COMMAND_RETURN_FALSE: UpdateCompareFlag(false); return 0; - /* Special command only used by compiler. + /* Special command only used by compiler. case COMMAND_VAR_INT: */ default: @@ -2251,9 +2296,9 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) } int8 CRunningScript::ProcessCommands200To299(int32 command) -{ +{ switch (command) { - /* Special commands. + /* Special commands. case COMMAND_VAR_FLOAT: case COMMAND_LVAR_INT: case COMMAND_LVAR_FLOAT: @@ -2645,7 +2690,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) pPed->m_fearFlags |= ScriptParams[1]; return 0; } - /* Not implemented. + /* Not implemented. case COMMAND_SET_CHAR_THREAT_REACTION: */ case COMMAND_SET_CHAR_OBJ_NO_OBJ: @@ -2657,7 +2702,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) pPed->ClearObjective(); return 0; } - /* Not implemented. + /* Not implemented. case COMMAND_ORDER_DRIVER_OUT_OF_CAR: case COMMAND_ORDER_CHAR_TO_DRIVE_CAR: case COMMAND_ADD_PATROL_POINT: @@ -2704,7 +2749,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) UpdateCompareFlag(pPed->bScriptObjectiveCompleted); return 0; } - /* Not implemented. + /* Not implemented. case COMMAND_SET_CHAR_DRIVE_AGGRESSION: case COMMAND_SET_CHAR_MAX_DRIVESPEED: */ @@ -2820,7 +2865,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) CTheScripts::ClearSpaceForMissionEntity(pos, pPlayer->m_pPed); return 0; } - /* Not implemented. + /* Not implemented. case COMMAND_MAKE_CHAR_DO_NOTHING: */ default: @@ -2890,7 +2935,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command) pVehicle->IsWithinArea(x1, y1, x2, y2)); if (!ScriptParams[5]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugSquare(x1, y1, x2, y2); return 0; @@ -2910,7 +2955,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command) pVehicle->IsWithinArea(x1, y1, z1, x2, y2, z2)); if (!ScriptParams[7]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, (z1 + z2) / 2); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugCube(x1, y1, z1, x2, y2, z2); return 0; @@ -4334,7 +4379,7 @@ int8 CRunningScript::ProcessCommands400To499(int32 command) CWanted::SetMaximumWantedLevel(ScriptParams[0]); return 0; } - /* Debug commands? + /* Debug commands? case COMMAND_SAVE_VAR_INT: case COMMAND_SAVE_VAR_FLOAT: */ @@ -5129,7 +5174,7 @@ int8 CRunningScript::ProcessCommands500To599(int32 command) CVector pos = *(CVector*)&ScriptParams[0]; if (pos.z <= MAP_Z_LOW_LIMIT) pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - CCoronas::RegisterCorona((uint32)this + m_nIp, ScriptParams[6], ScriptParams[7], ScriptParams[8], + CCoronas::RegisterCorona((uintptr)this + m_nIp, ScriptParams[6], ScriptParams[7], ScriptParams[8], 255, pos, *(float*)&ScriptParams[3], 150.0f, ScriptParams[4], ScriptParams[5], 1, 0, 0, 0.0f); return 0; } @@ -5741,7 +5786,7 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) UpdateCompareFlag(pPed->bIsShooting && pPed->IsWithinArea(x1, y1, x2, y2)); if (!ScriptParams[5]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugSquare(x1, y1, x2, y2); return 0; @@ -5758,14 +5803,14 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) UpdateCompareFlag(pPed->bIsShooting && pPed->IsWithinArea(x1, y1, x2, y2)); if (!ScriptParams[5]) return 0; - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, x1, y1, x2, y2, MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) CTheScripts::DrawDebugSquare(x1, y1, x2, y2); return 0; } case COMMAND_IS_CURRENT_PLAYER_WEAPON: { - CollectParameters(&m_nIp, 2); + CollectParameters(&m_nIp, 2); CPed* pPed = CWorld::Players[ScriptParams[0]].m_pPed; assert(pPed); UpdateCompareFlag(ScriptParams[1] == pPed->m_weapons[pPed->m_currentWeapon].m_eWeaponType); @@ -7781,7 +7826,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) CVector pos = *(CVector*)&ScriptParams[0]; if (pos.z <= MAP_Z_LOW_LIMIT) pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); - C3dMarkers::PlaceMarkerSet((uint32)this + m_nIp, 4, pos, *(float*)&ScriptParams[3], + C3dMarkers::PlaceMarkerSet((uintptr)this + m_nIp, 4, pos, *(float*)&ScriptParams[3], SPHERE_MARKER_R, SPHERE_MARKER_G, SPHERE_MARKER_B, SPHERE_MARKER_A, SPHERE_MARKER_PULSE_PERIOD, SPHERE_MARKER_PULSE_FRACTION, 0); return 0; @@ -7988,7 +8033,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y); float radius = *(float*)&ScriptParams[3]; CTheScripts::GetActualScriptSphereIndex(CollectNextParameterWithoutIncreasingPC(m_nIp)); - ScriptParams[0] = CTheScripts::AddScriptSphere((uint32)this + m_nIp, pos, radius); + ScriptParams[0] = CTheScripts::AddScriptSphere((uintptr)this + m_nIp, pos, radius); StoreParameters(&m_nIp, 1); return 0; } @@ -9920,7 +9965,7 @@ void CRunningScript::LocatePlayerCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(X - dX, Y - dY, Z - dZ, X + dX, Y + dY, Z + dZ); @@ -10004,9 +10049,9 @@ void CRunningScript::LocatePlayerCharCommand(int32 command, uint32* pIp) UpdateCompareFlag(result); if (debug) #ifdef FIX_BUGS - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); #else - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dX, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dX, b3D ? Z : MAP_Z_LOW_LIMIT); #endif if (CTheScripts::DbgFlag) { if (b3D) @@ -10084,7 +10129,7 @@ void CRunningScript::LocatePlayerCarCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(X - dX, Y - dY, Z - dZ, X + dX, Y + dY, Z + dZ); @@ -10188,7 +10233,7 @@ void CRunningScript::LocateCharCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(X - dX, Y - dY, Z - dZ, X + dX, Y + dY, Z + dZ); @@ -10274,9 +10319,9 @@ void CRunningScript::LocateCharCharCommand(int32 command, uint32* pIp) UpdateCompareFlag(result); if (debug) #ifdef FIX_BUGS - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); #else - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dX, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dX, b3D ? Z : MAP_Z_LOW_LIMIT); #endif if (CTheScripts::DbgFlag) { if (b3D) @@ -10355,7 +10400,7 @@ void CRunningScript::LocateCharCarCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(X - dX, Y - dY, Z - dZ, X + dX, Y + dY, Z + dZ); @@ -10433,7 +10478,7 @@ void CRunningScript::LocateCharObjectCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(X - dX, Y - dY, Z - dZ, X + dX, Y + dY, Z + dZ); @@ -10505,7 +10550,7 @@ void CRunningScript::LocateCarCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(X - dX, Y - dY, Z - dZ, X + dX, Y + dY, Z + dZ); @@ -10544,7 +10589,7 @@ void CRunningScript::LocateSniperBulletCommand(int32 command, uint32* pIp) result = CBulletInfo::TestForSniperBullet(X - dX, X + dX, Y - dY, Y + dY, b3D ? Z - dZ : -1000.0f, b3D ? Z + dZ : 1000.0f); UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, X - dX, Y - dY, X + dX, Y + dY, b3D ? Z : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(X - dX, Y - dY, Z - dZ, X + dX, Y + dY, Z + dZ); @@ -10661,7 +10706,7 @@ void CRunningScript::PlayerInAreaCheckCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(infX, infY, infZ, supX, supY, supZ); @@ -10783,7 +10828,7 @@ void CRunningScript::PlayerInAngledAreaCheckCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantAngledArea((uint32)this + m_nIp, infX, infY, supX, supY, + CTheScripts::HighlightImportantAngledArea((uintptr)this + m_nIp, infX, infY, supX, supY, rotatedSupX, rotatedSupY, rotatedInfX, rotatedInfY, b3D ? (infZ + supZ) / 2 : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) @@ -10904,7 +10949,7 @@ void CRunningScript::CharInAreaCheckCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(infX, infY, infZ, supX, supY, supZ); @@ -11002,7 +11047,7 @@ void CRunningScript::CarInAreaCheckCommand(int32 command, uint32* pIp) } UpdateCompareFlag(result); if (debug) - CTheScripts::HighlightImportantArea((uint32)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : MAP_Z_LOW_LIMIT); + CTheScripts::HighlightImportantArea((uintptr)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : MAP_Z_LOW_LIMIT); if (CTheScripts::DbgFlag) { if (b3D) CTheScripts::DrawDebugCube(infX, infY, infZ, supX, supY, supZ); diff --git a/src/core/CdStream.cpp b/src/core/CdStream.cpp index 666041e1..d9978040 100644 --- a/src/core/CdStream.cpp +++ b/src/core/CdStream.cpp @@ -1,3 +1,4 @@ +#ifdef _WIN32 #define WITHWINDOWS #include "common.h" @@ -16,9 +17,8 @@ struct CdReadInfo char field_C; bool bLocked; bool bInUse; - char _pad0; int32 nStatus; - HANDLE hSemaphore; + HANDLE hSemaphore; // used for CdStreamSync HANDLE hFile; OVERLAPPED Overlapped; }; @@ -32,7 +32,7 @@ int32 gNumChannels; HANDLE gImgFiles[MAX_CDIMAGES]; HANDLE _gCdStreamThread; -HANDLE gCdStreamSema; +HANDLE gCdStreamSema; // released when we have new thing to read(so channel is set) DWORD _gCdStreamThreadId; CdReadInfo *gpReadInfo; @@ -296,6 +296,7 @@ CdStreamGetLastPosn(void) return lastPosnRead; } +// wait for channel to finish reading int32 CdStreamSync(int32 channel) { @@ -324,6 +325,7 @@ CdStreamSync(int32 channel) if ( _gbCdStreamOverlapped && pChannel->hFile ) { ASSERT(pChannel->hFile != nil ); + // Beware: This is blocking call (because of last parameter) if ( GetOverlappedResult(pChannel->hFile, &pChannel->Overlapped, &NumberOfBytesTransferred, TRUE) ) return STREAM_NONE; else @@ -406,6 +408,7 @@ WINAPI CdStreamThread(LPVOID lpThreadParameter) { pChannel->nStatus = STREAM_NONE; } + // Beware: This is blocking call (because of last parameter) else if ( GetLastError() == ERROR_IO_PENDING && GetOverlappedResult(pChannel->hFile, &pChannel->Overlapped, &NumberOfBytesTransferred, TRUE) ) { @@ -508,3 +511,4 @@ CdStreamGetNumImages(void) { return gNumImages; } +#endif diff --git a/src/core/CdStream.h b/src/core/CdStream.h index ba6c63a3..d0f9a855 100644 --- a/src/core/CdStream.h +++ b/src/core/CdStream.h @@ -41,4 +41,8 @@ void RemoveFirstInQueue(Queue *queue); bool CdStreamAddImage(char const *path); char *CdStreamGetImageName(int32 cd); void CdStreamRemoveImages(void); -int32 CdStreamGetNumImages(void); \ No newline at end of file +int32 CdStreamGetNumImages(void); + +#ifndef _WIN32 +extern bool flushStream[MAX_CDCHANNELS]; +#endif diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp new file mode 100644 index 00000000..7c49f5f1 --- /dev/null +++ b/src/core/CdStreamPosix.cpp @@ -0,0 +1,516 @@ +#ifndef _WIN32 +#include "common.h" +#include "crossplatform.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "CdStream.h" +#include "rwcore.h" +#include "RwHelper.h" + +#define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) +#define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) + +// #define ONE_THREAD_PER_CHANNEL // Don't use if you're not on SSD/Flash. (Also you may want to benefit from this via using all channels in Streaming.cpp) + +bool flushStream[MAX_CDCHANNELS]; + +struct CdReadInfo +{ + uint32 nSectorOffset; + uint32 nSectorsToRead; + void *pBuffer; + bool bLocked; + bool bReading; + int32 nStatus; +#ifdef ONE_THREAD_PER_CHANNEL + int8 nThreadStatus; // 0: created 1:initalized 2:abort now + pthread_t pChannelThread; + sem_t pStartSemaphore; +#endif + sem_t pDoneSemaphore; // used for CdStreamSync + int32 hFile; +}; + +char gCdImageNames[MAX_CDIMAGES+1][64]; +int32 gNumImages; +int32 gNumChannels; + +int32 gImgFiles[MAX_CDIMAGES]; // -1: error 0:unused otherwise: fd +char *gImgNames[MAX_CDIMAGES]; + +#ifndef ONE_THREAD_PER_CHANNEL +pthread_t _gCdStreamThread; +sem_t gCdStreamSema; // released when we have new thing to read(so channel is set) +int8 gCdStreamThreadStatus; // 0: created 1:initalized 2:abort now +Queue gChannelRequestQ; +bool _gbCdStreamOverlapped; +#endif + +CdReadInfo *gpReadInfo; + +int32 lastPosnRead; + +int _gdwCdStreamFlags; + +void *CdStreamThread(void* channelId); + +void +CdStreamInitThread(void) +{ + int status; + +#ifndef ONE_THREAD_PER_CHANNEL + gChannelRequestQ.items = (int32 *)calloc(gNumChannels + 1, sizeof(int32)); + gChannelRequestQ.head = 0; + gChannelRequestQ.tail = 0; + gChannelRequestQ.size = gNumChannels + 1; + ASSERT(gChannelRequestQ.items != nil ); + status = sem_init(&gCdStreamSema, 0, 0); +#endif + + + if (status == -1) { + CDTRACE("failed to create stream semaphore"); + ASSERT(0); + return; + } + + + if ( gNumChannels > 0 ) + { + for ( int32 i = 0; i < gNumChannels; i++ ) + { + status = sem_init(&gpReadInfo[i].pDoneSemaphore, 0, 0); + + if (status == -1) + { + CDTRACE("failed to create sync semaphore"); + ASSERT(0); + return; + } +#ifdef ONE_THREAD_PER_CHANNEL + status = sem_init(&gpReadInfo[i].pStartSemaphore, 0, 0); + + if (status == -1) + { + CDTRACE("failed to create start semaphore"); + ASSERT(0); + return; + } + gpReadInfo[i].nThreadStatus = 0; + int *channelI = (int*)malloc(sizeof(int)); + *channelI = i; + status = pthread_create(&gpReadInfo[i].pChannelThread, NULL, CdStreamThread, (void*)channelI); + + if (status == -1) + { + CDTRACE("failed to create sync thread"); + ASSERT(0); + return; + } +#endif + } + } + +#ifndef ONE_THREAD_PER_CHANNEL + debug("Using one streaming thread for all channels\n"); + status = pthread_create(&_gCdStreamThread, NULL, CdStreamThread, nil); + gCdStreamThreadStatus = 0; + + if (status == -1) + { + CDTRACE("failed to create sync thread"); + ASSERT(0); + return; + } +#else + debug("Using seperate streaming threads for each channel\n"); +#endif +} + +void +CdStreamInit(int32 numChannels) +{ + struct statvfs fsInfo; + + if((statvfs("models/gta3.img", &fsInfo)) < 0) + { + CDTRACE("can't get filesystem info"); + ASSERT(0); + return; + } + + _gdwCdStreamFlags = O_RDONLY | O_NOATIME; + + // People say it's slower +/* + if ( fsInfo.f_bsize <= CDSTREAM_SECTOR_SIZE ) + { + _gdwCdStreamFlags |= O_DIRECT; + debug("Using no buffered loading for streaming\n"); + } +*/ + void *pBuffer = (void *)RwMallocAlign(CDSTREAM_SECTOR_SIZE, fsInfo.f_bsize); + ASSERT( pBuffer != nil ); + + gNumImages = 0; + + gNumChannels = numChannels; + + gpReadInfo = (CdReadInfo *)calloc(sizeof(CdReadInfo), numChannels); + ASSERT( gpReadInfo != nil ); + + CDDEBUG("read info %p", gpReadInfo); + + CdStreamInitThread(); + + ASSERT( pBuffer != nil ); + RwFreeAlign(pBuffer); +} + +uint32 +GetGTA3ImgSize(void) +{ + ASSERT( gImgFiles[0] > 0 ); + struct stat statbuf; + + char path[PATH_MAX]; + realpath(gImgNames[0], path); + if (stat(path, &statbuf) == -1) { + // Try case-insensitivity + char *r = (char*)alloca(strlen(gImgNames[0]) + 2); + if (casepath(gImgNames[0], r)) + { + realpath(r, path); + if (stat(path, &statbuf) != -1) + goto ok; + } + + CDTRACE("can't get size of gta3.img"); + ASSERT(0); + return 0; + } +ok: + return statbuf.st_size; +} + +void +CdStreamShutdown(void) +{ + // Destroying semaphores and free(gpReadInfo) will be done at threads +#ifndef ONE_THREAD_PER_CHANNEL + free(gChannelRequestQ.items); + gCdStreamThreadStatus = 2; + sem_post(&gCdStreamSema); +#endif + +#ifdef ONE_THREAD_PER_CHANNEL + for ( int32 i = 0; i < gNumChannels; i++ ) { + gpReadInfo[i].nThreadStatus = 2; + sem_post(&gpReadInfo[i].pStartSemaphore); + } +#endif +} + + +int32 +CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) +{ + ASSERT( channel < gNumChannels ); + ASSERT( buffer != nil ); + + lastPosnRead = size + offset; + + ASSERT( _GET_INDEX(offset) < MAX_CDIMAGES ); + int32 hImage = gImgFiles[_GET_INDEX(offset)]; + ASSERT( hImage > 0 ); + + CdReadInfo *pChannel = &gpReadInfo[channel]; + ASSERT( pChannel != nil ); + + pChannel->hFile = hImage - 1; + + if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) + return STREAM_NONE; + + pChannel->nStatus = STREAM_NONE; + pChannel->nSectorOffset = _GET_OFFSET(offset); + pChannel->nSectorsToRead = size; + pChannel->pBuffer = buffer; + pChannel->bLocked = 0; + +#ifndef ONE_THREAD_PER_CHANNEL + AddToQueue(&gChannelRequestQ, channel); + if ( sem_post(&gCdStreamSema) != 0 ) + printf("Signal Sema Error\n"); +#else + if ( sem_post(&gpReadInfo[channel].pStartSemaphore) != 0 ) + printf("Signal Sema Error\n"); +#endif + + return STREAM_SUCCESS; +} + +int32 +CdStreamGetStatus(int32 channel) +{ + ASSERT( channel < gNumChannels ); + CdReadInfo *pChannel = &gpReadInfo[channel]; + ASSERT( pChannel != nil ); + +#ifdef ONE_THREAD_PER_CHANNEL + if (pChannel->nThreadStatus == 2) + return STREAM_NONE; +#else + if (gCdStreamThreadStatus == 2) + return STREAM_NONE; +#endif + + if ( pChannel->bReading ) + return STREAM_READING; + + if ( pChannel->nSectorsToRead != 0 ) + return STREAM_WAITING; + + if ( pChannel->nStatus != STREAM_NONE ) + { + int32 status = pChannel->nStatus; + + pChannel->nStatus = STREAM_NONE; + + return status; + } + + return STREAM_NONE; +} + +int32 +CdStreamGetLastPosn(void) +{ + return lastPosnRead; +} + +// wait for channel to finish reading +int32 +CdStreamSync(int32 channel) +{ + ASSERT( channel < gNumChannels ); + CdReadInfo *pChannel = &gpReadInfo[channel]; + ASSERT( pChannel != nil ); + + if (flushStream[channel]) { +#ifdef ONE_THREAD_PER_CHANNEL + pChannel->nSectorsToRead = 0; + pthread_kill(gpReadInfo[channel].pChannelThread, SIGINT); +#else + if (pChannel->bReading) { + pChannel->nSectorsToRead = 0; + pthread_kill(_gCdStreamThread, SIGINT); + } else { + pChannel->nSectorsToRead = 0; + } +#endif + pChannel->bReading = false; + flushStream[channel] = false; + return STREAM_NONE; + } + + if ( pChannel->nSectorsToRead != 0 ) + { + pChannel->bLocked = true; + + sem_wait(&pChannel->pDoneSemaphore); + } + + pChannel->bReading = false; + + return pChannel->nStatus; +} + +void +AddToQueue(Queue *queue, int32 item) +{ + ASSERT( queue != nil ); + ASSERT( queue->items != nil ); + queue->items[queue->tail] = item; + + queue->tail = (queue->tail + 1) % queue->size; + + if ( queue->head == queue->tail ) + debug("Queue is full\n"); +} + +int32 +GetFirstInQueue(Queue *queue) +{ + ASSERT( queue != nil ); + if ( queue->head == queue->tail ) + return -1; + + ASSERT( queue->items != nil ); + return queue->items[queue->head]; +} + +void +RemoveFirstInQueue(Queue *queue) +{ + ASSERT( queue != nil ); + if ( queue->head == queue->tail ) + { + debug("Queue is empty\n"); + return; + } + + queue->head = (queue->head + 1) % queue->size; +} + +void *CdStreamThread(void *param) +{ + debug("Created cdstream thread\n"); + +#ifndef ONE_THREAD_PER_CHANNEL + while (gCdStreamThreadStatus != 2) { + sem_wait(&gCdStreamSema); + int32 channel = GetFirstInQueue(&gChannelRequestQ); +#else + int channel = *((int*)param); + while (gpReadInfo[channel].nThreadStatus != 2){ + sem_wait(&gpReadInfo[channel].pStartSemaphore); +#endif + ASSERT( channel < gNumChannels ); + + CdReadInfo *pChannel = &gpReadInfo[channel]; + ASSERT( pChannel != nil ); + +#ifdef ONE_THREAD_PER_CHANNEL + if (gpReadInfo[channel].nThreadStatus == 0){ + gpReadInfo[channel].nThreadStatus = 1; +#else + if (gCdStreamThreadStatus == 0){ + gCdStreamThreadStatus = 1; +#endif + pid_t tid = syscall(SYS_gettid); + int ret = setpriority(PRIO_PROCESS, tid, getpriority(PRIO_PROCESS, getpid()) + 1); + } + + // spurious wakeup or we sent interrupt signal for flushing + if(pChannel->nSectorsToRead == 0) + continue; + + pChannel->bReading = true; + + if ( pChannel->nStatus == STREAM_NONE ) + { + ASSERT(pChannel->hFile >= 0); + ASSERT(pChannel->pBuffer != nil ); + + lseek(pChannel->hFile, pChannel->nSectorOffset * CDSTREAM_SECTOR_SIZE, SEEK_SET); + if (read(pChannel->hFile, pChannel->pBuffer, pChannel->nSectorsToRead * CDSTREAM_SECTOR_SIZE) == -1) { + // pChannel->nSectorsToRead == 0 at this point means we wanted to flush channel + pChannel->nStatus = pChannel->nSectorsToRead == 0 ? STREAM_NONE : STREAM_ERROR; + } else { + pChannel->nStatus = STREAM_NONE; + } + } + +#ifndef ONE_THREAD_PER_CHANNEL + RemoveFirstInQueue(&gChannelRequestQ); +#endif + + pChannel->nSectorsToRead = 0; + + if ( pChannel->bLocked ) + { + sem_post(&pChannel->pDoneSemaphore); + } + pChannel->bReading = false; + } +#ifndef ONE_THREAD_PER_CHANNEL + for ( int32 i = 0; i < gNumChannels; i++ ) + { + sem_destroy(&gpReadInfo[i].pDoneSemaphore); + } + sem_destroy(&gCdStreamSema); +#else + sem_destroy(&gpReadInfo[channel].pStartSemaphore); + sem_destroy(&gpReadInfo[channel].pDoneSemaphore); +#endif + free(gpReadInfo); + pthread_exit(nil); +} + +bool +CdStreamAddImage(char const *path) +{ + ASSERT(path != nil); + ASSERT(gNumImages < MAX_CDIMAGES); + + gImgFiles[gNumImages] = open(path, _gdwCdStreamFlags); + + // Fix case sensitivity and backslashes. + if (gImgFiles[gNumImages] == -1) { + char *r = (char*)alloca(strlen(path) + 2); + if (casepath(path, r)) + { + gImgFiles[gNumImages] = open(r, _gdwCdStreamFlags); + } + } + + if ( gImgFiles[gNumImages] == -1 ) { + assert(false); + return false; + } + + gImgNames[gNumImages] = strdup(path); + gImgFiles[gNumImages]++; // because -1: error 0: not used + + strcpy(gCdImageNames[gNumImages], path); + + gNumImages++; + + return true; +} + +char * +CdStreamGetImageName(int32 cd) +{ + ASSERT(cd < MAX_CDIMAGES); + if ( gImgFiles[cd] > 0) + return gCdImageNames[cd]; + + return nil; +} + +void +CdStreamRemoveImages(void) +{ + for ( int32 i = 0; i < gNumChannels; i++ ) + CdStreamSync(i); + + for ( int32 i = 0; i < gNumImages; i++ ) + { + close(gImgFiles[i] - 1); + free(gImgNames[i]); + gImgFiles[i] = 0; + } + + gNumImages = 0; +} + +int32 +CdStreamGetNumImages(void) +{ + return gNumImages; +} +#endif diff --git a/src/core/ControllerConfig.cpp b/src/core/ControllerConfig.cpp index cba8186f..dcd9f125 100644 --- a/src/core/ControllerConfig.cpp +++ b/src/core/ControllerConfig.cpp @@ -4,7 +4,8 @@ #endif #include "common.h" -#include "crossplatform.h" +#include "platform.h" +#include "crossplatform.h" // for Windows version #include "ControllerConfig.h" #include "Pad.h" #include "FileMgr.h" @@ -163,14 +164,14 @@ void CControllerConfigManager::InitDefaultControlConfiguration() SetControllerKeyAssociatedWithAction (VEHICLE_LOOKRIGHT, rsPADDOWN, KEYBOARD); SetControllerKeyAssociatedWithAction (VEHICLE_LOOKRIGHT, 'E', OPTIONAL_EXTRA); - - if ( _dwOperatingSystemVersion != OS_WIN98 ) - { + + if ( _dwOperatingSystemVersion == OS_WIN98 ) + SetControllerKeyAssociatedWithAction(VEHICLE_HORN, rsSHIFT, OPTIONAL_EXTRA); // BUG: must be KEYBOARD ? + else + { SetControllerKeyAssociatedWithAction(VEHICLE_HORN, rsLSHIFT, OPTIONAL_EXTRA); SetControllerKeyAssociatedWithAction(VEHICLE_HORN, rsRSHIFT, KEYBOARD); - } - else - SetControllerKeyAssociatedWithAction(VEHICLE_HORN, rsSHIFT, OPTIONAL_EXTRA); // BUG: must be KEYBOARD ? + } SetControllerKeyAssociatedWithAction (VEHICLE_HANDBRAKE, rsRCTRL, KEYBOARD); SetControllerKeyAssociatedWithAction (VEHICLE_HANDBRAKE, ' ', OPTIONAL_EXTRA); @@ -216,19 +217,19 @@ void CControllerConfigManager::InitDefaultControlConfiguration() SetControllerKeyAssociatedWithAction (PED_JUMPING, rsRCTRL, KEYBOARD); SetControllerKeyAssociatedWithAction (PED_JUMPING, ' ', OPTIONAL_EXTRA); - - if ( _dwOperatingSystemVersion != OS_WIN98 ) - { + + if ( _dwOperatingSystemVersion == OS_WIN98 ) + SetControllerKeyAssociatedWithAction(PED_SPRINT, rsSHIFT, OPTIONAL_EXTRA); // BUG: must be KEYBOARD ? + else + { SetControllerKeyAssociatedWithAction(PED_SPRINT, rsLSHIFT, OPTIONAL_EXTRA); #ifndef FIX_BUGS SetControllerKeyAssociatedWithAction(PED_SPRINT, rsRSHIFT, OPTIONAL_EXTRA); // BUG: must be KEYBOARD #else SetControllerKeyAssociatedWithAction(PED_SPRINT, rsRSHIFT, KEYBOARD); #endif - } - else - SetControllerKeyAssociatedWithAction(PED_SPRINT, rsSHIFT, OPTIONAL_EXTRA); // BUG: must be KEYBOARD ? - + } + SetControllerKeyAssociatedWithAction (PED_CYCLE_TARGET_LEFT, '[', KEYBOARD); SetControllerKeyAssociatedWithAction (PED_CYCLE_TARGET_RIGHT, ']', OPTIONAL_EXTRA); // BUG: must be KEYBOARD ? diff --git a/src/core/FileMgr.cpp b/src/core/FileMgr.cpp index 46d725cd..1939c861 100644 --- a/src/core/FileMgr.cpp +++ b/src/core/FileMgr.cpp @@ -1,6 +1,8 @@ #define _CRT_SECURE_NO_WARNINGS #include +#ifdef _WIN32 #include +#endif #include "common.h" #include "FileMgr.h" @@ -24,6 +26,31 @@ struct myFILE #define NUMFILES 20 static myFILE myfiles[NUMFILES]; + +#if !defined(_WIN32) +#include +#include +#include +#include "crossplatform.h" +#define _getcwd getcwd + +// Case-insensitivity on linux (from https://github.com/OneSadCookie/fcaseopen) +void mychdir(char const *path) +{ + char *r = (char*)alloca(strlen(path) + 2); + if (casepath(path, r)) + { + chdir(r); + } + else + { + errno = ENOENT; + } +} +#else +#define mychdir chdir +#endif + /* Force file to open as binary but remember if it was text mode */ static int myfopen(const char *filename, const char *mode) @@ -45,7 +72,31 @@ found: mode++; *p++ = 'b'; *p = '\0'; - myfiles[fd].file = fopen(filename, realmode); + +#if !defined(_WIN32) + char *newPath = strdup(filename); + // Normally casepath() fixes backslashes, but if the mode is sth other than r/rb it will create new file with backslashes on linux, so fix backslashes here + char *nextBs; + while(nextBs = strstr(newPath, "\\")){ + *nextBs = '/'; + } +#else + const char *newPath = filename; +#endif + + myfiles[fd].file = fopen(newPath, realmode); +// Be case-insensitive on linux (from https://github.com/OneSadCookie/fcaseopen/) +#if !defined(_WIN32) + if (!myfiles[fd].file) { + char *r = (char*)alloca(strlen(newPath) + 2); + if (casepath(newPath, r)) + { + myfiles[fd].file = fopen(r, realmode); + } + } + + free(newPath); +#endif if(myfiles[fd].file == nil) return 0; return fd; @@ -191,7 +242,7 @@ CFileMgr::ChangeDir(const char *dir) if(dir[strlen(dir)-1] != '\\') strcat(ms_dirName, "\\"); } - chdir(ms_dirName); + mychdir(ms_dirName); } void @@ -204,14 +255,14 @@ CFileMgr::SetDir(const char *dir) if(dir[strlen(dir)-1] != '\\') strcat(ms_dirName, "\\"); } - chdir(ms_dirName); + mychdir(ms_dirName); } void CFileMgr::SetDirMyDocuments(void) { SetDir(""); // better start at the root if user directory is relative - chdir(_psGetUserFilesFolder()); + mychdir(_psGetUserFilesFolder()); } int diff --git a/src/core/Fire.cpp b/src/core/Fire.cpp index 65b6deb2..933c73da 100644 --- a/src/core/Fire.cpp +++ b/src/core/Fire.cpp @@ -128,7 +128,7 @@ CFire::ProcessFire(void) lightpos.z = m_vecPos.z + 5.0f; if (!m_pEntity) { - CShadows::StoreStaticShadow((uint32)this, SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, &lightpos, + CShadows::StoreStaticShadow((uintptr)this, SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, &lightpos, 7.0f, 0.0f, 0.0f, -7.0f, 255, // this is 0 on PC which results in no shadow nRandNumber / 2, nRandNumber / 2, 0, @@ -199,7 +199,7 @@ CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength { CPed *ped = (CPed *)entityOnFire; CVehicle *veh = (CVehicle *)entityOnFire; - + if (entityOnFire->IsPed()) { if (ped->m_pFire) return nil; @@ -212,7 +212,7 @@ CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength return nil; } CFire *fire = GetNextFreeFire(); - + if (fire) { if (entityOnFire->IsPed()) { ped->m_pFire = fire; @@ -243,7 +243,7 @@ CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength veh->m_pCarFire = fire; if (fleeFrom) { CEventList::RegisterEvent(EVENT_CAR_SET_ON_FIRE, EVENT_ENTITY_VEHICLE, - entityOnFire, (CPed *)fleeFrom, 10000); + entityOnFire, (CPed *)fleeFrom, 10000); } } } diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 827e2ca7..f0d75d12 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -6,6 +6,7 @@ #define WITHWINDOWS #include "common.h" #include "crossplatform.h" +#include "platform.h" #include "Frontend.h" #include "Font.h" #include "Pad.h" @@ -900,6 +901,7 @@ CMenuManager::Draw() float smallestSliderBar = lineHeight * 0.1f; bool foundTheHoveringItem = false; wchar unicodeTemp[64]; + char asciiTemp[32]; #ifdef MENU_MAP if (m_nCurrScreen == MENUPAGE_MAP) { @@ -1054,15 +1056,18 @@ CMenuManager::Draw() #else switch (m_PrefsUseWideScreen) { case AR_AUTO: - rightText = (wchar*)L"AUTO"; + sprintf(asciiTemp, "AUTO"); break; case AR_4_3: - rightText = (wchar*)L"4:3"; + sprintf(asciiTemp, "4:3"); break; case AR_16_9: - rightText = (wchar*)L"16:9"; + sprintf(asciiTemp, "16:9"); break; } + + AsciiToUnicode(asciiTemp, unicodeTemp); + rightText = unicodeTemp; #endif break; case MENUACTION_RADIO: @@ -1102,13 +1107,12 @@ CMenuManager::Draw() break; #ifdef IMPROVED_VIDEOMODE case MENUACTION_SCREENMODE: - char mode[32]; if (m_nSelectedScreenMode == 0) - sprintf(mode, "FULLSCREEN"); + sprintf(asciiTemp, "FULLSCREEN"); else - sprintf(mode, "WINDOWED"); + sprintf(asciiTemp, "WINDOWED"); - AsciiToUnicode(mode, unicodeTemp); + AsciiToUnicode(asciiTemp, unicodeTemp); rightText = unicodeTemp; break; #endif @@ -4794,6 +4798,21 @@ CMenuManager::ProcessButtonPresses(void) DMAudio.PlayFrontEndTrack(m_PrefsRadioStation, 1); OutputDebugString("FRONTEND RADIO STATION CHANGED"); break; +#ifdef ASPECT_RATIO_SCALE + case MENUACTION_WIDESCREEN: + if (changeValueBy > 0) { + m_PrefsUseWideScreen++; + if (m_PrefsUseWideScreen > 2) + m_PrefsUseWideScreen = 2; + } else { + m_PrefsUseWideScreen--; + if (m_PrefsUseWideScreen < 0) + m_PrefsUseWideScreen = 0; + } + DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SUCCESS, 0); + SaveSettings(); + break; +#endif case MENUACTION_SCREENRES: if (m_bGameNotLoaded) { RwChar** videoMods = _psGetVideoModeList(); @@ -4903,17 +4922,13 @@ CMenuManager::ProcessOnOffMenuOptions() DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SUCCESS, 0); SaveSettings(); break; - case MENUACTION_WIDESCREEN: #ifndef ASPECT_RATIO_SCALE + case MENUACTION_WIDESCREEN: m_PrefsUseWideScreen = !m_PrefsUseWideScreen; -#else - m_PrefsUseWideScreen++; - if (m_PrefsUseWideScreen > 2) - m_PrefsUseWideScreen = 0; -#endif DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SUCCESS, 0); SaveSettings(); break; +#endif case MENUACTION_SETDBGFLAG: CTheScripts::InvertDebugFlag(); DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SUCCESS, 0); diff --git a/src/core/Frontend.h b/src/core/Frontend.h index e496f9c0..65c4e178 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -662,4 +662,3 @@ VALIDATE_SIZE(CMenuManager, 0x564); #endif extern CMenuManager FrontEndMenuManager; -extern unsigned long _dwOperatingSystemVersion; \ No newline at end of file diff --git a/src/core/Game.cpp b/src/core/Game.cpp index c50471f1..33afc956 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -2,7 +2,7 @@ #pragma warning( disable : 4005) #pragma warning( pop ) #include "common.h" -#include "crossplatform.h" +#include "platform.h" #include "Game.h" #include "main.h" diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index f24192ef..ed3892a6 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -1465,7 +1465,7 @@ CStreaming::GetCdImageOffset(int32 lastPosn) int dist, mindist; img = -1; - mindist = INT_MAX; + mindist = INT32_MAX; offset = ms_imageOffsets[ms_lastImageRead]; if(lastPosn <= offset || lastPosn > offset + ms_imageSize){ // last read position is not in last image @@ -1513,8 +1513,8 @@ CStreaming::GetNextFileOnCd(int32 lastPosn, bool priority) streamIdFirst = -1; streamIdNext = -1; - posnFirst = UINT_MAX; - posnNext = UINT_MAX; + posnFirst = UINT32_MAX; + posnNext = UINT32_MAX; for(si = ms_startRequestedList.m_next; si != &ms_endRequestedList; si = next){ next = si->m_next; @@ -1834,7 +1834,7 @@ CStreaming::LoadAllRequestedModels(bool priority) status = CdStreamRead(0, ms_pStreamingBuffer[0], imgOffset+posn, size); while(CdStreamSync(0) || status == STREAM_NONE); ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_READING; - + MakeSpaceFor(size * CDSTREAM_SECTOR_SIZE); ConvertBufferToObject(ms_pStreamingBuffer[0], streamId); if(ms_aInfoForModel[streamId].m_loadState == STREAMSTATE_STARTED) diff --git a/src/core/Timer.cpp b/src/core/Timer.cpp index aca7c1dc..ed5580fd 100644 --- a/src/core/Timer.cpp +++ b/src/core/Timer.cpp @@ -1,5 +1,6 @@ #define WITHWINDOWS #include "common.h" +#include "crossplatform.h" #include "DMAudio.h" #include "Record.h" @@ -16,15 +17,19 @@ float CTimer::ms_fTimeStepNonClipped; bool CTimer::m_UserPause; bool CTimer::m_CodePause; -uint32 oldPcTimer; - -uint32 suspendPcTimer; - uint32 _nCyclesPerMS = 1; +#ifdef _WIN32 LARGE_INTEGER _oldPerfCounter; - LARGE_INTEGER perfSuspendCounter; +#define RsTimerType uint32 +#else +#define RsTimerType double +#endif + +RsTimerType oldPcTimer; + +RsTimerType suspendPcTimer; uint32 suspendDepth; @@ -45,6 +50,7 @@ void CTimer::Initialise(void) m_snPreviousTimeInMilliseconds = 0; m_snTimeInMilliseconds = 1; +#ifdef _WIN32 LARGE_INTEGER perfFreq; if ( QueryPerformanceFrequency(&perfFreq) ) { @@ -53,6 +59,7 @@ void CTimer::Initialise(void) QueryPerformanceCounter(&_oldPerfCounter); } else +#endif { OutputDebugString("Performance counter not available, using millesecond timer\n"); _nCyclesPerMS = 0; @@ -77,6 +84,7 @@ void CTimer::Update(void) { m_snPreviousTimeInMilliseconds = m_snTimeInMilliseconds; +#ifdef _WIN32 if ( (double)_nCyclesPerMS != 0.0 ) { LARGE_INTEGER pc; @@ -106,10 +114,11 @@ void CTimer::Update(void) } } else +#endif { - uint32 timer = RsTimer(); + RsTimerType timer = RsTimer(); - uint32 updInMs = timer - oldPcTimer; + RsTimerType updInMs = timer - oldPcTimer; // We need that real frame time to fix transparent menu bug. #ifndef FIX_BUGS @@ -158,9 +167,11 @@ void CTimer::Suspend(void) if ( ++suspendDepth > 1 ) return; +#ifdef _WIN32 if ( (double)_nCyclesPerMS != 0.0 ) QueryPerformanceCounter(&perfSuspendCounter); else +#endif suspendPcTimer = RsTimer(); } @@ -169,6 +180,7 @@ void CTimer::Resume(void) if ( --suspendDepth != 0 ) return; +#ifdef _WIN32 if ( (double)_nCyclesPerMS != 0.0 ) { LARGE_INTEGER pc; @@ -177,19 +189,23 @@ void CTimer::Resume(void) _oldPerfCounter.LowPart += pc.LowPart - perfSuspendCounter.LowPart; } else +#endif oldPcTimer += RsTimer() - suspendPcTimer; } uint32 CTimer::GetCyclesPerMillisecond(void) { +#ifdef _WIN32 if (_nCyclesPerMS != 0) return _nCyclesPerMS; else +#endif return 1; } uint32 CTimer::GetCurrentTimeInCycles(void) { +#ifdef _WIN32 if ( _nCyclesPerMS != 0 ) { LARGE_INTEGER pc; @@ -197,6 +213,7 @@ uint32 CTimer::GetCurrentTimeInCycles(void) return (pc.LowPart - _oldPerfCounter.LowPart); // & 0x7FFFFFFF; pointless } else +#endif return RsTimer() - oldPcTimer; } diff --git a/src/core/ZoneCull.cpp b/src/core/ZoneCull.cpp index 6dcd0f18..c376e11f 100644 --- a/src/core/ZoneCull.cpp +++ b/src/core/ZoneCull.cpp @@ -533,7 +533,8 @@ CCullZone::IsEntityCloseEnoughToZone(CEntity *entity, bool checkLevel) if (lodDist > distToZone) return true; if (!checkLevel) return false; - return CTheZones::GetLevelFromPosition(&pos) == CTheZones::GetLevelFromPosition(&CVector(minx, miny, minz)); + CVector tempPos(minx, miny, minz); + return CTheZones::GetLevelFromPosition(&pos) == CTheZones::GetLevelFromPosition(&tempPos); } bool @@ -560,4 +561,4 @@ CCullZones::DoWeHaveMoreThanXOccurencesOfSet(int32 count, uint16 *set) } } return false; -} \ No newline at end of file +} diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 22c0735a..5b7519dc 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -703,9 +703,9 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){ ZoneArray[i] = ReadSaveBuf(buffer); - ZoneArray[i].child = GetPointerForZoneIndex((int32)ZoneArray[i].child); - ZoneArray[i].parent = GetPointerForZoneIndex((int32)ZoneArray[i].parent); - ZoneArray[i].next = GetPointerForZoneIndex((int32)ZoneArray[i].next); + ZoneArray[i].child = GetPointerForZoneIndex((uintptr)ZoneArray[i].child); + ZoneArray[i].parent = GetPointerForZoneIndex((uintptr)ZoneArray[i].parent); + ZoneArray[i].next = GetPointerForZoneIndex((uintptr)ZoneArray[i].next); } for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) @@ -722,9 +722,9 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) meant for a different array, but the game doesn't brake if save data stored is -1. */ - MapZoneArray[i].child = GetPointerForZoneIndex((int32)MapZoneArray[i].child); - MapZoneArray[i].parent = GetPointerForZoneIndex((int32)MapZoneArray[i].parent); - MapZoneArray[i].next = GetPointerForZoneIndex((int32)MapZoneArray[i].next); + MapZoneArray[i].child = GetPointerForZoneIndex((uintptr)MapZoneArray[i].child); + MapZoneArray[i].parent = GetPointerForZoneIndex((uintptr)MapZoneArray[i].parent); + MapZoneArray[i].next = GetPointerForZoneIndex((uintptr)MapZoneArray[i].next); assert(MapZoneArray[i].child == nil); assert(MapZoneArray[i].parent == nil); assert(MapZoneArray[i].next == nil); diff --git a/src/core/config.h b/src/core/config.h index ae30b539..d9f892a6 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -194,19 +194,22 @@ enum Config { #define FIX_BUGS // fixes bugs that we've came across during reversing, TODO: use this more #define TOGGLEABLE_BETA_FEATURES // toggleable from debug menu. not too many things #define MORE_LANGUAGES // Add more translations to the game -#define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch) +#define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch) #define USE_TXD_CDIMAGE // generate and load textures from txd.img #define IMPROVED_VIDEOMODE // save and load videomode parameters instead of a magic number //#define USE_TEXTURE_POOL -//#define AUDIO_OAL +#ifdef _WIN32 #define AUDIO_MSS +#else +#define AUDIO_OAL +#endif // Particle //#define PC_PARTICLE //#define PS2_ALTERNATIVE_CARSPLASH // unused on PS2 // Pad -#ifndef RW_GL3 +#if !defined(RW_GL3) && defined(_WIN32) #define XINPUT #endif #define DETECT_PAD_INPUT_SWITCH // Adds automatic switch of pad related stuff between controller and kb/m @@ -224,7 +227,7 @@ enum Config { #define SCROLLABLE_STATS_PAGE // only draggable by mouse atm #define TRIANGLE_BACK_BUTTON // #define CIRCLE_BACK_BUTTON -#define HUD_ENHANCEMENTS // Adjusts some aspects to make the HUD look/behave a little bit better. +#define HUD_ENHANCEMENTS // Adjusts some aspects to make the HUD look/behave a little bit better. #define BETA_SLIDING_TEXT // Script diff --git a/src/core/main.cpp b/src/core/main.cpp index 37a5673f..d6af0b2a 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -1773,6 +1773,8 @@ void GameInit() } } +// Not used anyway. PS2 main() port +#ifdef _WIN32 int main(int argc, char *argv[]) { @@ -1844,3 +1846,4 @@ main(int argc, char *argv[]) return 0; } +#endif diff --git a/src/core/patcher.cpp b/src/core/patcher.cpp index e5242e9d..83e06886 100644 --- a/src/core/patcher.cpp +++ b/src/core/patcher.cpp @@ -24,7 +24,7 @@ StaticPatcher::Apply() } ms_head = nil; } - +#ifdef _WIN32 std::vector usedAddresses; static DWORD protect[2]; @@ -75,4 +75,20 @@ InjectHook_internal(uint32 address, uint32 hook, int type) VirtualProtect((void*)(address + 1), 4, protect[0], &protect[1]); else VirtualProtect((void*)address, 5, protect[0], &protect[1]); -} \ No newline at end of file +} +#else +void +Protect_internal(uint32 address, uint32 size) +{ +} + +void +Unprotect_internal(void) +{ +} + +void +InjectHook_internal(uint32 address, uint32 hook, int type) +{ +} +#endif diff --git a/src/core/re3.cpp b/src/core/re3.cpp index 0ab32999..9bc6400c 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -1,7 +1,7 @@ -#include #include #define WITHWINDOWS #include "common.h" +#include "crossplatform.h" #include "patcher.h" #include "Renderer.h" #include "Credits.h" @@ -28,6 +28,11 @@ #include "debugmenu.h" #include "Frontend.h" +#ifndef _WIN32 +#include "assert.h" +#include +#endif + #include #ifdef RWLIBS @@ -36,7 +41,7 @@ extern "C" int vsprintf(char* const _Buffer, char const* const _Format, va_list #ifdef USE_PS2_RAND -unsigned __int64 myrand_seed = 1; +unsigned long long myrand_seed = 1; #else unsigned long int myrand_seed = 1; #endif @@ -201,13 +206,22 @@ static const char *carnames[] = { "yankee", "escape", "borgnine", "toyz", "ghost", }; -static std::list TweakVarsList; +static CTweakVar** TweakVarsList; +static int TweakVarsListSize = -1; static bool bAddTweakVarsNow = false; static const char *pTweakVarsDefaultPath = NULL; void CTweakVars::Add(CTweakVar *var) { - TweakVarsList.push_back(var); + if(TweakVarsListSize == -1) { + TweakVarsList = (CTweakVar**)malloc(64 * sizeof(CTweakVar*)); + TweakVarsListSize = 0; + } + if(TweakVarsListSize > 63) + TweakVarsList = (CTweakVar**) realloc(TweakVarsList, (TweakVarsListSize + 1) * sizeof(var)); + + TweakVarsList[TweakVarsListSize++] = var; +// TweakVarsList.push_back(var); if ( bAddTweakVarsNow ) var->AddDBG(pTweakVarsDefaultPath); @@ -217,8 +231,8 @@ void CTweakVars::AddDBG(const char *path) { pTweakVarsDefaultPath = path; - for(auto i = TweakVarsList.begin(); i != TweakVarsList.end(); ++i) - (*i)->AddDBG(pTweakVarsDefaultPath); + for(int i = 0; i < TweakVarsListSize; ++i) + TweakVarsList[i]->AddDBG(pTweakVarsDefaultPath); bAddTweakVarsNow = true; } @@ -392,6 +406,7 @@ static char re3_buff[re3_buffsize]; void re3_assert(const char *expr, const char *filename, unsigned int lineno, const char *func) { +#ifdef _WIN32 int nCode; strcpy_s(re3_buff, re3_buffsize, "Assertion failed!" ); @@ -436,13 +451,22 @@ void re3_assert(const char *expr, const char *filename, unsigned int lineno, con return; abort(); +#else + // TODO + printf("\nRE3 ASSERT FAILED\n\tFile: %s\n\tLine: %d\n\tFunction: %s\n\tExpression: %s\n",filename,lineno,func,expr); + assert(false); +#endif } void re3_debug(const char *format, ...) { va_list va; va_start(va, format); +#ifdef _WIN32 vsprintf_s(re3_buff, re3_buffsize, format, va); +#else + vsprintf(re3_buff, format, va); +#endif va_end(va); printf("%s", re3_buff); @@ -454,18 +478,26 @@ void re3_trace(const char *filename, unsigned int lineno, const char *func, cons char buff[re3_buffsize *2]; va_list va; va_start(va, format); +#ifdef _WIN32 vsprintf_s(re3_buff, re3_buffsize, format, va); va_end(va); sprintf_s(buff, re3_buffsize * 2, "[%s.%s:%d]: %s", filename, func, lineno, re3_buff); +#else + vsprintf(re3_buff, format, va); + va_end(va); - OutputDebugStringA(buff); + sprintf(buff, "[%s.%s:%d]: %s", filename, func, lineno, re3_buff); +#endif + + OutputDebugString(buff); } void re3_usererror(const char *format, ...) { va_list va; va_start(va, format); +#ifdef _WIN32 vsprintf_s(re3_buff, re3_buffsize, format, va); va_end(va); @@ -474,6 +506,11 @@ void re3_usererror(const char *format, ...) raise(SIGABRT); _exit(3); +#else + vsprintf(re3_buff, format, va); + printf("\nRE3 Error!\n\t%s\n",re3_buff); + assert(false); +#endif } #ifdef VALIDATE_SAVE_SIZE diff --git a/src/extras/debugmenu.cpp b/src/extras/debugmenu.cpp index a31426bb..f6b6eeb8 100644 --- a/src/extras/debugmenu.cpp +++ b/src/extras/debugmenu.cpp @@ -9,10 +9,11 @@ #include "debugmenu.h" #include +#ifdef _WIN32 #define snprintf _snprintf #define strdup _strdup - +#endif // Font stuff diff --git a/src/fakerw/fake.cpp b/src/fakerw/fake.cpp index f1531490..50d12b2f 100644 --- a/src/fakerw/fake.cpp +++ b/src/fakerw/fake.cpp @@ -7,6 +7,9 @@ #include #include #include +#ifndef _WIN32 +#include "crossplatform.h" +#endif using namespace rw; @@ -371,8 +374,24 @@ RwStream *RwStreamOpen(RwStreamType type, RwStreamAccessType accessType, const v StreamFile fakefile; file = rwNewT(StreamFile, 1, 0); memcpy(file, &fakefile, sizeof(StreamFile)); +#ifndef _WIN32 + // Be case-insensitive and fix backslashes (from https://github.com/OneSadCookie/fcaseopen/) + FILE* first = fopen((char*)pData, "r"); + char *r; + if (!first) { + r = (char*)alloca(strlen((char*)pData) + 2); + // Use default path(and pass error handling to librw) if we can't find any match + if (!casepath((char*)pData, r)) + r = (char*)pData; + } else + fclose(first); + + if(file->open((char*)r, mode)) + return file; +#else if(file->open((char*)pData, mode)) return file; +#endif rwFree(file); return nil; } diff --git a/src/modelinfo/VehicleModelInfo.cpp b/src/modelinfo/VehicleModelInfo.cpp index 098400cc..767dbdd6 100644 --- a/src/modelinfo/VehicleModelInfo.cpp +++ b/src/modelinfo/VehicleModelInfo.cpp @@ -262,7 +262,7 @@ CVehicleModelInfo::HideDamagedAtomicCB(RpAtomic *atomic, void *data) RpAtomic* CVehicleModelInfo::HideAllComponentsAtomicCB(RpAtomic *atomic, void *data) { - if(CVisibilityPlugins::GetAtomicId(atomic) & (int)data) + if(CVisibilityPlugins::GetAtomicId(atomic) & (uintptr)data) RpAtomicSetFlags(atomic, 0); else RpAtomicSetFlags(atomic, rpATOMICRENDER); @@ -415,7 +415,7 @@ CVehicleModelInfo::SetAtomicFlagCB(RwObject *object, void *data) { RpAtomic *atomic = (RpAtomic*)object; assert(RwObjectGetType(object) == rpATOMIC); - CVisibilityPlugins::SetAtomicFlag(atomic, (int)data); + CVisibilityPlugins::SetAtomicFlag(atomic, (uintptr)data); return object; } @@ -424,7 +424,7 @@ CVehicleModelInfo::ClearAtomicFlagCB(RwObject *object, void *data) { RpAtomic *atomic = (RpAtomic*)object; assert(RwObjectGetType(object) == rpATOMIC); - CVisibilityPlugins::ClearAtomicFlag(atomic, (int)data); + CVisibilityPlugins::ClearAtomicFlag(atomic, (uintptr)data); return object; } diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 78f4b586..2bd5c152 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -2854,7 +2854,7 @@ CPed::SetObjective(eObjective newObj, void *entity) case OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT: // In this special case, entity parameter isn't CEntity, but int. - SetObjectiveTimer((int)entity); + SetObjectiveTimer((uintptr)entity); break; case OBJECTIVE_KILL_CHAR_ON_FOOT: case OBJECTIVE_KILL_CHAR_ANY_MEANS: @@ -3347,7 +3347,7 @@ CPed::MakePhonecall(void) if (!IsPlayer() && CTimer::GetTimeInMilliseconds() > m_phoneTalkTimer - 7000 && bRunningToPhone) { FindPlayerPed()->m_pWanted->RegisterCrime_Immediately(m_crimeToReportOnPhone, GetPosition(), - (m_crimeToReportOnPhone == CRIME_POSSESSION_GUN ? (int)m_threatEntity : (int)((CPed*)m_pEventEntity)->m_threatEntity), false); + (m_crimeToReportOnPhone == CRIME_POSSESSION_GUN ? (uintptr)m_threatEntity : (uintptr)((CPed*)m_pEventEntity)->m_threatEntity), false); bRunningToPhone = false; } #endif @@ -4555,7 +4555,7 @@ CPed::SetPointGunAt(CEntity *to) SetLookFlag(to, true); SetAimFlag(to); #ifdef VC_PED_PORTS - SetLookTimer(INT_MAX); + SetLookTimer(INT32_MAX); #endif } @@ -4794,8 +4794,8 @@ CPed::SetEvasiveDive(CPhysical *reason, uint8 onlyRandomJump) if (reason->IsVehicle() && m_nPedType == PEDTYPE_COP) { if (veh->pDriver && veh->pDriver->IsPlayer()) { CWanted *wanted = FindPlayerPed()->m_pWanted; - wanted->RegisterCrime_Immediately(CRIME_RECKLESS_DRIVING, GetPosition(), (int)this, false); - wanted->RegisterCrime_Immediately(CRIME_SPEEDING, GetPosition(), (int)this, false); + wanted->RegisterCrime_Immediately(CRIME_RECKLESS_DRIVING, GetPosition(), (uintptr)this, false); + wanted->RegisterCrime_Immediately(CRIME_SPEEDING, GetPosition(), (uintptr)this, false); } } } diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index c6c4824b..92e3d358 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -1077,7 +1077,7 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) SetLookFlag(limitedCam, true); SetAimFlag(limitedCam); #ifdef VC_PED_PORTS - SetLookTimer(INT_MAX); // removing this makes head move for real, but I experinced some bugs. + SetLookTimer(INT32_MAX); // removing this makes head move for real, but I experinced some bugs. #endif } else { m_fRotationDest = limitedCam; diff --git a/src/render/Console.cpp b/src/render/Console.cpp index 5ae5d763..8ea5b7a3 100644 --- a/src/render/Console.cpp +++ b/src/render/Console.cpp @@ -17,7 +17,7 @@ CConsole::AddLine(char *s, uint8 r, uint8 g, uint8 b) char tempstr[MAX_STR_LEN+1]; while (strlen(s) > MAX_STR_LEN) { - strncpy_s(tempstr, s, MAX_STR_LEN); + strncpy(tempstr, s, MAX_STR_LEN); tempstr[MAX_STR_LEN-1] = '\0'; s += MAX_STR_LEN - 1; AddOneLine(tempstr, r, g, b); diff --git a/src/render/ParticleMgr.h b/src/render/ParticleMgr.h index 42e3f132..0100bb65 100644 --- a/src/render/ParticleMgr.h +++ b/src/render/ParticleMgr.h @@ -4,7 +4,7 @@ class CParticle; -enum +enum { ZCHECK_FIRST = BIT(0), ZCHECK_STEP = BIT(1), @@ -60,14 +60,12 @@ struct tParticleSystemData uint8 m_InitialColorVariation; RwRGBA m_FadeDestinationColor; uint32 m_ColorFadeTime; - + RwRaster **m_ppRaster; CParticle *m_pParticles; }; -#ifdef CHECK_STRUCT_SIZES VALIDATE_SIZE(tParticleSystemData, 0x88); -#endif class cParticleSystemMgr { @@ -121,14 +119,12 @@ public: tParticleSystemData m_aParticles[MAX_PARTICLES]; cParticleSystemMgr(); - + void Initialise(); void LoadParticleData(); void RangeCheck(tParticleSystemData *pData) { } }; -#ifdef CHECK_STRUCT_SIZES VALIDATE_SIZE(cParticleSystemMgr, 0x2420); -#endif -extern cParticleSystemMgr mod_ParticleSystemManager; \ No newline at end of file +extern cParticleSystemMgr mod_ParticleSystemManager; diff --git a/src/render/PlayerSkin.cpp b/src/render/PlayerSkin.cpp index 94af1fd1..d66f7ce4 100644 --- a/src/render/PlayerSkin.cpp +++ b/src/render/PlayerSkin.cpp @@ -123,7 +123,7 @@ void CPlayerSkin::BeginFrontendSkinEdit(void) { LoadPlayerDff(); - RpClumpForAllAtomics(gpPlayerClump, CClumpModelInfo::SetAtomicRendererCB, CVisibilityPlugins::RenderPlayerCB); + RpClumpForAllAtomics(gpPlayerClump, CClumpModelInfo::SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB); CWorld::Players[0].LoadPlayerSkin(); gOldFov = CDraw::GetFOV(); CDraw::SetFOV(30.0f); diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp index cefc1d9f..69f9dce0 100644 --- a/src/render/Shadows.cpp +++ b/src/render/Shadows.cpp @@ -645,7 +645,7 @@ CShadows::StoreShadowForPole(CEntity *pPole, float fOffsetX, float fOffsetY, flo PolePos.x += -CTimeCycle::GetSunPosition().x * (fPoleHeight / 2); PolePos.y += -CTimeCycle::GetSunPosition().y * (fPoleHeight / 2); - StoreStaticShadow((uint32)pPole + nID + _TODOCONST(51), SHADOWTYPE_DARK, gpPostShadowTex, &PolePos, + StoreStaticShadow((uintptr)pPole + nID + _TODOCONST(51), SHADOWTYPE_DARK, gpPostShadowTex, &PolePos, -CTimeCycle::GetSunPosition().x * (fPoleHeight / 2), -CTimeCycle::GetSunPosition().y * (fPoleHeight / 2), CTimeCycle::GetShadowSideX() * fPoleWidth, @@ -1516,7 +1516,7 @@ CShadows::UpdatePermanentShadows(void) // timePassed == aPermanentShadows[i].m_nLifeTime -> 0 float fMult = 1.0f - float(timePassed - (aPermanentShadows[i].m_nLifeTime * 3 / 4)) / (aPermanentShadows[i].m_nLifeTime / 4); - StoreStaticShadow((uint32)&aPermanentShadows[i], + StoreStaticShadow((uintptr)&aPermanentShadows[i], aPermanentShadows[i].m_nType, aPermanentShadows[i].m_pTexture, &aPermanentShadows[i].m_vecPos, @@ -1533,7 +1533,7 @@ CShadows::UpdatePermanentShadows(void) } else { - StoreStaticShadow((uint32)&aPermanentShadows[i], + StoreStaticShadow((uintptr)&aPermanentShadows[i], aPermanentShadows[i].m_nType, aPermanentShadows[i].m_pTexture, &aPermanentShadows[i].m_vecPos, diff --git a/src/render/Shadows.h b/src/render/Shadows.h index ef56d336..63aaaaf2 100644 --- a/src/render/Shadows.h +++ b/src/render/Shadows.h @@ -52,9 +52,7 @@ public: { } }; -#ifdef CHECK_STRUCT_SIZES VALIDATE_SIZE(CStoredShadow, 0x30); -#endif class CPolyBunch { @@ -69,9 +67,7 @@ public: { } }; -#ifdef CHECK_STRUCT_SIZES VALIDATE_SIZE(CPolyBunch, 0x6C); -#endif class CStaticShadow { @@ -93,16 +89,14 @@ public: bool m_bRendered; bool m_bTemp; RwTexture *m_pTexture; - + CStaticShadow() { } void Free(); }; -#ifdef CHECK_STRUCT_SIZES VALIDATE_SIZE(CStaticShadow, 0x40); -#endif class CPermanentShadow { @@ -120,7 +114,7 @@ public: uint32 m_nTimeCreated; uint32 m_nLifeTime; RwTexture *m_pTexture; - + CPermanentShadow() { } }; @@ -168,7 +162,7 @@ public: static void GeneratePolysForStaticShadow (int16 nStaticShadowID); static void CastShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); - static void CastShadowEntity (CEntity *pEntity, float fStartX, float fStartY, float fEndX, float fEndY, + static void CastShadowEntity (CEntity *pEntity, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); static void UpdateStaticShadows (void); static void UpdatePermanentShadows (void); diff --git a/src/rw/RwHelper.cpp b/src/rw/RwHelper.cpp index cb1d4ab5..5026e2c8 100644 --- a/src/rw/RwHelper.cpp +++ b/src/rw/RwHelper.cpp @@ -60,15 +60,15 @@ void * RwMallocAlign(RwUInt32 size, RwUInt32 align) { void *mem = (void *)malloc(size + align); - + ASSERT(mem != nil); - - void *addr = (void *)((((RwUInt32)mem) + align) & ~(align - 1)); - + + void *addr = (void *)((((uintptr)mem) + align) & ~(align - 1)); + ASSERT(addr != nil); - + *(((void **)addr) - 1) = mem; - + return addr; } @@ -76,11 +76,11 @@ void RwFreeAlign(void *mem) { ASSERT(mem != nil); - + void *addr = *(((void **)mem) - 1); - + ASSERT(addr != nil); - + free(addr); } @@ -381,7 +381,7 @@ CameraSize(RwCamera * camera, RwRect * rect, RwEngineGetVideoModeInfo(&videoMode, RwEngineGetCurrentVideoMode()); - + origSize.w = RwRasterGetWidth(RwCameraGetRaster(camera)); origSize.h = RwRasterGetHeight(RwCameraGetRaster(camera)); @@ -392,7 +392,7 @@ CameraSize(RwCamera * camera, RwRect * rect, /* For full screen applications, resizing the camera just doesn't * make sense, use the video mode size. */ - + r.x = r.y = 0; r.w = videoMode.width; r.h = videoMode.height; @@ -414,11 +414,11 @@ CameraSize(RwCamera * camera, RwRect * rect, { RwRaster *raster; RwRaster *zRaster; - + /* * Destroy rasters... */ - + raster = RwCameraGetRaster(camera); if( raster ) { @@ -430,14 +430,14 @@ CameraSize(RwCamera * camera, RwRect * rect, { RwRasterDestroy(zRaster); } - + /* - * Create new rasters... + * Create new rasters... */ raster = RwRasterCreate(rect->w, rect->h, 0, rwRASTERTYPECAMERA); zRaster = RwRasterCreate(rect->w, rect->h, 0, rwRASTERTYPEZBUFFER); - + if( raster && zRaster ) { RwCameraSetRaster(camera, raster); @@ -460,8 +460,8 @@ CameraSize(RwCamera * camera, RwRect * rect, rect->w = origSize.w; rect->h = origSize.h; - /* - * Use default values... + /* + * Use default values... */ raster = RwRasterCreate(rect->w, rect->h, 0, rwRASTERTYPECAMERA); @@ -495,9 +495,9 @@ CameraSize(RwCamera * camera, RwRect * rect, vw.y = viewWindow; } } - + RwCameraSetViewWindow(camera, &vw); - + RsGlobal.width = rect->w; RsGlobal.height = rect->h; } diff --git a/src/rw/TexRead.cpp b/src/rw/TexRead.cpp index 60945665..122ce655 100644 --- a/src/rw/TexRead.cpp +++ b/src/rw/TexRead.cpp @@ -3,6 +3,7 @@ #pragma warning( pop ) #include "common.h" #include "crossplatform.h" +#include "platform.h" #include "Timer.h" #ifdef GTA_PC diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp index 5184860b..cb514f07 100644 --- a/src/rw/VisibilityPlugins.cpp +++ b/src/rw/VisibilityPlugins.cpp @@ -114,7 +114,7 @@ CVisibilityPlugins::SetRenderWareCamera(RwCamera *camera) RpMaterial* SetAlphaCB(RpMaterial *material, void *data) { - ((RwRGBA*)RpMaterialGetColor(material))->alpha = (uint8)(uint32)data; + ((RwRGBA*)RpMaterialGetColor(material))->alpha = (uint8)(uintptr)data; return material; } @@ -833,15 +833,15 @@ void CVisibilityPlugins::SetClumpModelInfo(RpClump *clump, CClumpModelInfo *modelInfo) { CVehicleModelInfo *vmi; - SetFrameHierarchyId(RpClumpGetFrame(clump), (int32)modelInfo); + SetFrameHierarchyId(RpClumpGetFrame(clump), (uintptr)modelInfo); // Unused switch (modelInfo->GetModelType()) { // ignore MLO case MITYPE_VEHICLE: vmi = (CVehicleModelInfo*)modelInfo; - if(vmi->m_vehicleType == VEHICLE_TYPE_TRAIN || - vmi->m_vehicleType == VEHICLE_TYPE_HELI || + if(vmi->m_vehicleType == VEHICLE_TYPE_TRAIN || + vmi->m_vehicleType == VEHICLE_TYPE_HELI || vmi->m_vehicleType == VEHICLE_TYPE_PLANE) CLUMPEXT(clump)->visibilityCB = VehicleVisibilityCB_BigVehicle; else diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index bb074042..d0cdb358 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -1,5 +1,4 @@ #include "common.h" -#define USEALTERNATIVEWINFUNCS #include "crossplatform.h" #include "main.h" diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp index d3aeee26..77d1ddce 100644 --- a/src/save/PCSave.cpp +++ b/src/save/PCSave.cpp @@ -1,5 +1,4 @@ #include "common.h" -#define USEALTERNATIVEWINFUNCS #include "crossplatform.h" #include "FileMgr.h" diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp index f9464bb6..9971d2ae 100644 --- a/src/skel/crossplatform.cpp +++ b/src/skel/crossplatform.cpp @@ -1,5 +1,4 @@ #include "common.h" -#define USEALTERNATIVEWINFUNCS #include "crossplatform.h" // For internal use @@ -20,7 +19,8 @@ void GetLocalTime_CP(SYSTEMTIME *out) { tmToSystemTime(localTm, out); } -#if !defined _WIN32 || defined __MINGW32__ +// Compatible with Linux/POSIX and MinGW on Windows +#ifndef _WIN32 HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) { char newpathname[32]; strncpy(newpathname, pathname, 32); @@ -34,7 +34,7 @@ HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) { strncpy(firstfile->extension, "", sizeof(firstfile->extension)); HANDLE d; - if ((d = opendir(path)) == NULL || !FindNextFile(d, firstfile)) + if ((d = (HANDLE)opendir(path)) == NULL || !FindNextFile(d, firstfile)) return NULL; return d; @@ -45,7 +45,7 @@ bool FindNextFile(HANDLE d, WIN32_FIND_DATA* finddata) { static struct stat fileStats; static char path[PATH_MAX], relativepath[NAME_MAX + sizeof(finddata->folder) + 1]; int extensionLen = strlen(finddata->extension); - while ((file = readdir(d)) != NULL) { + while ((file = readdir((DIR*)d)) != NULL) { // We only want "DT_REG"ular Files, but reportedly some FS and OSes gives DT_UNKNOWN as type. if ((file->d_type == DT_UNKNOWN || file->d_type == DT_REG) && @@ -78,4 +78,119 @@ void FileTimeToSystemTime(time_t* writeTime, SYSTEMTIME* out) { tm *ptm = gmtime(writeTime); tmToSystemTime(ptm, out); } -#endif \ No newline at end of file +#endif + +#ifndef _WIN32 +char *strupr(char *s) { + char* tmp = s; + + for (;*tmp;++tmp) { + *tmp = toupper((unsigned char) *tmp); + } + + return s; +} +char *strlwr(char *s) { + char* tmp = s; + + for (;*tmp;++tmp) { + *tmp = tolower((unsigned char) *tmp); + } + + return s; +} + +char *trim(char *s) { + char *ptr; + if (!s) + return NULL; // handle NULL string + if (!*s) + return s; // handle empty string + for (ptr = s + strlen(s) - 1; (ptr >= s) && isspace(*ptr); --ptr); + ptr[1] = '\0'; + return s; +} + +// Case-insensitivity on linux (from https://github.com/OneSadCookie/fcaseopen) +// r must have strlen(path) + 2 bytes +int casepath(char const *path, char *r) +{ + size_t l = strlen(path); + char *p = (char*)alloca(l + 1); + strcpy(p, path); + + // my addon: change \'s with / + char *nextBs; + while(nextBs = strstr(p, "\\")){ + *nextBs = '/'; + } + + // my addon: linux doesn't handle filenames with spaces at the end nicely + p = trim(p); + + size_t rl = 0; + + DIR *d; + if (p[0] == '/') + { + d = opendir("/"); + p = p + 1; + } + else + { + d = opendir("."); + r[0] = '.'; + r[1] = 0; + rl = 1; + } + + int last = 0; + char *c = strsep(&p, "/"); + while (c) + { + if (!d) + { + return 0; + } + + if (last) + { + closedir(d); + return 0; + } + + r[rl] = '/'; + rl += 1; + r[rl] = 0; + + struct dirent *e = readdir(d); + while (e) + { + if (strcasecmp(c, e->d_name) == 0) + { + strcpy(r + rl, e->d_name); + rl += strlen(e->d_name); + + closedir(d); + d = opendir(r); + + break; + } + + e = readdir(d); + } + + if (!e) + { + strcpy(r + rl, c); + rl += strlen(c); + last = 1; + } + + c = strsep(&p, "/"); + } + + if (d) closedir(d); + return 1; +} +#endif diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index 342aab4e..f6a3408b 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -1,10 +1,38 @@ #include -// This is the common include for platform/renderer specific skeletons(glfw, win etc.) and cross platform things (like Windows directories wrapper, platform specific global arrays etc.) +// This is the common include for platform/renderer specific skeletons(glfw.cpp, win.cpp etc.) and using cross platform things (like Windows directories wrapper, platform specific global arrays etc.) +// Functions that's different on glfw and win but have same signature, should be located on platform.h. -// This only has as Win header. #ifdef _WIN32 +// This only has as Win header. #include "win.h" +extern DWORD _dwOperatingSystemVersion; +#else +char *strupr(char *str); +char *strlwr(char *str); +enum { + OS_WIN98, + OS_WIN2000, + OS_WINNT, + OS_WINXP, +}; + +enum { + LANG_OTHER, + LANG_GERMAN, + LANG_FRENCH, + LANG_ENGLISH, + LANG_ITALIAN, + LANG_SPANISH, +}; + +enum { + SUBLANG_OTHER, + SUBLANG_ENGLISH_AUS +}; + +extern long _dwOperatingSystemVersion; +int casepath(char const *path, char *r); #endif #ifdef RW_GL3 @@ -14,8 +42,8 @@ typedef struct RwBool fullScreen; RwV2d lastMousePos; double mouseWheel; // glfw doesn't cache it - int8 joy1id; - int8 joy2id; + RwInt8 joy1id; + RwInt8 joy2id; } psGlobalType; @@ -44,17 +72,6 @@ enum eGameState extern RwUInt32 gGameState; RwBool IsForegroundApp(); -void InitialiseLanguage(); -RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode); - -RwChar** _psGetVideoModeList(); -RwInt32 _psGetNumVideModes(); - -void _psSelectScreenVM(RwInt32 videoMode); -void HandleExit(); -void _InputTranslateShiftKeyUpDown(RsKeyCodes* rs); - -// Mostly wrappers around Windows functions #ifndef MAX_PATH #if !defined _WIN32 || defined __MINGW32__ @@ -64,39 +81,39 @@ void _InputTranslateShiftKeyUpDown(RsKeyCodes* rs); #endif #endif -// TODO: Remove USEALTERNATIVEWINFUNCS and don't use it anywhere when re3 becomes fully cross-platform, this is for testing // Codes compatible with Windows and Linux -#if defined USEALTERNATIVEWINFUNCS || !defined _WIN32 || defined __MINGW32__ +#if !defined _WIN32 #define DeleteFile unlink // Needed for save games struct SYSTEMTIME { - uint16 wYear; - uint16 wMonth; - uint16 wDayOfWeek; - uint16 wDay; - uint16 wHour; - uint16 wMinute; - uint16 wSecond; - uint16 wMilliseconds; + RwUInt16 wYear; + RwUInt16 wMonth; + RwUInt16 wDayOfWeek; + RwUInt16 wDay; + RwUInt16 wHour; + RwUInt16 wMinute; + RwUInt16 wSecond; + RwUInt16 wMilliseconds; }; void GetLocalTime_CP(SYSTEMTIME* out); #define GetLocalTime GetLocalTime_CP -#define OutputDebugString(s) re3_debug("[DBG-2]: " s "\n") +#define OutputDebugString(s) re3_debug("[DBG-2]: %s\n",s) #endif -// Only runs on GNU/POSIX/etc. -#if !defined _WIN32 || defined __MINGW32__ +// Compatible with Linux/POSIX and MinGW on Windows +#if !defined _WIN32 #include #include #include #include #include +#include -typedef DIR* HANDLE; +typedef void* HANDLE; #define INVALID_HANDLE_VALUE NULL -#define FindClose closedir +#define FindClose(h) closedir((DIR*)h) #define LOCALE_USER_DEFAULT 0 #define DATE_SHORTDATE 0 @@ -107,8 +124,8 @@ struct WIN32_FIND_DATA { time_t ftLastWriteTime; }; -HANDLE FindFirstFile(char*, WIN32_FIND_DATA*); +HANDLE FindFirstFile(const char*, WIN32_FIND_DATA*); bool FindNextFile(HANDLE, WIN32_FIND_DATA*); void FileTimeToSystemTime(time_t*, SYSTEMTIME*); void GetDateFormat(int, int, SYSTEMTIME*, int, char*, int); -#endif \ No newline at end of file +#endif diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index 63ebccee..b30bda7b 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -7,14 +7,11 @@ #pragma warning( disable : 4005) #pragma warning( pop ) -#pragma comment( lib, "Winmm.lib" ) // Needed for time - #if (defined(_MSC_VER)) #include #endif /* (defined(_MSC_VER)) */ #include #include "rwcore.h" -#include "resource.h" #include "skeleton.h" #include "platform.h" #include "crossplatform.h" @@ -69,14 +66,20 @@ static psGlobalType PsGlobal; #define JIF(x) if (FAILED(hr=(x))) \ {debug(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr); return;} +long _dwMemAvailPhys; +RwUInt32 gGameState; -// TODO: This is used on selecting video mode, so either think something or remove it completely -DWORD _dwMemTotalVideo = 1024 * (1024 * 1024); // 1024 MB as placeholder -DWORD _dwMemAvailPhys; - +#ifdef _WIN32 DWORD _dwOperatingSystemVersion; - -RwUInt32 gGameState; +#include "resource.h" +#else +long _dwOperatingSystemVersion; +#include +#include +#include +#include +#include +#endif /* ***************************************************************************** */ @@ -144,7 +147,7 @@ const char *_psGetUserFilesFolder() strcpy(szUserFiles, "data"); return szUserFiles; #else - static CHAR szUserFiles[256]; + static char szUserFiles[256]; strcpy(szUserFiles, "userfiles"); _psCreateFolder(szUserFiles); return szUserFiles; @@ -185,6 +188,8 @@ psCameraShowRaster(RwCamera *camera) /* ***************************************************************************** */ +#ifdef _WIN32 +#pragma comment( lib, "Winmm.lib" ) // Needed for time RwUInt32 psTimer(void) { @@ -202,6 +207,16 @@ psTimer(void) return time; } +#else +double +psTimer(void) +{ + struct timespec start; + clock_gettime(CLOCK_MONOTONIC_RAW, &start); + return start.tv_sec * 1000.0 + start.tv_nsec/1000000.0; +} +#endif + /* ***************************************************************************** @@ -209,12 +224,7 @@ psTimer(void) void psMouseSetPos(RwV2d *pos) { - POINT point; - - point.x = (RwInt32) pos->x; - point.y = (RwInt32) pos->y; - - glfwSetCursorPos(PSGLOBAL(window), point.x, point.y); + glfwSetCursorPos(PSGLOBAL(window), pos->x, pos->y); PSGLOBAL(lastMousePos.x) = (RwInt32)pos->x; @@ -285,7 +295,7 @@ psInitialise(void) gGameState = GS_START_UP; TRACE("gGameState = GS_START_UP"); - +#ifdef _WIN32 OSVERSIONINFO verInfo; verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); @@ -330,14 +340,19 @@ psInitialise(void) _dwMemAvailPhys = memstats.dwAvailPhys; -#ifdef FIX_BUGS debug("Physical memory size %u\n", memstats.dwTotalPhys); debug("Available physical memory %u\n", memstats.dwAvailPhys); #else - debug("Physical memory size %d\n", memstats.dwTotalPhys); - debug("Available physical memory %d\n", memstats.dwAvailPhys); -#endif + struct sysinfo systemInfo; + sysinfo(&systemInfo); + + _dwMemAvailPhys = systemInfo.freeram; + _dwOperatingSystemVersion = OS_WINXP; // To fool other classes + + debug("Physical memory size %u\n", systemInfo.totalram); + debug("Available physical memory %u\n", systemInfo.freeram); +#endif TheText.Unload(); return TRUE; @@ -413,18 +428,8 @@ RwChar **_psGetVideoModeList() if ( vm.flags & rwVIDEOMODEEXCLUSIVE ) { - if ( vm.width >= 640 - && vm.height >= 480 - && (vm.width == 640 - && vm.height == 480) - || !(vm.flags & rwVIDEOMODEEXCLUSIVE) - || (_dwMemTotalVideo - vm.depth * vm.height * vm.width / 8) > (12 * 1024 * 1024)/*12 MB*/ ) - { - _VMList[i] = (RwChar*)RwCalloc(100, sizeof(RwChar)); - rwsprintf(_VMList[i],"%lu X %lu X %lu", vm.width, vm.height, vm.depth); - } - else - _VMList[i] = nil; + _VMList[i] = (RwChar*)RwCalloc(100, sizeof(RwChar)); + rwsprintf(_VMList[i],"%lu X %lu X %lu", vm.width, vm.height, vm.depth); } else _VMList[i] = nil; @@ -445,6 +450,8 @@ void _psSelectScreenVM(RwInt32 videoMode) if (!_psSetVideoMode(RwEngineGetCurrentSubSystem(), videoMode)) { RsGlobal.quit = TRUE; + + printf("ERROR: Failed to select new screen resolution\n"); } else FrontEndMenuManager.LoadAllTextures(); @@ -589,7 +596,7 @@ psSelectDevice() #ifdef DEFAULT_NATIVE_RESOLUTION GcurSelVM = 1; #else - MessageBox(nil, "Cannot find 640x480 video mode", "GTA3", MB_OK); + printf("WARNING: Cannot find 640x480 video mode, selecting device cancelled\n"); return FALSE; #endif } @@ -602,8 +609,9 @@ psSelectDevice() FrontEndMenuManager.m_nPrefsHeight == 0 || FrontEndMenuManager.m_nPrefsDepth == 0){ // Defaults if nothing specified - FrontEndMenuManager.m_nPrefsWidth = GetSystemMetrics(SM_CXSCREEN); - FrontEndMenuManager.m_nPrefsHeight = GetSystemMetrics(SM_CYSCREEN); + const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + FrontEndMenuManager.m_nPrefsWidth = mode->width; + FrontEndMenuManager.m_nPrefsHeight = mode->height; FrontEndMenuManager.m_nPrefsDepth = 32; FrontEndMenuManager.m_nPrefsWindowed = 0; } @@ -632,7 +640,7 @@ psSelectDevice() } if(bestFsMode < 0){ - MessageBox(nil, "Cannot find desired video mode", "GTA3", MB_OK); + printf("WARNING: Cannot find desired video mode, selecting device cancelled\n"); return FALSE; } GcurSelVM = bestFsMode; @@ -886,6 +894,30 @@ CommandLineToArgv(RwChar *cmdLine, RwInt32 *argCount) */ void InitialiseLanguage() { +#ifndef _WIN32 + // Mandatory for Linux(Unix? Posix?) to set lang. to environment lang. + setlocale(LC_ALL, ""); + + char *systemLang, *keyboardLang; + + systemLang = setlocale (LC_ALL, NULL); + keyboardLang = setlocale (LC_CTYPE, NULL); + + short primUserLCID, primSystemLCID; + primUserLCID = primSystemLCID = !strncmp(systemLang, "fr_",3) ? LANG_FRENCH : + !strncmp(systemLang, "de_",3) ? LANG_GERMAN : + !strncmp(systemLang, "en_",3) ? LANG_ENGLISH : + !strncmp(systemLang, "it_",3) ? LANG_ITALIAN : + !strncmp(systemLang, "es_",3) ? LANG_SPANISH : + LANG_OTHER; + + short primLayout = !strncmp(keyboardLang, "fr_",3) ? LANG_FRENCH : (!strncmp(keyboardLang, "de_",3) ? LANG_GERMAN : LANG_ENGLISH); + + short subUserLCID, subSystemLCID; + subUserLCID = subSystemLCID = !strncmp(systemLang, "en_AU",5) ? SUBLANG_ENGLISH_AUS : SUBLANG_OTHER; + short subLayout = !strncmp(keyboardLang, "en_AU",5) ? SUBLANG_ENGLISH_AUS : SUBLANG_OTHER; + +#else WORD primUserLCID = PRIMARYLANGID(GetSystemDefaultLCID()); WORD primSystemLCID = PRIMARYLANGID(GetUserDefaultLCID()); WORD primLayout = PRIMARYLANGID((DWORD)GetKeyboardLayout(0)); @@ -893,7 +925,7 @@ void InitialiseLanguage() WORD subUserLCID = SUBLANGID(GetSystemDefaultLCID()); WORD subSystemLCID = SUBLANGID(GetUserDefaultLCID()); WORD subLayout = SUBLANGID((DWORD)GetKeyboardLayout(0)); - +#endif if ( primUserLCID == LANG_GERMAN || primSystemLCID == LANG_GERMAN || primLayout == LANG_GERMAN ) @@ -987,13 +1019,22 @@ void InitialiseLanguage() TheText.Unload(); TheText.Load(); + +#ifndef _WIN32 + // TODO this is needed for strcasecmp to work correctly across all languages, but can these cause other problems?? + setlocale(LC_CTYPE, "C"); + setlocale(LC_COLLATE, "C"); + setlocale(LC_NUMERIC, "C"); +#endif } /* ***************************************************************************** */ + void HandleExit() { +#ifdef _WIN32 MSG message; while ( PeekMessage(&message, nil, 0U, 0U, PM_REMOVE|PM_NOYIELD) ) { @@ -1007,8 +1048,21 @@ void HandleExit() DispatchMessage(&message); } } +#else + // We now handle terminate message always, why handle on some cases? + return; +#endif } - + +#ifndef _WIN32 +void terminateHandler(int sig, siginfo_t *info, void *ucontext) { + RsGlobal.quit = TRUE; +} + +void dummyHandler(int sig){ +} +#endif + void resizeCB(GLFWwindow* window, int width, int height) { /* * Handle event to ensure window contents are displayed during re-size @@ -1210,17 +1264,36 @@ cursorCB(GLFWwindow* window, double xpos, double ypos) { /* ***************************************************************************** */ +#ifdef _WIN32 int PASCAL WinMain(HINSTANCE instance, HINSTANCE prevInstance __RWUNUSED__, CMDSTR cmdLine, int cmdShow) { - RwV2d pos; - RwInt32 argc, i; + + RwInt32 argc; RwChar** argv; - StaticPatcher::Apply(); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, nil, SPIF_SENDCHANGE); +#else +int +main(int argc, char *argv[]) +{ +#endif + RwV2d pos; + RwInt32 i; +// StaticPatcher::Apply(); + +#ifndef _WIN32 + struct sigaction act; + act.sa_sigaction = terminateHandler; + act.sa_flags = SA_SIGINFO; + sigaction(SIGTERM, &act, NULL); + struct sigaction sa; + sa.sa_handler = dummyHandler; + sa.sa_flags = 0; + sigaction(SIGINT, &sa, NULL); // Needed for CdStreamPosix +#endif /* * Initialize the platform independent data. @@ -1231,7 +1304,7 @@ WinMain(HINSTANCE instance, return FALSE; } - +#ifdef _WIN32 /* * Get proper command line params, cmdLine passed to us does not * work properly under all circumstances... @@ -1248,6 +1321,7 @@ WinMain(HINSTANCE instance, * Parse command line parameters (except program name) one at * a time BEFORE RenderWare initialization... */ +#endif for(i=1; im_pCraneEntity != nil) - pCrane->m_pCraneEntity = CPools::GetBuildingPool()->GetSlot((uint32)pCrane->m_pCraneEntity - 1); + pCrane->m_pCraneEntity = CPools::GetBuildingPool()->GetSlot((uintptr)pCrane->m_pCraneEntity - 1); if (pCrane->m_pHook != nil) - pCrane->m_pHook = CPools::GetObjectPool()->GetSlot((uint32)pCrane->m_pHook - 1); + pCrane->m_pHook = CPools::GetObjectPool()->GetSlot((uintptr)pCrane->m_pHook - 1); if (pCrane->m_pVehiclePickedUp != nil) - pCrane->m_pVehiclePickedUp = CPools::GetVehiclePool()->GetSlot((uint32)pCrane->m_pVehiclePickedUp - 1); + pCrane->m_pVehiclePickedUp = CPools::GetVehiclePool()->GetSlot((uintptr)pCrane->m_pVehiclePickedUp - 1); } for (int i = 0; i < NUM_CRANES; i++) { aCranes[i].m_nAudioEntity = DMAudio.CreateEntity(AUDIOTYPE_CRANE, &aCranes[i]); -- cgit v1.2.3 From 36e2bc95d385c79075495d96e066d697727449d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 11 May 2020 20:10:01 +0300 Subject: Fix Windows build and premake --- premake5.lua | 3 ++- src/save/GenericGameStorage.cpp | 1 + src/save/PCSave.cpp | 1 + src/skel/crossplatform.cpp | 5 +++++ src/skel/crossplatform.h | 4 ++-- src/skel/glfw/glfw.cpp | 2 +- src/skel/win/win.cpp | 16 ++++++++-------- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/premake5.lua b/premake5.lua index dc16e31e..08ace524 100644 --- a/premake5.lua +++ b/premake5.lua @@ -90,7 +90,8 @@ workspace "re3" } debugdir (gamepath) if (exepath) then - debugcommand (gamepath .. exepath) + -- Used VS variable $(TargetFileName) because it doesn't accept premake tokens. Does debugcommand even work outside VS?? + debugcommand (gamepath .. "$(TargetFileName)") dir, file = exepath:match'(.*/)(.*)' debugdir (gamepath .. (dir or "")) end diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index d0cdb358..ba7bd216 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -1,3 +1,4 @@ +#define WITHWINDOWS #include "common.h" #include "crossplatform.h" #include "main.h" diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp index 77d1ddce..3dc80f73 100644 --- a/src/save/PCSave.cpp +++ b/src/save/PCSave.cpp @@ -1,3 +1,4 @@ +#define WITHWINDOWS #include "common.h" #include "crossplatform.h" diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp index 9971d2ae..40f4f053 100644 --- a/src/skel/crossplatform.cpp +++ b/src/skel/crossplatform.cpp @@ -1,6 +1,9 @@ #include "common.h" #include "crossplatform.h" +// Codes compatible with Windows and Linux +#ifndef _WIN32 + // For internal use // wMilliseconds is not needed void tmToSystemTime(const tm *tm, SYSTEMTIME *out) { @@ -18,6 +21,7 @@ void GetLocalTime_CP(SYSTEMTIME *out) { tm *localTm = localtime(×tamp); tmToSystemTime(localTm, out); } +#endif // Compatible with Linux/POSIX and MinGW on Windows #ifndef _WIN32 @@ -80,6 +84,7 @@ void FileTimeToSystemTime(time_t* writeTime, SYSTEMTIME* out) { } #endif +// Funcs/features from Windows that we need on other platforms #ifndef _WIN32 char *strupr(char *s) { char* tmp = s; diff --git a/src/skel/crossplatform.h b/src/skel/crossplatform.h index f6a3408b..a21877c1 100644 --- a/src/skel/crossplatform.h +++ b/src/skel/crossplatform.h @@ -82,7 +82,7 @@ RwBool IsForegroundApp(); #endif // Codes compatible with Windows and Linux -#if !defined _WIN32 +#ifndef _WIN32 #define DeleteFile unlink // Needed for save games @@ -103,7 +103,7 @@ void GetLocalTime_CP(SYSTEMTIME* out); #endif // Compatible with Linux/POSIX and MinGW on Windows -#if !defined _WIN32 +#ifndef _WIN32 #include #include #include diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index b30bda7b..4a35adcf 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -66,7 +66,7 @@ static psGlobalType PsGlobal; #define JIF(x) if (FAILED(hr=(x))) \ {debug(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr); return;} -long _dwMemAvailPhys; +unsigned long _dwMemAvailPhys; RwUInt32 gGameState; #ifdef _WIN32 diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index d20cc0bf..9a885818 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -100,10 +100,10 @@ IVideoWindow *pVW = nil; IMediaSeeking *pMS = nil; DWORD dwDXVersion; -DWORD _dwMemTotalPhys; -DWORD _dwMemAvailPhys; -DWORD _dwMemTotalVirtual; -DWORD _dwMemAvailVirtual; +SIZE_T _dwMemTotalPhys; +SIZE_T _dwMemAvailPhys; +SIZE_T _dwMemTotalVirtual; +SIZE_T _dwMemAvailVirtual; DWORD _dwMemTotalVideo; DWORD _dwMemAvailVideo; DWORD _dwOperatingSystemVersion; @@ -687,10 +687,10 @@ psInitialise(void) _GetVideoMemInfo(&_dwMemTotalVideo, &_dwMemAvailVideo); #ifdef FIX_BUGS - debug("Physical memory size %u\n", _dwMemTotalPhys); - debug("Available physical memory %u\n", _dwMemAvailPhys); - debug("Video memory size %u\n", _dwMemTotalVideo); - debug("Available video memory %u\n", _dwMemAvailVideo); + debug("Physical memory size %lu\n", _dwMemTotalPhys); + debug("Available physical memory %lu\n", _dwMemAvailPhys); + debug("Video memory size %lu\n", _dwMemTotalVideo); + debug("Available video memory %lu\n", _dwMemAvailVideo); #else debug("Physical memory size %d\n", _dwMemTotalPhys); debug("Available physical memory %d\n", _dwMemAvailPhys); -- cgit v1.2.3 From 70a8234dad441b73c998ee11b2932071ce55c540 Mon Sep 17 00:00:00 2001 From: aap Date: Mon, 11 May 2020 22:24:53 +0200 Subject: RenderPedCB from VC --- src/rw/VisibilityPlugins.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp index 5184860b..46ec8ae2 100644 --- a/src/rw/VisibilityPlugins.cpp +++ b/src/rw/VisibilityPlugins.cpp @@ -557,12 +557,16 @@ RpAtomic* CVisibilityPlugins::RenderPedCB(RpAtomic *atomic) { int32 alpha; + RwV3d cam2atm; - alpha = GetClumpAlpha(RpAtomicGetClump(atomic)); - if(alpha == 255) - AtomicDefaultRenderCallBack(atomic); - else - RenderAlphaAtomic(atomic, alpha); + RwV3dSub(&cam2atm, &RwFrameGetLTM(RpAtomicGetFrame(atomic))->pos, ms_pCameraPosn); + if(RwV3dDotProduct(&cam2atm, &cam2atm) < ms_pedLod1Dist){ + alpha = GetClumpAlpha(RpAtomicGetClump(atomic)); + if(alpha == 255) + AtomicDefaultRenderCallBack(atomic); + else + RenderAlphaAtomic(atomic, alpha); + } return atomic; } -- cgit v1.2.3 From c4a154557bad4a610abfc3424d392cf2fd9c4cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Tue, 12 May 2020 00:10:50 +0300 Subject: Fix appveyor (hopefully) --- premake5.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/premake5.lua b/premake5.lua index 08ace524..f295c3d9 100644 --- a/premake5.lua +++ b/premake5.lua @@ -170,7 +170,9 @@ project "re3" libdirs { "milessdk/lib" } - setpaths("$(GTA_III_RE_DIR)/", "%(cfg.buildtarget.name)", "") + if(os.getenv("GTA_III_RE_DIR")) then + setpaths("$(GTA_III_RE_DIR)/", "%(cfg.buildtarget.name)", "") + end filter "platforms:win*" files { addSrcFiles("src/skel/win") } -- cgit v1.2.3 From 603ac9ce4b1b46f6524f30fe1b7d8a87bd7576b3 Mon Sep 17 00:00:00 2001 From: erorcun Date: Tue, 12 May 2020 01:24:54 +0300 Subject: Update README.md --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index cffdbd1d..7a4c8ea2 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,19 @@ such that we have a working game at all times. - (Optional) If you want to use optional features like Russian language or menu map, copy the files in /gamefiles folder to your game root folder. - Move re3.exe to GTA 3 directory and run it. -> :information_source: **Rendering engine** re3 uses completely homebrew RenderWare-replacement rendering engine; [librw](https://github.com/aap/librw/). librw comes as submodule of re3, but you also can use LIBRW enviorenment variable to specify path to your own librw. +## How can I build it? + +Currently only building on VS2015/2017/2019 (Windows) and GCC (Linux) is tested. -> :warning: **Notice for builders** There are various settings at the very bottom of `config.h`, you may want to take a look there. i.e. FIX_BUGS define fixes the bugs we've come across. +- Clone the repo. +- Run `git submodule init` and `git submodule update`. +- Point GTA_III_RE_DIR environment variable to GTA3 root folder. +- Run premake + - On Windows: one of the `premake-vsXXXX.cmd` variants on root folder + - On Linux: proceed to [Building on Linux](https://github.com/GTAmodding/re3/wiki/Building-on-Linux). +- There are various settings at the very bottom of [config.h](https://github.com/GTAmodding/re3/tree/master/src/core/config.h), you may want to take a look there. i.e. FIX_BUGS define fixes the bugs we've come across. -https://github.com/GTAmodding/re3/tree/master/src/core/config.h +> :information_source: **Rendering engine** re3 uses completely homebrew RenderWare-replacement rendering engine; [librw](https://github.com/aap/librw/). librw comes as submodule of re3, but you also can use LIBRW enviorenment variable to specify path to your own librw. ## Contributing @@ -141,11 +149,3 @@ but here are some observations: * do *not* use `dw` for `DWORD` or so, we're not programming win32 * Generally, try to make the code look as if R* could have written it - -### Environment Variables -Here you can find a list of variables that you might need to set in windows: -``` -"GTA_III_RE_DIR" * path to "gta3_re" game folder usually where this plugin run. -"GTA_III_DIR" * path to "GTAIII" game folder. -"LIBRW" * path to LIBRW. -``` -- cgit v1.2.3 From 24f74a775f0c3d0fa56a51dc9767b68d66a221e7 Mon Sep 17 00:00:00 2001 From: erorcun Date: Tue, 12 May 2020 03:41:41 +0300 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a4c8ea2..3dcc9f58 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ such that we have a working game at all times. - (Optional) If you want to use optional features like Russian language or menu map, copy the files in /gamefiles folder to your game root folder. - Move re3.exe to GTA 3 directory and run it. -## How can I build it? +## Preparing the environment for building Currently only building on VS2015/2017/2019 (Windows) and GCC (Linux) is tested. -- cgit v1.2.3 From 8f1a2825d4126f87ec695132dc6ee080a652a1fa Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Tue, 12 May 2020 04:31:11 +0300 Subject: Remove odd calculations for bullet hit smoke --- src/weapons/Weapon.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index aef53094..e40deb61 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -997,9 +997,13 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim, for ( int32 i = 0; i < 16; i++ ) CParticle::AddParticle(PARTICLE_SPARK, point->point, point->normal*0.05f); - CVector dist = point->point - (*source); - CVector offset = dist - Max(0.2f*dist.Magnitude(), 2.0f) * CVector(ahead.x, ahead.y, 0.0f); - CVector smokePos = *source + offset; +#ifndef FIX_BUGS + CVector dist = point->point - (*source); + CVector offset = dist - Max(0.2f * dist.Magnitude(), 2.0f) * CVector(ahead.x, ahead.y, 0.0f); + CVector smokePos = *source + offset; +#else + CVector smokePos = point->point; +#endif // !FIX_BUGS smokePos.x += CGeneral::GetRandomNumberInRange(-0.2f, 0.2f); smokePos.y += CGeneral::GetRandomNumberInRange(-0.2f, 0.2f); @@ -1016,9 +1020,13 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim, for ( int32 i = 0; i < 16; i++ ) CParticle::AddParticle(PARTICLE_SPARK, point->point, point->normal*0.05f); +#ifndef FIX_BUGS CVector dist = point->point - (*source); CVector offset = dist - Max(0.2f*dist.Magnitude(), 0.5f) * CVector(ahead.x, ahead.y, 0.0f); - CVector smokePos = *source + offset; + CVector smokePos = *source + offset; +#else + CVector smokePos = point->point; +#endif // !FIX_BUGS CParticle::AddParticle(PARTICLE_BULLETHIT_SMOKE, smokePos, CVector(0.0f, 0.0f, 0.0f)); @@ -1265,9 +1273,13 @@ CWeapon::FireShotgun(CEntity *shooter, CVector *fireSource) for ( int32 i = 0; i < 16; i++ ) CParticle::AddParticle(PARTICLE_SPARK, point.point, point.normal*0.05f); +#ifndef FIX_BUGS CVector dist = point.point - (*fireSource); CVector offset = dist - Max(0.2f*dist.Magnitude(), 2.0f) * CVector(shootRot.x, shootRot.y, 0.0f); CVector smokePos = *fireSource + offset; +#else + CVector smokePos = point.point; +#endif CParticle::AddParticle(PARTICLE_BULLETHIT_SMOKE, smokePos, CVector(0.0f, 0.0f, 0.0f)); @@ -1280,9 +1292,13 @@ CWeapon::FireShotgun(CEntity *shooter, CVector *fireSource) for ( int32 i = 0; i < 16; i++ ) CParticle::AddParticle(PARTICLE_SPARK, point.point, point.normal*0.05f); +#ifndef FIX_BUGS CVector dist = point.point - (*fireSource); CVector offset = dist - Max(0.2f*dist.Magnitude(), 2.0f) * CVector(shootRot.x, shootRot.y, 0.0f); - CVector smokePos = *fireSource + offset; + CVector smokePos = *fireSource + offset; +#else + CVector smokePos = point.point; +#endif smokePos.x += CGeneral::GetRandomNumberInRange(-0.2f, 0.2f); smokePos.y += CGeneral::GetRandomNumberInRange(-0.2f, 0.2f); -- cgit v1.2.3 From 12b1eedcbf9de271c3210a98ed0d9af2d2126a30 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Tue, 12 May 2020 04:36:10 +0300 Subject: Include oal files --- premake5.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/premake5.lua b/premake5.lua index f34e9d63..4a6cc680 100644 --- a/premake5.lua +++ b/premake5.lua @@ -123,8 +123,7 @@ project "re3" files { addSrcFiles("src") } files { addSrcFiles("src/animation") } files { addSrcFiles("src/audio") } - --files { addSrcFiles("src/audio/miles") } - --files { addSrcFiles("src/audio/oal") } + files { addSrcFiles("src/audio/oal") } files { addSrcFiles("src/control") } files { addSrcFiles("src/core") } files { addSrcFiles("src/entities") } @@ -146,7 +145,7 @@ project "re3" includedirs { "src" } includedirs { "src/animation" } includedirs { "src/audio" } - --includedirs { "src/audio/oal" } + includedirs { "src/audio/oal" } includedirs { "src/control" } includedirs { "src/core" } includedirs { "src/entities" } @@ -185,8 +184,6 @@ project "re3" targetextension ".elf" defines { "OPENAL" } links { "openal", "mpg123", "sndfile", "pthread" } - files { addSrcFiles("src/audio/oal") } - includedirs { "src/audio/oal" } filter "platforms:*RW33*" staticruntime "on" -- cgit v1.2.3 From d5676be83eb64ddc88dddd4a54ebda399fd07c5e Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Tue, 12 May 2020 04:41:17 +0300 Subject: Fix premake copy --- premake5.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/premake5.lua b/premake5.lua index 4a6cc680..64b12d3a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -86,7 +86,7 @@ workspace "re3" scriptspath = scriptspath or "" if (gamepath) then postbuildcommands { - "{COPY} %{cfg.buildtarget.abspath} " .. gamepath .. scriptspath .. "%{cfg.buildtarget.name}" + '{COPY} "%{cfg.buildtarget.abspath}" "' .. gamepath .. scriptspath .. '%{cfg.buildtarget.name}"' } debugdir (gamepath) if (exepath) then -- cgit v1.2.3 From fab453efdeb9acc304c7c84d3ebc9fed0629fa47 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 12 May 2020 09:44:50 +0200 Subject: fixed bug in cutscene head --- src/objects/CutsceneHead.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/objects/CutsceneHead.cpp b/src/objects/CutsceneHead.cpp index 0938960e..55e75807 100644 --- a/src/objects/CutsceneHead.cpp +++ b/src/objects/CutsceneHead.cpp @@ -105,8 +105,11 @@ CCutsceneHead::Render(void) m_matrix.SetRotateY(PI/2); m_matrix = CMatrix(mat) * m_matrix; } + // This is head...it has no limbs +#ifndef FIX_BUGS RenderLimb(BONE_Lhand); RenderLimb(BONE_Rhand); +#endif }else #endif { @@ -127,11 +130,15 @@ CCutsceneHead::Render(void) void CCutsceneHead::RenderLimb(int32 bone) { + // It's not clear what this is... + // modelinfo for this object is not a ped so it also doesn't have any limbs +#ifndef FIX_BUGS RpAtomic *atomic; RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(m_parentObject->GetClump()); int idx = RpHAnimIDGetIndex(hier, bone); RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier); - CPedModelInfo *mi = (CPedModelInfo *)CModelInfo::GetModelInfo(GetModelIndex()); + CPedModelInfo *mi = (CPedModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + assert(mi->GetModelType() == MITYPE_PED); switch(bone){ case BONE_Lhand: atomic = mi->getLeftHand(); @@ -148,6 +155,7 @@ CCutsceneHead::RenderLimb(int32 bone) RwFrameUpdateObjects(frame); RpAtomicRender(atomic); } +#endif } #endif -- cgit v1.2.3 From 1afe36d0d0f17c3f58738510ea8c7564b7ff0a2c Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Tue, 12 May 2020 14:07:47 +0300 Subject: fix garages --- src/control/Garages.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index b6786598..a5e16c6b 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -1471,7 +1471,7 @@ void CGarage::UpdateDoorsHeight() void CGarage::BuildRotatedDoorMatrix(CEntity * pDoor, float fPosition) { float fAngle = -fPosition * HALFPI; - CVector up(-Sin(fAngle) * pDoor->GetForward().y, Sin(fAngle) * pDoor->GetForward().z, Cos(fAngle)); + CVector up(-Sin(fAngle) * pDoor->GetForward().y, Sin(fAngle) * pDoor->GetForward().x, Cos(fAngle)); pDoor->GetRight() = CrossProduct(up, pDoor->GetForward()); pDoor->GetUp() = up; } -- cgit v1.2.3 From 98a233da43acfa1bd1144d5b0236783beef30785 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 12 May 2020 16:27:12 +0200 Subject: little fixes to CClouds; disabled object clipping for SA cam --- src/core/Cam.cpp | 4 ++-- src/core/main.cpp | 3 +++ src/render/Clouds.cpp | 11 +++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index 21569647..8cd44f6f 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -5099,7 +5099,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, CColPoint foundCol; CEntity* foundEnt; CWorld::pIgnoreEntity = CamTargetEntity; - if (CWorld::ProcessLineOfSight(TargetCoors, Source, foundCol, foundEnt, true, dontCollideWithCars < 0.1f, false, true, false, true, false)) { + if (CWorld::ProcessLineOfSight(TargetCoors, Source, foundCol, foundEnt, true, dontCollideWithCars < 0.1f, false, false, false, true, false)) { float obstacleTargetDist = (TargetCoors - foundCol.point).Magnitude(); float obstacleCamDist = newDistance - obstacleTargetDist; if (!foundEnt->IsPed() || obstacleCamDist <= 1.0f) { @@ -5108,7 +5108,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, RwCameraSetNearClipPlane(Scene.camera, Max(0.05f, obstacleTargetDist - 0.3f)); } } else { - if (!CWorld::ProcessLineOfSight(foundCol.point, Source, foundCol, foundEnt, true, dontCollideWithCars < 0.1f, false, true, false, true, false)) { + if (!CWorld::ProcessLineOfSight(foundCol.point, Source, foundCol, foundEnt, true, dontCollideWithCars < 0.1f, false, false, false, true, false)) { float lessClip = obstacleCamDist - 0.35f; if (lessClip <= DEFAULT_NEAR) RwCameraSetNearClipPlane(Scene.camera, lessClip); diff --git a/src/core/main.cpp b/src/core/main.cpp index d6af0b2a..bcd6202e 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -263,6 +263,9 @@ DoFade(void) void DoRWStuffEndOfFrame(void) { +char buf[100]; +sprintf(buf, "timestep: %f %f", CTimer::GetTimeStep(), CTimer::GetTimeStepInMilliseconds()); +CDebug::PrintAt(buf, 10, 10); CDebug::DisplayScreenStrings(); // custom CDebug::DebugDisplayTextBuffer(); FlushObrsPrintfs(); diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp index 07688491..9c0fde0f 100644 --- a/src/render/Clouds.cpp +++ b/src/render/Clouds.cpp @@ -93,7 +93,7 @@ CClouds::Render(void) int minute = CClock::GetHours()*60 + CClock::GetMinutes(); RwV3d campos = *(RwV3d*)&TheCamera.GetPosition(); - float coverage = CWeather::CloudCoverage <= CWeather::Foggyness ? CWeather::Foggyness : CWeather::CloudCoverage; + float coverage = Max(CWeather::Foggyness, CWeather::Foggyness); // Moon int moonfadeout = Abs(minute - 180); // fully visible at 3AM @@ -308,20 +308,19 @@ CClouds::Render(void) bool UseDarkBackground(void) { - return RwFrameGetLTM(RwCameraGetFrame(TheCamera.m_pRwCamera))->up.z < -0.9f || - gbShowCollisionPolys; + return TheCamera.GetForward().z < -0.9f || gbShowCollisionPolys; } void CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, int16 botred, int16 botgreen, int16 botblue, int16 alpha) { - RwMatrix *mat = RwFrameGetLTM(RwCameraGetFrame(TheCamera.m_pRwCamera)); - float c = Sqrt(mat->right.x * mat->right.x + mat->right.y * mat->right.y); + CVector left = TheCamera.GetRight(); + float c = left.Magnitude2D(); if(c > 1.0f) c = 1.0f; ms_cameraRoll = Acos(c); - if(mat->right.z < 0.0f) + if(left.z < 0.0f) ms_cameraRoll = -ms_cameraRoll; if(UseDarkBackground()){ -- cgit v1.2.3 From 615bd1e87856c1abbf541e595742bf6cce7d4a5b Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Tue, 12 May 2020 20:22:35 +0300 Subject: garages fix --- src/control/Garages.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index a5e16c6b..d8fd3ec0 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -1509,7 +1509,7 @@ static bool DoINeedToRefreshPointer(CEntity * pDoor, bool bIsDummy, int8 nIndex) if (bIsDummy) { if (CPools::GetDummyPool()->IsFreeSlot(CPools::GetDummyPool()->GetJustIndex((CDummy*)pDoor))) return true; - if (nIndex != CPools::GetDummyPool()->GetIndex((CDummy*)pDoor)) + if (nIndex != (CPools::GetDummyPool()->GetIndex((CDummy*)pDoor) & 0x7F)) bNeedToFindDoorEntities = true; if (!CGarages::IsModelIndexADoor(pDoor->GetModelIndex())) return true; @@ -1517,7 +1517,7 @@ static bool DoINeedToRefreshPointer(CEntity * pDoor, bool bIsDummy, int8 nIndex) else { if (CPools::GetObjectPool()->IsFreeSlot(CPools::GetObjectPool()->GetJustIndex((CObject*)pDoor))) return true; - if (nIndex != CPools::GetObjectPool()->GetIndex((CObject*)pDoor)) + if (nIndex != (CPools::GetObjectPool()->GetIndex((CObject*)pDoor) & 0x7F)) bNeedToFindDoorEntities = true; if (!CGarages::IsModelIndexADoor(pDoor->GetModelIndex())) return true; -- cgit v1.2.3 From bcd2f8c64cd85ad08076c4312a74f393242586fc Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 12 May 2020 20:44:37 +0200 Subject: remove debug shit --- src/core/main.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/core/main.cpp b/src/core/main.cpp index bcd6202e..d6af0b2a 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -263,9 +263,6 @@ DoFade(void) void DoRWStuffEndOfFrame(void) { -char buf[100]; -sprintf(buf, "timestep: %f %f", CTimer::GetTimeStep(), CTimer::GetTimeStepInMilliseconds()); -CDebug::PrintAt(buf, 10, 10); CDebug::DisplayScreenStrings(); // custom CDebug::DebugDisplayTextBuffer(); FlushObrsPrintfs(); -- cgit v1.2.3 From c40fcdf39ab77cb0fde26e314652e0aaf9dd4544 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Tue, 12 May 2020 22:48:28 +0300 Subject: fix shotgun --- src/weapons/Weapon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index e40deb61..3ac769d7 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -1238,7 +1238,7 @@ CWeapon::FireShotgun(CEntity *shooter, CVector *fireSource) if ( cantStandup ) victimPed->SetFall(1500, AnimationId(ANIM_KO_SKID_FRONT + localDir), false); - victimPed->InflictDamage(nil, m_eWeaponType, info->m_nDamage, (ePedPieceTypes)point.pieceB, localDir); + victimPed->InflictDamage(shooter, m_eWeaponType, info->m_nDamage, (ePedPieceTypes)point.pieceB, localDir); if ( victimPed->m_nPedType == PEDTYPE_COP ) CEventList::RegisterEvent(EVENT_SHOOT_COP, EVENT_ENTITY_PED, victim, (CPed*)shooter, 10000); -- cgit v1.2.3 From c2ac6b3759901ecede7b22c1e9ab9f5a04ddd527 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 12 May 2020 01:24:57 +0200 Subject: Fix linux warnings --- src/animation/AnimBlendAssociation.h | 5 ++++- src/animation/FrameUpdate.cpp | 6 ++++-- src/audio/oal/aldlist.cpp | 4 ++-- src/audio/oal/aldlist.h | 4 ++-- src/control/CarAI.cpp | 1 + src/control/CarCtrl.cpp | 1 + src/control/Garages.cpp | 7 +++++++ src/control/Pickups.cpp | 2 ++ src/control/SceneEdit.cpp | 4 ++-- src/control/Script.cpp | 2 ++ src/core/AnimViewer.cpp | 4 ++-- src/core/Cam.cpp | 2 +- src/core/Camera.cpp | 16 +++++++++++++--- src/core/Camera.h | 3 ++- src/core/Collision.cpp | 2 +- src/core/ControllerConfig.cpp | 16 +++++++++++++++- src/core/FileLoader.cpp | 4 ++-- src/core/Frontend.cpp | 3 ++- src/core/Frontend.h | 2 +- src/core/Pad.cpp | 4 ++-- src/core/Pools.cpp | 4 ++++ src/core/Profile.cpp | 4 ++-- src/core/Profile.h | 4 ++-- src/core/Streaming.cpp | 4 +++- src/core/SurfaceTable.cpp | 2 +- src/core/SurfaceTable.h | 2 +- src/core/World.cpp | 1 + src/core/Zones.cpp | 2 +- src/core/Zones.h | 2 +- src/core/main.cpp | 10 +++++----- src/core/main.h | 4 ++-- src/modelinfo/PedModelInfo.cpp | 2 +- src/objects/ParticleObject.cpp | 10 +++++++++- src/peds/EmergencyPed.cpp | 2 ++ src/peds/Ped.cpp | 18 +++++++++++------- src/render/Particle.cpp | 3 +++ src/render/Renderer.cpp | 5 ++++- src/render/WaterLevel.cpp | 2 +- src/render/WaterLevel.h | 2 +- src/rw/VisibilityPlugins.cpp | 15 +++++++++------ src/save/GenericGameStorage.cpp | 2 +- src/skel/glfw/glfw.cpp | 2 +- src/vehicles/Automobile.cpp | 9 ++++++++- src/vehicles/Boat.cpp | 1 + src/vehicles/DamageManager.cpp | 1 + src/vehicles/Heli.cpp | 4 ++-- src/vehicles/Train.cpp | 2 +- src/vehicles/Train.h | 2 +- src/weapons/BulletInfo.cpp | 1 + src/weapons/ProjectileInfo.cpp | 3 +++ src/weapons/Weapon.cpp | 8 ++++++++ src/weapons/WeaponInfo.cpp | 10 +++++----- 52 files changed, 165 insertions(+), 70 deletions(-) diff --git a/src/animation/AnimBlendAssociation.h b/src/animation/AnimBlendAssociation.h index d0c60a88..2dff4391 100644 --- a/src/animation/AnimBlendAssociation.h +++ b/src/animation/AnimBlendAssociation.h @@ -62,7 +62,10 @@ public: CAnimBlendAssociation(void); CAnimBlendAssociation(CAnimBlendAssociation &other); - virtual ~CAnimBlendAssociation(void); +#ifndef FIX_BUGS + virtual +#endif + ~CAnimBlendAssociation(void); void AllocateAnimBlendNodeArray(int n); void FreeAnimBlendNodeArray(void); void Init(RpClump *clump, CAnimBlendHierarchy *hier); diff --git a/src/animation/FrameUpdate.cpp b/src/animation/FrameUpdate.cpp index 8697e7c6..a3a2013a 100644 --- a/src/animation/FrameUpdate.cpp +++ b/src/animation/FrameUpdate.cpp @@ -147,11 +147,12 @@ FrameUpdateCallBackWithVelocityExtractionNonSkinned(AnimBlendFrameData *frame, v mat->pos.x = pos.x - transx; mat->pos.y = pos.y - transy; mat->pos.z = pos.z; - if(mat->pos.z >= -0.8f) + if(mat->pos.z >= -0.8f) { if(mat->pos.z < -0.4f) mat->pos.z += (2.5f * mat->pos.z + 2.0f) * frame->resetPos.z; else mat->pos.z += frame->resetPos.z; + } mat->pos.x += frame->resetPos.x; mat->pos.y += frame->resetPos.y; } @@ -361,11 +362,12 @@ FrameUpdateCallBackWithVelocityExtractionSkinned(AnimBlendFrameData *frame, void xform->t.x = pos.x - transx; xform->t.y = pos.y - transy; xform->t.z = pos.z; - if(xform->t.z >= -0.8f) + if(xform->t.z >= -0.8f) { if(xform->t.z < -0.4f) xform->t.z += (2.5f * xform->t.z + 2.0f) * frame->resetPos.z; else xform->t.z += frame->resetPos.z; + } xform->t.x += frame->resetPos.x; xform->t.y += frame->resetPos.y; } diff --git a/src/audio/oal/aldlist.cpp b/src/audio/oal/aldlist.cpp index 768ace30..458b7c80 100644 --- a/src/audio/oal/aldlist.cpp +++ b/src/audio/oal/aldlist.cpp @@ -53,7 +53,7 @@ ALDeviceList::ALDeviceList() index = 0; // go through device list (each device terminated with a single NULL, list terminated with double NULL) - while (*devices != NULL) { + while (*devices != '\0') { if (strcmp(defaultDeviceName, devices) == 0) { defaultDeviceIndex = index; } @@ -186,7 +186,7 @@ unsigned int ALDeviceList::GetMaxNumSources(int index) /* * Checks if the extension is supported on the given device */ -bool ALDeviceList::IsExtensionSupported(int index, char *szExtName) +bool ALDeviceList::IsExtensionSupported(int index, const char *szExtName) { bool bReturn = false; diff --git a/src/audio/oal/aldlist.h b/src/audio/oal/aldlist.h index b8f1b31a..694c9d01 100644 --- a/src/audio/oal/aldlist.h +++ b/src/audio/oal/aldlist.h @@ -32,7 +32,7 @@ public: char *GetDeviceName(int index); void GetDeviceVersion(int index, int *major, int *minor); unsigned int GetMaxNumSources(int index); - bool IsExtensionSupported(int index, char *szExtName); + bool IsExtensionSupported(int index, const char *szExtName); int GetDefaultDevice(); void FilterDevicesMinVer(int major, int minor); void FilterDevicesMaxVer(int major, int minor); @@ -46,4 +46,4 @@ private: }; #endif -#endif // ALDEVICELIST_H \ No newline at end of file +#endif // ALDEVICELIST_H diff --git a/src/control/CarAI.cpp b/src/control/CarAI.cpp index 3e22ee77..b3fc85ae 100644 --- a/src/control/CarAI.cpp +++ b/src/control/CarAI.cpp @@ -431,6 +431,7 @@ void CCarAI::UpdateCarAI(CVehicle* pVehicle) } } break; + default: break; } } if (pVehicle->pDriver && pVehicle->pDriver->m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS){ diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index fcd1e83f..d6ccc8bb 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -2307,6 +2307,7 @@ void CCarCtrl::SteerAICarWithPhysicsFollowPath(CVehicle* pVehicle, float* pSwerv *pBrake = 0.0f; *pHandbrake = false; return; + default: break; } } pCurrentLink = &ThePaths.m_carPathLinks[pVehicle->AutoPilot.m_nCurrentPathNodeInfo]; diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index d8fd3ec0..5fc44974 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -517,6 +517,7 @@ void CGarage::Update() case GARAGE_BOMBSHOP1: DMAudio.PlayFrontEndSound(SOUND_GARAGE_BOMB1_SET, 1); break; case GARAGE_BOMBSHOP2: DMAudio.PlayFrontEndSound(SOUND_GARAGE_BOMB2_SET, 1); break; case GARAGE_BOMBSHOP3: DMAudio.PlayFrontEndSound(SOUND_GARAGE_BOMB3_SET, 1); break; + default: break; } m_eGarageState = GS_OPENING; if (!CGarages::BombsAreFree) @@ -561,6 +562,7 @@ void CGarage::Update() case GARAGE_BOMBSHOP3: CHud::SetHelpMessage(TheText.Get("GA_8"), false); // Use the detonator to activate the bomb. break; + default: break; } CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_GARAGE); FindPlayerPed()->m_pWanted->m_bIgnoredByCops = false; @@ -1065,6 +1067,7 @@ void CGarage::Update() case GARAGE_HIDEOUT_ONE: StoreAndRemoveCarsForThisHideout(CGarages::aCarsInSafeHouse1, MAX_STORED_CARS_IN_INDUSTRIAL); break; case GARAGE_HIDEOUT_TWO: StoreAndRemoveCarsForThisHideout(CGarages::aCarsInSafeHouse2, MAX_STORED_CARS_IN_COMMERCIAL); break; case GARAGE_HIDEOUT_THREE: StoreAndRemoveCarsForThisHideout(CGarages::aCarsInSafeHouse3, MAX_STORED_CARS_IN_SUBURBAN); break; + default: break; } } UpdateDoorsHeight(); @@ -1093,6 +1096,7 @@ void CGarage::Update() case GARAGE_HIDEOUT_ONE: bCreatedAllCars = RestoreCarsForThisHideout(CGarages::aCarsInSafeHouse1); break; case GARAGE_HIDEOUT_TWO: bCreatedAllCars = RestoreCarsForThisHideout(CGarages::aCarsInSafeHouse2); break; case GARAGE_HIDEOUT_THREE: bCreatedAllCars = RestoreCarsForThisHideout(CGarages::aCarsInSafeHouse3); break; + default: break; } if (bCreatedAllCars) m_eGarageState = GS_OPENING; @@ -2151,6 +2155,7 @@ int32 CGarages::CountCarsInHideoutGarage(eGarageType type) case GARAGE_HIDEOUT_THREE: total += (aCarsInSafeHouse3[i].HasCar()); break; + default: break; } } return total; @@ -2165,6 +2170,7 @@ int32 CGarages::FindMaxNumStoredCarsForGarage(eGarageType type) return LIMIT_CARS_IN_COMMERCIAL; case GARAGE_HIDEOUT_THREE: return LIMIT_CARS_IN_SUBURBAN; + default: break; } return 0; } @@ -2180,6 +2186,7 @@ bool CGarages::IsPointWithinHideOutGarage(Const CVector& point) point.y > aGarages[i].m_fY1 && point.y < aGarages[i].m_fY2 && point.z > aGarages[i].m_fZ1 && point.z < aGarages[i].m_fZ2) return true; + default: break; } } return false; diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 569af776..32bffa17 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -356,6 +356,7 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) return true; } break; + default: break; } } if (!m_bRemoved && (m_eType == PICKUP_ONCE_TIMEOUT || m_eType == PICKUP_MONEY) && CTimer::GetTimeInMilliseconds() > m_nTimer) @@ -576,6 +577,7 @@ CPickups::ModelForWeapon(eWeaponType weaponType) case WEAPONTYPE_FLAMETHROWER: return MI_FLAMETHROWER; case WEAPONTYPE_MOLOTOV: return MI_MOLOTOV; case WEAPONTYPE_GRENADE: return MI_GRENADE; + default: break; } return 0; } diff --git a/src/control/SceneEdit.cpp b/src/control/SceneEdit.cpp index 6aa64a3c..be8c5519 100644 --- a/src/control/SceneEdit.cpp +++ b/src/control/SceneEdit.cpp @@ -303,7 +303,7 @@ void CSceneEdit::Draw(void) nCommandDrawn -= (MOVIE_TOTAL_COMMANDS - 1); if (nCommandDrawn <= MOVIE_DO_NOTHING) nCommandDrawn += (MOVIE_TOTAL_COMMANDS - 1); - sprintf(str, pCommandStrings[nCommandDrawn]); + sprintf(str, "%s", pCommandStrings[nCommandDrawn]); AsciiToUnicode(str, wstr); CFont::SetColor(CRGBA(0, 0, 0, 0)); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(COMMAND_NAME_X_RIGHT - SHADOW_OFFSET), SCREEN_SCALE_Y(COMMAND_NAME_Y + SHADOW_OFFSET + i * COMMAND_NAME_HEIGHT), wstr); @@ -1095,4 +1095,4 @@ bool CSceneEdit::SelectWeapon(void) return false; } return false; -} \ No newline at end of file +} diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 30793f55..13000847 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -11305,6 +11305,7 @@ INITSAVEBUF case ENTITY_TYPE_DUMMY: type = 4; handle = CPools::GetDummyPool()->GetJustIndex((CDummy*)pEntity) + 1; + default: break; } } WriteSaveBuf(buf, type); @@ -11462,6 +11463,7 @@ void CTheScripts::ClearSpaceForMissionEntity(const CVector& pos, CEntity* pEntit printf("Deleted a ped where a mission entity should be\n"); break; } + default: break; } } } diff --git a/src/core/AnimViewer.cpp b/src/core/AnimViewer.cpp index 40a8b09e..f49f811f 100644 --- a/src/core/AnimViewer.cpp +++ b/src/core/AnimViewer.cpp @@ -120,7 +120,7 @@ CAnimViewer::Initialise(void) { if (!CFileMgr::ReadLine(fd, gString, 255)) break; - sscanf(gString, "%s %s", &modelName, &animGroup); + sscanf(gString, "%s %s", modelName, animGroup); int groupId; for (groupId = 0; groupId < NUM_ANIM_ASSOC_GROUPS; groupId++) { if (!strcmp(animGroup, CAnimManager::GetAnimGroupName((AssocGroupId)groupId))) @@ -429,4 +429,4 @@ CAnimViewer::Shutdown(void) CTimer::Shutdown(); CStreaming::Shutdown(); CTxdStore::RemoveTxdSlot(animTxdSlot); -} \ No newline at end of file +} diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index 8cd44f6f..6c79604c 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -885,7 +885,7 @@ CCam::PrintMode(void) sprintf(buf, " "); sprintf(buf, " "); - static char *modes[] = { "None", + static Const char *modes[] = { "None", "Top Down", "GTA Classic", "Behind Car", "Follow Ped", "Aiming", "Debug", "Sniper", "Rocket", "Model Viewer", "Bill", "Syphon", "Circle", "Cheesy Zoom", "Wheel", "Fixed", diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 9b178f35..35d230dc 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -80,6 +80,10 @@ CCamera::CCamera(void) Init(); } +CCamera::CCamera(float) +{ +} + void CCamera::Init(void) { @@ -87,7 +91,12 @@ CCamera::Init(void) float fMouseAccelHorzntl = m_fMouseAccelHorzntl; float fMouseAccelVertical = m_fMouseAccelVertical; #endif +#ifdef FIX_BUGS + static const CCamera DummyCamera = CCamera(0.f); + *this = DummyCamera; +#else memset(this, 0, sizeof(CCamera)); // getting rid of vtable, eh? +#endif #ifdef GTA3_1_1_PATCH m_fMouseAccelHorzntl = fMouseAccelHorzntl; m_fMouseAccelVertical = fMouseAccelVertical; @@ -740,6 +749,7 @@ CCamera::CamControl(void) case VEHICLE_TYPE_BOAT: ReqMode = CCam::MODE_BEHINDBOAT; break; + default: break; } // Car zoom value @@ -2992,7 +3002,7 @@ CCamera::SetZoomValueFollowPedScript(int16 dist) case 0: m_fPedZoomValueScript = 0.25f; break; case 1: m_fPedZoomValueScript = 1.5f; break; case 2: m_fPedZoomValueScript = 2.9f; break; - default: m_fPedZoomValueScript = m_fPedZoomValueScript; break; + default: break; } m_bUseScriptZoomValuePed = true; @@ -3007,7 +3017,7 @@ CCamera::SetZoomValueCamStringScript(int16 dist) case 0: m_fCarZoomValueScript = ((CVehicle*)Cams[ActiveCam].CamTargetEntity)->IsBoat() ? FREE_BOAT_ZOOM_VALUE_1 : FREE_CAR_ZOOM_VALUE_1; break; case 1: m_fCarZoomValueScript = ((CVehicle*)Cams[ActiveCam].CamTargetEntity)->IsBoat() ? FREE_BOAT_ZOOM_VALUE_2 : FREE_CAR_ZOOM_VALUE_2; break; case 2: m_fCarZoomValueScript = ((CVehicle*)Cams[ActiveCam].CamTargetEntity)->IsBoat() ? FREE_BOAT_ZOOM_VALUE_3 : FREE_CAR_ZOOM_VALUE_3; break; - default: m_fCarZoomValueScript = m_fCarZoomValueScript; break; + default: break; } } else #endif @@ -3016,7 +3026,7 @@ CCamera::SetZoomValueCamStringScript(int16 dist) case 0: m_fCarZoomValueScript = DEFAULT_CAR_ZOOM_VALUE_1; break; case 1: m_fCarZoomValueScript = DEFAULT_CAR_ZOOM_VALUE_2; break; case 2: m_fCarZoomValueScript = DEFAULT_CAR_ZOOM_VALUE_3; break; - default: m_fCarZoomValueScript = m_fCarZoomValueScript; break; + default: break; } } diff --git a/src/core/Camera.h b/src/core/Camera.h index 94bcbd23..80fc878e 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -403,7 +403,7 @@ public: int m_BlurRed; int m_BlurType; -uint32 unknown; // some counter having to do with music + uint32 unknown; // some counter having to do with music int m_iWorkOutSpeedThisNumFrames; int m_iNumFramesSoFar; @@ -549,6 +549,7 @@ uint32 unknown; // some counter having to do with music // High level and misc CCamera(void); + CCamera(float); void Init(void); void Process(void); void CamControl(void); diff --git a/src/core/Collision.cpp b/src/core/Collision.cpp index 0cdacfdb..01cc323a 100644 --- a/src/core/Collision.cpp +++ b/src/core/Collision.cpp @@ -231,7 +231,7 @@ CCollision::SortOutCollisionAfterLoad(void) void CCollision::LoadCollisionScreen(eLevelName level) { - static char *levelNames[4] = { + static Const char *levelNames[4] = { "", "IND_ZON", "COM_ZON", diff --git a/src/core/ControllerConfig.cpp b/src/core/ControllerConfig.cpp index dcd9f125..6a5080e5 100644 --- a/src/core/ControllerConfig.cpp +++ b/src/core/ControllerConfig.cpp @@ -610,6 +610,7 @@ void CControllerConfigManager::AffectControllerStateOn_ButtonDown(int32 button, case MOUSE: state = &CPad::GetPad(PAD1)->PCTempMouseState; break; + default: break; } if (pad != NULL) @@ -1024,7 +1025,7 @@ void CControllerConfigManager::AffectControllerStateOn_ButtonUp(int32 button, eC case JOYSTICK: state = &CPad::GetPad(PAD1)->PCTempJoyState; break; - + default: break; } if (process) @@ -1293,6 +1294,7 @@ bool CControllerConfigManager::GetIsKeyboardKeyDown(RsKeyCodes keycode) if (CPad::GetPad(PAD1)->GetApps()) return true; break; + default: break; } return false; @@ -1493,6 +1495,7 @@ bool CControllerConfigManager::GetIsKeyboardKeyJustDown(RsKeyCodes keycode) if (CPad::GetPad(PAD1)->GetAppsJustDown()) return true; break; + default: break; } return false; @@ -1530,6 +1533,7 @@ bool CControllerConfigManager::GetIsMouseButtonDown(RsKeyCodes keycode) if (CPad::GetPad(PAD1)->GetMouseX2()) return true; break; + default: break; } return false; @@ -1567,6 +1571,7 @@ bool CControllerConfigManager::GetIsMouseButtonUp(RsKeyCodes keycode) if (CPad::GetPad(PAD1)->GetMouseX2Up()) return true; break; + default: break; } return false; @@ -1747,6 +1752,7 @@ void CControllerConfigManager::DeleteMatchingActionInitiators(e_ControllerAction DeleteMatchingCommonControls (action, key, type); DeleteMatching1rst3rdPersonControls (action, key, type); break; + default: break; } } } @@ -1770,6 +1776,7 @@ bool CControllerConfigManager::GetIsKeyBlank(int32 key, eControllerType type) if (key != 0) return false; break; + default: break; } return true; @@ -1836,6 +1843,7 @@ e_ControllerActionType CControllerConfigManager::GetActionType(e_ControllerActio case PED_SNIPER_ZOOM_OUT: return ACTIONTYPE_1RSTPERSON; break; + default: break; } return ACTIONTYPE_NONE; @@ -1861,6 +1869,7 @@ void CControllerConfigManager::ClearSettingsAssociatedWithAction(e_ControllerAct m_aSettings[action][type].m_Key = 0; m_aSettings[action][type].m_ContSetOrder = SETORDER_NONE; break; + default: break; } ResetSettingOrder(action); @@ -1881,6 +1890,7 @@ wchar *CControllerConfigManager::GetControllerSettingTextWithOrderNumber(e_Contr return GetControllerSettingTextMouse (action); case JOYSTICK: return GetControllerSettingTextJoystick(action); + default: break; } } } @@ -2224,6 +2234,7 @@ wchar *CControllerConfigManager::GetControllerSettingTextKeyBoard(e_ControllerAc return TheText.Get("FEC_SFT"); // "SHIFT" break; } + default: break; } } } @@ -2256,6 +2267,7 @@ wchar *CControllerConfigManager::GetControllerSettingTextMouse(e_ControllerActio case 7: return TheText.Get("FEC_MXT"); // MXB2 break; + default: break; } return NULL; @@ -2375,6 +2387,7 @@ bool CControllerConfigManager::GetIsActionAButtonCombo(e_ControllerAction action case PED_CYCLE_TARGET_RIGHT: return true; break; + default: break; } return false; @@ -2395,6 +2408,7 @@ wchar *CControllerConfigManager::GetButtonComboText(e_ControllerAction action) case VEHICLE_LOOKBEHIND: return TheText.Get("FEC_LBC"); // Use Look Left With Look Right. break; + default: break; } return NULL; diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index 88afb40c..6e7188c5 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -753,7 +753,7 @@ CFileLoader::LoadClumpObject(const char *line) char model[24], txd[24]; CClumpModelInfo *mi; - if(sscanf(line, "%d %s %s", &id, &model, &txd) == 3){ + if(sscanf(line, "%d %s %s", &id, model, txd) == 3){ mi = CModelInfo::AddClumpModel(id); mi->SetName(model); mi->SetTexDictionary(txd); @@ -1184,7 +1184,7 @@ CFileLoader::LoadMapZones(const char *filename) float minx, miny, minz; float maxx, maxy, maxz; if(sscanf(line, "%s %d %f %f %f %f %f %f %d", - &name, &type, + name, &type, &minx, &miny, &minz, &maxx, &maxy, &maxz, &level) == 9) diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index f0d75d12..d58d0576 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -412,7 +412,7 @@ CMenuManager::ThingsToDoBeforeLeavingPage() // ------ Functions not in the game/inlined ends void -CMenuManager::BuildStatLine(char *text, void *stat, bool itsFloat, void *stat2) +CMenuManager::BuildStatLine(Const char *text, void *stat, bool itsFloat, void *stat2) { if (!text) return; @@ -5020,6 +5020,7 @@ CMenuManager::SaveLoadFileError_SetUpErrorScreen() case SAVESTATUS_DELETEFAILED10: ChangeScreen(MENUPAGE_DELETE_FAILED, 0, true, false); break; + default: break; } } diff --git a/src/core/Frontend.h b/src/core/Frontend.h index 65c4e178..89517528 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -598,7 +598,7 @@ public: #endif public: - static void BuildStatLine(char *text, void *stat, bool itsFloat, void *stat2); + static void BuildStatLine(Const char *text, void *stat, bool itsFloat, void *stat2); static void CentreMousePointer(); void CheckCodesForControls(int); bool CheckHover(int x1, int x2, int y1, int y2); diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index da86d15e..924d4724 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -509,7 +509,7 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp() double xpos = 1.0f, ypos; glfwGetCursorPos(PSGLOBAL(window), &xpos, &ypos); - if (xpos != NULL) { + if (xpos != 0.f) { state.MMB = true; state.RMB = true; state.LMB = true; @@ -565,7 +565,7 @@ void CPad::UpdateMouse() #else double xpos = 1.0f, ypos; glfwGetCursorPos(PSGLOBAL(window), &xpos, &ypos); - if (xpos == NULL) + if (xpos == 0.f) return; int32 signX = 1; diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index bc65f6b6..b361c36f 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -90,7 +90,11 @@ CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot) // relocate to another slot?? CObject *newObject = new CObject(object->GetModelIndex(), false); CWorld::Remove(object); +#ifdef FIX_BUGS + *newObject = *object; +#else memcpy(newObject, object, ms_pObjectPool->GetMaxEntrySize()); +#endif CWorld::Add(newObject); object->m_rwObject = nil; delete object; diff --git a/src/core/Profile.cpp b/src/core/Profile.cpp index 05d54133..0aa18ab8 100644 --- a/src/core/Profile.cpp +++ b/src/core/Profile.cpp @@ -7,7 +7,7 @@ float CProfile::ms_afCumulativeTime[NUM_PROFILES]; float CProfile::ms_afEndTime[NUM_PROFILES]; float CProfile::ms_afMaxEndTime[NUM_PROFILES]; float CProfile::ms_afMaxCumulativeTime[NUM_PROFILES]; -char *CProfile::ms_pProfileString[NUM_PROFILES]; +Const char *CProfile::ms_pProfileString[NUM_PROFILES]; RwRGBA CProfile::ms_aBarColours[NUM_PROFILES]; void CProfile::Initialise() @@ -68,4 +68,4 @@ void CProfile::ShowResults() ms_afMaxCumulativeTime[PROFILE_RENDERING_TIME] = Max(ms_afMaxCumulativeTime[PROFILE_RENDERING_TIME], ms_afCumulativeTime[PROFILE_RENDERING_TIME]); ms_afMaxCumulativeTime[PROFILE_TOTAL] = Max(ms_afMaxCumulativeTime[PROFILE_TOTAL], ms_afCumulativeTime[PROFILE_TOTAL]); } -#endif \ No newline at end of file +#endif diff --git a/src/core/Profile.h b/src/core/Profile.h index d2e8054b..4fe693ae 100644 --- a/src/core/Profile.h +++ b/src/core/Profile.h @@ -19,10 +19,10 @@ class CProfile static float ms_afEndTime[NUM_PROFILES]; static float ms_afMaxEndTime[NUM_PROFILES]; static float ms_afMaxCumulativeTime[NUM_PROFILES]; - static char *ms_pProfileString[NUM_PROFILES]; + static Const char *ms_pProfileString[NUM_PROFILES]; static RwRGBA ms_aBarColours[NUM_PROFILES]; public: static void Initialise(); static void SuspendProfile(eProfile profile); static void ShowResults(); -}; \ No newline at end of file +}; diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index a2e6048b..c961f53d 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -710,6 +710,7 @@ CStreaming::RequestSubway(void) RequestModel(MI_SUBPLATFORM_SUB, STREAMFLAGS_NOFADE); RequestModel(MI_SUBPLATFORM_SUB2, STREAMFLAGS_NOFADE); break; + default: break; } } @@ -747,6 +748,7 @@ CStreaming::RequestIslands(eLevelName level) RequestModel(islandLODindust, BIGBUILDINGFLAGS); RequestModel(islandLODcomSub, BIGBUILDINGFLAGS); break; + default: break; } } @@ -1750,7 +1752,7 @@ CStreaming::ProcessLoadingChannel(int32 ch) void CStreaming::RetryLoadFile(int32 ch) { - char *key; + Const char *key; CPad::StopPadsShaking(); diff --git a/src/core/SurfaceTable.cpp b/src/core/SurfaceTable.cpp index 7212fc65..08a84cfd 100644 --- a/src/core/SurfaceTable.cpp +++ b/src/core/SurfaceTable.cpp @@ -9,7 +9,7 @@ float CSurfaceTable::ms_aAdhesiveLimitTable[NUMADHESIVEGROUPS][NUMADHESIVEGROUPS]; void -CSurfaceTable::Initialise(char *filename) +CSurfaceTable::Initialise(Const char *filename) { int lineno, fieldno; char *line; diff --git a/src/core/SurfaceTable.h b/src/core/SurfaceTable.h index 4af6a265..12246dce 100644 --- a/src/core/SurfaceTable.h +++ b/src/core/SurfaceTable.h @@ -100,7 +100,7 @@ class CSurfaceTable { static float ms_aAdhesiveLimitTable[NUMADHESIVEGROUPS][NUMADHESIVEGROUPS]; public: - static void Initialise(char *filename); + static void Initialise(Const char *filename); static int GetAdhesionGroup(uint8 surfaceType); static float GetWetMultiplier(uint8 surfaceType); static float GetAdhesiveLimit(CColPoint &colpoint); diff --git a/src/core/World.cpp b/src/core/World.cpp index c884f1ed..c15c134d 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -2205,6 +2205,7 @@ CWorld::TriggerExplosionSectorList(CPtrList &list, const CVector &position, floa case ENTITY_TYPE_OBJECT: pObject->ObjectDamage(300.0f * fDamageMultiplier); break; + default: break; } } } diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 5b7519dc..4f491a49 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -357,7 +357,7 @@ CTheZones::FindSmallestZonePositionILN(const CVector *v) } int16 -CTheZones::FindZoneByLabelAndReturnIndex(char *name) +CTheZones::FindZoneByLabelAndReturnIndex(Const char *name) { char str[8]; memset(str, 0, 8); diff --git a/src/core/Zones.h b/src/core/Zones.h index 67800569..6549dad5 100644 --- a/src/core/Zones.h +++ b/src/core/Zones.h @@ -86,7 +86,7 @@ public: static CZone *FindSmallestZonePosition(const CVector *v); static CZone *FindSmallestZonePositionType(const CVector *v, eZoneType type); static CZone *FindSmallestZonePositionILN(const CVector *v); - static int16 FindZoneByLabelAndReturnIndex(char *name); + static int16 FindZoneByLabelAndReturnIndex(Const char *name); static CZoneInfo *GetZoneInfo(const CVector *v, uint8 day); static void GetZoneInfoForTimeOfDay(const CVector *pos, CZoneInfo *info); static void SetZoneCarInfo(uint16 zoneid, uint8 day, int16 carDensity, diff --git a/src/core/main.cpp b/src/core/main.cpp index d6af0b2a..1ea8dc7f 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -401,7 +401,7 @@ DestroySplashScreen(void) splashTxdId = -1; } -char* +Const char* GetRandomSplashScreen(void) { int index; @@ -424,10 +424,10 @@ GetRandomSplashScreen(void) return splashName; } -char* +Const char* GetLevelSplashScreen(int level) { - static char *splashScreens[4] = { + static Const char *splashScreens[4] = { nil, "splash1", "splash2", @@ -1278,7 +1278,7 @@ void TheGame(void) CGame::Initialise("DATA\\GTA3.DAT"); #endif - char *splash = GetRandomSplashScreen(); // inlined here + Const char *splash = GetRandomSplashScreen(); // inlined here LoadingScreen("Starting Game", NULL, splash); @@ -1312,7 +1312,7 @@ void TheGame(void) if (FrontEndMenuManager.m_bWantToLoad) #endif { - char *splash1 = GetLevelSplashScreen(CGame::currLevel); + Const char *splash1 = GetLevelSplashScreen(CGame::currLevel); LoadSplash(splash1); } diff --git a/src/core/main.h b/src/core/main.h index 90b13fbb..32a880d6 100644 --- a/src/core/main.h +++ b/src/core/main.h @@ -22,8 +22,8 @@ void LoadingScreen(const char *str1, const char *str2, const char *splashscreen) void LoadingIslandScreen(const char *levelName); CSprite2d *LoadSplash(const char *name); void DestroySplashScreen(void); -char *GetLevelSplashScreen(int level); -char *GetRandomSplashScreen(void); +Const char *GetLevelSplashScreen(int level); +Const char *GetRandomSplashScreen(void); void LittleTest(void); void ValidateVersion(); void ResetLoadingScreenBar(void); diff --git a/src/modelinfo/PedModelInfo.cpp b/src/modelinfo/PedModelInfo.cpp index 47080e23..0cb0fc36 100644 --- a/src/modelinfo/PedModelInfo.cpp +++ b/src/modelinfo/PedModelInfo.cpp @@ -180,7 +180,7 @@ CPedModelInfo::SetLowDetailClump(RpClump *lodclump) struct ColNodeInfo { - char *name; + Const char *name; int pedNode; int pieceType; float x, z; diff --git a/src/objects/ParticleObject.cpp b/src/objects/ParticleObject.cpp index 3dd80546..2fbe6195 100644 --- a/src/objects/ParticleObject.cpp +++ b/src/objects/ParticleObject.cpp @@ -61,7 +61,7 @@ CParticleObject::CParticleObject() : m_nState(POBJECTSTATE_INITIALISED), m_pNext(NULL), m_pPrev(NULL), - m_nRemoveTimer(NULL) + m_nRemoveTimer(0) { ; @@ -1127,13 +1127,21 @@ CParticleObject::SaveParticle(uint8 *buffer, uint32 *length) for ( CParticleObject *p = pCloseListHead; p != NULL; p = p->m_pNext ) { +#ifdef FIX_BUGS + *(CParticleObject*)buffer = *p; +#else memcpy(buffer, p, sizeof(CParticleObject)); +#endif buffer += sizeof(CParticleObject); } for ( CParticleObject *p = pFarListHead; p != NULL; p = p->m_pNext ) { +#ifdef FIX_BUGS + *(CParticleObject*)buffer = *p; +#else memcpy(buffer, p, sizeof(CParticleObject)); +#endif buffer += sizeof(CParticleObject); } diff --git a/src/peds/EmergencyPed.cpp b/src/peds/EmergencyPed.cpp index 7229ed3f..cdaee657 100644 --- a/src/peds/EmergencyPed.cpp +++ b/src/peds/EmergencyPed.cpp @@ -166,6 +166,7 @@ CEmergencyPed::FiremanAI(void) m_nEmergencyPedState = EMERGENCY_PED_READY; SetMoveState(PEDMOVE_WALK); break; + default: break; } } @@ -410,6 +411,7 @@ CEmergencyPed::MedicAI(void) m_nEmergencyPedState = EMERGENCY_PED_READY; SetMoveState(PEDMOVE_WALK); break; + default: break; } } } diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 2bd5c152..f4e99d4d 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -5048,13 +5048,13 @@ CPed::LoadFightData(void) sscanf( &line[lp], "%s %f %f %f %f %c %s %d %d", - &moveName, + moveName, &startFireTime, &endFireTime, &comboFollowOnTime, &strikeRadius, &hitLevel, - &animName, + animName, &damage, &flags); @@ -10686,6 +10686,7 @@ CPed::ProcessControl(void) Say(SOUND_PED_HANDS_UP); } break; + default: break; } SetMoveAnim(); if (bPedIsBleeding) { @@ -11810,8 +11811,10 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) } } else if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER) { - switch (ped->m_vehEnterType) { - if (!veh->bIsBus) { + if (veh->bIsBus) { + veh->AddPassenger(ped); + } else { + switch (ped->m_vehEnterType) { case CAR_DOOR_RF: veh->AddPassenger(ped, 0); break; @@ -11821,10 +11824,10 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) case CAR_DOOR_LR: veh->AddPassenger(ped, 1); break; - } - default: - veh->AddPassenger(ped); + default: + veh->AddPassenger(ped); break; + } } ped->m_nPedState = PED_DRIVING; if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) @@ -17119,6 +17122,7 @@ CPed::SetObjective(eObjective newObj, CVector dest) if (sq(m_distanceToCountSeekDone) > (m_nextRoutePointPos - GetPosition()).MagnitudeSqr2D()) return; break; + default: break; } if (IsTemporaryObjective(m_objective)) { diff --git a/src/render/Particle.cpp b/src/render/Particle.cpp index 5995432b..4223ac10 100644 --- a/src/render/Particle.cpp +++ b/src/render/Particle.cpp @@ -984,6 +984,7 @@ CParticle *CParticle::AddParticle(tParticleType type, CVector const &vecPos, CVe case PARTICLE_WATER_HYDRANT: pParticle->m_vecPosition.z += 20.0f * psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; break; + default: break; } if ( fSize != 0.0f ) @@ -1214,6 +1215,7 @@ void CParticle::Update() continue; } break; + default: break; } } } @@ -1295,6 +1297,7 @@ void CParticle::Update() continue; } break; + default: break; } } } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 1f1e3b50..8a48eb11 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1174,6 +1174,7 @@ CRenderer::IsEntityCullZoneVisible(CEntity *ent) if(!obj->IsStatic()) return true; return !(obj->m_pCurSurface && obj->m_pCurSurface->bZoneCulled2); + default: break; } return true; } @@ -1182,12 +1183,14 @@ bool CRenderer::IsVehicleCullZoneVisible(CEntity *ent) { CVehicle *v = (CVehicle*)ent; - switch(v->GetStatus()) + switch(v->GetStatus()) { case STATUS_SIMPLE: case STATUS_PHYSICS: case STATUS_ABANDONED: case STATUS_WRECKED: return !(v->m_pCurGroundEntity && v->m_pCurGroundEntity->bZoneCulled2); + default: break; + } return true; } diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index e8e79f96..1a28ce83 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -52,7 +52,7 @@ const float fBlueMult = 1.4f; void -CWaterLevel::Initialise(char *pWaterDat) +CWaterLevel::Initialise(Const char *pWaterDat) { ms_nNoOfWaterLevels = 0; diff --git a/src/render/WaterLevel.h b/src/render/WaterLevel.h index a471bc52..985c9744 100644 --- a/src/render/WaterLevel.h +++ b/src/render/WaterLevel.h @@ -79,7 +79,7 @@ class CWaterLevel static int16 nGeomUsed; public: - static void Initialise(char *pWaterDat); + static void Initialise(Const char *pWaterDat); static void Shutdown(); static void CreateWavyAtomic(); static void DestroyWavyAtomic(); diff --git a/src/rw/VisibilityPlugins.cpp b/src/rw/VisibilityPlugins.cpp index d034391c..22edcb68 100644 --- a/src/rw/VisibilityPlugins.cpp +++ b/src/rw/VisibilityPlugins.cpp @@ -231,7 +231,7 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist) { RpAtomic *lodatm; float fadefactor; - uint8 alpha; + uint32 alpha; CSimpleModelInfo *mi; mi = GetAtomicModelInfo(atomic); @@ -730,11 +730,13 @@ CVisibilityPlugins::SetAtomicModelInfo(RpAtomic *atomic, { AtomicExt *ext = ATOMICEXT(atomic); ext->modelInfo = modelInfo; - switch (modelInfo->GetModelType()) - case MITYPE_SIMPLE: - case MITYPE_TIME: - if(modelInfo->m_normalCull) - SetAtomicRenderCallback(atomic, RenderObjNormalAtomic); + switch (modelInfo->GetModelType()) { + case MITYPE_SIMPLE: + case MITYPE_TIME: + if(modelInfo->m_normalCull) + SetAtomicRenderCallback(atomic, RenderObjNormalAtomic); + default: break; + } } CSimpleModelInfo* @@ -851,6 +853,7 @@ CVisibilityPlugins::SetClumpModelInfo(RpClump *clump, CClumpModelInfo *modelInfo else CLUMPEXT(clump)->visibilityCB = VehicleVisibilityCB; break; + default: break; } } diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index ba7bd216..8aae4011 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -246,7 +246,7 @@ GenericLoad() // Load SimpleVars and Scripts CheckSum = 0; - CDate(CompileDateAndTime); + CDate dummy; // unused CPad::ResetCheats(); if (!ReadInSizeofSaveFileBuffer(file, size)) return false; diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index 4a35adcf..f0a704a8 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -429,7 +429,7 @@ RwChar **_psGetVideoModeList() if ( vm.flags & rwVIDEOMODEEXCLUSIVE ) { _VMList[i] = (RwChar*)RwCalloc(100, sizeof(RwChar)); - rwsprintf(_VMList[i],"%lu X %lu X %lu", vm.width, vm.height, vm.depth); + rwsprintf(_VMList[i],"%d X %d X %d", vm.width, vm.height, vm.depth); } else _VMList[i] = nil; diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 60f17204..a880f26d 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -252,6 +252,7 @@ CAutomobile::ProcessControl(void) strongGrip2 = true; } } + default: break; } } @@ -423,6 +424,7 @@ CAutomobile::ProcessControl(void) m_fGasPedal = 0.0f; m_nCarHornTimer = 0; break; + default: break; } // what's going on here? @@ -1259,6 +1261,7 @@ CAutomobile::PreRender(void) m_aWheelColPoints[i].point + CVector(0.0f, 0.0f, 0.05f), CVector(0.0f, 0.0f, 0.0f), nil, 0.1f); break; + default: break; } } }else{ @@ -1383,6 +1386,7 @@ CAutomobile::PreRender(void) GetForward().x, GetForward().y, &m_aWheelSkidmarkMuddy[CARWHEEL_REAR_LEFT], &m_aWheelSkidmarkBloody[CARWHEEL_REAR_LEFT]); break; + default: break; } switch(m_aWheelState[CARWHEEL_REAR_RIGHT]){ @@ -1400,6 +1404,7 @@ CAutomobile::PreRender(void) GetForward().x, GetForward().y, &m_aWheelSkidmarkMuddy[CARWHEEL_REAR_RIGHT], &m_aWheelSkidmarkBloody[CARWHEEL_REAR_RIGHT]); break; + default: break; } } @@ -1851,7 +1856,7 @@ CAutomobile::PreRender(void) false); CVector pos = GetPosition() - 4.0f*GetForward(); if(Damage.GetLightStatus(VEHLIGHT_REAR_LEFT) == LIGHT_STATUS_OK || - Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) + Damage.GetLightStatus(VEHLIGHT_REAR_RIGHT) == LIGHT_STATUS_OK) { if(m_fBrakePedal > 0.0f) CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), 10.0f, 1.0f, 0.0f, 0.0f, @@ -1860,6 +1865,7 @@ CAutomobile::PreRender(void) CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), 7.0f, 0.6f, 0.0f, 0.0f, CPointLights::FOG_NONE, false); + } } }else{ // Lights off @@ -3781,6 +3787,7 @@ CAutomobile::IsDoorReady(eDoors door) case DOOR_FRONT_RIGHT: doorflag = CAR_DOOR_FLAG_RF; break; case DOOR_REAR_LEFT: doorflag = CAR_DOOR_FLAG_LR; break; case DOOR_REAR_RIGHT: doorflag = CAR_DOOR_FLAG_RR; break; + default: break; } return (doorflag & m_nGettingInFlags) == 0; } diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index 348f2732..d992d190 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -180,6 +180,7 @@ CBoat::ProcessControl(void) return; } break; + default: break; } float collisionDamage = pHandling->fCollisionDamageMultiplier * m_fDamageImpulse; diff --git a/src/vehicles/DamageManager.cpp b/src/vehicles/DamageManager.cpp index 03ccfe77..6b59ccda 100644 --- a/src/vehicles/DamageManager.cpp +++ b/src/vehicles/DamageManager.cpp @@ -85,6 +85,7 @@ CDamageManager::ApplyDamage(tComponent component, float damage, float unused) ProgressEngineDamage(); ProgressPanelDamage(subComp); break; + default: break; } return true; } diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index e4cd5883..7b62b461 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -996,7 +996,7 @@ CHeli::TestRocketCollision(CVector *rocketPos) for(i = 0; i < NUM_HELIS; i++){ if(pHelis[i] && !pHelis[i]->bExplosionProof && (*rocketPos - pHelis[i]->GetPosition()).MagnitudeSqr() < sq(8.0f)){ - pHelis[i]->m_fAngularSpeed = (CGeneral::GetRandomNumber() < RAND_MAX/2) ? 0.05f : -0.05f; + pHelis[i]->m_fAngularSpeed = CGeneral::GetRandomTrueFalse() ? 0.05f : -0.05f; pHelis[i]->m_heliStatus = HELI_STATUS_SHOT_DOWN; pHelis[i]->m_nExplosionTimer = CTimer::GetTimeInMilliseconds() + 10000; hit = true; @@ -1023,7 +1023,7 @@ CHeli::TestBulletCollision(CVector *line0, CVector *line1, CVector *bulletPos, i if(pHelis[i]->m_heliType == HELI_CATALINA && pHelis[i]->m_nBulletDamage > 400 || pHelis[i]->m_heliType != HELI_CATALINA && pHelis[i]->m_nBulletDamage > 700){ - pHelis[i]->m_fAngularSpeed = (CGeneral::GetRandomNumber() < RAND_MAX/2) ? 0.05f : -0.05f; + pHelis[i]->m_fAngularSpeed = CGeneral::GetRandomTrueFalse() ? 0.05f : -0.05f; pHelis[i]->m_heliStatus = HELI_STATUS_SHOT_DOWN; pHelis[i]->m_nExplosionTimer = CTimer::GetTimeInMilliseconds() + 10000; } diff --git a/src/vehicles/Train.cpp b/src/vehicles/Train.cpp index 7831a0c8..1d47ca3a 100644 --- a/src/vehicles/Train.cpp +++ b/src/vehicles/Train.cpp @@ -492,7 +492,7 @@ CTrain::Shutdown(void) } void -CTrain::ReadAndInterpretTrackFile(char *filename, CTrainNode **nodes, int16 *numNodes, int32 numStations, float *stationDists, +CTrain::ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int16 *numNodes, int32 numStations, float *stationDists, float *totalLength, float *totalDuration, CTrainInterpolationLine *interpLines, bool rightRail) { bool readingFile = false; diff --git a/src/vehicles/Train.h b/src/vehicles/Train.h index 6aa76fa8..c645ecaf 100644 --- a/src/vehicles/Train.h +++ b/src/vehicles/Train.h @@ -87,7 +87,7 @@ public: static void InitTrains(void); static void Shutdown(void); - static void ReadAndInterpretTrackFile(char *filename, CTrainNode **nodes, int16 *numNodes, int32 numStations, float *stationDists, + static void ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int16 *numNodes, int32 numStations, float *stationDists, float *totalLength, float *totalDuration, CTrainInterpolationLine *interpLines, bool rightRail); static void UpdateTrains(void); }; diff --git a/src/weapons/BulletInfo.cpp b/src/weapons/BulletInfo.cpp index 92d98a50..389e7486 100644 --- a/src/weapons/BulletInfo.cpp +++ b/src/weapons/BulletInfo.cpp @@ -200,6 +200,7 @@ void CBulletInfo::Update(void) case ENTITY_TYPE_VEHICLE: DMAudio.PlayOneShot(((CVehicle*)pHitEntity)->m_audioEntityId, SOUND_WEAPON_HIT_VEHICLE, 1.0f); break; + default: break; } } CGlass::WasGlassHitByBullet(pHitEntity, point.point); diff --git a/src/weapons/ProjectileInfo.cpp b/src/weapons/ProjectileInfo.cpp index 8297d953..47bc65ac 100644 --- a/src/weapons/ProjectileInfo.cpp +++ b/src/weapons/ProjectileInfo.cpp @@ -116,6 +116,7 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, elasticity = 0.5f; break; } + default: break; } int i = 0; @@ -137,6 +138,7 @@ CProjectileInfo::AddProjectile(CEntity *entity, eWeaponType weapon, CVector pos, case WEAPONTYPE_GRENADE: ms_apProjectile[i] = new CProjectile(MI_GRENADE); break; + default: break; } if (ms_apProjectile[i] == nil) @@ -183,6 +185,7 @@ CProjectileInfo::RemoveNotAdd(CEntity *entity, eWeaponType weaponType, CVector p case WEAPONTYPE_ROCKETLAUNCHER: CExplosion::AddExplosion(nil, entity, EXPLOSION_ROCKET, pos, 0); break; + default: break; } } diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index 3ac769d7..67e01a2e 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -806,6 +806,7 @@ CWeapon::FireInstantHit(CEntity *shooter, CVector *fireSource) break; } + default: break; } DoBulletImpact(shooter, victim, fireSource, &target, &point, ahead); @@ -1070,6 +1071,7 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim, break; } + default: break; } } @@ -1101,6 +1103,7 @@ CWeapon::DoBulletImpact(CEntity *shooter, CEntity *victim, PlayOneShotScriptObject(SCRIPT_SOUND_BULLET_HIT_GROUND_3, point->point); break; } + default: break; } } else @@ -1328,6 +1331,7 @@ CWeapon::FireShotgun(CEntity *shooter, CVector *fireSource) break; } + default: break; } } @@ -1359,6 +1363,7 @@ CWeapon::FireShotgun(CEntity *shooter, CVector *fireSource) PlayOneShotScriptObject(SCRIPT_SOUND_BULLET_HIT_GROUND_3, point.point); break; } + default: break; } } else @@ -1768,6 +1773,7 @@ CWeapon::FireInstantHitFromCar(CAutomobile *shooter, bool left) PlayOneShotScriptObject(SCRIPT_SOUND_BULLET_HIT_GROUND_3, point.point); break; } + default: break; } } else @@ -2037,6 +2043,7 @@ CWeapon::Update(int32 audioEntity) break; } + default: break; } } @@ -2131,6 +2138,7 @@ FireOneInstantHitRound(CVector *source, CVector *target, int32 damage) PlayOneShotScriptObject(SCRIPT_SOUND_BULLET_HIT_GROUND_3, point.point); break; } + default: break; } } else diff --git a/src/weapons/WeaponInfo.cpp b/src/weapons/WeaponInfo.cpp index aec9c69a..c4ab75d2 100644 --- a/src/weapons/WeaponInfo.cpp +++ b/src/weapons/WeaponInfo.cpp @@ -105,8 +105,8 @@ CWeaponInfo::LoadWeaponData(void) sscanf( &line[lp], "%s %s %f %d %d %d %d %f %f %f %f %f %f %f %s %s %f %f %f %f %d %d", - &weaponName, - &fireType, + weaponName, + fireType, &range, &firingRate, &reload, @@ -119,8 +119,8 @@ CWeaponInfo::LoadWeaponData(void) &fireOffsetX, &fireOffsetY, &fireOffsetZ, - &animToPlay, - &anim2ToPlay, + animToPlay, + anim2ToPlay, &animLoopStart, &animLoopEnd, &delayBetweenAnimAndFire, @@ -201,4 +201,4 @@ CWeaponInfo::Shutdown(void) { debug("Shutting down CWeaponInfo...\n"); debug("CWeaponInfo shut down\n"); -} \ No newline at end of file +} -- cgit v1.2.3