Skip to content

Commit

Permalink
WIP of xrAI and xrSE_Factory. Small code cleanup and refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr committed Dec 30, 2017
1 parent 68f4212 commit 9c96e16
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 61 deletions.
4 changes: 1 addition & 3 deletions src/utils/xrAI/AIMapExport.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef AIMapExportH
#define AIMapExportH
#pragma once

//----------------------------------------------------
struct SAIParams
Expand All @@ -26,4 +25,3 @@ struct SAIParams
#define E_AIMAP_CHUNK_PARAMS 0x0003
#define E_AIMAP_CHUNK_NODES 0x0004
//----------------------------------------------------
#endif
5 changes: 0 additions & 5 deletions src/utils/xrAI/compiler.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#include "stdafx.h"
#include "compiler.h"
#include "xrCDB/Intersect.hpp"

CDB::MODEL Level;
CDB::COLLIDER XRC;
Nodes g_nodes;
xr_vector<SCover> g_covers_palette;
Lights g_lights;
SAIParams g_params;
Fbox LevelBB;

void mem_Optimize()
{
Expand Down
16 changes: 2 additions & 14 deletions src/utils/xrAI/compiler.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "xrCDB/xrCDB.h"
#include "Common/LevelStructure.hpp"
#include "AIMapExport.h"
#include "utils/Shader_xrLC.h"
#include "xrAICore/Navigation/level_graph.h"
#include "editors/LevelEditor/Engine/communicate.h"
#include "Etextureparams.h"

Expand Down Expand Up @@ -43,18 +43,10 @@ struct vertex // definition of "patch" or "node"
u32 nForward() { return n2; }
u32 nRight() { return n3; }
u32 nBack() { return n4; }
void PointLF(Fvector& D);
void PointFR(Fvector& D);
void PointRB(Fvector& D);
void PointBL(Fvector& D);
};

using DWORDs = xr_vector<u32>;

#include "xrAICore/Navigation/level_graph.h"

void Compress(CLevelGraph::CVertex& Dest, vertex& Src);

#define LT_DIRECT 0
#define LT_POINT 1
#define LT_SECONDARY 2
Expand Down Expand Up @@ -85,13 +77,9 @@ using Marks = xr_vector<BYTE>;
using Lights = xr_vector<R_Light>;

// data
extern CDB::MODEL Level;
extern Nodes g_nodes;
extern xr_vector<SCover> g_covers_palette;
extern Lights g_lights;
extern SAIParams g_params;
extern CDB::MODEL Level;
extern CDB::COLLIDER XRC;
extern Fbox LevelBB;

