Rename Image to Texture, add PRAGMA macros to pragmautil.hpp, add some TODO() and WARNING() calls

This commit is contained in:
Tulpen 2023-05-27 18:11:46 +01:00
parent 5aaf616f34
commit 72d5aa0502
14 changed files with 207 additions and 160 deletions

1
.gitignore vendored
View file

@ -20,6 +20,7 @@ build
*.lst
*.user
*.kdev4
*.kate-swp
docs.json
__dummy.html
dub.selections.json

26
README.md Normal file
View file

@ -0,0 +1,26 @@
# Hibis Game Engine
Hibis (short for Hibiscus ([named after the genus of flowering plants](https://en.wikipedia.org/wiki/Hibiscus))) is a work in progress game engine written in C++.<br>
The goal of this game engine is to provide each part of the engine (renderer, audio, physics etc.) in seperate libraries so you can easily make your own system if need be.
# Install
## Pre-compiled libraries
lmao they don't exist yet chill
## Compiling
### Note: MSVC
`MSVC` (Microsoft Visual C++ Compiler) is unsupported and I cannot guarentee that Hibis will compile using it. Please use another compiler like G++ or Ninja instead.
### Dependencies
To compile Hibis, you will need:
- Meson
- Meson-compatible compiler (recommended: Ninja or ccache + G++)
- A few minutes of your time
Each non-core library also has specific dependencies, including:
- (RSDL) SDL2
- (RSDL) SDL2_ttf
Linux users should be able to get all of these (except time) from their package manager.<br>
Windows users will need to use vcpkg or similar to easily get these dependencies.
### Actually Compiling
#### No Customising
Run `compile.sh` in the folder you cloned Hibis into.
#### Customising
In the folder you cloned Hibis into, run `meson build` to create a folder where the magic happens.<br>
Move into the build directory using CD and you can now use `meson configure` to adjust compile options.<br>
Once you have configured everything, run `meson compile` in the build directory and it should finish successfully.

View file

@ -36,3 +36,5 @@
- [ ] Physics Shape creation
- [ ] Collision via raycasting
- [ ] Option to *allow* for Physics Shapes to be able to be drawn (on by default, both compile time and run time, turn off at compile time via version(`-version=NoPhysShapeDraw`?))
## Examples
- [ ] Example Game: Megaman clone

View file

@ -1,16 +1,18 @@
#include "enginever.hpp"
#include "engine.hpp"
#include <pragmautil.hpp>
#include <core/graphics/drawable.hpp>
namespace hibis {
Engine::Engine(Renderer* renderer, LoggerCallback logger) {
this->renderer = renderer;
loggerCallback = logger;
previousProcessTick = 0.00001f;
previousPhysicsProcessTick = 0.00001f;
previousProcessTick = std::chrono::steady_clock::now();
previousPhysicsProcessTick = std::chrono::steady_clock::now();
//watch.start();
this->loggerCallback(Information, "Started Hibis!");
this->loggerCallback(Information, "Started Hibis [using v" + (std::string)getEngineVersion() + "]!");
}
Engine::~Engine() {
@ -18,32 +20,35 @@ namespace hibis {
}
void Engine::runNodeProcesses() {
// TODO: fix delta then adapt for runNodePhysicsProcesses
//const float current = watch.peek.total!"msecs" / 1_000;
//float delta = (current - previousProcessTick);
TODO("check if delta calc is correct")
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
auto delta = std::chrono::duration<float>(current - previousProcessTick);
for (Node* node : nodeList) {
node->physicsProcess(0.00f);
node->process(delta.count());
}
//this.previousProcessTick = watch.peek.total!"msecs" / 1_000;
previousProcessTick = std::chrono::steady_clock::now();
}
void Engine::runNodePhysicsProcesses() {
// TODO: See above TODO
// Schade! Have the wrong function content while I figure out how std.datetime.watch works
//const float current = watch.peek.total!"msecs" / 1_000;
//float delta = (current - previousProcessTick);
const std::chrono::time_point<std::chrono::steady_clock> current = std::chrono::steady_clock::now();
auto delta = std::chrono::duration<float>(current - previousProcessTick);
for (Node* node : nodeList) {
node->physicsProcess(0.00f);
node->physicsProcess(delta.count());
}
//this.previousPhysicsProcessTick = watch.peek.total!"msecs" / 1_000;
previousProcessTick = std::chrono::steady_clock::now();
}
void Engine::drawNodes() {
// TODO
TODO("check if this works")
for (Node* node : nodeList) {
if (Drawable* drawNode = (Drawable*)&node) {
drawNode->draw(renderer);
}
}
}
const char* Engine::getEngineVersion() { return HIBIS_VERSION; }

View file

@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include <chrono>
#include "../renderer/renderer.hpp"
#include "../callback.hpp"
@ -22,8 +23,8 @@ namespace hibis {
private:
Renderer* renderer;
//StopWatch watch;
float previousProcessTick;
float previousPhysicsProcessTick;
std::chrono::time_point<std::chrono::steady_clock> previousProcessTick;
std::chrono::time_point<std::chrono::steady_clock> previousPhysicsProcessTick;
std::vector<Node*> nodeList;
LoggerCallback loggerCallback;

View file

@ -4,6 +4,7 @@
namespace hibis {
class Drawable {
public:
virtual void draw(Renderer* renderer) = 0;
};
}

View file

@ -1,7 +0,0 @@
#pragma once
#include "resource.hpp"
namespace hibis {
class Image : Resource {};
}

View file

@ -0,0 +1,11 @@
#pragma once
#include "resource.hpp"
#include <pragmautil.hpp>
namespace hibis {
TODO("Make this function")
class Texture : Resource {
void* data;
};
}

View file

@ -1,3 +1,9 @@
#pragma once
// TODO: pragma
#define PRAGMA(x) _Pragma(#x)
#define MESSAGE(x) PRAGMA(message(x))
#define TODO(x) PRAGMA(message("TODO: " x))
#define WARNING(x) PRAGMA(GCC warning(x))
#define ERROR(x) PRAGMA(GCC error(x))

View file

@ -3,8 +3,7 @@
#include <fmt/format.h>
#include "font.hpp"
namespace hibis {
namespace rsdl {
namespace hibis::rsdl {
Font::Font(std::string path, uint size) {
this->size = size;
this->path = path;
@ -31,4 +30,3 @@ namespace hibis {
}
}
}
}

View file

@ -5,8 +5,7 @@
#include <SDL2/SDL_ttf.h>
namespace hibis {
namespace rsdl {
namespace hibis::rsdl {
class Font : public Resource {
public:
Font(std::string path, uint size);
@ -27,4 +26,3 @@ namespace hibis {
bool didReload = false;
};
}
}

View file

@ -6,8 +6,7 @@
#include <pragmautil.hpp>
namespace hibis {
namespace rsdl {
namespace hibis::rsdl {
RSDL::RSDL(std::string title, IntVec2 size, LoggerCallback callback) {
logger = callback;
@ -60,6 +59,7 @@ namespace hibis {
}
void RSDL::drawText(Resource* resource, std::string text, IntVec2 pos, Color color) {
WARNING("tulip what the hell is this, this sucks.\nAvoid remaking textures every time text has to be drawn")
if (Font* font = (Font*)resource) {
SDL_Surface* textSurface = TTF_RenderText_Solid(font->loadedFont, text.c_str(), SDL_Color {color.r, color.g, color.b, color.a });
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
@ -93,6 +93,7 @@ namespace hibis {
}
}
void RSDL::setWindowTitle(std::string title) {}
void RSDL::setWindowTitle(std::string title) {
SDL_SetWindowTitle(window, title.c_str());
}
}

View file

@ -9,8 +9,7 @@
#include <math/types.hpp>
#include <renderer/renderer.hpp>
namespace hibis {
namespace rsdl {
namespace hibis::rsdl {
/** \class RSDL
* Renderer implementation using SDL2 Renderer for the Hibis game engine
*/
@ -20,7 +19,7 @@ namespace hibis {
~RSDL();
void clearScreen(Color col = Color {0, 0, 0, 1});
void clearScreen(Color col = Color {0, 0, 0, 255});
void renderCurrent();
@ -40,4 +39,3 @@ namespace hibis {
LoggerCallback logger;
};
}
}

View file

@ -11,6 +11,12 @@
#include <engine/engine.hpp>
#include <pragmautil.hpp>
#if defined(_MSC_VER) || defined(_MSC_FULL_VER)
WARNING("Please avoid using MSVC in C++ projects utilising std::chrono due to frame timing issues")
#endif
using namespace hibis;
using namespace hibis::rsdl;
@ -34,7 +40,7 @@ void logger(LoggingSeverity severity, std::string message) {
break;
}
std::cout << fmt::format("[{}]: {}", severity, message) << std::endl;
std::cout << fmt::format("[{}]: {}", sevString, message) << std::endl;
}
int main() {