Skip to content

Commit

Permalink
wip pc stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
UNSTOP4BLE committed Apr 4, 2024
1 parent a496cc1 commit 2edf798
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 202 deletions.
12 changes: 8 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"version": 6,
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "pc-debug",
"displayName": "Debug (PC)",
"binaryDir": "${sourceDir}/build",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
Expand All @@ -18,6 +19,7 @@
"name": "pc-release",
"displayName": "Release (PC)",
"binaryDir": "${sourceDir}/build",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
Expand All @@ -26,17 +28,19 @@
"name": "psp-debug",
"displayName": "Debug (PSP)",
"binaryDir": "${sourceDir}/build",
"toolchainFile": "$env{PSPDEV}/psp/share/pspdev.cmake",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{PSPDEV}/psp/share/pspdev.cmake",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "psp-release",
"displayName": "Release (PSP)",
"binaryDir": "${sourceDir}/build",
"toolchainFile": "$env{PSPDEV}/psp/share/pspdev.cmake",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{PSPDEV}/psp/share/pspdev.cmake",
"CMAKE_BUILD_TYPE": "Release"
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "chartparser.h"
#include "timer.h"
#include "screen.h"
#include "psp/input.h"

//#ifndef PSP
#include <SDL2/SDL.h>
Expand All @@ -16,6 +17,7 @@ class PSPFunkin
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Surface *screenSurface;
Input::Event event;
//#endif
Timer timer;
Audio::Mixer *audioMixer;
Expand Down
51 changes: 15 additions & 36 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "psp/audio_streamed_file.h"
#include "psp/font.h"
#include "psp/font.h"
#include "psp/pad.h"
#include "psp/input.h"
#include "psp/tween.h"

#include "menu/title.h"
Expand Down Expand Up @@ -60,54 +60,33 @@ int main()
//#else
ASSERTFUNC(SDL_Init(SDL_INIT_EVERYTHING) >= 0, "failed to init sdl");
//#endif
Pad_Init();
app->audioMixer = new Audio::Mixer();
app->audioMixer->start();
GFX::init();
FntInit();
setScreenCol(0xFF00FF00);

Input::KeyboardDevice inputDevice;

app->timer.start();
setScreen(new TitleScreen());
while(1)
{
auto last = std::chrono::high_resolution_clock::now();

if (Pad_Held(PSP_CTRL_CROSS))
printf("press\n");
#ifndef PSP
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch (event.type) {
case SDL_WINDOWEVENT:

switch (event.window.event) {

case SDL_WINDOWEVENT_CLOSE: // exit game

SDL_DestroyWindow(app->window);
app->window = NULL;
app->screenSurface = NULL;
SDL_Quit();
abort();
break;
default:
break;
}
break;
default:
break;
}
}
#endif

#ifdef DEBUG
if (Pad_Pressed(PSP_CTRL_SELECT))
break;
#endif
GFX::clear(app->screenCol);
Pad_Update();
SDL_PumpEvents();

if (Input::windowClosed()) {
// all this should probably be moved to app->quit() or a similar function
SDL_DestroyWindow(app->window);
app->window = NULL;
app->screenSurface = NULL;
SDL_Quit();
abort();
}

inputDevice.getEvent(app->event);
ASSERTFUNC(app->currentScreen, "screen is NULL");
app->currentScreen->update();
app->currentScreen->draw();
Expand Down
8 changes: 4 additions & 4 deletions src/menu/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../main.h"
#include "../screen.h"
#include "../psp/font.h"
#include "../psp/pad.h"
#include "../app.h"

#include "../playstate.h"

