Added PS Vita support

This commit is contained in:
2023-03-14 00:20:43 -07:00
parent 3587efb9ad
commit f5c5d1f49d
39 changed files with 937 additions and 340 deletions

View File

@ -3,14 +3,6 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Libraries
target_link_libraries(${DAWN_TARGET_NAME}
SceLibKernel_stub
SceDisplay_stub
stdc++
pthread
)
# Includes
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
@ -18,9 +10,18 @@ target_include_directories(${DAWN_TARGET_NAME}
)
# Platform variables
target_compile_definitions(${DAWN_TARGET_NAME}
PUBLIC
DAWN_ASSET_BUILD_PREFIX="../../assets/"
DAWN_OPENGL_HLSL=true
)
set(DAWN_OPENGL_EXCLUDE_LIBRARIES true CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Subdirs
add_subdirectory(host)
add_subdirectory(input)
add_subdirectory(time)
# Toolchain
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
@ -28,6 +29,32 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11" CACHE INTERNAL ${DAWN_CACHE_TARG
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1" CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Libraries
target_link_libraries(${DAWN_TARGET_NAME}
PUBLIC
m
stdc++
vitaGL
mathneon
vitashark
kubridge_stub
SceAppMgr_stub
SceAudio_stub
SceCtrl_stub
SceCommonDialog_stub
SceDisplay_stub
SceKernelDmacMgr_stub
SceGxm_stub
SceShaccCg_stub
SceSysmodule_stub
ScePower_stub
SceTouch_stub
SceVshBridge_stub
SceIofilemgr_stub
SceShaccCgExt
libtaihen_stub.a
)
# VPK Packaging
if(NOT DEFINED DAWN_VITA_APP_NAME)
message(FATAL_ERROR "Please define DAWN_VITA_APP_NAME in your target.")

View File

@ -0,0 +1,7 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include <vitaGL.h>

View File

@ -0,0 +1,44 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "debug/debug.hpp"
#include <vitasdk.h>
#include "dawnopengl.hpp"
// Initialize sceMsgDialog widget with a given message text
static int vitaMsgInit(const char *msg) {
SceMsgDialogUserMessageParam msg_param;
memset(&msg_param, 0, sizeof(msg_param));
msg_param.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_OK;
msg_param.msg = (SceChar8 *)msg;
SceMsgDialogParam param;
sceMsgDialogParamInit(&param);
_sceCommonDialogSetMagicNumber(&param.commonParam);
param.mode = SCE_MSG_DIALOG_MODE_USER_MSG;
param.userMsgParam = &msg_param;
return sceMsgDialogInit(&param);
}
// Gets current state for sceMsgDialog running widget
static int vitaMsgGetResult(void) {
if(sceMsgDialogGetStatus() != SCE_COMMON_DIALOG_STATUS_FINISHED) return 0;
sceMsgDialogTerm();
return 1;
}
// Draws an error message on screen and force closes the app after user input
template<typename... A>
static void debugMessage(const char *fmt, A... args) {
char string[512];
sprintf(string, fmt, args...);
vitaMsgInit(string);
while(!vitaMsgGetResult()) {
glClear(GL_COLOR_BUFFER_BIT);
vglSwapBuffers(GL_TRUE);
}
}

View File

@ -4,24 +4,194 @@
// https://opensource.org/licenses/MIT
#include "DawnHostVita.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
void vitaTestCube() {
float colors[] = {1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0}; // Colors for a face
float vertices_front[] = {-0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f}; // Front Face
float vertices_back[] = {-0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Back Face
float vertices_left[] = {-0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f}; // Left Face
float vertices_right[] = {0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Right Face
float vertices_top[] = {-0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f}; // Top Face
float vertices_bottom[] = {-0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Bottom Face
uint16_t indices[] = {
0, 1, 2, 1, 2, 3, // Front
4, 5, 6, 5, 6, 7, // Back
8, 9,10, 9,10,11, // Left
12,13,14,13,14,15, // Right
16,17,18,17,18,19, // Top
20,21,22,21,22,23 // Bottom
};
// Creating colors array for all faces
float color_array[12*6];
int i;
for (i=0;i<12*6;i++){
color_array[i] = colors[i % 12];
}
// Creating vertex array for all faces
float vertex_array[12*6];
memcpy(&vertex_array[12*0], &vertices_front[0], sizeof(float) * 12);
memcpy(&vertex_array[12*1], &vertices_back[0], sizeof(float) * 12);
memcpy(&vertex_array[12*2], &vertices_left[0], sizeof(float) * 12);
memcpy(&vertex_array[12*3], &vertices_right[0], sizeof(float) * 12);
memcpy(&vertex_array[12*4], &vertices_top[0], sizeof(float) * 12);
memcpy(&vertex_array[12*5], &vertices_bottom[0], sizeof(float) * 12);
// Setting clear color
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
// Initializing mvp matrix with a perspective full screen matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube
// Enabling depth test
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
// Main loop
for (;;){
// Clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Drawing our cube with vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertex_array);
glColorPointer(3, GL_FLOAT, 0, color_array);
glRotatef(1.0f, 0.0f, 0.0f, 1.0f); // Rotating cube at each frame by 1 on axis x and axis w
glRotatef(0.5f, 0.0f, 1.0f, 0.0f); // Rotating cube at each frame by 0.5 on axis x and 1.0 on axis z
glDrawElements(GL_TRIANGLES, 6*6, GL_UNSIGNED_SHORT, indices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
// Performing buffer swap
vglSwapBuffers(GL_FALSE);
}
}
DawnHost::DawnHost() {
}
int32_t DawnHost::init(DawnGame *game) {
this->game = game;
vglInit(0x800000);
vglWaitVblankStart(GL_TRUE);
// Override the defaults
game->renderManager.backBuffer.setSize(DAWN_VITA_WIDTH, DAWN_VITA_HEIGHT);
// Initialize the game
auto result = game->init();
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
// Hard-Load the first scene assets.
if(game->scene != nullptr) {
auto assets = game->scene->getRequiredAssets();
game->assetManager.queueLoad(assets);
game->assetManager.syncLoad();
game->scene->stage();
}
return DAWN_HOST_INIT_RESULT_SUCCESS;
}
int32_t DawnHost::start(DawnGame *game) {
double_t time, newTime;
float_t fDelta;
int32_t updateResult;
// Main Render Loop
time = 0.0f;
for(;;) {
// Determine the delta.
float_t fDelta = 1.0f / 60.0f;
time = newTime;
// Perform update
updateResult = this->update(game, fDelta);
// Did the update complete successfully?
if(updateResult == DAWN_HOST_UPDATE_RESULT_EXIT) {
break;
} else if(updateResult != DAWN_HOST_UPDATE_RESULT_SUCCESS) {
return updateResult;
}
// Performing buffer swap
vglSwapBuffers(GL_FALSE);
}
return DAWN_HOST_START_RESULT_EXIT_SUCCESS;
}
int32_t DawnHost::update(DawnGame *game, float_t delta) {
// Tick game.
auto ret = game->update(delta);
switch(ret) {
case DAWN_GAME_UPDATE_RESULT_SUCCESS:
return DAWN_HOST_UPDATE_RESULT_SUCCESS;
case DAWN_GAME_UPDATE_RESULT_EXIT:
return DAWN_HOST_UPDATE_RESULT_EXIT;
default:
return ret;
}
}
void DawnHost::unload(DawnGame *game) {
vglEnd();
}
DawnHost::~DawnHost() {
}
int main(int argc, char **args) {
// Success
std::stringstream output;
std::vector<std::string> hello = { "Hello" };
hello.push_back(",");
hello.push_back(" C++ ");
hello.push_back("world!");
for (auto &s : hello) {
// std::cout does't work ATM :(
output << s;
}
output << std::endl;
printf("%s\n", output.str().c_str());
int32_t result;
while(1) {
// Create the host
auto host = new DawnHost();
auto game = new DawnGame(host);
// Initialize the host and error check
result = host->init(game);
switch(result) {
case DAWN_HOST_INIT_RESULT_SUCCESS:
break;
default:
return result;
}
sceKernelExitProcess(0);
// Request the main loop to start running.
result = host->start(game);
switch(result) {
case DAWN_HOST_START_RESULT_SUCCESS:
break;
case DAWN_HOST_START_RESULT_EXIT_SUCCESS:
break;
default:
return result;
}
// Main loop finished without errors, cleanup
host->unload(game);
delete game;
delete host;
// Success
return 0;
}

View File

@ -4,10 +4,19 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <sstream>
#include <vector>
#include <cstdio>
#include <psp2/kernel/processmgr.h>
#include "dawnopengl.hpp"
#include "dawnlibs.hpp"
#include "host/DawnHost.hpp"
#include "debug/debug.hpp"
#define DAWN_VITA_WIDTH 960
#define DAWN_VITA_HEIGHT 540
namespace Dawn {
class DawnHostData {
void *nothing;
};
}
/**
* Main entry function received by parent Win32 Operating System.

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
InputManager.cpp
)

View File

@ -0,0 +1,20 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "InputManager.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
InputManager::InputManager(DawnGame *game) : IInputManager<int32_t>(game) {
}
float_t InputManager::getInputValue(int32_t axis) {
auto exist = this->rawInputValues.find(axis);
if(exist == this->rawInputValues.end()) return 0.0f;
return exist->second;
}

View File

@ -0,0 +1,19 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/_InputManager.hpp"
namespace Dawn {
class InputManager : public IInputManager<int32_t> {
protected:
float_t getInputValue(int32_t axis) override;
public:
std::map<int32_t, float_t> rawInputValues;
InputManager(DawnGame *game);
};
}

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
TimeManager.cpp
)

View File

@ -0,0 +1,16 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TimeManager.hpp"
using namespace Dawn;
TimeManager::TimeManager() : ITimeManager() {
}
int64_t TimeManager::getTimestamp() {
return (int64_t)std::time(nullptr);
}

View File

@ -0,0 +1,15 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "time/ITimeManager.hpp"
namespace Dawn {
class TimeManager : public ITimeManager {
public:
TimeManager();
int64_t getTimestamp() override;
};
}