Compare commits
2 Commits
941eeb2493
...
bugfix/phy
| Author | SHA1 | Date | |
|---|---|---|---|
|
115f3bad62
|
|||
|
52d7bca677
|
@@ -69,8 +69,6 @@ add_library(akgl SHARED
|
|||||||
src/heap.c
|
src/heap.c
|
||||||
src/json_helpers.c
|
src/json_helpers.c
|
||||||
src/registry.c
|
src/registry.c
|
||||||
src/renderer.c
|
|
||||||
src/physics.c
|
|
||||||
src/sprite.c
|
src/sprite.c
|
||||||
src/staticstring.c
|
src/staticstring.c
|
||||||
src/tilemap.c
|
src/tilemap.c
|
||||||
@@ -144,8 +142,6 @@ install(FILES "include/akgl/controller.h" DESTINATION "include/akgl/")
|
|||||||
install(FILES "include/akgl/heap.h" DESTINATION "include/akgl/")
|
install(FILES "include/akgl/heap.h" DESTINATION "include/akgl/")
|
||||||
install(FILES "include/akgl/iterator.h" DESTINATION "include/akgl/")
|
install(FILES "include/akgl/iterator.h" DESTINATION "include/akgl/")
|
||||||
install(FILES "include/akgl/json_helpers.h" DESTINATION "include/akgl/")
|
install(FILES "include/akgl/json_helpers.h" DESTINATION "include/akgl/")
|
||||||
install(FILES "include/akgl/renderer.h" DESTINATION "include/akgl/")
|
|
||||||
install(FILES "include/akgl/physics.h" DESTINATION "include/akgl/")
|
|
||||||
install(FILES "include/akgl/registry.h" DESTINATION "include/akgl/")
|
install(FILES "include/akgl/registry.h" DESTINATION "include/akgl/")
|
||||||
install(FILES "include/akgl/sprite.h" DESTINATION "include/akgl/")
|
install(FILES "include/akgl/sprite.h" DESTINATION "include/akgl/")
|
||||||
install(FILES "include/akgl/staticstring.h" DESTINATION "include/akgl/")
|
install(FILES "include/akgl/staticstring.h" DESTINATION "include/akgl/")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef _SDL_GAMECONTROLLERDB_H_
|
#ifndef _SDL_GAMECONTROLLERDB_H_
|
||||||
#define _SDL_GAMECONTROLLERDB_H_
|
#define _SDL_GAMECONTROLLERDB_H_
|
||||||
|
|
||||||
// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Tue May 26 04:12:10 PM EDT 2026
|
// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Tue May 26 01:00:21 PM EDT 2026
|
||||||
|
|
||||||
#define AKGL_SDL_GAMECONTROLLER_DB_LEN 2228
|
#define AKGL_SDL_GAMECONTROLLER_DB_LEN 2228
|
||||||
|
|
||||||
|
|||||||
@@ -76,25 +76,16 @@ typedef struct akgl_Actor {
|
|||||||
float32_t vx;
|
float32_t vx;
|
||||||
float32_t vy;
|
float32_t vy;
|
||||||
float32_t vz;
|
float32_t vz;
|
||||||
// Environmental velocity. These are the forces acting on the actor by the
|
// Gravity. Forces acting on the actor on a given axis due to the forces
|
||||||
// environment (such as gravity and atmospheric drag)
|
// of gravity and drag.
|
||||||
float32_t ex;
|
float32_t gx;
|
||||||
float32_t ey;
|
float32_t gy;
|
||||||
float32_t ez;
|
float32_t gz;
|
||||||
// Thrust. Energy originating only from the actor's own acceleration on a
|
// Thrust. Energy originating only from the actor's own acceleration on a
|
||||||
// given axis, before the effects of gravity and drag.
|
// given axis, before the effects of gravity and drag.
|
||||||
float32_t tx;
|
float32_t tx;
|
||||||
float32_t ty;
|
float32_t ty;
|
||||||
float32_t tz;
|
float32_t tz;
|
||||||
// Acceleration. These are borrowed from the base character object.
|
|
||||||
// A given axis resets to 0 when the actor stops moving in a given axis.
|
|
||||||
float32_t ax;
|
|
||||||
float32_t ay;
|
|
||||||
float32_t az;
|
|
||||||
// Max speed. These are borrowed from the base character object.
|
|
||||||
float32_t sx;
|
|
||||||
float32_t sy;
|
|
||||||
float32_t sz;
|
|
||||||
// Position.
|
// Position.
|
||||||
float32_t x;
|
float32_t x;
|
||||||
float32_t y;
|
float32_t y;
|
||||||
|
|||||||
45
src/actor.c
45
src/actor.c
@@ -51,10 +51,6 @@ akerr_ErrorContext *akgl_actor_set_character(akgl_Actor *obj, char *basecharname
|
|||||||
obj->basechar = SDL_GetPointerProperty(AKGL_REGISTRY_CHARACTER, basecharname, NULL);
|
obj->basechar = SDL_GetPointerProperty(AKGL_REGISTRY_CHARACTER, basecharname, NULL);
|
||||||
|
|
||||||
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Character not found in the registry");
|
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "Character not found in the registry");
|
||||||
obj->ax = 0;
|
|
||||||
obj->ay = 0;
|
|
||||||
obj->sx = obj->basechar->sx;
|
|
||||||
obj->sy = obj->basechar->sy;
|
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,25 +113,14 @@ akerr_ErrorContext *akgl_actor_logic_changeframe(akgl_Actor *obj, akgl_Sprite *c
|
|||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// raises AKGL_ERR_LOGICINTERRUPT if we don't want the physics simulator to process us
|
// raises AKGL_ERR_LOGICINTERRUPT if we don't want the physics object to process us
|
||||||
akerr_ErrorContext *akgl_actor_logic_movement(akgl_Actor *actor, float32_t dt)
|
akerr_ErrorContext *akgl_actor_logic_movement(akgl_Actor *obj, float32_t dt)
|
||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
FAIL_ZERO_RETURN(errctx, actor, AKERR_NULLPOINTER, "actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "obj");
|
||||||
FAIL_ZERO_RETURN(errctx, actor, AKERR_NULLPOINTER, "actor->basechar");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "obj->basechar");
|
||||||
actor->sx = actor->basechar->sx;
|
// Effectively a NOOP, this is handled by the physics engine now
|
||||||
actor->sy = actor->basechar->sy;
|
// These functions are still present in case the library user wants per-actor behavior
|
||||||
actor->sz = actor->basechar->sz;
|
|
||||||
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_LEFT) ) {
|
|
||||||
actor->ax = -actor->basechar->ax;
|
|
||||||
} else if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_RIGHT) ) {
|
|
||||||
actor->ax = actor->basechar->ax;
|
|
||||||
}
|
|
||||||
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_UP) ) {
|
|
||||||
actor->ay = -actor->basechar->ay;
|
|
||||||
} else if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_DOWN) ) {
|
|
||||||
actor->ay = actor->basechar->ay;
|
|
||||||
}
|
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,12 +262,10 @@ akerr_ErrorContext *akgl_actor_add_child(akgl_Actor *obj, akgl_Actor *child)
|
|||||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_left_on(akgl_Actor *obj, SDL_Event *event)
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_left_on(akgl_Actor *obj, SDL_Event *event)
|
||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "actor->basechar");
|
|
||||||
//SDL_Log("event %d (button %d / key %d) moves actor left", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) moves actor left", event->type, event->gbutton.which, event->key.key);
|
||||||
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
||||||
obj->ax = -(obj->basechar->ax);
|
|
||||||
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_LEFT | AKGL_ACTOR_STATE_FACE_LEFT));
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_LEFT | AKGL_ACTOR_STATE_FACE_LEFT));
|
||||||
//SDL_Log("new target actor state: %b", obj->state);
|
//SDL_Log("new target actor state: %b", obj->state);
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
@@ -294,8 +277,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_left_off(akgl_Actor *obj, SDL
|
|||||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
//SDL_Log("event %d (button %d / key %d) stops moving actor left", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) stops moving actor left", event->type, event->gbutton.which, event->key.key);
|
||||||
obj->ax = 0;
|
|
||||||
obj->ex = 0;
|
|
||||||
obj->tx = 0;
|
obj->tx = 0;
|
||||||
obj->vx = 0;
|
obj->vx = 0;
|
||||||
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_LEFT);
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_LEFT);
|
||||||
@@ -308,9 +289,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_right_on(akgl_Actor *obj, SDL
|
|||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
FAIL_ZERO_RETURN(errctx, obj->basechar, AKERR_NULLPOINTER, "actor->basechar");
|
|
||||||
//SDL_Log("event %d (button %d / key %d) moves actor right", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) moves actor right", event->type, event->gbutton.which, event->key.key);
|
||||||
obj->ax = obj->basechar->ax;
|
|
||||||
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
||||||
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_RIGHT | AKGL_ACTOR_STATE_FACE_RIGHT));
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_RIGHT | AKGL_ACTOR_STATE_FACE_RIGHT));
|
||||||
//SDL_Log("new target actor state: %b", obj->state);
|
//SDL_Log("new target actor state: %b", obj->state);
|
||||||
@@ -323,8 +302,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_right_off(akgl_Actor *obj, SD
|
|||||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
//SDL_Log("event %d (button %d / key %d) stops moving actor right", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) stops moving actor right", event->type, event->gbutton.which, event->key.key);
|
||||||
obj->ax = 0;
|
|
||||||
obj->ex = 0;
|
|
||||||
obj->tx = 0;
|
obj->tx = 0;
|
||||||
obj->vx = 0;
|
obj->vx = 0;
|
||||||
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_RIGHT);
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_RIGHT);
|
||||||
@@ -338,7 +315,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_up_on(akgl_Actor *obj, SDL_Ev
|
|||||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
//SDL_Log("event %d (button %d / key %d) moves actor up", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) moves actor up", event->type, event->gbutton.which, event->key.key);
|
||||||
obj->ay = -(obj->basechar->ay);
|
|
||||||
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
||||||
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_FACE_UP | AKGL_ACTOR_STATE_MOVING_UP));
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_FACE_UP | AKGL_ACTOR_STATE_MOVING_UP));
|
||||||
//SDL_Log("new target actor state: %b", obj->state);
|
//SDL_Log("new target actor state: %b", obj->state);
|
||||||
@@ -351,8 +327,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_up_off(akgl_Actor *obj, SDL_E
|
|||||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
//SDL_Log("event %d (button %d / key %d) stops moving actor up", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) stops moving actor up", event->type, event->gbutton.which, event->key.key);
|
||||||
obj->ay = 0;
|
|
||||||
obj->ey = 0;
|
|
||||||
obj->ty = 0;
|
obj->ty = 0;
|
||||||
obj->vy = 0;
|
obj->vy = 0;
|
||||||
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_UP);
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_UP);
|
||||||
@@ -366,7 +340,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_down_on(akgl_Actor *obj, SDL_
|
|||||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor");
|
||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
//SDL_Log("event %d (button %d / key %d) moves actor down", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) moves actor down", event->type, event->gbutton.which, event->key.key);
|
||||||
obj->ay = obj->basechar->ay;
|
|
||||||
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
AKGL_BITMASK_DEL(obj->state, (AKGL_ACTOR_STATE_FACE_ALL | AKGL_ACTOR_STATE_MOVING_ALL));
|
||||||
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_DOWN | AKGL_ACTOR_STATE_FACE_DOWN));
|
AKGL_BITMASK_ADD(obj->state, (AKGL_ACTOR_STATE_MOVING_DOWN | AKGL_ACTOR_STATE_FACE_DOWN));
|
||||||
//SDL_Log("new target actor state: %b", obj->state);
|
//SDL_Log("new target actor state: %b", obj->state);
|
||||||
@@ -380,8 +353,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_down_off(akgl_Actor *obj, SDL
|
|||||||
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
FAIL_ZERO_RETURN(errctx, event, AKERR_NULLPOINTER, "NULL event");
|
||||||
//SDL_Log("event %d (button %d / key %d) stops moving actor down", event->type, event->gbutton.which, event->key.key);
|
//SDL_Log("event %d (button %d / key %d) stops moving actor down", event->type, event->gbutton.which, event->key.key);
|
||||||
obj->ty = 0;
|
obj->ty = 0;
|
||||||
obj->ey = 0;
|
|
||||||
obj->ay = 0;
|
|
||||||
obj->vy = 0;
|
obj->vy = 0;
|
||||||
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_DOWN);
|
AKGL_BITMASK_DEL(obj->state, AKGL_ACTOR_STATE_MOVING_DOWN);
|
||||||
//SDL_Log("new target actor state: %b", obj->state);
|
//SDL_Log("new target actor state: %b", obj->state);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <math.h>
|
|
||||||
#include <akstdlib.h>
|
#include <akstdlib.h>
|
||||||
#include <akgl/physics.h>
|
#include <akgl/physics.h>
|
||||||
#include <akgl/actor.h>
|
#include <akgl/actor.h>
|
||||||
@@ -49,11 +48,16 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_ss_gravity(akgl_PhysicsBackend *
|
|||||||
FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor");
|
FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor");
|
||||||
|
|
||||||
// Assume the X origin is - (screen left)
|
// Assume the X origin is - (screen left)
|
||||||
actor->ex -= (self->gravity_x * dt);
|
actor->gx -= (self->gravity_x * dt);
|
||||||
// Assume Y origin is + (down screen)
|
// Assume Y origin is + (down screen)
|
||||||
actor->ey += (self->gravity_y * dt);
|
actor->gy += (self->gravity_y * dt);
|
||||||
// Assume Z origin is - (behind the camera)
|
// Assume Z origin is - (behind the camera)
|
||||||
actor->ez -= (self->gravity_z * dt);
|
actor->gz -= (self->gravity_z * dt);
|
||||||
|
|
||||||
|
// Counteract velocity with atmospheric drag
|
||||||
|
actor->gx += actor->vx * self->drag_x * dt;
|
||||||
|
actor->gy -= actor->vy * self->drag_y * dt;
|
||||||
|
actor->gz += actor->vz * self->drag_z * dt;
|
||||||
|
|
||||||
SUCCEED_RETURN(e);
|
SUCCEED_RETURN(e);
|
||||||
}
|
}
|
||||||
@@ -71,9 +75,19 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_ss_move(struct akgl_PhysicsBacke
|
|||||||
PREPARE_ERROR(e);
|
PREPARE_ERROR(e);
|
||||||
FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self");
|
FAIL_ZERO_RETURN(e, self, AKERR_NULLPOINTER, "self");
|
||||||
FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor");
|
FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "actor");
|
||||||
actor->x += actor->vx * dt;
|
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_LEFT) ) {
|
||||||
actor->y += actor->vy * dt;
|
actor->x += (-actor->vx * dt) + (actor->gx * dt);
|
||||||
actor->z += actor->vz * dt;
|
}
|
||||||
|
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_RIGHT) ) {
|
||||||
|
actor->x += (actor->vx * dt) + (actor->gx * dt);
|
||||||
|
}
|
||||||
|
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_UP) ) {
|
||||||
|
actor->y += (-actor->vy * dt) + (actor->gy * dt);
|
||||||
|
}
|
||||||
|
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_DOWN) ) {
|
||||||
|
actor->y += (actor->vy * dt) + (actor->gy * dt);
|
||||||
|
}
|
||||||
|
|
||||||
SUCCEED_RETURN(e);
|
SUCCEED_RETURN(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,9 +150,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_simulate(akgl_PhysicsBackend *se
|
|||||||
}
|
}
|
||||||
if ( actor->parent != NULL ) {
|
if ( actor->parent != NULL ) {
|
||||||
// Children don't move independently of their parents, they just have an offset
|
// Children don't move independently of their parents, they just have an offset
|
||||||
actor->x = actor->parent->x + actor->vx;
|
|
||||||
actor->y = actor->parent->y + actor->vy;
|
|
||||||
actor->z = actor->parent->z + actor->vz;
|
|
||||||
continue;
|
continue;
|
||||||
} else if ( actor->basechar == NULL ) {
|
} else if ( actor->basechar == NULL ) {
|
||||||
continue;
|
continue;
|
||||||
@@ -148,52 +159,28 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_simulate(akgl_PhysicsBackend *se
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// thrust is a function of acceleration on a given axis
|
|
||||||
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_LEFT) ||
|
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_LEFT) ||
|
||||||
AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_RIGHT) ) {
|
AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_RIGHT) ) {
|
||||||
actor->tx += actor->ax * dt;
|
actor->tx += actor->basechar->ax * dt;
|
||||||
}
|
}
|
||||||
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_UP) ||
|
if ( AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_UP) ||
|
||||||
AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_DOWN) ) {
|
AKGL_BITMASK_HAS(actor->state, AKGL_ACTOR_STATE_MOVING_DOWN) ) {
|
||||||
actor->ty += actor->ay * dt;
|
actor->ty += actor->basechar->ay * dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// velocity equals thrust unless thrust exceeds max speed
|
// velocity equals thrust unless thrust exceeds max speed
|
||||||
if ( fabsf(actor->tx) > fabsf(actor->sx) ) {
|
if ( actor->tx > actor->basechar->sx ) {
|
||||||
if ( actor->tx < 0 ) {
|
actor->vx = actor->basechar->sx;
|
||||||
actor->tx = -actor->sx;
|
|
||||||
} else {
|
} else {
|
||||||
actor->tx = actor->sx;
|
actor->vx = actor->tx;
|
||||||
}
|
}
|
||||||
}
|
if ( actor->ty > actor->basechar->sy ) {
|
||||||
if ( fabsf(actor->ty) > fabsf(actor->sy) ) {
|
actor->vy = actor->basechar->sy;
|
||||||
if ( actor->ty < 0 ) {
|
|
||||||
actor->ty = -actor->sy;
|
|
||||||
} else {
|
} else {
|
||||||
actor->ty = actor->sy;
|
actor->vy = actor->ty;
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( fabsf(actor->tz) > fabsf(actor->sz) ) {
|
|
||||||
if ( actor->tz < 0 ) {
|
|
||||||
actor->tz = -actor->sz;
|
|
||||||
} else {
|
|
||||||
actor->tz = actor->sz;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ATTEMPT {
|
ATTEMPT {
|
||||||
CATCH(e, actor->movementlogicfunc(actor, dt));
|
CATCH(e, actor->movementlogicfunc(actor, dt));
|
||||||
PASS(e, self->gravity(self, actor, dt));
|
PASS(e, self->gravity(self, actor, dt));
|
||||||
|
|
||||||
// Counteract velocity with atmospheric drag
|
|
||||||
actor->ex -= actor->ex * self->drag_x * dt;
|
|
||||||
actor->ey -= actor->ey * self->drag_y * dt;
|
|
||||||
actor->ez -= actor->ez * self->drag_z * dt;
|
|
||||||
|
|
||||||
actor->vx = actor->ex + actor->tx;
|
|
||||||
actor->vy = actor->ey + actor->ty;
|
|
||||||
actor->vz = actor->ez + actor->tz;
|
|
||||||
|
|
||||||
PASS(e, self->move(self, actor, dt));
|
PASS(e, self->move(self, actor, dt));
|
||||||
} CLEANUP {
|
} CLEANUP {
|
||||||
} PROCESS(e) {
|
} PROCESS(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user