Working on chunks
This commit is contained in:
@ -7,3 +7,10 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Chunk::Chunk() {
|
||||
|
||||
}
|
||||
|
||||
Chunk::~Chunk() {
|
||||
|
||||
}
|
@ -6,9 +6,31 @@
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
#define CHUNK_WIDTH 32
|
||||
#define CHUNK_HEIGHT 32
|
||||
#define CHUNK_DEPTH 8
|
||||
|
||||
namespace Dawn {
|
||||
struct ChunkPosition {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t z;
|
||||
};
|
||||
|
||||
enum class TileID : uint16_t {
|
||||
Null = 0,
|
||||
Test = 1
|
||||
};
|
||||
|
||||
struct Tile {
|
||||
enum TileID id;
|
||||
};
|
||||
|
||||
class Chunk {
|
||||
public:
|
||||
struct ChunkPosition position;
|
||||
struct Tile tiles[CHUNK_WIDTH][CHUNK_HEIGHT][CHUNK_DEPTH];
|
||||
Chunk();
|
||||
~Chunk();
|
||||
};
|
||||
}
|
@ -32,6 +32,35 @@ void Map::onInit() {
|
||||
}
|
||||
|
||||
void Map::onDispose() {
|
||||
this->chunkOrder.clear();
|
||||
}
|
||||
|
||||
void Map::setSize(
|
||||
const uint8_t width,
|
||||
const uint8_t height,
|
||||
const uint8_t depth
|
||||
) {
|
||||
this->mapChunkWidth = width;
|
||||
this->mapChunkHeight = height;
|
||||
this->mapChunkDepth = depth;
|
||||
this->chunks = std::make_unique<Chunk[]>(width * height * depth);
|
||||
|
||||
this->chunkTopLeft.x = 0;
|
||||
this->chunkTopLeft.y = 0;
|
||||
this->chunkTopLeft.z = 0;
|
||||
|
||||
this->chunkOrder.clear();
|
||||
for(uint8_t z = 0; z < depth; z++) {
|
||||
for(uint8_t y = 0; y < height; y++) {
|
||||
for(uint8_t x = 0; x < width; x++) {
|
||||
this->chunkOrder.push_back(&this->chunks[
|
||||
(z * height * width) +
|
||||
(y * width) +
|
||||
x
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<World> Map::getWorld() {
|
||||
|
@ -7,12 +7,18 @@
|
||||
#include "component/world/World.hpp"
|
||||
#include "component/entity/EntityID.hpp"
|
||||
#include "component/entity/EntityTilePosition.hpp"
|
||||
#include "Chunk.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Map : public SceneComponent {
|
||||
private:
|
||||
std::unordered_map<enum EntityID, std::weak_ptr<Entity>> entities;
|
||||
|
||||
uint8_t mapChunkWidth, mapChunkHeight, mapChunkDepth;
|
||||
std::unique_ptr<Chunk[]> chunks;
|
||||
std::vector<Chunk*> chunkOrder;
|
||||
struct ChunkPosition chunkTopLeft;
|
||||
|
||||
/**
|
||||
* Part of the ECS, this function is called when an entity is initialized.
|
||||
*
|
||||
@ -33,6 +39,19 @@ namespace Dawn {
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
|
||||
/**
|
||||
* Sets the size of the map.
|
||||
*
|
||||
* @param width The width of the map.
|
||||
* @param height The height of the map.
|
||||
* @param depth The depth of the map.
|
||||
*/
|
||||
void setSize(
|
||||
const uint8_t width,
|
||||
const uint8_t height,
|
||||
const uint8_t depth
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets the world that this map belongs to.
|
||||
*
|
||||
|
Reference in New Issue
Block a user