diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index ae83481..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "configurations": [ - { - "name": "Win32", - "includePath": [ - "${workspaceFolder}/**", - "${workspaceFolder}/source/fumoengine/input" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "windowsSdkVersion": "10.0.22000.0", - "compilerPath": "C:/mingw64/bin/gcc.exe", - "cStandard": "c17", - "cppStandard": "c++17", - "intelliSenseMode": "windows-gcc-x64" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 94cdde1..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "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", - "gametime.h": "c", - "stdlib.h": "c", - "stdio.h": "c", - "platform.h": "c", - "ringbuffer.h": "c", - "fumoengine.h": "c", - "fumocommon.h": "c" - } -} \ No newline at end of file diff --git a/build.py b/build.py index 23b9c28..b509c0d 100644 --- a/build.py +++ b/build.py @@ -1,94 +1,139 @@ -import os, sys -import json, hashlib +import hashlib +import json +import subprocess +from pathlib import Path -def walk_source(path): - source_paths = [] - subdirs = [] - - for dirpath, dirnames, filenames in os.walk(path): - source_paths += [os.path.join(dirpath, f) for f in filenames if f.endswith(".c")] - subdirs.append(dirpath) - - return (source_paths, subdirs) +GCC = "gcc" +ARGS = "-fdiagnostics-color -pthread -Wall -std=c17 -pedantic" -def get_checksums(source_files): - checksums = {} - - for path in source_files: - with open(path, "rb") as source_file: - source = source_file.read() - - checksum = hashlib.md5(source).hexdigest() - checksums[path] = checksum - - return checksums +SOURCE_DIR = Path("source/") +OBJECT_DIR = Path("objects/") +OUTPUT = Path("debug") -def read_checksum_file(): - checksums = {} - - if not os.path.exists("checksums.txt"): - return checksums - - with open("checksums.txt", "rb") as checksum_file: - checksums = json.loads(checksum_file.read()) - - return checksums +CHECKSUMS = Path("checksums.txt") +ERRORS = Path("errors.txt") -def write_checksum_file(checksums): - with open("checksums.txt", "w+") as checksum_file: - checksum_file.write(json.dumps(checksums)) +def disk_scan_chksms(sources: list[Path]) -> list[str]: + chksms: list[str] = [] + + for source in sources: + with open(source, "rb") as file: + raw = file.read() + chksms.append(hashlib.md5(raw).hexdigest()) + + return chksms -def get_object_names(path): - object_names = [] +def disk_read_chksms(txt: Path) -> tuple[list[Path], list[str]]: + sources: list[Path] + chksms: list[str] - for file in os.listdir(path): - if os.path.isfile(os.path.join(path, file)): - name = os.path.splitext(os.path.basename(file))[0] + if not txt.exists(): + return ([], []) - object_names.append(name) + with open(txt, "rb") as file: + zipped: dict[str, str] = json.loads(file.read()) - return object_names + sources, chksms = [Path(key) for key in zipped.keys()], zipped.values() + + return (sources, chksms) -def build(source_path, obj_path, out_path, recompile = False): - source_paths, subdirs = walk_source(source_path) +def disk_write_chksms(txt: Path, sources: list[Path], chksms: list[str]) -> None: + zipped = {str(source): chksm for source, chksm in zip(sources, chksms)} - if recompile: - result = os.system(f"gcc {' '.join(source_paths)} -I {' -I '.join(subdirs)} -o {out_path} -pthread -Wall -std=c17 -pedantic") - print(result) - return + with open(txt, "w+") as file: + file.write(json.dumps(zipped)) - checksums_before = read_checksum_file() - checksums_now = get_checksums(source_paths) - - object_names = get_object_names(obj_path) - compile_list = [] - - for path in checksums_now: - name = os.path.splitext(os.path.basename(path))[0] - - if path not in checksums_before or checksums_before[path] != checksums_now[path] or name not in object_names: - compile_list.append(path) - - if name in object_names: - object_names.remove(name) - - for object_name in object_names: - os.remove(f"{obj_path}\\{object_name}.o") - - for path in compile_list: - name = os.path.splitext(os.path.basename(path))[0] - - os.system(f"gcc -c {path} -I {' -I '.join(subdirs)} -o {obj_path}\\{name}.o -pthread -Wall -std=c17 -pedantic") - - write_checksum_file(checksums_now) - print(os.system(f"gcc {obj_path}\\*.o -o {out_path} -pthread -Wall -std=c17 -pedantic -g")) +def filter_chksms(sources, chksms, old_chksms) -> list[Path]: + difs = set(chksms).difference(old_chksms) + return [sources[chksms.index(dif)] for dif in difs] -build(sys.argv[1], sys.argv[2], sys.argv[3], True) \ No newline at end of file +def scan_sources(source_dir: Path) -> tuple[list[Path], list[Path]]: + sources = [source for source in source_dir.rglob("*.c")] + chksms = disk_scan_chksms(sources) + + old_sources, old_chksms = disk_read_chksms(CHECKSUMS) + updated_sources = filter_chksms(sources, chksms, old_chksms) + + disk_write_chksms(CHECKSUMS, sources, chksms) + return (updated_sources, sources) + + +def clean_objects(object_dir: Path, sources: list[Path]) -> None: + objects: list[Path] = [object for object in object_dir.rglob("*.o")] + + object_stems = [object.stem for object in objects] + source_stems = [source.stem for source in sources] + + for stem in set(object_stems).difference(source_stems): + objects[object_stems.index(stem)].unlink() + + +def compile(source: Path, includes: list[Path], object_dir: Path): + include_arg: str = " ".join(f"-I {dir}" for dir in includes) + output: Path = object_dir / source.with_suffix(".o").name + + args = f"{GCC} -c {source} {ARGS} {include_arg} -o {output}" + + return subprocess.Popen(args, stderr=subprocess.PIPE) + + +def disk_read_errors(txt: Path) -> dict[str, str]: + if not txt.exists(): + return {} + + with open(txt, "rb") as file: + return json.loads(file.read()) + + +def disk_write_errors(txt: Path, errs: dict[str, str]): + with open(txt, "w+") as file: + file.write(json.dumps(errs)) + + +def wait_compile_tasks(tasks, updated_sources) -> dict[str, str]: + errors = disk_read_errors(ERRORS) + + for task, source in zip(tasks, updated_sources): + out, err = task.communicate() + if err: + errors[str(source)] = err.decode("utf-8") + else: + errors[str(source)] = False + + disk_write_errors(ERRORS, errors) + return errors + + +def link(object_dir: Path, output: Path) -> None: + subprocess.run(f"{GCC} -g {object_dir}/*.o {ARGS} -o {output}") + + +def build(source_dir: Path, object_dir: Path, output: Path): + updated_sources, all_sources = scan_sources(source_dir) + includes = [path for path in source_dir.rglob("*") if path.is_dir()] + + + tasks = [] + for source in updated_sources: + tasks.append(compile(source, includes, object_dir)) + + errors = wait_compile_tasks(tasks, updated_sources).values() + + print("\n".join(err for err in errors if err is not False).strip("\n")) + + + clean_objects(object_dir, all_sources) + link(object_dir, output) + print(f"Compiled: {len(updated_sources)} Linked: {len(all_sources)}") + + +if __name__ == "__main__": + build(SOURCE_DIR, OBJECT_DIR, OUTPUT) \ No newline at end of file diff --git a/checksums.txt b/checksums.txt index 49259eb..42d39ab 100644 --- a/checksums.txt +++ b/checksums.txt @@ -1 +1 @@ -{"source\\main.c": "82d4037af47edc6a1ef16f061e8980c2", "source\\game\\gametime.c": "40eedcb0dd0e0ebd42a09860aeb24517", "source\\game\\tetr.c": "fee38bad904b2053644fddf0ba08cd5e", "source\\io\\ctrl.c": "a838d22152710a4be156b5c90c41863c", "source\\io\\input.c": "aca98b0ac5983206b3fad774dc4d6146", "source\\io\\term.c": "b8fa47ec18810973c2123e7ec3a3cec6", "source\\io\\platforms\\win.c": "5f8d684bbaae885edf7505a1d90d91e8", "source\\io\\platforms\\winhandler.c": "b0c21fa0370350172987a3ec39be1d20"} \ No newline at end of file +{"source\\fumoengine\\fumocommon.c": "3253ec40842eaf2b65cca13826e35118", "source\\fumoengine\\fumoengine.c": "e6c26dc323b01d0b8c2e7e2f64833eb7", "source\\fumoengine\\include\\dictionary.c": "aa85678a01e035d45c9f59b6fe917beb", "source\\fumoengine\\include\\event.c": "71e6818ecf285293cf01c791f13c4d00", "source\\fumoengine\\include\\ringbuffer.c": "306556649cea951ef769cdfc5ae2b60d", "source\\fumoengine\\include\\vector.c": "67e0cf60c3a359e6e8c8eb46e01e8513", "source\\fumoengine\\input\\ctrl.c": "87dbff7e38fc406cbf309717e63665ed", "source\\fumoengine\\input\\input.c": "5a57ebd313fc2fc0246a95ce6641e5e8", "source\\fumoengine\\input\\platforms\\parseinput.c": "c1562355adcec7d0dcb0a81e8d7ffcca", "source\\fumoengine\\input\\platforms\\win.c": "2014fc5cdb4c8770f510a63db779f8bf", "source\\fumoengine\\terminal\\terminal.c": "c213e73df14b8d5ebcf5f25d221c3fe6", "source\\fumotris\\fumotris.c": "defad533a34d69352e728dbda3306a79", "source\\fumotris\\tetr.c": "09dcf3a7119ccabe0cb69c0a8fd688e9"} \ No newline at end of file diff --git a/debug.exe b/debug.exe new file mode 100644 index 0000000..15cf365 Binary files /dev/null and b/debug.exe differ diff --git a/errors.txt b/errors.txt new file mode 100644 index 0000000..57fad7c --- /dev/null +++ b/errors.txt @@ -0,0 +1 @@ +{"source\\fumoengine\\input\\platforms\\parseinput.c": false, "source\\fumoengine\\terminal\\terminal.c": false, "source\\fumoengine\\fumoengine.c": "In file included from \u001b[01m\u001b[Ksource\\fumoengine\\fumoengine.h:7\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumoengine\\fumoengine.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include/vector.h:25:2:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[K;\u001b[m\u001b[K' before '\u001b[01m\u001b[K_Bool\u001b[m\u001b[K'\n 25 | g\n | \u001b[01;31m\u001b[K^\u001b[m\u001b[K\n | \u001b[32m\u001b[K;\u001b[m\u001b[K\n", "source\\fumoengine\\include\\vector.c": "In file included from \u001b[01m\u001b[Ksource\\fumoengine\\include\\vector.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include\\vector.h:25:2:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[K;\u001b[m\u001b[K' before '\u001b[01m\u001b[K_Bool\u001b[m\u001b[K'\n 25 | g\n | \u001b[01;31m\u001b[K^\u001b[m\u001b[K\n | \u001b[32m\u001b[K;\u001b[m\u001b[K\n", "source\\fumoengine\\include\\event.c": false, "source\\fumoengine\\fumocommon.c": false, "source\\fumoengine\\include\\ringbuffer.c": false, "source\\fumoengine\\input\\platforms\\win.c": false, "source\\fumotris\\fumotris.c": "In file included from \u001b[01m\u001b[Ksource\\fumoengine/fumoengine.h:7\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.h:2\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include/vector.h:25:2:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[K;\u001b[m\u001b[K' before '\u001b[01m\u001b[K_Bool\u001b[m\u001b[K'\n 25 | g\n | \u001b[01;31m\u001b[K^\u001b[m\u001b[K\n | \u001b[32m\u001b[K;\u001b[m\u001b[K\n", "source\\fumotris\\tetr.c": false, "source\\fumoengine\\input\\input.c": false, "source\\fumoengine\\input\\ctrl.c": false, "source\\fumoengine\\include\\dictionary.c": false} \ No newline at end of file diff --git a/hi.exe b/hi.exe deleted file mode 100644 index c6fb070..0000000 Binary files a/hi.exe and /dev/null differ diff --git a/objects/ctrl.o b/objects/ctrl.o index e4e2a9f..c6b2f3d 100644 Binary files a/objects/ctrl.o and b/objects/ctrl.o differ diff --git a/objects/dictionary.o b/objects/dictionary.o new file mode 100644 index 0000000..d97e0b0 Binary files /dev/null and b/objects/dictionary.o differ diff --git a/objects/event.o b/objects/event.o new file mode 100644 index 0000000..888b9b6 Binary files /dev/null and b/objects/event.o differ diff --git a/objects/fumocommon.o b/objects/fumocommon.o new file mode 100644 index 0000000..d921a20 Binary files /dev/null and b/objects/fumocommon.o differ diff --git a/objects/fumoengine.o b/objects/fumoengine.o new file mode 100644 index 0000000..068ab69 Binary files /dev/null and b/objects/fumoengine.o differ diff --git a/objects/fumotris.o b/objects/fumotris.o new file mode 100644 index 0000000..96eb26b Binary files /dev/null and b/objects/fumotris.o differ diff --git a/objects/gametime.o b/objects/gametime.o deleted file mode 100644 index 82eb46f..0000000 Binary files a/objects/gametime.o and /dev/null differ diff --git a/objects/input.o b/objects/input.o index cc31114..8412b22 100644 Binary files a/objects/input.o and b/objects/input.o differ diff --git a/objects/main.o b/objects/main.o deleted file mode 100644 index e580177..0000000 Binary files a/objects/main.o and /dev/null differ diff --git a/objects/parseinput.o b/objects/parseinput.o new file mode 100644 index 0000000..e9bae1f Binary files /dev/null and b/objects/parseinput.o differ diff --git a/objects/ringbuffer.o b/objects/ringbuffer.o new file mode 100644 index 0000000..4c928c2 Binary files /dev/null and b/objects/ringbuffer.o differ diff --git a/objects/term.o b/objects/term.o deleted file mode 100644 index 5c22ee1..0000000 Binary files a/objects/term.o and /dev/null differ diff --git a/objects/terminal.o b/objects/terminal.o new file mode 100644 index 0000000..6d644b5 Binary files /dev/null and b/objects/terminal.o differ diff --git a/objects/tetr.o b/objects/tetr.o index a47f702..8551cfb 100644 Binary files a/objects/tetr.o and b/objects/tetr.o differ diff --git a/objects/vector.o b/objects/vector.o new file mode 100644 index 0000000..afd86cd Binary files /dev/null and b/objects/vector.o differ diff --git a/objects/win.o b/objects/win.o index 0490208..95b8845 100644 Binary files a/objects/win.o and b/objects/win.o differ diff --git a/objects/winhandler.o b/objects/winhandler.o deleted file mode 100644 index 0fb62c5..0000000 Binary files a/objects/winhandler.o and /dev/null differ diff --git a/silly.exe b/silly.exe deleted file mode 100644 index a02981f..0000000 Binary files a/silly.exe and /dev/null differ diff --git a/source/fumoengine/input/ctrl.c b/source/fumoengine/input/ctrl.c index b7f994a..deba581 100644 --- a/source/fumoengine/input/ctrl.c +++ b/source/fumoengine/input/ctrl.c @@ -32,44 +32,36 @@ void FreeController(struct Controller *ctrl) FreeDictionary(&ctrl->binds); } -u32 hash_bind(u16f bind, u16f type) +u32 hash_bind(u16f code, u16f type) { - return bind + (type << 16); + return code | (type << 16); } -struct InputAxis *ControllerMap( - struct Controller *ctrl, - struct ControlMapping *map -) { - struct InputAxis *axis = &ctrl->axes[map->code]; +bool ControllerBind(struct Controller *ctrl, u16 control, u16 code, u16 type) +{ + u32 hash = hash_bind(code, type); - u32 hash = hash_bind(map->bind, map->type); + struct InputAxis *axis = &ctrl->axes[control]; struct InputAxis **bind = DictionarySet(BIND_T, &ctrl->binds, hash, axis); - if (bind == nullptr) { - printf("whar"); - exit(1); - } + if (bind == nullptr) + return false; *bind = axis; - axis->type = map->type; - return axis; + return true; } -bool ControllerMapMulti( +bool ControllerBindMulti( struct Controller *ctrl, usize n, - struct ControlMapping *maps, - struct InputAxis **binds + u16 *controls, + u16 *codes, + u16 *types ) { for (usize i = 0; i < n; i++) { - struct InputAxis *axis = ControllerMap(ctrl, maps + i); - - if (axis == nullptr) + if (!ControllerBind(ctrl, controls[i], codes[i], types[i])) return false; - - binds[i] = axis; } return true; @@ -81,7 +73,7 @@ void dispatch_update(struct InputAxis *axis, struct InputRecord *rec) axis->is_down = true; axis->is_held = true; axis->last_pressed = rec->time; - } else if (rec->is_up) { + } else { axis->is_up = true; axis->is_held = false; axis->last_released = rec->time; @@ -104,7 +96,7 @@ void ControllerPoll(struct Controller *ctrl, struct RecordBuffer *recs) for (usize i = 0; i < recs->head.len; i++) { struct InputRecord *rec = recs->buf + i; - u32 hash = hash_bind(rec->bind, rec->type); + u32 hash = hash_bind(rec->code, rec->type); struct InputAxis *axis = DictionaryFind(BIND_T, &ctrl->binds, hash); if (axis == nullptr) diff --git a/source/fumoengine/input/ctrl.h b/source/fumoengine/input/ctrl.h index 24030c9..fce02e0 100644 --- a/source/fumoengine/input/ctrl.h +++ b/source/fumoengine/input/ctrl.h @@ -4,30 +4,6 @@ #include "input.h" -struct ControlMapping { - u16 code; - u16 bind; - u16 type; -}; - -struct InputAxis { - nsec last_pressed; - nsec last_released; - - union { - struct Button but; - struct Axis axis; - struct Joystick js; - union InputData data; - }; - - u16 type; - - bool is_down; - bool is_held; - bool is_up; -}; - struct Controller { struct InputAxis *pending[IO_BUF_SIZE]; usize pending_len; @@ -43,16 +19,14 @@ bool CreateController(struct Controller *ctrl); void FreeController(struct Controller *ctrl); -struct InputAxis *ControllerMap( - struct Controller *ctrl, - struct ControlMapping *map -); +bool ControllerBind(struct Controller *ctrl, u16 control, u16 code, u16 type); -bool ControllerMapMulti( +bool ControllerBindMulti( struct Controller *ctrl, usize n, - struct ControlMapping *maps, - struct InputAxis **axis_ptrs + u16 *controls, + u16 *codes, + u16 *types ); void ControllerPoll(struct Controller *ctrl, struct RecordBuffer *recs); diff --git a/source/fumoengine/input/input.h b/source/fumoengine/input/input.h index ae4e158..e7f91ce 100644 --- a/source/fumoengine/input/input.h +++ b/source/fumoengine/input/input.h @@ -33,24 +33,30 @@ struct Joystick { }; union InputData { - struct Button input_but; - struct Axis input_axis; - struct Joystick input_js; + struct Button but; + struct Axis axis; + struct Joystick js; }; struct InputRecord { nsec time; - union { - struct Button but; - struct Axis axis; - struct Joystick js; - union InputData data; - }; + union InputData data; - u16 bind; + u16 code; u16 type; + bool is_down; +}; + +struct InputAxis { + nsec last_pressed; + nsec last_released; + + union InputData data; + + u16 type; + bool is_down; bool is_held; bool is_up; diff --git a/source/fumoengine/input/platforms/parseinput.c b/source/fumoengine/input/platforms/parseinput.c index b92717e..d6e6bb8 100644 --- a/source/fumoengine/input/platforms/parseinput.c +++ b/source/fumoengine/input/platforms/parseinput.c @@ -1,30 +1,29 @@ #include "parseinput.h" -void ReadButton(struct InputRecord *rec, u16f bind, bool is_down) +void ReadButton(struct InputRecord *rec, u16f code, bool is_down) { - rec->bind = bind; + rec->code = code; rec->type = BUTTON; rec->is_down = is_down; - rec->is_up = !is_down; } -void ReadAxis(struct InputRecord *rec, u16f bind, u64 value) +void ReadAxis(struct InputRecord *rec, u16f code, u64 value) { - rec->bind = bind; + rec->code = code; rec->type = AXIS; - rec->axis.value = value; + rec->data.axis.value = value; } -void ReadJoystick(struct InputRecord *rec, u16f bind, i32 x, i32 y) +void ReadJoystick(struct InputRecord *rec, u16f code, i32 x, i32 y) { - rec->bind = bind; + rec->code = code; rec->type = JOYSTICK; - rec->js.x = x; - rec->js.y = y; + rec->data.js.x = x; + rec->data.js.y = y; } size_t UCS2ToUTF8(char *buf, u16f ucs2) @@ -40,8 +39,10 @@ size_t UCS2ToUTF8(char *buf, u16f ucs2) return 2; } - buf[0] = 0xE0 + (ucs2 >> 12); - buf[1] = 0x80 + ((ucs2 >> 6) & 0x3F); - buf[2] = 0x80 + (ucs2 & 0x3F); - return 3; + else { + buf[0] = 0xE0 + (ucs2 >> 12); + buf[1] = 0x80 + ((ucs2 >> 6) & 0x3F); + buf[2] = 0x80 + (ucs2 & 0x3F); + return 3; + } } \ No newline at end of file diff --git a/source/fumotris/fumotris.c b/source/fumotris/fumotris.c index 155efd1..ef7cfcc 100644 --- a/source/fumotris/fumotris.c +++ b/source/fumotris/fumotris.c @@ -2,9 +2,6 @@ struct Fumotris { - struct ControlMapping mappings[BINDS_N]; - struct InputAxis *input[BINDS_N]; - struct TetrMap board; struct TetrMap piece; }; @@ -15,7 +12,7 @@ void FumotrisStart(void *inst_arg, void *game_arg) struct FumoInstance *inst = inst_arg; struct Fumotris *game = game_arg; - ControllerMapMulti(&inst->ctrl, BINDS_N, game->mappings, game->input); + ControllerBindMulti(&inst->ctrl, BINDS_N, controls_g, codes_g, types_g); CreateTetrMap(&game->board, 10, 10); CreateTetrMap(&game->piece, 3, 3); @@ -27,9 +24,10 @@ void FumotrisUpdate(void *inst_arg, void *game_arg) struct FumoInstance *inst = inst_arg; struct Fumotris *game = game_arg; - if (game->input[LEFT]->is_down) + if (inst->ctrl.axes[LEFT].is_down) game->piece.x -= 1; - if (game->input[RIGHT]->is_down) + + if (inst->ctrl.axes[RIGHT].is_down) game->piece.x += 1; TetrMapDraw(&game->board, &inst->term); diff --git a/source/fumotris/fumotris.h b/source/fumotris/fumotris.h index 27cdfaa..de2d6f8 100644 --- a/source/fumotris/fumotris.h +++ b/source/fumotris/fumotris.h @@ -5,7 +5,7 @@ #define BINDS_N 12 -enum FumotrisCode { +enum FumotrisControls { LEFT, RIGHT, SOFT_DROP, @@ -15,64 +15,102 @@ enum FumotrisCode { ROTATE_180, SWAP, ESC, + VSCROLL, HSCROLL, + MOUSE }; -struct ControlMapping mappings_global[BINDS_N] = { - { LEFT, 0x25, BUTTON }, - { RIGHT, 0x27, BUTTON }, - { SOFT_DROP, 0x28, BUTTON }, - { HARD_DROP, 0x20, BUTTON }, - { ROTATE_CCW, 'Z', BUTTON }, - { ROTATE_CW, 'X', BUTTON }, - { ROTATE_180, 'A', BUTTON }, - { SWAP, 'C', BUTTON }, - { ESC, 0x1B, BUTTON }, - { VSCROLL, 0, AXIS }, - { HSCROLL, 1, AXIS }, - { MOUSE, 0, JOYSTICK } +u16 controls_g[BINDS_N] = { + LEFT, + RIGHT, + SOFT_DROP, + HARD_DROP, + ROTATE_CCW, + ROTATE_CW, + ROTATE_180, + SWAP, + ESC, + + VSCROLL, + HSCROLL, + + MOUSE, }; -const u8 I[16] = { +u16 codes_g[BINDS_N] = { + 0x25, + 0x27, + 0x28, + 0x20, + 'Z', + 'X', + 'A', + 'C', + 0x1B, + + 0, + 1, + + 0 +}; + +u16 types_g[BINDS_N] = { + BUTTON, + BUTTON, + BUTTON, + BUTTON, + BUTTON, + BUTTON, + BUTTON, + BUTTON, + BUTTON, + + AXIS, + AXIS, + + JOYSTICK +}; + +u8 I[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }; -const u8 O[4] = { +u8 O[4] = { 1, 1, 1, 1 }; -const u8 T[9] = { +u8 T[9] = { 0, 1, 0, 1, 1, 1, 0, 0, 0 }; -const u8 S[9] = { +u8 S[9] = { 0, 1, 1, 1, 1, 0, 0, 0, 0 }; -const u8 Z[9] = { +u8 Z[9] = { 1, 1, 0, 0, 1, 1, 0, 0, 0 }; -const u8 J[9] = { +u8 J[9] = { 1, 0, 0, 1, 1, 1, 0, 0, 0 }; -const u8 L[9] = { +u8 L[9] = { 0, 0, 1, 1, 1, 1, 0, 0, 0 diff --git a/test.exe b/test.exe deleted file mode 100644 index 4ff9e84..0000000 Binary files a/test.exe and /dev/null differ