Improve inheritance system

This commit is contained in:
Dendy 2021-02-06 15:20:24 +01:00
parent 9e702bcdbb
commit 01e4d7c9ec
4 changed files with 35 additions and 8 deletions

View File

@ -21,8 +21,11 @@ int main(int argc, char* *argv){
NOD_Node *openbsd = NOD_CreateNode("OpenBSD"); NOD_Node *openbsd = NOD_CreateNode("OpenBSD");
NOD_Node *debianbsd = NOD_CreateNode("Debian GNU/kFreeBSD"); NOD_Node *debianbsd = NOD_CreateNode("Debian GNU/kFreeBSD");
NOD_Node *test = NOD_CreateNode2D("This is a test"); NOD_Node2D *point = NOD_CreateNode2D("Point2D");
NOD_NodeAddChild(debian, test); 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, linoox);
NOD_NodeAddChild(distros, bsd); NOD_NodeAddChild(distros, bsd);
@ -47,6 +50,7 @@ int main(int argc, char* *argv){
//NOD_NodeUnparent(child2); //NOD_NodeUnparent(child2);
NOD_PrintNodeTree(distros); NOD_PrintNodeTree(distros);
NOD_DestroyNodeBranch(distros); NOD_DestroyNodeBranch(distros);

View File

@ -25,7 +25,7 @@ NOD_Node *NOD_CreateNodeEX(char* type, char *name){
void NOD_DestroyNode(NOD_Node *node){ void NOD_DestroyNode(NOD_Node *node){
if(node != NULL){ 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 */ /** Cleanup dependencies on this node by its parent */
NOD_NodeUnparent(node); NOD_NodeUnparent(node);
free(node); free(node);
@ -133,9 +133,9 @@ void NOD_NodeUnparent(NOD_Node *node){
/* Free allocated memory if last child */ /* Free allocated memory if last child */
if(i + 1 == parent->childc){ if(i + 1 == parent->childc){
fprintf(stderr, /*fprintf(stderr,
"NOD_Debug: Freeing last child \"%s\" of vector \"%s\"...\n", "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->childv = realloc(parent->childv, sizeof(node) *parent->childc);
parent->childc--; parent->childc--;
} }

View File

@ -1,5 +1,21 @@
#include "node2d.h" #include "node2d.h"
NOD_Node *NOD_CreateNode2D(char *name){ NOD_Node2D *NOD_CreateNode2D(char *name){
return NOD_CreateNodeEX("Node2D", 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;
} }

View File

@ -1,6 +1,13 @@
#include"../node/node.h" #include"../node/node.h"
#include"../types.h"
#include<stdio.h> #include<stdio.h>
#include<stdlib.h>
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); void NOD_DestroyNode2D(NOD_Node *node);