diff --git a/README.md b/README.md index b2473f3..3840fab 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Logo](kaliber.png) +# Kaliber A simple, cross-platform 2D game engine with OpenGL and Vulkan renderers. Supports Linux and Android platforms. @@ -8,9 +8,8 @@ based on this engine. Full game code and assets are included in this repository. ## Pre-requisites: -This project uses **GN build system** for all platforms except Android -(I want to add support for APKs, Java code etc. to the GN configuration and use -it for all platforms). \ +**GN build system** is required for all platforms except Android (support for +APKs, Java code etc. is to be added to the GN configuration). \ Building GN from source: https://gn.googlesource.com/gn/ \ Pre-built GN binaries: @@ -18,8 +17,7 @@ https://chrome-infra-packages.appspot.com/p/gn/gn/ Linux is the supported host platform to build Android. **Gradle**, **Android SDK** and **NDK** are required. If you prefer, you can install -**Android Studio** which -includes all the requirements. +**Android Studio** which includes all the requirements. ## Building from the command-line: @@ -70,8 +68,7 @@ class HelloWorld final : public eng::Game { std::bind(&eng::Engine::Print, &eng::Engine::Get(), "Hello World!", base::Vector4f(1, 1, 1, 0))); - hello_world_.Create("hello_world_image"); - hello_world_.SetVisible(true); + hello_world_.Create("hello_world_image").SetVisible(true); animator_.Attach(&hello_world_); animator_.SetRotation(base::PI2f, 3, std::bind(base::SmootherStep, std::placeholders::_1)); @@ -84,7 +81,5 @@ class HelloWorld final : public eng::Game { eng::Animator animator_; }; -DECLARE_GAME_BEGIN -DECLARE_GAME(HelloWorld) -DECLARE_GAME_END +GAME_FACTORIES{GAME_CLASS(HelloWorld)}; ``` diff --git a/kaliber.png b/kaliber.png deleted file mode 100644 index a756276..0000000 Binary files a/kaliber.png and /dev/null differ diff --git a/src/demo/demo.cc b/src/demo/demo.cc index 6e82204..4dc51e7 100644 --- a/src/demo/demo.cc +++ b/src/demo/demo.cc @@ -14,9 +14,7 @@ #include "engine/game_factory.h" #include "engine/input_event.h" -DECLARE_GAME_BEGIN -DECLARE_GAME(Demo) -DECLARE_GAME_END +GAME_FACTORIES{GAME_CLASS(Demo)}; // #define RECORD 15 // #define REPLAY diff --git a/src/engine/game_factory.h b/src/engine/game_factory.h index 3cf513c..d6b1545 100644 --- a/src/engine/game_factory.h +++ b/src/engine/game_factory.h @@ -5,11 +5,11 @@ #include #include -#define DECLARE_GAME_BEGIN \ +#define GAME_FACTORIES \ std::vector> \ - eng::GameFactoryBase::game_classes = { -#define DECLARE_GAME(CLASS) {#CLASS, new eng::GameFactory()}, -#define DECLARE_GAME_END }; + eng::GameFactoryBase::game_classes +#define GAME_CLASS(CLASS) \ + { #CLASS, new eng::GameFactory() } namespace eng { @@ -19,6 +19,8 @@ class GameFactoryBase { public: virtual ~GameFactoryBase() = default; + // Create an instance for the class of the given name. The default factory is + // used if the name is empty (which is the first one in the list). static std::unique_ptr CreateGame(const std::string& name) { if (name.empty()) return game_classes.size() > 0 diff --git a/src/engine/image_quad.cc b/src/engine/image_quad.cc index b5c7c10..ed1b55b 100644 --- a/src/engine/image_quad.cc +++ b/src/engine/image_quad.cc @@ -16,10 +16,10 @@ ImageQuad::~ImageQuad() { Destroy(); } -void ImageQuad::Create(const std::string& asset_name, - std::array num_frames, - int frame_width, - int frame_height) { +ImageQuad& ImageQuad::Create(const std::string& asset_name, + std::array num_frames, + int frame_width, + int frame_height) { texture_ = Engine::Get().AcquireTexture(asset_name); num_frames_ = std::move(num_frames); frame_width_ = frame_width; @@ -30,6 +30,7 @@ void ImageQuad::Create(const std::string& asset_name, << asset_name; SetSize(Engine::Get().ToScale({GetFrameWidth(), GetFrameHeight()}) * Engine::Get().GetImageScaleFactor()); + return *this; } void ImageQuad::Destroy() { diff --git a/src/engine/image_quad.h b/src/engine/image_quad.h index a010aa0..660dc95 100644 --- a/src/engine/image_quad.h +++ b/src/engine/image_quad.h @@ -19,10 +19,10 @@ class ImageQuad final : public Animatable { ImageQuad(); ~ImageQuad() final; - void Create(const std::string& asset_name, - std::array num_frames = {1, 1}, - int frame_width = 0, - int frame_height = 0); + ImageQuad& Create(const std::string& asset_name, + std::array num_frames = {1, 1}, + int frame_width = 0, + int frame_height = 0); void Destroy(); diff --git a/src/hello_world/hello_world.cc b/src/hello_world/hello_world.cc index 97b07f0..234327a 100644 --- a/src/hello_world/hello_world.cc +++ b/src/hello_world/hello_world.cc @@ -16,8 +16,7 @@ class HelloWorld final : public eng::Game { std::bind(&eng::Engine::Print, &eng::Engine::Get(), "Hello World!", base::Vector4f(1, 1, 1, 0))); - hello_world_.Create("hello_world_image"); - hello_world_.SetVisible(true); + hello_world_.Create("hello_world_image").SetVisible(true); animator_.Attach(&hello_world_); animator_.SetRotation(base::PI2f, 3, std::bind(base::SmootherStep, std::placeholders::_1)); @@ -30,6 +29,4 @@ class HelloWorld final : public eng::Game { eng::Animator animator_; }; -DECLARE_GAME_BEGIN -DECLARE_GAME(HelloWorld) -DECLARE_GAME_END +GAME_FACTORIES{GAME_CLASS(HelloWorld)};