Introduced Content, ContentIndices, no more integer ids hardcoded, common refactor

This commit is contained in:
MihailRis
2023-11-21 11:38:59 +03:00
parent f2f9343737
commit 3b03464d27
35 changed files with 472 additions and 279 deletions
+7 -3
View File
@@ -1,6 +1,7 @@
#include "Level.h"
#include "World.h"
#include "LevelEvents.h"
#include "../content/Content.h"
#include "../lighting/Lighting.h"
#include "../voxels/Chunk.h"
#include "../voxels/Chunks.h"
@@ -11,8 +12,10 @@
#include "../objects/Player.h"
#include "../objects/player_control.h"
Level::Level(World* world, Player* player, EngineSettings& settings)
Level::Level(World* world, const Content* content, Player* player, EngineSettings& settings)
: world(world),
content(content),
contentIds(content->indices),
player(player),
chunksStorage(new ChunksStorage(this)),
events(new LevelEvents()) ,
@@ -24,8 +27,9 @@ Level::Level(World* world, Player* player, EngineSettings& settings)
chunks = new Chunks(matrixSize, matrixSize,
0, 0,
world->wfile,
events);
lighting = new Lighting(chunks);
events,
content);
lighting = new Lighting(content, chunks);
chunksController = new ChunksController(this, chunks, lighting,
settings.chunks.padding);
playerController = new PlayerController(this, settings);
+5
View File
@@ -4,6 +4,8 @@
#include "../typedefs.h"
#include "../settings.h"
class Content;
class ContentIndices;
class World;
class Player;
class Chunks;
@@ -17,6 +19,8 @@ class PlayerController;
class Level {
public:
World* world;
const Content* const content;
const ContentIndices* const contentIds;
Player* player;
Chunks* chunks;
ChunksStorage* chunksStorage;
@@ -28,6 +32,7 @@ public:
const EngineSettings& settings;
Level(World* world,
const Content* content,
Player* player,
EngineSettings& settings);
~Level();
+2 -2
View File
@@ -42,7 +42,7 @@ void World::write(Level* level, bool writeChunks) {
wfile->writePlayer(level->player);
}
Level* World::load(EngineSettings& settings) {
Level* World::load(EngineSettings& settings, const Content* content) {
WorldInfo info {name, wfile->directory, seed};
wfile->readWorldInfo(info);
seed = info.seed;
@@ -51,7 +51,7 @@ Level* World::load(EngineSettings& settings) {
vec3 playerPosition = vec3(0, 100, 0);
Camera* camera = new Camera(playerPosition, glm::radians(90.0f));
Player* player = new Player(playerPosition, 4.0f, camera);
Level* level = new Level(this, player, settings);
Level* level = new Level(this, content, player, settings);
wfile->readPlayer(player);
camera->rotation = mat4(1.0f);
+2 -1
View File
@@ -6,6 +6,7 @@
#include "../typedefs.h"
#include "../settings.h"
class Content;
class WorldFiles;
class Chunks;
class Level;
@@ -24,7 +25,7 @@ public:
~World();
void write(Level* level, bool writeChunks);
Level* load(EngineSettings& settings);
Level* load(EngineSettings& settings, const Content* content);
};
#endif /* WORLD_WORLD_H_ */