Completely reorganize file structure, delete unused imports,

clean all imports, surpress useless CLion warnings, clean code
master
aurailus 2019-01-22 17:08:06 -08:00
parent 5ebf737f20
commit 4346f45c1c
84 changed files with 352 additions and 301 deletions

View File

@ -2,6 +2,9 @@
<project version="4"> <project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration"> <component name="CidrRootsConfiguration">
<sourceRoots>
<file path="$PROJECT_DIR$/zeus" />
</sourceRoots>
<excludeRoots> <excludeRoots>
<file path="$PROJECT_DIR$/Libraries" /> <file path="$PROJECT_DIR$/Libraries" />
<file path="$PROJECT_DIR$/lib" /> <file path="$PROJECT_DIR$/lib" />

View File

@ -18,80 +18,80 @@ link_directories(lib/glew/lib)
add_executable(zeus add_executable(zeus
zeus/Main.cpp zeus/Main.cpp
zeus/engine/graphics/Mesh.cpp zeus/client/engine/graphics/Mesh.cpp
zeus/engine/graphics/Mesh.h zeus/client/engine/graphics/Mesh.h
zeus/engine/PerlinNoise.cpp zeus/generic/helpers/PerlinNoise.cpp
zeus/engine/PerlinNoise.h zeus/generic/helpers/PerlinNoise.h
zeus/engine/Entity.cpp zeus/client/engine/Entity.cpp
zeus/engine/Entity.h zeus/client/engine/Entity.h
zeus/engine/graphics/Shader.cpp zeus/client/engine/graphics/Shader.cpp
zeus/engine/graphics/Shader.h zeus/client/engine/graphics/Shader.h
zeus/engine/Window.cpp zeus/client/engine/Window.cpp
zeus/engine/Window.h zeus/client/engine/Window.h
zeus/engine/Camera.cpp zeus/client/engine/Camera.cpp
zeus/engine/Camera.h zeus/client/engine/Camera.h
zeus/engine/graphics/Texture.cpp zeus/client/engine/graphics/Texture.cpp
zeus/engine/graphics/Texture.h zeus/client/engine/graphics/Texture.h
zeus/mesh/MeshGenerator.cpp zeus/client/graphics/mesh/MeshGenerator.cpp
zeus/mesh/MeshGenerator.h zeus/client/graphics/mesh/MeshGenerator.h
zeus/engine/Timer.cpp zeus/client/engine/Timer.cpp
zeus/engine/Timer.h zeus/client/engine/Timer.h
zeus/blocks/BlockAtlas.cpp zeus/generic/blocks/BlockAtlas.cpp
zeus/blocks/BlockAtlas.h zeus/generic/blocks/BlockAtlas.h
zeus/blocks/BlockDef.cpp zeus/generic/blocks/BlockDef.cpp
zeus/blocks/BlockDef.h zeus/generic/blocks/BlockDef.h
zeus/mesh/MeshPart.cpp zeus/generic/blocks/MeshPart.cpp
zeus/mesh/MeshPart.h zeus/generic/blocks/MeshPart.h
zeus/mesh/MeshMod.h zeus/generic/blocks/MeshMod.h
zeus/mesh/Vertex.cpp zeus/client/graphics/mesh/Vertex.cpp
zeus/mesh/Vertex.h zeus/client/graphics/mesh/Vertex.h
zeus/mesh/BlockModel.cpp zeus/generic/blocks/BlockModel.cpp
zeus/mesh/BlockModel.h zeus/generic/blocks/BlockModel.h
zeus/engine/TextureAtlas.cpp zeus/generic/blocks/TextureAtlas.cpp
zeus/engine/TextureAtlas.h zeus/generic/blocks/TextureAtlas.h
zeus/game/world/World.cpp zeus/client/gameworld/World.cpp
zeus/game/world/World.h zeus/client/gameworld/World.h
zeus/blocks/BlockChunk.cpp zeus/generic/blocks/BlockChunk.cpp
zeus/blocks/BlockChunk.h zeus/generic/blocks/BlockChunk.h
zeus/engine/helpers/ArrayTrans3D.h zeus/generic/helpers/ArrayTrans3D.h
zeus/mesh/MeshChunk.cpp zeus/client/graphics/mesh/MeshChunk.cpp
zeus/mesh/MeshChunk.h zeus/client/graphics/mesh/MeshChunk.h
zeus/game/GameScene.cpp zeus/client/graphics/scene/GameScene.cpp
zeus/game/GameScene.h zeus/client/graphics/scene/GameScene.h
zeus/engine/graphics/Renderer.cpp zeus/client/engine/graphics/Renderer.cpp
zeus/engine/graphics/Renderer.h zeus/client/engine/graphics/Renderer.h
zeus/lua_api/LuaParser.cpp zeus/client/lua/LuaParser.cpp
zeus/lua_api/LuaParser.h zeus/client/lua/LuaParser.h
zeus/lua_api/l_register_block.cpp zeus/client/lua/l_register_block.cpp
zeus/lua_api/l_register_block.h zeus/client/lua/l_register_block.h
zeus/engine/graphics/TextBuilder.cpp zeus/client/engine/graphics/TextBuilder.cpp
zeus/engine/graphics/TextBuilder.h zeus/client/engine/graphics/TextBuilder.h
zeus/engine/graphics/TextBuilder.cpp zeus/client/engine/graphics/TextBuilder.cpp
zeus/engine/graphics/HudText.cpp zeus/client/engine/graphics/HudText.cpp
zeus/engine/graphics/HudText.h zeus/client/engine/graphics/HudText.h
zeus/game/gui/DebugGui.cpp zeus/client/graphics/gui/DebugGui.cpp
zeus/game/gui/DebugGui.h zeus/client/graphics/gui/DebugGui.h
zeus/game/world/Player.cpp zeus/client/gameworld/Player.cpp
zeus/game/world/Player.h zeus/client/gameworld/Player.h
zeus/engine/Ray.cpp zeus/client/engine/Ray.cpp
zeus/engine/Ray.h zeus/client/engine/Ray.h
zeus/lua_api/l_register_blockmodel.cpp zeus/client/lua/l_register_blockmodel.cpp
zeus/lua_api/l_register_blockmodel.h zeus/client/lua/l_register_blockmodel.h
zeus/lua_api/LuaApi.cpp zeus/client/lua/LuaApi.cpp
zeus/lua_api/LuaApi.h zeus/client/lua/LuaApi.h
zeus/client/Client.cpp zeus/client/Client.cpp
zeus/client/Client.h zeus/client/Client.h
zeus/client/SceneManager.cpp zeus/client/engine/scene/SceneManager.cpp
zeus/client/SceneManager.h zeus/client/engine/scene/SceneManager.h
zeus/client/Scene.h zeus/client/engine/scene/Scene.h
zeus/client/ClientState.h zeus/client/ClientState.h
zeus/game/MenuScene.cpp zeus/client/graphics/scene/MenuScene.cpp
zeus/game/MenuScene.h zeus/client/graphics/scene/MenuScene.h
zeus/server/Server.cpp zeus/server/Server.cpp
zeus/server/Server.h zeus/server/Server.h
zeus/server/ClientConnection.cpp zeus/server/network/ClientConnection.cpp
zeus/server/ClientConnection.h zeus/server/network/ClientConnection.h
zeus/server/Packet.cpp zeus/generic/network/Packet.cpp
zeus/server/Packet.h zeus/server/ServerPlayer.cpp zeus/server/ServerPlayer.h zeus/client/ServerConnection.cpp zeus/client/ServerConnection.h) zeus/generic/network/Packet.h zeus/server/ServerPlayer.cpp zeus/server/ServerPlayer.h zeus/client/network/ServerConnection.cpp zeus/client/network/ServerConnection.h zeus/client/gameworld/WorldThreadDefs.cpp zeus/client/gameworld/WorldThreadDefs.h)
target_link_libraries(zeus ${OPENGL_gl_LIBRARY} glfw libGLEW.so pthread lua dl) target_link_libraries(zeus ${OPENGL_gl_LIBRARY} glfw libGLEW.so pthread lua dl)

