Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
plugins.hpp
Go to the documentation of this file.
1
4#pragma once
5
7#include <aegis2d/ecs/export.hpp>
9
10#include <cstddef>
11#include <filesystem>
12#include <string>
13#include <string_view>
14#include <utility>
15#include <vector>
16
17namespace aegis2d::ecs {
18
21public:
24 explicit PluginContext(Scheduler& systems) noexcept : systems_{&systems} {}
25
28 [[nodiscard]] Scheduler& systems() const noexcept { return *systems_; }
29
32 void add_asset_folder(std::filesystem::path folder) {
33 asset_folders_.push_back(std::move(folder));
34 }
35
38 [[nodiscard]] const std::vector<std::filesystem::path>& asset_folders() const noexcept {
39 return asset_folders_;
40 }
41
42private:
43 Scheduler* systems_;
44 std::vector<std::filesystem::path> asset_folders_;
45};
46
48inline constexpr std::string_view plugin_start = "aegis2d_plugin_start";
49
77class AEGIS2D_ECS_EXPORT Plugins {
78public:
79 Plugins() = default;
80 // Libraries cannot be copied; spelled out so that an exported class does not try to.
81 Plugins(const Plugins&) = delete;
82 Plugins& operator=(const Plugins&) = delete;
83 Plugins(Plugins&&) noexcept = default;
84 Plugins& operator=(Plugins&&) noexcept = default;
85 ~Plugins() = default;
86
96 std::string load(const std::filesystem::path& path, PluginContext& context);
97
105 std::size_t load_folder(const std::filesystem::path& folder, PluginContext& context);
106
109 [[nodiscard]] std::size_t size() const noexcept { return plugins_.size(); }
110
111private:
112 std::vector<core::EngineLibrary> plugins_;
113};
114
115} // namespace aegis2d::ecs
What a plugin can add to the game, given to its start function.
Definition plugins.hpp:20
void add_asset_folder(std::filesystem::path folder)
Adds a folder of assets the plugin brings, which the game loads like its own.
Definition plugins.hpp:32
const std::vector< std::filesystem::path > & asset_folders() const noexcept
Folders of assets the plugins brought, in the order they were added.
Definition plugins.hpp:38
Scheduler & systems() const noexcept
The game's systems: the plugin adds its own, e.g. systems().add("drift", ...).
Definition plugins.hpp:28
PluginContext(Scheduler &systems) noexcept
A context adding to the game's systems.
Definition plugins.hpp:24
The plugins a game loaded, kept loaded as long as it lives.
Definition plugins.hpp:77
Plugins & operator=(const Plugins &)=delete
Plugins(Plugins &&) noexcept=default
Plugins(const Plugins &)=delete
Ordered list of named systems, all updated once per tick.
Definition system.hpp:100
Entity-Component-System used by client and server.
Definition animation.hpp:13
constexpr std::string_view plugin_start
Name of the C function a plugin exports, called once when it is loaded.
Definition plugins.hpp:48
Definition endpoint.hpp:85
Shared libraries loaded at run time, and the C entry point that tells an Aegis2D library and its vers...
Systems and the scheduler that updates them in order, once per tick.