diff --git a/game/system/newpad.cpp b/game/system/newpad.cpp index 70cc03094f..a7ecc31ff4 100644 --- a/game/system/newpad.cpp +++ b/game/system/newpad.cpp @@ -8,10 +8,12 @@ #include "common/log/log.h" #include "common/util/Assert.h" -#include +#include "common/util/FileUtil.h" #include "game/graphics/pipelines/opengl.h" // for GLFW macros +#include "third-party/imgui/imgui.h" + namespace Pad { /* @@ -57,6 +59,10 @@ void ClearKeys() { } void OnKeyPress(int key) { + if (ImGui::IsAnyItemActive()) { + return; + } + if (input_mode == InputModeStatus::Enabled) { if (key == GLFW_KEY_ESCAPE) { ExitInputMode(true); @@ -118,14 +124,13 @@ int IsPressed(MappingInfo& mapping, Button button, int pad = 0) { // returns the value of the analog axis (in the future, likely pressure sensitive if we support it?) // if invalid or otherwise -- returns 127 (analog stick neutral position) int AnalogValue(MappingInfo& /*mapping*/, Analog analog, int pad = 0) { - float input = 0.0f; - if (CheckPadIdx(pad) == -1) { // Pad out of range, return a stable value return 127; } - if (pad == 0 && g_gamepads.gamepad_idx[0] == -1) { // Gamepad not present - use keyboard + float input = 0.0f; + if (pad == 0) { // Movement controls mapped to WASD keys if (g_buffered_key_status[GLFW_KEY_W] && analog == Analog::Left_Y) input += -1.0f; @@ -145,7 +150,7 @@ int AnalogValue(MappingInfo& /*mapping*/, Analog analog, int pad = 0) { input += -1.0f; if (g_buffered_key_status[GLFW_KEY_L] && analog == Analog::Right_X) input += 1.0f; - } else if (pad == 1 && g_gamepads.gamepad_idx[1] == -1) { + } else if (pad == 1) { // these bindings are not sane if (g_buffered_key_status[GLFW_KEY_KP_5] && analog == Analog::Left_Y) input += -1.0f; @@ -165,7 +170,9 @@ int AnalogValue(MappingInfo& /*mapping*/, Analog analog, int pad = 0) { input += -1.0f; if (g_buffered_key_status[GLFW_KEY_KP_9] && analog == Analog::Right_X) input += 1.0f; - } else { // Gamepad present + } + + if (input == 0) { input = g_gamepad_analogs[pad][(int)analog]; } diff --git a/goal_src/jak1/engine/game/settings-h.gc b/goal_src/jak1/engine/game/settings-h.gc index 3acdaf004f..12430fbd5a 100644 --- a/goal_src/jak1/engine/game/settings-h.gc +++ b/goal_src/jak1/engine/game/settings-h.gc @@ -234,20 +234,3 @@ (define-extern *setting-control* setting-control) -(defun scf-time-to-uint64 () - (let ((date (new 'stack 'scf-time))) - (let ((temp (the uint64 0))) - (scf-get-time date) - - (logior! temp (-> date stat)) - (logior! temp (shl (-> date second) 8)) - (logior! temp (shl (-> date minute) 16)) - (logior! temp (shl (-> date hour) 24)) - (logior! temp (shl (-> date week) 32)) - (logior! temp (shl (-> date day) 40)) - (logior! temp (shl (-> date month) 48)) - (logior! temp (shl (-> date year) 56)) - temp - ) - ) -) diff --git a/goal_src/jak1/game.gp b/goal_src/jak1/game.gp index c6726d1e9b..914b6d6c15 100644 --- a/goal_src/jak1/game.gp +++ b/goal_src/jak1/game.gp @@ -1708,7 +1708,17 @@ "engine/connect.gc" "ui/text-h.gc" "game/settings-h.gc" - "math/knuth-rand.gc" ;; added + ) + +(goal-src "pc/util/knuth-rand.gc" "settings-h") + +(goal-src-sequence + ;; prefix + "engine/" + + :deps + ("$OUT/obj/settings-h.o") + "util/capture.gc" "debug/memory-usage-h.gc" "gfx/texture/texture.gc" @@ -2021,7 +2031,7 @@ (goal-src "pc/pckernel.gc" "settings" "video") (goal-src "pc/subtitle.gc" "text" "pckernel" "hint-control" "loader-h" "gsound" "ambient") (goal-src "pc/progress-pc.gc" "progress" "pckernel") -(goal-src "pc/anim-tester-x.gc" "pckernel" "gstring" "joint" "process-drawable" "art-h" "effect-control") +(goal-src "pc/util/anim-tester-x.gc" "pckernel" "gstring" "joint" "process-drawable" "art-h" "effect-control") (goal-src "pc/hud-classes-pc.gc" "pckernel" "hud" "battlecontroller" "generic-obs") ;; the debug menu is modified to include PC specific options: diff --git a/goal_src/jak1/pc/pckernel.gc b/goal_src/jak1/pc/pckernel.gc index 73eb25097c..8b61d429db 100644 --- a/goal_src/jak1/pc/pckernel.gc +++ b/goal_src/jak1/pc/pckernel.gc @@ -859,6 +859,10 @@ (("hard-fish-hiscore") (set! (-> obj secrets hard-fish-hiscore) (file-stream-read-int file))) (("hard-rats-hiscore") (set! (-> obj secrets hard-rats-hiscore) (file-stream-read-int file))) (("hard-rats-hiwave") (set! (-> obj secrets hard-rats-hiwave) (file-stream-read-int file))) + (("cheats") + (set! (-> obj cheats-known) (the pc-cheats (file-stream-read-int file))) + (set! (-> obj cheats) (logand (-> obj cheats-known) (file-stream-read-int file))) + ) (("music") (dotimes (i PC_MUSIC_LOG_LENGTH) (when (!= #x29 (file-stream-get-next-char-ret file)) @@ -986,6 +990,7 @@ (format file " (hard-rats-hiscore ~D)~%" (-> obj secrets hard-rats-hiscore)) (format file " (hard-rats-hiwave ~D)~%" (-> obj secrets hard-rats-hiwave)) |# + (format file " (cheats #x~x #x~x)~%" (-> obj cheats-known) (-> obj cheats)) (format file " (music~%") (dotimes (i PC_MUSIC_LOG_LENGTH) diff --git a/goal_src/jak1/pc/progress-pc.gc b/goal_src/jak1/pc/progress-pc.gc index 5cc57de59a..6f5762e900 100644 --- a/goal_src/jak1/pc/progress-pc.gc +++ b/goal_src/jak1/pc/progress-pc.gc @@ -447,9 +447,9 @@ ;; supersampling in fullscreen and stuff. this results in way too many resolution options lol. (when (!= display-mode 'windowed) - (*! sx 4) - (*! sy 4) - (*! mult 4) + (*! sx 2) + (*! sy 2) + (*! mult 2) ) ;; game aspect ratio @@ -1190,8 +1190,6 @@ (set-size! *pc-settings* newx newy)) (cpad-clear! 0 x) (cpad-clear! 0 circle) - (cpad-clear! 0 square) - (cpad-clear! 0 triangle) (sound-play "cursor-options") (set! (-> obj next-display-state) (progress-screen invalid)) (commit-to-file *pc-settings*) @@ -1234,8 +1232,6 @@ (set-aspect! *pc-settings* newx newy)))) (cpad-clear! 0 x) (cpad-clear! 0 circle) - (cpad-clear! 0 square) - (cpad-clear! 0 triangle) (sound-play "cursor-options") (commit-to-file *pc-settings*) (set! (-> obj next-display-state) (progress-screen invalid)) @@ -1631,6 +1627,7 @@ (cond ((-> *progress-state* yes-no-choice) (sound-play "start-options") + (commit-to-file *pc-settings*) (sound-volume-off) (kernel-shutdown) ) diff --git a/goal_src/jak1/pc/anim-tester-x.gc b/goal_src/jak1/pc/util/anim-tester-x.gc similarity index 100% rename from goal_src/jak1/pc/anim-tester-x.gc rename to goal_src/jak1/pc/util/anim-tester-x.gc diff --git a/goal_src/jak1/engine/math/knuth-rand.gc b/goal_src/jak1/pc/util/knuth-rand.gc similarity index 58% rename from goal_src/jak1/engine/math/knuth-rand.gc rename to goal_src/jak1/pc/util/knuth-rand.gc index 3447ac4035..8c5bb7f248 100644 --- a/goal_src/jak1/engine/math/knuth-rand.gc +++ b/goal_src/jak1/pc/util/knuth-rand.gc @@ -6,66 +6,82 @@ ;;;; This is a linear congruential pseudorandom number generator, as defined by D. H. Lehmer ;;;; and described by Donald E. Knuth in The Art of Computer Programming, Volume 3: Seminumerical Algorithms, section 3.2.1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(deftype knuth-rand-state (structure) - ((seed uint64)) + + +(defun scf-time-to-int64 () + "pack system time into 64-bits for randomization purposes." + (let ((date (new 'stack-no-clear 'scf-time))) + (scf-get-time date) + + (logior (the int (-> date stat)) + (shl (-> date second) 8) + (shl (-> date minute) 16) + (shl (-> date hour) 24) + (shl (-> date week) 32) + (shl (-> date day) 40) + (shl (-> date month) 48) + (shl (-> date year) 56)) + ) ) -(define *knuth-rand-state* (new 'global 'knuth-rand-state)) -(defun knuth-rand-init ((newSeed uint)) - (set! (-> *knuth-rand-state* seed) newSeed) -) -(knuth-rand-init (scf-time-to-uint64)) +(deftype knuth-rand-state (structure) + ((seed int64)) + ) + +(define *knuth-rand-state* (new 'static 'knuth-rand-state)) + + +(defun knuth-rand-init ((seed int)) + (set! (-> *knuth-rand-state* seed) seed) + ) (defun knuth-rand-advance-seed () ;; seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1) - (set! (-> *knuth-rand-state* seed) (the uint64 (logand (+ (imul64 (-> *knuth-rand-state* seed) 25214903917) 11) (- (shl 1 48) 1)))) -) + (set! (-> *knuth-rand-state* seed) (logand (+ (imul64 (-> *knuth-rand-state* seed) #x5deece66d) #xb) (- (shl 1 48) 1))) + ) (defun knuth-rand-next ((bits int)) (knuth-rand-advance-seed) - ;; return (int)(seed >>> (48 - bits)) (shr (-> *knuth-rand-state* seed) (- 48 bits)) -) + ) -(defun knuth-rand-nextInt () +(defun knuth-rand-next-int () (knuth-rand-advance-seed) (-> *knuth-rand-state* seed) -) + ) ;; returns a pseudorandom int in the range [min, max) -(defun knuth-rand-nextIntRange ((min int) (max int)) +(defun knuth-rand-int-range ((min int) (max int)) (let* ((bound (- max min)) - ;; int bits, val; - (bits (the uint64 0)) - (val (the uint64 0))) + ;; int bits, val; + (bits 0) + (val 0)) ;; if ((bound & -bound) == bound) // i.e., bound is a power of 2 (if (= (logand bound (* -1 bound)) bound) ;; return (int)((bound * (long)next(31)) >> 31); (return (sar (* bound (knuth-rand-next 31)) 31)) - ) + ) ;; do { ;; bits = next(31); ;; val = bits % bound; ;; } while (bits - val + (bound-1) < 0); ;; return val; - (while #t + (until (not (< (+ bits (- val) bound -1) 0)) (set! bits (knuth-rand-next 31)) (set! val (mod bits bound)) - - (if (>= (+ bits (* -1 val) bound -1) 0) - (return (+ min val)) ) - ) + (+ min val)) ) - -1 -) ;; returns a pseudorandom float in the range [0, 1) -(defun knuth-rand-nextFloat () +(defun knuth-rand-next-float () ;; return next(24) / ((float)(1 << 24)); (/ (the float (knuth-rand-next 24)) (shl 1 24)) -) \ No newline at end of file + ) + +(knuth-rand-init (scf-time-to-int64)) +