aa
aa
This commit is contained in:
parent
7c58e46fc4
commit
41f57d5ba8
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -59,5 +59,6 @@
|
|||
"ringbuffer.h": "c",
|
||||
"fumoengine.h": "c",
|
||||
"fumocommon.h": "c"
|
||||
}
|
||||
},
|
||||
"cmake.configureOnOpen": false
|
||||
}
|
37
.vscode/tasks.json
vendored
Normal file
37
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: gcc.exe build active file",
|
||||
"command": "C:/mingw64/bin/gcc.exe",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}\\${fileBasenameNoExtension}.exe"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "C:/mingw64/bin"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "Fumo build script",
|
||||
"command": "python build.py",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
17
build.py
17
build.py
|
@ -1,9 +1,12 @@
|
|||
import os, sys
|
||||
import json, hashlib
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def walk_source(path):
|
||||
source_paths = []
|
||||
def walk_source_dir(path: str) -> tuple[list[str], list[str]]:
|
||||
source_paths : list[str] = []
|
||||
subdirs = []
|
||||
|
||||
for dirpath, dirnames, filenames in os.walk(path):
|
||||
|
@ -55,8 +58,8 @@ def get_object_names(path):
|
|||
return object_names
|
||||
|
||||
|
||||
def build(source_path, obj_path, out_path, recompile = False):
|
||||
source_paths, subdirs = walk_source(source_path)
|
||||
def build(source_path, obj_path, out_path, recompile):
|
||||
source_paths, subdirs = walk_source_dir(source_path)
|
||||
|
||||
if recompile:
|
||||
result = os.system(f"gcc {' '.join(source_paths)} -I {' -I '.join(subdirs)} -o {out_path} -pthread -Wall -std=c17 -pedantic")
|
||||
|
@ -91,4 +94,4 @@ def build(source_path, obj_path, out_path, recompile = False):
|
|||
print(os.system(f"gcc {obj_path}\\*.o -o {out_path} -pthread -Wall -std=c17 -pedantic -g"))
|
||||
|
||||
|
||||
build(sys.argv[1], sys.argv[2], sys.argv[3], True)
|
||||
build("source/", "objects/", "debug", True)
|
|
@ -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);
|
||||
}
|
||||
|
||||
*bind = axis;
|
||||
axis->type = map->type;
|
||||
|
||||
return axis;
|
||||
}
|
||||
|
||||
bool ControllerMapMulti(
|
||||
struct Controller *ctrl,
|
||||
usize n,
|
||||
struct ControlMapping *maps,
|
||||
struct InputAxis **binds
|
||||
) {
|
||||
for (usize i = 0; i < n; i++) {
|
||||
struct InputAxis *axis = ControllerMap(ctrl, maps + i);
|
||||
|
||||
if (axis == nullptr)
|
||||
if (bind == nullptr)
|
||||
return false;
|
||||
|
||||
binds[i] = axis;
|
||||
*bind = axis;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ControllerBindMulti(
|
||||
struct Controller *ctrl,
|
||||
usize n,
|
||||
u16 *controls,
|
||||
u16 *codes,
|
||||
u16 *types
|
||||
) {
|
||||
for (usize i = 0; i < n; i++) {
|
||||
if (!ControllerBind(ctrl, controls[i], codes[i], types[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -33,22 +33,28 @@ 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;
|
||||
};
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
else {
|
||||
buf[0] = 0xE0 + (ucs2 >> 12);
|
||||
buf[1] = 0x80 + ((ucs2 >> 6) & 0x3F);
|
||||
buf[2] = 0x80 + (ucs2 & 0x3F);
|
||||
return 3;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue