From 097fa7d4ce3ed5d3654fa159f3d41a8604f6ab5e Mon Sep 17 00:00:00 2001 From: Axanery <41282531+Axanery@users.noreply.github.com> Date: Wed, 8 Nov 2023 13:01:57 -0500 Subject: [PATCH 1/2] Update SceneConfig and Animator Functionality --- source/Engine/Application.cpp | 9 ++- source/Engine/Bytecode/Compiler.cpp | 2 +- source/Engine/Bytecode/StandardLibrary.cpp | 70 ++++++++++++++++++++-- source/Engine/Scene.cpp | 4 +- 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/source/Engine/Application.cpp b/source/Engine/Application.cpp index f7b38576..3341610b 100644 --- a/source/Engine/Application.cpp +++ b/source/Engine/Application.cpp @@ -1407,7 +1407,7 @@ PUBLIC STATIC void Application::LoadSceneInfo() { if (stgElement->attributes.Exists("folder")) XMLParser::CopyTokenToString(stgElement->attributes.Get("folder"), scene.folder, sizeof(scene.folder)); else - // Accounts for scenes placed in the root of the Scenes folder if the file type is not "bin" + // Accounts for scenes placed in the root of the Scenes folder scene.folder[0] = '\0'; if (stgElement->attributes.Exists("id")) @@ -1425,6 +1425,13 @@ PUBLIC STATIC void Application::LoadSceneInfo() { else snprintf(scene.fileType, sizeof(scene.fileType), "bin"); + if (stgElement->attributes.Exists("filter")) + Scene::Filter = XMLParser::TokenToNumber(stgElement->attributes.Get("filter")); + else + Scene::Filter = 0xFF; + if (Scene::Filter == 0x00) + Scene::Filter = 0xFF; + Scene::ListData.push_back(scene); category.sceneCount++; Scene::StageCount++; diff --git a/source/Engine/Bytecode/Compiler.cpp b/source/Engine/Bytecode/Compiler.cpp index 31baddd0..d5f42ae6 100644 --- a/source/Engine/Bytecode/Compiler.cpp +++ b/source/Engine/Bytecode/Compiler.cpp @@ -1329,7 +1329,7 @@ PUBLIC void Compiler::GetUnary(bool canAssign) { case TOKEN_LOGICAL_NOT: EmitByte(OP_LG_NOT); break; case TOKEN_TYPEOF: EmitByte(OP_TYPEOF); break; - // HACK: replace these with prefix version of OP + // TODO: replace these with prefix version of OP // case TOKEN_INCREMENT: EmitByte(OP_INCREMENT); break; // case TOKEN_DECREMENT: EmitByte(OP_DECREMENT); break; default: diff --git a/source/Engine/Bytecode/StandardLibrary.cpp b/source/Engine/Bytecode/StandardLibrary.cpp index beb7eedb..337e337b 100644 --- a/source/Engine/Bytecode/StandardLibrary.cpp +++ b/source/Engine/Bytecode/StandardLibrary.cpp @@ -463,6 +463,21 @@ VMValue Animator_Create(int argCount, VMValue* args, Uint32 threadID) { return INTEGER_VAL((int)index); } +/*** + * Animator.Remove + * \desc Removes an animator. + * \param animator (Integer): The index of the animator. + * \ns Animator + */ +VMValue Animator_Remove(int argCount, VMValue* args, Uint32 threadID) { + CHECK_ARGCOUNT(1); + int animator = GET_ARG(0, GetInteger); + if (!Scene::AnimatorList[animator]) + return NULL_VAL; + delete Scene::AnimatorList[animator]; + Scene::AnimatorList[animator] = NULL; + return NULL_VAL; +} /*** * Animator.SetAnimation * \desc Sets the current animation and frame of an animator. @@ -8211,8 +8226,8 @@ VMValue Scene_ObjectTileCollision(int argCount, VMValue* args, Uint32 threadID) int cLayers = GET_ARG(1, GetInteger); int cMode = GET_ARG(2, GetInteger); int cPlane = GET_ARG(3, GetInteger); - int xOffset = GET_ARG(4, GetDecimal); - int yOffset = GET_ARG(5, GetDecimal); + int xOffset = (int)GET_ARG(4, GetDecimal); + int yOffset = (int)GET_ARG(5, GetDecimal); int setPos = GET_ARG(6, GetInteger); auto ent = (Entity*)entity->EntityPtr; @@ -8238,8 +8253,8 @@ VMValue Scene_ObjectTileGrip(int argCount, VMValue* args, Uint32 threadID) { int cLayers = GET_ARG(1, GetInteger); int cMode = GET_ARG(2, GetInteger); int cPlane = GET_ARG(3, GetInteger); - float xOffset = GET_ARG(4, GetDecimal); - float yOffset = GET_ARG(5, GetDecimal); + int xOffset = (int)GET_ARG(4, GetDecimal); + int yOffset = (int)GET_ARG(5, GetDecimal); float tolerance = GET_ARG(6, GetDecimal); auto ent = (Entity*)entity->EntityPtr; @@ -13281,6 +13296,49 @@ VMValue View_SetZ(int argCount, VMValue* args, Uint32 threadID) { Scene::Views[view_index].Z = value; return NULL_VAL; } +/*** +View.AdjustX +* \desc Adjusts the x - axis position of the camera for the specified view by an amount. +* \param viewIndex(Integer) : Index of the view. +* \param x(Number) : Desired X adjust amount. +* \ns View +*/ +VMValue View_AdjustX(int argCount, VMValue * args, Uint32 threadID) { + CHECK_ARGCOUNT(2); + int view_index = GET_ARG(0, GetInteger); + CHECK_VIEW_INDEX(); + Scene::Views[view_index].X += GET_ARG(1, GetDecimal); + return NULL_VAL; +} +/*** +* View.AdjustY +* \desc Adjusts the y-axis position of the camera for the specified view by an amount. +* \param viewIndex (Integer): Index of the view. +* \param y (Number): Desired Y adjust amount. +* \ns View +*/ +VMValue View_AdjustY(int argCount, VMValue * args, Uint32 threadID) { + CHECK_ARGCOUNT(2); + int view_index = GET_ARG(0, GetInteger); + CHECK_VIEW_INDEX(); + Scene::Views[view_index].Y += GET_ARG(1, GetDecimal); + return NULL_VAL; +} +/*** +* View.AdjustX +* \desc Adjusts the z-axis position of the camera for the specified view by an amount. +* \param viewIndex (Integer): Index of the view. +* \param z (Number): Desired Z adjust amount. +* \ns View +*/ +VMValue View_AdjustZ(int argCount, VMValue * args, Uint32 threadID) { + CHECK_ARGCOUNT(2); + int view_index = GET_ARG(0, GetInteger); + CHECK_VIEW_INDEX(); + Scene::Views[view_index].Z += GET_ARG(1, GetDecimal); + return NULL_VAL; +} + /*** * View.SetPosition * \desc Sets the position of the camera for the specified view. @@ -14055,6 +14113,7 @@ PUBLIC STATIC void StandardLibrary::Link() { // #region Animator INIT_CLASS(Animator); DEF_NATIVE(Animator, Create); + DEF_NATIVE(Animator, Remove); DEF_NATIVE(Animator, SetAnimation); DEF_NATIVE(Animator, Animate); DEF_NATIVE(Animator, GetSprite); @@ -15760,6 +15819,9 @@ PUBLIC STATIC void StandardLibrary::Link() { DEF_NATIVE(View, SetX); DEF_NATIVE(View, SetY); DEF_NATIVE(View, SetZ); + DEF_NATIVE(View, AdjustX); + DEF_NATIVE(View, AdjustY); + DEF_NATIVE(View, AdjustZ); DEF_NATIVE(View, SetPosition); DEF_NATIVE(View, SetAngle); DEF_NATIVE(View, SetSize); diff --git a/source/Engine/Scene.cpp b/source/Engine/Scene.cpp index 50d400ce..90e0c133 100644 --- a/source/Engine/Scene.cpp +++ b/source/Engine/Scene.cpp @@ -3251,7 +3251,7 @@ PUBLIC STATIC bool Scene::CheckObjectCollisionPlatform(Entity* thisEntity, Colli return collided; } -PUBLIC STATIC bool Scene::ObjectTileCollision(Entity* entity, int cLayers, int cMode, int cPlane, int xOffset, int yOffset, bool setPos) { +PUBLIC STATIC bool Scene::ObjectTileCollision(Enxztity* entity, int cLayers, int cMode, int cPlane, int xOffset, int yOffset, bool setPos) { int layerID = 1; bool collided = false; int posX = xOffset + entity->X; @@ -3457,7 +3457,7 @@ PUBLIC STATIC bool Scene::ObjectTileCollision(Entity* entity, int cLayers, int c } } -PUBLIC STATIC bool Scene::ObjectTileGrip(Entity* entity, int cLayers, int cMode, int cPlane, float xOffset, float yOffset, float tolerance) { +PUBLIC STATIC bool Scene::ObjectTileGrip(Entity* entity, int cLayers, int cMode, int cPlane, int xOffset, int yOffset, float tolerance) { int layerID = 1; bool collided = false; int posX = xOffset + entity->X; From e9ce2f28be666511d14bb286262851a335df804e Mon Sep 17 00:00:00 2001 From: Axanery <41282531+Axanery@users.noreply.github.com> Date: Wed, 8 Nov 2023 13:06:56 -0500 Subject: [PATCH 2/2] Fix Entity Error --- source/Engine/Scene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Engine/Scene.cpp b/source/Engine/Scene.cpp index 8c6013ae..e1f16f34 100644 --- a/source/Engine/Scene.cpp +++ b/source/Engine/Scene.cpp @@ -3362,7 +3362,7 @@ PUBLIC STATIC bool Scene::CheckObjectCollisionPlatform(Entity* thisEntity, Colli return collided; } -PUBLIC STATIC bool Scene::ObjectTileCollision(Enxztity* entity, int cLayers, int cMode, int cPlane, int xOffset, int yOffset, bool setPos) { +PUBLIC STATIC bool Scene::ObjectTileCollision(Entity* entity, int cLayers, int cMode, int cPlane, int xOffset, int yOffset, bool setPos) { int layerID = 1; bool collided = false; int posX = xOffset + entity->X;