Added class Level for runtime world stuff
This commit is contained in:
parent
4ceba017c7
commit
e8ca11894d
@ -4,12 +4,15 @@
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
CPP_SRCS += \
|
||||
../src/world/Level.cpp \
|
||||
../src/world/World.cpp
|
||||
|
||||
OBJS += \
|
||||
./src/world/Level.o \
|
||||
./src/world/World.o
|
||||
|
||||
CPP_DEPS += \
|
||||
./src/world/Level.d \
|
||||
./src/world/World.d
|
||||
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "physics/PhysicsSolver.h"
|
||||
#include "physics/Hitbox.h"
|
||||
#include "lighting/Lighting.h"
|
||||
#include "world/Level.h"
|
||||
#include "voxels/voxel.h"
|
||||
#include "voxels/Chunks.h"
|
||||
#include "window/Camera.h"
|
||||
@ -162,8 +163,11 @@ void update_controls(PhysicsSolver* physics,
|
||||
}
|
||||
}
|
||||
|
||||
void update_interaction(Chunks* chunks, PhysicsSolver* physics, Player* player, Lighting* lighting, LineBatch* lineBatch){
|
||||
void update_interaction(Level* level, LineBatch* lineBatch){
|
||||
Chunks* chunks = level->chunks;
|
||||
Player* player = level->player;
|
||||
Camera* camera = player->camera;
|
||||
Lighting* lighting = level->lighting;
|
||||
vec3 end;
|
||||
vec3 norm;
|
||||
vec3 iend;
|
||||
@ -182,7 +186,7 @@ void update_interaction(Chunks* chunks, PhysicsSolver* physics, Player* player,
|
||||
int x = (int)(iend.x)+(int)(norm.x);
|
||||
int y = (int)(iend.y)+(int)(norm.y);
|
||||
int z = (int)(iend.z)+(int)(norm.z);
|
||||
if (!physics->isBlockInside(x,y,z, player->hitbox)){
|
||||
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
|
||||
chunks->set(x, y, z, player->choosenBlock);
|
||||
lighting->onBlockSet(x,y,z, player->choosenBlock);
|
||||
}
|
||||
|
||||
@ -4,10 +4,10 @@
|
||||
class PhysicsSolver;
|
||||
class Chunks;
|
||||
class Player;
|
||||
class Lighting;
|
||||
class LineBatch;
|
||||
class Level;
|
||||
|
||||
void update_controls(PhysicsSolver* physics, Chunks* chunks, Player* player, float delta);
|
||||
void update_interaction(Chunks* chunks, PhysicsSolver* physics, Player* player, Lighting* lighting, LineBatch* lineBatch);
|
||||
void update_interaction(Level* level, LineBatch* lineBatch);
|
||||
|
||||
#endif /* PLAYER_CONTROL_H_ */
|
||||
|
||||
@ -42,6 +42,7 @@ using namespace glm;
|
||||
#include "physics/Hitbox.h"
|
||||
#include "physics/PhysicsSolver.h"
|
||||
#include "world/World.h"
|
||||
#include "world/Level.h"
|
||||
|
||||
#include "audio/Audio.h"
|
||||
#include "audio/audioutil.h"
|
||||
@ -58,9 +59,9 @@ int HEIGHT = 720;
|
||||
|
||||
|
||||
// Save all world data to files
|
||||
void write_world(World* world){
|
||||
void write_world(World* world, Level* level){
|
||||
WorldFiles* wfile = world->wfile;
|
||||
Chunks* chunks = world->chunks;
|
||||
Chunks* chunks = level->chunks;
|
||||
|
||||
for (unsigned int i = 0; i < chunks->volume; i++){
|
||||
Chunk* chunk = chunks->chunks[i];
|
||||
@ -72,6 +73,18 @@ void write_world(World* world){
|
||||
wfile->write();
|
||||
}
|
||||
|
||||
void update_level(World* world, Level* level, VoxelRenderer* renderer, vec3 position, float delta, long frame){
|
||||
update_controls(level->physics, level->chunks, level->player, delta);
|
||||
update_interaction(level, lineBatch);
|
||||
|
||||
level->chunks->setCenter(world->wfile, position.x,0,position.z);
|
||||
level->chunksController->_buildMeshes(renderer, frame);
|
||||
|
||||
int freeLoaders = level->chunksController->countFreeLoaders();
|
||||
for (int i = 0; i < freeLoaders; i++)
|
||||
level->chunksController->loadVisible(world->wfile);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
setup_definitions();
|
||||
@ -91,12 +104,11 @@ int main() {
|
||||
}
|
||||
std::cout << "-- loading world" << std::endl;
|
||||
|
||||
Camera* camera = new Camera(vec3(-320,255,32), radians(90.0f));
|
||||
World* world = new World("world-1", "world/", new Chunks(34,1,34, 0,0,0));
|
||||
Chunks* chunks = world->chunks;
|
||||
|
||||
|
||||
Camera* camera = new Camera(vec3(-320,200,32), radians(90.0f));
|
||||
World* world = new World("world-1", "world/");
|
||||
Player* player = new Player(vec3(camera->position), 4.0f, camera);
|
||||
Level* level = new Level(player, new Chunks(34,1,34, 0,0,0), new PhysicsSolver(vec3(0, -9.8f*2.0f, 0)));
|
||||
|
||||
world->wfile->readPlayer(player);
|
||||
camera->rotation = mat4(1.0f);
|
||||
camera->rotate(player->camY, player->camX, 0);
|
||||
@ -104,13 +116,9 @@ int main() {
|
||||
std::cout << "-- preparing systems" << std::endl;
|
||||
|
||||
VoxelRenderer renderer(1024*1024);
|
||||
PhysicsSolver physics(vec3(0,-9.8f*2.0f,0));
|
||||
Lighting lighting(chunks);
|
||||
|
||||
init_renderer();
|
||||
|
||||
ChunksController chunksController(chunks, &lighting);
|
||||
|
||||
float lastTime = glfwGetTime();
|
||||
float delta = 0.0f;
|
||||
|
||||
@ -137,18 +145,9 @@ int main() {
|
||||
devdata = !devdata;
|
||||
}
|
||||
|
||||
update_controls(&physics, chunks, player, delta);
|
||||
update_interaction(chunks, &physics, player, &lighting, lineBatch);
|
||||
|
||||
chunks->setCenter(world->wfile, camera->position.x,0,camera->position.z);
|
||||
chunksController._buildMeshes(&renderer, frame);
|
||||
|
||||
int freeLoaders = chunksController.countFreeLoaders();
|
||||
for (int i = 0; i < freeLoaders; i++)
|
||||
chunksController.loadVisible(world->wfile);
|
||||
|
||||
draw_world(player, camera, assets, world, occlusion);
|
||||
draw_hud(player, assets, world, devdata, fps);
|
||||
update_level(world, level, &renderer, camera->position, delta, frame);
|
||||
draw_world(world, level, camera, assets, occlusion);
|
||||
draw_hud(world, level, assets, devdata, fps);
|
||||
|
||||
Window::swapBuffers();
|
||||
Events::pullEvents();
|
||||
@ -156,7 +155,7 @@ int main() {
|
||||
std::cout << "-- saving world" << std::endl;
|
||||
|
||||
world->wfile->writePlayer(player);
|
||||
write_world(world);
|
||||
write_world(world, level);
|
||||
delete world;
|
||||
|
||||
std::cout << "-- shutting down" << std::endl;
|
||||
|
||||
19
src/world/Level.cpp
Normal file
19
src/world/Level.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "Level.h"
|
||||
#include "../lighting/Lighting.h"
|
||||
#include "../voxels/ChunksController.h"
|
||||
|
||||
Level::Level(Player* player, Chunks* chunks, PhysicsSolver* physics) :
|
||||
player(player),
|
||||
chunks(chunks),
|
||||
physics(physics) {
|
||||
lighting = new Lighting(chunks);
|
||||
chunksController = new ChunksController(chunks, lighting);
|
||||
}
|
||||
|
||||
Level::~Level(){
|
||||
delete chunks;
|
||||
delete physics;
|
||||
delete player;
|
||||
delete lighting;
|
||||
delete chunksController;
|
||||
}
|
||||
21
src/world/Level.h
Normal file
21
src/world/Level.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WORLD_LEVEL_H_
|
||||
#define WORLD_LEVEL_H_
|
||||
|
||||
class Player;
|
||||
class Chunks;
|
||||
class Lighting;
|
||||
class PhysicsSolver;
|
||||
class ChunksController;
|
||||
|
||||
class Level {
|
||||
public:
|
||||
Player* player;
|
||||
Chunks* chunks;
|
||||
PhysicsSolver* physics;
|
||||
Lighting* lighting;
|
||||
ChunksController* chunksController;
|
||||
Level(Player* player, Chunks* chunks, PhysicsSolver* physics);
|
||||
~Level();
|
||||
};
|
||||
|
||||
#endif /* WORLD_LEVEL_H_ */
|
||||
@ -4,7 +4,7 @@
|
||||
#include "../voxels/Chunk.h"
|
||||
#include "../voxels/Chunks.h"
|
||||
|
||||
World::World(std::string name, std::string directory, Chunks* chunks) : name(name), chunks(chunks) {
|
||||
World::World(std::string name, std::string directory) : name(name) {
|
||||
wfile = new WorldFiles(directory, REGION_VOL * (CHUNK_VOL * 2 + 8));
|
||||
}
|
||||
|
||||
|
||||
@ -10,9 +10,8 @@ class World {
|
||||
public:
|
||||
std::string name;
|
||||
WorldFiles* wfile;
|
||||
Chunks* chunks;
|
||||
|
||||
World(std::string name, std::string directory, Chunks* chunks);
|
||||
World(std::string name, std::string directory);
|
||||
~World();
|
||||
};
|
||||
|
||||
|
||||
@ -110,8 +110,9 @@ bool chunks_comparator(size_t i, size_t j) {
|
||||
}
|
||||
|
||||
|
||||
void draw_hud(Player* player, Assets* assets, World* world, bool devdata, int fps){
|
||||
Chunks* chunks = world->chunks;
|
||||
void draw_hud(World* world, Level* level, Assets* assets, bool devdata, int fps){
|
||||
Chunks* chunks = level->chunks;
|
||||
Player* player = level->player;
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
@ -143,8 +144,8 @@ void draw_hud(Player* player, Assets* assets, World* world, bool devdata, int fp
|
||||
batch->render();
|
||||
}
|
||||
|
||||
void draw_world(Player* player, Camera* camera, Assets* assets, World* world, bool occlusion){
|
||||
Chunks* chunks = world->chunks;
|
||||
void draw_world(World* world, Level* level, Camera* camera, Assets* assets, bool occlusion){
|
||||
Chunks* chunks = level->chunks;
|
||||
|
||||
glClearColor(0.7f,0.81f,1.0f,1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user