summaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorkitty piapiac <kcp@bsd.computer>2023-04-21 23:50:06 -0700
committerkitty piapiac <kcp@bsd.computer>2023-04-21 23:50:06 -0700
commit8f38659932677a2b0e00b7f4abda54ac76a8ecd9 (patch)
tree705767e858a3fe0c89b7b4bc0440012a084c6921 /input.c
parent599cde356b576759475d34dbfadb5548926c089d (diff)
SRS-style rotation skeleton
Diffstat (limited to 'input.c')
-rw-r--r--input.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/input.c b/input.c
index 8248ded..d22e2cb 100644
--- a/input.c
+++ b/input.c
@@ -4,10 +4,38 @@
#include"graph.h"
#include"input.h"
#define SDLBUT(x)SDL_BUTTON(SDL_BUTTON_##x)
-InputPoint input_point(V){InputPoint ip;SDL_GetMouseState((S32*)&ip.x,(S32*)&ip.y);ip.y=graph_win_h-ip.y;R ip;}
-InputButtons input_button(V){InputButtons ib={0};U32 mb;mb=SDL_GetMouseState(0,0);
- Q(SDLBUT(LEFT)&mb, ib.f|=IB_1)
- Q(SDLBUT(MIDDLE)&mb, ib.f|=IB_2)
- Q(SDLBUT(RIGHT)&mb, ib.f|=IB_3)
- Q(SDLBUT(X1)&mb, ib.f|=IB_4)
- R ib;}
+InputPoint input_point;
+InputButtons input_buttons;
+
+_ U32 map_mouse[][2]={
+ {SDLBUT(LEFT), IB_1},
+ {SDLBUT(RIGHT), IB_2},
+ {SDLBUT(MIDDLE),IB_3},
+ {SDLBUT(X1), IB_4}};
+
+_ U32 map_keeb[][2]={
+ {SDL_SCANCODE_LEFT, IB_L},
+ {SDL_SCANCODE_RIGHT, IB_R},
+ {SDL_SCANCODE_UP, IB_U},
+ {SDL_SCANCODE_DOWN, IB_D},
+ {SDL_SCANCODE_SPACE, IB_S},
+ {SDL_SCANCODE_Z, IB_Z},
+ {SDL_SCANCODE_X, IB_X},
+ {SDL_SCANCODE_C, IB_C}};
+
+#define ip input_point
+#define ib input_buttons
+#define mm map_mouse
+#define mk map_keeb
+V input_update(V){U32 mb,mm_len,mk_len,i,kb_len;IM U8*kb;InputButtons nb={0,0};
+ mb=SDL_GetMouseState((S32*)&ip.x,(S32*)&ip.y),ip.y=graph_win_h-ip.y,
+ kb=SDL_GetKeyboardState((S32*)&kb_len),
+ mm_len=(SZ mm)/(SZ mm[0]),
+ mk_len=(SZ mk)/(SZ mk[0]),
+ i=0;WH(i<mm_len,Q(mm[i][0]&mb, Q(mm[i][1]&(ib.p|ib.h),nb.h|=mm[i][1])OR nb.p|=mm[i][1]);++i)
+ i=0;WH(i<mk_len,Q(kb[mk[i][0]],Q(mk[i][1]&(ib.p|ib.h),nb.h|=mk[i][1])OR nb.p|=mk[i][1]);++i)
+ input_buttons=nb;}
+#undef mk
+#undef mm
+#undef ib
+#undef ip