2019-05-15 16:52:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-06-30 12:53:39 +02:00
|
|
|
#include "Game.h"
|
|
|
|
|
2019-05-15 16:52:37 +02:00
|
|
|
enum {
|
2020-05-05 13:02:42 +02:00
|
|
|
STREAM_OFFSET_TXD = MODELINFOSIZE,
|
2020-05-05 17:04:43 +02:00
|
|
|
STREAM_OFFSET_COL = STREAM_OFFSET_TXD+TXDSTORESIZE,
|
2020-05-08 15:59:57 +02:00
|
|
|
STREAM_OFFSET_ANIM = STREAM_OFFSET_COL+COLSTORESIZE,
|
|
|
|
NUMSTREAMINFO = STREAM_OFFSET_ANIM+NUMANIMBLOCKS
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum StreamFlags
|
|
|
|
{
|
2019-06-20 14:49:16 +02:00
|
|
|
STREAMFLAGS_DONT_REMOVE = 0x01,
|
|
|
|
STREAMFLAGS_SCRIPTOWNED = 0x02,
|
2019-06-28 12:34:02 +02:00
|
|
|
STREAMFLAGS_DEPENDENCY = 0x04, // Is this right?
|
2019-06-20 14:49:16 +02:00
|
|
|
STREAMFLAGS_PRIORITY = 0x08,
|
|
|
|
STREAMFLAGS_NOFADE = 0x10,
|
2020-05-05 18:06:38 +02:00
|
|
|
STREAMFLAGS_20 = 0x20, // TODO(MIAMI): what's this
|
2019-06-21 17:28:55 +02:00
|
|
|
|
2020-05-05 13:02:42 +02:00
|
|
|
STREAMFLAGS_CANT_REMOVE = STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_SCRIPTOWNED,
|
2019-06-21 17:28:55 +02:00
|
|
|
STREAMFLAGS_KEEP_IN_MEMORY = STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_SCRIPTOWNED|STREAMFLAGS_DEPENDENCY,
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum StreamLoadState
|
|
|
|
{
|
2019-06-20 14:49:16 +02:00
|
|
|
STREAMSTATE_NOTLOADED = 0,
|
|
|
|
STREAMSTATE_LOADED = 1,
|
|
|
|
STREAMSTATE_INQUEUE = 2,
|
2019-06-26 16:49:32 +02:00
|
|
|
STREAMSTATE_READING = 3, // channel is reading
|
|
|
|
STREAMSTATE_STARTED = 4, // first part loaded
|
2019-06-20 14:49:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ChannelState
|
|
|
|
{
|
2019-06-24 18:44:23 +02:00
|
|
|
CHANNELSTATE_IDLE = 0,
|
2019-06-26 16:49:32 +02:00
|
|
|
CHANNELSTATE_READING = 1,
|
2019-06-24 18:44:23 +02:00
|
|
|
CHANNELSTATE_STARTED = 2,
|
|
|
|
CHANNELSTATE_ERROR = 3,
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CStreamingInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CStreamingInfo *m_next;
|
|
|
|
CStreamingInfo *m_prev;
|
|
|
|
uint8 m_loadState;
|
|
|
|
uint8 m_flags;
|
|
|
|
|
|
|
|
int16 m_nextID;
|
|
|
|
uint32 m_position;
|
|
|
|
uint32 m_size;
|
|
|
|
|
2019-06-20 14:49:16 +02:00
|
|
|
bool GetCdPosnAndSize(uint32 &posn, uint32 &size);
|
|
|
|
void SetCdPosnAndSize(uint32 posn, uint32 size);
|
|
|
|
void AddToList(CStreamingInfo *link);
|
|
|
|
void RemoveFromList(void);
|
|
|
|
uint32 GetCdSize(void) { return m_size; }
|
2019-06-26 16:49:32 +02:00
|
|
|
bool IsPriority(void) { return !!(m_flags & STREAMFLAGS_PRIORITY); }
|
2019-06-20 14:49:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CStreamingChannel
|
|
|
|
{
|
2019-06-24 18:44:23 +02:00
|
|
|
int32 streamIds[4];
|
2019-06-20 14:49:16 +02:00
|
|
|
int32 offsets[4];
|
|
|
|
int32 state;
|
|
|
|
int32 field24;
|
|
|
|
int32 position;
|
|
|
|
int32 size;
|
2019-06-26 16:49:32 +02:00
|
|
|
int32 numTries;
|
2019-06-20 14:49:16 +02:00
|
|
|
int32 status; // from CdStream
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|
|
|
|
|
2019-06-20 14:49:16 +02:00
|
|
|
class CDirectory;
|
2019-06-27 00:12:58 +02:00
|
|
|
class CPtrList;
|
2019-06-20 14:49:16 +02:00
|
|
|
|
2019-05-15 16:52:37 +02:00
|
|
|
class CStreaming
|
|
|
|
{
|
|
|
|
public:
|
2020-04-17 07:54:14 +02:00
|
|
|
static bool ms_disableStreaming;
|
|
|
|
static bool ms_bLoadingBigModel;
|
|
|
|
static int32 ms_numModelsRequested;
|
|
|
|
static CStreamingInfo ms_aInfoForModel[NUMSTREAMINFO];
|
|
|
|
static CStreamingInfo ms_startLoadedList;
|
|
|
|
static CStreamingInfo ms_endLoadedList;
|
|
|
|
static CStreamingInfo ms_startRequestedList;
|
|
|
|
static CStreamingInfo ms_endRequestedList;
|
|
|
|
static int32 ms_oldSectorX;
|
|
|
|
static int32 ms_oldSectorY;
|
|
|
|
static int32 ms_streamingBufferSize;
|
|
|
|
static int8 *ms_pStreamingBuffer[2];
|
|
|
|
static int32 ms_memoryUsed;
|
|
|
|
static CStreamingChannel ms_channel[2];
|
|
|
|
static int32 ms_channelError;
|
|
|
|
static int32 ms_numVehiclesLoaded;
|
|
|
|
static int32 ms_vehiclesLoaded[MAXVEHICLESLOADED];
|
|
|
|
static int32 ms_lastVehicleDeleted;
|
2020-05-06 21:54:43 +02:00
|
|
|
static bool ms_bIsPedFromPedGroupLoaded[NUMMODELSPERPEDGROUP];
|
2020-04-17 07:54:14 +02:00
|
|
|
static CDirectory *ms_pExtraObjectsDir;
|
|
|
|
static int32 ms_numPriorityRequests;
|
|
|
|
static int32 ms_currentPedGrp;
|
2019-06-20 14:49:16 +02:00
|
|
|
static int32 ms_lastCullZone;
|
2020-04-17 07:54:14 +02:00
|
|
|
static uint16 ms_loadedGangs;
|
|
|
|
static uint16 ms_loadedGangCars;
|
2019-06-20 14:49:16 +02:00
|
|
|
static int32 ms_currentPedLoading;
|
2020-04-17 07:54:14 +02:00
|
|
|
static int32 ms_imageOffsets[NUMCDIMAGES];
|
|
|
|
static int32 ms_lastImageRead;
|
|
|
|
static int32 ms_imageSize;
|
|
|
|
static uint32 ms_memoryAvailable;
|
2019-06-20 14:49:16 +02:00
|
|
|
|
|
|
|
static void Init(void);
|
2020-05-05 13:02:42 +02:00
|
|
|
static void Init2(void);
|
2019-06-20 14:49:16 +02:00
|
|
|
static void Shutdown(void);
|
2019-06-28 12:34:02 +02:00
|
|
|
static void Update(void);
|
2019-06-20 14:49:16 +02:00
|
|
|
static void LoadCdDirectory(void);
|
2019-06-21 17:28:55 +02:00
|
|
|
static void LoadCdDirectory(const char *dirname, int32 n);
|
|
|
|
static bool ConvertBufferToObject(int8 *buf, int32 streamId);
|
|
|
|
static bool FinishLoadingLargeFile(int8 *buf, int32 streamId);
|
2019-06-28 12:34:02 +02:00
|
|
|
static bool HasModelLoaded(int32 id) { return ms_aInfoForModel[id].m_loadState == STREAMSTATE_LOADED; }
|
2020-05-05 13:02:42 +02:00
|
|
|
static bool HasTxdLoaded(int32 id) { return HasModelLoaded(id+STREAM_OFFSET_TXD); }
|
2020-05-05 17:04:43 +02:00
|
|
|
static bool HasColLoaded(int32 id) { return HasModelLoaded(id+STREAM_OFFSET_COL); }
|
2020-05-08 15:59:57 +02:00
|
|
|
static bool HasAnimLoaded(int32 id) { return HasModelLoaded(id+STREAM_OFFSET_ANIM); }
|
2020-05-05 13:02:42 +02:00
|
|
|
static bool CanRemoveModel(int32 id) { return (ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0; }
|
|
|
|
static bool CanRemoveTxd(int32 id) { return CanRemoveModel(id+STREAM_OFFSET_TXD); }
|
2020-05-05 17:04:43 +02:00
|
|
|
static bool CanRemoveCol(int32 id) { return CanRemoveModel(id+STREAM_OFFSET_COL); }
|
2020-05-08 15:59:57 +02:00
|
|
|
static bool CanRemoveAnim(int32 id) { return CanRemoveModel(id+STREAM_OFFSET_ANIM); }
|
2019-05-15 16:52:37 +02:00
|
|
|
static void RequestModel(int32 model, int32 flags);
|
2019-06-24 18:44:23 +02:00
|
|
|
static void ReRequestModel(int32 model) { RequestModel(model, ms_aInfoForModel[model].m_flags); }
|
2019-06-21 17:28:55 +02:00
|
|
|
static void RequestTxd(int32 txd, int32 flags) { RequestModel(txd + STREAM_OFFSET_TXD, flags); }
|
2019-06-24 18:44:23 +02:00
|
|
|
static void ReRequestTxd(int32 txd) { ReRequestModel(txd + STREAM_OFFSET_TXD); }
|
2020-05-05 17:04:43 +02:00
|
|
|
static void RequestCol(int32 col, int32 flags) { RequestModel(col + STREAM_OFFSET_COL, flags); }
|
|
|
|
static void ReRequestCol(int32 col) { ReRequestModel(col + STREAM_OFFSET_COL); }
|
2020-05-08 15:59:57 +02:00
|
|
|
static void RequestAnim(int32 col, int32 flags) { RequestModel(col + STREAM_OFFSET_ANIM, flags); }
|
|
|
|
static void ReRequestAnim(int32 col) { ReRequestModel(col + STREAM_OFFSET_ANIM); }
|
2019-06-21 17:28:55 +02:00
|
|
|
static void RequestBigBuildings(eLevelName level);
|
2020-05-05 17:04:43 +02:00
|
|
|
static void RequestBigBuildings(eLevelName level, const CVector &pos);
|
|
|
|
static void InstanceBigBuildings(eLevelName level, const CVector &pos);
|
2019-06-21 17:28:55 +02:00
|
|
|
static void RequestIslands(eLevelName level);
|
|
|
|
static void RequestSpecialModel(int32 modelId, const char *modelName, int32 flags);
|
|
|
|
static void RequestSpecialChar(int32 charId, const char *modelName, int32 flags);
|
2019-06-28 12:34:02 +02:00
|
|
|
static bool HasSpecialCharLoaded(int32 id);
|
|
|
|
static void SetMissionDoesntRequireSpecialChar(int32 id);
|
2019-06-26 16:49:32 +02:00
|
|
|
static void DecrementRef(int32 id);
|
2019-06-21 17:28:55 +02:00
|
|
|
static void RemoveModel(int32 id);
|
2019-06-23 13:11:41 +02:00
|
|
|
static void RemoveTxd(int32 id) { RemoveModel(id + STREAM_OFFSET_TXD); }
|
2020-05-05 17:04:43 +02:00
|
|
|
static void RemoveCol(int32 id) { RemoveModel(id + STREAM_OFFSET_COL); }
|
2020-05-08 15:59:57 +02:00
|
|
|
static void RemoveAnim(int32 id) { RemoveModel(id + STREAM_OFFSET_ANIM); }
|
2019-06-24 18:44:23 +02:00
|
|
|
static void RemoveUnusedBuildings(eLevelName level);
|
|
|
|
static void RemoveBuildings(eLevelName level);
|
|
|
|
static void RemoveUnusedBigBuildings(eLevelName level);
|
|
|
|
static void RemoveIslandsNotUsed(eLevelName level);
|
|
|
|
static void RemoveBigBuildings(eLevelName level);
|
|
|
|
static bool RemoveLoadedVehicle(void);
|
2020-05-06 21:54:43 +02:00
|
|
|
static bool RemoveLeastUsedModel(uint32 excludeMask);
|
2019-06-24 18:44:23 +02:00
|
|
|
static void RemoveAllUnusedModels(void);
|
|
|
|
static void RemoveUnusedModelsInLoadedList(void);
|
|
|
|
static int32 GetAvailableVehicleSlot(void);
|
2019-06-21 17:28:55 +02:00
|
|
|
static bool IsTxdUsedByRequestedModels(int32 txdId);
|
|
|
|
static bool AddToLoadedVehiclesList(int32 modelId);
|
2019-06-24 18:44:23 +02:00
|
|
|
static bool IsObjectInCdImage(int32 id);
|
|
|
|
static void SetModelIsDeletable(int32 id);
|
|
|
|
static void SetModelTxdIsDeletable(int32 id);
|
|
|
|
static void SetMissionDoesntRequireModel(int32 id);
|
2019-06-28 12:34:02 +02:00
|
|
|
static void LoadInitialPeds(void);
|
|
|
|
static void LoadInitialVehicles(void);
|
|
|
|
static void StreamVehiclesAndPeds(void);
|
|
|
|
static void StreamZoneModels(const CVector &pos);
|
|
|
|
static void RemoveCurrentZonesModels(void);
|
2020-05-05 17:04:43 +02:00
|
|
|
static void LoadBigBuildingsWhenNeeded(void);
|
2019-06-24 18:44:23 +02:00
|
|
|
|
2019-06-26 16:49:32 +02:00
|
|
|
static int32 GetCdImageOffset(int32 lastPosn);
|
2019-06-24 18:44:23 +02:00
|
|
|
static int32 GetNextFileOnCd(int32 position, bool priority);
|
|
|
|
static void RequestModelStream(int32 ch);
|
2019-06-26 16:49:32 +02:00
|
|
|
static bool ProcessLoadingChannel(int32 ch);
|
2019-06-26 21:33:58 +02:00
|
|
|
static void RetryLoadFile(int32 ch);
|
2019-06-26 16:49:32 +02:00
|
|
|
static void LoadRequestedModels(void);
|
|
|
|
static void LoadAllRequestedModels(bool priority);
|
2019-06-24 18:44:23 +02:00
|
|
|
static void FlushChannels(void);
|
|
|
|
static void FlushRequestList(void);
|
2019-06-21 17:28:55 +02:00
|
|
|
|
2019-06-12 20:07:37 +02:00
|
|
|
static void MakeSpaceFor(int32 size);
|
|
|
|
static void ImGonnaUseStreamingMemory(void);
|
|
|
|
static void IHaveUsedStreamingMemory(void);
|
|
|
|
static void UpdateMemoryUsed(void);
|
2019-06-25 00:42:23 +02:00
|
|
|
|
2019-06-27 00:12:58 +02:00
|
|
|
static void AddModelsToRequestList(const CVector &pos);
|
|
|
|
static void ProcessEntitiesInSectorList(CPtrList &list, float x, float y, float xmin, float ymin, float xmax, float ymax);
|
|
|
|
static void ProcessEntitiesInSectorList(CPtrList &list);
|
|
|
|
static void DeleteFarAwayRwObjects(const CVector &pos);
|
|
|
|
static void DeleteAllRwObjects(void);
|
2019-06-27 14:17:42 +02:00
|
|
|
static void DeleteRwObjectsAfterDeath(const CVector &pos);
|
|
|
|
static void DeleteRwObjectsBehindCamera(int32 mem);
|
2019-06-27 00:12:58 +02:00
|
|
|
static void DeleteRwObjectsInSectorList(CPtrList &list);
|
|
|
|
static void DeleteRwObjectsInOverlapSectorList(CPtrList &list, int32 x, int32 y);
|
2019-06-27 14:17:42 +02:00
|
|
|
static bool DeleteRwObjectsBehindCameraInSectorList(CPtrList &list, int32 mem);
|
|
|
|
static bool DeleteRwObjectsNotInFrustumInSectorList(CPtrList &list, int32 mem);
|
2019-06-24 18:44:23 +02:00
|
|
|
|
2019-06-27 00:12:58 +02:00
|
|
|
static void LoadScene(const CVector &pos);
|
2019-06-27 10:58:51 +02:00
|
|
|
|
2019-06-28 12:34:02 +02:00
|
|
|
static void MemoryCardSave(uint8 *buffer, uint32 *length);
|
|
|
|
static void MemoryCardLoad(uint8 *buffer, uint32 length);
|
2019-08-15 16:51:39 +02:00
|
|
|
|
|
|
|
static void UpdateForAnimViewer(void);
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|