Expand All @@ -20,14 +20,14 @@ MainMenuScreen::MainMenuScreen(void) {

void MainMenuScreen::update(void)
{
if (Pad_Pressed(PSP_CTRL_DOWN))
if (app->event.isPressed(Input::MENU_DOWN))
{
selection -= 1;
if (selection < 0)
selection = 0;
backgroundy.setValue(0, 1.0);
}
else if (Pad_Pressed(PSP_CTRL_UP))
else if (app->event.isPressed(Input::MENU_UP))
{
selection += 1;
if (selection > static_cast<int>(COUNT_OF(songs)-1))
Expand All @@ -36,7 +36,7 @@ void MainMenuScreen::update(void)
}
selectedsong = songs[selection];

if (Pad_Pressed(PSP_CTRL_CROSS | PSP_CTRL_START))
if (app->event.isPressed(Input::MENU_ENTER))
setScreen(new PlayStateScreen(selectedsong));
}

Expand Down
4 changes: 2 additions & 2 deletions src/menu/title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "../chartparser.h"
#include "../psp/animation.h"
#include "../psp/audio_file_readers.h"
#include "../psp/pad.h"
#include "../psp/input.h"
#include <chrono>

#include "mainmenu.h"
Expand Down Expand Up @@ -64,7 +64,7 @@ void TitleScreen::update(void)
// AnimOBJECT_SetAnim(&titleGF, 1, -1);
}
// AnimOBJECT_Tick(&titleGF);
if (Pad_Pressed(PSP_CTRL_CROSS | PSP_CTRL_START))
if (app->event.isPressed(Input::MENU_ENTER))
{
if (state != Title)
state = Title;
Expand Down
21 changes: 10 additions & 11 deletions src/playstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "main.h"
#include "screen.h"
#include "psp/font.h"
#include "psp/pad.h"
#include "psp/input.h"
#include "chartparser.h"
#include "character.h"
#include "app.h"
Expand Down Expand Up @@ -98,7 +98,7 @@ void PlayStateScreen::initscr(std::string song) {
notePos.opponent[1] = { 67, 14};
notePos.opponent[2] = {107, 14};
notePos.opponent[3] = {147, 14};

//set up ratings and timings (kinda stolen off of psych engine lmao)
//setRating(Rating &rating, std::string name, int score, bool splash, float ratingmod, int hitwindow)
ratingData.emplace_back("sick", 350, true, 1, 45);
Expand Down Expand Up @@ -298,15 +298,14 @@ void PlayStateScreen::missedNote() {

void PlayStateScreen::updateInput(void)
{
checkPad[0] = Pad_Pressed(PSP_CTRL_LEFT | PSP_CTRL_SQUARE);
checkPad[1] = Pad_Pressed(PSP_CTRL_DOWN | PSP_CTRL_CROSS | PSP_CTRL_LTRIGGER);
checkPad[2] = Pad_Pressed(PSP_CTRL_UP | PSP_CTRL_TRIANGLE | PSP_CTRL_RTRIGGER);
checkPad[3] = Pad_Pressed(PSP_CTRL_RIGHT | PSP_CTRL_CIRCLE);
checkPadHeld[0] = Pad_Held(PSP_CTRL_LEFT | PSP_CTRL_SQUARE);
checkPadHeld[1] = Pad_Held(PSP_CTRL_DOWN | PSP_CTRL_CROSS | PSP_CTRL_LTRIGGER);
checkPadHeld[2] = Pad_Held(PSP_CTRL_UP | PSP_CTRL_TRIANGLE | PSP_CTRL_RTRIGGER);
checkPadHeld[3] = Pad_Held(PSP_CTRL_RIGHT | PSP_CTRL_CIRCLE);

checkPad[0] = app->event.isPressed(Input::GAME_LEFT);
checkPad[1] = app->event.isPressed(Input::GAME_DOWN);
checkPad[2] = app->event.isPressed(Input::GAME_UP);
checkPad[3] = app->event.isPressed(Input::GAME_RIGHT);
checkPadHeld[0] = app->event.isHeld(Input::GAME_LEFT);
checkPadHeld[1] = app->event.isHeld(Input::GAME_DOWN);
checkPadHeld[2] = app->event.isHeld(Input::GAME_UP);
checkPadHeld[3] = app->event.isHeld(Input::GAME_RIGHT);

//handle note hits here? why not lol
//opponent
Expand Down
13 changes: 10 additions & 3 deletions src/psp/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
#include "../app.h"
#include "../screen.h"
#include <SDL2/SDL_image.h>
#define PCSCALE 1 // works by multiplying psp screen res by this number


#include "memory.h"

namespace GFX {

void init(void) {
app->window = SDL_CreateWindow("PSPFunkin", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH * PCSCALE, SCREEN_HEIGHT * PCSCALE, SDL_WINDOW_SHOWN);
app->window = SDL_CreateWindow("PSPFunkin", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
app->renderer = SDL_CreateRenderer(app->window, -1, SDL_RENDERER_ACCELERATED);
app->screenSurface = SDL_GetWindowSurface(app->window);
}
Expand Down Expand Up @@ -43,6 +41,15 @@ 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
5 changes: 5 additions & 0 deletions src/psp/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

namespace GFX {

#ifdef PSP
constexpr int SCREEN_WIDTH = 480;
constexpr int SCREEN_HEIGHT = 272;
#else
constexpr int SCREEN_WIDTH = 1280;
constexpr int SCREEN_HEIGHT = 720;
#endif

template<typename T> struct RECT {
public:
Expand Down
Loading

0 comments on commit 2edf798

Please sign in to comment.