Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cMapBase.h
Go to the documentation of this file.
1 //
5 
6 #ifndef _INC_cMapBase_H
7 #define _INC_cMapBase_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "GrayMapData.h"
13 #include "CMapKeys.h"
14 #include "cMapTime.h"
15 
23 
24 namespace GrayMapData
25 {
26  enum MAP_LOD_TYPE //
27  {
30  // (Zone (64K), Oct (8192), Sector (1024), Block (128))
31 
32  MAP_LOD_BLOCK = 0, // 1 meter per height point. smallest patch unit for map. 128 meters across.
33  MAP_LOD_SECTOR, // 8 meters per height point. 1K
35  MAP_LOD_ZONE, // 64K
36  MAP_LOD_WORLD, // Max size of the world map
37  };
38 
39  const int MAP_LOD_RATIO = 8;
40 
42  typedef int MAP_PATCH_POINT_t;
44 
45 #define MAP_SCALE(lod) (1<<((lod)*3))
46 #define MAP_SIZE(lod) (MAP_SCALE(lod) * MAP_PATCH_POINTS)
47 
48  enum MAP_LIMITS_TYPE // various limits in meters. (MAP_METERI_t)
49  {
50  MAP_MIN_X = 0, // meters
51  MAP_MAX_X = MAP_SIZE(MAP_LOD_WORLD), // MAP_METERI_t = arbitrary max size.
52 
53  MAP_MIN_Y = 0, // meters
54  MAP_MAX_Y = MAP_SIZE(MAP_LOD_WORLD), // MAP_METERI_t = arbitrary max size.
55 
56  MAP_MIN_Z = -1000, // meters height // arbitrary for objects (not just height map). MAP_METERf_t
57  MAP_MAX_Z = 10000, // meters height // arbitrary for objects (not just height map)
58  MAP_BAD_Z = -10000, // a bad height means the patch didn't load! MAP_METERf_t
59 
60  MAP_HEIGHT_MIN = -100, // (in meters) this just applies to the height map. MAP_METERf_t
61  MAP_HEIGHT_SEA = 0, // (in meters) for sea level. MAP_METERf_t
62  MAP_HEIGHT_MAX = 2521, // (in meters) = 65536*MAP_HEIGHT_SCALE + MAP_HEIGHT_MIN. This just applies to the height map
63 
64  MAP_VIEWDIST_TER_MAX = 10000, // farthest we will see terrain. (MAP_METERI_t)
65  MAP_VIEWDIST_OBJ_MAX = 2000, // farthest distance server will send objects to us. (MAP_METERI_t)
66 
67  MAP_VIEWDIST_TER_DEF = 1000, // default FAR default. MAP_METERI_t MAP_VIEWDIST_TER_MAX
68  MAP_VIEWDIST_OBJ_DEF = 300, // default distance server will send objects to us. MAP_METERI_t MAP_VIEWDIST_OBJ_MAX
69  };
70 
71  const D3DVALUE MAP_VIEWDIST_NEAR_DEF = 0.3f; // near plane.
72  const D3DVALUE MAP_VIEWDIST_MIN = 0.1f; // Inside viewers head.
73 
74  enum MAP_CHANNEL_TYPE_ // m_ChannelsLoaded
75  {
78 
80 
81  // The data channels for a patch.
82  MAP_CHANNEL_Height = 0x0001,
83  MAP_CHANNEL_Normal = 0x0002,
86 
87  MAP_CHANNEL_Script = 0x0020,
88  MAP_CHANNEL_All = 0x003F,
89 
90  // Flags.
91  // More specific change info.
92  MAP_CHANNEL_Height_LegX = 0x0100, // this leg/skirt has changed so we need to adjust the skirt of my neighbor. (x=0)
93  MAP_CHANNEL_Height_LegY = 0x0200, // this leg/skirt has changed so we need to adjust the skirt of my neighbor. (y=0)
94  MAP_CHANNEL_Surface_LegX = 0x0400, // this leg/skirt has changed so we need to adjust the skirt of my neighbor.
95  MAP_CHANNEL_Surface_LegY = 0x0800, // this leg/skirt has changed so we need to adjust the skirt of my neighbor.
96 
97  // special read flags.
101  MAP_CHANNEL_Now = 0x8000,
102  };
103  typedef WORD MAP_CHANNEL_t; // Mask of MAP_CHANNEL_TYPE_.
104 
105  //**************************************************************
106  // MAP_CHANNEL_Height
107  // we typically use 16 bit Greyscale height map. MAP_HEIGHT_SEA
108  typedef unsigned short MAP_HEIGHT_t; // Raw 16 bit value from the height map image. use MAP_HEIGHT_SCALE and MAP_HEIGHT_MIN to get meters.
109  const MAP_HEIGHT_t MAP_HEIGHT_UNITS = 0xFFFF; // RAW max for 16 bit units.
110  const MAP_METERf_t MAP_HEIGHT_SCALE = 0.04f; // height map to world meters, 1 height map unit = 4cm
111 
112  //**************************************************************
113 
114  typedef BYTE MAP_SURFACE_ID_t; // high detail texture id in use for this location. from Surfaces.scp
116  {
118  MAP_SURFACE_Legacy = 0, // just let the underlying patch MAP_CHANNEL_Texture show thru.
119  // Snow, Wood, Ice, Dirt, Grass, Stone, Pavers, etc.
120  MAP_SURFACE_Hole = 254, // non blocking hole in the terrain.
122  };
123 
124  //**************************************************************
125 
127  {
128  // General class of the terrain at a point. (for physics and footstep noise)
129  // Might derive this from MAP_SURFACE_TYPE or MAP_CHANNEL_Texture color at a point ??
130  // NOTE: This is NOT how the char is responding to the terrain (flying,swimming,walking,etc)
131  MAP_TERRAIN_NONE = 0, // in the air. (may be flying or falling)
132 
133  MAP_TERRAIN_STONE, // faster move ?
135  MAP_TERRAIN_DIRT, // default surface.
137  MAP_TERRAIN_MUD, // swampy
139  MAP_TERRAIN_ICE, // slippery. low traction.
140 
141  // Not on the terrain anymore.
142 
143  MAP_TERRAIN_WATER_SHALLOW, // shallow water. feet splashing.
144  MAP_TERRAIN_WATER_SURFACE, // deep water. but swimming at top
145  MAP_TERRAIN_WATER_DEEP, // deep water. (may be swimming or dropping)
146  MAP_TERRAIN_WATER_BOTTOM, // deep under water walking on the bottom
147 
148  MAP_TERRAIN_UnderGround, // underground in a chamber (object)
149  MAP_TERRAIN_BURIED, // stuck underground ?
151 
152  MAP_TERRAIN_MASK_ANY = 0x7fffffff,
153  };
154 
155  typedef DWORD MAP_TERRAIN_MASK_t; // Mask of bits from above. _1BITMASK(MAP_TERRAIN_DIRT)
156 
157  class cMapPatch;
160  class cMapEntity;
161 
162  extern GRAYMAPDATA_LINK cCoordSpaceDX g_Coords; // convert DX render to/from map/world coord space.
163 
165  {
169 
170  public:
171  float m_FadeBias; // shader controls for drawing water.
172  float m_FadeExp;
173  D3DCOLOR m_ColorDef; // default color for water. can be overloaded by each water object.
174 
175  MAP_METERf_t m_SeaLevelDef; // default sea level water height. for new created water blocks. MAP_HEIGHT_SEA
176 
177  public:
179  : m_FadeBias(0.1f)
180  , m_FadeExp(4.0f)
181  , m_ColorDef(D3DCOLOR_ARGB(0xb2, 0, 0, 0))
182  , m_SeaLevelDef(100) // MAP_HEIGHT_SEA
183  {
184  }
185  };
186 
188  {
194  public:
195  cMapBase(const char* pszMapName = "Map");
196  virtual ~cMapBase();
197 
198  HRESULT LoadMap(const FILECHAR_t* pszInstallPath, const FILECHAR_t* pszMapName = "Map");
199 
200  static bool GRAYCALL IsValidPatchSize(MAP_METERI_t iSize);
201 
202  virtual bool isPatchInBounds(const cMapPatch* pPatch) const; // in current view bounds?
203  virtual cMapPatchPtr LoadPatchXY(MAP_METERI_t x, MAP_METERI_t y, MAP_METERI_t iSize, MAP_CHANNEL_t uLoadFlags = 0);
204  cMapPatchPtr LoadPatchBest(MAP_METERI_t x, MAP_METERI_t y, MAP_METERI_t iSize, MAP_CHANNEL_t uLoadFlags = 0);
205 
206  bool ClampPointDynamic(cPoint3f& ptW) const;
207 
208  // MAP_CHANNEL_Height
211  {
214  return GetHeightAt(ptW.m_x, ptW.m_y, iSize, uFlags);
215  }
217  {
218  v.x = x;
219  v.z = y;
220  v.y = GetHeightAt(g_Coords.CvtRenderToWorld(v), MAP_SIZE(MAP_LOD_BLOCK));
221  }
222 
223  bool SetHeightAt(MAP_METERI_t x, MAP_METERI_t y, MAP_METERf_t iHeight, MAP_METERI_t iSize);
224  bool SetHeightAt(const cPoint3f& ptW, MAP_METERI_t iSize)
225  {
226  return SetHeightAt((MAP_METERI_t)ptW.m_x, (MAP_METERI_t)ptW.m_y, ptW.m_z, iSize);
227  }
228 
229  GINTERSECT_TYPE GetHeightRayContactPatch(cPoint3f& ptWContact, const cPoint3f& ptWOrigin, const cVector3f& avDir, cPoint3f& ptWPosNext, float fMaxRange, MAP_METERI_t iSize = MAP_SIZE(MAP_LOD_BLOCK));
230  bool GetHeightRayContact(cPoint3f& ptWContact, const cPoint3f& ptWOrigin, const cVector3f& avDir, float fMaxRange = 1000.0f, MAP_METERI_t iSize = MAP_SIZE(MAP_LOD_BLOCK));
231 
232  // MAP_CHANNEL_Surface
233  MAP_SURFACE_ID_t GetSurfacePt(MAP_METERI_t x, MAP_METERI_t y);
234  bool SetSurfacePt(MAP_METERI_t x, MAP_METERI_t y, MAP_SURFACE_ID_t eSurfaceID);
235 
236  // MAP_CHANNEL_Normal
237  float GetNormalAt(OUT cVector3f& vNorm, MAP_METER_t x, MAP_METER_t y, MAP_METERI_t iSize);
238  float GetNormalAt(OUT cVector3f& vNorm, const cPoint3f& ptW, MAP_METERI_t iSize)
239  {
240  return GetNormalAt(vNorm, ptW.m_x, ptW.m_y, iSize);
241  }
242 
243  float GetNormalGradeAt(MAP_METER_t x, MAP_METER_t y, MAP_METERI_t iSize); // terrain grade at a point. 0 to 1
244  float GetNormalGradeAt(const cPoint3f& ptW, MAP_METERI_t iSize) // terrain grade at a point. 0 to 1
245  {
246  return GetNormalGradeAt(ptW.m_x, ptW.m_y, iSize);
247  }
248  void GetNormalBounce(MAP_METER_t x, MAP_METER_t y, const cVector3f& vApproach, cVector3f& vBounce);
249 
250  // MAP_CHANNEL_Water
251  MAP_METER_t GetWaterLevel(MAP_METER_t x, MAP_METER_t y, MAP_METERI_t iSize);
253  {
254  return GetWaterLevel(ptW.m_x, ptW.m_y, iSize);
255  }
256 
257  // Derived
258  MAP_TERRAIN_TYPE GetTerrainType(const cPoint3f& pt, MAP_METERf_t fCharHeight, cVector3f* pvNorm, MAP_METERf_t* pfGroundLevel = nullptr, MAP_METERf_t* pfWaterLevel = nullptr);
259 
260  STDMETHOD(s_PropPut)(const cScriptableProp* pProp, const cVariant& vVal);
261  STDMETHOD(s_PropGet)(const cScriptableProp* pProp, OUT cVariant& vValRet);
262  STDMETHOD(SetObjStateLoaded)(); // extra cleanup at the end of the load.
263 
265 
266  public:
269  enum P_TYPE_
270  {
271 #define cMapBaseProp(a,b,c,d,e) P_##a,
272 #include "cMapBaseProps.tbl"
273 #undef cMapBaseProp
275  };
276  static cScriptableProp sm_Props[P_QTY + 1];
277 
278  cValueRange<MAP_METERI_t> m_SizeHeight; // min/max patch sizes for patches that have height maps. MAP_SIZE(MAP_LOD_SECTOR),MAP_SIZE(MAP_LOD_OCTANT)
279 
280  // real bounds of the map. (GM's can go outside this?)
281  cWinSize m_MapSize; // max size of the map in meters. ASSUME % MAP_SIZE(MAP_LOD_SECTOR) = 0
282  cRectI m_MapDynamic; // Restrict the player/dynamic objects to this rect of map.
283 
284  cMapWaterDef m_WaterDef; // default params for water to be displayed.
285 
286  // For map SCP file crypting.
287  CMapKeys m_MapKeys; // cache the crypt keys for reading parts of this map.
288  };
289 };
290 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYMAPDATA_LINK
Definition: GrayMapData.h:13
float D3DVALUE
Definition: MathDX.h:18
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define D3DCOLOR_ARGB(a, r, g, b)
Definition: cColorRef.h:28
DWORD D3DCOLOR
Stuff normally defined in windows.h or DirectX headers.
Definition: cColorRef.h:24
#define MAP_SIZE(lod)
size of a patch (in meters (MAP_METERI_t))
Definition: cMapBase.h:46
Definition: cMapCommon.h:42
Definition: cCoordSpace.h:20
cPoint3f CvtRenderToWorld(const cVector3f &vPt) const
Definition: cCoordSpace.h:73
Definition: cRectI.h:22
Definition: cScriptableObj.h:26
Definition: cScriptableInterface.h:97
Definition: cVariant.h:26
TYPE m_z
Definition: cVecT.h:544
TYPE y
Definition: cVecT.h:545
TYPE z
Definition: cVecT.h:545
TYPE m_x
Definition: cVecT.h:544
TYPE m_y
Definition: cVecT.h:544
TYPE x
Definition: cVecT.h:545
Definition: cVector.h:94
Definition: WinTypes.h:128
Definition: cMapKeys.h:49
Definition: cMapBase.h:188
cMapWaterDef m_WaterDef
Definition: cMapBase.h:284
CHEAPOBJECT_IMPL
Definition: cMapBase.h:267
cValueRange< MAP_METERI_t > m_SizeHeight
Definition: cMapBase.h:278
float GetNormalGradeAt(const cPoint3f &ptW, MAP_METERI_t iSize)
Definition: cMapBase.h:244
P_TYPE_
Definition: cMapBase.h:270
@ P_QTY
Definition: cMapBase.h:274
MAP_METERf_t GetHeightAt(const cPoint3f &ptW, MAP_METERI_t iSize, MAP_CHANNEL_t uFlags=MAP_CHANNEL_Height)
Definition: cMapBase.h:210
MAP_METER_t GetWaterLevel(const cPoint3f &ptW, MAP_METERI_t iSize)
Definition: cMapBase.h:252
cRectI m_MapDynamic
Definition: cMapBase.h:282
bool SetHeightAt(const cPoint3f &ptW, MAP_METERI_t iSize)
Definition: cMapBase.h:224
cWinSize m_MapSize
Definition: cMapBase.h:281
CMapKeys m_MapKeys
Definition: cMapBase.h:287
float GetNormalAt(OUT cVector3f &vNorm, const cPoint3f &ptW, MAP_METERI_t iSize)
Definition: cMapBase.h:238
void GetHeightVert(cVector3f &v, DVALUEDEF_t x, DVALUEDEF_t y)
Definition: cMapBase.h:216
Definition: cMapEntity.h:76
Definition: cMapPatch.h:23
Definition: cMapBase.h:165
MAP_METERf_t m_SeaLevelDef
Definition: cMapBase.h:175
D3DCOLOR m_ColorDef
Definition: cMapBase.h:173
float m_FadeExp
Definition: cMapBase.h:172
float m_FadeBias
Definition: cMapBase.h:171
cMapWaterDef()
Definition: cMapBase.h:178
Definition: cHeapObject.h:38
Definition: cThreadLockRef.h:44
double MAP_METER_t
float meters for x,y,z, similar to MAP_METERI_t. also D3DVALUE or DVALUEDEF_t METERSf_t
Definition: cMapCommon.h:22
float DVALUEDEF_t
similar to D3DVALUE in DX. the basic default dimension type. DVALUEDEF_t
Definition: cVecT.h:34
GINTERSECT_TYPE
Definition: cVecT.h:20
Definition: GrayMapData.cpp:12
const int MAP_LOD_RATIO
Ratio of one LOD to the next. i.e. a parent patch has (max) <= MAP_LOD_RATIO^2 immediate children.
Definition: cMapBase.h:39
WORD MAP_CHANNEL_t
Definition: cMapBase.h:103
const MAP_METERf_t MAP_HEIGHT_SCALE
Definition: cMapBase.h:110
int MAP_PATCH_POINT_t
this gives the number of samples in the heightmap file: 128 means a 129x129 file (include skirt pixel...
Definition: cMapBase.h:42
const D3DVALUE MAP_VIEWDIST_MIN
Definition: cMapBase.h:72
DWORD MAP_TERRAIN_MASK_t
Definition: cMapBase.h:155
BYTE MAP_SURFACE_ID_t
Definition: cMapBase.h:114
MAP_CHANNEL_TYPE_
Definition: cMapBase.h:75
@ MAP_CHANNEL_NonCrit
get cached data only else just fail. (or out of bounds)
Definition: cMapBase.h:98
@ MAP_CHANNEL_Height
the height map. MAP_HEIGHT_t
Definition: cMapBase.h:82
@ MAP_CHANNEL_Surface_LegY
Definition: cMapBase.h:95
@ MAP_CHANNEL_Surface_LegX
Definition: cMapBase.h:94
@ MAP_CHANNEL_All
never used with MAP_CHANNEL_NonCrit ?
Definition: cMapBase.h:88
@ MAP_CHANNEL_Normal
always computed normal/bump map. (NOT loaded from file)
Definition: cMapBase.h:83
@ MAP_CHANNEL_Surface
the detailed ground surfaces. (detailed patch textures) (for roads, etc) (TODO Make this into an obje...
Definition: cMapBase.h:84
@ MAP_CHANNEL_Height_LegX
Definition: cMapBase.h:92
@ MAP_CHANNEL_Placement
going to place an object. (must have proper height info)
Definition: cMapBase.h:99
@ MAP_CHANNEL_NONE
Definition: cMapBase.h:79
@ MAP_CHANNEL_Script
the script listing all the child objects in the patch. includes water level.
Definition: cMapBase.h:87
@ MAP_CHANNEL_Height_LegY
Definition: cMapBase.h:93
@ MAP_CHANNEL_IgnoreBounds
load even if outside bounds. (usually for very large objects)
Definition: cMapBase.h:100
@ MAP_CHANNEL_Now
i need this data now. can't wait for it.
Definition: cMapBase.h:101
@ MAP_CHANNEL_Texture
the ground texture. (for distance viewing only)
Definition: cMapBase.h:85
MAP_SURFACE_TYPE
Definition: cMapBase.h:116
@ MAP_SURFACE_Legacy
For MAP_CHANNEL_Surface.
Definition: cMapBase.h:118
@ MAP_SURFACE_QTY
Definition: cMapBase.h:121
@ MAP_SURFACE_Hole
Definition: cMapBase.h:120
const MAP_HEIGHT_t MAP_HEIGHT_UNITS
Definition: cMapBase.h:109
MAP_TERRAIN_TYPE
Definition: cMapBase.h:127
@ MAP_TERRAIN_ICE
Definition: cMapBase.h:139
@ MAP_TERRAIN_MUD
Definition: cMapBase.h:137
@ MAP_TERRAIN_DIRT
Definition: cMapBase.h:135
@ MAP_TERRAIN_WATER_SHALLOW
Definition: cMapBase.h:143
@ MAP_TERRAIN_UnderGround
Definition: cMapBase.h:148
@ MAP_TERRAIN_QTY
Definition: cMapBase.h:150
@ MAP_TERRAIN_WATER_BOTTOM
Definition: cMapBase.h:146
@ MAP_TERRAIN_WATER_DEEP
Definition: cMapBase.h:145
@ MAP_TERRAIN_WATER_SURFACE
Definition: cMapBase.h:144
@ MAP_TERRAIN_SNOW
Definition: cMapBase.h:138
@ MAP_TERRAIN_WOOD
Definition: cMapBase.h:134
@ MAP_TERRAIN_BURIED
Definition: cMapBase.h:149
@ MAP_TERRAIN_GRASS
Definition: cMapBase.h:136
@ MAP_TERRAIN_STONE
Definition: cMapBase.h:133
@ MAP_TERRAIN_NONE
Definition: cMapBase.h:131
@ MAP_TERRAIN_MASK_ANY
Definition: cMapBase.h:152
__DECL_IMPORT cCoordSpaceDX g_Coords
unsigned short MAP_HEIGHT_t
Definition: cMapBase.h:108
MAP_LOD_TYPE
Definition: cMapBase.h:27
@ MAP_LOD_SECTOR
Definition: cMapBase.h:33
@ MAP_LOD_BLOCK
Definition: cMapBase.h:32
@ MAP_LOD_OCTANT
Definition: cMapBase.h:34
@ MAP_LOD_ZONE
Definition: cMapBase.h:35
@ MAP_LOD_WORLD
Definition: cMapBase.h:36
cRefPtr< cMapPatch > cMapPatchPtr
Definition: cMapBase.h:157
const MAP_PATCH_POINT_t MAP_PATCH_POINTS
arbitrary qty of points in the patch height grid. (meters @ MAP_LOD_BLOCK) MAP_PATCH_POINT_t
Definition: cMapBase.h:43
cThreadLockRef< cMapPatch > cMapPatchPtrX
Definition: cMapBase.h:159
int MAP_METERI_t
integer meters for the location of a patch. MAP_METER_t
Definition: cMapKeys.h:16
float MAP_METERf_t
Height meters dont need double accuracy. MAP_METER_t.
Definition: cMapKeys.h:17
const D3DVALUE MAP_VIEWDIST_NEAR_DEF
Definition: cMapBase.h:71
MAP_LIMITS_TYPE
Definition: cMapBase.h:49
@ MAP_MIN_Z
Definition: cMapBase.h:56
@ MAP_MAX_Z
Definition: cMapBase.h:57
@ MAP_HEIGHT_SEA
Definition: cMapBase.h:61
@ MAP_MAX_X
Definition: cMapBase.h:51
@ MAP_MAX_Y
Definition: cMapBase.h:54
@ MAP_VIEWDIST_TER_DEF
Definition: cMapBase.h:67
@ MAP_MIN_Y
Definition: cMapBase.h:53
@ MAP_HEIGHT_MIN
Definition: cMapBase.h:60
@ MAP_VIEWDIST_OBJ_DEF
Definition: cMapBase.h:68
@ MAP_HEIGHT_MAX
Definition: cMapBase.h:62
@ MAP_MIN_X
Definition: cMapBase.h:50
@ MAP_VIEWDIST_OBJ_MAX
Definition: cMapBase.h:65
@ MAP_BAD_Z
Definition: cMapBase.h:58
@ MAP_VIEWDIST_TER_MAX
Definition: cMapBase.h:64
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22