From 25a17c3619356dff101652ed067aca16d78a516f Mon Sep 17 00:00:00 2001 From: Nicholas Logan Date: Sat, 1 Jan 2022 16:09:18 -0500 Subject: [PATCH 1/2] Added ObjParticleList_SetAutoClearInstance and machine nullptr check in BaseFunction::_null_check --- source/GcLib/directx/DxObject.cpp | 8 ++++++-- source/GcLib/directx/DxScript.cpp | 13 +++++++++++++ source/GcLib/directx/DxScript.hpp | 1 + source/GcLib/directx/RenderObject.cpp | 1 + source/GcLib/directx/RenderObject.hpp | 4 ++++ source/GcLib/gstd/Script/ScriptFunction.cpp | 1 + 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/source/GcLib/directx/DxObject.cpp b/source/GcLib/directx/DxObject.cpp index 58e56ca7..7fdb8c46 100644 --- a/source/GcLib/directx/DxObject.cpp +++ b/source/GcLib/directx/DxObject.cpp @@ -484,7 +484,9 @@ void DxScriptParticleListObject2D::SetRenderState() { graphics->SetTextureFilter(filterMin_, filterMag_, filterMip_); } void DxScriptParticleListObject2D::CleanUp() { - GetParticlePointer()->ClearInstance(); + ParticleRenderer2D* obj = GetParticlePointer(); + if (obj->GetAutoClearInstance()) + obj->ClearInstance(); } //**************************************************************************** @@ -527,7 +529,9 @@ void DxScriptParticleListObject3D::SetRenderState() { graphics->SetTextureFilter(filterMin_, filterMag_, filterMip_); } void DxScriptParticleListObject3D::CleanUp() { - GetParticlePointer()->ClearInstance(); + ParticleRenderer3D* obj = GetParticlePointer(); + if (obj->GetAutoClearInstance()) + obj->ClearInstance(); } //**************************************************************************** diff --git a/source/GcLib/directx/DxScript.cpp b/source/GcLib/directx/DxScript.cpp index 0592b286..e48e22c4 100644 --- a/source/GcLib/directx/DxScript.cpp +++ b/source/GcLib/directx/DxScript.cpp @@ -402,6 +402,7 @@ static const std::vector dxFunction = { { "ObjParticleList_SetExtraData", DxScript::Func_ObjParticleList_SetExtraData, 4 }, { "ObjParticleList_AddInstance", DxScript::Func_ObjParticleList_AddInstance, 1 }, { "ObjParticleList_ClearInstance", DxScript::Func_ObjParticleList_ClearInstance, 1 }, + { "ObjParticleList_SetAutoClearInstance", DxScript::Func_ObjParticleList_SetAutoClearInstance, 2 }, //Mesh object functions { "ObjMesh_Create", DxScript::Func_ObjMesh_Create, 0 }, @@ -4071,6 +4072,18 @@ value DxScript::Func_ObjParticleList_ClearInstance(script_machine* machine, int } return value(); } +value DxScript::Func_ObjParticleList_SetAutoClearInstance(script_machine* machine, int argc, const value* argv) { + DxScript* script = (DxScript*)machine->data; + int id = argv[0].as_int(); + + DxScriptPrimitiveObject* obj = script->GetObjectPointerAs(id); + if (obj) { + ParticleRendererBase* objParticle = dynamic_cast(obj->GetObjectPointer()); + if (objParticle) + objParticle->SetAutoClearInstance(argv[1].as_boolean()); + } + return value(); +} //Dx関数:オブジェクト操作(DxMesh) value DxScript::Func_ObjMesh_Create(script_machine* machine, int argc, const value* argv) { diff --git a/source/GcLib/directx/DxScript.hpp b/source/GcLib/directx/DxScript.hpp index 0c498ca9..4f3cb4e8 100644 --- a/source/GcLib/directx/DxScript.hpp +++ b/source/GcLib/directx/DxScript.hpp @@ -394,6 +394,7 @@ namespace directx { DNH_FUNCAPI_DECL_(Func_ObjParticleList_SetExtraData); DNH_FUNCAPI_DECL_(Func_ObjParticleList_AddInstance); DNH_FUNCAPI_DECL_(Func_ObjParticleList_ClearInstance); + DNH_FUNCAPI_DECL_(Func_ObjParticleList_SetAutoClearInstance); //Dx関数:オブジェクト操作(DxMesh) static gstd::value Func_ObjMesh_Create(gstd::script_machine* machine, int argc, const gstd::value* argv); diff --git a/source/GcLib/directx/RenderObject.cpp b/source/GcLib/directx/RenderObject.cpp index 6a0215bb..6fcfa236 100644 --- a/source/GcLib/directx/RenderObject.cpp +++ b/source/GcLib/directx/RenderObject.cpp @@ -1366,6 +1366,7 @@ void TrajectoryObject3D::AddPoint(const D3DXMATRIX& mat) { ParticleRendererBase::ParticleRendererBase() { countInstance_ = 0U; countInstancePrev_ = 0U; + autoClearInstance_ = true; instColor_ = 0xffffffff; instPosition_ = D3DXVECTOR3(0, 0, 0); instScale_ = D3DXVECTOR3(1, 1, 1); diff --git a/source/GcLib/directx/RenderObject.hpp b/source/GcLib/directx/RenderObject.hpp index b26a8e07..736ab025 100644 --- a/source/GcLib/directx/RenderObject.hpp +++ b/source/GcLib/directx/RenderObject.hpp @@ -358,6 +358,9 @@ namespace directx { void AddInstance(); void ClearInstance(); + void SetAutoClearInstance(bool clear) { autoClearInstance_ = clear; } + bool GetAutoClearInstance() { return autoClearInstance_; } + void SetInstanceColor(D3DCOLOR color) { instColor_ = color; } void SetInstanceColorRGB(int r, int g, int b); void SetInstanceColorRGB(D3DCOLOR color); @@ -383,6 +386,7 @@ namespace directx { size_t countInstance_; size_t countInstancePrev_; std::vector instanceData_; + bool autoClearInstance_; D3DCOLOR instColor_; D3DXVECTOR3 instPosition_; diff --git a/source/GcLib/gstd/Script/ScriptFunction.cpp b/source/GcLib/gstd/Script/ScriptFunction.cpp index c7d58a2a..400e3e38 100644 --- a/source/GcLib/gstd/Script/ScriptFunction.cpp +++ b/source/GcLib/gstd/Script/ScriptFunction.cpp @@ -311,6 +311,7 @@ namespace gstd { if (val == nullptr || !val->has_data()) { std::string error = StringUtility::Format("Unsupported operation: value is null\r\n"); if (machine) machine->raise_error(error); + else throw error; return false; } } From 773f661cc00b7e3f629d6c54c25c094b31dcb88e Mon Sep 17 00:00:00 2001 From: Nicholas Logan Date: Sat, 1 Jan 2022 19:08:01 -0500 Subject: [PATCH 2/2] Kinematics equations --- source/GcLib/gstd/GstdUtility.hpp | 48 ++++++++++++++++++++++++++++++ source/GcLib/gstd/ScriptClient.cpp | 27 +++++++++++++++++ source/GcLib/gstd/ScriptClient.hpp | 4 +++ 3 files changed, 79 insertions(+) diff --git a/source/GcLib/gstd/GstdUtility.hpp b/source/GcLib/gstd/GstdUtility.hpp index 0c4f82c3..0c8f5f45 100644 --- a/source/GcLib/gstd/GstdUtility.hpp +++ b/source/GcLib/gstd/GstdUtility.hpp @@ -415,6 +415,54 @@ namespace gstd { return DifferentialLinear; } }; + + class Kinematic { + public: + template + static inline T U_VAD(T v, T a, T d) { return sqrt(v * v - 2 * a * d); } + template + static inline T U_VAT(T v, T a, T t) { return v - a * t; } + template + static inline T U_VDT(T v, T d, T t) { return 2 * d / t - v; } + template + static inline T U_ADT(T a, T d, T t) { return d / t - a * t / 2; } + + template + static inline T V_UAD(T u, T a, T d) { return sqrt(u * u + 2 * a * d); } + template + static inline T V_UAT(T u, T a, T t) { return u + a * t; } + template + static inline T V_UDT(T u, T d, T t) { return 2 * d / t - u; } + template + static inline T V_ADT(T a, T d, T t) { return d / t + a * t / 2; } + + template + static inline T A_UVD(T u, T v, T d) { return (v * v - u * u) / (2 * d); } + template + static inline T A_UVT(T u, T v, T t) { return (v - u) / t; } + template + static inline T A_UDT(T u, T d, T t) { return 2 * (d - u * t) / (t * t); } + template + static inline T A_VDT(T v, T d, T t) { return 2 * (v * t - d) / (t * t); } + + template + static inline T D_UVA(T u, T v, T a) { return (v * v - u * u) / (2 * a); } + template + static inline T D_UVT(T u, T v, T t) { return t / 2 * (u + v); } + template + static inline T D_UAT(T u, T a, T t) { return u * t + a * t * t / 2; } + template + static inline T D_VAT(T v, T a, T t) { return v * t - a * t * t / 2; } + + template + static inline T T_UVA(T u, T v, T a) { return (v - u) / a; } + template + static inline T T_UVD(T u, T v, T d) { return 2 * d / (u + v); } + template + static inline T T_UAD(T u, T a, T d) { return (-u + sqrt(u * u + 2 * a * d)) / a; } + template + static inline T T_VAD(T v, T a, T d) { return (v - sqrt(v * v - 2 * a * d)) / a; } + }; }; #endif diff --git a/source/GcLib/gstd/ScriptClient.cpp b/source/GcLib/gstd/ScriptClient.cpp index d908da8a..ab42b5a3 100644 --- a/source/GcLib/gstd/ScriptClient.cpp +++ b/source/GcLib/gstd/ScriptClient.cpp @@ -189,6 +189,28 @@ static const std::vector commonFunction = { { "Interpolate_X_AngleR", ScriptClientBase::Func_Interpolate_X_Angle, 4 }, { "Interpolate_X_Array", ScriptClientBase::Func_Interpolate_X_Array, 3 }, + //Kinematics + { "Kinematic_U_VAD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_U_VAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_U_VDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_U_ADT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_UAD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_UAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_UDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_ADT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_UVD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_UVT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_UDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_VDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_UVA", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_UVT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_UAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_VAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_UVA", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_UVD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_UAD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_VAD", ScriptClientBase::Func_Kinematic, 3 }, + //Rotation { "Rotate2D", ScriptClientBase::Func_Rotate2D, 3 }, { "Rotate2D", ScriptClientBase::Func_Rotate2D, 5 }, @@ -1449,6 +1471,11 @@ value ScriptClientBase::Func_Interpolate_X_Array(script_machine* machine, int ar return _ScriptValueLerp(machine, &arr[from], &arr[to], x, lerpFunc); } +template +value ScriptClientBase::Func_Kinematic(script_machine* machine, int argc, const value* argv) { + return CreateRealValue(funcKinematic(argv[0].as_real(), argv[1].as_real(), argv[2].as_real())); +} + value ScriptClientBase::Func_Rotate2D(script_machine* machine, int argc, const value* argv) { double pos[2] = { argv[0].as_real(), argv[1].as_real() }; double ang = argv[2].as_real(); diff --git a/source/GcLib/gstd/ScriptClient.hpp b/source/GcLib/gstd/ScriptClient.hpp index 8d0b6824..a878b797 100644 --- a/source/GcLib/gstd/ScriptClient.hpp +++ b/source/GcLib/gstd/ScriptClient.hpp @@ -312,6 +312,10 @@ namespace gstd { DNH_FUNCAPI_DECL_(Func_Interpolate_X_Angle); DNH_FUNCAPI_DECL_(Func_Interpolate_X_Array); + //Math functions; kinematics + template + DNH_FUNCAPI_DECL_(Func_Kinematic); + //Math functions; rotation DNH_FUNCAPI_DECL_(Func_Rotate2D); DNH_FUNCAPI_DECL_(Func_Rotate3D);