Moved debug text to DebugGui object, added FPS histogram.
Entities now have Texture field, currently only respected for GuiEntities.master
parent
6406a0350f
commit
9c3aac4789
|
@ -0,0 +1 @@
|
|||
zeus
|
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)
|
|||
project(zeus)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_FLAGS "-s -O3")
|
||||
#set(CMAKE_CXX_FLAGS "-s -O3")
|
||||
|
||||
include_directories(lib/glew/include/GL)
|
||||
include_directories(lib/glfw_linux/include)
|
||||
|
@ -53,11 +53,11 @@ add_executable(zeus
|
|||
zeus/engine/TextureAtlas.h
|
||||
zeus/world/World.cpp
|
||||
zeus/world/World.h
|
||||
zeus/world/BlockChunk.cpp
|
||||
zeus/world/BlockChunk.h
|
||||
zeus/blocks/BlockChunk.cpp
|
||||
zeus/blocks/BlockChunk.h
|
||||
zeus/engine/helpers/ArrayTrans3D.h
|
||||
zeus/world/MeshChunk.cpp
|
||||
zeus/world/MeshChunk.h
|
||||
zeus/mesh/MeshChunk.cpp
|
||||
zeus/mesh/MeshChunk.h
|
||||
zeus/world/GameInstance.cpp
|
||||
zeus/world/GameInstance.h
|
||||
zeus/engine/graphics/Renderer.cpp
|
||||
|
@ -66,10 +66,10 @@ add_executable(zeus
|
|||
zeus/lua_api/LuaParser.h
|
||||
zeus/lua_api/LRegisterBlock.cpp
|
||||
zeus/lua_api/LRegisterBlock.h
|
||||
zeus/mesh/TextBuilder.cpp
|
||||
zeus/mesh/TextBuilder.h
|
||||
zeus/mesh/TextBuilder.cpp
|
||||
zeus/engine/graphics/TextBuilder.cpp
|
||||
zeus/engine/graphics/TextBuilder.h
|
||||
zeus/engine/graphics/TextBuilder.cpp
|
||||
zeus/engine/graphics/HudText.cpp
|
||||
zeus/engine/graphics/HudText.h)
|
||||
zeus/engine/graphics/HudText.h zeus/world/DebugGui.cpp zeus/world/DebugGui.h)
|
||||
|
||||
target_link_libraries(zeus ${OPENGL_gl_LIBRARY} glfw libGLEW.so pthread lua dl)
|
Binary file not shown.
After Width: | Height: | Size: 185 B |
|
@ -13,6 +13,7 @@
|
|||
|
||||
GLfloat deltaTime = 0.0f;
|
||||
GLfloat lastTime = 0.0f;
|
||||
double fps = 0.0;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
Timer boot("Initialization");
|
||||
|
@ -36,18 +37,11 @@ int main(int argc, char* argv[]) {
|
|||
glfwPollEvents();
|
||||
|
||||
//Update game instance
|
||||
game->update(deltaTime);
|
||||
|
||||
game->update(deltaTime, fps);
|
||||
game->draw();
|
||||
|
||||
float fps = 1000 / (t.elapsedNs() / 1000000.0f);
|
||||
std::ostringstream out;
|
||||
out.precision(2);
|
||||
out << std::fixed << fps;
|
||||
std::string s = out.str();
|
||||
|
||||
game->fpsText->set(s + " FPS");
|
||||
}
|
||||
fps = 1000 / (t.elapsedNs() / 1000000.0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -65,11 +65,11 @@ void Camera::mouseControl(double deltaX, double deltaY) {
|
|||
yaw += deltaX;
|
||||
pitch += deltaY;
|
||||
|
||||
if (pitch > 89.0f) {
|
||||
pitch = 89.0f;
|
||||
if (pitch > 90.0f) {
|
||||
pitch = 90.0f;
|
||||
}
|
||||
if (pitch < -89.0f) {
|
||||
pitch = -89.0f;
|
||||
if (pitch < -90.0f) {
|
||||
pitch = -90.0f;
|
||||
}
|
||||
|
||||
update();
|
||||
|
|
|
@ -15,6 +15,19 @@ void Entity::create(Mesh* myMesh) {
|
|||
this->mesh = myMesh;
|
||||
}
|
||||
|
||||
void Entity::create(Mesh* myMesh, Texture* texture) {
|
||||
this->mesh = myMesh;
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
void Entity::setTexture(Texture *texture) {
|
||||
this->texture = texture;
|
||||
};
|
||||
|
||||
Texture* Entity::getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
void Entity::draw() {
|
||||
mesh->draw();
|
||||
}
|
||||
|
@ -63,4 +76,4 @@ glm::mat4 Entity::getModelMatrix() {
|
|||
|
||||
Entity::~Entity() {
|
||||
cleanup();
|
||||
};
|
||||
}
|
|
@ -9,15 +9,20 @@
|
|||
#include <gtc/matrix_transform.hpp>
|
||||
|
||||
#include "graphics/Mesh.h"
|
||||
#include "graphics/Texture.h"
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity();
|
||||
|
||||
void create(Mesh* mesh);
|
||||
void create(Mesh* mesh, Texture* texture);
|
||||
void draw();
|
||||
void cleanup();
|
||||
|
||||
void setTexture(Texture* texture);
|
||||
Texture* getTexture();
|
||||
|
||||
void setPosition(glm::vec3 position);
|
||||
glm::vec3* getPosition();
|
||||
|
||||
|
@ -33,6 +38,7 @@ public:
|
|||
~Entity();
|
||||
protected:
|
||||
Mesh* mesh;
|
||||
Texture* texture;
|
||||
|
||||
glm::vec3 position;
|
||||
glm::vec3 scale;
|
||||
|
|
|
@ -5,9 +5,12 @@
|
|||
//
|
||||
|
||||
#include "HudText.h"
|
||||
#include "../../mesh/TextBuilder.h"
|
||||
#include "TextBuilder.h"
|
||||
|
||||
HudText::HudText() {
|
||||
HudText::HudText() = default;
|
||||
|
||||
HudText::HudText(Texture *texture) {
|
||||
setTexture(texture);
|
||||
mesh = new Mesh();
|
||||
set("");
|
||||
}
|
||||
|
@ -18,4 +21,4 @@ void HudText::set(std::string text) {
|
|||
delete mesh;
|
||||
Mesh* mesh = TextBuilder().build(this->text);
|
||||
create(mesh);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
class HudText : public Entity {
|
||||
public:
|
||||
HudText();
|
||||
HudText(Texture* texture);
|
||||
|
||||
void set(std::string text);
|
||||
private:
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define ZEUS_TEXTBUILDER_H
|
||||
|
||||
|
||||
#include "../engine/graphics/Mesh.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
class TextBuilder {
|
||||
public:
|
|
@ -6,9 +6,9 @@
|
|||
#define GLPROJECT_MESHCHUNK_H
|
||||
|
||||
|
||||
#include "BlockChunk.h"
|
||||
#include "../blocks/BlockChunk.h"
|
||||
#include "../engine/Entity.h"
|
||||
#include "../mesh/MeshGenerator.h"
|
||||
#include "MeshGenerator.h"
|
||||
|
||||
class MeshChunk : public Entity {
|
||||
public:
|
|
@ -13,7 +13,7 @@
|
|||
#include <cstdio>
|
||||
#include "../engine/Timer.h"
|
||||
#include "../blocks/BlockAtlas.h"
|
||||
#include "../world/BlockChunk.h"
|
||||
#include "../blocks/BlockChunk.h"
|
||||
|
||||
const int CHUNK_SIZE = 16;
|
||||
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
//
|
||||
// Created by aurailus on 27/12/18.
|
||||
//
|
||||
|
||||
#include "DebugGui.h"
|
||||
|
||||
DebugGui::DebugGui() {
|
||||
fontTexture = new Texture((char*)"../tex/font.png");
|
||||
fontTexture->load();
|
||||
|
||||
histogramTexture = new Texture((char*)"../tex/histogram.png");
|
||||
histogramTexture->load();
|
||||
|
||||
alphaText = new HudText(fontTexture);
|
||||
alphaText->set("Zeus Alpha 0.0000000001");
|
||||
alphaText->setScale(3);
|
||||
alphaText->setPosition(glm::vec3(8, 4, 0));
|
||||
|
||||
fpsText = new HudText(fontTexture);
|
||||
fpsText->setScale(2);
|
||||
fpsText->setPosition(glm::vec3(8, 38, 0));
|
||||
|
||||
blockText = new HudText(fontTexture);
|
||||
blockText->setScale(2);
|
||||
blockText->setPosition(glm::vec3(8, 60, 0));
|
||||
|
||||
fpsHistogram = new Entity();
|
||||
fpsHistogram->create(new Mesh(), histogramTexture);
|
||||
fpsHistogram->setPosition(glm::vec3(0, 768, 0));
|
||||
}
|
||||
|
||||
void DebugGui::pushGuiObjects(std::vector<Entity*> &list) {
|
||||
list.push_back(alphaText);
|
||||
list.push_back(fpsText);
|
||||
list.push_back(blockText);
|
||||
list.push_back(fpsHistogram);
|
||||
}
|
||||
|
||||
void DebugGui::fpsHistUpdate() {
|
||||
std::vector<float> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
unsigned int indOffset = 0;
|
||||
float xOffset = 0;
|
||||
float width = 8;
|
||||
float height = 1;
|
||||
float i = 0.10;
|
||||
|
||||
for (double num : fpsHistory) {
|
||||
float h = (float)num * height;
|
||||
float sev = round(9 - (float)max(60 - num, 0.0)/6) / 10.0f;
|
||||
|
||||
auto columnVerts = std::vector<float> {
|
||||
xOffset, -h, 0, sev , sev, 0, 0, 0,
|
||||
xOffset + width, -h, 0, sev+i, sev, 0, 0, 0,
|
||||
xOffset + width, 0, 0, sev+i, sev+i, 0, 0, 0,
|
||||
xOffset, 0, 0, sev , sev+i, 0, 0, 0,
|
||||
};
|
||||
|
||||
for (float f : columnVerts) vertices.push_back(f);
|
||||
|
||||
indices.push_back( indOffset);
|
||||
indices.push_back(3 + indOffset);
|
||||
indices.push_back(1 + indOffset);
|
||||
indices.push_back(3 + indOffset);
|
||||
indices.push_back(2 + indOffset);
|
||||
indices.push_back(1 + indOffset);
|
||||
|
||||
xOffset += width;
|
||||
indOffset += 4;
|
||||
}
|
||||
|
||||
auto m = new Mesh();
|
||||
m->create(&vertices, &indices);
|
||||
|
||||
fpsHistogram->cleanup();
|
||||
fpsHistogram->create(m);
|
||||
}
|
||||
|
||||
void DebugGui::update(glm::vec3 pos, std::string block, double fps) {
|
||||
glm::vec3 chk = World::chunkVec(pos);
|
||||
glm::vec3 loc = World::localVec(pos);
|
||||
|
||||
if (fpsHistory.size() > FPS_HISTOGRAM_SIZE) fpsHistory.erase(fpsHistory.begin());
|
||||
|
||||
fpsHistory.push_back(fps);
|
||||
|
||||
fpsHistUpdate();
|
||||
|
||||
std::ostringstream out;
|
||||
out.precision(2);
|
||||
out << std::fixed << fps;
|
||||
std::string s = out.str();
|
||||
|
||||
fpsText->set(s + " FPS");
|
||||
|
||||
blockText->set(
|
||||
"World Pos: (" + to_string((int)pos.x) + ", " + to_string((int)pos.y) + ", " + to_string((int)pos.z) + ")\n" +
|
||||
"Chunk Pos: (" + to_string((int)chk.x) + ", " + to_string((int)chk.y) + ", " + to_string((int)chk.z) + ")\n" +
|
||||
"Local Pos: (" + to_string((int)loc.x) + ", " + to_string((int)loc.y) + ", " + to_string((int)loc.z) + ")\n" +
|
||||
"Block: " + block);
|
||||
}
|
||||
|
||||
DebugGui::~DebugGui() = default;
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// Created by aurailus on 27/12/18.
|
||||
//
|
||||
|
||||
#ifndef ZEUS_DEBUGGUI_H
|
||||
#define ZEUS_DEBUGGUI_H
|
||||
|
||||
|
||||
#include "../engine/graphics/HudText.h"
|
||||
#include "World.h"
|
||||
#include <sstream>
|
||||
|
||||
class DebugGui {
|
||||
public:
|
||||
DebugGui();
|
||||
|
||||
void pushGuiObjects(std::vector<Entity*> &list);
|
||||
void update(glm::vec3 pos, std::string block, double fps);
|
||||
|
||||
~DebugGui();
|
||||
|
||||
private:
|
||||
void fpsHistUpdate();
|
||||
|
||||
Texture* fontTexture;
|
||||
Texture* histogramTexture;
|
||||
|
||||
HudText* fpsText;
|
||||
HudText* alphaText;
|
||||
HudText* blockText;
|
||||
Entity* fpsHistogram;
|
||||
|
||||
const int FPS_HISTOGRAM_SIZE = 120;
|
||||
std::vector<double> fpsHistory;
|
||||
};
|
||||
|
||||
|
||||
#endif //ZEUS_DEBUGGUI_H
|
|
@ -22,44 +22,26 @@ void GameInstance::initialize(Renderer* renderer) {
|
|||
|
||||
p.doFile("../lua/file.lua");
|
||||
|
||||
//Build the world
|
||||
//The world requires the blockAtlas for meshing and handling inputs.
|
||||
world = new World(blockAtlas);
|
||||
|
||||
renderer->getCamera()->setPosition(glm::vec3(8, 24, 8));
|
||||
|
||||
// int SIZE = 24;
|
||||
// for (int i = -SIZE; i < SIZE; i++) {
|
||||
// for (int j = 0; j < 3; j++) {
|
||||
// for (int k = -SIZE; k < SIZE; k++) {
|
||||
// world->genNewChunk(glm::vec3(i, j, k));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
int SIZE = 10;
|
||||
for (int i = -SIZE; i < SIZE; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
for (int k = -SIZE; k < SIZE; k++) {
|
||||
world->genNewChunk(glm::vec3(i, j, k));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
world->genNewChunk(glm::vec3(0, 0, 0));
|
||||
|
||||
fontTexture = Texture((char*)"../tex/font.png");
|
||||
fontTexture.load();
|
||||
|
||||
alphaText = new HudText();
|
||||
alphaText->set("Zeus Alpha");
|
||||
alphaText->setScale(2.5);
|
||||
alphaText->setPosition(glm::vec3(8, 4, 0));
|
||||
guiEntities.push_back(alphaText);
|
||||
|
||||
fpsText = new HudText();
|
||||
fpsText->setScale(2);
|
||||
fpsText->setPosition(glm::vec3(8, 32, 0));
|
||||
guiEntities.push_back(fpsText);
|
||||
|
||||
blockText = new HudText();
|
||||
blockText->setScale(2);
|
||||
blockText->setPosition(glm::vec3(8, 52, 0));
|
||||
guiEntities.push_back(blockText);
|
||||
gui.pushGuiObjects(guiEntities);
|
||||
}
|
||||
|
||||
void GameInstance::update(GLfloat deltaTime) {
|
||||
void GameInstance::update(GLfloat deltaTime, double fps) {
|
||||
renderer->update();
|
||||
|
||||
auto camera = renderer->getCamera();
|
||||
|
@ -70,25 +52,17 @@ void GameInstance::update(GLfloat deltaTime) {
|
|||
|
||||
glm::vec3 round = World::roundVec(*camera->getPosition());
|
||||
round.y -= 2;
|
||||
glm::vec3 chunk = World::chunkVec(round);
|
||||
glm::vec3 local = World::localVec(round);
|
||||
// glm::vec3 chunk = World::chunkVec(round);
|
||||
// glm::vec3 local = World::localVec(round);
|
||||
|
||||
int block = world->getBlock(round);
|
||||
std::string name = "Null";
|
||||
|
||||
if (block >= 0) {
|
||||
name = blockAtlas->getBlock(block)->getIdentifier();
|
||||
}
|
||||
|
||||
if (block < 1) {
|
||||
camera->getPosition()->y -= 0.1;
|
||||
}
|
||||
gui.update(round, name, fps);
|
||||
|
||||
blockText->set(
|
||||
"World Pos: (" + to_string((int)round.x) + ", " + to_string((int)round.y) + ", " + to_string((int)round.z) + ")\n" +
|
||||
"Chunk Pos: (" + to_string((int)chunk.x) + ", " + to_string((int)chunk.y) + ", " + to_string((int)chunk.z) + ")\n" +
|
||||
"Local Pos: (" + to_string((int)local.x) + ", " + to_string((int)local.y) + ", " + to_string((int)local.z) + ")\n" +
|
||||
"Block: " + name);
|
||||
world->update();
|
||||
}
|
||||
|
||||
|
@ -105,15 +79,17 @@ void GameInstance::draw() {
|
|||
}
|
||||
|
||||
renderer->enableGuiShader();
|
||||
fontTexture.use();
|
||||
|
||||
for (auto &gui : *getGuiEntities()) {
|
||||
Texture* prevTexture = nullptr;
|
||||
|
||||
for (auto &gui : guiEntities) {
|
||||
if (gui->getTexture() != nullptr && gui->getTexture() != prevTexture) {
|
||||
prevTexture = gui->getTexture();
|
||||
gui->getTexture()->use();
|
||||
}
|
||||
|
||||
renderer->drawGui(gui);
|
||||
}
|
||||
|
||||
renderer->end();
|
||||
}
|
||||
|
||||
std::vector<Entity*>* GameInstance::getGuiEntities() {
|
||||
return &guiEntities;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "../engine/helpers/ArrayTrans3D.h"
|
||||
#include "../lua_api/LuaParser.h"
|
||||
#include "../engine/graphics/HudText.h"
|
||||
#include "DebugGui.h"
|
||||
|
||||
class GameInstance {
|
||||
public:
|
||||
|
@ -21,13 +22,9 @@ public:
|
|||
|
||||
void initialize(Renderer* renderer);
|
||||
|
||||
void update(GLfloat deltaTime);
|
||||
void update(GLfloat deltaTime, double fps);
|
||||
|
||||
void draw();
|
||||
|
||||
std::vector<Entity*>* getGuiEntities();
|
||||
|
||||
HudText* fpsText;
|
||||
public:
|
||||
//The renderer contains the camera, window, and draw methods.
|
||||
Renderer* renderer;
|
||||
|
@ -41,12 +38,9 @@ public:
|
|||
//The block atlas holds block definitions and models.
|
||||
BlockAtlas* blockAtlas;
|
||||
|
||||
//GUI Entities (Things to draw on the screen
|
||||
//GUI Related things
|
||||
std::vector<Entity*> guiEntities;
|
||||
Texture fontTexture;
|
||||
|
||||
HudText* alphaText;
|
||||
HudText* blockText;
|
||||
DebugGui gui;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -47,9 +47,6 @@ void World::update() {
|
|||
}
|
||||
|
||||
int World::getBlock(glm::vec3 pos) {
|
||||
// glm::vec3 chunkPos(round(pos.x / 16), round(pos.y / 16), round(pos.z / 16));
|
||||
// return 0;
|
||||
|
||||
auto chunkPos = World::chunkVec(World::roundVec(pos));
|
||||
auto local = World::localVec(World::roundVec(pos));
|
||||
|
||||
|
@ -57,7 +54,6 @@ int World::getBlock(glm::vec3 pos) {
|
|||
if (chunk != nullptr) {
|
||||
return chunk->getBlock(&local);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
#include <bits/unordered_map.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "BlockChunk.h"
|
||||
#include "MeshChunk.h"
|
||||
#include "../blocks/BlockChunk.h"
|
||||
#include "../mesh/MeshChunk.h"
|
||||
#include "../blocks/BlockAtlas.h"
|
||||
|
||||
class World {
|
||||
|
|
Loading…
Reference in New Issue