Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68dd00ed4a | ||
|
|
459aa18387 | ||
|
|
72dd8d214d | ||
|
|
f01faf7351 |
@@ -1,3 +0,0 @@
|
|||||||
BasedOnStyle: LLVM
|
|
||||||
IndentWidth: 2
|
|
||||||
BreakBeforeBraces: Allman
|
|
||||||
+2
-1
@@ -5,9 +5,10 @@
|
|||||||
!/include
|
!/include
|
||||||
!/src
|
!/src
|
||||||
!/tests
|
!/tests
|
||||||
|
!/utils
|
||||||
|
|
||||||
# Include files
|
# Include files
|
||||||
!/.clang-format
|
|
||||||
!/.gitignore
|
!/.gitignore
|
||||||
!/CMakeLists.txt
|
!/CMakeLists.txt
|
||||||
!/Makefile
|
!/Makefile
|
||||||
|
!/README.md
|
||||||
|
|||||||
+8
-15
@@ -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()
|
||||||
@@ -30,25 +36,16 @@ add_executable(engine_test
|
|||||||
src/engine/core/engine.cpp
|
src/engine/core/engine.cpp
|
||||||
src/engine/core/engine_db_provider.cpp
|
src/engine/core/engine_db_provider.cpp
|
||||||
)
|
)
|
||||||
add_executable(lifecycle_test
|
|
||||||
tests/engine/lifecycle_test.cpp
|
|
||||||
src/engine/core/engine.cpp
|
|
||||||
src/engine/core/engine_db_provider.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(event_bus_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
target_include_directories(event_bus_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
||||||
target_link_libraries(event_bus_test PRIVATE SQLite::SQLite3)
|
target_link_libraries(event_bus_test PRIVATE SQLite::SQLite3)
|
||||||
|
|
||||||
target_include_directories(db_provider_test PUBLIC
|
target_include_directories(db_provider_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
||||||
"${CMAKE_SOURCE_DIR}/include")
|
|
||||||
target_link_libraries(db_provider_test PRIVATE SQLite::SQLite3)
|
target_link_libraries(db_provider_test PRIVATE SQLite::SQLite3)
|
||||||
|
|
||||||
target_include_directories(engine_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
target_include_directories(engine_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
||||||
target_link_libraries(engine_test PRIVATE SQLite::SQLite3)
|
target_link_libraries(engine_test PRIVATE SQLite::SQLite3)
|
||||||
|
|
||||||
target_include_directories(lifecycle_test PUBLIC "${CMAKE_SOURCE_DIR}/include")
|
|
||||||
target_link_libraries(lifecycle_test PRIVATE SQLite::SQLite3)
|
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
NAME "Event Bus"
|
NAME "Event Bus"
|
||||||
COMMAND event_bus_test
|
COMMAND event_bus_test
|
||||||
@@ -61,7 +58,3 @@ add_test(
|
|||||||
NAME "Engine"
|
NAME "Engine"
|
||||||
COMMAND engine_test
|
COMMAND engine_test
|
||||||
)
|
)
|
||||||
add_test(
|
|
||||||
NAME "Lifecycle"
|
|
||||||
COMMAND lifecycle_test
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1,50 +1,32 @@
|
|||||||
#ifndef __MCS_ENGINE_HPP__
|
#ifndef __MCS_ENGINE_HPP__
|
||||||
#define __MCS_ENGINE_HPP__
|
#define __MCS_ENGINE_HPP__
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <engine/core/engine_db_provider.hpp>
|
|
||||||
#include <engine/core/engine_module.hpp>
|
#include <engine/core/engine_module.hpp>
|
||||||
#include <engine/core/engine_module_api.hpp>
|
#include <engine/core/engine_module_api.hpp>
|
||||||
|
#include <engine/core/engine_db_provider.hpp>
|
||||||
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/// Ядро движка Magic Srolls
|
/// Magic Srolls engine core
|
||||||
class MscEngine : public IMscEngineModuleAPI
|
class MscEngine : public IMscEngineModuleAPI
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/// @brief Загруженные модули
|
/// Loaded modules list
|
||||||
std::vector<std::shared_ptr<MscEngineModule>> _modules;
|
std::vector<std::shared_ptr<MscEngineModule>> _modules;
|
||||||
|
|
||||||
/// @brief Общая событийная шина движка
|
|
||||||
MscEventBus _bus;
|
MscEventBus _bus;
|
||||||
|
|
||||||
/// @brief Флаг работы движка
|
|
||||||
bool _isRunning = false;
|
|
||||||
|
|
||||||
/// @brief Время последнего тика
|
|
||||||
clock::time_point _lastUpdate;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @brief Номер ревизии
|
/// 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);
|
||||||
~MscEngine() = default;
|
|
||||||
|
|
||||||
/// @brief Запустить движок
|
|
||||||
void start();
|
|
||||||
|
|
||||||
/// @brief Остановить движок
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
MscEventBus &getBus() override;
|
MscEventBus &getBus() override;
|
||||||
std::unordered_map<std::string, std::uint16_t>
|
std::unordered_map<std::string, std::uint16_t> getLoadedModules() const override;
|
||||||
getLoadedModules() const override;
|
MscEngineModule &getModule(const std::string &name) override;
|
||||||
std::shared_ptr<MscEngineModule> &getModule(const std::string &name) override;
|
|
||||||
std::unique_ptr<MscEngineDBProvider> createDBProvider() override;
|
std::unique_ptr<MscEngineDBProvider> createDBProvider() override;
|
||||||
std::unique_ptr<MscEngineDBProvider>
|
std::unique_ptr<MscEngineDBProvider> createDBProvider(const std::string &filepath) override;
|
||||||
createDBProvider(const std::string &filepath) override;
|
|
||||||
void requestStop() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __MCS_ENGINE_HPP__
|
#endif // __MCS_ENGINE_HPP__
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef __MCS_ENGINE_MODULE_HPP__
|
#ifndef __MCS_ENGINE_MODULE_HPP__
|
||||||
#define __MCS_ENGINE_MODULE_HPP__
|
#define __MCS_ENGINE_MODULE_HPP__
|
||||||
|
|
||||||
#include "engine/core/engine_module_api.hpp"
|
|
||||||
#include "engine/utils/rev_range.hpp"
|
#include "engine/utils/rev_range.hpp"
|
||||||
|
#include "engine/core/engine_module_api.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -23,27 +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,
|
|
||||||
IMscEngineModuleAPI::clock::duration 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,43 +1,34 @@
|
|||||||
#ifndef __MSC_ENGINE_MODULE_API_HPP__
|
#ifndef __MSC_ENGINE_MODULE_API_HPP__
|
||||||
#define __MSC_ENGINE_MODULE_API_HPP__
|
#define __MSC_ENGINE_MODULE_API_HPP__
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <engine/core/engine_bus.hpp>
|
#include <engine/core/engine_bus.hpp>
|
||||||
#include <engine/core/engine_db_provider.hpp>
|
#include <engine/core/engine_db_provider.hpp>
|
||||||
#include <memory>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class MscEngineModule;
|
class MscEngineModule;
|
||||||
|
|
||||||
/// @brief Публичный API движка для модулей
|
|
||||||
class IMscEngineModuleAPI
|
class IMscEngineModuleAPI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using clock = std::chrono::steady_clock;
|
|
||||||
|
|
||||||
virtual ~IMscEngineModuleAPI() = default;
|
virtual ~IMscEngineModuleAPI() = default;
|
||||||
|
|
||||||
/// @brief Получить доступ к событийной шине
|
/// @brief Get access to engine event bus
|
||||||
virtual MscEventBus &getBus() = 0;
|
virtual MscEventBus &getBus() = 0;
|
||||||
|
|
||||||
/// @brief Получить список загруженных модулей
|
/// @brief Get access to loaded module list
|
||||||
virtual std::unordered_map<std::string, std::uint16_t>
|
virtual std::unordered_map<std::string, std::uint16_t> getLoadedModules() const = 0;
|
||||||
getLoadedModules() const = 0;
|
|
||||||
|
|
||||||
/// @brief Получить прямой доступ к модулю
|
/// @brief Access module by its name
|
||||||
virtual std::shared_ptr<MscEngineModule> &
|
virtual MscEngineModule &getModule(const std::string &name) = 0;
|
||||||
getModule(const std::string &name) = 0;
|
|
||||||
|
|
||||||
/// @brief Создать провайдер БД с хранением в памяти
|
/// @brief Create database provider with in-memory database
|
||||||
virtual std::unique_ptr<MscEngineDBProvider> createDBProvider() = 0;
|
virtual std::unique_ptr<MscEngineDBProvider> createDBProvider() = 0;
|
||||||
|
|
||||||
/// @brief Создать провайдер БД с указанным файлом
|
/// @brief Create database provider with file database
|
||||||
virtual std::unique_ptr<MscEngineDBProvider>
|
virtual std::unique_ptr<MscEngineDBProvider> createDBProvider(const std::string &filepath) = 0;
|
||||||
createDBProvider(const std::string &filepath) = 0;
|
|
||||||
|
|
||||||
/// @brief Запросить остановку движка
|
|
||||||
virtual void requestStop() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __MSC_ENGINE_MODULE_API_HPP__
|
#endif // __MSC_ENGINE_MODULE_API_HPP__
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
#include "engine/core/engine_module_api.hpp"
|
|
||||||
#include <chrono>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <engine/core/engine.hpp>
|
#include <engine/core/engine.hpp>
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::uint16_t MscEngine::REV = 1;
|
uint16_t MscEngine::REV = 0;
|
||||||
|
|
||||||
MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules)
|
MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules)
|
||||||
{
|
{
|
||||||
@@ -53,71 +49,17 @@ 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()
|
MscEventBus &MscEngine::getBus()
|
||||||
{
|
{
|
||||||
if (_isRunning)
|
return _bus;
|
||||||
return;
|
|
||||||
|
|
||||||
_isRunning = true;
|
|
||||||
_lastUpdate = clock::now();
|
|
||||||
|
|
||||||
for (auto &m : _modules)
|
|
||||||
m->onStart(*this);
|
|
||||||
|
|
||||||
constexpr auto tickDuration = std::chrono::milliseconds(50);
|
|
||||||
auto nextTick = clock::now();
|
|
||||||
|
|
||||||
using UpdateFn = std::function<void(IMscEngineModuleAPI & engine,
|
|
||||||
IMscEngineModuleAPI::clock::duration dt)>;
|
|
||||||
std::vector<UpdateFn> updateFns;
|
|
||||||
updateFns.reserve(_modules.size());
|
|
||||||
|
|
||||||
for (auto &m : _modules)
|
|
||||||
updateFns.emplace_back([m](IMscEngineModuleAPI &engine,
|
|
||||||
IMscEngineModuleAPI::clock::duration dt)
|
|
||||||
{ m->onUpdate(engine, dt); });
|
|
||||||
|
|
||||||
while (_isRunning)
|
|
||||||
{
|
|
||||||
nextTick += tickDuration;
|
|
||||||
const auto currentTick = clock::now();
|
|
||||||
const auto dt = currentTick - _lastUpdate;
|
|
||||||
|
|
||||||
// TODO: process
|
|
||||||
|
|
||||||
for (auto upd : updateFns)
|
|
||||||
upd(*this, dt);
|
|
||||||
|
|
||||||
_lastUpdate = currentTick;
|
|
||||||
|
|
||||||
std::this_thread::sleep_until(nextTick);
|
|
||||||
if (clock::now() > nextTick + std::chrono::seconds(1))
|
|
||||||
nextTick = clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &m : _modules)
|
|
||||||
m->onStop(*this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MscEngine::stop()
|
std::unordered_map<std::string, std::uint16_t> MscEngine::getLoadedModules() const
|
||||||
{
|
|
||||||
if (!_isRunning)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_isRunning = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MscEventBus &MscEngine::getBus() { return _bus; }
|
|
||||||
|
|
||||||
std::unordered_map<std::string, std::uint16_t>
|
|
||||||
MscEngine::getLoadedModules() const
|
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, std::uint16_t> result;
|
std::unordered_map<std::string, std::uint16_t> result;
|
||||||
for (const auto &module : _modules)
|
for (const auto &module : _modules)
|
||||||
@@ -132,12 +74,12 @@ MscEngine::getLoadedModules() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<MscEngineModule> &MscEngine::getModule(const std::string &name)
|
MscEngineModule &MscEngine::getModule(const std::string &name)
|
||||||
{
|
{
|
||||||
for (auto &module : _modules)
|
for (auto &module : _modules)
|
||||||
{
|
{
|
||||||
if (module.get()->getName() == name)
|
if (module.get()->getName() == name)
|
||||||
return module;
|
return *module.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error("Module not found: " + name);
|
throw std::runtime_error("Module not found: " + name);
|
||||||
@@ -148,13 +90,7 @@ std::unique_ptr<MscEngineDBProvider> MscEngine::createDBProvider()
|
|||||||
return std::make_unique<MscEngineDBProvider>();
|
return std::make_unique<MscEngineDBProvider>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<MscEngineDBProvider>
|
std::unique_ptr<MscEngineDBProvider> MscEngine::createDBProvider(const std::string &filepath)
|
||||||
MscEngine::createDBProvider(const std::string &filepath)
|
|
||||||
{
|
{
|
||||||
return std::make_unique<MscEngineDBProvider>(filepath);
|
return std::make_unique<MscEngineDBProvider>(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MscEngine::requestStop()
|
|
||||||
{
|
|
||||||
this->stop(); // TODO: заменить на флаг
|
|
||||||
}
|
|
||||||
|
|||||||
+8
-1
@@ -1,9 +1,16 @@
|
|||||||
|
#include "engine/modules/test1/test1.hpp"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <engine/core/engine.hpp>
|
#include <engine/core/engine.hpp>
|
||||||
|
#include <memory>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
printf("Hello, engine!\n");
|
auto engine =
|
||||||
|
std::make_unique<MscEngine>(std::vector<std::shared_ptr<MscEngineModule>>{
|
||||||
|
std::make_shared<Test1Module>()});
|
||||||
|
|
||||||
|
printf("Hello, CMake, %p!\n", &engine);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,157 +1,149 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <engine/core/engine.hpp>
|
|
||||||
#include <engine/core/engine_module.hpp>
|
|
||||||
#include <engine/utils/rev_range.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <engine/utils/rev_range.hpp>
|
||||||
|
#include <engine/core/engine.hpp>
|
||||||
|
#include <engine/core/engine_module.hpp>
|
||||||
|
|
||||||
class FirstTestModuleR1 : public MscEngineModule
|
class FirstTestModuleR1 : public MscEngineModule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string getName() const override { return "first_tmod"; };
|
std::string getName() const override
|
||||||
|
{
|
||||||
|
return "first_tmod";
|
||||||
|
};
|
||||||
|
|
||||||
std::uint16_t getRev() const override { return 1; }
|
std::uint16_t getRev() const override
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const std::unordered_map<std::string, MscRevisionRange> &
|
const std::unordered_map<std::string, MscRevisionRange> &getDependencies() const override
|
||||||
getDependencies() const override
|
{
|
||||||
{
|
static const std::unordered_map<std::string, MscRevisionRange> deps{};
|
||||||
static const std::unordered_map<std::string, MscRevisionRange> deps{};
|
return deps;
|
||||||
return deps;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
||||||
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onUpdate(IMscEngineModuleAPI &engine,
|
|
||||||
IMscEngineModuleAPI::clock::duration dt) override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FirstTestModuleR2 : public MscEngineModule
|
class FirstTestModuleR2 : public MscEngineModule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string getName() const override { return "first_tmod"; };
|
std::string getName() const override
|
||||||
|
{
|
||||||
|
return "first_tmod";
|
||||||
|
};
|
||||||
|
|
||||||
std::uint16_t getRev() const override { return 2; }
|
std::uint16_t getRev() const override
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
const std::unordered_map<std::string, MscRevisionRange> &
|
const std::unordered_map<std::string, MscRevisionRange> &getDependencies() const override
|
||||||
getDependencies() const override
|
{
|
||||||
{
|
static const std::unordered_map<std::string, MscRevisionRange> deps{};
|
||||||
static const std::unordered_map<std::string, MscRevisionRange> deps{};
|
return deps;
|
||||||
return deps;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
||||||
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onUpdate(IMscEngineModuleAPI &engine,
|
|
||||||
IMscEngineModuleAPI::clock::duration dt) override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SecondTestModuleE1 : public MscEngineModule
|
class SecondTestModuleE1 : public MscEngineModule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string getName() const override { return "second_tmod"; }
|
std::string getName() const override
|
||||||
|
{
|
||||||
|
return "second_tmod";
|
||||||
|
}
|
||||||
|
|
||||||
std::uint16_t getRev() const override { return 1; }
|
std::uint16_t getRev() const override
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const std::unordered_map<std::string, MscRevisionRange> &
|
const std::unordered_map<std::string, MscRevisionRange> &getDependencies() const override
|
||||||
getDependencies() const override
|
{
|
||||||
{
|
static const std::unordered_map<std::string, MscRevisionRange> deps{
|
||||||
static const std::unordered_map<std::string, MscRevisionRange> deps{
|
{"first_tmod", MscRevisionRange{1, 1}}};
|
||||||
{"first_tmod", MscRevisionRange{1, 1}}};
|
return deps;
|
||||||
return deps;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
||||||
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onUpdate(IMscEngineModuleAPI &engine,
|
|
||||||
IMscEngineModuleAPI::clock::duration dt) override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SecondTestModuleE2 : public MscEngineModule
|
class SecondTestModuleE2 : public MscEngineModule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string getName() const override { return "second_tmod"; }
|
std::string getName() const override
|
||||||
|
{
|
||||||
|
return "second_tmod";
|
||||||
|
}
|
||||||
|
|
||||||
std::uint16_t getRev() const override { return 1; }
|
std::uint16_t getRev() const override
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const std::unordered_map<std::string, MscRevisionRange> &
|
const std::unordered_map<std::string, MscRevisionRange> &getDependencies() const override
|
||||||
getDependencies() const override
|
{
|
||||||
{
|
static const std::unordered_map<std::string, MscRevisionRange> deps{
|
||||||
static const std::unordered_map<std::string, MscRevisionRange> deps{
|
{"first_tmod", MscRevisionRange{1, 2}}};
|
||||||
{"first_tmod", MscRevisionRange{1, 2}}};
|
return deps;
|
||||||
return deps;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
void onInitialize(IMscEngineModuleAPI &engine) override {}
|
||||||
void onStart(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onUpdate(IMscEngineModuleAPI &engine,
|
|
||||||
IMscEngineModuleAPI::clock::duration dt) override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void onStop(IMscEngineModuleAPI &engine) override {}
|
|
||||||
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void testSatisfiedModules()
|
void testSatisfiedModules()
|
||||||
{
|
{
|
||||||
MscEngine engine({std::make_shared<FirstTestModuleR1>(),
|
MscEngine engine({std::make_shared<FirstTestModuleR1>(),
|
||||||
std::make_shared<SecondTestModuleE1>()});
|
std::make_shared<SecondTestModuleE1>()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void testDuplicatedModules()
|
void testDuplicatedModules()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MscEngine engine({
|
MscEngine engine({
|
||||||
std::make_shared<FirstTestModuleR1>(),
|
std::make_shared<FirstTestModuleR1>(),
|
||||||
std::make_shared<FirstTestModuleR2>(),
|
std::make_shared<FirstTestModuleR2>(),
|
||||||
});
|
});
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &error)
|
catch (const std::runtime_error &error)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testUnsatisfiedModules()
|
void testUnsatisfiedModules()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MscEngine engine({std::make_shared<FirstTestModuleR2>(),
|
MscEngine engine({std::make_shared<FirstTestModuleR2>(),
|
||||||
std::make_shared<SecondTestModuleE1>()});
|
std::make_shared<SecondTestModuleE1>()});
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &error)
|
catch (const std::runtime_error &error)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testSatisfiedMultiversionModule()
|
void testSatisfiedMultiversionModule()
|
||||||
{
|
{
|
||||||
MscEngine engine({std::make_shared<FirstTestModuleR2>(),
|
MscEngine engine({std::make_shared<FirstTestModuleR2>(),
|
||||||
std::make_shared<SecondTestModuleE2>()});
|
std::make_shared<SecondTestModuleE2>()});
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
testSatisfiedModules();
|
testSatisfiedModules();
|
||||||
testDuplicatedModules();
|
testDuplicatedModules();
|
||||||
testUnsatisfiedModules();
|
testUnsatisfiedModules();
|
||||||
testSatisfiedMultiversionModule();
|
testSatisfiedMultiversionModule();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
#include "engine/core/engine.hpp"
|
|
||||||
#include "engine/core/engine_module.hpp"
|
|
||||||
#include "engine/utils/rev_range.hpp"
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
bool onInitWasCalled = false;
|
|
||||||
bool onStartWasCalled = false;
|
|
||||||
bool onUpdateWasCalled = false;
|
|
||||||
bool onStopWasCalled = false;
|
|
||||||
|
|
||||||
class TestModule : public MscEngineModule
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string getName() const override { return "test_mod"; }
|
|
||||||
std::uint16_t getRev() const override { return 1; }
|
|
||||||
const std::unordered_map<std::string, MscRevisionRange> &
|
|
||||||
getDependencies() const override
|
|
||||||
{
|
|
||||||
static const std::unordered_map<std::string, MscRevisionRange> deps{};
|
|
||||||
return deps;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onInitialize(IMscEngineModuleAPI &engine) override
|
|
||||||
{
|
|
||||||
onInitWasCalled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onStart(IMscEngineModuleAPI &engine) override
|
|
||||||
{
|
|
||||||
onStartWasCalled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onUpdate(IMscEngineModuleAPI &engine,
|
|
||||||
IMscEngineModuleAPI::clock::duration dt) override
|
|
||||||
{
|
|
||||||
onUpdateWasCalled = true;
|
|
||||||
engine.requestStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onStop(IMscEngineModuleAPI &engine) override { onStopWasCalled = true; }
|
|
||||||
|
|
||||||
void onDestory(IMscEngineModuleAPI &engine) override {}
|
|
||||||
};
|
|
||||||
|
|
||||||
void testStates()
|
|
||||||
{
|
|
||||||
MscEngine engine({std::make_shared<TestModule>()});
|
|
||||||
engine.start();
|
|
||||||
|
|
||||||
assert(onInitWasCalled);
|
|
||||||
assert(onStartWasCalled);
|
|
||||||
assert(onUpdateWasCalled);
|
|
||||||
assert(onStopWasCalled);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
testStates();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
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