Skip to content

Commit

Permalink
cmake presets
Browse files Browse the repository at this point in the history
  • Loading branch information
UNSTOP4BLE committed Apr 4, 2024
1 parent 2edf798 commit f710e18
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion build commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

11 changes: 7 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -85,7 +88,7 @@ int main()
SDL_Quit();
abort();
}

*/
inputDevice.getEvent(app->event);
ASSERTFUNC(app->currentScreen, "screen is NULL");
app->currentScreen->update();
Expand All @@ -97,7 +100,7 @@ int main()
last = current;

}
#ifdef DEBUG
#if defined(DEBUG) && defined(PSP)
gprof_cleanup();
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/playstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions src/psp/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ template<typename T> void drawTex(Texture* tex, GFX::RECT<int> *Img, GFX::RECT<T
{
SDL_Rect _img = {static_cast<int>(Img->x), static_cast<int>(Img->y), static_cast<int>(Img->w), static_cast<int>(Img->h)};
SDL_Rect _disp = {static_cast<int>(Disp->x), static_cast<int>(Disp->y), static_cast<int>(Disp->w), static_cast<int>(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<double>(angle), NULL, SDL_FLIP_NONE) >= 0, "failed to display sprite");
Expand Down
10 changes: 5 additions & 5 deletions src/psp/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T> struct RECT {
public:
Expand Down
82 changes: 34 additions & 48 deletions src/psp/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand 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
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

}
24 changes: 8 additions & 16 deletions src/psp/input.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <cstdio>

#include <cstdint>

namespace Input {
Expand All @@ -23,6 +23,7 @@ enum Button {
MENU_ESCAPE,
MENU_OPTION
};

struct Event {
public:
uint32_t timestamp;
Expand All @@ -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);
}

0 comments on commit f710e18

Please sign in to comment.