Rationale: Create a simple, minimalist 3D game engine in C using raylib for education, hacking, modification, and legitimate game development. With so many game engines focusing on how many features they have, this engine stands apart, stripped down to its bare essentials.
It doesn't do networking.
It doesn't have a UI.
It doesn't manage assets.
It doesn't manage memory.
It doesn't handle audio or input.
It doesn't have a particle system.
it doesn't have billboards, a native 3D model format, or a native scene format.
It doesn't even have a configuration file format.
Instead, all these features are left up to the game developer to support. It's so minimal, one could use it as a framework to build a more specific, more fully-featured engine atop it, making it not just a game engine, but a game engine engine. All it does have is:
-
Main loop with management(pause, unpause, exit) and callbacks
-
"Heads" - couples a render surface with a camera and event callbacks
-
Basic entity system with callbacks to define behavior
-
Generic scene interface with callbacks to support different scene types through dependency injection
-
Simple collision system to handle entity-entity collisions(AABB using spatial hashing)
-
Simple renderer using sphere-frustum intersection to handle frustum culling
-
A dynamic array container API (used internally, but exposed publicly for convenience)
This engine is so simple, it weighs in at only ~3600 lines of C.
This handles continuous collision between all Entitys in the scene.
A dynamically resizeable array used internally by the engine and provided to users.
This is the main system you will interface with in your game. All the other systems are subordinate to this in some manner. It uses an opaque struct to hold its state and references to all the other, subordinate systems.
This is what will appear in the world - enemies, props, projectiles, etc.. You will create templates of this struct to define the properties and behaviors of your Entities.
This couples a camera, input, pointer to an entity, and rendering context together. You will use this to see the world and interface with it.
This manages rendering the Scene to the various screen Regions handled by all current Heads.
This provides an interface which handles the world geometry and collision through callbacks. This is how maps/level formats will be implemented.
This provides a broad-phase method to store objects in the Scene in order to provide spatial queries for systems like Collision, provided to users.
These are the APIs used to make your game(s).
This just imports all the other headers.
CollisionResult Collision_checkAABB( Entity *a, Entity *b): Checks if two entities with AABB colliders are colliding and returns aCollisionResult.CollisionResult Collision_checkRayAABB( K_Ray ray, Entity *entity): Checks ifK_Ray,ray, intersects with the AABB collider ofentity.CollisionResult Collision_checkDiscreet( Entity *a, Entity *b): Runs a discreet collision detection check and returns aCollisionResult.CollisionResult Collision_checkContinuous( Entity *a, Entity *b, Vector3 movement): Runs a continuous collision detection check and returns aCollisionResultwith the info.
Defines macros, constants, enums, and types used commonly throughout the engine and game codebase.
-
   Most macro-defined constants are overridable
