Skip to content

Commit

Permalink
user_constants.h is now unused by default
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Dec 29, 2023
1 parent 57a5798 commit 2c7ac5b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ project(box2d
# message(STATUS "CMake C++ compiler: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMake system name: ${CMAKE_SYSTEM_NAME}")

set(BOX2D_LENGTH_UNIT_PER_METER "1.0" CACHE STRING "Length units per meter")
set(BOX2D_MAX_POLYGON_VERTICES "8" CACHE STRING "Maximum number of polygon vertices (affects performance)")
option(BOX2D_USER_CONSTANTS "Generate user_constants.h" OFF)

if (BOX2D_USER_CONSTANTS)
set(BOX2D_LENGTH_UNIT_PER_METER "1.0" CACHE STRING "Length units per meter")
set(BOX2D_MAX_POLYGON_VERTICES "8" CACHE STRING "Maximum number of polygon vertices (affects performance)")
endif()

# Needed for samples.exe to find box2d.dll
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
Expand Down
10 changes: 5 additions & 5 deletions include/box2d/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
/// Although most of these are not user configurable, it can be interesting for a user to see
/// these to understand the tuning values Box2D uses.

// todo move constraint hertz/damping here

#include "user_constants.h"
#ifdef BOX2D_USER_CONSTANTS
#include "user_constants.h"
#endif

/// box2d bases all length units on meters, but you may need different units for your game.
/// You can override this value to use different units.
#ifndef b2_lengthUnitsPerMeter
#define b2_lengthUnitsPerMeter 1.0f
#define b2_lengthUnitsPerMeter 1.0f
#endif

/// https://en.wikipedia.org/wiki/Pi
Expand All @@ -44,7 +44,7 @@
/// The maximum number of vertices on a convex polygon. Changing this affects performance even if you
/// don't use more vertices.
#ifndef b2_maxPolygonVertices
#define b2_maxPolygonVertices 8
#define b2_maxPolygonVertices 8
#endif

/// Maximum number of simultaneous worlds that can be allocated
Expand Down
21 changes: 9 additions & 12 deletions include/box2d/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@
#include <stddef.h>
#include <stdint.h>

// clang-format off
#ifdef __cplusplus
#define B2_LITERAL(T) T
#define B2_ZERO_INIT \
{ \
}
#define B2_LITERAL(T) T
#define B2_ZERO_INIT {}
#else
/// Used for C literals like (b2Vec2){1.0f, 2.0f} where C++ requires b2Vec2{1.0f, 2.0f}
#define B2_LITERAL(T) (T)

/// Used for C zero initialization, such as b2Vec2 v = {0} where C++ requires b2Vec2 v = {}
#define B2_ZERO_INIT \
{ \
0 \
}
/// Used for C literals like (b2Vec2){1.0f, 2.0f} where C++ requires b2Vec2{1.0f, 2.0f}
#define B2_LITERAL(T) (T)

/// Used for C zero initialization, such as b2Vec2 v = {0} where C++ requires b2Vec2 v = {}
#define B2_ZERO_INIT {0}
#endif
// clang-format on

/// Returns the number of elements of an array
#define B2_ARRAY_COUNT(A) (int)(sizeof(A) / sizeof(A[0]))
Expand Down
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
configure_file(user_constants.h.in user_constants.h)

set(BOX2D_SOURCE_FILES
aabb.c
aabb.h
Expand Down Expand Up @@ -87,6 +85,12 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

add_library(box2d ${BOX2D_SOURCE_FILES} ${BOX2D_API_FILES})

if (BOX2D_USER_CONSTANTS)
# this file allows users to override constants
configure_file(user_constants.h.in user_constants.h)
target_compile_definitions(box2d PUBLIC BOX2D_USER_CONSTANTS)
endif()

# Generate box2d_export.h to handles shared library builds
# turned this off to make Box2D easier to use without cmake
# include(GenerateExportHeader)
Expand Down

0 comments on commit 2c7ac5b

Please sign in to comment.