Skip to content

Commit

Permalink
Merge pull request #8 from NicholasLogan/master
Browse files Browse the repository at this point in the history
Particle instance autoclear & machine nullptr
  • Loading branch information
nazjun authored Jan 2, 2022
2 parents dcec906 + 773f661 commit b9edd94
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/GcLib/directx/DxObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

//****************************************************************************
Expand Down Expand Up @@ -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();
}

//****************************************************************************
Expand Down
13 changes: 13 additions & 0 deletions source/GcLib/directx/DxScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ static const std::vector<function> 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 },
Expand Down Expand Up @@ -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<DxScriptPrimitiveObject>(id);
if (obj) {
ParticleRendererBase* objParticle = dynamic_cast<ParticleRendererBase*>(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) {
Expand Down
1 change: 1 addition & 0 deletions source/GcLib/directx/DxScript.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions source/GcLib/directx/RenderObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions source/GcLib/directx/RenderObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -383,6 +386,7 @@ namespace directx {
size_t countInstance_;
size_t countInstancePrev_;
std::vector<VERTEX_INSTANCE> instanceData_;
bool autoClearInstance_;

D3DCOLOR instColor_;
D3DXVECTOR3 instPosition_;
Expand Down
48 changes: 48 additions & 0 deletions source/GcLib/gstd/GstdUtility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,54 @@ namespace gstd {
return DifferentialLinear<T>;
}
};

class Kinematic {
public:
template<typename T>
static inline T U_VAD(T v, T a, T d) { return sqrt(v * v - 2 * a * d); }
template<typename T>
static inline T U_VAT(T v, T a, T t) { return v - a * t; }
template<typename T>
static inline T U_VDT(T v, T d, T t) { return 2 * d / t - v; }
template<typename T>
static inline T U_ADT(T a, T d, T t) { return d / t - a * t / 2; }

template<typename T>
static inline T V_UAD(T u, T a, T d) { return sqrt(u * u + 2 * a * d); }
template<typename T>
static inline T V_UAT(T u, T a, T t) { return u + a * t; }
template<typename T>
static inline T V_UDT(T u, T d, T t) { return 2 * d / t - u; }
template<typename T>
static inline T V_ADT(T a, T d, T t) { return d / t + a * t / 2; }

template<typename T>
static inline T A_UVD(T u, T v, T d) { return (v * v - u * u) / (2 * d); }
template<typename T>
static inline T A_UVT(T u, T v, T t) { return (v - u) / t; }
template<typename T>
static inline T A_UDT(T u, T d, T t) { return 2 * (d - u * t) / (t * t); }
template<typename T>
static inline T A_VDT(T v, T d, T t) { return 2 * (v * t - d) / (t * t); }

template<typename T>
static inline T D_UVA(T u, T v, T a) { return (v * v - u * u) / (2 * a); }
template<typename T>
static inline T D_UVT(T u, T v, T t) { return t / 2 * (u + v); }
template<typename T>
static inline T D_UAT(T u, T a, T t) { return u * t + a * t * t / 2; }
template<typename T>
static inline T D_VAT(T v, T a, T t) { return v * t - a * t * t / 2; }

template<typename T>
static inline T T_UVA(T u, T v, T a) { return (v - u) / a; }
template<typename T>
static inline T T_UVD(T u, T v, T d) { return 2 * d / (u + v); }
template<typename T>
static inline T T_UAD(T u, T a, T d) { return (-u + sqrt(u * u + 2 * a * d)) / a; }
template<typename T>
static inline T T_VAD(T v, T a, T d) { return (v - sqrt(v * v - 2 * a * d)) / a; }
};
};
#endif

Expand Down
1 change: 1 addition & 0 deletions source/GcLib/gstd/Script/ScriptFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
27 changes: 27 additions & 0 deletions source/GcLib/gstd/ScriptClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ static const std::vector<function> commonFunction = {
{ "Interpolate_X_AngleR", ScriptClientBase::Func_Interpolate_X_Angle<true>, 4 },
{ "Interpolate_X_Array", ScriptClientBase::Func_Interpolate_X_Array, 3 },

//Kinematics
{ "Kinematic_U_VAD", ScriptClientBase::Func_Kinematic<Math::Kinematic::U_VAD>, 3 },
{ "Kinematic_U_VAT", ScriptClientBase::Func_Kinematic<Math::Kinematic::U_VAT>, 3 },
{ "Kinematic_U_VDT", ScriptClientBase::Func_Kinematic<Math::Kinematic::U_VDT>, 3 },
{ "Kinematic_U_ADT", ScriptClientBase::Func_Kinematic<Math::Kinematic::U_ADT>, 3 },
{ "Kinematic_V_UAD", ScriptClientBase::Func_Kinematic<Math::Kinematic::V_UAD>, 3 },
{ "Kinematic_V_UAT", ScriptClientBase::Func_Kinematic<Math::Kinematic::V_UAT>, 3 },
{ "Kinematic_V_UDT", ScriptClientBase::Func_Kinematic<Math::Kinematic::V_UDT>, 3 },
{ "Kinematic_V_ADT", ScriptClientBase::Func_Kinematic<Math::Kinematic::V_ADT>, 3 },
{ "Kinematic_A_UVD", ScriptClientBase::Func_Kinematic<Math::Kinematic::A_UVD>, 3 },
{ "Kinematic_A_UVT", ScriptClientBase::Func_Kinematic<Math::Kinematic::A_UVT>, 3 },
{ "Kinematic_A_UDT", ScriptClientBase::Func_Kinematic<Math::Kinematic::A_UDT>, 3 },
{ "Kinematic_A_VDT", ScriptClientBase::Func_Kinematic<Math::Kinematic::A_VDT>, 3 },
{ "Kinematic_D_UVA", ScriptClientBase::Func_Kinematic<Math::Kinematic::D_UVA>, 3 },
{ "Kinematic_D_UVT", ScriptClientBase::Func_Kinematic<Math::Kinematic::D_UVT>, 3 },
{ "Kinematic_D_UAT", ScriptClientBase::Func_Kinematic<Math::Kinematic::D_UAT>, 3 },
{ "Kinematic_D_VAT", ScriptClientBase::Func_Kinematic<Math::Kinematic::D_VAT>, 3 },
{ "Kinematic_T_UVA", ScriptClientBase::Func_Kinematic<Math::Kinematic::T_UVA>, 3 },
{ "Kinematic_T_UVD", ScriptClientBase::Func_Kinematic<Math::Kinematic::T_UVD>, 3 },
{ "Kinematic_T_UAD", ScriptClientBase::Func_Kinematic<Math::Kinematic::T_UAD>, 3 },
{ "Kinematic_T_VAD", ScriptClientBase::Func_Kinematic<Math::Kinematic::T_VAD>, 3 },

//Rotation
{ "Rotate2D", ScriptClientBase::Func_Rotate2D, 3 },
{ "Rotate2D", ScriptClientBase::Func_Rotate2D, 5 },
Expand Down Expand Up @@ -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<double (*funcKinematic)(double, double, double)>
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();
Expand Down
4 changes: 4 additions & 0 deletions source/GcLib/gstd/ScriptClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ namespace gstd {
DNH_FUNCAPI_DECL_(Func_Interpolate_X_Angle);
DNH_FUNCAPI_DECL_(Func_Interpolate_X_Array);

//Math functions; kinematics
template<double (*funcKinematic)(double, double, double)>
DNH_FUNCAPI_DECL_(Func_Kinematic);

//Math functions; rotation
DNH_FUNCAPI_DECL_(Func_Rotate2D);
DNH_FUNCAPI_DECL_(Func_Rotate3D);
Expand Down

0 comments on commit b9edd94

Please sign in to comment.