View File

@ -331,7 +331,7 @@ zeus.register_blockmodel("default:block_side_foliage", {
**Block Creation** **Block Creation**
The function zeus.register_block creates a block in the game. The function zeus.register_block creates a block in the scene.
The first argument is the name of the block, which should be prefixed by the mod name and a colon. The first argument is the name of the block, which should be prefixed by the mod name and a colon.
The next argument is a table of properties. These are the following accepted properties: The next argument is a table of properties. These are the following accepted properties:

View File

@ -4,6 +4,7 @@
#pragma clang diagnostic pop #pragma clang diagnostic pop
#include "client/Client.h" #include "client/Client.h"
#include "server/Server.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
std::string start = "client"; std::string start = "client";

View File

@ -2,11 +2,11 @@
// Created by aurailus on 06/01/19. // Created by aurailus on 06/01/19.
// //
//TODO: Move the forking code to main
#include <zconf.h> #include <zconf.h>
#include <signal.h> #include <signal.h>
#include "Client.h" #include "Client.h"
#include "../server/Packet.h"
#include <asio.hpp>
using asio::ip::udp; using asio::ip::udp;

View File

@ -5,12 +5,14 @@
#ifndef ZEUS_CLIENT_H #ifndef ZEUS_CLIENT_H
#define ZEUS_CLIENT_H #define ZEUS_CLIENT_H
#include "../engine/graphics/Renderer.h" #include "engine/graphics/Renderer.h"
#include "../engine/Timer.h"
#include "SceneManager.h"
#include "ClientState.h" #include "ClientState.h"
#include "../game/GameScene.h" #include "engine/scene/SceneManager.h"
#include "../game/MenuScene.h"
#include "graphics/scene/GameScene.h"
#include "graphics/scene/MenuScene.h"
#include "engine/Timer.h"
class Client { class Client {
public: public:

View File

@ -5,8 +5,7 @@
#ifndef ZEUS_CLIENTSTATE_H #ifndef ZEUS_CLIENTSTATE_H
#define ZEUS_CLIENTSTATE_H #define ZEUS_CLIENTSTATE_H
#include "engine/graphics/Renderer.h"
#include "../engine/graphics/Renderer.h"
struct ClientState { struct ClientState {
Renderer* renderer; Renderer* renderer;

View File

@ -2,7 +2,6 @@
// Created by aurailus on 25/11/18. // Created by aurailus on 25/11/18.
// //
#include <iostream>
#include "Entity.h" #include "Entity.h"
Entity::Entity() { Entity::Entity() {

View File

@ -7,6 +7,7 @@
#include <glm.hpp> #include <glm.hpp>
#include <gtc/matrix_transform.hpp> #include <gtc/matrix_transform.hpp>
#include <iostream>
#include "graphics/Mesh.h" #include "graphics/Mesh.h"
#include "graphics/Texture.h" #include "graphics/Texture.h"

View File

@ -8,7 +8,8 @@
#include <vec3.hpp> #include <vec3.hpp>
#include <cmath> #include <cmath>
#include <glm.hpp> #include <glm.hpp>
#include "../game/world/Player.h"
#include "../gameworld/Player.h"
class Ray { class Ray {
public: public:

View File

@ -2,7 +2,6 @@
// Created by aurailus on 26/11/18. // Created by aurailus on 26/11/18.
// //
#include <cstdio>
#include "Window.h" #include "Window.h"
Window::Window() : Window(800, 600) {}; Window::Window() : Window(800, 600) {};

View File

@ -7,6 +7,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <cstdio>
class Window { class Window {
public: public:

View File

@ -5,7 +5,6 @@
// //
#include "HudText.h" #include "HudText.h"
#include "TextBuilder.h"
HudText::HudText() = default; HudText::HudText() = default;

View File

@ -7,6 +7,7 @@
#include "../Entity.h" #include "../Entity.h"
#include "TextBuilder.h"
class HudText : public Entity { class HudText : public Entity {
public: public:

View File

@ -6,7 +6,6 @@
#define GLPROJECT_MESH_H #define GLPROJECT_MESH_H
#include <GL/glew.h> #include <GL/glew.h>
#include <iostream>
#include <vector> #include <vector>
class Mesh { class Mesh {

View File

@ -9,6 +9,7 @@
#include "../Window.h" #include "../Window.h"
#include "../Camera.h" #include "../Camera.h"
#include "../Entity.h" #include "../Entity.h"
#include <ext.hpp> #include <ext.hpp>
class Renderer { class Renderer {

View File

@ -2,7 +2,6 @@
// Created by aurailus on 26/11/18. // Created by aurailus on 26/11/18.
// //
#include <cstring>
#include "Shader.h" #include "Shader.h"
Shader::Shader() { Shader::Shader() {

View File

@ -5,12 +5,13 @@
#ifndef GLPROJECT_SHADER_H #ifndef GLPROJECT_SHADER_H
#define GLPROJECT_SHADER_H #define GLPROJECT_SHADER_H
#include <string>
#include <iostream>
#include <fstream>
#include <GL/glew.h> #include <GL/glew.h>
#include <string>
#include <cstring>
#include <fstream>
#include <iostream>
class Shader { class Shader {
public: public:
Shader(); Shader();

View File

@ -2,6 +2,9 @@
// Created by aurailus on 25/12/18. // Created by aurailus on 25/12/18.
// //
#pragma clang diagnostic push
#pragma ide diagnostic ignored "bugprone-integer-division"
#include "TextBuilder.h" #include "TextBuilder.h"
Mesh* TextBuilder::build(std::string text) { Mesh* TextBuilder::build(std::string text) {
@ -56,3 +59,4 @@ Mesh* TextBuilder::build(std::string text) {
return m; return m;
} }
#pragma clang diagnostic pop

View File

@ -5,7 +5,7 @@
#ifndef ZEUS_TEXTBUILDER_H #ifndef ZEUS_TEXTBUILDER_H
#define ZEUS_TEXTBUILDER_H #define ZEUS_TEXTBUILDER_H
#include <string>
#include "Mesh.h" #include "Mesh.h"
class TextBuilder { class TextBuilder {

View File

@ -2,7 +2,6 @@
// Created by aurailus on 29/11/18. // Created by aurailus on 29/11/18.
// //
#include <iostream>
#include "Texture.h" #include "Texture.h"
Texture::Texture() = default; Texture::Texture() = default;

View File

@ -6,6 +6,7 @@
#define GLPROJECT_TEXTURE_H #define GLPROJECT_TEXTURE_H
#include <glew.h> #include <glew.h>
#include <iostream>
#include <stb_image.h> #include <stb_image.h>
class Texture { class Texture {

View File

@ -5,7 +5,8 @@
#ifndef ZEUS_SCENE_H #ifndef ZEUS_SCENE_H
#define ZEUS_SCENE_H #define ZEUS_SCENE_H
#include "ClientState.h" #include "../../ClientState.h"
#include <iostream>
class Scene { class Scene {
public: public:

View File

@ -5,9 +5,7 @@
#ifndef ZEUS_SCENEMANAGER_H #ifndef ZEUS_SCENEMANAGER_H
#define ZEUS_SCENEMANAGER_H #define ZEUS_SCENEMANAGER_H
#include "Scene.h" #include "Scene.h"
#include "ClientState.h"
class SceneManager { class SceneManager {
public: public:

View File

@ -2,9 +2,7 @@
// Created by aurailus on 28/12/18. // Created by aurailus on 28/12/18.
// //
#include <iostream>
#include "Player.h" #include "Player.h"
#include "../../engine/Timer.h"
Player::Player() { Player::Player() {
pos = glm::vec3(0, 0, 0); pos = glm::vec3(0, 0, 0);

View File

@ -6,8 +6,11 @@
#define ZEUS_PLAYER_H #define ZEUS_PLAYER_H
#include "../../engine/Camera.h" #include <iostream>
#include "World.h" #include "World.h"
#include "../engine/Camera.h"
#include "../engine/Timer.h"
class Player { class Player {
public: public:

View File

@ -6,8 +6,6 @@
#pragma clang diagnostic ignored "-Wmissing-noreturn" #pragma clang diagnostic ignored "-Wmissing-noreturn"
#include "World.h" #include "World.h"
#include "../../engine/PerlinNoise.h"
#include "../../engine/helpers/ArrayTrans3D.h"
World::World(BlockAtlas *atlas) { World::World(BlockAtlas *atlas) {
blockAtlas = atlas; blockAtlas = atlas;
@ -119,15 +117,8 @@ std::vector<bool>* World::getAdjacentsCull(glm::vec3 pos) {
} }
void World::update() { void World::update() {
Timer world("World update");
//Create / Finalize BlockChunks
handleChunkGenQueue(); handleChunkGenQueue();
//Create / Finalize MeshChunks
handleMeshGenQueue(); handleMeshGenQueue();
// game.printElapsedMs();
} }
int World::getBlock(glm::vec3 pos) { int World::getBlock(glm::vec3 pos) {
@ -209,7 +200,7 @@ void World::handleChunkGenQueue() {
//Function that runs on each ChunkGenThread in the chunk generation threadpool. //Function that runs on each ChunkGenThread in the chunk generation threadpool.
//Takes a threadDef object which contains a vector of tasks to do, and infinitely loops, completing tasks and //Takes a threadDef object which contains a vector of tasks to do, and infinitely loops, completing tasks and
//re-inserting them into the vector to be further manipulated by the main thread. //re-inserting them into the vector to be further manipulated by the main thread.
void World::chunkGenThread(World::ChunkThreadDef* threadDef) { void World::chunkGenThread(ChunkThreadDef* threadDef) {
PerlinNoise p(9); PerlinNoise p(9);
PerlinNoise p2(9); PerlinNoise p2(9);
@ -219,7 +210,7 @@ void World::chunkGenThread(World::ChunkThreadDef* threadDef) {
lock.lock(); lock.lock();
//Find the first unfinished task //Find the first unfinished task
World::ChunkThreadData* data = nullptr; ChunkThreadData* data = nullptr;
for (auto iter = threadDef->tasks.begin(); iter != threadDef->tasks.end(); ) { for (auto iter = threadDef->tasks.begin(); iter != threadDef->tasks.end(); ) {
if (!(*iter)->done) { if (!(*iter)->done) {
data = (*iter); data = (*iter);
@ -276,7 +267,7 @@ void World::chunkGenThread(World::ChunkThreadDef* threadDef) {
lock.unlock(); lock.unlock();
} }
this_thread::sleep_for(0.5ms); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
} }
@ -347,7 +338,7 @@ void World::meshGenThread(MeshThreadDef* threadDef) {
lock.lock(); lock.lock();
//Find the first unfinished task //Find the first unfinished task
World::MeshThreadData* data = nullptr; MeshThreadData* data = nullptr;
for (auto iter = threadDef->tasks.begin(); iter != threadDef->tasks.end(); ) { for (auto iter = threadDef->tasks.begin(); iter != threadDef->tasks.end(); ) {
if (!(*iter)->done) { if (!(*iter)->done) {
data = (*iter); data = (*iter);
@ -368,63 +359,10 @@ void World::meshGenThread(MeshThreadDef* threadDef) {
lock.unlock(); lock.unlock();
} }
this_thread::sleep_for(0.5ms); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
} }
std::unordered_map<glm::vec3, MeshChunk*, World::vec3cmp>* World::getMeshChunks() { std::unordered_map<glm::vec3, MeshChunk*, World::vec3cmp>* World::getMeshChunks() {
return &meshChunks; return &meshChunks;
} }
//Constructors and Destructors for the MeshThreadData / ChunkThreadData structs.
World::ChunkThreadData::ChunkThreadData(glm::vec3 pos, BlockAtlas *atlas) {
this->pos = pos;
this->atlas = atlas;
this->done = false;
this->chunk = nullptr;
}
World::ChunkThreadDef::ChunkThreadDef() {
thread = new std::thread(chunkGenThread, this);
sched_param sch_params{};
sch_params.sched_priority = 1;
pthread_setschedparam(thread->native_handle(), SCHED_RR, &sch_params);
thread->detach();
}
World::ChunkThreadDef::~ChunkThreadDef() {
delete thread;
}
World::MeshThreadData::MeshThreadData(glm::vec3 pos, BlockChunk *chunk, std::vector<bool>* adjacents, BlockAtlas *atlas) {
this->pos = pos;
this->chunk = chunk;
this->atlas = atlas;
this->adjacents = adjacents;
this->done = false;
this->vertices = new std::vector<float>();
this->indices = new std::vector<unsigned int>();
}
World::MeshThreadData::~MeshThreadData() {
delete vertices;
delete indices;
delete adjacents;
}
World::MeshThreadDef::MeshThreadDef() {
thread = new std::thread(meshGenThread, this);
sched_param sch_params{};
sch_params.sched_priority = 1;
pthread_setschedparam(thread->native_handle(), SCHED_RR, &sch_params);
thread->detach();
}
World::MeshThreadDef::~MeshThreadDef() {
delete thread;
}

View File

@ -5,25 +5,22 @@
#ifndef GLPROJECT_WORLD_H #ifndef GLPROJECT_WORLD_H
#define GLPROJECT_WORLD_H #define GLPROJECT_WORLD_H
#include <unordered_set>
#include <iostream> #include <iostream>
#include <gtc/type_ptr.hpp> #include <unordered_set>
#include <vec3.hpp>
#include <thread>
#include <bits/unordered_map.h> #include <bits/unordered_map.h>
#include <thread>
#include <mutex> #include <mutex>
#include <vec3.hpp>
#include <gtc/type_ptr.hpp>
#include "../../blocks/BlockChunk.h" #include "WorldThreadDefs.h"
#include "../../mesh/MeshChunk.h" #include "../../generic/helpers/PerlinNoise.h"
#include "../../blocks/BlockAtlas.h" #include "../../generic/helpers/ArrayTrans3D.h"
#include "../../generic/blocks/BlockAtlas.h"
#include "../../generic/blocks/BlockChunk.h"
#include "../graphics/mesh/MeshChunk.h"
class World { class World {
private:
//Predeclare structs
struct MeshThreadData;
struct MeshThreadDef;
struct ChunkThreadData;
struct ChunkThreadDef;
public: public:
//Hashing function for glm::vec3 in maps and lists //Hashing function for glm::vec3 in maps and lists
struct vec3cmp { struct vec3cmp {
@ -63,7 +60,7 @@ public:
} }
static glm::vec3 chunkVec(glm::vec3 globalVec) { static glm::vec3 chunkVec(glm::vec3 globalVec) {
return glm::vec3(floor(globalVec.x / 16), floor(globalVec.y / 16), floor(globalVec.z / 16)); return glm::vec3(std::floor(globalVec.x / 16), std::floor(globalVec.y / 16), std::floor(globalVec.z / 16));
} }
static glm::vec3 localVec(glm::vec3 globalVec) { static glm::vec3 localVec(glm::vec3 globalVec) {
@ -113,53 +110,6 @@ private:
std::vector<MeshThreadData*> finishedMesh; std::vector<MeshThreadData*> finishedMesh;
BlockAtlas* blockAtlas; BlockAtlas* blockAtlas;
//Structs for the thread pool implementations
struct MeshThreadData {
MeshThreadData(glm::vec3 pos, BlockChunk* chunk, std::vector<bool>* adjacents, BlockAtlas* atlas);
glm::vec3 pos;
BlockChunk* chunk;
BlockAtlas* atlas;
std::vector<bool>* adjacents;
bool done;
std::vector<float>* vertices;
std::vector<unsigned int>* indices;
~MeshThreadData();
};
struct MeshThreadDef {
MeshThreadDef();
std::thread* thread;
std::mutex lock;
std::vector<MeshThreadData*> tasks;
~MeshThreadDef();
};
struct ChunkThreadData {
ChunkThreadData(glm::vec3 pos, BlockAtlas* atlas);
glm::vec3 pos;
BlockAtlas* atlas;
bool done;
BlockChunk* chunk;
};
struct ChunkThreadDef {
ChunkThreadDef();
std::thread* thread;
std::mutex lock;
std::vector<ChunkThreadData*> tasks;
~ChunkThreadDef();
};
}; };
#endif //GLPROJECT_WORLD_H #endif //GLPROJECT_WORLD_H

View File

@ -0,0 +1,57 @@
//
// Created by aurailus on 22/01/19.
//
#include "WorldThreadDefs.h"
#include "World.h"
ChunkThreadData::ChunkThreadData(glm::vec3 pos, BlockAtlas *atlas) {
this->pos = pos;
this->atlas = atlas;
this->done = false;
this->chunk = nullptr;
}
ChunkThreadDef::ChunkThreadDef() {
thread = new std::thread(World::chunkGenThread, this);
sched_param sch_params{};
sch_params.sched_priority = 1;
pthread_setschedparam(thread->native_handle(), SCHED_RR, &sch_params);
thread->detach();
}
ChunkThreadDef::~ChunkThreadDef() {
delete thread;
}
MeshThreadData::MeshThreadData(glm::vec3 pos, BlockChunk *chunk, std::vector<bool>* adjacents, BlockAtlas *atlas) {
this->pos = pos;
this->chunk = chunk;
this->atlas = atlas;
this->adjacents = adjacents;
this->done = false;
this->vertices = new std::vector<float>();
this->indices = new std::vector<unsigned int>();
}
MeshThreadData::~MeshThreadData() {
delete vertices;
delete indices;
delete adjacents;
}
MeshThreadDef::MeshThreadDef() {
thread = new std::thread(World::meshGenThread, this);
sched_param sch_params{};
sch_params.sched_priority = 1;
pthread_setschedparam(thread->native_handle(), SCHED_RR, &sch_params);
thread->detach();
}
MeshThreadDef::~MeshThreadDef() {
delete thread;
}

View File

@ -0,0 +1,64 @@
//
// Created by aurailus on 22/01/19.
//
#ifndef ZEUS_WORLDTHREADDEFS_H
#define ZEUS_WORLDTHREADDEFS_H
#include <vec3.hpp>
#include <thread>
#include <mutex>
#include "../../generic/blocks/BlockChunk.h"
#include "../../generic/blocks/BlockAtlas.h"
//Structs for storing the threads used in World, and passing data to and from them.
struct MeshThreadData {
MeshThreadData(glm::vec3 pos, BlockChunk* chunk, std::vector<bool>* adjacents, BlockAtlas* atlas);
glm::vec3 pos;
BlockChunk* chunk;
BlockAtlas* atlas;
std::vector<bool>* adjacents;
bool done;
std::vector<float>* vertices;
std::vector<unsigned int>* indices;
~MeshThreadData();
};
struct MeshThreadDef {
MeshThreadDef();
std::thread* thread;
std::mutex lock;
std::vector<MeshThreadData*> tasks;
~MeshThreadDef();
};
struct ChunkThreadData {
ChunkThreadData(glm::vec3 pos, BlockAtlas* atlas);
glm::vec3 pos;
BlockAtlas* atlas;
bool done;
BlockChunk* chunk;
};
struct ChunkThreadDef {
ChunkThreadDef();
std::thread* thread;
std::mutex lock;
std::vector<ChunkThreadData*> tasks;
~ChunkThreadDef();
};
#endif //ZEUS_WORLDTHREADDEFS_H

View File

@ -48,7 +48,7 @@ void DebugGui::fpsHistUpdate() {
for (double num : fpsHistory) { for (double num : fpsHistory) {
float h = (float)num * height; float h = (float)num * height;
float sev = round(9 - (float)max(60 - num, 0.0)/6) / 10.0f; float sev = (float)std::round(9 - std::max(60 - num, 0.0)/6) / 10.0f;
auto columnVerts = std::vector<float> { auto columnVerts = std::vector<float> {
xOffset, -h, 0, sev , sev, 0, 0, 0, xOffset, -h, 0, sev , sev, 0, 0, 0,
@ -125,6 +125,7 @@ void DebugGui::update(Player* player, World* world, Window* window, BlockAtlas*
fpsText->set(string_double(fps) + " FPS"); fpsText->set(string_double(fps) + " FPS");
fpsHistUpdate(); fpsHistUpdate();
using namespace std; //Temporary, delete when refactoring this
playerText->set( playerText->set(
"Chunk: " + to_string(world->lastGenUpdates) + ", Mesh: " + to_string(world->lastMeshUpdates) + "\n" + "Chunk: " + to_string(world->lastGenUpdates) + ", Mesh: " + to_string(world->lastMeshUpdates) + "\n" +
"W: " + to_string((int)player->getPos()->x) + "," + to_string((int)player->getPos()->y) + "," + to_string((int)player->getPos()->z) + "\n" + "W: " + to_string((int)player->getPos()->x) + "," + to_string((int)player->getPos()->y) + "," + to_string((int)player->getPos()->z) + "\n" +

View File

@ -6,10 +6,9 @@
#define ZEUS_DEBUGGUI_H #define ZEUS_DEBUGGUI_H
#include "../../engine/graphics/HudText.h" #include "../../engine/graphics/HudText.h"
#include "../world/World.h"
#include "../world/Player.h"
#include "../../engine/Window.h" #include "../../engine/Window.h"
#include "../../engine/Ray.h" #include "../../engine/Ray.h"
#include <sstream> #include <sstream>
class DebugGui { class DebugGui {

View File

@ -6,8 +6,7 @@
#define GLPROJECT_MESHCHUNK_H #define GLPROJECT_MESHCHUNK_H
#include "../blocks/BlockChunk.h" #include "../../engine/Entity.h"
#include "../engine/Entity.h"
#include "MeshGenerator.h" #include "MeshGenerator.h"
class MeshChunk : public Entity { class MeshChunk : public Entity {

View File

@ -3,7 +3,6 @@
// //
#include "MeshGenerator.h" #include "MeshGenerator.h"
#include "../engine/helpers/ArrayTrans3D.h"
MeshGenerator::MeshGenerator() { MeshGenerator::MeshGenerator() {
indOffset = 0; indOffset = 0;

View File

@ -2,18 +2,25 @@
// Created by aurailus on 01/12/18. // Created by aurailus on 01/12/18.
// //
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#ifndef GLPROJECT_MESHGENERATOR_H #ifndef GLPROJECT_MESHGENERATOR_H
#define GLPROJECT_MESHGENERATOR_H #define GLPROJECT_MESHGENERATOR_H
#define GLM_ENABLE_EXPERIMENTAL #define GLM_ENABLE_EXPERIMENTAL
#include "BlockModel.h"
#include <vector>
#include <gtx/normal.hpp> #include <gtx/normal.hpp>
#include <vector>
#include <cstdio> #include <cstdio>
#include "../engine/Timer.h"
#include "../blocks/BlockAtlas.h" #include "../../engine/Timer.h"
#include "../blocks/BlockChunk.h" #include "../../../generic/blocks/BlockDef.h"
#include "../../../generic/blocks/BlockChunk.h"
#include "../../../generic/blocks/BlockAtlas.h"
#include "../../../generic/helpers/ArrayTrans3D.h"
#include "../../../generic/blocks/BlockModel.h"
#include "Vertex.h"
const int CHUNK_SIZE = 16; const int CHUNK_SIZE = 16;
@ -33,3 +40,5 @@ private:
}; };
#endif //GLPROJECT_MESHGENERATOR_H #endif //GLPROJECT_MESHGENERATOR_H
#pragma clang diagnostic pop

View File

@ -3,8 +3,10 @@
// //
#include "GameScene.h" #include "GameScene.h"
#include "../lua_api/l_register_block.h"
#include "../lua_api/l_register_blockmodel.h" //TODO: Fix this
#include "../../lua/l_register_block.h"
#include "../../lua/l_register_blockmodel.h"
GameScene::GameScene(ClientState* state) : Scene(state) { GameScene::GameScene(ClientState* state) : Scene(state) {
server = new ServerConnection("127.0.0.1", 12345); server = new ServerConnection("127.0.0.1", 12345);
@ -22,7 +24,7 @@ GameScene::GameScene(ClientState* state) : Scene(state) {
p.doFile("../lua/file.lua"); p.doFile("../lua/file.lua");
//The game requires the blockAtlas for meshing and handling inputs. //The scene requires the blockAtlas for meshing and handling inputs.
world = new World(blockAtlas); world = new World(blockAtlas);
int SIZE = 12; int SIZE = 12;

View File

@ -6,20 +6,19 @@
#define SRC_GAMEWORLD_H #define SRC_GAMEWORLD_H
#include "world/World.h" #include "../../engine/scene/Scene.h"
#include "../engine/Camera.h" #include "../../engine/graphics/Renderer.h"
#include "../engine/Window.h" #include "../gui/DebugGui.h"
#include "../engine/PerlinNoise.h"
#include "../engine/graphics/Renderer.h" #include "../../lua/LuaParser.h"
#include "../engine/helpers/ArrayTrans3D.h"
#include "../lua_api/LuaParser.h" #include "../../gameworld/World.h"
#include "../engine/graphics/HudText.h" #include "../../gameworld/Player.h"
#include "gui/DebugGui.h"
#include "world/Player.h" #include "../../network/ServerConnection.h"
#include "../engine/Ray.h"
#include "../client/Scene.h" #include "../../../generic/blocks/TextureAtlas.h"
#include "../server/Server.h" #include "../../../generic/blocks/BlockAtlas.h"
#include "../client/ServerConnection.h"
class GameScene : public Scene { class GameScene : public Scene {
public: public:
@ -37,7 +36,7 @@ public:
TextureAtlas* textureAtlas; TextureAtlas* textureAtlas;
BlockAtlas* blockAtlas; BlockAtlas* blockAtlas;
//Entities to be drawn with world shaders //Entities to be drawn with gameworld shaders
std::vector<Entity*> entities; std::vector<Entity*> entities;
//GUI Related things //GUI Related things

View File

@ -3,7 +3,6 @@
// //
#include "MenuScene.h" #include "MenuScene.h"
#include "../engine/graphics/HudText.h"
MenuScene::MenuScene(ClientState *state) : Scene(state) { MenuScene::MenuScene(ClientState *state) : Scene(state) {
fontTexture = new Texture((char*)"../tex/gui/font.png"); fontTexture = new Texture((char*)"../tex/gui/font.png");

View File

@ -6,8 +6,9 @@
#define ZEUS_MENUSCENE_H #define ZEUS_MENUSCENE_H
#include "../client/ClientState.h" #include "../../ClientState.h"
#include "../client/Scene.h" #include "../../engine/scene/Scene.h"
#include "../../engine/graphics/HudText.h"
class MenuScene : public Scene { class MenuScene : public Scene {
public: public:

View File

@ -5,9 +5,8 @@
#ifndef ZEUS_LUAAPI_H #ifndef ZEUS_LUAAPI_H
#define ZEUS_LUAAPI_H #define ZEUS_LUAAPI_H
#include "../game/GameScene.h"
#include "LuaParser.h" #include "LuaParser.h"
#include "../graphics/scene/GameScene.h"
class LuaApi { class LuaApi {
public: public:

View File

@ -2,13 +2,8 @@
// Created by aurailus on 17/12/18. // Created by aurailus on 17/12/18.
// //
#include <iostream>
#include "LuaParser.h" #include "LuaParser.h"
//double LuaParser::average(int a, int b, int c) {
// return (a + b + c) / (double)(3);
//}
void LuaParser::init() { void LuaParser::init() {
L.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string); L.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string);

View File

@ -5,11 +5,9 @@
#ifndef ZEUS_LUAPARSER_H #ifndef ZEUS_LUAPARSER_H
#define ZEUS_LUAPARSER_H #define ZEUS_LUAPARSER_H
//Should give tracebacks if there's a segfault
//#define SOL_CHECK_ARGUMENTS
#include <string> #include <string>
#include <sol.hpp> #include <sol.hpp>
#include <iostream>
class LuaParser { class LuaParser {
public: public:

View File

@ -4,7 +4,7 @@
#include "l_register_block.h" #include "l_register_block.h"
//Add a block to the game. //Add a block to the scene.
//The first variable is the identifer, which is used internally and by mods to reference the block. //The first variable is the identifer, which is used internally and by mods to reference the block.
//The second variable is a table containing all the block's data. This is used to define properties of the nodeblock. //The second variable is a table containing all the block's data. This is used to define properties of the nodeblock.
void l_register_block::api(std::string identifier, sol::table data) { void l_register_block::api(std::string identifier, sol::table data) {

View File

@ -6,10 +6,12 @@
#define ZEUS_SERVERCONNECTION_H #define ZEUS_SERVERCONNECTION_H
#include <string> #include <string>
#include <iostream>
#include <vec3.hpp> #include <vec3.hpp>
#include <asio.hpp> #include <asio.hpp>
#include "../../generic/network/Packet.h"
#include "../engine/Timer.h" #include "../engine/Timer.h"
#include "../server/Packet.h"
struct ServerConfig { struct ServerConfig {
glm::vec3 playerPos; glm::vec3 playerPos;

View File

@ -4,6 +4,10 @@
#include "BlockAtlas.h" #include "BlockAtlas.h"
BlockAtlas::BlockAtlas() {
textureAtlas = nullptr;
}
BlockAtlas::BlockAtlas(TextureAtlas *textureAtlas) { BlockAtlas::BlockAtlas(TextureAtlas *textureAtlas) {
this->textureAtlas = textureAtlas; this->textureAtlas = textureAtlas;
} }

View File

@ -6,12 +6,13 @@
#define GLPROJECT_BLOCKATLAS_H #define GLPROJECT_BLOCKATLAS_H
#include "../mesh/BlockModel.h" #include <vector>
#include "BlockDef.h" #include "BlockDef.h"
#include "TextureAtlas.h"
class BlockAtlas { class BlockAtlas {
public: public:
BlockAtlas() = default; BlockAtlas();
explicit BlockAtlas(TextureAtlas* textureAtlas); explicit BlockAtlas(TextureAtlas* textureAtlas);
void registerBlock(BlockDef* def); void registerBlock(BlockDef* def);

View File

@ -2,9 +2,7 @@
// Created by aurailus on 14/12/18. // Created by aurailus on 14/12/18.
// //
#include <iostream>
#include "BlockChunk.h" #include "BlockChunk.h"
#include "../engine/helpers/ArrayTrans3D.h"
BlockChunk::BlockChunk(std::vector<int>* blocks) { BlockChunk::BlockChunk(std::vector<int>* blocks) {
this->blocks = blocks; this->blocks = blocks;

View File

@ -7,6 +7,8 @@
#include <vec3.hpp> #include <vec3.hpp>
#include <vector> #include <vector>
#include <iostream>
#include "../helpers/ArrayTrans3D.h"
class BlockChunk { class BlockChunk {
public: public:

View File

@ -1,5 +1,3 @@
#include <utility>
// //
// Created by aurailus on 02/12/18. // Created by aurailus on 02/12/18.
// //

View File

@ -5,7 +5,8 @@
#ifndef GLPROJECT_BLOCKDEF_H #ifndef GLPROJECT_BLOCKDEF_H
#define GLPROJECT_BLOCKDEF_H #define GLPROJECT_BLOCKDEF_H
#include "../mesh/BlockModel.h" #include <string>
#include "BlockModel.h"
class BlockDef { class BlockDef {

View File

@ -2,7 +2,6 @@
// Created by aurailus on 04/12/18. // Created by aurailus on 04/12/18.
// //
#include <utility>
#include "BlockModel.h" #include "BlockModel.h"
BlockModel::BlockModel(bool culls, bool visible) { BlockModel::BlockModel(bool culls, bool visible) {

View File

@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include <sol.hpp> #include <sol.hpp>
#include "MeshPart.h" #include "MeshPart.h"
#include "../../client/graphics/mesh/Vertex.h"
using namespace std; //Just to preserve my sanity using namespace std; //Just to preserve my sanity

View File

@ -2,17 +2,21 @@
// Created by aurailus on 02/12/18. // Created by aurailus on 02/12/18.
// //
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#ifndef GLPROJECT_MESHPART_H #ifndef GLPROJECT_MESHPART_H
#define GLPROJECT_MESHPART_H #define GLPROJECT_MESHPART_H
#define GLM_ENABLE_EXPERIMENTAL #define GLM_ENABLE_EXPERIMENTAL
#include <vector>
#include <vec4.hpp> #include <vec4.hpp>
#include <gtx/normal.hpp> #include <gtx/normal.hpp>
#include <vector>
#include "MeshMod.h" #include "MeshMod.h"
#include "Vertex.h" #include "TextureAtlas.h"
#include "../engine/TextureAtlas.h" #include "../../client/graphics/mesh/Vertex.h"
class MeshVertexIter; class MeshVertexIter;
class MeshIndexIter; class MeshIndexIter;
@ -67,3 +71,5 @@ private:
#endif //GLPROJECT_MESHPART_H #endif //GLPROJECT_MESHPART_H
#pragma clang diagnostic pop

View File

@ -2,6 +2,9 @@
// Created by aurailus on 06/12/18. // Created by aurailus on 06/12/18.
// //
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define CUTE_FILES_IMPLEMENTATION #define CUTE_FILES_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION
@ -146,3 +149,4 @@ glm::vec4* TextureAtlas::getUVs(std::string* texture) {
} }
return &textures.at(*texture); return &textures.at(*texture);
} }
#pragma clang diagnostic pop

View File

@ -7,11 +7,11 @@
#include <glew.h> #include <glew.h>
#include <iostream> #include <iostream>
#include <list>
#include <vec4.hpp> #include <vec4.hpp>
#include <list>
#include <map> #include <map>
#include "graphics/Texture.h" #include "../../client/engine/graphics/Texture.h"
class TextureAtlas { class TextureAtlas {
public: public:

View File

@ -2,6 +2,9 @@
// Created by aurailus on 14/12/18. // Created by aurailus on 14/12/18.
// //
#pragma clang diagnostic push
#pragma ide diagnostic ignored "bugprone-integer-division"
#ifndef GLPROJECT_ARRAYTRANS3D_H #ifndef GLPROJECT_ARRAYTRANS3D_H
#define GLPROJECT_ARRAYTRANS3D_H #define GLPROJECT_ARRAYTRANS3D_H
@ -37,3 +40,5 @@ public:
#endif //GLPROJECT_ARRAYTRANS3D_H #endif //GLPROJECT_ARRAYTRANS3D_H
#pragma clang diagnostic pop

View File

@ -1,15 +1,13 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#include "PerlinNoise.h" #include "PerlinNoise.h"
#include <cmath>
#include <random>
#include <algorithm>
#include <numeric>
// THIS IS A DIRECT TRANSLATION TO C++11 FROM THE REFERENCE // THIS IS A DIRECT TRANSLATION TO C++11 FROM THE REFERENCE
// JAVA IMPLEMENTATION OF THE IMPROVED PERLIN FUNCTION (see http://mrl.nyu.edu/~perlin/noise/) // JAVA IMPLEMENTATION OF THE IMPROVED PERLIN FUNCTION (see http://mrl.nyu.edu/~perlin/noise/)
// THE ORIGINAL JAVA IMPLEMENTATION IS COPYRIGHT 2002 KEN PERLIN // THE ORIGINAL JAVA IMPLEMENTATION IS COPYRIGHT 2002 KEN PERLIN
// I ADDED AN EXTRA METHOD THAT GENERATES A NEW PERMUTATION VECTOR (THIS IS NOT PRESENT IN THE ORIGINAL IMPLEMENTATION) // I ADDED AN EXTRA METHOD THAT GENERATES A NEW PERMUTATION VECTOR (THIS IS NOT PRESENT IN THE ORIGINAL IMPLEMENTATION)
// Initialize with the reference values for the permutation vector // Initialize with the reference values for the permutation vector
PerlinNoise::PerlinNoise() { PerlinNoise::PerlinNoise() {
@ -92,3 +90,5 @@ double PerlinNoise::grad(int hash, double x, double y, double z) {
v = h < 4 ? y : h == 12 || h == 14 ? x : z; v = h < 4 ? y : h == 12 || h == 14 ? x : z;
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
} }
#pragma clang diagnostic pop

View File

@ -1,3 +1,6 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
// THIS CLASS IS A TRANSLATION TO C++11 FROM THE REFERENCE // THIS CLASS IS A TRANSLATION TO C++11 FROM THE REFERENCE
// JAVA IMPLEMENTATION OF THE IMPROVED PERLIN FUNCTION (see http://mrl.nyu.edu/~perlin/noise/) // JAVA IMPLEMENTATION OF THE IMPROVED PERLIN FUNCTION (see http://mrl.nyu.edu/~perlin/noise/)
@ -8,6 +11,10 @@
#define PERLINNOISE_H #define PERLINNOISE_H
#include <vector> #include <vector>
#include <cmath>
#include <random>
#include <algorithm>
#include <numeric>
class PerlinNoise { class PerlinNoise {
// The permutation vector // The permutation vector
@ -16,7 +23,7 @@ public:
// Initialize with the reference values for the permutation vector // Initialize with the reference values for the permutation vector
PerlinNoise(); PerlinNoise();
// Generate a new permutation vector based on the value of seed // Generate a new permutation vector based on the value of seed
PerlinNoise(unsigned int seed); explicit PerlinNoise(unsigned int seed);
// Get a noise value, for 2D images z can have any value // Get a noise value, for 2D images z can have any value
double noise(double x, double y, double z); double noise(double x, double y, double z);
private: private:
@ -26,3 +33,5 @@ private:
}; };
#endif #endif
#pragma clang diagnostic pop

View File

@ -2,7 +2,6 @@
// Created by aurailus on 10/01/19. // Created by aurailus on 10/01/19.
// //
#include <iostream>
#include "Packet.h" #include "Packet.h"
Packet::Packet(Packet::PacketType p) { Packet::Packet(Packet::PacketType p) {

View File

@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <asio.hpp> #include <asio.hpp>
#include <iostream>
class Packet { class Packet {
public: public:

View File

@ -3,7 +3,6 @@
// //
#include "Server.h" #include "Server.h"
#include "../game/world/Player.h"
Server::Server() = default; Server::Server() = default;

View File

@ -7,12 +7,12 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "../engine/Timer.h"
#include "ClientConnection.h"
#include "Packet.h"
#include "ServerPlayer.h"
#include <iostream> #include <iostream>
#include <asio.hpp> #include <asio.hpp>
#include "ServerPlayer.h"
#include "network/ClientConnection.h"
#include "../generic/network/Packet.h"
#include "../client/engine/Timer.h"
using asio::ip::udp; using asio::ip::udp;

View File

@ -4,6 +4,10 @@
#include "ServerPlayer.h" #include "ServerPlayer.h"
ServerPlayer::ServerPlayer() {
this->connection = nullptr;
}
ServerPlayer::ServerPlayer(ClientConnection *connection, glm::vec3 pos) { ServerPlayer::ServerPlayer(ClientConnection *connection, glm::vec3 pos) {
this->pos = pos; this->pos = pos;
this->connection = connection; this->connection = connection;

View File

@ -7,15 +7,15 @@
#include <vec3.hpp> #include <vec3.hpp>
#include "ClientConnection.h" #include "network/ClientConnection.h"
class ServerPlayer { class ServerPlayer {
public: public:
ServerPlayer() = default; ServerPlayer();
ServerPlayer(ClientConnection* connection, glm::vec3 pos); ServerPlayer(ClientConnection* connection, glm::vec3 pos);
ClientConnection* connection; ClientConnection* connection;
glm::vec3 pos; glm::vec3 pos = glm::vec3(0, 0, 0);
std::vector<glm::vec3> requestedChunks; std::vector<glm::vec3> requestedChunks;
}; };

View File

@ -5,7 +5,6 @@
#ifndef ZEUS_CLIENTCONNECTION_H #ifndef ZEUS_CLIENTCONNECTION_H
#define ZEUS_CLIENTCONNECTION_H #define ZEUS_CLIENTCONNECTION_H
#include <asio.hpp> #include <asio.hpp>
class ClientConnection { class ClientConnection {