mirror of
https://github.com/open-goal/jak-project
synced 2026-06-04 02:47:17 -04:00
[runtime] fix gamepad race condition, only allow gamepad for pad 0, fix defstatehandler, allow mapping any pad w/ keyboard (#993)
* fix gamepad race condition, only allow gamepad for pad 0, fix `defstatehandler`, allow mapping any pad w/ keyboard * dont render debug stuff with manylevel hack
This commit is contained in:
@@ -170,6 +170,7 @@ void poll_events() {
|
||||
|
||||
void input_mode_set(u32 enable) {
|
||||
if (enable == s7.offset + FIX_SYM_TRUE) { // #t
|
||||
Pad::g_input_mode_mapping = g_settings.pad_mapping_info;
|
||||
Pad::EnterInputMode();
|
||||
} else {
|
||||
Pad::ExitInputMode(enable != s7.offset); // use #f for graceful exit, or 'canceled for abrupt
|
||||
|
||||
@@ -455,7 +455,7 @@ void Tfrag3::debug_render_all_trees_nolores(const RenderSettings& settings,
|
||||
m_cached_trees[i].kind != tfrag3::TFragmentTreeKind::LOWRES_TRANS &&
|
||||
m_cached_trees[i].kind != tfrag3::TFragmentTreeKind::LOWRES) {
|
||||
settings_copy.tree_idx = i;
|
||||
render_tree_cull_debug(settings_copy, render_state, prof);
|
||||
// render_tree_cull_debug(settings_copy, render_state, prof);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -663,4 +663,4 @@ void Tfrag3::render_tree_cull_debug(const RenderSettings& settings,
|
||||
remaining -= to_do;
|
||||
start += to_do;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,6 +731,7 @@ void InitMachine_PCPort() {
|
||||
make_function_symbol_from_c("pc-pad-get-mapped-button", (void*)Gfx::get_mapped_button);
|
||||
make_function_symbol_from_c("pc-pad-input-map-save!", (void*)Gfx::input_mode_save);
|
||||
make_function_symbol_from_c("pc-pad-input-mode-set", (void*)Gfx::input_mode_set);
|
||||
make_function_symbol_from_c("pc-pad-input-pad-set", (void*)Pad::input_mode_pad_set);
|
||||
make_function_symbol_from_c("pc-pad-input-mode-get", (void*)Pad::input_mode_get);
|
||||
make_function_symbol_from_c("pc-pad-input-key-get", (void*)Pad::input_mode_get_key);
|
||||
make_function_symbol_from_c("pc-pad-input-index-get", (void*)Pad::input_mode_get_index);
|
||||
|
||||
+10
-10
@@ -26,7 +26,7 @@ float g_gamepad_analogs[(int)Analog::Max] = {127};
|
||||
|
||||
// input mode for controller mapping
|
||||
InputModeStatus input_mode = InputModeStatus::Disabled;
|
||||
u64 input_mode_pad = 0;
|
||||
int input_mode_pad = 0;
|
||||
u64 input_mode_key = -1;
|
||||
u64 input_mode_mod = 0;
|
||||
u64 input_mode_index = 0;
|
||||
@@ -105,7 +105,7 @@ int IsPressed(MappingInfo& mapping, Button button, int pad = 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_gamepad_buttons[(int)button]) {
|
||||
if (pad == 0 && g_gamepad_buttons[(int)button]) {
|
||||
return 1;
|
||||
}
|
||||
auto key = mapping.pad_mapping[pad][(int)button];
|
||||
@@ -193,6 +193,10 @@ u64 input_mode_get_index() {
|
||||
return input_mode_index;
|
||||
}
|
||||
|
||||
void input_mode_pad_set(s64 idx) {
|
||||
input_mode_pad = idx;
|
||||
}
|
||||
|
||||
/*
|
||||
********************************
|
||||
* Gamepad Support
|
||||
@@ -212,6 +216,9 @@ void check_gamepad() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (!glfwJoystickPresent(g_gamepads.gamepad_idx)) {
|
||||
lg::info("Gamepad has been disconnected");
|
||||
g_gamepads.gamepad_idx = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,17 +239,10 @@ void clear_gamepads() {
|
||||
}
|
||||
|
||||
void update_gamepads() {
|
||||
clear_gamepads();
|
||||
|
||||
check_gamepad();
|
||||
|
||||
if (g_gamepads.gamepad_idx == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!glfwJoystickPresent(g_gamepads.gamepad_idx)) {
|
||||
g_gamepads.gamepad_idx = -1;
|
||||
lg::info("Gamepad has been disconnected");
|
||||
clear_gamepads();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ void ExitInputMode(bool);
|
||||
u64 input_mode_get();
|
||||
u64 input_mode_get_key();
|
||||
u64 input_mode_get_index();
|
||||
void input_mode_pad_set(s64);
|
||||
|
||||
void initialize();
|
||||
void update_gamepads();
|
||||
|
||||
@@ -310,6 +310,7 @@
|
||||
(define-extern __pc-texture-relocate (function object object object none))
|
||||
(define-extern __pc-get-mips2c (function string function))
|
||||
(define-extern pc-pad-input-mode-set (function symbol none))
|
||||
(define-extern pc-pad-input-pad-set (function int none))
|
||||
(define-extern pc-pad-input-mode-get (function int))
|
||||
(define-extern pc-pad-input-key-get (function int))
|
||||
(define-extern pc-pad-input-index-get (function int))
|
||||
|
||||
+24
-16
@@ -38,7 +38,7 @@ There are several ways to "go"
|
||||
- go from the main thread of the main process. This causes the (-> pp state) to change, the stack frames
|
||||
to be cleaned up, and the old state's exit to be called. It will reset the stack, then run the code.
|
||||
Unlike the others, this means you "go" immediately.
|
||||
|
||||
|
||||
The compiler has two special hooks related to states: go-hook and define-state-hook.
|
||||
These take care of doing a go and a state definition and properly checking types.
|
||||
|
||||
@@ -95,7 +95,7 @@ It type checks the arguments for the entry function.
|
||||
(defmacro make-function-process (proc-type func &key (from *default-dead-pool*) &key (to *default-pool*) &key (name #f) &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args)
|
||||
"Start a new process that runs a function on its main thread.
|
||||
Returns a pointer to the new process (or #f? on error)."
|
||||
|
||||
|
||||
(with-gensyms (new-proc)
|
||||
`(let ((,new-proc (the-as ,proc-type (get-process ,from ,proc-type ,stack-size))))
|
||||
(when ,new-proc
|
||||
@@ -110,7 +110,7 @@ It type checks the arguments for the entry function.
|
||||
(defmacro make-init-process (proc-type func &key (from *default-dead-pool*) &key (to *default-pool*) &key (name #f) &key (stack-size #x4000) &key (stack *kernel-dram-stack*) &rest args)
|
||||
"Start a new process and run an init function on it.
|
||||
Returns a pointer to the new process, or #f (or is it 0?) if something goes wrong."
|
||||
|
||||
|
||||
(with-gensyms (new-proc)
|
||||
`(let ((,new-proc (the-as ,proc-type (get-process ,from ,proc-type ,stack-size))))
|
||||
(when ,new-proc
|
||||
@@ -151,7 +151,7 @@ It type checks the arguments for the entry function.
|
||||
&key (post *no-state*)
|
||||
)
|
||||
"Define a new state!"
|
||||
|
||||
|
||||
(with-gensyms (new-state)
|
||||
(let ((defstate-type (first parents)))
|
||||
(when (not (null? *defstate-type-stack*))
|
||||
@@ -162,24 +162,32 @@ It type checks the arguments for the entry function.
|
||||
;; check for default handlers
|
||||
(let ((default-handlers (assoc defstate-type *default-state-handlers*)))
|
||||
(when (not (null? default-handlers))
|
||||
;;(fmt #t "found default-handlers for {}: {}\n" defstate-type default-handlers)
|
||||
;; event
|
||||
(set! default-handlers (cdr default-handlers))
|
||||
(when (and (not event) (car default-handlers))
|
||||
(when (and (eq? event '*no-state*) (car default-handlers))
|
||||
(set! event (car default-handlers)))
|
||||
;; enter
|
||||
(set! default-handlers (cdr default-handlers))
|
||||
(when (and (not enter) (car default-handlers))
|
||||
(when (and (eq? enter '*no-state*) (car default-handlers))
|
||||
(set! enter (car default-handlers)))
|
||||
;; trans
|
||||
(set! default-handlers (cdr default-handlers))
|
||||
(when (and (not trans) (car default-handlers))
|
||||
(when (and (eq? trans '*no-state*) (car default-handlers))
|
||||
(set! trans (car default-handlers)))
|
||||
;; exit
|
||||
(set! default-handlers (cdr default-handlers))
|
||||
(when (and (not exit) (car default-handlers))
|
||||
(when (and (eq? exit '*no-state*) (car default-handlers))
|
||||
(set! exit (car default-handlers)))
|
||||
;; code
|
||||
(set! default-handlers (cdr default-handlers))
|
||||
(when (and (not code) (car default-handlers))
|
||||
(when (and (eq? code '*no-state*) (car default-handlers))
|
||||
(set! code (car default-handlers)))
|
||||
;; post
|
||||
(set! default-handlers (cdr default-handlers))
|
||||
(when (and (not post) (car default-handlers))
|
||||
(when (and (eq? post '*no-state*) (car default-handlers))
|
||||
(set! post (car default-handlers)))
|
||||
|
||||
(set! default-handlers (cdr default-handlers))
|
||||
)
|
||||
)
|
||||
@@ -207,7 +215,7 @@ It type checks the arguments for the entry function.
|
||||
`(define-virtual-state-hook ,state-name ,defstate-type ,new-state :event ,event :enter ,enter :trans ,trans :exit ,exit :code ,code :post ,post)
|
||||
`(define-state-hook ,state-name ,defstate-type ,new-state :event ,event :enter ,enter :trans ,trans :exit ,exit :code ,code :post ,post)
|
||||
)
|
||||
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -215,7 +223,7 @@ It type checks the arguments for the entry function.
|
||||
|
||||
(defmacro behavior (bindings &rest body)
|
||||
"Define an anonymous behavior for a process state. This may only be used inside a defstate!"
|
||||
|
||||
|
||||
(let ((behavior-type (first *defstate-type-stack*)))
|
||||
(pop! *defstate-type-stack*)
|
||||
`(lambda :behavior ,behavior-type ,bindings ,@body)
|
||||
@@ -275,11 +283,11 @@ It type checks the arguments for the entry function.
|
||||
)
|
||||
(else
|
||||
;; Note: this is added to let us defstate on a child before the parent.
|
||||
;; The child won't be usable like this, but it will prevent a crash.
|
||||
;; The child won't be usable like this, but it will prevent a crash.
|
||||
(format 0 "[STATE ERROR] inherit-state got a null parent state. Child is ~A~%" (-> child name))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
child
|
||||
)
|
||||
|
||||
@@ -330,7 +338,7 @@ It type checks the arguments for the entry function.
|
||||
;; loop through current stack frames
|
||||
(let ((frame (-> pp stack-frame-top)))
|
||||
(while frame
|
||||
(case (-> frame type)
|
||||
(case (-> frame type)
|
||||
((protect-frame state)
|
||||
((-> (the-as protect-frame frame) exit))
|
||||
)
|
||||
@@ -338,7 +346,7 @@ It type checks the arguments for the entry function.
|
||||
(set! frame (-> frame next))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
;; done with going!
|
||||
(process-mask-clear! (-> pp mask) going)
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
(deftype pc-pad-proc (process)
|
||||
((state-time int64)
|
||||
(input-index uint64)
|
||||
(pad-idx uint64)
|
||||
(pad-idx int64)
|
||||
)
|
||||
:heap-base #x20
|
||||
(:states
|
||||
@@ -123,17 +123,19 @@
|
||||
(kill-by-name 'pc-pad-show *active-pool*)
|
||||
)
|
||||
|
||||
(defun-debug pc-pad-input-start ()
|
||||
(defun-debug pc-pad-input-start ((pad-idx int))
|
||||
"Start the PC port pad debug key mapping"
|
||||
|
||||
(if (not (handle->process (-> *pc-pad-proc-list* input)))
|
||||
(let ((procp
|
||||
(make-init-process pc-pad-proc :name 'pc-pad-input
|
||||
(lambda :behavior pc-pad-proc ()
|
||||
(set! (-> self pad-idx) 0)
|
||||
(lambda :behavior pc-pad-proc ((pad-idx int))
|
||||
(set! (-> self pad-idx) pad-idx)
|
||||
(pc-pad-input-mode-set #t)
|
||||
(pc-pad-input-pad-set (-> self pad-idx))
|
||||
(go pc-pi-mapping-button)
|
||||
)
|
||||
pad-idx
|
||||
)
|
||||
))
|
||||
(set! (-> *pc-pad-proc-list* input) (ppointer->handle procp))
|
||||
@@ -194,6 +196,7 @@
|
||||
;; something's changed, go back to the main state and check everything
|
||||
(go pc-pi-mapping-button)
|
||||
)
|
||||
(none)
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user