Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
entity.h File Reference

Entities: the things of a level that live (barrels that explode, trigger zones, relays, doors, enemies...). They are read from a level (sections ENTI, PROP and LINK, see Documentation/level_format.md). More...

#include "level.h"

Go to the source code of this file.

Data Structures

struct  jo_entity_class
 Class of entities: its callbacks (JO_NULL: nothing to do). More...
struct  __jo_entity
 An entity. More...
struct  jo_actor
 Data of an actor (the first member of the data of a class of actors). More...

Macros

#define JO_ENTITY_MAX
 Entities at most (they are allocated with their count when a level is loaded).
#define JO_ENTITY_MAX_CLASSES
 Classes at most (the engine uses 8).
#define JO_ENTITY_MAX_PENDING
 Actions waiting for their delay at most.
#define JO_ENTITY_MAX_MODELS
 Different models of the entities at most (the models of the classes too: the things broken, the pieces).
#define JO_ENTITY_WAKE_DISTANCE
 The entities farther from the player are not updated (world units), unless they wait for something (timer), see jo_entities_set_wake().
#define JO_ENTITY_DRAW_DISTANCE
 The models of the entities farther are not drawn (world units), see the property draw_distance.
#define JO_ENTITY_FAR_DISTANCE
 The far model of the entities is drawn farther (world units), see the properties far_model and far_distance.
#define JO_ENTITY_FLAG_DISABLED
 Flags of an entity: the ones of the level (ENTITY_FLAG_xxx of the schema).
#define JO_ENTITY_FLAG_SOLID
 A solid entity (the collisions, the bullets): set it with jo_entity_set_solid(); set in the flags directly, it is solid from the next jo_entities_update() (the collisions read a list of the solid entities).
#define JO_ENTITY_FLAG_HIDDEN
#define JO_ENTITY_FLAG_DEAD
 Flags of an entity: the state.
#define JO_ENTITY_FLAG_PLAYER_INSIDE
#define JO_ENTITY_FLAG_DOORWAY
 Flag of an entity set by its class: in a doorway between 2 cells (a door), drawn when one of the cells around it (its position +- its radius on X and Z) is drawn (its position alone: a cell hidden behind the door closed).

Typedefs

typedef struct __jo_entity jo_entity
typedef void(*) jo_entity_area_damage_callback(const jo_pos3D_fixed *const center, const int radius, const int damage, jo_entity *const source)
 Damage around a point given to the game (the player is not an entity).
typedef void(*) jo_actor_bone_callback(jo_entity *const entity, const int bone, const jo_fixed(*const matrix)[3])
 Called when an actor is drawn, after each bone (a weapon in a hand, a muzzle flash).
typedef typedef __attribute__
 16 bits word of any memory (see __jo_uint32_alias)

Functions

struct __jo_entity __attribute__ ((aligned(16)))
void jo_entity_register_class (const jo_entity_class *const cls)
 Register a class of the game (before jo_entities_load()).
void jo_entity_class_set_parallel_draw (const jo_entity_class *const cls, const bool parallel)
 Let the master CPU draw the entities of a class (its draw callback) while the slave CPU draws others of the same class (its draw_slave callback), see jo_entities_draw().
int jo_entities_load (jo_level *const level)
 Create the entities of a level (sections ENTI, PROP, LINK): the previous ones are freed.
void jo_entities_free (void)
 Free the entities (and their models).
void jo_entities_update (const jo_pos3D_fixed *const player, const int elapsed)
 Update the entities: the delayed actions, the classes, the trigger zones.
void jo_entities_set_wake (const int distance, const bool when_seen)
 The entities updated by jo_entities_update(): the ones that wait for something (timer > 0), the ones near the player, and the ones seen.
void jo_entities_prepare_draw (const int slave_share)
 Prepare the drawing of the entities of the frame (the camera matrix is the current matrix, see jo_3d_set_depth_bias()): the ones seen, their tint (the light of the lamps, see jo_3d_point_lights_sample()), the share of the slave CPU (see jo_entities_draw_slave()). Before jo_3d_slave_begin() and the job of the slave CPU.
