mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-09 07:18:34 -04:00
Vita: Support touch input kinda
This commit is contained in:
parent
55c1cde463
commit
494101f4cc
@ -9,7 +9,7 @@ CFILES :=$(wildcard src/*.c)
|
||||
OBJS := $(addprefix $(BUILD_DIR)/, $(CFILES:src/%.c=%.o))
|
||||
|
||||
# Needed by psvDebugScreenPrintf
|
||||
LIBS += -lm -lSceDisplay_stub -lSceCtrl_stub -lSceGxm_stub
|
||||
LIBS += -lm -lSceDisplay_stub -lSceCtrl_stub -lSceTouch_stub -lSceGxm_stub
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
|
@ -21,6 +21,7 @@ const cc_result ReturnCode_SocketWouldBlock = SCE_NET_ERROR_EWOULDBLOCK;
|
||||
const cc_result ReturnCode_DirectoryExists = EEXIST;
|
||||
const char* Platform_AppNameSuffix = " PS Vita";
|
||||
static int epoll_id;
|
||||
static int stdout_fd;
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
@ -32,15 +33,8 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
|
||||
}
|
||||
|
||||
void Platform_Log(const char* msg, int len) {
|
||||
int fd = sceKernelGetStdout();
|
||||
sceIoWrite(fd, msg, len);
|
||||
sceIoWrite(fd, "\n", 1);
|
||||
|
||||
//sceIoDevctl("emulator:", 2, msg, len, NULL, 0);
|
||||
//cc_string str = String_Init(msg, len, len);
|
||||
//cc_file file = 0;
|
||||
//File_Open(&file, &str);
|
||||
//File_Close(file);
|
||||
if (!stdout_fd) stdout_fd = sceKernelGetStdout();
|
||||
sceIoWrite(stdout_fd, msg, len);
|
||||
}
|
||||
|
||||
#define UnixTime_TotalMS(time) ((cc_uint64)time.sec * 1000 + UNIX_EPOCH + (time.usec / 1000))
|
||||
|
@ -138,7 +138,7 @@ void android_main(void) {
|
||||
SetupProgram(0, NULL);
|
||||
for (;;) { RunProgram(0, NULL); }
|
||||
}
|
||||
#elif defined CC_BUILD_3DS || defined CC_BUILD_PSP || defined CC_BUILD_GCWII || defined CC_BUILD_DREAMCAST
|
||||
#elif defined CC_BUILD_3DS || defined CC_BUILD_PSP || defined CC_BUILD_GCWII || defined CC_BUILD_DREAMCAST || defined CC_BUILD_XBOX || defined CC_BUILD_PSVITA
|
||||
int main(int argc, char** argv) {
|
||||
SetupProgram(argc, argv);
|
||||
while (WindowInfo.Exists) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "Logger.h"
|
||||
#include <vitasdk.h>
|
||||
static cc_bool launcherMode;
|
||||
static SceTouchPanelInfo frontPanel;
|
||||
|
||||
struct _DisplayData DisplayInfo;
|
||||
struct _WinData WindowInfo;
|
||||
@ -38,6 +39,10 @@ void Window_Init(void) {
|
||||
|
||||
Input.GamepadSource = true;
|
||||
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
|
||||
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
|
||||
sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_START);
|
||||
|
||||
sceTouchGetPanelInfo(SCE_TOUCH_PORT_FRONT, &frontPanel);
|
||||
}
|
||||
|
||||
void Window_Create2D(int width, int height) { launcherMode = true; }
|
||||
@ -104,12 +109,45 @@ static void ProcessCircleInput(SceCtrlData* pad, double delta) {
|
||||
Event_RaiseRawMove(&PointerEvents.RawMoved, dx * scale, dy * scale);
|
||||
}
|
||||
|
||||
void Window_ProcessEvents(double delta) {
|
||||
SceCtrlData pad;
|
||||
/* TODO implement */
|
||||
sceCtrlReadBufferPositive(0, &pad, 1);
|
||||
int mods = pad.buttons;
|
||||
|
||||
static void ProcessTouchPress(int x, int y) {
|
||||
if (!frontPanel.maxDispX || !frontPanel.maxDispY) {
|
||||
// TODO: Shouldn't ever happen? need to check
|
||||
Pointer_SetPosition(0, x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
// rescale from touch range to screen range
|
||||
x = (x - frontPanel.minDispX) * SCREEN_WIDTH / frontPanel.maxDispX;
|
||||
y = (y - frontPanel.minDispY) * SCREEN_HEIGHT / frontPanel.maxDispY;
|
||||
Pointer_SetPosition(0, x, y);
|
||||
}
|
||||
|
||||
static void ProcessTouchInput(void) {
|
||||
SceTouchData touch;
|
||||
|
||||
// sceTouchRead is blocking (seems to block until vblank), and don't want that
|
||||
int res = sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch, 1);
|
||||
if (res == 0) return; // no data available yet
|
||||
if (res < 0) return; // error occurred
|
||||
|
||||
if (touch.reportNum > 0) {
|
||||
int x = touch.report[0].x;
|
||||
int y = touch.report[0].y;
|
||||
ProcessTouchPress(X, Y);
|
||||
}
|
||||
Input_SetNonRepeatable(CCMOUSE_L, touch.reportNum > 0);
|
||||
}
|
||||
|
||||
static void ProcessPadInput(double delta) {
|
||||
SceCtrlData pad;
|
||||
|
||||
// sceCtrlReadBufferPositive is blocking (seems to block until vblank), and don't want that
|
||||
int res = sceCtrlPeekBufferPositive(0, &pad, 1);
|
||||
if (res == 0) return; // no data available yet
|
||||
if (res < 0) return; // error occurred
|
||||
|
||||
int mods = pad.buttons;
|
||||
if (launcherMode) {
|
||||
HandleButtons_Launcher(mods);
|
||||
} else {
|
||||
@ -121,6 +159,12 @@ void Window_ProcessEvents(double delta) {
|
||||
}
|
||||
}
|
||||
|
||||
void Window_ProcessEvents(double delta) {
|
||||
/* TODO implement */
|
||||
ProcessPadInput(delta);
|
||||
ProcessTouchInput();
|
||||
}
|
||||
|
||||
void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita
|
||||
|
||||
void Window_EnableRawMouse(void) { Input.RawMode = true; }
|
||||
|
@ -319,10 +319,7 @@ void Gfx_EndFrame(void) {
|
||||
}
|
||||
|
||||
void Gfx_OnWindowResize(void) {
|
||||
/* TODO: Eliminate this nasty hack.. */
|
||||
Game_UpdateDimensions();
|
||||
glViewport(0, 0, Game.Width, Game.Height);
|
||||
|
||||
/* With cocoa backend, in some cases [NSOpenGLContext update] will actually */
|
||||
/* call glViewport with the size of the window framebuffer */
|
||||
/* https://github.com/glfw/glfw/issues/80 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user