Kohi Game Engine
scene.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "assets/kasset_types.h"
4 #include "audio/kaudio_types.h"
5 #include "core_resource_types.h"
6 #include "defines.h"
8 #include "identifiers/khandle.h"
10 #include "math/math_types.h"
13 
14 struct frame_data;
15 struct render_packet;
16 struct directional_light;
17 struct point_light;
18 struct skybox;
19 struct water_plane;
20 struct camera;
21 struct scene_config;
22 struct terrain;
23 struct ray;
24 struct raycast_result;
25 struct transform;
26 struct viewport;
28 
29 typedef enum scene_state {
43 
44 typedef struct scene_attachment {
46  // Handle into the hierarchy graph.
48  // A handle indexing into the resource array of the given type (i.e. meshes).
50 
54 
55 typedef enum scene_flag {
57  /* @brief Indicates if the scene can be saved once modified
58  * (i.e. read-only would be used for runtime, writing would
59  * be used in editor, etc.)
60  */
63 
64 // Bitwise flags to be used on scene load, etc.
65 typedef u32 scene_flags;
66 
67 typedef struct scene_node_metadata {
69  // Metadata considered stale/non-existant if INVALID_ID_U64
71 
72  // The name of the node.
75 
80 
81 typedef struct scene_terrain_metadata {
86 
87 typedef struct scene_skybox_metadata {
91 
95 
96 struct scene_audio_emitter;
97 struct scene_volume;
98 struct scene_hit_sphere;
99 
100 typedef struct scene {
103 
106 
108  char* description;
109 
110  // darray of directional lights.
112  // Array of scene attachments for directional lights.
114 
115  // darray of point lights.
117  // Array of scene attachments for point lights.
119 
120  // darray of audio emitters.
121  struct scene_audio_emitter* audio_emitters;
122  // Array of scene attachments for audio_emitters.
124 
125  // darray of static meshes.
127  // Array of scene attachments for meshes.
129  // Array of mesh metadata.
131 
132  // darray of terrains.
133  struct terrain* terrains;
134  // Array of scene attachments for terrains.
136  // Array of terrain metadata.
138 
139  // darray of skyboxes.
140  struct skybox* skyboxes;
141  // Array of scene attachments for skyboxes.
143  // Array of skybox metadata.
145 
146  // darray of water planes.
148  // Array of scene attachments for water planes.
150  // Array of water plane metadata.
152 
153  // darray of volumes.
154  struct scene_volume* volumes;
155  // Array of scene attachments for volumes.
157 
158  // darray of hit spheres.
159  struct scene_hit_sphere* hit_spheres;
160  // Array of scene attachments for hit spheres.
162 
163  // A grid for the scene.
165 
166  // A pointer to the scene configuration resource.
168 
170 
171  // An array of node metadata, indexed by hierarchy graph handle.
172  // Marked as unused by id == INVALID_ID
173  // Size of this array is always highest id+1. Does not shrink on node destruction.
175 
176  // The number of node_metadatas currently allocated.
178 
180 
190 KAPI b8 scene_create(kasset_scene* config, scene_flags flags, scene* out_scene);
191 
200 
208 
218 
226 
234 KAPI b8 scene_update(scene* scene, const struct frame_data* p_frame_data);
235 
236 KAPI void scene_render_frame_prepare(scene* scene, const struct frame_data* p_frame_data);
237 
247 KAPI void scene_update_lod_from_view_position(scene* scene, const struct frame_data* p_frame_data, vec3 view_position, f32 near_clip, f32 far_clip);
248 
249 KAPI b8 scene_raycast(scene* scene, const struct ray* r, struct raycast_result* out_result);
250 
251 KAPI b8 scene_debug_render_data_query(scene* scene, u32* data_count, struct geometry_render_data** debug_geometries);
252 
253 KAPI b8 scene_mesh_render_data_query(const scene* scene, const frustum* f, vec3 center, struct frame_data* p_frame_data, u32* out_count, struct geometry_render_data** out_geometries);
254 KAPI b8 scene_mesh_render_data_query_from_line(const scene* scene, vec3 direction, vec3 center, f32 radius, struct frame_data* p_frame_data, u32* out_count, struct geometry_render_data** out_geometries);
255 
256 KAPI b8 scene_terrain_render_data_query(const scene* scene, const frustum* f, vec3 center, struct frame_data* p_frame_data, u32* out_count, struct geometry_render_data** out_terrain_geometries);
257 KAPI b8 scene_terrain_render_data_query_from_line(const scene* scene, vec3 direction, vec3 center, f32 radius, struct frame_data* p_frame_data, u32* out_count, struct geometry_render_data** out_geometries);
258 
259 KAPI b8 scene_water_plane_query(const scene* scene, const frustum* f, vec3 center, struct frame_data* p_frame_data, u32* out_count, struct water_plane*** out_water_planes);
260 
261 KAPI b8 scene_node_xform_get_by_name(const scene* scene, kname name, khandle* out_xform_handle);
262 KAPI b8 scene_node_xform_get(const scene* scene, khandle node_handle, khandle* out_xform_handle);
263 KAPI b8 scene_node_local_matrix_get(const scene* scene, khandle node_handle, mat4* out_matrix);
265 
267 KAPI b8 scene_node_child_count_get(const scene* s, kname name, u32* out_child_count);
268 KAPI b8 scene_node_child_name_get_by_index(const scene* s, kname name, u32 index, kname* out_child_name);
269 
scene_node_attachment_type
Definition: core_resource_types.h:14
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:205
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
float f32
32-bit floating point number
Definition: defines.h:47
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
A global handle system for Kohi. Handles are used to obtain various resources using a unique handle i...
u64 kname
A kname is a string hash made for quick comparisons versus traditional string comparisons.
Definition: kname.h:36
Contains various math types required for the engine.
struct scene_static_mesh_metadata scene_static_mesh_metadata
KAPI b8 scene_node_exists(const scene *s, kname name)
struct scene_water_plane_metadata scene_water_plane_metadata
KAPI b8 scene_node_local_matrix_get_by_name(const scene *scene, kname name, mat4 *out_matrix)
KAPI b8 scene_node_xform_get_by_name(const scene *scene, kname name, khandle *out_xform_handle)
struct scene_skybox_metadata scene_skybox_metadata
KAPI b8 scene_node_local_matrix_get(const scene *scene, khandle node_handle, mat4 *out_matrix)
struct scene_attachment scene_attachment
KAPI b8 scene_initialize(scene *scene)
Performs initialization routines on the scene, including processing configuration (if provided) and s...
KAPI b8 scene_node_child_name_get_by_index(const scene *s, kname name, u32 index, kname *out_child_name)
u32 scene_flags
Definition: scene.h:65
KAPI b8 scene_create(kasset_scene *config, scene_flags flags, scene *out_scene)
Creates a new scene with the given config with default values. No resources are allocated....
KAPI b8 scene_node_child_count_get(const scene *s, kname name, u32 *out_child_count)
KAPI void scene_destroy(scene *s)
Destroys the scene, releasing any remaining resources held by it. Automatically triggers unload if sc...
struct scene_terrain_metadata scene_terrain_metadata
KAPI b8 scene_terrain_render_data_query_from_line(const scene *scene, vec3 direction, vec3 center, f32 radius, struct frame_data *p_frame_data, u32 *out_count, struct geometry_render_data **out_geometries)
KAPI b8 scene_mesh_render_data_query(const scene *scene, const frustum *f, vec3 center, struct frame_data *p_frame_data, u32 *out_count, struct geometry_render_data **out_geometries)
KAPI void scene_update_lod_from_view_position(scene *scene, const struct frame_data *p_frame_data, vec3 view_position, f32 near_clip, f32 far_clip)
Updates LODs of items in the scene based on the given position and clipping distances.
KAPI void scene_render_frame_prepare(scene *scene, const struct frame_data *p_frame_data)
KAPI b8 scene_load(scene *scene)
Performs loading routines and resource allocation on the given scene.
struct scene_node_metadata scene_node_metadata
KAPI b8 scene_mesh_render_data_query_from_line(const scene *scene, vec3 direction, vec3 center, f32 radius, struct frame_data *p_frame_data, u32 *out_count, struct geometry_render_data **out_geometries)
scene_flag
Definition: scene.h:55
@ SCENE_FLAG_READONLY
Definition: scene.h:61
@ SCENE_FLAG_NONE
Definition: scene.h:56
KAPI b8 scene_node_xform_get(const scene *scene, khandle node_handle, khandle *out_xform_handle)
KAPI b8 scene_debug_render_data_query(scene *scene, u32 *data_count, struct geometry_render_data **debug_geometries)
KAPI b8 scene_unload(scene *scene, b8 immediate)
Performs unloading routines and resource de-allocation on the given scene. A scene is also destroyed ...
KAPI b8 scene_save(scene *s)
KAPI b8 scene_terrain_render_data_query(const scene *scene, const frustum *f, vec3 center, struct frame_data *p_frame_data, u32 *out_count, struct geometry_render_data **out_terrain_geometries)
scene_state
Definition: scene.h:29
@ SCENE_STATE_LOADING
In the process of loading the hierarchy.
Definition: scene.h:35
@ SCENE_STATE_INITIALIZED
Configuration parsed, not yet loaded hierarchy setup.
Definition: scene.h:33
@ SCENE_STATE_LOADED
Everything is loaded, ready to play.
Definition: scene.h:37
@ SCENE_STATE_UNLOADING
In the process of unloading, not ready to play.
Definition: scene.h:39
@ SCENE_STATE_UNINITIALIZED
created, but nothing more.
Definition: scene.h:31
@ SCENE_STATE_UNLOADED
Unloaded and ready to be destroyed.
Definition: scene.h:41
KAPI b8 scene_update(scene *scene, const struct frame_data *p_frame_data)
Performs any required scene updates for the given frame.
KAPI b8 scene_raycast(scene *scene, const struct ray *r, struct raycast_result *out_result)
KAPI b8 scene_water_plane_query(const scene *scene, const frustum *f, vec3 center, struct frame_data *p_frame_data, u32 *out_count, struct water_plane ***out_water_planes)
struct scene scene
Represents a camera that can be used for a variety of things, especially rendering....
Definition: camera.h:21
Definition: debug_grid.h:20
A directional light, typically used to emulate sun/moon light.
Definition: light_system.h:33
Engine-level current frame-specific data.
Definition: frame_data.h:11
Definition: math_types.h:272
Definition: renderer_types.h:35
Definition: hierarchy_graph.h:50
Definition: kasset_types.h:321
A handle is a unique identifier used a system in the engine to avoid using raw pointers where possibl...
Definition: khandle.h:25
Represents an instance of a static mesh. This is to be used in the world. Material instances are obta...
Definition: static_mesh_system.h:14
A point light, the most common light source, which radiates out from the given position.
Definition: light_system.h:64
Represents a line which starts at an origin and proceed infinitely in the given direction....
Definition: geometry_3d.h:9
Definition: geometry_3d.h:28
Definition: scene.h:44
kname * tags
Definition: scene.h:52
scene_node_attachment_type attachment_type
Definition: scene.h:45
khandle hierarchy_node_handle
Definition: scene.h:47
u32 tag_count
Definition: scene.h:51
khandle resource_handle
Definition: scene.h:49
Definition: scene.h:67
kname name
Definition: scene.h:73
u64 uniqueid
Definition: scene.h:70
u32 index
Definition: scene.h:68
Definition: scene.h:87
kname cubemap_name
Definition: scene.h:88
kname package_name
Definition: scene.h:89
Definition: scene.h:76
kname resource_name
Definition: scene.h:77
kname package_name
Definition: scene.h:78
Definition: scene.h:81
kname name
Definition: scene.h:82
kname resource_name
Definition: scene.h:83
kname package_name
Definition: scene.h:84
Definition: scene.h:92
u32 reserved
Definition: scene.h:93
Definition: scene.h:100
scene_flags flags
Definition: scene.h:102
scene_state state
Definition: scene.h:104
struct terrain * terrains
Definition: scene.h:133
struct point_light * point_lights
Definition: scene.h:116
debug_grid grid
Definition: scene.h:164
scene_attachment * water_plane_attachments
Definition: scene.h:149
scene_water_plane_metadata * water_plane_metadata
Definition: scene.h:151
scene_attachment * directional_light_attachments
Definition: scene.h:113
kname name
Definition: scene.h:107
hierarchy_graph hierarchy
Definition: scene.h:169
struct scene_volume * volumes
Definition: scene.h:154
scene_attachment * point_light_attachments
Definition: scene.h:118
scene_attachment * terrain_attachments
Definition: scene.h:135
scene_static_mesh_metadata * mesh_metadata
Definition: scene.h:130
u32 id
Definition: scene.h:101
char * description
Definition: scene.h:108
scene_terrain_metadata * terrain_metadata
Definition: scene.h:137
struct scene_hit_sphere * hit_spheres
Definition: scene.h:159
scene_attachment * skybox_attachments
Definition: scene.h:142
struct skybox * skyboxes
Definition: scene.h:140
struct water_plane * water_planes
Definition: scene.h:147
struct directional_light * dir_lights
Definition: scene.h:111
scene_attachment * mesh_attachments
Definition: scene.h:128
kstatic_mesh_instance * static_meshes
Definition: scene.h:126
scene_attachment * hit_sphere_attachments
Definition: scene.h:161
kasset_scene * config
Definition: scene.h:167
b8 enabled
Definition: scene.h:105
struct scene_audio_emitter * audio_emitters
Definition: scene.h:121
scene_attachment * audio_emitter_attachments
Definition: scene.h:123
scene_attachment * volume_attachments
Definition: scene.h:156
scene_skybox_metadata * skybox_metadata
Definition: scene.h:144
scene_node_metadata * node_metadata
Definition: scene.h:174
u32 node_metadata_count
Definition: scene.h:177
Definition: skybox.h:19
Definition: terrain.h:81
Definition: viewport.h:6
Definition: water_plane.h:13
a 4x4 matrix, typically used to represent object transformations.
Definition: math_types.h:195
A 3-element vector.
Definition: math_types.h:49