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.
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)};
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

View File

@ -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

View File

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

View File

@ -16,10 +16,10 @@ ImageQuad::~ImageQuad() {
Destroy();
}
void ImageQuad::Create(const std::string& asset_name,
std::array<int, 2> num_frames,
int frame_width,
int frame_height) {
ImageQuad& ImageQuad::Create(const std::string& asset_name,
std::array<int, 2> 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() {

View File

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

View File

@ -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)};