Skip to content

Commit ee156ce

Browse files
Merge pull request #22 from usermicrodevices/develop
Develop
2 parents 8de70db + 3d8b0b2 commit ee156ce

36 files changed

Lines changed: 1831 additions & 1969 deletions

CMakeLists.txt

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ else()
1818
message(STATUS "ASIO found via find_package")
1919
endif()
2020

21+
# Add GLM include directory
2122
set(GLM_DIR "${CMAKE_SOURCE_DIR}/thirdparty/glm")
2223
set(GLM_INCLUDE_DIRS "${GLM_DIR}")
24+
include_directories(${glm_INCLUDE_DIRS})
2325

2426
find_package(nlohmann_json 3.2.0 QUIET)
2527
if(NOT nlohmann_json_FOUND)
@@ -58,8 +60,13 @@ find_package(ZLIB REQUIRED)
5860
# Find OpenSSL for encryption
5961
find_package(OpenSSL REQUIRED)
6062

61-
# Add GLM include directory
62-
include_directories(${glm_INCLUDE_DIRS})
63+
# Find UUID library
64+
find_library(UUID_LIBRARY NAMES uuid)
65+
if(NOT UUID_LIBRARY)
66+
message(FATAL_ERROR "libuuid not found - install libuuid-dev or equivalent")
67+
endif()
68+
69+
find_library(CRYPT_LIB crypt)
6370

