Add basic app interface

- Add pool struct for data pools
This commit is contained in:
2026-05-04 15:49:54 +01:00
parent 9e85763f9e
commit 55f4b4d933
9 changed files with 334 additions and 113 deletions
+21 -20
View File
@@ -4,10 +4,6 @@
#include "pch.h"
#include "utils.h"
using ImageID = uint32_t;
using FontID = uint32_t;
using TextID = uint32_t;
struct Font {
TTF_Font *font;
bool pixel_art;
@@ -52,6 +48,12 @@ struct Event {
};
};
struct Animation {
std::vector<int> frames;
float frame_rate;
bool loop;
};
struct Window {
public:
// title can be free'd by the caller after the window is created, as it's copied internally.
@@ -61,19 +63,21 @@ public:
// Rendering functions
ImageID load_image(const char *path, bool pixel_art = false);
void unload_image(ImageID image_id);
int load_image(const char *path, bool pixel_art = false);
void unload_image(int image_id);
Vec2<float> get_image_size(int image_id);
FontID load_font(const char *path, int font_size, bool bold = false, bool italic = false, bool underline = false, bool pixel_art = false);
void unload_font(FontID font_id);
int load_font(const char *path, int font_size, bool bold = false, bool italic = false, bool underline = false, bool pixel_art = false);
void unload_font(int font_id);
// text is copied internally, so it can be free'd by the caller after the text is created.
TextID create_text(FontID font_id, const char *text, uint32_t length, Color color);
void unload_text(TextID text_id);
int create_text(int font_id, const char *text, uint32_t length, Color color);
void unload_text(int text_id);
Vec2<float> get_text_size(int text_id);
bool write(TextID text_id, Vec2<float> position, float z, float angle = 0.0f, Vec2<float> scale = {1.0f, 1.0f});
bool write(int text_id, Vec2<float> position, float z, float angle = 0.0f, Vec2<float> scale = {1.0f, 1.0f});
bool draw(ImageID image_id, Vec2<float> position, float z, float angle = 0.0f, Vec2<float> scale = {1.0f, 1.0f}, float alpha = 1.0f);
bool draw(int image_id, Vec2<float> position, float z, float angle = 0.0f, Vec2<float> scale = {1.0f, 1.0f}, float alpha = 1.0f);
bool draw_rect(Rect rect, Color color, float z, float angle = 0.0f);
@@ -119,16 +123,13 @@ private:
SDL_Texture *white_tex;
// Image pool
std::vector<SDL_Texture *> images;
std::vector<int> free_image_indices;
Pool<SDL_Texture *> image_pool;
// Font pool
std::vector<struct Font> fonts;
std::vector<int> free_font_indices;
Pool<struct Font> font_pool;
// Text pool
std::vector<SDL_Texture *> texts;
std::vector<int> free_text_indices;
Pool<SDL_Texture *> text_pool;
struct RenderInstruction {
enum Type {
@@ -143,13 +144,13 @@ private:
union {
struct {
ImageID image_id;
int image_id;
Vec2<float> position;
float alpha;
} draw_image;
struct {
TextID text_id;
int text_id;
Vec2<float> position;
} draw_text;