Skip to content

Commit 9c96e16

Browse files
committed
WIP of xrAI and xrSE_Factory. Small code cleanup and refactoring.
1 parent 68f4212 commit 9c96e16

File tree

6 files changed

+30
-61
lines changed

6 files changed

+30
-61
lines changed

src/utils/xrAI/AIMapExport.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef AIMapExportH
2-
#define AIMapExportH
1+
#pragma once
32

43
//----------------------------------------------------
54
struct SAIParams
@@ -26,4 +25,3 @@ struct SAIParams
2625
#define E_AIMAP_CHUNK_PARAMS 0x0003
2726
#define E_AIMAP_CHUNK_NODES 0x0004
2827
//----------------------------------------------------
29-
#endif

src/utils/xrAI/compiler.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#include "stdafx.h"
22
#include "compiler.h"
3-
#include "xrCDB/Intersect.hpp"
43

54
CDB::MODEL Level;
6-
CDB::COLLIDER XRC;
75
Nodes g_nodes;
8-
xr_vector<SCover> g_covers_palette;
9-
Lights g_lights;
106
SAIParams g_params;
11-
Fbox LevelBB;
127

138
void mem_Optimize()
149
{

src/utils/xrAI/compiler.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

33
#include "xrCDB/xrCDB.h"
4-
#include "Common/LevelStructure.hpp"
54
#include "AIMapExport.h"
65
#include "utils/Shader_xrLC.h"
6+
#include "xrAICore/Navigation/level_graph.h"
77
#include "editors/LevelEditor/Engine/communicate.h"
88
#include "Etextureparams.h"
99

@@ -43,18 +43,10 @@ struct vertex // definition of "patch" or "node"
4343
u32 nForward() { return n2; }
4444
u32 nRight() { return n3; }
4545
u32 nBack() { return n4; }
46-
void PointLF(Fvector& D);
47-
void PointFR(Fvector& D);
48-
void PointRB(Fvector& D);
49-
void PointBL(Fvector& D);
5046
};
5147

5248
using DWORDs = xr_vector<u32>;
5349

54-
#include "xrAICore/Navigation/level_graph.h"
55-
56-
void Compress(CLevelGraph::CVertex& Dest, vertex& Src);
57-
5850
#define LT_DIRECT 0
5951
#define LT_POINT 1
6052
#define LT_SECONDARY 2
@@ -85,13 +77,9 @@ using Marks = xr_vector<BYTE>;
8577
using Lights = xr_vector<R_Light>;
8678

8779
// data
80+
extern CDB::MODEL Level;
8881
extern Nodes g_nodes;
89-
extern xr_vector<SCover> g_covers_palette;
90-
extern Lights g_lights;
9182
extern SAIParams g_params;
92-
extern CDB::MODEL Level;
93-
extern CDB::COLLIDER XRC;
94-
extern Fbox LevelBB;
9583

