Example scene layout.
This commit is contained in:
@ -6,7 +6,6 @@
|
||||
# Libs
|
||||
target_link_libraries(${DUSK_TARGET_NAME}
|
||||
PUBLIC
|
||||
cglm
|
||||
)
|
||||
|
||||
# Includes
|
||||
@ -24,5 +23,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(entity)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(render)
|
||||
add_subdirectory(entity)
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "camera.h"
|
||||
|
||||
void cameraInit(camera_t *camera) {
|
||||
glm_mat4_identity(camera->projection);
|
||||
glm_mat4_identity(camera->view);
|
||||
}
|
||||
|
||||
void cameraLookAt(
|
||||
camera_t *camera,
|
||||
const vec3 eye,
|
||||
const vec3 center,
|
||||
const vec3 up
|
||||
) {
|
||||
glm_lookat(eye, center, up, camera->view);
|
||||
}
|
||||
|
||||
void cameraPerspective(
|
||||
camera_t *camera,
|
||||
float aspect,
|
||||
float fovy,
|
||||
float zNear,
|
||||
float zFar
|
||||
) {
|
||||
glm_perspective(fovy, aspect, zNear, zFar, camera->projection);
|
||||
}
|
||||
|
||||
void cameraOrtho(
|
||||
camera_t *camera,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float near,
|
||||
float far
|
||||
) {
|
||||
glm_ortho(left, right, bottom, top, near, far, camera->projection);
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
mat4 projection;
|
||||
mat4 view;
|
||||
} camera_t;
|
||||
|
||||
/**
|
||||
* Initializes the camera.
|
||||
*
|
||||
* @param camera The camera to initialize.
|
||||
*/
|
||||
void cameraInit(camera_t *camera);
|
||||
|
||||
/**
|
||||
* Changes a camera to look at a specific point.
|
||||
*
|
||||
* @param camera The camera to modify.
|
||||
* @param eye The position of the camera.
|
||||
* @param center The point to look at.
|
||||
* @param up The up vector.
|
||||
*/
|
||||
void cameraLookAt(
|
||||
camera_t *camera,
|
||||
const vec3 eye,
|
||||
const vec3 center,
|
||||
const vec3 up
|
||||
);
|
||||
|
||||
/**
|
||||
* Changes the camera's perspective.
|
||||
*
|
||||
* @param camera The camera to modify.
|
||||
* @param fovy The field of view in the y direction.
|
||||
* @param aspect The aspect ratio.
|
||||
* @param zNear The near plane.
|
||||
* @param zFar The far plane.
|
||||
*/
|
||||
void cameraPerspective(
|
||||
camera_t *camera,
|
||||
const float fovy,
|
||||
const float aspect,
|
||||
const float zNear,
|
||||
const float zFar
|
||||
);
|
||||
|
||||
/**
|
||||
* Changes the camera's orthographic perspective.
|
||||
*
|
||||
* @param camera The camera to modify.
|
||||
* @param left The left plane.
|
||||
* @param right The right plane.
|
||||
* @param bottom The bottom plane.
|
||||
* @param top The top plane.
|
||||
* @param near The near plane.
|
||||
* @param far The far plane.
|
||||
*/
|
||||
void cameraOrtho(
|
||||
camera_t *camera,
|
||||
const float left,
|
||||
const float right,
|
||||
const float bottom,
|
||||
const float top,
|
||||
const float near,
|
||||
const float far
|
||||
);
|
@ -14,13 +14,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <cglm/cglm.h>
|
||||
#include <float.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef float float_t;
|
||||
typedef double double_t;
|
||||
typedef bool bool_t;
|
||||
typedef char char_t;
|
||||
|
||||
|
@ -7,19 +7,24 @@
|
||||
|
||||
#include "game.h"
|
||||
#include "input.h"
|
||||
#include "render/scene.h"
|
||||
|
||||
game_t GAME;
|
||||
|
||||
void gameInit() {
|
||||
memset(&GAME, 0, sizeof(game_t));
|
||||
|
||||
inputInit();
|
||||
sceneInit();
|
||||
}
|
||||
|
||||
void gameUpdate() {
|
||||
GAME.tick++;
|
||||
|
||||
inputUpdate();
|
||||
|
||||
if(inputWasPressed(INPUT_MENU)) {
|
||||
// Quit
|
||||
printf("Quit\n");
|
||||
}
|
||||
sceneUpdate();
|
||||
}
|
||||
|
||||
void gameDispose() {
|
||||
|
||||
}
|
@ -10,6 +10,12 @@
|
||||
|
||||
#define GAME_TICK_RATE 60
|
||||
|
||||
typedef struct {
|
||||
uint32_t tick;
|
||||
} game_t;
|
||||
|
||||
extern game_t GAME;
|
||||
|
||||
/**
|
||||
* Initializes the game.
|
||||
*/
|
||||
|
@ -7,6 +7,7 @@
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
entity.c
|
||||
overworld.c
|
||||
)
|
||||
|
||||
# Subdirs
|
25
src/dusk/overworld/overworld.c
Normal file
25
src/dusk/overworld/overworld.c
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "overworld.h"
|
||||
|
||||
void overworldInit() {
|
||||
|
||||
}
|
||||
|
||||
void overworldSceneInit() {
|
||||
|
||||
}
|
||||
|
||||
void overworldSceneDeinit() {
|
||||
|
||||
}
|
||||
|
||||
void overworldUpdate() {
|
||||
|
||||
}
|
||||
|
14
src/dusk/overworld/overworld.h
Normal file
14
src/dusk/overworld/overworld.h
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
void overworldInit();
|
||||
void overworldSceneInit();
|
||||
void overworldSceneDeinit();
|
||||
void overworldUpdate();
|
@ -6,7 +6,7 @@
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
camera.c
|
||||
scene.c
|
||||
)
|
||||
|
||||
# Subdirs
|
47
src/dusk/render/scene.c
Normal file
47
src/dusk/render/scene.c
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "scene.h"
|
||||
#include "assert/assert.h"
|
||||
#include "overworld/overworld.h"
|
||||
|
||||
scenetypecallback_t SCENE_CALLBACKS[] = {
|
||||
{ NULL, NULL, NULL, NULL },// SCENE_TYPE_INITIAL
|
||||
{ overworldInit, overworldSceneInit, overworldSceneDeinit, overworldUpdate },
|
||||
};
|
||||
|
||||
scene_t SCENE;
|
||||
|
||||
void sceneInit() {
|
||||
memset(&SCENE, 0, sizeof(scene_t));
|
||||
|
||||
for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) {
|
||||
if(SCENE_CALLBACKS[i].onInit) SCENE_CALLBACKS[i].onInit();
|
||||
}
|
||||
|
||||
sceneSet(SCENE_TYPE_OVERWORLD);// Testing
|
||||
}
|
||||
|
||||
void sceneUpdate() {
|
||||
assertTrue(SCENE.current < SCENE_TYPE_COUNT, "Invalid Scene Type");
|
||||
|
||||
if(SCENE.next != SCENE.current) {
|
||||
SCENE.current = SCENE.next;
|
||||
if(SCENE_CALLBACKS[SCENE.current].onActive) {
|
||||
SCENE_CALLBACKS[SCENE.current].onActive();
|
||||
}
|
||||
}
|
||||
|
||||
if(SCENE_CALLBACKS[SCENE.current].onUpdate) {
|
||||
SCENE_CALLBACKS[SCENE.current].onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void sceneSet(const scenetype_t scene) {
|
||||
assertTrue(SCENE.next < SCENE_TYPE_COUNT, "Invalid Scene Type");
|
||||
SCENE.next = scene;
|
||||
}
|
47
src/dusk/render/scene.h
Normal file
47
src/dusk/render/scene.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef enum {
|
||||
SCENE_TYPE_INITIAL,
|
||||
SCENE_TYPE_OVERWORLD,
|
||||
} scenetype_t;
|
||||
|
||||
#define SCENE_TYPE_COUNT 2
|
||||
|
||||
typedef struct {
|
||||
scenetype_t current;
|
||||
scenetype_t next;
|
||||
} scene_t;
|
||||
|
||||
typedef struct {
|
||||
void (*onInit)();
|
||||
void (*onActive)();
|
||||
void (*onInactive)();
|
||||
void (*onUpdate)();
|
||||
} scenetypecallback_t;
|
||||
|
||||
extern scene_t SCENE;
|
||||
|
||||
/**
|
||||
* Initializes the scene system.
|
||||
*/
|
||||
void sceneInit();
|
||||
|
||||
/**
|
||||
* Updates the scene system.
|
||||
*/
|
||||
void sceneUpdate();
|
||||
|
||||
/**
|
||||
* Sets the current scene. This will happen at the start of the next tick.
|
||||
*
|
||||
* @param scene The scene to set.
|
||||
*/
|
||||
void sceneSet(const scenetype_t scene);
|
@ -9,6 +9,7 @@ target_link_libraries(${DUSK_TARGET_NAME}
|
||||
archive_static
|
||||
m
|
||||
spng_static
|
||||
cglm
|
||||
)
|
||||
|
||||
# Includes
|
||||
|
@ -10,6 +10,13 @@
|
||||
#include "duskglimpl.h"
|
||||
|
||||
#include <libgen.h>
|
||||
#include <cglm/cglm.h>
|
||||
#include <float.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef float float_t;
|
||||
typedef double double_t;
|
||||
|
||||
extern char_t EXECUTABLE_PATH[];
|
||||
extern char_t EXECUTABLE_DIRECTORY[];
|
Reference in New Issue
Block a user