├── .github
└── workflows
│ └── doxygen-gh-pages.yml
├── .gitignore
├── .vscode
└── settings.json
├── CMakeLists.txt
├── Doxyfile
├── LICENSE.md
├── README.md
└── include
└── silvergun
├── _debug
├── exceptions.hpp
└── logger.hpp
├── _globals
├── _defines.hpp
├── commands.hpp
├── engine_time.hpp
├── handlers.hpp
├── message.hpp
├── scene.hpp
└── slv_asset.hpp
├── cmp
├── _components.hpp
├── ai.hpp
├── background.hpp
├── bounding_box.hpp
├── component.hpp
├── dispatcher.hpp
├── gfx.hpp
├── hitbox.hpp
├── location.hpp
├── motion.hpp
├── overlay.hpp
└── sprite.hpp
├── config.hpp
├── display.hpp
├── engine.hpp
├── input.hpp
├── mgr
├── _managers.hpp
├── assets.hpp
├── audio.hpp
├── manager.hpp
├── messages.hpp
├── renderer.hpp
├── spawner.hpp
├── systems.hpp
├── variables.hpp
└── world.hpp
├── silvergun.hpp
└── sys
├── _systems.hpp
├── animate.hpp
├── collision.hpp
├── logic.hpp
├── movement.hpp
└── system.hpp
/.github/workflows/doxygen-gh-pages.yml:
--------------------------------------------------------------------------------
1 | # https://github.com/marketplace/actions/doxygen-github-pages-deploy-action
2 | name: Doxygen GitHub Pages Deploy Action
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 |
9 | jobs:
10 | deploy:
11 | runs-on: ubuntu-latest
12 | permissions:
13 | contents: write
14 | steps:
15 | - uses: DenverCoder1/doxygen-github-pages-action@v2.0.0
16 | with:
17 | github_token: ${{ secrets.GITHUB_TOKEN }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | docs
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "files.exclude": {
3 | "**/.git": true,
4 | "**/build": true,
5 | "**/docs": true
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Silvergun CMake
2 | # See LICENSE.md for copyright information.
3 |
4 | cmake_minimum_required(VERSION 3.11)
5 | project(silvergun VERSION 0.8.0 DESCRIPTION "Silvergun Game Engine")
6 | enable_language(CXX)
7 |
8 | set(CMAKE_BUILD_TYPE Release)
9 | include(GNUInstallDirs)
10 |
11 | install(DIRECTORY include/
12 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
13 | FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
14 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2019-present Matthew Evans
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Silvergun Game Engine
2 |
3 | __Silvergun__ is a lightweight cross-platform 2D game engine written in C++17 using an [ECS](https://en.wikipedia.org/wiki/Entity_component_system) design.
4 |
5 | ### Requirements
6 | - __Build tools__:
7 | - A working C++ build environment with [CMake](https://cmake.org)
8 | - __Libraries__:
9 | - [Allegro Game Library](https://liballeg.org)
10 |
11 | -----
12 |
13 | ### Documentation
14 |
15 | See the API documentation at . Documentation can be built locally using [Doxygen](https://doxygen.nl/index.html).
16 |
17 | -----
18 |
19 | ### Tools
20 |
21 | - [slv-mkscript](https://github.com/AtomicSponge/slv-mkscript) - Generate game scripts. Requires [NodeJS](https://nodejs.org/)
22 |
23 | -----
24 |
25 | ### Demo Game
26 |
27 | For a live demo and simple example of the the API usage, see the following:
28 |
29 | - [Playable Demo](https://atomicsponge.github.io/slv-demo-01/)
30 |
31 | - [Source Code](https://github.com/AtomicSponge/slv-demo-01)
32 |
--------------------------------------------------------------------------------
/include/silvergun/_debug/exceptions.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * silvergun
3 | * --------
4 | * By Matthew Evans
5 | * See LICENSE.md for copyright information.
6 | */
7 |
8 | #if !defined(SLV_EXCEPTION_HPP)
9 | #define SLV_EXCEPTION_HPP
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | #include "silvergun/_debug/logger.hpp"
16 | #include "silvergun/_globals/_defines.hpp"
17 | #include "silvergun/_globals/engine_time.hpp"
18 |
19 | namespace slv {
20 |
21 | /*
22 | * Creates an info object that can be passed to the engine exceptions.
23 | */
24 | class exception_item final {
25 | friend class engine_error;
26 | friend class engine_exception;
27 |
28 | private:
29 | const char* description; // Exception description.
30 | const char* location; // Exception location.
31 | const unsigned int code; // Code of error
32 | const int64_t time; // Time of exception.
33 |
34 | exception_item() = delete; // Delete default constructor.
35 | ~exception_item() = default; // Default destructor.
36 | // Create a new exception item.
37 | exception_item(const std::string& d, const std::string& l, const unsigned int& c) :
38 | description(d.c_str()), location(l.c_str()), code(c), time(engine_time::check()) {};
39 | };
40 |
41 | /*!
42 | * \class engine_error
43 | * \brief Throws an engine runtime error.
44 | *
45 | * Exceptions thrown this way will terminate the engine.
46 | */
47 | class engine_error final : public std::exception {
48 | private:
49 | const exception_item item; // Store the exception item.
50 |
51 | public:
52 | /*!
53 | * \brief Create a new runtime error object. Sets the location to Engine and code to 1.
54 | * \param d An exception description.
55 | */
56 | engine_error(const std::string& d) : item(exception_item(d, "Engine", 1)) {};
57 |
58 | engine_error() = delete; // Delete default constructor.
59 | virtual ~engine_error() = default; // Default destructor.
60 |
61 | /*!
62 | * \brief Returns the description of the thrown exception.
63 | * \return Description of thrown exception.
64 | */
65 | const char* what() const noexcept override {
66 | return item.description;
67 | };
68 |
69 | /*!
70 | * \brief Return the location the exception occured.
71 | * \return Location of thrown exception.
72 | */
73 | const char* where() const noexcept {
74 | return item.location;
75 | };
76 |
77 | /*!
78 | * \brief Return the time the exception occured.
79 | * \return Time of thrown exception.
80 | */
81 | int64_t when() const noexcept {
82 | return item.time;
83 | };
84 | };
85 |
86 | /*!
87 | * \class engine_exception
88 | * \brief Throws an internal engine exception.
89 | *
90 | * Exceptions thrown this way will not terminate the engine. \n
91 | * If debugging is enabled, they will also be logged to file.
92 | */
93 | class engine_exception final : public std::exception {
94 | private:
95 | const exception_item item; // Store the exception item.
96 |
97 | public:
98 | /*!
99 | * \brief Create an engine exception.
100 | * \param d Description of exception.
101 | * \param l Location in engine of exception.
102 | * \param c Code of exception.
103 | */
104 | engine_exception(const std::string& d, const std::string& l, const unsigned int& c) :
105 | item(exception_item(d, l, c)) {
106 | if constexpr (build_options.debug_mode) {
107 | logger::log(item.description, item.location, item.code, item.time);
108 | }
109 | };
110 |
111 | engine_exception() = delete; // Delete default constructor.
112 | virtual ~engine_exception() = default; // Default destructor.
113 |
114 | /*!
115 | * \brief Returns the description of the thrown exception.
116 | * \return Description of thrown exception.
117 | */
118 | const char* what() const noexcept override {
119 | return item.description;
120 | };
121 |
122 | /*!
123 | * \brief Return the location the exception occured.
124 | * \return Location of thrown exception.
125 | */
126 | const char* where() const noexcept {
127 | return item.location;
128 | };
129 |
130 | /*!
131 | * \brief Return the time the exception occured.
132 | * \return Time of thrown exception.
133 | */
134 | int64_t when() const noexcept {
135 | return item.time;
136 | };
137 | };
138 |
139 | }
140 |
141 | #endif
142 |
--------------------------------------------------------------------------------
/include/silvergun/_debug/logger.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * silvergun
3 | * --------
4 | * By Matthew Evans
5 | * See LICENSE.md for copyright information.
6 | */
7 |
8 | #if !defined(SLV_LOGGER_HPP)
9 | #define SLV_LOGGER_HPP
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | namespace slv {
20 |
21 | class engine;
22 |
23 | /*!
24 | * \class logger
25 | * \brief Logs exceptions to file. This option is built when the engine is in debug mode.
26 | */
27 | class logger final {
28 | friend class engine;
29 |
30 | private:
31 | logger() = default;
32 | ~logger() = default;
33 |
34 | static void start(void) {
35 | std::time_t t = std::time(nullptr);
36 | std::ostringstream date_stream;
37 | date_stream << std::put_time(std::localtime(&t), "%d-%m-%Y_%H-%M-%S");
38 | std::string date = date_stream.str();
39 | std::cout << "Logging exceptions to: exceptions_" + date + ".log.csv\n";
40 | log_file.open("exceptions_" + date + ".log.csv", std::ios::out | std::ios::trunc);
41 | log_file << "Description, Location, Time, Code" << std::endl;
42 | };
43 |
44 | static void stop(void) {
45 | log_file.close();
46 | };
47 |
48 | inline static std::ofstream log_file;
49 |
50 | public:
51 | logger(const logger&) = delete; // Delete copy constructor.
52 | void operator=(logger const&) = delete; // Delete assignment operator.
53 |
54 | /*!
55 | * \brief Add exception information to the logger.
56 | * \param d Description of item.
57 | * \param l Location of item.
58 | * \param c Error code of item.
59 | * \param t Engine time of item.
60 | */
61 | static const void log(
62 | const std::string& d, const std::string& l,
63 | const unsigned int& c, const int64_t& t) {
64 | log_file << d + ", " + l + ", " + std::to_string(c) + ", " + std::to_string(t) + "\n";
65 | };
66 | };
67 |
68 | }
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/include/silvergun/_globals/_defines.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * silvergun
3 | * --------
4 | * By Matthew Evans
5 | * See LICENSE.md for copyright information.
6 | */
7 |
8 | #if !defined(SLV_GLOBAL_DEFINES_HPP)
9 | #define SLV_GLOBAL_DEFINES_HPP
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | #include
16 |
17 | // Enable math defines for entire engine.
18 | #if !defined(_USE_MATH_DEFINES)
19 | #define _USE_MATH_DEFINES
20 | #endif
21 |
22 | // Define true & false for macro use.
23 | #if !defined(TRUE)
24 | #define TRUE (1)
25 | #endif
26 | #if !defined(FALSE)
27 | #define FALSE (0)
28 | #endif
29 |
30 | // Enable debug mode
31 | #if defined(SLV_BUILD_DEBUG)
32 | #define SLV_DEBUG_MODE TRUE
33 | #else
34 | #define SLV_DEBUG_MODE FALSE
35 | #endif
36 |
37 | // Require OpenGL 3.0
38 | #if !defined(SLV_REQUIRE_OPENGL_LATEST)
39 | #define SLV_OPENGL_LATEST TRUE
40 | #else
41 | #define SLV_OPENGL_LATEST FALSE
42 | #endif
43 |
44 | // Set the timer rate.
45 | // Number of ticks per second as a float.
46 | #if !defined(SLV_TICKS_PER_SECOND)
47 | #define SLV_TICKS_PER_SECOND (60.0f)
48 | #endif
49 |
50 | // Set max number of playing samples.
51 | #if !defined(SLV_MAX_PLAYING_SAMPLES)
52 | #define SLV_MAX_PLAYING_SAMPLES (12)
53 | #endif
54 |
55 | // Toggle keyboard building
56 | #if !defined(SLV_DISABLE_KEYBOARD)
57 | #define SLV_USE_KEYBOARD TRUE
58 | #else
59 | #define SLV_USE_KEYBOARD FALSE
60 | #endif
61 |
62 | // Toggle mouse building
63 | #if !defined(SLV_DISABLE_MOUSE)
64 | #define SLV_USE_MOUSE TRUE
65 | #else
66 | #define SLV_USE_MOUSE FALSE
67 | #endif
68 |
69 | // Toggle joystick building
70 | #if !defined(SLV_DISABLE_JOYSTICK)
71 | #define SLV_USE_JOYSTICK TRUE
72 | #else
73 | #define SLV_USE_JOYSTICK FALSE
74 | #endif
75 |
76 | // Toggle touch building
77 | #if !defined(SLV_DISABLE_TOUCH)
78 | #define SLV_USE_TOUCH TRUE
79 | #else
80 | #define SLV_USE_TOUCH FALSE
81 | #endif
82 |
83 | #if !SLV_USE_KEYBOARD && !SLV_USE_MOUSE && !SLV_USE_JOYSTICK && !SLV_USE_TOUCH
84 | #error Must define at least one input device to be used
85 | #endif
86 |
87 | namespace slv {
88 |
89 | /*
90 | * Build flags for configuring the engine.
91 | */
92 | struct slv_build_options {
93 | inline constexpr static bool debug_mode = static_cast(SLV_DEBUG_MODE);
94 | inline constexpr static bool opengl_latest = static_cast(SLV_OPENGL_LATEST);
95 | inline constexpr static float ticks_per_sec = static_cast(SLV_TICKS_PER_SECOND);
96 | inline constexpr static int max_playing_samples = static_cast(SLV_MAX_PLAYING_SAMPLES);
97 |
98 | // Input options
99 | inline constexpr static bool keyboard_enabled = static_cast(SLV_USE_KEYBOARD);
100 | inline constexpr static bool mouse_enabled = static_cast(SLV_USE_MOUSE);
101 | inline constexpr static bool joystick_enabled = static_cast(SLV_USE_JOYSTICK);
102 | inline constexpr static bool touch_enabled = static_cast(SLV_USE_TOUCH);
103 | };
104 | inline constexpr slv_build_options build_options;
105 |
106 | }
107 |
108 | #endif
109 |
--------------------------------------------------------------------------------
/include/silvergun/_globals/commands.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * silvergun
3 | * --------
4 | * By Matthew Evans
5 | * See LICENSE.md for copyright information.
6 | */
7 |
8 | #if !defined(SLV_COMMANDS_HPP)
9 | #define SLV_COMMANDS_HPP
10 |
11 | #include
12 | #include