Skip to content

Commit a0bc6ff

Browse files
authored
Support multiple NavGraphs, fix bugs, bump version to 2.14.0 (#86)
1 parent 559ccf8 commit a0bc6ff

20 files changed

Lines changed: 402 additions & 361 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0141 NEW)
33
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<CONFIG:Debug>,EditAndContinue,ProgramDatabase>" CACHE STRING "MSVC debug information format")
44
project(
55
NavKit
6-
VERSION 2.13.0
6+
VERSION 2.14.0
77
DESCRIPTION "An app to create NAVP and AIRG files for use with Hitman: World of Assassination"
88
LANGUAGES CXX)
99
set(CMAKE_CXX_STANDARD 20)

include/NavKit/NavKitConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define NavKit_VERSION_MAJOR "2"
2-
#define NavKit_VERSION_MINOR "13"
2+
#define NavKit_VERSION_MINOR "14"
33
#define NavKit_VERSION_PATCH "0"

include/NavKit/module/InputHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class InputHandler {
3434
float moveUp;
3535
float moveDown;
3636

37+
static constexpr int MENU_HEIGHT = 20;
3738
static constexpr int QUIT = 1;
3839
static constexpr float BASE_KEYBOARD_SPEED = 22.0f;
3940
static constexpr float SHIFT_SPEED_MULTIPLIER = 4.0f;

include/NavKit/module/Navp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Navp {
5555

5656
static void updateNavMeshBuffers(const NavPower::NavMesh* navMesh, int selectedIndex);
5757

58+
static int getTotalAreaCount(const NavPower::NavMesh* navMesh);
59+
static NavPower::Area& getAreaByIndex(const NavPower::NavMesh* navMesh, int index);
60+
5861
static void updateHitTestBuffers(const NavPower::NavMesh* navMesh);
5962

6063
void renderPfSeedPoints() const;

include/NavWeakness/NavPower.h

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
NavPower.h - v1.2.0
2+
NavPower.h - v2.0.0
33
A header file for use with NavPower's binary navmesh files.
44
55
Licensed under the MIT License
@@ -149,11 +149,11 @@ namespace NavPower
149149
uint32_t m_kdTreeBytes;
150150
uint32_t m_linkRecordBytes = 0;
151151
uint32_t m_totalBytes;
152-
float m_buildScale = 2.0;
153-
float m_voxSize = 0.1;
154-
float m_radius = 0.2;
155-
float m_stepHeight = 0.3;
156-
float m_height = 1.8; // Human Height
152+
float m_buildScale = 2.0f;
153+
float m_voxSize = 0.1f;
154+
float m_radius = 0.2f;
155+
float m_stepHeight = 0.3f;
156+
float m_height = 1.8f; // Human Height
157157
BBox m_bbox;
158158
Axis m_buildUpAxis = Axis::Z;
159159
// In NAVPs from Hitman WoA the padding isn't just 0x00
@@ -408,22 +408,19 @@ namespace NavPower
408408
bool compareY(Area& a1, Area& a2);
409409
bool compareZ(Area& a1, Area& a2);
410410

411-
class NavMesh
411+
class NavGraph
412412
{
413413
public:
414-
Binary::Header* m_hdr;
415-
Binary::SectionHeader* m_sectHdr;
416-
Binary::NavSetHeader* m_setHdr;
417-
Binary::NavGraphHeader* m_graphHdr;
414+
Binary::NavGraphHeader* m_hdr;
418415
std::vector<Area> m_areas;
419416
Binary::KDTreeData* m_kdTreeData;
420417
Binary::KDNode* m_rootKDNode;
421418

422-
NavMesh() {};
423-
NavMesh(const char* p_NavMeshPath) { readJson(p_NavMeshPath);};
419+
NavGraph() {};
420+
NavGraph(auto s_NavGraphJson);
424421

425422

426-
NavMesh(uintptr_t p_data, uint32_t p_filesize) { read(p_data, p_filesize); };
423+
NavGraph(uintptr_t p_data) { read(p_data); };
427424

428425
// Build m_areas pointer to index map so the pointers can be replaced with indices (+1) in the JSON file
429426
std::map<Binary::Area*, uint32_t> AreaPointerToIndexMap();
@@ -451,10 +448,10 @@ namespace NavPower
451448
uint32_t generateKdTree(uintptr_t s_nodePtr, std::vector<Area>& s_areas, std::map<Binary::Area*, uint32_t>& p_AreaPointerToNavGraphOffsetMap);
452449

453450
void writeJson(std::ostream& f);
454-
void readJson(const char* p_NavMeshPath);
451+
void readJson(auto s_NavGraphJson);
455452
void writeBinary(std::ostream& f);
456453

457-
void read(uintptr_t p_data, uint32_t p_filesize);
454+
void read(uintptr_t& p_data);
458455

459456
// This parses the k-d tree and outputs it as a vector of bounding boxes
460457
std::map<uint32_t, std::vector<std::pair<uint32_t, BBox>>> ParseKDTree()
@@ -507,6 +504,44 @@ namespace NavPower
507504
}
508505
};
509506

507+
class Section
508+
{
509+
public:
510+
Binary::SectionHeader* m_hdr;
511+
Binary::NavSetHeader* m_setHdr;
512+
std::vector<NavGraph> m_aNavGraphs;
513+
514+
Section(){};
515+
Section(uintptr_t& p_data) { read(p_data); };
516+
517+
void read(uintptr_t& p_data);
518+
519+
void readJson(auto p_SectionJson);
520+
521+
void writeJson(std::ofstream& f);
522+
523+
void writeBinary(std::ostream& f);
524+
};
525+
526+
class NavMesh
527+
{
528+
public:
529+
Binary::Header* m_hdr;
530+
std::vector<Section> m_aSections;
531+
532+
NavMesh() {};
533+
NavMesh(const char* p_NavGraphJsonPath);
534+
NavMesh(uintptr_t p_data, uint32_t p_filesize) { read(p_data, p_filesize); };
535+
536+
void read(uintptr_t p_data, uint32_t p_filesize);
537+
538+
void readJson(const char* p_NavGraphJsonPath);
539+
540+
void writeJson(std::ofstream& f);
541+
542+
void writeBinary(std::ostream& f);
543+
};
544+
510545
// This function was made by github.com/OrfeasZ aka NoFaTe
511546
uint32_t CalculateChecksum(void* p_Data, uint32_t p_Size);
512547
} // namespace NavPower

