From 82421ca64c3f8fa0a41698899f549a7d2d58cc4a Mon Sep 17 00:00:00 2001 From: Doyle Thai Date: Fri, 23 Sep 2016 19:36:18 +1000 Subject: [PATCH] Improve performance by swapping render groups Last used render groups are brought to front of render list when searching for valid group- as per- recently used items are likely to be used again. --- src/Renderer.c | 14 +++++++++++++- src/WorldTraveller.c | 2 +- src/dengine.c | 7 ++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Renderer.c b/src/Renderer.c index 49b9b9b..c807fa3 100644 --- a/src/Renderer.c +++ b/src/Renderer.c @@ -13,6 +13,11 @@ INTERNAL void addVertexToRenderGroup(Renderer *renderer, Texture *tex, v4 color, Vertex *vertexList, i32 numVertexes) { + +#ifdef DENGINE_DEBUG + ASSERT(numVertexes > 0); +#endif + /* Find vacant/matching render group */ RenderGroup *targetGroup = NULL; for (i32 i = 0; i < ARRAY_COUNT(renderer->groups); i++) @@ -46,7 +51,13 @@ INTERNAL void addVertexToRenderGroup(Renderer *renderer, Texture *tex, v4 color, i32 freeVertexSlots = renderer->groupCapacity - group->vertexIndex; if (numVertexes < freeVertexSlots) { - targetGroup = &renderer->groups[i]; + if (i != 0) + { + RenderGroup tmp = renderer->groups[0]; + renderer->groups[0] = renderer->groups[i]; + renderer->groups[i] = tmp; + } + targetGroup = &renderer->groups[0]; break; } } @@ -289,6 +300,7 @@ void renderer_string(Renderer *const renderer, MemoryArena *arena, Rect camera, v2 pivotPoint, f32 rotate, v4 color) { i32 strLen = common_strlen(string); + if (strLen <= 0) return; // TODO(doyle): Slightly incorrect string length in pixels calculation, // because we use the advance metric of each character for length not diff --git a/src/WorldTraveller.c b/src/WorldTraveller.c index d0a123b..b61d6ff 100644 --- a/src/WorldTraveller.c +++ b/src/WorldTraveller.c @@ -101,7 +101,7 @@ INTERNAL void rendererInit(GameState *state, v2 windowSize) GL_CHECK_ERROR(); // TODO(doyle): Lazy allocate render group capacity - renderer->groupCapacity = 1024; + renderer->groupCapacity = 4096; for (i32 i = 0; i < ARRAY_COUNT(renderer->groups); i++) { renderer->groups[i].vertexList = diff --git a/src/dengine.c b/src/dengine.c index 7dfd06e..10aff3e 100644 --- a/src/dengine.c +++ b/src/dengine.c @@ -224,9 +224,14 @@ i32 main(void) f32 msPerFrame = secondsElapsed * 1000.0f; f32 framesPerSecond = 1.0f / secondsElapsed; + i32 entityCount = + worldTraveller.world[worldTraveller.currWorldIndex] + .freeEntityIndex; + char textBuffer[256]; snprintf(textBuffer, ARRAY_COUNT(textBuffer), - "Dengine | %f ms/f | %f fps", msPerFrame, framesPerSecond); + "Dengine | %f ms/f | %f fps | Entity Count: %d", + msPerFrame, framesPerSecond, entityCount); glfwSetWindowTitle(window, textBuffer); titleUpdateFrequencyInSeconds = 0.5f;