Mercurial > molko
annotate src/core/util.h @ 59:52792b863ff7
misc: separate core from game
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 21 Jan 2020 12:42:33 +0100 |
parents | src/util.h@f053a9f38c0e |
children | 80a913d25aa9 |
rev | line source |
---|---|
39
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 /* |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 * util.h -- utilities |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 * Permission to use, copy, modify, and/or distribute this software for any |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 * purpose with or without fee is hereby granted, provided that the above |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 * copyright notice and this permission notice appear in all copies. |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 */ |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
19 #ifndef MOLKO_UTIL_H |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 #define MOLKO_UTIL_H |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
21 |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 #include <stddef.h> |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
24 /** |
47
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
25 * Get the number of elements in a static array. |
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
26 * |
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
27 * \param x the array |
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
28 * \return the number of elements |
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
29 */ |
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
30 #define nelem(x) sizeof ((x)) / sizeof ((x)[0]) |
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
31 |
f053a9f38c0e
core: implement basic scrolling, closes #2459
David Demelier <markand@malikania.fr>
parents:
39
diff
changeset
|
32 /** |
39
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
33 * Wrapper around malloc(3) that exits on allocation failure. |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 * \param size the size |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 * \return a pointer |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 * \post returned pointer will never be NULL |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
38 */ |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
39 void * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
40 emalloc(size_t size); |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
41 |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
42 /** |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
43 * Wrapper around calloc(3) that exits on allocation failure. |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
44 * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 * \param n the number of objects to allocate |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
46 * \param size the size per n |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
47 * \return a pointer |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
48 * \post returned pointer will never be NULL |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
49 */ |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
50 void * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
51 ecalloc(size_t n, size_t size); |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
52 |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 /** |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
54 * Put the thread to sleep for a given amount of milliseconds. |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
55 * |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
56 * \param ms the number of milliseconds to wait |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
57 */ |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
58 void |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
59 delay(unsigned int ms); |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
60 |
9d1421c09dfb
core: add more utilities to improve code simplicity
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
61 #endif /* !MOLKO_UTIL_H */ |