Skip to content

Commit

Permalink
Xcode fixes (#72)
Browse files Browse the repository at this point in the history
`B2_DEBUG`
type conversion
  • Loading branch information
erincatto authored Dec 10, 2023
1 parent 8ae4fae commit d484c6c
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 27 deletions.
6 changes: 6 additions & 0 deletions include/box2d/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#define B2_ZERO_INIT {0}
#endif

#ifdef NDEBUG
#define B2_DEBUG 0
#else
#define B2_DEBUG 1
#endif

#define B2_ARRAY_COUNT(A) (int)(sizeof(A) / sizeof(A[0]))
#define B2_MAYBE_UNUSED(x) ((void)(x))
#define B2_NULL_INDEX (-1)
Expand Down
5 changes: 1 addition & 4 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ set_target_properties(samples PROPERTIES
target_include_directories(samples PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${JSMN_DIR})
target_link_libraries(samples PUBLIC box2d imgui glfw glad enkiTS)

if (${CMAKE_BUILD_TYPE} STREQUAL Debug)
target_compile_definitions(samples PRIVATE _DEBUG)
endif ()

# target_compile_definitions(samples PRIVATE "$<$<CONFIG:DEBUG>:SAMPLES_DEBUG>")
# message(STATUS "runtime = ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
# message(STATUS "binary = ${CMAKE_CURRENT_BINARY_DIR}")

Expand Down
2 changes: 1 addition & 1 deletion samples/collection/sample_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class Sensor : public Sample
Ring* ring = (Ring*)b2Body_GetUserData(ringBodyId);
if (ring != nullptr && ring->valid)
{
int index = ring - m_rings;
int index = (int)(ring - m_rings);
assert(0 <= index && index < e_count);

// Defer destruction to avoid double destruction and event invalidation (orphaned shape ids)
Expand Down
6 changes: 3 additions & 3 deletions samples/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

struct Settings;

#if defined(_DEBUG)
constexpr bool g_sampleDebug = true;
#else
#ifdef NDEBUG
constexpr bool g_sampleDebug = false;
#else
constexpr bool g_sampleDebug = true;
#endif

#define RAND_LIMIT 32767
Expand Down
4 changes: 2 additions & 2 deletions samples/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static bool ReadFile(char*& data, int& size, const char* filename)
}

fseek(file, 0, SEEK_END);
size = ftell(file);
size = (int)ftell(file);
fseek(file, 0, SEEK_SET);

if (size == 0)
Expand Down Expand Up @@ -102,7 +102,7 @@ void Settings::Load()
const char* s = data + tokens[i + 1].start;
strncpy(buffer, s, count);
char* dummy;
m_sampleIndex = strtol(buffer, &dummy, 10);
m_sampleIndex = (int)strtol(buffer, &dummy, 10);
}
else if (jsoneq(data, &tokens[i], "drawShapes") == 0)
{
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ target_include_directories(box2d
)

target_link_libraries(box2d PRIVATE simde)
#target_compile_definitions(box2d PRIVATE "$<$<CONFIG:DEBUG>:B2_DEBUG>")

message(STATUS "CMake C compiler: ${CMAKE_C_COMPILER_ID}")
message(STATUS "CMake C++ compiler: ${CMAKE_CXX_COMPILER_ID}")
Expand All @@ -96,7 +97,7 @@ if (MSVC)
target_compile_options(box2d PRIVATE /W4 /WX /experimental:c11atomics)
target_compile_options(box2d PRIVATE /arch:AVX2)
# target_compile_options(box2d PRIVATE /arch:SSE2)
# target_compile_definitions(box2d PUBLIC "$<$<CONFIG:RELWITHDEBINFO>:B2_ENABLE_ASSERT>")
target_compile_definitions(box2d PUBLIC "$<$<CONFIG:RELWITHDEBINFO>:B2_ENABLE_ASSERT>")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(STATUS "CMake using Clang-CL")
target_compile_options(box2d PRIVATE /W4 /WX /std:c17 /arch:AVX2)
Expand Down
4 changes: 2 additions & 2 deletions src/block_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void* b2AllocBlock(b2BlockAllocator* allocator, int32_t size)

b2Chunk* chunk = allocator->chunks + allocator->chunkCount;
chunk->blocks = (b2Block*)b2Alloc(b2_chunkSize);
#if defined(_DEBUG)
#if B2_DEBUG
memset(chunk->blocks, 0xcd, b2_chunkSize);
#endif
int32_t blockSize = b2_blockSizes[index];
Expand Down Expand Up @@ -194,7 +194,7 @@ void b2FreeBlock(b2BlockAllocator* allocator, void* p, int32_t size)
int32_t index = b2_sizeMap.values[size];
B2_ASSERT(0 <= index && index < b2_blockSizeCount);

#if defined(_DEBUG)
#if B2_DEBUG
// Verify the memory address and size is valid.
int32_t blockSize = b2_blockSizes[index];
bool found = false;
Expand Down
8 changes: 4 additions & 4 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#error Unknown platform
#endif

#if defined(_DEBUG) || defined(B2_ENABLE_ASSERT)
#if !defined(NDEBUG) || defined(B2_ENABLE_ASSERT)
#define B2_ASSERT(condition) \
do \
{ \
Expand All @@ -75,8 +75,8 @@
#define B2_ASSERT(...) ((void)0)
#endif

#if defined(_DEBUG)
#define B2_VALIDATE 1
#else
#if defined(NDEBUG)
#define B2_VALIDATE 0
#else
#define B2_VALIDATE 1
#endif
2 changes: 1 addition & 1 deletion src/dynamic_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ static void b2RotateNodes(b2DynamicTree* tree, int32_t iA)
if (costCE < bestCost)
{
bestRotation = b2_rotateCE;
bestCost = costCE;
// bestCost = costCE;
}

switch (bestRotation)
Expand Down
4 changes: 2 additions & 2 deletions src/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ void b2SolverTask(int32_t startIndex, int32_t endIndex, uint32_t threadIndexDont
B2_ASSERT(stages[stageIndex].type == b2_stagePrepareJoints);
b2ExecuteMainStage(stages + stageIndex, context, syncBits);
stageIndex += 1;
jointSyncIndex += 1;
// jointSyncIndex += 1;

uint32_t constraintSyncIndex = 1;
syncBits = (constraintSyncIndex << 16) | stageIndex;
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void b2SolverTask(int32_t startIndex, int32_t endIndex, uint32_t threadIndexDont
b2ExecuteMainStage(stages + iterStageIndex, context, syncBits);
iterStageIndex += 1;
}
graphSyncIndex += 1;
// graphSyncIndex += 1;

b2ApplyOverflowRestitution(context);
}
Expand Down
6 changes: 3 additions & 3 deletions src/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <stdbool.h>
#include <string.h>

#if _DEBUG
#if B2_DEBUG
int32_t g_probeCount;
#endif

Expand Down Expand Up @@ -91,7 +91,7 @@ static inline uint32_t b2KeyHash(uint64_t key)
return (uint32_t)h;
}

#if _DEBUG
#if B2_DEBUG
int32_t g_probeCount;
#endif

Expand All @@ -102,7 +102,7 @@ int32_t b2FindSlot(const b2HashSet* set, uint64_t key, uint32_t hash)
const b2SetItem* items = set->items;
while (items[index].hash != 0 && items[index].key != key)
{
#if _DEBUG
#if B2_DEBUG
g_probeCount += 1;
#endif
index = (index + 1) & (capacity - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ float b2GetMilliseconds(const b2Timer* timer)
struct timeval t;
gettimeofday(&t, 0);
time_t start_sec = timer->start_sec;
suseconds_t start_usec = timer->start_usec;
suseconds_t start_usec = (suseconds_t)timer->start_usec;

// http://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html
if (t.tv_usec < start_usec)
Expand All @@ -111,7 +111,7 @@ float b2GetMillisecondsAndReset(b2Timer* timer)
struct timeval t;
gettimeofday(&t, 0);
time_t start_sec = timer->start_sec;
suseconds_t start_usec = timer->start_usec;
suseconds_t start_usec = (suseconds_t)timer->start_usec;

// http://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html
if (t.tv_usec < start_usec)
Expand Down
4 changes: 2 additions & 2 deletions test/test_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int TableTest(void)

ENSURE(set.count == (itemCount - removeCount));

#ifdef _DEBUG
#if B2_DEBUG
extern int32_t g_probeCount;
g_probeCount = 0;
#endif
Expand All @@ -80,7 +80,7 @@ int TableTest(void)
float ms = b2GetMilliseconds(&timer);
printf("set: count = %d, b2ContainsKey = %.5f ms, ave = %.5f us\n", itemCount, ms, 1000.0f * ms / itemCount);

#ifdef _DEBUG
#if B2_DEBUG
float aveProbeCount = (float)g_probeCount / (float)itemCount;
printf("item count = %d, probe count = %d, ave probe count %.2f\n", itemCount, g_probeCount, aveProbeCount);
#endif
Expand Down

0 comments on commit d484c6c

Please sign in to comment.