brzeszczot

brzeszczot.git
git clone git://git.lenczewski.org/brzeszczot.git
Log | Files | Refs

libriot.h (2212B)


      1 #ifndef LIBRIOT_H
      2 #define LIBRIOT_H
      3 
      4 #include "common.h"
      5 #include "utils.h"
      6 
      7 #ifdef __cplusplus
      8 extern "C" {
      9 #endif /* __cplusplus */
     10 
     11 typedef s32 riot_relptr_t;
     12 typedef u32 riot_offptr_t;
     13 
     14 struct riot_intrusive_list_node {
     15 	riot_relptr_t prev, next;
     16 };
     17 
     18 inline void
     19 riot_intrusive_list_node_link(struct riot_intrusive_list_node *self,
     20 			      struct riot_intrusive_list_node *prev,
     21 			      struct riot_intrusive_list_node *next) {
     22 	assert(self);
     23 	assert(prev);
     24 	assert(next);
     25 
     26 	prev->next = RELPTR_ABS2REL(riot_relptr_t, prev, self);
     27 	self->prev = RELPTR_ABS2REL(riot_relptr_t, self, prev);
     28 	self->next = RELPTR_ABS2REL(riot_relptr_t, self, next);
     29 	next->prev = RELPTR_ABS2REL(riot_relptr_t, next, self);
     30 }
     31 
     32 inline void
     33 riot_intrusive_list_node_snip(struct riot_intrusive_list_node *self) {
     34 	assert(self);
     35 
     36 	struct riot_intrusive_list_node *prev, *next;
     37 	prev = RELPTR_REL2ABS(struct riot_intrusive_list_node *, riot_relptr_t, self, self->prev);
     38 	next = RELPTR_REL2ABS(struct riot_intrusive_list_node *, riot_relptr_t, self, self->next);
     39 
     40 	prev->next = RELPTR_ABS2REL(riot_relptr_t, prev, next);
     41 	next->prev = RELPTR_ABS2REL(riot_relptr_t, next, prev);
     42 	self->prev = self->next = RELPTR_NULL;
     43 }
     44 
     45 struct riot_intrusive_list {
     46 	struct riot_intrusive_list_node root;
     47 };
     48 
     49 inline void
     50 riot_intrusive_list_init(struct riot_intrusive_list *self) {
     51 	assert(self);
     52 
     53 	self->root.prev = self->root.next = RELPTR_ABS2REL(riot_relptr_t, &self->root, &self->root);
     54 }
     55 
     56 inline void
     57 riot_intrusive_list_push(struct riot_intrusive_list *self,
     58 			 struct riot_intrusive_list_node *elem) {
     59 	assert(self);
     60 	assert(elem);
     61 
     62 	struct riot_intrusive_list_node *prev, *next;
     63 	prev = RELPTR_REL2ABS(struct riot_intrusive_list_node *, riot_relptr_t, &self->root, self->root.prev);
     64 	next = RELPTR_REL2ABS(struct riot_intrusive_list_node *, riot_relptr_t, &self->root, self->root.next);
     65 
     66 	riot_intrusive_list_node_link(elem, prev, next);
     67 }
     68 
     69 typedef u32 fnv1a_u32;
     70 typedef u64 xxh64_u64;
     71 
     72 struct riot_fvec2 {
     73 	f32 vs[2];
     74 };
     75 
     76 struct riot_fvec3 {
     77 	f32 vs[3];
     78 };
     79 
     80 struct riot_fvec4 {
     81 	f32 vs[4];
     82 };
     83 
     84 struct riot_fmat4x4 {
     85 	f32 vs[16];
     86 };
     87 
     88 struct riot_rgba {
     89 	u8 vs[4];
     90 };
     91 
     92 #ifdef __cplusplus
     93 };
     94 #endif /* __cplusplus */
     95 
     96 #endif /* LIBRIOT_H */