summaryrefslogtreecommitdiff
path: root/README.md
blob: 7aaed7d3d9a969ffa3b985bdc8e64f683e05ec51 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# KONENGINE
## KonAki's Small C99 Game Engine

![License](https://img.shields.io/badge/license-MIT-blue)
![Language](https://img.shields.io/badge/language-C99-orange)

## About

This is my game engine. It's built out of my own small libraries, and it's meant to be for game jams and videos. Things like doom-likes, RTS games, rpgmaker-style games, visual novels, metroidvanias and the weird indie stuff that messes with the window itself.

It's made so that you call it, not the other way around. There is no framework that owns your main loop unless you want one. If you do want one, [konprogram](kon/konprogram.h) opens the window, runs the loop and cleans up, and you hand it a few callbacks.

Everything is written in [c99](https://en.wikipedia.org/wiki/C99) and drawn by a software renderer, so no gpu is needed.

### What's in it

The reusable stuff is single-header and lives in [kon](kon). Those are the ones you can drag into any project:

- konwinlib: windows and input events
- konsofren: the software renderer, 2D and 3D
- konmath: vectors, matrices
- konfont: text, built-in bitmap font or a ttf
- kontime: timing and sleeping
- kontoml: a very minimal toml parser
- koninput: input state on top of konwinlib

The engine modules are a `.h` and a `.c` pair, they depend on each other a bit, and you pick which ones to build:

| module | what it does |
| --- | --- |
| font | konfont |
| toml | kontoml |
| tile | tilemaps and sprite sheets |
| 3d | first person kit: mouse look body, walls from a tilemap, editable hill terrain (adds tile) |
| sector | maps made of rooms (vertices, floors, ceilings, walls) with entities like doors and buttons, in a text format |
| world | one place to move bodies through sector maps, terrain, tilemaps and your own boxes, cylinders, spheres and planes (needs 3d, sector) |
| pack | encrypted asset packs |
| assets | named asset cache with reference counts, loose files or a pack |
| image | stb_image so assets can load pngs |
| audio | sound playing, looping, pitch, buses, fades, positional sound, music crossfades |
| mic | microphone level, talking detection, last few seconds as a sound |
| model | glTF models and animation, converted to my own `.kmdl` format |
| ui | immediate mode ui |
| debug | developer console and asset view |

### Supported Platforms:

- linux
- bsd
- windows (cross compiled with mingw, not tested much yet)
- web (planned)

## Usage

Use the build script from the project root. Pick the modules you want:

```sh
./build.sh -m font,assets,image,audio
```

yes, it's just that. If a module needs another one it adds it for you, so `debug` pulls in `font` and `assets`.

<details>
<summary>All the build options</summary>

```
./build.sh [-d] [-D] [-p platform] [-m module,...] [-o objdir] [target ...]
```

- `-d` is a debug build. It also turns on the developer build.
- `-D` is the developer build without debug. This lets loose files override the pack and turns on the developer-only stuff like the console.
- `-p` is `linux`, `bsd` or `windows`. It finds your own if you leave it out.
- `-m` is the list of modules from the table above.
- `-o` is where the objects go, `obj` by default.

targets are `all`, `run`, `clean`, `tools`, `pack` and `examples`.

</details>

If you'd rather use make directly, the [Makefile](Makefile) is a normal one. The script just sets the flags and calls it. It was made to stay as POSIX as I can.

### Your own program

The shortest way to a window is konprogram:

```c
#include "konprogram.h"

static void draw(kon_program_t *program, kon_framebuffer_t *game, void *user) {
	kon_clearFramebuffer(game, 0xFF1B1826);
}

int main(void) {
	kon_programConfig_t config = {0};

	config.title = "hello";
	config.draw = draw;
	return kon_programRun(&config);
}
```

Every field of the config can be left at 0 and every callback is optional. The game is drawn at a small resolution and scaled to the window.

### Developer build

With `-d` or `-D` the console opens with the grave key. It knows window commands, your own commands and variables, and it shows what assets are loaded. Without those flags the console is not built at all.

Loose files in the `assets` folder override the ones in the pack only in the developer build.

## Tools

`./build.sh tools` builds these into the object directory.

- konpack: puts a folder into an encrypted `.kpk` pack
- konmodel: converts a glTF/glb into a `.kmdl` model

```sh
obj/konmodel art/models/Fox.glb assets/models/fox.kmdl -t models/
```

## Examples

The examples are their own little programs, in the [examples](examples) folder. Each one says how to build it at the top of the file.

- [modelview.c](examples/modelview.c) shows a model and plays and blends its animations
- [sound.c](examples/sound.c) is an audio and mic playground, everything is made in code so no files needed
- [ui.c](examples/ui.c) is a character card maker made with the ui module

```sh
./build.sh -d -m audio,mic,debug obj/sound
obj/sound
```

## Third party

I use stb_image, stb_truetype, miniaudio and cgltf. The example model is the Fox from the Khronos sample models. All the credits and licenses are in [THIRD_PARTY.md](THIRD_PARTY.md).

## License - [MIT License](LICENSE)