From 01e4d7c9ecc1ad03a50225a0d48ae403f3f41021 Mon Sep 17 00:00:00 2001 From: Dendy Date: Sat, 6 Feb 2021 15:20:24 +0100 Subject: [PATCH] Improve inheritance system --- src/main.c | 8 ++++++-- src/node/node.c | 6 +++--- src/node2d/node2d.c | 20 ++++++++++++++++++-- src/node2d/node2d.h | 9 ++++++++- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 6f2f524..9024cd0 100644 --- a/src/main.c +++ b/src/main.c @@ -21,8 +21,11 @@ int main(int argc, char* *argv){ NOD_Node *openbsd = NOD_CreateNode("OpenBSD"); NOD_Node *debianbsd = NOD_CreateNode("Debian GNU/kFreeBSD"); - NOD_Node *test = NOD_CreateNode2D("This is a test"); - NOD_NodeAddChild(debian, test); + NOD_Node2D *point = NOD_CreateNode2D("Point2D"); + point->pos.x = 2; + printf("The X value of '%s' is %d!\n", point->node.name, 3); + + NOD_NodeAddChild(debian, point); NOD_NodeAddChild(distros, linoox); NOD_NodeAddChild(distros, bsd); @@ -47,6 +50,7 @@ int main(int argc, char* *argv){ //NOD_NodeUnparent(child2); + NOD_PrintNodeTree(distros); NOD_DestroyNodeBranch(distros); diff --git a/src/node/node.c b/src/node/node.c index b12c460..7b4aa5c 100644 --- a/src/node/node.c +++ b/src/node/node.c @@ -25,7 +25,7 @@ NOD_Node *NOD_CreateNodeEX(char* type, char *name){ void NOD_DestroyNode(NOD_Node *node){ if(node != NULL){ - printf("NOD_Info: Deleting node \"%s\"\n", node->name); + /*printf("NOD_Info: Deleting node \"%s\"\n", node->name);*/ /** Cleanup dependencies on this node by its parent */ NOD_NodeUnparent(node); free(node); @@ -133,9 +133,9 @@ void NOD_NodeUnparent(NOD_Node *node){ /* Free allocated memory if last child */ if(i + 1 == parent->childc){ - fprintf(stderr, + /*fprintf(stderr, "NOD_Debug: Freeing last child \"%s\" of vector \"%s\"...\n", - node->name, parent->name); + node->name, parent->name);*/ parent->childv = realloc(parent->childv, sizeof(node) *parent->childc); parent->childc--; } diff --git a/src/node2d/node2d.c b/src/node2d/node2d.c index fc90969..5cd1789 100644 --- a/src/node2d/node2d.c +++ b/src/node2d/node2d.c @@ -1,5 +1,21 @@ #include "node2d.h" -NOD_Node *NOD_CreateNode2D(char *name){ - return NOD_CreateNodeEX("Node2D", name); +NOD_Node2D *NOD_CreateNode2D(char *name){ + NOD_Node2D *node = NULL; + NOD_Node *plain_node = NULL; + + plain_node = NOD_CreateNodeEX("Node2D", name); + + if(plain_node != NULL){ + plain_node = realloc(plain_node, sizeof(NOD_Node2D)); + + if(plain_node != NULL){ + node = (NOD_Node2D*)plain_node; + + node->pos.x = 0; + node->pos.y = 0; + } + } + + return node; } diff --git a/src/node2d/node2d.h b/src/node2d/node2d.h index 72c9a8f..7a015cd 100644 --- a/src/node2d/node2d.h +++ b/src/node2d/node2d.h @@ -1,6 +1,13 @@ #include"../node/node.h" +#include"../types.h" #include +#include -NOD_Node *NOD_CreateNode2D(char *name); +typedef struct node_2d{ + NOD_Node node; + vector2Di pos; +} NOD_Node2D; + +NOD_Node2D *NOD_CreateNode2D(char *name); void NOD_DestroyNode2D(NOD_Node *node);