diff --git a/building.txt b/building.txt index 8ead7da..b44c9e2 100644 --- a/building.txt +++ b/building.txt @@ -3,19 +3,13 @@ Bounce uses premake for generating project files in a platform agnostic manner. Grab premake from http://industriousone.com/premake. Put premake into bounce/. -Visual Studio 2015 - -Say { premake5 vs2015 } on a command line. -Open build/vs2015/bounce.sln. -Set testbed as the startup project. -Press F5 to run. - Visual Studio 2017 Ensure you have installed the Visual Studio 2015 libraries Say { premake5 vs2017 } on a command line. Open build/vs2017/bounce.sln. Set testbed as the startup project. +In the testbed debugging properties, set the Working Directory to ..\..\examples\testbed. Press F5 to run. Linux @@ -30,14 +24,16 @@ x32 Say { premake5 gmake } on a terminal. From build/gmake say { make config="debug_x32" }. +Set the testbed directory as the working directory Open testbed from /bin/x32/testbed/. x64 Say { premake5 gmake } on a terminal. From build/gmake say { make config="debug_x64" }. +Set the testbed directory as the working directory Open testbed from /bin/x64/testbed/. Mac -I don't run Mac currently and therefore can't test the build system in this platform. +I don't run Mac currently and therefore can't test the build system in this platform. \ No newline at end of file diff --git a/examples/testbed/framework/profiler.cpp b/examples/testbed/framework/profiler.cpp index c55447e..e240ce8 100644 --- a/examples/testbed/framework/profiler.cpp +++ b/examples/testbed/framework/profiler.cpp @@ -30,26 +30,26 @@ struct Event Event* parent; }; -static b3Time time; -static b3BoundedQueue events; -static Event* top = NULL; +static b3Time s_time; +static b3BoundedQueue s_events; +static Event* s_top = NULL; bool b3PushProfileScope(const char* name) { - time.Update(); + s_time.Update(); Event e; e.tid = -1; e.pid = -1; - e.t0 = time.GetCurrentMilis(); + e.t0 = s_time.GetCurrentMilis(); e.t1 = 0; e.name = name; - e.parent = top; + e.parent = s_top; - Event* back = events.Push(e); + Event* back = s_events.Push(e); if (back) { - top = back; + s_top = back; } return back != NULL; @@ -57,35 +57,35 @@ bool b3PushProfileScope(const char* name) void b3PopProfileScope() { - B3_ASSERT(top); - B3_ASSERT(top->t1 == 0); + B3_ASSERT(s_top); + B3_ASSERT(s_top->t1 == 0); - time.Update(); - top->t1 = time.GetCurrentMilis(); - B3_ASSERT(top->t1 != 0); - top = top->parent; + s_time.Update(); + s_top->t1 = s_time.GetCurrentMilis(); + B3_ASSERT(s_top->t1 != 0); + s_top = s_top->parent; } void ProfileBegin() { - B3_ASSERT(events.IsEmpty()); + B3_ASSERT(s_events.IsEmpty()); } void ProfileEnd() { ProfileBeginEvents(); - while (events.IsEmpty() == false) + while (s_events.IsEmpty() == false) { - const Event& e = events.Front(); - events.Pop(); + const Event& e = s_events.Front(); + s_events.Pop(); ProfileEvent(e.tid, e.pid, e.name, e.t0, e_begin); ProfileEvent(e.tid, e.pid, e.name, e.t1, e_end); ProfileEvent(e.tid, e.pid, e.name, e.t1 - e.t0); } - B3_ASSERT(events.IsEmpty()); + B3_ASSERT(s_events.IsEmpty()); ProfileEndEvents(); } @@ -106,7 +106,7 @@ void ProfileBeginEvents() } -void ProfileEvent(i32 tid, i32 pid, const char* name, float64 time, ProfileType type) +void ProfileEvent(i32 tid, i32 pid, const char* name, float64 t, ProfileType type) { } @@ -128,38 +128,38 @@ void ProfileEndEvents() using namespace rapidjson; -static FILE* file = NULL; -static FileWriteStream* stream = NULL; -static Writer* writer = NULL; +static FILE* s_file = NULL; +static FileWriteStream* s_stream = NULL; +static Writer* s_writer = NULL; #define STRING(x) String(x, sizeof(x) - 1) void ProfileBeginEvents() { - if (file) + if (s_file) { return; } - file = fopen("profile.json", "wt"); - if (!file) + s_file = fopen("profile.json", "wt"); + if (!s_file) { return; } static char buffer[512]; - stream = new FileWriteStream(file, buffer, sizeof(buffer)); + s_stream = new FileWriteStream(s_file, buffer, sizeof(buffer)); - writer = new Writer(*stream); + s_writer = new Writer(*s_stream); - writer->StartObject(); - writer->STRING("traceEvents"); - writer->StartArray(); + s_writer->StartObject(); + s_writer->STRING("traceEvents"); + s_writer->StartArray(); } -void ProfileEvent(i32 tid, i32 pid, const char* name, float64 time, ProfileType type) +void ProfileEvent(i32 tid, i32 pid, const char* name, float64 t, ProfileType type) { - if (!writer) + if (!s_writer) { return; } @@ -174,15 +174,15 @@ void ProfileEvent(i32 tid, i32 pid, const char* name, float64 time, ProfileType float64 scale = 1000.0; - writer->StartObject(); - writer->STRING("pid"); writer->Int(pid); - writer->STRING("tid"); writer->Int(tid); - writer->STRING("ts"); writer->Int64((u64)(time * scale)); - writer->STRING("ph"); writer->String(phase, 1); - writer->STRING("cat"); writer->STRING("physics"); - writer->STRING("name"); writer->String(name, strlen(name)); - writer->STRING("args"); writer->StartObject(); writer->EndObject(); - writer->EndObject(); + s_writer->StartObject(); + s_writer->STRING("pid"); s_writer->Int(pid); + s_writer->STRING("tid"); s_writer->Int(tid); + s_writer->STRING("ts"); s_writer->Int64((u64)(t * scale)); + s_writer->STRING("ph"); s_writer->String(phase, 1); + s_writer->STRING("cat"); s_writer->STRING("physics"); + s_writer->STRING("name"); s_writer->String(name, strlen(name)); + s_writer->STRING("args"); s_writer->StartObject(); s_writer->EndObject(); + s_writer->EndObject(); } void ProfileEvent(i32 tid, i32 pid, const char* name, float64 elapsed) @@ -191,22 +191,22 @@ void ProfileEvent(i32 tid, i32 pid, const char* name, float64 elapsed) void ProfileEndEvents() { - if (!writer) + if (!s_writer) { return; } - writer->EndArray(); - writer->EndObject(); + s_writer->EndArray(); + s_writer->EndObject(); - delete writer; - writer = NULL; + delete s_writer; + s_writer = NULL; - delete stream; - stream = NULL; + delete s_stream; + s_stream = NULL; - fclose(file); - file = NULL; + fclose(s_file); + s_file = NULL; } #undef STRING diff --git a/premake5.lua b/premake5.lua index 69733e1..097f98d 100644 --- a/premake5.lua +++ b/premake5.lua @@ -34,7 +34,7 @@ solution (solution_name) rtti "Off" flags { "FloatFast" } - configuration "release" + configuration "release" targetdir ( solution_dir .. action .. bin_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" ) objdir ( "!" .. solution_dir .. action .. obj_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" ) defines { "NDEBUG" } @@ -48,13 +48,15 @@ solution (solution_name) configuration { "windows" } defines { "_WIN32", "WIN32", "_WINDOWS" } + filter "language:C++" + buildoptions { "-std=c++11" } + project "bounce" kind "StaticLib" language "C++" location ( solution_dir .. action ) includedirs { bounce_inc_dir } - vpaths { [""] = "bounce" } - buildoptions { "-std=c++11" } -- require C++11 + vpaths { [""] = "bounce" } files { @@ -157,7 +159,6 @@ solution (solution_name) location ( solution_dir .. action ) includedirs { external_dir } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } - buildoptions { "-std=c++11" } -- require C++11 files { @@ -171,7 +172,6 @@ solution (solution_name) location ( solution_dir .. action ) includedirs { external_dir } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } - buildoptions { "-std=c++11" } -- require C++11 files { @@ -184,7 +184,6 @@ solution (solution_name) location ( solution_dir .. action ) includedirs { external_dir, bounce_inc_dir, examples_inc_dir } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } - buildoptions { "-std=c++11" } -- GNU/GCC C++11 files { @@ -212,7 +211,6 @@ solution (solution_name) location ( solution_dir .. action ) includedirs { bounce_inc_dir, examples_inc_dir } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } - buildoptions { "-std=c++11" } -- GNU/GCC C++11 files { diff --git a/src/bounce/collision/trees/static_tree.cpp b/src/bounce/collision/trees/static_tree.cpp index d34f8f4..5f3c104 100644 --- a/src/bounce/collision/trees/static_tree.cpp +++ b/src/bounce/collision/trees/static_tree.cpp @@ -32,11 +32,8 @@ b3StaticTree::~b3StaticTree() static B3_FORCE_INLINE bool b3SortPredicate(const b3AABB3* set, u32 axis, u32 a, u32 b) { - const b3AABB3* b1 = set + a; - const b3AABB3* b2 = set + b; - - b3Vec3 c1 = b1->Centroid(); - b3Vec3 c2 = b2->Centroid(); + b3Vec3 c1 = set[a].Centroid(); + b3Vec3 c2 = set[b].Centroid(); return c1[axis] < c2[axis]; } @@ -70,13 +67,16 @@ static void b3Sort(const b3AABB3* set, u32 axis, u32* ids, u32 count) static u32 b3Partition(const b3AABB3& setAABB, const b3AABB3* set, u32* ids, u32 count) { + // Choose a partitioning axis. u32 splitAxis = setAABB.GetLongestAxisIndex(); + + // Choose a split point. float32 splitPos = setAABB.Centroid()[splitAxis]; - // Sort along longest axis + // Sort along the split axis. b3Sort(set, splitAxis, ids, count); - // Find the object that splits the set in two subsets. + // Find the AABB that splits the set in two subsets. u32 left = 0; u32 right = count - 1; u32 middle = left; @@ -91,14 +91,12 @@ static u32 b3Partition(const b3AABB3& setAABB, const b3AABB3* set, u32* ids, u32 ++middle; } - B3_ASSERT(middle >= left); - B3_ASSERT(middle <= right); - // Ensure nonempty subsets. u32 count1 = middle; u32 count2 = count - middle; if (count1 == 0 || count2 == 0) { + // Choose median. middle = (left + right) / 2; } @@ -182,11 +180,6 @@ void b3StaticTree::Build(const b3AABB3* set, u32 count) void b3StaticTree::Draw(b3Draw* draw) const { - b3Color red = b3Color(1.0f, 0.0f, 0.0f, 1.0f); - b3Color green = b3Color(0.0f, 1.0f, 0.0f, 1.0f); - b3Color blue = b3Color(0.0f, 0.0f, 1.0f, 1.0f); - b3Color purple = b3Color(1.0f, 0.0f, 1.0f, 1.0f); - if (m_nodeCount == 0) { return; @@ -206,11 +199,11 @@ void b3StaticTree::Draw(b3Draw* draw) const const b3Node* node = m_nodes + nodeIndex; if (node->IsLeaf()) { - draw->DrawAABB(node->aabb, purple); + draw->DrawAABB(node->aabb, b3Color_pink); } else { - draw->DrawAABB(node->aabb, red); + draw->DrawAABB(node->aabb, b3Color_red); stack.Push(node->child1); stack.Push(node->child2);