sgl
annotate src/cb.c @ 0:40491760d6e3
starting work on SimplyGL
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Tue, 10 May 2011 00:06:20 +0300 |
parents | |
children | 648f8604d2b2 |
rev | line source |
---|---|
nuclear@0 | 1 #include <stdlib.h> |
nuclear@0 | 2 #include <string.h> |
nuclear@0 | 3 #include "sgl.h" |
nuclear@0 | 4 |
nuclear@0 | 5 struct cbnode { |
nuclear@0 | 6 void (*func[SGL_NUM_CALLBACKS])(); |
nuclear@0 | 7 struct cbnode *next; |
nuclear@0 | 8 }; |
nuclear@0 | 9 |
nuclear@0 | 10 struct cbnode first_cbnode; |
nuclear@0 | 11 struct cbnode *cb = &first_cbnode; |
nuclear@0 | 12 |
nuclear@0 | 13 int sgl_push_callbacks(void) |
nuclear@0 | 14 { |
nuclear@0 | 15 struct cbnode *node; |
nuclear@0 | 16 |
nuclear@0 | 17 if(!(node = malloc(sizeof *node))) { |
nuclear@0 | 18 return -1; |
nuclear@0 | 19 } |
nuclear@0 | 20 node->next = cb; |
nuclear@0 | 21 cb = node; |
nuclear@0 | 22 sgl_clear_callbacks(); |
nuclear@0 | 23 return 0; |
nuclear@0 | 24 } |
nuclear@0 | 25 |
nuclear@0 | 26 int sgl_pop_callbacks(void) |
nuclear@0 | 27 { |
nuclear@0 | 28 struct cbnode *node; |
nuclear@0 | 29 |
nuclear@0 | 30 if(!cb->next) { |
nuclear@0 | 31 return -1; |
nuclear@0 | 32 } |
nuclear@0 | 33 |
nuclear@0 | 34 node = cb; |
nuclear@0 | 35 cb = cb->next; |
nuclear@0 | 36 free(node); |
nuclear@0 | 37 return 0; |
nuclear@0 | 38 } |
nuclear@0 | 39 |
nuclear@0 | 40 void sgl_clear_callbacks(void) |
nuclear@0 | 41 { |
nuclear@0 | 42 memset(cb->func, 0, sizeof cb->func); |
nuclear@0 | 43 } |
nuclear@0 | 44 |
nuclear@0 | 45 void (*sgl_callback(int idx, void (*func)()))() |
nuclear@0 | 46 { |
nuclear@0 | 47 void (*prev)() = cb->func[idx]; |
nuclear@0 | 48 cb->func[idx] = func; |
nuclear@0 | 49 return prev; |
nuclear@0 | 50 } |