Skip to content

Commit

Permalink
v2.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
selimanac committed Jul 16, 2024
1 parent 1f173bd commit 40b4235
Show file tree
Hide file tree
Showing 16 changed files with 1,842 additions and 2,052 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ builtins
/.vscode
.vscode
*.der
*.sublime-project
*.sublime-workspace
compile_commands.json
compile_flags.txt

.clang-format
.clangd
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Open your game.project file and in the dependencies field under project add:

## Release Notes

2.1.3

- Small fix to prevent collision with Defold's build-in box2D lib.

2.1.2

- Internal Update Frequency added. Default value is set from game.project file (display.frequency).
Expand Down
30 changes: 18 additions & 12 deletions daabbcc/include/DynamicTree.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef DynamicTree_hpp
#define DynamicTree_hpp
#pragma once

#include "DynamicTree/b2DynamicTree.h"
#include <dmsdk/dlib/hashtable.h>
Expand All @@ -9,6 +8,7 @@
#define JC_SORT_IMPLEMENTATION
#include "jc/sort.h"

namespace daabbcc {
struct orderResultValues {
int32 proxyID;
float32 distance;
Expand All @@ -19,7 +19,8 @@ class DynamicTree {
DynamicTree();
~DynamicTree();

int m_UpdateFrequency; // = dmConfigFile::GetInt(m_Config, "display.update_frequency", 0);
int m_UpdateFrequency; // = dmConfigFile::GetInt(m_Config,
// "display.update_frequency", 0);
// Add new group
int AddGroup();

Expand All @@ -44,19 +45,23 @@ class DynamicTree {
bool QueryCallback(int32 proxyId, int groupId);

// b2DynamicTree raycast callback
float32 RayCastCallback(const b2RayCastInputAABB &input, int32 proxyId, int groupId);
float32 RayCastCallback(const b2RayCastInputAABB &input, int32 proxyId,
int groupId);

// RayCast to AABB
void RayCast(int groupId, float start_x, float start_y, float end_x, float end_y);
void RayCast(int groupId, float start_x, float start_y, float end_x,
float end_y);

void RayCastSort(int groupId, float start_x, float start_y, float end_x, float end_y);
void RayCastSort(int groupId, float start_x, float start_y, float end_x,
float end_y);

// Query with AABB
void QueryAABB(int groupId, float x, float y, int w, int h);

// Query with ID
void QueryID(int groupId,
int proxyID); // std::vector<int32> QueryID(int groupId, int proxyID);
void
QueryID(int groupId,
int proxyID); // std::vector<int32> QueryID(int groupId, int proxyID);

// Query with ID - Distance Ordered
void QueryIDSort(int groupId, int proxyID);
Expand All @@ -81,7 +86,8 @@ class DynamicTree {

bool isSorted;

void AddGameObject(uint32_t groupID, int32 proxyId, dmGameObject::HInstance instance, int32 w, int32 h);
void AddGameObject(uint32_t groupID, int32 proxyId,
dmGameObject::HInstance instance, int32 w, int32 h);

void GameobjectUpdate();

Expand Down Expand Up @@ -132,13 +138,13 @@ class DynamicTree {
orderResultValues tmpOrder;
dmArray<orderResultValues> tmpOrderResult;

static void IterateRemoveCallback(DynamicTree *context, const uint32_t *key, Groups *value);
static void IterateRemoveCallback(DynamicTree *context, const uint32_t *key,
Groups *value);
void CalcTimeStep(float &step_dt, uint32_t &num_steps);

void DestroyProxyID(int groupId, int proxyID);

// Reset class
void ResetTree();
};

#endif /* DynamicTree_hpp */
} // namespace daabbcc
192 changes: 89 additions & 103 deletions daabbcc/include/DynamicTree/b2Collision.h
Original file line number Diff line number Diff line change
@@ -1,122 +1,108 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

#ifndef B2_COLLISION_H
#define B2_COLLISION_H
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

#pragma once

#include "b2Math.h"

/// Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
struct b2RayCastInputAABB
{
b2Vec2 p1, p2;
float32 maxFraction;
namespace daabbcc {

/// Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 -
/// p1).
struct b2RayCastInputAABB {
b2Vec2 p1, p2;
float32 maxFraction;
};

/// Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2
/// come from b2RayCastInputAABB.
struct b2RayCastOutputAABB
{
b2Vec2 normal;
float32 fraction;
/// Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1
/// and p2 come from b2RayCastInputAABB.
struct b2RayCastOutputAABB {
b2Vec2 normal;
float32 fraction;
};

/// An axis aligned bounding box.
struct b2AABB
{
/// Verify that the bounds are sorted.
bool IsValid() const;

/// Get the center of the AABB.
b2Vec2 GetCenter() const
{
return 0.5f * (lowerBound + upperBound);
}

/// Get the extents of the AABB (half-widths).
b2Vec2 GetExtents() const
{
return 0.5f * (upperBound - lowerBound);
}

/// Get the perimeter length
float32 GetPerimeter() const
{
float32 wx = upperBound.x - lowerBound.x;
float32 wy = upperBound.y - lowerBound.y;
return 2.0f * (wx + wy);
}

/// Combine an AABB into this one.
void Combine(const b2AABB& aabb)
{
lowerBound = b2Min(lowerBound, aabb.lowerBound);
upperBound = b2Max(upperBound, aabb.upperBound);
}

/// Combine two AABBs into this one.
void Combine(const b2AABB& aabb1, const b2AABB& aabb2)
{
lowerBound = b2Min(aabb1.lowerBound, aabb2.lowerBound);
upperBound = b2Max(aabb1.upperBound, aabb2.upperBound);
}

/// Does this aabb contain the provided AABB.
bool Contains(const b2AABB& aabb) const
{
bool result = true;
result = result && lowerBound.x <= aabb.lowerBound.x;
result = result && lowerBound.y <= aabb.lowerBound.y;
result = result && aabb.upperBound.x <= upperBound.x;
result = result && aabb.upperBound.y <= upperBound.y;
return result;
}

bool RayCast(b2RayCastOutputAABB* output, const b2RayCastInputAABB& input) const;

b2Vec2 lowerBound; ///< the lower vertex
b2Vec2 upperBound; ///< the upper vertex
struct b2AABB {
/// Verify that the bounds are sorted.
bool IsValid() const;

/// Get the center of the AABB.
b2Vec2 GetCenter() const { return 0.5f * (lowerBound + upperBound); }

/// Get the extents of the AABB (half-widths).
b2Vec2 GetExtents() const { return 0.5f * (upperBound - lowerBound); }

/// Get the perimeter length
float32 GetPerimeter() const {
float32 wx = upperBound.x - lowerBound.x;
float32 wy = upperBound.y - lowerBound.y;
return 2.0f * (wx + wy);
}

/// Combine an AABB into this one.
void Combine(const b2AABB &aabb) {
lowerBound = b2Min(lowerBound, aabb.lowerBound);
upperBound = b2Max(upperBound, aabb.upperBound);
}

/// Combine two AABBs into this one.
void Combine(const b2AABB &aabb1, const b2AABB &aabb2) {
lowerBound = b2Min(aabb1.lowerBound, aabb2.lowerBound);
upperBound = b2Max(aabb1.upperBound, aabb2.upperBound);
}

/// Does this aabb contain the provided AABB.
bool Contains(const b2AABB &aabb) const {
bool result = true;
result = result && lowerBound.x <= aabb.lowerBound.x;
result = result && lowerBound.y <= aabb.lowerBound.y;
result = result && aabb.upperBound.x <= upperBound.x;
result = result && aabb.upperBound.y <= upperBound.y;
return result;
}

bool RayCast(b2RayCastOutputAABB *output,
const b2RayCastInputAABB &input) const;

b2Vec2 lowerBound; ///< the lower vertex
b2Vec2 upperBound; ///< the upper vertex
};


// ---------------- Inline Functions ------------------------------------------

inline bool b2AABB::IsValid() const
{
b2Vec2 d = upperBound - lowerBound;
bool valid = d.x >= 0.0f && d.y >= 0.0f;
valid = valid && lowerBound.IsValid() && upperBound.IsValid();
return valid;
inline bool b2AABB::IsValid() const {
b2Vec2 d = upperBound - lowerBound;
bool valid = d.x >= 0.0f && d.y >= 0.0f;
valid = valid && lowerBound.IsValid() && upperBound.IsValid();
return valid;
}

inline bool b2TestOverlap(const b2AABB& a, const b2AABB& b)
{
b2Vec2 d1, d2;
d1 = b.lowerBound - a.upperBound;
d2 = a.lowerBound - b.upperBound;
inline bool b2TestOverlap(const b2AABB &a, const b2AABB &b) {
b2Vec2 d1, d2;
d1 = b.lowerBound - a.upperBound;
d2 = a.lowerBound - b.upperBound;

if (d1.x > 0.0f || d1.y > 0.0f)
return false;
if (d1.x > 0.0f || d1.y > 0.0f)
return false;

if (d2.x > 0.0f || d2.y > 0.0f)
return false;
if (d2.x > 0.0f || d2.y > 0.0f)
return false;

return true;
return true;
}

#endif
} // namespace daabbcc
Loading

0 comments on commit 40b4235

Please sign in to comment.