diff --git a/src/debug/lines.cpp b/src/debug/lines.cpp index 3322c608..a70b4558 100644 --- a/src/debug/lines.cpp +++ b/src/debug/lines.cpp @@ -17,6 +17,27 @@ namespace lol { +//Resets draw infos +void Debug::ResetDrawSetup() +{ + g_scene->SetLineTime(); + g_scene->SetLineMask(); +} +//Sets draw infos +void Debug::DrawSetup(float new_time) +{ + g_scene->SetLineTime(new_time); +} +void Debug::DrawSetup(int new_mask) +{ + g_scene->SetLineMask(new_mask); +} +void Debug::DrawSetup(float new_time, int new_mask) +{ + g_scene->SetLineTime(new_time); + g_scene->SetLineMask(new_mask); +} + void Debug::DrawLine(vec3 a, vec3 b, vec4 color) { g_scene->AddLine(a, b, color); diff --git a/src/lol/algorithm/aabb_tree.h b/src/lol/algorithm/aabb_tree.h index 1a877045..2cdf2285 100644 --- a/src/lol/algorithm/aabb_tree.h +++ b/src/lol/algorithm/aabb_tree.h @@ -343,7 +343,6 @@ template class QuadTree : public AABBTree { friend void Debug::Draw(OcTree* tree, vec4 color); - //template friend void Debug::Draw(QuadTree* tree, vec4 color); public: QuadTree() { m_debug_y_offset = 0.f; } virtual ~QuadTree() { } @@ -357,7 +356,6 @@ template class OcTree : public AABBTree { friend void Debug::Draw(OcTree* tree, vec4 color); - //template friend void Debug::Draw(OcTree* tree, vec4 color); public: OcTree() { } virtual ~OcTree() { } diff --git a/src/lol/debug/lines.h b/src/lol/debug/lines.h index 2df1db66..b68915a2 100644 --- a/src/lol/debug/lines.h +++ b/src/lol/debug/lines.h @@ -24,6 +24,13 @@ namespace lol namespace Debug { +//Resets draw infos +void ResetDrawSetup(); +//Sets draw infos +void DrawSetup(float new_time); +void DrawSetup(int new_mask); +void DrawSetup(float new_time, int new_mask); + void DrawLine(vec3 a, vec3 b, vec4 color); void DrawBox(box3 a, vec4 color); void DrawBox(vec3 a, vec3 b, vec4 color); diff --git a/src/scene.cpp b/src/scene.cpp index 3ed2b798..832de7ef 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -59,8 +59,11 @@ private: /* New scenegraph */ Array m_primitives; - /* Old API */ - Array m_lines; + /* Old API */ + float m_new_line_time; + int m_new_line_mask; + Array m_lines; + int m_debug_mask; Shader *m_line_shader; VertexDeclaration *m_line_vdecl; @@ -94,6 +97,10 @@ Scene::Scene(ivec2 size) data->m_line_shader = 0; data->m_line_vdecl = new VertexDeclaration(VertexStream(VertexUsage::Position, VertexUsage::Color)); + + data->m_debug_mask = 1; + SetLineTime(); + SetLineMask(); } Scene::~Scene() @@ -173,9 +180,18 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale) data->m_tiles.Push(t); } +void Scene::SetLineTime(float new_time) +{ + data->m_new_line_time = new_time; +} +void Scene::SetLineMask(int new_mask) +{ + data->m_new_line_mask = new_mask; +} + void Scene::AddLine(vec3 a, vec3 b, vec4 color) { - data->m_lines.Push(a, b, color); + data->m_lines.Push(a, b, color, data->m_new_line_time, data->m_new_line_mask); } void Scene::AddLight(Light *l) @@ -315,7 +331,7 @@ void Scene::RenderTiles() // XXX: rename to Blit() #endif } -void Scene::RenderLines() // XXX: rename to Blit() +void Scene::RenderLines(float seconds) // XXX: rename to Blit() { RenderContext rc; @@ -331,19 +347,30 @@ void Scene::RenderLines() // XXX: rename to Blit() if (!data->m_line_shader) data->m_line_shader = Shader::Create(LOLFX_RESOURCE_NAME(line)); - VertexBuffer *vb = new VertexBuffer((sizeof(vec3) + sizeof(vec4)) * 2 * linecount); - float *vertex = (float *)vb->Lock(0, 0); + Array buff; + buff.Resize(linecount); + int real_linecount = 0; for (int i = 0; i < linecount; i++) { - memcpy(vertex, &data->m_lines[i].m1, sizeof(vec3)); - vertex += 3; - memcpy(vertex, &data->m_lines[i].m3, sizeof(vec4)); - vertex += 4; - memcpy(vertex, &data->m_lines[i].m2, sizeof(vec3)); - vertex += 3; - memcpy(vertex, &data->m_lines[i].m3, sizeof(vec4)); - vertex += 4; + if (data->m_lines[i].m5 & data->m_debug_mask) + { + buff[real_linecount].m1 = data->m_lines[i].m1; + buff[real_linecount].m2 = data->m_lines[i].m3; + buff[real_linecount].m3 = data->m_lines[i].m2; + buff[real_linecount].m4 = data->m_lines[i].m3; + real_linecount++; + } + data->m_lines[i].m4 -= seconds; + if (data->m_lines[i].m4 < 0.f) + { + data->m_lines.RemoveSwap(i--); + linecount--; + } } + int vb_size = (sizeof(vec3) + sizeof(vec4)) * 2 * real_linecount; + VertexBuffer *vb = new VertexBuffer(vb_size); + float *vertex = (float *)vb->Lock(0, 0); + memcpy(vertex, buff.Data(), vb_size); vb->Unlock(); data->m_line_shader->Bind(); @@ -362,11 +389,11 @@ void Scene::RenderLines() // XXX: rename to Blit() data->m_line_vdecl->Bind(); data->m_line_vdecl->SetStream(vb, attr_pos, attr_col); - data->m_line_vdecl->DrawElements(MeshPrimitive::Lines, 0, 2 * linecount); + data->m_line_vdecl->DrawElements(MeshPrimitive::Lines, 0, 2 * real_linecount); data->m_line_vdecl->Unbind(); data->m_line_shader->Unbind(); - data->m_lines.Empty(); + //data->m_lines.Empty(); delete vb; } diff --git a/src/scene.h b/src/scene.h index 3baf38de..5fb15e83 100644 --- a/src/scene.h +++ b/src/scene.h @@ -45,7 +45,7 @@ public: void RenderPrimitives(); void RenderTiles(); - void RenderLines(); + void RenderLines(float seconds); /* New scenegraph */ void AddPrimitive(Mesh *mesh, Shader *shader, mat4 const &matrix); @@ -53,6 +53,8 @@ public: /* FIXME: this should be deprecated -- it doesn't really match * the architecture we want to build */ void AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale); + void SetLineTime(float new_time=-1.f); + void SetLineMask(int new_mask=0xFFFFFFFF); void AddLine(vec3 a, vec3 b, vec4 color); void AddLight(Light *light); diff --git a/src/ticker.cpp b/src/ticker.cpp index fb5329ac..3fa86d81 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -411,7 +411,7 @@ void TickerData::DrawThreadTick() /* Do this render step */ g_scene->RenderPrimitives(); g_scene->RenderTiles(); - g_scene->RenderLines(); + g_scene->RenderLines(data->deltatime); } Profiler::Stop(Profiler::STAT_TICK_DRAW);