Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68dd00ed4a | ||
|
|
459aa18387 | ||
|
|
72dd8d214d | ||
|
|
f01faf7351 |
@@ -5,8 +5,10 @@
|
|||||||
!/include
|
!/include
|
||||||
!/src
|
!/src
|
||||||
!/tests
|
!/tests
|
||||||
|
!/utils
|
||||||
|
|
||||||
# Include files
|
# Include files
|
||||||
!/.gitignore
|
!/.gitignore
|
||||||
!/CMakeLists.txt
|
!/CMakeLists.txt
|
||||||
!/Makefile
|
!/Makefile
|
||||||
|
!/README.md
|
||||||
|
|||||||
+7
-1
@@ -4,6 +4,8 @@ project(magic_scrolls)
|
|||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
find_package(SQLite3 REQUIRED)
|
find_package(SQLite3 REQUIRED)
|
||||||
|
find_package(oatpp 1.4.0 REQUIRED)
|
||||||
|
find_package(oatpp-swagger 1.4.0 REQUIRED)
|
||||||
|
|
||||||
file(GLOB_RECURSE sources
|
file(GLOB_RECURSE sources
|
||||||
"${CMAKE_SOURCE_DIR}/src/*.cpp")
|
"${CMAKE_SOURCE_DIR}/src/*.cpp")
|
||||||
@@ -11,7 +13,11 @@ file(GLOB_RECURSE sources
|
|||||||
add_executable(magic_scrolls ${sources})
|
add_executable(magic_scrolls ${sources})
|
||||||
|
|
||||||
target_include_directories(magic_scrolls PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
target_include_directories(magic_scrolls PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
||||||
target_link_libraries(magic_scrolls PRIVATE SQLite::SQLite3)
|
target_link_libraries(magic_scrolls PRIVATE
|
||||||
|
SQLite::SQLite3
|
||||||
|
oatpp::oatpp
|
||||||
|
oatpp::oatpp-swagger
|
||||||
|
)
|
||||||
|
|
||||||
# -------
|
# -------
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Magic Scrolls
|
||||||
|
|
||||||
|
Server-side game engine for the game "Magic Scrolls".
|
||||||
|
|
||||||
|
This engine is building as:
|
||||||
|
|
||||||
|
- **Core**: provides event bus, database providers factory, module registration, lifecycle events
|
||||||
|
- **Modules**: separate parts that can use core features using engine public API
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- **Make**: 4.4.1
|
||||||
|
- **CMake**: 4.2.3
|
||||||
|
- **GCC**: 15.2.0
|
||||||
|
- **sqlite3-dev** (lib): 3.46.1
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
|
||||||
|
1. Clone repository
|
||||||
|
2. Run `sudo ./utils/install-oatpp.sh`
|
||||||
|
3. Build: `cmake -B build` and then `cmake --build build`
|
||||||
|
4. Run: `./build/magic_scrolls
|
||||||
@@ -12,32 +12,16 @@
|
|||||||
class MscEngine : public IMscEngineModuleAPI
|
class MscEngine : public IMscEngineModuleAPI
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
using clock = std::chrono::steady_clock;
|
/// Loaded modules list
|
||||||
|
|
||||||
/// @brief Loaded modules list
|
|
||||||
std::vector<std::shared_ptr<MscEngineModule>> _modules;
|
std::vector<std::shared_ptr<MscEngineModule>> _modules;
|
||||||
|
|
||||||
/// @brief Common event bus
|
|
||||||
MscEventBus _bus;
|
MscEventBus _bus;
|
||||||
|
|
||||||
/// @brief Is engine running rn
|
|
||||||
bool _isRunning = false;
|
|
||||||
|
|
||||||
/// @brief Last update time
|
|
||||||
clock::time_point _lastUpdate;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Actual version
|
/// Actual version
|
||||||
static uint16_t REV;
|
static uint16_t REV;
|
||||||
|
|
||||||
MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules);
|
MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules);
|
||||||
|
|
||||||
/// @brief Start engine
|
|
||||||
void start();
|
|
||||||
|
|
||||||
/// @brief Stop engine
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
MscEventBus &getBus() override;
|
MscEventBus &getBus() override;
|
||||||
std::unordered_map<std::string, std::uint16_t> getLoadedModules() const override;
|
std::unordered_map<std::string, std::uint16_t> getLoadedModules() const override;
|
||||||
MscEngineModule &getModule(const std::string &name) override;
|
MscEngineModule &getModule(const std::string &name) override;
|
||||||
|
|||||||
@@ -23,26 +23,8 @@ public:
|
|||||||
virtual const std::unordered_map<std::string, MscRevisionRange> &
|
virtual const std::unordered_map<std::string, MscRevisionRange> &
|
||||||
getDependencies() const = 0;
|
getDependencies() const = 0;
|
||||||
|
|
||||||
/// @brief Module initialization
|
/// Module initialization phase
|
||||||
/// @param engine engine public API for modules
|
|
||||||
virtual void onInitialize(IMscEngineModuleAPI &engine) = 0;
|
virtual void onInitialize(IMscEngineModuleAPI &engine) = 0;
|
||||||
|
|
||||||
/// @brief Engine start event handler
|
|
||||||
/// @param engine engine public API for modules
|
|
||||||
virtual void onStart(IMscEngineModuleAPI &engine) = 0;
|
|
||||||
|
|
||||||
/// @brief Engine update cycle step
|
|
||||||
/// @param engine engine public API for modules
|
|
||||||
/// @param dt loop delta
|
|
||||||
virtual void onUpdate(IMscEngineModuleAPI &engine, float dt) = 0;
|
|
||||||
|
|
||||||
/// @brief Engine stop event handler
|
|
||||||
/// @param engine engine public API for modules
|
|
||||||
virtual void onStop(IMscEngineModuleAPI &engine) = 0;
|
|
||||||
|
|
||||||
/// @brief Module destroying
|
|
||||||
/// @param engine engine public API for modules
|
|
||||||
virtual void onDestory(IMscEngineModuleAPI &engine) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __MCS_ENGINE_MODULE_HPP__
|
#endif // __MCS_ENGINE_MODULE_HPP__
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
#ifndef __MSC_TEST_1_MODULE_HPP__
|
|
||||||
#define __MSC_TEST_1_MODULE_HPP__
|
|
||||||
|
|
||||||
#include "engine/core/engine_module.hpp"
|
|
||||||
#include "engine/core/engine_module_api.hpp"
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
class Test1Module : public MscEngineModule
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
~Test1Module() = default;
|
|
||||||
|
|
||||||
std::string getName() const override;
|
|
||||||
uint16_t getRev() const override;
|
|
||||||
const std::unordered_map<std::string, MscRevisionRange> &
|
|
||||||
getDependencies() const override;
|
|
||||||
|
|
||||||
void onInitialize(IMscEngineModuleAPI &engine) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __MSC_TEST_1_MODULE_HPP__
|
|
||||||
@@ -49,38 +49,11 @@ MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules)
|
|||||||
std::to_string(current_rev));
|
std::to_string(current_rev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.get()->onInitialize(*this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_modules = std::move(modules);
|
_modules = std::move(modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MscEngine::start()
|
|
||||||
{
|
|
||||||
if (_isRunning)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_isRunning = true;
|
|
||||||
_lastUpdate = clock::now();
|
|
||||||
|
|
||||||
double accumulator = 0.0;
|
|
||||||
constexpr double fixedDt = 1.0 / 30.0;
|
|
||||||
|
|
||||||
while (_isRunning)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MscEngine::stop()
|
|
||||||
{
|
|
||||||
if (!_isRunning)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_isRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MscEventBus &MscEngine::getBus()
|
MscEventBus &MscEngine::getBus()
|
||||||
{
|
{
|
||||||
return _bus;
|
return _bus;
|
||||||
|
|||||||
Executable
+44
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
BUILD_TYPE=$1
|
||||||
|
|
||||||
|
if [ -z "$BUILD_TYPE" ]; then
|
||||||
|
BUILD_TYPE="Debug"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf tmp
|
||||||
|
mkdir tmp
|
||||||
|
cd tmp
|
||||||
|
|
||||||
|
function install_module () {
|
||||||
|
|
||||||
|
BUILD_TYPE=$1
|
||||||
|
MODULE_NAME=$2
|
||||||
|
NPROC=$(nproc)
|
||||||
|
|
||||||
|
if [ -z "$NPROC" ]; then
|
||||||
|
NPROC=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "-> [ ] Installing '$MODULE_NAME' ($BUILD_TYPE)..."
|
||||||
|
|
||||||
|
git clone --depth=1 https://github.com/oatpp/$MODULE_NAME
|
||||||
|
|
||||||
|
cd $MODULE_NAME
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOATPP_BUILD_TESTS=OFF -DOATPP_SQLITE_AMALGAMATION=ON ..
|
||||||
|
make install -j $NPROC
|
||||||
|
|
||||||
|
cd ../..
|
||||||
|
|
||||||
|
echo "-> [x] Module '$MODULE_NAME' installed!"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
install_module $BUILD_TYPE oatpp
|
||||||
|
install_module $BUILD_TYPE oatpp-swagger
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
rm -rf tmp
|
||||||
Reference in New Issue
Block a user