Some refactor
This commit is contained in:
parent
123f3ae6ff
commit
4ceba017c7
@ -8,6 +8,7 @@ RM := rm -rf
|
|||||||
|
|
||||||
# All of the sources participating in the build are defined here
|
# All of the sources participating in the build are defined here
|
||||||
-include sources.mk
|
-include sources.mk
|
||||||
|
-include src/world/subdir.mk
|
||||||
-include src/window/subdir.mk
|
-include src/window/subdir.mk
|
||||||
-include src/voxels/subdir.mk
|
-include src/voxels/subdir.mk
|
||||||
-include src/physics/subdir.mk
|
-include src/physics/subdir.mk
|
||||||
|
|||||||
@ -33,4 +33,5 @@ src/objects \
|
|||||||
src/physics \
|
src/physics \
|
||||||
src/voxels \
|
src/voxels \
|
||||||
src/window \
|
src/window \
|
||||||
|
src/world \
|
||||||
|
|
||||||
|
|||||||
24
Debug/src/world/subdir.mk
Normal file
24
Debug/src/world/subdir.mk
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
################################################################################
|
||||||
|
# Automatically-generated file. Do not edit!
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
|
CPP_SRCS += \
|
||||||
|
../src/world/World.cpp
|
||||||
|
|
||||||
|
OBJS += \
|
||||||
|
./src/world/World.o
|
||||||
|
|
||||||
|
CPP_DEPS += \
|
||||||
|
./src/world/World.d
|
||||||
|
|
||||||
|
|
||||||
|
# Each subdirectory must supply rules for building sources it contributes
|
||||||
|
src/world/%.o: ../src/world/%.cpp src/world/subdir.mk
|
||||||
|
@echo 'Building file: $<'
|
||||||
|
@echo 'Invoking: Cross G++ Compiler'
|
||||||
|
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
||||||
|
@echo 'Finished building: $<'
|
||||||
|
@echo ' '
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ float bytes2Float(char* srcs, unsigned int offset){
|
|||||||
return *(float*)(&value);
|
return *(float*)(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldFiles::WorldFiles(const char* directory, size_t mainBufferCapacity) : directory(directory){
|
WorldFiles::WorldFiles(std::string directory, size_t mainBufferCapacity) : directory(directory){
|
||||||
mainBufferIn = new char[CHUNK_VOL*2];
|
mainBufferIn = new char[CHUNK_VOL*2];
|
||||||
mainBufferOut = new char[mainBufferCapacity];
|
mainBufferOut = new char[mainBufferCapacity];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public:
|
|||||||
char* mainBufferIn;
|
char* mainBufferIn;
|
||||||
char* mainBufferOut;
|
char* mainBufferOut;
|
||||||
|
|
||||||
WorldFiles(const char* directory, size_t mainBufferCapacity);
|
WorldFiles(std::string directory, size_t mainBufferCapacity);
|
||||||
~WorldFiles();
|
~WorldFiles();
|
||||||
|
|
||||||
void put(const char* chunkData, int x, int y);
|
void put(const char* chunkData, int x, int y);
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "../physics/Hitbox.h"
|
#include "../physics/Hitbox.h"
|
||||||
|
#include "../physics/PhysicsSolver.h"
|
||||||
|
#include "../voxels/Chunks.h"
|
||||||
|
#include "../window/Events.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
class Camera;
|
class Camera;
|
||||||
class Hitbox;
|
class Hitbox;
|
||||||
|
class PhysicsSolver;
|
||||||
|
class Chunks;
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -41,6 +41,7 @@ using namespace glm;
|
|||||||
#include "lighting/Lighting.h"
|
#include "lighting/Lighting.h"
|
||||||
#include "physics/Hitbox.h"
|
#include "physics/Hitbox.h"
|
||||||
#include "physics/PhysicsSolver.h"
|
#include "physics/PhysicsSolver.h"
|
||||||
|
#include "world/World.h"
|
||||||
|
|
||||||
#include "audio/Audio.h"
|
#include "audio/Audio.h"
|
||||||
#include "audio/audioutil.h"
|
#include "audio/audioutil.h"
|
||||||
@ -49,10 +50,18 @@ using namespace glm;
|
|||||||
|
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
#include "world_render.h"
|
#include "world_render.h"
|
||||||
|
#include "player_control.h"
|
||||||
|
|
||||||
|
|
||||||
|
int WIDTH = 1280;
|
||||||
|
int HEIGHT = 720;
|
||||||
|
|
||||||
|
|
||||||
// Save all world data to files
|
// Save all world data to files
|
||||||
void write_world(WorldFiles* wfile, Chunks* chunks){
|
void write_world(World* world){
|
||||||
|
WorldFiles* wfile = world->wfile;
|
||||||
|
Chunks* chunks = world->chunks;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < chunks->volume; i++){
|
for (unsigned int i = 0; i < chunks->volume; i++){
|
||||||
Chunk* chunk = chunks->chunks[i];
|
Chunk* chunk = chunks->chunks[i];
|
||||||
if (chunk == nullptr)
|
if (chunk == nullptr)
|
||||||
@ -63,17 +72,6 @@ void write_world(WorldFiles* wfile, Chunks* chunks){
|
|||||||
wfile->write();
|
wfile->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deleting world data from memory
|
|
||||||
void close_world(WorldFiles* wfile, Chunks* chunks){
|
|
||||||
delete chunks;
|
|
||||||
delete wfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WIDTH = 1280;
|
|
||||||
int HEIGHT = 720;
|
|
||||||
|
|
||||||
#include "player_control.h"
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
setup_definitions();
|
setup_definitions();
|
||||||
@ -93,13 +91,13 @@ int main() {
|
|||||||
}
|
}
|
||||||
std::cout << "-- loading world" << std::endl;
|
std::cout << "-- loading world" << std::endl;
|
||||||
|
|
||||||
Camera *camera = new Camera(vec3(-320,255,32), radians(90.0f));
|
Camera* camera = new Camera(vec3(-320,255,32), radians(90.0f));
|
||||||
WorldFiles *wfile = new WorldFiles("world/", REGION_VOL * (CHUNK_VOL * 2 + 8));
|
World* world = new World("world-1", "world/", new Chunks(34,1,34, 0,0,0));
|
||||||
Chunks *chunks = new Chunks(34,1,34, 0,0,0);
|
Chunks* chunks = world->chunks;
|
||||||
|
|
||||||
|
|
||||||
Player* player = new Player(vec3(camera->position), 4.0f, camera);
|
Player* player = new Player(vec3(camera->position), 4.0f, camera);
|
||||||
wfile->readPlayer(player);
|
world->wfile->readPlayer(player);
|
||||||
camera->rotation = mat4(1.0f);
|
camera->rotation = mat4(1.0f);
|
||||||
camera->rotate(player->camY, player->camX, 0);
|
camera->rotate(player->camY, player->camX, 0);
|
||||||
|
|
||||||
@ -142,24 +140,24 @@ int main() {
|
|||||||
update_controls(&physics, chunks, player, delta);
|
update_controls(&physics, chunks, player, delta);
|
||||||
update_interaction(chunks, &physics, player, &lighting, lineBatch);
|
update_interaction(chunks, &physics, player, &lighting, lineBatch);
|
||||||
|
|
||||||
chunks->setCenter(wfile, camera->position.x,0,camera->position.z);
|
chunks->setCenter(world->wfile, camera->position.x,0,camera->position.z);
|
||||||
chunksController._buildMeshes(&renderer, frame);
|
chunksController._buildMeshes(&renderer, frame);
|
||||||
|
|
||||||
int freeLoaders = chunksController.countFreeLoaders();
|
int freeLoaders = chunksController.countFreeLoaders();
|
||||||
for (int i = 0; i < freeLoaders; i++)
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
chunksController.loadVisible(wfile);
|
chunksController.loadVisible(world->wfile);
|
||||||
|
|
||||||
draw_world(player, camera, assets, chunks, occlusion);
|
draw_world(player, camera, assets, world, occlusion);
|
||||||
draw_hud(player, assets, chunks, devdata, fps);
|
draw_hud(player, assets, world, devdata, fps);
|
||||||
|
|
||||||
Window::swapBuffers();
|
Window::swapBuffers();
|
||||||
Events::pullEvents();
|
Events::pullEvents();
|
||||||
}
|
}
|
||||||
std::cout << "-- saving world" << std::endl;
|
std::cout << "-- saving world" << std::endl;
|
||||||
|
|
||||||
wfile->writePlayer(player);
|
world->wfile->writePlayer(player);
|
||||||
write_world(wfile, chunks);
|
write_world(world);
|
||||||
close_world(wfile, chunks);
|
delete world;
|
||||||
|
|
||||||
std::cout << "-- shutting down" << std::endl;
|
std::cout << "-- shutting down" << std::endl;
|
||||||
|
|
||||||
|
|||||||
13
src/world/World.cpp
Normal file
13
src/world/World.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
#include "../files/WorldFiles.h"
|
||||||
|
#include "../voxels/Chunk.h"
|
||||||
|
#include "../voxels/Chunks.h"
|
||||||
|
|
||||||
|
World::World(std::string name, std::string directory, Chunks* chunks) : name(name), chunks(chunks) {
|
||||||
|
wfile = new WorldFiles(directory, REGION_VOL * (CHUNK_VOL * 2 + 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
World::~World(){
|
||||||
|
delete wfile;
|
||||||
|
}
|
||||||
19
src/world/World.h
Normal file
19
src/world/World.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef WORLD_WORLD_H_
|
||||||
|
#define WORLD_WORLD_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class WorldFiles;
|
||||||
|
class Chunks;
|
||||||
|
|
||||||
|
class World {
|
||||||
|
public:
|
||||||
|
std::string name;
|
||||||
|
WorldFiles* wfile;
|
||||||
|
Chunks* chunks;
|
||||||
|
|
||||||
|
World(std::string name, std::string directory, Chunks* chunks);
|
||||||
|
~World();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* WORLD_WORLD_H_ */
|
||||||
@ -110,7 +110,9 @@ bool chunks_comparator(size_t i, size_t j) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void draw_hud(Player* player, Assets* assets, Chunks* chunks, bool devdata, int fps){
|
void draw_hud(Player* player, Assets* assets, World* world, bool devdata, int fps){
|
||||||
|
Chunks* chunks = world->chunks;
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
Shader* uishader = assets->getShader("ui");
|
Shader* uishader = assets->getShader("ui");
|
||||||
@ -141,7 +143,9 @@ void draw_hud(Player* player, Assets* assets, Chunks* chunks, bool devdata, int
|
|||||||
batch->render();
|
batch->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_world(Player* player, Camera* camera, Assets* assets, Chunks* chunks, bool occlusion){
|
void draw_world(Player* player, Camera* camera, Assets* assets, World* world, bool occlusion){
|
||||||
|
Chunks* chunks = world->chunks;
|
||||||
|
|
||||||
glClearColor(0.7f,0.81f,1.0f,1);
|
glClearColor(0.7f,0.81f,1.0f,1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user