Skip to content

Commit

Permalink
Merge branch 'all-in-one-vs2022' into all-in-one-vs2022-wpo
Browse files Browse the repository at this point in the history
  • Loading branch information
themrdemonized committed Nov 9, 2024
2 parents cc05f92 + 3357456 commit 3d2424d
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 197 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ How to compile exes:
6. For successful compilation, **the latest build tools with MFC and ATL libraries is required**
## Changelog
**2024.11.09**
* Temporary disabled cform_cache (https://github.com/themrdemonized/xray-monolith/issues/100)
**2024.11.08**
* Lucy, RavenAscendant, NLTP_ASHES: Transparency shader fix for detectors (https://github.com/nltp-ashes/Western-Goods/releases/tag/fix-vanilla-shader)
Expand Down
2 changes: 1 addition & 1 deletion src/xrCDB/ISpatial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void ISpatial_DB::initialize(Fbox& BB)
BB.get_CD(bbc, bbd);

bbc.set(0, 0, 0); // generic
bbd.set(4096, 4096, 4096); // generic
bbd.set(1024, 1024, 1024); // generic

allocator_pool.reserve(128);
m_center.set(bbc);
Expand Down
57 changes: 0 additions & 57 deletions src/xrCDB/OPC_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,63 +178,6 @@ OPCODE_Model::~OPCODE_Model()
#endif // __MESHMERIZER_H__
}


#include "..\xrCore\stream_reader.h"

void OPCODE_Model::Load(CStreamReader* stream) {
mNoLeaf = stream->r_u32();
mQuantized = stream->r_u32();

const u32 nodesNum = stream->r_u32();
if(mNoLeaf && !mQuantized) {
mTree = CNEW(AABBNoLeafTree)();
auto* ptr = CALLOC(AABBNoLeafNode, nodesNum);
const u32 size = nodesNum * sizeof(AABBNoLeafNode);
// CopyMemory(ptr, stream->pointer(), size);
stream->r(ptr, size);
for(int i = 0; i < nodesNum; ++i) {
const auto* rootPtr = &ptr[0];
if(!ptr[i].HasLeaf())
ptr[i].mData += (uintptr_t)rootPtr;
if(!ptr[i].HasLeaf2())
ptr[i].mData2 += (uintptr_t)rootPtr;
}
mTree->SetData(ptr, nodesNum);
}
else {
R_ASSERT(FALSE); // Not used by engine so not supported
}
}

void OPCODE_Model::Save(IWriter* stream) const {
stream->w_u32(mNoLeaf);
stream->w_u32(mQuantized);

const u32 nodesNum = mTree->GetNbNodes();
stream->w_u32(mTree->GetNbNodes());

void* pData = nullptr;
if(mNoLeaf && !mQuantized) {
auto* ptr = CALLOC(AABBNoLeafNode, nodesNum);
const u32 size = nodesNum * sizeof(AABBNoLeafNode);
R_ASSERT(size == mTree->GetUsedBytes());
CopyMemory(ptr, mTree->GetData(), size);
pData = ptr;
for(int i = 0; i < nodesNum; ++i, ++ptr) {
const auto* rootPtr = mTree->GetData();
if(!ptr->HasLeaf())
ptr->mData -= (uintptr_t)rootPtr;
if(!ptr->HasLeaf2())
ptr->mData2 -= (uintptr_t)rootPtr;
}
}
else {
R_ASSERT(FALSE); // Not used by engine so not supported
}
stream->w(pData, mTree->GetUsedBytes());
xr_free(pData);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Builds a collision model.
Expand Down
4 changes: 0 additions & 4 deletions src/xrCDB/OPC_Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class OPCODE_API OPCODE_Model
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Build(const OPCODECREATE& create);


void Load(CStreamReader* stream);
void Save(IWriter* stream) const;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A method to access the tree.
Expand Down
5 changes: 0 additions & 5 deletions src/xrCDB/OPC_OptimizedTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ IMPLEMENT_NOLEAF_NODE(AABBQuantizedNoLeafNode, QuantizedAABB)
virtual bool Build(AABBTree* tree); \
/* Data access */ \
inline_ const volume* GetNodes() const { return mNodes; } \
void* GetData() const override { return static_cast<void*>(mNodes); }\
void SetData(void* ptr, udword nbNodes) override { mNodes = static_cast<volume*>(ptr); mNbNodes = nbNodes; }\
/* Stats */ \
virtual udword GetUsedBytes() const { return mNbNodes*sizeof(volume); } \
private: \
Expand All @@ -142,9 +140,6 @@ class OPCODE_API AABBOptimizedTree
// Data access
inline_ udword GetNbNodes() const { return mNbNodes; }

virtual void* GetData() const = 0;
virtual void SetData(void* ptr, udword nbNodes) = 0;

virtual udword GetUsedBytes() const = 0;
virtual bool Build(AABBTree* tree) = 0;
protected:
Expand Down
119 changes: 16 additions & 103 deletions src/xrCDB/xrCDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,119 +85,32 @@ void MODEL::build_thread(void* params)
//Msg ("* xrCDB: cform build completed, memory usage: %d K",P.M->memory()/1024);
}

#include "..\xrCore\stream_reader.h"

u64 crc64(void* p, u64 mem_size) {
u8* temp = (u8*)p;

u64 crc = 0;
u64 size = mem_size;
size_t umem = u64(u32(-1));

while(mem_size > umem) {
crc += (u64)crc32(temp, umem);
mem_size -= umem;
temp += umem;
}

crc += crc32(temp, mem_size);

return crc;
}

void MODEL::build(Fvector* V, int Vcnt, TRI* T, int Tcnt, build_callback* bc, void* bcp)
{
auto serialize = [&](pcstr fileName) {
IWriter* wstream = FS.w_open(fileName);
if(!wstream)
return false;

wstream->w_u32(verts_count);
wstream->w(verts, sizeof(Fvector) * verts_count);
wstream->w_u32(tris_count);
wstream->w(tris, sizeof(TRI) * tris_count);

if(tree) {
tree->Save(wstream);
}

FS.w_close(wstream);
return !!tree;
};

auto deserialize = [&](pcstr fileName) {
auto rstream = FS.rs_open(0, fileName);
if(!rstream)
return false;

CFREE(verts);
CFREE(tris);
CFREE(tree);

verts_count = rstream->r_u32();
verts = CALLOC(Fvector, verts_count);
const u32 vertsSize = verts_count * sizeof(Fvector);
rstream->r(verts, vertsSize);

tris_count = rstream->r_u32();
tris = CALLOC(TRI, tris_count);
const u32 trisSize = tris_count * sizeof(TRI);
rstream->r(tris, trisSize);

//verts_count = Vcnt;
//verts = CALLOC(Fvector, verts_count);
//CopyMemory(verts, V, verts_count * sizeof(Fvector));

//// tris
//tris_count = Tcnt;
//tris = CALLOC(TRI, tris_count);
//CopyMemory(tris, T, tris_count * sizeof(TRI));

//// callback
//if(bc) bc(verts, Vcnt, tris, Tcnt, bcp);

tree = CNEW(OPCODE_Model)();
tree->Load(rstream);
FS.r_close(rstream);
status = S_READY;
return true;
};

R_ASSERT(S_INIT == status);
R_ASSERT((Vcnt>=4)&&(Tcnt>=2));

_initialize_cpu_thread();

static bool disable_cdb_chace = !!strstr(Core.Params, "-no_cdb");

if(disable_cdb_chace) {
build_internal(V, Vcnt, T, Tcnt, bc, bcp);
status = S_READY;

return;
}

std::string hashed_name = "";
hashed_name += std::to_string(Vcnt) + "_";
hashed_name += std::to_string(Tcnt) + "_";
hashed_name += std::to_string(crc64(V, sizeof(Fvector) * Vcnt)) + "_";
hashed_name += std::to_string(crc64(T, sizeof(TRI) * Tcnt));

string_path fName{};
strconcat(sizeof(fName), fName, "cform_cache\\", FS.get_path("$level$")->m_Add, hashed_name.c_str(), ".cdb");
FS.update_path(fName, "$app_data_root$", fName);

if(!FS.exist(fName)) {
Msg("* ObjectSpace cache for '%s' not found. Building the model from scratch..", fName);

#ifdef _EDITOR
build_internal (V,Vcnt,T,Tcnt,bc,bcp);
#else
if (!strstr(Core.Params, "-mt_cdb"))
{
build_internal(V, Vcnt, T, Tcnt, bc, bcp);
status = S_READY;

serialize(fName);
}
else {
deserialize(fName);
else
{
BTHREAD_params P = {this, V, Vcnt, T, Tcnt, bc, bcp};
thread_spawn(build_thread, "CDB-construction", 0, &P);
while (S_INIT == status)
{
if (status != S_INIT)
break;
Sleep(5);
}
}
#endif
}

void MODEL::build_internal(Fvector* V, int Vcnt, TRI* T, int Tcnt, build_callback* bc, void* bcp)
Expand Down
2 changes: 2 additions & 0 deletions src/xrCDB/xr_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ void CObjectSpace::Load(LPCSTR path, LPCSTR fname, CDB::build_callback build_cal
}

void CObjectSpace::Load(IReader* F, CDB::build_callback build_callback)


{
hdrCFORM H;
F->r(&H, sizeof(hdrCFORM));
Expand Down
1 change: 0 additions & 1 deletion src/xrEngine/IGame_Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

//#include "securom_api.h"

ENGINE_API u32 CURRENT_XRAI_VERSION = XRAI_CURRENT_VERSION;
ENGINE_API IGame_Level* g_pGameLevel = NULL;
extern BOOL g_bLoaded;

Expand Down
19 changes: 1 addition & 18 deletions src/xrEngine/xrLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ struct NodeCompressed
}
}

ICF void linknew(u8 link_index, u32 value) {
data[0 + link_index * 3] = (value >> 16) & 0xFF;
data[1 + link_index * 3] = (value >> 8) & 0xFF;
data[2 + link_index * 3] = value & 0xFF;
}

ICF void light(u8 value)
{
data[10] |= value << 4;
Expand Down Expand Up @@ -240,16 +234,6 @@ struct NodeCompressed
NodePosition p;
// 32 + 16 + 40 + 92 = 180 bits = 24.5 bytes => 25 bytes

ICF u32 linknew(u8 index) const {
u32 value = 0;

value |= (data[0 + index * 3] << 16);
value |= (data[1 + index * 3] << 8);
value |= (data[2 + index * 3]);

return value;
}

ICF u32 link(u8 index) const
{
switch (index)
Expand Down Expand Up @@ -398,8 +382,7 @@ typedef SNodePositionOld NodePosition;
const u32 XRCL_CURRENT_VERSION = 18; //17; // input
const u32 XRCL_PRODUCTION_VERSION = 14; // output
const u32 CFORM_CURRENT_VERSION = 4;
const u32 MAX_NODE_BIT_COUNT = 24;
const u32 MAX_NODE_BIT_COUNT = 23;
const u32 XRAI_CURRENT_VERSION = 10;
extern ENGINE_API u32 CURRENT_XRAI_VERSION;

#endif // xrLevelH
2 changes: 1 addition & 1 deletion src/xrGame/game_graph_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ IC CGameGraph::CGameGraph(const IReader& _stream)
{
IReader& stream = const_cast<IReader&>(_stream);
m_header.load(&stream);
//R_ASSERT2(header().version() == XRAI_CURRENT_VERSION, "Graph version mismatch!");
R_ASSERT2(header().version() == XRAI_CURRENT_VERSION, "Graph version mismatch!");
m_nodes = (CVertex*)stream.pointer();
m_current_level_some_vertex_id = _GRAPH_ID(-1);
m_enabled.assign(header().vertex_count(), true);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/game_level_cross_table_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ IC CGameLevelCrossTable::CGameLevelCrossTable(const void* buffer, const u32& buf
Memory.mem_copy(&m_tCrossTableHeader, buffer, sizeof(m_tCrossTableHeader));
buffer = (const u8*)buffer + sizeof(m_tCrossTableHeader);

//R_ASSERT2(m_tCrossTableHeader.version() == XRAI_CURRENT_VERSION, "Cross table version mismatch!");
R_ASSERT2(m_tCrossTableHeader.version() == XRAI_CURRENT_VERSION, "Cross table version mismatch!");

m_tpaCrossTable = (CCell*)buffer;
}
Expand Down
4 changes: 1 addition & 3 deletions src/xrGame/level_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ CLevelGraph::CLevelGraph()

// m_header & data
m_header = (CHeader*)m_reader->pointer();
CURRENT_XRAI_VERSION = header().version();
Msg("$ CURRENT_XRAI_VERSION [%d]", CURRENT_XRAI_VERSION);
// R_ASSERT(header().version() == XRAI_CURRENT_VERSION);
R_ASSERT(header().version() == XRAI_CURRENT_VERSION);
m_reader->advance(sizeof(CHeader));
m_nodes = (CVertex*)m_reader->pointer();
m_row_length = iFloor((header().box().max.z - header().box().min.z) / header().cell_size() + EPS_L + 1.5f);
Expand Down
3 changes: 0 additions & 3 deletions src/xrGame/level_graph_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ ICF const xrGUID& CLevelGraph::CHeader::guid() const

ICF u32 CLevelGraph::CVertex::link(int index) const
{
if(CURRENT_XRAI_VERSION != XRAI_CURRENT_VERSION) {
return (NodeCompressed::linknew(u8(index)));
}
return (NodeCompressed::link(u8(index)));
}

Expand Down

0 comments on commit 3d2424d

Please sign in to comment.