summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-11 23:40:13 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-11 23:40:13 +1000
commit272cc9563315566061bbbd7078f76c76a3484e4b (patch)
tree3264c6acef2e3d3a7dab1c806233062395a5b5f3
parent3a151b1d1f99b59dfd6d98c1e7520b48b57d6f5e (diff)
removing example targets from xmake.lua and fix identation
-rw-r--r--examples/game_demo/game_demo.c24
-rw-r--r--examples/input/ex_input.c120
-rw-r--r--examples/skinned_animation/ex_skinned_animation.c2
-rw-r--r--src/maths/maths.c4
-rw-r--r--tests/pool_tests.c6
-rw-r--r--xmake.lua302
6 files changed, 122 insertions, 336 deletions
diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c
index 1b86028..b3fa70d 100644
--- a/examples/game_demo/game_demo.c
+++ b/examples/game_demo/game_demo.c
@@ -107,18 +107,18 @@ int main() {
// Shadow_Run(entities, entity_count);
// Quat rot = quat_from_axis_angle(VEC3_X, HALF_PI, true);
- Immdraw_Sphere(transform_create(VEC3_ZERO, quat_ident(), 0.5), vec4(1.0, 0.0, 0.0, 1.0), false);
- Immdraw_Cuboid(transform_create(vec3(2.0, 0.0, 0.0), quat_ident(), 1.0),
- vec4(1.0, 0.0, 0.0, 1.0), false);
-
- // if (draw_debug) {
- // // draw the player model with shadows
- // Render_RenderEntities(render_entities->data, render_entities->len);
- // // Render_DrawTerrain();
- // Skybox_Draw(&skybox, cam);
- // } else {
- // Shadow_DrawDebugQuad();
- // }
+ // Immdraw_Sphere(transform_create(VEC3_ZERO, quat_ident(), 0.5), vec4(1.0, 0.0, 0.0, 1.0),
+ // false); Immdraw_Cuboid(transform_create(vec3(2.0, 0.0, 0.0), quat_ident(), 1.0),
+ // vec4(1.0, 0.0, 0.0, 1.0), false);
+
+ if (draw_debug) {
+ // draw the player model with shadows
+ Render_RenderEntities(render_entities->data, render_entities->len);
+ // Render_DrawTerrain();
+ Skybox_Draw(&skybox, cam);
+ } else {
+ Shadow_DrawDebugQuad();
+ }
// Terrain_Draw(terrain);
// Grid_Draw();
diff --git a/examples/input/ex_input.c b/examples/input/ex_input.c
deleted file mode 100644
index 576b364..0000000
--- a/examples/input/ex_input.c
+++ /dev/null
@@ -1,120 +0,0 @@
-#include <glfw3.h>
-
-#include "camera.h"
-#include "core.h"
-#include "input.h"
-#include "keys.h"
-#include "maths.h"
-#include "maths_types.h"
-#include "primitives.h"
-#include "render.h"
-#include "render_backend.h"
-#include "render_types.h"
-
-typedef struct game_state {
- camera camera;
- vec3 camera_euler;
- bool first_mouse_update; // so the camera doesnt lurch when you run the first
- // process_camera_rotation
-} game_state;
-
-void update_camera_rotation(input_state* input, game_state* game, camera* cam);
-
-int main() {
- core* core = core_bringup();
-
- vec3 cam_pos = vec3_create(5, 5, 5);
- game_state game = {
- .camera = camera_create(cam_pos, vec3_negate(cam_pos), VEC3_Y, deg_to_rad(45.0)),
- .camera_euler = vec3_create(90, 0, 0),
- .first_mouse_update = true,
- };
-
- // load a texture
- texture tex = texture_data_load("assets/models/obj/cube/container.jpg", false);
- texture_data_upload(&tex);
-
- printf("Starting look direction: ");
- print_vec3(game.camera.front);
-
- // Main loop
- const f32 camera_lateral_speed = 0.2;
- const f32 camera_zoom_speed = 0.15;
-
- while (!should_exit(core)) {
- input_update(&core->input);
-
- vec3 translation = VEC3_ZERO;
- if (key_is_pressed(KEYCODE_W) || key_is_pressed(KEYCODE_KEY_UP)) {
- printf("Move Forwards\n");
- translation = vec3_mult(game.camera.front, camera_zoom_speed);
- } else if (key_is_pressed(KEYCODE_S) || key_is_pressed(KEYCODE_KEY_DOWN)) {
- printf("Move Backwards\n");
- translation = vec3_mult(game.camera.front, -camera_zoom_speed);
- } else if (key_is_pressed(KEYCODE_A) || key_is_pressed(KEYCODE_KEY_LEFT)) {
- printf("Move Left\n");
- vec3 lateral = vec3_normalise(vec3_cross(game.camera.front, game.camera.up));
- translation = vec3_mult(lateral, -camera_lateral_speed);
- } else if (key_is_pressed(KEYCODE_D) || key_is_pressed(KEYCODE_KEY_RIGHT)) {
- printf("Move Right\n");
- vec3 lateral = vec3_normalise(vec3_cross(game.camera.front, game.camera.up));
- translation = vec3_mult(lateral, camera_lateral_speed);
- }
- game.camera.position = vec3_add(game.camera.position, translation);
- // update_camera_rotation(&core->input, &game, &game.camera);
-
- // UNUSED: threadpool_process_results(&core->threadpool, 1);
-
- render_frame_begin(&core->renderer);
-
- mat4 model = mat4_translation(VEC3_ZERO);
-
- gfx_backend_draw_frame(&core->renderer, &game.camera, model, &tex);
-
- render_frame_end(&core->renderer);
- }
-
- core_shutdown(core);
-
- return 0;
-}
-
-void update_camera_rotation(input_state* input, game_state* game, camera* cam) {
- float xoffset = -input->mouse.x_delta; // xpos - lastX;
- float yoffset = -input->mouse.y_delta; // reversed since y-coordinates go from bottom to top
- if (game->first_mouse_update) {
- xoffset = 0.0;
- yoffset = 0.0;
- game->first_mouse_update = false;
- }
-
- float sensitivity = 0.2f; // change this value to your liking
- xoffset *= sensitivity;
- yoffset *= sensitivity;
-
- // x = yaw
- game->camera_euler.x += xoffset;
- // y = pitch
- game->camera_euler.y += yoffset;
- // we dont update roll
-
- f32 yaw = game->camera_euler.x;
- f32 pitch = game->camera_euler.y;
-
- // make sure that when pitch is out of bounds, screen doesn't get flipped
- if (game->camera_euler.y > 89.0f) game->camera_euler.y = 89.0f;
- if (game->camera_euler.y < -89.0f) game->camera_euler.y = -89.0f;
-
- vec3 front = cam->front;
- front.x = cos(deg_to_rad(yaw) * cos(deg_to_rad(pitch)));
- front.y = sin(deg_to_rad(pitch));
- front.z = sin(deg_to_rad(yaw)) * cos(deg_to_rad(pitch));
-
- front = vec3_normalise(front);
- // save it back
- cam->front.x = front.x;
- cam->front.y = front.y;
- // roll is static
-
- print_vec3(cam->front);
-}
diff --git a/examples/skinned_animation/ex_skinned_animation.c b/examples/skinned_animation/ex_skinned_animation.c
index 7704b99..25fc097 100644
--- a/examples/skinned_animation/ex_skinned_animation.c
+++ b/examples/skinned_animation/ex_skinned_animation.c
@@ -66,6 +66,8 @@ int main() {
// quat rot = quat_ident();
Transform tf = transform_create(VEC3_ZERO, quat_ident(), 1.0);
+ // TODO: Drawing should still just use the PBR pipeline
+
// draw_skinned_model(&core->renderer, &game.camera, simple_skin, tf, &our_scene);
Frame_End();
diff --git a/src/maths/maths.c b/src/maths/maths.c
index aedee76..1c5a91a 100644
--- a/src/maths/maths.c
+++ b/src/maths/maths.c
@@ -30,6 +30,6 @@ Mat4 transform_to_mat(Transform *tf) {
Mat4 scale = mat4_scale(tf->scale);
Mat4 rotation = mat4_rotation(tf->rotation);
Mat4 translation = mat4_translation(tf->position);
- return mat4_mult(translation, mat4_mult(rotation, scale));
- // return mat4_mult(mat4_mult(scale, rotation), translation);
+ // return mat4_mult(translation, mat4_mult(rotation, scale));
+ return mat4_mult(mat4_mult(scale, rotation), translation);
} \ No newline at end of file
diff --git a/tests/pool_tests.c b/tests/pool_tests.c
index 10a4bed..a268a61 100644
--- a/tests/pool_tests.c
+++ b/tests/pool_tests.c
@@ -38,9 +38,9 @@ typedef struct foo {
} foo;
CORE_DEFINE_HANDLE(bar);
-typedef struct bar_handle {
+typedef struct barHandle {
u32 raw;
-} bar_handle;
+} barHandle;
TYPED_POOL(foo, bar);
TEST(Pool, TypedPool) {
@@ -48,7 +48,7 @@ TEST(Pool, TypedPool) {
// create pool
bar_pool pool = bar_pool_create(&a, 2, sizeof(foo));
- bar_handle first_handle, second_handle, third_handle;
+ barHandle first_handle, second_handle, third_handle;
foo* first = bar_pool_alloc(&pool, &first_handle);
foo* second = bar_pool_alloc(&pool, &second_handle);
// Third one shouldnt work
diff --git a/xmake.lua b/xmake.lua
index 9b5151b..3559534 100644
--- a/xmake.lua
+++ b/xmake.lua
@@ -25,7 +25,6 @@ elseif is_plat("windows") then
add_defines("CEL_PLATFORM_WINDOWS")
add_syslinks("user32", "gdi32", "kernel32", "shell32")
-- add_requires("vulkansdk", { system = true })
-
-- add_links("pthreadVC2-w64")
elseif is_plat("macosx") then
add_defines("CEL_PLATFORM_MAC")
@@ -38,18 +37,18 @@ end
-- Compile GLFW from source
package("local_glfw")
-add_deps("cmake")
-set_sourcedir(path.join(os.scriptdir(), "deps/glfw-3.3.8"))
-on_install(function(package)
- local configs = {}
- -- NOTE(omni): Keeping these around as comments in case we need to modify glfw flags
- -- table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
- -- table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
- import("package.tools.cmake").install(package, configs)
-end)
-on_test(function(package)
- -- assert(package:has_cfuncs("add", {includes = "foo.h"}))
-end)
+ add_deps("cmake")
+ set_sourcedir(path.join(os.scriptdir(), "deps/glfw-3.3.8"))
+ on_install(function(package)
+ local configs = {}
+ -- NOTE(omni): Keeping these around as comments in case we need to modify glfw flags
+ -- table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+ -- table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+ import("package.tools.cmake").install(package, configs)
+ end)
+ on_test(function(package)
+ -- assert(package:has_cfuncs("add", {includes = "foo.h"}))
+ end)
package_end()
add_requires("local_glfw")
@@ -77,89 +76,86 @@ local unity_sources = {
}
rule("compile_glsl_vert_shaders")
-set_extensions(".vert")
-on_buildcmd_file(function(target, batchcmds, sourcefile, opt)
- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".vert.spv")
+ set_extensions(".vert")
+ on_buildcmd_file(function(target, batchcmds, sourcefile, opt)
+ local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".vert.spv")
- print("Compiling shader: %s to %s", sourcefile, targetfile)
- batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile })
- -- batchcmds:add_depfiles(sourcefile)
-end)
-rule("compile_glsl_frag_shaders")
-set_extensions(".frag")
-on_buildcmd_file(function(target, batchcmds, sourcefile, opt)
- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".frag.spv")
+ print("Compiling shader: %s to %s", sourcefile, targetfile)
+ batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile })
+ -- batchcmds:add_depfiles(sourcefile)
+ end)
- print("Compiling shader: %s to %s", sourcefile, targetfile)
- batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile })
- -- batchcmds:add_depfiles(sourcefile)
-end)
+rule("compile_glsl_frag_shaders")
+ set_extensions(".frag")
+ on_buildcmd_file(function(target, batchcmds, sourcefile, opt)
+ local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".frag.spv")
+
+ print("Compiling shader: %s to %s", sourcefile, targetfile)
+ batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile })
+ -- batchcmds:add_depfiles(sourcefile)
+ end)
-- TODO: Metal shaders compilation
-- common configuration for both static and shared libraries
target("core_config")
-set_kind("static") -- kind is required but you can ignore it since it's just for common settings
-add_packages("local_glfw")
-add_defines("CEL_REND_BACKEND_OPENGL")
-add_includedirs("deps/cgltf", { public = true })
-add_includedirs("deps/glfw-3.3.8/include/GLFW", { public = true })
-add_includedirs("deps/glad/include", { public = true })
-add_includedirs("deps/stb_image", { public = true })
-add_includedirs("deps/stb_image_write", { public = true })
-add_includedirs("deps/stb_truetype", { public = true })
-add_includedirs("include/", { public = true })
-add_includedirs("src/", { public = true })
-add_includedirs("src/core", { public = true })
-add_includedirs("src/logos/", { public = true })
-add_includedirs("src/maths/", { public = true })
-add_includedirs("src/platform/", { public = true })
-add_includedirs("src/ral", { public = true })
-add_includedirs("src/ral/backends/opengl", { public = true })
-add_includedirs("src/render", { public = true })
-add_includedirs("src/ral/backends/vulkan", { public = true })
-add_includedirs("src/resources/", { public = true })
-add_includedirs("src/std/", { public = true })
-add_includedirs("src/std/containers", { public = true })
-add_includedirs("src/systems/", { public = true })
-add_files("src/empty.c") -- for some reason we need this on Mac so it doesnt call 'ar' with no files and error
--- add_rules("compile_glsl_vert_shaders")
--- add_rules("compile_glsl_frag_shaders")
--- add_files("assets/shaders/triangle.vert")
--- add_files("assets/shaders/triangle.frag")
--- add_files("assets/shaders/cube.vert")
--- add_files("assets/shaders/cube.frag")
--- add_files("assets/shaders/*.frag")
-if is_plat("windows") then
- -- add_includedirs("$(env VULKAN_SDK)/Include", { public = true })
- -- add_linkdirs("$(env VULKAN_SDK)/Lib", { public = true })
- -- add_links("vulkan-1")
-end
-if is_plat("macosx") then
- -- add_files("src/renderer/backends/metal/*.m")
- add_files("src/ral/backends/vulkan/*.c")
-end
-set_default(false) -- prevents standalone building of this target
+ set_kind("static") -- kind is required but you can ignore it since it's just for common settings
+ add_packages("local_glfw")
+ add_defines("CEL_REND_BACKEND_OPENGL")
+ add_includedirs("deps/cgltf", { public = true })
+ add_includedirs("deps/glfw-3.3.8/include/GLFW", { public = true })
+ add_includedirs("deps/glad/include", { public = true })
+ add_includedirs("deps/stb_image", { public = true })
+ add_includedirs("deps/stb_image_write", { public = true })
+ add_includedirs("deps/stb_truetype", { public = true })
+ add_includedirs("include/", { public = true })
+ add_includedirs("src/", { public = true })
+ add_includedirs("src/core", { public = true })
+ add_includedirs("src/logos/", { public = true })
+ add_includedirs("src/maths/", { public = true })
+ add_includedirs("src/platform/", { public = true })
+ add_includedirs("src/ral", { public = true })
+ add_includedirs("src/ral/backends/opengl", { public = true })
+ add_includedirs("src/render", { public = true })
+ add_includedirs("src/ral/backends/vulkan", { public = true })
+ add_includedirs("src/resources/", { public = true })
+ add_includedirs("src/std/", { public = true })
+ add_includedirs("src/std/containers", { public = true })
+ add_includedirs("src/systems/", { public = true })
+ add_files("src/empty.c") -- for some reason we need this on Mac so it doesnt call 'ar' with no files and error
+ -- add_rules("compile_glsl_vert_shaders")
+ -- add_rules("compile_glsl_frag_shaders")
+ -- add_files("assets/shaders/*.frag")
+ if is_plat("windows") then
+ -- add_includedirs("$(env VULKAN_SDK)/Include", { public = true })
+ -- add_linkdirs("$(env VULKAN_SDK)/Lib", { public = true })
+ -- add_links("vulkan-1")
+ end
+ if is_plat("macosx") then
+ -- add_files("src/renderer/backends/metal/*.m")
+ -- add_files("src/ral/backends/vulkan/*.c")
+ end
+ set_default(false) -- prevents standalone building of this target
target("core_static")
-set_kind("static")
-add_deps("core_config") -- inherit common configurations
-set_policy("build.merge_archive", true)
-add_files(core_sources)
--- Link against static CRT
-if is_plat("windows") then
- -- add_links("libcmt", "legacy_stdio_definitions") -- for release builds
- add_links("libcmtd", "legacy_stdio_definitions") -- for debug builds
-end
+ set_kind("static")
+ add_deps("core_config") -- inherit common configurations
+ set_policy("build.merge_archive", true)
+ add_files(core_sources)
+ -- Link against static CRT
+ if is_plat("windows") then
+ add_links("libcmt", "legacy_stdio_definitions") -- for release builds
+ add_links("libcmtd", "legacy_stdio_definitions") -- for debug builds
+ end
target("core_shared")
-set_kind("shared")
-add_deps("core_config") -- inherit common configurations
-add_files(core_sources)
--- Link against dynamic CRT
-if is_plat("windows") then
- -- add_links("msvcrt", "legacy_stdio_definitions") -- for release builds
- add_links("msvcrtd", "legacy_stdio_definitions") -- for debug builds
-end
+ set_kind("shared")
+ add_deps("core_config") -- inherit common configurations
+ add_files(core_sources)
+ -- Link against dynamic CRT
+ if is_plat("windows") then
+ add_links("msvcrt", "legacy_stdio_definitions") -- for release builds
+ add_links("msvcrtd", "legacy_stdio_definitions") -- for debug builds
+ end
-- target("main_loop")
-- set_kind("binary")
@@ -183,119 +179,27 @@ end
-- end)
-- end
--- target("cube")
--- set_kind("binary")
--- set_group("examples")
--- -- add_defines("CEL_REND_BACKEND_OPENGL")
--- add_deps("core_static")
--- add_files("examples/cube/ex_cube.c")
--- set_rundir("$(projectdir)")
-
--- target("primitives")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_static")
--- add_files("examples/primitives/ex_primitives.c")
--- set_rundir("$(projectdir)")
-
--- -- target("std")
--- -- set_kind("binary")
--- -- set_group("examples")
--- -- add_deps("core_static")
--- -- add_files("examples/standard_lib/ex_std.c")
--- -- set_rundir("$(projectdir)")
-
--- -- target("obj")
--- -- set_kind("binary")
--- -- set_group("examples")
--- -- add_deps("core_static")
--- -- add_files("examples/obj_loading/ex_obj_loading.c")
--- -- set_rundir("$(projectdir)")
-
--- -- target("input")
--- -- set_kind("binary")
--- -- set_group("examples")
--- -- add_deps("core_static")
--- -- add_files("examples/input/ex_input.c")
--- -- set_rundir("$(projectdir)")
-
--- target("gltf")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_static")
--- add_files("examples/gltf_loading/ex_gltf_loading.c")
--- set_rundir("$(projectdir)")
-
--- target("pbr_params")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_static")
--- add_files("examples/pbr_params/ex_pbr_params.c")
--- set_rundir("$(projectdir)")
-
--- target("pbr_textured")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_static")
--- add_files("examples/pbr_textured/ex_pbr_textured.c")
--- set_rundir("$(projectdir)")
-
--- target("shadows")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_static")
--- add_files("examples/shadow_maps/ex_shadow_maps.c")
--- set_rundir("$(projectdir)")
-
--- target("transforms")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_shared")
--- add_files("examples/transforms/ex_transforms.c")
--- set_rundir("$(projectdir)")
-
--- target("animation")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_shared")
--- add_files("examples/property_animation/ex_property_animation.c")
--- set_rundir("$(projectdir)")
-
target("skinned")
-set_kind("binary")
-set_group("examples")
-add_deps("core_shared")
-add_files("examples/skinned_animation/ex_skinned_animation.c")
-set_rundir("$(projectdir)")
-
--- target("input")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_static")
--- add_files("examples/input/ex_input.c")
--- set_rundir("$(projectdir)")
-
--- target("demo")
--- set_kind("binary")
--- set_group("examples")
--- add_deps("core_static")
--- add_files("examples/demo/demo.c")
--- set_rundir("$(projectdir)")
+ set_kind("binary")
+ set_group("examples")
+ add_deps("core_shared")
+ add_files("examples/skinned_animation/ex_skinned_animation.c")
+ set_rundir("$(projectdir)")
target("game")
-set_kind("binary")
-set_group("examples")
-add_deps("core_static")
-add_files("examples/game_demo/game_demo.c")
-set_rundir("$(projectdir)")
-
--- target("pool_tests")
--- set_kind("binary")
--- set_group("tests")
--- add_deps("core_static")
--- add_files(unity_sources)
--- add_includedirs("deps/Unity/src", {public = true})
--- add_includedirs("deps/Unity/extras/fixture/src", {public = true})
--- add_includedirs("deps/Unity/extras/memory/src", {public = true})
--- add_files("tests/pool_tests.c")
--- add_files("tests/pool_test_runner.c")
+ set_kind("binary")
+ set_group("examples")
+ add_deps("core_static")
+ add_files("examples/game_demo/game_demo.c")
+ set_rundir("$(projectdir)")
+
+target("pool_tests")
+ set_kind("binary")
+ set_group("tests")
+ add_deps("core_static")
+ add_files(unity_sources)
+ add_includedirs("deps/Unity/src", {public = true})
+ add_includedirs("deps/Unity/extras/fixture/src", {public = true})
+ add_includedirs("deps/Unity/extras/memory/src", {public = true})
+ add_files("tests/pool_tests.c")
+ add_files("tests/pool_test_runner.c") \ No newline at end of file