HoverRace  2.0
Level.h
Go to the documentation of this file.
1 
2 // Level.h
3 //
4 // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 //
22 
23 #pragma once
24 
25 #include "MazeElement.h"
26 #include "ShapeCollisions.h"
27 
28 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
29 # ifdef MR_ENGINE
30 # define MR_DllDeclare __declspec( dllexport )
31 # else
32 # define MR_DllDeclare __declspec( dllimport )
33 # endif
34 #else
35 # define MR_DllDeclare
36 #endif
37 
38 // Defines
39 #define MR_NB_MAX_PLAYER 32
40 #define MR_NB_PERNET_ACTORS 512
41 
42 // for game options (also found in TrackSelect.h)
43 #define OPT_ALLOW_WEAPONS 0x40
44 #define OPT_ALLOW_MINES 0x20
45 #define OPT_ALLOW_CANS 0x10
46 #define OPT_ALLOW_BASIC 0x08
47 #define OPT_ALLOW_BI 0x02
48 #define OPT_ALLOW_CX 0x04
49 #define OPT_ALLOW_EON 0x01
50 
51 // Class declaration
52 namespace HoverRace {
53  namespace Model {
54  class Track;
55  }
56  namespace Parcel {
57  class ObjStream;
58  }
59 }
60 
61 namespace HoverRace {
62 namespace Model {
63 
64 struct SectionId
65 {
66  enum eSectionType : MR_Int32 { eRoom, eFeature };
67 
70 
71  void Serialize(Parcel::ObjStream &pArchive);
72 };
73 
75 {
76  // This class will be derived for construction purpose by the MazeCompiler
77  // that is why it is only protected, not private
78  //
79  // This class will also be overrided by the simulator
80  // Simulator related methods and members will than have to be
81  // moved in the MR_SimulatorLevel class
82 
83 public:
84  enum { eNonClassified = -1, eMustBeDeleted = -2 };
85 
86 protected:
87  struct Section
88  {
89  int mNbVertex; // Number of vertex that compose the section
90 
91  // Geometry
96 
97  // Dounding box geometry
100 
101  // Wall textures
102  std::vector<std::shared_ptr<SurfaceElement>> mWallTexture;
103  std::shared_ptr<SurfaceElement> mFloorTexture;
104  std::shared_ptr<SurfaceElement> mCeilingTexture;
105 
106  // Methods
107  Section();
108  ~Section();
109 
110  void SerializeStructure(Parcel::ObjStream &pArchive);
111  };
112 
113  struct Feature : public Section
114  {
115  // Connectivity
117 
118  void SerializeStructure(Parcel::ObjStream &pArchive);
119  };
120 
121  struct Room : public Section
122  {
123  struct AudibleRoom
124  {
125  AudibleRoom();
126  ~AudibleRoom();
127 
128  void Serialize(Parcel::ObjStream &pArchive);
129 
130  // This class will have be modified if we want to take in account the
131  // fact that a closed door do not let pass the sound
133  int mNbVertexSources; // Number of connection from where the sound is comming
134  int *mVertexList; // List of the connections from where the sound is comming
135  BYTE *mSoundCoefficient; // Attenuation factor of the sound
136  };
137 
138  // Connectivity
139  int mNbChild;
140  int *mChildList; // Index of the child sections
141 
142  int *mNeighborList; // One entry per polygon side
143  // Sides with no Neighbor are mark with -1
144  // this is a Room specific member
145 
146  // Pre-computed inter-room effects
147  int mNbVisibleRoom; // Size of mVisibleRoomList
148  int *mVisibleRoomList; // List of the room that are visible from the current room
149  // This attribute apply only to Sections without parent
150 
152  SectionId *mVisibleFloorList; // Ordered floor list
153  SectionId *mVisibleCeilingList;// Ordered ceiling list
154 
155  int mNbAudibleRoom; // Theses members are only used by the server
156  AudibleRoom *mAudibleRoomList; // List of the room from where a sound can be heard from the current room
157 
158  // Methods
159  Room();
160  ~Room();
161 
162  void SerializeStructure(Parcel::ObjStream &pArchive);
163  };
164 
166  {
168 
169  public:
170  SectionShape(Section *section) : SUPER(), section(section) { }
171 
172  MR_Int32 XMin() const override { return section->mMin.mX; }
173  MR_Int32 XMax() const override { return section->mMax.mX; }
174  MR_Int32 YMin() const override { return section->mMin.mY; }
175  MR_Int32 YMax() const override { return section->mMax.mY; }
176  MR_Int32 ZMin() const override { return section->mFloorLevel; }
177  MR_Int32 ZMax() const override { return section->mCeilingLevel; }
178 
179  int VertexCount() const override { return section->mNbVertex; }
180 
181  MR_Int32 X(int pIndex) const override { return section->mVertexList[pIndex].mX ; }
182  MR_Int32 Y(int pIndex) const override { return section->mVertexList[pIndex].mY; }
183  MR_Int32 SideLen(int pIndex) const override { return section->mWallLen[pIndex]; }
184 
185  private:
187  };
188 
190  {
191  public:
192  FreeElementList() : mPrevLink(nullptr), mNext(nullptr) { }
193  ~FreeElementList();
194 
195  public:
196  void Unlink();
197  void LinkTo(FreeElementList **pPrevLink);
198 
199  static void SerializeList(Parcel::ObjStream &pArchive,
200  FreeElementList **pListHead);
201 
202  public:
205  std::shared_ptr<FreeElement> mElement;
206  };
207 
208  // Private Data
209  // Level structure
211 
212  int mNbRoom; // Number of room in the level
214 
215  int mNbFeature; // Number of features in the level
217 
218  char mGameOpts;
219 
220  // Main character starting position and references
222  int mPlayerTeam[MR_NB_MAX_PLAYER];
223  int mStartingRoom[MR_NB_MAX_PLAYER];
224  MR_3DCoordinate mStartingPosition[MR_NB_MAX_PLAYER];
225  MR_Angle mStartingOrientation[MR_NB_MAX_PLAYER];
226 
227  // FreeElements
230 
233 
234  // PermActor moving cache (Big patch since there is a smll bug in the design)
236  int mPermActorIndexCache[MR_NB_PERNET_ACTORS];
237  int mPermActorNewRoomCache[MR_NB_PERNET_ACTORS];
238 
239  // Broadcast hook
240  void (*mElementCreationBroadcastHook) (FreeElement *pElement, int pRoom, void *pHookData);
241  void (*mPermElementStateBroadcastHook) (FreeElement *pElement, int pRoom, int pPermId, void *pHookData);
243 
244  // Helper functions
245  int GetRealRoomRecursive(const MR_2DCoordinate &pPosition, int pOriginalSection, int = -1) const;
246 
247 public:
248  Level(Track &track, BOOL pAllowRendering = FALSE, char pGameOpts = 1);
249  Level(const Level&) = delete;
250  ~Level();
251 
252  Level &operator=(const Level&) = delete;
253 
254  // Network stuff
255  void SetBroadcastHook(
256  void (*pCreationHook)(FreeElement*, int, void*),
257  void (*pStateHook)(FreeElement*, int, int, void*),
258  void *pHookData);
259 
260  // Serialisation functions
261  void Serialize(Parcel::ObjStream &pArchive);
262 
263  // Structure interrogation functions
264  int GetRoomCount() const;
265 
266  // Starting pos related stuff
267  int GetPlayerCount() const;
268  int GetPlayerTeam(int pPlayerId) const;
269  int GetStartingRoom(int pPlayerId) const;
270  const MR_3DCoordinate &GetStartingPos(int pPlayerId) const;
271  MR_Angle GetStartingOrientation(int pPlayerId) const;
272 
273  // Structural information
274  PolygonShape *GetRoomShape(int pRoomId) const;
275  MR_Int32 GetRoomWallLen(int pRoomId, int pVertex) const;
276  MR_Int32 GetRoomBottomLevel(int pRoomId) const;
277  MR_Int32 GetRoomTopLevel(int pRoomId) const;
278  const MR_2DCoordinate &GetRoomVertex(int pRoomId, int pVertex) const;
279  int GetRoomVertexCount(int pRoomId) const;
280 
281  PolygonShape *GetFeatureShape(int pFeatureId) const;
282  MR_Int32 GetFeatureWallLen(int pFeatureId, int pVertex) const;
283  MR_Int32 GetFeatureBottomLevel(int pFeatureId) const;
284  MR_Int32 GetFeatureTopLevel(int pFeatureId) const;
285  const MR_2DCoordinate &GetFeatureVertex(int pFeatureId, int pVertex) const;
286  int GetFeatureVertexCount(int pFeatureId) const;
287 
288  const int *GetVisibleZones(int pRoomId, int &pNbVisibleZones) const;
289  int GetNbVisibleSurface(int pRoomId) const;
290  const SectionId *GetVisibleFloorList(int pRoomId) const;
291  const SectionId *GetVisibleCeilingList(int pRoomId) const;
292  int GetNeighbor(int pRoomId, int pVertex) const;
293  int GetParent(int pFeatureId) const;
294  int GetFeatureCount(int pRoomId) const;
295  int GetFeature(int pRoomId, int pChildIndex) const;
296 
297  SurfaceElement *GetRoomWallElement(int pRoomId, size_t pVertex) const;
298  SurfaceElement *GetRoomBottomElement(int pRoomId) const;
299  SurfaceElement *GetRoomTopElement(int pRoomId) const;
300 
301  SurfaceElement *GetFeatureWallElement(int pFeatureId, size_t pVertex) const;
302  SurfaceElement *GetFeatureBottomElement(int pFeatureId) const;
303  SurfaceElement *GetFeatureTopElement(int pFeatureId) const;
304 
305  // Free element content interrogation and manipulation
306  MR_FreeElementHandle GetFirstFreeElement(int pRoom) const;
307  static MR_FreeElementHandle GetNextFreeElement(MR_FreeElementHandle pHandle);
308  static FreeElement *GetFreeElement(MR_FreeElementHandle pHandle);
309  MR_FreeElementHandle GetPermanentElementHandle(int pElem) const;
310 
311  // -1 mean non classified
312  void MoveElement(MR_FreeElementHandle pHandle, int pNewRoom);
313  // -1 mean non classified
314  MR_FreeElementHandle InsertElement(std::shared_ptr<FreeElement> pElement,
315  int pNewRoom, BOOL Broadcast = FALSE);
316  static void DeleteElement(MR_FreeElementHandle pHandle);
317 
318  // Set and broadcast the newporition
319  void SetPermElementPos(int pPermElement, int pRoom, const MR_3DCoordinate &pNewPos);
320  void FlushPermElementPosCache();
321 
322  // Element movement functions
323  int FindRoomForPoint(const MR_2DCoordinate &pPosition, int pStartingRoom) const;
324 
325  void GetRoomContact(int pRoom, const ShapeInterface *pShape, RoomContactSpec &pAnswer);
326 
327  BOOL GetRoomWallContactOrientation(int pRoom, int pWall, const ShapeInterface *pShape, MR_Angle &pAnswer);
328 
329  BOOL GetFeatureContact(int pFeature, const ShapeInterface *pShape, ContactSpec &pAnswer);
330 
331  BOOL GetFeatureContactOrientation(int pFeature, const ShapeInterface *pShape, MR_Angle &pAnswer);
332 
333 private:
335 };
336 
337 } // namespace Model
338 } // namespace HoverRace
339 
340 #undef MR_DllDeclare
FreeElementList * mFreeElementNonClassifiedList
Definition: Level.h:228
int VertexCount() const override
Definition: Level.h:179
Track & track
Definition: Level.h:334
MR_Int32 YMin() const override
Definition: Level.h:174
std::shared_ptr< SurfaceElement > mCeilingTexture
Definition: Level.h:104
MR_2DCoordinate mMax
Definition: Level.h:99
Definition: ShapeCollisions.h:61
std::vector< std::shared_ptr< SurfaceElement > > mWallTexture
Definition: Level.h:102
int mNbPlayer
Definition: Level.h:221
eSectionType
Definition: Level.h:66
Room * mRoomList
Definition: Level.h:213
Level
Definition: Log.h:62
Section * section
Definition: Level.h:186
Definition: Level.h:64
MR_2DCoordinate mMin
Definition: Level.h:98
Definition: WorldCoordinates.h:46
#define MR_NB_PERNET_ACTORS
Definition: Level.h:40
eSectionType mType
Definition: Level.h:68
FreeElementList()
Definition: Level.h:192
MR_Int32 YMax() const override
Definition: Level.h:175
#define MR_NB_MAX_PLAYER
Definition: Level.h:39
int mNbPermNetActor
Definition: Level.h:231
int mSectionSource
Definition: Level.h:132
char mGameOpts
Definition: Level.h:218
int mPermActorCacheCount
Definition: Level.h:235
Definition: Shapes.h:50
void * mBroadcastHookData
Definition: Level.h:242
Definition: MazeElement.h:128
Definition: WorldCoordinates.h:75
AudibleRoom * mAudibleRoomList
Definition: Level.h:156
MR_Int16 MR_Angle
Definition: WorldCoordinates.h:96
SectionId * mVisibleFloorList
Definition: Level.h:152
MR_Int32 XMax() const override
Definition: Level.h:173
int mNbVisibleRoom
Definition: Level.h:147
int mNbChild
Definition: Level.h:139
Feature * mFeatureList
Definition: Level.h:216
MR_Int32 mFloorLevel
Definition: Level.h:92
int mParentSectionIndex
Definition: Level.h:116
Definition: MazeElement.h:151
int * mVisibleRoomList
Definition: Level.h:148
FreeElementList * mNext
Definition: Level.h:204
int mNbVertexSources
Definition: Level.h:133
int mNbAudibleRoom
Definition: Level.h:155
Base class for parcel serializers.
Definition: ObjStream.h:58
A track level.
Definition: Track.h:57
int * mNeighborList
Definition: Level.h:142
int32_t MR_Int32
Definition: MR_Types.h:43
int mNbRoom
Definition: Level.h:212
FreeElementList ** mFreeElementClassifiedByRoomList
Definition: Level.h:229
Definition: Shapes.h:120
MR_Int32 ZMin() const override
Definition: Level.h:176
int mNbVisibleSurface
Definition: Level.h:151
MR_Int32 * mWallLen
Definition: Level.h:95
Definition: Level.h:121
Definition: Level.h:113
int mNbVertex
Definition: Level.h:89
MR_Int32 X(int pIndex) const override
Definition: Level.h:181
BOOL mAllowRendering
Definition: Level.h:210
MR_Int32 Y(int pIndex) const override
Definition: Level.h:182
FreeElementList ** mPrevLink
Definition: Level.h:203
Definition: Level.h:87
BYTE * mSoundCoefficient
Definition: Level.h:135
Definition: Level.h:74
MR_Int32 ZMax() const override
Definition: Level.h:177
MR_FreeElementHandleClass * MR_FreeElementHandle
Definition: MazeElement.h:51
int * mVertexList
Definition: Level.h:134
Definition: Announcement.h:24
std::shared_ptr< SurfaceElement > mFloorTexture
Definition: Level.h:103
#define MR_DllDeclare
Definition: Level.h:35
MR_Int32 XMin() const override
Definition: Level.h:172
SectionId * mVisibleCeilingList
Definition: Level.h:153
MR_Int32 SideLen(int pIndex) const override
Definition: Level.h:183
Definition: ShapeCollisions.h:67
MR_2DCoordinate * mVertexList
Definition: Level.h:94
int mNbFeature
Definition: Level.h:215
MR_Int32 mId
Definition: Level.h:69
std::shared_ptr< FreeElement > mElement
Definition: Level.h:205
SectionShape(Section *section)
Definition: Level.h:170
int * mChildList
Definition: Level.h:140
MR_Int32 mCeilingLevel
Definition: Level.h:93