Fixed some camera bugs.
This commit is contained in:
13
src/display/scene/CMakeLists.txt
Normal file
13
src/display/scene/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
scenemanager.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(overworld)
|
10
src/display/scene/overworld/CMakeLists.txt
Normal file
10
src/display/scene/overworld/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
sceneoverworld.c
|
||||
)
|
58
src/display/scene/overworld/sceneoverworld.c
Normal file
58
src/display/scene/overworld/sceneoverworld.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "sceneoverworld.h"
|
||||
#include "rpg/entity/entity.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/framebuffer/framebuffer.h"
|
||||
#include "display/scene/scenemanager.h"
|
||||
#include "display/mesh/quad.h"
|
||||
|
||||
camera_t SCENE_OVERWORLD_CAMERA;
|
||||
|
||||
void sceneOverworldInit(void) {
|
||||
cameraInit(&SCENE_OVERWORLD_CAMERA);
|
||||
SCENE_OVERWORLD_CAMERA.type = CAMERA_TYPE_ORTHOGRAPHIC;
|
||||
SCENE_OVERWORLD_CAMERA.orthographic.left = 0.0f;
|
||||
SCENE_OVERWORLD_CAMERA.orthographic.right = frameBufferGetWidth(FRAMEBUFFER_BOUND);
|
||||
SCENE_OVERWORLD_CAMERA.orthographic.top = 0.0f;
|
||||
SCENE_OVERWORLD_CAMERA.orthographic.bottom = frameBufferGetHeight(FRAMEBUFFER_BOUND);
|
||||
SCENE_OVERWORLD_CAMERA.nearClip = -1.0f;
|
||||
SCENE_OVERWORLD_CAMERA.farClip = 100.0f;
|
||||
|
||||
glm_mat4_identity(SCENE_OVERWORLD_CAMERA.transform);
|
||||
|
||||
scene_t *scene = &SCENE_MANAGER_SCENES[SCENE_TYPE_OVERWORLD];
|
||||
scene->flags |= SCENE_FLAG_ACTIVE | SCENE_FLAG_VISIBLE;
|
||||
}
|
||||
|
||||
void sceneOverworldUpdate(void) {
|
||||
}
|
||||
|
||||
void sceneOverworldRender(void) {
|
||||
frameBufferClear(
|
||||
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
|
||||
COLOR_CORNFLOWER_BLUE
|
||||
);
|
||||
|
||||
cameraPushMatrix(&SCENE_OVERWORLD_CAMERA);
|
||||
meshDraw(&QUAD_MESH_SIMPLE, -1, -1);
|
||||
|
||||
spriteBatchPush(
|
||||
NULL,
|
||||
0.0f, 0.0f, 32.0f, 32.0f,
|
||||
0xFF, 0x00, 0x00, 0xFF,
|
||||
0.0f, 0.0f, 1.0f, 1.0f
|
||||
);
|
||||
spriteBatchFlush();
|
||||
|
||||
cameraPopMatrix();
|
||||
}
|
||||
|
||||
void sceneOverworldDispose(void) {
|
||||
// Dispose of the overworld scene.
|
||||
}
|
31
src/display/scene/overworld/sceneoverworld.h
Normal file
31
src/display/scene/overworld/sceneoverworld.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "display/camera.h"
|
||||
|
||||
extern camera_t SCENE_OVERWORLD_CAMERA;
|
||||
|
||||
/**
|
||||
* Initialize the overworld scene.
|
||||
*/
|
||||
void sceneOverworldInit(void);
|
||||
|
||||
/**
|
||||
* Update the overworld scene.
|
||||
*/
|
||||
void sceneOverworldUpdate(void);
|
||||
|
||||
/**
|
||||
* Render the overworld scene.
|
||||
*/
|
||||
void sceneOverworldRender(void);
|
||||
|
||||
/**
|
||||
* Dispose of the overworld scene.
|
||||
*/
|
||||
void sceneOverworldDispose(void);
|
32
src/display/scene/scene.h
Normal file
32
src/display/scene/scene.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#define SCENE_FLAG_VISIBLE (1 << 0)
|
||||
#define SCENE_FLAG_ACTIVE (1 << 1)
|
||||
|
||||
typedef struct {
|
||||
void (*init)(void);
|
||||
void (*update)(void);
|
||||
void (*render)(void);
|
||||
void (*dispose)(void);
|
||||
void (*active)(void);
|
||||
void (*sleep)(void);
|
||||
|
||||
uint8_t flags;
|
||||
} scene_t;
|
||||
|
||||
typedef enum {
|
||||
SCENE_TYPE_LOGO,
|
||||
SCENE_TYPE_OVERWORLD,
|
||||
|
||||
SCENE_TYPE_COUNT
|
||||
} scenetype_t;
|
||||
|
||||
#define SCENE_TYPE_INITIAL SCENE_TYPE_OVERWORLD
|
52
src/display/scene/scenemanager.c
Normal file
52
src/display/scene/scenemanager.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "scenemanager.h"
|
||||
|
||||
#include "display/scene/overworld/sceneoverworld.h"
|
||||
|
||||
scenemanager_t SCENE_MANAGER;
|
||||
|
||||
scene_t SCENE_MANAGER_SCENES[SCENE_TYPE_COUNT] = {
|
||||
[SCENE_TYPE_LOGO] = { 0 },
|
||||
|
||||
[SCENE_TYPE_OVERWORLD] = {
|
||||
.init = sceneOverworldInit,
|
||||
.update = sceneOverworldUpdate,
|
||||
.render = sceneOverworldRender,
|
||||
.dispose = sceneOverworldDispose
|
||||
}
|
||||
};
|
||||
|
||||
void sceneManagerInit(void) {
|
||||
scene_t *initial = &SCENE_MANAGER_SCENES[SCENE_TYPE_INITIAL];
|
||||
if(initial->init != NULL) initial->init();
|
||||
}
|
||||
|
||||
void sceneManagerUpdate(void) {
|
||||
// For each scene.
|
||||
for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) {
|
||||
scene_t *scene = &SCENE_MANAGER_SCENES[i];
|
||||
if((scene->flags & SCENE_FLAG_ACTIVE) == 0) continue;
|
||||
if(scene->update != NULL) scene->update();
|
||||
}
|
||||
}
|
||||
|
||||
void sceneManagerRender(void) {
|
||||
for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) {
|
||||
scene_t *scene = &SCENE_MANAGER_SCENES[i];
|
||||
if((scene->flags & SCENE_FLAG_VISIBLE) == 0) continue;
|
||||
if(scene->render != NULL) scene->render();
|
||||
}
|
||||
}
|
||||
|
||||
void sceneManagerDispose(void) {
|
||||
for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) {
|
||||
scene_t *scene = &SCENE_MANAGER_SCENES[i];
|
||||
if(scene->dispose != NULL) scene->dispose();
|
||||
}
|
||||
}
|
21
src/display/scene/scenemanager.h
Normal file
21
src/display/scene/scenemanager.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "scene.h"
|
||||
|
||||
typedef struct {
|
||||
int nothing;
|
||||
} scenemanager_t;
|
||||
|
||||
extern scenemanager_t SCENE_MANAGER;
|
||||
extern scene_t SCENE_MANAGER_SCENES[SCENE_TYPE_COUNT];
|
||||
|
||||
void sceneManagerInit(void);
|
||||
void sceneManagerUpdate(void);
|
||||
void sceneManagerRender(void);
|
||||
void sceneManagerDispose(void);
|
Reference in New Issue
Block a user