-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathSector_2_5D.h
170 lines (142 loc) · 5.75 KB
/
Sector_2_5D.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef SECTOR_2_5DH
#define SECTOR_2_5DH
#include "Sector.h"
#include "../math/Vector2.h"
#include "../math/Vector3.h"
#include "../render/Camera.h"
#include "../world/LevelFunc.h"
/*********************************************
2.5D Sector.
Current limits (per sector):
Vertex Count: 65536
WallCount: 65535
Limits per level:
Total Sector Count: 65535
*********************************************/
//SOLID_WALL = no mirror or adjoin, this is a solid wall (the default).
#define SOLID_WALL 0xffff
#define MAX_ADJOIN_COUNT 2
class IDriver3D;
class Object;
class WorldCell;
class Wall
{
public:
enum WallTextures_e
{
WALL_TEX_MID=0,
WALL_TEX_TOP,
WALL_TEX_BOT,
WALL_TEX_SIGN,
WALL_TEX_COUNT
};
enum WallFlags
{
WALL_FLAGS_NONE = 0,
WALL_FLAGS_SOLIDTEX = (1<<0), //draw a solid texture regardless of connectivity.
WALL_FLAGS_XFLIP = (1<<1), //texture: flip on x.
WALL_FLAGS_YFLIP = (1<<2),
WALL_FLAGS_MASKWALL = (1<<3),
WALL_FLAGS_TRANS = (1<<4),
WALL_FLAGS_SKY = (1<<5),
WALL_FLAGS_MORPH = (1<<6),
WALL_FLAGS_INV_MORPH = (1<<7),
};
public:
uint16_t m_idx[2]; //vertex indices.
uint16_t m_adjoin[MAX_ADJOIN_COUNT]; //dual-adjoin support
uint16_t m_mirror[MAX_ADJOIN_COUNT]; //
uint32_t m_flags; //wall flags
uint32_t m_mapFlags; //map flags (used by the automap)
int16_t m_lightDelta;
TextureHandle m_textures[WALL_TEX_COUNT];
Vector2 m_texOffset[WALL_TEX_COUNT];
Vector2 m_texScale[WALL_TEX_COUNT];
float m_wallLen; //used for computing texture coordinates.
LevelFunc *m_pFunc;
};
class Sector_2_5D : public Sector
{
public:
Sector_2_5D();
virtual ~Sector_2_5D();
void Render(IDriver3D *pDriver, Camera *pCamera) override;
bool PointInsideSector(float x, float y);
float GetZ_Floor(float x, float y, const std::vector<Sector *>& Sectors);
float GetZ_Ceil(float x, float y, const std::vector<Sector *>& Sectors);
static void RenderSectors(IDriver3D *pDriver, WorldCell *pCell, Camera *pCamera, Sector_2_5D *pStart, const std::vector<Sector *>& Sectors);
static void Collide(Vector3 *p0, Vector3 *p1, uint32_t& uSector, float fRadius, const std::vector<Sector *>& Sectors, bool bPassThruAdjoins);
static void RayCastAndActivate(Vector3 *p0, Vector3 *p1, uint32_t& uSector, const std::vector<Sector *>& Sectors);
public:
enum
{
SEC_FLAGS_NONE = 0,
SEC_FLAGS_EXTERIOR = (1<<0),
SEC_FLAGS_FLOOR_SLOPE = (1<<1),
SEC_FLAGS_CEIL_SLOPE = (1<<2),
SEC_FLAGS_FLOOR_FLIP = (1<<3),
SEC_FLAGS_CEIL_FLIP = (1<<4),
SEC_FLAGS_FLOORWATER = (1<<5),
SEC_FLAGS_UNDERWATER = (1<<6),
SEC_FLAGS_SKYFLOOR = (1<<7),
SEC_FLAGS_ALLOW_NONSOLID_ACTIVATE = (1<<8), //activate walls even if they aren't solid.
};
//A sector can currently have up to 65536 vertices.
uint16_t m_uVertexCount;
uint16_t m_uWallCount;
uint32_t m_uFlags;
uint8_t m_uLayer;
uint8_t m_uAmbientFloor;
uint8_t m_uAmbientCeil;
uint8_t m_pad[2];
Vector2 *m_pVertexBase;
Vector2 *m_pVertexCur;
Vector2 m_ZRangeBase, m_ZRangeCur;
Vector2 m_FloorTexScale;
Vector2 m_CeilTexScale;
float m_fFloorSlope;
float m_fCeilSlope;
int32_t m_aLightFX[3]; //floor, ceiling, walls.
uint16_t m_auSlopeSector[2];
uint16_t m_auSlopeAnchor[2];
Vector2 m_texOffset[2];
Wall *m_Walls;
uint16_t m_vAdjoin[2]; //vertical adjoins [top/bottom].
Vector3 m_vAdjOffset[2];
TextureHandle m_hFloorTex;
TextureHandle m_hCeilTex;
LevelFunc *m_pFunc;
protected:
struct VisStack
{
Vector2 fL, fR;
Vector3 offset;
uint32_t uStartX, uEndX;
bool bUsePortalClip;
Sector_2_5D *pNext;
float *depth; //ignored by primary sectors.
};
static Vector2 m_nearPlane[2];
static Vector3 s_vCurrentOffs;
static bool m_bUpdateVis;
static VisStack m_visStack[];
static VisStack m_visStack_VAdjoin[];
static int32_t m_visStackCnt;
static int32_t m_visStackIdx;
static int32_t m_visStackCnt_VAdjoin;
static float s_fFogRange;
static Camera m_Camera2D;
static void VisStack_Push(Vector2& fL, Vector2& fR, uint32_t uStartX, uint32_t uEndX, Sector_2_5D *pNext, bool bUsePortalClip=true, Vector3& vOffset=s_vCurrentOffs);
static VisStack *VisStack_Pop();
static void VisStack_Clear();
static void Visibility2D(const Vector3& cPos, Vector2 fL, Vector2 fR, uint32_t uStartX, uint32_t uEndX, Sector_2_5D *pCurSec, const std::vector<Sector *>& Sectors, bool bUsePortalClip, IDriver3D *pDriver);
static void WallRasterizer(const Vector3& cPos, uint32_t uStartX, uint32_t uEndX, Sector_2_5D *pCurSec, const std::vector<Sector *>& Sectors);
static void _DrawWall(IDriver3D *pDriver, Sector_2_5D *pCurSec, Sector_2_5D *pNextSec, Sector_2_5D *pBotSec, Sector_2_5D *pTopSec, uint16_t w, Vector2 *worldPos, const std::vector<Sector *>& Sectors);
static void _DrawFloor(IDriver3D *pDriver, Sector_2_5D *pCurSec, const Vector2 *worldPos, const Vector2& a, const Vector2& n0, const Vector2& n1, const std::vector<Sector *>& Sectors);
static void _SetupCameraParameters(const Vector3& cPos, const Vector3& cDir, Vector2 fL, Vector2 fR);
static void _AddSectorToList(int32_t s, Vector3 *p0, Vector2& vPathMin, Vector2& vPathMax, const std::vector<Sector *>& Sectors);
static void AddObjectToRender(Object *pObj, float fIntensity, const Vector3& vOffs);
static void RenderObjects(IDriver3D *pDriver);
static void RenderSky(IDriver3D *pDriver, WorldCell *pCell);
};
#endif //SECTOR_2_5DH