added a tilesystem, please look at it lol and make it more efficient in drawing so it draws whats needed.

This commit is contained in:
nosch
2025-09-01 20:52:19 +02:00
parent 8ac12f71cc
commit 29c8801ada
2 changed files with 137 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
#ifndef TILEBASE_HPP
#define TILEBASE_HPP
#include "../render/textures.hpp"
#include <unordered_map>
#include <vector>
#include <array>
// Forward declarations
struct Chunk;
struct Layer;
struct Map;
struct Tile {
ID id;
ID spriteid;
int animationframe;
std::vector<int> inventory;
Chunk* owner; // pointer instead of reference
void Draw();
void Update(float deltatime);
Tile(ID Id, ID spriteId, Chunk* owner);
Tile(); // default constructor (needed for containers)
};
struct Chunk {
raylib::Vector2 position;
Tile tiles[64]; // dynamic instead of fixed array
Layer* owner;
void Draw();
Chunk(Layer* Owner);
Chunk(); // default constructor
};
struct Vector2Hash {
std::size_t operator()(const Vector2& v) const noexcept;
};
struct Vector2Eq {
bool operator()(const Vector2& a, const Vector2& b) const noexcept;
};
struct Layer {
std::unordered_map<Vector2, Chunk, Vector2Hash, Vector2Eq> chunks;
ID id;
bool DEBUG;
Map* owner;
void Draw();
Layer(ID Id, Map* Owner);
Layer(); // default constructor
};
struct Map {
std::array<Layer, 4> layers; // ground/water/void/decoration
int worldtime;
bool DEBUG;
Map();
void Draw();
};
#endif // !TILEBASE_HPP