lib/Debug/NavWeakness.dll

39.5 KB
Binary file not shown.

lib/Release/NavWeakness.dll

10 KB
Binary file not shown.

src/NavKit.cpp

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* SOFTWARE.
2121
*/
2222
#include <SDL.h>
23+
#include <SDL_syswm.h>
2324
#include <cpptrace/from_current.hpp>
2425
#include "../include/NavKit/module/Airg.h"
2526
#include "../include/NavKit/module/Gui.h"
@@ -34,8 +35,48 @@
3435
#include "../include/NavKit/util/ErrorHandler.h"
3536
#include "../include/NavKit/util/FileUtil.h"
3637
#include "../include/NavKit/util/UpdateChecker.h"
38+
#include <windows.h>
39+
3740
#undef main
3841

42+
void runFrameIteration() {
43+
Renderer::getInstance().renderFrame();
44+
InputHandler::getInstance().hitTest();
45+
Gui::getInstance().drawGui();
46+
47+
SceneExtract::getInstance().finalizeExtractScene();
48+
SceneMesh::getInstance().finalizeSceneMeshBuild();
49+
Navp::getInstance().finalizeBuild();
50+
SceneMesh::getInstance().finalizeLoad();
51+
Airg::getInstance().finalizeSave();
52+
SceneMesh::getInstance().finalizeExtractResources();
53+
Renderer::getInstance().finalizeFrame();
54+
}
55+
56+
bool mainLoopIteration() {
57+
if (InputHandler::getInstance().handleInput() == InputHandler::QUIT) {
58+
return false;
59+
}
60+
runFrameIteration();
61+
return true;
62+
}
63+
64+
static int SDLCALL eventFilter(void* userdata, SDL_Event* event) {
65+
if (event->type == SDL_SYSWMEVENT) {
66+
const SDL_SysWMmsg* wmMsg = event->syswm.msg;
67+
if (wmMsg->subsystem == SDL_SYSWM_WINDOWS) {
68+
if (wmMsg->msg.win.msg == WM_ENTERMENULOOP) {
69+
SetTimer(wmMsg->msg.win.hwnd, 1, 1, nullptr);
70+
} else if (wmMsg->msg.win.msg == WM_EXITMENULOOP) {
71+
KillTimer(wmMsg->msg.win.hwnd, 1);
72+
} else if (wmMsg->msg.win.msg == WM_TIMER) {
73+
runFrameIteration();
74+
}
75+
}
76+
}
77+
return 1;
78+
}
79+
3980
int SDL_main(const int argc, char** argv) {
4081
CPPTRACE_TRY
4182
{
@@ -49,34 +90,16 @@ int SDL_main(const int argc, char** argv) {
4990
}
5091
renderer.initShaders();
5192
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
93+
SDL_SetEventFilter(eventFilter, nullptr);
5294

5395
UpdateChecker& updateChecker = UpdateChecker::getInstance();
5496
updateChecker.startUpdateCheck();
5597

56-
SceneExtract& sceneExtract = SceneExtract::getInstance();
57-
Navp& navp = Navp::getInstance();
58-
SceneMesh& obj = SceneMesh::getInstance();
59-
Airg& airg = Airg::getInstance();
60-
InputHandler& inputHandler = InputHandler::getInstance();
6198
Menu::updateMenuState();
62-
Gui& gui = Gui::getInstance();
6399
bool isRunning = true;
64100
Logger::log(NK_INFO, "NavKit initialized.");
65101
while (isRunning) {
66-
if (inputHandler.handleInput() == InputHandler::QUIT) {
67-
isRunning = false;
68-
}
69-
renderer.renderFrame();
70-
inputHandler.hitTest();
71-
gui.drawGui();
72-
73-
sceneExtract.finalizeExtractScene();
74-
obj.finalizeSceneMeshBuild();
75-
navp.finalizeBuild();
76-
obj.finalizeLoad();
77-
airg.finalizeSave();
78-
obj.finalizeExtractResources();
79-
renderer.finalizeFrame();
102+
isRunning = mainLoopIteration();
80103
}
81104

82105
NFD_Quit();

0 commit comments

Comments
 (0)