diff options
author | Sergeanur <s.anureev@yandex.ua> | 2021-06-28 02:59:07 +0200 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2021-06-28 04:12:54 +0200 |
commit | f8297df9c5a7d65d5658d1a8d85d391fbb15b95a (patch) | |
tree | 9dcfac13fc3be99320ca7b546c4ff2007bff4121 /src/core | |
parent | Remove waiting for stream closure in multi-thread audio (diff) | |
download | re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.gz re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.bz2 re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.lz re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.xz re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.tar.zst re3-f8297df9c5a7d65d5658d1a8d85d391fbb15b95a.zip |
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Pools.cpp | 18 | ||||
-rw-r--r-- | src/core/Radar.cpp | 31 | ||||
-rw-r--r-- | src/core/Zones.cpp | 75 | ||||
-rw-r--r-- | src/core/Zones.h | 4 | ||||
-rw-r--r-- | src/core/common.h | 209 |
5 files changed, 73 insertions, 264 deletions
diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index d824d498..d1947813 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -14,6 +14,7 @@ #include "Wanted.h" #include "World.h" #include "MemoryHeap.h" +#include "SaveBuf.h" CCPtrNodePool *CPools::ms_pPtrNodePool; CEntryInfoNodePool *CPools::ms_pEntryInfoNodePool; @@ -137,15 +138,20 @@ CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot) void CPools::LoadVehiclePool(uint8* buf, uint32 size) { INITSAVEBUF - int nNumCars = ReadSaveBuf<int>(buf); - int nNumBoats = ReadSaveBuf<int>(buf); - int nNumBikes = ReadSaveBuf<int>(buf); + int nNumCars, nNumBoats, nNumBikes; + ReadSaveBuf(&nNumCars, buf); + ReadSaveBuf(&nNumBoats, buf); + ReadSaveBuf(&nNumBikes, buf); for (int i = 0; i < nNumCars + nNumBoats + nNumBikes; i++) { - uint32 type = ReadSaveBuf<uint32>(buf); - int16 model = ReadSaveBuf<int16>(buf); + uint32 type; + int16 model; + int32 slot; + + ReadSaveBuf(&type, buf); + ReadSaveBuf(&model, buf); CStreaming::RequestModel(model, STREAMFLAGS_DEPENDENCY); CStreaming::LoadAllRequestedModels(false); - int32 slot = ReadSaveBuf<int32>(buf); + ReadSaveBuf(&slot, buf); CVehicle* pVehicle; #ifdef COMPATIBLE_SAVES if (type == VEHICLE_TYPE_BOAT) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index fadca215..f58f4687 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -19,6 +19,7 @@ #include "Streaming.h" #include "SpecialFX.h" #include "Font.h" +#include "SaveBuf.h" float CRadar::m_radarRange; sRadarTrace CRadar::ms_RadarTrace[NUMRADARBLIPS]; @@ -973,21 +974,21 @@ INITSAVEBUF CheckSaveHeader(buf, 'R', 'D', 'R', '\0', size - SAVE_HEADER_SIZE); for (int i = 0; i < NUMRADARBLIPS; i++) { - ms_RadarTrace[i].m_nColor = ReadSaveBuf<uint32>(buf); - ms_RadarTrace[i].m_Radius = ReadSaveBuf<float>(buf); - ms_RadarTrace[i].m_eBlipType = ReadSaveBuf<uint32>(buf); - ms_RadarTrace[i].m_nEntityHandle = ReadSaveBuf<int32>(buf); - ms_RadarTrace[i].m_vec2DPos.x = ReadSaveBuf<float>(buf); // CVector2D - ms_RadarTrace[i].m_vec2DPos.y = ReadSaveBuf<float>(buf); - ms_RadarTrace[i].m_vecPos = ReadSaveBuf<CVector>(buf); - ms_RadarTrace[i].m_BlipIndex = ReadSaveBuf<uint16>(buf); - ms_RadarTrace[i].m_bDim = ReadSaveBuf<bool>(buf); - ms_RadarTrace[i].m_bInUse = ReadSaveBuf<bool>(buf); - ms_RadarTrace[i].m_bShortRange = ReadSaveBuf<bool>(buf); - ms_RadarTrace[i].m_unused = ReadSaveBuf<bool>(buf); - ms_RadarTrace[i].m_wScale = ReadSaveBuf<int16>(buf); - ms_RadarTrace[i].m_eBlipDisplay = ReadSaveBuf<uint16>(buf); - ms_RadarTrace[i].m_eRadarSprite = ReadSaveBuf<uint16>(buf); + ReadSaveBuf(&ms_RadarTrace[i].m_nColor, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_Radius, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_eBlipType, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_nEntityHandle, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_vec2DPos.x, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_vec2DPos.y, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_vecPos, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_BlipIndex, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_bDim, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_bInUse, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_bShortRange, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_unused, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_wScale, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_eBlipDisplay, buf); + ReadSaveBuf(&ms_RadarTrace[i].m_eRadarSprite, buf); } VALIDATESAVEBUF(size); diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 26d3efb0..93eca199 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -8,6 +8,7 @@ #include "Text.h" #include "World.h" #include "Timer.h" +#include "SaveBuf.h" eLevelName CTheZones::m_CurrLevel; int16 CTheZones::FindIndex; @@ -714,11 +715,11 @@ CTheZones::SaveOneZone(CZone *zone, uint8 **buffer, uint32 *length, eZoneType zo WriteSaveBuf(*buffer, *length, zone->zoneinfoNight); int32 zoneId; - zoneId = GetIndexForZonePointer(zone->child); + zoneId = GetIndexForNavigationZonePointer(zone->child); WriteSaveBuf(*buffer, *length, zoneId); - zoneId = GetIndexForZonePointer(zone->parent); + zoneId = GetIndexForNavigationZonePointer(zone->parent); WriteSaveBuf(*buffer, *length, zoneId); - zoneId = GetIndexForZonePointer(zone->next); + zoneId = GetIndexForNavigationZonePointer(zone->next); WriteSaveBuf(*buffer, *length, zoneId); } @@ -731,9 +732,9 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) uint32 length = 0; CheckSaveHeaderWithLength(buffer, length, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE); - m_CurrLevel = ReadSaveBuf<eLevelName>(buffer, length); - FindIndex = ReadSaveBuf<int16>(buffer, length); - ReadSaveBuf<int16>(buffer, length); + ReadSaveBuf(&m_CurrLevel, buffer); + ReadSaveBuf(&FindIndex, buffer); + SkipSaveBuf(buffer, 2); for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++) LoadOneZone(&NavigationZoneArray[i], &buffer, &length, ZONE_NAVIG); @@ -742,21 +743,21 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) LoadOneZone(&InfoZoneArray[i], &buffer, &length, ZONE_INFO); for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) - ZoneInfoArray[i] = ReadSaveBuf<CZoneInfo>(buffer, length); + ReadSaveBuf(&ZoneInfoArray[i], buffer); - TotalNumberOfNavigationZones = ReadSaveBuf<int16>(buffer, length); - TotalNumberOfInfoZones = ReadSaveBuf<int16>(buffer, length); - TotalNumberOfZoneInfos = ReadSaveBuf<int16>(buffer, length); - ReadSaveBuf<int16>(buffer, length); + ReadSaveBuf(&TotalNumberOfNavigationZones, buffer); + ReadSaveBuf(&TotalNumberOfInfoZones, buffer); + ReadSaveBuf(&TotalNumberOfZoneInfos, buffer); + SkipSaveBuf(buffer, 2); for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) LoadOneZone(&MapZoneArray[i], &buffer, &length, ZONE_MAPZONE); for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++) - AudioZoneArray[i] = ReadSaveBuf<int16>(buffer, length); + ReadSaveBuf(&AudioZoneArray[i], buffer); - TotalNumberOfMapZones = ReadSaveBuf<uint16>(buffer, length); - NumberOfAudioZones = ReadSaveBuf<uint16>(buffer, length); + ReadSaveBuf(&TotalNumberOfMapZones, buffer); + ReadSaveBuf(&NumberOfAudioZones, buffer); VALIDATESAVEBUF(size) } @@ -764,26 +765,36 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) void CTheZones::LoadOneZone(CZone *zone, uint8 **buffer, uint32 *length, eZoneType zoneType) { - *(uint32*)&zone->name[0] = ReadSaveBuf<uint32>(*buffer, *length); - *(uint32*)&zone->name[4] = ReadSaveBuf<uint32>(*buffer, *length); +#ifdef THIS_IS_STUPID + uint32 part1, part2; + ReadSaveBuf(&part1, *buffer, *length); + ReadSaveBuf(&part2, *buffer, *length); + + *(uint64 *)&zone->name[0] = (uint64)part2; + *(uint64 *)&zone->name[0] <<= 32; + *(uint64 *)&zone->name[0] |= (uint64)part1; +#else + for(int i = 0; i < sizeof(zone->name); i++) + ReadSaveBuf(&zone->name[i], *buffer, *length); +#endif - zone->minx = ReadSaveBuf<float>(*buffer, *length); - zone->miny = ReadSaveBuf<float>(*buffer, *length); - zone->minz = ReadSaveBuf<float>(*buffer, *length); - zone->maxx = ReadSaveBuf<float>(*buffer, *length); - zone->maxy = ReadSaveBuf<float>(*buffer, *length); - zone->maxz = ReadSaveBuf<float>(*buffer, *length); + ReadSaveBuf(&zone->minx, *buffer, *length); + ReadSaveBuf(&zone->miny, *buffer, *length); + ReadSaveBuf(&zone->minz, *buffer, *length); + ReadSaveBuf(&zone->maxx, *buffer, *length); + ReadSaveBuf(&zone->maxy, *buffer, *length); + ReadSaveBuf(&zone->maxz, *buffer, *length); - zone->type = ReadSaveBuf<eZoneType>(*buffer, *length); - zone->level = ReadSaveBuf<eLevelName>(*buffer, *length); - zone->zoneinfoDay = ReadSaveBuf<int16>(*buffer, *length); - zone->zoneinfoNight = ReadSaveBuf<int16>(*buffer, *length); + ReadSaveBuf(&zone->type, *buffer, *length); + ReadSaveBuf(&zone->level, *buffer, *length); + ReadSaveBuf(&zone->zoneinfoDay, *buffer, *length); + ReadSaveBuf(&zone->zoneinfoNight, *buffer, *length); int32 zoneId; - zoneId = ReadSaveBuf<int32>(*buffer, *length); - zone->child = GetPointerForZoneIndex(zoneId); - zoneId = ReadSaveBuf<int32>(*buffer, *length); - zone->parent = GetPointerForZoneIndex(zoneId); - zoneId = ReadSaveBuf<int32>(*buffer, *length); - zone->next = GetPointerForZoneIndex(zoneId); + ReadSaveBuf(&zoneId, *buffer, *length); + zone->child = GetPointerForNavigationZoneIndex(zoneId); + ReadSaveBuf(&zoneId, *buffer, *length); + zone->parent = GetPointerForNavigationZoneIndex(zoneId); + ReadSaveBuf(&zoneId, *buffer, *length); + zone->next = GetPointerForNavigationZoneIndex(zoneId); }
\ No newline at end of file diff --git a/src/core/Zones.h b/src/core/Zones.h index b987f009..2316eeef 100644 --- a/src/core/Zones.h +++ b/src/core/Zones.h @@ -103,8 +103,8 @@ public: static void SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity); static void SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup); static int16 FindAudioZone(CVector *pos); - static CZone *GetPointerForZoneIndex(ssize_t i) { return i == -1 ? nil : &NavigationZoneArray[i]; } - static ssize_t GetIndexForZonePointer(CZone *zone) { return zone == nil ? -1 : zone - NavigationZoneArray; } + static CZone *GetPointerForNavigationZoneIndex(ssize_t i) { return i == -1 ? nil : &NavigationZoneArray[i]; } + static ssize_t GetIndexForNavigationZonePointer(CZone *zone) { return zone == nil ? -1 : zone - NavigationZoneArray; } static void AddZoneToAudioZoneArray(CZone *zone); static void InitialiseAudioZoneArray(void); static void SaveAllZones(uint8 *buffer, uint32 *length); diff --git a/src/core/common.h b/src/core/common.h index 38ba7ea8..ca29ef5a 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -392,212 +392,3 @@ __inline__ void TRACE(char *f, ...) { } // this is re3 only, and so the function #define CONCAT_(x,y) x##y #define CONCAT(x,y) CONCAT_(x,y) -#ifdef DEBUGMENU -// Tweaking stuff for debugmenu -#define TWEAKPATH ___tw___TWEAKPATH -#define SETTWEAKPATH(path) static const char *___tw___TWEAKPATH = path; -#define TWEAKFUNC(v) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH); -#define TWEAKFUNCN(v, name) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH); -#define TWEAKBOOL(v) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH); -#define TWEAKBOOLN(v, name) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH); -#define TWEAKINT32(v, lower, upper, step) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKINT32N(v, lower, upper, step, name) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKUINT32(v, lower, upper, step) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKUINT32N(v, lower, upper, step, name) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKINT16(v, lower, upper, step) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKINT16N(v, lower, upper, step, name) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKUINT16(v, lower, upper, step) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKUINT16N(v, lower, upper, step, name) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKINT8(v, lower, upper, step) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKINT8N(v, lower, upper, step, name) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKUINT8(v, lower, upper, step) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKUINT8N(v, lower, upper, step, name) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKFLOAT(v, lower, upper, step) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH); -#define TWEAKFLOATN(v, lower, upper, step, name) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH); -#define TWEAKSWITCH(v, lower, upper, str, f) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, str, f, TWEAKPATH); -#define TWEAKSWITCHN(v, lower, upper, str, f, name) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, str, f, TWEAKPATH); - -// interface -class CTweakVar -{ -public: - virtual void AddDBG(const char *path) = 0; -}; - -class CTweakVars -{ -public: - static void Add(CTweakVar *var); - static void AddDBG(const char *path); -}; - -class CTweakFunc : public CTweakVar -{ - const char *m_pPath, *m_pVarName; - void (*m_pFunc)(); -public: - CTweakFunc(void (*pFunc)(), const char *strName, const char *strPath) : - m_pPath(strPath), m_pVarName(strName), m_pFunc(pFunc) - { - CTweakVars::Add(this); - } - - void AddDBG(const char *path); -}; - -class CTweakBool : public CTweakVar -{ - const char *m_pPath, *m_pVarName; - bool *m_pBoolVar; -public: - CTweakBool(bool *pBool, const char *strName, const char *strPath) : - m_pPath(strPath), m_pVarName(strName), m_pBoolVar(pBool) - { - CTweakVars::Add(this); - } - - void AddDBG(const char *path); -}; - -class CTweakSwitch : public CTweakVar -{ - const char *m_pPath, *m_pVarName; - void *m_pIntVar; - int32 m_nMin, m_nMax; - const char **m_aStr; - void (*m_pFunc)(); -public: - CTweakSwitch(void *pInt, const char *strName, int32 nMin, int32 nMax, const char **aStr, - void (*pFunc)(), const char *strPath) - : m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), m_nMin(nMin), m_nMax(nMax), - m_aStr(aStr) - { - CTweakVars::Add(this); - } - - void AddDBG(const char *path); -}; - -#define _TWEEKCLASS(name, type) \ - class name : public CTweakVar \ - { \ - public: \ - const char *m_pPath, *m_pVarName; \ - type *m_pIntVar, m_nLoawerBound, m_nUpperBound, m_nStep; \ - \ - name(type *pInt, const char *strName, type nLower, type nUpper, type nStep, \ - const char *strPath) \ - : m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), \ - m_nLoawerBound(nLower), m_nUpperBound(nUpper), m_nStep(nStep) \ - \ - { \ - CTweakVars::Add(this); \ - } \ - \ - void AddDBG(const char *path); \ - }; - -_TWEEKCLASS(CTweakInt8, int8); -_TWEEKCLASS(CTweakUInt8, uint8); -_TWEEKCLASS(CTweakInt16, int16); -_TWEEKCLASS(CTweakUInt16, uint16); -_TWEEKCLASS(CTweakInt32, int32); -_TWEEKCLASS(CTweakUInt32, uint32); -_TWEEKCLASS(CTweakFloat, float); - -#undef _TWEEKCLASS -#endif - -#ifdef VALIDATE_SAVE_SIZE -extern int32 _saveBufCount; -#define INITSAVEBUF _saveBufCount = 0; -#define VALIDATESAVEBUF(b) assert(_saveBufCount == b); -#else -#define INITSAVEBUF -#define VALIDATESAVEBUF(b) -#endif - -inline void SkipSaveBuf(uint8 *&buf, int32 skip) -{ - buf += skip; -#ifdef VALIDATE_SAVE_SIZE - _saveBufCount += skip; -#endif -} - -inline void SkipSaveBuf(uint8*& buf, uint32 &length, int32 skip) -{ - buf += skip; - length += skip; -#ifdef VALIDATE_SAVE_SIZE - _saveBufCount += skip; -#endif -} - -template<typename T> -inline const T ReadSaveBuf(uint8 *&buf) -{ - T &value = *(T*)buf; - SkipSaveBuf(buf, sizeof(T)); - return value; -} - -template<typename T> -inline const T ReadSaveBuf(uint8 *&buf, uint32 &length) -{ - T &value = *(T*)buf; - SkipSaveBuf(buf, length, sizeof(T)); - return value; -} - -template<typename T> -inline T *WriteSaveBuf(uint8 *&buf, const T &value) -{ - T *p = (T*)buf; - *p = value; - SkipSaveBuf(buf, sizeof(T)); - return p; -} - -template<typename T> -inline T *WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value) -{ - T *p = (T*)buf; - *p = value; - SkipSaveBuf(buf, length, sizeof(T)); - return p; -} - - -#define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32)) - -#define WriteSaveHeader(buf,a,b,c,d,size) \ - WriteSaveBuf(buf, a);\ - WriteSaveBuf(buf, b);\ - WriteSaveBuf(buf, c);\ - WriteSaveBuf(buf, d);\ - WriteSaveBuf<uint32>(buf, size); - -#define WriteSaveHeaderWithLength(buf,len,a,b,c,d,size) \ - WriteSaveBuf(buf, len, a);\ - WriteSaveBuf(buf, len, b);\ - WriteSaveBuf(buf, len, c);\ - WriteSaveBuf(buf, len, d);\ - WriteSaveBuf<uint32>(buf, len, size); - -#define CheckSaveHeader(buf,a,b,c,d,size)\ - assert(ReadSaveBuf<char>(buf) == a);\ - assert(ReadSaveBuf<char>(buf) == b);\ - assert(ReadSaveBuf<char>(buf) == c);\ - assert(ReadSaveBuf<char>(buf) == d);\ - assert(ReadSaveBuf<uint32>(buf) == size); - -#define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size)\ - assert(ReadSaveBuf<char>(buf,len) == a);\ - assert(ReadSaveBuf<char>(buf,len) == b);\ - assert(ReadSaveBuf<char>(buf,len) == c);\ - assert(ReadSaveBuf<char>(buf,len) == d);\ - assert(ReadSaveBuf<uint32>(buf,len) == size); - - -void cprintf(char*, ...); |