Skip to content

Commit 516471c

Browse files
authored
Implement GhostObject and W3DGhostObject (#906)
1 parent 1a1f9b3 commit 516471c

File tree

13 files changed

+919
-13
lines changed

13 files changed

+919
-13
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ set(GAMEENGINE_SRC
362362
platform/w3dengine/client/w3ddisplay.cpp
363363
platform/w3dengine/client/w3dgameclient.cpp
364364
platform/w3dengine/client/w3dgamelogic.cpp
365+
platform/w3dengine/client/w3dghostobject.cpp
365366
platform/w3dengine/client/w3dpoly.cpp
366367
platform/w3dengine/client/w3dparticlesys.cpp
367368
platform/w3dengine/client/w3dpropbuffer.cpp

src/game/client/draw/w3dmodeldraw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class W3DModelDraw : public DrawModule, public ObjectDrawInterface
399399
void Set_Model_State(ModelConditionInfo const *new_state);
400400
void Stop_Client_Particle_Systems();
401401

402-
RenderObjClass *Get_Render_Object() { return m_renderObject; }
402+
RenderObjClass *Get_Render_Object() const { return m_renderObject; }
403403
bool Get_Fully_Obscured_By_Shroud() const { return m_fullyObscuredByShroud; }
404404
const W3DModelDrawModuleData *Get_W3D_Model_Draw_Module_Data() const
405405
{

src/game/logic/object/ghostobject.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,60 @@
1313
* LICENSE
1414
*/
1515
#include "ghostobject.h"
16+
#include "gamelogic.h"
17+
#include "object.h"
18+
#include "xfer.h"
1619

1720
#ifndef GAME_DLL
1821
GhostObjectManager *g_theGhostObjectManager = nullptr;
1922
#endif
23+
24+
GhostObject::GhostObject() :
25+
m_parentObject(nullptr),
26+
m_geoType(GEOMETRY_SPHERE),
27+
m_geoIsSmall(false),
28+
m_geoMajorRadius(0.0f),
29+
m_geoMinorRadius(0.0f),
30+
m_cachedAngle(0.0f),
31+
m_parentPartitionData(nullptr)
32+
{
33+
m_cachedPos.Zero();
34+
}
35+
36+
void GhostObject::Xfer_Snapshot(Xfer *xfer)
37+
{
38+
unsigned char version = 1;
39+
xfer->xferVersion(&version, 1);
40+
ObjectID parent_id = OBJECT_UNK;
41+
42+
if (m_parentObject != nullptr) {
43+
parent_id = m_parentObject->Get_ID();
44+
}
45+
46+
xfer->xferObjectID(&parent_id);
47+
48+
if (xfer->Get_Mode() == XFER_LOAD) {
49+
m_parentObject = g_theGameLogic->Find_Object_By_ID(parent_id);
50+
51+
if (parent_id != OBJECT_UNK) {
52+
captainslog_relassert(
53+
m_parentObject != nullptr, CODE_06, "GhostObject::Xfer_Snapshot - Unable to connect m_parentObject");
54+
}
55+
}
56+
57+
xfer->xferUser(&m_geoType, sizeof(m_geoType));
58+
xfer->xferBool(&m_geoIsSmall);
59+
xfer->xferReal(&m_geoMajorRadius);
60+
xfer->xferReal(&m_geoMinorRadius);
61+
xfer->xferReal(&m_cachedAngle);
62+
xfer->xferCoord3D(&m_cachedPos);
63+
}
64+
65+
GhostObjectManager::GhostObjectManager() : m_isUpdatingMapBoundary(false), m_isLoading(false), m_localPlayerIndex(0) {}
66+
67+
void GhostObjectManager::Xfer_Snapshot(Xfer *xfer)
68+
{
69+
unsigned char version = 1;
70+
xfer->xferVersion(&version, 1);
71+
xfer->xferInt(&m_localPlayerIndex);
72+
}

src/game/logic/object/ghostobject.h

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,61 @@
1414
*/
1515
#pragma once
1616
#include "always.h"
17+
#include "coord.h"
18+
#include "geometry.h"
1719
#include "snapshot.h"
1820

1921
class GhostObject;
2022
class Object;
2123
class PartitionData;
2224

25+
class GhostObject : public SnapShot
26+
{
27+
public:
28+
GhostObject();
29+
virtual ~GhostObject() {}
30+
virtual void CRC_Snapshot(Xfer *xfer) override {}
31+
virtual void Xfer_Snapshot(Xfer *xfer) override;
32+
virtual void Load_Post_Process() override {}
33+
virtual void SnapShot(int player) = 0;
34+
virtual void Update_Parent_Object(Object *obj, PartitionData *data) = 0;
35+
virtual void Free_SnapShot(int player) = 0;
36+
37+
protected:
38+
Object *m_parentObject;
39+
GeometryType m_geoType;
40+
bool m_geoIsSmall;
41+
float m_geoMajorRadius;
42+
float m_geoMinorRadius;
43+
float m_cachedAngle;
44+
Coord3D m_cachedPos;
45+
PartitionData *m_parentPartitionData;
46+
};
47+
2348
class GhostObjectManager : public SnapShot
2449
{
2550
public:
26-
virtual void CRC_Snapshot(Xfer *xfer) override;
51+
GhostObjectManager();
52+
virtual void CRC_Snapshot(Xfer *xfer) override {}
2753
virtual void Xfer_Snapshot(Xfer *xfer) override;
28-
virtual void Load_Post_Process() override;
29-
virtual ~GhostObjectManager();
30-
virtual void Reset();
31-
virtual GhostObject *Add_Ghost_Object(Object *obj, PartitionData *data);
32-
virtual void Remove_Ghost_Object(GhostObject *obj);
33-
virtual void Set_Local_Player_Index(int index);
34-
virtual void Update_Orphaned_Objects(int *unk, int unk2);
35-
virtual void Release_Partition_Data();
36-
virtual void Restore_Partition_Data();
54+
virtual void Load_Post_Process() override {}
55+
virtual ~GhostObjectManager() {}
56+
virtual void Reset() {}
57+
virtual GhostObject *Add_Ghost_Object(Object *obj, PartitionData *data) { return nullptr; }
58+
virtual void Remove_Ghost_Object(GhostObject *obj) {}
59+
virtual void Set_Local_Player_Index(int index) { m_localPlayerIndex = index; }
60+
virtual void Update_Orphaned_Objects(int *unk, int unk2) {}
61+
virtual void Release_Partition_Data() {}
62+
virtual void Restore_Partition_Data() {}
3763

3864
void Set_Updating_Map_Boundary(bool update) { m_isUpdatingMapBoundary = update; }
65+
void Set_Is_Loading(bool loading) { m_isLoading = loading; }
3966

40-
private:
67+
protected:
4168
int m_localPlayerIndex;
4269
bool m_isUpdatingMapBoundary;
4370
bool m_isLoading;
71+
friend class W3DGhostObject;
4472
};
4573

4674
#ifdef GAME_DLL

src/game/logic/system/gamelogic.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "display.h"
1717
#include "drawable.h"
1818
#include "gameclient.h"
19+
#include "ghostobject.h"
1920
#include "mapobject.h"
2021
#include "object.h"
2122
#include "recorder.h"
@@ -384,3 +385,8 @@ TerrainLogic *GameLogic::Create_Terrain_Logic()
384385
{
385386
return new TerrainLogic();
386387
}
388+
389+
GhostObjectManager *GameLogic::Create_Ghost_Object_Manager()
390+
{
391+
return new GhostObjectManager();
392+
}

src/game/logic/system/partitionmanager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,9 @@ bool PartitionFilterAcceptByKindOf::Allow(Object *obj)
835835
{
836836
return obj->Is_KindOf_Multi(m_mustBeSet, m_mustBeClear);
837837
}
838+
839+
void PartitionData::Friend_Set_Previous_Shrouded_Status(int index, ObjectShroudStatus status)
840+
{
841+
m_previousShroudedness[index] = status;
842+
m_everSeen[index] = status != SHROUDED_UNK4;
843+
}

src/game/logic/system/partitionmanager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ class PartitionData : public MemoryPoolObject
159159
void Remove_From_Dirty_Modules(PartitionData **dirtyModules);
160160
void Make_Dirty(bool b);
161161
ObjectShroudStatus Get_Shrouded_Status(int index);
162+
ObjectShroudStatus Get_Previous_Shrouded_Status(int index) { return m_previousShroudedness[index]; }
163+
void Friend_Set_Previous_Shrouded_Status(int index, ObjectShroudStatus status);
164+
void Set_Ghost_Object(GhostObject *obj) { m_ghostObject = obj; }
162165

163166
private:
164167
Object *m_object;

src/hooker/setuphooks_zh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,7 @@ void Setup_Hooks()
15001500
Hook_Any(0x004A7DA0, GameLogic::Find_Control_Bar_Override);
15011501
Hook_Any(0x004A7FA0, GameLogic::Add_TOC_Entry);
15021502
Hook_Any(0x004A7B50, GameLogic::Create_Terrain_Logic);
1503+
Hook_Any(0x004A7AF0, GameLogic::Create_Ghost_Object_Manager);
15031504

15041505
// shadermanager.h
15051506
Hook_Any(0x0074DF20, W3DShaderManager::Init);
@@ -2974,4 +2975,5 @@ void Setup_Hooks()
29742975

29752976
// w3dgamelogic.h
29762977
Hook_Any(0x00741E50, W3DGameLogic::Create_Terrain_Logic);
2978+
Hook_Any(0x00741EB0, W3DGameLogic::Create_Ghost_Object_Manager);
29772979
}

src/platform/w3dengine/client/w3dgamelogic.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
* LICENSE
1414
*/
1515
#include "w3dgamelogic.h"
16+
#include "w3dghostobject.h"
1617
#include "w3dterrainlogic.h"
1718

1819
TerrainLogic *W3DGameLogic::Create_Terrain_Logic()
1920
{
2021
return new W3DTerrainLogic();
2122
}
23+
24+
GhostObjectManager *W3DGameLogic::Create_Ghost_Object_Manager()
25+
{
26+
return new W3DGhostObjectManager();
27+
}

0 commit comments

Comments
 (0)