Change window handle to a union

This commit is contained in:
UnknownShadow200 2024-06-26 08:16:16 +10:00
parent f07c13c02a
commit a422564bc7
33 changed files with 76 additions and 70 deletions

View File

@ -22,6 +22,7 @@ jobs:
id: compile
run: |
apk add curl curl-dev
export PSPSDK=$(psp-config --pspsdk-path)
make psp
@ -49,4 +50,4 @@ jobs:
if: ${{ always() && steps.compile.outcome == 'success' }}
with:
DESTINATION_URL: '${{ secrets.NOTIFY_URL }}'
WORKFLOW_NAME: 'psp'
WORKFLOW_NAME: 'psp'

View File

@ -20,6 +20,8 @@ ifeq ($(strip $(PSPSDK)),)
$(warning "Please set PSPSDK variables in your environment. For example:")
$(warning export PSPSDK=/usr/local/pspsk/psp/sdk)
$(warning export PATH=/usr/local/pspsk/bin:$$PATH)
$(warning Or)
$(warning export PSPSDK=$$(shell psp-config --pspsdk-path))
$(error Failed to find PSPSDK installation)
endif

View File

@ -392,9 +392,9 @@ static cc_result Music_PlayOgg(struct Stream* source) {
#ifdef CC_BUILD_ANDROID
/* Don't play music while in the background on Android */
/* TODO: Not use such a terrible approach */
if (!Window_Main.Handle) {
if (!Window_Main.Handle.ptr) {
Audio_Pause(&music_ctx);
while (!Window_Main.Handle && !music_stopping) {
while (!Window_Main.Handle.ptr && !music_stopping) {
Thread_Sleep(10); continue;
}
Audio_Play(&music_ctx);

View File

@ -471,6 +471,7 @@ typedef cc_uint8 EntityID;
typedef cc_uint8 Face;
typedef cc_uint32 cc_result;
typedef cc_uint64 TimeMS;
typedef union cc_pointer_ { cc_uintptr val; void* ptr; } cc_pointer;
typedef struct Rect2D_ { int x, y, width, height; } Rect2D;
typedef struct TextureRec_ { float u1, v1, u2, v2; } TextureRec;

View File

@ -399,7 +399,8 @@ static cc_bool CanDeleteTexture(struct Entity* except) {
int i;
if (!except->TextureId) return false;
for (i = 0; i < ENTITIES_MAX_COUNT; i++) {
for (i = 0; i < ENTITIES_MAX_COUNT; i++)
{
if (!Entities.List[i] || Entities.List[i] == except) continue;
if (Entities.List[i]->TextureId == except->TextureId) return false;
}

View File

@ -74,7 +74,7 @@ static void CreateDeviceAndSwapChain(void) {
desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
// RefreshRate intentionally left at 0 so display's refresh rate is used
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = Window_Main.Handle;
desc.OutputWindow = Window_Main.Handle.ptr;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Windowed = TRUE;

View File

@ -136,7 +136,7 @@ static cc_bool deviceCreated;
static void TryCreateDevice(void) {
cc_result res;
D3DCAPS9 caps;
HWND winHandle = (HWND)Window_Main.Handle;
HWND winHandle = (HWND)Window_Main.Handle.ptr;
D3DPRESENT_PARAMETERS args = { 0 };
D3D9_FillPresentArgs(&args);

View File

@ -146,7 +146,6 @@ void Screen_PointerUp(void* s, int id, int x, int y);
typedef void (*Widget_LeftClick)(void* screen, void* widget);
union WidgetMeta { int val; void* ptr; };
struct WidgetVTABLE {
/* Draws this widget on-screen. */
@ -184,7 +183,7 @@ struct WidgetVTABLE {
cc_uint8 horAnchor, verAnchor; /* The reference point for when this widget is resized */ \
int xOffset, yOffset; /* Offset from the reference point */ \
Widget_LeftClick MenuClick; \
union WidgetMeta meta;
cc_pointer meta;
/* Whether a widget is prevented from being interacted with */
#define WIDGET_FLAG_DISABLED 0x01

View File

@ -71,9 +71,9 @@ static CC_INLINE int Display_ScaleX(int x) { return (int)(x * DisplayInfo.ScaleX
static CC_INLINE int Display_ScaleY(int y) { return (int)(y * DisplayInfo.ScaleY); }
/* Data for a window */
struct _WindowData {
struct cc_window {
/* Readonly platform-specific handle to the window. */
void* Handle;
cc_pointer Handle;
/* Size of the content area of the window. (i.e. area that can draw to) */
/* This area does NOT include borders and titlebar surrounding the window. */
int Width, Height;
@ -100,10 +100,10 @@ struct _WindowData {
#define DEFAULT_UI_SCALE_Y (1.0f / 480)
/* Data for the game/launcher window */
CC_VAR extern struct _WindowData WindowInfo; /* Named WindowInfo for backwards compatibility */
CC_VAR extern struct cc_window WindowInfo; /* Named WindowInfo for backwards compatibility */
#define Window_Main WindowInfo
/* Data for alternate game window (e.g. 3DS) */
extern struct _WindowData Window_Alt;
extern struct cc_window Window_Alt;
/* Initialises necessary state before initing platform and loading options */
void Window_PreInit(void);

View File

@ -19,8 +19,8 @@ static u16 top_width, top_height;
static u16 btm_width, btm_height;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct _WindowData Window_Alt;
struct cc_window WindowInfo;
struct cc_window Window_Alt;
cc_bool launcherTop;
void Window_PreInit(void) {

View File

@ -158,7 +158,8 @@ static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject s
Platform_LogConst("WIN - CREATED");
win_handle = ANativeWindow_fromSurface(env, surface);
winCreated = true;
Window_Main.Handle = win_handle;
Window_Main.Handle.ptr = win_handle;
RefreshWindowBounds();
/* TODO: Restore context */
Event_RaiseVoid(&WindowEvents.Created);
@ -168,8 +169,9 @@ static void JNICALL java_processSurfaceDestroyed(JNIEnv* env, jobject o) {
Platform_LogConst("WIN - DESTROYED");
if (win_handle) ANativeWindow_release(win_handle);
win_handle = NULL;
Window_Main.Handle = NULL;
win_handle = NULL;
Window_Main.Handle.ptr = NULL;
/* eglSwapBuffers might return EGL_BAD_SURFACE, EGL_BAD_ALLOC, or some other error */
/* Instead the context is lost here in a consistent manner */
if (Gfx.Created) Gfx_LoseContext("surface lost");

View File

@ -349,10 +349,10 @@ static void DoCreateWindow(int width, int height) {
BRect frame(x, y, x + width - 1, y + height - 1);
win_handle = new CC_BWindow(frame);
Window_Main.Exists = true;
Window_Main.Handle = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.Exists = true;
Window_Main.Handle.ptr = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
frame = win_handle->Bounds();
Window_Main.Width = frame.IntegerWidth() + 1;

View File

@ -16,7 +16,7 @@ static cc_bool launcherMode;
cc_bool window_inited;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
void Window_PreInit(void) {
vid_set_mode(DEFAULT_VID_MODE, DEFAULT_PIXEL_MODE);

View File

@ -23,7 +23,7 @@ static void* xfb;
static GXRModeObj* rmode;
void* Window_XFB;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
static void OnPowerOff(void) {

View File

@ -15,7 +15,7 @@
static cc_bool launcherMode;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
void Window_PreInit(void) {
display_init(RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, FILTERS_DISABLED);

View File

@ -130,7 +130,7 @@ static int bg_id;
static u16* bg_ptr;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
void Window_PreInit(void) {
videoSetModeSub(MODE_0_2D);

View File

@ -27,7 +27,7 @@ static cc_bool launcherMode;
static char pad_buff[2][34];
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
void Window_PreInit(void) { }
void Window_Init(void) {

View File

@ -29,7 +29,8 @@ static char padBuf0[256] __attribute__((aligned(64)));
static char padBuf1[256] __attribute__((aligned(64)));
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
framebuffer_t fb_colors[2];
zbuffer_t fb_depth;
static int display_mode;

View File

@ -25,7 +25,7 @@ static KbData kb_data;
static KbConfig kb_config;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
static void sysutil_callback(u64 status, u64 param, void* usrdata) {
switch (status) {

View File

@ -22,7 +22,7 @@
static cc_bool launcherMode;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
void Window_PreInit(void) {
sceCtrlSetSamplingCycle(0);

View File

@ -17,7 +17,7 @@ static cc_bool launcherMode;
static SceTouchPanelInfo frontPanel;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
#define DISPLAY_WIDTH 960
#define DISPLAY_HEIGHT 544

View File

@ -89,10 +89,10 @@ static void DoCreateWindow(int width, int height, int flags) {
if (!win_handle) Window_SDLFail("creating window");
RefreshWindowBounds();
Window_Main.Exists = true;
Window_Main.Handle = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.Exists = true;
Window_Main.Handle.ptr = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.SoftKeyboardInstant = true;
ApplyIcon();

View File

@ -73,10 +73,10 @@ static void DoCreateWindow(int width, int height, int flags) {
SDL_DestroyProperties(props);
RefreshWindowBounds();
Window_Main.Exists = true;
Window_Main.Handle = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.Exists = true;
Window_Main.Handle.ptr = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.SoftKeyboardInstant = true;
ApplyIcon();

View File

@ -22,7 +22,7 @@
static cc_bool launcherMode;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
static void OnVblank(void* work) {
smpc_peripheral_intback_issue();

View File

@ -21,7 +21,7 @@ static PadState pad;
static AppletHookCookie cookie;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
static void SetResolution(void) {
// check whether the Switch is docked
@ -66,18 +66,18 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1;
Window_Main.Focused = true;
Window_Main.Exists = true;
Window_Main.Handle = nwindowGetDefault();
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.Focused = true;
Window_Main.Exists = true;
Window_Main.Handle.ptr = nwindowGetDefault();
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE;
Input_SetTouchMode(true);
Gui_SetTouchUI(true);
Input.Sources = INPUT_SOURCE_GAMEPAD;
nwindowSetDimensions(Window_Main.Handle, 1920, 1080);
nwindowSetDimensions(Window_Main.Handle.ptr, 1920, 1080);
SetResolution();
}
@ -228,7 +228,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
*-----------------------------------------------------OpenGL context------------------------------------------------------*
*#########################################################################################################################*/
static void GLContext_InitSurface(void) {
NWindow* window = (NWindow*)Window_Main.Handle;
NWindow* window = (NWindow*)Window_Main.Handle.ptr;
if (!window) return; /* window not created or lost */
// terrible, but fixes 720p/1080p resolution change on handheld/docked modes

View File

@ -425,7 +425,6 @@ void Window_Free(void) {
static void DoCreateWindow(int width, int height) {
Window_Main.Exists = true;
Window_Main.Handle = (void*)1;
Window_Main.Focused = true;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
@ -523,10 +522,10 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
}
void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) {
bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels");
bmp->width = width;
bmp->height = height;
void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) {
bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels");
bmp->width = width;
bmp->height = height;
}
void Window_FreeFramebuffer(struct Bitmap* bmp) {

View File

@ -33,8 +33,8 @@ extern "C" {
static cc_bool launcherMode;
static cc_bool keyboardOpen;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct _WindowData Window_Alt;
struct cc_window WindowInfo;
struct cc_window Window_Alt;
cc_bool launcherTop;

View File

@ -394,10 +394,10 @@ static void DoCreateWindow(int width, int height) {
win_DC = GetDC(win_handle);
if (!win_DC) Logger_Abort2(GetLastError(), "Failed to get device context");
Window_Main.Exists = true;
Window_Main.Handle = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.Exists = true;
Window_Main.Handle.ptr = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false);
}

View File

@ -379,10 +379,10 @@ static void DoCreateWindow(int width, int height) {
XkbSetDetectableAutoRepeat(win_display, true, &supported);
RefreshWindowBounds(width, height);
Window_Main.Exists = true;
Window_Main.Handle = (void*)win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.Exists = true;
Window_Main.Handle.val = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false);
/* So right name appears in e.g. Ubuntu Unity launchbar */

View File

@ -20,7 +20,7 @@ static xid_dev_t* xid_ctrl;
static xid_gamepad_in gp_state;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
// TODO No idea if this even works
static void OnDataReceived(UTR_T* utr) {

View File

@ -19,7 +19,7 @@
static cc_bool launcherMode;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
static uint32_t reg_read32(int reg)
{

View File

@ -378,10 +378,10 @@ static void DoCreateWindow(int width, int height) {
AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
NewAEEventHandlerUPP(HandleQuitMessage), 0, false);
Window_Main.Exists = true;
Window_Main.Handle = winHandle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.Exists = true;
Window_Main.Handle.ptr = winHandle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
// CGAssociateMouseAndMouseCursorPosition implicitly grabs cursor
del = [CCWindowDelegate alloc];

View File

@ -5,7 +5,7 @@
#include "Platform.h"
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
struct cc_window WindowInfo;
#define Display_CentreX(width) (DisplayInfo.x + (DisplayInfo.Width - width) / 2)
#define Display_CentreY(height) (DisplayInfo.y + (DisplayInfo.Height - height) / 2)
@ -115,7 +115,7 @@ static EGLint ctx_numConfig;
static void GLContext_InitSurface(void); // replacement in Window_Switch.c for handheld/docked resolution fix
#else
static void GLContext_InitSurface(void) {
void* window = Window_Main.Handle;
void* window = Window_Main.Handle.ptr;
if (!window) return; /* window not created or lost */
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, window, NULL);