Revision 316
documented list and queue
proj/libs/classes/include/list.h | ||
---|---|---|
2 | 2 |
#define LIST_H_INCLUDED |
3 | 3 |
|
4 | 4 |
struct list_node; |
5 |
/** |
|
6 |
* @brief List node. |
|
7 |
* |
|
8 |
* Can be used like a C++ std::list iterator. |
|
9 |
* A list node stores a void* to allow for more flexibility. |
|
10 |
*/ |
|
5 | 11 |
typedef struct list_node list_node_t; |
6 | 12 |
|
13 |
/** |
|
14 |
* @brief Construct list node. |
|
15 |
* @param p Pointer to previous list node |
|
16 |
* @param n Pointer to next list node |
|
17 |
* @param val Value to be stored in the list node |
|
18 |
* @return Pointer to created list node |
|
19 |
*/ |
|
7 | 20 |
list_node_t* (list_node_ctor)(list_node_t *p, list_node_t *n, void *val); |
21 |
/** |
|
22 |
* @brief Destruct list node. |
|
23 |
* @param p Pointer to list node to be destroyed |
|
24 |
*/ |
|
8 | 25 |
void (list_node_dtor)(list_node_t *p); |
26 |
/** |
|
27 |
* @brief Get next node. |
|
28 |
* @param p Pointer to list node |
|
29 |
* @return Pointer to next list node |
|
30 |
*/ |
|
9 | 31 |
list_node_t* (list_node_next)(const list_node_t *p); |
32 |
/** |
|
33 |
* @brief Get previous node. |
|
34 |
* @param p Pointer to list node |
|
35 |
* @return Pointer to previous list node |
|
36 |
*/ |
|
10 | 37 |
list_node_t* (list_node_prev)(const list_node_t *p); |
38 |
/** |
|
39 |
* @brief Get value stored in the node. |
|
40 |
* @param p Pointer to list node |
|
41 |
* @return Pointer to the stored value (which is in turn a void*). |
|
42 |
*/ |
|
11 | 43 |
void** (list_node_val )(list_node_t *p); |
12 | 44 |
|
13 | 45 |
struct list; |
46 |
/** |
|
47 |
* @brief List. |
|
48 |
* |
|
49 |
* Can be used like a C++ std::list. |
|
50 |
* A list_t is a sequence of list_node_t nodes, that store void* to allow for more flexibility. |
|
51 |
*/ |
|
14 | 52 |
typedef struct list list_t; |
15 | 53 |
|
16 |
list_t* (list_ctor)(void); |
|
17 |
int (list_dtor)(list_t *l); |
|
18 |
list_node_t* (list_begin )(list_t *l); |
|
19 |
list_node_t* (list_end )(list_t *l); |
|
20 |
size_t (list_size )(const list_t *l); |
|
21 |
int (list_empty )(const list_t *l); |
|
22 |
list_node_t* (list_insert)(list_t *l, list_node_t *position, void *val); |
|
23 |
void* (list_erase )(list_t *l, list_node_t *position); |
|
54 |
/** |
|
55 |
* @brief Construct empty list. |
|
56 |
* @return Pointer to created list |
|
57 |
*/ |
|
58 |
list_t* (list_ctor) (void); |
|
59 |
/** |
|
60 |
* @brief Destruct list. |
|
61 |
* |
|
62 |
* A list can only be destroyed once it is empty. |
|
63 |
* This is because a list stores void*, whose memory most likely need to be free'd. |
|
64 |
* @param l Pointer to list to be destroyed |
|
65 |
* @return SUCCESS if the destruction was successful, other value otherwise. |
|
66 |
*/ |
|
67 |
int (list_dtor) (list_t *l); |
|
68 |
/** |
|
69 |
* @brief Get pointer to the first node of the list. |
|
70 |
* @param l Pointer to list |
|
71 |
* @return Pointer to first node of the list. |
|
72 |
*/ |
|
73 |
list_node_t* (list_begin) (list_t *l); |
|
74 |
/** |
|
75 |
* @brief Get pointer to the past-the-end node of the list. |
|
76 |
* @param l Pointer to list |
|
77 |
* @return Pointer to past-the-end node of the list |
|
78 |
*/ |
|
79 |
list_node_t* (list_end) (list_t *l); |
|
80 |
/** |
|
81 |
* @brief Get size of the list. |
|
82 |
* @param l Pointer to list |
|
83 |
* @return Size of the list |
|
84 |
*/ |
|
85 |
size_t (list_size) (const list_t *l); |
|
86 |
/** |
|
87 |
* @brief Know if list is empty or not. |
|
88 |
* @param l Pointer to list |
|
89 |
* @return true if the list is empty (size is zero), false otherwise |
|
90 |
*/ |
|
91 |
int (list_empty) (const list_t *l); |
|
92 |
/** |
|
93 |
* @brief Insert value in list. |
|
94 |
* @param l Pointer to list |
|
95 |
* @param position Pointer to node, before which the new value will be inserted |
|
96 |
* @param val Value to be inserted before position |
|
97 |
* @return Pointer to newly-created node |
|
98 |
*/ |
|
99 |
list_node_t* (list_insert) (list_t *l, list_node_t *position, void *val); |
|
100 |
/** |
|
101 |
* @brief Erase value in list. |
|
102 |
* @param l Pointer to list |
|
103 |
* @param position Node to be deleted |
|
104 |
* @return Value contained in the deleted node, which must be free'd if appropriate |
|
105 |
*/ |
|
106 |
void* (list_erase) (list_t *l, list_node_t *position); |
|
107 |
/** |
|
108 |
* @brief Insert new value at the end of the list. |
|
109 |
* @param l Pointer to list |
|
110 |
* @param val Value to be inserted |
|
111 |
*/ |
|
24 | 112 |
void (list_push_back)(list_t *l, void *val); |
25 |
void** (list_front)(list_t *l); |
|
113 |
/** |
|
114 |
* @brief Get first element of the list. |
|
115 |
* @param l Pointer to list |
|
116 |
* @return Pointer to value at the beginning of the list |
|
117 |
*/ |
|
118 |
void** (list_front) (list_t *l); |
|
119 |
/** |
|
120 |
* @brief Erase first element of the list. |
|
121 |
* @param l Pointer to list |
|
122 |
*/ |
|
26 | 123 |
void (list_pop_front)(list_t *l); |
27 |
list_node_t* (list_find)(list_t *l, void *val); |
|
124 |
/** |
|
125 |
* @brief Find value in list. |
|
126 |
* |
|
127 |
* Values are found by direct comparison of void* |
|
128 |
* @param l Pointer to list |
|
129 |
* @param val Pointer to value to be found in the list |
|
130 |
* @return Node whose value compares equal to val, or past-the-end node if not found |
|
131 |
*/ |
|
132 |
list_node_t* (list_find) (list_t *l, void *val); |
|
28 | 133 |
|
29 | 134 |
#endif //LIST_H_INCLUDED |
proj/libs/classes/include/queue.h | ||
---|---|---|
2 | 2 |
#define QUEUE_H_INCLUDED |
3 | 3 |
|
4 | 4 |
struct queue; |
5 |
/** |
|
6 |
* @brief Queue. |
|
7 |
* |
|
8 |
* Can be used like a C++ std::queue. |
|
9 |
* A queue_t is an interface for a list_t that simulates a FIFO. |
|
10 |
*/ |
|
5 | 11 |
typedef struct queue queue_t; |
6 | 12 |
|
7 |
const size_t queue_max_size; |
|
8 |
|
|
13 |
/** |
|
14 |
* @brief Construct empty queue. |
|
15 |
* @return Pointer to created queue |
|
16 |
*/ |
|
9 | 17 |
queue_t* (queue_ctor )(void); |
18 |
/** |
|
19 |
* @brief Destruct queue. |
|
20 |
* |
|
21 |
* A queue can only be destroyed once it is empty. |
|
22 |
* This is because a queue stores void*, whose memory most likely need to be free'd. |
|
23 |
* @param q Pointer to queue to be destroyed |
|
24 |
* @return SUCCESS if the destruction was successful, other value otherwise. |
|
25 |
*/ |
|
10 | 26 |
int (queue_dtor )(queue_t *q); |
27 |
/** |
|
28 |
* @brief Get size of the queue. |
|
29 |
* @param q Pointer to queue |
|
30 |
* @return Size of the queue |
|
31 |
*/ |
|
11 | 32 |
size_t (queue_size )(const queue_t *q); |
33 |
/** |
|
34 |
* @brief Know if queue is empty or not. |
|
35 |
* @param q Pointer to queue |
|
36 |
* @return true if the queue is empty (size is zero), false otherwise |
|
37 |
*/ |
|
12 | 38 |
int (queue_empty)(const queue_t *q); |
39 |
/** |
|
40 |
* @brief Insert new value in the queue. |
|
41 |
* @param q Pointer to queue |
|
42 |
* @param val Value to be inserted |
|
43 |
*/ |
|
13 | 44 |
void (queue_push )(queue_t *q, void *val); |
45 |
/** |
|
46 |
* @brief Get next element in the queue. |
|
47 |
* @param q Pointer to queue |
|
48 |
* @return Value at the beginning of the queue |
|
49 |
*/ |
|
14 | 50 |
void* (queue_top )(const queue_t *q); |
51 |
/** |
|
52 |
* @brief Erase next element of the queue. |
|
53 |
* @param q Pointer to queue |
|
54 |
*/ |
|
15 | 55 |
void (queue_pop )(queue_t *q); |
16 | 56 |
|
17 | 57 |
#endif //QUEUE_H_INCLUDED |
proj/libs/classes/src/list.c | ||
---|---|---|
6 | 6 |
list_node_t *p, *n; |
7 | 7 |
void *val; |
8 | 8 |
}; |
9 |
|
|
9 | 10 |
list_node_t* (list_node_ctor)(list_node_t *p, list_node_t *n, void *val){ |
10 | 11 |
list_node_t *ret = malloc(sizeof(list_node_t)); |
11 | 12 |
if(ret == NULL) return NULL; |
... | ... | |
14 | 15 |
ret->val = val; |
15 | 16 |
return ret; |
16 | 17 |
} |
17 |
void (list_node_dtor)(list_node_t *p){ |
|
18 |
void (list_node_dtor)(list_node_t *p){
|
|
18 | 19 |
free(p); |
19 | 20 |
} |
20 | 21 |
list_node_t* (list_node_next)(const list_node_t *p){ return p->n; } |
... | ... | |
26 | 27 |
list_node_t *end_; |
27 | 28 |
size_t sz; |
28 | 29 |
}; |
29 |
list_t* (list_ctor)(void){ |
|
30 |
|
|
31 |
list_t* (list_ctor) (void){ |
|
30 | 32 |
list_t *ret = malloc(sizeof(list_t)); |
31 | 33 |
if(ret == NULL) return NULL; |
32 | 34 |
ret->sz = 0; |
... | ... | |
41 | 43 |
ret->end_ ->p = ret->begin_; |
42 | 44 |
return ret; |
43 | 45 |
} |
44 |
int (list_dtor)(list_t *l){
|
|
46 |
int (list_dtor) (list_t *l){
|
|
45 | 47 |
if(l == NULL) return 0; |
46 | 48 |
if(list_size(l) > 0) return 1; |
47 | 49 |
list_node_dtor(l->begin_); |
... | ... | |
49 | 51 |
free(l); |
50 | 52 |
return 0; |
51 | 53 |
} |
52 |
list_node_t* (list_begin )( list_t *l){ return l->begin_->n; }
|
|
53 |
list_node_t* (list_end )( list_t *l){ return l->end_; }
|
|
54 |
size_t (list_size )(const list_t *l){ return l->sz; }
|
|
55 |
int (list_empty )(const list_t *l){ return !(l->sz); }
|
|
56 |
list_node_t* (list_insert)(list_t *l, list_node_t *position, void *val){ |
|
54 |
list_node_t* (list_begin) (list_t *l){ return l->begin_->n; }
|
|
55 |
list_node_t* (list_end) (list_t *l){ return l->end_; }
|
|
56 |
size_t (list_size) (const list_t *l){ return l->sz; }
|
|
57 |
int (list_empty) (const list_t *l){ return (l->sz ? true : false); }
|
|
58 |
list_node_t* (list_insert) (list_t *l, list_node_t *position, void *val){
|
|
57 | 59 |
list_node_t *node = list_node_ctor(position->p, position, val); |
58 | 60 |
position->p->n = node; |
59 | 61 |
position->p = node; |
60 | 62 |
++l->sz; |
61 | 63 |
return node; |
62 | 64 |
} |
63 |
void* (list_erase )(list_t *l, list_node_t *position){
|
|
65 |
void* (list_erase) (list_t *l, list_node_t *position){
|
|
64 | 66 |
position->p->n = position->n; |
65 | 67 |
position->n->p = position->p; |
66 | 68 |
void *ret = position->val; |
... | ... | |
71 | 73 |
void (list_push_back)(list_t *l, void *val){ |
72 | 74 |
list_insert(l, list_end(l), val); |
73 | 75 |
} |
74 |
void** (list_front)(list_t *l){ |
|
76 |
void** (list_front) (list_t *l){
|
|
75 | 77 |
return list_node_val(list_begin(l)); |
76 | 78 |
} |
77 | 79 |
void (list_pop_front)(list_t *l){ |
78 | 80 |
list_erase(l, list_begin(l)); |
79 | 81 |
} |
80 |
list_node_t* (list_find)(list_t *l, void *val){ |
|
82 |
list_node_t* (list_find) (list_t *l, void *val){
|
|
81 | 83 |
list_node_t *it = list_begin(l); |
82 | 84 |
while(it != list_end(l) && *list_node_val(it) != val){ |
83 | 85 |
it = list_node_next(it); |
proj/libs/classes/src/queue.c | ||
---|---|---|
5 | 5 |
#include "list.h" |
6 | 6 |
#include "errors.h" |
7 | 7 |
|
8 |
const size_t queue_max_size = UINT_MAX; |
|
9 |
|
|
10 | 8 |
struct queue{ |
11 | 9 |
list_t *l; |
12 | 10 |
}; |
proj/libs/uart/src/uart.c | ||
---|---|---|
313 | 313 |
} |
314 | 314 |
|
315 | 315 |
int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]){ |
316 |
{ |
|
317 |
size_t cnt = 0; |
|
318 |
for(size_t i = 0; i < num; ++i){ |
|
319 |
cnt += sz[i]; |
|
320 |
if(cnt > queue_max_size) return TRANS_REFUSED; |
|
321 |
} |
|
322 |
} |
|
323 | 316 |
int ret; |
324 | 317 |
uint8_t *tmp; |
325 | 318 |
tmp = malloc(sizeof(uint8_t)); *tmp = NCTP_START; queue_push(out, tmp); |
proj/tasks.md | ||
---|---|---|
3 | 3 |
### Most priority |
4 | 4 |
- [ ] Implement multiplayer 1v1 game and win condition to reach N kills. |
5 | 5 |
- [ ] Leaderboard of fastest win, or any achievement (to make use of RTC). |
6 |
- [ ] Documentation |
|
7 |
- [ ] Report |
|
6 | 8 |
|
7 | 9 |
### Mid priority |
8 |
- [ ] Implement path finding for melee AI. |
|
9 |
- [ ] Implement zombie mode (single-player or co-op). |
|
10 |
- [x] Implement path finding for melee AI. |
|
11 |
- [x] Implement zombie mode (single-player) |
|
12 |
- [ ] Implement zombie mode (co-op) |
|
10 | 13 |
- [ ] Implement algorithm to decide when gunner AI needs to shoot. |
11 |
- [ ] Implement campaign mode (single-player or co-op). |
|
14 |
- [ ] Implement campaign mode (single-player) |
|
15 |
- [ ] Implement campaign mode (co-op). |
|
12 | 16 |
- [ ] Visibility algorithm |
13 | 17 |
|
14 | 18 |
### Low Priority |
Also available in: Unified diff