From f710e18f480136033f66327755ec871e2bb706db Mon Sep 17 00:00:00 2001 From: UNSTOP4BLE Date: Thu, 4 Apr 2024 23:32:56 +0200 Subject: [PATCH] cmake presets --- .github/workflows/main.yml | 2 +- build commands.txt | 2 +- src/main.cpp | 11 +++-- src/playstate.cpp | 4 +- src/psp/gfx.cpp | 8 ---- src/psp/gfx.h | 10 ++--- src/psp/input.cpp | 82 ++++++++++++++++---------------------- src/psp/input.h | 24 ++++------- 8 files changed, 58 insertions(+), 85 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 39a7e45..c0099cf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: - name: Checkout uses: actions/checkout@main - name: Install Dependencies And Compile - run: apk add cmake gmp mpc1 mpfr4 gcc g++ --quiet && cd cht2bin && cmake -S . -B ./build && cmake --build ./build && cd .. && psp-cmake -S . -B ./build && cmake --build ./build && mkdir export && cht2bin/build/cht2bin assets/songs/bopeebo/bopeebo.json build/assets/songs/bopeebo/bopeebo.bin && cp -R build export + run: apk add cmake gmp mpc1 mpfr4 gcc g++ --quiet && cd cht2bin && cmake -S . -B ./build && cmake --build ./build && cd .. && cmake --preset psp-release && cmake --build ./build && mkdir export && cht2bin/build/cht2bin assets/songs/bopeebo/bopeebo.json build/assets/songs/bopeebo/bopeebo.bin && cp -R build export - name: Publish Artifact uses: actions/upload-artifact@main with: diff --git a/build commands.txt b/build commands.txt index 3ff8ebd..6dd108d 100644 --- a/build commands.txt +++ b/build commands.txt @@ -3,6 +3,6 @@ cmake -S . -B ./build cmake --build ./build funkin: -psp-cmake -S . -B ./build or cmake -S . -B ./build -DCMAKE_TOOLCHAIN_FILE="${PSPDEV}/psp/share/pspdev.cmake" +cmake --preset psp cmake --build ./build diff --git a/src/main.cpp b/src/main.cpp index 81a691e..a7bd262 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -66,8 +66,11 @@ int main() FntInit(); setScreenCol(0xFF00FF00); +#ifdef PSP + Input::ControllerDevice inputDevice; +#else Input::KeyboardDevice inputDevice; - +#endif app->timer.start(); setScreen(new TitleScreen()); while(1) @@ -76,7 +79,7 @@ int main() GFX::clear(app->screenCol); SDL_PumpEvents(); - + /* if (Input::windowClosed()) { // all this should probably be moved to app->quit() or a similar function SDL_DestroyWindow(app->window); @@ -85,7 +88,7 @@ int main() SDL_Quit(); abort(); } - +*/ inputDevice.getEvent(app->event); ASSERTFUNC(app->currentScreen, "screen is NULL"); app->currentScreen->update(); @@ -97,7 +100,7 @@ int main() last = current; } -#ifdef DEBUG +#if defined(DEBUG) && defined(PSP) gprof_cleanup(); #endif diff --git a/src/playstate.cpp b/src/playstate.cpp index a0fdd30..4171de3 100644 --- a/src/playstate.cpp +++ b/src/playstate.cpp @@ -167,7 +167,7 @@ void PlayStateScreen::update(void) } else { - app->parser.songTime += app->timer.elapsedS(); + app->parser.songTime += app->timer.elapsedS()*1000; //song start if (app->parser.curStep <= 0) @@ -262,7 +262,7 @@ void PlayStateScreen::draw(void) void PlayStateScreen::freescr(void) { delete player; delete opponent; - // delete gf; + delete gf; curstage.free(); GFX::freeTex(hud); GFX::freeTex(icons); diff --git a/src/psp/gfx.cpp b/src/psp/gfx.cpp index cc2f290..c340a56 100644 --- a/src/psp/gfx.cpp +++ b/src/psp/gfx.cpp @@ -41,14 +41,6 @@ template void drawTex(Texture* tex, GFX::RECT *Img, GFX::RECT(Img->x), static_cast(Img->y), static_cast(Img->w), static_cast(Img->h)}; SDL_Rect _disp = {static_cast(Disp->x), static_cast(Disp->y), static_cast(Disp->w), static_cast(Disp->h)}; -#ifndef PSP - float factorw = (SCREEN_WIDTH/480); - float factorh = (SCREEN_HEIGHT/272); - _disp.x *= factorw; - _disp.y *= factorh; - _disp.w *= factorw; - _disp.h *= factorh; -#endif SDL_SetTextureAlphaMod(tex, alpha); ASSERTFUNC(SDL_RenderCopyEx(app->renderer, tex, &_img, &_disp, static_cast(angle), NULL, SDL_FLIP_NONE) >= 0, "failed to display sprite"); diff --git a/src/psp/gfx.h b/src/psp/gfx.h index 4215a52..2dac076 100644 --- a/src/psp/gfx.h +++ b/src/psp/gfx.h @@ -4,13 +4,13 @@ namespace GFX { -#ifdef PSP +//#ifdef PSP constexpr int SCREEN_WIDTH = 480; constexpr int SCREEN_HEIGHT = 272; -#else -constexpr int SCREEN_WIDTH = 1280; -constexpr int SCREEN_HEIGHT = 720; -#endif +//#else +//constexpr int SCREEN_WIDTH = 1280; +//constexpr int SCREEN_HEIGHT = 720; +//#endif template struct RECT { public: diff --git a/src/psp/input.cpp b/src/psp/input.cpp index 1f4926b..e023703 100644 --- a/src/psp/input.cpp +++ b/src/psp/input.cpp @@ -10,22 +10,6 @@ namespace Input { -static const SDL_Scancode keyboardMapping[NUM_BUTTONS]{ - SDL_SCANCODE_UP, // GAME_UP - SDL_SCANCODE_DOWN, // GAME_DOWN - SDL_SCANCODE_LEFT, // GAME_LEFT - SDL_SCANCODE_RIGHT, // GAME_RIGHT - SDL_SCANCODE_ESCAPE, // GAME_PAUSE - - SDL_SCANCODE_UP, // MENU_UP - SDL_SCANCODE_DOWN, // MENU_DOWN - SDL_SCANCODE_LEFT, // MENU_LEFT - SDL_SCANCODE_RIGHT, // MENU_RIGHT - SDL_SCANCODE_RETURN, // MENU_ENTER - SDL_SCANCODE_ESCAPE, // MENU_ESCAPE - SDL_SCANCODE_TAB // MENU_OPTION -}; - #ifdef PSP static const uint32_t pspMapping[NUM_BUTTONS]{ PSP_CTRL_UP | PSP_CTRL_TRIANGLE, // GAME_UP @@ -58,10 +42,27 @@ static const int controllerMapping[NUM_BUTTONS][2]{ { SDL_CONTROLLER_BUTTON_B, -1 }, // MENU_ESCAPE { SDL_CONTROLLER_BUTTON_X -1 } // MENU_OPTION }; + +static const SDL_Scancode keyboardMapping[NUM_BUTTONS]{ + SDL_SCANCODE_UP, // GAME_UP + SDL_SCANCODE_DOWN, // GAME_DOWN + SDL_SCANCODE_LEFT, // GAME_LEFT + SDL_SCANCODE_RIGHT, // GAME_RIGHT + SDL_SCANCODE_ESCAPE, // GAME_PAUSE + + SDL_SCANCODE_UP, // MENU_UP + SDL_SCANCODE_DOWN, // MENU_DOWN + SDL_SCANCODE_LEFT, // MENU_LEFT + SDL_SCANCODE_RIGHT, // MENU_RIGHT + SDL_SCANCODE_RETURN, // MENU_ENTER + SDL_SCANCODE_ESCAPE, // MENU_ESCAPE + SDL_SCANCODE_TAB // MENU_OPTION +}; #endif bool KeyboardDevice::getEvent(Event &output) { output.reset(); + output.buttonsHeld = _buttonsHeld; #ifdef PSP // PSP has no keyboard @@ -76,8 +77,8 @@ bool KeyboardDevice::getEvent(Event &output) { if (event.key.keysym.scancode != keyboardMapping[i]) continue; - //if (event.key.repeat) - //continue; + if (event.key.repeat) + continue; if (event.type == SDL_KEYDOWN) { output.buttonsPressed |= bits; @@ -90,7 +91,6 @@ bool KeyboardDevice::getEvent(Event &output) { output.timestamp = event.key.timestamp; output.buttonsHeld = _buttonsHeld; valid = true; - printf("%d %d\n", i, output.buttonsHeld); } } @@ -99,32 +99,29 @@ bool KeyboardDevice::getEvent(Event &output) { } bool ControllerDevice::getEvent(Event &output) { - output.reset(); - #ifdef PSP - SceCtrlData state; - SceCtrlLatch events; - - if (sceCtrlReadBufferPositive(&state) <= 0) - return false; - if (sceCtrlReadLatch(&events) <= 0) - return false; + auto lastHeld = _buttonsHeld; + _buttonsHeld = 0; - output.timestamp = state.TimeStamp; + SceCtrlData state; + sceCtrlReadBufferPositive(&state, 1); for (int i = 0; i < NUM_BUTTONS; i++) { - uint32_t bits = 1 << i; - - if (events.uiMake & pspMapping[i]) - output.buttonsPressed |= bits; - if (events.uiBreak & pspMapping[i]) - output.buttonsReleased |= bits; - if (events.uiPress & pspMapping[i]) - output.buttonsHeld |= bits; + if (state.Buttons & pspMapping[i]) + _buttonsHeld |= 1 << i; } + auto changed = _buttonsHeld ^ lastHeld; + + output.timestamp = state.TimeStamp; + output.buttonsPressed = changed & _buttonsHeld; + output.buttonsReleased = changed & lastHeld; + output.buttonsHeld = _buttonsHeld; return true; #else + output.reset(); + output.buttonsHeld = _buttonsHeld; + SDL_Event event; bool valid = false; @@ -158,15 +155,4 @@ bool ControllerDevice::getEvent(Event &output) { #endif } -bool windowClosed(void) { - SDL_Event event; - - while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT) > 0) { - if (event.window.event == SDL_WINDOWEVENT_CLOSE) - return true; - } - - return false; -} - } diff --git a/src/psp/input.h b/src/psp/input.h index 4e781e1..4aa13f2 100644 --- a/src/psp/input.h +++ b/src/psp/input.h @@ -1,5 +1,5 @@ #pragma once -#include + #include namespace Input { @@ -23,6 +23,7 @@ enum Button { MENU_ESCAPE, MENU_OPTION }; + struct Event { public: uint32_t timestamp; @@ -41,38 +42,29 @@ struct Event { return (buttonsReleased >> button) & 1; } inline bool isHeld(Button button) { - printf("isHeld %d\n",buttonsHeld); return (buttonsHeld >> button) & 1; } }; class Device { +protected: + uint32_t _buttonsHeld; + public: + inline Device(void) + : _buttonsHeld(0) {} + virtual bool getEvent(Event &output) { (void)output; return false; } }; class KeyboardDevice : public Device { -private: - uint32_t _buttonsHeld; - public: - inline KeyboardDevice(void) - : _buttonsHeld(0) {} - bool getEvent(Event &output); }; class ControllerDevice : public Device { -private: - uint32_t _buttonsHeld; - public: - inline ControllerDevice(void) - : _buttonsHeld(0) {} - bool getEvent(Event &output); }; - -bool windowClosed(void); }