summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/collision/ColStore.cpp176
-rw-r--r--src/collision/ColStore.h17
-rw-r--r--src/control/Garages.h2
-rw-r--r--src/control/Script.h2
-rw-r--r--src/control/Script7.cpp3
-rw-r--r--src/core/Streaming.cpp40
-rw-r--r--src/core/Streaming.h12
-rw-r--r--src/modelinfo/BaseModelInfo.h2
-rw-r--r--src/render/SpecialFX.cpp4
9 files changed, 234 insertions, 24 deletions
diff --git a/src/collision/ColStore.cpp b/src/collision/ColStore.cpp
index f1e695fe..90a29bc2 100644
--- a/src/collision/ColStore.cpp
+++ b/src/collision/ColStore.cpp
@@ -1,5 +1,7 @@
#include "common.h"
+#include "main.h"
+#include "smallHeap.h"
#include "templates.h"
#include "General.h"
#include "ModelInfo.h"
@@ -8,6 +10,9 @@
#include "Script.h"
#include "Timer.h"
#include "Camera.h"
+#include "World.h"
+#include "Zones.h"
+#include "Garages.h"
#include "Frontend.h"
#include "Physical.h"
#include "ColStore.h"
@@ -15,16 +20,55 @@
#include "Pools.h"
CPool<ColDef,ColDef> *CColStore::ms_pColPool;
+bool CColStore::m_onlyBB;
#ifndef MASTER
bool bDispColInMem;
#endif
+// LCS: file done except unused:
+// CColStore::LoadCol(int,char const*)
+// CColStore::LoadAllBoundingBoxes(void)
+// CColStore::Write(base::cRelocatableChunkWriter &)
+
+const CVector&
+LevelPos(eLevelName level)
+{
+ static CVector pos[4] = {
+ CVector(1060.0f, -800.0f, 0.0f),
+ CVector(1060.0f, -800.0f, 0.0f),
+ CVector(350.0f, -624.0f, 0.0f),
+ CVector(-670.0f, -511.0f, 0.0f)
+ };
+ return pos[level];
+};
+
+static eLevelName
+PosLevel(const CVector &pos)
+{
+ static eLevelName lastPlayerLevel = LEVEL_INDUSTRIAL;
+ static eLevelName lastOtherLevel = LEVEL_INDUSTRIAL;
+
+ if(Abs(FindPlayerCoors().x - pos.x) < 5.0f &&
+ Abs(FindPlayerCoors().y - pos.y) < 5.0f &&
+ Abs(FindPlayerCoors().z - pos.z) < 5.0f){
+ if(CGame::currLevel != LEVEL_GENERIC)
+ lastPlayerLevel = CGame::currLevel;
+ return lastPlayerLevel;
+ }else{
+ eLevelName lvl = CTheZones::GetLevelFromPosition(&pos);
+ if(lvl != LEVEL_GENERIC)
+ lastOtherLevel = lvl;
+ return lastOtherLevel;
+ }
+}
+
void
CColStore::Initialise(void)
{
- if(ms_pColPool == nil)
+ if(ms_pColPool == nil){
ms_pColPool = new CPool<ColDef,ColDef>(COLSTORESIZE, "CollisionFiles");
- AddColSlot("generic"); // slot 0. not streamed
+ AddColSlot("generic"); // slot 0. not streamed
+ }
#ifndef MASTER
VarConsole.Add("Display collision in memory", &bDispColInMem, true);
#endif
@@ -38,7 +82,9 @@ CColStore::Shutdown(void)
RemoveColSlot(i);
if(ms_pColPool)
delete ms_pColPool;
+#ifdef FIX_BUGS
ms_pColPool = nil;
+#endif
}
int
@@ -119,11 +165,34 @@ CColStore::LoadCol(int32 slot, uint8 *buffer, int32 bufsize)
return success;
}
+struct ColChunkEntry
+{
+ int32 modelId; // -1 marks end
+ CColModel *colModel;
+};
+
+void
+CColStore::LoadColCHK(int32 slot, void *data, void *chunk)
+{
+ ColDef *def = GetSlot(slot);
+ def->chunk = chunk;
+ CStreaming::RegisterPointer(&def->chunk, 1, true);
+ for(ColChunkEntry *entry = (ColChunkEntry*)data; entry->modelId != -1; entry++){
+ CBaseModelInfo *mi = CModelInfo::GetModelInfo(entry->modelId);
+ mi->SetColModel(entry->colModel, true); // we own this? can that work?
+ CStreaming::RegisterPointer(&mi->m_colModel, 1, true);
+ }
+ def->isLoaded = true;
+}
+
+CColModel nullCollision;
+
void
CColStore::RemoveCol(int32 slot)
{
int id;
- GetSlot(slot)->isLoaded = false;
+ ColDef *def = GetSlot(slot);
+ def->isLoaded = false;
for(id = 0; id < MODELINFOSIZE; id++){
CBaseModelInfo *mi = CModelInfo::GetModelInfo(id);
if(mi){
@@ -132,6 +201,23 @@ CColStore::RemoveCol(int32 slot)
col->RemoveCollisionVolumes();
}
}
+ if(gUseChunkFiles){
+ for(id = 0; id < MODELINFOSIZE; id++){
+ CBaseModelInfo *mi = CModelInfo::GetModelInfo(id);
+ if(mi){
+ CColModel *col = mi->GetColModel();
+ if(col && col->level == slot){
+ mi->SetColModel(&nullCollision);
+ CStreaming::UnregisterPointer(&mi->m_colModel, 1);
+ }
+ }
+ }
+ if(def->chunk){
+ CStreaming::UnregisterPointer(&def->chunk, 1);
+ cSmallHeap::msInstance.Free(def->chunk);
+ def->chunk = nil;
+ }
+ }
}
void
@@ -156,29 +242,49 @@ CColStore::RemoveAllCollision(void)
}
static bool bLoadAtSecondPosition;
-static CVector2D secondPosition;
+static CVector secondPosition;
void
-CColStore::AddCollisionNeededAtPosn(const CVector2D &pos)
+CColStore::AddCollisionNeededAtPosn(const CVector &pos)
{
bLoadAtSecondPosition = true;
secondPosition = pos;
}
void
-CColStore::LoadCollision(const CVector2D &pos)
+CColStore::LoadCollision(const CVector &pos, eLevelName level)
{
int i;
if(CStreaming::ms_disableStreaming)
return;
+ if(level == LEVEL_GENERIC)
+ level = PosLevel(pos);
+
+ eLevelName allowedLevel = (eLevelName)CTheScripts::AllowedCollision[0];
+ if(allowedLevel == LEVEL_GENERIC)
+ allowedLevel = (eLevelName)CTheScripts::AllowedCollision[1];
+
+ bool requestedSomething = false;
+
for(i = 1; i < COLSTORESIZE; i++){
- if(GetSlot(i) == nil)
+ if(GetSlot(i) == nil || !DoScriptsWantThisIn(i))
continue;
bool wantThisOne = false;
+ if(strcmp(GetColName(i), "indust") == 0){
+ if(allowedLevel != LEVEL_GENERIC && level != LEVEL_INDUSTRIAL)
+ wantThisOne = allowedLevel == LEVEL_INDUSTRIAL;
+ else
+ wantThisOne = level == LEVEL_INDUSTRIAL;
+ }else if(GetBoundingBox(i).IsPointInside(LevelPos(level)))
+ wantThisOne = true;
+ else if(allowedLevel != LEVEL_GENERIC && GetBoundingBox(i).IsPointInside(LevelPos(allowedLevel)))
+ wantThisOne = true;
+
+/* // LCS: removed
if(GetBoundingBox(i).IsPointInside(pos) ||
bLoadAtSecondPosition && GetBoundingBox(i).IsPointInside(secondPosition, -119.0f) ||
strcmp(GetColName(i), "yacht") == 0){
@@ -203,28 +309,38 @@ CColStore::LoadCollision(const CVector2D &pos)
}
}
}
+*/
- if(wantThisOne)
+ if(wantThisOne){
CStreaming::RequestCol(i, STREAMFLAGS_PRIORITY);
- else
+ requestedSomething = true;
+ }else
CStreaming::RemoveCol(i);
}
+ if(requestedSomething){
+ CTimer::Suspend();
+ // BUG? request was done with priority but now loading non-priority?
+ CStreaming::LoadAllRequestedModels(false);
+ CGarages::SetupAnyGaragesForThisIsland();
+ CTimer::Resume();
+ }
bLoadAtSecondPosition = false;
}
void
-CColStore::RequestCollision(const CVector2D &pos)
+CColStore::RequestCollision(const CVector &pos)
{
int i;
for(i = 1; i < COLSTORESIZE; i++)
- if(GetSlot(i) && GetBoundingBox(i).IsPointInside(pos, -115.0f))
+ if(GetSlot(i) && DoScriptsWantThisIn(i) && GetBoundingBox(i).IsPointInside(LevelPos(PosLevel(pos)), -115.0f))
CStreaming::RequestCol(i, STREAMFLAGS_PRIORITY);
}
void
-CColStore::EnsureCollisionIsInMemory(const CVector2D &pos)
+CColStore::EnsureCollisionIsInMemory(const CVector &pos)
{
+/* // LCS: removed
int i;
if(CStreaming::ms_disableStreaming)
@@ -240,16 +356,48 @@ CColStore::EnsureCollisionIsInMemory(const CVector2D &pos)
CStreaming::LoadAllRequestedModels(false);
CTimer::Resume();
}
+*/
}
bool
-CColStore::HasCollisionLoaded(const CVector2D &pos)
+CColStore::DoScriptsWantThisIn(int32 slot)
+{
+ if(slot == 0)
+ return false;
+ ColDef *coldef = GetSlot(slot);
+ if(coldef == nil)
+ return false;
+ if(strcmp(coldef->name, "fortstaunton") == 0)
+ return !CTheScripts::IsFortStauntonDestroyed();
+ if(strcmp(coldef->name, "fortdestroyed") == 0)
+ return CTheScripts::IsFortStauntonDestroyed();
+ return true;
+}
+
+bool
+CColStore::HasCollisionLoaded(eLevelName level)
{
int i;
+ const CVector &pos = LevelPos(level);
for(i = 1; i < COLSTORESIZE; i++)
- if(GetSlot(i) && GetBoundingBox(i).IsPointInside(pos, -115.0f) &&
+ if(GetSlot(i) && DoScriptsWantThisIn(i) &&
+ (!CGeneral::faststricmp(GetColName(i), "indust") && level == LEVEL_INDUSTRIAL ||
+ GetBoundingBox(i).IsPointInside(pos)) &&
!GetSlot(i)->isLoaded)
return false;
return true;
}
+
+bool
+CColStore::HasCollisionLoaded(const CVector &pos)
+{
+ return HasCollisionLoaded(PosLevel(pos));
+}
+
+void
+CColStore::Load(bool onlyBB, CPool<ColDef> *pool)
+{
+ ms_pColPool = pool;
+ m_onlyBB = onlyBB;
+}
diff --git a/src/collision/ColStore.h b/src/collision/ColStore.h
index e0da92ca..d09bbf8f 100644
--- a/src/collision/ColStore.h
+++ b/src/collision/ColStore.h
@@ -9,11 +9,13 @@ struct ColDef { // made up name
char name[20];
int16 minIndex;
int16 maxIndex;
+ void *chunk;
};
class CColStore
{
static CPool<ColDef,ColDef> *ms_pColPool;
+ static bool m_onlyBB;
public:
static void Initialise(void);
@@ -25,15 +27,18 @@ public:
static CRect &GetBoundingBox(int32 slot);
static void IncludeModelIndex(int32 slot, int32 modelIndex);
static bool LoadCol(int32 storeID, uint8 *buffer, int32 bufsize);
+ static void LoadColCHK(int32 slot, void *data, void *chunk);
static void RemoveCol(int32 slot);
- static void AddCollisionNeededAtPosn(const CVector2D &pos);
+ static void AddCollisionNeededAtPosn(const CVector &pos);
static void LoadAllCollision(void);
static void RemoveAllCollision(void);
- static void LoadCollision(const CVector2D &pos);
- static void RequestCollision(const CVector2D &pos);
- static void EnsureCollisionIsInMemory(const CVector2D &pos);
- static bool HasCollisionLoaded(const CVector2D &pos);
- static bool HasCollisionLoaded(eLevelName level) { return true; }; // TODO
+ static void LoadCollision(const CVector &pos, eLevelName level = LEVEL_GENERIC);
+ static void RequestCollision(const CVector &pos);
+ static void EnsureCollisionIsInMemory(const CVector &pos);
+ static bool DoScriptsWantThisIn(int32 slot);
+ static bool HasCollisionLoaded(eLevelName level);
+ static bool HasCollisionLoaded(const CVector &pos);
+ static void Load(bool, CPool<ColDef> *pool);
static ColDef *GetSlot(int slot) {
assert(slot >= 0);
diff --git a/src/control/Garages.h b/src/control/Garages.h
index 3d12d4a2..47de898f 100644
--- a/src/control/Garages.h
+++ b/src/control/Garages.h
@@ -293,4 +293,6 @@ public:
}
static bool IsThisGarageTypeSafehouse(uint8 type) { return FindSafeHouseIndexForGarageType(type) >= 0; }
+ static void SetupAnyGaragesForThisIsland(void) {} // TODO(LCS)
+
};
diff --git a/src/control/Script.h b/src/control/Script.h
index c30768b3..fa8a64cd 100644
--- a/src/control/Script.h
+++ b/src/control/Script.h
@@ -485,7 +485,7 @@ public:
static void SetObjectiveForAllPedsInCollective(int, eObjective);
#endif
- bool IsFortStauntonDestroyed() { return *(int32*)&ScriptSpace[FSDestroyedFlag] == 1; }
+ static bool IsFortStauntonDestroyed() { return FSDestroyedFlag && *(int32*)&ScriptSpace[FSDestroyedFlag] == 1; }
};
diff --git a/src/control/Script7.cpp b/src/control/Script7.cpp
index 601a979d..c50f0dea 100644
--- a/src/control/Script7.cpp
+++ b/src/control/Script7.cpp
@@ -423,9 +423,10 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command)
case COMMAND_REQUEST_COLLISION:
{
CollectParameters(&m_nIp, 2);
- CVector2D pos;
+ CVector pos;
pos.x = GET_FLOAT_PARAM(0);
pos.y = GET_FLOAT_PARAM(1);
+ pos.z = 0.0f;
CColStore::RequestCollision(pos);
return 0;
}
diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp
index 19339fb6..8cdc3a66 100644
--- a/src/core/Streaming.cpp
+++ b/src/core/Streaming.cpp
@@ -3150,6 +3150,46 @@ CStreaming::LoadSceneCollision(const CVector &pos)
CStreaming::LoadAllRequestedModels(false);
}
+//--LCS: TODO PSP and PS2
+// some things commented out that might be Rsl3D dependent
+void CStreaming::RegisterPointer(void *ptr, int, bool) {}
+RpAtomic *CStreaming::RegisterAtomic(RpAtomic *atomic, void *)
+{
+ return atomic;
+}
+void CStreaming::RegisterClump(RpClump *clump)
+{
+ RpClumpForAllAtomics(clump, RegisterAtomic, nil);
+}
+RpAtomic *CStreaming::RegisterInstance(RpAtomic *atomic, void *)
+{
+// RegisterPointer(&atomic->geometry, 2, true);
+ return atomic;
+}
+void CStreaming::RegisterInstance(RpClump *clump)
+{
+ RpClumpForAllAtomics(clump, RegisterInstance, nil);
+}
+
+void CStreaming::UnregisterPointer(void *ptr, int) {}
+RpAtomic *CStreaming::UnregisterAtomic(RpAtomic *atomic, void *)
+{
+ return atomic;
+}
+void CStreaming::UnregisterClump(RpClump *clump)
+{
+ RpClumpForAllAtomics(clump, UnregisterAtomic, nil);
+}
+RpAtomic *CStreaming::UnregisterInstance(RpAtomic *atomic, void *)
+{
+// UnregisterPointer(&atomic->geometry, 2);
+ return atomic;
+}
+void CStreaming::UnregisterInstance(RpClump *clump)
+{
+ RpClumpForAllAtomics(clump, UnregisterInstance, nil);
+}
+
void
CStreaming::MemoryCardSave(uint8 *buf, uint32 *size)
{
diff --git a/src/core/Streaming.h b/src/core/Streaming.h
index 66262721..4b9502e9 100644
--- a/src/core/Streaming.h
+++ b/src/core/Streaming.h
@@ -20,6 +20,7 @@ enum StreamFlags
STREAMFLAGS_40 = 0x40, // TODO(LCS): what's this
STREAMFLAGS_AMBIENT_SCRIPT_OWNED = 0x80,
+ // TODO(LCS): STREAMFLAGS_AMBIENT_SCRIPT_OWNED in STREAMFLAGS_CANT_REMOVE? check CColStore
STREAMFLAGS_CANT_REMOVE = STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_SCRIPTOWNED,
STREAMFLAGS_KEEP_IN_MEMORY = STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_SCRIPTOWNED|STREAMFLAGS_DEPENDENCY,
};
@@ -209,6 +210,17 @@ public:
static void LoadScene(const CVector &pos);
static void LoadSceneCollision(const CVector &pos);
+ static void RegisterPointer(void *ptr, int, bool);
+ static RpAtomic *RegisterAtomic(RpAtomic *atomic, void *);
+ static void RegisterClump(RpClump *clump);
+ static RpAtomic *RegisterInstance(RpAtomic *atomic, void *);
+ static void RegisterInstance(RpClump *clump);
+ static void UnregisterPointer(void *ptr, int);
+ static RpAtomic *UnregisterAtomic(RpAtomic *atomic, void *);
+ static void UnregisterClump(RpClump *clump);
+ static RpAtomic *UnregisterInstance(RpAtomic *atomic, void *);
+ static void UnregisterInstance(RpClump *clump);
+
static void MemoryCardSave(uint8 *buffer, uint32 *length);
static void MemoryCardLoad(uint8 *buffer, uint32 length);
diff --git a/src/modelinfo/BaseModelInfo.h b/src/modelinfo/BaseModelInfo.h
index a93040b1..3f691602 100644
--- a/src/modelinfo/BaseModelInfo.h
+++ b/src/modelinfo/BaseModelInfo.h
@@ -29,7 +29,9 @@ protected:
uint8 m_type;
uint8 m_num2dEffects;
bool m_bOwnsColModel;
+public: // need this in colstore
CColModel *m_colModel;
+protected:
int16 m_2dEffectsID;
int16 m_objectId;
uint16 m_refCount;
diff --git a/src/render/SpecialFX.cpp b/src/render/SpecialFX.cpp
index 35b0b2fc..3387cb2e 100644
--- a/src/render/SpecialFX.cpp
+++ b/src/render/SpecialFX.cpp
@@ -877,7 +877,7 @@ C3dMarkers::PlaceMarker(uint32 identifier, uint16 type, CVector &pos, float size
pMarker->m_Matrix.GetPosition() = pos;
if (pMarker->m_bFindZOnNextPlacement) {
- if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(CVector2D(pos))) {
+ if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(pos)) {
float z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z + 1.0f, nil);
if (z != 0.0f)
pMarker->m_Matrix.GetPosition().z = z - 0.05f * size;
@@ -893,7 +893,7 @@ C3dMarkers::PlaceMarker(uint32 identifier, uint16 type, CVector &pos, float size
pMarker->AddMarker(identifier, type, size, r, g, b, a, pulsePeriod, pulseFraction, rotateRate);
if (type == MARKERTYPE_CYLINDER || type == MARKERTYPE_0 || type == MARKERTYPE_2) {
- if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(CVector2D(pos))) {
+ if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(pos)) {
float z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z + 1.0f, nil);
if (z != 0.0f)
pos.z = z - 0.05f * size;