HoverRace  2.0
MazeElement.h
Go to the documentation of this file.
1 
2 // MazeElement.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 "../Util/DllObjectFactory.h"
26 #include "../VideoServices/Viewport3D.h"
27 #include "ContactEffect.h"
28 #include "Shapes.h"
29 
30 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
31 # ifdef MR_ENGINE
32 # define MR_DllDeclare __declspec( dllexport )
33 # else
34 # define MR_DllDeclare __declspec( dllimport )
35 # endif
36 #else
37 # define MR_DllDeclare
38 #endif
39 
40 namespace HoverRace {
41  namespace Model {
42  class Level;
43  class Track;
44  }
45  namespace Parcel {
46  class ObjStream;
47  }
48 }
49 
50 class MR_FreeElementHandleClass;
51 using MR_FreeElementHandle = MR_FreeElementHandleClass*;
52 
53 namespace HoverRace {
54 namespace Model {
55 
57 {
58  int mDataLen;
59  const MR_UInt8 *mData;
60 };
61 
84 {
86 
87 public:
89  virtual ~Element() { }
90 
91  virtual void AddRenderer() { }
92 
93  // Contact effect interface
94  virtual void ApplyEffect(const ContactEffect *pEffect,
95  MR_SimulationTime pTime, MR_SimulationTime pDuration,
96  BOOL pValidDirection, MR_Angle pHorizontalDirection,
97  MR_Int32 pZMin, MR_Int32 pZMax,
98  Track &track)
99  {
100  HR_UNUSED(pEffect, pTime, pDuration,
101  pValidDirection, pHorizontalDirection,
102  pZMin, pZMax, track);
103  }
104 
105  virtual const ContactEffectList *GetEffectList() { return nullptr; }
106 
107  // Helper functions
108  void ApplyEffects(const ContactEffectList *pList,
109  MR_SimulationTime pTime, MR_SimulationTime pDuration,
110  BOOL pValidDirection, MR_Angle pHorizontalDirection,
111  MR_Int32 pZMin, MR_Int32 pZMax,
112  Track &track)
113  {
114  if (pList) {
115  for (auto lEffect : *pList) {
116  ApplyEffect(lEffect, pTime, pDuration,
117  pValidDirection, pHorizontalDirection,
118  pZMin, pZMax, track);
119  }
120  }
121  }
122 
123 public:
124  // Prevent overriding of the Serialize function.
125  void Serialize(Parcel::ObjStream&) override final { }
126 };
127 
129 {
130  using SUPER = Element;
131 
132 public:
134  virtual ~SurfaceElement() { }
135 
137  const MR_3DCoordinate &pUpperLeft, const MR_3DCoordinate &pLowerRight,
138  MR_Int32 pLen, MR_SimulationTime pTime)
139  {
140  HR_UNUSED(pDest, pUpperLeft, pLowerRight, pLen, pTime);
141  }
142 
144  int pNbVertex, const MR_2DCoordinate *pVertexList,
145  MR_Int32 pLevel, BOOL pTop, MR_SimulationTime pTime)
146  {
147  HR_UNUSED(pDest, pNbVertex, pVertexList, pLevel, pTop, pTime);
148  }
149 };
150 
152  public Element,
153  public std::enable_shared_from_this<FreeElement>
154 {
155  using SUPER = Element;
156 
157 public:
158  //HACK: Temporary default value for scripting.
159  FreeElement(const Util::ObjectFromFactoryId &id = { 0, 0 }) : SUPER(id)
160  {
161  }
162  virtual ~FreeElement() { }
163 
164  virtual void Render(VideoServices::Viewport3D *pDest,
165  MR_SimulationTime pTime)
166  {
167  HR_UNUSED(pDest, pTime);
168  }
169 
170  virtual void PlayInternalSounds() { }
171  virtual void PlayExternalSounds(int pDB, int pPan) { HR_UNUSED(pDB, pPan); }
172 
173  virtual ElementNetState GetNetState() const
174  {
175  return { 0, nullptr };
176  }
177 
178  virtual void SetNetState(int pDataLen, const MR_UInt8 *pData)
179  {
180  HR_UNUSED(pDataLen, pData);
181  assert(pDataLen == 0);
182  }
183 
184  //TODO: Track physics & collision data in a separate heap.
185 
186  // Logic interface (For simulation)
187 
195  virtual int Simulate(MR_SimulationTime pTimeSlice, Track &track, int pRoom)
196  {
197  HR_UNUSED(pTimeSlice, track);
198  return pRoom;
199  }
200 
205  virtual const ShapeInterface *GetObstacleShape() { return nullptr; }
206 
211  virtual const ShapeInterface *GetReceivingContactEffectShape() { return nullptr; }
212 
217  virtual const ShapeInterface *GetGivingContactEffectShape() { return nullptr; }
218 
219  // Perm state hook
220 
226  virtual bool AssignPermNumber(int pNumber)
227  {
228  HR_UNUSED(pNumber);
229  return false;
230  }
231 
232  virtual void SetOwnerId(int pOwnerId) { HR_UNUSED(pOwnerId); }
233 
234 public:
237 };
238 
239 } // namespace Model
240 } // namespace HoverRace
241 
242 #undef MR_DllDeclare
Unique identifier for a Factory Object.
Definition: DllObjectFactory.h:54
virtual ~FreeElement()
Definition: MazeElement.h:162
std::vector< ContactEffect * > ContactEffectList
Definition: ContactEffect.h:56
virtual void Render(VideoServices::Viewport3D *pDest, MR_SimulationTime pTime)
Definition: MazeElement.h:164
Level
Definition: Log.h:62
void ApplyEffects(const ContactEffectList *pList, MR_SimulationTime pTime, MR_SimulationTime pDuration, BOOL pValidDirection, MR_Angle pHorizontalDirection, MR_Int32 pZMin, MR_Int32 pZMax, Track &track)
Definition: MazeElement.h:108
Definition: WorldCoordinates.h:46
virtual bool AssignPermNumber(int pNumber)
Assign a permanent hook number.
Definition: MazeElement.h:226
virtual ~SurfaceElement()
Definition: MazeElement.h:134
const MR_UInt8 * mData
Definition: MazeElement.h:59
virtual const ContactEffectList * GetEffectList()
Definition: MazeElement.h:105
Definition: Viewport3D.h:53
virtual void RenderWallSurface(VideoServices::Viewport3D *pDest, const MR_3DCoordinate &pUpperLeft, const MR_3DCoordinate &pLowerRight, MR_Int32 pLen, MR_SimulationTime pTime)
Definition: MazeElement.h:136
Definition: Shapes.h:50
Definition: MazeElement.h:128
Definition: WorldCoordinates.h:75
virtual void PlayInternalSounds()
Definition: MazeElement.h:170
MR_Int16 MR_Angle
Definition: WorldCoordinates.h:96
SurfaceElement(const Util::ObjectFromFactoryId &id)
Definition: MazeElement.h:133
MR_Angle mOrientation
Definition: MazeElement.h:236
virtual void SetNetState(int pDataLen, const MR_UInt8 *pData)
Definition: MazeElement.h:178
MR_Int32 MR_SimulationTime
Definition: WorldCoordinates.h:106
Definition: MazeElement.h:151
Base class for all contact effects.
Definition: ContactEffect.h:44
virtual ElementNetState GetNetState() const
Definition: MazeElement.h:173
virtual void RenderHorizontalSurface(VideoServices::Viewport3D *pDest, int pNbVertex, const MR_2DCoordinate *pVertexList, MR_Int32 pLevel, BOOL pTop, MR_SimulationTime pTime)
Definition: MazeElement.h:143
int mDataLen
Definition: MazeElement.h:58
Base class for parcel serializers.
Definition: ObjStream.h:58
A track level.
Definition: Track.h:57
virtual const ShapeInterface * GetObstacleShape()
Get the shape that stops other elements&#39; movement.
Definition: MazeElement.h:205
virtual void SetOwnerId(int pOwnerId)
Definition: MazeElement.h:232
virtual const ShapeInterface * GetGivingContactEffectShape()
Get the shape that gives an effect when touching while moving.
Definition: MazeElement.h:217
int32_t MR_Int32
Definition: MR_Types.h:43
#define MR_DllDeclare
Definition: MazeElement.h:37
MR_3DCoordinate mPosition
Definition: MazeElement.h:235
Element(const Util::ObjectFromFactoryId &id)
Definition: MazeElement.h:88
FreeElement(const Util::ObjectFromFactoryId &id={0, 0})
Definition: MazeElement.h:159
Base class for object created with a Dll Factory.
Definition: DllObjectFactory.h:86
virtual void AddRenderer()
Definition: MazeElement.h:91
Represents all objects (wall, floor, ceiling, etc.) that can be found in a maze.
Definition: MazeElement.h:83
virtual int Simulate(MR_SimulationTime pTimeSlice, Track &track, int pRoom)
Advance the simulation.
Definition: MazeElement.h:195
virtual void PlayExternalSounds(int pDB, int pPan)
Definition: MazeElement.h:171
MR_FreeElementHandleClass * MR_FreeElementHandle
Definition: MazeElement.h:51
virtual const ShapeInterface * GetReceivingContactEffectShape()
Get the shape that gives an effect when touched by a moving element.
Definition: MazeElement.h:211
Definition: Announcement.h:24
virtual void ApplyEffect(const ContactEffect *pEffect, MR_SimulationTime pTime, MR_SimulationTime pDuration, BOOL pValidDirection, MR_Angle pHorizontalDirection, MR_Int32 pZMin, MR_Int32 pZMax, Track &track)
Definition: MazeElement.h:94
uint8_t MR_UInt8
Definition: MR_Types.h:40
virtual ~Element()
Definition: MazeElement.h:89
void Serialize(Parcel::ObjStream &) overridefinal
Definition: MazeElement.h:125
Definition: MazeElement.h:56