Skip to content

Commit

Permalink
Moved PSP build from SDL1 to SDL2; Adjustments due to toolchain update
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeef committed May 14, 2024
1 parent eb940a6 commit d6831af
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 91 deletions.
81 changes: 33 additions & 48 deletions cmake/DependenciesPSP.cmake
Original file line number Diff line number Diff line change
@@ -1,61 +1,46 @@
# FIXME: This macro probably defines target that links to more libraries than actually needed.
macro(add_psp_dependencies)
add_library(SDL_1_XX INTERFACE)
target_link_libraries(SDL_1_XX INTERFACE
-lSDL_mixer
-lSDLmain
-lSDL
)
add_library(PSP_SDK INTERFACE)
target_link_libraries(PSP_SDK INTERFACE
-L${PSPDEV}/psp/sdk/lib
-lpspirkeyb
-lpspdebug
-lpspgu
-lpspvram
-lpspvfpu
-lpspctrl
-lpspge
-lpspdisplay
-lpsphprm
-lpspaudio
-lpsppower_driver
-lpsppower
)

add_library(SDL_2_XX INTERFACE)
target_link_libraries(SDL_2_XX INTERFACE
-L${PSPDEV}/psp
-lGL
-lmodplug
-lvorbisenc
-lvorbisfile
-lvorbis
-logg
-lSDL2_mixer
-lSDL2main
-lSDL2
)

add_library(Dependencies INTERFACE)
target_link_libraries(Dependencies INTERFACE
-L${PSPDEV}/psp/lib
-lg
-lstdc++
-lc
-lGLU
-lglut
-lz
-lm
-lGL
-lvorbisidec
-lmikmod
-lpspvfpu
-L${PSPDEV}/psp/sdk/lib
-L${PSPDEV}/psp
-lpspdebug
-lpspgu
-lpspctrl
-lpspge
-lpspirkeyb
-lpsppower
-lpsppower_driver
-lpspdisplay
-lpsphprm
-lpspsdk
-lpsprtc
-lpspaudio
-lpsputility
-lpspnet_inet
-lc
-lpspuser
)

PSP_SDK
)
target_compile_definitions(Dependencies INTERFACE
SPELUNKY_PSP_PLATFORM_PSP
-Dmain=SDL_main
)

)
endmacro()

macro(spelunky_psp_post_build_psp)
add_custom_command(
TARGET Spelunky_PSP
POST_BUILD COMMAND
"psp-strip" "$<TARGET_FILE:Spelunky_PSP>"
COMMENT "Stripping binary"
)

create_pbp_file(TARGET Spelunky_PSP
ICON_PATH ${ASSETS_PATH}/metadata/icon.png
BACKGROUND_PATH ${ASSETS_PATH}/metadata/background.png
Expand Down
3 changes: 2 additions & 1 deletion scripts/config-psp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ cd $BUILD_PATH

psp-cmake $ROOT_PATH \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH
-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH \
-DCMAKE_VERBOSE_MAKEFILE=ON
2 changes: 1 addition & 1 deletion src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ target_link_libraries(Audio
Patterns
PRIVATE
Logger
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,SDL_1_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>,SDL_1_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_DARWIN}>,SDL_2_XX,>
Expand Down
5 changes: 3 additions & 2 deletions src/audio/src/Audio_SDL_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#include "AudioBank.hpp"
#include "logger/log.h"

#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
// FIXME: Forcing SDL2; move all platforms to SDL2 (Windows left)
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>

#include <type_traits>
#include <cassert>
Expand Down
2 changes: 1 addition & 1 deletion src/input/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ target_link_libraries(Input
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_DARWIN}>:SDL_2_XX>
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>:SDL_2_XX>
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>:SDL_1_XX>
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>:SDL_1_XX>
$<$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>:SDL_2_XX>
$<$<BOOL:${SPELUNKY_PSP_WITH_IMGUI}>:imgui>
Dependencies
)
4 changes: 2 additions & 2 deletions src/time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project(Time)

add_library(Time STATIC
interface/time/Timestep.hpp
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,src/Timestep_SDL1.cpp,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,src/Timestep_SDL2.cpp,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>,src/Timestep_SDL1.cpp,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>,src/Timestep_SDL1.cpp,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_DARWIN}>,src/Timestep_SDL2.cpp,>
Expand All @@ -15,7 +15,7 @@ target_include_directories(Time
)

target_link_libraries(Time PUBLIC
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,SDL_1_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>,SDL_1_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_DARWIN}>,SDL_2_XX,>
Expand Down
4 changes: 3 additions & 1 deletion src/time/src/Timestep_SDL2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "time/Timestep.hpp"
#include <SDL_timer.h>