-
V3_ZERO: a Vector3 of all zeroes. -
V3_UP: a Vector3 of a +Y-up normal. -
Enumeration of:
-
For looping through
Xform.xf[]:-
POSITION: 0 -
ROTATION: 1 -
SCALE: 2 -
SKEW: 3
-
-
-
Forward declaration of the following structs:
-
Engine(Opaque): This is the main part you will interface with in your game -
Entity(Transparent): This is what will appear in the world - enemies, props, projectiles, etc.. You will create templates of this struct to define the properties and behaviors of your Entities. -
Head(Opaque): This couples a camera, input, pointer to an entity, and rendering context together. You will use this to see the world and interface with it.
-
-
The following values:
uint64,uint16,uint32,uint16,uint8,int64,int32,int16,int8,uint, andword.wordis the same width as the platform's word-size. -
The following structs:
-
CollisionResult: holds information regarding the result of a collision between two entities. It has the following fields:-
Vector3 position: where collision occurred -
Vector3 normal: surface normal at collision point -
float distance: Distance to collision -
int material_id: indicates surface type -
void *user_data: scene-specific data -
bool hit: self-explanatory
-
-
EntityList: holds a pointer to an array of entities for various uses. It has the following fields:-
Entity **entities: pointer to the array of entities -
uint count: number of entities in the array -
uint capacity: actual capacity of the array
-
-
Renderable: holds user-defined information for something which can be rendered to visualize an entity. Used in theEntitystruct. It has the following fields:-
Vector3 offset: an offset to be applied to the renderable if adjusting its placement in relation to the entity is needed -
void *data: a pointer to the data to be rendered -
void (*RenderableCallback)(Renderable *renderable, Vector3 position, Vector3 rotation, Vector3 scale): a function pointer to the callback used to render theRenderable
-
-
Xformholdsposition,rotation,scale, andskew, internally union'd withxf[4]to allow for swizzling.
-
-
Macro Defines:
DYNAMIC_ARRAY_GROWTH_FACTOR(default 2.0f): The amount to multiply the size of the array by when growing it(overridable).
-
Macro Functions:
DynamicArray(type, capacity): Constructs a newDynamicArrayin a simple manner. Takes the type of the data the array will store, followed by the starting capacity for the array.DynamicArray_add(array, datum): Wrapper forDynamicArray_append()for adding a single element to the Array.
-
Constructor / Destructor:
void *DynamicArray_new(size_t datum_size, size_t capacity): Constructs a newDynamicArraywith element size ofdatum_size, containingcapacityelements.void DynamicArray_free(void *array): Frees the givenDynamicArray,array, from memory.
-
Methods:
void DynamicArray_grow(void **array): Increases the capacity ofarraybyDYNAMIC_ARRAY_GROWTH_FACTORtimes its capacity.void DynamicArray_shrink(void *array): Decreases the capacity ofarrayby its capacity divided byDYNAMIC_ARRAY_GROWTH_FACTOR.void DynamicArray_append(void **array, void *data, size_t length): Appendslengthnumber of elements from the given arraydatato theDynamicArray,array.size_t DynamicArray_capacity(void *array): Gets the capacity ofarray.void DynamicArray_clear(void *array): Clears all entries fromarray(really, it just sets its length to 0).size_t DynamicArray_datumSize(void *array): Gets the size of the type of the element stored inarray.void DynamicArray_concat(void **array1, void *array2): Concatenatesarray2toarray1.void DynamicArray_delete(void *array, size_t index, size_t length): Removes the elements starting atindexforlengthnumber of cells fromarray.void DynamicArray_insert(void **array, size_t index, void *data, size_t length):Insertslengthnumber of elements fromdataintoarrayatindex.size_t DynamicArray_length(void *array): Gets the number of elements currently stored inarray.void DynamicArray_replace(void **array, size_t index, void *data, size_t length): Replaceslengthnumber of elements inarraywith the same number of elements fromdata, starting atindex.
-
Typedefs:
-
Callback types:
-
void (*EngineCallback)(Engine *engine): General callback. -
void (*EngineUpdateCallback)(Engine *engine, float delta): Called after updating every other system. Passes delta time with it. -
void (*EngineResizeCallback)(Engine *engine, uint width, uint height): Called after resizing the window. Use it to adjust the viewport size ofHeads if needed.
-
-
Struct:
-
EngineVTable: holds all the callbacks called by Engine. It holds the following fields:-
EngineCallback Setup: Called at the end of constructing theEnginestruct. -
EngineCallback Run: Called upon starting the engine with theEngine_run()method. Runs before the main loop starts. Use it to initialize certain things. -
EngineUpdateCallback Update: Called every frame after updating all the other systems and entities. -
EngineCallback Render: Called after rendering to all the activeHeads. Used for final composition of the rendered frame before presenting it to the screen. -
EngineResizeCallback Resize: Called upon resizing the window. Use it to adjust the viewport size of all theheads if needed. -
EngineCallback Exit: Called upon stopping the engine. Use it to deinitialize certain things if needed. -
EngineCallback Free: Called before freeing upEnginefrom memory. Use it to free up anything you need to get rid of so it's not stuck in memory, inaccessible.
-
-
-
Engine Methods:
-
Constructor/Destructor
-
Engine *Engine_new( EngineVTable *vtable): Constructs a newEnginestruct, and returns a pointer. Takes a preparedEngineVTable, already populated with callbacks. -
void Engine_free(Engine *engine): Frees up anEnginefrom memory. This will call theFreecallback if it has been provided.
-
-
Setters
void Engine_setVTable(Engine *engine, EngineVTable *vtable): Sets the engine's VTable to a different EngineVTable.
-
Getters
-
float Engine_getDeltaTime(Engine *engine): Gets the delta time for the current frame. -
uint64 EngineGetFrameNumber(Engine *engine): Gets the number of frames which have been rendered since running the engine. -
EntityList *Engine_getEntityList(Engine *engine): Gets a list of all the Entities subordinate to the Engine. -
Head *Engine_getHeads(Engine *engine): Returns a pointer to the root Head. -
Scene *Engine_getScene(Engine *engine): Returns a pointer to the current Scene.
-
-
Methods
-
void Engine_run(Engine *engine): Runs the Engine, starting the simulation. -
void Engine_pause(Engine *engine, bool paused): Sets the paused state of the engine. Useful for pausing the simulation, and to pass control between the Engine and a menu. -
void Engine_requestExit(Engine *engine): Requests the engine to exit on the next update.
-
-
-
- Typedefs:
typedef void (*EntityCallback)( Entity *entity);
typedef void (*EntityCollisionCallback)(Entity *entity, CollisionResult collision);
typedef void (*EntityUpdateCallback)( Entity *entity, float delta);
typedef struct
EntityVTable
{
EntityCallback Setup; /* Called on initialization of a new Entity */
EntityCallback Enter; /* Called upon Entity entering the scene */
EntityUpdateCallback Update; /* Called once every tick prior to rendering */
EntityUpdateCallback Render; /* Called once every frame prior to rendering the Entity */
EntityCollisionCallback OnCollision; /* Called when the Entity collides with something while moving */
EntityCollisionCallback OnCollided; /* Called when another Entity collides with this Entity */
EntityCallback Exit; /* Called upon Entity exiting the scene */
EntityCallback Free; /* Called upon freeing Entity from memory */
}
EntityVTable;
typedef struct
Entity
{
void *user_data;
EntityVTable *vtable;
Renderable *renderables[ MAX_LOD_LEVELS];
float lod_distances[MAX_LOD_LEVELS];
uint8 lod_count;
float visibility_radius;
float floor_max_angle;
union {
Vector3 bounds;
struct {
float
radius,
height,
_reserved_;
};
};
Vector3
bounds_offset,
renderable_offset,
velocity;
int max_slides;
union {
Transform transform;
struct {
Vector3 position;
Quaternion orientation;
Vector3 scale;
};
};
struct {
union {
uint8 layers;
struct {
bool
layer_0:1,
layer_1:1,
layer_2:1,
layer_3:1,
layer_4:1,
layer_5:1,
layer_6:1,
layer_7:1;
};
};
union {
uint8 masks;
struct {
bool
mask_0:1,
mask_1:1,
mask_2:1,
mask_3:1,
mask_4:1,
mask_5:1,
mask_6:1,
mask_7:1;
};
};
}
collision;
union {
uint8 flags;
struct {
bool
active :1,
visible :1,
solid :1; /* Solid or area collision */
CollisionShape
collision_shape:2; /* 0 = None | 1 = AABB | 2 = Cylinder | 3 = Sphere */
bool
_flag_5 :1,
_flag_6 :1,
_flag_7 :1;
};
};
char *local_data[];
}
Entity;-
*Constructor / Destructor *
Entity *Entity_new(const Entity *template_entity, Scene *scene, size_t local_data_size): Constructs a new entity from the giventemplate_entity, adding it to thescene, with optionallocal_data_sizememory allocated at the end.void Entity_free(Entity *entity): Destructs the givenentityremoving it from the scene.
-
Setters / Getters:
double Entity_getAge(Entity *entity): Get the age of the entity in seconds since the time of its creation.BoundingBox Entity_getBoundingBox(Entity *entity): Get the raylibBoundingBoxof the entity.Renderable *Entity_getLODRenderable(Entity *entity, Vector3 camera_position): Get theRenderableforentityat the givencamera_position.Engine *Entity_getEngine(Entity *entity): Get theenginewhichentityis subordinate to.Entity *Entity_getNext(Entity *entity): Get the nextEntityin the linked list in relation toentity.Entity *Entity_getPrev(Entity *entity): Get the previousEntityin the linked list in relation toentity.Scene *Entity_getScene(Entity *entity): Get theScenetheentityis currently in.uint64 Entity_getUniqueID(Entity *entity): Get the unique ID ofentity.bool Entity_isOnFloor(Entity *entity): Returns true ifentityis touching a floor.bool Entity_isOnWall(Entity *entity): Returns true ifentityis touching a wall.bool Entity_isOnCeiling(Entity *entity): Returns true ifentityis touching a ceiling.
-
Methods:
CollisionResult Entity_move(Entity *entity, Vector3 movement): Move theentitybymovementuntil the first collision.CollisionResult Entity_moveAndSlide(Entity *entity, Vector3 movement): Move theentitybymovement, allowing it to slide(requires you set theEntity.max_slidesvalue).
- Typedefs:
/* Callback Types */
typedef void (*HeadCallback)( Head *head);
typedef void (*HeadUpdateCallback)( Head *head, float delta);
typedef void (*HeadResizeCallback)( Head *head, uint width, uint height);
typedef struct
HeadVTable
{
HeadCallback Setup; /* Called immediately after initialization */
HeadUpdateCallback Update; /* Called every frame before rendering */
HeadCallback PreRender; /* Called during render, prior to rendering the scene.*/
HeadCallback PostRender; /* Called after rendering the scene */
HeadResizeCallback Resize; /* Called upon window resize */
HeadCallback Exit; /* Called upon removal of Head from engine */
HeadCallback Free; /* Called upon freeing the Head from memory */
}
HeadVTable;
typedef struct
{
float max_render_distance;
int max_entities_per_frame;
union {
uint8 flags;
struct {
bool frustum_culling :1;
bool sort_transparent_entities:1;
bool level_of_detail :1;
bool flag_3 :1; /* 3-4 not yet defined */
bool flag_4 :1;
bool draw_entity_origin :1;
bool draw_bounding_boxes :1;
bool show_lod_levels :1;
};
};
}
RendererSettings;-
Constructor / Destructor:
Head *Head_new(int Controller_ID, Region region, HeadVTable *vtable, Engine *engine): Constructs a newHeadwith a screen region ofregion, the callbacks invtable, adds it toengineand returns the pointer.void Head_free(Head *head): Destructs thehead, calling itsHeadVTable.Free()callback, and then freeing itself from memory.
-
Setters / Getters:
Head *Head_getNext(Head *head): Gets the pointer to the nextHeadin the linked list fromhead.Head *Head_getPrev(Head *head): Gets the pointer to the previousHeadin the linked list fromhead.Camera3D *Head_getCamera(Head *head): Gets the pointer tohead'sCamera3D.Engine *Head_getEngine(Head *head): Gets the pointer to theEnginethe givenheadis in.Frustum *Head_getFrustum(Head *head): Gets the pointer to thehead'sCamera3D'sFrustum.RenderTexture *Head_getViewport(Head *head): Only available ifHEAD_USE_RENDER_TEXTUREis defined. Gets the pointer to theRenderTextureviewport.Region Head_getRegion(Head *head): Gets the pointer tohead'sRegionof the screen it renders to.void Head_setRegion(Head *head, Region region): Sets thehead's screen region.void *Head_getUserData( Head *head): Gets the pointer to the data pointed to byhead.void Head_setUserData(Head *head, void *user_data): Sets the dataheadpoints to.void Head_setVTable(Head *head, HeadVTable *vtable): Sets theHeadVTableheaduses for callbacks.HeadVTable *Head_getVTable(Head *head): Gets the pointer to theHeadVTablecurrently used byhead.RendererSettings *Head_getRendererSettings(Head *head): Gets the pointer to theRenderSettingsused byhead.
-
Methods:
void Head_setup(Head *head): Calls theHeadVTable.Setup()functionheadcurrently points to.void Head_update(Head *head, float delta): Calls theHeadVTable.Update()functionheadcurrently points to.void Head_preRender(Head *head): Calls theHeadVTable.PreRender()functionheadcurrently points to.void Head_postRender(Head *head): Calls theHeadVTable.PostRender()functionheadcurrently points to.void Head_exit(Head *head): Calls theHeadVTable.Exit()functionheadcurrently points to.
-
Typedefs:
Renderer: Opaque struct of the renderer.
-
Methods:
void Renderer_submitEntity(Renderer *renderer, Entity *entity): Called each frame in order to submit an entity to be rendered.void Renderer_submitGeometry(Renderer *renderer, Renderable *renderable, Vector3 pos, Vector3 bounds): Called each frame in order to submit a chunk of geometry(such as level geometry) to be rendered.
- Typedefs:
typedef struct Scene Scene;
typedef void (*SceneCallback)( Scene *scene);
typedef void (*SceneDataCallback)( Scene *scene, void *map_data);
typedef void (*SceneUpdateCallback)( Scene *scene, float delta);
typedef void (*SceneEntityCallback)( Scene *scene, Entity *entity);
typedef CollisionResult (*SceneCollisionCallback)(Scene *scene, Entity *entity, Vector3 to);
typedef CollisionResult (*SceneRaycastCallback)( Scene *scene, Vector3 from, Vector3 to);
typedef void (*SceneRenderCallback)( Scene *scene, Head *head);
typedef struct
SceneVTable
{
SceneDataCallback Setup; /* Called on initialization */
SceneCallback Enter; /* Called on entering the engine */
SceneUpdateCallback Update; /* Called once every frame after updating all the entities and before rendering */
SceneEntityCallback EntityEnter; /* Called every time an Entity enters the scene */
SceneEntityCallback EntityExit; /* Called every time an Entity exits the scene */
SceneCollisionCallback CheckCollision; /* Called when checking if an entity would collide if moved */
SceneCollisionCallback MoveEntity; /* Called Every time an Entity moves in order to check if it has collided with the scene */
SceneRaycastCallback Raycast; /* Called Every time a raycast is performed in order to check if has collided with the scene */
SceneRenderCallback Render; /* Called once every frame in order to render the scene */
SceneCallback Exit; /* Called upon Scene exiting the engine */
SceneDataCallback Free; /* Called upon freeing the Scene from memory */
}
SceneVTable;-
Constructor / Destructor:
Scene *Scene_new(SceneVTable *scene_type, void *data, Engine *engine): Constructs a newScenewith the callbacks defined inscene_type,data, and adds it toengine.void Scene_free(Scene *scene): Destructssceneby calling itsSceneVTable.Free()callback, and then freeing itself from memory.
-
Setters / Getters;
Engine *Scene_getEngine(Scene *scene): Gets the pointer to theEnginesceneis currently in.uint Scene_getEntityCount( Scene *scene): Gets the number ofEntitys inscene.EntityList *Scene_getEntityList( Scene *scene): Gets theEntitys in the scene as an array.void *Scene_getMapData(Scene *scene): Gets the pointer toscene's data.
-
Methods;
void Scene_enter(Scene *scene): Calls theSceneVTable.Enter()functionscenecurrently points to.void Scene_update(Scene *scene, float delta): Calls theSceneVTable.Update()functionscenecurrently points to.void Scene_entityEnter(Scene *scene, Entity *entity): Calls theSceneVTable.EntityEnter()functionscenecurrently points to.void Scene_entityExit(Scene *scene, Entity *entity): Calls theSceneVTable.EntityExit()functionscenecurrently points to.CollisionResult Scene_checkCollision( Scene *scene, Entity *entity, Vector3 to): Calls theSceneVTable.CheckCollision()functionscenecurrently points to. Returns theCollisionResult.CollisionResult Scene_checkContinuous(Scene *scene, Entity *entity, Vector3 movement): Calls theSceneVTable.CheckContinuous()functionscenecurrently points to. Returns theCollisionResult.CollisionResult Scene_raycast(Scene *scene, Vector3 from, Vector3 to): Calls theSceneVTable.Raycast()functionscenecurrently points to.void Scene_render(Scene *scene, Head *head): Calls theSceneVTable.Render()functionscenecurrently points to.void Scene_exit(Scene *scene): Calls theSceneVTable.Exit()functionscenecurrently points to.
-
Typedefs:
SpatialHash: Opaque struct for the spatial hash.
-
Constructor / Destructor:
SpatialHash *SpatialHash_new(void): Construct a newSpatialHash.void SpatialHash_free(SpatialHash *hash): Destruct aSpatialHash, freeing it from memory.
-
Methods:
void SpatialHash_clear(SpatialHash *hash): Clears all the items from theSpatialHash,hash.void SpatialHash_insert(SpatialHash *hash, void *data, Vector3 center, Vector3 bounds): Insertsdataintohashatcenterwithboundsdimensions for later retrieval.void *SpatialHash_queryRegion(SpatialHash *hash, BoundingBox region, void **query_results, int *count): Queries all the entries inhashwithinregion, and populatesquery_resultswithcountof them.
These APIs are used internally within the engine. They are NOT to be used to make games. They are documented here in order to enable developers to better understand the engine for education and modification.
-
Typedefs:
typedef struct CollisionScene CollisionScene: Opaque type for the collision scene.
-
Scene MGMT:
void CollisionScene__markRebuild(CollisionScene *scene):void CollisionScene__insertEntity(CollisionScene *scene, Entity *entity):void CollisionScene__clear(CollisionScene *scene):
-
Methods:
Entity **CollisionScene__queryRegion(CollisionScene *scene, BoundingBox bbox, int *count): Returns an array ofEntitys in thescenewithin the givenbbox, and modifiescountto indicate the length of the array.CollisionResult CollisionScene__checkCollision(CollisionScene *scene, Entity *entity, Vector3 to): Checksentityfor a discreet collision withinsceneif it's at positionto. Returns results asCollisionResult.CollisionResult CollisionScene__moveEntity(CollisionScene *scene, Entity *entity, Vector3 movement): Checksentityfor a continuous collision withinsceneby moving it alongmovement. Returns result asCollisionResult.CollisionResult CollisionScene__raycast(CollisionScene *scene, K_Ray ray): Checks a raycastraywithinscene. Returns result asCollisionResult.void CollisionScene__update(CollisionScene *scene): Rebuilds the wholeCollisionSceneSpatialHash.
- Methods:
Head *Engine__getHeads(Engine *engine): Returns the pointer to the firstheadin the list attached toengine.void Engine__insertHead(Engine *engine, Head *head): Adds a newheadtoengine.void Engine__removeHead(Engine *engine, Head *head): Removes the givenheadfromengine.Scene *Engine__getScene(Engine *engine): Returns the pointer to the currentScene.void Engine__insertScene(Engine *engine, Scene *scene): Adds a newScene,scene, to theengine.void Engine__removeScene(Engine *engine, Scene *scene): Removes theScene,scene, rom theengine.Renderer *Engine__getRenderer(Engine *engine): Returns a pointer to theengine'sRenderer.
- Typedefs:
typedef struct
EntityNode
{
struct EntityNode
*prev,
*next;
Engine *engine;
Scene *scene;
uint64 unique_ID;
double creation_time;
size_t size;
int current_lod;
float last_lod_distance; /* Cache to avoid recalculating every frame */
union {
uint8 flags;
struct {
bool
visible_last_frame:1, /* For frustum culling optimizations */
on_floor :1, /* Collision States */
on_wall :1,
on_ceiling :1,
_flag_4 :1, /* Not yet defined */
_flag_5 :1,
_flag_6 :1,
_flag_7 :1;
};
};
Entity base;
}
EntityNode;-
Destructors:
void EntityNode__free(EntityNode *entity_node): Freesentity_nodefrom memory.void EntityNode__freeAll(EntityNode *entity_node): Frees allEntityNodes in the chain connected toentity_node.
-
Methods:
void EntityNode__insert(EntityNode *self, EntityNode *to): InsertsEntityNodeselfbehindto.void EntityNode__updateAll(EntityNode *entity_node, float delta): Calls the update callback ofentity_node, passing it the elapsed time asdelta. Called once every tick.void EntityNode__renderAll(EntityNode *entity_node, float delta): Calls the render callback ofentity_node, passing it the elapsed time asdelta. Called once every frame.
- Typedefs:
typedef struct
Head
{
Camera3D camera;
Vector3
prev_position,
prev_target;
float prev_fovy;
int
prev_width,
prev_height;
#ifdef HEAD_USE_RENDER_TEXTURE
RenderTexture viewport;
#endif /* HEAD_USE_RENDER_TEXTURE */
Region region;
RendererSettings settings;
Frustum frustum;
Engine *engine;
void *user_data;
struct Head
*prev,
*next;
HeadVTable *vtable;
}
Head;- Methods:
void Head__freeAll(Head *head): Frees allHeads in the chain connected tohead.void Head__updateAll(Head *head, float delta): Updates allHeads in the chain connected tohead, passing the elapsed time since last frame asdelta. Called every render frame.
-
Typedefs:
typedef struct Renderer Renderer
-
Constructor / Destructor:
Renderer *Renderer__new( Engine *engine): Constructs a newRendererand attaches it toengine.void Renderer__free(Renderer *renderer): Freesrendererfrom memory.
-
Methods:
void Renderer__render(Renderer *renderer, Head *head): Renders the current scene tohead's region/viewport.
- Typedefs:
typedef struct
Scene
{
struct Scene
*prev,
*next;
Engine *engine;
MemPool entity_pool;
EntityNode *entities;
CollisionScene *collision_scene;
SceneVTable *vtable;
void *map_data;
EntityList entity_list;
uint entity_count;
union {
uint8 flags;
struct {
bool dirty_EntityList:1;
bool flag_1 :1; /* 1-7 not yet defined */
bool flag_2 :1;
bool flag_3 :1;
bool flag_4 :1;
bool flag_5 :1;
bool flag_6 :1;
bool flag_7 :1;
};
};
}
Scene;- Methods:
void Scene__freeAll(Scene *scene): Frees allScenes attached to the engine.EntityNode *Scene__getEntities(Scene *scene): Returns an array of allEntityNodes attached toscenevoid Scene__insertEntity(Scene *scene, EntityNode *node): Inserts a newEntityNode,node, intoscene.void Scene__removeEntity(Scene *scene, EntityNode *node): Removes theEntityNode,node, fromscene.void Scene__update(Scene *scene, float delta): Updates thescene, passing the elapsed time since last update viadelta.
- Typedefs:
typedef struct SpatialEntry SpatialEntry;
typedef struct
SpatialHash
{
SpatialEntry *entry_pool; /* pre-allocated entries for performance */
SpatialEntry *free_entries; /* Free list for recycling */
int pool_size;
int pool_used;
int hash_size; /* Number of hash buckets */
float cell_size; /* Size of each cell */
SpatialEntry *cells[SPATIAL_HASH_SIZE];
}
SpatialHash;Zero-Clause BSD
===============
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.