From f8c0dc54e36cc201c657aa12e5a22029b092e1bc Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Mon, 13 Jul 2026 21:58:18 +0530 Subject: restructed all the files + uci done now also broke the symbol analyser in the process, i didn't help much, i had to pull out the pen & paper, but it made a cool graph never the less multithreading was a pain! but it got it in the end fixed the structs naming convention, if it's used outside by other files, it's typedeffed, otherwise it's not fixed the recursive imports issued i had in go_args*, where i was casting it to void* in uci to make it work now response.c doesn't deal with ipc, really happy with that change now every single thing has its own responsibility --- src/ipc/state.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/ipc/state.c (limited to 'src/ipc/state.c') diff --git a/src/ipc/state.c b/src/ipc/state.c new file mode 100644 index 0000000..02ba38b --- /dev/null +++ b/src/ipc/state.c @@ -0,0 +1,41 @@ +#include +#include + +#define IPC_INTERNAL +#include "ipc/state.h" + +void ipc_state_init(ipc_state_t *state) { + // done by main.c in the loop + // engine_messages_init(&state->engine_messages); + uci_state_init(&state->uci_state); + state->from_position = (position_t) {0}; + ipc_moves_init(&state->moves); + state->uci_state.moves = &state->moves; + atomic_init(&state->event, EVENT_INIT); +} + +void ipc_state_deinit(ipc_state_t *state) { + engine_messages_deinit(&state->engine_messages); + uci_state_deinit(&state->uci_state); + ipc_moves_deinit(&state->moves); +} + +void ipc_state_game_reset(ipc_state_t *state) { + state->from_position = (position_t) {0}; + state->moves.count = 0; +} + +void ipc_state_wait_for_event(ipc_state_t *state, size_t event) { + assert(event < EVENTS_COUNT); + while (!ipc_state_is_event(state, event)); +} + +bool ipc_state_is_event(ipc_state_t *state, size_t event) { + assert(event < EVENTS_COUNT); + return atomic_load(&state->event) == event; +} + +void ipc_state_set_event(ipc_state_t *state, size_t event) { + assert(event < EVENTS_COUNT); + atomic_store(&state->event, event); +} -- cgit v1.2.3