vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
script_module.h
1#pragma once
2
3#include <filesystem>
4#include <memory>
5#include <string>
6
7#include "platform/library/dynamic_library.h"
8
9namespace Vkm::Engine {
10
11class BehaviorSystem;
12class EventBus;
13class NetSession;
14class ResourceManager;
15class Scene;
16
23class ScriptModule {
24 public:
25 ScriptModule() = default;
26 ~ScriptModule();
27
28 ScriptModule(const ScriptModule& other) = delete;
29 ScriptModule& operator=(const ScriptModule& other) = delete;
30
31 ScriptModule(ScriptModule && other) = delete;
32 ScriptModule& operator=(ScriptModule && other) = delete;
33
34 public:
46 bool load(const std::filesystem::path& modulePath, EventBus* events);
47
61 bool reload(Scene& scene, BehaviorSystem& behaviors, EventBus& events);
62
70 bool buildScene(Scene& scene, ResourceManager& resources);
71
81 bool setupNetwork(NetSession& session);
82
91 void unload(EventBus& events);
92
99 void expect(const std::filesystem::path& modulePath, EventBus& events);
100
101 bool isLoaded() const { return m_lib->isLoaded(); }
102
109 const std::filesystem::path& modulePath() const { return m_modulePath; }
110
111 private:
115 struct OpenedModule {
116 std::unique_ptr<DynamicLibrary> lib;
117 std::filesystem::path copy;
118 };
119
120 private:
129 OpenedModule openBuilt();
130
138 void adopt(OpenedModule opened);
139
148 void releaseRegistrations(EventBus* events);
149
150 private:
151 std::unique_ptr<DynamicLibrary> m_lib = std::make_unique<DynamicLibrary>();
152 NetSession* m_net = nullptr;
153 std::filesystem::path m_modulePath;
154 std::filesystem::path m_loadedCopyPath;
155 int m_reloadCounter = 0;
156};
157
158} // namespace Vkm::Engine
Drives the lifecycle of every entity's ScriptComponent behaviors.
Definition behavior_system.h:27
Typed pub/sub event dispatcher.
Definition event_bus.h:22
One end of a game, whether it is the authority or a guest.
Definition net_session.h:116
Open type-erased resource registry with typed handles and generational lifetimes.
Definition resource_manager.h:46
Central registry managing entities and an open set of component types.
Definition scene.h:29
void unload(EventBus &events)
Drop the loaded module and the behavior types it registered.
void expect(const std::filesystem::path &modulePath, EventBus &events)
Unload whatever is loaded and remember modulePath for a project not yet built.
bool buildScene(Scene &scene, ResourceManager &resources)
Let the module seed scene through the optional vkmBuildScene, if it has one.
const std::filesystem::path & modulePath() const
The built module this loaded from, not the mapped copy: the file to watch for a build.
Definition script_module.h:109
bool setupNetwork(NetSession &session)
Let the module say what a player is, through the optional vkmSetupNetwork.
bool reload(Scene &scene, BehaviorSystem &behaviors, EventBus &events)
Hot-reload from the same path: serialize, swap module, recreate.
bool load(const std::filesystem::path &modulePath, EventBus *events)
Load the gameplay module and register its behaviors.