GhostObject.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: GhostObject.h ////////////////////////////////////////////////////////////
  24. // Placeholder for objects that have been deleted but need to be maintained because
  25. // a player can see them fogged.
  26. // Author: Mark Wilczynski, August 2002
  27. #pragma once
  28. #ifndef _GHOSTOBJECT_H_
  29. #define _GHOSTOBJECT_H_
  30. #include "Lib/BaseType.h"
  31. #include "Common/Snapshot.h"
  32. // #define DEBUG_FOG_MEMORY ///< this define is used to force object snapshots for all players, not just local player.
  33. //Magic pointer value which indicates that a drawable pointer is actually invalid
  34. //because we're looking at a ghost object.
  35. #define GHOST_OBJECT_DRAWABLE 0xFFFFFFFF
  36. class Object;
  37. class PartitionData;
  38. enum GeometryType;
  39. enum ObjectID;
  40. class GhostObject : public Snapshot
  41. {
  42. public:
  43. GhostObject();
  44. virtual ~GhostObject();
  45. virtual void snapShot(int playerIndex)=0;
  46. virtual void updateParentObject(Object *object, PartitionData *mod)=0;
  47. virtual void freeSnapShot(int playerIndex)=0;
  48. inline PartitionData *friend_getPartitionData(void) const {return m_partitionData;}
  49. inline GeometryType getGeometryType(void) const {return m_parentGeometryType;}
  50. inline Bool getGeometrySmall(void) const {return m_parentGeometryIsSmall;}
  51. inline Real getGeometryMajorRadius(void) const {return m_parentGeometryMajorRadius;}
  52. inline Real getGeometryMinorRadius(void) const {return m_parentGeometryminorRadius;}
  53. inline Real getParentAngle(void) const {return m_parentAngle;}
  54. inline const Coord3D *getParentPosition(void) const {return &m_parentPosition;}
  55. protected:
  56. virtual void crc( Xfer *xfer );
  57. virtual void xfer( Xfer *xfer );
  58. virtual void loadPostProcess( void );
  59. Object *m_parentObject; ///< object which we are ghosting
  60. GeometryType m_parentGeometryType;
  61. Bool m_parentGeometryIsSmall;
  62. Real m_parentGeometryMajorRadius;
  63. Real m_parentGeometryminorRadius;
  64. Real m_parentAngle;
  65. Coord3D m_parentPosition;
  66. PartitionData *m_partitionData; ///< our PartitionData
  67. };
  68. class GhostObjectManager : public Snapshot
  69. {
  70. public:
  71. GhostObjectManager();
  72. virtual ~GhostObjectManager();
  73. virtual void reset(void);
  74. virtual GhostObject *addGhostObject(Object *object, PartitionData *pd);
  75. virtual void removeGhostObject(GhostObject *mod);
  76. virtual inline void setLocalPlayerIndex(int index) { m_localPlayer = index; }
  77. inline int getLocalPlayerIndex(void) { return m_localPlayer; }
  78. virtual void updateOrphanedObjects(int *playerIndexList, int numNonLocalPlayers);
  79. virtual void releasePartitionData(void); ///<saves data needed to later rebuild partition manager data.
  80. virtual void restorePartitionData(void); ///<restores ghost objects into the partition manager.
  81. inline void lockGhostObjects(Bool enableLock) {m_lockGhostObjects=enableLock;} ///<temporary lock on creating new ghost objects. Only used by map border resizing!
  82. inline void saveLockGhostObjects(Bool enableLock) {m_saveLockGhostObjects=enableLock;}
  83. protected:
  84. virtual void crc( Xfer *xfer );
  85. virtual void xfer( Xfer *xfer );
  86. virtual void loadPostProcess( void );
  87. Int m_localPlayer;
  88. Bool m_lockGhostObjects;
  89. Bool m_saveLockGhostObjects; ///< used to lock the ghost object system during a save/load
  90. };
  91. // the singleton
  92. extern GhostObjectManager *TheGhostObjectManager;
  93. #endif // _GAME_DISPLAY_H_