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
|
#ifndef __GAME_MATRIX__
#define __GAME_MATRIX__
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "defs.h"
#include "DynamicArray.h"
/**
* A SMatrix is a 2d, square array.
*/
typedef struct _SMatrix SMatrix;
SMatrix *
s_matrix_new (size_t width, size_t height);
void
s_matrix_free (SMatrix * self, bool free_data);
/**
* Reallocate a SMatrix from one tuple width to an other.
*
* @note The new tupel size must be larger then the laset, or it will be
* tursicated.
*
* @note You need to free the old SMatrix yourself, this is to avoid memory
* leaks.
*/
SMatrix *
s_matrix_realloc (SMatrix * self, size_t width);
/**
* Get element y in tuple x.
*
* Equivilant to matrix[x][y] wolud be in static 2d arrays.
*/
spointer
s_matrix_get (SMatrix * self, size_t x, size_t y);
void
s_matrix_set (SMatrix * self, size_t x, size_t y, spointer data);
spointer *
s_matrix_get_tupel (SMatrix * self, size_t x);
void
s_matrix_append (SMatrix * self, spointer data);
SDynamicArray *
s_matrix_get_tupel_as_dynamic_array (SMatrix * self, size_t x);
/**
* This itterates over each tuple. giving the tuple as the item in the
* callback function.
*/
void
s_matrix_foreach (SMatrix * self, ForEachFunc callback, spointer data);
#endif /*__GAME_MATRIX__ */
|