|
Aegis2D
Modular C++26 2D game engine for networked games
|
Logging, time, main loop, events and configuration shared by client and server. More...
Classes | |
| struct | CommandArg |
An argument a command takes: {.name = "count", .type = ArgType::Integer}. More... | |
| class | CommandCall |
| The arguments of a command being run, read in their types. More... | |
| struct | CommandResult |
| What running a line gave. More... | |
| class | Commands |
| The commands a console runs: each has a name, its arguments and a help. More... | |
| class | Config |
| JSON configuration file (server port, window size...) read through typed getters. More... | |
| class | ConfigError |
| Thrown when a configuration cannot be read or parsed. More... | |
| struct | ConfigMember |
| One member of a JSON object. More... | |
| struct | ConfigValue |
| One value of a configuration document, independent of the JSON library. More... | |
| class | ConsoleVariables |
| The settings a console reads and changes by name while the game runs. More... | |
| struct | EngineLibrary |
| An Aegis2D library, opened and checked by load_library(). More... | |
| class | EventBus |
| Lets systems react to events without knowing who sends them. More... | |
| class | EventQueue |
| Deferred event queue dispatched by priority at a chosen point in the tick. More... | |
| class | FixedTimestep |
| Turns variable frame times into a whole number of fixed simulation steps. More... | |
| class | HotReload |
| Watches files and reloads each one with its own function when it changes. More... | |
| class | LibraryError |
| A shared library could not be opened or is not one the engine can load. More... | |
| struct | LibraryInfo |
| What an Aegis2D library tells about itself, from its C entry point. More... | |
| class | Logger |
Writes timestamped messages to the console (std::clog) and to an optional file. More... | |
| class | MainLoop |
| Drives a game: fixed-rate updates, then one render per frame. More... | |
| class | Preloader |
| Loads a list of resources in the background, telling how far it is. More... | |
| struct | PreloadFailure |
| A resource a Preloader could not load, and why. More... | |
| struct | ProfileEntry |
| Time a named part of a frame took, as Profiler::last_frame() gives it. More... | |
| class | Profiler |
| Timers around the parts of a frame (its phases, each system of a ecs::Scheduler...), and the breakdown of the last frame for the metrics overlay. More... | |
| class | ProfileScope |
| Times a scope while it lives: from Profiler::scope() to its destruction. More... | |
| class | Random |
| Seeded pseudo-random generator (PCG32), for gameplay the server must replay. More... | |
| class | ResourceCache |
| Shares resources by name: each is loaded once, counted, and freed when unused. More... | |
| class | SharedLibrary |
A shared library opened at run time (.so, .dylib or .dll), closed when destroyed. More... | |
| class | SpscQueue |
| Fixed-capacity FIFO queue passing values from one thread to another without locks. More... | |
| class | Stopwatch |
Measures elapsed time with the monotonic std::chrono::steady_clock. More... | |
| struct | TraceEvent |
| A scope timed while tracing (Profiler::start_trace()), for write_chrome_trace(). More... | |
| struct | TraceThread |
| The trace of one thread, as write_chrome_trace() writes it. More... | |
| struct | VarFlags |
What a console variable allows: {.saved = true, .cheat = true}. More... | |
| struct | VarInfo |
| A console variable as declared, with its value now. More... | |
| struct | VarSetting |
| A variable to set, as a command line or a settings file gives it. More... | |
| struct | VarSettings |
| Settings read from a command line or a file, and what could not be read. More... | |
Typedefs | |
| using | Duration = std::chrono::nanoseconds |
| Duration type used for simulation time (nanoseconds). | |
| using | CommandHandler = std::function< std::string(const CommandCall &call)> |
| What a command does with its arguments. | |
| using | VarValue = std::variant< bool, std::int64_t, double, std::string > |
| Value of a console variable: a boolean, an integer, a number or a text. | |
| using | SubscriptionId = std::uint64_t |
| Handle returned by EventBus::subscribe(), used to unsubscribe. Never 0. | |
Enumerations | |
| enum class | ArgType : std::uint8_t { Text , Integer , Number , Boolean } |
| Type of an argument of a command, read from its text as a console variable's. More... | |
| enum class | CommandStatus : std::uint8_t { Done , Empty , Unknown , WrongArguments , Failed } |
| How running a line went. More... | |
| enum class | VarResult : std::uint8_t { Changed , Unknown , ReadOnly , Cheat , WrongType , BadText } |
| What became of a change of a console variable. More... | |
| enum class | LogLevel : std::uint8_t { Debug , Info , Warn , Error , Off } |
| Severity of a log message, from the most verbose to the most severe. More... | |
Functions | |
| constexpr Duration | step_from_rate (std::uint32_t ticks_per_second) noexcept |
| Length of one step for a given update rate. | |
| std::string_view | to_string (VarResult result) noexcept |
| Sentence for a VarResult, as a console shows it. | |
| std::string | to_text (const VarValue &value) |
| A value as text, as ConsoleVariables::set_text() reads it. | |
| std::optional< VarValue > | read_value (std::string_view text, const VarValue &like) |
| Reads a value from text, in the type of another one, as ConsoleVariables::set_text() does. | |
| bool | is_console_name (std::string_view name) noexcept |
| Tells whether a name is valid for a console variable or a command. | |
| std::string_view | to_string (LogLevel level) noexcept |
| Short upper-case name of a level. | |
| template<typename... Args> | |
| void | log_debug (std::format_string< Args... > format, Args &&... args) |
Logs a Debug message with the global logger. | |
| template<typename... Args> | |
| void | log_info (std::format_string< Args... > format, Args &&... args) |
Logs an Info message with the global logger. | |
| template<typename... Args> | |
| void | log_warn (std::format_string< Args... > format, Args &&... args) |
Logs a Warn message with the global logger. | |
| template<typename... Args> | |
| void | log_error (std::format_string< Args... > format, Args &&... args) |
Logs an Error message with the global logger. | |
| std::optional< std::size_t > | memory_use () noexcept |
| Memory of the process in RAM now: its resident set (Linux, macOS) or working set (Windows), in bytes. | |
| std::string_view | name () noexcept |
| Name of the module, used to check that it is linked. | |
| std::filesystem::path | executable_dir () |
| Folder containing the running executable. | |
| std::filesystem::path | asset_dir () |
Folder of the assets copied next to the executable by aegis2d_copy_assets(). | |
| std::filesystem::path | asset_path (const std::filesystem::path &relative) |
| Path of one asset. | |
| void | write_chrome_trace (std::ostream &out, std::span< const TraceThread > threads, std::string_view process="aegis2d") |
Writes traces in the Chrome trace format, which Perfetto (ui.perfetto.dev) and chrome://tracing open. | |
| void | save_chrome_trace (const std::filesystem::path &file, std::span< const TraceThread > threads, std::string_view process="aegis2d") |
| Writes traces to a file in the Chrome trace format (write_chrome_trace()). | |
| std::vector< std::string > | profile_lines (const Profiler &profiler, std::size_t most=12) |
| The breakdown of the last frame as lines of the metrics overlay. | |
| EngineLibrary | load_library (const std::filesystem::path &path, std::uint32_t api_version=library_api_version) |
| Opens an Aegis2D library and checks that the engine can use it. | |
| VarSettings | settings_from_arguments (std::span< const std::string_view > arguments) |
Reads the +set name value of a command line. | |
| VarSettings | settings_from_arguments (int argc, char **argv) |
Reads the +set name value of main()'s arguments. | |
| VarSettings | settings_from_text (std::string_view text, std::string_view origin) |
| Reads settings from text, one per line. | |
| VarSettings | settings_from_file (const std::filesystem::path &file) |
| Reads settings from a file, as settings_from_text() reads text. | |
| std::vector< std::string > | apply_settings (ConsoleVariables &variables, std::span< const VarSetting > settings) |
| Sets variables, in order: a later setting wins over an earlier one. | |
Variables | |
| constexpr bool | hot_reload_by_default = true |
Whether to turn hot reload on: in debug builds (NDEBUG not defined). | |
| constexpr std::uint32_t | library_api_version = 1 |
| Version of the interface between the engine and the libraries it loads. | |
| constexpr std::string_view | library_entry = "aegis2d_library_entry" |
| Name of the C function every Aegis2D library exports (see LibraryInfo). | |
Logging, time, main loop, events and configuration shared by client and server.
| using aegis2d::core::CommandHandler = typedef std::function<std::string(const CommandCall& call)> |
What a command does with its arguments.
It returns what the console shows, or nothing. It throws an exception derived from std::exception to fail: the line fails with its message.
| using aegis2d::core::Duration = typedef std::chrono::nanoseconds |
Duration type used for simulation time (nanoseconds).
| using aegis2d::core::SubscriptionId = typedef std::uint64_t |
Handle returned by EventBus::subscribe(), used to unsubscribe. Never 0.
| using aegis2d::core::VarValue = typedef std::variant<bool, std::int64_t, double, std::string> |
Value of a console variable: a boolean, an integer, a number or a text.
|
strong |
|
strong |
How running a line went.
|
strong |
Severity of a log message, from the most verbose to the most severe.
Off is only meant for Logger::set_level(): it disables every message.
| Enumerator | |
|---|---|
| Debug | |
| Info | |
| Warn | |
| Error | |
| Off | |
|
strong |
What became of a change of a console variable.
| std::vector< std::string > aegis2d::core::apply_settings | ( | ConsoleVariables & | variables, |
| std::span< const VarSetting > | settings | ||
| ) |
Sets variables, in order: a later setting wins over an earlier one.
Each value is read by ConsoleVariables::set_text(), so it follows the variable's type and flags: an unknown, read-only or cheat variable (while cheats are off) is not changed. Apply a settings file first, then the command line, so the command line wins.
| variables | Variables to set. |
| settings | Settings to apply. |
"game.cfg:3: player_speed:
not a value of the variable's type"; empty when all were applied. | std::filesystem::path aegis2d::core::asset_dir | ( | ) |
Folder of the assets copied next to the executable by aegis2d_copy_assets().
executable_dir() / "assets". | std::runtime_error | if executable_dir() fails. |
| std::filesystem::path aegis2d::core::asset_path | ( | const std::filesystem::path & | relative | ) |
Path of one asset.
| relative | Path inside the assets folder, e.g. "sprites/player.png". |
asset_dir() / relative; the file is not required to exist. | std::runtime_error | if executable_dir() fails. |
| std::filesystem::path aegis2d::core::executable_dir | ( | ) |
Folder containing the running executable.
Independent of the working directory: a game started from a shortcut, an IDE or another folder still finds its files. Read once from the operating system (/proc/self/exe, _NSGetExecutablePath or GetModuleFileNameW), then cached.
| std::runtime_error | if the operating system does not tell. |
|
noexcept |
Tells whether a name is valid for a console variable or a command.
| name | Name to check. |
true for lower case letters, digits, _ and ., starting with a letter, at most 64 characters. | EngineLibrary aegis2d::core::load_library | ( | const std::filesystem::path & | path, |
| std::uint32_t | api_version = library_api_version |
||
| ) |
Opens an Aegis2D library and checks that the engine can use it.
Calls its entry point (library_entry) and compares the version it was built with to api_version: a library built for another version of the engine is refused before any of its code runs, other than the entry point.
| path | Path of the library file. |
| api_version | Version the library must have, library_api_version by default. |
| LibraryError | if it cannot be opened, has no entry point, gives no information or was built for another version; the message gives both versions. |
| void aegis2d::core::log_debug | ( | std::format_string< Args... > | format, |
| Args &&... | args | ||
| ) |
Logs a Debug message with the global logger.
| format | std::format format string. |
| args | Values to format. |
| void aegis2d::core::log_error | ( | std::format_string< Args... > | format, |
| Args &&... | args | ||
| ) |
Logs an Error message with the global logger.
| format | std::format format string. |
| args | Values to format. |
| void aegis2d::core::log_info | ( | std::format_string< Args... > | format, |
| Args &&... | args | ||
| ) |
Logs an Info message with the global logger.
| format | std::format format string. |
| args | Values to format. |
| void aegis2d::core::log_warn | ( | std::format_string< Args... > | format, |
| Args &&... | args | ||
| ) |
Logs a Warn message with the global logger.
| format | std::format format string. |
| args | Values to format. |
|
noexcept |
Memory of the process in RAM now: its resident set (Linux, macOS) or working set (Windows), in bytes.
Asks the system each time (a file read on Linux, a system call elsewhere): call it a few times a second at most, as the metrics overlay does.
|
noexcept |
Name of the module, used to check that it is linked.
"core", a view of a static string. | std::vector< std::string > aegis2d::core::profile_lines | ( | const Profiler & | profiler, |
| std::size_t | most = 12 |
||
| ) |
The breakdown of the last frame as lines of the metrics overlay.
| profiler | Profiler whose last_frame() to show. |
| most | Most scopes shown; the slowest are kept, in their order. |
"FRAME 16.4 MS", then a line per scope indented by its depth, such as " MOVEMENT 0.31 MS X2" (the calls when more than one), in capitals for the pixel font. | std::optional< VarValue > aegis2d::core::read_value | ( | std::string_view | text, |
| const VarValue & | like | ||
| ) |
Reads a value from text, in the type of another one, as ConsoleVariables::set_text() does.
| text | Such as "on", "42" or "0.5"; blanks around it are ignored, but for a text. |
| like | Value of the type to read. |
text does not read in that type. | void aegis2d::core::save_chrome_trace | ( | const std::filesystem::path & | file, |
| std::span< const TraceThread > | threads, | ||
| std::string_view | process = "aegis2d" |
||
| ) |
Writes traces to a file in the Chrome trace format (write_chrome_trace()).
| file | File to write, created or replaced; a .json file opens in Perfetto. |
| threads | The trace of each thread. |
| process | Name of the process in the viewer. |
| std::runtime_error | if the file cannot be written; the message names it. |
| VarSettings aegis2d::core::settings_from_arguments | ( | int | argc, |
| char ** | argv | ||
| ) |
Reads the +set name value of main()'s arguments.
| argc | Number of arguments, the program's name included. |
| argv | Arguments; the first, the program's name, is skipped. |
| VarSettings aegis2d::core::settings_from_arguments | ( | std::span< const std::string_view > | arguments | ) |
Reads the +set name value of a command line.
Every other argument is left to the game, so the engine's settings mix with its own options: my_game --port 4242 +set player_speed 450 +set r_vsync off. The shell keeps a value with spaces in one argument when it is quoted.
| arguments | Arguments, without the program's name. |
+set without a name and a value as an error. | VarSettings aegis2d::core::settings_from_file | ( | const std::filesystem::path & | file | ) |
Reads settings from a file, as settings_from_text() reads text.
| file | Path of the file. |
| VarSettings aegis2d::core::settings_from_text | ( | std::string_view | text, |
| std::string_view | origin | ||
| ) |
Reads settings from text, one per line.
A line is name value or set name value, the value being the rest of the line, or the text between double quotes when it is quoted. Blank lines, and lines starting with # or //, are skipped.
| text | Text of the settings. |
| origin | Name of the text in the errors, such as a file name. |
|
constexprnoexcept |
Length of one step for a given update rate.
| ticks_per_second | Update rate in hertz, e.g. 60; must not be 0. |
1s / ticks_per_second, rounded down to the nanosecond.
|
noexcept |
Short upper-case name of a level.
| level | Level to name. |
"DEBUG", "INFO", "WARN", "ERROR" or "OFF".
|
noexcept |
Sentence for a VarResult, as a console shows it.
| result | Result of a change. |
"unknown variable", a view of a static string. | std::string aegis2d::core::to_text | ( | const VarValue & | value | ) |
A value as text, as ConsoleVariables::set_text() reads it.
| value | Value. |
"true" or "false", the integer, the shortest text of the number that reads back the same, or the text. | void aegis2d::core::write_chrome_trace | ( | std::ostream & | out, |
| std::span< const TraceThread > | threads, | ||
| std::string_view | process = "aegis2d" |
||
| ) |
Writes traces in the Chrome trace format, which Perfetto (ui.perfetto.dev) and chrome://tracing open.
A JSON object whose traceEvents are the names of the process and of each thread, then a complete event ("ph": "X") per scope and frame, in microseconds.
| out | Stream to write to. |
| threads | The trace of each thread, numbered from 1 in this order. |
| process | Name of the process in the viewer. |
|
constexpr |
Whether to turn hot reload on: in debug builds (NDEBUG not defined).
Not inline, so each file that includes this header gets the value of its own build type: the game's, whatever the engine was built with. Pass it to HotReload.
|
inlineconstexpr |
Version of the interface between the engine and the libraries it loads.
Raised whenever what an engine library exchanges with the engine changes, so a library built for another engine is refused by load_library() instead of crashing.
|
inlineconstexpr |
Name of the C function every Aegis2D library exports (see LibraryInfo).