nodes are doubly-linked list and correctly render from lowest to highest (opposite of touch dispatch)

This commit is contained in:
Aaron Culliney 2015-09-05 00:13:48 -07:00
parent 2b80c35d69
commit 4985d52169

View File

@ -15,15 +15,17 @@
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
// WARNING : linked list designed for convenience and not performance =P ... if the amount of GLNode objecs grows
// WARNING : linked list designed for convenience and not performance =P ... if the amount of GLNode objects grows
// wildly, should rethink this ...
typedef struct glnode_array_node_s {
struct glnode_array_node_s *next;
struct glnode_array_node_s *last;
glnode_render_order_t order;
GLNode node;
} glnode_array_node_s;
static glnode_array_node_s *glNodes = NULL;
static glnode_array_node_s *head = NULL;
static glnode_array_node_s *tail = NULL;
// -----------------------------------------------------------------------------
@ -33,19 +35,33 @@ void glnode_registerNode(glnode_render_order_t order, GLNode node) {
glnode_array_node_s *arrayNode = malloc(sizeof(glnode_array_node_s));
assert(arrayNode);
arrayNode->next = NULL;
arrayNode->last = NULL;
arrayNode->order = order;
arrayNode->node = node;
if (glNodes == NULL) {
glNodes = arrayNode;
if (head == NULL) {
assert(tail == NULL);
head = arrayNode;
tail = arrayNode;
} else {
glnode_array_node_s *p = glNodes;
while ((order < p->order) && p->next) {
glnode_array_node_s *p0 = NULL;
glnode_array_node_s *p = head;
while (p && (order < p->order)) {
p0 = p;
p = p->next;
}
glnode_array_node_s *q = p->next;
p->next = arrayNode;
arrayNode->next = q;
if (p0) {
p0->next = arrayNode;
} else {
head = arrayNode;
}
if (p) {
p->last = arrayNode;
} else {
tail = arrayNode;
}
arrayNode->next = p;
arrayNode->last = p0;
}
pthread_mutex_unlock(&mutex);
@ -53,7 +69,7 @@ void glnode_registerNode(glnode_render_order_t order, GLNode node) {
void glnode_setupNodes(void) {
LOG("glnode_setupNodes ...");
glnode_array_node_s *p = glNodes;
glnode_array_node_s *p = head;
while (p) {
p->node.setup();
p = p->next;
@ -62,7 +78,7 @@ void glnode_setupNodes(void) {
void glnode_shutdownNodes(void) {
LOG("glnode_shutdownNodes ...");
glnode_array_node_s *p = glNodes;
glnode_array_node_s *p = head;
while (p) {
p->node.shutdown();
p = p->next;
@ -70,15 +86,15 @@ void glnode_shutdownNodes(void) {
}
void glnode_renderNodes(void) {
glnode_array_node_s *p = glNodes;
glnode_array_node_s *p = tail;
while (p) {
p->node.render();
p = p->next;
p = p->last;
}
}
void glnode_reshapeNodes(int w, int h) {
glnode_array_node_s *p = glNodes;
glnode_array_node_s *p = head;
while (p) {
p->node.reshape(w, h);
p = p->next;
@ -87,7 +103,7 @@ void glnode_reshapeNodes(int w, int h) {
#if INTERFACE_TOUCH
int64_t glnode_onTouchEvent(interface_touch_event_t action, int pointer_count, int pointer_idx, float *x_coords, float *y_coords) {
glnode_array_node_s *p = glNodes;
glnode_array_node_s *p = head;
int64_t flags = 0x0;
while (p) {
flags = p->node.onTouchEvent(action, pointer_count, pointer_idx, x_coords, y_coords);