// FIXME: Forcing SDL2; move all platforms to SDL2 (Windows left)
#include <SDL2/SDL_timer.h>

Timestamp Timestep::delay() const
{
Expand Down
2 changes: 1 addition & 1 deletion src/video/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ target_link_libraries(Video
glad
Input
GraphicsUtils
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,SDL_1_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>,SDL_1_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>,SDL_2_XX,>
$<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_DARWIN}>,SDL_2_XX,>
Expand Down
67 changes: 34 additions & 33 deletions src/video/src/Video_PSP.cpp
Original file line number Diff line number Diff line change
@@ -1,81 +1,82 @@
//
// Created by dbeef on 7/7/19.
//
#include "video/Video.hpp"
#include "glad/glad.h"
#include "graphics_utils/DebugGlCall.hpp"
#include "time/Timestep.hpp"
#include "logger/log.h"
#include "glad/glad.h"

#include <SDL/SDL.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>

struct PlatformSpecific
{
// Nothing platform specific to be stored.
SDL_Window* window;
void* gl_context;
};

Video::~Video() = default; // For pimpl idiom.
Video::Video() : _timestep(60) {}; // For pimpl idiom.

void Video::tear_down_gl()
{
SDL_GL_DeleteContext(_platform_specific->gl_context);
SDL_DestroyWindow(_platform_specific->window);
SDL_QuitSubSystem(SDL_INIT_VIDEO);

_platform_specific->window = nullptr;
_platform_specific->gl_context = nullptr;
}

void Video::swap_buffers() const
{
SDL_GL_SwapBuffers();
SDL_GL_SwapWindow(_platform_specific->window);
}

bool Video::setup_gl()
{
log_info("Entered Video::setup_gl.");

_platform_specific = std::make_unique<PlatformSpecific>();
_viewport = std::make_shared<Viewport>(480, 272);

if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
log_error("SDL_Init Error: %s", SDL_GetError());
SDL_ClearError();
return false;
}

SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );

SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 0);
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0);

SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);

SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1);

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_LoadLibrary(nullptr);
SDL_ClearError();

// Create a window
auto surface = SDL_SetVideoMode(_viewport->get_width_pixels(),
_viewport->get_height_pixels(),
0, // current display's bpp
SDL_DOUBLEBUF | SDL_OPENGL | SDL_SWSURFACE);

if (!surface) {
log_error("SDL_SetVideoMode Error: %s", SDL_GetError());
_platform_specific->window = SDL_CreateWindow("SpelunkyPSP",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
480, 272,
SDL_WINDOW_OPENGL);
if (!_platform_specific->window)
{
log_error("SDL_CreateWindow Error: %s", SDL_GetError());
SDL_ClearError();
return false;
}

if(!gladLoadGLES1Loader((GLADloadproc) SDL_GL_GetProcAddress)) {
log_error("Error while loading ptrs to OpenGL functions");
int w, h;
SDL_GL_GetDrawableSize(_platform_specific->window, &w, &h);
_viewport = std::make_shared<Viewport>(w, h);

_platform_specific->gl_context = SDL_GL_CreateContext(_platform_specific->window);
if (!_platform_specific->gl_context)
{
log_error("SDL_GL_CreateContext Error: %s", SDL_GetError());
SDL_ClearError();
return false;
}

SDL_GL_MakeCurrent(_platform_specific->window, _platform_specific->gl_context);
SDL_ClearError();

DebugGlCall(glEnable(GL_TEXTURE_2D));

DebugGlCall(glShadeModel(GL_SMOOTH));
DebugGlCall(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE));

Expand Down
2 changes: 1 addition & 1 deletion vendor/glad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (SPELUNKY_PSP_PLATFORM_LINUX OR
SPELUNKY_PSP_PLATFORM_DARWIN)
add_subdirectory(glad_opengl_1.3)
elseif(SPELUNKY_PSP_PLATFORM_PSP)
add_subdirectory(glad_opengl_es_1.0)
add_subdirectory(glad_dummy)
elseif(SPELUNKY_PSP_PLATFORM_ANDROID)
add_subdirectory(glad_opengl_es_1.0)
else()
Expand Down
5 changes: 5 additions & 0 deletions vendor/glad/glad_dummy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_library(glad INTERFACE)
target_include_directories(glad INTERFACE include)

# For platform defines:
target_link_libraries(glad INTERFACE Dependencies)
1 change: 1 addition & 0 deletions vendor/glad/glad_dummy/include/glad/glad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "SDL2/SDL_opengl.h"

0 comments on commit d6831af

Please sign in to comment.