9684
struct b_BuildTexture : public b_texture
9785
{

src/utils/xrAI/compiler_cover.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#include "stdafx.h"
22
#include "compiler.h"
33
#include "xrCDB/Intersect.hpp"
4-
#include "utils/xrLCUtil/xrThread.hpp"
54
#include <mmsystem.h>
65

76
#include "xrGame/quadtree.h"
87
#include "xrGame/cover_point.h"
98
#include "Common/object_broker.h"
10-
#include "xrCore/_fbox2.h"
119

1210
Shader_xrLC_LIB* g_shaders_xrlc;
1311
xr_vector<b_material> g_materials;
@@ -266,10 +264,10 @@ class CoverThread : public CThread
266264
Q.Perform(N);
267265

268266
// main cycle: trace rays and compute counts
269-
for (auto it = Q.q_List.begin(); it != Q.q_List.end(); it++)
267+
for (auto &it : Q.q_List)
270268
{
271269
// calc dir & range
272-
u32 ID = *it;
270+
u32 ID = it;
273271
R_ASSERT(ID < g_nodes.size());
274272
if (N == ID)
275273
continue;

src/utils/xrAI/compiler_load.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "stdafx.h"
22
#include "compiler.h"
3-
#include "Common/LevelGameDef.h"
4-
#include "xrAICore/Navigation/level_graph.h"
5-
#include "AIMapExport.h"
3+
4+
// TODO: Do we really need this?
5+
Lights g_lights;
6+
Fbox LevelBB;
67

78
IC const Fvector vertex_position(const CLevelGraph::CPosition& Psrc, const Fbox& bb, const SAIParams& params)
89
{
@@ -54,19 +55,18 @@ extern void Surface_Init();
5455
void xrLoad(LPCSTR name, bool draft_mode)
5556
{
5657
FS.get_path("$level$")->_set((LPSTR)name);
57-
string256 N;
58+
string_path file_name;
5859
if (!draft_mode)
5960
{
6061
// shaders
61-
string_path N;
62-
FS.update_path(N, "$game_data$", "shaders_xrlc.xr");
62+
FS.update_path(file_name, "$game_data$", "shaders_xrlc.xr");
6363
g_shaders_xrlc = new Shader_xrLC_LIB();
64-
g_shaders_xrlc->Load(N);
64+
g_shaders_xrlc->Load(file_name);
6565

6666
// Load CFORM
6767
{
68-
strconcat(sizeof(N), N, name, "build.cform");
69-
IReader* fs = FS.r_open(N);
68+
strconcat(sizeof(file_name), file_name, name, "build.cform");
69+
IReader* fs = FS.r_open(file_name);
7070
R_ASSERT(fs->find_chunk(0));
7171

7272
hdrCFORM H;
@@ -89,9 +89,8 @@ void xrLoad(LPCSTR name, bool draft_mode)
8989

9090
// Load level data
9191
{
92-
strconcat(sizeof(N), N, name, "build.prj");
93-
IReader* fs = FS.r_open(N);
94-
IReader* F;
92+
strconcat(sizeof(file_name), file_name, name, "build.prj");
93+
IReader* fs = FS.r_open(file_name);
9594

9695
// Version
9796
u32 version;
@@ -111,7 +110,7 @@ void xrLoad(LPCSTR name, bool draft_mode)
111110
Logger.Status("Processing textures...");
112111
{
113112
Surface_Init();
114-
F = fs->open_chunk(EB_Textures);
113+
IReader* F = fs->open_chunk(EB_Textures);
115114
u32 tex_count = F->length() / sizeof(b_texture);
116115
for (u32 t = 0; t < tex_count; t++)
117116
{
@@ -176,8 +175,7 @@ void xrLoad(LPCSTR name, bool draft_mode)
176175
BT.pSurface = Surface_Load(N, w, h);
177176
R_ASSERT2(BT.pSurface, "Can't load surface");
178177
if ((w != BT.dwWidth) || (h != BT.dwHeight))
179-
Msg("! THM doesn't correspond to the texture: %dx%d -> %dx%d", BT.dwWidth,
180-
BT.dwHeight, w, h);
178+
Msg("! THM doesn't correspond to the texture: %dx%d -> %dx%d", BT.dwWidth, BT.dwHeight, w, h);
181179
BT.Vflip();
182180
}
183181
else
@@ -195,9 +193,8 @@ void xrLoad(LPCSTR name, bool draft_mode)
195193
}
196194
// Load lights
197195
{
198-
strconcat(sizeof(N), N, name, "build.prj");
199-
200-
IReader* F = FS.r_open(N);
196+
strconcat(sizeof(file_name), file_name, name, "build.prj");
197+
IReader* F = FS.r_open(file_name);
201198
R_ASSERT2(F, "There is no file 'build.prj'!");
202199
IReader& fs = *F;
203200

@@ -256,10 +253,9 @@ void xrLoad(LPCSTR name, bool draft_mode)
256253
}
257254
// Load initial map from the Level Editor
258255
{
259-
string_path file_name;
260256
strconcat(sizeof(file_name), file_name, name, "build.aimap");
261257
IReader* F = FS.r_open(file_name);
262-
R_ASSERT2(F, file_name);
258+
R_ASSERT2(F, "There is no file 'build.aimap'!");
263259

264260
R_ASSERT(F->open_chunk(E_AIMAP_CHUNK_VERSION));
265261
R_ASSERT(F->r_u16() == E_AIMAP_VERSION);

src/utils/xrAI/compiler_save.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ float CalculateHeight(Fbox& BB)
4444
// All nodes
4545
BB.invalidate();
4646

47-
for (u32 i = 0; i < g_nodes.size(); i++)
48-
{
49-
vertex& N = g_nodes[i];
50-
BB.modify(N.Pos);
51-
}
47+
for (auto &i : g_nodes)
48+
BB.modify(i.Pos);
49+
5250
return BB.vMax.y - BB.vMin.y + EPS_L;
5351
}
5452

@@ -64,7 +62,7 @@ class CNodeRenumberer
6462
return (vertex0.p.xz() < vertex1.p.xz());
6563
}
6664

67-
IC bool operator()(u32 vertex_id0, u32 vertex_id1) const
65+
IC bool operator()(const u32 vertex_id0, const u32 vertex_id1) const
6866
{
6967
return (compressed_nodes[vertex_id0].p.xz() < compressed_nodes[vertex_id1].p.xz());
7068
}
@@ -114,7 +112,6 @@ void xrSaveNodes(LPCSTR name, LPCSTR out_name)
114112

115113
string_path fName;
116114
strconcat(sizeof(fName), fName, name, out_name);
117-
118115
IWriter* fs = FS.w_open(fName);
119116

120117
// Header
@@ -128,23 +125,20 @@ void xrSaveNodes(LPCSTR name, LPCSTR out_name)
128125
fs->w(&H, sizeof(H));
129126
// All nodes
130127
Logger.Status("Saving nodes...");
131-
for (u32 i = 0; i < g_nodes.size(); ++i)
128+
for (auto &i : g_nodes)
132129
{
133-
vertex& N = g_nodes[i];
134130
NodeCompressed NC;
135-
Compress(NC, N, H);
131+
Compress(NC, i, H);
136132
compressed_nodes.push_back(NC);
137133
}
138134

139135
xr_vector<u32> sorted;
140136
xr_vector<u32> renumbering;
141137
CNodeRenumberer A(compressed_nodes, sorted, renumbering);
142138

143-
for (u32 i = 0; i < g_nodes.size(); ++i)
144-
{
145-
fs->w(&compressed_nodes[i], sizeof(NodeCompressed));
146-
Logger.Progress(float(i) / float(g_nodes.size()));
147-
}
139+
for (auto &i : compressed_nodes)
140+
fs->w(&i, sizeof(NodeCompressed));
141+
148142
// Stats
149143
u32 SizeTotal = fs->tell();
150144
Msg("%dK saved", SizeTotal / 1024);

0 commit comments

Comments
 (0)