Skip to content

Commit

Permalink
Handle xrAI version 9 correctly
Browse files Browse the repository at this point in the history
AI nodes from version 9 are the same as nodes from version 8

Thanks for the builds versions:
https://github.com/abramcumner/xray_re-tools/blob/master/sources/xray_re/xr_ai_version.h
  • Loading branch information
Xottab-DUTY committed Jan 6, 2023
1 parent baad166 commit 7a1f0c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
13 changes: 9 additions & 4 deletions src/Common/LevelStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,17 @@ const u32 MAX_NODE_BIT_COUNT = 23;

enum xrAI_Versions : u8
{
XRAI_VERSION_SOC = 8,
XRAI_VERSION_CS = 9,
XRAI_VERSION_COP = 10,
// Release SOC: builds 2945, 2947 and further
XRAI_VERSION_SOC = 8,

// PRIQUEL: early CS builds on SOC engine, e.g. build 3120
XRAI_VERSION_PRIQUEL = 9,

// Release CS/COP: build 3456 and further
XRAI_VERSION_CS_COP = 10,

XRAI_VERSION_ALLOWED = XRAI_VERSION_SOC,
XRAI_VERSION_OPENXRAY = XRAI_VERSION_COP,
XRAI_VERSION_OPENXRAY = XRAI_VERSION_CS_COP,

XRAI_CURRENT_VERSION = XRAI_VERSION_OPENXRAY
};
Expand Down
35 changes: 21 additions & 14 deletions src/xrAICore/Navigation/level_graph_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ class CLevelGraphManager
size_t m_vertex_count;

public:
CLevelGraphManager(IReader* stream, size_t vertex_count, u32 version) : m_vertex_count(vertex_count)
CLevelGraphManager(IReader* stream, size_t vertex_count, xrAI_Versions version) : m_vertex_count(vertex_count)
{
if (version == XRAI_VERSION_COP || version == XRAI_VERSION_CS)
switch (version)
{
case XRAI_CURRENT_VERSION:
static_assert(XRAI_CURRENT_VERSION == XRAI_VERSION_CS_COP,
"If you have changed the xrAI version, don't forget to add back compatibility with CS/COP xrAI version.");
m_nodes = static_cast<CLevelVertex*>(stream->pointer());
}
else if (version == XRAI_VERSION_SOC)
break;

case XRAI_VERSION_PRIQUEL:
case XRAI_VERSION_SOC:
{
m_compatibility_mode = true;
m_nodes = new CLevelVertex[vertex_count + 1]; // additional one, so we don't trigger access violation
Expand All @@ -30,27 +35,29 @@ class CLevelGraphManager
newNode = oldNode;
}

// Mark end node as END NODE SOC
// Mark end node
// so we can spot that in debugger, if we need
NodeCompressed& endNode = m_nodes[vertex_count + 1];
endNode.data[0] = 'E';
endNode.data[1] = 'N';
endNode.data[2] = 'D';
endNode.data[0] = 'A';
endNode.data[1] = 'I';
endNode.data[2] = version;
endNode.data[3] = ' ';
endNode.data[4] = 'N';
endNode.data[5] = 'O';
endNode.data[6] = 'D';
endNode.data[7] = 'E';
endNode.data[8] = ' ';
endNode.data[9] = 'S';
endNode.data[10] = 'O';
endNode.data[11] = 'C';
endNode.data[9] = 'E';
endNode.data[10] = 'N';
endNode.data[11] = 'D';
static_assert(sizeof(endNode.data) == 12, "If you have changed the NodeCompressed structure, please update the code above.");
break;
}
else
{

default:
FATAL("Unsupported level graph version.");
}
NODEFAULT;
} // switch (version)
}

~CLevelGraphManager()
Expand Down

0 comments on commit 7a1f0c1

Please sign in to comment.