struct b_BuildTexture : public b_texture
{
Expand Down
6 changes: 2 additions & 4 deletions src/utils/xrAI/compiler_cover.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "stdafx.h"
#include "compiler.h"
#include "xrCDB/Intersect.hpp"
#include "utils/xrLCUtil/xrThread.hpp"
#include <mmsystem.h>

#include "xrGame/quadtree.h"
#include "xrGame/cover_point.h"
#include "Common/object_broker.h"
#include "xrCore/_fbox2.h"

Shader_xrLC_LIB* g_shaders_xrlc;
xr_vector<b_material> g_materials;
Expand Down Expand Up @@ -266,10 +264,10 @@ class CoverThread : public CThread
Q.Perform(N);

// main cycle: trace rays and compute counts
for (auto it = Q.q_List.begin(); it != Q.q_List.end(); it++)
for (auto &it : Q.q_List)
{
// calc dir & range
u32 ID = *it;
u32 ID = it;
R_ASSERT(ID < g_nodes.size());
if (N == ID)
continue;
Expand Down
36 changes: 16 additions & 20 deletions src/utils/xrAI/compiler_load.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "stdafx.h"
#include "compiler.h"
#include "Common/LevelGameDef.h"
#include "xrAICore/Navigation/level_graph.h"
#include "AIMapExport.h"

// TODO: Do we really need this?
Lights g_lights;
Fbox LevelBB;

IC const Fvector vertex_position(const CLevelGraph::CPosition& Psrc, const Fbox& bb, const SAIParams& params)
{
Expand Down Expand Up @@ -54,19 +55,18 @@ extern void Surface_Init();
void xrLoad(LPCSTR name, bool draft_mode)
{
FS.get_path("$level$")->_set((LPSTR)name);
string256 N;
string_path file_name;
if (!draft_mode)
{
// shaders
string_path N;
FS.update_path(N, "$game_data$", "shaders_xrlc.xr");
FS.update_path(file_name, "$game_data$", "shaders_xrlc.xr");
g_shaders_xrlc = new Shader_xrLC_LIB();
g_shaders_xrlc->Load(N);
g_shaders_xrlc->Load(file_name);

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

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

// Load level data
{
strconcat(sizeof(N), N, name, "build.prj");
IReader* fs = FS.r_open(N);
IReader* F;
strconcat(sizeof(file_name), file_name, name, "build.prj");
IReader* fs = FS.r_open(file_name);

// Version
u32 version;
Expand All @@ -111,7 +110,7 @@ void xrLoad(LPCSTR name, bool draft_mode)
Logger.Status("Processing textures...");
{
Surface_Init();
F = fs->open_chunk(EB_Textures);
IReader* F = fs->open_chunk(EB_Textures);
u32 tex_count = F->length() / sizeof(b_texture);
for (u32 t = 0; t < tex_count; t++)
{
Expand Down Expand Up @@ -176,8 +175,7 @@ void xrLoad(LPCSTR name, bool draft_mode)
BT.pSurface = Surface_Load(N, w, h);
R_ASSERT2(BT.pSurface, "Can't load surface");
if ((w != BT.dwWidth) || (h != BT.dwHeight))
Msg("! THM doesn't correspond to the texture: %dx%d -> %dx%d", BT.dwWidth,
BT.dwHeight, w, h);
Msg("! THM doesn't correspond to the texture: %dx%d -> %dx%d", BT.dwWidth, BT.dwHeight, w, h);
BT.Vflip();
}
else
Expand All @@ -195,9 +193,8 @@ void xrLoad(LPCSTR name, bool draft_mode)
}
// Load lights
{
strconcat(sizeof(N), N, name, "build.prj");

IReader* F = FS.r_open(N);
strconcat(sizeof(file_name), file_name, name, "build.prj");
IReader* F = FS.r_open(file_name);
R_ASSERT2(F, "There is no file 'build.prj'!");
IReader& fs = *F;

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

R_ASSERT(F->open_chunk(E_AIMAP_CHUNK_VERSION));
R_ASSERT(F->r_u16() == E_AIMAP_VERSION);
Expand Down
24 changes: 9 additions & 15 deletions src/utils/xrAI/compiler_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ float CalculateHeight(Fbox& BB)
// All nodes
BB.invalidate();

for (u32 i = 0; i < g_nodes.size(); i++)
{
vertex& N = g_nodes[i];
BB.modify(N.Pos);
}
for (auto &i : g_nodes)
BB.modify(i.Pos);

return BB.vMax.y - BB.vMin.y + EPS_L;
}

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

IC bool operator()(u32 vertex_id0, u32 vertex_id1) const
IC bool operator()(const u32 vertex_id0, const u32 vertex_id1) const
{
return (compressed_nodes[vertex_id0].p.xz() < compressed_nodes[vertex_id1].p.xz());
}
Expand Down Expand Up @@ -114,7 +112,6 @@ void xrSaveNodes(LPCSTR name, LPCSTR out_name)

string_path fName;
strconcat(sizeof(fName), fName, name, out_name);

IWriter* fs = FS.w_open(fName);

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

xr_vector<u32> sorted;
xr_vector<u32> renumbering;
CNodeRenumberer A(compressed_nodes, sorted, renumbering);

for (u32 i = 0; i < g_nodes.size(); ++i)
{
fs->w(&compressed_nodes[i], sizeof(NodeCompressed));
Logger.Progress(float(i) / float(g_nodes.size()));
}
for (auto &i : compressed_nodes)
fs->w(&i, sizeof(NodeCompressed));

// Stats
u32 SizeTotal = fs->tell();
Msg("%dK saved", SizeTotal / 1024);
Expand Down

0 comments on commit 9c96e16

Please sign in to comment.