From bfb985a08e4bde3a1248f533e9448d2489b9ddc0 Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Wed, 14 Jun 2023 23:20:36 +1000 Subject: [PATCH] Renamed Box_EngineNode to Box_Node --- Box.vcxproj | 4 +- box/box_engine.c | 32 ++++----- box/box_engine.h | 4 +- box/box_engine_node.h | 74 --------------------- box/{box_engine_node.c => box_node.c} | 70 +++++++++---------- box/box_node.h | 74 +++++++++++++++++++++ box/lib_node.c | 96 +++++++++++++-------------- 7 files changed, 177 insertions(+), 177 deletions(-) delete mode 100644 box/box_engine_node.h rename box/{box_engine_node.c => box_node.c} (68%) create mode 100644 box/box_node.h diff --git a/Box.vcxproj b/Box.vcxproj index e6b19e1..9037151 100644 --- a/Box.vcxproj +++ b/Box.vcxproj @@ -139,7 +139,7 @@ xcopy "$(SolutionDir)Toy\repl\repl_tools.*" "$(SolutionDir)box" /Y /I /E - + @@ -153,7 +153,7 @@ xcopy "$(SolutionDir)Toy\repl\repl_tools.*" "$(SolutionDir)box" /Y /I /E - + diff --git a/box/box_engine.c b/box/box_engine.c index c448b32..007b68b 100644 --- a/box/box_engine.c +++ b/box/box_engine.c @@ -82,8 +82,8 @@ void Box_initEngine() { void Box_freeEngine() { //clear existing root node if (engine.rootNode != NULL) { - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onFree", NULL); - Box_freeEngineNode(engine.rootNode); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onFree", NULL); + Box_freeNode(engine.rootNode); engine.rootNode = NULL; } @@ -114,8 +114,8 @@ static inline void execLoadRootNode() { //free the existing root node if (engine.rootNode != NULL) { - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onFree", NULL); - Box_freeEngineNode(engine.rootNode); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onFree", NULL); + Box_freeNode(engine.rootNode); engine.rootNode = NULL; } @@ -126,7 +126,7 @@ static inline void execLoadRootNode() { free((void*)source); //allocate the new root node - engine.rootNode = TOY_ALLOCATE(Box_EngineNode, 1); + engine.rootNode = TOY_ALLOCATE(Box_Node, 1); //BUGFIX: make an inner-interpreter Toy_Interpreter inner; @@ -146,10 +146,10 @@ static inline void execLoadRootNode() { Toy_setInterpreterAssert(&inner, engine.interpreter.assertOutput); Toy_setInterpreterError(&inner, engine.interpreter.errorOutput); - Box_initEngineNode(engine.rootNode, &inner, tb, size); + Box_initNode(engine.rootNode, &inner, tb, size); //immediately call onLoad() after running the script - for loading other nodes - Box_callEngineNode(engine.rootNode, &inner, "onLoad", NULL); + Box_callNode(engine.rootNode, &inner, "onLoad", NULL); //cache the scope for later freeing engine.rootNode->scope = inner.scope; @@ -163,7 +163,7 @@ static inline void execLoadRootNode() { engine.nextRootNodeFilename = TOY_TO_NULL_LITERAL; //init the new node-tree - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onInit", NULL); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onInit", NULL); } static inline void execEvents() { @@ -213,7 +213,7 @@ static inline void execEvents() { //call the function Toy_pushLiteralArray(&args, eventLiteral); - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onKeyDown", &args); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onKeyDown", &args); Toy_freeLiteral(Toy_popLiteralArray(&args)); //push to the event list @@ -240,7 +240,7 @@ static inline void execEvents() { //call the function Toy_pushLiteralArray(&args, eventLiteral); - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onKeyUp", &args); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onKeyUp", &args); Toy_freeLiteral(Toy_popLiteralArray(&args)); //push to the event list @@ -261,7 +261,7 @@ static inline void execEvents() { Toy_pushLiteralArray(&args, mouseXRel); Toy_pushLiteralArray(&args, mouseYRel); - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onMouseMotion", &args); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onMouseMotion", &args); Toy_freeLiteral(mouseX); Toy_freeLiteral(mouseY); @@ -312,7 +312,7 @@ static inline void execEvents() { Toy_pushLiteralArray(&args, mouseY); Toy_pushLiteralArray(&args, mouseButton); - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onMouseButtonDown", &args); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onMouseButtonDown", &args); Toy_freeLiteral(mouseX); Toy_freeLiteral(mouseY); @@ -362,7 +362,7 @@ static inline void execEvents() { Toy_pushLiteralArray(&args, mouseY); Toy_pushLiteralArray(&args, mouseButton); - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onMouseButtonUp", &args); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onMouseButtonUp", &args); Toy_freeLiteral(mouseX); Toy_freeLiteral(mouseY); @@ -383,7 +383,7 @@ static inline void execEvents() { Toy_pushLiteralArray(&args, mouseX); Toy_pushLiteralArray(&args, mouseY); - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onMouseWheel", &args); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onMouseWheel", &args); Toy_freeLiteral(mouseX); Toy_freeLiteral(mouseY); @@ -404,7 +404,7 @@ static inline void execEvents() { static inline void execStep() { if (engine.rootNode != NULL) { //steps - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onStep", NULL); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onStep", NULL); } } @@ -461,7 +461,7 @@ void Box_execEngine() { Dbg_stopTimer(&dbgTimer); Dbg_startTimer(&dbgTimer, "onDraw() calls"); - Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onDraw", NULL); + Box_callRecursiveNode(engine.rootNode, &engine.interpreter, "onDraw", NULL); Dbg_stopTimer(&dbgTimer); Dbg_startTimer(&dbgTimer, "render screen"); diff --git a/box/box_engine.h b/box/box_engine.h index 055a876..18e5b2e 100644 --- a/box/box_engine.h +++ b/box/box_engine.h @@ -1,7 +1,7 @@ #pragma once #include "box_common.h" -#include "box_engine_node.h" +#include "box_node.h" #include "toy_interpreter.h" #include "toy_literal_array.h" @@ -12,7 +12,7 @@ //the base engine object, which represents the state of the game typedef struct Box_private_engine { //engine stuff - Box_EngineNode* rootNode; + Box_Node* rootNode; Toy_Literal nextRootNodeFilename; clock_t simTime; clock_t realTime; diff --git a/box/box_engine_node.h b/box/box_engine_node.h deleted file mode 100644 index 701a7d9..0000000 --- a/box/box_engine_node.h +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include "box_common.h" - -#include "toy_literal_dictionary.h" -#include "toy_interpreter.h" - -#define OPAQUE_TAG_ENGINE_NODE 1001 - -//forward declare -typedef struct Box_private_engineNode Box_EngineNode; -// typedef void (*EngineNodeCallback)(void*); - -//the node object, which forms a tree -typedef struct Box_private_engineNode { - //function for releasing memory NOTE: removed, because it's not needed with only 1 node type - I've left them commented out because I might need them soon - // EngineNodeCallback freeMemory; - - //toy functions, stored in a dict for flexibility - Toy_LiteralDictionary* functions; - - //point to the parent - Box_EngineNode* parent; - - //BUGFIX: hold the node's scope so it can be popped - Toy_Scope* scope; - - //my opaque type tag - int tag; - - //use Toy's memory model - Box_EngineNode** children; - int capacity; - int count; //includes tombstones - int childCount; - - //rendering-specific features - SDL_Texture* texture; - SDL_Rect rect; - int frames; - int currentFrame; -} Box_EngineNode; //TODO: rename this? - -BOX_API void Box_initEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const unsigned char* tb, size_t size); //run bytecode, then grab all top-level function literals -BOX_API void Box_pushEngineNode(Box_EngineNode* node, Box_EngineNode* child); //push to the array (prune tombstones when expanding/copying) -BOX_API void Box_freeEngineNode(Box_EngineNode* node); //free this node and all children - -BOX_API Box_EngineNode* Box_getChildEngineNode(Box_EngineNode* node, int index); -BOX_API void Box_freeChildEngineNode(Box_EngineNode* node, int index); - -BOX_API Toy_Literal Box_callEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args); -BOX_API Toy_Literal Box_callEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args); //call "fnName" on this node, and only this node, if it exists - -//for calling various lifecycle functions -BOX_API void Box_callRecursiveEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args); -BOX_API void Box_callRecursiveEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args); //call "fnName" on this node, and all children, if it exists - -BOX_API int Box_getChildCountEngineNode(Box_EngineNode* node); - -BOX_API int Box_loadTextureEngineNode(Box_EngineNode* node, const char* fname); -BOX_API void Box_freeTextureEngineNode(Box_EngineNode* node); - -BOX_API void Box_setRectEngineNode(Box_EngineNode* node, SDL_Rect rect); -BOX_API SDL_Rect Box_getRectEngineNode(Box_EngineNode* node); - -BOX_API void Box_setFramesEngineNode(Box_EngineNode* node, int frames); -BOX_API int Box_getFramesEngineNode(Box_EngineNode* node); -BOX_API void Box_setCurrentFrameEngineNode(Box_EngineNode* node, int currentFrame); -BOX_API int Box_getCurrentFrameEngineNode(Box_EngineNode* node); -BOX_API void Box_incrementCurrentFrame(Box_EngineNode* node); - -BOX_API void Box_setTextEngineNode(Box_EngineNode* node, TTF_Font* font, const char* text, SDL_Color color); - -BOX_API void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest); diff --git a/box/box_engine_node.c b/box/box_node.c similarity index 68% rename from box/box_engine_node.c rename to box/box_node.c index 5f3a77d..eff529b 100644 --- a/box/box_engine_node.c +++ b/box/box_node.c @@ -1,15 +1,15 @@ -#include "box_engine_node.h" +#include "box_node.h" #include "box_engine.h" #include "toy_memory.h" -void Box_initEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const unsigned char* tb, size_t size) { +void Box_initNode(Box_Node* node, Toy_Interpreter* interpreter, const unsigned char* tb, size_t size) { //init // node->freeMemory = freeMemory; node->functions = TOY_ALLOCATE(Toy_LiteralDictionary, 1); node->parent = NULL; node->scope = NULL; - node->tag = OPAQUE_TAG_ENGINE_NODE; + node->tag = OPAQUE_TAG_NODE; node->children = NULL; node->capacity = 0; node->count = 0; @@ -41,13 +41,13 @@ void Box_initEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, cons } } -void Box_pushEngineNode(Box_EngineNode* node, Box_EngineNode* child) { +void Box_pushNode(Box_Node* node, Box_Node* child) { //push to the array if (node->count + 1 > node->capacity) { int oldCapacity = node->capacity; node->capacity = TOY_GROW_CAPACITY(oldCapacity); - node->children = TOY_GROW_ARRAY(Box_EngineNode*, node->children, oldCapacity, node->capacity); + node->children = TOY_GROW_ARRAY(Box_Node*, node->children, oldCapacity, node->capacity); } //assign @@ -60,18 +60,18 @@ void Box_pushEngineNode(Box_EngineNode* node, Box_EngineNode* child) { node->childCount++; } -void Box_freeEngineNode(Box_EngineNode* node) { +void Box_freeNode(Box_Node* node) { if (node == NULL) { return; //NO-OP } //free this node's children for (int i = 0; i < node->count; i++) { - Box_freeEngineNode(node->children[i]); + Box_freeNode(node->children[i]); } //free the pointer array to the children - TOY_FREE_ARRAY(Box_EngineNode*, node->children, node->capacity); + TOY_FREE_ARRAY(Box_Node*, node->children, node->capacity); if (node->functions != NULL) { Toy_freeLiteralDictionary(node->functions); @@ -83,14 +83,14 @@ void Box_freeEngineNode(Box_EngineNode* node) { } if (node->texture != NULL) { - Box_freeTextureEngineNode(node); + Box_freeTextureNode(node); } //free this node's memory - TOY_FREE(Box_EngineNode, node); + TOY_FREE(Box_Node, node); } -Box_EngineNode* Box_getChildEngineNode(Box_EngineNode* node, int index) { +Box_Node* Box_getChildNode(Box_Node* node, int index) { if (index < 0 || index > node->count) { return NULL; } @@ -98,20 +98,20 @@ Box_EngineNode* Box_getChildEngineNode(Box_EngineNode* node, int index) { return node->children[index]; } -void Box_freeChildEngineNode(Box_EngineNode* node, int index) { +void Box_freeChildNode(Box_Node* node, int index) { //get the child node - Box_EngineNode* childNode = node->children[index]; + Box_Node* childNode = node->children[index]; //free the node if (childNode != NULL) { - Box_freeEngineNode(childNode); + Box_freeNode(childNode); node->childCount--; } node->children[index] = NULL; } -Toy_Literal Box_callEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args) { +Toy_Literal Box_callNodeLiteral(Box_Node* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args) { Toy_Literal ret = TOY_TO_NULL_LITERAL; //if this fn exists @@ -147,18 +147,18 @@ Toy_Literal Box_callEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* int return ret; } -Toy_Literal Box_callEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args) { +Toy_Literal Box_callNode(Box_Node* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args) { //call "fnName" on this node, and all children, if it exists Toy_Literal key = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString(fnName)); - Toy_Literal ret = Box_callEngineNodeLiteral(node, interpreter, key, args); + Toy_Literal ret = Box_callNodeLiteral(node, interpreter, key, args); Toy_freeLiteral(key); return ret; } -void Box_callRecursiveEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args) { +void Box_callRecursiveNodeLiteral(Box_Node* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args) { //if this fn exists if (Toy_existsLiteralDictionary(node->functions, key)) { Toy_Literal fn = Toy_getLiteralDictionary(node->functions, key); @@ -190,25 +190,25 @@ void Box_callRecursiveEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* i //recurse to the (non-tombstone) children for (int i = 0; i < node->count; i++) { if (node->children[i] != NULL) { - Box_callRecursiveEngineNodeLiteral(node->children[i], interpreter, key, args); + Box_callRecursiveNodeLiteral(node->children[i], interpreter, key, args); } } } -void Box_callRecursiveEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args) { +void Box_callRecursiveNode(Box_Node* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args) { //call "fnName" on this node, and all children, if it exists Toy_Literal key = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString(fnName)); - Box_callRecursiveEngineNodeLiteral(node, interpreter, key, args); + Box_callRecursiveNodeLiteral(node, interpreter, key, args); Toy_freeLiteral(key); } -int Box_getChildCountEngineNode(Box_EngineNode* node) { +int Box_getChildCountNode(Box_Node* node) { return node->childCount; } -int Box_loadTextureEngineNode(Box_EngineNode* node, const char* fname) { +int Box_loadTextureNode(Box_Node* node, const char* fname) { SDL_Surface* surface = IMG_Load(fname); if (surface == NULL) { @@ -226,52 +226,52 @@ int Box_loadTextureEngineNode(Box_EngineNode* node, const char* fname) { int w, h; SDL_QueryTexture(node->texture, NULL, NULL, &w, &h); SDL_Rect r = { 0, 0, w, h }; - Box_setRectEngineNode(node, r); - Box_setFramesEngineNode(node, 1); //default + Box_setRectNode(node, r); + Box_setFramesNode(node, 1); //default return 0; } -void Box_freeTextureEngineNode(Box_EngineNode* node) { +void Box_freeTextureNode(Box_Node* node) { if (node->texture != NULL) { SDL_DestroyTexture(node->texture); node->texture = NULL; } } -void Box_setRectEngineNode(Box_EngineNode* node, SDL_Rect rect) { +void Box_setRectNode(Box_Node* node, SDL_Rect rect) { node->rect = rect; } -SDL_Rect Box_getRectEngineNode(Box_EngineNode* node) { +SDL_Rect Box_getRectNode(Box_Node* node) { return node->rect; } -void Box_setFramesEngineNode(Box_EngineNode* node, int frames) { +void Box_setFramesNode(Box_Node* node, int frames) { node->frames = frames; node->currentFrame = 0; //just in case } -int Box_getFramesEngineNode(Box_EngineNode* node) { +int Box_getFramesNode(Box_Node* node) { return node->frames; } -void Box_setCurrentFrameEngineNode(Box_EngineNode* node, int currentFrame) { +void Box_setCurrentFrameNode(Box_Node* node, int currentFrame) { node->currentFrame = currentFrame; } -int Box_getCurrentFrameEngineNode(Box_EngineNode* node) { +int Box_getCurrentFrameNode(Box_Node* node) { return node->currentFrame; } -void Box_incrementCurrentFrame(Box_EngineNode* node) { +void Box_incrementCurrentFrame(Box_Node* node) { node->currentFrame++; if (node->currentFrame >= node->frames) { node->currentFrame = 0; } } -void Box_setTextEngineNode(Box_EngineNode* node, TTF_Font* font, const char* text, SDL_Color color) { +void Box_setTextNode(Box_Node* node, TTF_Font* font, const char* text, SDL_Color color) { SDL_Surface* surface = TTF_RenderText_Solid(font, text, color); node->texture = SDL_CreateTextureFromSurface(engine.renderer, surface); @@ -284,7 +284,7 @@ void Box_setTextEngineNode(Box_EngineNode* node, TTF_Font* font, const char* tex } -void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest) { +void Box_drawNode(Box_Node* node, SDL_Rect dest) { if (!node->texture) return; SDL_Rect src = node->rect; src.x += src.w * node->currentFrame; //TODO: improve this diff --git a/box/box_node.h b/box/box_node.h new file mode 100644 index 0000000..53e0df5 --- /dev/null +++ b/box/box_node.h @@ -0,0 +1,74 @@ +#pragma once + +#include "box_common.h" + +#include "toy_literal_dictionary.h" +#include "toy_interpreter.h" + +#define OPAQUE_TAG_NODE 1001 + +//forward declare +typedef struct Box_private_node Box_Node; +// typedef void (*Box_NodeCallback)(void*); + +//the node object, which forms a tree +typedef struct Box_private_node { + //function for releasing memory NOTE: removed, because it's not needed with only 1 node type - I've left them commented out because I might need them soon + // Box_NodeCallback freeMemory; + + //toy functions, stored in a dict for flexibility + Toy_LiteralDictionary* functions; + + //point to the parent + Box_Node* parent; + + //BUGFIX: hold the node's scope so it can be popped + Toy_Scope* scope; + + //my opaque type tag + int tag; + + //use Toy's memory model + Box_Node** children; + int capacity; + int count; //includes tombstones + int childCount; + + //rendering-specific features + SDL_Texture* texture; + SDL_Rect rect; + int frames; + int currentFrame; +} Box_Node; //TODO: rename this? + +BOX_API void Box_initNode(Box_Node* node, Toy_Interpreter* interpreter, const unsigned char* tb, size_t size); //run bytecode, then grab all top-level function literals +BOX_API void Box_pushNode(Box_Node* node, Box_Node* child); //push to the array (prune tombstones when expanding/copying) +BOX_API void Box_freeNode(Box_Node* node); //free this node and all children + +BOX_API Box_Node* Box_getChildNode(Box_Node* node, int index); +BOX_API void Box_freeChildNode(Box_Node* node, int index); + +BOX_API Toy_Literal Box_callNodeLiteral(Box_Node* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args); +BOX_API Toy_Literal Box_callNode(Box_Node* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args); //call "fnName" on this node, and only this node, if it exists + +//for calling various lifecycle functions +BOX_API void Box_callRecursiveNodeLiteral(Box_Node* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args); +BOX_API void Box_callRecursiveNode(Box_Node* node, Toy_Interpreter* interpreter, const char* fnName, Toy_LiteralArray* args); //call "fnName" on this node, and all children, if it exists + +BOX_API int Box_getChildCountNode(Box_Node* node); + +BOX_API int Box_loadTextureNode(Box_Node* node, const char* fname); +BOX_API void Box_freeTextureNode(Box_Node* node); + +BOX_API void Box_setRectNode(Box_Node* node, SDL_Rect rect); +BOX_API SDL_Rect Box_getRectNode(Box_Node* node); + +BOX_API void Box_setFramesNode(Box_Node* node, int frames); +BOX_API int Box_getFramesNode(Box_Node* node); +BOX_API void Box_setCurrentFrameNode(Box_Node* node, int currentFrame); +BOX_API int Box_getCurrentFrameNode(Box_Node* node); +BOX_API void Box_incrementCurrentFrame(Box_Node* node); + +BOX_API void Box_setTextNode(Box_Node* node, TTF_Font* font, const char* text, SDL_Color color); + +BOX_API void Box_drawNode(Box_Node* node, SDL_Rect dest); diff --git a/box/lib_node.c b/box/lib_node.c index 111d084..86af3f3 100644 --- a/box/lib_node.c +++ b/box/lib_node.c @@ -1,6 +1,6 @@ #include "lib_node.h" -#include "box_engine_node.h" +#include "box_node.h" #include "box_engine.h" #include "repl_tools.h" @@ -47,7 +47,7 @@ static int nativeLoadNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume const unsigned char* tb = Toy_compileString((const char*)source, &size); free((void*)source); - Box_EngineNode* node = TOY_ALLOCATE(Box_EngineNode, 1); + Box_Node* node = TOY_ALLOCATE(Box_Node, 1); //BUGFIX: make an -interpreter Toy_Interpreter inner; @@ -67,10 +67,10 @@ static int nativeLoadNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume Toy_setInterpreterAssert(&inner, interpreter->assertOutput); Toy_setInterpreterError(&inner, interpreter->errorOutput); - Box_initEngineNode(node, &inner, tb, size); + Box_initNode(node, &inner, tb, size); //immediately call onLoad() after running the script - for loading other nodes - Box_callEngineNode(node, &inner, "onLoad", NULL); + Box_callNode(node, &inner, "onLoad", NULL); // return the node Toy_Literal nodeLiteral = TOY_TO_OPAQUE_LITERAL(node, node->tag); @@ -93,27 +93,27 @@ static int nativeInitNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume return -1; } - Toy_Literal node = Toy_popLiteralArray(arguments); + Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments); - Toy_Literal nodeIdn = node; - if (TOY_IS_IDENTIFIER(node) && Toy_parseIdentifierToValue(interpreter, &node)) { + Toy_Literal nodeIdn = nodeLiteral; + if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) { Toy_freeLiteral(nodeIdn); } //check argument types - if (!TOY_IS_OPAQUE(node)) { + if (!TOY_IS_OPAQUE(nodeLiteral)) { interpreter->errorOutput("Incorrect argument type passed to initNode\n"); - Toy_freeLiteral(node); + Toy_freeLiteral(nodeLiteral); return -1; } - Box_EngineNode* engineNode = TOY_AS_OPAQUE(node); + Box_Node* node = TOY_AS_OPAQUE(nodeLiteral); //init the new node (and ONLY this node) - Box_callEngineNode(engineNode, &engine.interpreter, "onInit", NULL); + Box_callNode(node, &engine.interpreter, "onInit", NULL); //cleanup - Toy_freeLiteral(node); + Toy_freeLiteral(nodeLiteral); return 0; } @@ -145,10 +145,10 @@ static int nativePushNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume } //push the node - Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent); - Box_EngineNode* childNode = TOY_AS_OPAQUE(child); + Box_Node* parentNode = TOY_AS_OPAQUE(parent); + Box_Node* childNode = TOY_AS_OPAQUE(child); - Box_pushEngineNode(parentNode, childNode); + Box_pushNode(parentNode, childNode); //no return value Toy_freeLiteral(parent); @@ -185,7 +185,7 @@ static int nativeGetChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* ar } //push the node - Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent); + Box_Node* parentNode = TOY_AS_OPAQUE(parent); int intIndex = TOY_AS_INTEGER(index); if (intIndex < 0 || intIndex >= parentNode->count) { @@ -195,7 +195,7 @@ static int nativeGetChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* ar return -1; } - Box_EngineNode* childNode = Box_getChildEngineNode(parentNode, intIndex); + Box_Node* childNode = Box_getChildNode(parentNode, intIndex); Toy_Literal child; if (childNode == NULL) { @@ -236,7 +236,7 @@ static int nativeFreeChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* a return -1; } - Box_EngineNode* node = TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = TOY_AS_OPAQUE(nodeLiteral); int idx = TOY_AS_INTEGER(indexLiteral); //check bounds @@ -248,8 +248,8 @@ static int nativeFreeChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* a } //TODO: differentiate between onFree() and freeing memory - Box_callRecursiveEngineNode(node, interpreter, "onFree", NULL); - Box_freeChildEngineNode(node, idx); + Box_callRecursiveNode(node, interpreter, "onFree", NULL); + Box_freeChildNode(node, idx); //cleanup Toy_freeLiteral(nodeLiteral); @@ -278,8 +278,8 @@ static int nativeGetParentNode(Toy_Interpreter* interpreter, Toy_LiteralArray* a } //push the node - Box_EngineNode* node = TOY_AS_OPAQUE(nodeLiteral); - Box_EngineNode* parent = node->parent; + Box_Node* node = TOY_AS_OPAQUE(nodeLiteral); + Box_Node* parent = node->parent; Toy_Literal parentLiteral = TOY_TO_NULL_LITERAL; if (parent != NULL) { @@ -316,8 +316,8 @@ static int nativeGetChildNodeCount(Toy_Interpreter* interpreter, Toy_LiteralArra } //get the count - Box_EngineNode* node = TOY_AS_OPAQUE(nodeLiteral); - int childCount = Box_getChildCountEngineNode(node); + Box_Node* node = TOY_AS_OPAQUE(nodeLiteral); + int childCount = Box_getChildCountNode(node); Toy_Literal childCountLiteral = TOY_TO_INTEGER_LITERAL(childCount); Toy_pushLiteralArray(&interpreter->stack, childCountLiteral); @@ -368,14 +368,14 @@ static int nativeLoadNodeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* Toy_freeLiteral(drivePathLiteral); //not needed anymore //actually load TODO: number the opaques, and check the tag - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); if (node->texture != NULL) { - Box_freeTextureEngineNode(node); + Box_freeTextureNode(node); } - if (Box_loadTextureEngineNode(node, Toy_toCString(TOY_AS_STRING(filePathLiteral))) != 0) { - interpreter->errorOutput("Failed to load the texture into the EngineNode\n"); + if (Box_loadTextureNode(node, Toy_toCString(TOY_AS_STRING(filePathLiteral))) != 0) { + interpreter->errorOutput("Failed to load the texture into the Box_Node\n"); Toy_freeLiteral(filePathLiteral); Toy_freeLiteral(nodeLiteral); return -1; @@ -410,10 +410,10 @@ static int nativeFreeNodeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* } //actually load TODO: number the opaques, and check the numbers - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); if (node->texture != NULL) { - Box_freeTextureEngineNode(node); + Box_freeTextureNode(node); } //cleanup @@ -472,10 +472,10 @@ static int nativeSetNodeRect(Toy_Interpreter* interpreter, Toy_LiteralArray* arg } //actually set - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); SDL_Rect r = {TOY_AS_INTEGER(x), TOY_AS_INTEGER(y), TOY_AS_INTEGER(w), TOY_AS_INTEGER(h)}; - Box_setRectEngineNode(node, r); + Box_setRectNode(node, r); //cleanup Toy_freeLiteral(nodeLiteral); @@ -509,7 +509,7 @@ static int nativeGetNodeRectX(Toy_Interpreter* interpreter, Toy_LiteralArray* ar } //actually get - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.x); Toy_pushLiteralArray(&interpreter->stack, resultLiteral); @@ -542,7 +542,7 @@ static int nativeGetNodeRectY(Toy_Interpreter* interpreter, Toy_LiteralArray* ar } //actually get - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.y); Toy_pushLiteralArray(&interpreter->stack, resultLiteral); @@ -575,7 +575,7 @@ static int nativeGetNodeRectW(Toy_Interpreter* interpreter, Toy_LiteralArray* ar } //actually get - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.w); Toy_pushLiteralArray(&interpreter->stack, resultLiteral); @@ -608,7 +608,7 @@ static int nativeGetNodeRectH(Toy_Interpreter* interpreter, Toy_LiteralArray* ar } //actually get - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); Toy_Literal resultLiteral = TOY_TO_INTEGER_LITERAL(node->rect.h); Toy_pushLiteralArray(&interpreter->stack, resultLiteral); @@ -648,9 +648,9 @@ static int nativeSetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* a } //actually set - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); - Box_setFramesEngineNode(node, TOY_AS_INTEGER(framesLiteral)); + Box_setFramesNode(node, TOY_AS_INTEGER(framesLiteral)); //cleanup Toy_freeLiteral(nodeLiteral); @@ -681,7 +681,7 @@ static int nativeGetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* a } //actually get - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); Toy_Literal framesLiteral = TOY_TO_INTEGER_LITERAL(node->frames); Toy_pushLiteralArray(&interpreter->stack, framesLiteral); @@ -723,9 +723,9 @@ static int nativeSetCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralAr } //actually set - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); - Box_setCurrentFrameEngineNode(node, TOY_AS_INTEGER(currentFrameLiteral)); + Box_setCurrentFrameNode(node, TOY_AS_INTEGER(currentFrameLiteral)); //cleanup Toy_freeLiteral(nodeLiteral); @@ -756,7 +756,7 @@ static int nativeGetCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralAr } //actually get - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); Toy_Literal currentFrameLiteral = TOY_TO_INTEGER_LITERAL(node->currentFrame); Toy_pushLiteralArray(&interpreter->stack, currentFrameLiteral); @@ -790,7 +790,7 @@ static int nativeIncrementCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_Lit } //actually get - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); Box_incrementCurrentFrame(node); @@ -854,7 +854,7 @@ static int nativeDrawNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume } //actually render - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); SDL_Rect r = {TOY_AS_INTEGER(x), TOY_AS_INTEGER(y), 0, 0}; if (TOY_IS_INTEGER(w) && TOY_IS_INTEGER(h)) { @@ -866,7 +866,7 @@ static int nativeDrawNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume r.h = node->rect.h; } - Box_drawEngineNode(node, r); + Box_drawNode(node, r); //cleanup Toy_freeLiteral(nodeLiteral); @@ -992,8 +992,8 @@ static int nativeSetNodeText(Toy_Interpreter* interpreter, Toy_LiteralArray* arg SDL_Color color = (SDL_Color){ .r = TOY_AS_INTEGER(rLiteral), .g = TOY_AS_INTEGER(gLiteral), .b = TOY_AS_INTEGER(bLiteral), .a = TOY_AS_INTEGER(aLiteral) }; //actually set - Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral); - Box_setTextEngineNode(node, font, Toy_toCString(TOY_AS_STRING(textLiteral)), color); + Box_Node* node = (Box_Node*)TOY_AS_OPAQUE(nodeLiteral); + Box_setTextNode(node, font, Toy_toCString(TOY_AS_STRING(textLiteral)), color); //cleanup TTF_CloseFont(font); @@ -1071,7 +1071,7 @@ static int nativeCallNodeFn(Toy_Interpreter* interpreter, Toy_LiteralArray* argu Toy_Literal fnNameIdentifier = TOY_TO_IDENTIFIER_LITERAL(Toy_copyRefString(TOY_AS_STRING(fnName))); //call the function - Toy_Literal result = Box_callEngineNodeLiteral(TOY_AS_OPAQUE(nodeLiteral), interpreter, fnNameIdentifier, &extraArgs); + Toy_Literal result = Box_callNodeLiteral(TOY_AS_OPAQUE(nodeLiteral), interpreter, fnNameIdentifier, &extraArgs); Toy_pushLiteralArray(&interpreter->stack, result);