summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/camera.c11
-rw-r--r--src/core/camera.h12
-rw-r--r--src/core/core.c56
-rw-r--r--src/core/core.h19
4 files changed, 42 insertions, 56 deletions
diff --git a/src/core/camera.c b/src/core/camera.c
index 50c4054..428a50d 100644
--- a/src/core/camera.c
+++ b/src/core/camera.c
@@ -2,16 +2,15 @@
#include "maths.h"
-Camera Camera_Create(vec3 pos, vec3 front, vec3 up, f32 fov) {
+Camera Camera_Create(Vec3 pos, Vec3 front, Vec3 up, f32 fov) {
Camera c = { .position = pos, .front = front, .up = up, .fov = fov };
return c;
}
-mat4 Camera_ViewProj(Camera *c, f32 lens_height, f32 lens_width, mat4 *out_view,
- mat4 *out_proj) {
- mat4 proj = mat4_perspective(c->fov, lens_width / lens_height, 0.1, 100.0);
- vec3 camera_direction = vec3_add(c->position, c->front);
- mat4 view = mat4_look_at(c->position, camera_direction, c->up);
+Mat4 Camera_ViewProj(Camera *c, f32 lens_height, f32 lens_width, Mat4 *out_view, Mat4 *out_proj) {
+ Mat4 proj = mat4_perspective(c->fov, lens_width / lens_height, 0.1, 100.0);
+ Vec3 camera_direction = vec3_add(c->position, c->front);
+ Mat4 view = mat4_look_at(c->position, camera_direction, c->up);
if (out_view) {
*out_view = view;
}
diff --git a/src/core/camera.h b/src/core/camera.h
index 233f5f3..bacbca9 100644
--- a/src/core/camera.h
+++ b/src/core/camera.h
@@ -8,14 +8,14 @@
#include "maths_types.h"
typedef struct Camera {
- vec3 position;
- vec3 front;
- vec3 up;
+ Vec3 position;
+ Vec3 front;
+ Vec3 up;
f32 fov;
} Camera;
/** @brief create a camera */
-Camera Camera_Create(vec3 pos, vec3 front, vec3 up, f32 fov);
+Camera Camera_Create(Vec3 pos, Vec3 front, Vec3 up, f32 fov);
/**
* @brief Get 3D camera transform matrix
@@ -23,10 +23,10 @@ Camera Camera_Create(vec3 pos, vec3 front, vec3 up, f32 fov);
* @param out_proj optionally stores just the projection matrix
* @returns the camera's view projection matrix pre-multiplied
*/
-PUB mat4 Camera_ViewProj(Camera* c, f32 lens_height, f32 lens_width, mat4* out_view, mat4* out_proj);
+PUB Mat4 Camera_ViewProj(Camera* c, f32 lens_height, f32 lens_width, Mat4* out_view, Mat4* out_proj);
/** @brief Get 2D camera transform matrix */
-PUB mat4 Camera_View2D(Camera* c); // TODO: 2D cameras
+PUB Mat4 Camera_View2D(Camera* c); // TODO: 2D cameras
// TODO: Basic reusable camera controls
diff --git a/src/core/core.c b/src/core/core.c
index a022366..602d35c 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -11,37 +11,35 @@
#include "render_types.h"
#include "scene.h"
+// These are only the initial window dimensions
#define SCR_WIDTH 1000
#define SCR_HEIGHT 1000
Core g_core; /** @brief global `Core` that other files can use */
-
struct Core {
const char* app_name;
- Renderer renderer;
- input_state input;
- model_pool models;
+ GLFWwindow* window;
+ Renderer* renderer;
+ Input_State input;
};
/** @brief Gets the global `Core` singleton */
inline Core* GetCore() { return &g_core; }
-void core_bringup() {
+void Core_Bringup() {
INFO("Initiate Core bringup");
RendererConfig conf = { .window_name = { "Celeritas Engine Core" },
- .scr_width = SCR_WIDTH,
- .scr_height = SCR_HEIGHT,
- .clear_colour = (vec3){ .08, .08, .1 } };
-
- g_core.renderer.backend_context = NULL;
+ .scr_width = SCR_WIDTH,
+ .scr_height = SCR_HEIGHT,
+ .clear_colour = (Vec3){ .08, .08, .1 } };
// initialise all subsystems
- if (!Renderer_Init(conf, &g_core.renderer)) {
+ if (!Renderer_Init(conf, g_core.renderer)) {
// FATAL("Failed to start renderer");
ERROR_EXIT("Failed to start renderer\n");
}
- if (!Input_Init(&g_core.input, g_core.renderer.window)) {
+ if (!Input_Init(&g_core.input, g_core.window)) {
// the input system needs the glfw window which is created by the renderer
// hence the order here is important
ERROR_EXIT("Failed to start input system\n");
@@ -50,34 +48,28 @@ void core_bringup() {
size_t model_data_max = 1024 * 1024 * 1024;
arena model_arena = arena_create(malloc(model_data_max), model_data_max);
- model_pool model_pool = model_pool_create(&model_arena, 256, sizeof(model));
- g_core.models = model_pool;
- INFO("Created model pool allocator");
+ // model_pool model_pool = model_pool_create(&model_arena, 256, sizeof(model));
+ // g_core.models = model_pool;
+ // INFO("Created model pool allocator");
- INFO("Creating default scene");
- scene_init(&g_core.default_scene);
+ // INFO("Creating default scene");
+ // scene_init(&g_core.default_scene);
}
#include <glfw3.h>
-/* bool should_window_close(core* core) { glfwWindowShouldClose(core->renderer.window); } */
-void core_input_update() { input_update(&g_core.input); }
-void core_frame_begin(core* core) { render_frame_begin(&core->renderer); }
-void core_frame_end(core* core) { render_frame_end(&core->renderer); }
-
-void core_shutdown() {
- // threadpool_destroy(&core->threadpool);
- input_system_shutdown(&g_core.input);
- renderer_shutdown(&g_core.renderer);
+void Core_Shutdown() {
+ Input_Shutdown(&g_core.input);
+ Renderer_Shutdown(g_core.renderer);
}
-bool should_exit() {
- return key_just_released(KEYCODE_ESCAPE) || glfwWindowShouldClose(g_core.renderer.window);
+bool ShouldExit() {
+ return key_just_released(KEYCODE_ESCAPE) || glfwWindowShouldClose(g_core.window);
}
-void frame_begin() {
+void Frame_Begin() {
glfwPollEvents();
- render_frame_begin(&g_core.renderer);
+ Render_FrameBegin(g_core.renderer);
}
-void frame_draw() {}
-void frame_end() { render_frame_end(&g_core.renderer); }
+void Frame_Draw() {}
+void Frame_End() { Render_FrameEnd(g_core.renderer); }
diff --git a/src/core/core.h b/src/core/core.h
index 469f8d1..7916143 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -9,18 +9,13 @@
typedef struct Core Core;
-
-core* get_global_core();
-
-// --- Lifecycle
+Core* get_global_core();
/** @brief Throws error if the core cannot be instantiated */
-void core_bringup();
-void core_shutdown();
-bool should_exit();
-
-void frame_begin();
-void frame_draw();
-void frame_end();
+void Core_Bringup();
+void Core_Shutdown();
+bool ShouldExit();
-void core_input_update();
+void Frame_Begin();
+void Frame_Draw();
+void Frame_End();