Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Playstation Vita Support #14

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
508f4dc
Initial work, still crashes
sharkwouter May 9, 2020
c3ba08f
Use json file for configuration
sharkwouter May 9, 2020
e6be53a
Update README
sharkwouter May 9, 2020
2d52291
Improve output when config can't be loaded
sharkwouter May 9, 2020
763d996
Update CMakeLists.txt for Vita
sharkwouter May 9, 2020
346720c
Updated CMakeLists.txt and added assets
sharkwouter May 9, 2020
7843b4c
Remove CMake directory
sharkwouter May 9, 2020
cebe499
Fix keys not loading from configuration
sharkwouter May 14, 2020
bb82760
Moved vita specific assets
sharkwouter May 14, 2020
f156b80
Set resolution to vita one
sharkwouter May 14, 2020
8c49d5f
Update configuration file
sharkwouter May 14, 2020
7dcfce4
Use DOLCESDK
sharkwouter Dec 11, 2020
047011d
Change config to use start and not disable music
sharkwouter Dec 12, 2020
f6cfc19
Add app0:/ to all file loading
sharkwouter Dec 12, 2020
fc637f6
Make panel-pop able to compile for PC again
sharkwouter Dec 12, 2020
97544eb
Clean up config file
sharkwouter Dec 12, 2020
a13812d
Removed out of place spaces
sharkwouter Dec 12, 2020
eb2b537
Minimize changes from master
sharkwouter Dec 12, 2020
9f3972f
Remove useless print statement
sharkwouter Dec 12, 2020
1cff2a9
Make same codebase work with both PC and Vita
sharkwouter Dec 12, 2020
a409f3f
Fix formatting
sharkwouter Dec 12, 2020
c3a4a4f
Make configuration writable for PS Vita
sharkwouter Dec 12, 2020
46dbe9e
Don't show options which make no sense to Vita users
sharkwouter Dec 12, 2020
7be217c
Fix small error in json file for Vita
sharkwouter Dec 12, 2020
f21fdf6
Update version and title on Vita
sharkwouter Dec 12, 2020
9a3029f
Fix version number
sharkwouter Dec 12, 2020
3550fe5
Replace placeholder images for Vita
sharkwouter Dec 12, 2020
0b1332d
Add source for startup image
sharkwouter Dec 12, 2020
1794013
Updated README with instructions on how to build Vita version
sharkwouter Dec 12, 2020
9cf54be
Fix Playstation Vita title in README being too big
sharkwouter Dec 14, 2020
f938c81
Update README.md
sharkwouter Dec 14, 2020
5d1d036
Use VITASDK instead of the unsupported DolceSDK
sharkwouter Dec 23, 2023
1ae534b
Clean up some Vita specific code
sharkwouter Dec 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 73 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,80 @@ set(SRCS
Menus/Menu.cpp
InputState.cpp InputState.h InputEvents/InputEvent.cpp InputEvents/InputEvent.h InputEvents/KeyboardKey.cpp InputEvents/KeyboardKey.h Config/InputConfig.cpp Config/InputConfig.h InputEvents/JoyButton.cpp InputEvents/JoyButton.h InputEvents/JoyHat.cpp InputEvents/JoyHat.h InputEvents/JoyAxisDirection.cpp InputEvents/JoyAxisDirection.h)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/CMake")

add_executable(panel-pop ${SRCS})

find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)
if (VITA)
# Project start
set(VITA_APPNAME PanelPop)
set(VITA_TITLEID "PPOP00001")
set(VITA_VERSION "00.03")

# Find libraries
include(FindPkgConfig)
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer)
pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
pkg_search_module(JSONCPP REQUIRED jsoncpp)

target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${JSONCPP_LIBRARIES}
)

include_directories(
${PROJECT_SOURCE_DIR}/include
${SDL2_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
${JSONCPP_INCLUDE_DIRS}
)

include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
vita_create_self(panel-pop.self panel-pop)

vita_create_vpk(panel-pop.vpk ${VITA_TITLEID} panel-pop.self
VERSION ${VITA_VERSION}
NAME ${VITA_APPNAME}
FILE platform/vita/sce_sys sce_sys
FILE platform/vita/panelpop.json panelpop.json
FILE assets/fonts assets/fonts
FILE assets/music assets/music
FILE assets/sfx assets/sfx
FILE assets/1p.png assets/1p.png
FILE assets/2p.png assets/2p.png
FILE assets/bg1.png assets/bg1.png
FILE assets/sprites.png assets/sprites.png
FILE assets/title.png assets/title.png
)
ELSE()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/CMake")

find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)

find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(jsoncpp REQUIRED)
get_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)

include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR}
${SDL2_MIXER_INCLUDE_DIR})
include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR}
${SDL2_MIXER_INCLUDE_DIR}
${JSON_INC_PATH})

