2State :: struct {
3 id: Mode;
4 camera: Camera2D;
5}
8state_init :: (current_mode: Mode, st: ..State) {
9 for st array_add(*states, it);
10 current = state_find(current_mode);
11}
13state_switch :: (state_id: Mode) {
14 idx := state_find(state_id);
15 new_state := *states[idx];
16 old_state := *states[current];
18 old_state.camera = camera;
19 camera = new_state.camera;
21 current = idx;
22}
25#scope_file
28states: [..]State;
29current: int;
32state_find :: (id: Mode) -> idx: int {
33 ok, idx := array_find(states, { id, {} }, find_by_id);
34 assert(ok, "Should not happen @ state_find");
35 return idx;
36}
38find_by_id :: (a: State, b: State) -> bool {
39 return a.id == b.id;
40}
index : binary-tree
---