Code cleanup

This commit is contained in:
Attila Uygun 2023-08-05 01:52:07 +02:00
parent 478bb8ecb1
commit f56cc119bf
7 changed files with 24 additions and 31 deletions

View File

@ -1,4 +1,4 @@
![Logo](kaliber.png) # Kaliber
A simple, cross-platform 2D game engine with OpenGL and Vulkan renderers. A simple, cross-platform 2D game engine with OpenGL and Vulkan renderers.
Supports Linux and Android platforms. 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: ## Pre-requisites:
This project uses **GN build system** for all platforms except Android **GN build system** is required for all platforms except Android (support for
(I want to add support for APKs, Java code etc. to the GN configuration and use APKs, Java code etc. is to be added to the GN configuration). \
it for all platforms). \
Building GN from source: Building GN from source:
https://gn.googlesource.com/gn/ \ https://gn.googlesource.com/gn/ \
Pre-built GN binaries: 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**, Linux is the supported host platform to build Android. **Gradle**,
**Android SDK** and **NDK** are required. If you prefer, you can install **Android SDK** and **NDK** are required. If you prefer, you can install
**Android Studio** which **Android Studio** which includes all the requirements.
includes all the requirements.
## Building from the command-line: ## 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!", std::bind(&eng::Engine::Print, &eng::Engine::Get(), "Hello World!",
base::Vector4f(1, 1, 1, 0))); base::Vector4f(1, 1, 1, 0)));
hello_world_.Create("hello_world_image"); hello_world_.Create("hello_world_image").SetVisible(true);
hello_world_.SetVisible(true);
animator_.Attach(&hello_world_); animator_.Attach(&hello_world_);
animator_.SetRotation(base::PI2f, 3, animator_.SetRotation(base::PI2f, 3,
std::bind(base::SmootherStep, std::placeholders::_1)); std::bind(base::SmootherStep, std::placeholders::_1));
@ -84,7 +81,5 @@ class HelloWorld final : public eng::Game {
eng::Animator animator_; eng::Animator animator_;
}; };
DECLARE_GAME_BEGIN GAME_FACTORIES{GAME_CLASS(HelloWorld)};
DECLARE_GAME(HelloWorld)
DECLARE_GAME_END
``` ```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

View File

@ -14,9 +14,7 @@
#include "engine/game_factory.h" #include "engine/game_factory.h"
#include "engine/input_event.h" #include "engine/input_event.h"
DECLARE_GAME_BEGIN GAME_FACTORIES{GAME_CLASS(Demo)};
DECLARE_GAME(Demo)
DECLARE_GAME_END
// #define RECORD 15 // #define RECORD 15
// #define REPLAY // #define REPLAY

View File

@ -5,11 +5,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#define DECLARE_GAME_BEGIN \ #define GAME_FACTORIES \
std::vector<std::pair<std::string, eng::GameFactoryBase*>> \ std::vector<std::pair<std::string, eng::GameFactoryBase*>> \
eng::GameFactoryBase::game_classes = { eng::GameFactoryBase::game_classes
#define DECLARE_GAME(CLASS) {#CLASS, new eng::GameFactory<CLASS>()}, #define GAME_CLASS(CLASS) \
#define DECLARE_GAME_END }; { #CLASS, new eng::GameFactory<CLASS>() }
namespace eng { namespace eng {
@ -19,6 +19,8 @@ class GameFactoryBase {
public: public:
virtual ~GameFactoryBase() = default; 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<Game> CreateGame(const std::string& name) { static std::unique_ptr<Game> CreateGame(const std::string& name) {
if (name.empty()) if (name.empty())
return game_classes.size() > 0 return game_classes.size() > 0

View File

@ -16,7 +16,7 @@ ImageQuad::~ImageQuad() {
Destroy(); Destroy();
} }
void ImageQuad::Create(const std::string& asset_name, ImageQuad& ImageQuad::Create(const std::string& asset_name,
std::array<int, 2> num_frames, std::array<int, 2> num_frames,
int frame_width, int frame_width,
int frame_height) { int frame_height) {
@ -30,6 +30,7 @@ void ImageQuad::Create(const std::string& asset_name,
<< asset_name; << asset_name;
SetSize(Engine::Get().ToScale({GetFrameWidth(), GetFrameHeight()}) * SetSize(Engine::Get().ToScale({GetFrameWidth(), GetFrameHeight()}) *
Engine::Get().GetImageScaleFactor()); Engine::Get().GetImageScaleFactor());
return *this;
} }
void ImageQuad::Destroy() { void ImageQuad::Destroy() {

View File

@ -19,7 +19,7 @@ class ImageQuad final : public Animatable {
ImageQuad(); ImageQuad();
~ImageQuad() final; ~ImageQuad() final;
void Create(const std::string& asset_name, ImageQuad& Create(const std::string& asset_name,
std::array<int, 2> num_frames = {1, 1}, std::array<int, 2> num_frames = {1, 1},
int frame_width = 0, int frame_width = 0,
int frame_height = 0); int frame_height = 0);

View File

@ -16,8 +16,7 @@ class HelloWorld final : public eng::Game {
std::bind(&eng::Engine::Print, &eng::Engine::Get(), "Hello World!", std::bind(&eng::Engine::Print, &eng::Engine::Get(), "Hello World!",
base::Vector4f(1, 1, 1, 0))); base::Vector4f(1, 1, 1, 0)));
hello_world_.Create("hello_world_image"); hello_world_.Create("hello_world_image").SetVisible(true);
hello_world_.SetVisible(true);
animator_.Attach(&hello_world_); animator_.Attach(&hello_world_);
animator_.SetRotation(base::PI2f, 3, animator_.SetRotation(base::PI2f, 3,
std::bind(base::SmootherStep, std::placeholders::_1)); std::bind(base::SmootherStep, std::placeholders::_1));
@ -30,6 +29,4 @@ class HelloWorld final : public eng::Game {
eng::Animator animator_; eng::Animator animator_;
}; };
DECLARE_GAME_BEGIN GAME_FACTORIES{GAME_CLASS(HelloWorld)};
DECLARE_GAME(HelloWorld)
DECLARE_GAME_END