Added animations to node
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="assets\scripts\entity.toy" />
|
<None Include="assets\scripts\entity.toy" />
|
||||||
|
<None Include="assets\scripts\frames.toy" />
|
||||||
<None Include="assets\scripts\init.toy" />
|
<None Include="assets\scripts\init.toy" />
|
||||||
<None Include="assets\scripts\scene.toy" />
|
<None Include="assets\scripts\scene.toy" />
|
||||||
<None Include="assets\scripts\tilemap\layer-background.toy" />
|
<None Include="assets\scripts\tilemap\layer-background.toy" />
|
||||||
|
|||||||
2
Toy
2
Toy
Submodule Toy updated: 9b673f23ad...e243ad949a
22
assets/scripts/frames.toy
Normal file
22
assets/scripts/frames.toy
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import node;
|
||||||
|
|
||||||
|
fn onInit(node: opaque) {
|
||||||
|
node.loadTexture("sprites:/frametest.png");
|
||||||
|
|
||||||
|
//mapped to the given image
|
||||||
|
node.setNodeRect(0, 0, 32, 32);
|
||||||
|
node.setNodeFrames(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
fn onStep(node: opaque) {
|
||||||
|
counter++;
|
||||||
|
if (counter >= 60) {
|
||||||
|
counter = 0;
|
||||||
|
node.incrementCurrentNodeFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn onDraw(node: opaque) {
|
||||||
|
node.drawNode(0, 0);
|
||||||
|
}
|
||||||
@@ -28,4 +28,4 @@ mapInputEventToKeyUp("character_right", "right"); //event, keysym
|
|||||||
initWindow("Airport Game", 1080, 720, false);
|
initWindow("Airport Game", 1080, 720, false);
|
||||||
|
|
||||||
//kick off the logic of the scene graph
|
//kick off the logic of the scene graph
|
||||||
loadRootNode("scripts:/scene.toy");
|
loadRootNode("scripts:/frames.toy");
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
|||||||
//render each tile
|
//render each tile
|
||||||
for (var j = lowerY; j <= upperY; j++) {
|
for (var j = lowerY; j <= upperY; j++) {
|
||||||
for (var i = lowerX; i <= upperX; i++) {
|
for (var i = lowerX; i <= upperX; i++) {
|
||||||
node.getNodeChild(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
node.getChildNode(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.getNodeChild(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
node.getChildNode(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import standard;
|
import standard;
|
||||||
import node;
|
import node;
|
||||||
|
|
||||||
|
//TODO: get child count
|
||||||
var childCounter: int = 0;
|
var childCounter: int = 0;
|
||||||
|
|
||||||
var levelXCount: int const = 4;
|
var levelXCount: int const = 4;
|
||||||
@@ -49,7 +50,7 @@ fn onDraw(node: opaque) {
|
|||||||
|
|
||||||
//iterate over each layer, passing in the screen dimensions
|
//iterate over each layer, passing in the screen dimensions
|
||||||
for (var c = 0; c < childCounter; c++) {
|
for (var c = 0; c < childCounter; c++) {
|
||||||
node.getNodeChild(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 2);
|
node.getChildNode(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
assets/sprites/frametest.png
Normal file
BIN
assets/sprites/frametest.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 404 B |
@@ -13,6 +13,8 @@ void Box_initEngineNode(Box_EngineNode* node, Toy_Interpreter* interpreter, cons
|
|||||||
node->capacity = 0;
|
node->capacity = 0;
|
||||||
node->count = 0;
|
node->count = 0;
|
||||||
node->texture = NULL;
|
node->texture = NULL;
|
||||||
|
node->rect = ((SDL_Rect) { 0, 0, 0, 0 });
|
||||||
|
node->frames = 0;
|
||||||
|
|
||||||
Toy_initLiteralDictionary(node->functions);
|
Toy_initLiteralDictionary(node->functions);
|
||||||
|
|
||||||
@@ -205,6 +207,7 @@ int Box_loadTextureEngineNode(Box_EngineNode* node, const char* fname) {
|
|||||||
SDL_QueryTexture(node->texture, NULL, NULL, &w, &h);
|
SDL_QueryTexture(node->texture, NULL, NULL, &w, &h);
|
||||||
SDL_Rect r = { 0, 0, w, h };
|
SDL_Rect r = { 0, 0, w, h };
|
||||||
Box_setRectEngineNode(node, r);
|
Box_setRectEngineNode(node, r);
|
||||||
|
Box_setFramesEngineNode(node, 1); //default
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -220,6 +223,36 @@ void Box_setRectEngineNode(Box_EngineNode* node, SDL_Rect rect) {
|
|||||||
node->rect = rect;
|
node->rect = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest) {
|
BOX_API SDL_Rect Box_getRectEngineNode(Box_EngineNode* node) {
|
||||||
SDL_RenderCopy(engine.renderer, node->texture, &node->rect, &dest);
|
return node->rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOX_API void Box_setFramesEngineNode(Box_EngineNode* node, int frames) {
|
||||||
|
node->frames = frames;
|
||||||
|
node->currentFrame = 0; //just in case
|
||||||
|
}
|
||||||
|
|
||||||
|
BOX_API int Box_getFramesEngineNode(Box_EngineNode* node) {
|
||||||
|
return node->frames;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOX_API void Box_setCurrentFrameEngineNode(Box_EngineNode* node, int currentFrame) {
|
||||||
|
node->currentFrame = currentFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOX_API int Box_getCurrentFrameEngineNode(Box_EngineNode* node) {
|
||||||
|
return node->currentFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOX_API void Box_incrementCurrentFrame(Box_EngineNode* node) {
|
||||||
|
node->currentFrame++;
|
||||||
|
if (node->currentFrame >= node->frames) {
|
||||||
|
node->currentFrame = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest) {
|
||||||
|
SDL_Rect src = node->rect;
|
||||||
|
src.x += src.w * node->currentFrame; //TODO: improve this
|
||||||
|
SDL_RenderCopy(engine.renderer, node->texture, &src, &dest);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ typedef struct Box_private_engineNode {
|
|||||||
|
|
||||||
//my opaque type tag
|
//my opaque type tag
|
||||||
int tag;
|
int tag;
|
||||||
// int _unused0;
|
|
||||||
|
|
||||||
//use Toy's memory model
|
//use Toy's memory model
|
||||||
Box_EngineNode** children;
|
Box_EngineNode** children;
|
||||||
@@ -34,16 +33,18 @@ typedef struct Box_private_engineNode {
|
|||||||
//rendering-specific features
|
//rendering-specific features
|
||||||
SDL_Texture* texture;
|
SDL_Texture* texture;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
//TODO: depth
|
int frames;
|
||||||
} Box_EngineNode;
|
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_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_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 and tombstone this node
|
BOX_API void Box_freeEngineNode(Box_EngineNode* node); //free this node and all children
|
||||||
|
|
||||||
BOX_API Toy_Literal Box_callEngineNodeLiteral(Box_EngineNode* node, Toy_Interpreter* interpreter, Toy_Literal key, Toy_LiteralArray* args);
|
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
|
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_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 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
|
||||||
|
|
||||||
@@ -51,5 +52,12 @@ BOX_API int Box_loadTextureEngineNode(Box_EngineNode* node, const char* fname);
|
|||||||
BOX_API void Box_freeTextureEngineNode(Box_EngineNode* node);
|
BOX_API void Box_freeTextureEngineNode(Box_EngineNode* node);
|
||||||
|
|
||||||
BOX_API void Box_setRectEngineNode(Box_EngineNode* node, SDL_Rect rect);
|
BOX_API void Box_setRectEngineNode(Box_EngineNode* node, SDL_Rect rect);
|
||||||
//TODO: getRect
|
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_drawEngineNode(Box_EngineNode* node, SDL_Rect dest);
|
BOX_API void Box_drawEngineNode(Box_EngineNode* node, SDL_Rect dest);
|
||||||
|
|||||||
392
box/lib_node.c
392
box/lib_node.c
@@ -113,6 +113,97 @@ static int nativeInitNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nativePushNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
//checks
|
||||||
|
if (arguments->count != 2) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to pushNode\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toy_Literal child = Toy_popLiteralArray(arguments);
|
||||||
|
Toy_Literal parent = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal parentIdn = parent;
|
||||||
|
if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) {
|
||||||
|
Toy_freeLiteral(parentIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
Toy_Literal childIdn = child;
|
||||||
|
if (TOY_IS_IDENTIFIER(child) && Toy_parseIdentifierToValue(interpreter, &child)) {
|
||||||
|
Toy_freeLiteral(childIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TOY_IS_OPAQUE(parent) || !TOY_IS_OPAQUE(child)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to pushNode\n");
|
||||||
|
Toy_freeLiteral(parent);
|
||||||
|
Toy_freeLiteral(child);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//push the node
|
||||||
|
Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent);
|
||||||
|
Box_EngineNode* childNode = TOY_AS_OPAQUE(child);
|
||||||
|
|
||||||
|
Box_pushEngineNode(parentNode, childNode);
|
||||||
|
|
||||||
|
//no return value
|
||||||
|
Toy_freeLiteral(parent);
|
||||||
|
Toy_freeLiteral(child);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeGetChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
//checks
|
||||||
|
if (arguments->count != 2) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to getChildNode\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toy_Literal index = Toy_popLiteralArray(arguments);
|
||||||
|
Toy_Literal parent = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal parentIdn = parent;
|
||||||
|
if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) {
|
||||||
|
Toy_freeLiteral(parentIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
Toy_Literal indexIdn = index;
|
||||||
|
if (TOY_IS_IDENTIFIER(index) && Toy_parseIdentifierToValue(interpreter, &index)) {
|
||||||
|
Toy_freeLiteral(indexIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TOY_IS_OPAQUE(parent) || !TOY_IS_INTEGER(index)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to getChildNode\n");
|
||||||
|
Toy_freeLiteral(parent);
|
||||||
|
Toy_freeLiteral(index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//push the node
|
||||||
|
Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent);
|
||||||
|
int intIndex = TOY_AS_INTEGER(index);
|
||||||
|
|
||||||
|
if (intIndex < 0 || intIndex >= parentNode->count) {
|
||||||
|
interpreter->errorOutput("index out of bounds in getChildNode\n");
|
||||||
|
Toy_freeLiteral(parent);
|
||||||
|
Toy_freeLiteral(index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Box_EngineNode* childNode = parentNode->children[intIndex];
|
||||||
|
Toy_Literal child = TOY_TO_OPAQUE_LITERAL(childNode, childNode->tag);
|
||||||
|
|
||||||
|
Toy_pushLiteralArray(&interpreter->stack, child);
|
||||||
|
|
||||||
|
//no return value
|
||||||
|
Toy_freeLiteral(parent);
|
||||||
|
Toy_freeLiteral(child);
|
||||||
|
Toy_freeLiteral(index);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int nativeFreeChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeFreeChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
if (arguments->count != 2) {
|
if (arguments->count != 2) {
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to freeChildNode\n");
|
interpreter->errorOutput("Incorrect number of arguments passed to freeChildNode\n");
|
||||||
@@ -162,101 +253,10 @@ static int nativeFreeChildNode(Toy_Interpreter* interpreter, Toy_LiteralArray* a
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nativePushNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeGetParentNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
//checks
|
|
||||||
if (arguments->count != 2) {
|
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to pushNode\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toy_Literal child = Toy_popLiteralArray(arguments);
|
|
||||||
Toy_Literal parent = Toy_popLiteralArray(arguments);
|
|
||||||
|
|
||||||
Toy_Literal parentIdn = parent;
|
|
||||||
if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) {
|
|
||||||
Toy_freeLiteral(parentIdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
Toy_Literal childIdn = child;
|
|
||||||
if (TOY_IS_IDENTIFIER(child) && Toy_parseIdentifierToValue(interpreter, &child)) {
|
|
||||||
Toy_freeLiteral(childIdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TOY_IS_OPAQUE(parent) || !TOY_IS_OPAQUE(child)) {
|
|
||||||
interpreter->errorOutput("Incorrect argument type passed to pushNode\n");
|
|
||||||
Toy_freeLiteral(parent);
|
|
||||||
Toy_freeLiteral(child);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//push the node
|
|
||||||
Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent);
|
|
||||||
Box_EngineNode* childNode = TOY_AS_OPAQUE(child);
|
|
||||||
|
|
||||||
Box_pushEngineNode(parentNode, childNode);
|
|
||||||
|
|
||||||
//no return value
|
|
||||||
Toy_freeLiteral(parent);
|
|
||||||
Toy_freeLiteral(child);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nativeGetNodeChild(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
|
||||||
//checks
|
|
||||||
if (arguments->count != 2) {
|
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to getNodeChild\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toy_Literal index = Toy_popLiteralArray(arguments);
|
|
||||||
Toy_Literal parent = Toy_popLiteralArray(arguments);
|
|
||||||
|
|
||||||
Toy_Literal parentIdn = parent;
|
|
||||||
if (TOY_IS_IDENTIFIER(parent) && Toy_parseIdentifierToValue(interpreter, &parent)) {
|
|
||||||
Toy_freeLiteral(parentIdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
Toy_Literal indexIdn = index;
|
|
||||||
if (TOY_IS_IDENTIFIER(index) && Toy_parseIdentifierToValue(interpreter, &index)) {
|
|
||||||
Toy_freeLiteral(indexIdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TOY_IS_OPAQUE(parent) || !TOY_IS_INTEGER(index)) {
|
|
||||||
interpreter->errorOutput("Incorrect argument type passed to getNodeChild\n");
|
|
||||||
Toy_freeLiteral(parent);
|
|
||||||
Toy_freeLiteral(index);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//push the node
|
|
||||||
Box_EngineNode* parentNode = TOY_AS_OPAQUE(parent);
|
|
||||||
int intIndex = TOY_AS_INTEGER(index);
|
|
||||||
|
|
||||||
if (intIndex < 0 || intIndex >= parentNode->count) {
|
|
||||||
interpreter->errorOutput("index out of bounds in getNodeChild\n");
|
|
||||||
Toy_freeLiteral(parent);
|
|
||||||
Toy_freeLiteral(index);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Box_EngineNode* childNode = parentNode->children[intIndex];
|
|
||||||
Toy_Literal child = TOY_TO_OPAQUE_LITERAL(childNode, childNode->tag);
|
|
||||||
|
|
||||||
Toy_pushLiteralArray(&interpreter->stack, child);
|
|
||||||
|
|
||||||
//no return value
|
|
||||||
Toy_freeLiteral(parent);
|
|
||||||
Toy_freeLiteral(child);
|
|
||||||
Toy_freeLiteral(index);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nativeGetNodeParent(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
|
||||||
//checks
|
//checks
|
||||||
if (arguments->count != 1) {
|
if (arguments->count != 1) {
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to getNodeParent\n");
|
interpreter->errorOutput("Incorrect number of arguments passed to getParentNode\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ static int nativeGetNodeParent(Toy_Interpreter* interpreter, Toy_LiteralArray* a
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
interpreter->errorOutput("Incorrect argument type passed to getNodeParent\n");
|
interpreter->errorOutput("Incorrect argument type passed to getParentNode\n");
|
||||||
Toy_freeLiteral(nodeLiteral);
|
Toy_freeLiteral(nodeLiteral);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -384,9 +384,9 @@ static int nativeFreeTexture(Toy_Interpreter* interpreter, Toy_LiteralArray* arg
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nativeSetRect(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeSetNodeRect(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
if (arguments->count != 5) {
|
if (arguments->count != 5) {
|
||||||
interpreter->errorOutput("Incorrect number of arguments passed to setRect\n");
|
interpreter->errorOutput("Incorrect number of arguments passed to setNodeRect\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +424,7 @@ static int nativeSetRect(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
|
|||||||
|
|
||||||
//check argument types
|
//check argument types
|
||||||
if (!TOY_IS_OPAQUE(nodeLiteral) || !TOY_IS_INTEGER(x) || !TOY_IS_INTEGER(y) || !TOY_IS_INTEGER(w) || !TOY_IS_INTEGER(h)) {
|
if (!TOY_IS_OPAQUE(nodeLiteral) || !TOY_IS_INTEGER(x) || !TOY_IS_INTEGER(y) || !TOY_IS_INTEGER(w) || !TOY_IS_INTEGER(h)) {
|
||||||
interpreter->errorOutput("Incorrect argument type passed to setRect\n");
|
interpreter->errorOutput("Incorrect argument type passed to setNodeRect\n");
|
||||||
Toy_freeLiteral(nodeLiteral);
|
Toy_freeLiteral(nodeLiteral);
|
||||||
Toy_freeLiteral(x);
|
Toy_freeLiteral(x);
|
||||||
Toy_freeLiteral(y);
|
Toy_freeLiteral(y);
|
||||||
@@ -449,7 +449,187 @@ static int nativeSetRect(Toy_Interpreter* interpreter, Toy_LiteralArray* argumen
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: get x, y, w, h
|
static int nativeSetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 2) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to setNodeFrames\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal framesLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
Toy_Literal frameLiteralIdn = framesLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(framesLiteral) && Toy_parseIdentifierToValue(interpreter, &framesLiteral)) {
|
||||||
|
Toy_freeLiteral(frameLiteralIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral) || !TOY_IS_INTEGER(framesLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to setNodeFrames\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(framesLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually set
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
|
||||||
|
Box_setFramesEngineNode(node, TOY_AS_INTEGER(framesLiteral));
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(framesLiteral);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeGetNodeFrames(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 1) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to getNodeFrames\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to getNodeFrames\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually get
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
Toy_Literal framesLiteral = TOY_TO_INTEGER_LITERAL(node->frames);
|
||||||
|
|
||||||
|
Toy_pushLiteralArray(interpreter, framesLiteral);
|
||||||
|
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(framesLiteral);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeSetCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 2) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to setCurrentNodeFrame\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal currentFrameLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
Toy_Literal currentFrameLiteralIdn = currentFrameLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(currentFrameLiteral) && Toy_parseIdentifierToValue(interpreter, ¤tFrameLiteral)) {
|
||||||
|
Toy_freeLiteral(currentFrameLiteralIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral) || !TOY_IS_INTEGER(currentFrameLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to setCurrentNodeFrame\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(currentFrameLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually set
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
|
||||||
|
Box_setFramesEngineNode(node, TOY_AS_INTEGER(currentFrameLiteral));
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(currentFrameLiteral);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeGetCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 1) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to getCurrentNodeFrame\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to getCurrentNodeFrame\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually get
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
Toy_Literal currentFrameLiteral = TOY_TO_INTEGER_LITERAL(node->currentFrame);
|
||||||
|
|
||||||
|
Toy_pushLiteralArray(interpreter, currentFrameLiteral);
|
||||||
|
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
Toy_freeLiteral(currentFrameLiteral);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nativeIncrementCurrentNodeFrame(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
|
if (arguments->count != 1) {
|
||||||
|
interpreter->errorOutput("Incorrect number of arguments passed to incrementCurrentNodeFrame\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the arguments
|
||||||
|
Toy_Literal nodeLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal nodeIdn = nodeLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(nodeLiteral) && Toy_parseIdentifierToValue(interpreter, &nodeLiteral)) {
|
||||||
|
Toy_freeLiteral(nodeIdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
//check argument types
|
||||||
|
if (!TOY_IS_OPAQUE(nodeLiteral)) {
|
||||||
|
interpreter->errorOutput("Incorrect argument type passed to incrementCurrentNodeFrame\n");
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//actually get
|
||||||
|
Box_EngineNode* node = (Box_EngineNode*)TOY_AS_OPAQUE(nodeLiteral);
|
||||||
|
|
||||||
|
Box_incrementCurrentFrame(node);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
Toy_freeLiteral(nodeLiteral);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int nativeDrawNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
static int nativeDrawNode(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
|
||||||
if (arguments->count != 3 && arguments->count != 5) {
|
if (arguments->count != 3 && arguments->count != 5) {
|
||||||
@@ -614,17 +794,23 @@ int Box_hookNode(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Liter
|
|||||||
Natives natives[] = {
|
Natives natives[] = {
|
||||||
{"loadNode", nativeLoadNode},
|
{"loadNode", nativeLoadNode},
|
||||||
{"initNode", nativeInitNode},
|
{"initNode", nativeInitNode},
|
||||||
{"freeChildNode", nativeFreeChildNode},
|
|
||||||
{"pushNode", nativePushNode},
|
{"pushNode", nativePushNode},
|
||||||
{"getNodeChild", nativeGetNodeChild},
|
{"getChildNode", nativeGetChildNode},
|
||||||
{"getNodeParent", nativeGetNodeParent},
|
{"freeChildNode", nativeFreeChildNode},
|
||||||
|
{"getParentNode", nativeGetParentNode},
|
||||||
{"loadTexture", nativeLoadTexture},
|
{"loadTexture", nativeLoadTexture},
|
||||||
{"freeTexture", nativeFreeTexture},
|
{"freeTexture", nativeFreeTexture},
|
||||||
{"setRect", nativeSetRect},
|
{"setNodeRect", nativeSetNodeRect},
|
||||||
|
//get rect
|
||||||
|
{"setNodeFrames", nativeSetNodeFrames},
|
||||||
|
{"getNodeFrames", nativeGetNodeFrames},
|
||||||
|
{"setCurrentNodeFrame", nativeSetCurrentNodeFrame},
|
||||||
|
{"getCurrentNodeFrame", nativeGetCurrentNodeFrame},
|
||||||
|
{"incrementCurrentNodeFrame", nativeIncrementCurrentNodeFrame},
|
||||||
{"drawNode", nativeDrawNode},
|
{"drawNode", nativeDrawNode},
|
||||||
{"callNodeFn", nativeCallNodeFn},
|
{"callNodeFn", nativeCallNodeFn},
|
||||||
|
|
||||||
//get rect, get node var, create empty node, get child count, get root node
|
//TODO: get rect, get node var, create empty node, get child count, get root node
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user