2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @file physics.h
|
|
|
|
|
* @brief Declares the public physics API.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-05-26 10:36:31 -04:00
|
|
|
#ifndef _PHYSICS_H_
|
|
|
|
|
#define _PHYSICS_H_
|
|
|
|
|
|
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
|
#include <akerror.h>
|
|
|
|
|
#include <akgl/actor.h>
|
|
|
|
|
#include <akgl/iterator.h>
|
2026-06-02 17:11:16 -04:00
|
|
|
#include <akgl/staticstring.h>
|
2026-05-26 10:36:31 -04:00
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/** @brief Defines a pluggable physics backend and its environmental parameters. */
|
2026-05-26 10:36:31 -04:00
|
|
|
typedef struct akgl_PhysicsBackend {
|
|
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *(*simulate)(struct akgl_PhysicsBackend *self, akgl_Iterator *opflags);
|
2026-05-26 11:22:45 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *(*gravity)(struct akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt);
|
2026-05-26 10:36:31 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *(*collide)(struct akgl_PhysicsBackend *self, akgl_Actor *a1, akgl_Actor *a2);
|
2026-05-26 11:22:45 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *(*move)(struct akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt);
|
2026-05-26 10:36:31 -04:00
|
|
|
|
|
|
|
|
double drag_x;
|
|
|
|
|
double drag_y;
|
|
|
|
|
double drag_z;
|
|
|
|
|
double gravity_x;
|
|
|
|
|
double gravity_y;
|
|
|
|
|
double gravity_z;
|
|
|
|
|
SDL_Time gravity_time;
|
Reindent all C sources to the canonical stroustrup style
Mechanical whitespace-only change across src/, include/, tests/, and
util/, applied with scripts/reindent.sh. No behavioral change.
Most files already conformed. The genuine outliers indented at 2 columns
(json_helpers.c, util.c from akgl_rectangle_points onward, assets.c,
staticstring.c, akgl_actor_add_child, util.h, staticstring.h) or used
spaces where the canonical form is a tab (draw.c). cc-mode also re-aligns
line-continuation backslashes in multi-line macros to its default
c-backslash-column, which is required for the tree to be a fixed point of
the indenter.
Verified whitespace-only: `git diff -w` over this change is empty apart
from three trailing blank lines removed at EOF in src/heap.c,
src/registry.c, and tests/tilemap.c. The build produces no new errors and
ctest is unchanged at 13/14, with `character` still the one intentional
failure.
The tree is now a fixed point of `scripts/reindent.sh --check`.
include/akgl/SDL_GameControllerDB.h is generated and excluded.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 18:17:37 -04:00
|
|
|
SDL_Time timer_gravity;
|
2026-05-26 10:36:31 -04:00
|
|
|
} akgl_PhysicsBackend;
|
|
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics null gravity.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param actor Actor to inspect or modify.
|
|
|
|
|
* @param dt Elapsed simulation time in seconds.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-26 11:22:45 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_null_gravity(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics null collide.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param a1 First actor supplied to collision handling.
|
|
|
|
|
* @param a2 Second actor supplied to collision handling.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-26 10:36:31 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_null_collide(akgl_PhysicsBackend *self, akgl_Actor *a1, akgl_Actor *a2);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics null move.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param actor Actor to inspect or modify.
|
|
|
|
|
* @param dt Elapsed simulation time in seconds.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-26 11:22:45 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_null_move(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics init null.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-26 10:36:31 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_init_null(akgl_PhysicsBackend *self);
|
|
|
|
|
|
|
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics arcade gravity.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param actor Actor to inspect or modify.
|
|
|
|
|
* @param dt Elapsed simulation time in seconds.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-06-02 13:15:26 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_arcade_gravity(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics arcade collide.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param a1 First actor supplied to collision handling.
|
|
|
|
|
* @param a2 Second actor supplied to collision handling.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_API When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-06-02 13:15:26 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_arcade_collide(akgl_PhysicsBackend *self, akgl_Actor *a1, akgl_Actor *a2);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics arcade move.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param actor Actor to inspect or modify.
|
|
|
|
|
* @param dt Elapsed simulation time in seconds.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-06-02 13:15:26 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_arcade_move(akgl_PhysicsBackend *self, akgl_Actor *actor, float32_t dt);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics init arcade.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-06-02 13:15:26 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_init_arcade(akgl_PhysicsBackend *self);
|
|
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics factory.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param type Expected JSON property type or backend type name.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_KEY When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-06-02 17:11:16 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_factory(akgl_PhysicsBackend *self, akgl_String *type);
|
2026-05-26 10:36:31 -04:00
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Physics simulate.
|
|
|
|
|
* @param self Backend or object instance to operate on.
|
|
|
|
|
* @param opflags Optional iterator operation flags; `NULL` selects defaults.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKGL_ERR_LOGICINTERRUPT When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-26 10:36:31 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_physics_simulate(akgl_PhysicsBackend *self, akgl_Iterator *opflags);
|
|
|
|
|
|
|
|
|
|
#endif // _PHYSICS_H_
|