blob: 787d19d20e2896ade09aa948ce6d2613086d69ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
Project & engine architecture
---------------------------
This document is a collection of vaguely related ideas surrounding how some of
the core functionality of the engine is designed.
## State Management [state.c](../src/state.c)


WIP
```
while((newstate = state_update(current_state)) != STATE_Exit) {
if (newstate != STATE_NULL) {
state = newstate;
state_free(current_state);
current_state = state_load(newstate);
} else {
// Input stuff
// Update stuff
// Render stuff
// Time stuff
}
}
```
## Input Handling [keypress.h](../src/keypress.h)
The input handling can be thought of as a stack of contexts. The method used in
the engine is further described in
["designing a robust input handling system for games"](https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/designing-a-robust-input-handling-system-for-games-r2975/)
We use a null-terminated statically allocated list of structs containing the
following:
* `struct Key`: Takes a `uint16 modifier` and a `uint32 key`
([SDL Keycode](https://wiki.libsdl.org/SDLKeycodeLookup))
* `uint32 time_pressed`: Time in ms since it was pressed.
* `void (*down_function)(void*)`: The function to be run upon key activation.
* `struct Funarg down_arg`: The argument for the function to be called. The argument is
automatically added a pointer to the current (game) context for each call.
* `void (*up_function)(void*)`: The function to be run upon key deactivation.
* `struct Funarg up_arg`: The argument for the function to be called.
Upon keypress,
```c
for (int i = 0; i < len(keys) && keys[i] != NULL; i++) {
if ( keys[i].function_down != NULL
&& keys[i].key.key == pressed_key
&& keys[i].key.modifier & current_mods == current_mods) {
time_pressed = now();
keys[i].function_down(funarg_up);
}
}
```
And basically the same goes for keyup, except, we dont check any modifier keys,
instead we check if `time_pressed > 0`
By using `time_pressed`, we can "charge" moves if needed be, and once released
we can measure how long the player held down the key.
It can be visualized by giving a pointer to a UI-part and setting it to visible,
and toggling said visibility again once the key is released.
## Rendering
### Window management
The plan is to spawn a new thread for each window.
### Tile rendering
When rendering tiles, we go by drawing walls on the floor tile, such that for
each floor tile we calculate the number of adjacent walls and fetch the
corresponding texture that match that combination of neighbouring walls.
|