mirror of https://github.com/bjornbytes/lovr.git
Fix early exit logic for raycast & querySphere
This commit is contained in:
parent
a4dc1d9ffb
commit
91e586bbd4
|
@ -63,11 +63,11 @@ typedef struct {
|
||||||
bool should_stop;
|
bool should_stop;
|
||||||
} RaycastData;
|
} RaycastData;
|
||||||
|
|
||||||
static void raycastCallback(void* data, dGeomID a, dGeomID b) {
|
static void raycastCallback(void* d, dGeomID a, dGeomID b) {
|
||||||
if (((RaycastData*)data)->should_stop) return;
|
RaycastData* data = d;
|
||||||
|
if (data->should_stop) return;
|
||||||
RaycastCallback callback = ((RaycastData*) data)->callback;
|
RaycastCallback callback = data->callback;
|
||||||
void* userdata = ((RaycastData*) data)->userdata;
|
void* userdata = data->userdata;
|
||||||
Shape* shape = dGeomGetData(b);
|
Shape* shape = dGeomGetData(b);
|
||||||
|
|
||||||
if (!shape) {
|
if (!shape) {
|
||||||
|
@ -78,7 +78,9 @@ static void raycastCallback(void* data, dGeomID a, dGeomID b) {
|
||||||
int count = dCollide(a, b, MAX_CONTACTS, &contact->geom, sizeof(dContact));
|
int count = dCollide(a, b, MAX_CONTACTS, &contact->geom, sizeof(dContact));
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
dContactGeom g = contact[i].geom;
|
dContactGeom g = contact[i].geom;
|
||||||
callback(shape, g.pos[0], g.pos[1], g.pos[2], g.normal[0], g.normal[1], g.normal[2], userdata);
|
data->should_stop = callback(
|
||||||
|
shape, g.pos[0], g.pos[1], g.pos[2], g.normal[0], g.normal[1], g.normal[2], userdata
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,15 +92,14 @@ typedef struct {
|
||||||
} QueryData;
|
} QueryData;
|
||||||
|
|
||||||
static void queryCallback(void* d, dGeomID a, dGeomID b) {
|
static void queryCallback(void* d, dGeomID a, dGeomID b) {
|
||||||
if (((QueryData*)d)->should_stop) return;
|
QueryData* data = d;
|
||||||
Shape* shape = dGeomGetData(b);
|
if (data->should_stop) return;
|
||||||
|
|
||||||
|
Shape* shape = dGeomGetData(b);
|
||||||
if (!shape) {
|
if (!shape) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryData* data = d;
|
|
||||||
|
|
||||||
dContactGeom contact;
|
dContactGeom contact;
|
||||||
if (dCollide(a, b, 1 | CONTACTS_UNIMPORTANT, &contact, sizeof(contact))) {
|
if (dCollide(a, b, 1 | CONTACTS_UNIMPORTANT, &contact, sizeof(contact))) {
|
||||||
if (data->callback) {
|
if (data->callback) {
|
||||||
|
@ -327,7 +328,7 @@ bool lovrWorldQueryBox(World* world, float position[3], float size[3], QueryCall
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lovrWorldQuerySphere(World* world, float position[3], float radius, QueryCallback callback, void* userdata) {
|
bool lovrWorldQuerySphere(World* world, float position[3], float radius, QueryCallback callback, void* userdata) {
|
||||||
QueryData data = { .callback = callback, .userdata = userdata, .called = false };
|
QueryData data = { .callback = callback, .userdata = userdata, .called = false, .should_stop = false };
|
||||||
dGeomID sphere = dCreateSphere(world->space, fabsf(radius));
|
dGeomID sphere = dCreateSphere(world->space, fabsf(radius));
|
||||||
dGeomSetPosition(sphere, position[0], position[1], position[2]);
|
dGeomSetPosition(sphere, position[0], position[1], position[2]);
|
||||||
dSpaceCollide2(sphere, (dGeomID) world->space, &data, queryCallback);
|
dSpaceCollide2(sphere, (dGeomID) world->space, &data, queryCallback);
|
||||||
|
|
Loading…
Reference in New Issue