From 5feb20b352499437648caa21efd7aecfef2a0b58 Mon Sep 17 00:00:00 2001 From: Julia <145168563+julia-aph@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:20:44 -0500 Subject: [PATCH] time, c things just learned you don't need to include everything all the damn time --- Fumofumotris.code-workspace | 63 +++++++++++ hi.exe | Bin 66475 -> 65675 bytes source/game/gametime.c | 10 +- source/game/gametime.h | 7 +- source/io/ctrl.c | 204 ++++++++++++++---------------------- source/io/ctrl.h | 65 ++++++------ source/io/input.c | 59 +---------- source/io/input.h | 30 ++++-- source/main.c | 4 +- 9 files changed, 213 insertions(+), 229 deletions(-) create mode 100644 Fumofumotris.code-workspace diff --git a/Fumofumotris.code-workspace b/Fumofumotris.code-workspace new file mode 100644 index 0000000..8400082 --- /dev/null +++ b/Fumofumotris.code-workspace @@ -0,0 +1,63 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "files.associations": { + "pthread.h": "c", + "fumotris.h": "c", + "string.h": "c", + "input.h": "c", + "stdint.h": "c", + "iso646.h": "c", + "win.h": "c", + "array": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "string_view": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp", + "execution": "cpp", + "stdbool.h": "c" + } + } +} \ No newline at end of file diff --git a/hi.exe b/hi.exe index e4ef518335611d168b2d6647f1718d82dd6f9ed6..0799adada267a0015f48dc8b384e328022597846 100644 GIT binary patch delta 11362 zcmc&)d0bTG`akEuAPgWQgNOslFlRsn(s2P%OUDv8n&!B5wMB6OH6=;W>n(LaG8rcn zeB3IlL96SUqm+9&kcqaUnOQEOw&1l}v|cN3-0yqNoPn|E{(irIe)IXf=h>h4d7t-r zmvdmpia=*cU`3f>O@2Z?_bA6*)o@%Bm&An%LJF70aomK;%^5;|W928qd5IGFR6dtR z^MkdGsgUW=(&%ZvYlf8vYDE*!dZV@aSvk(rW8U;BMN`0xK(nDS)4udI->v&lV6A>u zrd_CLO92oRq6MO5(;&gnejH;Jds)LNUl_&TL;Hko`~u@>>wLPqdkS= zu4@mnp*7A2-uQKQj+2}n_akIyq(j$uR-sp@^iqsUa%#HCeoAlf3nD;mgH&?VG#-wn z@}L;q2Byq8G=H_rx)Qw_WD)9;=*yr4-b^9wdI&$>N&VX`2x67WI|czjFdt)UJQyx} z`qc_R(IH8~y;>R+5Ol}7$l^!d6@Qv}3<8!I>DjTz&&1xmEPDD2tj}iHu&WONywGiArB%##~Vp zFzBL!inKtPj9Z|UGk=Ykozn9VRs(VjLmV~0SZu=_9%Y6k=#6mHNsd$BOFO(m$+=GM z$5EkE;+IF`TqlR@s8A@`P5w|vMRK~Ik{rCF!qUQoQduU*11vtNx-auL+%bvA8uwvm(>Uw%^HkS zUSMJ!fOa6DEcml(%WXVE^Bp!V6I`Fno=zQl>|bkN5G3aiiHH}hKfsZY(os&ooHQM)^7Ll97@1_s$GqfYV)ErIj*qFif@FF^>U{&V zkf%e8J>QX)9I=1AF=BsK42*Xp2drpO4jQ#U>gBBg8B)}ep;p#PO)Z*jiW-}0Ot3PU z{h6l`&SJTWc{H^hTT->pMDL>D46=I9^y6s5tJ zE@Gdx%j2E}Mus1^#>wS(+}cHk2pshpDLHi4Qz4ImZb#U~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5$&u|LUXWHY$;!cuQ3G_V4C>-Kfw%nprbv=X_e+!q}O2%=G0>JN;dycqI#7 zQ>bje&)#WJ-yQH#Gj}O8_n?nD2`cN*zl1k^w?Z=y`;D% zveU;Z#ZL3~DAEgB6_>scO8fShrILZ_&ed9D;@({8Ewz;0`F1kDUQF*F@%cLRxy?4SWW@Q3|+-ujrkt=V~(K$P-tQJq}shRb)Mn zV9#7d_84UCSCNIjqeNc1ifkohLgv5L>&!dzBSWvi&)I3F>ZA5Z!xd!6ZSA{CWbBni zv=lPqRb(BIWn4w}@Oz5%p|)(N-^-LNncX%>`LSH_ES-PLEOv42G{s#k{x7}m&SvGm zJ{(W?Zwu?DaJ}}@o6*za^C;>B+FTkHb}t?gb8+T}(BPT`-2er8oa0Inw2~!W z)`C*LCFJ>|0wF}r*{8gp?RE&SIYtlI?4Bk^pmn=&7?^u zhvRL%3Pflo{TYOrPMwrfD+7Ga!s}skzzY8noCcCl*&_=A{J){{mz>HL>#6aS9AypY z-S{XZ5KP~l8jkRiKU)%M4Os56{qPn}J3h0IYzi>?9QYXloc-V!0yrOmgXa948(=p6 z*3pK~SEn@ul=pHp$bf));gxfGCQUhQlB@%%^t1^#_jRW?+3pvdY5Zy)Sx&rJ; zc<&1xNR?mQhwI9@FYI`s8rGJL+RkgsPOXP(S0@+6;S+E`1xvs&(pzoWk)!;H%z3bM zURe>o^;5(dUZcTh?6Cac8F^q+z}$)P_;~6+KeU~RL^M0}$(dVojeeU5LwFPVm4IEH zb`%_Uz#5+dNAS;DgwJ3_`0Q0ji_Xe3`8BsImni(}L9AaBvjihJ%~0slv9V4-sc#0y zcTQ{F$p1278Av~!9Uj@044eB2f_fVLWp-p+K!_Q5A&;f1FXfSk1IjTE{7abEmEK}- U+Wk6nN{dibB-426%Z9}N15C<5p#T5? diff --git a/source/game/gametime.c b/source/game/gametime.c index 3c6fbcc..635a645 100644 --- a/source/game/gametime.c +++ b/source/game/gametime.c @@ -5,11 +5,17 @@ #include "win.h" #endif -struct timespec TimeNow() +struct Time { + u32 sec; + u32 nsec; +}; + +struct Time TimeNow() { struct timespec ts; + // Need to check for failiure timespec_get(&ts, TIME_UTC); - return ts; + return (struct Time) { ts.tv_sec, ts.tv_nsec }; } double TimeNowDouble() diff --git a/source/game/gametime.h b/source/game/gametime.h index 4f227e7..61c8dd6 100644 --- a/source/game/gametime.h +++ b/source/game/gametime.h @@ -1,6 +1,11 @@ #pragma once #include -struct timespec TimeNow(); +struct Time { + u32 sec; + u32 nsec; +}; + +struct Time TimeNow(); double TimeNowDouble(); diff --git a/source/io/ctrl.c b/source/io/ctrl.c index 0bea90e..142eaca 100644 --- a/source/io/ctrl.c +++ b/source/io/ctrl.c @@ -1,89 +1,49 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include "ctrl.h" -#include "fumotris.h" -#include "hash.h" -#include "input.h" - -struct CtrlAxis { - struct timespec last_pressed; - struct timespec last_released; - - u8 type; - u8 is_down; - u8 is_held; - u8 is_up; - - union { - struct Button but; - struct Axis axis; - struct Joystick js; - union InputData data; - }; +struct ctrl_bkt { + union InputID id; + struct InputAxis *axis; }; struct ctrl_dict { - size_t capacity; - size_t filled; + struct ctrl_bkt *bkts; - struct ctrl_bkt { - hashtype hash; - u16 value; - u8 type; - - struct CtrlAxis *axis; - } *bkts; + u16f capacity; + u16f filled; }; -struct Controller { - struct ctrl_dict codes; - struct ctrl_dict binds; - struct CtrlAxis *axes; - - struct InputBuffer input_buf; - - struct { - size_t len; - struct CtrlAxis *axes[IO_BUF_SIZE]; - } pending_buf; +struct axis_vec { + struct InputAxis *axes; + u16f size; + u16f len; }; -bool NewCtrl(struct Controller *ctrl, size_t code_cap, size_t bind_cap) +size_t a = sizeof(struct ctrl_dict); + +bool NewCtrl(struct Controller *ctrl, size_t init_axes) { - struct ctrl_bkt *code_bkts = calloc(code_cap, sizeof(struct ctrl_bkt)); - struct ctrl_bkt *bind_bkts = calloc(bind_cap, sizeof(struct ctrl_bkt)); - struct CtrlAxis *axes = calloc(code_cap, sizeof(struct CtrlAxis)); + struct ctrl_bkt *code_bkts = calloc(init_axes, sizeof(struct ctrl_bkt)); + struct ctrl_bkt *bind_bkts = calloc(init_axes, sizeof(struct ctrl_bkt)); + struct InputAxis *axes = calloc(init_axes, sizeof(struct InputAxis)); if (code_bkts == nullptr or bind_bkts == nullptr or axes == nullptr) return false; - for (size_t i = 0; i < code_cap; i++) { - code_bkts[i].axis = axes + i; - } - *ctrl = (struct Controller) { + .buf.len = 0, + .pending_buf.len = 0, + + .axis_vec.axes = axes, .codes = (struct ctrl_dict) { - .capacity = code_cap, - .filled = 0, .bkts = code_bkts, + .capacity = init_axes, + .filled = 0, }, .binds = (struct ctrl_dict) { - .capacity = bind_cap, - .filled = 0, .bkts = bind_bkts, + .capacity = init_axes, + .filled = 0, }, - .axes = axes, - - .input_buf = (struct InputBuffer) { - .len = 0, - }, - .pending_buf.len = 0, }; return true; } @@ -92,7 +52,7 @@ void FreeCtrl(struct Controller *ctrl) { free(ctrl->codes.bkts); free(ctrl->binds.bkts); - free(ctrl->axes); + free(ctrl->axis_vec.axes); } struct ctrl_bkt *get_bkt(struct ctrl_dict *dict, size_t i) @@ -100,122 +60,101 @@ struct ctrl_bkt *get_bkt(struct ctrl_dict *dict, size_t i) return &dict->bkts[i]; } -void set_bkt(struct ctrl_bkt *bkt, hashtype hash, u16f value, u8f type) -{ - bkt->hash = hash; - bkt->value = value; - bkt->type = type; -} - size_t wrap_index(size_t i, size_t max) { return i % (SIZE_MAX - max + 1); } -hashtype hash_id(u16f value, u8f type) +struct ctrl_bkt *find_or_set(struct ctrl_dict *dict, union InputID id) { - struct { u16 id; u8 type; } id = { value, type }; - return Hash(&id, sizeof(id)); -} - -bool find_or_set(struct ctrl_dict *dict, struct ctrl_bkt **out, u16f value, u8f type) -{ - hashtype hash = hash_id(value, type); - const size_t index = hash % dict->capacity; + const size_t index = id.hash % dict->capacity; size_t i = index; while (i != wrap_index(index - 1, dict->capacity)) { struct ctrl_bkt *bkt = get_bkt(dict, i); - if (bkt->hash == 0) { - set_bkt(bkt, hash, value, type); + if (bkt->axis == nullptr) { + bkt->id.hash = id.hash; dict->filled += 1; - *out = bkt; - return false; + + return bkt; } - if (bkt->value == value and bkt->type == type) { - *out = bkt; - return true; + if (bkt->id.hash == id.hash) { + return bkt; } i = (i + 1) % dict->capacity; } - *out = nullptr; - return false; + return nullptr; } -struct ctrl_bkt *find(struct ctrl_dict *dict, u16f value, u8f type) +struct ctrl_bkt *find(struct ctrl_dict *dict, union InputID id) { - hashtype hash = hash_id(value, type); - const size_t index = hash % dict->capacity; + const size_t index = id.hash % dict->capacity; size_t i = index; while (i != wrap_index(index - 1, dict->capacity)) { struct ctrl_bkt *bkt = get_bkt(dict, i); - if (bkt->hash == 0) - goto next; - if (bkt->value == value and bkt->type == type) + if (bkt->id.hash == id.hash) return bkt; -next: i = (i + 1) % dict->capacity; }; return nullptr; } -struct CtrlAxis *find_axis(struct ctrl_dict *dict, u16f value, u8f type) +struct InputAxis *find_axis(struct ctrl_dict *dict, union InputID id) { - struct ctrl_bkt *bkt = find(dict, value, type); + struct ctrl_bkt *bkt = find(dict, id); if (bkt == nullptr) return nullptr; return bkt->axis; } -bool CtrlMap(struct Controller *ctrl, u16f code, u16f bind, u8f type) +union InputID to_id(u16f value, u16f type) { - if (ctrl->codes.filled >= ctrl->codes.capacity or ctrl->binds.filled >= ctrl->binds.capacity) { - printf("fatal error"); - exit(1); - } + return (union InputID) { .value = value, .type = type }; +} - struct ctrl_bkt *code_bkt; - find_or_set(&ctrl->codes, &code_bkt, code, type); - - struct ctrl_bkt *bind_bkt; - bool bind_existed = find_or_set(&ctrl->binds, &bind_bkt, bind, type); +bool CtrlMap(struct Controller *ctrl, u16f code, u16f type, u16f bind) +{ + struct ctrl_bkt *code_bkt = find_or_set(&ctrl->codes, to_id(code, type)); + struct ctrl_bkt *bind_bkt = find_or_set(&ctrl->binds, to_id(bind, type)); - if(bind_existed and bind_bkt->axis == code_bkt->axis) + if (code_bkt->axis == nullptr) + code_bkt->axis = &ctrl->axis_vec.axes[ctrl->axis_vec.len++]; + else if (code_bkt->axis == bind_bkt->axis) return false; bind_bkt->axis = code_bkt->axis; - code_bkt->axis->type = type; + code_bkt->axis->id.type = type; return true; } -struct CtrlAxis *CtrlGet(struct Controller *ctrl, u16f code, u8f type) +struct InputAxis *CtrlGet(struct Controller *ctrl, u16f code, u16f type) { - struct ctrl_bkt *code_bkt = find(&ctrl->codes, code, type); + struct ctrl_bkt *code_bkt = find(&ctrl->codes, to_id(code, type)); if (code_bkt == nullptr) return nullptr; return code_bkt->axis; } -void dispatch_update(struct CtrlAxis *axis, struct InputRecord *rec) +void dispatch_update(struct InputAxis *axis, struct InputRecord *rec) { if (rec->is_down and !axis->is_held) { axis->is_down = true; axis->is_held = true; - axis->last_pressed = rec->timestamp; + axis->last_pressed = rec->time; } else if (rec->is_up) { axis->is_up = true; axis->is_held = false; - axis->last_released = rec->timestamp; + axis->last_released = rec->time; } axis->data = rec->data; @@ -224,17 +163,18 @@ void dispatch_update(struct CtrlAxis *axis, struct InputRecord *rec) bool CtrlPoll(struct Controller *ctrl) { for (size_t i = 0; i < ctrl->pending_buf.len; i++) { - struct CtrlAxis *axis = ctrl->pending_buf.axes[i]; + struct InputAxis *axis = ctrl->pending_buf.axes[i]; axis->is_up = false; axis->is_down = false; } - ctrl->pending_buf.len = ctrl->input_buf.len; + ctrl->pending_buf.len = ctrl->buf.len; - for (size_t i = 0; i < ctrl->input_buf.len; i++) { - struct InputRecord *rec = &ctrl->input_buf.records[i]; - struct CtrlAxis *axis = find_axis(&ctrl->binds, rec->bind, rec->type); + for (size_t i = 0; i < ctrl->buf.len; i++) { + struct InputRecord *rec = &ctrl->buf.recs[i]; + union InputID rec_id = to_id(rec->bind, rec->type); + struct InputAxis *axis = find_axis(&ctrl->binds, rec_id); if (axis == nullptr) continue; @@ -242,7 +182,7 @@ bool CtrlPoll(struct Controller *ctrl) ctrl->pending_buf.axes[i] = axis; } - ctrl->input_buf.len = 0; + ctrl->buf.len = 0; return true; } @@ -250,22 +190,32 @@ bool CtrlPoll(struct Controller *ctrl) int main() { struct Controller ctrl; - if (!NewCtrl(&ctrl, 3, 3)) + if (!NewCtrl(&ctrl, 3)) return 1; - CtrlMap(&ctrl, 123, 111, BUTTON); + CtrlMap(&ctrl, 123, BUTTON, 111); + CtrlMap(&ctrl, 0, BUTTON, 8); - ctrl.input_buf.records[ctrl.input_buf.len++] = (struct InputRecord) { + ctrl.buf.recs[ctrl.buf.len++] = (struct InputRecord) { .bind = 111, .type = BUTTON, .is_down = true, .but.value = 69 }; + ctrl.buf.recs[ctrl.buf.len++] = (struct InputRecord) { + .bind = 8, + .type = BUTTON, + .is_down = true, + .but.value = 1000 + }; CtrlPoll(&ctrl); - struct CtrlAxis *a = CtrlGet(&ctrl, 123, BUTTON); + struct InputAxis *a = CtrlGet(&ctrl, 123, BUTTON); printf("%u\n", a->but.value); + + struct InputAxis *b = CtrlGet(&ctrl, 0, BUTTON); + printf("%u\n", b->but.value); printf("success"); return 0; diff --git a/source/io/ctrl.h b/source/io/ctrl.h index 60d48c4..1661bfc 100644 --- a/source/io/ctrl.h +++ b/source/io/ctrl.h @@ -5,21 +5,14 @@ #include #include #include -#include -#include #include "fumotris.h" -#include "hash.h" +#include "gametime.h" #include "input.h" -struct CtrlAxis { - struct timespec last_pressed; - struct timespec last_released; - - u8 type; - u8 is_down; - u8 is_held; - u8 is_up; +struct InputAxis { + struct Time last_pressed; + struct Time last_released; union { struct Button but; @@ -27,40 +20,50 @@ struct CtrlAxis { struct Joystick js; union InputData data; }; + + union InputID id; + u8 is_down; + u8 is_held; + u8 is_up; }; -struct ctrl_dict { - size_t capacity; - size_t filled; +static struct ctrl_bkt { + union InputID id; + struct InputAxis *axis; +}; - struct ctrl_bkt { - hashtype hash; - u16 value; - u8 type; +static struct ctrl_dict { + struct ctrl_bkt *bkts; - struct CtrlAxis *axis; - } *bkts; + u16f capacity; + u16f filled; +}; + +static struct axis_vec { + struct InputAxis *axes; + + u16f size; + u16f len; }; struct Controller { + struct InputBuffer buf; + struct { + struct InputAxis *axes[IO_BUF_SIZE]; + u16f len; + } pending_buf; + + struct axis_vec axis_vec; struct ctrl_dict codes; struct ctrl_dict binds; - struct CtrlAxis *axes; - - struct InputBuffer input_buf; - - struct { - size_t len; - struct CtrlAxis *axes[IO_BUF_SIZE]; - } pending_buf; }; -bool NewCtrl(struct Controller *ctrl, size_t code_cap, size_t bind_cap); +bool NewCtrl(struct Controller *ctrl, size_t init_axes); void FreeCtrl(struct Controller *ctrl); -bool CtrlMap(struct Controller *ctrl, u16f code, u16f bind, u8f type); +bool CtrlMap(struct Controller *ctrl, u16f code, u16f type, u16f bind); -struct CtrlAxis *CtrlGet(struct Controller *ctrl, u16f code, u8f type); +struct InputAxis *CtrlGet(struct Controller *ctrl, u16f code, u16f type); bool CtrlPoll(struct Controller *ctrl); \ No newline at end of file diff --git a/source/io/input.c b/source/io/input.c index 63f0037..a5dd882 100644 --- a/source/io/input.c +++ b/source/io/input.c @@ -1,64 +1,11 @@ -#include +#include "input.h" #include -#include -#include -#include -#include -#include "fumotris.h" #include "platform.h" -#define IO_BUF_SIZE 16 - -enum InputType { - BUTTON, - AXIS, - JOYSTICK, - ESCAPE -}; - -struct Button { - u64 value; -}; -struct Axis { - i64 value; -}; -struct Joystick { - i32 x; - i32 y; -}; -union InputData { - struct Button input_but; - struct Axis input_axis; - struct Joystick input_js; -}; - -struct InputRecord { - u16f bind; - struct timespec timestamp; - - u8 type; - u8 is_down; - u8 is_held; - u8 is_up; - - union { - struct Button but; - struct Axis axis; - struct Joystick js; - union InputData data; - }; -}; - -struct InputBuffer { - size_t len; - size_t start; - struct InputRecord records[IO_BUF_SIZE]; -}; - struct InputRecord *in_buf_get(struct InputBuffer *buf, size_t i) { - return buf->records + (buf->start + 1) % IO_BUF_SIZE; + return buf->recs + (buf->start + 1) % IO_BUF_SIZE; } void InputBufferTransfer(struct InputBuffer *tmp, struct InputBuffer *dest) @@ -78,7 +25,7 @@ void InputBufferTransfer(struct InputBuffer *tmp, struct InputBuffer *dest) void InputBufferCopy(struct InputBuffer *buf, struct InputRecord *src) { - buf->records[(buf->start + buf->len) % IO_BUF_SIZE] = *src; + buf->recs[(buf->start + buf->len) % IO_BUF_SIZE] = *src; buf->len += 1; } diff --git a/source/io/input.h b/source/io/input.h index 5fb1397..cc6c417 100644 --- a/source/io/input.h +++ b/source/io/input.h @@ -6,6 +6,7 @@ #include #include "fumotris.h" +#include "gametime.h" #define IO_BUF_SIZE 16 @@ -16,6 +17,14 @@ enum InputType { ESCAPE }; +union InputID { + struct { + union { u16 code; u16 bind; u16 value }; + u16 type; + }; + u32 hash; +}; + struct Button { u64 value; }; @@ -33,13 +42,7 @@ union InputData { }; struct InputRecord { - u16f bind; - struct timespec timestamp; - - u8 type; - u8 is_down; - u8 is_held; - u8 is_up; + struct Time time; union { struct Button but; @@ -47,12 +50,19 @@ struct InputRecord { struct Joystick js; union InputData data; }; + + u16f bind; + + u8 type; + u8 is_down; + u8 is_held; + u8 is_up; }; struct InputBuffer { - size_t len; - size_t start; - struct InputRecord records[IO_BUF_SIZE]; + struct InputRecord recs[IO_BUF_SIZE]; + u8f len; + u8f start; }; void InputBufferTransfer(struct InputBuffer *tmp, struct InputBuffer *dest); diff --git a/source/main.c b/source/main.c index f6a6e09..0a0308d 100644 --- a/source/main.c +++ b/source/main.c @@ -114,7 +114,7 @@ void Loop(struct Instance *game) bool Start(struct Instance *game) { - if (!NewCtrl(&game->ctrl, code_count, code_count)) + if (!NewCtrl(&game->ctrl)) return false; for (size_t i = 0; i < code_count; i++) { @@ -144,7 +144,7 @@ int main() if(!PlatformInit()) exit(1); - InputStart(&game.ctrl.input_buf, ); + InputStart(&game.ctrl.buf, ); Loop(&game); return 0;