Compare commits

...

2 Commits

Author SHA1 Message Date
92aae07fd1 input: optimizado el constructor 2023-05-23 18:30:30 +02:00
bc017c1d55 demo: optimizada la inicialización de input 2023-05-23 18:27:27 +02:00
3 changed files with 7 additions and 22 deletions

View File

@@ -90,24 +90,8 @@ int main(int argc, char *argv[])
screen->addNotifier(asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"));
// Inicializa el objeto input
Input *input = new Input(asset->get("gamecontrollerdb.txt"));
input->setVerbose(options->console);
input->discoverGameController();
//input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
//input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
//input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
//input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
//input->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
//input->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
//input->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
//input->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
string controllerName = "";
int numControllers = input->getNumControllers();
if (numControllers > 0)
{
// Obtiene el nombre del primer mando conectado
controllerName = input->getControllerName(0);
}
Input *input = new Input(asset->get("gamecontrollerdb.txt"), options->console);
string controllerName = input->getControllerName(0);
// Inicializa el texto
Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer);
@@ -282,7 +266,7 @@ int main(int argc, char *argv[])
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'N' para mostrar", 1, {240, 240, 240}, 1, {0, 0, 192});
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, options->screen.nativeWidth / 2, text->getCharacterSize() * 8, "una notificacion", 1, {240, 240, 240}, 1, {0, 0, 192});
debugText->writeCentered(options->screen.nativeWidth / 2, options->screen.nativeHeight / 2, controllerName);
debugText->writeCentered(options->screen.nativeWidth / 2, (options->screen.nativeHeight / 2) + (debugText->getCharacterSize()*2), inputPressed);
debugText->writeCentered(options->screen.nativeWidth / 2, (options->screen.nativeHeight / 2) + (debugText->getCharacterSize() * 2), inputPressed);
// Vuelca el buffer en pantalla
screen->blit();

View File

@@ -2,7 +2,7 @@
#include <iostream>
// Constructor
Input::Input(string file)
Input::Input(string file, bool verbose)
{
// Fichero gamecontrollerdb.txt
dbPath = file;
@@ -18,10 +18,11 @@ Input::Input(string file)
gcb.active = false;
gameControllerBindings.resize(INPUT_TOTAL, gcb);
verbose = true;
this->verbose = verbose;
enabled = true;
setDefaultBindings();
discoverGameController();
}
// Actualiza el estado del objeto

View File

@@ -89,7 +89,7 @@ private:
public:
// Constructor
Input(string file);
Input(string file, bool verbose=true);
// Actualiza el estado del objeto
void update();