diff options
67 files changed, 260 insertions, 240 deletions
| diff --git a/contributing.md b/contributing.md index 38a83fd..2fe46f7 100644 --- a/contributing.md +++ b/contributing.md @@ -1,11 +1,15 @@ -# Contributing new code +This document contains +<details><summary> +examples +</summary> +that you can click on to open them. +</details> + +# Git  - Please do the following *before* sending a pull request:    - Merge upstream code (if any) back into your own branch    - Run formatters/linters - -# Git -  - Push as often as possible  - Development is done on separate branches, these follow a pattern of    `name/feature` (i.e. `loek/dll-so-poc` or `jaro/class2`) @@ -17,8 +21,9 @@  - Formatting nitty-gritty is handled by clang-format/clang-tidy (run `make    format` in the root folder of this repository to format all sources files) -- ASCII only -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +- <details><summary> +  ASCII only +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    // crepe startup message @@ -30,9 +35,10 @@    // crêpe startup message    std::string message = "こんにちは世界";    ``` -  </td></tr></table> -- Class names are always singular -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </td></tr></table></details> +- <details><summary> +  Class names are always singular +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    class Foo {}; @@ -42,7 +48,7 @@    ```cpp    class Cars {};    ``` -  </td></tr></table> +  </td></tr></table></details>  - Source files contain the following types of comments:    - What is the code supposed to do (optional)    - Implementation details (if applicable) @@ -50,8 +56,9 @@    - Usage documentation (required)    - Implementation details (if they affect the header)    - Design/data structure decisions (if applicable) -- Comments are placed *above* the line(s) they are explaining -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +- <details><summary> +  Comments are placed *above* the line(s) they are explaining +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    int add(int a, int b) { @@ -68,7 +75,7 @@      return out;    }    ``` -  </td></tr></table> +  </td></tr></table></details>  - Header includes are split into paragraphs separated by a blank line. The    order is:    1. system headers (using `<`brackets`>`) @@ -80,6 +87,7 @@    > sure to separate the include statements using a blank line (clang-format    > may sort include statements, but does not sort across empty lines). +  <details><summary>Example</summary>    <table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp @@ -100,9 +108,10 @@    #include <iostream>    #include "api/Sprite.h"    ``` -  </td></tr></table> -- `using namespace` may not be used in header files, only in source files. -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </td></tr></table></details> +- <details><summary> +  <code>using namespace</code> may not be used in header files, only in source files. +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    example.h:    ```cpp @@ -134,10 +143,12 @@    template <typename T>    T foo();    ``` -  </td></tr></table> +  </td></tr></table></details> -- Getter and setter functions are appropriately prefixed with `get_` and `set_`. -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +- <details><summary> +  Getter and setter functions are appropriately prefixed with <code>get_</code> +  and <code>set_</code>. +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    class Foo { @@ -160,12 +171,12 @@      int speed;    };    ``` -  </td></tr></table> - -- A singleton's instance is always accessed using a getter function that +  </td></tr></table></details> +- <details><summary> +  A singleton's instance is always accessed using a getter function that    instantiates its own class as a static variable within the getter function -  scope, instead of storing the instance as a member variable directly: -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  scope, instead of storing the instance as a member variable directly. +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    class Foo { @@ -186,11 +197,11 @@    };    ``` -  </td></tr></table> - -- Member variable default values should be directly defined in the class/struct +  </td></tr></table></details> +- <details><summary> +  Member variable default values should be directly defined in the class/struct    declaration instead of using the constructor. -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    class Foo { @@ -206,28 +217,39 @@      int speed;    };    ``` -  </td></tr></table> - +  </td></tr></table></details>  - Use of the `auto` type is *not* allowed, with the following exceptions: -  - When naming the item type in a range-based for loop: -     +  - <details><summary> +    When naming the item type in a range-based for loop +    </summary> +      ```cpp      for (auto & item : foo()) {        // ...      }      ``` -  - When calling template factory methods that explicitly name the return type +    </details> +  - <details><summary> +    When calling template factory methods that explicitly name the return type      in the function call signature +    </summary> +      ```cpp      auto ptr = make_unique<Foo>();      ``` -  - When fetching a singleton instance +    </details> +  - <details><summary> +    When fetching a singleton instance +    </summary> +      ```cpp      auto & mgr = crepe::api::Config::get_instance();      ``` +    </details> -- Only use member initializer lists for non-trivial types. -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +- <details><summary> +  Only use member initializer lists for non-trivial types. +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    class Foo { @@ -248,10 +270,10 @@      int bar;    };    ``` -  </td></tr></table> - -- C++-style structs should define default values for all non-trivial fields. -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </td></tr></table></details> +- <details><summary> +  C++-style structs should define default values for all non-trivial fields. +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    struct Foo { @@ -267,11 +289,11 @@      std::string baz;    };    ``` -  </td></tr></table> - -- Declare incomplete classes instead of including the relevant header where +  </td></tr></table></details> +- <details><summary> +  Declare incomplete classes instead of including the relevant header where    possible (i.e. if you only need a reference or raw pointer). -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    class Bar; @@ -288,11 +310,11 @@      Bar & bar;    };    ``` -  </td></tr></table> - -- Template functions are only *declared* in a `.h` header, and *defined* in a -  matching `.hpp` header. -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </td></tr></table></details> +- <details><summary> +  Template functions are only <i>declared</i> in a <code>.h</code> header, and +  <i>defined</i> in a matching <code>.hpp</code> header. +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    add.h:    ```cpp @@ -320,11 +342,11 @@      return a + b;    }    ``` -  </td></tr></table> - -- Where possible, end (initializer) lists with a trailing comma (e.g. with +  </td></tr></table></details> +- <details><summary> +  Where possible, end (initializer) lists with a trailing comma (e.g. with    structs, enums) -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    enum Color { @@ -343,9 +365,10 @@      Blue    };    ``` -  </td></tr></table> -- `#pragma` should be used instead of include guards -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +  </td></tr></table></details> +- <details><summary> +  <code>#pragma</code> should be used instead of include guards +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    #pragma once @@ -362,7 +385,7 @@    #endif    ``` -  </td></tr></table> +  </td></tr></table></details>  ## CMakeLists-specific @@ -373,20 +396,26 @@  # Structure -- All engine-related code is implemented under the `crepe` namespace, -  user-facing APIs under `crepe::api` (the folder structure should also reflect -  this). +- Files are placed in the appropriate directory: +  |Path|Purpose| +  |-|-| +  |`crepe/`|Auxiliary, managers| +  |`crepe/api/`|User-facing APIs| +  |`crepe/util/`|Standalone utilities and helper functions| +  |`crepe/system/`|(ECS) system classes| +  |`crepe/facade/`|Library façades|  - Do not (indirectly) include private *dependency* headers in API header files,    as these are no longer accessible when the engine is installed +- All code is implemented under the `crepe` namespace.  - Header files declare either a single class or symbols within a single    namespace. -- TODO: folder structure  # Documentation  - All documentation is written in U.S. English -- Doxygen commands are used with a backslash instead of an at-sign. -  <table><tr><th>Good</th><th>Bad</th></tr><tr><td> +- <details><summary> +  Doxygen commands are used with a backslash instead of an at-sign. +  </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td>    ```cpp    /** @@ -406,7 +435,7 @@     */    void foo();    ``` -  </td></tr></table> +  </td></tr></table></details>  # Libraries diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 9ad1ff9..867329f 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,39 +1,23 @@  target_sources(crepe PUBLIC  	Asset.cpp -	Sound.cpp -	SoundContext.cpp  	Particle.cpp -	ParticleSystem.cpp -	SDLApp.cpp  	ComponentManager.cpp  	Component.cpp -	ScriptSystem.cpp -	PhysicsSystem.cpp -	CollisionSystem.cpp  	Collider.cpp -	SDLContext.cpp -	RenderSystem.cpp  	Metadata.cpp  )  target_sources(crepe PUBLIC FILE_SET HEADERS FILES  	Asset.h -	Sound.h -	SoundContext.h -	SDLContext.h  	ComponentManager.h  	ComponentManager.hpp  	Component.h -	System.h -	ScriptSystem.h -	PhysicsSystem.h -	CollisionSystem.h  	Collider.h -	SDLContext.h -	RenderSystem.h  	Metadata.h  )  add_subdirectory(api) +add_subdirectory(facade) +add_subdirectory(system)  add_subdirectory(util) diff --git a/src/crepe/api/AssetManager.cpp b/src/crepe/api/AssetManager.cpp index 560df6c..b891760 100644 --- a/src/crepe/api/AssetManager.cpp +++ b/src/crepe/api/AssetManager.cpp @@ -2,7 +2,7 @@  #include "AssetManager.h" -using namespace crepe::api; +using namespace crepe;  AssetManager & AssetManager::get_instance() {  	static AssetManager instance; diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h index 3e72a49..fefbed9 100644 --- a/src/crepe/api/AssetManager.h +++ b/src/crepe/api/AssetManager.h @@ -5,7 +5,7 @@  #include <string>  #include <unordered_map> -namespace crepe::api { +namespace crepe {  class AssetManager { @@ -30,6 +30,6 @@ public:  								 bool reload = false);  }; -} // namespace crepe::api +} // namespace crepe  #include "AssetManager.hpp" diff --git a/src/crepe/api/AssetManager.hpp b/src/crepe/api/AssetManager.hpp index 468724c..977b4e1 100644 --- a/src/crepe/api/AssetManager.hpp +++ b/src/crepe/api/AssetManager.hpp @@ -2,7 +2,7 @@  #include "AssetManager.h" -namespace crepe::api { +namespace crepe {  template <typename asset>  std::shared_ptr<asset> AssetManager::cache(const std::string & file_path, @@ -21,4 +21,4 @@ std::shared_ptr<asset> AssetManager::cache(const std::string & file_path,  	return new_asset;  } -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index 35b8d83..63fd0d7 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,10 +1,10 @@  #include <memory> -#include "../Sound.h" +#include "../facade/Sound.h"  #include "AudioSource.h" -using namespace crepe::api; +using namespace crepe;  AudioSource::AudioSource(std::unique_ptr<Asset> audio_clip) {  	this->sound = std::make_unique<crepe::Sound>(std::move(audio_clip)); diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 7980212..42add50 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -6,10 +6,8 @@  #include "../Component.h"  namespace crepe { -class Sound; -} -namespace crepe::api { +class Sound;  //! Audio source component  class AudioSource : Component { @@ -35,7 +33,7 @@ public:  	float volume;  private: -	std::unique_ptr<crepe::Sound> sound; +	std::unique_ptr<Sound> sound;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 6133cc8..21638f4 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -9,7 +9,7 @@ class ScriptSystem;  class ComponentManager;  } // namespace crepe -namespace crepe::api { +namespace crepe {  class Script; @@ -30,6 +30,6 @@ protected:  	std::unique_ptr<Script> script = nullptr;  }; -} // namespace crepe::api +} // namespace crepe  #include "BehaviorScript.hpp" diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp index 2a3502f..4751607 100644 --- a/src/crepe/api/BehaviorScript.hpp +++ b/src/crepe/api/BehaviorScript.hpp @@ -7,7 +7,7 @@  #include "BehaviorScript.h"  #include "Script.h" -namespace crepe::api { +namespace crepe {  template <class T>  BehaviorScript & BehaviorScript::set_script() { @@ -19,4 +19,4 @@ BehaviorScript & BehaviorScript::set_script() {  	return *this;  } -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index 762574b..931b012 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -1,7 +1,7 @@  #pragma once  #include "../Collider.h" -namespace crepe::api { +namespace crepe {  class CircleCollider : public Collider {  public: @@ -10,4 +10,4 @@ public:  	int radius;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Color.cpp b/src/crepe/api/Color.cpp index fb5bd1a..fc6313d 100644 --- a/src/crepe/api/Color.cpp +++ b/src/crepe/api/Color.cpp @@ -1,6 +1,6 @@  #include "Color.h" -using namespace crepe::api; +using namespace crepe;  Color Color::white = Color(255, 255, 255, 0);  Color Color::red = Color(255, 0, 0, 0); diff --git a/src/crepe/api/Color.h b/src/crepe/api/Color.h index e818de4..6b54888 100644 --- a/src/crepe/api/Color.h +++ b/src/crepe/api/Color.h @@ -1,6 +1,6 @@  #pragma once -namespace crepe::api { +namespace crepe {  class Color { @@ -34,4 +34,4 @@ private:  	static Color black;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index 8a7f268..22104a7 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -2,7 +2,7 @@  #include "../util/log.h" -namespace crepe::api { +namespace crepe {  class Config {  private: @@ -27,7 +27,7 @@ public:  		 * Only messages with equal or higher priority than this value will be  		 * logged.  		 */ -		util::LogLevel level = util::LogLevel::INFO; +		LogLevel level = LogLevel::INFO;  		/**  		 * \brief Colored log output  		 * @@ -37,4 +37,4 @@ public:  	} log;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Force.cpp b/src/crepe/api/Force.cpp index e359adc..3c33ad3 100644 --- a/src/crepe/api/Force.cpp +++ b/src/crepe/api/Force.cpp @@ -2,7 +2,7 @@  #include "Force.h" -namespace crepe::api { +namespace crepe {  Force::Force(uint32_t game_object_id, uint32_t magnitude, uint32_t direction)  	: Component(game_object_id) { @@ -18,4 +18,4 @@ Force::Force(uint32_t game_object_id, uint32_t magnitude, uint32_t direction)  		std::round(magnitude * std::sin(radian_direction)));  } -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Force.h b/src/crepe/api/Force.h index 8da9a00..c08a8b9 100644 --- a/src/crepe/api/Force.h +++ b/src/crepe/api/Force.h @@ -4,7 +4,7 @@  #include "../Component.h" -namespace crepe::api { +namespace crepe {  class Force : public Component {  public: @@ -14,4 +14,4 @@ public:  	int32_t force_y;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 5393e39..2592d2d 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -3,7 +3,7 @@  #include "GameObject.h"  #include "Metadata.h" -using namespace crepe::api; +using namespace crepe;  using namespace std;  GameObject::GameObject(uint32_t id, std::string name, std::string tag, diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 862fee8..dcd33ad 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -5,7 +5,7 @@  #include "api/Point.h" -namespace crepe::api { +namespace crepe {  class GameObject {  public: @@ -19,6 +19,6 @@ public:  	uint32_t id;  }; -} // namespace crepe::api +} // namespace crepe  #include "GameObject.hpp" diff --git a/src/crepe/api/GameObject.hpp b/src/crepe/api/GameObject.hpp index 3c7e867..77cf40e 100644 --- a/src/crepe/api/GameObject.hpp +++ b/src/crepe/api/GameObject.hpp @@ -4,7 +4,7 @@  #include "GameObject.h" -namespace crepe::api { +namespace crepe {  template <typename T, typename... Args>  T & GameObject::add_component(Args &&... args) { @@ -12,4 +12,4 @@ T & GameObject::add_component(Args &&... args) {  	return mgr.add_component<T>(this->id, std::forward<Args>(args)...);  } -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Point.h b/src/crepe/api/Point.h index b47b7e6..575d624 100644 --- a/src/crepe/api/Point.h +++ b/src/crepe/api/Point.h @@ -1,6 +1,6 @@  #pragma once -namespace crepe::api { +namespace crepe {  class Point {  public: @@ -8,4 +8,4 @@ public:  	double y;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index ebf9fb9..0a6262a 100644 --- a/src/crepe/api/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -1,6 +1,6 @@  #include "Rigidbody.h" -using namespace crepe::api; +using namespace crepe;  Rigidbody::Rigidbody(uint32_t game_object_id, int mass, int gravity_scale,  					 BodyType bodyType) diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h index 6079a76..518ed94 100644 --- a/src/crepe/api/Rigidbody.h +++ b/src/crepe/api/Rigidbody.h @@ -4,7 +4,7 @@  #include "../Component.h" -namespace crepe::api { +namespace crepe {  // FIXME: can't this enum be defined inside the class declaration of Rigidbody?  enum class BodyType { @@ -27,4 +27,4 @@ public:  	BodyType body_type;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index 5016ed0..390cec7 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -1,3 +1,3 @@  #include "Script.h" -using namespace crepe::api; +using namespace crepe; diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 59e6ec0..49e625f 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -6,7 +6,7 @@ namespace crepe {  class ScriptSystem;  } -namespace crepe::api { +namespace crepe {  class BehaviorScript; @@ -29,10 +29,10 @@ protected:  	std::vector<std::reference_wrapper<T>> get_components();  private: -	friend class crepe::api::BehaviorScript; +	friend class crepe::BehaviorScript;  	BehaviorScript * parent = nullptr;  }; -} // namespace crepe::api +} // namespace crepe  #include "Script.hpp" diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index 8004fe3..d96c0e8 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -5,7 +5,7 @@  #include "BehaviorScript.h"  #include "Script.h" -namespace crepe::api { +namespace crepe {  template <typename T>  T & Script::get_component() { @@ -22,4 +22,4 @@ std::vector<std::reference_wrapper<T>> Script::get_components() {  	return mgr.get_components_by_id<T>(this->parent->game_object_id);  } -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 806f147..3dd44f2 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -1,15 +1,14 @@  #include <cstdint>  #include <memory> -#include "api/Texture.h" -#include "util/log.h" +#include "../util/log.h"  #include "Component.h"  #include "Sprite.h" +#include "Texture.h"  using namespace std;  using namespace crepe; -using namespace crepe::api;  Sprite::Sprite(uint32_t id, shared_ptr<Texture> image, const Color & color,  			   const FlipSettings & flip) diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index b06125e..bdb4da9 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -9,7 +9,7 @@  #include "Component.h" -namespace crepe::api { +namespace crepe {  struct FlipSettings {  	bool flip_x = 1; @@ -29,4 +29,4 @@ public:  	uint8_t order_in_layer;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index 481ef7c..8fc5c13 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -1,12 +1,12 @@  #include <SDL2/SDL_render.h> -#include "util/log.h" +#include "../facade/SDLContext.h" +#include "../util/log.h"  #include "Asset.h" -#include "SDLContext.h"  #include "Texture.h" -using namespace crepe::api; +using namespace crepe;  using namespace std;  Texture::Texture(unique_ptr<Asset> res) { diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h index f8481e3..9a86f6f 100644 --- a/src/crepe/api/Texture.h +++ b/src/crepe/api/Texture.h @@ -12,7 +12,7 @@ namespace crepe {  class SDLContext;  } -namespace crepe::api { +namespace crepe {  class Texture { @@ -30,4 +30,4 @@ private:  	friend class crepe::SDLContext;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index 4b4da8f..a80aff3 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -6,7 +6,7 @@  #include "Component.h"  #include "Transform.h" -using namespace crepe::api; +using namespace crepe;  Transform::Transform(uint32_t game_id, Point point, double rot, double scale)  	: Component(game_id), position(point), rotation(rot), scale(scale) { diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index 85e16b4..f918115 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -6,7 +6,7 @@  #include "Component.h" -namespace crepe::api { +namespace crepe {  class Transform : public Component {  	// FIXME: What's the difference between the `Point` and `Position` @@ -25,4 +25,4 @@ public:  	double scale;  }; -} // namespace crepe::api +} // namespace crepe diff --git a/src/crepe/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt new file mode 100644 index 0000000..dbddcc6 --- /dev/null +++ b/src/crepe/facade/CMakeLists.txt @@ -0,0 +1,14 @@ +target_sources(crepe PUBLIC +	Sound.cpp +	SoundContext.cpp +	SDLApp.cpp +	SDLContext.cpp +) + +target_sources(crepe PUBLIC FILE_SET HEADERS FILES +	Sound.h +	SoundContext.h +	SDLContext.h +	SDLContext.h +) + diff --git a/src/crepe/SDLApp.cpp b/src/crepe/facade/SDLApp.cpp index c6ddeaa..c6ddeaa 100644 --- a/src/crepe/SDLApp.cpp +++ b/src/crepe/facade/SDLApp.cpp diff --git a/src/crepe/SDLApp.h b/src/crepe/facade/SDLApp.h index e67947b..6d8f3f4 100644 --- a/src/crepe/SDLApp.h +++ b/src/crepe/facade/SDLApp.h @@ -2,7 +2,7 @@  #include <SDL2/SDL.h> -#include "api/ParticleEmitter.h" +#include "../api/ParticleEmitter.h"  class SDLApp {  public: diff --git a/src/crepe/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 8bc5bc6..8da93e9 100644 --- a/src/crepe/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -7,10 +7,10 @@  #include <cstddef>  #include <iostream> -#include "api/Sprite.h" -#include "api/Texture.h" -#include "api/Transform.h" -#include "util/log.h" +#include "../api/Sprite.h" +#include "../api/Texture.h" +#include "../api/Transform.h" +#include "../util/log.h"  #include "SDLContext.h" @@ -89,8 +89,7 @@ SDLContext::SDLContext() {  void SDLContext::present_screen() { SDL_RenderPresent(this->game_renderer); } -void SDLContext::draw(const api::Sprite & sprite, -					  const api::Transform & transform) { +void SDLContext::draw(const Sprite & sprite, const Transform & transform) {  	static SDL_RendererFlip render_flip  		= (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) diff --git a/src/crepe/SDLContext.h b/src/crepe/facade/SDLContext.h index 4d9c1bc..f1ba8a6 100644 --- a/src/crepe/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -3,17 +3,13 @@  #include <SDL2/SDL_render.h>  #include <SDL2/SDL_video.h> -#include "api/Sprite.h" -#include "api/Transform.h" - -#include "RenderSystem.h" - -namespace crepe::api { -class Texture; -} +#include "../api/Sprite.h" +#include "../api/Transform.h" +#include "../system/RenderSystem.h"  namespace crepe { +class Texture;  class SDLContext {  public: @@ -34,13 +30,13 @@ private:  	virtual ~SDLContext();  private: -	friend class api::Texture; +	friend class Texture;  	SDL_Texture * texture_from_path(const char *);  	//SDL_Texture* setTextureFromPath(const char*, SDL_Rect& clip, const int row, const int col);  private:  	friend class RenderSystem; -	void draw(const api::Sprite &, const api::Transform &); +	void draw(const Sprite &, const Transform &);  	void clear_screen();  	void present_screen(); diff --git a/src/crepe/Sound.cpp b/src/crepe/facade/Sound.cpp index 64fa281..648ec81 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/facade/Sound.cpp @@ -1,4 +1,4 @@ -#include "util/log.h" +#include "../util/log.h"  #include "Sound.h"  #include "SoundContext.h" diff --git a/src/crepe/Sound.h b/src/crepe/facade/Sound.h index 917b57e..183bd7c 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/facade/Sound.h @@ -4,7 +4,7 @@  #include <soloud/soloud.h>  #include <soloud/soloud_wav.h> -#include "Asset.h" +#include "../Asset.h"  namespace crepe { diff --git a/src/crepe/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp index 72047d2..5e5a3a9 100644 --- a/src/crepe/SoundContext.cpp +++ b/src/crepe/facade/SoundContext.cpp @@ -1,4 +1,4 @@ -#include "util/log.h" +#include "../util/log.h"  #include "SoundContext.h" diff --git a/src/crepe/SoundContext.h b/src/crepe/facade/SoundContext.h index d3123d2..d3123d2 100644 --- a/src/crepe/SoundContext.h +++ b/src/crepe/facade/SoundContext.h diff --git a/src/crepe/system/CMakeLists.txt b/src/crepe/system/CMakeLists.txt new file mode 100644 index 0000000..ff6f66f --- /dev/null +++ b/src/crepe/system/CMakeLists.txt @@ -0,0 +1,15 @@ +target_sources(crepe PUBLIC +	ParticleSystem.cpp +	ScriptSystem.cpp +	PhysicsSystem.cpp +	CollisionSystem.cpp +	RenderSystem.cpp +) + +target_sources(crepe PUBLIC FILE_SET HEADERS FILES +	System.h +	ScriptSystem.h +	PhysicsSystem.h +	CollisionSystem.h +	RenderSystem.h +) diff --git a/src/crepe/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 55e0fdc..55e0fdc 100644 --- a/src/crepe/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp diff --git a/src/crepe/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 1e9f1aa..1e9f1aa 100644 --- a/src/crepe/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index af6c550..397b586 100644 --- a/src/crepe/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -1,9 +1,9 @@  #include <cmath>  #include <ctime> -#include "api/ParticleEmitter.h" +#include "../ComponentManager.h" +#include "../api/ParticleEmitter.h" -#include "ComponentManager.h"  #include "ParticleSystem.h"  using namespace crepe; diff --git a/src/crepe/ParticleSystem.h b/src/crepe/system/ParticleSystem.h index ad96eb0..3ac1d3f 100644 --- a/src/crepe/ParticleSystem.h +++ b/src/crepe/system/ParticleSystem.h @@ -1,6 +1,6 @@  #pragma once -#include "api/ParticleEmitter.h" +#include "../api/ParticleEmitter.h"  namespace crepe { diff --git a/src/crepe/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp index 16f4c10..cea8062 100644 --- a/src/crepe/PhysicsSystem.cpp +++ b/src/crepe/system/PhysicsSystem.cpp @@ -1,14 +1,13 @@  #include <iostream> -#include "api/Force.h" -#include "api/Rigidbody.h" -#include "api/Transform.h" +#include "../ComponentManager.h" +#include "../api/Force.h" +#include "../api/Rigidbody.h" +#include "../api/Transform.h" -#include "ComponentManager.h"  #include "PhysicsSystem.h"  using namespace crepe; -using namespace crepe::api;  PhysicsSystem::PhysicsSystem() {} diff --git a/src/crepe/PhysicsSystem.h b/src/crepe/system/PhysicsSystem.h index 33b4072..33b4072 100644 --- a/src/crepe/PhysicsSystem.h +++ b/src/crepe/system/PhysicsSystem.h diff --git a/src/crepe/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index fae93f0..5a07cc2 100644 --- a/src/crepe/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -1,16 +1,15 @@  #include <functional>  #include <vector> -#include "api/Sprite.h" -#include "api/Transform.h" -#include "util/log.h" +#include "../ComponentManager.h" +#include "../api/Sprite.h" +#include "../api/Transform.h" +#include "../facade/SDLContext.h" +#include "../util/log.h" -#include "ComponentManager.h"  #include "RenderSystem.h" -#include "SDLContext.h"  using namespace crepe; -using namespace crepe::api;  RenderSystem::RenderSystem() { dbg_trace(); } diff --git a/src/crepe/RenderSystem.h b/src/crepe/system/RenderSystem.h index 4b910a4..4b910a4 100644 --- a/src/crepe/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h diff --git a/src/crepe/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index 171b490..f1fae4d 100644 --- a/src/crepe/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -2,16 +2,15 @@  #include <functional>  #include <vector> -#include "api/BehaviorScript.h" -#include "api/Script.h" -#include "util/log.h" +#include "../ComponentManager.h" +#include "../api/BehaviorScript.h" +#include "../api/Script.h" +#include "../util/log.h" -#include "ComponentManager.h"  #include "ScriptSystem.h"  using namespace std;  using namespace crepe; -using namespace crepe::api;  ScriptSystem::ScriptSystem() { dbg_trace(); }  ScriptSystem::~ScriptSystem() { dbg_trace(); } diff --git a/src/crepe/ScriptSystem.h b/src/crepe/system/ScriptSystem.h index 1f472a0..32e793c 100644 --- a/src/crepe/ScriptSystem.h +++ b/src/crepe/system/ScriptSystem.h @@ -4,12 +4,10 @@  #include "System.h" -namespace crepe::api { -class Script; -} -  namespace crepe { +class Script; +  class ScriptSystem : public System {  public:  	static ScriptSystem & get_instance(); @@ -20,7 +18,8 @@ private:  	~ScriptSystem();  private: -	std::forward_list<api::Script *> get_scripts(); +	// TODO: to forward_list<reference_wrapper> +	std::forward_list<Script *> get_scripts();  };  } // namespace crepe diff --git a/src/crepe/System.h b/src/crepe/system/System.h index 8744920..8744920 100644 --- a/src/crepe/System.h +++ b/src/crepe/system/System.h diff --git a/src/crepe/util/CMakeLists.txt b/src/crepe/util/CMakeLists.txt index bbeaad9..3675bee 100644 --- a/src/crepe/util/CMakeLists.txt +++ b/src/crepe/util/CMakeLists.txt @@ -1,11 +1,11 @@  target_sources(crepe PUBLIC -	color.cpp +	LogColor.cpp  	log.cpp  	fmt.cpp  )  target_sources(crepe PUBLIC FILE_SET HEADERS FILES -	color.h +	LogColor.h  	log.h  	fmt.h  ) diff --git a/src/crepe/util/color.cpp b/src/crepe/util/LogColor.cpp index a7bbc81..b5fe3ea 100644 --- a/src/crepe/util/color.cpp +++ b/src/crepe/util/LogColor.cpp @@ -1,16 +1,17 @@  #include <cstdarg>  #include "../api/Config.h" -#include "color.h" +#include "LogColor.h" +  #include "fmt.h" -using namespace crepe::util; +using namespace crepe;  using namespace std;  static constexpr const char * RESET_CODE = "\e[0m";  const string LogColor::str(const string & content) { -	auto & cfg = api::Config::get_instance(); +	auto & cfg = Config::get_instance();  	string out = content;  	if (cfg.log.color) out = this->code + out;  	if (content.size() == 0) return out; diff --git a/src/crepe/util/color.h b/src/crepe/util/LogColor.h index 91e1abe..c1170cb 100644 --- a/src/crepe/util/color.h +++ b/src/crepe/util/LogColor.h @@ -2,7 +2,7 @@  #include <string> -namespace crepe::util { +namespace crepe {  class LogColor {  public: @@ -48,4 +48,4 @@ private:  	std::string final = "";  }; -} // namespace crepe::util +} // namespace crepe diff --git a/src/crepe/util/fmt.cpp b/src/crepe/util/fmt.cpp index 397bf9f..4b50da8 100644 --- a/src/crepe/util/fmt.cpp +++ b/src/crepe/util/fmt.cpp @@ -6,7 +6,7 @@  using namespace std; -string crepe::util::va_stringf(va_list args, const char * fmt) { +string crepe::va_stringf(va_list args, const char * fmt) {  	string out;  	va_list args_copy; @@ -26,7 +26,7 @@ string crepe::util::va_stringf(va_list args, const char * fmt) {  	return out;  } -string crepe::util::stringf(const char * fmt, ...) { +string crepe::stringf(const char * fmt, ...) {  	va_list args;  	va_start(args, fmt);  	string out = va_stringf(args, fmt); diff --git a/src/crepe/util/fmt.h b/src/crepe/util/fmt.h index 44c426f..e319e6e 100644 --- a/src/crepe/util/fmt.h +++ b/src/crepe/util/fmt.h @@ -2,9 +2,9 @@  #include <string> -namespace crepe::util { +namespace crepe {  std::string va_stringf(va_list args, const char * fmt);  std::string stringf(const char * fmt, ...); -} // namespace crepe::util +} // namespace crepe diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp index 6bcc4ae..4a8f8e8 100644 --- a/src/crepe/util/log.cpp +++ b/src/crepe/util/log.cpp @@ -7,7 +7,7 @@  #include "fmt.h"  #include "log.h" -using namespace crepe::util; +using namespace crepe;  using namespace std;  string log_prefix(LogLevel level) { @@ -27,25 +27,25 @@ string log_prefix(LogLevel level) {  }  static void log(LogLevel level, const string msg) { -	auto & cfg = crepe::api::Config::get_instance(); +	auto & cfg = Config::get_instance();  	if (level < cfg.log.level) return;  	string out = log_prefix(level) + msg;  	if (!out.ends_with("\n")) out += "\n";  	// TODO: also log to file or smth -	printf("%s", out.c_str()); +	fwrite(out.c_str(), 1, out.size(), stdout);  	fflush(stdout);  } -void crepe::util::logf(const char * fmt, ...) { +void crepe::logf(const char * fmt, ...) {  	va_list args;  	va_start(args, fmt);  	log(LogLevel::DEBUG, va_stringf(args, fmt));  	va_end(args);  } -void crepe::util::logf(LogLevel level, const char * fmt, ...) { +void crepe::logf(LogLevel level, const char * fmt, ...) {  	va_list args;  	va_start(args, fmt);  	log(level, va_stringf(args, fmt)); diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h index 308ba96..5a1cf00 100644 --- a/src/crepe/util/log.h +++ b/src/crepe/util/log.h @@ -3,28 +3,27 @@  // allow user to disable debug macros  #ifndef CREPE_DISABLE_MACROS -#include "color.h" +#include "LogColor.h"  // utility macros  #define _crepe_logf_here(level, format, ...) \ -	crepe::util::logf( \ +	crepe::logf( \  		level, "%s" format, \ -		crepe::util::LogColor().fg_white(false).fmt( \ +		crepe::LogColor().fg_white(false).fmt( \  			"%s (%s:%d)", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__), \  		__VA_ARGS__)  // very illegal global function-style macros  // NOLINTBEGIN  #define dbg_logf(fmt, ...) \ -	_crepe_logf_here(crepe::util::LogLevel::DEBUG, ": " fmt, __VA_ARGS__) -#define dbg_log(str) \ -	_crepe_logf_here(crepe::util::LogLevel::DEBUG, "%s: " str, "") -#define dbg_trace() _crepe_logf_here(crepe::util::LogLevel::TRACE, "%s", "") +	_crepe_logf_here(crepe::LogLevel::DEBUG, ": " fmt, __VA_ARGS__) +#define dbg_log(str) _crepe_logf_here(crepe::LogLevel::DEBUG, "%s: " str, "") +#define dbg_trace() _crepe_logf_here(crepe::LogLevel::TRACE, "%s", "")  // NOLINTEND  #endif -namespace crepe::util { +namespace crepe {  enum LogLevel {  	TRACE, @@ -37,4 +36,4 @@ enum LogLevel {  void logf(const char * fmt, ...);  void logf(enum LogLevel level, const char * fmt, ...); -} // namespace crepe::util +} // namespace crepe diff --git a/src/example/asset_manager.cpp b/src/example/asset_manager.cpp index 7e15d1f..cf64f89 100644 --- a/src/example/asset_manager.cpp +++ b/src/example/asset_manager.cpp @@ -1,11 +1,9 @@ - - -#include <crepe/Sound.h>  #include <crepe/api/AssetManager.h>  #include <crepe/api/Texture.h> +#include <crepe/facade/Sound.h>  using namespace crepe; -using namespace crepe::api; +  int main() {  	// this needs to be called before the asset manager otherwise the destructor diff --git a/src/example/audio_internal.cpp b/src/example/audio_internal.cpp index c7dd163..1ea839d 100644 --- a/src/example/audio_internal.cpp +++ b/src/example/audio_internal.cpp @@ -3,14 +3,13 @@   * Standalone example for usage of the internal \c Sound class.   */ -#include <crepe/Sound.h>  #include <crepe/api/Config.h> +#include <crepe/facade/Sound.h>  #include <crepe/util/log.h>  #include <thread>  using namespace crepe; -using namespace crepe::api;  using namespace std;  using namespace std::chrono_literals;  using std::make_unique; @@ -18,8 +17,8 @@ using std::make_unique;  // Unrelated stuff that is not part of this POC  int _ = []() {  	// Show dbg_trace() output -	auto & cfg = api::Config::get_instance(); -	cfg.log.level = util::LogLevel::TRACE; +	auto & cfg = Config::get_instance(); +	cfg.log.level = LogLevel::TRACE;  	return 0; // satisfy compiler  }(); diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp index 3c68974..ea1eaad 100644 --- a/src/example/components_internal.cpp +++ b/src/example/components_internal.cpp @@ -15,7 +15,6 @@  #include <crepe/util/log.h> -using namespace crepe::api;  using namespace crepe;  using namespace std; diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index 5646edd..eb5eeba 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -5,7 +5,6 @@  #include "../crepe/api/GameObject.h"  #include "../crepe/api/Transform.h" -using namespace crepe::api;  using namespace crepe;  using namespace std; diff --git a/src/example/log.cpp b/src/example/log.cpp index 75f133c..db8aa48 100644 --- a/src/example/log.cpp +++ b/src/example/log.cpp @@ -7,13 +7,12 @@  #include <crepe/util/log.h>  using namespace crepe; -using namespace crepe::util;  // unrelated setup code  int _ = []() {  	// make sure all log messages get printed -	auto & cfg = api::Config::get_instance(); -	cfg.log.level = util::LogLevel::TRACE; +	auto & cfg = Config::get_instance(); +	cfg.log.level = LogLevel::TRACE;  	return 0; // satisfy compiler  }(); diff --git a/src/example/particle.cpp b/src/example/particle.cpp index fe8a43b..69da015 100644 --- a/src/example/particle.cpp +++ b/src/example/particle.cpp @@ -1,15 +1,15 @@ -#include "Particle.h" -#include "ParticleSystem.h" -#include "SDLApp.h" -#include "api/ParticleEmitter.h"  #include <chrono> +#include <iostream> +#include <thread> +  #include <crepe/Component.h>  #include <crepe/ComponentManager.h> +#include <crepe/Particle.h>  #include <crepe/api/GameObject.h> -#include <iostream> -#include <thread> +#include <crepe/api/ParticleEmitter.h> +#include <crepe/facade/SDLApp.h> +#include <crepe/system/ParticleSystem.h> -using namespace crepe::api;  using namespace crepe;  using namespace std; diff --git a/src/example/physics.cpp b/src/example/physics.cpp index 1bafdf3..c7db6ac 100644 --- a/src/example/physics.cpp +++ b/src/example/physics.cpp @@ -1,15 +1,15 @@ -#include "PhysicsSystem.h"  #include <chrono> +#include <iostream> +#include <thread> +  #include <crepe/Component.h>  #include <crepe/ComponentManager.h>  #include <crepe/api/Force.h>  #include <crepe/api/GameObject.h>  #include <crepe/api/Rigidbody.h>  #include <crepe/api/Transform.h> -#include <iostream> -#include <thread> +#include <crepe/system/PhysicsSystem.h> -using namespace crepe::api;  using namespace crepe;  using namespace std; diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp index 9624093..f3d8a7d 100644 --- a/src/example/rendering.cpp +++ b/src/example/rendering.cpp @@ -1,8 +1,6 @@ - -  #include <crepe/ComponentManager.h> -#include <crepe/RenderSystem.h>  #include <crepe/api/GameObject.h> +#include <crepe/system/RenderSystem.h>  #include <crepe/util/log.h>  #include <crepe/api/AssetManager.h> @@ -17,7 +15,6 @@  using namespace std;  using namespace crepe; -using namespace crepe::api;  int main() { diff --git a/src/example/script.cpp b/src/example/script.cpp index e4c8319..928eddf 100644 --- a/src/example/script.cpp +++ b/src/example/script.cpp @@ -4,7 +4,7 @@   */  #include <crepe/ComponentManager.h> -#include <crepe/ScriptSystem.h> +#include <crepe/system/ScriptSystem.h>  #include <crepe/util/log.h>  #include <crepe/api/BehaviorScript.h> @@ -14,14 +14,13 @@  #include <crepe/api/Transform.h>  using namespace crepe; -using namespace crepe::api;  using namespace std;  // Unrelated stuff that is not part of this POC  int _ = []() {  	// Show dbg_trace() output -	auto & cfg = api::Config::get_instance(); -	cfg.log.level = util::LogLevel::TRACE; +	auto & cfg = Config::get_instance(); +	cfg.log.level = LogLevel::TRACE;  	return 0; // satisfy compiler  }(); |