Engine core and assets loading refactor
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "Level.h"
|
||||
#include "World.h"
|
||||
#include "../lighting/Lighting.h"
|
||||
#include "../voxels/Chunks.h"
|
||||
#include "../voxels/ChunksController.h"
|
||||
#include "../player_control.h"
|
||||
#include "../physics/Hitbox.h"
|
||||
#include "../physics/PhysicsSolver.h"
|
||||
#include "../objects/Player.h"
|
||||
|
||||
@@ -24,3 +26,16 @@ Level::~Level(){
|
||||
delete chunksController;
|
||||
delete playerController;
|
||||
}
|
||||
|
||||
void Level::update(float delta, bool interactions) {
|
||||
playerController->update_controls(delta);
|
||||
if (interactions) {
|
||||
playerController->update_interaction();
|
||||
}
|
||||
else
|
||||
{
|
||||
playerController->selectedBlockId = -1;
|
||||
}
|
||||
vec3 position = player->hitbox->position;
|
||||
chunks->setCenter(world->wfile, position.x, position.z);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ public:
|
||||
PlayerController* playerController;
|
||||
Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics);
|
||||
~Level();
|
||||
|
||||
void update(float delta, bool interactions);
|
||||
|
||||
};
|
||||
|
||||
#endif /* WORLD_LEVEL_H_ */
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
#include "../files/WorldFiles.h"
|
||||
#include "../voxels/Chunk.h"
|
||||
#include "../voxels/Chunks.h"
|
||||
#include "Level.h"
|
||||
#include "../objects/Player.h"
|
||||
#include "../physics/PhysicsSolver.h"
|
||||
#include "../window/Camera.h"
|
||||
|
||||
World::World(std::string name, std::string directory, int seed) : name(name), seed(seed) {
|
||||
wfile = new WorldFiles(directory, REGION_VOL * (CHUNK_VOL * 2 + 8));
|
||||
@@ -11,3 +15,27 @@ World::World(std::string name, std::string directory, int seed) : name(name), se
|
||||
World::~World(){
|
||||
delete wfile;
|
||||
}
|
||||
|
||||
void World::write(Level* level) {
|
||||
Chunks* chunks = level->chunks;
|
||||
|
||||
for (unsigned int i = 0; i < chunks->volume; i++) {
|
||||
Chunk* chunk = chunks->chunks[i];
|
||||
if (chunk == nullptr || !chunk->isUnsaved())
|
||||
continue;
|
||||
wfile->put((const char*)chunk->voxels, chunk->x, chunk->z);
|
||||
}
|
||||
|
||||
wfile->write();
|
||||
wfile->writePlayer(level->player);
|
||||
}
|
||||
|
||||
Level* World::loadLevel(Player* player) {
|
||||
Level* level = new Level(this, player, new Chunks(56, 56, 0, 0), new PhysicsSolver(vec3(0, -19.6f, 0)));
|
||||
wfile->readPlayer(player);
|
||||
|
||||
Camera* camera = player->camera;
|
||||
camera->rotation = mat4(1.0f);
|
||||
camera->rotate(player->camY, player->camX, 0);
|
||||
return level;
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
class WorldFiles;
|
||||
class Chunks;
|
||||
class Level;
|
||||
class Player;
|
||||
|
||||
class World {
|
||||
public:
|
||||
@@ -14,6 +16,9 @@ public:
|
||||
|
||||
World(std::string name, std::string directory, int seed);
|
||||
~World();
|
||||
|
||||
void write(Level* level);
|
||||
Level* loadLevel(Player* player);
|
||||
};
|
||||
|
||||
#endif /* WORLD_WORLD_H_ */
|
||||
|
||||
Reference in New Issue
Block a user