|
@@ -105,8 +105,8 @@ present :: proc() {
|
|
|
//
|
|
//
|
|
|
// WARNING: Not calling this will make your program impossible to interact with.
|
|
// WARNING: Not calling this will make your program impossible to interact with.
|
|
|
process_events :: proc() {
|
|
process_events :: proc() {
|
|
|
- s.keys_went_up = {}
|
|
|
|
|
- s.keys_went_down = {}
|
|
|
|
|
|
|
+ s.key_went_up = {}
|
|
|
|
|
+ s.key_went_down = {}
|
|
|
s.mouse_button_went_up = {}
|
|
s.mouse_button_went_up = {}
|
|
|
s.mouse_button_went_down = {}
|
|
s.mouse_button_went_down = {}
|
|
|
s.mouse_delta = {}
|
|
s.mouse_delta = {}
|
|
@@ -122,12 +122,12 @@ process_events :: proc() {
|
|
|
s.shutdown_wanted = true
|
|
s.shutdown_wanted = true
|
|
|
|
|
|
|
|
case Window_Event_Key_Went_Down:
|
|
case Window_Event_Key_Went_Down:
|
|
|
- s.keys_went_down[e.key] = true
|
|
|
|
|
- s.keys_is_held[e.key] = true
|
|
|
|
|
|
|
+ s.key_went_down[e.key] = true
|
|
|
|
|
+ s.key_is_held[e.key] = true
|
|
|
|
|
|
|
|
case Window_Event_Key_Went_Up:
|
|
case Window_Event_Key_Went_Up:
|
|
|
- s.keys_went_up[e.key] = true
|
|
|
|
|
- s.keys_is_held[e.key] = false
|
|
|
|
|
|
|
+ s.key_went_up[e.key] = true
|
|
|
|
|
+ s.key_is_held[e.key] = false
|
|
|
|
|
|
|
|
case Window_Event_Mouse_Button_Went_Down:
|
|
case Window_Event_Mouse_Button_Went_Down:
|
|
|
s.mouse_button_went_down[e.button] = true
|
|
s.mouse_button_went_down[e.button] = true
|
|
@@ -145,6 +145,18 @@ process_events :: proc() {
|
|
|
case Window_Event_Mouse_Wheel:
|
|
case Window_Event_Mouse_Wheel:
|
|
|
s.mouse_wheel_delta = e.delta
|
|
s.mouse_wheel_delta = e.delta
|
|
|
|
|
|
|
|
|
|
+ case Window_Event_Gamepad_Button_Went_Down:
|
|
|
|
|
+ if e.gamepad < MAX_GAMEPADS {
|
|
|
|
|
+ s.gamepad_button_went_down[e.gamepad][e.button] = true
|
|
|
|
|
+ s.gamepad_button_is_held[e.gamepad][e.button] = true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ case Window_Event_Gamepad_Button_Went_Up:
|
|
|
|
|
+ if e.gamepad < MAX_GAMEPADS {
|
|
|
|
|
+ s.gamepad_button_went_up[e.gamepad][e.button] = true
|
|
|
|
|
+ s.gamepad_button_is_held[e.gamepad][e.button] = false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
case Window_Event_Resize:
|
|
case Window_Event_Resize:
|
|
|
s.width = e.width
|
|
s.width = e.width
|
|
|
s.height = e.height
|
|
s.height = e.height
|
|
@@ -213,19 +225,19 @@ draw_current_batch :: proc() {
|
|
|
// Returns true if a keyboard key went down between the current and the previous frame. Set when
|
|
// Returns true if a keyboard key went down between the current and the previous frame. Set when
|
|
|
// 'process_events' runs (probably once per frame).
|
|
// 'process_events' runs (probably once per frame).
|
|
|
key_went_down :: proc(key: Keyboard_Key) -> bool {
|
|
key_went_down :: proc(key: Keyboard_Key) -> bool {
|
|
|
- return s.keys_went_down[key]
|
|
|
|
|
|
|
+ return s.key_went_down[key]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Returns true if a keyboard key went up (was released) between the current and the previous frame.
|
|
// Returns true if a keyboard key went up (was released) between the current and the previous frame.
|
|
|
// Set when 'process_events' runs (probably once per frame).
|
|
// Set when 'process_events' runs (probably once per frame).
|
|
|
key_went_up :: proc(key: Keyboard_Key) -> bool {
|
|
key_went_up :: proc(key: Keyboard_Key) -> bool {
|
|
|
- return s.keys_went_up[key]
|
|
|
|
|
|
|
+ return s.key_went_up[key]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Returns true if a keyboard is currently being held down. Set when 'process_events' runs (probably
|
|
// Returns true if a keyboard is currently being held down. Set when 'process_events' runs (probably
|
|
|
// once per frame).
|
|
// once per frame).
|
|
|
key_is_held :: proc(key: Keyboard_Key) -> bool {
|
|
key_is_held :: proc(key: Keyboard_Key) -> bool {
|
|
|
- return s.keys_is_held[key]
|
|
|
|
|
|
|
+ return s.key_is_held[key]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
mouse_button_went_down :: proc(button: Mouse_Button) -> bool {
|
|
mouse_button_went_down :: proc(button: Mouse_Button) -> bool {
|
|
@@ -248,6 +260,30 @@ get_mouse_position :: proc() -> Vec2 {
|
|
|
return s.mouse_position
|
|
return s.mouse_position
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+gamepad_button_went_down :: proc(gamepad: int, button: Gamepad_Button) -> bool {
|
|
|
|
|
+ if gamepad < 0 || gamepad >= MAX_GAMEPADS {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return s.gamepad_button_went_down[gamepad][button]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+gamepad_button_went_up :: proc(gamepad: int, button: Gamepad_Button) -> bool {
|
|
|
|
|
+ if gamepad < 0 || gamepad >= MAX_GAMEPADS {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return s.gamepad_button_went_up[gamepad][button]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+gamepad_button_is_held :: proc(gamepad: int, button: Gamepad_Button) -> bool {
|
|
|
|
|
+ if gamepad < 0 || gamepad >= MAX_GAMEPADS {
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return s.gamepad_button_is_held[gamepad][button]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
//---------//
|
|
//---------//
|
|
|
// DRAWING //
|
|
// DRAWING //
|
|
|
//---------//
|
|
//---------//
|
|
@@ -931,6 +967,8 @@ Handle :: hm.Handle
|
|
|
Texture_Handle :: distinct Handle
|
|
Texture_Handle :: distinct Handle
|
|
|
TEXTURE_NONE :: Texture_Handle {}
|
|
TEXTURE_NONE :: Texture_Handle {}
|
|
|
|
|
|
|
|
|
|
+MAX_GAMEPADS :: 4
|
|
|
|
|
+
|
|
|
// This keeps track of the internal state of the library. Usually, you do not need to poke at it.
|
|
// This keeps track of the internal state of the library. Usually, you do not need to poke at it.
|
|
|
// It is created and kept as a global variable when 'init' is called. However, 'init' also returns
|
|
// It is created and kept as a global variable when 'init' is called. However, 'init' also returns
|
|
|
// the pointer to it, so you can later use 'set_internal_state' to restore it (after for example hot
|
|
// the pointer to it, so you can later use 'set_internal_state' to restore it (after for example hot
|
|
@@ -949,14 +987,18 @@ State :: struct {
|
|
|
mouse_delta: Vec2,
|
|
mouse_delta: Vec2,
|
|
|
mouse_wheel_delta: f32,
|
|
mouse_wheel_delta: f32,
|
|
|
|
|
|
|
|
- keys_went_down: #sparse [Keyboard_Key]bool,
|
|
|
|
|
- keys_went_up: #sparse [Keyboard_Key]bool,
|
|
|
|
|
- keys_is_held: #sparse [Keyboard_Key]bool,
|
|
|
|
|
|
|
+ key_went_down: #sparse [Keyboard_Key]bool,
|
|
|
|
|
+ key_went_up: #sparse [Keyboard_Key]bool,
|
|
|
|
|
+ key_is_held: #sparse [Keyboard_Key]bool,
|
|
|
|
|
|
|
|
mouse_button_went_down: #sparse [Mouse_Button]bool,
|
|
mouse_button_went_down: #sparse [Mouse_Button]bool,
|
|
|
mouse_button_went_up: #sparse [Mouse_Button]bool,
|
|
mouse_button_went_up: #sparse [Mouse_Button]bool,
|
|
|
mouse_button_is_held: #sparse [Mouse_Button]bool,
|
|
mouse_button_is_held: #sparse [Mouse_Button]bool,
|
|
|
|
|
|
|
|
|
|
+ gamepad_button_went_down: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
|
|
|
|
|
+ gamepad_button_went_up: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
|
|
|
|
|
+ gamepad_button_is_held: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
|
|
|
|
|
+
|
|
|
window: Window_Handle,
|
|
window: Window_Handle,
|
|
|
width: int,
|
|
width: int,
|
|
|
height: int,
|
|
height: int,
|
|
@@ -1100,6 +1142,32 @@ Keyboard_Key :: enum {
|
|
|
KP_Equal = 336,
|
|
KP_Equal = 336,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+Gamepad_Button :: enum {
|
|
|
|
|
+ // DPAD buttons
|
|
|
|
|
+ Left_Face_Up,
|
|
|
|
|
+ Left_Face_Down,
|
|
|
|
|
+ Left_Face_Left,
|
|
|
|
|
+ Left_Face_Right,
|
|
|
|
|
+
|
|
|
|
|
+ Right_Face_Up, // XBOX: Y, PS: Triangle
|
|
|
|
|
+ Right_Face_Down, // XBOX: A, PS: X
|
|
|
|
|
+ Right_Face_Left, // XBOX: X, PS: Square
|
|
|
|
|
+ Right_Face_Right, // XBOX: B, PS: Circle
|
|
|
|
|
+
|
|
|
|
|
+ Left_Shoulder,
|
|
|
|
|
+ Left_Trigger,
|
|
|
|
|
+
|
|
|
|
|
+ Right_Shoulder,
|
|
|
|
|
+ Right_Trigger,
|
|
|
|
|
+
|
|
|
|
|
+ Left_Stick_Press, // Clicking the left analogue stick
|
|
|
|
|
+ Right_Stick_Press, // Clicking the right analogue stick
|
|
|
|
|
+
|
|
|
|
|
+ Middle_Face_Left, // Select / back / options button
|
|
|
|
|
+ Middle_Face_Middle, // PS button (not available on XBox)
|
|
|
|
|
+ Middle_Face_Right, // Start
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// Used by API builder. Everything after this constant will not be in karl2d.doc.odin
|
|
// Used by API builder. Everything after this constant will not be in karl2d.doc.odin
|
|
|
API_END :: true
|
|
API_END :: true
|
|
|
|
|
|