int jo_entities_draw (void)
 Draw the entities of the master CPU (the camera matrix is the current matrix, see jo_3d_set_depth_bias()).
int jo_entities_draw_slave (void)
 Draw the entities of the slave CPU (call it on the slave CPU, in the job between jo_3d_slave_begin() and jo_3d_slave_end(), see jo_entities_prepare_draw()): first the ones with a draw_slave callback, then the models.
int jo_entities_slave_wait_time (void)
 Time the master CPU waited for the entities of the slave CPU in the last frame (see jo_entities_draw()).
int jo_entities_test_counts (const int which)
int jo_entities_polygon_count (const bool slave)
 Polygons of the entities of a CPU in the frame (see jo_entities_prepare_draw(): the polygons of their models, plus 8 each), to balance the CPUs.
int jo_entity_count (void)
 Number of entities.
jo_entity * jo_entity_get (const int index)
 An entity.
jo_entity * jo_entity_find (const char *const name)
 Find an entity by its name.
void jo_entity_send (jo_entity *const target, const int action, const int param, jo_entity *const source)
 Send an action to an entity now.
void jo_entity_fire (jo_entity *const source, const int event, const int param)
 Fire an event of an entity: its links send their actions (now or after their delay).
void jo_entity_damage (jo_entity *const entity, const int damage, jo_entity *const source)
 Damage an entity: EVENT_DAMAGE, or the death (class death(), EVENT_DEATH) when its health reaches 0.
void jo_entities_damage_area (const jo_pos3D_fixed *const center, const int radius, const int damage, jo_entity *const source)
 Damage everything around a point: the entities (their foot) and the game (see jo_entities_set_area_damage_callback()).
void jo_entities_set_area_damage_callback (const jo_entity_area_damage_callback callback)
 Give the damage around a point to the game (the player).
jo_entity * jo_entities_ray_hit (const jo_pos3D_fixed *const origin, const jo_pos3D_fixed *const dir, const jo_fixed max_t, jo_fixed *const t, jo_pos3D_fixed *const normal)
 First solid entity hit by a ray (its cylinder).
bool jo_entities_is_blocked (const jo_fixed x, const jo_fixed z, const int radius)
 Check if a circle on the ground is in a solid entity (collisions of the player).
