mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-10 12:41:35 -10:00
As described in #1278, the current scripting system has issues with handling non-trivial C++ types. Since fixing that deficiency is too much work, especially since we are in a feature freeze, I decided to simply enforce the usage of trivial types for scripting handles. Fortunately, only two handles used non-trivial types so it was relatively easy to fix those instances by dynamically allocating those and only storing the pointers in the lua memory. This fixes a bug in JAD-XA where the game would crash at the last boss. Also, I noticed that the HudGauge handle used a copy of the hud gauge rather than a pointer to the actual instance so I'm pretty sure that any scripting changes to a custom HUD gauge simply didn't work before.
209 lines
5.2 KiB
C++
209 lines
5.2 KiB
C++
//
|
|
//
|
|
|
|
#include "particle.h"
|
|
#include "vecmath.h"
|
|
#include "object.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
particle_h::particle_h() {
|
|
}
|
|
particle_h::particle_h(const particle::WeakParticlePtr& part_p) {
|
|
this->part = part_p;
|
|
}
|
|
particle::WeakParticlePtr particle_h::Get() {
|
|
return this->part;
|
|
}
|
|
bool particle_h::isValid() {
|
|
return !part.expired();
|
|
}
|
|
|
|
|
|
//**********HANDLE: Particle
|
|
ADE_OBJ(l_Particle, particle_h*, "particle", "Handle to a particle");
|
|
|
|
ADE_FUNC(__gc, l_Particle, NULL, "Removes the allocated reference of this handle", NULL, NULL)
|
|
{
|
|
particle_h *ph = NULL;
|
|
if (!ade_get_args(L, "o", l_Particle.Get(&ph)))
|
|
return ADE_RETURN_NIL;
|
|
|
|
if (ph == NULL)
|
|
return ADE_RETURN_NIL;
|
|
|
|
if (!ph->isValid()) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
// Clean up the pointer
|
|
delete ph;
|
|
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
ADE_VIRTVAR(Position, l_Particle, "vector", "The current position of the particle (world vector)", "vector", "The current position")
|
|
{
|
|
particle_h *ph = NULL;
|
|
vec3d newVec = vmd_zero_vector;
|
|
if (!ade_get_args(L, "o|o", l_Particle.Get(&ph), l_Vector.Get(&newVec)))
|
|
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
|
|
|
|
if (ph == NULL)
|
|
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
|
|
|
|
if (!ph->isValid())
|
|
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
|
|
|
|
if (ADE_SETTING_VAR)
|
|
{
|
|
ph->Get().lock()->pos = newVec;
|
|
}
|
|
|
|
return ade_set_args(L, "o", l_Vector.Set(ph->Get().lock()->pos));
|
|
}
|
|
|
|
ADE_VIRTVAR(Velocity, l_Particle, "vector", "The current velocity of the particle (world vector)", "vector", "The current velocity")
|
|
{
|
|
particle_h *ph = NULL;
|
|
vec3d newVec = vmd_zero_vector;
|
|
if (!ade_get_args(L, "o|o", l_Particle.Get(&ph), l_Vector.Get(&newVec)))
|
|
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
|
|
|
|
if (ph == NULL)
|
|
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
|
|
|
|
if (!ph->isValid())
|
|
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
|
|
|
|
if (ADE_SETTING_VAR)
|
|
{
|
|
ph->Get().lock()->velocity = newVec;
|
|
}
|
|
|
|
return ade_set_args(L, "o", l_Vector.Set(ph->Get().lock()->velocity));
|
|
}
|
|
|
|
ADE_VIRTVAR(Age, l_Particle, "number", "The time this particle already lives", "number", "The current age or -1 on error")
|
|
{
|
|
particle_h *ph = NULL;
|
|
float newAge = -1.0f;
|
|
if (!ade_get_args(L, "o|f", l_Particle.Get(&ph), &newAge))
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (ph == NULL)
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (!ph->isValid())
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (ADE_SETTING_VAR)
|
|
{
|
|
if (newAge >= 0)
|
|
ph->Get().lock()->age = newAge;
|
|
}
|
|
|
|
return ade_set_args(L, "f", ph->Get().lock()->age);
|
|
}
|
|
|
|
ADE_VIRTVAR(MaximumLife, l_Particle, "number", "The time this particle can live", "number", "The maximal life or -1 on error")
|
|
{
|
|
particle_h *ph = NULL;
|
|
float newLife = -1.0f;
|
|
if (!ade_get_args(L, "o|f", l_Particle.Get(&ph), &newLife))
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (ph == NULL)
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (!ph->isValid())
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (ADE_SETTING_VAR)
|
|
{
|
|
if (newLife >= 0)
|
|
ph->Get().lock()->max_life = newLife;
|
|
}
|
|
|
|
return ade_set_args(L, "f", ph->Get().lock()->max_life);
|
|
}
|
|
|
|
ADE_VIRTVAR(Radius, l_Particle, "number", "The radius of the particle", "number", "The radius or -1 on error")
|
|
{
|
|
particle_h *ph = NULL;
|
|
float newRadius = -1.0f;
|
|
if (!ade_get_args(L, "o|f", l_Particle.Get(&ph), &newRadius))
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (ph == NULL)
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (!ph->isValid())
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (ADE_SETTING_VAR)
|
|
{
|
|
if (newRadius >= 0)
|
|
ph->Get().lock()->radius = newRadius;
|
|
}
|
|
|
|
return ade_set_args(L, "f", ph->Get().lock()->radius);
|
|
}
|
|
|
|
ADE_VIRTVAR(TracerLength, l_Particle, "number", "The tracer legth of the particle", "number", "The radius or -1 on error")
|
|
{
|
|
particle_h *ph = NULL;
|
|
float newTracer = -1.0f;
|
|
if (!ade_get_args(L, "o|f", l_Particle.Get(&ph), &newTracer))
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (ph == NULL)
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
if (!ph->isValid())
|
|
return ade_set_error(L, "f", -1.0f);
|
|
|
|
// tracer_length has been deprecated
|
|
return ade_set_args(L, "f", -1.0f);
|
|
}
|
|
|
|
ADE_VIRTVAR(AttachedObject, l_Particle, "object", "The object this particle is attached to. If valid the position will be relativ to this object and the velocity will be ignored.", "object", "Attached object or invalid object handle on error")
|
|
{
|
|
particle_h *ph = NULL;
|
|
object_h *newObj = nullptr;
|
|
if (!ade_get_args(L, "o|o", l_Particle.Get(&ph), l_Object.GetPtr(&newObj)))
|
|
return ade_set_error(L, "o", l_Object.Set(object_h()));
|
|
|
|
if (ph == NULL)
|
|
return ade_set_error(L, "o", l_Object.Set(object_h()));
|
|
|
|
if (!ph->isValid())
|
|
return ade_set_error(L, "o", l_Object.Set(object_h()));
|
|
|
|
if (ADE_SETTING_VAR)
|
|
{
|
|
if (newObj->IsValid())
|
|
ph->Get().lock()->attached_objnum = newObj->objp->signature;
|
|
}
|
|
|
|
return ade_set_args(L, "o", l_Object.Set(object_h(&Objects[ph->Get().lock()->attached_objnum])));
|
|
}
|
|
|
|
ADE_FUNC(isValid, l_Particle, NULL, "Detects whether this handle is valid", "boolean", "true if valid false if not")
|
|
{
|
|
particle_h *ph = NULL;
|
|
if (!ade_get_args(L, "o", l_Particle.Get(&ph)))
|
|
return ADE_RETURN_FALSE;
|
|
|
|
if (ph == NULL)
|
|
return ADE_RETURN_FALSE;
|
|
|
|
return ade_set_args(L, "b", ph->isValid());
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|