From 010c9da01c2babb470534c601ff43a8a63136fe4 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 30 Aug 2020 12:46:49 +0200 Subject: [PATCH] Cleanup --- Makefile.wiiu | 5 +-- README.md | 12 +++++++- src/gui/GuiButton.h | 6 ++-- src/gui/GuiFrame.cpp | 8 ----- src/gui/GuiFrame.h | 33 ++++++-------------- src/gui/GuiImage.h | 10 +++--- src/gui/GuiSound.h | 4 +-- src/gui/GuiText.cpp | 2 +- src/gui/GuiText.h | 4 +-- src/gui/GuiTrigger.h | 2 +- src/gui/SDLController.h | 4 +-- src/gui/SDLControllerJoystick.h | 2 +- src/gui/SDLControllerMouse.h | 4 +-- src/gui/SDLControllerWiiUGamepad.h | 11 +++---- src/gui/SDLControllerWiiUProContoller.h | 2 +- src/gui/SDLControllerXboxOne.h | 4 +-- src/main.cpp | 41 ++++++++++++------------- 17 files changed, 69 insertions(+), 85 deletions(-) diff --git a/Makefile.wiiu b/Makefile.wiiu index 40d65da..c876fb7 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -33,12 +33,13 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -CXXFLAGS := $(CFLAGS) -std=c++14 +CXXFLAGS := $(CFLAGS) -std=c++20 ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -LIBS := -lSDL2_mixer -lSDL2 -lSDL2_image -ljpeg -lvorbisidec -logg -lmodplug -lmpg123 -lSDL2_ttf -lfreetype -lpng -lz -lbz2 -lwut +LIBS := -lSDL2_mixer -lmodplug -lstdc++ -lm -lmpg123 -lm -lvorbisfile -lvorbis -lm -logg -lSDL2_ttf -lfreetype -lbz2 -lSDL2_image -lpng16 -lz -lm -lz -ljpeg -lSDL2 /opt/devkitpro/wut/lib/libwut.a -lm -Wl,--no-undefined -lSDL2 /opt/devkitpro/wut/lib/libwut.a + #------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level diff --git a/README.md b/README.md index b35d395..034f2f2 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,14 @@ pacman -S git mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-SDL2 mingw64/m mkdir build && cd build C:\devkitPro\msys2\mingw64\bin\cmake.exe -DSDL2_PATH=C:/devkitPro/msys2/mingw64 -Wno-dev -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=C:/devkitPro/msys2/mingw64/bin/g++.exe DCMAKE_C_COMPILER=C:/devkitPro/msys2/mingw64/bin/gcc.exe ../ make -``` \ No newline at end of file +``` + +## Wii U + +Install these libs from [wiiu-fling](https://gitlab.com/QuarkTheAwesome/wiiu-fling#installing): +- `pacman -S wiiu-fling/wiiu-sdl2 wiiu-fling/wiiu-sdl2_gfx wiiu-fling/wiiu-sdl2_image wiiu-fling/wiiu-sdl2_ttf` +And these from [dkp-libs](https://devkitpro.org/wiki/devkitPro_pacman): +- `pacman -S devkitPPC wut-tools wut wiiu-portlibs dkp-libs/wiiu-sdl2_mixer` + +Build via: +`make -f Makefile.wiiu` \ No newline at end of file diff --git a/src/gui/GuiButton.h b/src/gui/GuiButton.h index b5e0c96..40e1e1c 100644 --- a/src/gui/GuiButton.h +++ b/src/gui/GuiButton.h @@ -91,14 +91,14 @@ public: void setTrigger(GuiTrigger *t, int32_t idx = -1); //! - void resetState(void); + void resetState(void) override; //!Constantly called to draw the GuiButton - void draw(CVideo *video); + void draw(CVideo *video) override; //!Constantly called to allow the GuiButton to respond to updated input data //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD - void update(GuiController *c); + void update(GuiController *c) override; sigslot::signal2 selected; sigslot::signal2 deSelected; diff --git a/src/gui/GuiFrame.cpp b/src/gui/GuiFrame.cpp index eeaf77c..7b259eb 100644 --- a/src/gui/GuiFrame.cpp +++ b/src/gui/GuiFrame.cpp @@ -91,14 +91,6 @@ void GuiFrame::removeAll() { mutex.unlock(); } -void GuiFrame::close() { - //Application::instance()->pushForDelete(this); -} - -void GuiFrame::dimBackground(bool d) { - dim = d; -} - GuiElement *GuiFrame::getGuiElementAt(uint32_t index) const { if (index >= elements.size()) { return NULL; diff --git a/src/gui/GuiFrame.h b/src/gui/GuiFrame.h index 9f907d8..ef97816 100644 --- a/src/gui/GuiFrame.h +++ b/src/gui/GuiFrame.h @@ -68,49 +68,34 @@ public: //!Sets the visibility of the window //!\param v visibility (true = visible) - void setVisible(bool v); + void setVisible(bool v) override; //!Resets the window's state to STATE_DEFAULT - void resetState(); + void resetState() override; //!Sets the window's state //!\param s State - void setState(int32_t s, int32_t c = -1); + void setState(int32_t s, int32_t c = -1) override; - void clearState(int32_t s, int32_t c = -1); + void clearState(int32_t s, int32_t c = -1) override; //!Gets the index of the GuiElement inside the window that is currently selected //!\return index of selected GuiElement - int32_t getSelected(); - - //!Dim the Window's background - void dimBackground(bool d); + int32_t getSelected() override; //!Draws all the elements in this GuiFrame - void draw(CVideo *v); + void draw(CVideo *v) override; //!Updates the window and all elements contains within //!Allows the GuiFrame and all elements to respond to the input data specified //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD - void update(GuiController *t); - - //!virtual Close Window - this will put the object on the delete queue in MainWindow - virtual void close(); - - //!virtual show window function - virtual void show() {} - - //!virtual hide window function - virtual void hide() {} - - //!virtual enter main loop function (blocking) - virtual void exec() {} + void update(GuiController *t) override; //!virtual updateEffects which is called by the main loop - virtual void updateEffects(); + void updateEffects() override; //!virtual process which is called by the main loop - virtual void process(); + void process() override; //! Signals //! On Closing diff --git a/src/gui/GuiImage.h b/src/gui/GuiImage.h index 142729d..5691130 100644 --- a/src/gui/GuiImage.h +++ b/src/gui/GuiImage.h @@ -25,18 +25,16 @@ class GuiImage : public GuiElement { public: //!\overload //!\param img Pointer to GuiImageData element - GuiImage(const std::string &path); + explicit GuiImage(const std::string &path); //!Destructor - virtual ~GuiImage(); + ~GuiImage() override; //!Constantly called to draw the image - void draw(CVideo *pVideo); - - + void draw(CVideo *pVideo) override; protected: SDL_Surface *imgSurface = nullptr; SDL_Texture *texture = nullptr; - virtual void process(); + void process() override; }; diff --git a/src/gui/GuiSound.h b/src/gui/GuiSound.h index 6234d26..2664cfc 100644 --- a/src/gui/GuiSound.h +++ b/src/gui/GuiSound.h @@ -25,10 +25,10 @@ public: //!Constructor //!\param sound Pointer to the sound data //!\param filesize Length of sound data - GuiSound(const char *filepath); + explicit GuiSound(const char *filepath); //!Destructor - virtual ~GuiSound(); + ~GuiSound() override; //!Load a file and replace the old one bool Load(const char *filepath); diff --git a/src/gui/GuiText.cpp b/src/gui/GuiText.cpp index 14de7d2..9260acf 100644 --- a/src/gui/GuiText.cpp +++ b/src/gui/GuiText.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . ****************************************************************************/ #include -#include +#include #include "GuiText.h" #include "../CVideo.h" #include "../logger.h" diff --git a/src/gui/GuiText.h b/src/gui/GuiText.h index d726c59..d065f14 100644 --- a/src/gui/GuiText.h +++ b/src/gui/GuiText.h @@ -30,9 +30,9 @@ public: //!\param s Font size //!\param c Font color GuiText(const std::string &t, int32_t s, SDL_Color c, TTF_Font *gFont); - virtual ~GuiText(); + ~GuiText() override; - virtual void draw(CVideo *pVideo); + void draw(CVideo *pVideo) override; protected: SDL_Surface *textSurface = nullptr; diff --git a/src/gui/GuiTrigger.h b/src/gui/GuiTrigger.h index a09adb4..98507bc 100644 --- a/src/gui/GuiTrigger.h +++ b/src/gui/GuiTrigger.h @@ -16,7 +16,7 @@ ****************************************************************************/ #pragma once -#include +#include class GuiController; diff --git a/src/gui/SDLController.h b/src/gui/SDLController.h index 8c13150..d0a0b35 100644 --- a/src/gui/SDLController.h +++ b/src/gui/SDLController.h @@ -10,11 +10,11 @@ class SDLController : public GuiController { public: - SDLController(int32_t channel) : GuiController(channel) { + explicit SDLController(int32_t channel) : GuiController(channel) { } - virtual bool update(SDL_Event *e) = 0; + virtual bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) = 0; virtual void before() { diff --git a/src/gui/SDLControllerJoystick.h b/src/gui/SDLControllerJoystick.h index db28bc9..419171b 100644 --- a/src/gui/SDLControllerJoystick.h +++ b/src/gui/SDLControllerJoystick.h @@ -6,7 +6,7 @@ public: } - virtual bool update(SDL_Event *e) override { + bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override { if (e->type == SDL_JOYBUTTONDOWN) { data.buttons_h |= (1 << e->jbutton.button); } else if (e->type == SDL_JOYBUTTONUP) { diff --git a/src/gui/SDLControllerMouse.h b/src/gui/SDLControllerMouse.h index 896b4e8..8a9d9cb 100644 --- a/src/gui/SDLControllerMouse.h +++ b/src/gui/SDLControllerMouse.h @@ -3,11 +3,11 @@ class SDLControllerMouse: public SDLController { public: - SDLControllerMouse(int32_t channel) : SDLController(channel) { + explicit SDLControllerMouse(int32_t channel) : SDLController(channel) { } - virtual bool update(SDL_Event *e) override { + virtual bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override { if (e->type == SDL_MOUSEMOTION) { data.y = e->motion.y; data.x = e->motion.x; diff --git a/src/gui/SDLControllerWiiUGamepad.h b/src/gui/SDLControllerWiiUGamepad.h index 57529c8..2063539 100644 --- a/src/gui/SDLControllerWiiUGamepad.h +++ b/src/gui/SDLControllerWiiUGamepad.h @@ -21,14 +21,14 @@ static GuiTrigger::eButtons vpad_button_map[] = { class SDLControllerWiiUGamepad : public SDLController { public: - SDLControllerWiiUGamepad(int32_t channel) : SDLController(channel) { + explicit SDLControllerWiiUGamepad(int32_t channel) : SDLController(channel) { } - virtual bool update(SDL_Event *e) override { + bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override { if (e->type == SDL_FINGERMOTION) { - data.y = e->tfinger.y * 720; - data.x = e->tfinger.x * 1280;; + data.y = e->tfinger.y * screenHeight; + data.x = e->tfinger.x * screenWidth;; data.validPointer = true; } else if (e->type == SDL_FINGERUP) { data.validPointer = false; @@ -36,8 +36,7 @@ public: } else if (e->type == SDL_FINGERDOWN) { data.validPointer = true; data.buttons_h |= GuiTrigger::TOUCHED; - } - if (e->type == SDL_JOYBUTTONDOWN) { + } else if (e->type == SDL_JOYBUTTONDOWN) { data.buttons_h |= vpad_button_map[e->jbutton.button]; } else if (e->type == SDL_JOYBUTTONUP) { data.buttons_h &= ~vpad_button_map[e->jbutton.button]; diff --git a/src/gui/SDLControllerWiiUProContoller.h b/src/gui/SDLControllerWiiUProContoller.h index aedbb5d..98684ee 100644 --- a/src/gui/SDLControllerWiiUProContoller.h +++ b/src/gui/SDLControllerWiiUProContoller.h @@ -4,7 +4,7 @@ class SDLControllerWiiUProContoller : public SDLControllerWiiUGamepad { public: - SDLControllerWiiUProContoller(int32_t channel) : SDLControllerWiiUGamepad(channel){ + explicit SDLControllerWiiUProContoller(int32_t channel) : SDLControllerWiiUGamepad(channel){ } }; diff --git a/src/gui/SDLControllerXboxOne.h b/src/gui/SDLControllerXboxOne.h index b89011b..c3cca45 100644 --- a/src/gui/SDLControllerXboxOne.h +++ b/src/gui/SDLControllerXboxOne.h @@ -42,11 +42,11 @@ if(axis == targetAxis){ \ class SDLControllerXboxOne : public SDLController { public: - SDLControllerXboxOne(int32_t channel) : SDLController(channel) { + explicit SDLControllerXboxOne(int32_t channel) : SDLController(channel) { } - virtual bool update(SDL_Event *e) override { + bool update(SDL_Event *e, int32_t screenWidth, int32_t screenHeight) override { if (e->type == SDL_JOYBUTTONDOWN) { data.buttons_h |= xbox_button_map[e->jbutton.button]; } else if (e->type == SDL_JOYBUTTONUP) { diff --git a/src/main.cpp b/src/main.cpp index e64e57a..d612116 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ #include "gui/SDLControllerXboxOne.h" #include "gui/SDLControllerWiiUProContoller.h" -#include +#include #include #include @@ -25,7 +25,7 @@ #ifdef __WIIU__ #include #include -#include +#include #include bool CheckRunning(){ switch(ProcUIProcessMessages(true)) @@ -51,16 +51,14 @@ bool CheckRunning(){ } #endif -void proccessEvents(); - -bool addJoystick(int deviceId, std::map &controllerList, std::map& map); +bool addJoystick(int deviceId, std::map &controllerList, std::map& joystickToChannel); GuiTrigger::eChannels increaseChannel(GuiTrigger::eChannels channel); -void removeJoystick(int32_t which, std::map &controllerList, std::map& joystickToChannel); +void removeJoystick(int32_t instanceId, std::map &controllerList, std::map& joystickToChannel); int main(int argc, char *args[]) { - CVideo *video = new CVideo(); + auto *video = new CVideo(); #if defined _WIN32 // Create the Console @@ -110,19 +108,21 @@ int main(int argc, char *args[]) { bool quit = false; SDL_Event e; while (SDL_PollEvent(&e)) { + int32_t channel = -1; SDL_JoystickID jId = -1; if(e.type == SDL_JOYDEVICEADDED) { addJoystick(e.jdevice.which, controllerList, joystickToChannel); + continue; }else if(e.type == SDL_JOYDEVICEREMOVED) { auto j = SDL_JoystickFromInstanceID(e.jdevice.which); if (j) { removeJoystick(e.jdevice.which, controllerList, joystickToChannel); SDL_JoystickClose(j); + continue; } - }else if (e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP || e.type == SDL_FINGERMOTION){ - controllerList[GuiTrigger::CHANNEL_1]->update(&e); - } else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP || e.type == SDL_MOUSEMOTION){ - controllerList[GuiTrigger::CHANNEL_1]->update(&e); + }else if (e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP || e.type == SDL_FINGERMOTION || + e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP || e.type == SDL_MOUSEMOTION){ + channel = GuiTrigger::CHANNEL_1; } else if (e.type == SDL_JOYAXISMOTION) { jId = e.jaxis.which; } else if (e.type == SDL_JOYHATMOTION) { @@ -136,9 +136,12 @@ int main(int argc, char *args[]) { if(jId != -1){ if(joystickToChannel.find(jId) != joystickToChannel.end()){ - controllerList[joystickToChannel[jId]]->update(&e); + channel = joystickToChannel[jId]; } } + if(channel != -1){ + controllerList[static_cast(channel)]->update(&e, video->getWidth(), video->getHeight()); + } } if(quit){ break; @@ -226,12 +229,8 @@ GuiTrigger::eChannels increaseChannel(GuiTrigger::eChannels channel) { return GuiTrigger::CHANNEL_4; case GuiTrigger::CHANNEL_4: return GuiTrigger::CHANNEL_5; - } - return GuiTrigger::CHANNEL_ALL; -} - -void proccessEvents() { - - int res = 0; - -} + case GuiTrigger::CHANNEL_5: + case GuiTrigger::CHANNEL_ALL: + return GuiTrigger::CHANNEL_ALL; + } +} \ No newline at end of file