fix issue 26, switch to VS 2017, cleanup

This commit is contained in:
Irlan 2017-07-19 10:58:05 -03:00
parent 8986ea00eb
commit e27deb2868
4 changed files with 70 additions and 83 deletions

View File

@ -3,19 +3,13 @@ Bounce uses premake for generating project files in a platform agnostic manner.
Grab premake from http://industriousone.com/premake. Grab premake from http://industriousone.com/premake.
Put premake into bounce/. 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 Visual Studio 2017
Ensure you have installed the Visual Studio 2015 libraries Ensure you have installed the Visual Studio 2015 libraries
Say { premake5 vs2017 } on a command line. Say { premake5 vs2017 } on a command line.
Open build/vs2017/bounce.sln. Open build/vs2017/bounce.sln.
Set testbed as the startup project. Set testbed as the startup project.
In the testbed debugging properties, set the Working Directory to ..\..\examples\testbed.
Press F5 to run. Press F5 to run.
Linux Linux
@ -30,14 +24,16 @@ x32
Say { premake5 gmake } on a terminal. Say { premake5 gmake } on a terminal.
From build/gmake say { make config="debug_x32" }. From build/gmake say { make config="debug_x32" }.
Set the testbed directory as the working directory
Open testbed from /bin/x32/testbed/. Open testbed from /bin/x32/testbed/.
x64 x64
Say { premake5 gmake } on a terminal. Say { premake5 gmake } on a terminal.
From build/gmake say { make config="debug_x64" }. From build/gmake say { make config="debug_x64" }.
Set the testbed directory as the working directory
Open testbed from /bin/x64/testbed/. Open testbed from /bin/x64/testbed/.
Mac 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.

View File

