From b39a537adfcee747ab165b6890ba654ea6ee8369 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 10 Jul 2024 18:25:48 +1000 Subject: [PATCH] Fix touch input issues and compiling issues --- Makefile | 27 ++++++++++++++++++++------- src/Entity.c | 8 ++++++-- src/TouchUI.c | 28 +++++++++++++++------------- src/Window_Dreamcast.c | 2 +- src/Window_GCWii.c | 1 + src/Window_Web.c | 4 ++-- 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 0597f8870..33ed3adfd 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -SOURCE_DIR := src -BUILD_DIR := build -C_SOURCES := $(wildcard $(SOURCE_DIR)/*.c) -C_OBJECTS := $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES)) +SOURCE_DIR = src +BUILD_DIR = build +C_SOURCES = $(wildcard $(SOURCE_DIR)/*.c) +C_OBJECTS = $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES)) -OBJECTS := $(C_OBJECTS) +OBJECTS = $(C_OBJECTS) ENAME = ClassiCube CFLAGS = -g -pipe -fno-math-errno -Werror -Wno-error=missing-braces -Wno-error=strict-aliasing -Wno-error=maybe-uninitialized LDFLAGS = -g -rdynamic @@ -34,7 +34,8 @@ ifeq ($(PLAT),web) CC = emcc OEXT = .html CFLAGS = -g - LDFLAGS = -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=1Mb --js-library $(SOURCE_DIR)/interop_web.js + LDFLAGS = -g -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=1Mb --js-library $(SOURCE_DIR)/interop_web.js + BUILD_DIR = build-web endif ifeq ($(PLAT),mingw) @@ -43,16 +44,19 @@ ifeq ($(PLAT),mingw) CFLAGS += -DUNICODE LDFLAGS = -g LIBS = -mwindows -lwinmm -limagehlp + BUILD_DIR = build-win endif ifeq ($(PLAT),linux) CFLAGS += -DCC_BUILD_ICON LIBS = -lX11 -lXi -lpthread -lGL -ldl + BUILD_DIR = build-linux endif ifeq ($(PLAT),sunos) CFLAGS += -DCC_BUILD_ICON LIBS = -lsocket -lX11 -lXi -lGL + BUILD_DIR = build-solaris endif ifeq ($(PLAT),darwin) @@ -60,30 +64,35 @@ ifeq ($(PLAT),darwin) CFLAGS += -DCC_BUILD_ICON LIBS = LDFLAGS = -rdynamic -framework Cocoa -framework OpenGL -framework IOKit -lobjc + BUILD_DIR = build-macos endif ifeq ($(PLAT),freebsd) CFLAGS += -I /usr/local/include -DCC_BUILD_ICON LDFLAGS = -L /usr/local/lib -rdynamic LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread + BUILD_DIR = build-freebsd endif ifeq ($(PLAT),openbsd) CFLAGS += -I /usr/X11R6/include -I /usr/local/include -DCC_BUILD_ICON LDFLAGS = -L /usr/X11R6/lib -L /usr/local/lib -rdynamic LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread + BUILD_DIR = build-openbsd endif ifeq ($(PLAT),netbsd) CFLAGS += -I /usr/X11R7/include -I /usr/pkg/include -DCC_BUILD_ICON LDFLAGS = -L /usr/X11R7/lib -L /usr/pkg/lib -rdynamic LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread + BUILD_DIR = build-netbsd endif ifeq ($(PLAT),dragonfly) CFLAGS += -I /usr/local/include -DCC_BUILD_ICON LDFLAGS = -L /usr/local/lib -rdynamic LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread + BUILD_DIR = build-flybsd endif ifeq ($(PLAT),haiku) @@ -91,6 +100,7 @@ ifeq ($(PLAT),haiku) CFLAGS = -g -pipe -fno-math-errno LDFLAGS = -g LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker + BUILD_DIR = build-haiku endif ifeq ($(PLAT),beos) @@ -98,18 +108,22 @@ ifeq ($(PLAT),beos) CFLAGS = -g -pipe LDFLAGS = -g LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker + BUILD_DIR = build-beos TRACK_DEPENDENCIES=0 endif ifeq ($(PLAT),serenityos) LIBS = -lgl -lSDL2 + BUILD_DIR = build-serenity endif ifeq ($(PLAT),irix) CC = gcc LIBS = -lGL -lX11 -lXi -lpthread -ldl + BUILD_DIR = build-irix endif + ifdef SDL2 CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_SDL2 LIBS += -lSDL2 @@ -119,7 +133,6 @@ ifdef SDL3 LIBS += -lSDL3 endif - ifdef TERMINAL CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_TERMINAL -DCC_GFX_BACKEND=CC_GFX_BACKEND_SOFTGPU LIBS := $(subst mwindows,mconsole,$(LIBS)) diff --git a/src/Entity.c b/src/Entity.c index 2e928b81b..6ac057930 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -944,13 +944,17 @@ static cc_bool LocalPlayer_HandleJump(int key, struct InputDevice* device) { static cc_bool LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks; - hacks->HalfSpeeding = hacks->Enabled; + cc_bool touch = device->type == INPUT_DEVICE_TOUCH; + + hacks->HalfSpeeding = (!touch || !hacks->HalfSpeeding) && hacks->Enabled; return true; } static cc_bool LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks; - hacks->Speeding = hacks->Enabled; + cc_bool touch = device->type == INPUT_DEVICE_TOUCH; + + hacks->Speeding = (!touch || !hacks->Speeding) && hacks->Enabled; return true; } diff --git a/src/TouchUI.c b/src/TouchUI.c index 99c3f6252..df3066c6f 100644 --- a/src/TouchUI.c +++ b/src/TouchUI.c @@ -505,7 +505,6 @@ struct TouchButtonDesc { static struct TouchScreen { Screen_Body - const struct TouchButtonDesc* descs; int numOnscreen, numBtns; struct FontDesc font; struct ThumbstickWidget thumbstick; @@ -536,8 +535,8 @@ static void TouchScreen_BindClick(void* screen, void* widget) { struct TouchScreen* s = (struct TouchScreen*)screen; struct ButtonWidget* btn = (struct ButtonWidget*)widget; - int i = btn->meta.val; - Bind_OnTriggered[s->descs[i].bind](0, &TouchDevice); + struct TouchButtonDesc* desc = (struct TouchButtonDesc*)btn->meta.ptr; + Bind_OnTriggered[desc->bind](0, &TouchDevice); } static const struct TouchButtonDesc onscreenDescs[ONSCREEN_MAX_BTNS] = { @@ -566,6 +565,7 @@ static const struct TouchButtonDesc hackDescs[2] = { #define TOUCHSCREEN_BTN_COLOR PackedCol_Make(255, 255, 255, 200) static void TouchScreen_InitButtons(struct TouchScreen* s) { struct HacksComp* hacks = &Entities.CurPlayer->Hacks; + const struct TouchButtonDesc* descs; const struct TouchButtonDesc* desc; int buttons = GetOnscreenButtons(); int i, j; @@ -579,7 +579,7 @@ static void TouchScreen_InitButtons(struct TouchScreen* s) { ButtonWidget_Init(&s->onscreen[j], 100, desc->OnClick); if (desc->enabled) Widget_SetDisabled(&s->onscreen[j], !(*desc->enabled)); - s->onscreen[j].meta.val = i; + s->onscreen[j].meta.ptr = desc; s->onscreen[j].color = TOUCHSCREEN_BTN_COLOR; s->widgets[j] = (struct Widget*)&s->onscreen[j]; j++; @@ -587,19 +587,19 @@ static void TouchScreen_InitButtons(struct TouchScreen* s) { s->numOnscreen = j; if (hacks->Flying || hacks->Noclip) { - s->descs = hackDescs; + descs = hackDescs; s->numBtns = Array_Elems(hackDescs); } else { - s->descs = normDescs; + descs = normDescs; s->numBtns = Array_Elems(normDescs); } for (i = 0; i < s->numBtns; i++) { s->widgets[i + ONSCREEN_MAX_BTNS] = (struct Widget*)&s->btns[i]; - ButtonWidget_Init(&s->btns[i], 60, s->descs[i].OnClick); + ButtonWidget_Init(&s->btns[i], 60, descs[i].OnClick); s->btns[i].color = TOUCHSCREEN_BTN_COLOR; - s->btns[i].meta.val = i; + s->btns[i].meta.ptr = &descs[i]; } } @@ -628,12 +628,12 @@ static void TouchScreen_ContextRecreated(void* screen) { for (i = 0; i < s->numOnscreen; i++) { - desc = &onscreenDescs[s->onscreen[i].meta.val]; + desc = (struct TouchButtonDesc*)s->onscreen[i].meta.ptr; ButtonWidget_SetConst(&s->onscreen[i], desc->text, &s->font); } for (i = 0; i < s->numBtns; i++) { - desc = &s->descs[i]; + desc = (struct TouchButtonDesc*)s->btns[i].meta.ptr; ButtonWidget_SetConst(&s->btns[i], desc->text, &s->font); } ButtonWidget_SetConst(&s->more, "...", &s->font); @@ -668,6 +668,7 @@ static int TouchScreen_PointerDown(void* screen, int id, int x, int y) { static void TouchScreen_PointerUp(void* screen, int id, int x, int y) { struct TouchScreen* s = (struct TouchScreen*)screen; + struct TouchButtonDesc* desc; int i; //Chat_Add1("POINTER UP: %i", &id); s->thumbstick.active &= ~id; @@ -676,9 +677,10 @@ static void TouchScreen_PointerUp(void* screen, int id, int x, int y) { for (i = 0; i < s->numBtns; i++) { if (!(s->btns[i].active & id)) continue; + desc = (struct TouchButtonDesc*)s->btns[i].meta.ptr; - if (s->descs[i].bind) { - Bind_OnReleased[s->descs[i].bind](0, &TouchDevice); + if (desc->bind) { + Bind_OnReleased[desc->bind](0, &TouchDevice); } s->btns[i].active &= ~id; return; @@ -717,7 +719,7 @@ static void TouchScreen_Layout(void* screen) { for (i = 0; i < s->numBtns; i++) { - desc = &s->descs[i]; + desc = (struct TouchButtonDesc*)s->btns[i].meta.ptr; Widget_SetLocation(&s->btns[i], ANCHOR_MAX, ANCHOR_MAX, desc->x, desc->y); s->btns[i].yOffset += height; diff --git a/src/Window_Dreamcast.c b/src/Window_Dreamcast.c index 8ba98700c..93aa044da 100644 --- a/src/Window_Dreamcast.c +++ b/src/Window_Dreamcast.c @@ -279,7 +279,7 @@ void Gamepads_Process(float delta) { for (int i = 0; i < INPUT_MAX_GAMEPADS; i++) { - cont = maple_enum_type(port, MAPLE_FUNC_CONTROLLER); + cont = maple_enum_type(i, MAPLE_FUNC_CONTROLLER); if (!cont) return; state = (cont_state_t*)maple_dev_status(cont); if (!state) return; diff --git a/src/Window_GCWii.c b/src/Window_GCWii.c index a265a9eee..609e17824 100644 --- a/src/Window_GCWii.c +++ b/src/Window_GCWii.c @@ -3,6 +3,7 @@ #include "Window.h" #include "Platform.h" #include "Input.h" +#include "InputHandler.h" #include "Event.h" #include "String.h" #include "Funcs.h" diff --git a/src/Window_Web.c b/src/Window_Web.c index 7e865a402..8365972bb 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -451,7 +451,7 @@ void Window_SetTitle(const cc_string* title) { static char pasteBuffer[512]; static cc_string pasteStr; EMSCRIPTEN_KEEPALIVE void Window_RequestClipboardText(void) { - Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_COPY, 0); + Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_COPY, 0, &NormDevice); } EMSCRIPTEN_KEEPALIVE void Window_StoreClipboardText(char* src) { @@ -461,7 +461,7 @@ EMSCRIPTEN_KEEPALIVE void Window_StoreClipboardText(char* src) { EMSCRIPTEN_KEEPALIVE void Window_GotClipboardText(char* src) { Window_StoreClipboardText(src); - Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_PASTE, 0); + Event_RaiseInput(&InputEvents.Down, INPUT_CLIPBOARD_PASTE, 0, &NormDevice); } extern void interop_TryGetClipboardText(void);