Skip to content

Commit

Permalink
Implement GhostObject and W3DGhostObject (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwil authored Apr 29, 2023
1 parent 1a1f9b3 commit 516471c
Show file tree
Hide file tree
Showing 13 changed files with 919 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ set(GAMEENGINE_SRC
platform/w3dengine/client/w3ddisplay.cpp
platform/w3dengine/client/w3dgameclient.cpp
platform/w3dengine/client/w3dgamelogic.cpp
platform/w3dengine/client/w3dghostobject.cpp
platform/w3dengine/client/w3dpoly.cpp
platform/w3dengine/client/w3dparticlesys.cpp
platform/w3dengine/client/w3dpropbuffer.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/draw/w3dmodeldraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class W3DModelDraw : public DrawModule, public ObjectDrawInterface
void Set_Model_State(ModelConditionInfo const *new_state);
void Stop_Client_Particle_Systems();

RenderObjClass *Get_Render_Object() { return m_renderObject; }
RenderObjClass *Get_Render_Object() const { return m_renderObject; }
bool Get_Fully_Obscured_By_Shroud() const { return m_fullyObscuredByShroud; }
const W3DModelDrawModuleData *Get_W3D_Model_Draw_Module_Data() const
{
Expand Down
53 changes: 53 additions & 0 deletions src/game/logic/object/ghostobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,60 @@
* LICENSE
*/
#include "ghostobject.h"
#include "gamelogic.h"
#include "object.h"
#include "xfer.h"

#ifndef GAME_DLL
GhostObjectManager *g_theGhostObjectManager = nullptr;
#endif

GhostObject::GhostObject() :
m_parentObject(nullptr),
m_geoType(GEOMETRY_SPHERE),
m_geoIsSmall(false),
m_geoMajorRadius(0.0f),
m_geoMinorRadius(0.0f),
m_cachedAngle(0.0f),
m_parentPartitionData(nullptr)
{
m_cachedPos.Zero();
}

void GhostObject::Xfer_Snapshot(Xfer *xfer)
{
unsigned char version = 1;
xfer->xferVersion(&version, 1);
ObjectID parent_id = OBJECT_UNK;

if (m_parentObject != nullptr) {
parent_id = m_parentObject->Get_ID();
}

xfer->xferObjectID(&parent_id);

if (xfer->Get_Mode() == XFER_LOAD) {
m_parentObject = g_theGameLogic->Find_Object_By_ID(parent_id);

if (parent_id != OBJECT_UNK) {
captainslog_relassert(
m_parentObject != nullptr, CODE_06, "GhostObject::Xfer_Snapshot - Unable to connect m_parentObject");
}
}

xfer->xferUser(&m_geoType, sizeof(m_geoType));
xfer->xferBool(&m_geoIsSmall);
xfer->xferReal(&m_geoMajorRadius);
xfer->xferReal(&m_geoMinorRadius);
xfer->xferReal(&m_cachedAngle);
xfer->xferCoord3D(&m_cachedPos);
}

GhostObjectManager::GhostObjectManager() : m_isUpdatingMapBoundary(false), m_isLoading(false), m_localPlayerIndex(0) {}

void GhostObjectManager::Xfer_Snapshot(Xfer *xfer)
{
unsigned char version = 1;
xfer->xferVersion(&version, 1);
xfer->xferInt(&m_localPlayerIndex);
}
50 changes: 39 additions & 11 deletions src/game/logic/object/ghostobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,61 @@
*/
#pragma once
#include "always.h"
#include "coord.h"
#include "geometry.h"
#include "snapshot.h"

class GhostObject;
class Object;
class PartitionData;

class GhostObject : public SnapShot
{
public:
GhostObject();
virtual ~GhostObject() {}
virtual void CRC_Snapshot(Xfer *xfer) override {}
virtual void Xfer_Snapshot(Xfer *xfer) override;
virtual void Load_Post_Process() override {}
virtual void SnapShot(int player) = 0;
virtual void Update_Parent_Object(Object *obj, PartitionData *data) = 0;
virtual void Free_SnapShot(int player) = 0;

protected:
Object *m_parentObject;
GeometryType m_geoType;
bool m_geoIsSmall;
float m_geoMajorRadius;
float m_geoMinorRadius;
float m_cachedAngle;
Coord3D m_cachedPos;
PartitionData *m_parentPartitionData;
};

class GhostObjectManager : public SnapShot
{
public:
virtual void CRC_Snapshot(Xfer *xfer) override;
GhostObjectManager();
virtual void CRC_Snapshot(Xfer *xfer) override {}
virtual void Xfer_Snapshot(Xfer *xfer) override;
virtual void Load_Post_Process() override;
virtual ~GhostObjectManager();
virtual void Reset();
virtual GhostObject *Add_Ghost_Object(Object *obj, PartitionData *data);
virtual void Remove_Ghost_Object(GhostObject *obj);
virtual void Set_Local_Player_Index(int index);
virtual void Update_Orphaned_Objects(int *unk, int unk2);
virtual void Release_Partition_Data();
virtual void Restore_Partition_Data();
virtual void Load_Post_Process() override {}
virtual ~GhostObjectManager() {}
virtual void Reset() {}
virtual GhostObject *Add_Ghost_Object(Object *obj, PartitionData *data) { return nullptr; }
virtual void Remove_Ghost_Object(GhostObject *obj) {}
virtual void Set_Local_Player_Index(int index) { m_localPlayerIndex = index; }
virtual void Update_Orphaned_Objects(int *unk, int unk2) {}
virtual void Release_Partition_Data() {}
virtual void Restore_Partition_Data() {}

void Set_Updating_Map_Boundary(bool update) { m_isUpdatingMapBoundary = update; }
void Set_Is_Loading(bool loading) { m_isLoading = loading; }

private:
protected:
int m_localPlayerIndex;
bool m_isUpdatingMapBoundary;
bool m_isLoading;
friend class W3DGhostObject;
};

#ifdef GAME_DLL
Expand Down
6 changes: 6 additions & 0 deletions src/game/logic/system/gamelogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "display.h"
#include "drawable.h"
#include "gameclient.h"
#include "ghostobject.h"
#include "mapobject.h"
#include "object.h"
#include "recorder.h"
Expand Down Expand Up @@ -384,3 +385,8 @@ TerrainLogic *GameLogic::Create_Terrain_Logic()
{
return new TerrainLogic();
}

GhostObjectManager *GameLogic::Create_Ghost_Object_Manager()
{
return new GhostObjectManager();
}
6 changes: 6 additions & 0 deletions src/game/logic/system/partitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,3 +835,9 @@ bool PartitionFilterAcceptByKindOf::Allow(Object *obj)
{
return obj->Is_KindOf_Multi(m_mustBeSet, m_mustBeClear);
}

void PartitionData::Friend_Set_Previous_Shrouded_Status(int index, ObjectShroudStatus status)
{
m_previousShroudedness[index] = status;
m_everSeen[index] = status != SHROUDED_UNK4;
}
3 changes: 3 additions & 0 deletions src/game/logic/system/partitionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class PartitionData : public MemoryPoolObject
void Remove_From_Dirty_Modules(PartitionData **dirtyModules);
void Make_Dirty(bool b);
ObjectShroudStatus Get_Shrouded_Status(int index);
ObjectShroudStatus Get_Previous_Shrouded_Status(int index) { return m_previousShroudedness[index]; }
void Friend_Set_Previous_Shrouded_Status(int index, ObjectShroudStatus status);
void Set_Ghost_Object(GhostObject *obj) { m_ghostObject = obj; }

private:
Object *m_object;
Expand Down
2 changes: 2 additions & 0 deletions src/hooker/setuphooks_zh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ void Setup_Hooks()
Hook_Any(0x004A7DA0, GameLogic::Find_Control_Bar_Override);
Hook_Any(0x004A7FA0, GameLogic::Add_TOC_Entry);
Hook_Any(0x004A7B50, GameLogic::Create_Terrain_Logic);
Hook_Any(0x004A7AF0, GameLogic::Create_Ghost_Object_Manager);

// shadermanager.h
Hook_Any(0x0074DF20, W3DShaderManager::Init);
Expand Down Expand Up @@ -2974,4 +2975,5 @@ void Setup_Hooks()

// w3dgamelogic.h
Hook_Any(0x00741E50, W3DGameLogic::Create_Terrain_Logic);
Hook_Any(0x00741EB0, W3DGameLogic::Create_Ghost_Object_Manager);
}
6 changes: 6 additions & 0 deletions src/platform/w3dengine/client/w3dgamelogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
* LICENSE
*/
#include "w3dgamelogic.h"
#include "w3dghostobject.h"
#include "w3dterrainlogic.h"

TerrainLogic *W3DGameLogic::Create_Terrain_Logic()
{
return new W3DTerrainLogic();
}

GhostObjectManager *W3DGameLogic::Create_Ghost_Object_Manager()
{
return new W3DGhostObjectManager();
}
Loading

0 comments on commit 516471c

Please sign in to comment.