Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
PhysicsContext.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
4
6
7std::vector<float> g_raycastBuffer;
8std::vector<float> g_overlapBuffer;
9std::vector<float> g_shapeCastBuffer;
10float g_massDataBuffer[2] = {};
11
12b2JointId findValidJoint(uint32_t entityId) {
13 auto it = g_ctx.entityToJoint.find(entityId);
14 if (it == g_ctx.entityToJoint.end()) return b2_nullJointId;
15 if (!b2Joint_IsValid(it->second)) return b2_nullJointId;
16 return it->second;
17}
18
19b2BodyId findValidBody(uint32_t entityId) {
20 auto it = g_ctx.entityToBody.find(entityId);
21 if (it == g_ctx.entityToBody.end()) return b2_nullBodyId;
22 if (!b2Body_IsValid(it->second)) return b2_nullBodyId;
23 return it->second;
24}
25
26uint32_t entityFromBody(b2BodyId bodyId) {
27 void* ud = b2Body_GetUserData(bodyId);
28 if (!ud) return 0xFFFFFFFF;
29 return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(ud));
30}
31
32uint32_t entityFromShape(b2ShapeId shapeId) {
33 b2BodyId bodyId = b2Shape_GetBody(shapeId);
34 return entityFromBody(bodyId);
35}
36
37void pushEntityBits(std::vector<float>& buf, uint32_t entityId) {
38 float bits;
39 std::memcpy(&bits, &entityId, sizeof(float));
40 buf.push_back(bits);
41}
b2JointId findValidJoint(uint32_t entityId)
float g_massDataBuffer[2]
uint32_t entityFromBody(b2BodyId bodyId)
PhysicsContext g_ctx
std::vector< float > g_shapeCastBuffer
uint32_t entityFromShape(b2ShapeId shapeId)
void pushEntityBits(std::vector< float > &buf, uint32_t entityId)
std::vector< float > g_raycastBuffer
std::vector< float > g_overlapBuffer
b2BodyId findValidBody(uint32_t entityId)