mirror of
https://github.com/danule222/xrbDS.git
synced 2025-06-18 22:35:40 -04:00
Implement basic input system
This commit is contained in:
parent
4aef21edd5
commit
3e8a191739
@ -1,8 +1,11 @@
|
||||
#include "core/engine.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <nds.h>
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
|
||||
#include "input/input.h"
|
||||
|
||||
// Main program function
|
||||
int main(void) {
|
||||
@ -12,7 +15,6 @@ int main(void) {
|
||||
exit(1);
|
||||
|
||||
engine->run();
|
||||
engine->shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -22,36 +24,34 @@ std::unique_ptr<Engine> Engine::Create() {
|
||||
}
|
||||
|
||||
void Engine::run() {
|
||||
isRunning = true;
|
||||
|
||||
while (pmMainLoop()) {
|
||||
processInput();
|
||||
update();
|
||||
renderer->render();
|
||||
render();
|
||||
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::shutdown() { isRunning = false; }
|
||||
|
||||
void Engine::processInput() {
|
||||
scanKeys();
|
||||
int keys = keysDown();
|
||||
}
|
||||
void Engine::processInput() { input->update(); }
|
||||
|
||||
void Engine::update() {
|
||||
// Update
|
||||
}
|
||||
|
||||
void Engine::render() { renderer->render(); }
|
||||
|
||||
Engine::Engine() {
|
||||
isRunning = false;
|
||||
|
||||
// Debug
|
||||
// consoleDemoInit();
|
||||
|
||||
// Initialize the graphics renderer
|
||||
renderer = Renderer::Create();
|
||||
if (!renderer)
|
||||
exit(2);
|
||||
|
||||
// Initialize the input system
|
||||
input = Input::Create();
|
||||
if (!input)
|
||||
exit(3);
|
||||
|
||||
// Debug
|
||||
consoleDemoInit();
|
||||
}
|
@ -3,23 +3,73 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* @class Renderer
|
||||
* @brief A base class for rendering operations.
|
||||
*
|
||||
* The Renderer class provides an interface for rendering graphics, including
|
||||
* methods for managing frames, clearing the screen, and drawing objects.
|
||||
*/
|
||||
class Renderer {
|
||||
public:
|
||||
/**
|
||||
* @brief Virtual destructor for the Renderer class.
|
||||
*
|
||||
* Ensures proper cleanup of derived classes.
|
||||
*/
|
||||
virtual ~Renderer() = default;
|
||||
|
||||
/**
|
||||
* @brief Factory method to create a Renderer instance.
|
||||
*
|
||||
* @return A unique pointer to a Renderer instance.
|
||||
*/
|
||||
static std::unique_ptr<Renderer> Create();
|
||||
|
||||
/**
|
||||
* @brief Renders the current frame.
|
||||
*
|
||||
* This method handles the rendering process, including frame management
|
||||
* and drawing operations.
|
||||
*/
|
||||
void render();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Prepares the renderer for a new frame.
|
||||
*
|
||||
* This method is called at the beginning of the rendering process.
|
||||
*/
|
||||
void beginFrame();
|
||||
|
||||
/**
|
||||
* @brief Finalizes the rendering of the current frame.
|
||||
*
|
||||
* This method is called at the end of the rendering process.
|
||||
*/
|
||||
void endFrame();
|
||||
|
||||
/**
|
||||
* @brief Clears the screen to prepare for rendering.
|
||||
*
|
||||
* This method resets the screen to a default state, typically clearing
|
||||
* any previous drawings.
|
||||
*/
|
||||
void clearScreen();
|
||||
|
||||
/**
|
||||
* @brief Draws a cube of the specified size.
|
||||
*
|
||||
* @param size The size of the cube to be drawn.
|
||||
*/
|
||||
void drawCube(float size);
|
||||
|
||||
/**
|
||||
* @brief Constructor for the Renderer class.
|
||||
*
|
||||
* The constructor is private to enforce the use of the Create() factory
|
||||
* method.
|
||||
*/
|
||||
Renderer();
|
||||
};
|
||||
|
||||
|
@ -1,11 +1,17 @@
|
||||
#include "input/input.h"
|
||||
|
||||
#include <nds.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Input::Input() {
|
||||
// Initialize input system
|
||||
scanKeys();
|
||||
}
|
||||
|
||||
std::unique_ptr<Input> Input::Create() {
|
||||
return std::unique_ptr<Input>(new Input());
|
||||
}
|
||||
|
||||
void Input::update() {
|
||||
// Update key states
|
||||
scanKeys();
|
||||
@ -14,8 +20,8 @@ void Input::update() {
|
||||
keysUpState = keysUp();
|
||||
}
|
||||
|
||||
bool Input::isKeyHeld(int key) const { return keysHeldState & key; }
|
||||
bool Input::isKeyHeld(EKey key) const { return keysHeldState & key; }
|
||||
|
||||
bool Input::isKeyDown(int key) const { return keysDownState & key; }
|
||||
bool Input::isKeyDown(EKey key) const { return keysDownState & key; }
|
||||
|
||||
bool Input::isKeyUp(int key) const { return keysUpState & key; }
|
||||
bool Input::isKeyUp(EKey key) const { return keysUpState & key; }
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "graphics/renderer.h"
|
||||
|
||||
class Input;
|
||||
class MainLoop;
|
||||
class Renderer;
|
||||
|
||||
@ -17,17 +18,14 @@ public:
|
||||
// Run the main game loop
|
||||
void run();
|
||||
|
||||
// Shutdown the engine
|
||||
void shutdown();
|
||||
|
||||
private:
|
||||
bool isRunning;
|
||||
std::unique_ptr<Renderer> renderer;
|
||||
std::unique_ptr<Input> input;
|
||||
|
||||
// Internal methods for the game loop
|
||||
void processInput();
|
||||
void update();
|
||||
|
||||
std::unique_ptr<Renderer> renderer;
|
||||
void render();
|
||||
|
||||
Engine();
|
||||
};
|
||||
|
@ -1,24 +1,43 @@
|
||||
#ifndef XRBDS_INPUT_H
|
||||
#define XRBDS_INPUT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <calico/types.h>
|
||||
#include <nds/input.h>
|
||||
|
||||
enum EKey : u16 {
|
||||
A = KEY_A,
|
||||
B = KEY_B,
|
||||
X = KEY_X,
|
||||
Y = KEY_Y,
|
||||
L = KEY_L,
|
||||
R = KEY_R,
|
||||
START = KEY_START,
|
||||
SELECT = KEY_SELECT,
|
||||
EKEY_COUNT
|
||||
};
|
||||
|
||||
class Input {
|
||||
public:
|
||||
Input();
|
||||
virtual ~Input() = default;
|
||||
|
||||
static std::unique_ptr<Input> Create();
|
||||
|
||||
void update();
|
||||
|
||||
bool isKeyHeld(int key) const;
|
||||
bool isKeyHeld(EKey key) const;
|
||||
|
||||
bool isKeyDown(int key) const;
|
||||
bool isKeyDown(EKey key) const;
|
||||
|
||||
bool isKeyUp(int key) const;
|
||||
bool isKeyUp(EKey key) const;
|
||||
|
||||
private:
|
||||
u32 keysHeldState = 0;
|
||||
u32 keysDownState = 0;
|
||||
u32 keysUpState = 0;
|
||||
|
||||
Input();
|
||||
};
|
||||
|
||||
#endif // XRBDS_INPUT_H
|
Loading…
Reference in New Issue
Block a user