bool jo_entities_is_blocked_at (const jo_fixed x, const jo_fixed y, const jo_fixed z, const int radius, const int height, const jo_entity *const except)
 Like jo_entities_is_blocked(), with the heights: a solid entity blocks only a body at its level (a low piece of furniture doesn't block the player in a duct over it).
void jo_entity_set_solid (jo_entity *const entity, const bool solid)
 Make an entity solid or not (see JO_ENTITY_FLAG_SOLID).
jo_entity * jo_entities_get_blocking (const jo_fixed x, const jo_fixed z, const int radius, const jo_entity *const except)
 The solid entity in a circle on the ground (collisions of a vehicle).
int jo_entity_get_int (const jo_entity *const entity, const char *const key, const int default_value)
 Property of an entity (PROP).
jo_fixed jo_entity_get_fixed (const jo_entity *const entity, const char *const key, const jo_fixed default_value)
const char * jo_entity_get_string (const jo_entity *const entity, const char *const key, const char *const default_value)
bool jo_entities_get_zone_request (const char **const level, const char **const spawn)
 Change of level asked by an entity zone_link (the player went in it): the game fades the screen, loads the level (jo_entities_load(), jo_cells_load()...), puts the player on the entity spawn, then calls jo_entities_clear_zone_request().
void jo_entities_clear_zone_request (void)
 The change of level is done (see jo_entities_get_zone_request()).
jo_3d_mesh * jo_entity_load_model (const char *const filename)
 Load a model for the entities (loaded once: shared by all the entities).
jo_3d_model * jo_entity_get_model (const char *const filename)
 Load a model for the entities (loaded once: shared by all the entities).
void jo_entity_set_mesh (jo_entity *const entity, jo_3d_mesh *const mesh)
 Change the model of an entity (the dead model of an explosive...).
int jo_entity_view_distance (const jo_entity *const entity)
 Check if the model of an entity is drawn (near enough, in the view).
void jo_entities_set_lod_scale (const int scale)
 A magnified view (binoculars, a sniper scope): the entities are drawn and detailed as far as they look.
int jo_entity_turn_to (jo_entity *const entity, const jo_fixed x, const jo_fixed z, const int max_step)
 Turn an entity toward a point on the ground (its model looks toward +Z turned by its yaw: the direction (sin yaw, cos yaw)).
void jo_actor_spawn (jo_entity *const entity)
 Create the actor of an entity: its model (the model of the entity, it has a skeleton), the animation of its property animation ("idle" by default).
void jo_actor_set_shadow (jo_entity *const entity, const int radius)
 The shadow of an actor on the ground: a dark disc under its position (its feet), drawn with its model by jo_actor_draw() and jo_actor_draw_slave() (the VDP1 darkens the pixels under it: 1 to 3 commands).
void jo_actor_update (jo_entity *const entity, const int elapsed)
 Advance the animation of an actor.
void jo_actor_draw (jo_entity *const entity)
 Draw an actor (its model in the pose of its animation) at its position, turned by its yaw.
void jo_actor_draw_slave (jo_entity *const entity, const int far_distance, const unsigned int hidden_bones)
 Draw an actor on the slave CPU (call it on the slave CPU, see jo_entities_draw_slave()): its model in the pose of its animation at its position, turned by its yaw, with the distance and the tint prepared (see jo_entities_prepare_draw()).
bool jo_actor_play (jo_entity *const entity, const char *const name, const int blend)
 Play an animation (nothing if it is already played).
bool jo_actor_restart (jo_entity *const entity, const char *const name, const int blend)
 Play an animation again from its start.
bool jo_actor_is_done (const jo_entity *const entity)
 Check if the animation of an actor is at its end (the last key of an animation that doesn't loop).
bool jo_actor_is_playing (const jo_entity *const entity, const char *const name)
 Check which animation an actor plays.

Variables

unsigned int flags
jo_pos3D_fixed position
int radius
int height
short box_x
short box_z
int yaw
const jo_entity_class * cls
const char * name
int health
jo_3d_mesh * mesh
jo_3d_mesh * far_mesh
jo_pos3D_fixed center
int mesh_radius
int far_distance
int draw_distance
int timer
int state
void * data
unsigned short first_prop
unsigned short prop_count
unsigned short first_link
unsigned short link_count
jo_pos3D_fixed cell_position
short cells [5]
unsigned short cell_generation
short view_distance
unsigned short tint
jo_fixed center_dy

Detailed Description

Entities: the things of a level that live (barrels that explode, trigger zones, relays, doors, enemies...). They are read from a level (sections ENTI, PROP and LINK, see Documentation/level_format.md).

Author
Johannes Fetz
Remarks
With the file system and the 3D modules (and JO_COMPILE_WITH_EFFECTS_MODULE = 1 for the fire, the smoke, the flash and the shake of the explosions, see effects.h)
  • An entity has a class: its behavior. The engine has the generic classes (explosive, trigger, relay...), the game registers its own classes with jo_entity_register_class() before jo_entities_load()
  • Events and actions: when something happens to an entity (EVENT_DEATH, EVENT_ENTER...), the links of the level send actions to other entities (ACTION_DAMAGE, ACTION_TRIGGER...), with a delay. The game doesn't wire anything
  • Damage: health, EVENT_DAMAGE, EVENT_DEATH, damage around a point (the explosions damage the other barrels: chain reactions); the damage of the player is given to the game (jo_entities_set_area_damage_callback())
  • Only the entities near the player (or that wait for something) are updated

Data Structure Documentation

◆ __jo_entity

struct __jo_entity

An entity.

Data Fields
short box_x
short box_z
unsigned short cell_generation
jo_pos3D_fixed cell_position
short cells[5]
jo_pos3D_fixed center
jo_fixed center_dy
const jo_entity_class * cls
void * data
int draw_distance
int far_distance
jo_3d_mesh * far_mesh
unsigned short first_link
unsigned short first_prop
unsigned int flags
int health
int height
unsigned short link_count
jo_3d_mesh * mesh
int mesh_radius
const char * name
jo_pos3D_fixed position
unsigned short prop_count
int radius
int state
int timer
unsigned short tint
short view_distance
int yaw

◆ jo_actor

struct jo_actor

Data of an actor (the first member of the data of a class of actors).

Data Fields
short animation
int blend
int blend_duration
jo_actor_bone_callback bone_callback
jo_3d_model * far_model
jo_3d_model * model
short previous
int previous_time
int shadow_radius
int time

Macro Definition Documentation

◆ JO_ENTITY_DRAW_DISTANCE

#define JO_ENTITY_DRAW_DISTANCE

The models of the entities farther are not drawn (world units), see the property draw_distance.

◆ JO_ENTITY_FAR_DISTANCE

#define JO_ENTITY_FAR_DISTANCE

The far model of the entities is drawn farther (world units), see the properties far_model and far_distance.

◆ JO_ENTITY_FLAG_DEAD

#define JO_ENTITY_FLAG_DEAD

Flags of an entity: the state.

◆ JO_ENTITY_FLAG_DISABLED

#define JO_ENTITY_FLAG_DISABLED

Flags of an entity: the ones of the level (ENTITY_FLAG_xxx of the schema).

◆ JO_ENTITY_FLAG_DOORWAY

#define JO_ENTITY_FLAG_DOORWAY

Flag of an entity set by its class: in a doorway between 2 cells (a door), drawn when one of the cells around it (its position +- its radius on X and Z) is drawn (its position alone: a cell hidden behind the door closed).

◆ JO_ENTITY_FLAG_HIDDEN

#define JO_ENTITY_FLAG_HIDDEN

◆ JO_ENTITY_FLAG_PLAYER_INSIDE

#define JO_ENTITY_FLAG_PLAYER_INSIDE

◆ JO_ENTITY_FLAG_SOLID

#define JO_ENTITY_FLAG_SOLID

A solid entity (the collisions, the bullets): set it with jo_entity_set_solid(); set in the flags directly, it is solid from the next jo_entities_update() (the collisions read a list of the solid entities).

◆ JO_ENTITY_MAX

#define JO_ENTITY_MAX

Entities at most (they are allocated with their count when a level is loaded).

◆ JO_ENTITY_MAX_CLASSES

#define JO_ENTITY_MAX_CLASSES

Classes at most (the engine uses 8).

◆ JO_ENTITY_MAX_MODELS

#define JO_ENTITY_MAX_MODELS

Different models of the entities at most (the models of the classes too: the things broken, the pieces).

◆ JO_ENTITY_MAX_PENDING

#define JO_ENTITY_MAX_PENDING

Actions waiting for their delay at most.

◆ JO_ENTITY_WAKE_DISTANCE

#define JO_ENTITY_WAKE_DISTANCE

The entities farther from the player are not updated (world units), unless they wait for something (timer), see jo_entities_set_wake().

Typedef Documentation

◆ __attribute__

struct __attribute__

16 bits word of any memory (see __jo_uint32_alias)

Raw image struct.

Remarks
Accessed as jo_img or jo_img_8bits (may alias)

◆ jo_actor_bone_callback

typedef void(*) jo_actor_bone_callback(jo_entity *const entity, const int bone, const jo_fixed(*const matrix)[3])

Called when an actor is drawn, after each bone (a weapon in a hand, a muzzle flash).

Parameters
entityThe actor
boneIndex of the bone
matrixMatrix of the bone (see jo_3d_transform_point_by())

◆ jo_entity

typedef struct __jo_entity jo_entity

◆ jo_entity_area_damage_callback

typedef void(*) jo_entity_area_damage_callback(const jo_pos3D_fixed *const center, const int radius, const int damage, jo_entity *const source)

Damage around a point given to the game (the player is not an entity).

Parameters
centerCenter (world space)
radiusRadius (world units)
damageDamage at the center (less farther, 0 at the radius)
sourceEntity that made it (JO_NULL: the game)

Function Documentation

◆ __attribute__()

struct __jo_entity __attribute__ ( (aligned(16)) )

◆ jo_actor_draw()

void jo_actor_draw ( jo_entity *const entity)

Draw an actor (its model in the pose of its animation) at its position, turned by its yaw.

Parameters
entityEntity

◆ jo_actor_draw_slave()

void jo_actor_draw_slave ( jo_entity *const entity,
const int far_distance,
const unsigned int hidden_bones )

Draw an actor on the slave CPU (call it on the slave CPU, see jo_entities_draw_slave()): its model in the pose of its animation at its position, turned by its yaw, with the distance and the tint prepared (see jo_entities_prepare_draw()).

Parameters
entityEntity
far_distanceThe far model farther (world units, on the ground), -1: the one of the entity
hidden_bonesBones not drawn (bits, see jo_3d_model_set_hidden_bones())

◆ jo_actor_is_done()

bool jo_actor_is_done ( const jo_entity *const entity)

Check if the animation of an actor is at its end (the last key of an animation that doesn't loop).

Parameters
entityEntity
Returns
true at the end (a loop: never)

◆ jo_actor_is_playing()

bool jo_actor_is_playing ( const jo_entity *const entity,
const char *const name )

Check which animation an actor plays.

Parameters
entityEntity
nameName of the animation
Returns
true if it plays it

◆ jo_actor_play()

bool jo_actor_play ( jo_entity *const entity,
const char *const name,
const int blend )

Play an animation (nothing if it is already played).

Parameters
entityEntity
nameName of the animation
blendMilliseconds of the change (blend from the previous pose), 0: at once
Returns
false if the model doesn't have this animation

◆ jo_actor_restart()

bool jo_actor_restart ( jo_entity *const entity,
const char *const name,
const int blend )

Play an animation again from its start.

Parameters
entityEntity
nameName of the animation
blendMilliseconds of the change
Returns
false if the model doesn't have this animation

◆ jo_actor_set_shadow()

void jo_actor_set_shadow ( jo_entity *const entity,
const int radius )

The shadow of an actor on the ground: a dark disc under its position (its feet), drawn with its model by jo_actor_draw() and jo_actor_draw_slave() (the VDP1 darkens the pixels under it: 1 to 3 commands).

Parameters
entityThe actor
radiusRadius (world units), 0: none (the property shadow of the entity, 0 by default)

◆ jo_actor_spawn()

void jo_actor_spawn ( jo_entity *const entity)

Create the actor of an entity: its model (the model of the entity, it has a skeleton), the animation of its property animation ("idle" by default).

Parameters
entityEntity (its data starts with a jo_actor)

◆ jo_actor_update()

void jo_actor_update ( jo_entity *const entity,
const int elapsed )

Advance the animation of an actor.

Parameters
entityEntity
elapsedMilliseconds

◆ jo_entities_clear_zone_request()

void jo_entities_clear_zone_request ( void )

The change of level is done (see jo_entities_get_zone_request()).

◆ jo_entities_damage_area()

void jo_entities_damage_area ( const jo_pos3D_fixed *const center,
const int radius,
const int damage,
jo_entity *const source )

Damage everything around a point: the entities (their foot) and the game (see jo_entities_set_area_damage_callback()).

Parameters
centerCenter (world space)
radiusRadius (world units)
damageDamage at the center (less farther, 0 at the radius)
sourceEntity that made it (it isn't damaged), JO_NULL: the game

◆ jo_entities_draw()

int jo_entities_draw ( void )

Draw the entities of the master CPU (the camera matrix is the current matrix, see jo_3d_set_depth_bias()).

Returns
Number of entities drawn
Remarks
The entities with a draw callback are drawn after the ones of the slave CPU with a draw_slave callback (the master CPU waits for them: the callbacks of a class share its data, the faces of the characters), but the ones of a class drawn in parallel (see jo_entity_class_set_parallel_draw()): drawn first, while the slave CPU draws

◆ jo_entities_draw_slave()

int jo_entities_draw_slave ( void )

Draw the entities of the slave CPU (call it on the slave CPU, in the job between jo_3d_slave_begin() and jo_3d_slave_end(), see jo_entities_prepare_draw()): first the ones with a draw_slave callback, then the models.

Returns
Number of entities drawn

◆ jo_entities_free()

void jo_entities_free ( void )

Free the entities (and their models).

◆ jo_entities_get_blocking()

jo_entity * jo_entities_get_blocking ( const jo_fixed x,
const jo_fixed z,
const int radius,
const jo_entity *const except )

The solid entity in a circle on the ground (collisions of a vehicle).

Parameters
xCenter (world space)
zCenter
radiusRadius (world units)
exceptEntity not checked (the vehicle itself), JO_NULL: none
Returns
The first entity found, JO_NULL: none

◆ jo_entities_get_zone_request()

bool jo_entities_get_zone_request ( const char **const level,
const char **const spawn )

Change of level asked by an entity zone_link (the player went in it): the game fades the screen, loads the level (jo_entities_load(), jo_cells_load()...), puts the player on the entity spawn, then calls jo_entities_clear_zone_request().

Parameters
levelJOL file of the level (output, valid until the next request)
spawnName of the entity of the level where the player appears (output, "": the game chooses)
Returns
true if a change of level is asked

◆ jo_entities_is_blocked()

bool jo_entities_is_blocked ( const jo_fixed x,
const jo_fixed z,
const int radius )

Check if a circle on the ground is in a solid entity (collisions of the player).

Parameters
xCenter (world space)
zCenter
radiusRadius (world units)
Returns
true if it is blocked

◆ jo_entities_is_blocked_at()

bool jo_entities_is_blocked_at ( const jo_fixed x,
const jo_fixed y,
const jo_fixed z,
const int radius,
const int height,
const jo_entity *const except )

Like jo_entities_is_blocked(), with the heights: a solid entity blocks only a body at its level (a low piece of furniture doesn't block the player in a duct over it).

Parameters
xPosition of the feet
yPosition of the feet (Saturn Y: down)
zPosition of the feet
radiusRadius of the body (world units)
heightHeight of the body (world units)
exceptEntity not checked (the body itself), JO_NULL: none
Returns
true if a solid entity is in the way (the entity goes from its feet up to its height)

◆ jo_entities_load()

int jo_entities_load ( jo_level *const level)

Create the entities of a level (sections ENTI, PROP, LINK): the previous ones are freed.

Parameters
levelLevel (it can be freed after: what the entities need is copied)
Returns
Number of entities
Remarks
The models are loaded (jo_3d_load_model()), the classes spawn their entities. An unknown class: the entity only draws its model (the name of the class is printed with JO_DEBUG)

◆ jo_entities_polygon_count()

int jo_entities_polygon_count ( const bool slave)

Polygons of the entities of a CPU in the frame (see jo_entities_prepare_draw(): the polygons of their models, plus 8 each), to balance the CPUs.

Parameters
slavefalse: the master CPU, true: the slave CPU
Returns
Polygons

◆ jo_entities_prepare_draw()

void jo_entities_prepare_draw ( const int slave_share)

Prepare the drawing of the entities of the frame (the camera matrix is the current matrix, see jo_3d_set_depth_bias()): the ones seen, their tint (the light of the lamps, see jo_3d_point_lights_sample()), the share of the slave CPU (see jo_entities_draw_slave()). Before jo_3d_slave_begin() and the job of the slave CPU.

Parameters
slave_shareShare of the cost of the entities drawn by the slave CPU (0 to 1024, 0: all by the master CPU): the entities with a draw_slave callback or without draw callback, the others stay on the master CPU
Remarks
Without it, jo_entities_draw() prepares the frame with everything on the master CPU

◆ jo_entities_ray_hit()

jo_entity * jo_entities_ray_hit ( const jo_pos3D_fixed *const origin,
const jo_pos3D_fixed *const dir,
const jo_fixed max_t,
jo_fixed *const t,
jo_pos3D_fixed *const normal )

First solid entity hit by a ray (its cylinder).

Parameters
originOrigin (world space)
dirDirection (unit vector, Q16.16)
max_tLength of the ray (world units, Q16.16)
tDistance of the hit (output, Q16.16)
normalNormal of the cylinder at the hit (output, unit vector)
Returns
The entity, JO_NULL if nothing is hit

◆ jo_entities_set_area_damage_callback()

void jo_entities_set_area_damage_callback ( const jo_entity_area_damage_callback callback)

Give the damage around a point to the game (the player).

Parameters
callbackCallback, JO_NULL: none

◆ jo_entities_set_lod_scale()

void jo_entities_set_lod_scale ( const int scale)

A magnified view (binoculars, a sniper scope): the entities are drawn and detailed as far as they look.

Parameters
scaleThe magnification (1: normal): the distances of jo_entity_view_distance() are divided by it

◆ jo_entities_set_wake()

void jo_entities_set_wake ( const int distance,
const bool when_seen )

The entities updated by jo_entities_update(): the ones that wait for something (timer > 0), the ones near the player, and the ones seen.

Parameters
distanceNearer than it on X and Z, from the edge of their cylinder (world units, JO_ENTITY_WAKE_DISTANCE by default; 0: none by the distance)
when_seentrue: also the ones drawn in the last frame (in a cell seen, in the view: see jo_entities_prepare_draw()), false by default. With a short distance, the entities behind the walls sleep (less CPU): their class wakes them by their timer (a noise, an alarm)

◆ jo_entities_slave_wait_time()

int jo_entities_slave_wait_time ( void )

Time the master CPU waited for the entities of the slave CPU in the last frame (see jo_entities_draw()).

Returns
Microseconds

◆ jo_entities_test_counts()

int jo_entities_test_counts ( const int which)

◆ jo_entities_update()

void jo_entities_update ( const jo_pos3D_fixed *const player,
const int elapsed )

Update the entities: the delayed actions, the classes, the trigger zones.

Parameters
playerPosition of the player (foot, world space)
elapsedTime since the last update (milliseconds)

◆ jo_entity_class_set_parallel_draw()

void jo_entity_class_set_parallel_draw ( const jo_entity_class *const cls,
const bool parallel )

Let the master CPU draw the entities of a class (its draw callback) while the slave CPU draws others of the same class (its draw_slave callback), see jo_entities_draw().

Parameters
clsClass (registered or not)
paralleltrue: the 2 callbacks don't share data that they change while they draw (each one only reads the class data, or writes the data of its own entity), false (default): the master CPU waits until the slave CPU has drawn all its entities with a draw_slave callback before it draws them
Remarks
Without it, the characters of a crowd are drawn one CPU after the other: the master CPU waited 15 ms for the slave CPU in front of 9 characters (28 frames per second instead of 30), whatever the share of each CPU
The actors of the class "actor" of the engine without bone callback are always drawn in parallel

◆ jo_entity_count()

int jo_entity_count ( void )

Number of entities.

◆ jo_entity_damage()

void jo_entity_damage ( jo_entity *const entity,
const int damage,
jo_entity *const source )

Damage an entity: EVENT_DAMAGE, or the death (class death(), EVENT_DEATH) when its health reaches 0.

Parameters
entityEntity (nothing if it is dead, disabled or can't be damaged)
damageDamage
sourceEntity that did it (JO_NULL: the game, the player)

◆ jo_entity_find()

jo_entity * jo_entity_find ( const char *const name)

Find an entity by its name.

Returns
The entity, JO_NULL if there is none

◆ jo_entity_fire()

void jo_entity_fire ( jo_entity *const source,
const int event,
const int param )

Fire an event of an entity: its links send their actions (now or after their delay).

Parameters
sourceEntity
eventJO_LEVEL_EVENT_xxx
paramParameter (given to the actions of the links with the parameter -1)

◆ jo_entity_get()

jo_entity * jo_entity_get ( const int index)

An entity.

Parameters
indexIndex (0 to jo_entity_count() - 1: the order of the level)

◆ jo_entity_get_fixed()

jo_fixed jo_entity_get_fixed ( const jo_entity *const entity,
const char *const key,
const jo_fixed default_value )

◆ jo_entity_get_int()

int jo_entity_get_int ( const jo_entity *const entity,
const char *const key,
const int default_value )

Property of an entity (PROP).

Parameters
entityEntity
keyName
default_valueValue when the entity doesn't have it
Returns
The value (an INT property read as fixed is converted, and the opposite)

◆ jo_entity_get_model()

jo_3d_model * jo_entity_get_model ( const char *const filename)

Load a model for the entities (loaded once: shared by all the entities).

Parameters
filenameJOM file
Returns
The model, JO_NULL if it can't be loaded

◆ jo_entity_get_string()

const char * jo_entity_get_string ( const jo_entity *const entity,
const char *const key,
const char *const default_value )

◆ jo_entity_load_model()

jo_3d_mesh * jo_entity_load_model ( const char *const filename)

Load a model for the entities (loaded once: shared by all the entities).

Parameters
filenameJOM file
Returns
Its mesh, JO_NULL if it can't be loaded

◆ jo_entity_register_class()

void jo_entity_register_class ( const jo_entity_class *const cls)

Register a class of the game (before jo_entities_load()).

Parameters
clsClass (it must stay in memory). A class with the name of a class of the engine replaces it

◆ jo_entity_send()

void jo_entity_send ( jo_entity *const target,
const int action,
const int param,
jo_entity *const source )

Send an action to an entity now.

Parameters
targetTarget
actionJO_LEVEL_ACTION_xxx (or an action of the game: from 100)
paramParameter (the damage of DAMAGE)
sourceEntity that sent it (JO_NULL: the game)
Remarks
If the class doesn't do it: TRIGGER and USE fire the event TRIGGER, DAMAGE damages, KILL kills, ENABLE, DISABLE and TOGGLE change JO_ENTITY_FLAG_DISABLED. A disabled entity ignores the other actions

◆ jo_entity_set_mesh()

void jo_entity_set_mesh ( jo_entity *const entity,
jo_3d_mesh *const mesh )

Change the model of an entity (the dead model of an explosive...).

Parameters
entityEntity
meshMesh (JO_NULL: none)
Remarks
The far model is not used any more (see the property far_model)

◆ jo_entity_set_solid()

void jo_entity_set_solid ( jo_entity *const entity,
const bool solid )

Make an entity solid or not (see JO_ENTITY_FLAG_SOLID).

Parameters
entityEntity
solidtrue: solid

◆ jo_entity_turn_to()

int jo_entity_turn_to ( jo_entity *const entity,
const jo_fixed x,
const jo_fixed z,
const int max_step )

Turn an entity toward a point on the ground (its model looks toward +Z turned by its yaw: the direction (sin yaw, cos yaw)).

Parameters
entityEntity
xPoint (world space)
zPoint
max_stepThe most it turns (degrees)
Returns
The angle left (degrees, 0 to 180)

◆ jo_entity_view_distance()

int jo_entity_view_distance ( const jo_entity *const entity)

Check if the model of an entity is drawn (near enough, in the view).

Parameters
entityEntity
Returns
Distance from the player on the ground (world units), -1: not drawn
Remarks
For the draw callback of the classes (the camera matrix is the current matrix)

Variable Documentation

◆ box_x

short box_x

◆ box_z

short box_z

◆ cell_generation

unsigned short cell_generation

◆ cell_position

jo_pos3D_fixed cell_position

◆ cells

short cells[5]

◆ center

◆ center_dy

jo_fixed center_dy

◆ cls

const jo_entity_class* cls

◆ data

void* data

◆ draw_distance

int draw_distance

◆ far_distance

int far_distance

◆ far_mesh

jo_3d_mesh* far_mesh

◆ first_link

unsigned short first_link

◆ first_prop

unsigned short first_prop

◆ flags

unsigned int flags

◆ health

int health

◆ height

int height

◆ link_count

unsigned short link_count

◆ mesh

jo_3d_mesh* mesh

◆ mesh_radius

int mesh_radius

◆ name

const char* name

◆ position

jo_pos3D_fixed position

◆ prop_count

unsigned short prop_count

◆ radius

int radius

◆ state

int state

◆ timer

int timer

◆ tint

unsigned short tint

◆ view_distance

short view_distance

◆ yaw

int yaw