target_link_libraries(panel-pop ${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${SDL2_MIXER_LIBRARIES})
target_link_libraries(panel-pop ${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
jsoncpp)
ENDIF()
62 changes: 34 additions & 28 deletions Config/ConfigHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include "../InputEvents/JoyButton.h"
#include "../InputEvents/JoyAxisDirection.h"

#include <boost/property_tree/detail/ptree_implementation.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <SDL2/SDL_keyboard.h>
#include <SDL2/SDL_scancode.h>
#include <SDL2/SDL_mixer.h>
#include <exception>
#include <iostream>
#include <string>
#include <json/json.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess going from INI to JSON is OK. I know handling C++ dependencies on Windows is a pain though...

#include <fstream>

ConfigHandler::ConfigHandler() {
}
Expand All @@ -30,25 +30,32 @@ ConfigHandler &ConfigHandler::getInstance() {
}

bool ConfigHandler::loadConfig() {
try {
boost::property_tree::read_ini(CONFIG_FILENAME, _settingsTree);
} catch (std::exception &e) {
std::cerr << "error in reading config file, using defaults..."
<< std::endl;
std::cerr << e.what();
std::ifstream configFile;
std::string configPath = CONFIG_DIR + CONFIG_FILENAME;
configFile.open(configPath, std::ios::in);
Json::CharReaderBuilder builder;
JSONCPP_STRING errs;
if (!parseFromStream(builder, configFile, &_settingsTree, &errs)) {
std::cerr << "error in reading config file, using defaults..." << std::endl;
std::cerr << errs;
configFile.close();
return false;
}
configFile.close();
return true;
}

bool ConfigHandler::saveConfig() {
boost::property_tree::write_ini(CONFIG_FILENAME, _settingsTree);
std::string configPath = CONFIG_DIR + CONFIG_FILENAME;
std::ofstream configFile(configPath, std::ios::binary);
configFile << _settingsTree;
configFile.close();
return true;
}

InputConfig ConfigHandler::getKeyConfig(int player) {

auto prefix = "keys.p" + std::to_string(player) + "_";
auto prefix = "p" + std::to_string(player) + "_";
return InputConfig(parseInputEvent(prefix + "up"),
parseInputEvent(prefix + "down"),
parseInputEvent(prefix + "left"),
Expand All @@ -60,7 +67,7 @@ InputConfig ConfigHandler::getKeyConfig(int player) {
}

InputEvent *ConfigHandler::parseInputEvent(const std::string &configKey) {
std::string value = _settingsTree.get<std::string>(configKey);
std::string value = _settingsTree["keys"].get(configKey, "").asString();

char type = value[0];
switch (type) {
Expand Down Expand Up @@ -94,52 +101,51 @@ InputEvent *ConfigHandler::parseInputEvent(const std::string &configKey) {
}

void ConfigHandler::setKeyConfig(InputConfig config, int player) {

StateManager::getInstance().setKeys(config, player);
auto prefix = "keys.p" + std::to_string(player) + "_";
_settingsTree.put(prefix + "up", config._up->toString());
_settingsTree.put(prefix + "down", config._down->toString());
_settingsTree.put(prefix + "left", config._left->toString());
_settingsTree.put(prefix + "right", config._right->toString());
_settingsTree.put(prefix + "swap", config._swap->toString());
_settingsTree.put(prefix + "raiseStack", config._raiseStack->toString());
_settingsTree.put(prefix + "start", config._start->toString());
auto prefix = "p" + std::to_string(player) + "_";
_settingsTree["keys"][prefix + "up"] = config._up->toString();
_settingsTree["keys"][prefix + "down"] = config._down->toString();
_settingsTree["keys"][prefix + "left"] = config._left->toString();
_settingsTree["keys"][prefix + "right"] = config._right->toString();
_settingsTree["keys"][prefix + "swap"] = config._swap->toString();
_settingsTree["keys"][prefix + "raiseStack"] = config._raiseStack->toString();
_settingsTree["keys"][prefix + "start"] = config._start->toString();

}

void ConfigHandler::setFullscreen(bool fs) {
_settingsTree.put("video.fullscreen", fs);
_settingsTree["video"]["fullscreen"] = fs;
if (fs != SDLContext::getInstance().isFullscreen()) {
SDLContext::getInstance().toggleFullscreen();
}
}

void ConfigHandler::setMusicVolume(int vol) {
_settingsTree.put("audio.music_volume", vol);
_settingsTree["audio"]["music_volume"] = vol;
Mix_VolumeMusic(vol);
}

void ConfigHandler::setSfxVolume(int vol) {
_settingsTree.put("audio.sfx_volume", vol);
_settingsTree["audio"]["sfx_volume"] = vol;
Mix_Volume(-1, vol);
}

bool ConfigHandler::getFullscreen() {
return _settingsTree.get("video.fullscreen", false);
return _settingsTree["video"].get("fullscreen", false).asBool();
}

int ConfigHandler::getMusicVolume() {
return _settingsTree.get("audio.music_volume", MIX_MAX_VOLUME);
return _settingsTree["audio"].get("music_volume", MIX_MAX_VOLUME).asInt();
}

int ConfigHandler::getSfxVolume() {
return _settingsTree.get("audio.sfx_volume", MIX_MAX_VOLUME);
return _settingsTree["audio"].get("sfx_volume", MIX_MAX_VOLUME).asInt();
}

int ConfigHandler::getEndlessHighScore() {
return _settingsTree.get("endless.high_score", 0);
return _settingsTree["endless"].get("high_score", 0).asInt();
}

void ConfigHandler::setEndlessHighScore(int score) {
_settingsTree.put("endless.high_score", score);
_settingsTree["endless"]["high_score"] = score;
}
13 changes: 10 additions & 3 deletions Config/ConfigHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#ifndef CONFIG_CONFIGHANDLER_H_
#define CONFIG_CONFIGHANDLER_H_

#include <boost/property_tree/ptree.hpp>
#include <json/json.h>
#include <SDL2/SDL_scancode.h>
#include <SDL2/SDL.h>
#include "InputConfig.h"
#include "../InputEvents/KeyboardKey.h"

Expand All @@ -18,7 +19,12 @@ class ConfigHandler {

static ConfigHandler &getInstance();

const char *CONFIG_FILENAME = "panelpop.ini";
const std::string CONFIG_FILENAME = "panelpop.json";
#ifdef __vita__
const std::string CONFIG_DIR = SDL_GetPrefPath(NULL,"panel-pop");;
#else
const std::string CONFIG_DIR = "./";
#endif
bool loadConfig();
bool saveConfig();

Expand All @@ -40,7 +46,8 @@ class ConfigHandler {
ConfigHandler(ConfigHandler const &) = delete;
void operator=(ConfigHandler const &) = delete;

boost::property_tree::ptree _settingsTree;
Json::Value _settingsTree;

InputEvent *parseInputEvent(const std::string &configKey);
};

Expand Down
14 changes: 9 additions & 5 deletions Menus/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ MainMenu::MainMenu() {
[&]() {
StateManager::getInstance().switchToState(new AIGameState);
}));
addItem(
MenuItem("2P VS",
[&]() {
StateManager::getInstance().switchToState(new VsGameState);
}));

#ifndef __vita__
addItem(
MenuItem("2P VS",
[&]() {
StateManager::getInstance().switchToState(new VsGameState);
}));
#endif

addItem(
MenuItem("Options",
[&]() {
Expand Down
32 changes: 23 additions & 9 deletions Menus/OptionsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <SDL2/SDL_timer.h>
#include <string>
#include <vector>
#include <sstream>


#include "../Config/ConfigHandler.h"
#include "../SDLContext.h"
Expand All @@ -23,22 +25,34 @@ OptionsMenu::OptionsMenu(OptionsMenuState &state) :

ConfigHandler &cf = ConfigHandler::getInstance();

addItem(
MenuItem("Fullscreen", [&]() {}, cf.getFullscreen(), 1,
MenuItem::OptionType::TOGGLE));
#ifndef __vita__
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the PSP specific options menu could be its own class.

addItem(
MenuItem("Fullscreen", [&]() {}, cf.getFullscreen(), 1,
MenuItem::OptionType::TOGGLE));
#endif

addItem(
MenuItem("Music volume", [&]() {}, cf.getMusicVolume(),
MIX_MAX_VOLUME, MenuItem::OptionType::SLIDER));
addItem(
MenuItem("SFX volume", [&]() {}, cf.getSfxVolume(), MIX_MAX_VOLUME,
MenuItem::OptionType::SLIDER));
addItem(MenuItem("Configure controls", [&]() {
_state.configurePlayerKeys(_items.at(_selection).getValue() + 1);
}, 0, 1, MenuItem::OptionType::PLAYER));

#ifndef __vita__
addItem(MenuItem("Configure controls", [&]() {
_state.configurePlayerKeys(_items.at(_selection).getValue() + 1);
}, 0, 1, MenuItem::OptionType::PLAYER));
#endif

addItem(MenuItem("Apply", [&]() {
cf.setFullscreen(_items.at(0).getValue());
cf.setMusicVolume(_items.at(1).getValue());
cf.setSfxVolume(_items.at(2).getValue());
#ifdef __vita__
cf.setMusicVolume(_items.at(0).getValue());
cf.setSfxVolume(_items.at(1).getValue());
#else
cf.setFullscreen(_items.at(0).getValue());
cf.setMusicVolume(_items.at(1).getValue());
cf.setSfxVolume(_items.at(2).getValue());
#endif
cf.saveConfig();
_state.goBack();
}));
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The default keyboard controls will always work in the menus.
* SDL2_image
* SDL2_ttf
* SDL2_mixer
* boost
* jsoncpp

#### Linux
1. `cmake`
Expand All @@ -58,3 +58,10 @@ folders into the MinGW installation's respective folders.

1. `cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND"`
2. `make`

#### Playstation Vita

Install the [DolceSDK](https://github.com/DolceSDK/doc) and [this SDL2 fork](https://github.com/isage/SDL-mirror). Then Playstation Vita version can be build.

1. ``cmake -DCMAKE_TOOLCHAIN_FILE="${DOLCESDK}/share/dolce.toolchain.cmake" ..``
2. ``make``
22 changes: 0 additions & 22 deletions panelpop.ini

This file was deleted.

Loading