@ -30,26 +30,26 @@ struct Event
Event* parent; Event* parent;
}; };
static b3Time time; static b3Time s_time;
static b3BoundedQueue<Event, 256> events; static b3BoundedQueue<Event, 256> s_events;
static Event* top = NULL; static Event* s_top = NULL;
bool b3PushProfileScope(const char* name) bool b3PushProfileScope(const char* name)
{ {
time.Update(); s_time.Update();
Event e; Event e;
e.tid = -1; e.tid = -1;
e.pid = -1; e.pid = -1;
e.t0 = time.GetCurrentMilis(); e.t0 = s_time.GetCurrentMilis();
e.t1 = 0; e.t1 = 0;
e.name = name; e.name = name;
e.parent = top; e.parent = s_top;
Event* back = events.Push(e); Event* back = s_events.Push(e);
if (back) if (back)
{ {
top = back; s_top = back;
} }
return back != NULL; return back != NULL;
@ -57,35 +57,35 @@ bool b3PushProfileScope(const char* name)
void b3PopProfileScope() void b3PopProfileScope()
{ {
B3_ASSERT(top); B3_ASSERT(s_top);
B3_ASSERT(top->t1 == 0); B3_ASSERT(s_top->t1 == 0);
time.Update(); s_time.Update();
top->t1 = time.GetCurrentMilis(); s_top->t1 = s_time.GetCurrentMilis();
B3_ASSERT(top->t1 != 0); B3_ASSERT(s_top->t1 != 0);
top = top->parent; s_top = s_top->parent;
} }
void ProfileBegin() void ProfileBegin()
{ {
B3_ASSERT(events.IsEmpty()); B3_ASSERT(s_events.IsEmpty());
} }
void ProfileEnd() void ProfileEnd()
{ {
ProfileBeginEvents(); ProfileBeginEvents();
while (events.IsEmpty() == false) while (s_events.IsEmpty() == false)
{ {
const Event& e = events.Front(); const Event& e = s_events.Front();
events.Pop(); s_events.Pop();
ProfileEvent(e.tid, e.pid, e.name, e.t0, e_begin); 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_end);
ProfileEvent(e.tid, e.pid, e.name, e.t1 - e.t0); ProfileEvent(e.tid, e.pid, e.name, e.t1 - e.t0);
} }
B3_ASSERT(events.IsEmpty()); B3_ASSERT(s_events.IsEmpty());
ProfileEndEvents(); 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; using namespace rapidjson;
static FILE* file = NULL; static FILE* s_file = NULL;
static FileWriteStream* stream = NULL; static FileWriteStream* s_stream = NULL;
static Writer<FileWriteStream>* writer = NULL; static Writer<FileWriteStream>* s_writer = NULL;
#define STRING(x) String(x, sizeof(x) - 1) #define STRING(x) String(x, sizeof(x) - 1)
void ProfileBeginEvents() void ProfileBeginEvents()
{ {
if (file) if (s_file)
{ {
return; return;
} }
file = fopen("profile.json", "wt"); s_file = fopen("profile.json", "wt");
if (!file) if (!s_file)
{ {
return; return;
} }
static char buffer[512]; static char buffer[512];
stream = new FileWriteStream(file, buffer, sizeof(buffer)); s_stream = new FileWriteStream(s_file, buffer, sizeof(buffer));
writer = new Writer<FileWriteStream>(*stream); s_writer = new Writer<FileWriteStream>(*s_stream);
writer->StartObject(); s_writer->StartObject();
writer->STRING("traceEvents"); s_writer->STRING("traceEvents");
writer->StartArray(); 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; return;
} }
@ -174,15 +174,15 @@ void ProfileEvent(i32 tid, i32 pid, const char* name, float64 time, ProfileType
float64 scale = 1000.0; float64 scale = 1000.0;
writer->StartObject(); s_writer->StartObject();
writer->STRING("pid"); writer->Int(pid); s_writer->STRING("pid"); s_writer->Int(pid);
writer->STRING("tid"); writer->Int(tid); s_writer->STRING("tid"); s_writer->Int(tid);
writer->STRING("ts"); writer->Int64((u64)(time * scale)); s_writer->STRING("ts"); s_writer->Int64((u64)(t * scale));
writer->STRING("ph"); writer->String(phase, 1); s_writer->STRING("ph"); s_writer->String(phase, 1);
writer->STRING("cat"); writer->STRING("physics"); s_writer->STRING("cat"); s_writer->STRING("physics");
writer->STRING("name"); writer->String(name, strlen(name)); s_writer->STRING("name"); s_writer->String(name, strlen(name));
writer->STRING("args"); writer->StartObject(); writer->EndObject(); s_writer->STRING("args"); s_writer->StartObject(); s_writer->EndObject();
writer->EndObject(); s_writer->EndObject();
} }
void ProfileEvent(i32 tid, i32 pid, const char* name, float64 elapsed) 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() void ProfileEndEvents()
{ {
if (!writer) if (!s_writer)
{ {
return; return;
} }
writer->EndArray(); s_writer->EndArray();
writer->EndObject(); s_writer->EndObject();
delete writer; delete s_writer;
writer = NULL; s_writer = NULL;
delete stream; delete s_stream;
stream = NULL; s_stream = NULL;
fclose(file); fclose(s_file);
file = NULL; s_file = NULL;
} }
#undef STRING #undef STRING

View File

@ -34,7 +34,7 @@ solution (solution_name)
rtti "Off" rtti "Off"
flags { "FloatFast" } flags { "FloatFast" }
configuration "release" configuration "release"
targetdir ( solution_dir .. action .. bin_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" ) targetdir ( solution_dir .. action .. bin_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" )
objdir ( "!" .. solution_dir .. action .. obj_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" ) objdir ( "!" .. solution_dir .. action .. obj_dir .. "%{cfg.platform}/%{cfg.buildcfg}/%{prj.name}" )
defines { "NDEBUG" } defines { "NDEBUG" }
@ -48,13 +48,15 @@ solution (solution_name)
configuration { "windows" } configuration { "windows" }
defines { "_WIN32", "WIN32", "_WINDOWS" } defines { "_WIN32", "WIN32", "_WINDOWS" }
filter "language:C++"
buildoptions { "-std=c++11" }
project "bounce" project "bounce"
kind "StaticLib" kind "StaticLib"
language "C++" language "C++"
location ( solution_dir .. action ) location ( solution_dir .. action )
includedirs { bounce_inc_dir } includedirs { bounce_inc_dir }
vpaths { [""] = "bounce" } vpaths { [""] = "bounce" }
buildoptions { "-std=c++11" } -- require C++11
files files
{ {
@ -157,7 +159,6 @@ solution (solution_name)
location ( solution_dir .. action ) location ( solution_dir .. action )
includedirs { external_dir } includedirs { external_dir }
vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" }
buildoptions { "-std=c++11" } -- require C++11
files files
{ {
@ -171,7 +172,6 @@ solution (solution_name)
location ( solution_dir .. action ) location ( solution_dir .. action )
includedirs { external_dir } includedirs { external_dir }
vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" }
buildoptions { "-std=c++11" } -- require C++11
files files
{ {
@ -184,7 +184,6 @@ solution (solution_name)
location ( solution_dir .. action ) location ( solution_dir .. action )
includedirs { external_dir, bounce_inc_dir, examples_inc_dir } includedirs { external_dir, bounce_inc_dir, examples_inc_dir }
vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" }
buildoptions { "-std=c++11" } -- GNU/GCC C++11
files files
{ {
@ -212,7 +211,6 @@ solution (solution_name)
location ( solution_dir .. action ) location ( solution_dir .. action )
includedirs { bounce_inc_dir, examples_inc_dir } includedirs { bounce_inc_dir, examples_inc_dir }
vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" } vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" }
buildoptions { "-std=c++11" } -- GNU/GCC C++11
files files
{ {

View File

@ -32,11 +32,8 @@ b3StaticTree::~b3StaticTree()
static B3_FORCE_INLINE bool b3SortPredicate(const b3AABB3* set, u32 axis, u32 a, u32 b) static B3_FORCE_INLINE bool b3SortPredicate(const b3AABB3* set, u32 axis, u32 a, u32 b)
{ {
const b3AABB3* b1 = set + a; b3Vec3 c1 = set[a].Centroid();
const b3AABB3* b2 = set + b; b3Vec3 c2 = set[b].Centroid();
b3Vec3 c1 = b1->Centroid();
b3Vec3 c2 = b2->Centroid();
return c1[axis] < c2[axis]; 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) static u32 b3Partition(const b3AABB3& setAABB, const b3AABB3* set, u32* ids, u32 count)
{ {
// Choose a partitioning axis.
u32 splitAxis = setAABB.GetLongestAxisIndex(); u32 splitAxis = setAABB.GetLongestAxisIndex();
// Choose a split point.
float32 splitPos = setAABB.Centroid()[splitAxis]; float32 splitPos = setAABB.Centroid()[splitAxis];
// Sort along longest axis // Sort along the split axis.
b3Sort(set, splitAxis, ids, count); 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 left = 0;
u32 right = count - 1; u32 right = count - 1;
u32 middle = left; u32 middle = left;
@ -91,14 +91,12 @@ static u32 b3Partition(const b3AABB3& setAABB, const b3AABB3* set, u32* ids, u32
++middle; ++middle;
} }
B3_ASSERT(middle >= left);
B3_ASSERT(middle <= right);
// Ensure nonempty subsets. // Ensure nonempty subsets.
u32 count1 = middle; u32 count1 = middle;
u32 count2 = count - middle; u32 count2 = count - middle;
if (count1 == 0 || count2 == 0) if (count1 == 0 || count2 == 0)
{ {
// Choose median.
middle = (left + right) / 2; middle = (left + right) / 2;
} }
@ -182,11 +180,6 @@ void b3StaticTree::Build(const b3AABB3* set, u32 count)
void b3StaticTree::Draw(b3Draw* draw) const 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) if (m_nodeCount == 0)
{ {
return; return;
@ -206,11 +199,11 @@ void b3StaticTree::Draw(b3Draw* draw) const
const b3Node* node = m_nodes + nodeIndex; const b3Node* node = m_nodes + nodeIndex;
if (node->IsLeaf()) if (node->IsLeaf())
{ {
draw->DrawAABB(node->aabb, purple); draw->DrawAABB(node->aabb, b3Color_pink);
} }
else else
{ {
draw->DrawAABB(node->aabb, red); draw->DrawAABB(node->aabb, b3Color_red);
stack.Push(node->child1); stack.Push(node->child1);
stack.Push(node->child2); stack.Push(node->child2);