Nothing really changed
This commit is contained in:
@@ -311,6 +311,15 @@ void cmdEcho(const consolecmdexec_t *exec) {
|
|||||||
|
|
||||||
// May move these later
|
// May move these later
|
||||||
void consoleUpdate() {
|
void consoleUpdate() {
|
||||||
|
if(inputPressed(INPUT_BIND_CONSOLE)) {
|
||||||
|
CONSOLE.visible = !CONSOLE.visible;
|
||||||
|
if(CONSOLE.visible) {
|
||||||
|
consolePrint("Console opened.");
|
||||||
|
} else {
|
||||||
|
consolePrint("Console closed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(uint32_t i = 0; i < CONSOLE.execBufferCount; i++) {
|
for(uint32_t i = 0; i < CONSOLE.execBufferCount; i++) {
|
||||||
consolecmdexec_t *exec = &CONSOLE.execBuffer[i];
|
consolecmdexec_t *exec = &CONSOLE.execBuffer[i];
|
||||||
assertNotNull(exec->cmd, "Command execution has no command.");
|
assertNotNull(exec->cmd, "Command execution has no command.");
|
||||||
|
@@ -6,5 +6,46 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
#include "world/overworld.h"
|
||||||
|
|
||||||
scene_t SCENE_CURRENT = SCENE_INITIAL;
|
scene_t SCENE_CURRENT;
|
||||||
|
scenecallback_t SCENE_CALLBACKS[SCENE_COUNT] = {
|
||||||
|
[SCENE_INITIAL] = {
|
||||||
|
.init = NULL,
|
||||||
|
.update = NULL
|
||||||
|
},
|
||||||
|
|
||||||
|
[SCENE_OVERWORLD] = {
|
||||||
|
.init = overworldInit,
|
||||||
|
.update = overworldUpdate,
|
||||||
|
.dispose = NULL
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void sceneInit(void) {
|
||||||
|
for(uint8_t i = 0; i < SCENE_COUNT; i++) {
|
||||||
|
if(SCENE_CALLBACKS[i].init) {
|
||||||
|
SCENE_CALLBACKS[i].init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SCENE_CURRENT = SCENE_INITIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneSet(const scene_t scene) {
|
||||||
|
SCENE_CURRENT = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneUpdate(void) {
|
||||||
|
if(SCENE_CALLBACKS[SCENE_CURRENT].update) {
|
||||||
|
SCENE_CALLBACKS[SCENE_CURRENT].update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneDispose(void) {
|
||||||
|
for(uint8_t i = 0; i < SCENE_COUNT; i++) {
|
||||||
|
if(SCENE_CALLBACKS[i].dispose) {
|
||||||
|
SCENE_CALLBACKS[i].dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -6,10 +6,42 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SCENE_INITIAL,
|
SCENE_INITIAL,
|
||||||
SCENE_OVERWORLD,
|
SCENE_OVERWORLD,
|
||||||
|
|
||||||
|
SCENE_COUNT
|
||||||
} scene_t;
|
} scene_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void (*init)(void);
|
||||||
|
void (*update)(void);
|
||||||
|
void (*dispose)(void);
|
||||||
|
} scenecallback_t;
|
||||||
|
|
||||||
extern scene_t SCENE_CURRENT;
|
extern scene_t SCENE_CURRENT;
|
||||||
|
extern scenecallback_t SCENE_CALLBACKS[SCENE_COUNT];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the scene module.
|
||||||
|
*/
|
||||||
|
void sceneInit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current scene.
|
||||||
|
*
|
||||||
|
* @param scene The scene to set.
|
||||||
|
*/
|
||||||
|
void sceneSet(const scene_t scene);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current scene.
|
||||||
|
*/
|
||||||
|
void sceneUpdate(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of the current scene.
|
||||||
|
*/
|
||||||
|
void sceneDispose(void);
|
@@ -20,13 +20,11 @@ void gameInit(void) {
|
|||||||
inputInit();
|
inputInit();
|
||||||
eventInit();
|
eventInit();
|
||||||
uiTextboxInit();
|
uiTextboxInit();
|
||||||
overworldInit();
|
sceneInit();
|
||||||
|
|
||||||
SCENE_CURRENT = SCENE_OVERWORLD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gameUpdate(void) {
|
void gameUpdate(void) {
|
||||||
overworldUpdate();
|
sceneUpdate();
|
||||||
uiTextboxUpdate();
|
uiTextboxUpdate();
|
||||||
eventUpdate();
|
eventUpdate();
|
||||||
|
|
||||||
@@ -35,5 +33,5 @@ void gameUpdate(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gameDispose(void) {
|
void gameDispose(void) {
|
||||||
|
sceneDispose();
|
||||||
}
|
}
|
@@ -20,20 +20,20 @@ void inputUpdate(void) {
|
|||||||
INPUT.current = inputStateGet();
|
INPUT.current = inputStateGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t inputIsDown(const uint8_t bind) {
|
bool_t inputIsDown(const inputbind_t bind) {
|
||||||
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
|
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
|
||||||
return (INPUT.current & bind) != 0;
|
return (INPUT.current & bind) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t inputWasDown(const uint8_t bind) {
|
bool_t inputWasDown(const inputbind_t bind) {
|
||||||
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
|
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
|
||||||
return (INPUT.previous & bind) != 0;
|
return (INPUT.previous & bind) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t inputPressed(const uint8_t bind) {
|
bool_t inputPressed(const inputbind_t bind) {
|
||||||
return inputIsDown(bind) && !inputWasDown(bind);
|
return inputIsDown(bind) && !inputWasDown(bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t inputReleased(const uint8_t bind) {
|
bool_t inputReleased(const inputbind_t bind) {
|
||||||
return !inputIsDown(bind) && inputWasDown(bind);
|
return !inputIsDown(bind) && inputWasDown(bind);
|
||||||
}
|
}
|
@@ -8,13 +8,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
|
typedef uint8_t inputbind_t;
|
||||||
|
typedef inputbind_t inputstate_t;
|
||||||
|
|
||||||
#define INPUT_BIND_UP (1 << 0)
|
#define INPUT_BIND_UP (1 << 0)
|
||||||
#define INPUT_BIND_DOWN (1 << 1)
|
#define INPUT_BIND_DOWN (1 << 1)
|
||||||
#define INPUT_BIND_LEFT (1 << 2)
|
#define INPUT_BIND_LEFT (1 << 2)
|
||||||
#define INPUT_BIND_RIGHT (1 << 3)
|
#define INPUT_BIND_RIGHT (1 << 3)
|
||||||
#define INPUT_BIND_ACTION (1 << 4)
|
#define INPUT_BIND_ACTION (1 << 4)
|
||||||
#define INPUT_BIND_CANCEL (1 << 5)
|
#define INPUT_BIND_CANCEL (1 << 5)
|
||||||
#define INPUT_BIND_COUNT (INPUT_BIND_CANCEL + 1)
|
#define INPUT_BIND_CONSOLE (1 << 6)
|
||||||
|
|
||||||
|
#define INPUT_BIND_COUNT (INPUT_BIND_CONSOLE + 1)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t current;
|
uint8_t current;
|
||||||
@@ -38,7 +43,7 @@ void inputUpdate(void);
|
|||||||
*
|
*
|
||||||
* @return The current input state as a bitmask.
|
* @return The current input state as a bitmask.
|
||||||
*/
|
*/
|
||||||
uint8_t inputStateGet(void);
|
inputstate_t inputStateGet(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a specific input bind is currently pressed.
|
* Checks if a specific input bind is currently pressed.
|
||||||
@@ -46,7 +51,7 @@ uint8_t inputStateGet(void);
|
|||||||
* @param bind The input bind to check.
|
* @param bind The input bind to check.
|
||||||
* @return true if the bind is currently pressed, false otherwise.
|
* @return true if the bind is currently pressed, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool_t inputIsDown(const uint8_t bind);
|
bool_t inputIsDown(const inputbind_t bind);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a specific input bind was pressed in the last update.
|
* Checks if a specific input bind was pressed in the last update.
|
||||||
@@ -54,7 +59,7 @@ bool_t inputIsDown(const uint8_t bind);
|
|||||||
* @param bind The input bind to check.
|
* @param bind The input bind to check.
|
||||||
* @return true if the bind was pressed in the last update, false otherwise.
|
* @return true if the bind was pressed in the last update, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool_t inputWasDown(const uint8_t bind);
|
bool_t inputWasDown(const inputbind_t bind);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a specific input bind was down this frame but not in the the
|
* Checks if a specific input bind was down this frame but not in the the
|
||||||
@@ -63,7 +68,7 @@ bool_t inputWasDown(const uint8_t bind);
|
|||||||
* @param bind The input bind to check.
|
* @param bind The input bind to check.
|
||||||
* @return true if the bind is currently pressed, false otherwise.
|
* @return true if the bind is currently pressed, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool_t inputPressed(const uint8_t bind);
|
bool_t inputPressed(const inputbind_t bind);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a specific input bind was released this frame.
|
* Checks if a specific input bind was released this frame.
|
||||||
@@ -71,4 +76,4 @@ bool_t inputPressed(const uint8_t bind);
|
|||||||
* @param bind The input bind to check.
|
* @param bind The input bind to check.
|
||||||
* @return true if the bind was released this frame, false otherwise.
|
* @return true if the bind was released this frame, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool_t inputReleased(const uint8_t bind);
|
bool_t inputReleased(const inputbind_t bind);
|
@@ -10,7 +10,6 @@ target_sources(${DUSK_TARGET_NAME}
|
|||||||
renderbackbuffer.c
|
renderbackbuffer.c
|
||||||
rendertext.c
|
rendertext.c
|
||||||
renderconsole.c
|
renderconsole.c
|
||||||
renderscene.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
@@ -19,3 +18,4 @@ add_subdirectory(framebuffer)
|
|||||||
add_subdirectory(mesh)
|
add_subdirectory(mesh)
|
||||||
add_subdirectory(texture)
|
add_subdirectory(texture)
|
||||||
add_subdirectory(spritebatch)
|
add_subdirectory(spritebatch)
|
||||||
|
add_subdirectory(scene)
|
@@ -11,8 +11,7 @@
|
|||||||
#include "rendertext.h"
|
#include "rendertext.h"
|
||||||
#include "renderconsole.h"
|
#include "renderconsole.h"
|
||||||
#include "console/console.h"
|
#include "console/console.h"
|
||||||
#include "dusksdl2input.h"
|
#include "display/scene/renderscene.h"
|
||||||
#include "renderscene.h"
|
|
||||||
#include "display/spritebatch/spritebatch.h"
|
#include "display/spritebatch/spritebatch.h"
|
||||||
#include "display/camera/camera.h"
|
#include "display/camera/camera.h"
|
||||||
|
|
||||||
@@ -95,10 +94,10 @@ errorret_t renderDraw(void) {
|
|||||||
spriteBatchClear();
|
spriteBatchClear();
|
||||||
renderBackBufferBind();
|
renderBackBufferBind();
|
||||||
|
|
||||||
// Draw everything
|
// Draw the scene
|
||||||
renderSceneDraw();
|
renderSceneDraw();
|
||||||
|
|
||||||
// UI
|
// Draw UI
|
||||||
cameraUIPush();
|
cameraUIPush();
|
||||||
renderConsoleDraw();
|
renderConsoleDraw();
|
||||||
spriteBatchFlush();
|
spriteBatchFlush();
|
||||||
|
@@ -10,9 +10,7 @@
|
|||||||
#include "rendertext.h"
|
#include "rendertext.h"
|
||||||
|
|
||||||
void renderConsoleDraw(void) {
|
void renderConsoleDraw(void) {
|
||||||
// if(!CONSOLE.visible) return;
|
if(!CONSOLE.visible) return;
|
||||||
|
|
||||||
// renderTextDraw(0, 0, "Dusk Console");
|
|
||||||
|
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
char_t *line;
|
char_t *line;
|
||||||
|
8
src/dusksdl2/display/renderoverworld.h
Normal file
8
src/dusksdl2/display/renderoverworld.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
@@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2025 Dominic Masters
|
|
||||||
*
|
|
||||||
* This software is released under the MIT License.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "renderscene.h"
|
|
||||||
|
|
||||||
void renderSceneInit(void) {
|
|
||||||
// Initialize scene-related resources here
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderSceneDraw(void) {
|
|
||||||
// Draw the current scene here
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderSceneDispose(void) {
|
|
||||||
// Dispose of scene-related resources here
|
|
||||||
}
|
|
13
src/dusksdl2/display/scene/CMakeLists.txt
Normal file
13
src/dusksdl2/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
|
||||||
|
renderscene.c
|
||||||
|
)
|
||||||
|
|
||||||
|
# Subdirs
|
||||||
|
# add_subdirectory(draw)
|
44
src/dusksdl2/display/scene/renderscene.c
Normal file
44
src/dusksdl2/display/scene/renderscene.c
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "renderscene.h"
|
||||||
|
|
||||||
|
renderscenecallback_t RENDER_SCENE_CALLBACKS[SCENE_COUNT] = {
|
||||||
|
[SCENE_INITIAL] = {
|
||||||
|
.init = NULL,
|
||||||
|
.draw = NULL,
|
||||||
|
.dispose = NULL
|
||||||
|
},
|
||||||
|
|
||||||
|
[SCENE_OVERWORLD] = {
|
||||||
|
.init = NULL,
|
||||||
|
.draw = NULL,
|
||||||
|
.dispose = NULL
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
void renderSceneInit(void) {
|
||||||
|
for (int i = 0; i < SCENE_COUNT; i++) {
|
||||||
|
if (RENDER_SCENE_CALLBACKS[i].init) {
|
||||||
|
RENDER_SCENE_CALLBACKS[i].init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderSceneDraw(void) {
|
||||||
|
if(RENDER_SCENE_CALLBACKS[SCENE_CURRENT].draw) {
|
||||||
|
RENDER_SCENE_CALLBACKS[SCENE_CURRENT].draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void renderSceneDispose(void) {
|
||||||
|
for (int i = 0; i < SCENE_COUNT; i++) {
|
||||||
|
if (RENDER_SCENE_CALLBACKS[i].dispose) {
|
||||||
|
RENDER_SCENE_CALLBACKS[i].dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -6,7 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "display/scene.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void (*init)(void);
|
||||||
|
void (*draw)(void);
|
||||||
|
void (*dispose)(void);
|
||||||
|
} renderscenecallback_t;
|
||||||
|
|
||||||
|
extern renderscenecallback_t RENDER_SCENE_CALLBACKS[SCENE_COUNT];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the render scene module.
|
* Initializes the render scene module.
|
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
#include "dusksdl2input.h"
|
#include "dusksdl2input.h"
|
||||||
|
|
||||||
uint8_t inputStateGet() {
|
inputstate_t inputStateGet() {
|
||||||
uint8_t state = 0;
|
inputstate_t state = 0;
|
||||||
|
|
||||||
#if INPUT_SUPPORT_GAMEPAD
|
#if INPUT_SUPPORT_GAMEPAD
|
||||||
// Get gamepad state.
|
// Get gamepad state.
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
#if INPUT_SUPPORT_GAMEPAD
|
#if INPUT_SUPPORT_GAMEPAD
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const SDL_GameControllerButton button;
|
const SDL_GameControllerButton button;
|
||||||
const uint8_t bind;
|
const inputbind_t bind;
|
||||||
} inputsdlbuttonmap_t;
|
} inputsdlbuttonmap_t;
|
||||||
|
|
||||||
static const inputsdlbuttonmap_t INPUT_SDL_BUTTON_MAP[] = {
|
static const inputsdlbuttonmap_t INPUT_SDL_BUTTON_MAP[] = {
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
{ SDL_CONTROLLER_BUTTON_DPAD_RIGHT, INPUT_BIND_RIGHT },
|
{ SDL_CONTROLLER_BUTTON_DPAD_RIGHT, INPUT_BIND_RIGHT },
|
||||||
{ SDL_CONTROLLER_BUTTON_A, INPUT_BIND_ACTION },
|
{ SDL_CONTROLLER_BUTTON_A, INPUT_BIND_ACTION },
|
||||||
{ SDL_CONTROLLER_BUTTON_B, INPUT_BIND_CANCEL },
|
{ SDL_CONTROLLER_BUTTON_B, INPUT_BIND_CANCEL },
|
||||||
|
{ SDL_CONTROLLER_BUTTON_MISC1, INPUT_BIND_CONSOLE },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -37,7 +38,7 @@
|
|||||||
#if INPUT_SUPPORT_KEYBOARD
|
#if INPUT_SUPPORT_KEYBOARD
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SDL_Scancode code;
|
SDL_Scancode code;
|
||||||
uint8_t bind;
|
inputbind_t bind;
|
||||||
} inputsdlkbmap_t;
|
} inputsdlkbmap_t;
|
||||||
|
|
||||||
static const inputsdlkbmap_t INPUT_SDL_KEYBOARD_MAP[] = {
|
static const inputsdlkbmap_t INPUT_SDL_KEYBOARD_MAP[] = {
|
||||||
@@ -47,6 +48,7 @@
|
|||||||
{ SDL_SCANCODE_D, INPUT_BIND_RIGHT },
|
{ SDL_SCANCODE_D, INPUT_BIND_RIGHT },
|
||||||
{ SDL_SCANCODE_SPACE, INPUT_BIND_ACTION },
|
{ SDL_SCANCODE_SPACE, INPUT_BIND_ACTION },
|
||||||
{ SDL_SCANCODE_ESCAPE, INPUT_BIND_CANCEL },
|
{ SDL_SCANCODE_ESCAPE, INPUT_BIND_CANCEL },
|
||||||
|
{ SDL_SCANCODE_GRAVE, INPUT_BIND_CONSOLE },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
Reference in New Issue
Block a user