Moved some game code into engine code
This commit is contained in:
77
module.jai
77
module.jai
@@ -1,5 +1,8 @@
|
||||
EDITOR :: true;
|
||||
#module_parameters(WITH_EDITOR := true, WITH_NETWORKING := false);
|
||||
|
||||
EDITOR :: WITH_EDITOR;
|
||||
DEBUG :: true;
|
||||
NETWORKING :: WITH_NETWORKING;
|
||||
|
||||
#if EDITOR {
|
||||
//#load "../editor/scene_editor.jai";
|
||||
@@ -21,6 +24,7 @@ input : Input_State;
|
||||
current_scene: *Scene;
|
||||
|
||||
camera_buffer : Buffer_Handle;
|
||||
time_buffer : Buffer_Handle;
|
||||
screen_data_buffer : Buffer_Handle;
|
||||
directional_light_buffer : Buffer_Handle;
|
||||
|
||||
@@ -29,6 +33,17 @@ dt: float;
|
||||
quit: bool;
|
||||
frame_index : u64 = 0;
|
||||
|
||||
Camera_Data :: struct {
|
||||
projection_matrix: Matrix4;
|
||||
view_matrix: Matrix4;
|
||||
position: Vector4;
|
||||
}
|
||||
|
||||
Shader_Time :: struct {
|
||||
time: float;
|
||||
padding: Vector3;
|
||||
}
|
||||
|
||||
coven_init :: (window_title: string, window_width: u32, window_height: u32, fullscreen: bool) {
|
||||
window = create_window(window_title, window_width, window_height, fullscreen);
|
||||
renderer = create_renderer(window);
|
||||
@@ -41,7 +56,7 @@ coven_init :: (window_title: string, window_width: u32, window_height: u32, full
|
||||
ui_init();
|
||||
}
|
||||
|
||||
coven_run :: (game_update_proc: (float)) {
|
||||
coven_run :: (game_update_proc: (float), game_update_post_physics_proc: (float)) {
|
||||
time = xx seconds_since_init();
|
||||
|
||||
while !quit {
|
||||
@@ -51,7 +66,6 @@ coven_run :: (game_update_proc: (float)) {
|
||||
|
||||
update_input();
|
||||
|
||||
|
||||
// @Incomplete
|
||||
if key_pressed(.SHIFT) && key_down(.ESCAPE) {
|
||||
quit = true;
|
||||
@@ -69,6 +83,15 @@ coven_run :: (game_update_proc: (float)) {
|
||||
|
||||
game_update_proc(min(0.4, dt));
|
||||
|
||||
update_animators(dt);
|
||||
|
||||
update_physics(current_scene, dt);
|
||||
update_transforms();
|
||||
game_update_post_physics_proc(dt);
|
||||
sync_engine_buffers();
|
||||
|
||||
update_particle_systems(dt);
|
||||
|
||||
ui_end();
|
||||
|
||||
update_audio(dt);
|
||||
@@ -81,8 +104,54 @@ coven_run :: (game_update_proc: (float)) {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
sync_engine_buffers :: () {
|
||||
// Camera buffer
|
||||
camera := *current_scene.camera;
|
||||
|
||||
camera_data : Camera_Data;
|
||||
camera_data.projection_matrix = camera.projection_matrix;
|
||||
camera_data.view_matrix = camera.view_matrix;
|
||||
camera_data.position = to_v4(camera.position);
|
||||
upload_data_to_buffer(renderer, camera_buffer, *camera_data, size_of(Camera_Data));
|
||||
|
||||
shader_time : Shader_Time;
|
||||
shader_time.time = time;
|
||||
upload_data_to_buffer(renderer, time_buffer, *shader_time, size_of(Shader_Time));
|
||||
|
||||
// Sync entity transforms
|
||||
for current_scene.entities {
|
||||
if it.flags & .RENDERABLE {
|
||||
if it.renderable.type == {
|
||||
case .MODEL; {
|
||||
for n, i: it.renderable.model.nodes {
|
||||
if n.meshes.count > 0 {
|
||||
node_data := *it.renderable.nodes[i];
|
||||
upload_data_to_buffer(renderer, node_data.transform_buffer, *node_data.transform.world_matrix, size_of(Matrix4));
|
||||
|
||||
if node_data.num_bones > 0 {
|
||||
for handle, mesh_index: n.meshes {
|
||||
m := parray_get(*renderer.meshes, handle);
|
||||
bones : [MAX_BONES] Matrix4;
|
||||
for bone_index: 0..m.num_bones-1 {
|
||||
bone := *it.renderable.nodes[m.bone_indices[bone_index]];
|
||||
bones[bone_index] = bone.transform.world_matrix * m.bone_matrices[bone_index];
|
||||
}
|
||||
upload_data_to_buffer(renderer, node_data.bone_buffers[mesh_index], bones.data, size_of(Matrix4) * m.num_bones);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if NETWORKING {
|
||||
#load "networking/networking.jai";
|
||||
}
|
||||
|
||||
#load "input/input.jai";
|
||||
#load "networking/networking.jai";
|
||||
#load "renderer/renderer.jai";
|
||||
#load "windowing/window.jai";
|
||||
#load "physics/physics.jai";
|
||||
|
||||
Reference in New Issue
Block a user