Minor refactor
This commit is contained in:
@@ -147,7 +147,7 @@ Panel* create_new_world_panel(Engine* engine, PagesControl* menu) {
|
|||||||
auto folder = paths->getWorldsFolder()/u8path(nameutf8);
|
auto folder = paths->getWorldsFolder()/u8path(nameutf8);
|
||||||
std::filesystem::create_directories(folder);
|
std::filesystem::create_directories(folder);
|
||||||
World* world = new World(nameutf8, folder, seed, settings);
|
World* world = new World(nameutf8, folder, seed, settings);
|
||||||
auto screen = new LevelScreen(engine, world->load(settings, engine->getContent()));
|
auto screen = new LevelScreen(engine, world->create(settings, engine->getContent()));
|
||||||
engine->setScreen(shared_ptr<Screen>(screen));
|
engine->setScreen(shared_ptr<Screen>(screen));
|
||||||
});
|
});
|
||||||
panel->add(button);
|
panel->add(button);
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ void BlocksRenderer::blockCubeShaded(const ivec3& icoord,
|
|||||||
const vec3& offset,
|
const vec3& offset,
|
||||||
const vec3& size,
|
const vec3& size,
|
||||||
const UVRegion(&texfaces)[6],
|
const UVRegion(&texfaces)[6],
|
||||||
const Block* block, ubyte states) {
|
const Block* block, ubyte rotation) {
|
||||||
|
|
||||||
ivec3 X(1, 0, 0);
|
ivec3 X(1, 0, 0);
|
||||||
ivec3 Y(0, 1, 0);
|
ivec3 Y(0, 1, 0);
|
||||||
@@ -244,7 +244,7 @@ void BlocksRenderer::blockCubeShaded(const ivec3& icoord,
|
|||||||
ivec3 coord = icoord;
|
ivec3 coord = icoord;
|
||||||
if (block->rotatable) {
|
if (block->rotatable) {
|
||||||
auto& rotations = block->rotations;
|
auto& rotations = block->rotations;
|
||||||
auto& orient = rotations.variants[states & BLOCK_ROT_MASK];
|
auto& orient = rotations.variants[rotation];
|
||||||
X = orient.axisX;
|
X = orient.axisX;
|
||||||
Y = orient.axisY;
|
Y = orient.axisY;
|
||||||
Z = orient.axisZ;
|
Z = orient.axisZ;
|
||||||
@@ -411,7 +411,7 @@ void BlocksRenderer::render(const voxel* voxels) {
|
|||||||
|
|
||||||
vec3 size = hitbox.size();
|
vec3 size = hitbox.size();
|
||||||
vec3 off = hitbox.min();
|
vec3 off = hitbox.min();
|
||||||
blockCubeShaded(ivec3(x,y,z), off, size, texfaces, &def, vox.states);
|
blockCubeShaded(ivec3(x,y,z), off, size, texfaces, &def, vox.rotation());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class BlocksRenderer {
|
|||||||
const glm::vec3& size,
|
const glm::vec3& size,
|
||||||
const UVRegion(&faces)[6],
|
const UVRegion(&faces)[6],
|
||||||
const Block* block,
|
const Block* block,
|
||||||
ubyte states);
|
ubyte rotation);
|
||||||
void blockXSprite(int x, int y, int z, const glm::vec3& size, const UVRegion& face1, const UVRegion& face2, float spread);
|
void blockXSprite(int x, int y, int z, const glm::vec3& size, const UVRegion& face1, const UVRegion& face2, float spread);
|
||||||
|
|
||||||
bool isOpenForLight(int x, int y, int z) const;
|
bool isOpenForLight(int x, int y, int z) const;
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ const float FLIGHT_SPEED_MUL = 4.0f;
|
|||||||
const float CHEAT_SPEED_MUL = 5.0f;
|
const float CHEAT_SPEED_MUL = 5.0f;
|
||||||
const float JUMP_FORCE = 8.0f;
|
const float JUMP_FORCE = 8.0f;
|
||||||
|
|
||||||
Player::Player(glm::vec3 position, float speed, Camera* camera) :
|
Player::Player(glm::vec3 position, float speed) :
|
||||||
speed(speed),
|
speed(speed),
|
||||||
camera(camera),
|
|
||||||
choosenBlock(1) {
|
choosenBlock(1) {
|
||||||
|
camera = new Camera(position, glm::radians(90.0f));
|
||||||
hitbox = new Hitbox(position, vec3(0.3f,0.9f,0.3f));
|
hitbox = new Hitbox(position, vec3(0.3f,0.9f,0.3f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public:
|
|||||||
float camX = 0.0f;
|
float camX = 0.0f;
|
||||||
float camY = 0.0f;
|
float camY = 0.0f;
|
||||||
|
|
||||||
Player(glm::vec3 position, float speed, Camera* camera);
|
Player(glm::vec3 position, float speed);
|
||||||
~Player();
|
~Player();
|
||||||
|
|
||||||
void teleport(glm::vec3 position);
|
void teleport(glm::vec3 position);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ const AABB* Chunks::isObstacle(float x, float y, float z){
|
|||||||
const Block* def = contentIds->getBlockDef(v->id);
|
const Block* def = contentIds->getBlockDef(v->id);
|
||||||
if (def->obstacle) {
|
if (def->obstacle) {
|
||||||
const AABB& hitbox = def->rotatable
|
const AABB& hitbox = def->rotatable
|
||||||
? def->rt.hitboxes[v->states & BLOCK_ROT_MASK]
|
? def->rt.hitboxes[v->rotation()]
|
||||||
: def->hitbox;
|
: def->hitbox;
|
||||||
if (def->rt.solid) {
|
if (def->rt.solid) {
|
||||||
return &hitbox;
|
return &hitbox;
|
||||||
@@ -225,7 +225,9 @@ voxel* Chunks::rayCast(vec3 start,
|
|||||||
// TODO: replace this dumb solution with something better
|
// TODO: replace this dumb solution with something better
|
||||||
if (def && !def->rt.solid) {
|
if (def && !def->rt.solid) {
|
||||||
const int gridSize = BLOCK_AABB_GRID * 2;
|
const int gridSize = BLOCK_AABB_GRID * 2;
|
||||||
const AABB& box = def->rotatable ? def->rt.hitboxes[voxel->states & BLOCK_ROT_MASK] : def->hitbox;
|
const AABB& box = def->rotatable
|
||||||
|
? def->rt.hitboxes[voxel->rotation()]
|
||||||
|
: def->hitbox;
|
||||||
const int subs = gridSize;
|
const int subs = gridSize;
|
||||||
iend = vec3(ix, iy, iz);
|
iend = vec3(ix, iy, iz);
|
||||||
end -= iend;
|
end -= iend;
|
||||||
|
|||||||
@@ -43,15 +43,17 @@ void ChunksStorage::remove(int x, int z) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
||||||
|
World* world = level->world;
|
||||||
|
|
||||||
auto chunk = shared_ptr<Chunk>(new Chunk(x, z));
|
auto chunk = shared_ptr<Chunk>(new Chunk(x, z));
|
||||||
store(chunk);
|
store(chunk);
|
||||||
unique_ptr<ubyte> data(level->world->wfile->getChunk(chunk->x, chunk->z));
|
unique_ptr<ubyte> data(world->wfile->getChunk(chunk->x, chunk->z));
|
||||||
if (data) {
|
if (data) {
|
||||||
chunk->decode(data.get());
|
chunk->decode(data.get());
|
||||||
chunk->setLoaded(true);
|
chunk->setLoaded(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
light_t* lights = level->world->wfile->getLights(chunk->x, chunk->z);
|
light_t* lights = world->wfile->getLights(chunk->x, chunk->z);
|
||||||
if (lights) {
|
if (lights) {
|
||||||
chunk->lightmap->set(lights);
|
chunk->lightmap->set(lights);
|
||||||
chunk->setLoadedLights(true);
|
chunk->setLoadedLights(true);
|
||||||
|
|||||||
+2
-2
@@ -19,11 +19,11 @@ struct voxel {
|
|||||||
blockid_t id;
|
blockid_t id;
|
||||||
uint8_t states;
|
uint8_t states;
|
||||||
|
|
||||||
inline uint8_t rotation() {
|
inline uint8_t rotation() const {
|
||||||
return states & BLOCK_ROT_MASK;
|
return states & BLOCK_ROT_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int8_t variant() {
|
inline int8_t variant() const {
|
||||||
return (states & BLOCK_VARIANT_MASK) >> 4;
|
return (states & BLOCK_VARIANT_MASK) >> 4;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+9
-6
@@ -56,17 +56,20 @@ void World::write(Level* level) {
|
|||||||
wfile->writePlayer(level->player);
|
wfile->writePlayer(level->player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float DEF_PLAYER_Y = 100.0f;
|
||||||
|
const float DEF_PLAYER_SPEED = 4.0f;
|
||||||
|
|
||||||
|
Level* World::create(EngineSettings& settings, const Content* content) {
|
||||||
|
Player* player = new Player(vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED);
|
||||||
|
return new Level(this, content, player, settings);
|
||||||
|
}
|
||||||
|
|
||||||
Level* World::load(EngineSettings& settings, const Content* content) {
|
Level* World::load(EngineSettings& settings, const Content* content) {
|
||||||
wfile->readWorldInfo(this);
|
wfile->readWorldInfo(this);
|
||||||
|
|
||||||
vec3 playerPosition = vec3(0, 100, 0);
|
Player* player = new Player(vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED);
|
||||||
Camera* camera = new Camera(playerPosition, glm::radians(90.0f));
|
|
||||||
Player* player = new Player(playerPosition, 4.0f, camera);
|
|
||||||
Level* level = new Level(this, content, player, settings);
|
Level* level = new Level(this, content, player, settings);
|
||||||
|
|
||||||
wfile->readPlayer(player);
|
wfile->readPlayer(player);
|
||||||
|
|
||||||
camera->rotation = glm::mat4(1.0f);
|
|
||||||
camera->rotate(player->camY, player->camX, 0);
|
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,7 @@ public:
|
|||||||
|
|
||||||
void updateTimers(float delta);
|
void updateTimers(float delta);
|
||||||
void write(Level* level);
|
void write(Level* level);
|
||||||
|
Level* create(EngineSettings& settings, const Content* content);
|
||||||
Level* load(EngineSettings& settings, const Content* content);
|
Level* load(EngineSettings& settings, const Content* content);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user