6471
# Config system
6572
set(CONFIG_SOURCES
@@ -79,7 +86,10 @@ set(PROCESS_SOURCES
7986
# Scripting system
8087
set(SCRIPTING_SOURCES
8188
src/scripting/PythonAPI.cpp
89+
#src/scripting/PythonEvent.cpp
90+
src/scripting/PythonModule.cpp
8291
src/scripting/PythonScripting.cpp
92+
src/scripting/ScriptHotReloader.cpp
8393
)
8494

8595
# Network system
@@ -93,32 +103,36 @@ set(NETWORK_SOURCES
93103
src/network/WebSocketProtocol.cpp
94104
)
95105

96-
# Core logic system
97-
set(LOGIC_CORE_SOURCES
98-
src/game/LogicCore.cpp
99-
src/game/LogicWorld.cpp
100-
src/game/LogicEntity.cpp
101-
src/game/GameLogic.cpp
102-
src/game/EntityManager.cpp
103-
src/game/Player.cpp
104-
src/game/NPCEntity.cpp
105-
)
106-
107106
# Loot system source files
108107
set(LOOT_SOURCES
109108
src/game/LootItem.cpp
110109
src/game/InventorySystem.cpp
111110
src/game/LootTable.cpp
111+
src/game/LootTableManager.cpp
112112
)
113113

114114
# 3D world system
115115
set(WORLD_SOURCES
116116
src/game/WorldChunk.cpp
117117
src/game/WorldGenerator.cpp
118+
src/game/NPCEntity.cpp
118119
src/game/NPCSystem.cpp
119120
src/game/MobSystem.cpp
120121
src/game/GameEntity.cpp
121122
src/game/CollisionSystem.cpp
123+
src/game/LogicWorld.cpp
124+
)
125+
126+
# Core logic system
127+
set(LOGIC_CORE_SOURCES
128+
src/game/LogicCore.cpp
129+
src/game/LogicEntity.cpp
130+
src/game/GameLogic.cpp
131+
src/game/EntityManager.cpp
132+
src/game/SkillSystem.cpp
133+
src/game/Player.cpp
134+
src/game/PlayerManager.cpp
135+
src/game/QuestManager.cpp
122136
)
123137

124138
# Database system
@@ -130,10 +144,9 @@ set(DATABASE_SOURCES
130144
if(USE_CITUS)
131145
message(STATUS "Building with Citus support")
132146
list(APPEND DATABASE_SOURCES src/database/CitusClient.cpp)
133-
add_definitions(-DUSE_CITUS=1)
134147
else()
135148
message(STATUS "Building without Citus (PostgreSQL only)")
136-
add_definitions(-DUSE_CITUS=0)
149+
# No definition added here – Citus code is completely excluded
137150
endif()
138151

139152
# Include directories
@@ -160,6 +173,11 @@ add_executable(gameserver
160173
${DATABASE_SOURCES}
161174
)
162175

176+
# Add target-specific preprocessor definitions
177+
if(USE_CITUS)
178+
target_compile_definitions(gameserver PRIVATE USE_CITUS=1)
179+
endif()
180+
163181
# Link libraries
164182
target_link_libraries(gameserver PRIVATE
165183
${OPENGL_LIBRARIES}
@@ -173,6 +191,8 @@ target_link_libraries(gameserver PRIVATE
173191
Python3::Python
174192
fmt::fmt
175193
spdlog::spdlog
194+
${UUID_LIBRARY}
195+
${CRYPT_LIB}
176196
)
177197

178198
# Compiler flags

include/database/DbManager.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class DbManager {
4646
void Shutdown();
4747
bool IsInitialized() const { return initialized_; }
4848

49+
std::string EscapeString(const std::string& input);
50+
4951
// Backend Management
5052
bool SaveGameState(const std::string& key, const nlohmann::json& state);
5153
bool SetBackend(DatabaseType type, const nlohmann::json& config);
@@ -54,6 +56,13 @@ class DbManager {
5456
nlohmann::json Query(const std::string& sql) { return backend_->Query(sql); };
5557
nlohmann::json GetPlayer(uint64_t playerId){ return backend_->GetPlayer(playerId); };
5658

59+
bool UpdatePlayerPosition(uint64_t playerId, float x, float y, float z) {
60+
if (backend_) {
61+
return backend_->UpdatePlayerPosition(playerId, x, y, z);
62+
}
63+
return false;
64+
}
65+
5766
// Configuration
5867
bool LoadConfiguration(const std::string& configPath = "");
5968
nlohmann::json GetConfiguration() const { return config_; }

include/game/GameLogic.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "game/PlayerManager.hpp"
1616
#include "game/InventorySystem.hpp"
1717
#include "game/LootTableManager.hpp"
18-
#include "game/MobSystem.hpp"
18+
//#include "game/MobSystem.hpp"
1919
#include "game/SkillSystem.hpp"
2020
#include "game/QuestManager.hpp"
2121
#include "game/EntityManager.hpp"

include/game/LogicCore.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
#include "network/BinaryProtocol.hpp"
2121
//#include "config/ConfigManager.hpp"
2222
//#include "logging/Logger.hpp"
23-
//#include "database/DbManager.hpp"
24-
//#include "game/RAIIThread.hpp"
23+
#include "database/DbManager.hpp"
24+
25+
#include "game/RAIIThread.hpp"
2526
#include "game/LogicWorld.hpp"
2627
#include "game/LogicEntity.hpp"
27-
//#include "game/PlayerManager.hpp"
2828

29-
class PythonScripting;
30-
class ScriptHotReloader;
29+
//class PlayerManager;
30+
#include "game/PlayerManager.hpp"
31+
32+
//class PythonScripting;
33+
//class ScriptHotReloader;
3134
#include "scripting/PythonScripting.hpp"
3235

3336
class LogicCore {

include/game/LogicWorld.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class LogicWorld {
6060
int GetActiveChunkCount() const { return activeChunkCount_; }
6161
void SaveChunkData();
6262

63+
void SetTimeOfDay(float time); // 0.0 to 1.0
64+
float GetTimeOfDay() const;
65+
6366
private:
6467
LogicWorld();
6568
~LogicWorld();
@@ -80,4 +83,5 @@ class LogicWorld {
8083
// Entity storage
8184
std::unordered_map<uint64_t, std::shared_ptr<GameEntity>> entities_;
8285
mutable std::mutex entitiesMutex_;
86+
std::atomic<float> currentTimeOfDay_{0.0f}; // 0.0 to 1.0
8387
};

include/game/LootItem.hpp

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

3+
#include <algorithm>
34
#include <string>
45
#include <vector>
5-
#include <nlohmann/json.hpp>
6+
67
#include <glm/glm.hpp>
8+
#include <nlohmann/json.hpp>
79

810
enum class LootRarity {
911
COMMON = 0,
@@ -59,6 +61,9 @@ class LootItem {
5961
const glm::vec3& GetIconColor() const { return iconColor_; }
6062

6163
// Setters
64+
void SetId(uint64_t id) { id_ = id; }
65+
void SetName(const std::string& name) { name_ = name; }
66+
void SetRarity(LootRarity rarity = LootRarity::COMMON) { rarity_ = rarity; }
6267
void SetStackSize(int size);
6368
void SetLevelRequirement(int level);
6469
void SetIconColor(const glm::vec3& color);

include/game/LootTable.hpp

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

3-
#include <vector>
3+
#include <algorithm>
4+
#include <fstream>
45
#include <random>
6+
#include <vector>
57
#include <unordered_map>
68

9+
#include "logging/Logger.hpp"
710
#include "game/LootItem.hpp"
811

912
struct LootEntry {
10-
std::string itemId;
13+
uint64_t itemId;
14+
std::string name;
1115
float dropChance = 0.0f; // 0.0 to 1.0
1216
int minQuantity = 1;
1317
int maxQuantity = 1;

include/game/MobSystem.hpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// MobSystem.hpp
22
#pragma once
33

4-
#include <vector>
5-
#include <unordered_map>
4+
#include <algorithm>
65
#include <chrono>
6+
#include <cmath>
77
#include <random>
8+
#include <vector>
9+
#include <unordered_map>
810

911
#include <glm/glm.hpp>
1012

11-
#include "game/WorldChunk.hpp"
12-
#include "game/LootTable.hpp"
13+
#include "logging/Logger.hpp"
14+
#include "config/ConfigManager.hpp"
1315

14-
//#include "game/NPCEntity.hpp"
15-
enum class NPCType;
16-
class NPCEntity;
16+
//#include "game/WorldChunk.hpp"
17+
//#include "game/LootTable.hpp"
18+
//#include "game/PlayerManager.hpp"
19+
//#include "game/EntityManager.hpp"
20+
//#include "game/LootTableManager.hpp"
21+
#include "game/NPCEntity.hpp"
1722

1823
// Mob spawn zone
1924
struct MobSpawnZone {
@@ -25,7 +30,7 @@ struct MobSpawnZone {
2530
int maxMobs = 10;
2631
float respawnTime = 30.0f; // seconds
2732
std::string name;
28-
std::string lootTableId; // Add loot table reference
33+
std::string lootTableId;
2934
};
3035

3136
// Mob variant (leveled version of a mob type)
@@ -35,7 +40,7 @@ struct MobVariant {
3540
float healthMultiplier = 1.0f;
3641
float damageMultiplier = 1.0f;
3742
float experienceReward = 10.0f;
38-
std::string lootTableId; // Reference to loot table
43+
std::string lootTableId;
3944
};
4045

4146
// Mob death info for rewards

include/game/NPCEntity.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "game/GameEntity.hpp"
1717
#include "game/LootTableManager.hpp"
18-
#include "game/MobSystem.hpp"
18+
//#include "game/MobSystem.hpp"
1919
#include "logging/Logger.hpp"
2020
#include "config/ConfigManager.hpp"
2121

@@ -403,6 +403,10 @@ class NPCEntity : public GameEntity {
403403
NPCLootTable loot_table_;
404404
NPCDialogue dialogue_;
405405

406+
glm::vec3 move_target_;
407+
bool has_move_target_ = false;
408+
float move_speed_multiplier_ = 1.0f;
409+
406410
// Targeting
407411
uint64_t target_id_ = 0;
408412
std::vector<uint64_t> hate_list_; // Ordered by hate/damage dealt
@@ -411,8 +415,6 @@ class NPCEntity : public GameEntity {
411415
// AI state tracking
412416
float state_timer_ = 0.0f;
413417
float idle_timer_ = 0.0f;
414-
float patrol_index_ = 0.0f;
415-
bool patrol_direction_ = true; // true = forward, false = backward
416418

417419
// Combat tracking
418420
float attack_cooldown_ = 0.0f;
@@ -421,6 +423,10 @@ class NPCEntity : public GameEntity {
421423
float summon_cooldown_ = 0.0f;
422424

423425
// Patrol and movement
426+
float patrol_index_ = 0.0f;
427+
bool patrol_direction_ = true; // true = forward, false = backward
428+
float patrol_wait_timer_ = 0.0f;
429+
bool waiting_at_patrol_point_ = false;
424430
glm::vec3 spawn_position_;
425431
std::queue<glm::vec3> patrol_queue_;
426432

@@ -439,6 +445,6 @@ class NPCEntity : public GameEntity {
439445
static constexpr float DESPAWN_DELAY = 10.0f;
440446

441447
friend class NPCAISystem;
442-
friend class MobSystem;
448+
//friend class MobSystem;
443449
friend class EntityManager;
444450
};

0 commit comments

Comments
 (0)