summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AssetManager.cpp2
-rw-r--r--src/Event.cpp5
-rw-r--r--src/Framebuffer.cpp12
-rw-r--r--src/Game.cpp5
-rw-r--r--src/GameState.cpp2
-rw-r--r--src/Render.cpp8
-rw-r--r--src/Renderer.cpp3
-rw-r--r--src/RendererEntity.cpp2
-rw-r--r--src/RendererSection.cpp4
-rw-r--r--src/RendererSectionData.cpp5
-rw-r--r--src/RendererSky.cpp9
-rw-r--r--src/RendererWorld.cpp16
-rw-r--r--src/Utility.cpp2
-rw-r--r--src/World.cpp6
14 files changed, 68 insertions, 13 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp
index 66e7767..ba2b4f4 100644
--- a/src/AssetManager.cpp
+++ b/src/AssetManager.cpp
@@ -11,6 +11,7 @@
#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_PNG
#include <stb_image.h>
+#include <optick.h>
#include "Utility.hpp"
#include "Plugin.hpp"
@@ -661,6 +662,7 @@ std::string AssetManager::GetAssetNameByBlockId(BlockId block) {
}
Asset *AssetManager::GetAssetPtr(const std::string & assetName) {
+ OPTICK_EVENT();
AssetTreeNode *node;
if (assetName[0] != '/')
node = GetAssetByAssetName('/' + assetName);
diff --git a/src/Event.cpp b/src/Event.cpp
index 5c126bb..ea09af3 100644
--- a/src/Event.cpp
+++ b/src/Event.cpp
@@ -1,5 +1,7 @@
#include "Event.hpp"
+#include <optick.h>
+
std::list<EventListener*> EventSystem::listeners;
std::recursive_mutex EventSystem::listenersMutex;
@@ -14,6 +16,7 @@ EventListener::~EventListener() {
}
void EventListener::HandleEvent() {
+ OPTICK_EVENT();
if (!NotEmpty())
return;
@@ -27,6 +30,7 @@ void EventListener::HandleEvent() {
}
void EventListener::HandleAllEvents() {
+ OPTICK_EVENT();
if (!NotEmpty())
return;
@@ -54,6 +58,7 @@ void EventListener::RegisterHandler(size_t eventId, const EventListener::Handler
}
void EventListener::PollEvents() {
+ OPTICK_EVENT();
std::lock_guard<std::recursive_mutex> rawLock (rawEventsMutex);
if (rawEvents.empty())
return;
diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp
index fb7ebc7..d81b0e0 100644
--- a/src/Framebuffer.cpp
+++ b/src/Framebuffer.cpp
@@ -3,11 +3,13 @@
#include <string>
#include "Utility.hpp"
#include "AssetManager.hpp"
+#include <optick.h>
const GLuint magic = 316784;
GLuint quadVao = magic, quadVbo = magic;
Framebuffer::Framebuffer(unsigned int width, unsigned int height, bool createDepthStencilBuffer) : width(width), height(height) {
+ OPTICK_EVENT();
if (quadVao == magic) {
float quadVertices[] = {
// positions // texCoords
@@ -70,11 +72,13 @@ Framebuffer::~Framebuffer() {
}
void Framebuffer::Activate() {
+ OPTICK_EVENT();
glViewport(0, 0, width, height);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
}
void Framebuffer::RenderTo(Framebuffer &target) {
+ OPTICK_EVENT();
glBindFramebuffer(GL_FRAMEBUFFER, target.fbo);
glViewport(0, 0, target.width, target.height);
AssetManager::GetAsset<AssetShader>("/altcraft/shaders/fbo")->shader->Activate();
@@ -96,8 +100,8 @@ void Framebuffer::Resize(unsigned int newWidth, unsigned int newHeight) {
}
}
-Framebuffer &Framebuffer::GetDefault()
-{
+Framebuffer &Framebuffer::GetDefault() {
+ OPTICK_EVENT();
static char fboDefaultData[sizeof(Framebuffer)];
static Framebuffer *fboDefault = nullptr;
if (fboDefault == nullptr) {
@@ -111,8 +115,8 @@ Framebuffer &Framebuffer::GetDefault()
return *fboDefault;
}
-void Framebuffer::Clear(bool color, bool depth, bool stencil)
-{
+void Framebuffer::Clear(bool color, bool depth, bool stencil) {
+ OPTICK_EVENT();
Activate();
GLbitfield clearBits = 0;
if (color)
diff --git a/src/Game.cpp b/src/Game.cpp
index a3f2b50..d67072e 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -2,6 +2,8 @@
#include <memory>
+#include <optick.h>
+
#include "Render.hpp"
#include "GameState.hpp"
#include "NetworkClient.hpp"
@@ -127,7 +129,6 @@ void InitEvents() {
default:
break;
}
- LOG(INFO) << "Changed key";
});
listener.RegisterHandler("MouseMove", [](const Event& eventData) {
@@ -171,6 +172,7 @@ void InitEvents() {
}
void RunGame() {
+ OPTICK_THREAD("Main");
InitEvents();
timer = std::make_unique<LoopExecutionTimeController>(std::chrono::milliseconds(16));
@@ -180,6 +182,7 @@ void RunGame() {
SetState(State::MainMenu);
while (isRunning) {
+ OPTICK_FRAME("MainThread");
listener.HandleAllEvents();
if (gs) {
if (GetState() == State::Playing) {
diff --git a/src/GameState.cpp b/src/GameState.cpp
index 9e92c1f..e4278ec 100644
--- a/src/GameState.cpp
+++ b/src/GameState.cpp
@@ -2,11 +2,13 @@
#include <glm/gtc/matrix_transform.hpp>
#include <easylogging++.h>
+#include <optick.h>
#include "Event.hpp"
#include "Packet.hpp"
void GameState::Update(double deltaTime) {
+ OPTICK_EVENT();
if (!gameStatus.isGameStarted)
return;
diff --git a/src/Render.cpp b/src/Render.cpp
index 00daf99..6218740 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -2,6 +2,7 @@
#include <imgui.h>
#include <easylogging++.h>
+#include <optick.h>
#include "imgui_impl_sdl_gl3.h"
#include "Shader.hpp"
@@ -173,6 +174,7 @@ void Render::UpdateKeyboard() {
}
void Render::RenderFrame() {
+ OPTICK_EVENT();
framebuffer->Clear();
Framebuffer::GetDefault().Clear();
@@ -193,7 +195,9 @@ void Render::RenderFrame() {
world->Update(GetTime()->RemainTimeMs());
}
- SDL_GL_SwapWindow(window);
+
+ OPTICK_EVENT("VSYNC");
+ SDL_GL_SwapWindow(window);
}
void Render::HandleEvents() {
@@ -350,6 +354,7 @@ void Render::SetMouseCapture(bool IsCaptured) {
}
void Render::Update() {
+ OPTICK_EVENT();
HandleEvents();
if (HasFocus && GetState() == State::Playing) UpdateKeyboard();
if (isMouseCaptured) HandleMouseCapture();
@@ -360,6 +365,7 @@ void Render::Update() {
}
void Render::RenderGui() {
+ OPTICK_EVENT();
ImGui_ImplSdlGL3_NewFrame(window);
if (isMouseCaptured) {
diff --git a/src/Renderer.cpp b/src/Renderer.cpp
index 0db23db..947fd6f 100644
--- a/src/Renderer.cpp
+++ b/src/Renderer.cpp
@@ -1,6 +1,9 @@
#include "Renderer.hpp"
+#include <optick.h>
+
void RenderState::SetActiveVao(GLuint Vao) {
+ OPTICK_EVENT();
glBindVertexArray(Vao);
ActiveVao = Vao;
}
diff --git a/src/RendererEntity.cpp b/src/RendererEntity.cpp
index fc5e1a2..fcbf79a 100644
--- a/src/RendererEntity.cpp
+++ b/src/RendererEntity.cpp
@@ -2,6 +2,7 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
+#include <optick.h>
#include "Entity.hpp"
#include "GameState.hpp"
@@ -123,6 +124,7 @@ RendererEntity::~RendererEntity() {
}
void RendererEntity::Render(RenderState& renderState, const World *world) {
+ OPTICK_EVENT();
glm::mat4 model = glm::mat4(1.0);
const Entity &entity = world->GetEntity(entityId);
model = glm::translate(model, entity.pos.glm());
diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp
index 1521c6f..d797771 100644
--- a/src/RendererSection.cpp
+++ b/src/RendererSection.cpp
@@ -1,6 +1,7 @@
#include "RendererSection.hpp"
#include <easylogging++.h>
+#include <optick.h>
#include "Utility.hpp"
#include "Renderer.hpp"
@@ -31,6 +32,7 @@ GLuint RendererSection::VboVertices = magicUniqueConstant;
GLuint RendererSection::VboUvs = magicUniqueConstant;
RendererSection::RendererSection(const RendererSectionData &data) {
+ OPTICK_EVENT();
if (VboVertices == magicUniqueConstant) {
glGenBuffers(1, &VboVertices);
glGenBuffers(1, &VboUvs);
@@ -155,6 +157,7 @@ void swap(RendererSection & lhs, RendererSection & rhs) {
}
void RendererSection::Render(RenderState &renderState) {
+ OPTICK_EVENT();
renderState.SetActiveVao(Vao);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, numOfFaces);
glCheckError();
@@ -169,6 +172,7 @@ size_t RendererSection::GetHash() {
}
void RendererSection::UpdateData(const RendererSectionData & data) {
+ OPTICK_EVENT();
glBindBuffer(GL_ARRAY_BUFFER, Vbo[TEXTURES]);
glBufferData(GL_ARRAY_BUFFER, data.textures.size() * sizeof(glm::vec4), data.textures.data(), GL_DYNAMIC_DRAW);
diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp
index 3b51809..69ed665 100644
--- a/src/RendererSectionData.cpp
+++ b/src/RendererSectionData.cpp
@@ -3,6 +3,7 @@
#include <array>
#include <glm/gtc/matrix_transform.hpp>
+#include <optick.h>
#include "World.hpp"
@@ -101,8 +102,8 @@ std::array<BlockId, 4096> SetBlockIdData(const SectionsData &sections) {
return blockIdData;
}
-RendererSectionData ParseSection(const SectionsData &sections)
-{
+RendererSectionData ParseSection(const SectionsData &sections) {
+ OPTICK_EVENT();
RendererSectionData data;
std::vector<std::pair<BlockId, BlockFaces*>> idModels;
diff --git a/src/RendererSky.cpp b/src/RendererSky.cpp
index d0e9518..1eab369 100644
--- a/src/RendererSky.cpp
+++ b/src/RendererSky.cpp
@@ -1,5 +1,7 @@
#include "RendererSky.hpp"
+#include <optick.h>
+
#include "Renderer.hpp"
#include "Utility.hpp"
@@ -127,16 +129,15 @@ RendererSky::RendererSky() {
glCheckError();
}
-RendererSky::~RendererSky()
-{
+RendererSky::~RendererSky() {
glDeleteBuffers(1, &VboVert);
glDeleteBuffers(1, &VboUv);
glDeleteVertexArrays(1, &Vao);
//glCheckError();
}
-void RendererSky::Render(RenderState &renderState)
-{
+void RendererSky::Render(RenderState &renderState) {
+ OPTICK_EVENT();
renderState.SetActiveVao(Vao);
glDrawArrays(GL_TRIANGLES, 0, 36);
glCheckError();
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index bcb6f92..ebb049d 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -2,6 +2,7 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
+#include <optick.h>
#include "DebugInfo.hpp"
#include "Frustum.hpp"
@@ -15,9 +16,11 @@
#include "Game.hpp"
void RendererWorld::WorkerFunction(size_t workerId) {
+ OPTICK_THREAD("Worker");
EventListener tasksListener;
tasksListener.RegisterHandler("ParseSection", [&](const Event &eventData) {
+ OPTICK_EVENT("EV_ParseSection");
auto data = eventData.get<std::tuple<size_t, size_t, bool>>();
if (std::get<0>(data) != workerId)
return;
@@ -37,6 +40,7 @@ void RendererWorld::WorkerFunction(size_t workerId) {
}
void RendererWorld::ParseQueueUpdate() {
+ OPTICK_EVENT();
while (!parseQueue.empty()) {
size_t id = 0;
for (; id < RendererWorld::parsingBufferSize && parsing[id].parsing; ++id) {}
@@ -70,6 +74,7 @@ void RendererWorld::ParseQueueUpdate() {
}
void RendererWorld::ParseQeueueRemoveUnnecessary() {
+ OPTICK_EVENT();
size_t size = parseQueue.size();
static std::vector<Vector> elements;
elements.clear();
@@ -113,6 +118,7 @@ void RendererWorld::ParseQeueueRemoveUnnecessary() {
}
void RendererWorld::UpdateAllSections(VectorF playerPos) {
+ OPTICK_EVENT();
Vector playerChunk(std::floor(GetGameState()->GetPlayer()->pos.x / 16), 0, std::floor(GetGameState()->GetPlayer()->pos.z / 16));
std::vector<Vector> suitableChunks;
@@ -148,6 +154,7 @@ void RendererWorld::UpdateAllSections(VectorF playerPos) {
}
RendererWorld::RendererWorld() {
+ OPTICK_EVENT();
MaxRenderingDistance = 2;
numOfWorkers = _max(1, (signed int) std::thread::hardware_concurrency() - 2);
@@ -158,6 +165,7 @@ RendererWorld::RendererWorld() {
PrepareRender();
listener->RegisterHandler("DeleteSectionRender", [this](const Event& eventData) {
+ OPTICK_EVENT("EV_DeleteSectionRender");
auto vec = eventData.get<Vector>();
auto it = sections.find(vec);
if (it == sections.end())
@@ -166,6 +174,7 @@ RendererWorld::RendererWorld() {
});
listener->RegisterHandler("SectionParsed",[this](const Event &eventData) {
+ OPTICK_EVENT("EV_SectionParsed");
auto id = eventData.get<size_t>();
parsing[id].parsing = false;
@@ -185,6 +194,7 @@ RendererWorld::RendererWorld() {
});
listener->RegisterHandler("EntityChanged", [this](const Event& eventData) {
+ OPTICK_EVENT("EV_EntityChanged");
auto data = eventData.get<unsigned int>();
for (unsigned int entityId : GetGameState()->GetWorld().GetEntitiesList()) {
if (entityId == data) {
@@ -194,6 +204,7 @@ RendererWorld::RendererWorld() {
});
listener->RegisterHandler("ChunkChanged", [this](const Event& eventData) {
+ OPTICK_EVENT("EV_ChunkChanged");
auto vec = eventData.get<Vector>();
if (vec == Vector())
return;
@@ -211,6 +222,7 @@ RendererWorld::RendererWorld() {
});
listener->RegisterHandler("ChunkChangedForce", [this](const Event& eventData) {
+ OPTICK_EVENT("EV_ChunkChangedForce");
auto vec = eventData.get<Vector>();
if (vec == Vector())
return;
@@ -271,6 +283,7 @@ RendererWorld::~RendererWorld() {
}
void RendererWorld::Render(RenderState & renderState) {
+ OPTICK_EVENT();
//Common
glm::mat4 projection = glm::perspective(
glm::radians(70.0f), (float) renderState.WindowWidth / (float) renderState.WindowHeight,
@@ -286,7 +299,7 @@ void RendererWorld::Render(RenderState & renderState) {
entityShader->SetUniform("projection", projection);
entityShader->SetUniform("view", view);
glCheckError();
-
+
renderState.SetActiveVao(RendererEntity::GetVao());
for (auto& it : entities) {
it.Render(renderState, &GetGameState()->GetWorld());
@@ -434,6 +447,7 @@ void RendererWorld::PrepareRender() {
}
void RendererWorld::Update(double timeToUpdate) {
+ OPTICK_EVENT();
static auto timeSincePreviousUpdate = std::chrono::steady_clock::now();
if (parseQueueNeedRemoveUnnecessary)
diff --git a/src/Utility.cpp b/src/Utility.cpp
index 848ee02..09696fd 100644
--- a/src/Utility.cpp
+++ b/src/Utility.cpp
@@ -2,9 +2,11 @@
#include <thread>
+#include <optick.h>
#include <easylogging++.h>
GLenum glCheckError_(const char *file, int line) {
+ OPTICK_EVENT();
GLenum errorCode;
while ((errorCode = glGetError()) != GL_NO_ERROR) {
std::string error;
diff --git a/src/World.cpp b/src/World.cpp
index da0a33b..fa281f1 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2,6 +2,7 @@
#include <bitset>
#include <glm/glm.hpp>
+#include <optick.h>
#include "Event.hpp"
#include "DebugInfo.hpp"
@@ -131,6 +132,7 @@ const Section &World::GetSection(Vector sectionPos) const {
// TODO: skip liquid blocks
RaycastResult World::Raycast(glm::vec3 position, glm::vec3 direction) const {
+ OPTICK_EVENT();
const float maxLen = 5.0;
const float step = 0.01;
glm::vec3 pos = glm::vec3(0.0);
@@ -150,6 +152,7 @@ RaycastResult World::Raycast(glm::vec3 position, glm::vec3 direction) const {
}
void World::UpdatePhysics(float delta) {
+ OPTICK_EVENT();
struct CollisionResult {
bool isCollide;
//Vector block;
@@ -158,6 +161,7 @@ void World::UpdatePhysics(float delta) {
};
auto testCollision = [this](double width, double height, VectorF pos)->CollisionResult {
+ OPTICK_EVENT("testCollision");
int blockXBegin = pos.x - width - 1.0;
int blockXEnd = pos.x + width + 0.5;
int blockYBegin = pos.y - 0.5;
@@ -177,6 +181,7 @@ void World::UpdatePhysics(float delta) {
for (int y = blockYBegin; y <= blockYEnd; y++) {
for (int z = blockZBegin; z <= blockZEnd; z++) {
for (int x = blockXBegin; x <= blockXEnd; x++) {
+ OPTICK_EVENT("testCollision");
BlockId block = this->GetBlockId(Vector(x, y, z));
if (block.id == 0 || block.id == 31 || block.id == 37 || block.id == 38 || block.id == 175 || block.id == 78)
continue;
@@ -191,6 +196,7 @@ void World::UpdatePhysics(float delta) {
};
for (auto& it : entities) {
+ OPTICK_EVENT("Foreach entities");
if (it.isFlying) {
VectorF newPos = it.pos + VectorF(it.vel.x, it.vel.y, it.vel.z) * delta;
auto coll = testCollision(it.width, it.height, newPos);