commit x64 compilation from lulu cause the other branch dont seems to compile properly at home
This commit is contained in:
103
include/modules/script_squirrel/cobject/cobject.cpp
Normal file
103
include/modules/script_squirrel/cobject/cobject.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/engine_vm.h"
|
||||
#include "raytracer/raytracer_core.h"
|
||||
#include "automation/automation_source_group.h"
|
||||
#include "scene3d/scene.h"
|
||||
#include "scene3d/group.h"
|
||||
#include "scene3d/memitter.h"
|
||||
#include "scene3d/mcamera.h"
|
||||
#include "scene3d/mobject.h"
|
||||
#include "scene3d/mtrigger.h"
|
||||
#include "scene3d/mlight.h"
|
||||
#include "scene3d/instance.h"
|
||||
#include "ui/ui_cursor.h"
|
||||
#include "core/raster_font.h"
|
||||
#include "input/input_device.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void CObject::Initialize(CObjectType t, void *o, bool m)
|
||||
{
|
||||
Release();
|
||||
|
||||
type = t;
|
||||
native = o;
|
||||
managed = m;
|
||||
|
||||
if (native)
|
||||
switch (type)
|
||||
{
|
||||
case typetag_Picture: ((Picture *)native)->AddRef(); break;
|
||||
case typetag_Texture: ((Render::Texture *)native)->AddRef(); break;
|
||||
case typetag_Geometry: ((Render::Geometry *)native)->AddRef(); break;
|
||||
case typetag_Material: ((Render::Material *)native)->AddRef(); break;
|
||||
case typetag_InputDevice: ((Input::Device *)native)->AddRef(); break;
|
||||
case typetag_AutomationSource: ((Automation::Source *)native)->AddRef(); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
void CObject::Release()
|
||||
{
|
||||
if (native == NULL)
|
||||
return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case typetag_Picture: ((Picture *)native)->RemoveRef(); break;
|
||||
case typetag_Texture: ((Render::Texture *)native)->RemoveRef(); break;
|
||||
case typetag_Geometry: ((Render::Geometry *)native)->RemoveRef(); break;
|
||||
case typetag_Material: ((Render::Material *)native)->RemoveRef(); break;
|
||||
case typetag_InputDevice: ((Input::Device *)native)->RemoveRef(); break;
|
||||
case typetag_AutomationSource: ((Automation::Source *)native)->RemoveRef(); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (managed)
|
||||
switch (type)
|
||||
{
|
||||
case typetag_Metafile: delete ((NML::File *)native); break;
|
||||
case typetag_Raytracer: delete ((Raytrace::Raytracer *)native); break;
|
||||
case typetag_RasterFont: delete ((Render::RasterFont *)native); break;
|
||||
case typetag_AutomationSourceGroup: delete ((Automation::SourceGroup *)native); break;
|
||||
case typetag_Group: delete ((S3D::Group *)native); break;
|
||||
case typetag_Scene3d: delete ((S3D::Scene *)native); break;
|
||||
case typetag_UICursor: delete ((S2D::Cursor *)native); break;
|
||||
|
||||
default:
|
||||
__LOG_E__ << "Type " << CObjectTypeToString(type) << " should not be managed by the VM.\n";
|
||||
break;
|
||||
}
|
||||
|
||||
native = NULL;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
CObject::CObject(EngineVM *v, CObjectType t, void *o, bool managed) : vm(v)
|
||||
{
|
||||
list_item = vm->cobjects.Add(this);
|
||||
|
||||
native = NULL;
|
||||
Initialize(t, o, managed);
|
||||
}
|
||||
CObject::~CObject()
|
||||
{
|
||||
if (list_item)
|
||||
{
|
||||
vm->cobjects.Remove(list_item);
|
||||
// g_flog << "Native object alive count: " << vm->cobjects.GetCount() << "\n";
|
||||
}
|
||||
Release();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
154
include/modules/script_squirrel/cobject/cobject_impl.cpp
Normal file
154
include/modules/script_squirrel/cobject/cobject_impl.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/cobject_decl.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/squirrel_vm.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CObject::GetBase(HSQUIRRELVM vm, int idx, void **o, CObjectType *types)
|
||||
{
|
||||
// get object type
|
||||
CObjectType type;
|
||||
if (!GetType(vm, idx, type))
|
||||
return false;
|
||||
|
||||
// cast to target type if compatible
|
||||
for (int n = 0; types[n] != typetag_Undefined; ++n)
|
||||
if (type == types[n])
|
||||
return Get(vm, idx, (void **)o);
|
||||
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static SQInteger CObject_release_hook(SQUserPointer p, SQInteger size)
|
||||
{
|
||||
if (CObject *pv = (CObject *)p)
|
||||
delete pv;
|
||||
return 0;
|
||||
}
|
||||
bool push_CObject(HSQUIRRELVM vm, const CObject &quat)
|
||||
{
|
||||
CObject *newquat = new CObject((EngineVM *)sq_getforeignptr(vm));
|
||||
*newquat = quat;
|
||||
if (!CreateNativeClassInstance(vm, "CObject", newquat, CObject_release_hook))
|
||||
{
|
||||
delete newquat;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
::SquirrelObject new_CObject(HSQUIRRELVM vm, const CObject &quat)
|
||||
{
|
||||
::SquirrelObject ret(vm);
|
||||
if (push_CObject(vm, quat))
|
||||
{
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int construct_CObject(HSQUIRRELVM vm, CObject *p)
|
||||
{
|
||||
sq_setinstanceup(vm, 1, p);
|
||||
sq_setreleasehook(vm, 1, CObject_release_hook);
|
||||
return 1;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CObject::Push(HSQUIRRELVM v, void *_ptr, CObjectType _type, bool managed)
|
||||
{
|
||||
CObject *o = new CObject((EngineVM *)sq_getforeignptr(v), _type, _ptr, managed);
|
||||
|
||||
if (!CreateNativeClassInstance(v, "CObject", o, CObject_release_hook))
|
||||
{
|
||||
__LOG_E__ << "Could not allocate native reference.\n";
|
||||
_safe_delete(o);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool CObject::GetType(HSQUIRRELVM v, int idx, CObjectType &type)
|
||||
{
|
||||
StackHandler sa(v);
|
||||
|
||||
CObject *self;
|
||||
if (SQ_FAILED(sq_getinstanceup(v, idx, (SQUserPointer*)&self, (SQUserPointer)&__CObject_decl)))
|
||||
return false;
|
||||
|
||||
__ASSERT__(self != NULL);
|
||||
|
||||
type = self->type;
|
||||
return true;
|
||||
}
|
||||
bool CObject::Get(HSQUIRRELVM v, int idx, void **p, CObjectType type)
|
||||
{
|
||||
__ASSERT__(p != NULL);
|
||||
|
||||
StackHandler sa(v);
|
||||
|
||||
CObject *self;
|
||||
if (SQ_FAILED(sq_getinstanceup(v, idx, (SQUserPointer*)&self, (SQUserPointer)&__CObject_decl)))
|
||||
return false;
|
||||
|
||||
__ASSERT__(self != NULL);
|
||||
|
||||
if ((type != typetag_Undefined) && (self->type != type))
|
||||
{
|
||||
sq_throwerror(v, String::Format("Native reference to '%s' expected, got '%s'", CObjectTypeToString(type), CObjectTypeToString(self->type)));
|
||||
return false;
|
||||
}
|
||||
|
||||
p[0] = self->native;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(CObject, constructor)
|
||||
return construct_CObject(v, new CObject((EngineVM *)sq_getforeignptr(v)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(CObject, _cmp)
|
||||
_GetSelf(CObject, CObject);
|
||||
_GetTypedParam(object, 2, CObject, CObject);
|
||||
return sa.Return(asbool(self->native == object->native));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(CObject, type)
|
||||
_GetSelf(CObject, CObject);
|
||||
return sa.Return((int)self->type);
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(CObject, isValid)
|
||||
_GetSelf(CObject, CObject);
|
||||
return sa.Return(asbool(self->native));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(CObject, isNull)
|
||||
_GetSelf(CObject, CObject);
|
||||
return sa.Return(!asbool(self->native));
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_BEGIN_CLASS(CObject)
|
||||
|
||||
_MEMBER_FUNCTION(CObject, constructor, -1, ".")
|
||||
_MEMBER_FUNCTION(CObject, _cmp, 2, ".xx")
|
||||
|
||||
_MEMBER_FUNCTION(CObject, isValid, 1, _SC("."))
|
||||
_MEMBER_FUNCTION(CObject, isNull, 1, _SC("."))
|
||||
_MEMBER_FUNCTION(CObject, type, 1, _SC("."))
|
||||
|
||||
_END_CLASS(CObject)
|
||||
//------------------------------------------------------------------------------
|
||||
@ -0,0 +1,206 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __COBJECT_GEOMETRY_TEMPLATE_IMPL__
|
||||
#define __COBJECT_GEOMETRY_TEMPLATE_IMPL__
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/geometry_template_decl.h"
|
||||
#include "script_squirrel/cobject/cobject_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/uv_decl.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "core/geometry_template.h"
|
||||
#include "core/resource_factories.h"
|
||||
#include "core/render_resource_factory.h"
|
||||
#include "core/render_data.h"
|
||||
#include "core/renderer.h"
|
||||
#include "core/engine.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Core;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define _GetGeometryTemplate(_VAR, _IDX) _GetTypedParam(_VAR, _IDX, GeometryTemplate, GeometryTemplate)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
_IMPL_NATIVE_CONSTRUCTION(GeometryTemplate, GeometryTemplate);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, constructor)
|
||||
return construct_GeometryTemplate(v, new GeometryTemplate);
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, clearMaterial)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->ClearMaterials();
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushMaterial)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
const SQChar *name = sa.GetString(2);
|
||||
t->PushMaterial(name);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, clear)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->Clear();
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, beginPolygon)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->BeginPolygon();
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushVertex)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(_v, 2, Vector4, Vector)
|
||||
t->PushVertex(*_v);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushNormal)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(n, 2, Vector4, Vector)
|
||||
t->PushNormal(*n);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushColor)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(c, 2, Vector4, Vector)
|
||||
t->PushColor(Color(*c));
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, pushUV)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetTypedParam(uv, 3, Vector2, UV)
|
||||
t->PushUV(sa.GetInt(2), *uv);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, endPolygon)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->EndPolygon((ushort)sa.GetInt(2));
|
||||
return 0;
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, setVertexMergeThreshold)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
t->SetVertexMergeThreshold(sa.GetFloat(2));
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(GeometryTemplate, instantiate)
|
||||
_GetGeometryTemplate(t, 1)
|
||||
_GetCObject(ResourceFactories, typetag_ResourceFactories, f, 2)
|
||||
AutoPtr <Geometry> g(t->Instantiate(sa.GetString(3)));
|
||||
Render::Geometry *r = f->render->NewGeometry();
|
||||
r->Create(*f->render, *g);
|
||||
_ReturnCObject(r, typetag_Geometry)
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//# Class: GeometryTemplate
|
||||
_BEGIN_CLASS(GeometryTemplate)
|
||||
|
||||
_MEMBER_FUNCTION(GeometryTemplate, constructor, 1, _SC("."))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//# Topic: Polygon creation
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*#
|
||||
Func: beginPolygon
|
||||
Proto: void:
|
||||
Desc: Begin declaration of a new polygon.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, beginPolygon, 1, _SC("."))
|
||||
/*#
|
||||
Func: pushVertex
|
||||
Proto: void:Vector
|
||||
Desc: Push a vertex on the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushVertex, 2, _SC(".x"))
|
||||
/*#
|
||||
Func: pushNormal
|
||||
Proto: void:Vector
|
||||
Desc: Push a normal on the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushNormal, 2, _SC(".x"))
|
||||
/*#
|
||||
Func: pushColor
|
||||
Proto: void:Vector
|
||||
Desc: Push a color on the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushColor, 2, _SC(".x"))
|
||||
/*#
|
||||
Func: pushUV
|
||||
Proto: void:int channel, UV
|
||||
Desc: Push an UV on a channel of the current polygon declaration.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushUV, 3, _SC(".ix"))
|
||||
/*#
|
||||
Func: endPolygon
|
||||
Proto: void:int material
|
||||
Desc: End declaration of the current polygon and specify its material index.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, endPolygon, 2, _SC(".i"))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//# Topic: Geometry creation
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*#
|
||||
Func: clear
|
||||
Proto: void:
|
||||
Desc: Clear current template definition, keep the current material table.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, clear, 1, _SC("."))
|
||||
|
||||
/*#
|
||||
Func: instantiate
|
||||
Proto: Geometry:Engine engine, string name
|
||||
Desc: Instantiate the current template as a named geometry.
|
||||
Note: If the geometry name is already found in the current engine cache, a
|
||||
cached copy will be returned instead of a new instantiation.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, instantiate, 3, _SC(".xs"))
|
||||
|
||||
/*#
|
||||
Func: clearMaterial
|
||||
Proto: void:
|
||||
Desc: Push a material on the template material table.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, clearMaterial, 1, _SC("."))
|
||||
/*#
|
||||
Func: pushMaterial
|
||||
Proto: void:String path
|
||||
Desc: Push a material path on the template material table.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, pushMaterial, 2, _SC(".s"))
|
||||
|
||||
/*#
|
||||
Func: setVertexMergeThreshold
|
||||
Proto: void:float threshold
|
||||
Desc: Set the vertex merging algorithm threshold.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(GeometryTemplate, setVertexMergeThreshold, 2, _SC(".n"))
|
||||
|
||||
_END_CLASS(GeometryTemplate)
|
||||
|
||||
|
||||
#endif // __COBJECT_GEOMETRY_TEMPLATE_IMPL__
|
||||
643
include/modules/script_squirrel/cobject/matrix_impl.cpp
Normal file
643
include/modules/script_squirrel/cobject/matrix_impl.cpp
Normal file
@ -0,0 +1,643 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "math/matrix4.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "math/quaternion.h"
|
||||
#include "nstring/nstring.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
_DECL_CLASS(Matrix4)
|
||||
_IMPL_NATIVE_CONSTRUCTION(Matrix4, Matrix4)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, constructor)
|
||||
Matrix4 temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); break;
|
||||
case 5:
|
||||
{
|
||||
_GetTypedParam(_u, 2, Vector4, Vector);
|
||||
_GetTypedParam(_v, 3, Vector4, Vector);
|
||||
_GetTypedParam(_w, 4, Vector4, Vector);
|
||||
_GetTypedParam(_x, 5, Vector4, Vector);
|
||||
|
||||
if (_u && _v && _w && _x)
|
||||
{ temp.Set(_u->x, _u->y, _u->z, _u->w, _v->x, _v->y, _v->z, _v->w, _w->x, _w->y, _w->z, _w->w, _x->x, _x->y, _x->z, _x->w); }
|
||||
else
|
||||
return sa.ThrowError("Matrix4() invalid parameters");
|
||||
}
|
||||
break;
|
||||
|
||||
case 17:
|
||||
temp.Set(
|
||||
sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5),
|
||||
sa.GetFloat(6), sa.GetFloat(7), sa.GetFloat(8), sa.GetFloat(9),
|
||||
sa.GetFloat(10), sa.GetFloat(11), sa.GetFloat(12), sa.GetFloat(13),
|
||||
sa.GetFloat(14), sa.GetFloat(15), sa.GetFloat(16), sa.GetFloat(17)
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Matrix4() wrong parameter count");
|
||||
}
|
||||
return construct_Matrix4(v, new Matrix4(temp));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// The string class is used to speed up comparison as it uses a hash-based early
|
||||
// rejection.
|
||||
static String uc_m00("m00"), uc_m10("m10"), uc_m20("m20"), uc_m30("m30"),
|
||||
uc_m01("m01"), uc_m11("m11"), uc_m21("m21"), uc_m31("m31"),
|
||||
uc_m02("m02"), uc_m12("m12"), uc_m22("m22"), uc_m32("m32"),
|
||||
uc_m03("m03"), uc_m13("m13"), uc_m23("m23"), uc_m33("m33");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, _set)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m30) return sa.Return(self->m[3][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m31) return sa.Return(self->m[3][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m32) return sa.Return(self->m[3][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m03) return sa.Return(self->m[0][3] = sa.GetFloat(3));
|
||||
if (idx == uc_m13) return sa.Return(self->m[1][3] = sa.GetFloat(3));
|
||||
if (idx == uc_m23) return sa.Return(self->m[2][3] = sa.GetFloat(3));
|
||||
if (idx == uc_m33) return sa.Return(self->m[3][3] = sa.GetFloat(3));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, _get)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0]);
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0]);
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0]);
|
||||
if (idx == uc_m30) return sa.Return(self->m[3][0]);
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1]);
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1]);
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1]);
|
||||
if (idx == uc_m31) return sa.Return(self->m[3][1]);
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2]);
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2]);
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2]);
|
||||
if (idx == uc_m32) return sa.Return(self->m[3][2]);
|
||||
if (idx == uc_m03) return sa.Return(self->m[0][3]);
|
||||
if (idx == uc_m13) return sa.Return(self->m[1][3]);
|
||||
if (idx == uc_m23) return sa.Return(self->m[2][3]);
|
||||
if (idx == uc_m33) return sa.Return(self->m[3][3]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetRow)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, SetRow)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(row, 3, Vector4, Vector)
|
||||
self->SetRow(sa.GetInt(2), *row);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetColumn)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetColumn(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, SetColumn)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(col, 3, Vector4, Vector)
|
||||
self->SetColumn(sa.GetInt(2), *col);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetFront)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(2)));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetBack)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(2).Reversed()));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetUp)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(1)));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetDown)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(1).Reversed()));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetRight)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(0)));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetLeft)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(0).Reversed()));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetPosition)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(3)));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, _mul)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(mtx, 2, Matrix4, Matrix4)
|
||||
_SA_RETURN_OBJECT(new_Matrix4(v, *self * *mtx));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, AsMatrix3)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, Matrix3::FromMatrix4(*self)));
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, GetInverseMatrix)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_SA_RETURN_OBJECT(new_Matrix4(v, self->InversedFast()));
|
||||
_END_IMPL
|
||||
//-----------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, Print)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
const char *label = "Matrix";
|
||||
if (sa.GetParamCount() == 2)
|
||||
label = sa.GetString(2);
|
||||
__LOG__ << "Dumping matrix '" << label << "':\n";
|
||||
for (int n = 0; n < 4; ++n)
|
||||
{
|
||||
Vector4 v = self->GetRow(n);
|
||||
__LOG__ << "Row " << n << ": { " << v.x << ", " << v.y << ", " << v.z << ", " << v.w << "}\n";
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix4, RotationFromMatrix3)
|
||||
_GetSelf(Matrix4, Matrix4);
|
||||
_GetTypedParam(mtx, 2, Matrix3, Matrix3)
|
||||
self->m[0][0] = mtx->m[0][0]; self->m[1][0] = mtx->m[1][0]; self->m[2][0] = mtx->m[2][0];
|
||||
self->m[0][1] = mtx->m[0][1]; self->m[1][1] = mtx->m[1][1]; self->m[2][1] = mtx->m[2][1];
|
||||
self->m[0][2] = mtx->m[0][2]; self->m[1][2] = mtx->m[1][2]; self->m[2][2] = mtx->m[2][2];
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/*#
|
||||
Topic: Matrix
|
||||
Type: Matrix3
|
||||
Type: Matrix4
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: MatrixGeneric
|
||||
Desc: Global functions
|
||||
#*/
|
||||
/*#
|
||||
Func: Matrix3
|
||||
Proto: Matrix3:float m00...m33
|
||||
Desc: Create a new 3x3 matrix.
|
||||
Example:
|
||||
// Construct a default unity matrix.
|
||||
local a = Matrix3()
|
||||
// Vector based constructor.
|
||||
local b = Matrix3(v0, v1, v2)
|
||||
// Float based constructor.
|
||||
local c = Matrix3(m00, m10, m20, m01, m11, m21, m02, m12, m22)
|
||||
#*/
|
||||
/*#
|
||||
Func: Matrix4
|
||||
Proto: Matrix4:float m00...m44
|
||||
Desc: Create a new 4x4 matrix.
|
||||
Example:
|
||||
// Construct a default unity matrix.
|
||||
local a = Matrix4()
|
||||
// Vector based constructor.
|
||||
local b = Matrix4(v0, v1, v2, v3)
|
||||
// Float based constructor.
|
||||
local c = Matrix3(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33)
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixX
|
||||
Proto: Matrix3:float angle
|
||||
Desc: Create a 3x3 rotation matrix around the X axis, angle is in degree.
|
||||
Example: local m = RotationMatrixX(Deg(45))
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixY
|
||||
Proto: Matrix3:float angle
|
||||
Desc: Create a 3x3 rotation matrix around the Y axis, angle is in degree.
|
||||
Example: local m = RotationMatrixY(Deg(45))
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixZ
|
||||
Proto: Matrix3:float angle
|
||||
Desc: Create a 3x3 rotation matrix around the Z axis, angle is in degree.
|
||||
Example: local m = RotationMatrixZ(Deg(45))
|
||||
#*/
|
||||
/*#
|
||||
Func: MatrixToEuler
|
||||
Proto: Vector:Matrix3,RotationOrder
|
||||
Desc: Convert a world space matrix to Euler angles.
|
||||
#*/
|
||||
/*#
|
||||
Func: EulerFromDirection
|
||||
Proto: Vector:Vector direction
|
||||
Desc: Convert a world space direction vector to an Euler angle triplet (x, y, z).
|
||||
#*/
|
||||
/*#
|
||||
Func: EulerFromDirectionAndUp
|
||||
Proto: Vector:Vector direction,Vector up
|
||||
Desc: Convert a world space direction and up vectors to an Euler angle triplet (x, y, z).
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixFromDirection
|
||||
Proto: Matrix3:Vector direction
|
||||
Desc: Convert a world space direction vector to a 3x3 rotation matrix.
|
||||
#*/
|
||||
/*#
|
||||
Func: RotationMatrixFromDirectionAndUp
|
||||
Proto: Matrix3:Vector direction,Vector up
|
||||
Desc: Convert a world space direction and up vectors to a 3x3 rotation matrix.
|
||||
#*/
|
||||
/*#
|
||||
Func: TransformationMatrix
|
||||
Proto: Matrix4:Vector position,Vector euler,Vector scale,Vector pivot
|
||||
Desc: Create a position, rotation, scale, offset 4x4 matrix.<br>The offset is applied first, scale second, rotation third and finally position is applied.
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: Matrix4Generic
|
||||
Desc: Matrix 4x4
|
||||
#*/
|
||||
_BEGIN_CLASS(Matrix4)
|
||||
_MEMBER_FUNCTION(Matrix4, constructor, -1, _T(". n|x n|x n|x n|x nnnn nnnn"))
|
||||
_MEMBER_FUNCTION(Matrix4, _get, 2, _T("xs"))
|
||||
_MEMBER_FUNCTION(Matrix4, _set, 3, _T("xsn"))
|
||||
_MEMBER_FUNCTION(Matrix4, _mul, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Func: GetRow
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix row as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetRow, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetRow
|
||||
Proto: void:int index, Vector row
|
||||
Desc: Set a matrix row from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, SetRow, 3, _T("xix"))
|
||||
/*#
|
||||
Func: GetColumn
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix column as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetColumn, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetColumn
|
||||
Proto: void:int index, Vector column
|
||||
Desc: Set a matrix column from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, SetColumn, 3, _T("xix"))
|
||||
/*#
|
||||
Func: AsMatrix3
|
||||
Proto: Matrix3:
|
||||
Desc: Return matrix as a 3x3 matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, AsMatrix3, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetInverseMatrix
|
||||
Proto: Matrix4:
|
||||
Desc: Return inverse matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetInverseMatrix, 1, _T("x"))
|
||||
/*#
|
||||
Func: Print
|
||||
Proto: void:
|
||||
Desc: Output matrix content to the engine log.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, Print, -1, _T("x"))
|
||||
/*#
|
||||
Func: RotationFromMatrix3
|
||||
Proto: void:Matrix3 orientation
|
||||
Desc: Set the rotation part of a 4x4 transformation matrix from a 3x3 matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, RotationFromMatrix3, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Section: Matrix4Component
|
||||
Desc: Transformation matrix component
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: GetFront
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix front axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetFront, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetBack
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix down axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetBack, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetRight
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix right axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetRight, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetLeft
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix left axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetLeft, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetUp
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix up axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetUp, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetDown
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix down axis vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetDown, 1, _T("x"))
|
||||
/*#
|
||||
Func: GetPosition
|
||||
Proto: Vector:
|
||||
Desc: Return the transformation matrix position vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix4, GetPosition, 1, _T("x"))
|
||||
|
||||
_END_CLASS(Matrix4)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_DECL_CLASS(Matrix3);
|
||||
_IMPL_NATIVE_CONSTRUCTION(Matrix3, Matrix3);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, constructor)
|
||||
Matrix3 temp, *newv = NULL;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(1, 0, 0, 0, 1, 0, 0, 0, 1); break;
|
||||
case 4:
|
||||
{
|
||||
_GetTypedParam(_u, 2, Vector4, Vector);
|
||||
_GetTypedParam(_v, 3, Vector4, Vector);
|
||||
_GetTypedParam(_w, 4, Vector4, Vector);
|
||||
|
||||
if (_u && _v && _w)
|
||||
{ temp.Set(*_u, *_v, *_w); }
|
||||
else
|
||||
return sa.ThrowError("Matrix3() invalid parameters");
|
||||
}
|
||||
break;
|
||||
|
||||
case 10:
|
||||
temp.Set(
|
||||
sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4),
|
||||
sa.GetFloat(5), sa.GetFloat(6), sa.GetFloat(7),
|
||||
sa.GetFloat(8), sa.GetFloat(9), sa.GetFloat(10)
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Matrix3() wrong parameter count");
|
||||
}
|
||||
|
||||
newv = new Matrix3(temp);
|
||||
return construct_Matrix3(v, newv);
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, _set)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0] = sa.GetFloat(3));
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1] = sa.GetFloat(3));
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2] = sa.GetFloat(3));
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2] = sa.GetFloat(3));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, _get)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
String idx(sa.GetString(2));
|
||||
|
||||
if (idx == uc_m00) return sa.Return(self->m[0][0]);
|
||||
if (idx == uc_m10) return sa.Return(self->m[1][0]);
|
||||
if (idx == uc_m20) return sa.Return(self->m[2][0]);
|
||||
if (idx == uc_m01) return sa.Return(self->m[0][1]);
|
||||
if (idx == uc_m11) return sa.Return(self->m[1][1]);
|
||||
if (idx == uc_m21) return sa.Return(self->m[2][1]);
|
||||
if (idx == uc_m02) return sa.Return(self->m[0][2]);
|
||||
if (idx == uc_m12) return sa.Return(self->m[1][2]);
|
||||
if (idx == uc_m22) return sa.Return(self->m[2][2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, GetRow)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetRow(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, SetRow)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(row, 3, Vector4, Vector)
|
||||
self->SetRow(sa.GetInt(2), *row);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, GetColumn)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->GetColumn(sa.GetInt(2))));
|
||||
_END_IMPL
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, SetColumn)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(col, 3, Vector4, Vector)
|
||||
self->SetColumn(sa.GetInt(2), *col);
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, _mul)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(mtx, 2, Matrix3, Matrix3)
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, *self * *mtx));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, AsMatrix4)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Matrix4(v, Matrix4::FromMatrix3(*self)));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, FromOrthonormalBasis)
|
||||
// _CHECK_SELF(Matrix3, Matrix3);
|
||||
_GetTypedParam(_w, 2, Vector4, Vector)
|
||||
Vector4 *_v = NULL;
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
{ _GetTypedParam(__v, 3, Vector4, Vector)
|
||||
_v = __v; } break;
|
||||
default:
|
||||
return sa.ThrowError("Matrix3::FromOrthonormalBasis() wrong parameter count");
|
||||
}
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, Matrix3::FromOrthonormalBasis(*_w, _v)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, SlerpTo)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
_GetTypedParam(to, 3, Matrix3, Matrix3)
|
||||
float t = sa.GetFloat(2);
|
||||
Matrix3 out = Quaternion::Slerp(t, Quaternion::FromMatrix3(*self), Quaternion::FromMatrix3(*to)).AsMatrix3();
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, out))
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Matrix3, AsEuler)
|
||||
_GetSelf(Matrix3, Matrix3);
|
||||
Math::rOrder rorder = Math::rOrder_Default;
|
||||
if (sa.GetParamCount() == 2)
|
||||
rorder = (Math::rOrder)sa.GetInt(2);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->AsEuler(rorder)));
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/*#
|
||||
Section: Matrix3Generic
|
||||
Desc: Matrix 3x3
|
||||
#*/
|
||||
_BEGIN_CLASS(Matrix3)
|
||||
_MEMBER_FUNCTION(Matrix3, constructor, -1, _T(". n|x n|x n|x nnn nnn"))
|
||||
_MEMBER_FUNCTION(Matrix3, _get, 2, _T("xs"))
|
||||
_MEMBER_FUNCTION(Matrix3, _set, 3, _T("xsn"))
|
||||
_MEMBER_FUNCTION(Matrix3, _mul, 2, _T("xx"))
|
||||
/*#
|
||||
Func: GetRow
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix row as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, GetRow, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetRow
|
||||
Proto: void:int index, Vector row
|
||||
Desc: Set a matrix row from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, SetRow, 3, _T("xix"))
|
||||
/*#
|
||||
Func: GetColumn
|
||||
Proto: Vector:int index
|
||||
Desc: Return a matrix column as a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, GetColumn, 2, _T("xi"))
|
||||
/*#
|
||||
Func: SetColumn
|
||||
Proto: void:int index, Vector column
|
||||
Desc: Set a matrix column from a vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, SetColumn, 3, _T("xix"))
|
||||
/*#
|
||||
Func: AsMatrix4
|
||||
Proto: Matrix4:
|
||||
Desc: Return matrix as a 4x4 matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, AsMatrix4, 1, _T("x"))
|
||||
/*#
|
||||
Func: FromOrthonormalBasis
|
||||
Proto: Matrix3:Vector u,[Vector v]
|
||||
Desc: Build an orientation matrix from one or two basis vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, FromOrthonormalBasis, -2, _T(".xx"))
|
||||
/*#
|
||||
Func: SlerpTo
|
||||
Proto: Matrix3:float t,Matrix3 to
|
||||
Desc: Interpolate a 3x3 orientation matrix to another 3x3 orientation matrix using spherical linear interpolation.
|
||||
Example:
|
||||
local m_a = ItemGetRotationMatrix(item_a)
|
||||
local m_b = ItemGetRotationMatrix(item_b)
|
||||
|
||||
// m_c will store a rotation halfway between the rotation stored in the m_a and m_b matrices.
|
||||
local m_c = m_a.SlerpTo(0.5, m_b)
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, SlerpTo, 3, _T("xnx"))
|
||||
/*#
|
||||
Func: AsEuler
|
||||
Proto: Vector:[RotationOrder method]
|
||||
Desc: Return a 3x3 orientation matrix as an Euler triplet.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Matrix3, AsEuler, -1, _T("xi"))
|
||||
_END_CLASS(Matrix3)
|
||||
328
include/modules/script_squirrel/cobject/quaternion_impl.cpp
Normal file
328
include/modules/script_squirrel/cobject/quaternion_impl.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
nEngine - GSFramework
|
||||
Copyright 2001-2012 Emmanuel Julien. All Rights Reserved.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#include "script_squirrel/cobject/quaternion_decl.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "math/quaternion.h"
|
||||
#include "math/vector.h"
|
||||
#include "nstring/nstring.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
_DECL_CLASS(Quaternion)
|
||||
_IMPL_NATIVE_CONSTRUCTION(Quaternion, Quaternion)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, constructor)
|
||||
Quaternion temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(); break;
|
||||
case 5:
|
||||
temp.Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5));
|
||||
break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Quaternion() wrong parameter count");
|
||||
}
|
||||
return construct_Quaternion(v, new Quaternion(temp));
|
||||
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _cloned)
|
||||
_GetTypedParam(quat, 2, Quaternion, Quaternion);
|
||||
return construct_Quaternion(v, new Quaternion(*quat));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _set)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
|
||||
const SQChar *s = sa.GetString(2);
|
||||
int index = s ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x':
|
||||
return sa.Return(self->x = sa.GetFloat(3));
|
||||
case 1: case 'y':
|
||||
return sa.Return(self->y = sa.GetFloat(3));
|
||||
case 2: case 'z':
|
||||
return sa.Return(self->z = sa.GetFloat(3));
|
||||
case 3: case 'w':
|
||||
return sa.Return(self->w = sa.GetFloat(3));
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _get)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
const SQChar *s = sa.GetString(2);
|
||||
if (s && (s[1] != 0))
|
||||
return SQ_ERROR;
|
||||
int index = s && (s[1] == 0) ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x':
|
||||
return sa.Return(self->x);
|
||||
case 1: case 'y':
|
||||
return sa.Return(self->y);
|
||||
case 2: case 'z':
|
||||
return sa.Return(self->z);
|
||||
case 3: case 'w':
|
||||
return sa.Return(self->w);
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _mul)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Quaternion * Quaternion.
|
||||
_CHECK_INST_PARAM_RAW(quat, 2, Quaternion, Quaternion);
|
||||
if (quat)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self * *quat));
|
||||
}
|
||||
break;
|
||||
|
||||
// Quaternion * Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self * (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self * sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion * operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _div)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
// Quaternion / Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self / (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self / sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion / operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _add)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Quaternion + Quaternion.
|
||||
_CHECK_INST_PARAM_RAW(quat, 2, Quaternion, Quaternion);
|
||||
if (quat)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self + *quat));
|
||||
}
|
||||
break;
|
||||
|
||||
// Quaternion + Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self + (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self + sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion + operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, _sub)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Quaternion - Quaternion.
|
||||
_CHECK_INST_PARAM_RAW(quat, 2, Quaternion, Quaternion);
|
||||
if (quat)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self - *quat));
|
||||
}
|
||||
break;
|
||||
|
||||
// Quaternion - Scalar
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self - (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, *self - sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Quaternion - operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Set)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 1: self->Set(); break;
|
||||
case 2: self->Set(sa.GetFloat(2)); break;
|
||||
case 3: self->Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
case 4: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4)); break;
|
||||
case 5: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5)); break;
|
||||
default:
|
||||
return sa.ThrowError("Quaternion Set() wrong parameters");
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Slerp)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
float k = sa.GetFloat(2);
|
||||
_GetTypedParam(quat, 3, Quaternion, Quaternion)
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::Slerp(k, *self, *quat)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Normalize)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, self->Normalize()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Inverse)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, self->Inverse()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Dot)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(quat, 2, Quaternion, Quaternion);
|
||||
return sa.Return(self->Dot(*quat));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, AsMatrix3)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_SA_RETURN_OBJECT(new_Matrix3(v, self->AsMatrix3()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, QuaternionFromAxisAngle)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(vec, 3, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::FromAxisAngle(sa.GetFloat(2), vec->x, vec->y, vec->z)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, QuaternionFromMatrix3)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(mtx, 2, Matrix3, Matrix3);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::FromMatrix3(*mtx)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, QuaternionLookAt)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Quaternion(v, Quaternion::LookAt(*vec)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Quaternion, Print)
|
||||
_GetSelf(Quaternion, Quaternion);
|
||||
const char *label = "Quaternion";
|
||||
if (sa.GetParamCount() == 2)
|
||||
label = sa.GetString(2);
|
||||
__LOG__ << label << ": { x = " << self->x << ", y = " << self->y << ", z = " << self->z << ", w = " << self->w << "}\n";
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
/*#
|
||||
Topic: Quaternion
|
||||
Type: Quaternion
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: QuaternionGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
_BEGIN_CLASS(Quaternion)
|
||||
|
||||
/*#
|
||||
Func: Quaternion
|
||||
Proto: Quaternion:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Create a new quaternion.
|
||||
Example:
|
||||
local u = Quaternion()
|
||||
local v = Quaternion(0, 0, 0, 1)
|
||||
|
||||
u.Set(-1, 0, 0)
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, constructor, -1, _T(".n|xnnn"))
|
||||
_MEMBER_FUNCTION(Quaternion, _cloned, 2, _T(".x"))
|
||||
_MEMBER_FUNCTION(Quaternion, _set, 2, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _get, 2, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _add, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _sub, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _mul, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Quaternion, _div, 2, _T("xn"))
|
||||
|
||||
/*#
|
||||
Func: Set
|
||||
Proto: void:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Set quaternion values.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Set, -1, _T("xnnnn"))
|
||||
/*#
|
||||
Func: Slerp
|
||||
Proto: Quaternion:float,Quaternion
|
||||
Desc: Returns a spherical linear interpolation.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Slerp, 3, _T("xnx"))
|
||||
/*#
|
||||
Func: Normalize
|
||||
Proto: Quaternion:void
|
||||
Desc: Returns the normalized quaternion.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Normalize, 1, _T("x"))
|
||||
/*#
|
||||
Func: Inverse
|
||||
Proto: Quaternion:void
|
||||
Desc: Returns the inverse quaternion.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Inverse, 1, _T("x"))
|
||||
/*#
|
||||
Func: Dot
|
||||
Proto: Quaternion:Quaternion
|
||||
Desc: Returns the Dot product.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Dot, 2, _T("xx"))
|
||||
/*#
|
||||
Func: AsMatrix3
|
||||
Proto: Matrix3:void
|
||||
Desc: Returns the Matrix3 from the quaternion.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, AsMatrix3, 1, _T("x"))
|
||||
/*#
|
||||
Func: QuaternionFromAxisAngle
|
||||
Proto: Quaternion:float angle,Vector axis
|
||||
Desc: Returns a quaternion based on angle and axis.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, QuaternionFromAxisAngle, 3, _T(".nx"))
|
||||
/*#
|
||||
Func: QuaternionFromMatrix3
|
||||
Proto: Quaternion:Matrix3
|
||||
Desc: Returns a quaternion based on a Matrix3.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, QuaternionFromMatrix3, 2, _T(".x"))
|
||||
/*#
|
||||
Func: QuaternionLookAt
|
||||
Proto: Quaternion:Vector direction
|
||||
Desc: Returns a quaternion looking at direction.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, QuaternionLookAt, 2, _T(".x"))
|
||||
/*#
|
||||
Func: Print
|
||||
Proto: void:
|
||||
Desc: Dump this quaternion components (x,y,z,w) to the engine log.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Quaternion, Print, -1, _T("x"))
|
||||
|
||||
_END_CLASS(Quaternion)
|
||||
@ -0,0 +1,113 @@
|
||||
#include "squirrel.h"
|
||||
#include "script_squirrel/cobject/squirrel_object.h"
|
||||
#include "script_squirrel/cobject/squirrel_bindings_utils.h"
|
||||
|
||||
bool CreateStaticNamespace(HSQUIRRELVM v,ScriptNamespaceDecl *sn)
|
||||
{
|
||||
int n = 0;
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,sn->name,-1);
|
||||
sq_newtable(v);
|
||||
const ScriptClassMemberDecl *members = sn->members;
|
||||
const ScriptClassMemberDecl *m = 0;
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
const ScriptConstantDecl *consts = sn->constants;
|
||||
const ScriptConstantDecl *c = 0;
|
||||
n = 0;
|
||||
while(consts[n].name) {
|
||||
c = &consts[n];
|
||||
sq_pushstring(v,c->name,-1);
|
||||
switch(c->type) {
|
||||
case OT_STRING: sq_pushstring(v,c->val.s,-1);break;
|
||||
case OT_INTEGER: sq_pushinteger(v,c->val.i);break;
|
||||
case OT_FLOAT: sq_pushfloat(v,c->val.f);break;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
if(sn->delegate) {
|
||||
const ScriptClassMemberDecl *members = sn->delegate;
|
||||
const ScriptClassMemberDecl *m = 0;
|
||||
sq_newtable(v);
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
sq_setdelegate(v,-2);
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateClass(HSQUIRRELVM v,SquirrelClassDecl *cd)
|
||||
{
|
||||
int n = 0;
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,cd->name,-1);
|
||||
if(cd->base) {
|
||||
sq_pushstring(v,cd->base,-1);
|
||||
if(SQ_FAILED(sq_get(v,-3))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(SQ_FAILED(sq_newclass(v,cd->base?1:0))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
sq_settypetag(v,-1,(SQUserPointer)cd);
|
||||
const ScriptClassMemberDecl *members = cd->members;
|
||||
const ScriptClassMemberDecl *m = 0;
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateNativeClassInstance(HSQUIRRELVM v,const SQChar *classname,SQUserPointer ud,SQRELEASEHOOK hook)
|
||||
{
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,classname,-1);
|
||||
if(SQ_FAILED(sq_rawget(v,-2))){
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
//sq_pushroottable(v);
|
||||
if(SQ_FAILED(sq_createinstance(v,-1))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
sq_remove(v,-3); //removes the root table
|
||||
sq_remove(v,-2); //removes the the class
|
||||
if(SQ_FAILED(sq_setinstanceup(v,-1,ud))) {
|
||||
sq_settop(v,oldtop);
|
||||
return false;
|
||||
}
|
||||
sq_setreleasehook(v,-1,hook);
|
||||
return true;
|
||||
}
|
||||
470
include/modules/script_squirrel/cobject/squirrel_object.cpp
Normal file
470
include/modules/script_squirrel/cobject/squirrel_object.cpp
Normal file
@ -0,0 +1,470 @@
|
||||
#include "squirrel.h"
|
||||
#include "squirrel_object.h"
|
||||
//#include "SquirrelVM.h"
|
||||
|
||||
SquirrelObject::SquirrelObject(HSQUIRRELVM v)
|
||||
{
|
||||
vm = v;
|
||||
sq_resetobject(&_o);
|
||||
}
|
||||
|
||||
SquirrelObject::~SquirrelObject()
|
||||
{
|
||||
if(vm)
|
||||
sq_release(vm,&_o);
|
||||
}
|
||||
|
||||
SquirrelObject::SquirrelObject(const SquirrelObject &o)
|
||||
{
|
||||
vm = o.vm;
|
||||
_o = o._o;
|
||||
sq_addref(vm,&_o);
|
||||
}
|
||||
|
||||
SquirrelObject::SquirrelObject(HSQOBJECT &o)
|
||||
{
|
||||
_o = o;
|
||||
sq_addref(vm,&_o);
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::Clone()
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(GetType() == OT_TABLE || GetType() == OT_ARRAY)
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_clone(vm,-1);
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SquirrelObject & SquirrelObject::operator =(const SquirrelObject &o)
|
||||
{
|
||||
HSQOBJECT t;
|
||||
t = o._o;
|
||||
sq_addref(vm,&t);
|
||||
sq_release(vm,&_o);
|
||||
_o = t;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SquirrelObject & SquirrelObject::operator =(int n)
|
||||
{
|
||||
sq_pushinteger(vm,n);
|
||||
AttachToStackObject(-1);
|
||||
sq_pop(vm,1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void SquirrelObject::Append(const SquirrelObject &o)
|
||||
{
|
||||
if(sq_isarray(_o)) {
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushobject(vm,o._o);
|
||||
sq_arrayappend(vm,-2);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
}
|
||||
|
||||
void SquirrelObject::AttachToStackObject(int idx)
|
||||
{
|
||||
HSQOBJECT t;
|
||||
sq_getstackobj(vm,idx,&t);
|
||||
sq_addref(vm,&t);
|
||||
sq_release(vm,&_o);
|
||||
_o = t;
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetDelegate(SquirrelObject &obj)
|
||||
{
|
||||
if(obj.GetType() == OT_TABLE ||
|
||||
obj.GetType() == OT_NULL) {
|
||||
switch(_o._type) {
|
||||
case OT_USERDATA:
|
||||
case OT_TABLE:
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushobject(vm,obj._o);
|
||||
if(SQ_SUCCEEDED(sq_setdelegate(vm,-2)))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::GetDelegate()
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(_o._type == OT_TABLE || _o._type == OT_USERDATA)
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_getdelegate(vm,-1);
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::IsNull() const
|
||||
{
|
||||
return sq_isnull(_o);
|
||||
}
|
||||
|
||||
bool SquirrelObject::IsNumeric() const
|
||||
{
|
||||
return sq_isnumeric(_o) ? true : false;
|
||||
}
|
||||
|
||||
int SquirrelObject::Len() const
|
||||
{
|
||||
int ret = 0;
|
||||
if(sq_isarray(_o) || sq_istable(_o) || sq_isstring(_o)) {
|
||||
sq_pushobject(vm,_o);
|
||||
ret = sq_getsize(vm,-1);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define _SETVALUE_INT_BEGIN \
|
||||
bool ret = false; \
|
||||
int top = sq_gettop(vm); \
|
||||
sq_pushobject(vm,_o); \
|
||||
sq_pushinteger(vm,key);
|
||||
|
||||
#define _SETVALUE_INT_END \
|
||||
if(SQ_SUCCEEDED(sq_rawset(vm,-3))) { \
|
||||
ret = true; \
|
||||
} \
|
||||
sq_settop(vm,top); \
|
||||
return ret;
|
||||
|
||||
bool SquirrelObject::SetValue(SQInteger key,const SquirrelObject &val)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushobject(vm,val._o);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,int n)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushinteger(vm,n);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,float f)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushfloat(vm,f);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,const SQChar *s)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushstring(vm,s,-1);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(int key,bool b)
|
||||
{
|
||||
_SETVALUE_INT_BEGIN
|
||||
sq_pushbool(vm,b);
|
||||
_SETVALUE_INT_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SquirrelObject &key,const SquirrelObject &val)
|
||||
{
|
||||
bool ret = false;
|
||||
int top = sq_gettop(vm);
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushobject(vm,key._o);
|
||||
sq_pushobject(vm,val._o);
|
||||
if(SQ_SUCCEEDED(sq_rawset(vm,-3))) {
|
||||
ret = true;
|
||||
}
|
||||
sq_settop(vm,top);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define _SETVALUE_STR_BEGIN \
|
||||
bool ret = false; \
|
||||
int top = sq_gettop(vm); \
|
||||
sq_pushobject(vm,_o); \
|
||||
sq_pushstring(vm,key,-1);
|
||||
|
||||
#define _SETVALUE_STR_END \
|
||||
if(SQ_SUCCEEDED(sq_rawset(vm,-3))) { \
|
||||
ret = true; \
|
||||
} \
|
||||
sq_settop(vm,top); \
|
||||
return ret;
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,const SquirrelObject &val)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushobject(vm,val._o);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,int n)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushinteger(vm,n);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,float f)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushfloat(vm,f);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,const SQChar *s)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushstring(vm,s,-1);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetValue(const SQChar *key,bool b)
|
||||
{
|
||||
_SETVALUE_STR_BEGIN
|
||||
sq_pushbool(vm,b);
|
||||
_SETVALUE_STR_END
|
||||
}
|
||||
|
||||
|
||||
SQObjectType SquirrelObject::GetType()
|
||||
{
|
||||
return _o._type;
|
||||
}
|
||||
|
||||
bool SquirrelObject::GetSlot(int key) const
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushinteger(vm,key);
|
||||
if(SQ_SUCCEEDED(sq_get(vm,-2))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
SquirrelObject SquirrelObject::GetValue(int key)const
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(GetSlot(key)) {
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
float SquirrelObject::GetFloat(int key) const
|
||||
{
|
||||
float ret = 0.0f;
|
||||
if(GetSlot(key)) {
|
||||
sq_getfloat(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SquirrelObject::GetInt(int key) const
|
||||
{
|
||||
SQInteger ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getinteger(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return (int)ret;
|
||||
}
|
||||
|
||||
const SQChar *SquirrelObject::GetString(int key) const
|
||||
{
|
||||
const SQChar *ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getstring(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::GetBool(int key) const
|
||||
{
|
||||
SQBool ret = false;
|
||||
if(GetSlot(key)) {
|
||||
sq_getbool(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret?true:false;
|
||||
}
|
||||
|
||||
bool SquirrelObject::Exists(const SQChar *key) const
|
||||
{
|
||||
bool ret = false;
|
||||
if(GetSlot(key)) {
|
||||
ret = true;
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool SquirrelObject::GetSlot(const SQChar *name) const
|
||||
{
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushstring(vm,name,-1);
|
||||
if(SQ_SUCCEEDED(sq_get(vm,-2))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::GetValue(const SQChar *key)const
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
if(GetSlot(key)) {
|
||||
ret.AttachToStackObject(-1);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
float SquirrelObject::GetFloat(const SQChar *key) const
|
||||
{
|
||||
float ret = 0.0f;
|
||||
if(GetSlot(key)) {
|
||||
sq_getfloat(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SquirrelObject::GetInt(const SQChar *key) const
|
||||
{
|
||||
SQInteger ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getinteger(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return (int)ret;
|
||||
}
|
||||
|
||||
const SQChar *SquirrelObject::GetString(const SQChar *key) const
|
||||
{
|
||||
const SQChar *ret = 0;
|
||||
if(GetSlot(key)) {
|
||||
sq_getstring(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::GetBool(const SQChar *key) const
|
||||
{
|
||||
SQBool ret = false;
|
||||
if(GetSlot(key)) {
|
||||
sq_getbool(vm,-1,&ret);
|
||||
sq_pop(vm,1);
|
||||
}
|
||||
sq_pop(vm,1);
|
||||
return ret?true:false;
|
||||
}
|
||||
|
||||
SQUserPointer SquirrelObject::GetInstanceUP(SQUserPointer tag) const
|
||||
{
|
||||
SQUserPointer up = 0;
|
||||
sq_pushobject(vm,_o);
|
||||
sq_getinstanceup(vm,-1,(SQUserPointer*)&up,(SQUserPointer)tag);
|
||||
sq_pop(vm,1);
|
||||
return up;
|
||||
}
|
||||
|
||||
bool SquirrelObject::SetInstanceUP(SQUserPointer up)
|
||||
{
|
||||
if(!sq_isinstance(_o)) return false;
|
||||
sq_pushobject(vm,_o);
|
||||
sq_setinstanceup(vm,-1,up);
|
||||
sq_pop(vm,1);
|
||||
return true;
|
||||
}
|
||||
|
||||
SquirrelObject SquirrelObject::GetAttributes(const SQChar *key)
|
||||
{
|
||||
SquirrelObject ret(vm);
|
||||
int top = sq_gettop(vm);
|
||||
sq_pushobject(vm,_o);
|
||||
if(key)
|
||||
sq_pushstring(vm,key,-1);
|
||||
else
|
||||
sq_pushnull(vm);
|
||||
if(SQ_SUCCEEDED(sq_getattributes(vm,-2))) {
|
||||
ret.AttachToStackObject(-1);
|
||||
}
|
||||
sq_settop(vm,top);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SquirrelObject::BeginIteration()
|
||||
{
|
||||
if(!sq_istable(_o) && !sq_isarray(_o) && !sq_isclass(_o))
|
||||
return false;
|
||||
sq_pushobject(vm,_o);
|
||||
sq_pushnull(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SquirrelObject::Next(SquirrelObject &key,SquirrelObject &val)
|
||||
{
|
||||
if(SQ_SUCCEEDED(sq_next(vm,-2))) {
|
||||
key.AttachToStackObject(-2);
|
||||
val.AttachToStackObject(-1);
|
||||
sq_pop(vm,2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const SQChar* SquirrelObject::ToString()
|
||||
{
|
||||
return sq_objtostring(&_o);
|
||||
}
|
||||
|
||||
SQInteger SquirrelObject::ToInteger()
|
||||
{
|
||||
return sq_objtointeger(&_o);
|
||||
}
|
||||
|
||||
SQFloat SquirrelObject::ToFloat()
|
||||
{
|
||||
return sq_objtofloat(&_o);
|
||||
}
|
||||
|
||||
bool SquirrelObject::ToBool()
|
||||
{
|
||||
//<<FIXME>>
|
||||
return _o._unVal.nInteger?true:false;
|
||||
}
|
||||
|
||||
void SquirrelObject::EndIteration()
|
||||
{
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
29
include/modules/script_squirrel/cobject/uc_binding.cpp
Normal file
29
include/modules/script_squirrel/cobject/uc_binding.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/geometry_template_decl.h"
|
||||
#include "script_squirrel/cobject/cobject_decl.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/uv_decl.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterUCBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
// Engine types wrapper object.
|
||||
_INIT_CLASS(vm, CObject)
|
||||
|
||||
// VM owned objects.
|
||||
_INIT_CLASS(vm, GeometryTemplate)
|
||||
|
||||
_INIT_CLASS(vm, Matrix3)
|
||||
_INIT_CLASS(vm, Matrix4)
|
||||
_INIT_CLASS(vm, Vector)
|
||||
|
||||
_INIT_CLASS(vm, UV)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
122
include/modules/script_squirrel/cobject/uv_impl.cpp
Normal file
122
include/modules/script_squirrel/cobject/uv_impl.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/cobject/uv_decl.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
|
||||
_IMPL_NATIVE_CONSTRUCTION(UV, GS::Vector2);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(UV, constructor)
|
||||
Vector2 temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(0, 0); break;
|
||||
case 2:
|
||||
if (sa.GetType(2) == OT_INSTANCE)
|
||||
{
|
||||
_GetTypedParam(uv, 2, Vector2, UV);
|
||||
if (uv)
|
||||
temp = *uv;
|
||||
else return sa.ThrowError("Invalid instance type");
|
||||
}
|
||||
else temp.Set(sa.GetFloat(2), 0);
|
||||
break;
|
||||
case 3: temp.Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Wrong parameter count");
|
||||
}
|
||||
return construct_UV(v, new Vector2(temp));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, _cloned)
|
||||
_GetTypedParam(uv, 2, Vector2, UV);
|
||||
return construct_UV(v, new Vector2(*uv));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, _set)
|
||||
_GetSelf(Vector2, UV);
|
||||
|
||||
const SQChar *s = sa.GetString(2);
|
||||
int index = s ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'u': case 'x':
|
||||
return sa.Return(self->x = sa.GetFloat(3));
|
||||
case 1: case 'v': case 'y':
|
||||
return sa.Return(self->y = sa.GetFloat(3));
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, _get)
|
||||
_GetSelf(Vector2, UV);
|
||||
const SQChar *s = sa.GetString(2);
|
||||
if (s && (s[1] != 0))
|
||||
return SQ_ERROR;
|
||||
int index = s && (s[1] == 0) ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'u': case 'x':
|
||||
return sa.Return(self->x);
|
||||
case 1: case 'v': case 'y':
|
||||
return sa.Return(self->y);
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(UV, Set)
|
||||
_GetSelf(Vector2, UV);
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 1: self->Set(0, 0); break;
|
||||
case 2: self->Set(sa.GetFloat(2), 0); break;
|
||||
case 3: self->Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
default:
|
||||
return sa.ThrowError("Wrong parameter count");
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/*#
|
||||
Topic: UV
|
||||
Type: UV
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: UVGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
_BEGIN_CLASS(UV)
|
||||
|
||||
_MEMBER_FUNCTION(UV, constructor, -1, _T(".n|xn"))
|
||||
_MEMBER_FUNCTION(UV, _cloned, 2, _T(".x"))
|
||||
_MEMBER_FUNCTION(UV, _set, 3, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(UV, _get, 2, _T("xs|n"))
|
||||
|
||||
/*#
|
||||
Func: Set
|
||||
Proto: void:float x = 0,float y = 0
|
||||
Desc: Set UV values.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(UV, Set, -1, _T("xnn"))
|
||||
|
||||
_END_CLASS(UV)
|
||||
//------------------------------------------------------------------------------
|
||||
533
include/modules/script_squirrel/cobject/vector_impl.cpp
Normal file
533
include/modules/script_squirrel/cobject/vector_impl.cpp
Normal file
@ -0,0 +1,533 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "math/matrix4.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "math/vector.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
#ifndef _T
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
_IMPL_NATIVE_CONSTRUCTION(Vector, Vector4);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
_MEMBER_FUNCTION_IMPL(Vector, constructor)
|
||||
Vector4 temp;
|
||||
int nparams = sa.GetParamCount();
|
||||
|
||||
switch (nparams)
|
||||
{
|
||||
case 1: temp.Set(); break;
|
||||
case 2:
|
||||
if (sa.GetType(2) == OT_INSTANCE)
|
||||
{
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
if (vec)
|
||||
temp = *vec;
|
||||
else return sa.ThrowError("Vector() invalid instance type");
|
||||
}
|
||||
else
|
||||
temp.Set(sa.GetFloat(2));
|
||||
break;
|
||||
case 3: temp.Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
case 4: temp.Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4)); break;
|
||||
case 5: temp.Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5)); break;
|
||||
|
||||
default:
|
||||
return sa.ThrowError("Vector wrong parameters");
|
||||
}
|
||||
return construct_Vector(v, new Vector4(temp));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _cloned)
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return construct_Vector(v, new Vector4(*vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _set)
|
||||
_GetSelf(Vector4, Vector);
|
||||
|
||||
const SQChar *s = sa.GetString(2);
|
||||
int index = s ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x': case 'r':
|
||||
return sa.Return(self->x = sa.GetFloat(3));
|
||||
case 1: case 'y': case 'g':
|
||||
return sa.Return(self->y = sa.GetFloat(3));
|
||||
case 2: case 'z': case 'b':
|
||||
return sa.Return(self->z = sa.GetFloat(3));
|
||||
case 3: case 'w': case 'a':
|
||||
return sa.Return(self->w = sa.GetFloat(3));
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _get)
|
||||
_GetSelf(Vector4, Vector);
|
||||
const SQChar *s = sa.GetString(2);
|
||||
if (s && (s[1] != 0))
|
||||
return SQ_ERROR;
|
||||
int index = s && (s[1] == 0) ? s[0] : sa.GetInt(2);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0: case 'x': case 'r':
|
||||
return sa.Return(self->x);
|
||||
case 1: case 'y': case 'g':
|
||||
return sa.Return(self->y);
|
||||
case 2: case 'z': case 'b':
|
||||
return sa.Return(self->z);
|
||||
case 3: case 'w': case 'a':
|
||||
return sa.Return(self->w);
|
||||
}
|
||||
return SQ_ERROR;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _add)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self + *vec)) }
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self + sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector + operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _sub)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self - *vec)); }
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self - sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector - operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _mul)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Vector * Vector.
|
||||
_CHECK_INST_PARAM_RAW(vec, 2, Vector4, Vector);
|
||||
if (vec)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * *vec));
|
||||
// Vector * Matrix3.
|
||||
_CHECK_INST_PARAM_RAW(m3, 2, Matrix3, Matrix3);
|
||||
if (m3)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * *m3));
|
||||
// Vector * Matrix4.
|
||||
_CHECK_INST_PARAM_RAW(m4, 2, Matrix4, Matrix4);
|
||||
if (m4)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * *m4));
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_INTEGER:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * (float)sa.GetInt(2)));
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector * operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector,_div)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self / *vec)); }
|
||||
case OT_FLOAT:
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self / sa.GetFloat(2)));
|
||||
}
|
||||
return sa.ThrowError("Vector / operator: Invalid argument type.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Set)
|
||||
_GetSelf(Vector4, Vector);
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 1: self->Set(); break;
|
||||
case 2: self->Set(sa.GetFloat(2)); break;
|
||||
case 3: self->Set(sa.GetFloat(2), sa.GetFloat(3)); break;
|
||||
case 4: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4)); break;
|
||||
case 5: self->Set(sa.GetFloat(2), sa.GetFloat(3), sa.GetFloat(4), sa.GetFloat(5)); break;
|
||||
default:
|
||||
return sa.ThrowError("Vector Set() wrong parameters");
|
||||
}
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Dot)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(self->Dot(*vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Cross)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Cross(*vec)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, AngleWithVector)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(acosf(Types::Clamp(self->Dot(*vec), -1.f, 1.f)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Reverse)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Reversed()));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Dist)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(Vector4::Dist(*self, *vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Dist2)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return(Vector4::Dist2(*self, *vec));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Len)
|
||||
_GetSelf(Vector4, Vector);
|
||||
return sa.Return(self->Len());
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Len2)
|
||||
_GetSelf(Vector4, Vector);
|
||||
return sa.Return(self->Len2());
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, ClampMagnitude)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->ClampedMagnitude(0, sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, clamp)
|
||||
_GetSelf(Vector4, Vector);
|
||||
Vector4 mn, mx;
|
||||
if (sa.GetType(2) == OT_INSTANCE)
|
||||
{ _GetTypedParam(_mn, 2, Vector4, Vector); mn = *_mn; }
|
||||
else mn.Set(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2));
|
||||
if (sa.GetType(3) == OT_INSTANCE)
|
||||
{ _GetTypedParam(_mx, 3, Vector4, Vector); mx = *_mx; }
|
||||
else mx.Set(sa.GetFloat(3), sa.GetFloat(3), sa.GetFloat(3));
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Clamped(mn, mx)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, ApplyMatrix)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_CHECK_INST_PARAM_RAW(m3, 2, Matrix3, Matrix3);
|
||||
if (m3) _SA_RETURN_OBJECT(new_Vector(v, *self * *m3));
|
||||
_CHECK_INST_PARAM_RAW(m4, 2, Matrix4, Matrix4);
|
||||
if (m4) _SA_RETURN_OBJECT(new_Vector(v, *self * *m4));
|
||||
return sa.ThrowError("Vector::ApplyMatrix(): Invalid parameter");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, ApplyRotationMatrix)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_CHECK_INST_PARAM_RAW(m3, 2, Matrix3, Matrix3);
|
||||
if (m3) _SA_RETURN_OBJECT(new_Vector(v, *self * *m3));
|
||||
_CHECK_INST_PARAM_RAW(m4, 2, Matrix4, Matrix4);
|
||||
if (m4) _SA_RETURN_OBJECT(new_Vector(v, *self * Matrix3::FromMatrix4(*m4)));
|
||||
return sa.ThrowError("Vector::ApplyRotationMatrix(): Invalid parameter");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Randomize)
|
||||
if (sa.GetParamCount() == 2)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4::Random(0, sa.GetFloat(2))));
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4::Random(sa.GetFloat(2), sa.GetFloat(3))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Normalize)
|
||||
_GetSelf(Vector4, Vector);
|
||||
if (sa.GetParamCount() == 1)
|
||||
_SA_RETURN_OBJECT(new_Vector(v, self->Normalized()))
|
||||
else _SA_RETURN_OBJECT(new_Vector(v, self->Normalized() * sa.GetFloat(2)))
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Lerp)
|
||||
_GetSelf(Vector4, Vector);
|
||||
float k = sa.GetFloat(2), ik = 1.f - k;
|
||||
_GetTypedParam(vec, 3, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * k + *vec * ik));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, _cmp)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
return sa.Return((*self) == (*vec) ? true : false);
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, IsEqual)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_GetTypedParam(vec, 2, Vector4, Vector);
|
||||
float d2 = 0.0001f;
|
||||
switch (sa.GetParamCount())
|
||||
{
|
||||
case 2: break;
|
||||
case 3: d2 = sa.GetFloat(3); break;
|
||||
default: return sa.ThrowError("Vector::IsEqual() wrong parameter count");
|
||||
}
|
||||
d2 *= d2;
|
||||
return sa.Return(Vector4::Dist2(*self, *vec) < d2 ? true : false);
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Min)
|
||||
_GetSelf(Vector4, Vector);
|
||||
|
||||
if ((sa.GetParamCount() == 2) || (sa.GetParamCount() == 4))
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x < vec->x ? self->x : vec->x, self->y < vec->y ? self->y : vec->y, self->z < vec->z ? self->z : vec->z))); }
|
||||
case OT_FLOAT:
|
||||
{ float x = sa.GetFloat(2), y = sa.GetFloat(3), z = sa.GetFloat(4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x < x ? self->x : x, self->y < y ? self->y : y, self->z < z ? self->z : z))); }
|
||||
}
|
||||
return sa.ThrowError("Vector Min(): Invalid parameter list.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Max)
|
||||
_GetSelf(Vector4, Vector);
|
||||
if ((sa.GetParamCount() == 2) || (sa.GetParamCount() == 4))
|
||||
switch (sa.GetType(2))
|
||||
{
|
||||
case OT_INSTANCE:
|
||||
{ _GetTypedParam(vec, 2, Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x > vec->x ? self->x : vec->x, self->y > vec->y ? self->y : vec->y, self->z > vec->z ? self->z : vec->z))); }
|
||||
case OT_FLOAT:
|
||||
{ float x = sa.GetFloat(2), y = sa.GetFloat(3), z = sa.GetFloat(4);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, Vector4(self->x > x ? self->x : x, self->y > y ? self->y : y, self->z > z ? self->z : z))); }
|
||||
}
|
||||
return sa.ThrowError("Vector Max(): Invalid parameter list.\n");
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Scale)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * sa.GetFloat(2)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, AddReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self + Vector4(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, MulReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * Vector4(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, SubReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self - Vector4(sa.GetFloat(2), sa.GetFloat(2), sa.GetFloat(2))));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, DivReal)
|
||||
_GetSelf(Vector4, Vector);
|
||||
const float ik = 1.f / sa.GetFloat(2);
|
||||
_SA_RETURN_OBJECT(new_Vector(v, *self * Vector4(ik, ik, ik)));
|
||||
_END_IMPL
|
||||
|
||||
_MEMBER_FUNCTION_IMPL(Vector, Print)
|
||||
_GetSelf(Vector4, Vector);
|
||||
const char *label = "Vector";
|
||||
if (sa.GetParamCount() == 2)
|
||||
label = sa.GetString(2);
|
||||
__LOG__ << label << ": { " << self->x << ", " << self->y << ", " << self->z << ", " << self->w << "}\n";
|
||||
return 0;
|
||||
_END_IMPL
|
||||
|
||||
/*#
|
||||
Topic: Vector
|
||||
Type: Vector
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: VectorGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
_BEGIN_CLASS(Vector)
|
||||
|
||||
/*#
|
||||
Func: Vector
|
||||
Proto: Vector:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Create a new vector.
|
||||
Example: local v = Vector(1, 0, 0)
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, constructor, -1, _T(".n|xnnn"))
|
||||
_MEMBER_FUNCTION(Vector, _cloned, 2, _T(".x"))
|
||||
_MEMBER_FUNCTION(Vector, _set, 3, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Vector, _get, 2, _T("xs|n"))
|
||||
_MEMBER_FUNCTION(Vector, _add, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _sub, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _mul, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _div, 2, _T("xx|n"))
|
||||
_MEMBER_FUNCTION(Vector, _cmp, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Func: Set
|
||||
Proto: void:float x = 0,float y = 0,float z = 0,float w = 1
|
||||
Desc: Set vector values.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Set, -1, _T("xnnnn"))
|
||||
/*#
|
||||
Func: ApplyMatrix
|
||||
Proto: Vector:[Matrix4|Matrix3] matrix
|
||||
Desc: Transform vector by a given matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, ApplyMatrix, 2, _T("xx"))
|
||||
/*#
|
||||
Func: ApplyRotationMatrix
|
||||
Proto: Vector:[Matrix4|Matrix3] matrix
|
||||
Desc: Transform vector by the rotation part of a given matrix.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, ApplyRotationMatrix, 2, _T("xx"))
|
||||
|
||||
_MEMBER_FUNCTION(Vector, AddReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, MulReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, SubReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, DivReal, 2, _T("xn"))
|
||||
_MEMBER_FUNCTION(Vector, Scale, 2, _T("xn"))
|
||||
/*#
|
||||
Func: Clamp
|
||||
Proto: Vector:(Vector|float) min,(Vector|float) max
|
||||
Desc: Individually clamp vector components to a given range.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, clamp, 3, _T("x x|n x|n"))
|
||||
/*#
|
||||
Func: ClampMagnitude
|
||||
Proto: Vector:float len
|
||||
Desc: Clamp vector magnitude to a specific length.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, ClampMagnitude, 2, _T("xn"))
|
||||
/*#
|
||||
Func: Reverse
|
||||
Proto: Vector:
|
||||
Desc: Return the reverse vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Reverse, 1, _T("x"))
|
||||
|
||||
/*#
|
||||
Func: Min
|
||||
Proto: Vector:[Vector|float x,float y, float z] min
|
||||
Desc: Return the smallest value of the vector component or parameter for all the vector components.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Min, -2, _T("xn|xnn"))
|
||||
/*#
|
||||
Func: Max
|
||||
Proto: Vector:[Vector|float x,float y, float z] max
|
||||
Desc: Return the largest value of the vector component or parameter for all the vector components.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Max, -2, _T("xn|xnn"))
|
||||
|
||||
/*#
|
||||
Func: Dot
|
||||
Proto: float:Vector v
|
||||
Desc: Return the dot product between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Dot, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Cross
|
||||
Proto: Vector:Vector v
|
||||
Desc: Return the cross product between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Cross, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Len
|
||||
Proto: float:Vector v
|
||||
Desc: Return the length of this vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Len, 1, _T("x"))
|
||||
/*#
|
||||
Func: Len2
|
||||
Proto: float:Vector v
|
||||
Desc: Return the squared length of this vector.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Len2, 1, _T("x"))
|
||||
/*#
|
||||
Func: AngleWithVector
|
||||
Proto: float:Vector v
|
||||
Desc: Return the angle between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, AngleWithVector, 2, _T("xx"))
|
||||
|
||||
/*#
|
||||
Func: Normalize
|
||||
Proto: Vector:float length = 1
|
||||
Desc: Return a normalized version of this vector scaled to a constant.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Normalize, -1, _T("xn"))
|
||||
/*#
|
||||
Func: Dist
|
||||
Proto: float:Vector v
|
||||
Desc: Return the distance between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Dist, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Dist2
|
||||
Proto: float:Vector v
|
||||
Desc: Return the squared distance between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Dist2, 2, _T("xx"))
|
||||
/*#
|
||||
Func: Lerp
|
||||
Proto: float:Vector v,float t
|
||||
Desc: Return a linearly interpolated vector between two vectors.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Lerp, 3, _T("xnx"))
|
||||
/*#
|
||||
Func: Randomize
|
||||
Proto: Vector:Vector v,float min,float max
|
||||
Desc: Return a random vector in a given range.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Randomize, -2, _T(".nn"))
|
||||
|
||||
/*#
|
||||
Func: IsEqual
|
||||
Proto: bool:Vector v,float epsilon = 0.0001
|
||||
Desc: Test vectors for equality with a given espilon tolerance.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, IsEqual, -2, _T("xxn"))
|
||||
/*#
|
||||
Func: Print
|
||||
Proto: void:
|
||||
Desc: Dump this vector components to the engine log.
|
||||
#*/
|
||||
_MEMBER_FUNCTION(Vector, Print, -1, _T("x"))
|
||||
|
||||
_END_CLASS(Vector)
|
||||
|
||||
//-----------------------------------------------
|
||||
void UCBind_RegisterVector(HSQUIRRELVM vm)
|
||||
//-----------------------------------------------
|
||||
{
|
||||
_INIT_CLASS(vm, Vector);
|
||||
}
|
||||
142
include/modules/script_squirrel/engine_vm.cpp
Normal file
142
include/modules/script_squirrel/engine_vm.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/engine_vm.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/cobject/cobject_decl.h"
|
||||
#include "script_squirrel/legacy/squirrel_binding.h"
|
||||
#include "script/scripted_object.h"
|
||||
#include "script/script_variant.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool EngineVM::Open()
|
||||
{
|
||||
if (!SquirrelVM::Open())
|
||||
return false;
|
||||
|
||||
#define __SQ_REGISTERINT(__NAME__, __V__) sq_pushstring(vm, __NAME__, -1); sq_pushinteger(vm, __V__); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
__SQ_REGISTERINT("objectTypeUndefined", typetag_Undefined)
|
||||
__SQ_REGISTERINT("objectTypeDeleted", typetag_Deleted)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeEngine", typetag_Engine)
|
||||
__SQ_REGISTERINT("objectTypeResourceCache", typetag_ResourceSet)
|
||||
__SQ_REGISTERINT("objectTypeProject", typetag_Project)
|
||||
__SQ_REGISTERINT("objectTypeRenderer", typetag_Renderer)
|
||||
__SQ_REGISTERINT("objectTypeRaytracer", typetag_Raytracer)
|
||||
__SQ_REGISTERINT("objectTypeMixer", typetag_Mixer)
|
||||
__SQ_REGISTERINT("objectTypeScene", typetag_Scene3d)
|
||||
__SQ_REGISTERINT("objectTypeClock", typetag_Clock)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeFont", typetag_Font)
|
||||
__SQ_REGISTERINT("objectTypeRasterFont", typetag_RasterFont)
|
||||
__SQ_REGISTERINT("objectTypeUI", typetag_Scene2d)
|
||||
__SQ_REGISTERINT("objectTypeUICursor", typetag_UICursor)
|
||||
__SQ_REGISTERINT("objectTypeWindow", typetag_Window)
|
||||
__SQ_REGISTERINT("objectTypeWidget", typetag_Widget)
|
||||
__SQ_REGISTERINT("objectTypeSizerWidget", typetag_SizerWidget)
|
||||
__SQ_REGISTERINT("objectTypeContainerWidget", typetag_ContainerWidget)
|
||||
__SQ_REGISTERINT("objectTypeSpacerWidget", typetag_SpacerWidget)
|
||||
__SQ_REGISTERINT("objectTypeCanvasWidget", typetag_CanvasWidget)
|
||||
__SQ_REGISTERINT("objectTypeTextWidget", typetag_TextWidget)
|
||||
__SQ_REGISTERINT("objectTypeBitmapWidget", typetag_BitmapWidget)
|
||||
__SQ_REGISTERINT("objectTypeCheckWidget", typetag_CheckWidget)
|
||||
__SQ_REGISTERINT("objectTypePicture", typetag_Picture)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeGroup", typetag_Group)
|
||||
__SQ_REGISTERINT("objectTypeItem", typetag_Item)
|
||||
__SQ_REGISTERINT("objectTypeCamera", typetag_Camera)
|
||||
__SQ_REGISTERINT("objectTypeObject", typetag_Object)
|
||||
__SQ_REGISTERINT("objectTypeLight", typetag_Light)
|
||||
__SQ_REGISTERINT("objectTypeInstance", typetag_Instance)
|
||||
__SQ_REGISTERINT("objectTypeMotion", typetag_Motion)
|
||||
__SQ_REGISTERINT("objectTypeTrigger", typetag_Trigger)
|
||||
__SQ_REGISTERINT("objectTypePath", typetag_Path)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeSound", typetag_Sound)
|
||||
__SQ_REGISTERINT("objectTypeTexture", typetag_Texture)
|
||||
__SQ_REGISTERINT("objectTypeGeometry", typetag_Geometry)
|
||||
__SQ_REGISTERINT("objectTypeMaterial", typetag_Material)
|
||||
__SQ_REGISTERINT("objectTypeColShape", typetag_ColShape)
|
||||
__SQ_REGISTERINT("objectTypeConstraint", typetag_Constraint)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeMetafile", typetag_Metafile)
|
||||
__SQ_REGISTERINT("objectTypeMetatag", typetag_Metatag)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeHidDevice", typetag_InputDevice)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeEditorPlugin", typetag_EditorPlugin)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeProjectScene", typetag_ProjectScene)
|
||||
__SQ_REGISTERINT("objectTypeProjectLayer", typetag_ProjectLayer)
|
||||
|
||||
__SQ_REGISTERINT("objectTypeAnimationSource", typetag_AutomationSource)
|
||||
__SQ_REGISTERINT("objectTypeAnimationSourceGroup", typetag_AutomationSourceGroup)
|
||||
|
||||
sq_pop(vm, 1);
|
||||
|
||||
_INIT_CLASS(vm, CObject);
|
||||
|
||||
RegisterAllSquirrelBinding(vm);
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool EngineVM::PushVariant(const Variant &v)
|
||||
{
|
||||
if (v.type == Variant::Type_UserObject)
|
||||
return CObject::Push(vm, v.ptr, (CObjectType)v.typetag);
|
||||
return SquirrelVM::PushVariant(v);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
int EngineVM::InvalidateNativeReference(void *ptr)
|
||||
{
|
||||
uint invalidated_count = 0;
|
||||
ListForeachPtr(CObject *, o, cobjects)
|
||||
if (o->native == ptr)
|
||||
{
|
||||
cobjects.Remove(o);
|
||||
|
||||
o->list_item = NULL;
|
||||
o->type = typetag_Deleted;
|
||||
o->native = NULL;
|
||||
|
||||
++invalidated_count;
|
||||
}
|
||||
|
||||
// __LOG_E__ << "Invalidate native object " << nString::Format("0x%x", ptr) << " - reference found: " << count << ", CObject left: " << safe_ptr_list.GetCount() << ".\n";
|
||||
return invalidated_count;
|
||||
}
|
||||
void EngineVM::ReleaseAllNativeReferences()
|
||||
{
|
||||
ListForeachPtr(CObject *, o, cobjects)
|
||||
o->Release();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void EngineVM::Close()
|
||||
{
|
||||
/*
|
||||
[EJ] We have to drop all native object references now. If we don't,
|
||||
native objects holding a reference to a script object will crash the VM
|
||||
when they try to release it from their destructor (hence making a
|
||||
reentrant call into the VM).
|
||||
*/
|
||||
ReleaseAllNativeReferences();
|
||||
|
||||
SquirrelVM::Close();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
161
include/modules/script_squirrel/engine_vm_debugger.cpp
Normal file
161
include/modules/script_squirrel/engine_vm_debugger.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/engine_vm_debugger.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/engine_vm.h"
|
||||
#include "core/sound.h"
|
||||
#include "motion/motion.h"
|
||||
#include "scene3d/group.h"
|
||||
#include "scene3d/mobject.h"
|
||||
#include "scene3d/mlight.h"
|
||||
#include "scene3d/mcamera.h"
|
||||
#include "scene3d/mtrigger.h"
|
||||
#include "scene3d/scene.h"
|
||||
#include "project/project.h"
|
||||
#include "script/script_profiler.h"
|
||||
#include "script/scripted_object.h"
|
||||
#include "raytracer/raytracer_core.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
String SquirrelDebugger::FormatUserObjectParameter(CObjectType type)
|
||||
{
|
||||
// Check for null safe ptr.
|
||||
void *test;
|
||||
CObject::Get(vm, -1, &test);
|
||||
if (!test)
|
||||
return "Null";
|
||||
|
||||
// Get type specific data.
|
||||
switch (type)
|
||||
{
|
||||
case typetag_Group:
|
||||
{
|
||||
S3D::Group *group;
|
||||
CObject::Get(vm, -1, (void **)&group, type);
|
||||
return String::Format("(id='%s', items=%d, ...)", group->name.c_str(), group->GetItemList().GetCount());
|
||||
}
|
||||
case typetag_Motion:
|
||||
{
|
||||
Core::Motion *motion;
|
||||
CObject::Get(vm, -1, (void **)&motion, type);
|
||||
return String::Format("(id='%s', channels=%d, length=%.2fs, ...)", motion->name.c_str(), motion->GetChannelList().GetCount(), motion->GetDuration().toSec());
|
||||
}
|
||||
case typetag_Geometry:
|
||||
{
|
||||
Render::Geometry *geometry;
|
||||
CObject::Get(vm, -1, (void **)&geometry, type);
|
||||
return String::Format("(id='%s', vertex=%d, material=%d, ...)", geometry->name.c_str(), geometry->material_table.GetCount());
|
||||
}
|
||||
case typetag_Picture:
|
||||
{
|
||||
Picture *picture;
|
||||
CObject::Get(vm, -1, (void **)&picture, type);
|
||||
return String::Format("(w=%dpx, h=%dpx, ...)", picture->GetWidth(), picture->GetHeight());
|
||||
}
|
||||
case typetag_Texture:
|
||||
{
|
||||
Render::Texture *texture;
|
||||
CObject::Get(vm, -1, (void **)&texture, type);
|
||||
return String::Format("(id='%s', w=%dpx, h=%dpx, ...)", texture->name.c_str(), texture->GetWidth(), texture->GetHeight());
|
||||
}
|
||||
case typetag_Sound:
|
||||
{
|
||||
Audio::Sound *sound;
|
||||
CObject::Get(vm, -1, (void **)&sound, type);
|
||||
return String::Format("(id='%s')", sound->name.c_str());
|
||||
}
|
||||
case typetag_Object:
|
||||
{
|
||||
S3D::MObject *object;
|
||||
CObject::Get(vm, -1, (void **)&object, type);
|
||||
return String::Format("(id='%s', uid=%d, geometry='%s', ...)", object->name.c_str(), object->GetUid(), object->geometry.IsEmpty() ? "None" : object->geometry.c_str());
|
||||
}
|
||||
case typetag_Light:
|
||||
{
|
||||
S3D::MLight *light;
|
||||
CObject::Get(vm, -1, (void **)&light, type);
|
||||
return String::Format("(id='%s', uid=%d, diffuse=%.2f, specular=%.2f, ...)", light->name.toUtf8(), light->GetUid(), light->diffuse_intensity, light->specular_intensity);
|
||||
}
|
||||
case typetag_Camera:
|
||||
{
|
||||
S3D::MCamera *camera;
|
||||
CObject::Get(vm, -1, (void **)&camera, type);
|
||||
return String::Format("(id='%s', uid=%d, fov=%.2f, ...)", camera->name.toUtf8(), camera->GetUid(), camera->GetFov());
|
||||
}
|
||||
case typetag_Trigger:
|
||||
{
|
||||
S3D::MTrigger *trigger;
|
||||
CObject::Get(vm, -1, (void **)&trigger, type);
|
||||
return String::Format("(id='%s', uid=%d, ...)", trigger->name.toUtf8(), trigger->GetUid());
|
||||
}
|
||||
case typetag_Scene3d:
|
||||
{
|
||||
S3D::Scene *scene;
|
||||
CObject::Get(vm, -1, (void **)&scene, type);
|
||||
return String::Format("(id='%s', items=%d, ...)", scene->name.toUtf8(), scene->GetItemList().GetCount());
|
||||
}
|
||||
case typetag_Item:
|
||||
{
|
||||
S3D::MItem *item;
|
||||
CObject::Get(vm, -1, (void **)&item, type);
|
||||
return String::Format("(id='%s', uid=%d, scripted=%s, ...)", item->name.toUtf8(), item->GetUid(), item->scripted_object.IsValid() && item->scripted_object->GetUnitList().GetCount() ? "True" : "False");
|
||||
}
|
||||
case typetag_Raytracer:
|
||||
{
|
||||
Raytrace::Raytracer *ray;
|
||||
CObject::Get(vm, -1, (void **)&ray, type);
|
||||
Raytrace::Configuration cfg = ray->GetConfiguration();
|
||||
return String::Format("(aa=%s, gi=%s, interlaced=%s, ...)", cfg.trace_aa ? "True" : "False", cfg.trace_gi ? "True" : "False", cfg.interlaced ? "True" : "False");
|
||||
}
|
||||
case typetag_Material:
|
||||
{
|
||||
Render::Material *material;
|
||||
CObject::Get(vm, -1, (void **)&material, type);
|
||||
return String::Format("(id='%s', ...)", material->name.toUtf8());
|
||||
}
|
||||
case typetag_Metafile:
|
||||
{
|
||||
NML::File *metafile;
|
||||
CObject::Get(vm, -1, (void **)&metafile, type);
|
||||
return String::Format("(path='%s', ...)", metafile->name.toUtf8());
|
||||
}
|
||||
case typetag_Metatag:
|
||||
{
|
||||
NML::Tag *metatag;
|
||||
CObject::Get(vm, -1, (void **)&metatag, type);
|
||||
return String::Format("(id='%s', ...)", metatag->name.toUtf8());
|
||||
}
|
||||
case typetag_ColShape:
|
||||
{
|
||||
S3D::PhysicShape *shape;
|
||||
CObject::Get(vm, -1, (void **)&shape, type);
|
||||
|
||||
String _type = "...";
|
||||
switch (shape->GetType())
|
||||
{
|
||||
case S3D::PhysicShape::TypeBox: _type = "Box"; break;
|
||||
case S3D::PhysicShape::TypeCone: _type = "Cone"; break;
|
||||
case S3D::PhysicShape::TypeSphere: _type = "Sphere"; break;
|
||||
case S3D::PhysicShape::TypeConvex: _type = "Convex"; break;
|
||||
case S3D::PhysicShape::TypeMesh: _type = "Mesh"; break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
return String::Format("(type=%s, mass=%.2f, ...)", _type.toUtf8(), shape->mass);
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
return String("...");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
EngineDebugger::EngineDebugger(EngineVM &vm) : SquirrelDebugger(vm) {}
|
||||
9
include/modules/script_squirrel/engine_vm_profiler.cpp
Normal file
9
include/modules/script_squirrel/engine_vm_profiler.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/engine_vm_profiler.h"
|
||||
|
||||
using namespace GS::Script;
|
||||
23
include/modules/script_squirrel/legacy/ai_binding.cpp
Normal file
23
include/modules/script_squirrel/legacy/ai_binding.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
|
||||
|
||||
//-------------------------------------------
|
||||
void RegisterAIBinding(HSQUIRRELVM vm)
|
||||
//-------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: AI
|
||||
Type: Path
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: AIPath
|
||||
Desc: AI Path functions
|
||||
#*/
|
||||
}
|
||||
419
include/modules/script_squirrel/legacy/animation_binding.cpp
Normal file
419
include/modules/script_squirrel/legacy/animation_binding.cpp
Normal file
@ -0,0 +1,419 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "squirrel_binding.h"
|
||||
#include "binding_helpers.h"
|
||||
#include "motion/motion.h"
|
||||
#include "automation/automation_source_group.h"
|
||||
#include "automation/automation_player.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
using namespace GS::Automation;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceSetLoopMode(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETINT(loop_mode)
|
||||
__SQ_GETEND
|
||||
source->SetLoopMode((Curve::LoopMode)loop_mode);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceSetLoop(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETFLOAT(loop_start)
|
||||
__SQ_GETFLOAT(loop_end)
|
||||
__SQ_GETEND
|
||||
source->SetLoop(Time::fromSec(loop_start), Time::fromSec(loop_end));
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceGetClock(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_RETURNFLOAT(source->time.toSec())
|
||||
}
|
||||
SQInteger AnimationSourceSetClock(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETFLOAT(time)
|
||||
__SQ_GETEND
|
||||
source->time = Time::fromSec(time);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceGetClockScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_RETURNFLOAT(source->time_scale)
|
||||
}
|
||||
SQInteger AnimationSourceSetClockScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETFLOAT(scale)
|
||||
__SQ_GETEND
|
||||
source->time_scale = scale;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceIsRelative(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_RETURNBOOL(source->relative);
|
||||
}
|
||||
SQInteger AnimationSourceSetRelative(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETBOOL(relative)
|
||||
__SQ_GETEND
|
||||
source->relative = asbool(relative);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceSetWeight(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETFLOAT(weight)
|
||||
__SQ_GETFLOAT(blend)
|
||||
__SQ_GETEND
|
||||
source->SetWeight(weight, blend);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceStop(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETFLOAT(blend)
|
||||
__SQ_GETEND
|
||||
source->Dispose(blend);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceIsDone(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_RETURNBOOL(source->IsDone());
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Group
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceGroupGetSourceCount(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_RETURNINT(group->source_list.GetCount())
|
||||
}
|
||||
SQInteger AnimationSourceGroupGetSource(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETINT(index)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(group->source_list[index], typetag_AutomationSource)
|
||||
}
|
||||
SQInteger AnimationSourceGroupAddSource(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETSAFEPTR(source, Source, typetag_AutomationSource)
|
||||
__SQ_GETEND
|
||||
group->source_list.Add(source);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceGroupSetLoopMode(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETINT(loop_mode)
|
||||
__SQ_GETEND
|
||||
group->SetLoopMode((Curve::LoopMode)loop_mode);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceGroupSetLoop(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETFLOAT(loop_start)
|
||||
__SQ_GETFLOAT(loop_end)
|
||||
__SQ_GETEND
|
||||
group->SetLoop(Time::fromSec(loop_start), Time::fromSec(loop_end));
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceGroupGetClock(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
if (group->source_list.GetCount() == 0)
|
||||
return sq_throwerror(vm, "No animation source in group");
|
||||
__SQ_RETURNFLOAT(group->source_list[0]->time.toSec())
|
||||
}
|
||||
SQInteger AnimationSourceGroupSetClock(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETFLOAT(time)
|
||||
__SQ_GETEND
|
||||
group->SetTime(Time::fromSec(time));
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceGroupGetClockScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
if (group->source_list.GetCount() == 0)
|
||||
return sq_throwerror(vm, "No animation source in group");
|
||||
__SQ_RETURNFLOAT(group->source_list[0]->time_scale)
|
||||
}
|
||||
SQInteger AnimationSourceGroupSetClockScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETFLOAT(scale)
|
||||
__SQ_GETEND
|
||||
group->SetTimeScale(scale);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceGroupSetRelative(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETBOOL(relative)
|
||||
__SQ_GETEND
|
||||
group->SetRelative(asbool(relative));
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger AnimationSourceGroupSetWeight(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETFLOAT(weight)
|
||||
__SQ_GETFLOAT(blend)
|
||||
__SQ_GETEND
|
||||
group->SetWeight(weight, blend);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceGroupStop(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_GETFLOAT(blend)
|
||||
__SQ_GETEND
|
||||
group->Dispose(blend);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger AnimationSourceGroupIsDone(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, SourceGroup, typetag_AutomationSourceGroup)
|
||||
__SQ_RETURNBOOL(group->IsDone());
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------
|
||||
void RegisterAnimationBinding(HSQUIRRELVM vm)
|
||||
//--------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Animation
|
||||
Type: AnimationSourceGroup
|
||||
Type: AnimationSource
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: Animation Source
|
||||
Desc: Provides control over an animation source.
|
||||
#*/
|
||||
/*#
|
||||
Func: AnimationSourceSetLoopMode
|
||||
Proto: void:AnimationSource, AnimationLoopMode mode
|
||||
Desc: Set animation source loop mode.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceSetLoopMode, "AnimationSourceSetLoopMode", _SC(".xi"));
|
||||
/*#
|
||||
Func: AnimationSourceSetLoop
|
||||
Proto: void:AnimationSource, float loop_start, float loop_end
|
||||
Desc: Set animation source loop point.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceSetLoop, "AnimationSourceSetLoop", _SC(".xnn"));
|
||||
/*#
|
||||
Func: AnimationSourceGetClock
|
||||
Proto: float:AnimationSource
|
||||
Desc: Get animation source clock.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGetClock, "AnimationSourceGetClock", _SC(".x"));
|
||||
/*#
|
||||
Func: AnimationSourceSetClock
|
||||
Proto: void:AnimationSource, float clock
|
||||
Desc: Set animation source clock.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceSetClock, "AnimationSourceSetClock", _SC(".xn"));
|
||||
/*#
|
||||
Func: AnimationSourceGetClockScale
|
||||
Proto: float:AnimationSource
|
||||
Desc: Get animation source clock scale.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGetClockScale, "AnimationSourceGetClockScale", _SC(".x"));
|
||||
/*#
|
||||
Func: AnimationSourceSetClockScale
|
||||
Proto: void:AnimationSource, float clock_scale
|
||||
Desc: Set animation source clock scale.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceSetClockScale, "AnimationSourceSetClockScale", _SC(".xn"));
|
||||
/*#
|
||||
Func: AnimationSourceSetWeight
|
||||
Proto: void:AnimationSource, float weight, float blend
|
||||
Desc: Set animation source weight and weight blend duration.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceSetWeight, "AnimationSourceSetWeight", _SC(".xnn"));
|
||||
/*#
|
||||
Func: AnimationSourceIsRelative
|
||||
Proto: bool:AnimationSource
|
||||
Desc: Return the animation source evaluation mode..
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceIsRelative, "AnimationSourceIsRelative", _SC(".x"));
|
||||
/*#
|
||||
Func: AnimationSourceSetRelative
|
||||
Proto: void:AnimationSource, bool relative
|
||||
Desc: Set animation source evaluation mode to relative instead of absolute.<br>Relative source offsets the value they modify instead of replacing it.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceSetRelative, "AnimationSourceSetRelative", _SC(".xb"));
|
||||
/*#
|
||||
Func: AnimationSourceStop
|
||||
Proto: void:AnimationSource, float blend
|
||||
Desc: Stop an animation source. The motion weight can be brought down to 0 over a given blend duration before the source is stopped.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceStop, "AnimationSourceStop", _SC(".xn"));
|
||||
/*#
|
||||
Func: AnimationSourceIsDone
|
||||
Proto: bool:AnimationSource
|
||||
Desc: Returns true if this animation source is done playing.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceIsDone, "AnimationSourceIsDone", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: Animation Source Group
|
||||
Desc: Provides control over a group of animation sources.
|
||||
#*/
|
||||
/*#
|
||||
Func: AnimationSourceGroupGetSourceCount
|
||||
Proto: int:AnimationSourceGroup
|
||||
Desc: Return the number of animation sources in this group.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupGetSourceCount, "AnimationSourceGroupGetSourceCount", _SC(".x"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupGetSource
|
||||
Proto: AnimationSource:AnimationSourceGroup, int index
|
||||
Desc: Return an animation source from the group.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupGetSource, "AnimationSourceGroupGetSource", _SC(".xi"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupAddSource
|
||||
Proto: void:AnimationSourceGroup, AnimationSource
|
||||
Desc: Add an animation source to the group.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupAddSource, "AnimationSourceGroupAddSource", _SC(".xx"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupSetLoopMode
|
||||
Proto: void:AnimationSourceGroup, AnimationLoopMode mode
|
||||
Desc: Set animation source group loop mode.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupSetLoopMode, "AnimationSourceGroupSetLoopMode", _SC(".xi"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupSetLoop
|
||||
Proto: void:AnimationSourceGroup, float loop_start, float loop_end
|
||||
Desc: Set animation source group loop point.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupSetLoop, "AnimationSourceGroupSetLoop", _SC(".xnn"));
|
||||
|
||||
/*#
|
||||
Func: AnimationSourceGroupGetClock
|
||||
Proto: float:AnimationSourceGroup
|
||||
Desc: Get animation source group clock.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupGetClock, "AnimationSourceGroupGetClock", _SC(".x"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupSetClock
|
||||
Proto: void:AnimationSourceGroup, float clock
|
||||
Desc: Set animation source group clock.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupSetClock, "AnimationSourceGroupSetClock", _SC(".xn"));
|
||||
|
||||
/*#
|
||||
Func: AnimationSourceGroupGetClockScale
|
||||
Proto: float:AnimationSourceGroup
|
||||
Desc: Get animation source group clock scale.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupGetClockScale, "AnimationSourceGroupGetClockScale", _SC(".x"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupSetClockScale
|
||||
Proto: void:AnimationSourceGroup, float clock_scale
|
||||
Desc: Set animation source group clock scale.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupSetClockScale, "AnimationSourceGroupSetClockScale", _SC(".xn"));
|
||||
|
||||
/*#
|
||||
Func: AnimationSourceGroupSetWeight
|
||||
Proto: void:AnimationSourceGroup, float weight, float blend
|
||||
Desc: Set animation source group weight and weight blend duration.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupSetWeight, "AnimationSourceGroupSetWeight", _SC(".xnn"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupSetRelative
|
||||
Proto: void:AnimationSourceGroup, bool relative
|
||||
Desc: Set animation source evaluation mode to relative instead of absolute.<br>Relative source offsets the value they modify instead of replacing it.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupSetRelative, "AnimationSourceGroupSetRelative", _SC(".xb"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupStop
|
||||
Proto: void:AnimationSourceGroup, float blend
|
||||
Desc: Stop an animation source group. The motion weight can be brought down to 0 over a given blend duration before the source group is stopped.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupStop, "AnimationSourceGroupStop", _SC(".xn"));
|
||||
/*#
|
||||
Func: AnimationSourceGroupIsDone
|
||||
Proto: bool:AnimationSourceGroup
|
||||
Desc: Returns true if this animation source group is done playing.
|
||||
#*/
|
||||
sq_register(vm, AnimationSourceGroupIsDone, "AnimationSourceGroupIsDone", _SC(".x"));
|
||||
|
||||
// Push defines.
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: AnimationLoopMode
|
||||
Values: AnimationConstant,AnimationRepeat,AnimationReset,AnimationOffsetRepeat,AnimationOscillate
|
||||
#*/
|
||||
sq_pushstring(vm, "AnimationConstant", -1); sq_pushinteger(vm, Curve::Constant); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "AnimationRepeat", -1); sq_pushinteger(vm, Curve::Repeat); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "AnimationReset", -1); sq_pushinteger(vm, Curve::Reset); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "AnimationOffsetRepeat", -1); sq_pushinteger(vm, Curve::OffsetAndRepeat); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "AnimationOscillate", -1); sq_pushinteger(vm, Curve::Oscillate); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
421
include/modules/script_squirrel/legacy/camera_binding.cpp
Normal file
421
include/modules/script_squirrel/legacy/camera_binding.cpp
Normal file
@ -0,0 +1,421 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "scene3d/scene.h"
|
||||
#include "scene3d/mobject.h"
|
||||
#include "scene3d/mcamera.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "core/renderer.h"
|
||||
#include "math/vector.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
static CObjectType camera_derived_types[] = { typetag_Item, typetag_Camera, typetag_Undefined };
|
||||
static CObjectType object_derived_types[] = { typetag_Item, typetag_Object, typetag_Undefined };
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger CameraGetItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(cam, MCamera, typetag_Camera)
|
||||
__SQ_RETURNSAFEPTR((MItem *)cam, typetag_Item)
|
||||
}
|
||||
SQInteger CameraGetFov(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types))
|
||||
__SQ_RETURNFLOAT(c->GetFov())
|
||||
}
|
||||
SQInteger CameraSetFov(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETFLOAT(f)
|
||||
__SQ_GETEND
|
||||
c->SetFov(f);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger CameraGetZoomFactor(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types))
|
||||
__SQ_RETURNFLOAT(c->zoom_factor)
|
||||
}
|
||||
SQInteger CameraSetZoomFactor(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETFLOAT(z)
|
||||
__SQ_GETEND
|
||||
c->SetZoomFactor(z);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger CameraSetFStop(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETFLOAT(f)
|
||||
__SQ_GETEND
|
||||
c->registry.CreateKey("PostProcess:Dof:FStop", f);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger CameraSetFocalDistance(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETFLOAT(f)
|
||||
__SQ_GETEND
|
||||
c->registry.CreateKey("PostProcess:Dof:FDist", f);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger CameraGetVisibleItems(HSQUIRRELVM vm) {
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETSAFEPTR(scene, Scene, typetag_Scene3d)
|
||||
__SQ_GETEND
|
||||
|
||||
sq_newarray(vm, 0);
|
||||
Vector4 cameraPos = c->GetMatrix().GetRow(3);
|
||||
Vector4 cameraForward = c->GetMatrix().GetRow(2); // Camera's forward vector
|
||||
|
||||
ListForeachPtr(MItem *, item, scene->GetItemList()) {
|
||||
if (item->GetItemType() == Type_Object) {
|
||||
if (MObject *o = (MObject *)item) {
|
||||
if (o->render_data.IsValid() && o->render_data->geometry.IsValid()) {
|
||||
Vector4 objectPos = o->GetMatrix().GetRow(3);
|
||||
Vector4 toObject = objectPos - cameraPos;
|
||||
|
||||
// Skip this object if it's too far
|
||||
float distance = toObject.Len();
|
||||
if (distance > 500) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if object is in front of the camera
|
||||
float dot = toObject.x * cameraForward.x + toObject.y * cameraForward.y + toObject.z * cameraForward.z;
|
||||
if (dot > 0) {
|
||||
// Perform frustum culling
|
||||
Frustum::Visibility vis = c->frustum.ClassifyMinMax(o->render_data->geometry->minmax, &o->GetMatrix());
|
||||
if (vis != Frustum::Outside) {
|
||||
CObject::Push(vm, (void *)item, typetag_Item);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
SQInteger CameraComputeProjectionMatrix(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETFRECT(viewport)
|
||||
__SQ_GETEND
|
||||
Matrix4 projection_matrix;
|
||||
c->ComputeProjectionMatrix(viewport, projection_matrix);
|
||||
__SQ_RETURNMATRIX4(projection_matrix)
|
||||
}
|
||||
*/
|
||||
SQInteger CameraSetAspectRatio(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETFLOAT(v)
|
||||
__SQ_GETEND
|
||||
c->aspect_ratio = v;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger CameraGetAspectRatio(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types))
|
||||
__SQ_RETURNFLOAT(c->aspect_ratio)
|
||||
}
|
||||
SQInteger CameraSetAspectRatioRefAxis(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETBOOL(v)
|
||||
__SQ_GETEND
|
||||
c->aspect_ratio_ref_yaxis = asbool(v);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger CameraSetClipping(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETFLOAT(n)
|
||||
__SQ_GETFLOAT(f)
|
||||
__SQ_GETEND
|
||||
c->z_near = n;
|
||||
c->z_far = f;
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger CameraGetZNear(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNFLOAT(c->z_near)
|
||||
}
|
||||
|
||||
SQInteger CameraGetZFar(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNFLOAT(c->z_far)
|
||||
}
|
||||
|
||||
|
||||
SQInteger CameraCullObject(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETCOBJECTBASE(o, MObject, object_derived_types)
|
||||
__SQ_GETEND
|
||||
|
||||
Frustum::Visibility vis = Frustum::Outside;
|
||||
if (o->render_data.IsValid() && o->render_data->geometry.IsValid())
|
||||
vis = c->frustum.ClassifyMinMax(o->render_data->geometry->minmax, &o->GetMatrix());
|
||||
|
||||
__SQ_RETURNINT(int(vis))
|
||||
}
|
||||
SQInteger CameraCullPosition(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETVECTOR(p)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNINT(int(c->frustum.ClassifySet(1, &p)))
|
||||
}
|
||||
|
||||
SQInteger CameraGetFrustumVertices(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETEND
|
||||
|
||||
const Vector4* vtx = c->frustum.GetVertices();
|
||||
|
||||
sq_newarray(vm, 0);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
PushVector(vm, vtx[i], false);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger CameraWorldToScreen(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETSAFEPTR(renderer, Renderer, typetag_Renderer)
|
||||
__SQ_GETVECTOR(world)
|
||||
__SQ_GETEND
|
||||
Vector4 screen;
|
||||
if (!c->WorldToScreen(renderer->GetViewport(), world, screen))
|
||||
screen.Set(-1, -1, -1, -1);
|
||||
__SQ_RETURNVECTOR(screen)
|
||||
}
|
||||
SQInteger CameraScreenToWorld(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETSAFEPTR(renderer, Renderer, typetag_Renderer)
|
||||
__SQ_GETFLOAT(x)
|
||||
__SQ_GETFLOAT(y)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNVECTOR(c->ScreenToWorld(renderer->GetViewport(), x, y))
|
||||
}
|
||||
SQInteger CameraScreenToWorldPlane(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(5)
|
||||
__SQ_GETCOBJECTBASE(c, MCamera, camera_derived_types)
|
||||
__SQ_GETSAFEPTR(renderer, Renderer, typetag_Renderer)
|
||||
__SQ_GETFLOAT(x)
|
||||
__SQ_GETFLOAT(y)
|
||||
__SQ_GETFLOAT(z)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNVECTOR(c->ScreenToWorld(renderer->GetViewport(), x, y, z))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------
|
||||
void RegisterCameraBinding(HSQUIRRELVM vm)
|
||||
//-------------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Camera
|
||||
Type: Camera
|
||||
Related: Item
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: CameraGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
/*#
|
||||
Func: CameraGetItem
|
||||
Proto: Item:Camera
|
||||
Example: local camera_item = CameraGetItem(camera)
|
||||
Desc: Return camera item.
|
||||
#*/
|
||||
sq_register(vm, CameraGetItem, "CameraGetItem", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: CameraAR
|
||||
Desc: Aspect ratio functions.
|
||||
#*/
|
||||
/*#
|
||||
Func: CameraSetAspectRatio
|
||||
Proto: void:Camera,float aspect_ratio
|
||||
Desc: Set camera aspect ratio.
|
||||
#*/
|
||||
sq_register(vm, CameraSetAspectRatio, "CameraSetAspectRatio", _SC(".xn"));
|
||||
/*#
|
||||
Func: CameraGetAspectRatio
|
||||
Proto: float:Camera
|
||||
Desc: Get camera aspect ratio.
|
||||
#*/
|
||||
sq_register(vm, CameraGetAspectRatio, "CameraGetAspectRatio", _SC(".x"));
|
||||
/*#
|
||||
Func: CameraSetAspectRatioRefAxis
|
||||
Proto: void:Camera,bool use_Y_axis
|
||||
Desc: Set camera aspect ratio correction to be done on the vertical screen axis (Y) instead of the horizontal axis (X).
|
||||
#*/
|
||||
sq_register(vm, CameraSetAspectRatioRefAxis, "CameraSetAspectRatioRefAxis", _SC(".xb"));
|
||||
|
||||
/*#
|
||||
Section: CameraViewport
|
||||
Desc: Viewport functions
|
||||
#*/
|
||||
/*#
|
||||
Func: CameraCullObject
|
||||
Proto: VisibilityFlags:Camera camera_to_cull_against,Object object_to_cull
|
||||
Desc: Cull an object against the camera frustum. Returns a visibility flag mask.
|
||||
#*/
|
||||
sq_register(vm, CameraCullObject, "CameraCullObject", _SC(".xx"));
|
||||
/*#
|
||||
Func: CameraCullPosition
|
||||
Proto: VisibilityFlags:Camera camera_to_cull_against,Vector world_position
|
||||
Desc: Cull a position in world space against the camera frustum. Returns a visibility flag mask.
|
||||
#*/
|
||||
sq_register(vm, CameraCullPosition, "CameraCullPosition", _SC(".xx"));
|
||||
|
||||
sq_register(vm, CameraGetFrustumVertices, "CameraGetFrustumVertices", _SC(".x"));
|
||||
sq_register(vm, CameraGetZNear, "CameraGetZNear", _SC(".x"));
|
||||
sq_register(vm, CameraGetZFar, "CameraGetZFar", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: CameraGetFov
|
||||
Proto: float:Camera
|
||||
Desc: Get camera fov in radian.
|
||||
#*/
|
||||
sq_register(vm, CameraGetFov, "CameraGetFov", _SC(".x"));
|
||||
/*#
|
||||
Func: CameraSetFov
|
||||
Proto: void:Camera,float fov_in_radian
|
||||
Example: CameraSetFov(camera, Deg(60))
|
||||
Desc: Get camera fov in radian.
|
||||
#*/
|
||||
sq_register(vm, CameraSetFov, "CameraSetFov", _SC(".xn"));
|
||||
|
||||
/*#
|
||||
Func: CameraGetZoomFactor
|
||||
Proto: float:Camera
|
||||
Desc: Get camera zoom.
|
||||
#*/
|
||||
sq_register(vm, CameraGetZoomFactor, "CameraGetZoomFactor", _SC(".x"));
|
||||
/*#
|
||||
Func: CameraSetZoomFactor
|
||||
Proto: void:Camera,float zoom_factor
|
||||
Example: CameraSetZoomFactor(camera, 3.2)
|
||||
Desc: Set camera zoom.
|
||||
#*/
|
||||
sq_register(vm, CameraSetZoomFactor, "CameraSetZoomFactor", _SC(".xn"));
|
||||
|
||||
|
||||
/*#
|
||||
Func: CameraSetFocalDistance
|
||||
Proto: void:Camera,float distance_in_meters
|
||||
Example:
|
||||
// Set focus 10 meters from camera. Objects closer or father than 10 meters will appear out of focus.
|
||||
CameraSetFocalDistance(camera, Mtr(10))
|
||||
Desc: Set camera focal distance, set to 0 or less to disable depth of field on the camera.
|
||||
#*/
|
||||
sq_register(vm, CameraSetFocalDistance, "CameraSetFocalDistance", _SC(".xn"));
|
||||
/*#
|
||||
Func: CameraSetFStop
|
||||
Proto: void:Camera,float fstop_in_meters
|
||||
Example: CameraSetFStop(camera, Mtr(4))
|
||||
Desc: Set camera f-stop, set to 0 or less to disable depth of field on the camera.
|
||||
#*/
|
||||
sq_register(vm, CameraSetFStop, "CameraSetFStop", _SC(".xn"));
|
||||
/*#
|
||||
Func: CameraSetClipping
|
||||
Proto: void:camera,float near, float far
|
||||
Example: CameraSetClipping(camera, Cm(1), Mtr(100))
|
||||
Desc: Set camera near and far clipping planes.
|
||||
#*/
|
||||
sq_register(vm, CameraSetClipping, "CameraSetClipping", _SC(".xnn"));
|
||||
/*#
|
||||
Func: CameraWorldToScreen
|
||||
Proto: vector:Camera,Renderer,Vector world_position
|
||||
Example:
|
||||
// Project world position {10,5,1} on the screen.
|
||||
local p2d = CameraWorldToScreen(camera, g_render, Vector(10, 5, 1))
|
||||
Desc: Transform a world space position to a normalized screen space position, in the range { [0;1], [0;1] }.
|
||||
#*/
|
||||
sq_register(vm, CameraWorldToScreen, "CameraWorldToScreen", _SC(".xxx"));
|
||||
/*#
|
||||
Func: CameraScreenToWorld
|
||||
Proto: vector:Camera,Renderer,float x,float y
|
||||
Example:
|
||||
// Transform the middle of the screen to a 3d world position 1 meter away from the camera.
|
||||
local wp = CameraScreenToWorld(camera, g_render, 0.5, 0.5)
|
||||
Desc: Transform a normalized screen space position to a world space position.<br>
|
||||
The screen space position is the result of a projection on the Z=1 imaginary plane, situated 1 meter in front of the camera.
|
||||
See: CameraScreenToWorldPlane
|
||||
#*/
|
||||
sq_register(vm, CameraScreenToWorld, "CameraScreenToWorld", _SC(".xxnn"));
|
||||
/*#
|
||||
Func: CameraScreenToWorldPlane
|
||||
Proto: vector:Camera,Renderer,float x,float y,float plane_distance_in_meters
|
||||
Desc: Transform a normalized screen space position to a world space position.<br>
|
||||
The screen space position is the result of a projection on an imaginary plane situated in front of the camera.
|
||||
#*/
|
||||
sq_register(vm, CameraScreenToWorldPlane, "CameraScreenToWorldPlane", _SC(".xxnnn"));
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: VisibilityFlags
|
||||
Desc: Reported by the visibility functions, visibility can be total, partial or null.
|
||||
Values: VisibilityOutside,VisibilityClipped,VisibilityInside
|
||||
#*/
|
||||
sq_pushstring(vm, "VisibilityOutside", -1); sq_pushinteger(vm, Frustum::Outside); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "VisibilityClipped", -1); sq_pushinteger(vm, Frustum::Clipped); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "VisibilityInside", -1); sq_pushinteger(vm, Frustum::Inside); sq_newslot(vm, -3, true);
|
||||
/*#
|
||||
Func: CameraGetVisibleItems
|
||||
Proto: array:Camera,Scene3d
|
||||
Desc: Get all visible items in the camera frustum.
|
||||
#*/
|
||||
sq_register(vm, CameraGetVisibleItems, "CameraGetVisibleItems", _SC(".xx"));
|
||||
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
73
include/modules/script_squirrel/legacy/clock_binding.cpp
Normal file
73
include/modules/script_squirrel/legacy/clock_binding.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "core/clock.h"
|
||||
#include <windows.h>
|
||||
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ClockReset(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(clock, GS::Core::Clock, typetag_Clock)
|
||||
clock->Reset();
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ClockGetCounter(HSQUIRRELVM vm)
|
||||
{
|
||||
// Get frequency
|
||||
LARGE_INTEGER frequency;
|
||||
QueryPerformanceFrequency(&frequency);
|
||||
LARGE_INTEGER counter;
|
||||
QueryPerformanceCounter(&counter);
|
||||
__SQ_RETURNINT(counter.QuadPart)
|
||||
}
|
||||
SQInteger ClockGetFrequency(HSQUIRRELVM vm)
|
||||
{
|
||||
// Get frequency
|
||||
LARGE_INTEGER frequency;
|
||||
QueryPerformanceFrequency(&frequency);
|
||||
__SQ_RETURNINT(frequency.QuadPart)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterClockBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Clock
|
||||
Type: Clock
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: ClockGeneral
|
||||
Desc: General functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ClockReset
|
||||
Proto: void:Clock
|
||||
Desc: Reset a clock object.
|
||||
#*/
|
||||
sq_register(vm, ClockReset, "ClockReset", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: ClockGetCounter
|
||||
Proto: int:Clock
|
||||
Desc: Get the counter of a clock object.
|
||||
#*/
|
||||
sq_register(vm, ClockGetCounter, "ClockGetCounter", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: ClockGetFrequency
|
||||
Proto: int:Clock
|
||||
Desc: Get the frequency of a clock object.
|
||||
#*/
|
||||
sq_register(vm, ClockGetFrequency, "ClockGetFrequency", _SC(".x"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
541
include/modules/script_squirrel/legacy/collision_binding.cpp
Normal file
541
include/modules/script_squirrel/legacy/collision_binding.cpp
Normal file
@ -0,0 +1,541 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "scene3d/mitem.h"
|
||||
#include "binding_helpers.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define __SQ_TEST_ITEM_PHYSIC if (!item->physic_item) return sq_throwerror(vm, "No physic interface.");
|
||||
|
||||
SQInteger ItemSetSelfMask(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETINT(mask)
|
||||
__SQ_GETEND
|
||||
__SQ_TEST_ITEM_PHYSIC
|
||||
item->physic_item->SetSelfMask(mask);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ItemCollisionActivate(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETBOOL(active)
|
||||
__SQ_GETEND
|
||||
__SQ_TEST_ITEM_PHYSIC
|
||||
item->physic_item->SetActive(asbool(active));
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ItemSetCollisionMask(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETINT(mask)
|
||||
__SQ_GETEND
|
||||
__SQ_TEST_ITEM_PHYSIC
|
||||
item->physic_item->SetCollisionMask(mask);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ItemGetShapeFromIndex(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETINT(idx)
|
||||
__SQ_GETEND
|
||||
__SQ_TEST_ITEM_PHYSIC
|
||||
if (idx < (SQInteger)item->physic_item_desc.shape_list.GetCount())
|
||||
__SQ_RETURNSAFEPTR(item->physic_item_desc.shape_list[idx], typetag_ColShape)
|
||||
__SQ_RETURNNULL
|
||||
}
|
||||
SQInteger ItemAddCollisionShape(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_TEST_ITEM_PHYSIC
|
||||
PhysicShape *shape = new PhysicShape;
|
||||
if (!shape)
|
||||
return sq_throwerror(vm, "Failed to allocate collision shape.");
|
||||
item->physic_item_desc.shape_list.Add(shape);
|
||||
__SQ_RETURNSAFEPTR(shape, typetag_ColShape)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ShapeSetMesh(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETSTRING(path)
|
||||
bool r = path ? shape->Set(PhysicShape::TypeMesh, path) : false;
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger ShapeSetConvex(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETSTRING(path)
|
||||
bool r = path ? shape->Set(PhysicShape::TypeConvex, path) : false;
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger ShapeSetSphere(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETFLOAT(radius)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(shape->Set(PhysicShape::TypeSphere, Vector4(radius, 0, 0)))
|
||||
}
|
||||
SQInteger ShapeSetBox(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETVECTOR(scale)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(shape->Set(PhysicShape::TypeBox, scale))
|
||||
}
|
||||
SQInteger ShapeSetCapsule(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETFLOAT(radius)
|
||||
__SQ_GETFLOAT(length)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(shape->Set(PhysicShape::TypeCapsule, Vector4(radius, length, 0.0)))
|
||||
}
|
||||
SQInteger ShapeSetCylinder(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETFLOAT(radius)
|
||||
__SQ_GETFLOAT(length)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(shape->Set(PhysicShape::TypeCylinder, Vector4(radius, length, 0.0)))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ShapeGetItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_RETURNSAFEPTR(NULL, typetag_Item);
|
||||
}
|
||||
SQInteger ShapeGetPosition(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_RETURNVECTOR(shape->position)
|
||||
}
|
||||
SQInteger ShapeSetPosition(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETVECTOR(p)
|
||||
__SQ_GETEND
|
||||
shape->position = p;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ShapeGetRotation(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_RETURNVECTOR(shape->rotation)
|
||||
}
|
||||
SQInteger ShapeSetRotation(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETVECTOR(e)
|
||||
__SQ_GETEND
|
||||
shape->rotation = e;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ShapeSetRestitution(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETFLOAT(r)
|
||||
__SQ_GETEND
|
||||
shape->restitution = r;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ShapeSetFriction(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETFLOAT(df)
|
||||
__SQ_GETFLOAT(sf)
|
||||
__SQ_GETEND
|
||||
shape->dynamic_friction = df;
|
||||
shape->static_friction = sf;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ShapeGetMass(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_RETURNFLOAT(shape->mass)
|
||||
}
|
||||
SQInteger ShapeSetMass(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(shape, PhysicShape, typetag_ColShape)
|
||||
__SQ_GETFLOAT(mass)
|
||||
__SQ_GETEND
|
||||
shape->mass = mass;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// //poly poly intersection
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Gather up one-dimensional extents of the projection of the polygon
|
||||
// onto this axis.
|
||||
void gatherPolygonProjectionExtents(GS::Array<GS::Vector4> poly, GS::Vector4 v, float &outMin, float &outMax)
|
||||
{
|
||||
// Initialize extents to a single point, the first vertex
|
||||
outMin = outMax = v.Dot(poly[0]);
|
||||
|
||||
// Now scan all the rest, growing extents to include them
|
||||
for (uint i = 1; i < poly.GetCount(); ++i) {
|
||||
float d = v.Dot(poly[i]);
|
||||
if (d < outMin)
|
||||
outMin = d;
|
||||
else if (d > outMax)
|
||||
outMax = d;
|
||||
}
|
||||
}
|
||||
// Helper routine: test if two convex polygons overlap, using only the edges of
|
||||
// the first polygon (polygon "a") to build the list of candidate separating axes.
|
||||
bool findSeparatingAxis(GS::Array<Vector4> poly_a, GS::Array<Vector4> poly_b)
|
||||
{
|
||||
// Iterate over all the edges
|
||||
uint prev = poly_a.GetCount() - 1;
|
||||
for (uint cur = 0; cur < poly_a.GetCount(); ++cur)
|
||||
{
|
||||
// Get edge vector. (Assume operator- is overloaded)
|
||||
GS::Vector4 edge = poly_a[cur] - poly_a[prev];
|
||||
edge.y = 0;
|
||||
edge.Normalize();
|
||||
|
||||
// Rotate vector 90 degrees (doesn't matter which way) to get
|
||||
// candidate separating axis.
|
||||
GS::Vector4 v(edge.z, 0, -edge.x);
|
||||
|
||||
// Gather extents of both polygons projected onto this axis
|
||||
float result_poly_a_min, result_poly_a_max;
|
||||
gatherPolygonProjectionExtents(poly_a, v, result_poly_a_min, result_poly_a_max);
|
||||
float result_poly_b_min, result_poly_b_max;
|
||||
gatherPolygonProjectionExtents(poly_b, v, result_poly_b_min, result_poly_b_max);
|
||||
|
||||
// Is this a separating axis?
|
||||
if (result_poly_a_max < result_poly_b_min) return true;
|
||||
if (result_poly_b_max < result_poly_a_min) return true;
|
||||
|
||||
// Next edge, please
|
||||
prev = cur;
|
||||
}
|
||||
|
||||
// Failed to find a separating axis
|
||||
return false;
|
||||
}
|
||||
|
||||
// Here is our high level entry point. It tests whether two polygons intersect. The
|
||||
// polygons must be convex, and they must not be degenerate.
|
||||
bool convexPolygonOverlap(GS::Array<GS::Vector4> poly_a, GS::Array<Vector4> poly_b) //poly[a, b, c, d]
|
||||
{
|
||||
// First, use all of A's edges to get candidate separating axes
|
||||
if (findSeparatingAxis(poly_a, poly_b))
|
||||
return false;
|
||||
|
||||
// Now swap roles, and use B's edges
|
||||
if (findSeparatingAxis(poly_b, poly_a))
|
||||
return false;
|
||||
|
||||
// No separating axis found. They must overlap
|
||||
return true;
|
||||
}
|
||||
|
||||
SQInteger convexPolygonOverlapBind(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
|
||||
GS::Array<GS::Vector4> poly_a(4);
|
||||
sq_pushnull(vm);//null iterator
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
sq_next(vm, __SQ_STACKPOS - 1);
|
||||
GetVector(vm, -1, poly_a[i]);
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
sq_pop(vm, 1); //pops the null iterator
|
||||
|
||||
__SQ_GETUPDATESTACK
|
||||
GS::Array<GS::Vector4> poly_b(4);
|
||||
sq_pushnull(vm);//null iterator
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
sq_next(vm, __SQ_STACKPOS - 1);
|
||||
GetVector(vm, -1, poly_b[i]);
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
sq_pop(vm, 1); //pops the null iterator
|
||||
|
||||
__SQ_GETEND
|
||||
|
||||
__SQ_RETURNBOOL(convexPolygonOverlap(poly_a, poly_b));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
bool PointInPoly2D(GS::Vector4 point, GS::Array<GS::Vector4> poly) // poly = [Vector(), Vector(), Vector(), Vector()]
|
||||
//------------------------------------------------------------
|
||||
{
|
||||
bool oddNodes = false;
|
||||
float x2 = poly[3].x;
|
||||
float z2 = poly[3].z;
|
||||
float x1, z1;
|
||||
|
||||
// vertex a
|
||||
x1 = poly[0].x;
|
||||
z1 = poly[0].z;
|
||||
if (((z1 < point.z) && (z2 >= point.z)) || (z1 >= point.z) && (z2 < point.z)) {
|
||||
if ((point.z - z1) / (z2 - z1) * (x2 - x1) < (point.x - x1))
|
||||
oddNodes = !oddNodes;
|
||||
}
|
||||
|
||||
x2 = x1;
|
||||
z2 = z1;
|
||||
|
||||
// vertex b
|
||||
x1 = poly[1].x;
|
||||
z1 = poly[1].z;
|
||||
if (((z1 < point.z) && (z2 >= point.z)) || (z1 >= point.z) && (z2 < point.z)) {
|
||||
if ((point.z - z1) / (z2 - z1) * (x2 - x1) < (point.x - x1))
|
||||
oddNodes = !oddNodes;
|
||||
}
|
||||
|
||||
x2 = x1;
|
||||
z2 = z1;
|
||||
|
||||
// vertex c
|
||||
x1 = poly[2].x;
|
||||
z1 = poly[2].z;
|
||||
if (((z1 < point.z) && (z2 >= point.z)) || (z1 >= point.z) && (z2 < point.z)) {
|
||||
if ((point.z - z1) / (z2 - z1) * (x2 - x1) < (point.x - x1))
|
||||
oddNodes = !oddNodes;
|
||||
}
|
||||
|
||||
x2 = x1;
|
||||
z2 = z1;
|
||||
|
||||
// vertex d
|
||||
x1 = poly[3].x;
|
||||
z1 = poly[3].z;
|
||||
if (((z1 < point.z) && (z2 >= point.z)) || (z1 >= point.z) && (z2 < point.z)) {
|
||||
if ((point.z - z1) / (z2 - z1) * (x2 - x1) < (point.x - x1))
|
||||
oddNodes = !oddNodes;
|
||||
}
|
||||
|
||||
return oddNodes;
|
||||
}
|
||||
|
||||
SQInteger PointInPoly2DBind(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
|
||||
__SQ_GETVECTOR(p);
|
||||
|
||||
GS::Array<GS::Vector4> poly_a(4);
|
||||
sq_pushnull(vm);//null iterator
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
sq_next(vm, __SQ_STACKPOS - 1);
|
||||
GetVector(vm, -1, poly_a[i]);
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
sq_pop(vm, 1); //pops the null iterator
|
||||
|
||||
__SQ_GETUPDATESTACK
|
||||
__SQ_GETEND
|
||||
|
||||
__SQ_RETURNBOOL(PointInPoly2D(p, poly_a));
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------
|
||||
void RegisterCollisionBinding(HSQUIRRELVM vm)
|
||||
//----------------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Func: convexPolygonOverlapBind
|
||||
Proto: void:array polyA, array polyB
|
||||
Desc: return if the 2 poly overlap
|
||||
#*/
|
||||
sq_register(vm, convexPolygonOverlapBind, "convexPolygonOverlapBind", _SC(".aa"));
|
||||
/*#
|
||||
Func: convexPolygonOverlapBind
|
||||
Proto: void:Vector p, array polyA
|
||||
Desc: return if the 2 poly overlap
|
||||
#*/
|
||||
sq_register(vm, PointInPoly2DBind, "PointInPoly2DBind", _SC(".xa"));
|
||||
/*#
|
||||
Topic: Collision
|
||||
Type: ColShape
|
||||
#*/
|
||||
/*#
|
||||
Section: CollisionShapeType
|
||||
Desc: Collision Shape Type functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ShapeSetMesh
|
||||
Proto: bool:ColShape shape,string path
|
||||
Desc: Set the shape as a collision mesh.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetMesh, "ShapeSetMesh", _SC(".xs"));
|
||||
/*#
|
||||
Func: ShapeSetConvex
|
||||
Proto: bool:ColShape shape,string path
|
||||
Desc: Set the shape as a convex collision.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetConvex, "ShapeSetConvex", _SC(".xs"));
|
||||
/*#
|
||||
Func: ShapeSetSphere
|
||||
Proto: bool:ColShape shape,float radius
|
||||
Desc: Set the shape as a sphere.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetSphere, "ShapeSetSphere", _SC(".xn"));
|
||||
/*#
|
||||
Func: ShapeSetBox
|
||||
Proto: bool:ColShape shape,Vector dimensions
|
||||
Desc: Set the shape as a box collision shape.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetBox, "ShapeSetBox", _SC(".xx"));
|
||||
/*#
|
||||
Func: ShapeSetCapsule
|
||||
Proto: bool:ColShape shape,float radius,float length
|
||||
Desc: Set the shape as a Z-oriented capsule collision shape.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetCapsule, "ShapeSetCapsule", _SC(".xnn"));
|
||||
/*#
|
||||
Func: ShapeSetCylinder
|
||||
Proto: bool:ColShape shape,float radius,float length
|
||||
Desc: Set the shape as a Z-oriented cylinder collision shape.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetCylinder, "ShapeSetCylinder", _SC(".xnn"));
|
||||
|
||||
/*#
|
||||
Section: CollisionShape
|
||||
Desc: Collision Shape functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ShapeSetPosition
|
||||
Proto: void:ColShape shape,Vector position
|
||||
Desc: Set the collision shape position in item space.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetPosition, "ShapeSetPosition", _SC(".xx"));
|
||||
/*#
|
||||
Func: ShapeGetPosition
|
||||
Proto: Vector:ColShape shape
|
||||
Desc: Get the collision shape position in item space.
|
||||
#*/
|
||||
sq_register(vm, ShapeGetPosition, "ShapeGetPosition", _SC(".x"));
|
||||
/*#
|
||||
Func: ShapeSetRotation
|
||||
Proto: void:ColShape shape,Vector position
|
||||
Desc: Set the collision shape position from a Euler triplet in item space.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetRotation, "ShapeSetRotation", _SC(".xx"));
|
||||
/*#
|
||||
Func: ShapeGetRotation
|
||||
Proto: Vector:ColShape shape
|
||||
Desc: Get the collision shape rotation as an Euler triplet in item space.
|
||||
#*/
|
||||
sq_register(vm, ShapeGetRotation, "ShapeGetRotation", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: ShapeSetMass
|
||||
Proto: void:ColShape shape,float mass
|
||||
Desc: Set the collision shape mass. Do not forget to update the item collision setup to update changes.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetMass, "ShapeSetMass", _SC(".xn"));
|
||||
/*#
|
||||
Func: ShapeGetMass
|
||||
Proto: float:ColShape shape
|
||||
Desc: Get the collision shape mass.
|
||||
#*/
|
||||
sq_register(vm, ShapeGetMass, "ShapeGetMass", _SC(".x"));
|
||||
/*#
|
||||
Func: ShapeSetFriction
|
||||
Proto: void:ColShape shape,float dynamic_friction,float static_friction
|
||||
Desc: Set collision shape dynamic and static friction.
|
||||
#*/
|
||||
sq_register(vm, ShapeSetFriction, "ShapeSetFriction", _SC(".xnn"));
|
||||
/*#
|
||||
Func: ShapeSetRestitution
|
||||
Proto: void:ColShape shape,float restitution
|
||||
Desc: Set collision shape restitution (1 for a perfect elastic collision).
|
||||
#*/
|
||||
sq_register(vm, ShapeSetRestitution, "ShapeSetRestitution", _SC(".xn"));
|
||||
/*#
|
||||
Func: ShapeGetItem
|
||||
Proto: Item:ColShape shape
|
||||
Desc: Get the item this collision shape belongs to.
|
||||
#*/
|
||||
sq_register(vm, ShapeGetItem, "ShapeGetItem", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: CollisionItem
|
||||
Desc: Item functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ItemAddCollisionShape
|
||||
Proto: ColShape:Item
|
||||
Desc: Add a new collision shape to item.
|
||||
#*/
|
||||
sq_register(vm, ItemAddCollisionShape, "ItemAddCollisionShape", _SC(".x"));
|
||||
/*#
|
||||
Func: ItemCollisionActivate
|
||||
Proto: void:Item,bool active
|
||||
Desc: Activate or deactivate item collision.
|
||||
#*/
|
||||
sq_register(vm, ItemCollisionActivate, "ItemCollisionActivate", _SC(".xb"));
|
||||
/*#
|
||||
Func: ItemSetSelfMask
|
||||
Proto: void:Item,int self_mask
|
||||
Desc: Set item self mask, this mask is a bit field.
|
||||
#*/
|
||||
sq_register(vm, ItemSetSelfMask, "ItemSetSelfMask", _SC(".xi"));
|
||||
/*#
|
||||
Func: ItemSetCollisionMask
|
||||
Proto: void:Item,int collision_mask
|
||||
Desc: Set item collision mask, this mask is a bit field.
|
||||
#*/
|
||||
sq_register(vm, ItemSetCollisionMask, "ItemSetCollisionMask", _SC(".xi"));
|
||||
/*#
|
||||
Func: ItemGetShapeFromIndex
|
||||
Proto: ColShape:item,int index
|
||||
Desc: Get item collision shape from index.
|
||||
#*/
|
||||
sq_register(vm, ItemGetShapeFromIndex, "ItemGetShapeFromIndex", _SC(".xi"));
|
||||
|
||||
// Push defines.
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: ShapeMask
|
||||
Desc: Shape mask to filter out certain type of shape from intersection tests.
|
||||
Values: CollisionTraceMesh,CollisionTraceSphere,CollisionTraceCuboid,CollisionTraceAll
|
||||
#*/
|
||||
sq_pushstring(vm, "CollisionTraceMesh", -1); sq_pushinteger(vm, -1); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "CollisionTraceSphere", -1); sq_pushinteger(vm, -1); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "CollisionTraceCuboid", -1); sq_pushinteger(vm, -1); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "CollisionTraceAll", -1); sq_pushinteger(vm, ~0); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
112
include/modules/script_squirrel/legacy/emitter_binding.cpp
Normal file
112
include/modules/script_squirrel/legacy/emitter_binding.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "scene3d/scene.h"
|
||||
#include "scene3d/memitter.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/graphic_resource_factory.h"
|
||||
|
||||
using namespace GS::Core;
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
SQInteger EmitterSetParticleModel(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(e, MEmitter, typetag_Emitter)
|
||||
__SQ_GETSAFEPTR(model, ParticleModel, typetag_ParticleModel)
|
||||
__SQ_GETEND
|
||||
if (e->render_data.IsNull())
|
||||
return sq_throwerror(vm, "Emitter has no render data, you need to call ItemRenderSetup() first.");
|
||||
e->render_data->particle_model = model;
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger EmitterSetBirthRateScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(e, MEmitter, typetag_Emitter)
|
||||
__SQ_GETFLOAT(scale)
|
||||
__SQ_GETEND
|
||||
e->birth_rate_scale = scale;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger EmitterSetBirthSizeScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(e, MEmitter, typetag_Emitter)
|
||||
__SQ_GETFLOAT(scale)
|
||||
__SQ_GETEND
|
||||
e->birth_size_scale = scale;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger EmitterSetBirthSpeedScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(e, MEmitter, typetag_Emitter)
|
||||
__SQ_GETFLOAT(scale)
|
||||
__SQ_GETEND
|
||||
e->birth_speed_scale = scale;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger EmitterSetBirthOpacityScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(e, MEmitter, typetag_Emitter)
|
||||
__SQ_GETFLOAT(scale)
|
||||
__SQ_GETEND
|
||||
e->birth_opacity_scale = scale;
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
void RegisterEmitterBinding(HSQUIRRELVM vm)
|
||||
//--------------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Emitter
|
||||
Type: Emitter
|
||||
Type: ParticleModel
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: EmitterSettings
|
||||
Desc: Emitter functions
|
||||
#*/
|
||||
/*#
|
||||
Func: EmitterSetParticleModel
|
||||
Proto: void:Emitter,ParticleModel
|
||||
Desc: Set the emitter particle model.
|
||||
#*/
|
||||
sq_register(vm, EmitterSetParticleModel, "EmitterSetParticleModel", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Func: EmitterSetBirthRateScale
|
||||
Proto: void:Emitter,float scale
|
||||
Desc: Set the emitter birth rate scale.
|
||||
#*/
|
||||
sq_register(vm, EmitterSetBirthRateScale, "EmitterSetBirthRateScale", _SC(".xn"));
|
||||
/*#
|
||||
Func: EmitterSetBirthSizeScale
|
||||
Proto: void:Emitter,float scale
|
||||
Desc: Set the emitter birth size scale.
|
||||
#*/
|
||||
sq_register(vm, EmitterSetBirthSizeScale, "EmitterSetBirthSizeScale", _SC(".xn"));
|
||||
/*#
|
||||
Func: EmitterSetBirthSpeedScale
|
||||
Proto: void:Emitter,float scale
|
||||
Desc: Set the emitter birth speed scale.
|
||||
#*/
|
||||
sq_register(vm, EmitterSetBirthSpeedScale, "EmitterSetBirthSpeedScale", _SC(".xn"));
|
||||
/*#
|
||||
Func: EmitterSetBirthOpacityScale
|
||||
Proto: void:Emitter,float scale
|
||||
Desc: Set the emitter birth opacity scale.
|
||||
#*/
|
||||
sq_register(vm, EmitterSetBirthOpacityScale, "EmitterSetBirthOpacityScale", _SC(".xn"));
|
||||
}
|
||||
103
include/modules/script_squirrel/legacy/font_binding.cpp
Normal file
103
include/modules/script_squirrel/legacy/font_binding.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "squirrel_binding.h"
|
||||
#include "binding_helpers.h"
|
||||
#include "font/font_renderer.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
void IterateTextParameters(HSQUIRRELVM vm, int idx, TextState &state);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger FontSetFallback(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(font, FontEx, typetag_Font)
|
||||
__SQ_GETSAFEPTR(fbck, FontEx, typetag_Font)
|
||||
__SQ_GETEND
|
||||
font->fallback = fbck;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger FontSetParametersOffset(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETSAFEPTR(font, FontEx, typetag_Font)
|
||||
__SQ_GETFLOAT(size)
|
||||
__SQ_GETFLOAT(tracking)
|
||||
__SQ_GETFLOAT(leading)
|
||||
__SQ_GETEND
|
||||
font->size_multiplier = size;
|
||||
font->tracking_offset = tracking;
|
||||
font->leading_offset = leading;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger FontComputeRect(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETRECT(clip_rect)
|
||||
__SQ_GETSTRING(text)
|
||||
__SQ_GETSAFEPTR(font, FontEx, typetag_Font)
|
||||
|
||||
TextState state;
|
||||
IterateTextParameters(vm, __sq_stackpos, state);
|
||||
__SQ_GETUPDATESTACK
|
||||
|
||||
state.font = font;
|
||||
iRect out_rect = FontRenderer::Format(text, state, clip_rect);
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNRECT(out_rect)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterFontBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Font
|
||||
Type: Font
|
||||
Desc: A truetype font that can be used to render to a picture object.
|
||||
Related: Picture,Project
|
||||
#*/
|
||||
/*#
|
||||
Section: FontGeneral
|
||||
Desc: Font Settings
|
||||
#*/
|
||||
/*#
|
||||
Func: FontSetParametersOffset
|
||||
Proto: void:Font,float size_multiplier,float tracking_offset,float leading_offset
|
||||
Desc: Set font-specific properties offset. This function is usually used to normalize font characteristics when porting an application to a different locale.
|
||||
#*/
|
||||
sq_register(vm, FontSetParametersOffset, "FontSetParametersOffset", _SC(".xnnn"));
|
||||
sq_register(vm, FontSetParametersOffset, "UIFontSetParametersOffset", _SC(".xnnn"));
|
||||
/*#
|
||||
Func: FontSetFallback
|
||||
Proto: void:Font font,Font fallback
|
||||
Desc: Set a font to query when a glyph is missing from this font.
|
||||
#*/
|
||||
sq_register(vm, FontSetFallback, "FontSetFallback", _SC(".xx"));
|
||||
sq_register(vm, FontSetFallback, "UIFontSetFallback", _SC(".xx"));
|
||||
/*#
|
||||
Func: FontComputeRect
|
||||
Proto: rect:rect clip_rect,string text,Font font,table param
|
||||
Desc: Compute the bounding rect of a formatted text string, does not perform any graphic output.
|
||||
<br>
|
||||
The following table keys are available:<br>
|
||||
<ul>
|
||||
<li><b>'color'</b>: Hexadecimal RGBA (eg. Red: xff0000ff)
|
||||
<li><b>'align'</b>: TextAlign
|
||||
<li><b>'format'</b>: TextFormat
|
||||
<li><b>'tracking'</b>: Integer value specifying an extra space between glyphs.
|
||||
<li><b>'heading'</b>: Integer value specifying an extra space between lines.
|
||||
</ul>
|
||||
#*/
|
||||
sq_register(vm, FontComputeRect, "FontComputeRect", _SC(".xsxt"));
|
||||
sq_register(vm, FontComputeRect, "UIFontComputeRect", _SC(".xsxt"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
537
include/modules/script_squirrel/legacy/geometry_binding.cpp
Normal file
537
include/modules/script_squirrel/legacy/geometry_binding.cpp
Normal file
@ -0,0 +1,537 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "core/render_data.h"
|
||||
#include "core/geometry.h"
|
||||
#include "core/iso_surface.h"
|
||||
#include "core/resource_factories.h"
|
||||
#include "core/graphic_resource_factory.h"
|
||||
#include "metafile/nml_object.h"
|
||||
#include "gpu/gpu_material.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Render;
|
||||
using namespace GS::Script;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometrySaveOnItself(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETSAFEPTR(f, Core::ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETEND
|
||||
|
||||
// get the geo from core
|
||||
GS::Core::Geometry * core_geo = f->graphic->LoadGeometry(g->name);
|
||||
|
||||
core_geo->flag = g->flag;
|
||||
core_geo->lod_distance = g->lod_distance;
|
||||
|
||||
if(g->lod_proxy.IsValid())
|
||||
core_geo->lod_proxy = g->lod_proxy->name;
|
||||
else
|
||||
core_geo->lod_proxy = "";
|
||||
|
||||
if(g->shadow_proxy.IsValid())
|
||||
core_geo->shadow_proxy = g->shadow_proxy->name;
|
||||
else
|
||||
core_geo->shadow_proxy = "";
|
||||
|
||||
bool r = NML::SaveToFile(*core_geo, core_geo->name);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryGetShadowProxyNull(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNBOOL(g->flag.IsSet(Core::Geometry::FlagNullShadowProxy))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometrySetShadowProxyNull(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETBOOL(ShadowProxyNull)
|
||||
__SQ_GETEND
|
||||
g->flag.Raise(Core::Geometry::FlagNullShadowProxy, asbool(ShadowProxyNull));
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryGetLodNull(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNBOOL(g->flag.IsSet(Core::Geometry::FlagNullLodProxy))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometrySetLodNull(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETBOOL(LodNull)
|
||||
__SQ_GETEND
|
||||
g->flag.Raise(Core::Geometry::FlagNullLodProxy, asbool(LodNull));
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryGetLodDistance(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNFLOAT(g->lod_distance)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometrySetLodDistance(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETFLOAT(n)
|
||||
__SQ_GETEND
|
||||
g->lod_distance = n;
|
||||
__SQ_RETURN
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryGetLod(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNSAFEPTR(g->lod_proxy.c_ptr(), typetag_Geometry)
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometrySetLod(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETSAFEPTRALLOWNULL(geo_Lod, GS::Render::Geometry, typetag_Geometry)
|
||||
__SQ_GETEND
|
||||
g->lod_proxy = geo_Lod ? geo_Lod : NULL;
|
||||
__SQ_RETURN
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryGetShadowProxy(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNSAFEPTR(g->shadow_proxy.c_ptr(), typetag_Geometry)
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometrySetShadowProxy(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETSAFEPTRALLOWNULL(geo_shadow_proxy, GS::Render::Geometry, typetag_Geometry)
|
||||
__SQ_GETEND
|
||||
g->shadow_proxy = geo_shadow_proxy? geo_shadow_proxy : NULL;
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryGetName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNSTRING(g->name)
|
||||
}
|
||||
SQInteger GeometryGetMinMax(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNMINMAX(g->minmax)
|
||||
}
|
||||
SQInteger GeometrySetHidden(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETBOOL(hidden)
|
||||
__SQ_GETEND
|
||||
g->flag.Raise(Core::Geometry::FlagHidden, asbool(hidden));
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger GeometryOptimize(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger GeometryComputeIsoSurface(HSQUIRRELVM vm)
|
||||
{
|
||||
sq_pop(vm, 4);
|
||||
/*
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETSAFEPTR(Item, nMItem, typetag_Item)
|
||||
__SQ_GETINT(nb_metaball)
|
||||
|
||||
if ((nb_metaball > 0) && (Item->GetItemType() == Type_Object))
|
||||
{
|
||||
// get the geometry, or if it doesn't have it create one
|
||||
nSharedPtr <nGeometry> g;
|
||||
if(((nMObject *)Item)->GetGeometry().IsNull())
|
||||
{
|
||||
g = new nGeometry(Item->GetScene().GetEngine());
|
||||
((nMObject *)Item)->SetGeometry(g.c_ptr());
|
||||
}
|
||||
else
|
||||
g = ((nMObject *)Item)->GetGeometry();
|
||||
|
||||
nVector* pos_metaball = new nVector[nb_metaball];
|
||||
|
||||
// get the list of metaball
|
||||
sq_pushnull(vm);//null iterator
|
||||
for(int i=0; i<nb_metaball; ++i)
|
||||
{
|
||||
sq_next(vm, __SQ_STACKPOS-1 );
|
||||
GetVector(vm, -1, pos_metaball[i]);
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
sq_pop(vm,1); //pops the null iterator
|
||||
|
||||
__SQ_GETUPDATESTACK
|
||||
|
||||
float* value_metaball = new float[nb_metaball];
|
||||
sq_pushnull(vm);//null iterator
|
||||
for(int i=0; i<nb_metaball; ++i)
|
||||
{
|
||||
sq_next(vm, __SQ_STACKPOS-1 );
|
||||
sq_getfloat(vm, -1, &value_metaball[i]);
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
sq_pop(vm,1); //pops the null iterator
|
||||
|
||||
__SQ_GETEND
|
||||
|
||||
// compute min max from the metaball
|
||||
nVector MinGrid(10000000.0f,10000000.0f,10000000.0f);
|
||||
nVector MaxGrid(-10000000.0f,-10000000.0f,-10000000.0f);
|
||||
|
||||
for(int i=0; i<nb_metaball; ++i)
|
||||
{
|
||||
if (pos_metaball[i].x+value_metaball[i] > MaxGrid.x) MaxGrid.x = pos_metaball[i].x+value_metaball[i];
|
||||
if (pos_metaball[i].y+value_metaball[i] > MaxGrid.y) MaxGrid.y = pos_metaball[i].y+value_metaball[i];
|
||||
if (pos_metaball[i].z+value_metaball[i] > MaxGrid.z) MaxGrid.z = pos_metaball[i].z+value_metaball[i];
|
||||
if (pos_metaball[i].x-value_metaball[i] < MinGrid.x) MinGrid.x = pos_metaball[i].x-value_metaball[i];
|
||||
if (pos_metaball[i].y-value_metaball[i] < MinGrid.y) MinGrid.y = pos_metaball[i].y-value_metaball[i];
|
||||
if (pos_metaball[i].z-value_metaball[i] < MinGrid.z) MinGrid.z = pos_metaball[i].z-value_metaball[i];
|
||||
}
|
||||
|
||||
nIsosurface isosurface(g->GetEngine());
|
||||
isosurface.Init(MinGrid, MaxGrid-MinGrid, nVector(90, 90, 90));
|
||||
|
||||
g->Free();
|
||||
isosurface.Triangularize(g.c_ptr(), nb_metaball, pos_metaball, value_metaball);
|
||||
g->material_table.Allocate(1);
|
||||
|
||||
nMaterial *m = g->material_table[0] = new nMaterial(g->GetEngine());
|
||||
m->renderword |= nMaterial::Render_Smooth;
|
||||
// m->shader_map = m->AsShaderMap();
|
||||
//g->ComputeVertexToPolygon();
|
||||
// // Update ISO
|
||||
g->render_data = g->GetEngine().GetRenderer().SetupGeometry(g.c_ptr());
|
||||
|
||||
_safe_delete_array(value_metaball);
|
||||
_safe_delete_array(pos_metaball);
|
||||
}
|
||||
*/
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger GeometrySetup(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__LOG_V__ << "GeometrySetup() STUB\n";
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryGetMaterialList(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
sq_newarray(vm, 0);
|
||||
|
||||
for (uint n = 0; n < g->material_table.GetCount(); ++n)
|
||||
{
|
||||
CObject::Push(vm, (void *)g->material_table[n].c_ptr(), typetag_Material);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
SQInteger GeometryGetMaterialCount(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_RETURNINT(g->material_table.GetCount())
|
||||
}
|
||||
SQInteger GeometryGetMaterial(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETSTRING(name)
|
||||
|
||||
Material *m = NULL;
|
||||
for (uint n = 0; n < g->material_table.GetCount(); ++n)
|
||||
if (g->material_table[n]->name == name)
|
||||
{
|
||||
m = g->material_table[n];
|
||||
break;
|
||||
}
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(m, typetag_Material)
|
||||
}
|
||||
SQInteger GeometryGetMaterialFromIndex(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETINT(index)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(g->material_table[(int)index].c_ptr(), typetag_Material)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometrySetMaterial(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(g, Geometry, typetag_Geometry)
|
||||
__SQ_GETINT(index)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(g->SetMaterial(uint(index), m))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger GeometryCloneMaterials(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(g, Geometry, typetag_Geometry)
|
||||
|
||||
__LOG_W__ << "[SQ] GeometryCloneMaterials: Cloning all materials for geometry '" << g->name << "'...\n";
|
||||
|
||||
uint mat_count = g->material_table.GetCount();
|
||||
__LOG_W__ << "[SQ] GeometryCloneMaterials: Found " << mat_count << " materials.\n";
|
||||
|
||||
for (uint i = 0; i < mat_count; ++i)
|
||||
{
|
||||
Material *original = g->material_table[i].c_ptr();
|
||||
if (!original)
|
||||
{
|
||||
__LOG_W__ << "[SQ] GeometryCloneMaterials: Material " << i << " is NULL, skipping.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
__LOG_W__ << "[SQ] GeometryCloneMaterials: Cloning material " << i << " ('" << original->name << "')...\n";
|
||||
|
||||
// Cast to GPU::Material
|
||||
GPU::Material *gpu_mat = dynamic_cast<GPU::Material*>(original);
|
||||
if (!gpu_mat)
|
||||
{
|
||||
__LOG_W__ << "[SQ] GeometryCloneMaterials: Material " << i << " is not GPU::Material, skipping.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Clone manually (same as MaterialClone)
|
||||
try
|
||||
{
|
||||
GPU::Renderer &rend = gpu_mat->renderer;
|
||||
Material *cloned = new GPU::Material(rend);
|
||||
|
||||
// Copy properties
|
||||
cloned->name = gpu_mat->name + "_clone";
|
||||
*((Core::BasicMaterial *)cloned) = *((Core::BasicMaterial *)gpu_mat);
|
||||
((GPU::Material*)cloned)->shader = gpu_mat->shader;
|
||||
|
||||
// Copy texture table
|
||||
for (uint n = 0; n < Core::Material::max_texture_stage; ++n)
|
||||
{
|
||||
cloned->texture_table[n] = gpu_mat->texture_table[n];
|
||||
}
|
||||
|
||||
// Assign cloned material back to geometry
|
||||
g->SetMaterial(i, cloned);
|
||||
|
||||
__LOG_W__ << "[SQ] GeometryCloneMaterials: Material " << i << " cloned successfully.\n";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
__LOG_E__ << "[SQ] GeometryCloneMaterials: Exception while cloning material " << i << "!\n";
|
||||
}
|
||||
}
|
||||
|
||||
__LOG_W__ << "[SQ] GeometryCloneMaterials: Done!\n";
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------
|
||||
void RegisterGeometryBinding(HSQUIRRELVM vm)
|
||||
//-------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Geometry
|
||||
Type: Geometry
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: GeometryGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: GeometryGetLod
|
||||
Proto: Geometry:Geometry geo
|
||||
Desc: Get geometry get geometry LOD.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetLod, "GeometryGetLod", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometrySetLod
|
||||
Proto: void:Geometry geo, Geometry geo_LOD
|
||||
Desc: Set geometry LOD.
|
||||
#*/
|
||||
sq_register(vm, GeometrySetLod, "GeometrySetLod", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Func: GeometryGetShadowProxy
|
||||
Proto: Geometry:Geometry geo
|
||||
Desc: Get geometry get geometry Shadow proxy.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetShadowProxy, "GeometryGetShadowProxy", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometrySetShadowProxy
|
||||
Proto: void:Geometry geo, Geometry show_proxy
|
||||
Desc: Set geometry shadow proxy
|
||||
#*/
|
||||
sq_register(vm, GeometrySetShadowProxy, "GeometrySetShadowProxy", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Func: GeometryGetLodDistance
|
||||
Proto: float:Geometry geo
|
||||
Desc: Get geometry Lod distance.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetLodDistance, "GeometryGetLodDistance", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometrySetLodDistance
|
||||
Proto: void:Geometry geo, float Lod distance
|
||||
Desc: Set geometry Lod distance
|
||||
#*/
|
||||
sq_register(vm, GeometrySetLodDistance, "GeometrySetLodDistance", _SC(".xn"));
|
||||
|
||||
/*#
|
||||
Func: GeometryGetLodNull
|
||||
Proto: bool:Geometry geo
|
||||
Desc: Get geometry Lod Null.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetLodNull, "GeometryGetLodNull", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometrySetLodNull
|
||||
Proto: void:Geometry geo, bool LodNull
|
||||
Desc: Set geometry Lod Null
|
||||
#*/
|
||||
sq_register(vm, GeometrySetLodNull, "GeometrySetLodNull", _SC(".xb"));
|
||||
/*#
|
||||
Func: GeometryGetShadowProxyNull
|
||||
Proto: bool:Geometry geo
|
||||
Desc: Get geometry ShadowProxy Null.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetShadowProxyNull, "GeometryGetShadowProxyNull", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometrySetShadowProxyNull
|
||||
Proto: void:Geometry geo, bool ShadowProxyNull
|
||||
Desc: Set geometry ShadowProxy Null
|
||||
#*/
|
||||
sq_register(vm, GeometrySetShadowProxyNull, "GeometrySetShadowProxyNull", _SC(".xb"));
|
||||
|
||||
/*#
|
||||
Func: GeometrySaveOnItself
|
||||
Proto: void:Geometry geo, g_factory
|
||||
Desc: Save the geometry on it's own nmg.
|
||||
#*/
|
||||
sq_register(vm, GeometrySaveOnItself, "GeometrySaveOnItself", _SC(".xx"));
|
||||
|
||||
|
||||
/*#
|
||||
Func: GeometryGetName
|
||||
Proto: string:Geometry geo
|
||||
Desc: Get geometry name.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetName, "GeometryGetName", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometrySetHidden
|
||||
Proto: void:Geometry geo,bool hidden
|
||||
Desc: Hide or show geometry, items referring to this geometry will still be updated.
|
||||
#*/
|
||||
sq_register(vm, GeometrySetHidden, "GeometrySetHidden", _SC(".xb"));
|
||||
/*#
|
||||
Func: GeometryOptimize
|
||||
Proto: void:Geometry geo
|
||||
Desc: Optimize geometry for realtime rendering.
|
||||
#*/
|
||||
sq_register(vm, GeometryOptimize, "GeometryOptimize", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometryComputeIsoSurface
|
||||
Proto: void:Item item, int nb_metaball,array pos_metaball,array value_metaball
|
||||
Desc: Create an iso surface to the geometry with the array of metaball.
|
||||
#*/
|
||||
sq_register(vm, GeometryComputeIsoSurface, "GeometryComputeIsoSurface", _SC(".xiaa"));
|
||||
/*#
|
||||
Func: GeometrySetup
|
||||
Proto: void:Geometry geo
|
||||
Desc: Setup geometry in the renderer.
|
||||
#*/
|
||||
sq_register(vm, GeometrySetup, "GeometrySetup", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: GeometryTopology
|
||||
Desc: Topology functions
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: GeometryGetMinMax
|
||||
Proto: MinMax:Geometry geo
|
||||
Desc: Get geometry minmax.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetMinMax, "GeometryGetMinMax", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: GeometryMaterial
|
||||
Desc: Material functions
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: GeometryGetMaterialList
|
||||
Proto: array:Geometry geo
|
||||
Desc: Return a list of all materials in a geometry.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetMaterialList, "GeometryGetMaterialList", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometryGetMaterialCount
|
||||
Proto: int:Geometry geo
|
||||
Desc: Get geometry material count.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetMaterialCount, "GeometryGetMaterialCount", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometryGetMaterial
|
||||
Proto: Material:Geometry geo,string name
|
||||
Desc: Get material from name.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetMaterial, "GeometryGetMaterial", _SC(".xs"));
|
||||
/*#
|
||||
Func: GeometrySetMaterial
|
||||
Proto: bool:Geometry geo,int index,Material material
|
||||
Desc: Replace a material in the geometry material table.
|
||||
#*/
|
||||
sq_register(vm, GeometrySetMaterial, "GeometrySetMaterial", _SC(".xix"));
|
||||
/*#
|
||||
Func: GeometryCloneMaterials
|
||||
Proto: void:Geometry geo
|
||||
Desc: Clone all materials in the geometry. Each material becomes an independent copy.
|
||||
Note: This allows you to modify materials for one geometry without affecting others that share the same loaded geometry file.
|
||||
Example: GeometryCloneMaterials(geo)
|
||||
#*/
|
||||
sq_register(vm, GeometryCloneMaterials, "GeometryCloneMaterials", _SC(".x"));
|
||||
/*#
|
||||
Func: GeometryGetMaterialFromIndex
|
||||
Proto: Material:Geometry geo,int index
|
||||
Desc: Get material from index.
|
||||
#*/
|
||||
sq_register(vm, GeometryGetMaterialFromIndex, "GeometryGetMaterialFromIndex", _SC(".xi"));
|
||||
}
|
||||
310
include/modules/script_squirrel/legacy/group_binding.cpp
Normal file
310
include/modules/script_squirrel/legacy/group_binding.cpp
Normal file
@ -0,0 +1,310 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "scene3d/group.h"
|
||||
#include "automation/automation_source_group.h"
|
||||
#include "math/matrix4.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
SQInteger GroupSetInvisible(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETBOOL(value)
|
||||
__SQ_GETEND
|
||||
group->SetInvisible(value ? true : false);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
extern SQInteger GetMatrix4(HSQUIRRELVM vm, int idx, GS::Matrix4 &mtx);
|
||||
|
||||
SQInteger GroupOffsetMatrix(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETMATRIX4(m)
|
||||
__SQ_GETEND
|
||||
group->Offset(m);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger GroupFindItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSTRING(item_id)
|
||||
__SQ_GETEND
|
||||
MItem *item = group->Item(item_id);
|
||||
__SQ_RETURNSAFEPTR(item, typetag_Item)
|
||||
}
|
||||
|
||||
SQInteger GroupSetRootItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSAFEPTR(root, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
group->SetRootItem(root);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger GroupGetRootItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_RETURNSAFEPTR(group->GetRootItem(), typetag_Item)
|
||||
}
|
||||
|
||||
SQInteger GroupItemIsMember(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(group->IsMember(item))
|
||||
}
|
||||
SQInteger GroupAddItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
group->Add(item);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger GroupRemoveItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
group->Remove(item);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger GroupSetName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSTRING(_name)
|
||||
group->name = _name;
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger GroupGetName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_RETURNSTRING(group->name)
|
||||
}
|
||||
|
||||
SQInteger GroupSetup(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, Group, typetag_Group)
|
||||
group->Setup();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger GroupSetupScript(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, Group, typetag_Group)
|
||||
__LOG_V__ << "GroupSetupScript: STUB\n";
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger GroupRenderSetup(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSAFEPTR(rf, GS::Core::ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETEND
|
||||
group->RenderSetup(rf);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger GroupReset(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, Group, typetag_Group)
|
||||
group->Reset();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
SQInteger GroupSetMotion(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(group, Group, typetag_Group)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETFLOAT(blend)
|
||||
GS::Automation::SourceGroup *anim_group = NULL;
|
||||
group->SetMotion(name, &anim_group, blend);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNMANAGEDSAFEPTR(anim_group, typetag_AutomationSourceGroup)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
SQInteger GroupGetItemList(HSQUIRRELVM vm)
|
||||
//--------------------------------------------------
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(group, Group, typetag_Group)
|
||||
sq_newarray(vm, 0);
|
||||
ListForeachPtr(MItem *, i, group->GetItemList())
|
||||
{
|
||||
CObject::Push(vm, (void *)i, typetag_Item);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//----------------------------------------------
|
||||
void RegisterGroupBinding(HSQUIRRELVM vm)
|
||||
//----------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Group
|
||||
Desc: A group holds a reference to several scene items.
|
||||
It is often used to keep track of instantiated 'block scene' items and resources inside a larger scene.
|
||||
Type: Group
|
||||
Related: Scene, Item
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: GroupManagement
|
||||
Desc: Management
|
||||
#*/
|
||||
/*#
|
||||
Func: GroupSetup
|
||||
Proto: void:Group group
|
||||
Desc: Setup all members of a group.
|
||||
See: ItemSetup
|
||||
#*/
|
||||
sq_register(vm, GroupSetup, "GroupSetup", _SC(".x"));
|
||||
/*#
|
||||
Func: GroupSetup
|
||||
Proto: void:Group group
|
||||
Desc: Setup all members of a group.
|
||||
See: ItemSetup
|
||||
#*/
|
||||
sq_register(vm, GroupSetup, "GroupSetup", _SC(".x"));
|
||||
/*#
|
||||
Func: GroupSetupScript
|
||||
Proto: void:Group group
|
||||
Desc: Setup the script object of all members of a group.
|
||||
See: ItemSetupScript
|
||||
#*/
|
||||
sq_register(vm, GroupSetupScript, "GroupSetupScript", _SC(".x"));
|
||||
/*#
|
||||
Func: GroupReset
|
||||
Proto: void:Group group
|
||||
Desc: Reset all members of a group.
|
||||
See: ItemReset
|
||||
#*/
|
||||
sq_register(vm, GroupReset, "GroupReset", _SC(".x"));
|
||||
/*#
|
||||
Func: GroupRenderSetup
|
||||
Proto: void:Group group,ResourceFactory factory
|
||||
Desc: Setup rendering data for all members of a group.
|
||||
Example: GroupRenderSetup(group, g_factory)
|
||||
See: ItemRenderSetup
|
||||
#*/
|
||||
sq_register(vm, GroupRenderSetup, "GroupRenderSetup", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Func: GroupGetItemList
|
||||
Proto: Array:Group group
|
||||
Desc: Return the group item list.
|
||||
Example:
|
||||
function ListGroupItemNames(group)
|
||||
{
|
||||
local group_name = GroupGetName(group)
|
||||
|
||||
local items = GroupGetItemList(group)
|
||||
foreach (item in items)
|
||||
print("Item " + ItemGetName(item) + " is a member of group" + group_name + ".")
|
||||
}
|
||||
#*/
|
||||
sq_register(vm, GroupGetItemList, "GroupGetItemList", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: GroupGetRootItem
|
||||
Proto: Item:Group group
|
||||
Desc: Return the root item of a group.
|
||||
#*/
|
||||
sq_register(vm, GroupGetRootItem, "GroupGetRootItem", _SC(".x"));
|
||||
/*#
|
||||
Func: GroupSetRootItem
|
||||
Proto: void:Group group,Item root_item
|
||||
Desc: Set the root item of a group. All members of a group are linked to its root item if it has one.
|
||||
#*/
|
||||
sq_register(vm, GroupSetRootItem, "GroupSetRootItem", _SC(".xx"));
|
||||
/*#
|
||||
Func: GroupSetInvisible
|
||||
Proto: void:Group group,bool set_invisible
|
||||
Desc: Hide all members of a group.
|
||||
#*/
|
||||
sq_register(vm, GroupSetInvisible, "GroupSetInvisible", _SC(".xb"));
|
||||
/*#
|
||||
Func: GroupFindItem
|
||||
Proto: item:Group group,string name_to_find
|
||||
Desc: Find an item in a group from its name.
|
||||
#*/
|
||||
sq_register(vm, GroupFindItem, "GroupFindItem", _SC(".xs"));
|
||||
/*#
|
||||
Func: GroupItemIsMember
|
||||
Proto: bool:Group group,Item item_to_test
|
||||
Desc: Returns true if item the belongs to the group, false otherwise.
|
||||
#*/
|
||||
sq_register(vm, GroupItemIsMember, "GroupItemIsMember", _SC(".xx"));
|
||||
/*#
|
||||
Func: GroupAddItem
|
||||
Proto: void:Group group,Item item_to_add
|
||||
Desc: Add an item to a group.
|
||||
#*/
|
||||
sq_register(vm, GroupAddItem, "GroupAddItem", _SC(".xx"));
|
||||
/*#
|
||||
Func: GroupRemoveItem
|
||||
Proto: void:Group group,Item item_to_remove
|
||||
Desc: Remove an item from a group.
|
||||
#*/
|
||||
sq_register(vm, GroupRemoveItem, "GroupRemoveItem", _SC(".xx"));
|
||||
/*#
|
||||
Func: GroupSetName
|
||||
Proto: void:Group group,string name
|
||||
Desc: Set the name of a group.
|
||||
#*/
|
||||
sq_register(vm, GroupSetName, "GroupSetName", _SC(".xs"));
|
||||
/*#
|
||||
Func: GroupGetName
|
||||
Proto: string:Group group
|
||||
Desc: Get the name of a group.
|
||||
#*/
|
||||
sq_register(vm, GroupGetName, "GroupGetName", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: GroupTransform
|
||||
Desc: Transformation
|
||||
#*/
|
||||
/*#
|
||||
Func: GroupOffsetMatrix
|
||||
Proto: void:Group group,matrix4 offset_matrix
|
||||
Desc: Apply a 4x4 offset matrix to all group members.
|
||||
See: TransformationMatrix
|
||||
#*/
|
||||
sq_register(vm, GroupOffsetMatrix, "GroupOffsetMatrix", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Section: GroupMotion
|
||||
Desc: Motion
|
||||
#*/
|
||||
/*#
|
||||
Func: GroupSetMotion
|
||||
Proto: AnimationSourceGroup:Group group,string motion_name,float blend
|
||||
Desc: Set motion on all group items, specify the blend duration, stop all current animation sources.
|
||||
See: ItemSetMotion
|
||||
#*/
|
||||
sq_register(vm, GroupSetMotion, "GroupSetMotion", _SC(".xsn"));
|
||||
}
|
||||
67
include/modules/script_squirrel/legacy/hash_binding.cpp
Normal file
67
include/modules/script_squirrel/legacy/hash_binding.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "hash/md5.h"
|
||||
#include "hash/nsha1.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MD5(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(source)
|
||||
|
||||
using namespace GS::MD5;
|
||||
|
||||
Digest md5;
|
||||
|
||||
md5_byte_t digest[16];
|
||||
md5.Append((const md5_byte_t *)source, GS::String::strlen(source));
|
||||
md5.Finish(digest);
|
||||
|
||||
char md5_string[33];
|
||||
DigestToString(digest, md5_string);
|
||||
md5_string[32] = 0;
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSTRING(md5_string)
|
||||
}
|
||||
SQInteger SHA1(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(source)
|
||||
GS::String hash = GS::SHA1::ComputeHexa(source);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSTRING(hash.c_str())
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void RegisterHashBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
using namespace GS::Script;
|
||||
|
||||
/*#
|
||||
Topic: Hash
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: Hashing
|
||||
Desc: Hashing
|
||||
#*/
|
||||
/*#
|
||||
Func: MD5
|
||||
Proto: String:String source
|
||||
Desc: Compute a MD5 hexadecimal hash.
|
||||
#*/
|
||||
sq_register(vm, MD5, "MD5", _SC(".s"));
|
||||
/*#
|
||||
Func: SHA1
|
||||
Proto: String:String source
|
||||
Desc: Compute a SHA1 hexadecimal hash.
|
||||
#*/
|
||||
sq_register(vm, SHA1, "SHA1", _SC(".s"));
|
||||
}
|
||||
169
include/modules/script_squirrel/legacy/http_binding.cpp
Normal file
169
include/modules/script_squirrel/legacy/http_binding.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "http_curl/http_curl.h"
|
||||
#include "script_squirrel/legacy/squirrel_binding.h"
|
||||
#include "script/script_variant.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
#if __PLATFORM_EMSCRIPTEN__
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger HttpPost(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger HttpUpdate(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#else
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
class SquirrelHTTP : public HTTP::Curl
|
||||
{
|
||||
HSQUIRRELVM vm;
|
||||
|
||||
public:
|
||||
|
||||
void OnRequestComplete(int ticket_id, const Array <char> &data)
|
||||
{
|
||||
SquirrelVM *sq_vm = GetVMObject(vm);
|
||||
|
||||
if (sq_vm->SetupFunctionCall("OnHttpRequestComplete"))
|
||||
{
|
||||
sq_vm->PushArgument(ticket_id);
|
||||
|
||||
if (data.GetSize() > 0)
|
||||
{
|
||||
String str(data.c_ptr(), data.GetCount());
|
||||
sq_vm->PushArgument(str.c_str());
|
||||
}
|
||||
else
|
||||
sq_vm->PushNullArgument();
|
||||
|
||||
sq_vm->DoFunctionCall();
|
||||
}
|
||||
}
|
||||
void OnRequestError(int ticket_id)
|
||||
{
|
||||
SquirrelVM *sq_vm = GetVMObject(vm);
|
||||
|
||||
if (sq_vm->SetupFunctionCall("OnHttpRequestError"))
|
||||
{
|
||||
sq_vm->PushArgument(ticket_id);
|
||||
sq_vm->DoFunctionCall();
|
||||
}
|
||||
}
|
||||
|
||||
SquirrelHTTP(HSQUIRRELVM v) : vm(v) {}
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger HttpPost(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSTRING(url)
|
||||
__SQ_GETSTRING(post)
|
||||
SquirrelVM *sq_vm = GetVMObject(vm);
|
||||
int id = sq_vm->http->Post(url, post);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNINT(id)
|
||||
}
|
||||
SQInteger HttpUpdate(HSQUIRRELVM vm)
|
||||
{
|
||||
SquirrelVM *sq_vm = GetVMObject(vm);
|
||||
sq_vm->http->Update();
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
//#include <iostream.h>
|
||||
#include <winsock.h>
|
||||
SQInteger GetIp(HSQUIRRELVM vm)
|
||||
{
|
||||
String ip_adress;
|
||||
|
||||
char ac[80];
|
||||
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) {
|
||||
__SQ_RETURNSTRING("");
|
||||
}
|
||||
struct hostent *phe = gethostbyname(ac);
|
||||
if (phe == 0) {
|
||||
__SQ_RETURNSTRING("");
|
||||
}
|
||||
|
||||
for (int i = 0; phe->h_addr_list[i] != 0; ++i) {
|
||||
struct in_addr addr;
|
||||
memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr));
|
||||
ip_adress += String(inet_ntoa(addr)) + String(" ");
|
||||
}
|
||||
|
||||
__SQ_RETURNSTRING(ip_adress.c_str())
|
||||
}
|
||||
//*********************************************************
|
||||
|
||||
#endif
|
||||
|
||||
void RegisterHTTPBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
#if __PLATFORM_EMSCRIPTEN__ == 0
|
||||
SquirrelVM *sq_vm = GetVMObject(vm);
|
||||
sq_vm->http = new SquirrelHTTP(vm);
|
||||
#endif
|
||||
|
||||
/*#
|
||||
Topic: HTTP
|
||||
Desc: Send HTTP POST request to a remote URL and receive remote response asynchronously.
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: HTTP helper
|
||||
Desc: HTTP helper functions.
|
||||
#*/
|
||||
/*#
|
||||
Func: HttpUpdate
|
||||
Proto: void:
|
||||
Desc: Update the HTTP subsystem. You must call this function to receive queued events.
|
||||
See: HttpPost
|
||||
#*/
|
||||
sq_register(vm, HttpUpdate, "HttpUpdate", _SC("."));
|
||||
/*#
|
||||
Func: HttpPost
|
||||
Proto: int:String url, String post
|
||||
Desc: POST an HTTP request to a remote URL and returns the request identifier.<br>This function returns immediately, the request result will be sent to the global HTTP script callbacks.
|
||||
Example:
|
||||
// POST a request with two parameters to a remote server.
|
||||
local id = HttpPost("http://www.someurl.com", "param_a=1&param_b=2")
|
||||
print("HTTP request posted, id: " + id)
|
||||
|
||||
// The two global HTTP request callbacks.
|
||||
function OnHttpRequestComplete(ticket_id, data)
|
||||
{
|
||||
print("HTTP request " + ticket_id + " complete.")
|
||||
print("Data received: " + data)
|
||||
}
|
||||
function OnHttpRequestError(ticket_id)
|
||||
{
|
||||
print("HTTP request " + ticket_id + " errored.")
|
||||
}
|
||||
#*/
|
||||
sq_register(vm, HttpPost, "HttpPost", _SC(".ss"));
|
||||
|
||||
|
||||
/*#
|
||||
Func: GetIp
|
||||
Proto: string:void
|
||||
Desc: Get local ip.
|
||||
#*/
|
||||
sq_register(vm, GetIp, "GetIp", _SC("."));
|
||||
}
|
||||
63
include/modules/script_squirrel/legacy/instance_binding.cpp
Normal file
63
include/modules/script_squirrel/legacy/instance_binding.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "scene3d/instance.h"
|
||||
#include "scene3d/group.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger InstanceGetItemList(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(instance, Instance, typetag_Instance)
|
||||
sq_newarray(vm, 0);
|
||||
if (instance->instance_group)
|
||||
ListForeachPtr(MItem *, i, instance->instance_group->GetItemList())
|
||||
{
|
||||
CObject::Push(vm, (void *)i, typetag_Item);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger InstanceGetTemplatePath(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(instance, Instance, typetag_Instance)
|
||||
__SQ_RETURNSTRING(instance->template_path.c_str())
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterInstanceBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Instance
|
||||
Type: Instance
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: InstanceGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
/*#
|
||||
Func: InstanceGetItemList
|
||||
Proto: array:Instance
|
||||
Desc: Return instance item list. Note: The instance must have been instantiate to return any item.
|
||||
#*/
|
||||
sq_register(vm, InstanceGetItemList, "InstanceGetItemList", _SC(".x"));
|
||||
/*#
|
||||
Func: InstanceGetTemplatePath
|
||||
Proto: string:Instance
|
||||
Desc: Return instance path
|
||||
#*/
|
||||
sq_register(vm, InstanceGetTemplatePath, "InstanceGetTemplatePath", _SC(".x"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
1072
include/modules/script_squirrel/legacy/io_binding.cpp
Normal file
1072
include/modules/script_squirrel/legacy/io_binding.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2455
include/modules/script_squirrel/legacy/item_binding.cpp
Normal file
2455
include/modules/script_squirrel/legacy/item_binding.cpp
Normal file
File diff suppressed because it is too large
Load Diff
347
include/modules/script_squirrel/legacy/light_binding.cpp
Normal file
347
include/modules/script_squirrel/legacy/light_binding.cpp
Normal file
@ -0,0 +1,347 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "scene3d/mlight.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
static CObjectType light_derived_types[] = { typetag_Item, typetag_Light, typetag_Undefined };
|
||||
|
||||
SQInteger LightGetDiffuseIntensity(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNFLOAT(l->diffuse_intensity)
|
||||
}
|
||||
|
||||
SQInteger LightSetProjectionTexture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETSAFEPTR(t, GS::Render::Texture, typetag_Texture)
|
||||
l->render_data->projection_texture = t;
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightSetDiffuseIntensity(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETFLOAT(i)
|
||||
__SQ_GETEND
|
||||
l->diffuse_intensity = i;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetDiffuseColor(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNVECTOR(l->diffuse_color)
|
||||
}
|
||||
SQInteger LightSetDiffuseColor(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETVECTOR(color)
|
||||
__SQ_GETEND
|
||||
l->diffuse_color = color;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetSpecularIntensity(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNFLOAT(l->specular_intensity)
|
||||
}
|
||||
SQInteger LightSetSpecularIntensity(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETFLOAT(i)
|
||||
__SQ_GETEND
|
||||
l->specular_intensity = i;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetSpecularColor(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNVECTOR(l->specular_color)
|
||||
}
|
||||
SQInteger LightSetSpecularColor(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETVECTOR(color)
|
||||
__SQ_GETEND
|
||||
l->specular_color = color;
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger LightSetConeAngle(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETFLOAT(angle)
|
||||
__SQ_GETEND
|
||||
l->cone_angle = angle;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetConeAngle(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNFLOAT(l->cone_angle)
|
||||
}
|
||||
SQInteger LightSetEdgeAngle(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETFLOAT(angle)
|
||||
__SQ_GETEND
|
||||
l->edge_angle = angle;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetEdgeAngle(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNFLOAT(l->edge_angle)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger LightSetRange(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETFLOAT(range)
|
||||
__SQ_GETEND
|
||||
l->range = range;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetRange(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNFLOAT(l->range)
|
||||
}
|
||||
SQInteger LightSetShadowRange(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETFLOAT(shadow_range)
|
||||
__SQ_GETEND
|
||||
l->shadow_range = shadow_range;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetShadowRange(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNFLOAT(l->shadow_range)
|
||||
}
|
||||
SQInteger LightSetVolumeRange(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETFLOAT(range)
|
||||
__SQ_GETEND
|
||||
l->volume_range = range;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger LightGetVolumeRange(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNFLOAT(l->volume_range)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
SQInteger LightGetItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNSAFEPTR((MItem *)l, typetag_Item)
|
||||
}
|
||||
SQInteger LightGetType(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
|
||||
__SQ_RETURNINT(l->model)
|
||||
}
|
||||
SQInteger LightSetType(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
|
||||
__SQ_GETINT(_type)
|
||||
__SQ_GETEND
|
||||
l->model = (GS::Core::Light::Model)_type;
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterLightBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Light
|
||||
Type: Light
|
||||
Related: Item
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: LightColor
|
||||
Desc: Light color functions
|
||||
#*/
|
||||
/*#
|
||||
Func: LightGetDiffuseIntensity
|
||||
Proto: float:Light
|
||||
Desc: Get light diffuse intensity.
|
||||
#*/
|
||||
sq_register(vm, LightGetDiffuseIntensity, "LightGetDiffuseIntensity", _SC(".x"));
|
||||
/*#
|
||||
Func: LightGetDiffuseColor
|
||||
Proto: Vector:Light
|
||||
Desc: Get light diffuse color.
|
||||
#*/
|
||||
sq_register(vm, LightGetDiffuseColor, "LightGetDiffuseColor", _SC(".x"));
|
||||
/*#
|
||||
Func: LightSetDiffuseIntensity
|
||||
Proto: void:Light,float intensity
|
||||
Desc: Set light diffuse intensity.
|
||||
#*/
|
||||
sq_register(vm, LightSetDiffuseIntensity, "LightSetDiffuseIntensity", _SC(".xn"));
|
||||
/*#
|
||||
Func: LightSetDiffuseColor
|
||||
Proto: void:Light,Vector color
|
||||
Desc: Set light diffuse color.
|
||||
#*/
|
||||
sq_register(vm, LightSetDiffuseColor, "LightSetDiffuseColor", _SC(".xx"));
|
||||
/*#
|
||||
Func: LightGetSpecularIntensity
|
||||
Proto: float:Light
|
||||
Desc: Get light specular intensity.
|
||||
#*/
|
||||
sq_register(vm, LightGetSpecularIntensity, "LightGetSpecularIntensity", _SC(".x"));
|
||||
/*#
|
||||
Func: LightGetSpecularColor
|
||||
Proto: Vector:Light
|
||||
Desc: Get light specular color.
|
||||
#*/
|
||||
sq_register(vm, LightGetSpecularColor, "LightGetSpecularColor", _SC(".x"));
|
||||
/*#
|
||||
Func: LightSetSpecularIntensity
|
||||
Proto: void:Light,float intensity
|
||||
Desc: Set light specular intensity.
|
||||
#*/
|
||||
sq_register(vm, LightSetSpecularIntensity, "LightSetSpecularIntensity", _SC(".xn"));
|
||||
/*#
|
||||
Func: LightSetSpecularColor
|
||||
Proto: void:Light,Vector color
|
||||
Desc: Set light specular color.
|
||||
#*/
|
||||
sq_register(vm, LightSetSpecularColor, "LightSetSpecularColor", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Section: LightSpot
|
||||
Desc: Spot functions
|
||||
#*/
|
||||
/*#
|
||||
Func: LightSetConeAngle
|
||||
Proto: void:Light,float angle
|
||||
Desc: Set light cone angle in radian, the cone angle is the spot area where intensity is at its maximum.
|
||||
#*/
|
||||
sq_register(vm, LightSetConeAngle, "LightSetConeAngle", _SC(".xn"));
|
||||
/*#
|
||||
Func: LightSetEdgeAngle
|
||||
Proto: void:Light,float angle
|
||||
Desc: Set light edge angle in radian, the edge angle is the spot area where intensity decreases from its maximum toward zero.
|
||||
#*/
|
||||
sq_register(vm, LightSetEdgeAngle, "LightSetEdgeAngle", _SC(".xn"));
|
||||
/*#
|
||||
Func: LightGetConeAngle
|
||||
Proto: float:Light
|
||||
Desc: Get light cone angle in radian.
|
||||
#*/
|
||||
sq_register(vm, LightGetConeAngle, "LightGetConeAngle", _SC(".x"));
|
||||
/*#
|
||||
Func: LightGetEdgeAngle
|
||||
Proto: float:Light
|
||||
Desc: Get light edge angle in radian.
|
||||
#*/
|
||||
sq_register(vm, LightGetEdgeAngle, "LightGetEdgeAngle", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: LightGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
/*#
|
||||
Func: LightSetRange
|
||||
Proto: void:Light,float range
|
||||
Desc: Set the light range in meter.
|
||||
#*/
|
||||
sq_register(vm, LightSetRange, "LightSetRange", _SC(".xn"));
|
||||
/*#
|
||||
Func: LightGetRange
|
||||
Proto: float:Light
|
||||
Desc: Return the light range in meter.
|
||||
#*/
|
||||
sq_register(vm, LightGetRange, "LightGetRange", _SC(".x"));
|
||||
/*#
|
||||
Func: LightSetShadowRange
|
||||
Proto: void:Light,float range
|
||||
Desc: Set the light range in meter.
|
||||
#*/
|
||||
sq_register(vm, LightSetShadowRange, "LightSetShadowRange", _SC(".xn"));
|
||||
/*#
|
||||
Func: LightGetRange
|
||||
Proto: float:Light
|
||||
Desc: Return the light range in meter.
|
||||
#*/
|
||||
sq_register(vm, LightGetShadowRange, "LightGetShadowRange", _SC(".x"));
|
||||
/*#
|
||||
Func: LightSetVolumeRange
|
||||
Proto: void:Light,float range
|
||||
Desc: Set the light volume range in meter. The volume range has no relation with the volumetric system and is only a performance hint used by some renderer. If unsure this value should be kept equal to the light range.
|
||||
#*/
|
||||
sq_register(vm, LightSetVolumeRange, "LightSetVolumeRange", _SC(".xn"));
|
||||
/*#
|
||||
Func: LightGetVolumeRange
|
||||
Proto: float:Light
|
||||
Desc: Return the light volume range in meter.
|
||||
#*/
|
||||
sq_register(vm, LightGetVolumeRange, "LightGetVolumeRange", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: LightSetProjectionTexture
|
||||
Proto: void:Light,Texture
|
||||
Desc: Set light projection texture.
|
||||
#*/
|
||||
sq_register(vm, LightSetProjectionTexture, "LightSetProjectionTexture", _SC(".xx"));
|
||||
/*#
|
||||
Func: LightGetItem
|
||||
Proto: Item:Light
|
||||
Desc: Get light item.
|
||||
#*/
|
||||
sq_register(vm, LightGetItem, "LightGetItem", _SC(".x"));
|
||||
/*#
|
||||
Func: LightGetType
|
||||
Proto: LightType:Light
|
||||
Desc: Get light type.
|
||||
#*/
|
||||
sq_register(vm, LightGetType, "LightGetType", _SC(".x"));
|
||||
/*#
|
||||
Func: LightSetType
|
||||
Proto: void:Light,LightType type
|
||||
Desc: Set light type.
|
||||
#*/
|
||||
sq_register(vm, LightSetType, "LightSetType", _SC(".xi"));
|
||||
|
||||
/*#
|
||||
Enum: LightType
|
||||
Values: LightTypeNone,LightTypeSpot,LightTypeLinear,LightTypePoint
|
||||
#*/
|
||||
using GS::Core::Light;
|
||||
|
||||
sq_pushstring(vm, "LightTypeNone", -1); sq_pushinteger(vm, Light::Model_None); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "LightTypeSpot", -1); sq_pushinteger(vm, Light::Model_Spot); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "LightTypeLinear", -1); sq_pushinteger(vm, Light::Model_Linear); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "LightTypePoint", -1); sq_pushinteger(vm, Light::Model_Point); sq_newslot(vm, -3, true);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
532
include/modules/script_squirrel/legacy/material_binding.cpp
Normal file
532
include/modules/script_squirrel/legacy/material_binding.cpp
Normal file
@ -0,0 +1,532 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "core/material_to_shader_tree.h"
|
||||
#include "core/render_data.h"
|
||||
#include "gpu/gpu_material.h"
|
||||
|
||||
using namespace GS::Render;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialGetDiffuse(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNVECTORW(m->diffuse)
|
||||
}
|
||||
SQInteger MaterialSetDiffuse(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
m->diffuse = c;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MaterialGetSpecular(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNVECTORW(m->specular)
|
||||
}
|
||||
SQInteger MaterialSetSpecular(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
m->specular = c;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MaterialGetSelf(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNVECTORW(m->self)
|
||||
}
|
||||
SQInteger MaterialSetSelf(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
m->self = c;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MaterialGetAmbient(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNVECTORW(m->ambient)
|
||||
}
|
||||
SQInteger MaterialSetAmbient(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
m->ambient = c;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialGetGlossiness(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNFLOAT(m->glossiness)
|
||||
}
|
||||
SQInteger MaterialSetGlossiness(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETFLOAT(v)
|
||||
__SQ_GETEND
|
||||
m->glossiness = v;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MaterialGetOpacity(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNFLOAT(m->opacity)
|
||||
}
|
||||
SQInteger MaterialSetOpacity(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETFLOAT(v)
|
||||
__SQ_GETEND
|
||||
m->opacity = v;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MaterialGetAlphaThreshold(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNFLOAT(m->athreshold)
|
||||
}
|
||||
SQInteger MaterialSetAlphaThreshold(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETFLOAT(v)
|
||||
__SQ_GETEND
|
||||
m->athreshold = v;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MaterialGetDepthBias(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_RETURNFLOAT(m->depth_bias)
|
||||
}
|
||||
SQInteger MaterialSetDepthBias(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(m, Material, typetag_Material)
|
||||
__SQ_GETFLOAT(v)
|
||||
__SQ_GETEND
|
||||
m->depth_bias = v;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialGetName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_RETURNSTRING(mat->name.c_str())
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialFlagGet(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_GETINT(flag)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(asbool(mat->renderword & flag))
|
||||
}
|
||||
SQInteger MaterialFlagSet(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_GETINT(flag)
|
||||
__SQ_GETBOOL(state)
|
||||
__SQ_GETEND
|
||||
if (state)
|
||||
mat->renderword |= flag;
|
||||
else mat->renderword &= ~flag;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialGetBlendOperator(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_RETURNINT(mat->blendop)
|
||||
}
|
||||
SQInteger MaterialSetBlendOperator(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_GETINT(op)
|
||||
__SQ_GETEND
|
||||
mat->blendop = op;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialGetTexture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_GETINT(slot)
|
||||
__SQ_GETEND
|
||||
if ((slot < 0) || (slot >= GS::Core::Material::max_texture_stage))
|
||||
return sq_throwerror(vm, "Invalid material texture slot index.");
|
||||
__SQ_RETURNSAFEPTR(mat->texture_table[slot].c_ptr(), typetag_Texture)
|
||||
}
|
||||
SQInteger MaterialSetTexture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_GETINT(slot)
|
||||
__SQ_GETSAFEPTR(tex, Texture, typetag_Texture)
|
||||
__SQ_GETEND
|
||||
if ((slot < 0) || (slot >= GS::Core::Material::max_texture_stage))
|
||||
return sq_throwerror(vm, "Invalid material texture slot index.");
|
||||
mat->texture_table[slot] = tex;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialClone(HSQUIRRELVM vm)
|
||||
{
|
||||
__LOG_W__ << "[SQ] MaterialClone: Called from Squirrel.\n";
|
||||
|
||||
__SQ_GETSINGLESAFEPTR(mat, Material, typetag_Material)
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Got material pointer: " << (void*)mat << "\n";
|
||||
|
||||
if (!mat)
|
||||
{
|
||||
__LOG_E__ << "[SQ] MaterialClone: Input material is NULL!\n";
|
||||
return sq_throwerror(vm, "Input material is NULL");
|
||||
}
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Material name: '" << mat->name << "'\n";
|
||||
__LOG_W__ << "[SQ] MaterialClone: Material refcount: " << mat->GetRefCount() << "\n";
|
||||
|
||||
// Cast to GPU::Material to ensure we're working with the right type
|
||||
__LOG_W__ << "[SQ] MaterialClone: Attempting dynamic_cast to GPU::Material...\n";
|
||||
GS::GPU::Material *gpu_mat = dynamic_cast<GS::GPU::Material*>(mat);
|
||||
|
||||
if (!gpu_mat)
|
||||
{
|
||||
__LOG_E__ << "[SQ] MaterialClone: Material is not a GPU::Material! Cannot clone.\n";
|
||||
return sq_throwerror(vm, "Material type not supported for cloning");
|
||||
}
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: dynamic_cast succeeded, got GPU::Material at " << (void*)gpu_mat << "\n";
|
||||
|
||||
// WORKAROUND: Clone manually without calling virtual methods
|
||||
// (calling virtual methods crashes for unknown reason)
|
||||
__LOG_W__ << "[SQ] MaterialClone: Cloning manually (bypassing virtual Clone())...\n";
|
||||
|
||||
Material *cloned = NULL;
|
||||
|
||||
try
|
||||
{
|
||||
__LOG_W__ << "[SQ] MaterialClone: Accessing renderer reference...\n";
|
||||
GS::GPU::Renderer &rend = gpu_mat->renderer;
|
||||
__LOG_W__ << "[SQ] MaterialClone: Renderer at: " << (void*)&rend << "\n";
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Allocating new GPU::Material...\n";
|
||||
cloned = new GS::GPU::Material(rend);
|
||||
__LOG_W__ << "[SQ] MaterialClone: Allocation succeeded: " << (void*)cloned << "\n";
|
||||
|
||||
// Copy properties manually
|
||||
__LOG_W__ << "[SQ] MaterialClone: Copying name...\n";
|
||||
cloned->name = gpu_mat->name + "_clone";
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Copying BasicMaterial properties...\n";
|
||||
*((GS::Core::BasicMaterial *)cloned) = *((GS::Core::BasicMaterial *)gpu_mat);
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Copying shader reference...\n";
|
||||
((GS::GPU::Material*)cloned)->shader = gpu_mat->shader;
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Copying texture table...\n";
|
||||
for (uint n = 0; n < GS::Core::Material::max_texture_stage; ++n)
|
||||
{
|
||||
cloned->texture_table[n] = gpu_mat->texture_table[n];
|
||||
}
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Manual clone complete!\n";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
__LOG_E__ << "[SQ] MaterialClone: EXCEPTION caught during manual clone!\n";
|
||||
if (cloned)
|
||||
delete cloned;
|
||||
return sq_throwerror(vm, "Exception during clone");
|
||||
}
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Clone() returned: " << (void*)cloned << "\n";
|
||||
|
||||
if (!cloned)
|
||||
{
|
||||
__LOG_E__ << "[SQ] MaterialClone: Clone() returned NULL!\n";
|
||||
return sq_throwerror(vm, "Failed to clone material");
|
||||
}
|
||||
|
||||
__LOG_W__ << "[SQ] MaterialClone: Returning managed pointer to Squirrel...\n";
|
||||
// Use managed pointer so Squirrel will handle the reference counting
|
||||
__SQ_RETURNMANAGEDSAFEPTR(cloned, typetag_Material)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialGetShader(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mat, Material, typetag_Material)
|
||||
__SQ_RETURNSAFEPTR(mat->GetShader(), typetag_MaterialShader)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterMaterialBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Material
|
||||
Type: Material
|
||||
Type: MaterialShader
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: MaterialRenderAttributes
|
||||
Desc: Render attributes functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MaterialGetDiffuse
|
||||
Proto: Vector:Material material
|
||||
Desc: Get material diffuse color.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetDiffuse, "MaterialGetDiffuse", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetDiffuse
|
||||
Proto: void:Material material,Vector diffuse_color
|
||||
Desc: Set material diffuse color.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetDiffuse, "MaterialSetDiffuse", _SC(".xx"));
|
||||
/*#
|
||||
Func: MaterialGetSpecular
|
||||
Proto: Vector:Material material
|
||||
Desc: Get material specular color.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetSpecular, "MaterialGetSpecular", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetSpecular
|
||||
Proto: void:Material material,Vector specular_color
|
||||
Desc: Set material specular color.
|
||||
Note: This value is combined with the light source own specular color and intensity.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetSpecular, "MaterialSetSpecular", _SC(".xx"));
|
||||
/*#
|
||||
Func: MaterialGetSelf
|
||||
Proto: Vector:Material material
|
||||
Desc: Get material self color.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetSelf, "MaterialGetSelf", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetSelf
|
||||
Proto: void:Material material,Vector self_color
|
||||
Desc: Set material self color.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetSelf, "MaterialSetSelf", _SC(".xx"));
|
||||
/*#
|
||||
Func: MaterialGetAmbient
|
||||
Proto: Vector:Material material
|
||||
Desc: Get material ambient color.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetAmbient, "MaterialGetAmbient", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetAmbient
|
||||
Proto: void:Material material,Vector ambient_color
|
||||
Desc: Set material ambient color.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetAmbient, "MaterialSetAmbient", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Func: MaterialGetGlossiness
|
||||
Proto: float:Material material
|
||||
Desc: Get material glossiness.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetGlossiness, "MaterialGetGlossiness", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetGlossiness
|
||||
Proto: void:Material material,float glossiness
|
||||
Desc: Set material glossiness.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetGlossiness, "MaterialSetGlossiness", _SC(".xn"));
|
||||
/*#
|
||||
Func: MaterialGetOpacity
|
||||
Proto: float:Material material
|
||||
Desc: Get material opacity.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetOpacity, "MaterialGetOpacity", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetOpacity
|
||||
Proto: void:Material material,float opacity
|
||||
Desc: Set material opacity.
|
||||
See: MaterialSetBlendOperator
|
||||
#*/
|
||||
sq_register(vm, MaterialSetOpacity, "MaterialSetOpacity", _SC(".xn"));
|
||||
/*#
|
||||
Func: MaterialGetAlphaThreshold
|
||||
Proto: float:Material material
|
||||
Desc: Get material alpha threshold.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetAlphaThreshold, "MaterialGetAlphaThreshold", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetAlphaThreshold
|
||||
Proto: void:Material material,float threshold
|
||||
Desc: Set material alpha threshold.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetAlphaThreshold, "MaterialSetAlphaThreshold", _SC(".xn"));
|
||||
/*#
|
||||
Func: MaterialGetDepthBias
|
||||
Proto: float:Material material
|
||||
Desc: Get material depth bias.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetDepthBias, "MaterialGetDepthBias", _SC(".x"));
|
||||
/*#
|
||||
Func: MaterialSetDepthBias
|
||||
Proto: void:Material material,float depth_bias
|
||||
Desc: Set material depth bias.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetDepthBias, "MaterialSetDepthBias", _SC(".xn"));
|
||||
/*#
|
||||
Func: MaterialGetTexture
|
||||
Proto: Texture:Material material,int slot
|
||||
Desc: Get texture at a given material slot.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetTexture, "MaterialGetTexture", _SC(".xn"));
|
||||
/*#
|
||||
Func: MaterialSetTexture
|
||||
Proto: void:Material material,int slot,Texture texture
|
||||
Desc: Set texture at a given material slot.
|
||||
#*/
|
||||
sq_register(vm, MaterialSetTexture, "MaterialSetTexture", _SC(".xnx"));
|
||||
/*#
|
||||
Func: MaterialGetShader
|
||||
Proto: MaterialShader:Material material
|
||||
Desc: Return the material shader for a given material.
|
||||
Note: A material shader encapsulates all the variants of a shader required to render a material.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetShader, "MaterialGetShader", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: MaterialGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MaterialGetName
|
||||
Proto: string:Material mat
|
||||
Desc: Get material name.
|
||||
#*/
|
||||
sq_register(vm, MaterialGetName, "MaterialGetName", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: MaterialClone
|
||||
Proto: Material:Material mat
|
||||
Desc: Clone a material (create an independent copy in memory).
|
||||
Note: The cloned material has all the same textures, properties, and configuration as the original, but changes to the clone won't affect the original material.
|
||||
Example: local mat_clone = MaterialClone(original_material)
|
||||
#*/
|
||||
sq_register(vm, MaterialClone, "MaterialClone", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: MaterialFlag
|
||||
Desc: Rendering flag functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MaterialSetRenderFlag
|
||||
Proto: void:Material mat,MaterialRenderFlag flag,bool state
|
||||
Desc: Add or remove a material render flag.
|
||||
Example:
|
||||
// Set the first material of a geometry to be double-sided.
|
||||
local mat = GeometryGetMaterialFromIndex(geo, 0)
|
||||
MaterialSetRenderFlag(mat, MaterialRenderDoubleSided, true)
|
||||
#*/
|
||||
sq_register(vm, MaterialFlagSet, "MaterialFlagSet", _SC(".xib"));
|
||||
sq_register(vm, MaterialFlagSet, "MaterialSetRenderFlag", _SC(".xib"));
|
||||
/*#
|
||||
Func: MaterialTestRenderFlag
|
||||
Proto: bool:Material mat,MaterialRenderFlag flag
|
||||
Desc: Test a material render flag.
|
||||
#*/
|
||||
sq_register(vm, MaterialFlagGet, "MaterialFlagGet", _SC(".xi"));
|
||||
sq_register(vm, MaterialFlagGet, "MaterialTestRenderFlag", _SC(".xi"));
|
||||
|
||||
/*#
|
||||
Func: MaterialSetBlendOperator
|
||||
Proto: void:Material mat,MaterialBlendOperator op
|
||||
Desc: Set the material blend operator. The blend operator controls how a material is composited onto screen.
|
||||
Example:
|
||||
// Set the first material of a geometry to use additive blending.
|
||||
local mat = GeometryGetMaterialFromIndex(geo, 0)
|
||||
MaterialSetBlendOperator(mat, MaterialBlendAdditive)
|
||||
#*/
|
||||
sq_register(vm, MaterialSetBlendOperator, "MaterialSetBlendOperator", _SC(".xi"));
|
||||
/*#
|
||||
Func: MaterialGetBlendOperator
|
||||
Proto: MaterialBlendOperator:Material mat
|
||||
Desc: Get the material blend operator.
|
||||
See: MaterialSetBlendOperator
|
||||
#*/
|
||||
sq_register(vm, MaterialGetBlendOperator, "MaterialGetBlendOperator", _SC(".x"));
|
||||
|
||||
//
|
||||
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "NullMaterial", -1); CObject::Push(vm, NULL, typetag_Material); sq_newslot(vm, -3, true);
|
||||
|
||||
using GS::Core::Material;
|
||||
|
||||
/*#
|
||||
Enum: MaterialBlendOperator
|
||||
Values: MaterialBlendNone,MaterialBlendAlpha,MaterialBlendAdditive
|
||||
#*/
|
||||
sq_pushstring(vm, "MaterialBlendNone", -1); sq_pushinteger(vm, Material::Blend_None); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialBlendAlpha", -1); sq_pushinteger(vm, Material::Blend_Alpha); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialBlendAdditive", -1); sq_pushinteger(vm, Material::Blend_Add); sq_newslot(vm, -3, true);
|
||||
|
||||
/*#
|
||||
Enum: MaterialRenderFlag
|
||||
Values: MaterialRenderUnlit,MaterialRenderSmooth,MaterialRenderNormalMapTangent,MaterialRenderNoFog,MaterialRenderDoubleSided,MaterialRenderWire,MaterialRenderVertexColor,MaterialRenderParralax,MaterialRenderToonShading,MaterialRenderNoDepthWrite,MaterialRenderNoDepthTest,MaterialRenderAlphaSoftZ,MaterialRenderAlphaInShadow
|
||||
#*/
|
||||
sq_pushstring(vm, "MaterialRenderUnlit", -1); sq_pushinteger(vm, Material::Render_Unlit); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderSmooth", -1); sq_pushinteger(vm, Material::Render_Smooth); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderNormalMapTangent", -1); sq_pushinteger(vm, Material::Render_NormalTangent); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderNoFog", -1); sq_pushinteger(vm, Material::Render_NoFog); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "MaterialRenderDoubleSided", -1); sq_pushinteger(vm, Material::Render_DoubleSided); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderWire", -1); sq_pushinteger(vm, Material::Render_Wire); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderVertexColor", -1); sq_pushinteger(vm, Material::Render_VertexColor); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderParralax", -1); sq_pushinteger(vm, Material::Render_ParralaxDisp); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderToonShading", -1); sq_pushinteger(vm, Material::Render_Toon); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "MaterialRenderNoDepthWrite", -1); sq_pushinteger(vm, Material::Render_NoZWrite); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderNoDepthTest", -1); sq_pushinteger(vm, Material::Render_NoZTest); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "MaterialRenderAlphaSoftZ", -1); sq_pushinteger(vm, Material::Render_AlphaSoftZ); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "MaterialRenderAlphaInShadow", -1); sq_pushinteger(vm, Material::Render_AlphaInShadow); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -0,0 +1,72 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "core/render_data.h"
|
||||
|
||||
using namespace GS::Render;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MaterialShaderSetUniformValue(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(shader, MaterialShader, typetag_MaterialShader)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETVECTOR(value)
|
||||
bool r = shader->SetUserUniformValue(name, value);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger MaterialShaderSetUniformTexture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(shader, MaterialShader, typetag_MaterialShader)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETSAFEPTRALLOWNULL(t, Texture, typetag_Texture)
|
||||
bool r = shader->SetUserUniformValue(name, t);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterMaterialShaderBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Material Shader
|
||||
Type: MaterialShader
|
||||
Desc: A material shader holds all the variants of a shader required to render a material.
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: MaterialShaderGeneral
|
||||
Desc: General functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MaterialShaderSetUniformValue
|
||||
Proto: bool:MaterialShader shader,String name,Vector value
|
||||
Desc: Set uniform value in a material shader.
|
||||
Note: The value is always passed as a vector of 4 floats, if the uniform type is smaller than vec4 unused entries of the vector are ignored.
|
||||
Example:
|
||||
local shader = MaterialGetShader(material)
|
||||
// u_user_param is a float.
|
||||
MaterialShaderSetUniformValue(shader, "u_user_param", Vector(1.0, 0.0, 0.0, 0.0))
|
||||
#*/
|
||||
sq_register(vm, MaterialShaderSetUniformValue, "MaterialShaderSetUniformValue", _SC(".xsx"));
|
||||
/*#
|
||||
Func: MaterialShaderSetUniformTexture
|
||||
Proto: bool:MaterialShader shader,String name,Texture texture
|
||||
Desc: Set uniform texture in a material shader.
|
||||
Example:
|
||||
local shader = MaterialGetShader(material)
|
||||
// u_user_tex is a Texture2D.
|
||||
MaterialShaderSetUniformTexture(shader, "u_user_tex", ResourceFactoryLoadTexture(g_factory, "textures/texture.png"))
|
||||
#*/
|
||||
sq_register(vm, MaterialShaderSetUniformTexture, "MaterialShaderSetUniformTexture", _SC(".xsx"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
165
include/modules/script_squirrel/legacy/matrix_binding.cpp
Normal file
165
include/modules/script_squirrel/legacy/matrix_binding.cpp
Normal file
@ -0,0 +1,165 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "math/matrix4.h"
|
||||
#include "math/matrix3.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PushMatrix4(HSQUIRRELVM vm, const Matrix4 &mtx)
|
||||
{
|
||||
push_Matrix4(vm, mtx);
|
||||
/*
|
||||
if (!CreateClassInstance(vm, "Matrix4", true))
|
||||
return sq_suspendvm(vm);
|
||||
|
||||
SetTableKey("m00", sq_pushfloat, -1, mtx.m[0][0]);
|
||||
SetTableKey("m10", sq_pushfloat, -1, mtx.m[1][0]);
|
||||
SetTableKey("m20", sq_pushfloat, -1, mtx.m[2][0]);
|
||||
SetTableKey("m30", sq_pushfloat, -1, mtx.m[3][0]);
|
||||
SetTableKey("m01", sq_pushfloat, -1, mtx.m[0][1]);
|
||||
SetTableKey("m11", sq_pushfloat, -1, mtx.m[1][1]);
|
||||
SetTableKey("m21", sq_pushfloat, -1, mtx.m[2][1]);
|
||||
SetTableKey("m31", sq_pushfloat, -1, mtx.m[3][1]);
|
||||
SetTableKey("m02", sq_pushfloat, -1, mtx.m[0][2]);
|
||||
SetTableKey("m12", sq_pushfloat, -1, mtx.m[1][2]);
|
||||
SetTableKey("m22", sq_pushfloat, -1, mtx.m[2][2]);
|
||||
SetTableKey("m32", sq_pushfloat, -1, mtx.m[3][2]);
|
||||
SetTableKey("m03", sq_pushfloat, -1, mtx.m[0][3]);
|
||||
SetTableKey("m13", sq_pushfloat, -1, mtx.m[1][3]);
|
||||
SetTableKey("m23", sq_pushfloat, -1, mtx.m[2][3]);
|
||||
SetTableKey("m33", sq_pushfloat, -1, mtx.m[3][3]);
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
SQInteger GetMatrix4(HSQUIRRELVM vm, int idx, Matrix4 &mtx)
|
||||
{
|
||||
GetTableKey("m00", sq_getfloat, idx, mtx.m[0][0]);
|
||||
GetTableKey("m10", sq_getfloat, idx, mtx.m[1][0]);
|
||||
GetTableKey("m20", sq_getfloat, idx, mtx.m[2][0]);
|
||||
GetTableKey("m30", sq_getfloat, idx, mtx.m[3][0]);
|
||||
GetTableKey("m01", sq_getfloat, idx, mtx.m[0][1]);
|
||||
GetTableKey("m11", sq_getfloat, idx, mtx.m[1][1]);
|
||||
GetTableKey("m21", sq_getfloat, idx, mtx.m[2][1]);
|
||||
GetTableKey("m31", sq_getfloat, idx, mtx.m[3][1]);
|
||||
GetTableKey("m02", sq_getfloat, idx, mtx.m[0][2]);
|
||||
GetTableKey("m12", sq_getfloat, idx, mtx.m[1][2]);
|
||||
GetTableKey("m22", sq_getfloat, idx, mtx.m[2][2]);
|
||||
GetTableKey("m32", sq_getfloat, idx, mtx.m[3][2]);
|
||||
GetTableKey("m03", sq_getfloat, idx, mtx.m[0][3]);
|
||||
GetTableKey("m13", sq_getfloat, idx, mtx.m[1][3]);
|
||||
GetTableKey("m23", sq_getfloat, idx, mtx.m[2][3]);
|
||||
GetTableKey("m33", sq_getfloat, idx, mtx.m[3][3]);
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PushMatrix3(HSQUIRRELVM vm, const Matrix3 &mtx)
|
||||
{
|
||||
push_Matrix3(vm, mtx);
|
||||
/*
|
||||
if (!CreateClassInstance(vm, "Matrix3", true))
|
||||
return sq_suspendvm(vm);
|
||||
|
||||
SetTableKey("m00", sq_pushfloat, -1, mtx.m[0][0]);
|
||||
SetTableKey("m10", sq_pushfloat, -1, mtx.m[1][0]);
|
||||
SetTableKey("m20", sq_pushfloat, -1, mtx.m[2][0]);
|
||||
SetTableKey("m01", sq_pushfloat, -1, mtx.m[0][1]);
|
||||
SetTableKey("m11", sq_pushfloat, -1, mtx.m[1][1]);
|
||||
SetTableKey("m21", sq_pushfloat, -1, mtx.m[2][1]);
|
||||
SetTableKey("m02", sq_pushfloat, -1, mtx.m[0][2]);
|
||||
SetTableKey("m12", sq_pushfloat, -1, mtx.m[1][2]);
|
||||
SetTableKey("m22", sq_pushfloat, -1, mtx.m[2][2]);
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
SQInteger GetMatrix3(HSQUIRRELVM vm, int idx, Matrix3 &mtx)
|
||||
{
|
||||
GetTableKey("m00", sq_getfloat, idx, mtx.m[0][0]);
|
||||
GetTableKey("m10", sq_getfloat, idx, mtx.m[1][0]);
|
||||
GetTableKey("m20", sq_getfloat, idx, mtx.m[2][0]);
|
||||
GetTableKey("m01", sq_getfloat, idx, mtx.m[0][1]);
|
||||
GetTableKey("m11", sq_getfloat, idx, mtx.m[1][1]);
|
||||
GetTableKey("m21", sq_getfloat, idx, mtx.m[2][1]);
|
||||
GetTableKey("m02", sq_getfloat, idx, mtx.m[0][2]);
|
||||
GetTableKey("m12", sq_getfloat, idx, mtx.m[1][2]);
|
||||
GetTableKey("m22", sq_getfloat, idx, mtx.m[2][2]);
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger RotationMatrixFromDirection(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETVECTOR(direction))
|
||||
__SQ_RETURNMATRIX3(Matrix3::FromOrthonormalBasis(direction))
|
||||
}
|
||||
SQInteger RotationMatrixFromDirectionAndUp(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETVECTOR(direction)
|
||||
__SQ_GETVECTOR(up)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNMATRIX3(Matrix3::FromOrthonormalBasis(direction, &up))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger EulerFromDirection(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETVECTOR(direction))
|
||||
__SQ_RETURNVECTOR(Matrix3::FromOrthonormalBasis(direction).AsEuler())
|
||||
}
|
||||
SQInteger EulerFromDirectionAndUp(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETVECTOR(direction)
|
||||
__SQ_GETVECTOR(up)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNVECTOR(Matrix3::FromOrthonormalBasis(direction, &up).AsEuler())
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MatrixToEuler(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETMATRIX3(matrix)
|
||||
__SQ_GETINT(rorder)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNVECTOR(matrix.AsEuler((Math::rOrder)rorder))
|
||||
}
|
||||
SQInteger TransformationMatrix(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETVECTOR(p)
|
||||
__SQ_GETVECTOR(r)
|
||||
__SQ_GETVECTOR(s)
|
||||
__SQ_GETVECTOR(t)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNMATRIX4(Matrix4::TransformationMatrix(p, r, s, &t))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterMatrixBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
using namespace GS::Script;
|
||||
|
||||
sq_register(vm, MatrixToEuler, "MatrixToEuler", _SC(".xi"));
|
||||
sq_register(vm, TransformationMatrix, "TransformationMatrix", _SC(".xxxx"));
|
||||
|
||||
sq_register(vm, RotationMatrixFromDirection, "RotationMatrixFromDirection", _SC(".x"));
|
||||
sq_register(vm, RotationMatrixFromDirectionAndUp, "RotationMatrixFromDirectionAndUp", _SC(".xx"));
|
||||
sq_register(vm, EulerFromDirection, "EulerFromDirection", _SC(".x"));
|
||||
sq_register(vm, EulerFromDirectionAndUp, "EulerFromDirectionAndUp", _SC(".xx"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
399
include/modules/script_squirrel/legacy/mixer_binding.cpp
Normal file
399
include/modules/script_squirrel/legacy/mixer_binding.cpp
Normal file
@ -0,0 +1,399 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "core/sound.h"
|
||||
#include "core/mixer.h"
|
||||
|
||||
using namespace GS::Audio;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MixerSetGain(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETFLOAT(gain)
|
||||
__SQ_GETEND
|
||||
mixer->SetMasterVolume(gain);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MixerMute(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
mixer->SetMasterVolume(0);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerUnmute(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
mixer->SetMasterVolume(1);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MixerChannelLock(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_RETURNINT(mixer->LockChannel())
|
||||
}
|
||||
SQInteger MixerChannelUnlock(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETEND
|
||||
mixer->UnlockChannel(channel);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelUnlockAll(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
mixer->UnlockAllChannels();
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelStart(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETSAFEPTR(sound, Sound, typetag_Sound)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(mixer->Start(channel, sound->mixer_data))
|
||||
}
|
||||
SQInteger MixerChannelStartStream(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETSTRING(uri)
|
||||
int r = mixer->Stream(channel, uri);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r != -1)
|
||||
}
|
||||
SQInteger MixerSoundStartFast(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETSAFEPTR(sound, Sound, typetag_Sound)
|
||||
bool r = mixer->StartFast(-1, sound->mixer_data);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger MixerSoundStart(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETSAFEPTR(sound, Sound, typetag_Sound)
|
||||
int channel = mixer->Start(-1, sound->mixer_data);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNINT(channel)
|
||||
}
|
||||
SQInteger MixerStreamStartFast(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETSTRING(uri)
|
||||
bool r = mixer->StreamFast(-1, uri);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger MixerStreamStart(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETSTRING(uri)
|
||||
int channel = mixer->Stream(-1, uri);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNINT(channel)
|
||||
}
|
||||
SQInteger MixerChannelPause(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETEND
|
||||
mixer->Pause(channel);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelResume(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETEND
|
||||
mixer->Resume(channel);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelGetState(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNINT(0)
|
||||
}
|
||||
SQInteger MixerChannelStop(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETEND
|
||||
mixer->Stop(channel);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelStopAll(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
// mixer->StopAllChannels();
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelSetGain(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETFLOAT(gain)
|
||||
__SQ_GETEND
|
||||
mixer->SetChannelVolume(channel, gain);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelSetPitch(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETFLOAT(pitch)
|
||||
__SQ_GETEND
|
||||
mixer->SetChannelPitch(channel, pitch);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelSetPanning(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETFLOAT(panning)
|
||||
__SQ_GETEND
|
||||
mixer->SetChannelPanning(channel, panning);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelSetLoopMode(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETINT(loop)
|
||||
__SQ_GETEND
|
||||
mixer->SetChannelLoopMode(channel, (IMixer::Loop)loop);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger MixerChannelSetLoopPosition(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mixer, IMixer, typetag_Mixer)
|
||||
__SQ_GETINT(channel)
|
||||
__SQ_GETINT(position)
|
||||
__SQ_GETEND
|
||||
mixer->SetChannelLoopPosition(channel, position);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterMixerBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Mixer
|
||||
Type: Mixer
|
||||
Type: Channel
|
||||
Related: Sound,ResourceFactory
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: ChannelManagement
|
||||
Desc: Channel management functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MixerChannelGetState
|
||||
Proto: ChannelState:Mixer,int channel
|
||||
Desc: Return the channel state.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelGetState, "MixerChannelGetState", _SC(".xi"));
|
||||
/*#
|
||||
Func: MixerChannelStop
|
||||
Proto: void:Mixer,int channel
|
||||
Desc: Stop playback on a given channel.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelStop, "MixerChannelStop", _SC(".xi"));
|
||||
/*#
|
||||
Func: MixerChannelPause
|
||||
Proto: void:Mixer,int channel
|
||||
Desc: Pause playback on a given channel.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelPause, "MixerChannelPause", _SC(".xi"));
|
||||
/*#
|
||||
Func: MixerChannelResume
|
||||
Proto: void:Mixer,int channel
|
||||
Desc: Resume playback on a given channel.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelResume, "MixerChannelResume", _SC(".xi"));
|
||||
/*#
|
||||
Func: MixerChannelStopAll
|
||||
Proto: void:Mixer
|
||||
Desc: Stop replay on all mixer channels.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelStopAll, "MixerChannelStopAll", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: MixerControl
|
||||
Desc: Mixer control functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MixerSetGain
|
||||
Proto: void:Mixer mixer,float gain
|
||||
Desc: Set the global mixer gain.
|
||||
#*/
|
||||
sq_register(vm, MixerSetGain, "MixerSetGain", _SC(".xn"));
|
||||
/*#
|
||||
Func: MixerPlaySoundFast
|
||||
Proto: bool:Mixer mixer,Sound sound
|
||||
Desc: Play a sound on the first channel available, this function returns immediately and the channel used for replay is not returned.
|
||||
See: ResourceFactoryLoadSound
|
||||
#*/
|
||||
sq_register(vm, MixerSoundStartFast, "MixerSoundStartFast", _SC(".xx"));
|
||||
sq_register(vm, MixerSoundStartFast, "MixerPlaySoundFast", _SC(".xx"));
|
||||
/*#
|
||||
Func: MixerPlaySound
|
||||
Proto: Channel:Mixer mixer,Sound sound
|
||||
Desc: Play a sound on the first channel available, the channel used for replay is returned. If no free channel was found -1 is returned.
|
||||
Note: Use MixerPlaySoundFast to prevent waiting for the mixer thread to return the channel used for playback if you do not need this information.
|
||||
See: MixerPlaySoundFast,ResourceFactoryLoadSound,MixerChannelPlaySound
|
||||
#*/
|
||||
sq_register(vm, MixerSoundStart, "MixerSoundStart", _SC(".xx"));
|
||||
sq_register(vm, MixerSoundStart, "MixerPlaySound", _SC(".xx"));
|
||||
/*#
|
||||
Func: MixerStartStreamFast
|
||||
Proto: bool:Mixer,uri
|
||||
Desc: Play a stream on the first channel available, this function returns immediately and the channel used for replay is not returned.
|
||||
#*/
|
||||
sq_register(vm, MixerStreamStartFast, "MixerStreamStartFast", _SC(".xs"));
|
||||
sq_register(vm, MixerStreamStartFast, "MixerStartStreamFast", _SC(".xs"));
|
||||
/*#
|
||||
Func: MixerStartStream
|
||||
Proto: Channel:Mixer,uri
|
||||
Desc: Play a stream on the first channel available, the channel used for replay is returned. If no free channel was found -1 is returned.
|
||||
Note: Use MixerStartStreamFast to prevent waiting for the mixer thread to return the channel used for playback if you do not need this information.
|
||||
See: MixerStartStreamFast,MixerChannelStartStream
|
||||
#*/
|
||||
sq_register(vm, MixerStreamStart, "MixerStreamStart", _SC(".xs"));
|
||||
sq_register(vm, MixerStreamStart, "MixerStartStream", _SC(".xs"));
|
||||
/*#
|
||||
Func: MixerMute
|
||||
Proto: void:Mixer
|
||||
Desc: Mute all sound output.
|
||||
#*/
|
||||
sq_register(vm, MixerMute, "MixerMute", _SC(".x"));
|
||||
/*#
|
||||
Func: MixerUnmute
|
||||
Proto: void:Mixer
|
||||
Desc: Unmute all sound output.
|
||||
#*/
|
||||
sq_register(vm, MixerUnmute, "MixerUnmute", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: ChannelControl
|
||||
Desc: Channel control functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MixerChannelLock
|
||||
Proto: Channel:Mixer
|
||||
Desc: Lock a new mixer channel.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelLock, "MixerChannelLock", _SC(".x"));
|
||||
/*#
|
||||
Func: MixerChannelUnlock
|
||||
Proto: void:Mixer,Channel
|
||||
Desc: Unlock channel.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelUnlock, "MixerChannelUnlock", _SC(".xi"));
|
||||
/*#
|
||||
Func: MixerChannelUnlockAll
|
||||
Proto: void:Mixer
|
||||
Desc: Unlock all channels.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelUnlockAll, "MixerChannelUnlockAll", _SC(".x"));
|
||||
/*#
|
||||
Func: MixerChannelPlaySound
|
||||
Proto: bool:Mixer,Channel,Sound
|
||||
Desc: Play a sound on a specific channel. Returns true on success, false otherwise.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelStart, "MixerChannelStart", _SC(".xix"));
|
||||
sq_register(vm, MixerChannelStart, "MixerChannelPlaySound", _SC(".xix"));
|
||||
/*#
|
||||
Func: MixerChannelStartStream
|
||||
Proto: bool:Mixer,Channel,string uri
|
||||
Desc: Play a stream on a specific channel. Returns true on success, false otherwise.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelStartStream, "MixerChannelStartStream", _SC(".xis"));
|
||||
|
||||
/*#
|
||||
Func: MixerChannelSetGain
|
||||
Proto: void:Mixer,Channel,float gain
|
||||
Desc: Set channel gain. Note: The channel gain is not reset by starting new sounds.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelSetGain, "MixerChannelSetGain", _SC(".xin"));
|
||||
/*#
|
||||
Func: MixerChannelSetPitch
|
||||
Proto: void:Mixer,Channel,float pitch
|
||||
Desc: Set channel pitch (Default: 1.0). Note: The channel pitch is not reset by starting new sounds.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelSetPitch, "MixerChannelSetPitch", _SC(".xin"));
|
||||
/*#
|
||||
Func: MixerChannelSetPanning
|
||||
Proto: void:Mixer,Channel,float panning
|
||||
Desc: Set channel panning (Default: 0.5). Note: The channel panning is not reset by starting new sounds.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelSetPanning, "MixerChannelSetPanning", _SC(".xin"));
|
||||
/*#
|
||||
Func: MixerChannelSetLoopMode
|
||||
Proto: void:Mixer,Channel,ChannelLoop loop
|
||||
Desc: Set channel loop mode.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelSetLoopMode, "MixerChannelSetLoopMode", _SC(".xii"));
|
||||
/*#
|
||||
Func: MixerChannelSetLoopPosition
|
||||
Proto: void:Mixer,Channel,int ms
|
||||
Desc: Set channel loop position in millisecond, the loop mode must be set to LoopRepeat for this setting to have any effect.
|
||||
#*/
|
||||
sq_register(vm, MixerChannelSetLoopPosition, "MixerChannelSetLoopPosition", _SC(".xii"));
|
||||
|
||||
// Push defines.
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: ChannelLoop
|
||||
Values: LoopNone,LoopRepeat
|
||||
#*/
|
||||
sq_pushstring(vm, "LoopNone", -1); sq_pushinteger(vm, IMixer::None); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "LoopRepeat", -1); sq_pushinteger(vm, IMixer::Repeat); sq_newslot(vm, -3, true);
|
||||
|
||||
/*#
|
||||
Enum: ChannelState
|
||||
Values: ChannelStateInvalid,ChannelStateStopped,ChannelStatePlaying,ChannelStatePaused
|
||||
#*/
|
||||
sq_pushstring(vm, "ChannelStateInvalid", -1); sq_pushinteger(vm, IMixer::Invalid); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelStateStopped", -1); sq_pushinteger(vm, IMixer::Stopped); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelStatePlaying", -1); sq_pushinteger(vm, IMixer::Playing); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelStatePaused", -1); sq_pushinteger(vm, IMixer::Paused); sq_newslot(vm, -3, true);
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
250
include/modules/script_squirrel/legacy/motion_binding.cpp
Normal file
250
include/modules/script_squirrel/legacy/motion_binding.cpp
Normal file
@ -0,0 +1,250 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "motion/motion.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Core;
|
||||
using namespace GS::Script;
|
||||
|
||||
/*
|
||||
#include "micropather.h"
|
||||
using namespace micropather;
|
||||
|
||||
#include "pathfinding.h"
|
||||
|
||||
MicroPather *pather;
|
||||
MapPathFinder* pathfinding_map;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger NodePathFinder_CreateNode(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETINT(id)
|
||||
__SQ_GETINT(id_child)
|
||||
__SQ_GETEND
|
||||
|
||||
pathfinding_map->AddChildToNode(id, id_child);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger NodePathFinder_AddChild(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETINT(id)
|
||||
__SQ_GETFLOAT(weight)
|
||||
__SQ_GETEND
|
||||
|
||||
pathfinding_map->CreateNode(weight, id);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger CreateMicroPather(HSQUIRRELVM vm)
|
||||
{
|
||||
pathfinding_map = new MapPathFinder();
|
||||
pather = new MicroPather(pathfinding_map, 20);
|
||||
__SQ_RETURN
|
||||
}
|
||||
*/
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MotionGetClosestPoint(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(motion, Motion, typetag_Motion)
|
||||
__SQ_GETVECTOR(p)
|
||||
__SQ_GETEND
|
||||
|
||||
Vector4 closest;
|
||||
if (motion)
|
||||
motion->GetClosestPoint(p, closest);
|
||||
__SQ_RETURNVECTOR(closest)
|
||||
}
|
||||
SQInteger MotionGetClosestTime(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(motion, Motion, typetag_Motion)
|
||||
__SQ_GETVECTOR(p)
|
||||
__SQ_GETEND
|
||||
|
||||
Vector4 closest;
|
||||
float closest_t = 0.f;
|
||||
if (motion)
|
||||
motion->GetClosestPoint(p, closest, &closest_t);
|
||||
__SQ_RETURNFLOAT(closest_t);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MotionEvaluateData(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(motion, Motion, typetag_Motion)
|
||||
__SQ_GETFLOAT(t)
|
||||
__SQ_GETEND
|
||||
GS::Variant sample;
|
||||
if (motion)
|
||||
motion->EvaluateData(Time::fromSec(t), sample);
|
||||
__SQ_RETURNSTRING(sample.s_value)
|
||||
}
|
||||
SQInteger MotionEvaluatePosition(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(motion, Motion, typetag_Motion)
|
||||
__SQ_GETFLOAT(t)
|
||||
__SQ_GETEND
|
||||
Vector4 sample(0, 0, 0);
|
||||
if (motion)
|
||||
motion->EvaluatePosition(Time::fromSec(t), sample, Curve::Repeat);
|
||||
__SQ_RETURNVECTOR(sample)
|
||||
}
|
||||
|
||||
SQInteger MotionEvaluateDirection(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(motion, Motion, typetag_Motion)
|
||||
__SQ_GETFLOAT(t)
|
||||
__SQ_GETEND
|
||||
Vector4 sample(0, 0, 0);
|
||||
if (motion)
|
||||
motion->EvaluateDirection(Time::fromSec(t), sample, Curve::Repeat);
|
||||
__SQ_RETURNVECTOR(sample)
|
||||
}
|
||||
|
||||
|
||||
SQInteger MotionEvaluatePositionConstant(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(motion, Motion, typetag_Motion)
|
||||
__SQ_GETFLOAT(t)
|
||||
__SQ_GETEND
|
||||
Vector4 sample(0, 0, 0);
|
||||
if (motion)
|
||||
motion->EvaluatePosition(Time::fromSec(t), sample, Curve::Constant);
|
||||
__SQ_RETURNVECTOR(sample)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger MotionGetName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Motion, typetag_Motion)
|
||||
__SQ_RETURNSTRING(m->name)
|
||||
}
|
||||
SQInteger MotionGetLength(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(m, Motion, typetag_Motion)
|
||||
__SQ_RETURNFLOAT(m->GetDuration().toSec())
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterMotionBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Motion
|
||||
Type: Motion
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: Motion
|
||||
Desc: Motion functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MotionGetClosestPoint
|
||||
Proto: float:Motion,Vector
|
||||
Desc: Return the nearest point on this motion for the position given
|
||||
#*/
|
||||
sq_register(vm, MotionGetClosestPoint, "MotionGetClosestPoint", _SC(".xx"));
|
||||
/*#
|
||||
Func: MotionGetClosestTime
|
||||
Proto: float:Motion,Vector
|
||||
Desc: Return the time for the nearest position.
|
||||
#*/
|
||||
sq_register(vm, MotionGetClosestTime, "MotionGetClosestTime", _SC(".xx"));
|
||||
/*#
|
||||
Func: MotionGetName
|
||||
Proto: String:Motion
|
||||
Desc: Return motion name.
|
||||
#*/
|
||||
sq_register(vm, MotionGetName, "MotionGetName", _SC(".x"));
|
||||
/*#
|
||||
Func: MotionEvaluateData
|
||||
Proto: String:Motion,float time
|
||||
Desc: Evaluate the data in motion at the specified time.
|
||||
#*/
|
||||
sq_register(vm, MotionEvaluateData, "MotionEvaluateData", _SC(".xn"));
|
||||
/*#
|
||||
Func: MotionEvaluatePosition
|
||||
Proto: Vector:Motion,float time
|
||||
Desc: Evaluate position triplet (x, y, z) in motion at the specified time. Note that a motion may not have all or any of the channels required for this evaluation.
|
||||
#*/
|
||||
sq_register(vm, MotionEvaluatePosition, "MotionEvaluatePosition", _SC(".xn"));
|
||||
sq_register(vm, MotionEvaluateDirection, "MotionEvaluateDirection", _SC(".xn"));
|
||||
/*#
|
||||
Func: MotionEvaluatePositionConstant
|
||||
Proto: Vector:Motion,float time
|
||||
Desc: IT'S CLAMPED TO THE BEGINING AND END. Evaluate position triplet (x, y, z) in motion at the specified time. Note that a motion may not have all or any of the channels required for this evaluation.
|
||||
#*/
|
||||
sq_register(vm, MotionEvaluatePositionConstant, "MotionEvaluatePositionConstant", _SC(".xn"));
|
||||
|
||||
/*#
|
||||
Func: MotionGetLength
|
||||
Proto: float:Motion
|
||||
Desc: Return highest timecode in motion.
|
||||
#*/
|
||||
sq_register(vm, MotionGetLength, "MotionGetLength", _SC(".x"));
|
||||
|
||||
// Push defines.
|
||||
sq_pushroottable(vm);
|
||||
|
||||
sq_pushstring(vm, "ChannelNone", -1); sq_pushinteger(vm, MotionChannel::NoType); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelXPos", -1); sq_pushinteger(vm, MotionChannel::XPos); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelYPos", -1); sq_pushinteger(vm, MotionChannel::YPos); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelZPos", -1); sq_pushinteger(vm, MotionChannel::ZPos); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelXRot", -1); sq_pushinteger(vm, MotionChannel::XRot); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelYRot", -1); sq_pushinteger(vm, MotionChannel::YRot); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelZRot", -1); sq_pushinteger(vm, MotionChannel::ZRot); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelXScl", -1); sq_pushinteger(vm, MotionChannel::XScl); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelYScl", -1); sq_pushinteger(vm, MotionChannel::YScl); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelZScl", -1); sq_pushinteger(vm, MotionChannel::ZScl); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelXPiv", -1); sq_pushinteger(vm, MotionChannel::XPiv); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelYPiv", -1); sq_pushinteger(vm, MotionChannel::YPiv); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelZPiv", -1); sq_pushinteger(vm, MotionChannel::ZPiv); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelRDif", -1); sq_pushinteger(vm, MotionChannel::RDif); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelGDif", -1); sq_pushinteger(vm, MotionChannel::GDif); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelBDif", -1); sq_pushinteger(vm, MotionChannel::BDif); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelRSpc", -1); sq_pushinteger(vm, MotionChannel::RSpc); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelGSpc", -1); sq_pushinteger(vm, MotionChannel::GSpc); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelBSpc", -1); sq_pushinteger(vm, MotionChannel::BSpc); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelDiffuseIntensity", -1); sq_pushinteger(vm, MotionChannel::DiffuseIntensity); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelSpecularIntensity", -1); sq_pushinteger(vm, MotionChannel::SpecularIntensity); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelConeAngle", -1); sq_pushinteger(vm, MotionChannel::ConeAngle); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelEdgeAngle", -1); sq_pushinteger(vm, MotionChannel::EdgeAngle); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelAlpha", -1); sq_pushinteger(vm, MotionChannel::Alpha); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelZoomFactor", -1); sq_pushinteger(vm, MotionChannel::ZoomFactor); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelRange", -1); sq_pushinteger(vm, MotionChannel::Range); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "ChannelFogStart", -1); sq_pushinteger(vm, MotionChannel::FogStart); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelFogEnd", -1); sq_pushinteger(vm, MotionChannel::FogEnd); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelRFog", -1); sq_pushinteger(vm, MotionChannel::RFog); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelGFog", -1); sq_pushinteger(vm, MotionChannel::GFog); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ChannelBFog", -1); sq_pushinteger(vm, MotionChannel::BFog); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
502
include/modules/script_squirrel/legacy/nml_binding.cpp
Normal file
502
include/modules/script_squirrel/legacy/nml_binding.cpp
Normal file
@ -0,0 +1,502 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "metafile/nml.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::NML;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger MetafileGetRoots(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(metafile, File, typetag_Metafile)
|
||||
|
||||
sq_newarray(vm, 0);
|
||||
if (metafile)
|
||||
{
|
||||
NMLFileForeach(tag, *metafile)
|
||||
{
|
||||
CObject::Push(vm, tag, typetag_Metatag, false);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
SQInteger MetatagGetChildren(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(metatag, Tag, typetag_Metatag)
|
||||
|
||||
sq_newarray(vm, 0);
|
||||
if (metatag)
|
||||
{
|
||||
NMLTagForeach(tag, *metatag)
|
||||
{
|
||||
CObject::Push(vm, tag, typetag_Metatag, false);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
SQInteger MetafileNew(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNMANAGEDSAFEPTR(new File, typetag_Metafile) }
|
||||
SQInteger MetafileDelete(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURN }
|
||||
|
||||
SQInteger MetafileLoadFromString(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mf, File, typetag_Metafile)
|
||||
__SQ_GETSTRING(file)
|
||||
bool success = Parser::LoadFromMemory((char *)file, String::strlen(file), *mf);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(success)
|
||||
}
|
||||
SQInteger MetafileLoad(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mf, File, typetag_Metafile)
|
||||
__SQ_GETSTRING(uri)
|
||||
bool success = Parser::Load(uri, *mf); // take care of the string
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(success)
|
||||
}
|
||||
SQInteger MetafileSave(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mf, File, typetag_Metafile)
|
||||
__SQ_GETSTRING(uri)
|
||||
bool success = Parser::Save(uri, *mf);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(success)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
static Tag *CreateMetatagFromSquirrelStackEntry(HSQUIRRELVM vm, int idx, const char *path)
|
||||
{
|
||||
Tag *tag = NULL;
|
||||
switch (sq_gettype(vm, idx))
|
||||
{
|
||||
case OT_NULL:
|
||||
tag = new Tag(path);
|
||||
break;
|
||||
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger value;
|
||||
sq_getinteger(vm, idx, &value);
|
||||
tag = new Tag(path, (int)value);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_FLOAT:
|
||||
{
|
||||
float value;
|
||||
sq_getfloat(vm, idx, &value);
|
||||
tag = new Tag(path, value);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool value;
|
||||
sq_getbool(vm, idx, &value);
|
||||
tag = new Tag(path, value ? true : false);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_STRING:
|
||||
{
|
||||
const char *value;
|
||||
sq_getstring(vm, idx, &value);
|
||||
tag = new Tag(path, value);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_TABLE:
|
||||
case OT_ARRAY:
|
||||
default:
|
||||
__LOG_E__ << "Cannot convert input Squirrel type to metatag value.\n";
|
||||
break;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger MetafileAddRoot(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mf, File, typetag_Metafile)
|
||||
__SQ_GETSTRING(path)
|
||||
Tag *tag = new Tag(path);
|
||||
if (!tag)
|
||||
return sq_throwerror(vm, "Failed to allocate metatag.");
|
||||
mf->AddRoot(tag);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
SQInteger MetatagAddChild(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(itg, Tag, typetag_Metatag)
|
||||
__SQ_GETSTRING(path)
|
||||
Tag *tag = new Tag(path);
|
||||
if (!tag)
|
||||
return sq_throwerror(vm, "Failed to allocate metatag.");
|
||||
itg->AddChild(tag);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
SQInteger MetatagDeleteChild(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(tag, Tag, typetag_Metatag)
|
||||
__SQ_GETSAFEPTR(child, Tag, typetag_Metatag)
|
||||
__SQ_GETEND
|
||||
|
||||
if (!tag->RemoveTag(child))
|
||||
return sq_throwerror(vm, "Child tag does not belong to this tag.");
|
||||
|
||||
__SQ_INVALIDATENATIVEREF(child);
|
||||
_safe_delete(child); // tags are not managed
|
||||
__SQ_RETURN
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger MetafileAddRootWithValue(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mf, File, typetag_Metafile)
|
||||
__SQ_GETSTRING(path)
|
||||
Tag *tag = CreateMetatagFromSquirrelStackEntry(vm, __SQ_STACKPOS, path);
|
||||
__SQ_GETUPDATESTACK
|
||||
__SQ_GETEND
|
||||
if (!tag)
|
||||
return sq_throwerror(vm, "Failed to add root tag to metafile.");
|
||||
mf->AddRoot(tag);
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
SQInteger MetatagAddChildWithValue(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(itg, Tag, typetag_Metatag)
|
||||
__SQ_GETSTRING(path)
|
||||
Tag *tag = CreateMetatagFromSquirrelStackEntry(vm, __SQ_STACKPOS, path);
|
||||
__SQ_GETUPDATESTACK
|
||||
__SQ_GETEND
|
||||
if (!tag)
|
||||
return sq_throwerror(vm, "Failed to add child tag.");
|
||||
itg->AddChild(tag);
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger MetafileGetTag(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mf, File, typetag_Metafile)
|
||||
__SQ_GETSTRING(path)
|
||||
Tag *tag = mf->GetTag(path);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
SQInteger MetafileGetTypedTag(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mf, File, typetag_Metafile)
|
||||
__SQ_GETSTRING(path)
|
||||
__SQ_GETINT(type)
|
||||
Tag *tag = mf->GetTypedTag(path, (GS::Variant::Type)type);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
SQInteger MetatagGetTag(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mf, Tag, typetag_Metatag)
|
||||
__SQ_GETSTRING(path)
|
||||
Tag *tag = mf->GetTag(path);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
SQInteger MetatagGetTypedTag(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mf, Tag, typetag_Metatag)
|
||||
__SQ_GETSTRING(path)
|
||||
__SQ_GETINT(type)
|
||||
Tag *tag = mf->GetTypedTag(path, (GS::Variant::Type)type);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(tag, typetag_Metatag)
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger MetatagGetType(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(tag, Tag, typetag_Metatag)
|
||||
__SQ_RETURNINT((int)tag->GetValue().GetType())
|
||||
}
|
||||
SQInteger MetatagGetName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(tag, Tag, typetag_Metatag)
|
||||
__SQ_RETURNSTRING(tag->name.c_str())
|
||||
}
|
||||
SQInteger MetatagSetName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(tag, Tag, typetag_Metatag)
|
||||
__SQ_GETSTRING(_name)
|
||||
tag->name = _name;
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger MetatagGetValue(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(tag, Tag, typetag_Metatag)
|
||||
|
||||
switch (tag->GetValue().GetType())
|
||||
{
|
||||
default:
|
||||
case GS::Variant::VariantNone:
|
||||
case GS::Variant::VariantBinary:
|
||||
break;
|
||||
|
||||
case GS::Variant::VariantBool:
|
||||
__SQ_RETURNBOOL(tag->GetBool())
|
||||
case GS::Variant::VariantInteger:
|
||||
__SQ_RETURNINT(tag->GetInteger())
|
||||
case GS::Variant::VariantFloat:
|
||||
__SQ_RETURNFLOAT(tag->GetReal())
|
||||
case GS::Variant::VariantString:
|
||||
__SQ_RETURNSTRING(tag->GetString())
|
||||
}
|
||||
|
||||
__LOG_E__ << "Cannot get value from tag '" << tag->name << "'. Unsupported type.\n";
|
||||
__SQ_RETURNINT(-1)
|
||||
}
|
||||
SQInteger MetatagSetValue(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(tag, Tag, typetag_Metatag)
|
||||
|
||||
switch (sq_gettype(vm, -1))
|
||||
{
|
||||
case OT_INTEGER:
|
||||
{
|
||||
__SQ_GETINT(value)
|
||||
tag->SetInteger(value);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_FLOAT:
|
||||
{
|
||||
__SQ_GETFLOAT(value)
|
||||
tag->SetReal(value);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_BOOL:
|
||||
{
|
||||
__SQ_GETBOOL(value)
|
||||
tag->SetBool(value ? true : false);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_STRING:
|
||||
{
|
||||
__SQ_GETSTRING(value)
|
||||
tag->SetString(value);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_NULL:
|
||||
case OT_TABLE:
|
||||
case OT_ARRAY:
|
||||
default:
|
||||
return sq_throwerror(vm, "Type cannot be converted to metatag value.");
|
||||
}
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void RegisterNMLBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Metafile
|
||||
Type: Metafile
|
||||
Type: Metatag
|
||||
Desc: A metafile is very similar to an XML file, it is mostly used to store data in a structured way.
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: MetaFile
|
||||
Desc: File functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MetafileNew
|
||||
Proto: Metafile:
|
||||
Desc: Create a new metafile, this object is managed, the VM will free it.
|
||||
#*/
|
||||
sq_register(vm, MetafileNew, "MetafileNew", _SC("."));
|
||||
// Obsolete
|
||||
sq_register(vm, MetafileDelete, "MetafileDelete", _SC(".x"));
|
||||
/*#
|
||||
Func: MetafileLoadFromString
|
||||
Proto: bool:Metafile,string content
|
||||
Desc: Load metafile from a string.
|
||||
#*/
|
||||
sq_register(vm, MetafileLoadFromString, "MetafileLoadFromString", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetafileLoad
|
||||
Proto: bool:Metafile,string path
|
||||
Desc: Load metafile from file system.
|
||||
#*/
|
||||
sq_register(vm, MetafileLoad, "MetafileLoad", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetafileSave
|
||||
Proto: bool:Metafile,string path
|
||||
Desc: Save metafile to file system.
|
||||
#*/
|
||||
sq_register(vm, MetafileSave, "MetafileSave", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetafileAddRoot
|
||||
Proto: Metatag:Metafile,string tag_name
|
||||
Desc: Add metafile root, returns the newly created metatag.
|
||||
#*/
|
||||
sq_register(vm, MetafileAddRoot, "MetafileAddRoot", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetafileAddRootWithValue
|
||||
Proto: Metatag:Metafile,string tag_name,...
|
||||
Desc: Add metafile root, returns the newly created metatag.
|
||||
#*/
|
||||
sq_register(vm, MetafileAddRootWithValue, "MetafileAddRootWithValue", _SC(".xs."));
|
||||
/*#
|
||||
Func: MetafileGetRoots
|
||||
Proto: array:Metafile
|
||||
Desc: Return all root tags of a metafile in an array.
|
||||
#*/
|
||||
sq_register(vm, MetafileGetRoots, "MetafileGetRoots", _SC(".x"));
|
||||
/*#
|
||||
Func: MetafileGetTag
|
||||
Proto: Metatag:Metafile,string tag_path
|
||||
Desc: Get metatag from metafile, the metatag path is formatted as follow: tag:child:tag_id; (eg: 'Pref:Sound:Volume;').
|
||||
#*/
|
||||
sq_register(vm, MetafileGetTag, "MetafileGetTag", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetafileGetTypedTag
|
||||
Proto: Metatag:Metafile,string tag_path,TagType
|
||||
Desc: Get metatag of a specific value type from a metafile.
|
||||
#*/
|
||||
sq_register(vm, MetafileGetTypedTag, "MetafileGetTypedTag", _SC(".xsi"));
|
||||
|
||||
/*#
|
||||
Section: MetaTag
|
||||
Desc: Tag functions
|
||||
#*/
|
||||
/*#
|
||||
Func: MetatagGetName
|
||||
Proto: string:Metatag
|
||||
Desc: Get metatag name.
|
||||
#*/
|
||||
sq_register(vm, MetatagGetName, "MetatagGetName", _SC(".x"));
|
||||
/*#
|
||||
Func: MetatagSetName
|
||||
Proto: void:Metatag,String
|
||||
Desc: Set metatag name.
|
||||
#*/
|
||||
sq_register(vm, MetatagSetName, "MetatagSetName", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetatagGetType
|
||||
Proto: TagType:Metatag
|
||||
Desc: Get metatag type.
|
||||
#*/
|
||||
sq_register(vm, MetatagGetType, "MetatagGetType", _SC(".x"));
|
||||
/*#
|
||||
Func: MetatagGetValue
|
||||
Proto: ...:Metatag
|
||||
Desc: Get metatag value.
|
||||
#*/
|
||||
sq_register(vm, MetatagGetValue, "MetatagGetValue", _SC(".x"));
|
||||
/*#
|
||||
Func: MetatagSetValue
|
||||
Proto: void:Metatag,...
|
||||
Desc: Set metatag value, the value type is automatically handled.
|
||||
#*/
|
||||
sq_register(vm, MetatagSetValue, "MetatagSetValue", _SC(".x."));
|
||||
|
||||
/*#
|
||||
Func: MetatagDeleteChild
|
||||
Proto: void:Metatag tag, Metatag child
|
||||
Desc: Delete a metatag child tag.
|
||||
Note: The removed child tag is freed and all existing script references to it are invalidated.
|
||||
#*/
|
||||
sq_register(vm, MetatagDeleteChild, "MetatagDeleteChild", _SC(".xx"));
|
||||
/*#
|
||||
Func: MetatagAddChild
|
||||
Proto: Metatag:Metatag,string tag_name
|
||||
Desc: Add metatag child, returns the newly created metatag.
|
||||
#*/
|
||||
sq_register(vm, MetatagAddChild, "MetatagAddChild", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetatagAddChildWithValue
|
||||
Proto: Metatag:Metatag,string tag_name,...
|
||||
Desc: Add metatag child, returns the newly created metatag.
|
||||
#*/
|
||||
sq_register(vm, MetatagAddChildWithValue, "MetatagAddChildWithValue", _SC(".xs."));
|
||||
|
||||
/*#
|
||||
Func: MetatagGetTag
|
||||
Proto: Metatag:Metatag,string tag_path
|
||||
Desc: Find metatag child.
|
||||
#*/
|
||||
sq_register(vm, MetatagGetTag, "MetatagGetTag", _SC(".xs"));
|
||||
/*#
|
||||
Func: MetatagGetTypedTag
|
||||
Proto: Metatag:Metatag,string tag_path,TagType
|
||||
Desc: Find child of a specific value type from a metatag.
|
||||
#*/
|
||||
sq_register(vm, MetatagGetTypedTag, "MetatagGetTypedTag", _SC(".xsi"));
|
||||
/*#
|
||||
Func: MetatagGetChildren
|
||||
Proto: Array:Metatag
|
||||
Desc: Return all children of a metatag in an array.
|
||||
#*/
|
||||
sq_register(vm, MetatagGetChildren, "MetatagGetChildren", _SC(".x"));
|
||||
|
||||
// Push defines.
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: TagType
|
||||
Values: TagTypeBinary,TagTypeString,TagTypeInteger,TagTypeReal,TagTypeNode,TagTypeNone
|
||||
#*/
|
||||
sq_pushstring(vm, "TagTypeBinary", -1); sq_pushinteger(vm, GS::Variant::VariantBinary); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "TagTypeInteger", -1); sq_pushinteger(vm, GS::Variant::VariantInteger); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "TagTypeNone", -1); sq_pushinteger(vm, GS::Variant::VariantNone); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "TagTypeReal", -1); sq_pushinteger(vm, GS::Variant::VariantFloat); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "TagTypeString", -1); sq_pushinteger(vm, GS::Variant::VariantString); sq_newslot(vm, -3, true);
|
||||
#if 1
|
||||
sq_pushstring(vm, "TagTypeNode", -1); sq_pushinteger(vm, GS::Variant::VariantNone); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "TagTypeTag", -1); sq_pushinteger(vm, GS::Variant::VariantNone); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "TagTypeShortcut", -1); sq_pushinteger(vm, GS::Variant::VariantNone); sq_newslot(vm, -3, true);
|
||||
#endif
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
217
include/modules/script_squirrel/legacy/object_binding.cpp
Normal file
217
include/modules/script_squirrel/legacy/object_binding.cpp
Normal file
@ -0,0 +1,217 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/legacy/binding_helpers.h"
|
||||
#include "scene3d/mobject.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
static CObjectType object_derived_types[] = { typetag_Item, typetag_Object, typetag_Undefined };
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ObjectGetLODBias(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_RETURNFLOAT(GS::Core::Object::lod_bias)
|
||||
}
|
||||
SQInteger ObjectSetLODBias(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETFLOAT(bias))
|
||||
GS::Core::Object::lod_bias = bias;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------
|
||||
SQInteger ObjectGetItem(HSQUIRRELVM vm)
|
||||
//-----------------------------------------------
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(obj, MObject, typetag_Object)
|
||||
__SQ_RETURNSAFEPTR((MItem *)obj, typetag_Item)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define __SQ_ASSERTRENDERDATA(__I__) if (__I__->render_data.IsNull()) return sq_throwerror(vm, "No render data, have you setup this item render data?");
|
||||
|
||||
SQInteger ObjectSetGeometry(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(o, MObject, object_derived_types)
|
||||
__SQ_GETSAFEPTRALLOWNULL(geo, GS::Render::Geometry, typetag_Geometry)
|
||||
__SQ_GETEND
|
||||
__SQ_ASSERTRENDERDATA(o)
|
||||
o->geometry = geo ? geo->name : NULL;
|
||||
o->render_data->geometry = geo;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ObjectGetGeometry(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(o, MObject, object_derived_types))
|
||||
__SQ_ASSERTRENDERDATA(o)
|
||||
__SQ_RETURNSAFEPTR(o->render_data->geometry.c_ptr(), typetag_Geometry)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ObjectSkinGetItemCount(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(o, MObject, object_derived_types))
|
||||
__SQ_RETURNINT(o->GetBoneCount())
|
||||
}
|
||||
SQInteger ObjectSkinGetItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(o, MObject, object_derived_types)
|
||||
__SQ_GETINT(n)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(o->GetBone(n) ? o->GetBone(n)->mitem : NULL, typetag_Item)
|
||||
}
|
||||
SQInteger ObjectSkinSetItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETCOBJECTBASE(o, MObject, object_derived_types)
|
||||
__SQ_GETINT(n)
|
||||
__SQ_GETSAFEPTRALLOWNULL(b, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
o->BindBone(n, b ? b->GetBaseItem() : NULL);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ObjectSetSkinMotion(HSQUIRRELVM vm)
|
||||
{
|
||||
/*
|
||||
__SQ_GETSTART(6)
|
||||
__SQ_GETSAFEPTR(obj, MObject, typetag_Object)
|
||||
__SQ_GETSTRING(motion_id)
|
||||
__SQ_GETFLOAT(blend)
|
||||
__SQ_GETFLOAT(weight)
|
||||
__SQ_GETFLOAT(t)
|
||||
__SQ_GETBOOL(loop)
|
||||
nHierarchyMotion *mot = (nHierarchyMotion *)obj->skin_motion_list.Find(motion_id);
|
||||
if (obj && mot)
|
||||
SetHierarchyMotion(obj->GetSkin(), mot, blend, weight, t, loop ? true : false);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
*/
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(o, MObject, object_derived_types)
|
||||
__SQ_GETSTRING(motion_name)
|
||||
|
||||
// obj->SetSkinMotion(motion_name);
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ObjectSetSkinMotionClockScale(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETCOBJECTBASE(o, MObject, object_derived_types)
|
||||
__SQ_GETFLOAT(scale)
|
||||
__SQ_GETEND
|
||||
return 0;
|
||||
}
|
||||
SQInteger ObjectStopAllSkinMotion(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(o, MObject, object_derived_types))
|
||||
// if (obj)
|
||||
// StopAllHierarchyMotion(obj->GetSkin());
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterObjectBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Object
|
||||
Type: Object
|
||||
Related: Item
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: ObjectGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ObjectGetItem
|
||||
Proto: Item:Object
|
||||
Desc: Get object item.
|
||||
#*/
|
||||
sq_register(vm, ObjectGetItem, "ObjectGetItem", _SC(".x"));
|
||||
/*#
|
||||
Func: ObjectSetGeometry
|
||||
Proto: void:Object,Geometry
|
||||
Desc: Set object geometry.
|
||||
#*/
|
||||
sq_register(vm, ObjectSetGeometry, "ObjectSetGeometry", _SC(".xx"));
|
||||
/*#
|
||||
Func: ObjectGetGeometry
|
||||
Proto: Geometry:Object
|
||||
Desc: Get geometry object.
|
||||
#*/
|
||||
sq_register(vm, ObjectGetGeometry, "ObjectGetGeometry", _SC(".x"));
|
||||
/*#
|
||||
Func: ObjectGetLODBias
|
||||
Proto: float:
|
||||
Desc: Get global object geometry lod bias.
|
||||
Note: This value is added to the distance used to select the lod level for a geometry before displaying it.
|
||||
#*/
|
||||
sq_register(vm, ObjectGetLODBias, "ObjectGetLODBias", _SC("."));
|
||||
/*#
|
||||
Func: ObjectSetLODBias
|
||||
Proto: void:float bias
|
||||
Desc: Set global object geometry lod bias.
|
||||
Note: This value is added to the distance used to select the lod level for a geometry before displaying it.
|
||||
Example: ObjectSetLODBias(Mtr(10.0)) // Push all geometry LODs back by 10 meters.
|
||||
#*/
|
||||
sq_register(vm, ObjectSetLODBias, "ObjectSetLODBias", _SC(".n"));
|
||||
|
||||
/*#
|
||||
Section: ObjectSkin
|
||||
Desc: Skin functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ObjectSkinGetItemCount
|
||||
Proto: int:Object
|
||||
Desc: Return the number of bone items in the object skin.
|
||||
#*/
|
||||
sq_register(vm, ObjectSkinGetItemCount, "ObjectSkinGetItemCount", _SC(".x"));
|
||||
/*#
|
||||
Func: ObjectSkinGetItem
|
||||
Proto: Item:Object,int index
|
||||
Desc: Return a bone item from the object skin.
|
||||
#*/
|
||||
sq_register(vm, ObjectSkinGetItem, "ObjectSkinGetItem", _SC(".xi"));
|
||||
/*#
|
||||
Func: ObjectSkinSetItem
|
||||
Proto: void:Object,int index,Item bone
|
||||
Desc: Set a bone item in the object skin.
|
||||
#*/
|
||||
sq_register(vm, ObjectSkinSetItem, "ObjectSkinSetItem", _SC(".xix"));
|
||||
|
||||
/*#
|
||||
Func: ObjectSetSkinMotion
|
||||
Proto: void:Object,string name
|
||||
Desc: Set object skin motion.
|
||||
#*/
|
||||
sq_register(vm, ObjectSetSkinMotion, "ObjectSetSkinMotion", _SC(".xs"));
|
||||
/*#
|
||||
Func: ObjectSetSkinMotionClockScale
|
||||
Proto: void:Object,float scale
|
||||
Desc: Set current object skin motion clock scale.
|
||||
#*/
|
||||
sq_register(vm, ObjectSetSkinMotionClockScale, "ObjectSetSkinMotionClockScale", _SC(".xf"));
|
||||
/*#
|
||||
Func: ObjectStopAllSkinMotion
|
||||
Proto: void:Object
|
||||
Desc: Stop all object skin motions.
|
||||
#*/
|
||||
sq_register(vm, ObjectStopAllSkinMotion, "ObjectStopAllSkinMotion", _SC(".x"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
222
include/modules/script_squirrel/legacy/peer_network_binding.cpp
Normal file
222
include/modules/script_squirrel/legacy/peer_network_binding.cpp
Normal file
@ -0,0 +1,222 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "squirrel_binding.h"
|
||||
#include "script/script_variant.h"
|
||||
#include "async/async_call_queue_thread.h"
|
||||
#include "binding_helpers.h"
|
||||
#include "sqstdblob.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
#if __PLATFORM_EMSCRIPTEN__ == 0
|
||||
|
||||
#include "network_enet/enet_network.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
struct ScriptPeerThread : public Network::Enet, public Threading::ASyncCallQueueThread
|
||||
{
|
||||
void OnIdle()
|
||||
{ UpdateHost(); }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
struct VMThreadData
|
||||
{
|
||||
SquirrelVM *vm;
|
||||
|
||||
void OnPeerConnection(void *peer)
|
||||
{
|
||||
if (peer && vm->SetupFunctionCall("OnPeerConnection"))
|
||||
{
|
||||
vm->PushVariant(Script::Variant(peer, typetag_Peer));
|
||||
vm->DoFunctionCall();
|
||||
}
|
||||
}
|
||||
void OnPacketReceived(void *peer, const Array <char> &packet)
|
||||
{
|
||||
if (peer && vm->SetupFunctionCall("OnPacketReceived"))
|
||||
{
|
||||
vm->PushVariant(Script::Variant(peer, typetag_Peer));
|
||||
vm->PushVariant(Script::Variant((const void *)packet.c_ptr(), packet.GetSize()));
|
||||
vm->DoFunctionCall();
|
||||
}
|
||||
}
|
||||
void OnConnectionClosed(void *peer)
|
||||
{
|
||||
if (peer && vm->SetupFunctionCall("OnConnectionClosed"))
|
||||
{
|
||||
vm->PushVariant(Script::Variant(peer, typetag_Peer));
|
||||
vm->DoFunctionCall();
|
||||
}
|
||||
}
|
||||
|
||||
// To be executed from the VM thread.
|
||||
ASync::CallQueue task_queue;
|
||||
|
||||
VMThreadData(SquirrelVM *v) : vm(v) {}
|
||||
};
|
||||
|
||||
VMThreadData vm_thread;
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void OnPeerConnection(void *peer)
|
||||
{ vm_thread.task_queue.QueueMemberCall(&vm_thread, &VMThreadData::OnPeerConnection, peer); }
|
||||
void OnPacketReceived(void *peer, const void *data, size_t size)
|
||||
{ vm_thread.task_queue.QueueMemberCall(&vm_thread, &VMThreadData::OnPacketReceived, peer, Array <char> (size, (const char *)data)); }
|
||||
void OnConnectionClosed(void *peer)
|
||||
{ vm_thread.task_queue.QueueMemberCall(&vm_thread, &VMThreadData::OnConnectionClosed, peer); }
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
ScriptPeerThread(SquirrelVM *v) : vm_thread(v) {}
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PeerNetOpenServer(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSTRING(ip)
|
||||
__SQ_GETINT(port)
|
||||
__SQ_GETEND
|
||||
|
||||
ScriptPeerThread *t = new ScriptPeerThread(GetVMObject(vm));
|
||||
if (t == NULL)
|
||||
return sq_throwerror(vm, "Failed to allocate peer network controller.");
|
||||
|
||||
t->Start();
|
||||
t->QueueMemberCall(t, &ScriptPeerThread::OpenServer, String(ip), port);
|
||||
|
||||
__SQ_RETURNMANAGEDSAFEPTR(t, typetag_PeerController)
|
||||
}
|
||||
SQInteger PeerNetOpenClient(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSTRING(ip)
|
||||
__SQ_GETINT(port)
|
||||
__SQ_GETEND
|
||||
|
||||
ScriptPeerThread *t = new ScriptPeerThread(GetVMObject(vm));
|
||||
if (t == NULL)
|
||||
return sq_throwerror(vm, "Failed to allocate peer network controller.");
|
||||
|
||||
t->Start();
|
||||
t->QueueMemberCall(t, &ScriptPeerThread::OpenClient, String(ip), port);
|
||||
|
||||
__SQ_RETURNMANAGEDSAFEPTR(t, typetag_PeerController)
|
||||
}
|
||||
SQInteger PeerNetUpdate(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(t, ScriptPeerThread, typetag_PeerController)
|
||||
t->vm_thread.task_queue.ExecuteAll();
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PeerNetSendString(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(t, ScriptPeerThread, typetag_PeerController)
|
||||
__SQ_GETSAFEPTR(peer, ENetPeer *, typetag_Peer)
|
||||
__SQ_GETSTRING(data)
|
||||
__SQ_GETEND
|
||||
t->QueueMemberCall(t, &ScriptPeerThread::SendString, peer, String(data));
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PeerNetBroadcastString(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(t, ScriptPeerThread, typetag_PeerController)
|
||||
__SQ_GETSTRING(data)
|
||||
__SQ_GETEND
|
||||
t->QueueMemberCall(t, &ScriptPeerThread::BroadcastString, String(data));
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#else
|
||||
|
||||
SQInteger PeerNetOpenServer(HSQUIRRELVM vm)
|
||||
{ return 0; }
|
||||
SQInteger PeerNetOpenClient(HSQUIRRELVM vm)
|
||||
{ return 0; }
|
||||
SQInteger PeerNetUpdate(HSQUIRRELVM vm)
|
||||
{ return 0; }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PeerNetSendString(HSQUIRRELVM vm)
|
||||
{ return 0; }
|
||||
SQInteger PeerNetBroadcastString(HSQUIRRELVM vm)
|
||||
{ return 0; }
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterINetBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Peer Network
|
||||
Desc: Implement a peer-to-peer network.
|
||||
Type: PeerController
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: PeerNetHandshake
|
||||
Desc: Handshaking
|
||||
#*/
|
||||
/*#
|
||||
Func: PeerNetOpenServer
|
||||
Proto: PeerController:String ip,int port
|
||||
Desc: Open a listening server connection on a given ip address and port.
|
||||
Note: A server connection is usually opened on the local host ip "127.0.0.1".
|
||||
Example:
|
||||
// Start a peer server on the local host on port 8000.
|
||||
PeerNetOpenServer("127.0.0.1", 8000)
|
||||
#*/
|
||||
sq_register(vm, PeerNetOpenServer, "PeerNetOpenServer", _SC(".si"));
|
||||
/*#
|
||||
Func: PeerNetOpenClient
|
||||
Proto: PeerController:String ip,int port
|
||||
Desc: Open a client connection to a given ip address and port.
|
||||
Example:
|
||||
// Connect client to peer server on the remote address 192.168.0.12 on port 8000.
|
||||
PeerNetOpenClient("192.168.0.12", 8000)
|
||||
#*/
|
||||
sq_register(vm, PeerNetOpenClient, "PeerNetOpenClient", _SC(".ss"));
|
||||
/*#
|
||||
Section: PeerNetCommunication
|
||||
Desc: Communication
|
||||
#*/
|
||||
/*#
|
||||
Func: PeerNetSendString
|
||||
Proto: void:PeerController controller,Peer peer,String data
|
||||
Desc: Send a string to a specific peer controller.
|
||||
Example:
|
||||
// Send the HELLO string to a specific peer.
|
||||
PeerNetSendString(controller, peer, "HELLO")
|
||||
#*/
|
||||
sq_register(vm, PeerNetSendString, "PeerNetSendString", _SC(".xxs"));
|
||||
/*#
|
||||
Func: PeerNetBroadcastString
|
||||
Proto: void:PeerController controller,String data
|
||||
Desc: Send a string to all peer controllers connected to this controller.
|
||||
Example:
|
||||
// Broadcast the HELLO string to all connected peers.
|
||||
PeerNetBroadcastString(controller, "HELLO")
|
||||
#*/
|
||||
sq_register(vm, PeerNetBroadcastString, "PeerNetBroadcastString", _SC(".xs"));
|
||||
/*#
|
||||
Func: PeerNetUpdate
|
||||
Proto: void:PeerController controller
|
||||
Desc: Dispatch all pending network events for a controller to the global handler functions.
|
||||
#*/
|
||||
sq_register(vm, PeerNetUpdate, "PeerNetUpdate", _SC(".x"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
448
include/modules/script_squirrel/legacy/physic_binding.cpp
Normal file
448
include/modules/script_squirrel/legacy/physic_binding.cpp
Normal file
@ -0,0 +1,448 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "squirrel.h"
|
||||
#include "binding_helpers.h"
|
||||
#include "physic/physic_constraint.h"
|
||||
#include "physic/physic_world.h"
|
||||
#include "scene3d/mconstraint.h"
|
||||
#include "scene3d/scene.h"
|
||||
#include "math/matrix4.h"
|
||||
#include "math/vector.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SceneAddConstraint(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(s, Scene, typetag_Scene3d)
|
||||
__SQ_GETSTRING(name)
|
||||
if (!s->physic_world)
|
||||
return sq_throwerror(vm, "Cannot create constraint, no physic world in scene.");
|
||||
MConstraint *c = new MConstraint(s->physic_world->NewConstraint());
|
||||
if (!c)
|
||||
return sq_throwerror(vm, "Failed to allocate constraint.");
|
||||
c->name = name;
|
||||
s->AddItem(c, true);
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(c, typetag_Constraint)
|
||||
}
|
||||
SQInteger SceneAddPointConstraint(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(6)
|
||||
__SQ_GETSAFEPTR(s, Scene, typetag_Scene3d)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETSAFEPTR(a, MItem, typetag_Item)
|
||||
__SQ_GETSAFEPTR(b, MItem, typetag_Item)
|
||||
__SQ_GETVECTOR(pivot_a)
|
||||
__SQ_GETVECTOR(pivot_b)
|
||||
|
||||
if (!s->physic_world)
|
||||
return sq_throwerror(vm, "Cannot create constraint, no physic world in scene.");
|
||||
MConstraint *c = new MConstraint(s->physic_world->NewConstraint());
|
||||
if (!c)
|
||||
return sq_throwerror(vm, "Failed to allocate constraint.");
|
||||
c->name = name;
|
||||
s->AddItem(c, true);
|
||||
|
||||
if (!a->physic_item || !b->physic_item)
|
||||
return sq_throwerror(vm, "Item has no physics component.");
|
||||
|
||||
c->desc.type = PhysicConstraintDesc::TypePoint;
|
||||
c->desc.item_a = a;
|
||||
c->desc.item_b = b;
|
||||
c->desc.pivot_a = GS::Matrix4::TranslationMatrix(pivot_a);
|
||||
c->desc.pivot_b = GS::Matrix4::TranslationMatrix(pivot_b);
|
||||
|
||||
c->Setup(s->physic_world);
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(c, typetag_Constraint)
|
||||
}
|
||||
SQInteger SceneAddPointConstraintHinge(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(6)
|
||||
__SQ_GETSAFEPTR(s, Scene, typetag_Scene3d)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETSAFEPTR(a, MItem, typetag_Item)
|
||||
__SQ_GETSAFEPTR(b, MItem, typetag_Item)
|
||||
__SQ_GETVECTOR(pivot_a)
|
||||
__SQ_GETVECTOR(pivot_b)
|
||||
|
||||
if (!s->physic_world)
|
||||
return sq_throwerror(vm, "Cannot create constraint, no physic world in scene.");
|
||||
MConstraint *c = new MConstraint(s->physic_world->NewConstraint());
|
||||
if (!c)
|
||||
return sq_throwerror(vm, "Failed to allocate constraint.");
|
||||
c->name = name;
|
||||
s->AddItem(c, true);
|
||||
|
||||
if (!a->physic_item || !b->physic_item)
|
||||
return sq_throwerror(vm, "Item has no physics component.");
|
||||
|
||||
c->desc.type = PhysicConstraintDesc::TypeHinge;
|
||||
c->desc.item_a = a;
|
||||
c->desc.item_b = b;
|
||||
c->desc.pivot_a = GS::Matrix4::TranslationMatrix(pivot_a);
|
||||
c->desc.pivot_b = GS::Matrix4::TranslationMatrix(pivot_b);
|
||||
|
||||
c->Setup(s->physic_world);
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(c, typetag_Constraint)
|
||||
}
|
||||
SQInteger ConstraintEnable(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_GETBOOL(b)
|
||||
__SQ_GETEND
|
||||
if (c->physic_data.IsValid())
|
||||
c->physic_data->Enable(asbool(b));
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ConstraintGetPivotA(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_RETURNVECTOR(c->desc.pivot_a.GetRow(3))
|
||||
}
|
||||
SQInteger ConstraintGetPivotB(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_RETURNVECTOR(c->desc.pivot_b.GetRow(3))
|
||||
}
|
||||
SQInteger ConstraintSetPivotA(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_GETVECTOR(pivot)
|
||||
__SQ_GETEND
|
||||
c->desc.pivot_a = GS::Matrix4::TranslationMatrix(pivot);
|
||||
c->physic_data->SetPivotA(c->desc.pivot_a);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ConstraintSetPivotB(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_GETVECTOR(pivot)
|
||||
__SQ_GETEND
|
||||
c->desc.pivot_b = GS::Matrix4::TranslationMatrix(pivot);
|
||||
c->physic_data->SetPivotB(c->desc.pivot_b);
|
||||
__SQ_RETURN
|
||||
}
|
||||
#include "physic_bullet/bullet_constraint.h"
|
||||
SQInteger ConstraintSetLimit(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(6)
|
||||
__SQ_GETSAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_GETFLOAT(low)
|
||||
__SQ_GETFLOAT(high)
|
||||
__SQ_GETFLOAT(softness)
|
||||
__SQ_GETFLOAT(biasfactor)
|
||||
__SQ_GETFLOAT(relaxationFactor)
|
||||
__SQ_GETEND
|
||||
((BulletConstraint*)(c->physic_data.c_ptr()))->setLimitHinge(low, high, softness, biasfactor, relaxationFactor);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ConstraintGetItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_RETURNSAFEPTR((MItem *)c, typetag_Item)
|
||||
}
|
||||
SQInteger ConstraintSetItemA(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_GETSAFEPTR(i, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
c->desc.item_a = i;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ConstraintSetItemB(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(c, MConstraint, typetag_Constraint)
|
||||
__SQ_GETSAFEPTR(i, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
c->desc.item_b = i;
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
#include "script_squirrel/mmf.h"
|
||||
|
||||
// See TELEMETRY_DATA.flags
|
||||
#define MMF_CONFIG_EXPLICIT_LOCAL_VEL 1
|
||||
#define MMF_CONFIG_EXPLICIT_LOCAL_ACCEL 2
|
||||
#define MMF_CONFIG_EXPLICIT_GLOBAL_ACCEL 4
|
||||
#define MMF_CONFIG_EXPLICIT_ACCEL_EXCLUDES_GRAVITY 8
|
||||
|
||||
// See TELEMETRY_DATA.flags
|
||||
#define CONFIG_EXPLICIT_LOCAL_VEL (1 << 0)
|
||||
#define CONFIG_EXPLICIT_LOCAL_ACCEL (1 << 1)
|
||||
#define CONFIG_EXPLICIT_ACCEL_EXCLUDES_GRAVITY (1 << 3)
|
||||
#define CONFIG_ROW_ORDERED_MATRIX (1 << 4)
|
||||
|
||||
// See TELEMETRY_DATA.axis
|
||||
#define AXIS_X_UP (1 << 0)
|
||||
#define AXIS_X_DOWN (1 << 1)
|
||||
#define AXIS_X_NORTH (1 << 2)
|
||||
#define AXIS_X_SOUTH (1 << 3)
|
||||
#define AXIS_X_EAST (1 << 4)
|
||||
#define AXIS_X_WEST (1 << 5)
|
||||
#define AXIS_Y_UP (1 << 8)
|
||||
#define AXIS_Y_DOWN (1 << 9)
|
||||
#define AXIS_Y_NORTH (1 << 10)
|
||||
#define AXIS_Y_SOUTH (1 << 11)
|
||||
#define AXIS_Y_EAST (1 << 12)
|
||||
#define AXIS_Y_WEST (1 << 13)
|
||||
#define AXIS_Z_UP (1 << 16)
|
||||
#define AXIS_Z_DOWN (1 << 17)
|
||||
#define AXIS_Z_NORTH (1 << 18)
|
||||
#define AXIS_Z_SOUTH (1 << 19)
|
||||
#define AXIS_Z_EAST (1 << 20)
|
||||
#define AXIS_Z_WEST (1 << 21)
|
||||
|
||||
|
||||
struct TELEMETRY_DATA
|
||||
{
|
||||
unsigned int flags;
|
||||
unsigned int axis;
|
||||
float accel[3];
|
||||
float vel[3];
|
||||
float rotationMatrix[3][3];
|
||||
DWORD packetTimeMillis;
|
||||
};
|
||||
/*
|
||||
struct SIMPHYNITYMMF
|
||||
{
|
||||
unsigned char flags;
|
||||
DWORD packetTime;
|
||||
float telemetryMatrix[16];
|
||||
float velocity[3];
|
||||
float accel[3];
|
||||
};*/
|
||||
struct SIMPHYNITYMMF
|
||||
{
|
||||
DWORD packetTime;
|
||||
float telemetryMatrix[16];
|
||||
float globalVelocity[3];
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
SQInteger CreateMMF(HSQUIRRELVM vm)
|
||||
//-------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNSAFEPTR(new CMMF(_T("$SIMPHYNITYTELEM$"), sizeof(TELEMETRY_DATA), _T("$SIMPHYNITYTELEMMUTEX$")), typetag_Item)
|
||||
// __SQ_RETURNSAFEPTR(new CMMF(_T("$SIMPHYNITYTELEM$"), sizeof(SIMPHYNITYMMF), _T("$SIMPHYNITYTELEMMUTEX$")), typetag_Item)
|
||||
}
|
||||
#define __SQ_GETPHYSICITEM(__I__) PhysicItem *iphysic = (__I__)->physic_item.c_ptr(); if (!iphysic) return sq_throwerror(vm, "No physics found, did you setup this item?");
|
||||
//-------------------------------------------------------
|
||||
SQInteger UpdateMMF(HSQUIRRELVM vm)
|
||||
//-------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(mmf, CMMF, typetag_Item)
|
||||
__SQ_GETSAFEPTR(item, MItem, typetag_Item)
|
||||
__SQ_GETFLOAT(Physic_T)
|
||||
__SQ_GETEND
|
||||
|
||||
__SQ_GETPHYSICITEM(item)
|
||||
|
||||
GS::Matrix4 item_matrix;
|
||||
iphysic->GetMatrix(item_matrix);
|
||||
item_matrix = item->GetBaseItem()->GetMatrix();
|
||||
|
||||
GS::Vector4 position;
|
||||
GS::Vector4 scale;
|
||||
GS::Matrix3 rotation;
|
||||
item_matrix.Decompose(&position, &scale, &rotation);
|
||||
|
||||
// GS::Vector4 velocity_vec = (item && item->isActive() ? iphysic->GetLinearVelocity() : GS::Vector4(0, 0, 0));
|
||||
GS::Vector4 velocity_vec = (item && item->isActive() ? iphysic->GetLinearVelocity() : GS::Vector4(0, 0, 0));
|
||||
/*
|
||||
|
||||
SIMPHYNITYMMF m_Telem;
|
||||
m_Telem.packetTime = Physic_T*1000.0f; // Current physics time.
|
||||
memcpy(m_Telem.telemetryMatrix, item_matrix.m, sizeof(m_Telem.telemetryMatrix)); // Current rotation, position.
|
||||
memcpy(m_Telem.globalVelocity, ((float *)&(velocity_vec.x)), sizeof(m_Telem.globalVelocity)); // Global vel XYZ.
|
||||
mmf->Write(&m_Telem);
|
||||
*/
|
||||
|
||||
TELEMETRY_DATA m_Telem;
|
||||
m_Telem.packetTimeMillis = Physic_T*1000.0f; // Current physics time.
|
||||
m_Telem.axis = AXIS_X_EAST | AXIS_Y_UP | AXIS_Z_NORTH;
|
||||
m_Telem.flags = CONFIG_EXPLICIT_LOCAL_VEL | CONFIG_EXPLICIT_ACCEL_EXCLUDES_GRAVITY | CONFIG_ROW_ORDERED_MATRIX;
|
||||
memcpy(m_Telem.rotationMatrix, rotation.m, sizeof(m_Telem.rotationMatrix)); // Current rotation
|
||||
memcpy(m_Telem.vel, ((float *)&(velocity_vec.x)), sizeof(m_Telem.vel)); // Global vel XYZ.
|
||||
m_Telem.accel[0] = 0; m_Telem.accel[1] = 0; m_Telem.accel[2] = 0;
|
||||
mmf->Write(&m_Telem);
|
||||
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
struct ENGINE_TELEMETRY_DATA
|
||||
{
|
||||
char package[32768];
|
||||
};
|
||||
|
||||
SQInteger CreateEngineMMF(HSQUIRRELVM vm)
|
||||
//-------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNSAFEPTR(new CMMF(_T("$DevelterInnovationSimulateur$"), sizeof(ENGINE_TELEMETRY_DATA), _T("$DevelterInnovationSimulateurMUTEX$")), typetag_Item)
|
||||
}
|
||||
//-------------------------------------------------------
|
||||
SQInteger UpdateEngineMMF(HSQUIRRELVM vm)
|
||||
//-------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(mmf, CMMF, typetag_Item)
|
||||
__SQ_GETSTRING(package)
|
||||
__SQ_GETEND
|
||||
|
||||
GS::String spackage(package);
|
||||
|
||||
if (spackage.Size() > 32768)
|
||||
return sq_throwerror(vm, "UpdateEngineMMF: package bigger than 16384 bits.");
|
||||
|
||||
ENGINE_TELEMETRY_DATA m_Telem;
|
||||
memset(m_Telem.package, 0, 32768);
|
||||
memcpy(m_Telem.package, spackage.c_str(), spackage.Size());
|
||||
mmf->Write(&m_Telem);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterPhysicBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Physic
|
||||
Type: Constraint
|
||||
Desc: Physic world functions. For item related physic functions please refer to the Item topic.
|
||||
Related: Item
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: CreateMMF
|
||||
Proto: MMF:void
|
||||
Desc: Create mmf object for simu purpose.
|
||||
#*/
|
||||
sq_register(vm, CreateMMF, "CreateMMF", _SC("."));
|
||||
/*#
|
||||
Func: UpdateMMF
|
||||
Proto: void:MMF, ,
|
||||
Desc: update the mmf with the object rotation and velocity.
|
||||
#*/
|
||||
sq_register(vm, UpdateMMF, "UpdateMMF", _SC(".xxf"));
|
||||
|
||||
/*#
|
||||
Func: CreateEngineMMF
|
||||
Proto: MMF:void
|
||||
Desc: Create mmf object for simu purpose.
|
||||
#*/
|
||||
sq_register(vm, CreateEngineMMF, "CreateEngineMMF", _SC("."));
|
||||
/*#
|
||||
Func: UpdateEngineMMF
|
||||
Proto: void:MMF
|
||||
Desc: update the mmf with the json values
|
||||
#*/
|
||||
sq_register(vm, UpdateEngineMMF, "UpdateEngineMMF", _SC(".xs"));
|
||||
/*#
|
||||
Section: ConstraintManagement
|
||||
Desc: Constraint management functions
|
||||
#*/
|
||||
/*#
|
||||
Func: SceneAddPointConstraint
|
||||
Proto: Constraint:Scene,string name, Item a,Item b,Vector pivot_a,Vector pivot_b
|
||||
Desc: Create a new point constraint between two items. The pivot position is in item space. The null item can be set as item B to specify an unmovable world space hook.
|
||||
#*/
|
||||
sq_register(vm, SceneAddPointConstraint, "SceneAddPointConstraint", _SC(".xsxxxx"));
|
||||
/*#
|
||||
Func: SceneAddPointConstraintHinge
|
||||
Proto: Constraint:Scene,string name, Item a,Item b,Vector pivot_a,Vector pivot_b
|
||||
Desc: Create a new point constraint between two items. The pivot position is in item space. The null item can be set as item B to specify an unmovable world space hook.
|
||||
#*/
|
||||
sq_register(vm, SceneAddPointConstraintHinge, "SceneAddPointConstraintHinge", _SC(".xsxxxx"));
|
||||
|
||||
/*#
|
||||
Func: ConstraintEnable
|
||||
Proto: void:Constraint,bool
|
||||
Desc: Enable/disable constraint.
|
||||
#*/
|
||||
sq_register(vm, ConstraintEnable, "ConstraintEnable", _SC(".xb"));
|
||||
|
||||
/*#
|
||||
Section: ConstraintConfiguration
|
||||
Desc: Constraint configuration functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ConstraintGetPivotA
|
||||
Proto: Vector:Constraint
|
||||
Desc: Get the constraint item A pivot vector.
|
||||
#*/
|
||||
sq_register(vm, ConstraintGetPivotA, "ConstraintGetPivotA", _SC(".x"));
|
||||
/*#
|
||||
Func: ConstraintGetPivotB
|
||||
Proto: Vector:Constraint
|
||||
Desc: Get the constraint item B pivot vector.
|
||||
#*/
|
||||
sq_register(vm, ConstraintGetPivotB, "ConstraintGetPivotB", _SC(".x"));
|
||||
/*#
|
||||
Func: ConstraintSetPivotA
|
||||
Proto: void:Constraint,Vector pivot
|
||||
Desc: Set the constraint item A pivot vector.
|
||||
#*/
|
||||
sq_register(vm, ConstraintSetPivotA, "ConstraintSetPivotA", _SC(".xx"));
|
||||
/*#
|
||||
Func: ConstraintSetPivotB
|
||||
Proto: void:Constraint,Vector pivot
|
||||
Desc: Set the constraint item B pivot vector.
|
||||
#*/
|
||||
sq_register(vm, ConstraintSetPivotB, "ConstraintSetPivotB", _SC(".xx"));
|
||||
/*#
|
||||
Func: ConstraintSetLimit
|
||||
Proto: void:Constraint,float low, float high, float softness, float biasfactor, float relaxationfactor
|
||||
Desc: Set the constraint limit.
|
||||
#*/
|
||||
sq_register(vm, ConstraintSetLimit, "ConstraintSetLimit", _SC(".xfffff"));
|
||||
|
||||
/*#
|
||||
Func: ConstraintGetItem
|
||||
Proto: Item:Constraint
|
||||
Desc: Get constraint item.
|
||||
#*/
|
||||
sq_register(vm, ConstraintGetItem, "ConstraintGetItem", _SC(".x"));
|
||||
/*#
|
||||
Func: ConstraintSetItemA
|
||||
Proto: void:Constraint,Item
|
||||
Desc: Set constraint item A.
|
||||
#*/
|
||||
sq_register(vm, ConstraintSetItemA, "ConstraintSetItemA", _SC(".xx"));
|
||||
/*#
|
||||
Func: ConstraintSetItemB
|
||||
Proto: void:Constraint,Item
|
||||
Desc: Set constraint item B.
|
||||
#*/
|
||||
sq_register(vm, ConstraintSetItemB, "ConstraintSetItemB", _SC(".xx"));
|
||||
|
||||
// Push defines.
|
||||
sq_pushroottable(vm);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
515
include/modules/script_squirrel/legacy/picture_binding.cpp
Normal file
515
include/modules/script_squirrel/legacy/picture_binding.cpp
Normal file
@ -0,0 +1,515 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "ui/ui.h"
|
||||
#include "font/font_renderer.h"
|
||||
#include "picture/pict_io.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
void IterateTextParameters(HSQUIRRELVM vm, int idx, TextState &state);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger NewPicture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETINT(w)
|
||||
__SQ_GETINT(h)
|
||||
__SQ_GETEND
|
||||
Picture *p = new Picture;
|
||||
if (!p || !p->AllocAs(w, h))
|
||||
return sq_throwerror(vm, String::Format("Failed to allocate a new %dx%d picture.", w, h));
|
||||
__SQ_RETURNSAFEPTR(p, typetag_Picture)
|
||||
}
|
||||
SQInteger LoadPicture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(path)
|
||||
Picture *p = new Picture;
|
||||
if (!p)
|
||||
return sq_throwerror(vm, "Failed to allocate picture.");
|
||||
if (!PictureIO::Get().Load(*p, path))
|
||||
return sq_throwerror(vm, String::Format("Failed to load picture '%s'.", path));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(p, typetag_Picture)
|
||||
}
|
||||
SQInteger PictureClone(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_RETURNSAFEPTR(new Picture(*p), typetag_Picture);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger PictureWriteText(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(5)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETRECT(out_rect)
|
||||
__SQ_GETSTRING(text)
|
||||
__SQ_GETSAFEPTR(font, FontEx, typetag_Font)
|
||||
|
||||
TextState state;
|
||||
IterateTextParameters(vm, -1, state);
|
||||
__SQ_GETUPDATESTACK
|
||||
|
||||
state.font = font;
|
||||
|
||||
iRect clip_rect = p->GetRect();
|
||||
FontRenderer::Format(text, state, out_rect);
|
||||
FontRenderer::Compose(*p, text, state, out_rect, clip_rect);
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger PictureApplyConvolution(HSQUIRRELVM vm)
|
||||
{
|
||||
Picture *pic;
|
||||
if (!CObject::Get(vm, -6, (void **)&pic, typetag_Picture))
|
||||
return -1;
|
||||
if (!pic)
|
||||
return sq_throwerror(vm, "Invalid picture.");
|
||||
|
||||
// Kernel size.
|
||||
SQInteger kw, kh;
|
||||
sq_getinteger(vm, -5, &kw);
|
||||
sq_getinteger(vm, -4, &kh);
|
||||
|
||||
int kernel[1024];
|
||||
if ((kw * kh) > 1024)
|
||||
return sq_throwerror(vm, "The convolution kernel is exceeding 1024 entries.");
|
||||
|
||||
sq_pushnull(vm); // iterator
|
||||
for (int n = 0; n < (kw * kh); ++n)
|
||||
{
|
||||
if (SQ_FAILED(sq_next(vm, -4)))
|
||||
break;
|
||||
|
||||
// Here -1 is the value and -2 is the key.
|
||||
SQInteger v;
|
||||
sq_getinteger(vm, -1, &v);
|
||||
kernel[n] = v;
|
||||
sq_pop(vm, 2); // Pops key and val before the next iteration.
|
||||
}
|
||||
sq_pop(vm, 1); // Pop the iterator.
|
||||
|
||||
SQFloat weight;
|
||||
sq_getfloat(vm, -2, &weight);
|
||||
SQInteger pass;
|
||||
sq_getinteger(vm, -1, &pass);
|
||||
|
||||
sq_pop(vm, 4); // Pop function arguments.
|
||||
|
||||
if (!pic->ApplyConvolution(kw, kh, kernel, int(weight * 256), pass))
|
||||
return sq_throwerror(vm, "Convolution filter failed.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
SQInteger PictureLine(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(6)
|
||||
__SQ_GETSAFEPTR(pic, Picture, typetag_Picture)
|
||||
__SQ_GETFLOAT(sx)
|
||||
__SQ_GETFLOAT(sy)
|
||||
__SQ_GETFLOAT(ex)
|
||||
__SQ_GETFLOAT(ey)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
|
||||
fRect rect = pic->GetRect().AsFloat();
|
||||
rect.ex -= 2; rect.ey -= 2;
|
||||
if ((rect.ex <= rect.sx) || (rect.ey < rect.sy))
|
||||
return 0;
|
||||
pic->DrawLineHQ(sx, sy, ex, ey, c.x, c.y, c.z, c.w, &rect);
|
||||
return 0;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PictureLoadContent(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(pic, Picture, typetag_Picture)
|
||||
__SQ_GETSTRING(path)
|
||||
bool r = PictureIO::Get().Load(*pic, path);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger PictureSaveTGA(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETSTRING(path)
|
||||
if (!PictureIO::Get().TgaSave(*p, path))
|
||||
return sq_throwerror(vm, String::Format("Failed to save picture to '%s'", path));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureSaveJPG(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETSTRING(path)
|
||||
p->Convert(PixelFormat::RGB8);
|
||||
if (!PictureIO::Get().Save(*p, path, "IJG"))
|
||||
return sq_throwerror(vm, String::Format("Failed to save picture to '%s'", path));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PictureGetRect(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(p, Picture, typetag_Picture)
|
||||
iRect rect(0, 0, 0, 0);
|
||||
if (p) rect.Set(0, 0, p->GetWidth(), p->GetHeight());
|
||||
__SQ_RETURNRECT(rect)
|
||||
}
|
||||
SQInteger PictureAlloc(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETINT(w)
|
||||
__SQ_GETINT(h)
|
||||
__SQ_GETEND
|
||||
if (!p->AllocAs(w, h))
|
||||
return sq_throwerror(vm, "Failed to allocate picture buffer");
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureResize(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETINT(w)
|
||||
__SQ_GETINT(h)
|
||||
__SQ_GETEND
|
||||
p->Resize(w, h);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PictureSetPixel(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETFLOAT(x)
|
||||
__SQ_GETFLOAT(y)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
p->DrawPlot(x, y, c.x, c.y, c.z, c.w);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureGetPixel(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETFLOAT(x)
|
||||
__SQ_GETFLOAT(y)
|
||||
__SQ_GETEND
|
||||
Color c;
|
||||
p->Sample(x / p->GetWidth(), y / p->GetHeight(), c);
|
||||
__SQ_RETURNVECTORW(Vector4(c.x, c.y, c.z, c.w))
|
||||
}
|
||||
SQInteger PictureFlip(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETBOOL(h)
|
||||
__SQ_GETBOOL(v)
|
||||
__SQ_GETEND
|
||||
p->Flip(asbool(h), asbool(v));
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureFillLockAlpha(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
p->Fill(c.x, c.y, c.z, c.w, 0, true);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureFill(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETEND
|
||||
p->Fill(c.x, c.y, c.z, c.w);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureFillRect(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(p, Picture, typetag_Picture)
|
||||
__SQ_GETVECTORW(c)
|
||||
__SQ_GETRECT(clip_rect)
|
||||
__SQ_GETEND
|
||||
p->Fill(c.x, c.y, c.z, c.w, &clip_rect);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureBlitRect(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(5)
|
||||
__SQ_GETSAFEPTR(src, Picture, typetag_Picture)
|
||||
__SQ_GETSAFEPTR(dst, Picture, typetag_Picture)
|
||||
__SQ_GETRECT(src_rect)
|
||||
__SQ_GETRECT(dst_rect)
|
||||
__SQ_GETINT(blend_mode)
|
||||
__SQ_GETEND
|
||||
Picture::Blit(*src, *dst, &src_rect, &dst_rect, (Picture::BlendMode)blend_mode);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureBlitRectMasked(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(5)
|
||||
__SQ_GETSAFEPTR(src, Picture, typetag_Picture)
|
||||
__SQ_GETSAFEPTR(dst, Picture, typetag_Picture)
|
||||
__SQ_GETSAFEPTR(msk, Picture, typetag_Picture)
|
||||
__SQ_GETRECT(src_rect)
|
||||
__SQ_GETRECT(dst_rect)
|
||||
__SQ_GETEND
|
||||
Picture::BlitMask(*src, *dst, *msk, &src_rect, &dst_rect);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PictureBlit(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(src, Picture, typetag_Picture)
|
||||
__SQ_GETSAFEPTR(dst, Picture, typetag_Picture)
|
||||
__SQ_GETINT(blend_mode)
|
||||
__SQ_GETEND
|
||||
Picture::Blit(*src, *dst, 0, 0, (Picture::BlendMode)blend_mode);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//--------------------------------------------------------
|
||||
void RegisterPictureBinding(HSQUIRRELVM vm)
|
||||
//--------------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Picture
|
||||
Type: Picture
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: PictureManagement
|
||||
Desc: Management
|
||||
#*/
|
||||
/*#
|
||||
Func: NewPicture
|
||||
Proto: Picture:int width,int height
|
||||
Desc: Create a new picture, width and height are specified in pixels.
|
||||
Example: local picture = NewPicture()
|
||||
#*/
|
||||
sq_register(vm, NewPicture, "NewPicture", _SC(".nn"));
|
||||
/*#
|
||||
Func: LoadPicture
|
||||
Proto: Picture:string path
|
||||
Desc: Load a picture. This function supports the following formats: Jpeg, Bmp, Targa, Png, Gif and PSD with alpha channel.
|
||||
Note: No caching mechanism involved, every call to this function will result in a filesystem access.
|
||||
Example: local picture = LoadPicture("assets/picture.png")
|
||||
#*/
|
||||
sq_register(vm, LoadPicture, "LoadPicture", _SC(".s"));
|
||||
/*#
|
||||
Func: PictureClone
|
||||
Proto: Picture:Picture source
|
||||
Desc: Clone a picture, return the cloned picture.
|
||||
#*/
|
||||
sq_register(vm, PictureClone, "PictureClone", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: PictureDrawing
|
||||
Desc: Drawing
|
||||
#*/
|
||||
/*#
|
||||
Func: PictureAlloc
|
||||
Proto: bool:Picture,width,height
|
||||
Desc: Change the picture internal storage dimensions, existing data will be lost.
|
||||
#*/
|
||||
sq_register(vm, PictureAlloc, "PictureAlloc", _SC(".xnn"));
|
||||
/*#
|
||||
Func: PictureLoadContent
|
||||
Proto: bool:Picture,string path
|
||||
Desc: Reload a picture object content from file.
|
||||
See: LoadPicture
|
||||
#*/
|
||||
sq_register(vm, PictureLoadContent, "PictureLoadContent", _SC(".xs"));
|
||||
/*#
|
||||
Func: PictureSaveTGA
|
||||
Proto: void:Picture,string path
|
||||
Desc: Save a picture object to Targa.
|
||||
Note: Make sure that you have access to the filesystem you plan on writing to.
|
||||
See: SystemHasMountPoint
|
||||
#*/
|
||||
sq_register(vm, PictureSaveTGA, "PictureSaveTGA", _SC(".xs"));
|
||||
/*#
|
||||
Func: PictureSaveJPG
|
||||
Proto: void:Picture,string path
|
||||
Desc: Save a picture object to jpg.
|
||||
Note: Make sure that you have access to the filesystem you plan on writing to.
|
||||
See: SystemHasMountPoint
|
||||
#*/
|
||||
sq_register(vm, PictureSaveJPG, "PictureSaveJPG", _SC(".xs"));
|
||||
/*#
|
||||
Func: PictureGetRect
|
||||
Proto: Rect:Picture
|
||||
Desc: Return a picture bounding rectangle.
|
||||
Example:
|
||||
local pict = PictureLoad("picture.psd")
|
||||
local rect = PictureGetRect(pict)
|
||||
|
||||
print("Picture width = " + rect.GetWidth() + ", height = " + rect.GetHeight())
|
||||
#*/
|
||||
sq_register(vm, PictureGetRect, "PictureGetRect", _SC(".x"));
|
||||
/*#
|
||||
Func: PictureFill
|
||||
Proto: void:Picture,Vector rgba
|
||||
Desc: Fill a picture with a solid color defined as an RGBA vector.
|
||||
#*/
|
||||
sq_register(vm, PictureFill, "PictureFill", _SC(".xx"));
|
||||
/*#
|
||||
Func: PictureFillLockAlpha
|
||||
Proto: void:Picture,Vector rgba
|
||||
Desc: Fill a picture with a solid color defined from an RGBA vector, does not write to alpha.
|
||||
#*/
|
||||
sq_register(vm, PictureFillLockAlpha, "PictureFillLockAlpha", _SC(".xx"));
|
||||
/*#
|
||||
Func: PictureFillRect
|
||||
Proto: void:Picture,Vector rgba,Rect
|
||||
Desc: Fill a rectangle inside a picture with a solid color defined from an RGBA vector.
|
||||
#*/
|
||||
sq_register(vm, PictureFillRect, "PictureFillRect", _SC(".xxx"));
|
||||
/*#
|
||||
Func: PictureApplyConvolution
|
||||
Proto: void:Picture,int kernel_width,int kernel_height,array kernel_values,float filter_weight,int pass_count
|
||||
Desc: Apply a convolution filter to the picture using a user specified kernel of values.<br>
|
||||
<br>
|
||||
The <em>weight</em> and <em>pass</em> parameters will be 1 in most use case,
|
||||
kernel values are integer in the nominal range [0;255].
|
||||
Example:
|
||||
function BlurPicture(picture, blur_strength = 1, blur_pass_count = 1)
|
||||
{
|
||||
local kernel = // 7x7 kernel
|
||||
[
|
||||
0, 1, 2, 4, 2, 1, 0,
|
||||
1, 2, 4, 6, 4, 2, 1,
|
||||
2, 3, 5, 8, 5, 3, 2,
|
||||
2, 4, 8, 8, 8, 4, 2,
|
||||
2, 3, 5, 8, 5, 3, 2,
|
||||
1, 2, 4, 6, 4, 2, 1,
|
||||
0, 1, 2, 4, 2, 1, 0
|
||||
]
|
||||
PictureApplyConvolution(picture, 7, 7, kernel, blur_strength, blur_pass_count)
|
||||
}
|
||||
#*/
|
||||
sq_register(vm, PictureApplyConvolution, "PictureApplyConvolution", _SC(".xiiani"));
|
||||
/*#
|
||||
Func: PictureLine
|
||||
Proto: bool:Texture,float start_x,float start_y,float end_x,float end_y,Vector rgba
|
||||
Desc: Draw a line, color is specified as an RGBA vector.
|
||||
#*/
|
||||
sq_register(vm, PictureLine, "PictureLine", _SC(".xnnnnx"));
|
||||
/*#
|
||||
Func: PictureWriteFont
|
||||
Proto: void:Picture,rect,string text,Font font,TextState
|
||||
Desc: Render formatted text to a picture.<br>
|
||||
TextState is table containing the following keys:<br>
|
||||
<ul>
|
||||
<li><b>'size'</b>: Size in pixels.
|
||||
<li><b>'color'</b>: Hexadecimal RGBA (eg. 0xff0000ff for red at 100% opacity).
|
||||
<li><b>'align'</b>: Text alignment, can be any of "left", "center", "right" or "justify".
|
||||
<li><b>'format'</b>: Text formating, can be any of "standard", "paragraph" or "column".
|
||||
<li><b>'tracking'</b>: Integer value specifying an extra space between glyphs.
|
||||
<li><b>'heading'</b>: Integer value specifying an extra space between lines.
|
||||
</ul>
|
||||
#*/
|
||||
sq_register(vm, PictureWriteText, "PictureWriteFont", _SC(".xxsxt"));
|
||||
sq_register(vm, PictureWriteText, "PictureWriteText", _SC(".xxsxt"));
|
||||
/*#
|
||||
Func: PictureSetPixel
|
||||
Proto: void:Picture,float x,float y,Vector rgba
|
||||
Desc: Set picture pixel at coordinate {x, y} in picture space from an RGBA vector.
|
||||
#*/
|
||||
sq_register(vm, PictureSetPixel, "PictureSetPixel", _SC(".xnnx"));
|
||||
/*#
|
||||
Func: PictureGetPixel
|
||||
Proto: Vector:Picture,float x,float y
|
||||
Desc: Return the picture pixel at coordinate {x, y} in picture space as an RGBA vector.
|
||||
#*/
|
||||
sq_register(vm, PictureGetPixel, "PictureGetPixel", _SC(".xnn"));
|
||||
|
||||
/*#
|
||||
Section: PictureManipulation
|
||||
Desc: Manipulation
|
||||
#*/
|
||||
/*#
|
||||
Func: PictureResize
|
||||
Proto: void:Picture,float w,float h
|
||||
Desc: Resize picture.
|
||||
#*/
|
||||
sq_register(vm, PictureResize, "PictureResize", _SC(".xii"));
|
||||
/*#
|
||||
Func: PictureFlip
|
||||
Proto: void:Picture,bool horizontal, bool vertical
|
||||
Desc: Flip picture on one or both axis.
|
||||
#*/
|
||||
sq_register(vm, PictureFlip, "PictureFlip", _SC(".xbb"));
|
||||
|
||||
/*#
|
||||
Section: PictureBlitting
|
||||
Desc: Blitting
|
||||
#*/
|
||||
/*#
|
||||
Func: PictureBlit
|
||||
Proto: void:Picture source,Picture destination,BlendMode mode
|
||||
Desc: Blit a picture to another picture with a selectable blend mode.
|
||||
#*/
|
||||
sq_register(vm, PictureBlit, "PictureBlit", _SC(".xxi"));
|
||||
/*#
|
||||
Func: PictureBlitRect
|
||||
Proto: void:Picture source,Picture destination,Rect source,Rect destination,BlendMode mode
|
||||
Desc: Blit a picture to another picture, both clipping zones and the blend mode can be specified.
|
||||
#*/
|
||||
sq_register(vm, PictureBlitRect, "PictureBlitRect", _SC(".xxxxi"));
|
||||
/*#
|
||||
Func: PictureBlitRectMasked
|
||||
Proto: void:Picture source,Picture destination,Picture mask,Rect source,Rect destination
|
||||
Desc: Blit a picture to another picture using a third picture alpha channel as an opacity mask.
|
||||
#*/
|
||||
sq_register(vm, PictureBlitRectMasked, "PictureBlitRectMasked", _SC(".xxxxx"));
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: BlendMode
|
||||
Values: BlendReplace,BlendAdd,BlendCompose,BlendComposeFast,BlendMultiply,BlendMultiply2x,BlendAlphaAdd,BlendAlphaMultiply,BlendAlphaMultiply2x,RgbToAlpha
|
||||
#*/
|
||||
sq_pushstring(vm, "BlendReplace", -1); sq_pushinteger(vm, Picture::BlendReplace); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendAdd", -1); sq_pushinteger(vm, Picture::BlendAdd); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendCompose", -1); sq_pushinteger(vm, Picture::BlendCompose); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendComposeFast", -1); sq_pushinteger(vm, Picture::BlendComposeFast); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendMultiply", -1); sq_pushinteger(vm, Picture::BlendMultiply); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendMultiply2x", -1); sq_pushinteger(vm, Picture::BlendMultiply2x); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendAlphaAdd", -1); sq_pushinteger(vm, Picture::BlendAlphaAdd); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendAlphaMultiply", -1); sq_pushinteger(vm, Picture::BlendAlphaMultiply); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "BlendAlphaMultiply2x", -1); sq_pushinteger(vm, Picture::BlendAlphaMultiply2x); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "RgbToAlpha", -1); sq_pushinteger(vm, Picture::RgbToAlpha); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
262
include/modules/script_squirrel/legacy/platform_binding.cpp
Normal file
262
include/modules/script_squirrel/legacy/platform_binding.cpp
Normal file
@ -0,0 +1,262 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
nEngine - GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "squirrel.h"
|
||||
#include "script_squirrel/legacy/binding_helpers.h"
|
||||
#include "licensing/licensing.h"
|
||||
#include "analytics/analytics.h"
|
||||
#include "billing/billing.h"
|
||||
#include "locale/country.h"
|
||||
#include "platform.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PlatformAnalyticsLogEvent(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(name)
|
||||
if (Platform::Get().analytics.IsValid())
|
||||
Platform::Get().analytics->logEvent(name);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PlatformAnalyticsServeFullscreenAd(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(location)
|
||||
if (Platform::Get().analytics.IsValid())
|
||||
Platform::Get().analytics->serveFullscreenAd(location);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PlatformBillingConfirmEvent(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(id)
|
||||
if (Platform::Get().billing.IsNull())
|
||||
return sq_throwerror(vm, "No billing system on this platform.");
|
||||
Platform::Get().billing->confirmPurchase(id);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PlatformBillingRestorePurchases(HSQUIRRELVM vm)
|
||||
{
|
||||
if (Platform::Get().billing.IsNull())
|
||||
return sq_throwerror(vm, "No billing system on this platform.");
|
||||
Platform::Get().billing->restorePurchases();
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PlatformBillingRequestPurchase(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(id)
|
||||
if (Platform::Get().billing.IsNull())
|
||||
return sq_throwerror(vm, "No billing system on this platform.");
|
||||
Platform::Get().billing->requestPurchase(id);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger PlatformBillingIsSupported(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNBOOL(Platform::Get().billing.IsValid()) }
|
||||
SQInteger PlatformGetLocale(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNSTRING(Platform::Get().GetLocale()) }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PlatformLicensingIsSupported(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_RETURNBOOL(Platform::Get().licensing.IsValid())
|
||||
}
|
||||
SQInteger PlatformLicensingCheck(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(id)
|
||||
if (Platform::Get().licensing.IsNull())
|
||||
return sq_throwerror(vm, "No licensing system on this platform.");
|
||||
Platform::Get().licensing->updateLicence(id);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(true)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PlatformGetName(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNSTRING(Platform::Get().GetName()) }
|
||||
SQInteger PlatformGetDeviceName(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNSTRING(Platform::Get().GetDeviceName()) }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PlatformOpenURL(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(url)
|
||||
bool r = Platform::Get().OpenURL(url);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger PlatformSendToBackground(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETBOOL(kill)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(Platform::Get().SendToBackground(asbool(kill)))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PlatformGetUserPath(HSQUIRRELVM vm)
|
||||
{
|
||||
String path;
|
||||
if (!Platform::Get().GetUserDir(path))
|
||||
return sq_throwerror(vm, "Failed to get user path.");
|
||||
__SQ_RETURNSTRING(path)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger PlatformOpenAppPage(HSQUIRRELVM vm)
|
||||
{
|
||||
Platform::Get().OpenAppPage();
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterPlatformBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
using namespace GS::Script;
|
||||
|
||||
/*#
|
||||
Section: SystemMisc
|
||||
Desc: Miscellaneous
|
||||
#*/
|
||||
/*#
|
||||
Func: PlatformOpenURL
|
||||
Proto: bool:String id
|
||||
Desc: Open an URL using the platform browser if available.
|
||||
#*/
|
||||
sq_register(vm, PlatformOpenURL, "PlatformOpenURL", _SC(".s"));
|
||||
/*#
|
||||
Func: PlatformSendToBackground
|
||||
Proto: bool:bool kill
|
||||
Desc: Send the current application to background, optionally try to kill it.
|
||||
#*/
|
||||
sq_register(vm, PlatformSendToBackground, "PlatformSendToBackground", _SC(".b"));
|
||||
|
||||
/*#
|
||||
Func: PlatformGetUserPath
|
||||
Proto: String:
|
||||
Desc: Return the current user path.
|
||||
#*/
|
||||
sq_register(vm, PlatformGetUserPath, "PlatformGetUserPath", _SC("."));
|
||||
|
||||
/*#
|
||||
Section: SystemVisibility
|
||||
Desc: Platform visibility
|
||||
#*/
|
||||
/*#
|
||||
Func: PlatformOpenAppPage
|
||||
Proto: void:
|
||||
Desc: Open the platform specific application page, use this to send the user to your rating page.
|
||||
#*/
|
||||
sq_register(vm, PlatformOpenAppPage, "PlatformOpenAppPage", _SC("."));
|
||||
|
||||
/*#
|
||||
Section: SystemLicensing
|
||||
Desc: Licensing
|
||||
#*/
|
||||
/*#
|
||||
Func: PlatformLicensingCheck
|
||||
Proto: void:String license_info
|
||||
Desc: Launch an asynchronous licensing request, the result will be sent to your script global 'OnLicensingEvent(String event)' function.
|
||||
#*/
|
||||
sq_register(vm, PlatformLicensingCheck, "PlatformLicensingCheck", _SC(".s"));
|
||||
/*#
|
||||
Func: PlatformLicensingIsSupported
|
||||
Proto: bool:
|
||||
Desc: Returns true if the current platform supports app license verification.
|
||||
#*/
|
||||
sq_register(vm, PlatformLicensingIsSupported, "PlatformLicensingIsSupported", _SC("."));
|
||||
|
||||
/*#
|
||||
Section: SystemBilling
|
||||
Desc: In-app billing
|
||||
#*/
|
||||
/*#
|
||||
Func: PlatformBillingConfirmEvent
|
||||
Proto: void:String id
|
||||
Desc: Confirm a billing event (like a purchase or a refund).
|
||||
#*/
|
||||
sq_register(vm, PlatformBillingConfirmEvent, "PlatformBillingConfirmEvent", _SC(".s"));
|
||||
/*#
|
||||
Func: PlatformBillingRestorePurchases
|
||||
Proto: void:
|
||||
Desc: Restore all managed purchases. The billing event callback will be called for each purchase ever made by the current user with the event string "Restored".
|
||||
#*/
|
||||
sq_register(vm, PlatformBillingRestorePurchases, "PlatformBillingRestorePurchases", _SC("."));
|
||||
/*#
|
||||
Func: PlatformBillingRequestPurchase
|
||||
Proto: void:String id
|
||||
Desc: Launch a purchase intent for the specified virtual good identifier. Returns true of the intent was successfully launched. Results will be transmitted to you through the global 'OnBillingEvent(String event, String item)' script callback.
|
||||
#*/
|
||||
sq_register(vm, PlatformBillingRequestPurchase, "PlatformBillingRequestPurchase", _SC(".s"));
|
||||
/*#
|
||||
Func: PlatformBillingIsSupported
|
||||
Proto: bool:
|
||||
Desc: Returns true if the current platform supports in-app billing (in-app purchase).
|
||||
#*/
|
||||
sq_register(vm, PlatformBillingIsSupported, "PlatformBillingIsSupported", _SC("."));
|
||||
/*#
|
||||
Func: PlatformGetLocale
|
||||
Proto: String:
|
||||
Desc: Return the current platform locale ISO2 code string (ISO 3166 two-character alphabetic code).
|
||||
#*/
|
||||
sq_register(vm, PlatformGetLocale, "PlatformGetLocale", _SC("."));
|
||||
|
||||
/*#
|
||||
Section: SystemAnalytics
|
||||
Desc: Analytics
|
||||
#*/
|
||||
/*#
|
||||
Func: PlatformAnalyticsLogEvent
|
||||
Proto: void:String name
|
||||
Desc: Log a named analytics event.
|
||||
#*/
|
||||
sq_register(vm, PlatformAnalyticsLogEvent, "PlatformAnalyticsLogEvent", _SC(".s"));
|
||||
/*#
|
||||
Func: PlatformAnalyticsServeFullscreenAd
|
||||
Proto: void:String location
|
||||
Desc: Serve a fullscreen ad, the location string is used as a marker to track the location of the display.
|
||||
#*/
|
||||
sq_register(vm, PlatformAnalyticsServeFullscreenAd, "PlatformAnalyticsServeFullscreenAd", _SC(".s"));
|
||||
|
||||
/*#
|
||||
Section: SystemHardware
|
||||
Desc: Host device
|
||||
#*/
|
||||
/*#
|
||||
Func: PlatformGetName
|
||||
Proto: String:
|
||||
Desc: Return the platform name (eg. "Win32", "iOS", "Android", ...).
|
||||
Note: A platform may run on several devices.
|
||||
fd See: PlatformGetDeviceName
|
||||
#*/
|
||||
sq_register(vm, PlatformGetDeviceName, "PlatformGetDeviceName", _SC("."));
|
||||
/*#
|
||||
Func: PlatformGetDeviceName
|
||||
Proto: String:
|
||||
Desc: Return the device name the platform is currently running on (eg. "iPad", "iPhone").
|
||||
#*/
|
||||
sq_register(vm, PlatformGetDeviceName, "PlatformGetDeviceName", _SC("."));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
241
include/modules/script_squirrel/legacy/profiler_binding.cpp
Normal file
241
include/modules/script_squirrel/legacy/profiler_binding.cpp
Normal file
@ -0,0 +1,241 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
2023 Emmanuel Julien
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
#include "binding_helpers.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct CallId {
|
||||
SQUserPointer caller; // caller funcid, 0 means native call
|
||||
SQUserPointer funcid;
|
||||
};
|
||||
|
||||
typedef uint64_t time_ns;
|
||||
|
||||
static time_ns get_clock() {
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
|
||||
typedef uint32_t CallIdx;
|
||||
|
||||
struct Call {
|
||||
CallId id;
|
||||
time_ns start;
|
||||
time_ns total{0};
|
||||
uint32_t hit{0}; // number of time this call was performed
|
||||
std::vector<CallIdx> child_calls; // [EJ] this is wasteful and inefficient
|
||||
};
|
||||
|
||||
struct FuncInfo {
|
||||
std::string name;
|
||||
std::string source;
|
||||
};
|
||||
|
||||
struct VMProfile {
|
||||
std::map<SQUserPointer, FuncInfo> func_info;
|
||||
|
||||
std::vector<Call> all_calls;
|
||||
CallIdx call_count{0};
|
||||
|
||||
std::vector<CallIdx> root_calls;
|
||||
std::vector<CallIdx> callstack; // current callstack
|
||||
};
|
||||
|
||||
static std::map<HSQUIRRELVM, VMProfile> vm_profiles;
|
||||
|
||||
static CallIdx find_call(std::vector<Call> &all_calls, std::vector<CallIdx> &calls, CallId call_id) {
|
||||
for (CallIdx i : calls) {
|
||||
const Call &call = all_calls[i];
|
||||
if (call.id.caller == call_id.caller && call.id.funcid == call_id.funcid) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct CallProfile {
|
||||
uint32_t hit; // number of calls
|
||||
time_ns total; // duration of all calls
|
||||
time_ns child; // duration of all child calls
|
||||
};
|
||||
|
||||
static CallProfile get_call_profile(const std::vector<Call> &all_calls, const Call &call) {
|
||||
CallProfile profile;
|
||||
profile.hit = call.hit;
|
||||
profile.total = call.total;
|
||||
profile.child = 0;
|
||||
|
||||
for (const CallIdx i : call.child_calls) {
|
||||
profile.child += all_calls[i].total;
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
static CallProfile get_calls_profile(const std::vector<Call> &all_calls, const std::vector<CallIdx> &idxs) {
|
||||
CallProfile profile;
|
||||
profile.hit = 0;
|
||||
profile.total = 0;
|
||||
profile.child = 0;
|
||||
|
||||
for (const auto idx : idxs) {
|
||||
const CallProfile call_profile = get_call_profile(all_calls, all_calls[idx]);
|
||||
profile.hit += call_profile.hit;
|
||||
profile.total += call_profile.total;
|
||||
profile.child += call_profile.child;
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
static void native_hook(HSQUIRRELVM vm, SQInteger event_type, const SQChar *sourcename, SQInteger line, const SQChar *funcname) {
|
||||
VMProfile &profile = vm_profiles[vm];
|
||||
|
||||
const time_ns time = get_clock();
|
||||
|
||||
if (event_type == 'l') { // line execution
|
||||
// TODO reimplement if ever needed
|
||||
} else if (event_type == 'c') { // function call
|
||||
SQFunctionInfo fi;
|
||||
sq_getfunctioninfo(vm, 0, &fi);
|
||||
|
||||
if (profile.func_info.find(fi.funcid) == std::end(profile.func_info)) {
|
||||
FuncInfo &info = profile.func_info[fi.funcid];
|
||||
info.name = fi.name;
|
||||
info.source = fi.source;
|
||||
}
|
||||
|
||||
//
|
||||
CallId call_id = {nullptr, fi.funcid};
|
||||
|
||||
std::vector<CallIdx> *child_calls = &profile.root_calls;
|
||||
|
||||
if (!profile.callstack.empty()) {
|
||||
Call &call = profile.all_calls[profile.callstack.back()];
|
||||
|
||||
call_id.caller = call.id.funcid;
|
||||
child_calls = &call.child_calls;
|
||||
}
|
||||
|
||||
//
|
||||
CallIdx i = find_call(profile.all_calls, *child_calls, call_id);
|
||||
|
||||
if (i == 0) {
|
||||
i = ++profile.call_count;
|
||||
child_calls->push_back(i);
|
||||
|
||||
profile.all_calls.resize(profile.call_count + 1); // allocate call object
|
||||
}
|
||||
|
||||
Call &call = profile.all_calls[i];
|
||||
call.id = call_id;
|
||||
call.start = time;
|
||||
++call.hit;
|
||||
|
||||
profile.callstack.push_back(i);
|
||||
} else if (event_type == 'r') { // returning from a function
|
||||
if (!profile.callstack.empty()) {
|
||||
Call &call = profile.all_calls[profile.callstack.back()];
|
||||
|
||||
const time_ns duration = time - call.start;
|
||||
call.total += duration;
|
||||
|
||||
profile.callstack.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool save_profile(HSQUIRRELVM vm, const char *path) {
|
||||
const auto i = vm_profiles.find(vm);
|
||||
|
||||
if (i == std::end(vm_profiles)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const VMProfile &profile = i->second;
|
||||
|
||||
// build a set of all functions (source + name) called during the profile
|
||||
// note: funcid is not unique in GS, probably because all scripts use a custom context in which the script is reloaded
|
||||
std::set<std::string> ids;
|
||||
|
||||
for (const auto &i : profile.func_info) {
|
||||
ids.insert(i.second.source + ":" + i.second.name);
|
||||
}
|
||||
|
||||
// compute timings for each function
|
||||
std::map<std::string, CallProfile> func_profiles;
|
||||
|
||||
for (const auto &id : ids) {
|
||||
std::vector<CallIdx> idxs;
|
||||
|
||||
for (size_t i = 1; i < profile.all_calls.size(); ++i) {
|
||||
const Call &call = profile.all_calls[i];
|
||||
|
||||
const FuncInfo &info = profile.func_info.find(call.id.funcid)->second;
|
||||
if (id == info.source + ":" + info.name) {
|
||||
idxs.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
func_profiles[id] = get_calls_profile(profile.all_calls, idxs);
|
||||
}
|
||||
|
||||
// output to CSV
|
||||
std::ofstream csv(path);
|
||||
csv << "function,total,children,self,hit,ntotal,nself" << std::endl;
|
||||
|
||||
for (const auto &i : func_profiles) {
|
||||
csv << i.first << ",";
|
||||
|
||||
const CallProfile &call_profile = i.second;
|
||||
|
||||
const time_ns self = call_profile.total - call_profile.child;
|
||||
|
||||
csv << call_profile.total << ",";
|
||||
csv << call_profile.child << ",";
|
||||
csv << self << ",";
|
||||
csv << call_profile.hit << ",";
|
||||
csv << call_profile.total / call_profile.hit << ",";
|
||||
csv << self / call_profile.hit;
|
||||
|
||||
csv << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
SQInteger StartProfiler(HSQUIRRELVM vm) {
|
||||
sq_setnativedebughook(vm, native_hook);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQInteger SaveProfile(HSQUIRRELVM vm) {
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(path)
|
||||
const bool res = save_profile(vm, path);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(res)
|
||||
}
|
||||
|
||||
SQInteger StopProfiler(HSQUIRRELVM vm) {
|
||||
sq_setnativedebughook(vm, nullptr);
|
||||
vm_profiles.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
void RegisterProfilerBinding(HSQUIRRELVM vm) {
|
||||
GS::Script::sq_register(vm, StartProfiler, "StartProfiler", _SC("."));
|
||||
GS::Script::sq_register(vm, SaveProfile, "SaveProfile", _SC(".s"));
|
||||
GS::Script::sq_register(vm, StopProfiler, "StopProfiler", _SC("."));
|
||||
}
|
||||
493
include/modules/script_squirrel/legacy/project_binding.cpp
Normal file
493
include/modules/script_squirrel/legacy/project_binding.cpp
Normal file
@ -0,0 +1,493 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/legacy/binding_helpers.h"
|
||||
#include "project/project.h"
|
||||
#include "scene3d/scene.h"
|
||||
#include "ui/ui_camera.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Core;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectGetClock(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_RETURNSAFEPTR(project->clock.c_ptr(), typetag_Clock)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectSetAll2DLayerOffset(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETFLOAT(x)
|
||||
__SQ_GETFLOAT(y)
|
||||
__SQ_GETEND
|
||||
|
||||
ListForeachPtr(ProjectLayer *, layer, project->layer_list)
|
||||
if (layer->inst)
|
||||
if (S2D::Scene *scene = layer->inst->instance_2d)
|
||||
{
|
||||
scene->offset_matrix = Matrix3::IdentityMatrix();
|
||||
scene->offset_matrix.m[0][2] = x / scene->GetCurrentCamera()->resolution.x;
|
||||
scene->offset_matrix.m[1][2] = y / scene->GetCurrentCamera()->resolution.y;
|
||||
}
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectLayerGetScene(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(layer, ProjectLayer, typetag_ProjectLayer)
|
||||
if (!layer->inst)
|
||||
return sq_throwerror(vm, "No scene in project layer");
|
||||
__SQ_RETURNSAFEPTR(layer->inst, typetag_ProjectScene)
|
||||
}
|
||||
SQInteger ProjectLayerSetZOrder(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(layer, ProjectLayer, typetag_ProjectLayer)
|
||||
__SQ_GETFLOAT(zorder)
|
||||
__SQ_GETEND
|
||||
layer->zorder = zorder;
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ProjectLayerGetZOrder(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(layer, ProjectLayer, typetag_ProjectLayer)
|
||||
__SQ_RETURNFLOAT(layer->zorder)
|
||||
}
|
||||
SQInteger ProjectAddLayer(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSAFEPTR(instance, ProjectSceneInstance, typetag_ProjectScene)
|
||||
__SQ_GETFLOAT(zorder)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(project->AddLayer(instance, zorder), typetag_ProjectLayer)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectNewScene3D(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_RETURNMANAGEDSAFEPTR(project->Instantiate(new S3D::Scene(project->vm)), typetag_ProjectScene)
|
||||
}
|
||||
SQInteger ProjectNewScene2D(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_RETURNMANAGEDSAFEPTR(project->Instantiate(new S2D::Scene(project->vm)), typetag_ProjectScene)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectGetSceneLayerList(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSAFEPTR(scene, ProjectSceneInstance, typetag_ProjectScene)
|
||||
__SQ_GETEND
|
||||
|
||||
sq_newarray(vm, 0);
|
||||
for (uint n = 0; n < project->layer_list.GetCount(); ++n)
|
||||
{
|
||||
ProjectLayer *layer = project->layer_list[n];
|
||||
if (layer->inst == scene)
|
||||
{
|
||||
CObject::Push(vm, (void *)layer, typetag_ProjectLayer);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
SQInteger ProjectInstantiateScene(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSTRING(path)
|
||||
sq_collectgarbage(vm);
|
||||
ProjectSceneInstance *project_scene = project->Instantiate(path);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(project_scene, typetag_ProjectScene)
|
||||
}
|
||||
SQInteger ProjectSceneIsActive(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSAFEPTR(scene, ProjectSceneInstance, typetag_ProjectScene)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(project && scene ? project->IsActive(*scene) : false)
|
||||
}
|
||||
SQInteger ProjectSceneActivate(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSAFEPTR(scene, ProjectSceneInstance, typetag_ProjectScene)
|
||||
__SQ_GETBOOL(active)
|
||||
__SQ_GETEND
|
||||
project->Activate(*scene, active ? true : false);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ProjectUnloadScene(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSAFEPTR(scene, ProjectSceneInstance, typetag_ProjectScene)
|
||||
__SQ_GETEND
|
||||
project->Delete(scene);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ProjectFindScene(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSTRING(path)
|
||||
ProjectSceneInstance *inst = project->FindSceneInstance(path);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(inst, typetag_ProjectScene)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectSceneGetType(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(scene, ProjectSceneInstance, typetag_ProjectScene)
|
||||
__SQ_RETURNINT(scene->GetType())
|
||||
}
|
||||
SQInteger ProjectSceneGetInstance(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(scene, ProjectSceneInstance, typetag_ProjectScene)
|
||||
|
||||
switch (scene->GetType())
|
||||
{
|
||||
case ProjectSceneInstance::Type_Scene2d:
|
||||
__SQ_RETURNSAFEPTR(scene->instance_2d, typetag_Scene2d)
|
||||
case ProjectSceneInstance::Type_Scene3d:
|
||||
__SQ_RETURNSAFEPTR(scene->instance_3d, typetag_Scene3d)
|
||||
|
||||
default: break;
|
||||
}
|
||||
return sq_throwerror(vm, "Invalid project scene");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectGetFileName(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_RETURNSTRING(project->name.CutFilePath().toUtf8())
|
||||
}
|
||||
SQInteger ProjectGetFilePath(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_RETURNSTRING(project->name.CutFileName().toUtf8())
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectSceneSetGlobal(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(scene, ProjectSceneInstance, typetag_ProjectScene)
|
||||
if (scene && (scene->GetType() == ProjectSceneInstance::Type_Scene3d))
|
||||
scene->instance_3d->SetAsScriptGlobalScene();
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ProjectGetScriptInstance(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(project, Project, typetag_Project)
|
||||
if (!project)
|
||||
return sq_suspendvm(vm);
|
||||
if (!project->script_unit->Self())
|
||||
return sq_throwerror(vm, "No script assigned to this project.");
|
||||
__SQ_RETURNOBJECT(((Script::SquirrelObject *)project->script_unit->Self())->object);
|
||||
}
|
||||
SQInteger ProjectEnd(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(project, Project, typetag_Project)
|
||||
if (project)
|
||||
project->flags.Set(Project::ProjectFlagEnd);
|
||||
// exit(0);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ProjectLoadFont(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSTRING(path)
|
||||
FontEx *font = project->font_cache->LoadFont(path);
|
||||
if (!font)
|
||||
return sq_throwerror(vm, String::Format("Failed to load font '%s'.", path));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(font, typetag_Font)
|
||||
}
|
||||
SQInteger ProjectLoadFontAliased(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSTRING(path)
|
||||
__SQ_GETSTRING(alias)
|
||||
FontEx *font = project->font_cache->LoadFont(path, alias);
|
||||
if (!font)
|
||||
return sq_throwerror(vm, String::Format("Failed to load font '%s' under alias '%s'.", path, alias));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(font, typetag_Font)
|
||||
}
|
||||
SQInteger ProjectDeleteFontAlias(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSTRING(alias)
|
||||
project->font_cache->DeleteAlias(alias);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger ProjectGetFont(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(project, Project, typetag_Project)
|
||||
__SQ_GETSTRING(path)
|
||||
FontEx *font = project->font_cache->GetAliasedFont(path);
|
||||
if (!font)
|
||||
return sq_throwerror(vm, String::Format("Font '%s' not found.", path));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(font, typetag_Font)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterProjectBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Project
|
||||
Type: Project
|
||||
Type: ProjectLayer
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: ProjectGeneral
|
||||
Desc: General project functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ProjectGetClock
|
||||
Proto: Clock:Project
|
||||
Desc: Get the project clock object.
|
||||
#*/
|
||||
sq_register(vm, ProjectGetClock, "ProjectGetClock", _SC(".x"));
|
||||
/*#
|
||||
Func: ProjectGetScriptInstance
|
||||
Proto: Instance:Project
|
||||
Desc: Get the project script instance.
|
||||
#*/
|
||||
sq_register(vm, ProjectGetScriptInstance, "ProjectGetScriptInstance", _SC(".x"));
|
||||
/*#
|
||||
Func: ProjectEnd
|
||||
Proto: void:Project
|
||||
Desc: Exit project.
|
||||
#*/
|
||||
sq_register(vm, ProjectEnd, "ProjectEnd", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: ProjectFontManagement
|
||||
Desc: UI Font management functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ProjectLoadFont
|
||||
Proto: Font:Project, string path
|
||||
Desc: Load a TrueType font in the project font cache.
|
||||
#*/
|
||||
sq_register(vm, ProjectLoadFont, "ProjectLoadFont", _SC(".xs"));
|
||||
sq_register(vm, ProjectLoadFont, "ProjectLoadUIFont", _SC(".xs"));
|
||||
/*#
|
||||
Func: ProjectLoadFontAliased
|
||||
Proto: Font:Project, string path, string alias
|
||||
Desc: Load a TrueType font under a specific alias.
|
||||
#*/
|
||||
sq_register(vm, ProjectLoadFontAliased, "ProjectLoadFontAliased", _SC(".xss"));
|
||||
sq_register(vm, ProjectLoadFontAliased, "ProjectLoadUIFontAliased", _SC(".xss"));
|
||||
/*#
|
||||
Func: ProjectDeleteFontAlias
|
||||
Proto: void:Project, string alias
|
||||
Desc: Delete a font alias from the font cache.
|
||||
#*/
|
||||
sq_register(vm, ProjectDeleteFontAlias, "ProjectDeleteFontAlias", _SC(".xs"));
|
||||
sq_register(vm, ProjectDeleteFontAlias, "ProjectDeleteUIFontAlias", _SC(".xs"));
|
||||
/*#
|
||||
Func: ProjectGetFont
|
||||
Proto: Font:Project, string name
|
||||
Desc: Retrieve a font from its name.
|
||||
#*/
|
||||
sq_register(vm, ProjectGetFont, "ProjectGetFont", _SC(".xs"));
|
||||
sq_register(vm, ProjectGetFont, "ProjectGetUIFont", _SC(".xs"));
|
||||
|
||||
/*#
|
||||
Section: ProjectLayerManagement
|
||||
Desc: Layer management functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ProjectLayerGetScene
|
||||
Proto: ProjectScene:ProjectLayer
|
||||
Desc: Return the scene instance a layer is displaying.
|
||||
#*/
|
||||
sq_register(vm, ProjectLayerGetScene, "ProjectLayerGetScene", _SC(".x"));
|
||||
/*#
|
||||
Func: ProjectAddLayer
|
||||
Proto: ProjectLayer:Project,ProjectScene,float zorder
|
||||
Desc: Create a new layer to display a project scene.
|
||||
Note: A scene can be added to several layers at once.
|
||||
#*/
|
||||
sq_register(vm, ProjectAddLayer, "ProjectAddLayer", _SC(".xxn"));
|
||||
/*#
|
||||
Func: ProjectLayerSetZOrder
|
||||
Proto: void:ProjectLayer,float
|
||||
Desc: Set layer Z order.
|
||||
Note: Smaller Z values are closer to the viewer.
|
||||
#*/
|
||||
sq_register(vm, ProjectLayerSetZOrder, "ProjectLayerSetZOrder", _SC(".xn"));
|
||||
/*#
|
||||
Func: ProjectLayerGetZOrder
|
||||
Proto: float:ProjectLayer
|
||||
Desc: Get layer Z order.
|
||||
#*/
|
||||
sq_register(vm, ProjectLayerGetZOrder, "ProjectLayerGetZOrder", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: ProjectSetAll2DLayerOffset
|
||||
Proto: void:Project,float x,float y
|
||||
Desc: Set the offset of all 2d layer in the current project stack. The offset is specified in the layer reference resolution.
|
||||
#*/
|
||||
sq_register(vm, ProjectSetAll2DLayerOffset, "ProjectSetAll2DLayerOffset", _SC(".xnn"));
|
||||
|
||||
/*#
|
||||
Section: ProjectSceneManagement
|
||||
Desc: Scene management functions
|
||||
#*/
|
||||
/*#
|
||||
Func: ProjectNewScene3D
|
||||
Proto: ProjectScene:Project
|
||||
Desc: Create a new scene 3D.
|
||||
Note: You need to add the newly created scene to a project layer to display it.
|
||||
Example:
|
||||
local project_scene = ProjectNewScene3D(g_project)
|
||||
ProjectAddLayer(g_project, project_scene, 0.5) // add the 3d scene to a project layer with Z offset of 0.5
|
||||
#*/
|
||||
sq_register(vm, ProjectNewScene3D, "ProjectNewScene", _SC(".x"));
|
||||
sq_register(vm, ProjectNewScene3D, "ProjectNewScene3D", _SC(".x"));
|
||||
/*#
|
||||
Func: ProjectNewScene2D
|
||||
Proto: ProjectScene:Project
|
||||
Desc: Create a new scene 2D.
|
||||
Note: You need to add the newly created scene to a project layer to display it.
|
||||
Example:
|
||||
local project_scene = ProjectNewScene2D(g_project)
|
||||
ProjectAddLayer(g_project, project_scene, 0.5) // add the 2d scene to a project layer with Z offset of 0.5
|
||||
#*/
|
||||
sq_register(vm, ProjectNewScene2D, "ProjectNewScene2D", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: ProjectFindScene
|
||||
Proto: ProjectScene:Project,string path
|
||||
Desc: Returns an instance of a specific scene in the project, returns an invalid object if no such instance could be found.
|
||||
#*/
|
||||
sq_register(vm, ProjectFindScene, "ProjectFindScene", _SC(".xs"));
|
||||
/*#
|
||||
Func: ProjectGetSceneLayerList
|
||||
Proto: Array:Project,ProjectScene
|
||||
Desc: Return all the project layers displaying a specific scene instance. A scene might be displayed by several different layers (eg. in order to display a split-screen view).
|
||||
#*/
|
||||
sq_register(vm, ProjectGetSceneLayerList, "ProjectGetSceneLayerList", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Func: ProjectSceneIsActive
|
||||
Proto: bool:Project,ProjectScene
|
||||
Desc: Return the active state of a project scene.
|
||||
#*/
|
||||
sq_register(vm, ProjectSceneIsActive, "ProjectSceneIsActive", _SC(".xx"));
|
||||
sq_register(vm, ProjectSceneIsActive, "ProjectIsSceneActive", _SC(".xx"));
|
||||
/*#
|
||||
Func: ProjectSceneActivate
|
||||
Proto: void:Project,ProjectScene,bool
|
||||
Desc: Activate or deactivate a project scene. When deactivated a scene is not updated or displayed anymore.
|
||||
#*/
|
||||
sq_register(vm, ProjectSceneActivate, "ProjectSceneActivate", _SC(".xxb"));
|
||||
sq_register(vm, ProjectSceneActivate, "ProjectActivateScene", _SC(".xxb"));
|
||||
/*#
|
||||
Func: ProjectInstantiateScene
|
||||
Proto: ProjectScene:Project,string path
|
||||
Desc: Instantiate a project scene.
|
||||
Note: You need to add the project scene to a layer to display it. This function will detect the type of scene to instantiate, 2d or 3d, from the input file.
|
||||
See: ProjectSceneGetType, ProjectDeleteScene
|
||||
Example:
|
||||
local project_scene = ProjectInstantiateScene(g_project, "scene_file.nms")
|
||||
ProjectAddLayer(g_project, project_scene, 0.5)
|
||||
#*/
|
||||
sq_register(vm, ProjectInstantiateScene, "ProjectInstantiateScene", _SC(".xs"));
|
||||
/*#
|
||||
Func: ProjectSceneSetGlobal
|
||||
Proto: void:ProjectScene
|
||||
Desc: Register scene as the global scene script object (g_scene).
|
||||
Note: The project automatically updates g_scene before updating or displaying a scene.
|
||||
#*/
|
||||
sq_register(vm, ProjectSceneSetGlobal, "ProjectSceneSetGlobal", _SC(".x"));
|
||||
/*#
|
||||
Func: ProjectDeleteScene
|
||||
Proto: void:Project,ProjectScene
|
||||
Desc: Delete a project scene.
|
||||
Note: All layers displaying this scene will be destroyed as well.
|
||||
#*/
|
||||
sq_register(vm, ProjectUnloadScene, "ProjectDeleteScene", _SC(".xx"));
|
||||
sq_register(vm, ProjectUnloadScene, "ProjectUnloadScene", _SC(".xx"));
|
||||
/*#
|
||||
Func: ProjectSceneGetType
|
||||
Proto: ProjectSceneType:ProjectScene
|
||||
Desc: Get a project scene type.
|
||||
#*/
|
||||
sq_register(vm, ProjectSceneGetType, "ProjectSceneGetType", _SC(".x"));
|
||||
/*#
|
||||
Func: ProjectSceneGetInstance
|
||||
Proto: Scene:ProjectScene
|
||||
Desc: Get the scene object of type Scene or UI from a project scene object.
|
||||
Example:
|
||||
local scene = ProjectSceneGetInstace(project_scene) // this project scene encapsulates a 3d scene
|
||||
SceneAddLight(scene, "MyLight")
|
||||
#*/
|
||||
sq_register(vm, ProjectSceneGetInstance, "ProjectSceneGetInstance", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: ProjectGetFileName
|
||||
Proto: String:Project
|
||||
Desc: Return the project file name, without the project path.
|
||||
See: ProjectGetFilePath
|
||||
#*/
|
||||
sq_register(vm, ProjectGetFileName, "ProjectGetFileName", _SC(".x"));
|
||||
/*#
|
||||
Func: ProjectGetFilePath
|
||||
Proto: String:Project
|
||||
Desc: Return the project path.
|
||||
See: ProjectGetFileName
|
||||
#*/
|
||||
sq_register(vm, ProjectGetFilePath, "ProjectGetFilePath", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Enum: ProjectSceneType
|
||||
Values: ProjectSceneTypeScene2d,ProjectSceneTypeScene3d
|
||||
#*/
|
||||
sq_pushstring(vm, "ProjectSceneTypeScene2d", -1); sq_pushinteger(vm, ProjectSceneInstance::Type_Scene2d); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "ProjectSceneTypeScene3d", -1); sq_pushinteger(vm, ProjectSceneInstance::Type_Scene3d); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pushstring(vm, "NullItem", -1); CObject::Push(vm, NULL, typetag_Item); sq_newslot(vm, -3, true);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
165
include/modules/script_squirrel/legacy/raytracer_binding.cpp
Normal file
165
include/modules/script_squirrel/legacy/raytracer_binding.cpp
Normal file
@ -0,0 +1,165 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "raytracer/raytracer_core.h"
|
||||
#include "core/graphic_resource_factory.h"
|
||||
#include "core/resource_factories.h"
|
||||
#include "core/geometry.h"
|
||||
#include "picture/pict_io.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
using namespace GS::Raytrace;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger NewRaytracer(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(f, Core::ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_RETURNSAFEPTR(new Raytracer(f->graphic), typetag_Raytracer)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger RaytracerSetScene(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(ray, Raytracer, typetag_Raytracer)
|
||||
__SQ_GETSAFEPTR(scn, S3D::Scene, typetag_Scene3d)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL((ray && scn) ? ray->SetScene(scn) : false)
|
||||
}
|
||||
SQInteger RaytracerTrace(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETSAFEPTR(ray, Raytracer, typetag_Raytracer)
|
||||
__SQ_GETSTRING(file)
|
||||
__SQ_GETINT(width)
|
||||
__SQ_GETINT(height)
|
||||
|
||||
bool r = false;
|
||||
Picture output(width, height);
|
||||
if (ray->Render(output, width, height))
|
||||
r = output.isValid() ? PictureIO::Get().TgaSave(output, file) : false;
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger RaytracerSetInterlace(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(ray, Raytracer, typetag_Raytracer)
|
||||
__SQ_GETBOOL(interlaced)
|
||||
__SQ_GETBOOL(interlace_even)
|
||||
__SQ_GETEND
|
||||
|
||||
Configuration config = ray->GetConfiguration();
|
||||
config.interlaced = interlaced ? true : false;
|
||||
config.interlace_even = interlace_even ? true : false;
|
||||
ray->SetConfiguration(config);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger RaytracerSetAntialias(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(5)
|
||||
__SQ_GETSAFEPTR(ray, Raytracer, typetag_Raytracer)
|
||||
__SQ_GETBOOL(trace_aa)
|
||||
__SQ_GETINT(aa_sample)
|
||||
__SQ_GETFLOAT(aa_threshold)
|
||||
__SQ_GETBOOL(aa_jitter)
|
||||
__SQ_GETEND
|
||||
|
||||
Configuration config = ray->GetConfiguration();
|
||||
config.trace_aa = trace_aa ? true : false;
|
||||
config.aa_sample = aa_sample;
|
||||
config.aa_threshold = aa_threshold;
|
||||
config.aa_jitter = aa_jitter ? true : false;
|
||||
ray->SetConfiguration(config);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger RaytracerSetGlobalIllum(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(4)
|
||||
__SQ_GETSAFEPTR(ray, Raytracer, typetag_Raytracer)
|
||||
__SQ_GETBOOL(trace_gi)
|
||||
__SQ_GETINT(gi_sample)
|
||||
__SQ_GETINT(indirect_gi_bounce)
|
||||
__SQ_GETEND
|
||||
|
||||
Configuration config = ray->GetConfiguration();
|
||||
config.trace_gi = trace_gi ? true : false;
|
||||
config.gi_sample = gi_sample;
|
||||
config.indirect_gi_bounce = indirect_gi_bounce;
|
||||
ray->SetConfiguration(config);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger RaytracerStartInterlacedSequence(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(ray, Raytracer, typetag_Raytracer)
|
||||
ray->StartInterlacedSequence();
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterRaytracerBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Raytracer
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: RaytracerGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
/*#
|
||||
Func: NewRaytracer
|
||||
Proto: Raytracer:ResourceFactory
|
||||
Desc: Create a new raytracer instance.
|
||||
#*/
|
||||
sq_register(vm, NewRaytracer, "NewRaytracer", _SC(".x"));
|
||||
/*#
|
||||
Func: RaytracerSetAntialias
|
||||
Proto: void:raytracer,bool enable,int sample_count,float threshold,bool jitter
|
||||
Desc: Set the raytracer antialias output. The number of AA sample can be set and jitered AA selected. Default threshold: 0.015.
|
||||
#*/
|
||||
sq_register(vm, RaytracerSetAntialias, "RaytracerSetAntialias", _SC(".xbinb"));
|
||||
/*#
|
||||
Func: RaytracerSetGlobalIllum
|
||||
Proto: void:raytracer,bool enable,int sample_count,int max_indirect_bounce
|
||||
Desc: Enable the raytracer global illumination. The number of GI sample can be set as well as a maximum number of indirect bounce.
|
||||
#*/
|
||||
sq_register(vm, RaytracerSetGlobalIllum, "RaytracerSetGlobalIllum", _SC(".xbii"));
|
||||
/*#
|
||||
Func: RaytracerSetInterlace
|
||||
Proto: void:raytracer,bool interlaced,bool even_frame
|
||||
Desc: Set the raytracer interlace output. The frame parity is specified as the second parameter.
|
||||
#*/
|
||||
sq_register(vm, RaytracerSetInterlace, "RaytracerSetInterlace", _SC(".xbb"));
|
||||
/*#
|
||||
Func: RaytracerStartInterlacedSequence
|
||||
Proto: void:raytracer
|
||||
Desc: Start an interlaced sequence. This function should be called when beginning a new sequence in order to ensure correct frame parity.
|
||||
#*/
|
||||
sq_register(vm, RaytracerStartInterlacedSequence, "RaytracerStartInterlacedSequence", _SC(".x"));
|
||||
/*#
|
||||
Func: RaytracerSetScene
|
||||
Proto: void:raytracer,scene
|
||||
Desc: Set raytracer scene, this function might be a little slow as it setups a lot data to work with.
|
||||
#*/
|
||||
sq_register(vm, RaytracerSetScene, "RaytracerSetScene", _SC(".xx"));
|
||||
/*#
|
||||
Func: RaytracerTrace
|
||||
Proto: void:raytracer,string out_picture,int width,int height
|
||||
Desc: Raytrace current scene to a Targa picture file. Note that when rendering interlaced sequences one of two calls to this function will return false to notify you that the current frame was only buffered and not saved.
|
||||
#*/
|
||||
sq_register(vm, RaytracerTrace, "RaytracerTrace", _SC(".xsii"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
1354
include/modules/script_squirrel/legacy/renderer_binding.cpp
Normal file
1354
include/modules/script_squirrel/legacy/renderer_binding.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,288 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "script_squirrel/cobject/matrix_decl.h"
|
||||
#include "core/resource_factories.h"
|
||||
#include "core/graphic_resource_factory.h"
|
||||
#include "core/render_resource_factory.h"
|
||||
#include "core/mixer_resource_factory.h"
|
||||
#include "core/raster_font.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Core;
|
||||
using namespace GS::Script;
|
||||
using namespace GS::Render;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryLoadPicture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
Picture *p = f->graphic->LoadPicture(name);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(p, typetag_Picture)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryLoadRasterFont(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(base)
|
||||
__SQ_GETSTRING(name)
|
||||
RasterFont *font = new RasterFont;
|
||||
if (!font)
|
||||
return sq_throwerror(vm, "Failed to allocate raster font object.");
|
||||
font->Load(*f->render, base, name);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNMANAGEDSAFEPTR(font, typetag_RasterFont)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryNewTexture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
Texture *t = f->render->NewTexture();
|
||||
__SQ_RETURNSAFEPTR(t, typetag_Texture)
|
||||
}
|
||||
SQInteger ResourceFactoryLoadTexture(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
Texture *t = f->render->LoadTexture(name);
|
||||
if (!t)
|
||||
return sq_throwerror(vm, String::Format("Texture '%s' not found.", name));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(t, typetag_Texture)
|
||||
}
|
||||
SQInteger ResourceFactoryLoadTextureEx(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETBOOL(bypass_cache)
|
||||
Texture *t = f->render->LoadTexture(name, asbool(bypass_cache));
|
||||
if (!t)
|
||||
return sq_throwerror(vm, String::Format("Texture '%s' not found.", name));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(t, typetag_Texture)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryLoadShader(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
Render::Shader *s = f->render->LoadShader(name);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(s, typetag_Shader)
|
||||
}
|
||||
SQInteger ResourceFactoryLoadShaderEx(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETBOOL(bypass_cache)
|
||||
Render::Shader *s = f->render->LoadShader(name, asbool(bypass_cache));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(s, typetag_Shader)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryLoadGeometry(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
Render::Geometry *g = f->render->LoadGeometry(name);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(g, typetag_Geometry)
|
||||
}
|
||||
SQInteger ResourceFactoryLoadGeometryEx(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETBOOL(bypass_cache)
|
||||
Render::Geometry *g = f->render->LoadGeometry(name, asbool(bypass_cache));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(g, typetag_Geometry)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryLoadMaterial(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
Render::Material *m = f->render->LoadMaterial(name);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(m, typetag_Material)
|
||||
}
|
||||
SQInteger ResourceFactoryLoadMaterialEx(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
__SQ_GETBOOL(bypass_cache)
|
||||
Render::Material *m = f->render->LoadMaterial(name, asbool(bypass_cache));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(m, typetag_Material)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryLoadSound(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
__SQ_GETSTRING(name)
|
||||
Audio::Sound *s = f->audio->LoadSound(name);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNSAFEPTR(s, typetag_Sound)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger ResourceFactoryPurge(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(f, ResourceFactories, typetag_ResourceFactories)
|
||||
uint purged = 0;
|
||||
purged += f->graphic->PurgeCache();
|
||||
purged += f->render->PurgeCache();
|
||||
// purged += f->mixer->PurgeCache();
|
||||
__SQ_RETURNINT(purged)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterResourceFactoryBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Resource Factory
|
||||
Desc: A resource factory caches all graphic and render resources used by a project. You can access your project resource factory from any script by using the global variable <b>g_factory</b>.
|
||||
Type: ResourceFactory
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: ResourceFactoryGeneral
|
||||
Desc: Resource Factory General
|
||||
#*/
|
||||
/*#
|
||||
Func: ResourceFactoryPurge
|
||||
Proto: int:ResourceFactory
|
||||
Desc: Call this function to unload from memory all cached resources that are not currently in use.
|
||||
Example:
|
||||
local purged_count = ResourceFactoryPurge(g_factory)
|
||||
print("Resource unloaded: " + purged_count)
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryPurge, "ResourceFactoryPurge", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: GraphicResourceFactory
|
||||
Desc: Graphic Resources
|
||||
#*/
|
||||
/*#
|
||||
Func: ResourceFactoryLoadPicture
|
||||
Proto: Picture:ResourceFactory,String name
|
||||
Desc: Load a picture from a graphic resource factory, this function use the resource cache to prevent redundant loads of the same resource.
|
||||
See: PictureLoad
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadPicture, "ResourceFactoryLoadPicture", _SC(".xs"));
|
||||
|
||||
/*#
|
||||
Section: RenderResourceFactory
|
||||
Desc: Render Resources
|
||||
#*/
|
||||
/*#
|
||||
Func: ResourceFactoryLoadRasterFont
|
||||
Proto: RasterFont:ResourceFactory,String name
|
||||
Desc: Load a raster font from a resource factory.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadRasterFont, "ResourceFactoryLoadRasterFont", _SC(".xss"));
|
||||
|
||||
/*#
|
||||
Func: ResourceFactoryNewTexture
|
||||
Proto: Texture:ResourceFactory
|
||||
Desc: Create a new texture from a resource factory.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryNewTexture, "ResourceFactoryNewTexture", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: ResourceFactoryLoadShader
|
||||
Proto: Shader:ResourceFactory,String name
|
||||
Desc: Load a shader from a resource factory.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadShader, "ResourceFactoryLoadShader", _SC(".xs"));
|
||||
/*#
|
||||
Func: ResourceFactoryLoadShaderEx
|
||||
Proto: Shader:ResourceFactory,String name,bool bypass_cache
|
||||
Desc: Load a shader from a resource factory, optionally bypassing the factory cache.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadShaderEx, "ResourceFactoryLoadShaderEx", _SC(".xsb"));
|
||||
|
||||
/*#
|
||||
Func: ResourceFactoryLoadTexture
|
||||
Proto: Texture:ResourceFactory,String name
|
||||
Desc: Load a texture from a resource factory.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadTexture, "ResourceFactoryLoadTexture", _SC(".xs"));
|
||||
/*#
|
||||
Func: ResourceFactoryLoadTextureEx
|
||||
Proto: Texture:ResourceFactory,String name,bool bypass_cache
|
||||
Desc: Load a texture from a resource factory, optionally bypassing the factory cache.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadTextureEx, "ResourceFactoryLoadTextureEx", _SC(".xsb"));
|
||||
|
||||
/*#
|
||||
Func: ResourceFactoryLoadGeometry
|
||||
Proto: Texture:ResourceFactory,String name
|
||||
Desc: Load a geometry from a resource factory.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadGeometry, "ResourceFactoryLoadGeometry", _SC(".xs"));
|
||||
/*#
|
||||
Func: ResourceFactoryLoadGeometryEx
|
||||
Proto: Texture:ResourceFactory,String name,bool bypass_cache
|
||||
Desc: Load a geometry from a resource factory, optionally bypassing the factory cache.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadGeometryEx, "ResourceFactoryLoadGeometryEx", _SC(".xsb"));
|
||||
|
||||
/*#
|
||||
Func: ResourceFactoryLoadMaterial
|
||||
Proto: Material:ResourceFactory,String name
|
||||
Desc: Load a material from a resource factory.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadMaterial, "ResourceFactoryLoadMaterial", _SC(".xs"));
|
||||
|
||||
/*#
|
||||
Func: ResourceFactoryLoadMaterialEx
|
||||
Proto: Material:ResourceFactory,String name,bool bypass_cache
|
||||
Desc: Load a material from a resource factory, optionally bypassing the factory cache.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadMaterialEx, "ResourceFactoryLoadMaterialEx", _SC(".xsb"));
|
||||
|
||||
/*#
|
||||
Section: MixerResourceFactory
|
||||
Desc: Mixer Resources
|
||||
#*/
|
||||
/*#
|
||||
Func: ResourceFactoryLoadSound
|
||||
Proto: Sound:ResourceFactory,String name
|
||||
Desc: Load a sound from a resource factory.
|
||||
#*/
|
||||
sq_register(vm, ResourceFactoryLoadSound, "ResourceFactoryLoadSound", _SC(".xs"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
1744
include/modules/script_squirrel/legacy/scene_binding.cpp
Normal file
1744
include/modules/script_squirrel/legacy/scene_binding.cpp
Normal file
File diff suppressed because it is too large
Load Diff
44
include/modules/script_squirrel/legacy/sound_binding.cpp
Normal file
44
include/modules/script_squirrel/legacy/sound_binding.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "squirrel.h"
|
||||
#include "script_squirrel/legacy/binding_helpers.h"
|
||||
#include "core/sound.h"
|
||||
|
||||
using namespace GS::Audio;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SoundGetDuration(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(s, Sound, typetag_Sound)
|
||||
__SQ_RETURNINT(s->mixer_data.IsValid() ? s->mixer_data->Get()->duration.toMs() : -1)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterSoundBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Sound
|
||||
Desc: A sound object stores audio data that can be played back by the sound mixer.
|
||||
Type: Sound
|
||||
Related: Mixer
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: SoundGeneric
|
||||
Desc: Generic functions
|
||||
#*/
|
||||
/*#
|
||||
Func: SoundGetDuration
|
||||
Proto: int:sound
|
||||
Desc: Returns the sound duration in milliseconds.
|
||||
#*/
|
||||
sq_register(vm, SoundGetDuration, "SoundGetDuration", _SC(".x"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
549
include/modules/script_squirrel/legacy/squirrel_binding.cpp
Normal file
549
include/modules/script_squirrel/legacy/squirrel_binding.cpp
Normal file
@ -0,0 +1,549 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
#include "squirrel.h"
|
||||
#include "script_squirrel/cobject/uc_binding.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "script_squirrel/cobject/uv_decl.h"
|
||||
|
||||
#include "squirrel_binding.h"
|
||||
#include "binding_helpers.h"
|
||||
|
||||
#if __PLATFORM_NINTENDO_WII__
|
||||
#include "platform/wii/script/wii_binding.h"
|
||||
#endif
|
||||
#include "geometry/bounding_box.h"
|
||||
#include "color/color.h"
|
||||
#include "geometry/rect.h"
|
||||
#include "filesystem/filesystem.h"
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Script {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static bool BindingError(HSQUIRRELVM vm, const char *msg)
|
||||
{
|
||||
// if (sq_getforeignptr(vm))
|
||||
// ((Script::VM *)sq_getforeignptr(vm))->Kill();
|
||||
SquirrelVM::DumpCallStack(vm, String::Format("Binding error: %s", msg).c_str());
|
||||
return false;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool CreateClassInstance(HSQUIRRELVM vm, const char *class_name, bool call)
|
||||
{
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, class_name, -1);
|
||||
if (SQ_FAILED(sq_get(vm, -2)))
|
||||
{
|
||||
sq_pop(vm, 1);
|
||||
return BindingError(vm, String::Format("Class '%s' is not declared.", class_name).c_str());
|
||||
}
|
||||
if (call)
|
||||
{
|
||||
sq_pushroottable(vm);
|
||||
if (SQ_FAILED(sq_call(vm, 1, SQTrue, SQTrue)))
|
||||
{
|
||||
sq_pop(vm, 1);
|
||||
return BindingError(vm, String::Format("Failed to instantiate class '%s'.", class_name).c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
sq_createinstance(vm, -1);
|
||||
sq_remove(vm, -2); // Remove root table.
|
||||
sq_remove(vm, -2); // Remove class.
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void PushColor(HSQUIRRELVM vm, const Color &c)
|
||||
{
|
||||
if (!CreateClassInstance(vm, "Vector", true))
|
||||
BindingError(vm, "Failed to create Vector instance.");
|
||||
SetTableKey("x", sq_pushfloat, -1, c.x);
|
||||
SetTableKey("y", sq_pushfloat, -1, c.y);
|
||||
SetTableKey("z", sq_pushfloat, -1, c.z);
|
||||
SetTableKey("w", sq_pushfloat, -1, c.w);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void PushVector2(HSQUIRRELVM vm, const Vector2 &v)
|
||||
{
|
||||
if (!CreateClassInstance(vm, "Vector2", true))
|
||||
BindingError(vm, "Failed to create Vector2 instance.");
|
||||
SetTableKey("x", sq_pushfloat, -1, v.x);
|
||||
SetTableKey("y", sq_pushfloat, -1, v.y);
|
||||
}
|
||||
void GetVector2(HSQUIRRELVM vm, SQInteger idx, Vector2 &v)
|
||||
{
|
||||
SQFloat x, y;
|
||||
GetTableKey("x", sq_getfloat, idx, x)
|
||||
GetTableKey("y", sq_getfloat, idx, y)
|
||||
v.Set(x, y);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void PushVector(HSQUIRRELVM vm, const Vector4 &v, bool push_w)
|
||||
{
|
||||
push_Vector(vm, v);
|
||||
}
|
||||
void GetVector(HSQUIRRELVM v, SQInteger idx, Vector4 &vo, bool get_w)
|
||||
{
|
||||
_CHECK_INST_PARAM_RAW(pv, idx, Vector4, Vector);
|
||||
vo = *pv;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void PushUV(HSQUIRRELVM vm, const Vector2 &uv)
|
||||
{
|
||||
if (!CreateClassInstance(vm, "UV", true))
|
||||
BindingError(vm, "Failed to create UV instance.");
|
||||
SetTableKey("u", sq_pushfloat, -1, uv.x);
|
||||
SetTableKey("v", sq_pushfloat, -1, uv.y);
|
||||
}
|
||||
void GetUV(HSQUIRRELVM v, SQInteger idx, Vector2 &uv)
|
||||
{
|
||||
_CHECK_INST_PARAM_RAW(pv, idx, Vector2, UV);
|
||||
uv = *pv;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void PushMinMax(HSQUIRRELVM vm, const MinMax &v)
|
||||
{
|
||||
if (!CreateClassInstance(vm, "MinMax", true))
|
||||
BindingError(vm, "Failed to create MinMax instance.");
|
||||
|
||||
sq_pushstring(vm, "min", -1);
|
||||
sq_get(vm, -2);
|
||||
SetTableKey("x", sq_pushfloat, -1, v.mn.x)
|
||||
SetTableKey("y", sq_pushfloat, -1, v.mn.y)
|
||||
SetTableKey("z", sq_pushfloat, -1, v.mn.z)
|
||||
sq_pop(vm, 1);
|
||||
|
||||
sq_pushstring(vm, "max", -1);
|
||||
sq_get(vm, -2);
|
||||
SetTableKey("x", sq_pushfloat, -1, v.mx.x)
|
||||
SetTableKey("y", sq_pushfloat, -1, v.mx.y)
|
||||
SetTableKey("z", sq_pushfloat, -1, v.mx.z)
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
void GetMinMax(HSQUIRRELVM vm, SQInteger idx, MinMax &v)
|
||||
{
|
||||
sq_pushstring(vm, "min", -1);
|
||||
sq_get(vm, -2);
|
||||
GetVector(vm, -1, v.mn);
|
||||
sq_pop(vm, 1);
|
||||
|
||||
sq_pushstring(vm, "max", -1);
|
||||
sq_get(vm, -2);
|
||||
GetVector(vm, -1, v.mx);
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void PushRect(HSQUIRRELVM vm, const fRect &r)
|
||||
{
|
||||
if (!CreateClassInstance(vm, "Rect"))
|
||||
BindingError(vm, "Failed to create Rect instance.");
|
||||
SetTableKey("sx", sq_pushfloat, -1, r.sx);
|
||||
SetTableKey("sy", sq_pushfloat, -1, r.sy);
|
||||
SetTableKey("ex", sq_pushfloat, -1, r.ex);
|
||||
SetTableKey("ey", sq_pushfloat, -1, r.ey);
|
||||
}
|
||||
void GetRect(HSQUIRRELVM vm, SQInteger idx, fRect &r)
|
||||
{
|
||||
SQFloat sx, sy, ex, ey;
|
||||
GetTableKey("sx", sq_getfloat, idx, sx)
|
||||
GetTableKey("sy", sq_getfloat, idx, sy)
|
||||
GetTableKey("ex", sq_getfloat, idx, ex)
|
||||
GetTableKey("ey", sq_getfloat, idx, ey)
|
||||
r.Set(sx, sy, ex, ey);
|
||||
}
|
||||
void PushRect(HSQUIRRELVM vm, const iRect &r)
|
||||
{ PushRect(vm, r.AsFloat()); }
|
||||
void GetRect(HSQUIRRELVM vm, SQInteger idx, iRect &r)
|
||||
{
|
||||
fRect t;
|
||||
GetRect(vm, idx, t);
|
||||
r.Set(int(t.sx), int(t.sy), int(t.ex), int(t.ey));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void sq_register(HSQUIRRELVM v, SQFUNCTION f, const char *fname, const SQChar *mask)
|
||||
{
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v, (const SQChar *)fname, -1);
|
||||
sq_newclosure(v, f, 0); // Create a new function.
|
||||
sq_setnativeclosurename(v, -1, fname);
|
||||
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, mask);
|
||||
sq_newslot(v, -3, false);
|
||||
sq_pop(v, 1); // Pop the root table.
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
} // Script
|
||||
} // GS
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
//------------------------------------------
|
||||
SQInteger SQAssert(HSQUIRRELVM vm)
|
||||
//------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETBOOL(c)
|
||||
__SQ_GETSTRING(d)
|
||||
if (!c)
|
||||
return sq_throwerror(vm, d);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
SQInteger SQPow(HSQUIRRELVM vm)
|
||||
//---------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETFLOAT(v)
|
||||
__SQ_GETFLOAT(p)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNFLOAT(pow(v, p))
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
SQInteger SQExp(HSQUIRRELVM vm)
|
||||
//---------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETFLOAT(v)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNFLOAT(exp(v))
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
SQInteger SQMod(HSQUIRRELVM vm)
|
||||
//---------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETINT(v)
|
||||
__SQ_GETINT(m)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNINT(v % m)
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
SQInteger SQAbsMod(HSQUIRRELVM vm)
|
||||
//------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETINT(v)
|
||||
__SQ_GETINT(m)
|
||||
__SQ_GETEND
|
||||
v %= m;
|
||||
if (v < 0)
|
||||
v = m + v;
|
||||
__SQ_RETURNINT(v)
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
SQInteger ObjectIsValid(HSQUIRRELVM vm)
|
||||
//-----------------------------------------------
|
||||
{
|
||||
void *p;
|
||||
if (!CObject::Get(vm, -1, &p))
|
||||
return -1;
|
||||
sq_pop(vm, 1);
|
||||
__SQ_RETURNBOOL(asbool(p));
|
||||
}
|
||||
|
||||
//----------------------------------------------
|
||||
SQInteger ObjectIsSame(HSQUIRRELVM vm)
|
||||
//----------------------------------------------
|
||||
{
|
||||
void *a, *b;
|
||||
if (!CObject::Get(vm, -2, &a) || !CObject::Get(vm, -1, &b))
|
||||
return -1;
|
||||
sq_pop(vm, 2);
|
||||
__SQ_RETURNBOOL(a == b);
|
||||
}
|
||||
|
||||
//----------------------------------------------
|
||||
SQInteger ShellExecute(HSQUIRRELVM vm)
|
||||
//----------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSTRING(path)
|
||||
__SQ_GETSTRING(parm)
|
||||
|
||||
int r = -1;
|
||||
|
||||
#if __PLATFORM_WINDOWS__
|
||||
if (path)
|
||||
{
|
||||
String cmd = parm ? String::Format("%s %s", path, parm).c_str() : path;
|
||||
__LOG_H__ << "Execute command '" << cmd << "'\n\n";
|
||||
|
||||
#if 0
|
||||
char szBuffer[_MAX_PATH * 10 + 1];
|
||||
|
||||
DWORD dw;
|
||||
HANDLE hIn, hOut;
|
||||
PROCESS_INFORMATION pi;
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
STARTUPINFO si;
|
||||
|
||||
if (CreatePipe(&hIn, &hOut, NULL, sizeof(szBuffer) * 2))
|
||||
{
|
||||
memset(&si, 0, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
si.hStdOutput = hOut;
|
||||
si.hStdError = hOut;
|
||||
|
||||
//if (!CreateProcess("C:\\WINDOWS\\system32\\cmd.exe", (LPSTR)cmd.c_str(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
|
||||
if (!CreateProcess(NULL, (LPSTR)cmd.c_str(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
|
||||
__LOG_N__ << "Couldn't create process: " << GetLastError() << "\n";
|
||||
else
|
||||
{
|
||||
CloseHandle(hOut);
|
||||
__LOG_N__ << "Reading ShellExecute...\n";
|
||||
|
||||
forever
|
||||
{
|
||||
if (ReadFile(hIn, szBuffer, sizeof(szBuffer) - 1, &dw, NULL) == 0)
|
||||
{
|
||||
if (GetLastError() == ERROR_NO_DATA)
|
||||
Sleep(1);
|
||||
|
||||
else if (GetLastError() == ERROR_BROKEN_PIPE)
|
||||
{
|
||||
GetExitCodeProcess(pi.hProcess, &dw);
|
||||
r = dw;
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (dw > 0)
|
||||
{
|
||||
szBuffer[dw] = 0;
|
||||
__LOG__ << szBuffer << "\n";
|
||||
}
|
||||
|
||||
if ((GetExitCodeProcess(pi.hProcess, &dw) == 0) || (dw != STILL_ACTIVE))
|
||||
{
|
||||
r = dw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(hIn);
|
||||
}
|
||||
else {
|
||||
__LOG_N__ << "Couldn't create pipe: " << GetLastError() << "\n";
|
||||
}
|
||||
#else
|
||||
char psBuffer[256];
|
||||
FILE *iopipe;
|
||||
|
||||
if ((iopipe = _popen(cmd.c_str(), "r" )) != 0)
|
||||
while (!feof(iopipe))
|
||||
if (fgets(psBuffer, 256, iopipe))
|
||||
__LOG__ << psBuffer;
|
||||
|
||||
r = _pclose(iopipe);
|
||||
#endif
|
||||
}
|
||||
#elif __PLATFORM_OSX__
|
||||
__LOG_E__ << "ShellExecute(): STUB\n";
|
||||
#elif __PLATFORM_LINUX__
|
||||
r = path ? system(parm ? String::Format("%s %s", path, parm).c_str() : path) : -1;
|
||||
#endif
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNINT(r)
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------
|
||||
SQInteger Sleep(HSQUIRRELVM vm)
|
||||
//---------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETINT(ms)
|
||||
__SQ_GETEND
|
||||
Platform::Get().Sleep(ms);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
void RegisterAllSquirrelBinding(HSQUIRRELVM vm)
|
||||
//------------------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Script
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: ScriptDebug
|
||||
Desc: Debugging
|
||||
#*/
|
||||
/*#
|
||||
Func: __Assert
|
||||
Proto: void:bool,string
|
||||
Desc: Assert an expression, throw an engine exception and suspend the VM if not verified.
|
||||
#*/
|
||||
sq_register(vm, SQAssert, "__Assert", _SC(".bs"));
|
||||
|
||||
/*#
|
||||
Section: ScriptGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
/*#
|
||||
Func: SQPow
|
||||
Proto: float:float value,float pow
|
||||
Desc: Returns value raised to power.
|
||||
#*/
|
||||
sq_register(vm, SQPow, "Pow", _SC(".ff"));
|
||||
/*#
|
||||
Func: SQExp
|
||||
Proto: float:float value
|
||||
Desc: Returns value in exponential .
|
||||
#*/
|
||||
sq_register(vm, SQExp, "Exp", _SC(".f"));
|
||||
/*#
|
||||
Func: SQMod
|
||||
Proto: int:int value,int divider
|
||||
Desc: Returns integer modulo of a value.
|
||||
#*/
|
||||
sq_register(vm, SQMod, "Mod", _SC(".ii"));
|
||||
/*#
|
||||
Func: SQAbsMod
|
||||
Proto: int:int value,int divider
|
||||
Desc: Returns integer modulo of the absolute of a given value.
|
||||
#*/
|
||||
sq_register(vm, SQAbsMod, "AbsMod", _SC(".ii"));
|
||||
/*#
|
||||
Func: ObjectIsValid
|
||||
Proto: bool:Object
|
||||
Desc: Returns true if the given engine object is valid, false otherwise.<br>This function can be used to test the validity of all engine types like geometry, material, item, scene and others.
|
||||
#*/
|
||||
sq_register(vm, ObjectIsValid, "ObjectIsValid", _SC(".x"));
|
||||
/*#
|
||||
Func: ObjectIsSame
|
||||
Proto: bool:Object,Object
|
||||
Desc: Returns true if two given engine object references are pointing to the same object.
|
||||
#*/
|
||||
sq_register(vm, ObjectIsSame, "ObjectIsSame", _SC(".xx"));
|
||||
|
||||
/*#
|
||||
Topic: System
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: SystemGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
/*#
|
||||
Func: ShellExecute
|
||||
Proto: int:string path,string param
|
||||
Desc: Execute an external program, returns its return code.
|
||||
#*/
|
||||
sq_register(vm, ShellExecute, "ShellExecute", _SC(".ss"));
|
||||
|
||||
|
||||
sq_register(vm, Sleep, "_Sleep", _SC(".i"));
|
||||
|
||||
// Legacy support.
|
||||
#if 1
|
||||
sq_register(vm, ObjectIsValid, "AIPathIsValid", _SC(".x"));
|
||||
sq_register(vm, ObjectIsValid, "GeometryIsValid", _SC(".x"));
|
||||
sq_register(vm, ObjectIsValid, "ItemIsValid", _SC(".x"));
|
||||
sq_register(vm, ObjectIsValid, "MetatagIsValid", _SC(".x"));
|
||||
sq_register(vm, ObjectIsValid, "TextureIsValid", _SC(".x"));
|
||||
sq_register(vm, ObjectIsValid, "WidgetIsValid", _SC(".x"));
|
||||
sq_register(vm, ObjectIsValid, "WindowIsValid", _SC(".x"));
|
||||
#endif
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: SystemConstant
|
||||
Values: SystemClockFrequency
|
||||
#*/
|
||||
sq_pushstring(vm, "SystemClockFrequency", -1); sq_pushinteger(vm, Platform::Get().GetClockFrequency()); sq_newslot(vm, -3, true);
|
||||
|
||||
// Register engine types.
|
||||
for (int n = 0; n < typetag_End; ++n)
|
||||
{
|
||||
String type_string = String::Format("EngineType%s", CObjectTypeToString((CObjectType)n));
|
||||
sq_pushstring(vm, type_string.TrimChar(' ').c_str(), -1); sq_pushinteger(vm, n); sq_newslot(vm, -3, true);
|
||||
}
|
||||
|
||||
// Newer faster bindings.
|
||||
RegisterUCBinding(vm);
|
||||
|
||||
//
|
||||
RegisterClockBinding(vm);
|
||||
RegisterMatrixBinding(vm);
|
||||
RegisterAnimationBinding(vm);
|
||||
RegisterAIBinding(vm);
|
||||
RegisterSystemBinding(vm);
|
||||
RegisterRendererBinding(vm);
|
||||
RegisterMixerBinding(vm);
|
||||
RegisterSceneBinding(vm);
|
||||
RegisterInstanceBinding(vm);
|
||||
RegisterGroupBinding(vm);
|
||||
RegisterCameraBinding(vm);
|
||||
RegisterObjectBinding(vm);
|
||||
RegisterMaterialBinding(vm);
|
||||
RegisterLightBinding(vm);
|
||||
RegisterProfilerBinding(vm);
|
||||
RegisterItemBinding(vm);
|
||||
RegisterMotionBinding(vm);
|
||||
RegisterCollisionBinding(vm);
|
||||
RegisterPhysicBinding(vm);
|
||||
RegisterPictureBinding(vm);
|
||||
RegisterTextureBinding(vm);
|
||||
RegisterSoundBinding(vm);
|
||||
RegisterGeometryBinding(vm);
|
||||
RegisterIOBinding(vm);
|
||||
RegisterUIBinding(vm);
|
||||
RegisterNMLBinding(vm);
|
||||
RegisterResourceFactoryBinding(vm);
|
||||
RegisterRaytracerBinding(vm);
|
||||
RegisterProjectBinding(vm);
|
||||
RegisterTriggerBinding(vm);
|
||||
RegisterEmitterBinding(vm);
|
||||
RegisterHashBinding(vm);
|
||||
RegisterHTTPBinding(vm);
|
||||
RegisterFontBinding(vm);
|
||||
RegisterPlatformBinding(vm);
|
||||
RegisterMaterialShaderBinding(vm);
|
||||
|
||||
#if __PLATFORM_NINTENDO_WII__
|
||||
RegisterWiiBinding(vm);
|
||||
#endif
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
@ -27,7 +27,6 @@ void RegisterFontBinding(HSQUIRRELVM);
|
||||
void RegisterGroupBinding(HSQUIRRELVM);
|
||||
void RegisterHashBinding(HSQUIRRELVM);
|
||||
void RegisterHTTPBinding(HSQUIRRELVM);
|
||||
void RegisterWebSocketBinding(HSQUIRRELVM);
|
||||
void RegisterInstanceBinding(HSQUIRRELVM);
|
||||
void RegisterIOBinding(HSQUIRRELVM);
|
||||
void RegisterItemBinding(HSQUIRRELVM);
|
||||
|
||||
254
include/modules/script_squirrel/legacy/system_binding.cpp
Normal file
254
include/modules/script_squirrel/legacy/system_binding.cpp
Normal file
@ -0,0 +1,254 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifdef __PLATFORM_WINDOWS__
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOGDI
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "squirrel_binding.h"
|
||||
#include "binding_helpers.h"
|
||||
#include "filesystem/filesystem.h"
|
||||
#include "filesystem/io_memory.h"
|
||||
#include "filesystem/io_cfile.h"
|
||||
#include "filesystem/io_handle.h"
|
||||
#include "rand/rand.h"
|
||||
#include "platform.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SystemGetClock(HSQUIRRELVM vm) {
|
||||
__SQ_RETURNINT(Platform::Get().GetClock()) }
|
||||
SQInteger SystemGarbageCollect(HSQUIRRELVM vm) {
|
||||
sq_collectgarbage(vm);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger SystemGetClockFrequency(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNINT(Platform::Get().GetClockFrequency()) }
|
||||
SQInteger SystemGetLocale(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNSTRING(/*Platform::Get().GetLocale()*/"STUB") }
|
||||
SQInteger SystemGetPlatform(HSQUIRRELVM vm)
|
||||
{ __SQ_RETURNSTRING(Platform::Get().GetName()) }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SystemSeedRand(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETINT(seed))
|
||||
Random::Seed(seed);
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger SystemRand(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETINT(range))
|
||||
__SQ_RETURNINT(Random::Rand(range));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SystemShowCursor(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETBOOL(show))
|
||||
#ifdef __PLATFORM_WINDOWS__
|
||||
ShowCursor(show);
|
||||
#endif
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SystemSleep(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETINT(ms))
|
||||
Platform::Get().Sleep(ms);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SystemSetProcessAffinity(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLE(__SQ_GETINT(num_thread))
|
||||
HANDLE process = GetCurrentProcess();
|
||||
DWORD_PTR processAffinityMask = 1 << 0;
|
||||
for (int i = 1; i < num_thread; ++i)
|
||||
processAffinityMask |= (1 << i);
|
||||
|
||||
BOOL success = SetProcessAffinityMask(process, processAffinityMask);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SystemMountLocalPath(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSTRING(mount_point)
|
||||
__SQ_GETSTRING(local_path)
|
||||
bool r = Platform::Get().io->Mount(new IO::CFile(local_path), mount_point);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger SystemHasMountPoint(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(mount_point)
|
||||
bool r = asbool(Platform::Get().io->GetIOSystem(mount_point));
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(r)
|
||||
}
|
||||
SQInteger GetPathFromMountPoint(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(mount_point)
|
||||
__SQ_GETEND
|
||||
IO::Base* base = Platform::Get().io->GetIOSystem(mount_point);
|
||||
if(base == NULL)
|
||||
__SQ_RETURNSTRING("")
|
||||
else
|
||||
__SQ_RETURNSTRING(base->MapToAbsolute(""))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger SystemLoadBindingPlugin(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(shared_lib_path)
|
||||
|
||||
SquirrelVM *sq = (SquirrelVM *)sq_getforeignptr(vm);
|
||||
int code_error = 0;
|
||||
Script::BindingPluginManager::Plugin *plugin = sq->binding_plugins.LoadPlugin(shared_lib_path, &code_error);
|
||||
|
||||
if (plugin == NULL)
|
||||
return sq_throwerror(vm, "Failed to load binding library.");
|
||||
|
||||
else
|
||||
{
|
||||
Script::IScriptBinding *binding = sq->binding_plugins.CreatePluginInterface(plugin);
|
||||
binding->RegisterBinding(*sq);
|
||||
}
|
||||
|
||||
__SQ_GETEND
|
||||
__SQ_RETURNBOOL(true)
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterSystemBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: System
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: System
|
||||
Desc: System functions
|
||||
#*/
|
||||
/*#
|
||||
Func: SystemSleep
|
||||
Proto: void:int
|
||||
Desc: Sleep the current thread for a specified number of milliseconds.
|
||||
#*/
|
||||
sq_register(vm, SystemSleep, "SystemSleep", _SC(".i"));
|
||||
|
||||
/*#
|
||||
Func: SystemSetProcessAffinity
|
||||
Proto: void:int
|
||||
Desc: Set the number of thread affinity for the process simulator.
|
||||
#*/
|
||||
sq_register(vm, SystemSetProcessAffinity, "SystemSetProcessAffinity", _SC(".i"));
|
||||
|
||||
/*#
|
||||
Func: SystemGetClock
|
||||
Proto: int:
|
||||
Desc: Return the raw system clock.
|
||||
#*/
|
||||
sq_register(vm, SystemGetClock, "SystemGetClock", _SC("."));
|
||||
/*#
|
||||
Func: SystemGarbageCollect
|
||||
Proto: void:
|
||||
Desc: garbage collect.
|
||||
#*/
|
||||
sq_register(vm, SystemGarbageCollect, "SystemGarbageCollect", _SC("."));
|
||||
/*#
|
||||
Func: SystemGetClockFrequency
|
||||
Proto: int:
|
||||
Desc: Return the system clock frequency.
|
||||
#*/
|
||||
sq_register(vm, SystemGetClockFrequency, "SystemGetClockFrequency", _SC("."));
|
||||
/*#
|
||||
Func: SystemGetLocale
|
||||
Proto: string:
|
||||
Desc: Return the system language description in a string ("FR","EN","ES","NL","IT").
|
||||
#*/
|
||||
sq_register(vm, SystemGetLocale, "SystemGetLocale", _SC("."));
|
||||
/*#
|
||||
Func: SystemGetPlatform
|
||||
Proto: string:
|
||||
Desc: Return the current platform ("Win32", "Linux32", "Wii").
|
||||
#*/
|
||||
sq_register(vm, SystemGetPlatform, "SystemGetPlatform", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: SystemRand
|
||||
Proto: int:int range
|
||||
Desc: Return a random number between [0;range].
|
||||
#*/
|
||||
sq_register(vm, SystemRand, "SystemRand", _SC(".n"));
|
||||
/*#
|
||||
Func: SystemSeedRand
|
||||
Proto: void:int seed
|
||||
Desc: Initialize the random number sequence with a given seed.
|
||||
#*/
|
||||
sq_register(vm, SystemSeedRand, "SystemSeedRand", _SC(".n"));
|
||||
|
||||
/*#
|
||||
Func: SystemShowCursor
|
||||
Proto: void:bool show
|
||||
Desc: Show/hide the platform cursor.
|
||||
#*/
|
||||
sq_register(vm, SystemShowCursor, "SystemShowCursor", _SC(".b"));
|
||||
|
||||
/*#
|
||||
Func: SystemMountLocalPath
|
||||
Proto: bool:String local_path,String mount_point
|
||||
Desc: Mount a local path under a specific mount point.
|
||||
Example: SystemMountLocalPath("d:/test/", "@test/") // "d:/test/a.jpg" can now be accessed as "@test/a.jpg".
|
||||
#*/
|
||||
sq_register(vm, SystemMountLocalPath, "SystemMountLocalPath", _SC(".ss"));
|
||||
/*#
|
||||
Func: SystemHasMountPoint
|
||||
Proto: bool:string mount_point
|
||||
Desc: Returns true if the specified mount point exists.
|
||||
#*/
|
||||
sq_register(vm, SystemHasMountPoint, "SystemHasMountPoint", _SC(".s"));
|
||||
/*#
|
||||
Func: GetPathFromMountPoint
|
||||
Proto: string:string mount_point
|
||||
Desc: Returns path if the specified mount point exists.
|
||||
#*/
|
||||
sq_register(vm, GetPathFromMountPoint, "GetPathFromMountPoint", _SC(".s"));
|
||||
|
||||
/*#
|
||||
Func: SystemLoadBindingPlugin
|
||||
Proto: bool:string library_path
|
||||
Desc: Load a script binding API from a shared library.
|
||||
#*/
|
||||
sq_register(vm, SystemLoadBindingPlugin, "SystemLoadBindingPlugin", _SC(".s"));
|
||||
|
||||
/*#
|
||||
Enum: HardwareButton
|
||||
Values: HardwareButtonHome,HardwareButtonMenu,HardwareButtonBack
|
||||
#*/
|
||||
sq_pushstring(vm, "HardwareButtonHome", -1); sq_pushinteger(vm, 0); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "HardwareButtonMenu", -1); sq_pushinteger(vm, 1); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "HardwareButtonBack", -1); sq_pushinteger(vm, 2); sq_newslot(vm, -3, true);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
158
include/modules/script_squirrel/legacy/texture_binding.cpp
Normal file
158
include/modules/script_squirrel/legacy/texture_binding.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "core/render_data.h"
|
||||
#include "core/graphic_resource_factory.h"
|
||||
#include "picture/pict.h"
|
||||
|
||||
using namespace GS::Render;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger TextureSetWrapping(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETSAFEPTR(t, Texture, typetag_Texture)
|
||||
__SQ_GETBOOL(wrap_u)
|
||||
__SQ_GETBOOL(wrap_v)
|
||||
__SQ_GETEND
|
||||
t->SetWrapping(wrap_u ? TextureParm::WrapRepeat : TextureParm::WrapClamp, wrap_v ? TextureParm::WrapRepeat : TextureParm::WrapClamp);
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger TextureSetStreamState(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(t, Texture, typetag_Texture)
|
||||
__SQ_GETINT(stream_state)
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger TextureRewindStream(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(t, Texture, typetag_Texture)
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger TextureGetWidth(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(t, Texture, typetag_Texture)
|
||||
__SQ_RETURNINT(t->GetWidth())
|
||||
}
|
||||
SQInteger TextureGetHeight(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(t, Texture, typetag_Texture)
|
||||
__SQ_RETURNINT(t->GetHeight())
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger TextureUpdate(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(t, Texture, typetag_Texture)
|
||||
__SQ_GETSAFEPTR(p, GS::Picture, typetag_Picture)
|
||||
__SQ_GETEND
|
||||
//__SQ_RETURNBOOL(t->Create((const char *)p->GetData(), p->GetWidth(), p->GetHeight()))
|
||||
t->Blit((const char *)p->GetData(), p->GetWidth(), p->GetHeight());
|
||||
__SQ_RETURN
|
||||
}
|
||||
SQInteger TextureRelease(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(t, Texture, typetag_Texture)
|
||||
t->Free();
|
||||
__SQ_RETURN
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterTextureBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Texture
|
||||
Type: Texture
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: TextureStream
|
||||
Desc: Data streaming
|
||||
#*/
|
||||
/*#
|
||||
Func: TextureSetStreamState
|
||||
Proto: void:texture,StreamState state
|
||||
Desc: Set the texture stream state.
|
||||
#*/
|
||||
sq_register(vm, TextureSetStreamState, "TextureSetStreamState", _SC(".xi"));
|
||||
/*#
|
||||
Func: TextureRewindStream
|
||||
Proto: void:texture
|
||||
Desc: Rewind texture stream.
|
||||
#*/
|
||||
sq_register(vm, TextureRewindStream, "TextureRewindStream", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Section: TextureSampling
|
||||
Desc: Texture sampling
|
||||
#*/
|
||||
/*#
|
||||
Func: TextureSetWrapping
|
||||
Proto: void:Texture,bool wrap_u, bool wrap_v
|
||||
Desc: Set the texture U and V wrap modes.
|
||||
#*/
|
||||
sq_register(vm, TextureSetWrapping, "TextureSetWrapping", _SC(".xbb"));
|
||||
|
||||
/*#
|
||||
Section: TextureGeneric
|
||||
Desc: Generic
|
||||
#*/
|
||||
/*#
|
||||
Func: TextureGetWidth
|
||||
Proto: int:texture
|
||||
Desc: Return the texture width.
|
||||
#*/
|
||||
sq_register(vm, TextureGetWidth, "TextureGetWidth", _SC(".x"));
|
||||
/*#
|
||||
Func: TextureGetHeight
|
||||
Proto: int:texture
|
||||
Desc: Return the texture height.
|
||||
#*/
|
||||
sq_register(vm, TextureGetHeight, "TextureGetHeight", _SC(".x"));
|
||||
|
||||
/*#
|
||||
Func: TextureUpdate
|
||||
Proto: bool:Texture,Picture
|
||||
Desc: Update the texture data from a picture object.
|
||||
#*/
|
||||
sq_register(vm, TextureUpdate, "TextureUpdate", _SC(".xx"));
|
||||
/*#
|
||||
Func: TextureRelease
|
||||
Proto: void:Texture
|
||||
Desc: Release the renderer data for a given texture. A subsequent call to TextureUpdate will then recreate the renderer object.
|
||||
#*/
|
||||
sq_register(vm, TextureRelease, "TextureRelease", _SC(".x"));
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/*#
|
||||
Enum: StreamState
|
||||
Values: StreamPlaying,StreamPaused
|
||||
#*/
|
||||
#if __ENABLE_DAV__
|
||||
sq_pushstring(vm, "StreamPlaying", -1); sq_pushinteger(vm, TextureStreamInterface::Stream_Playing); sq_newslot(vm, -3, true);
|
||||
sq_pushstring(vm, "StreamPaused", -1); sq_pushinteger(vm, TextureStreamInterface::Stream_Paused); sq_newslot(vm, -3, true);
|
||||
#endif
|
||||
|
||||
sq_pushstring(vm, "NullTexture", -1); CObject::Push(vm, NULL, typetag_Texture); sq_newslot(vm, -3, true);
|
||||
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
84
include/modules/script_squirrel/legacy/trigger_binding.cpp
Normal file
84
include/modules/script_squirrel/legacy/trigger_binding.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "binding_helpers.h"
|
||||
#include "scene3d/mtrigger.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::Core;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SQInteger TriggerGetItemList(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSINGLESAFEPTR(t, MTrigger, typetag_Trigger)
|
||||
sq_newarray(vm, 0);
|
||||
ListForeachPtr(Trigger::ItemInTrigger *, i, t->items_in_trigger)
|
||||
if (i->inside)
|
||||
{
|
||||
CObject::Push(vm, (void *)i, typetag_Item);
|
||||
sq_arrayappend(vm, -2);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
SQInteger TriggerTestItem(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(t, MTrigger, typetag_Trigger)
|
||||
__SQ_GETSAFEPTR(i, MItem, typetag_Item)
|
||||
__SQ_GETEND
|
||||
|
||||
ListForeachPtr(Trigger::ItemInTrigger *, _i, t->items_in_trigger)
|
||||
if (_i->inside && (i == (MItem *)_i->item->mitem))
|
||||
__SQ_RETURNBOOL(true)
|
||||
|
||||
__SQ_RETURNBOOL(false)
|
||||
}
|
||||
SQInteger TriggerPosInside(HSQUIRRELVM vm)
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(t, MTrigger, typetag_Trigger)
|
||||
__SQ_GETVECTOR(p)
|
||||
__SQ_GETEND
|
||||
|
||||
__SQ_RETURNBOOL(t->IsInside(p))
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RegisterTriggerBinding(HSQUIRRELVM vm)
|
||||
{
|
||||
/*#
|
||||
Topic: Trigger
|
||||
Type: Trigger
|
||||
Related: Item
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: TriggerGeneral
|
||||
Desc: Trigger general functions.
|
||||
#*/
|
||||
/*#
|
||||
Func: TriggerGetItemList
|
||||
Proto: array:Item
|
||||
Desc: Return an array of items currently inside this trigger.
|
||||
#*/
|
||||
sq_register(vm, TriggerGetItemList, "TriggerGetItemList", _SC(".x"));
|
||||
/*#
|
||||
Func: TriggerTestItem
|
||||
Proto: bool:Item trigger,Item item
|
||||
Desc: Test if a given item is currently inside this trigger.
|
||||
#*/
|
||||
sq_register(vm, TriggerTestItem, "TriggerTestItem", _SC(".xx"));
|
||||
/*#
|
||||
Func: TriggerPosInside
|
||||
Proto: bool:Item trigger,Vector p
|
||||
Desc: Test if a given p is currently inside this trigger.
|
||||
#*/
|
||||
sq_register(vm, TriggerPosInside, "TriggerPosInside", _SC(".xx"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
2639
include/modules/script_squirrel/legacy/ui_binding.cpp
Normal file
2639
include/modules/script_squirrel/legacy/ui_binding.cpp
Normal file
File diff suppressed because it is too large
Load Diff
644
include/modules/script_squirrel/legacy/wii_binding.cpp
Normal file
644
include/modules/script_squirrel/legacy/wii_binding.cpp
Normal file
@ -0,0 +1,644 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#if __PLATFORM_NINTENDO_WII__
|
||||
|
||||
|
||||
#include "squirrel_binding.h"
|
||||
#include "binding_helpers.h"
|
||||
#include "uc_binding.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <Revolution.h>
|
||||
#include <revolution/kpad.h>
|
||||
#include <revolution/sc.h>
|
||||
#include <revolution/arc.h>
|
||||
#include <revolution/cx.h>
|
||||
#include <revolution/tmcc/tmcc_jpeg.h>
|
||||
|
||||
#include <revolution/sc.h>
|
||||
#include <revolution/os.h>
|
||||
#include <revolution/mem/allocator.h>
|
||||
#include <revolution/wpad.h>
|
||||
|
||||
#include "Wii_platform.h"
|
||||
|
||||
//---------------------------------------------------------
|
||||
WIIHome Wii::HomeMenu ATTRIBUTE_ALIGN(32);
|
||||
|
||||
nWiiMixer* Wii::Mixer = NULL;
|
||||
WiiSaveMngr Wii::Save;
|
||||
nWiiGXRenderer* Wii::Renderer = NULL;
|
||||
GSFramework* Wii::Engine = NULL;
|
||||
nProject* Wii::Project = NULL;
|
||||
WIIWareStrap* Wii::Strap = NULL;
|
||||
nWiiAllocator Wii::MEM2_allocator;
|
||||
nIOMemoryFS* Wii::pMemory_fs = NULL;
|
||||
|
||||
unsigned int Wii::LastAudioUpdateTime = (u32)OSGetTick();
|
||||
bool Wii::DisableAudioUpdate = false;
|
||||
bool Wii::VideoInited = false;
|
||||
//---------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------
|
||||
bool Wii::LoadingAudioUpdate()
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
#define WII_LOADING_AUDIO_UPDATE_PERIOD_MS (1000/20)
|
||||
#define WII_LOADING_AUDIO_UPDATE_SLEEP_MS (2)
|
||||
|
||||
if (DisableAudioUpdate)
|
||||
return;
|
||||
|
||||
u32 currentTick = (u32)OSGetTick();
|
||||
u32 diffCSTime = OSTicksToMilliseconds( OSDiffTick( currentTick, LastAudioUpdateTime ) );
|
||||
|
||||
if (diffCSTime >= WII_LOADING_AUDIO_UPDATE_PERIOD_MS)
|
||||
{
|
||||
if (Wii::Mixer)
|
||||
{
|
||||
Wii::Mixer->Update();
|
||||
OSSleepMilliseconds( WII_LOADING_AUDIO_UPDATE_SLEEP_MS );
|
||||
|
||||
// OSReport("audio updated, delayMs=%d\n",diffCSTime);
|
||||
}
|
||||
LastAudioUpdateTime = (u32)OSGetTick();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
void Wii::EnableHomeMenu(bool value)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
if (value)
|
||||
WIIHome::enableFlags &= ~WII_HOME_DISABLE_HOME_BUTTON;
|
||||
else
|
||||
WIIHome::enableFlags |= WII_HOME_DISABLE_HOME_BUTTON;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
void Wii::ForceReturnToMenuInsteadOfReset(bool value)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
WIIHome::forceReturnToMenuInsteadOfReset = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
bool Wii::EnableResetAndPowerButtons(bool enable, bool allowPostpone)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
u32 f = WII_HOME_DISABLE_RESET_BUTTON | WII_HOME_DISABLE_POWER_BUTTON;
|
||||
bool res = !(WIIHome::enableFlags & f);
|
||||
|
||||
if (!enable && allowPostpone)
|
||||
f |= WII_HOME_ALLOW_POWER_POSTPONE | WII_HOME_ALLOW_RESET_POSTPONE;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
WIIHome::enableFlags &= ~f;
|
||||
WIIHome::enableFlags &= ~WII_HOME_ALLOW_POWER_POSTPONE;
|
||||
WIIHome::enableFlags &= ~WII_HOME_ALLOW_RESET_POSTPONE;
|
||||
}
|
||||
else
|
||||
WIIHome::enableFlags |= f;
|
||||
return res;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
float Wii::GetSquareRatioFor16_9()
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
// cf VI_library_book, page 47
|
||||
// Game Virtual Space EFB XFB VI
|
||||
//NTSC, EURGB60 832<33>456 640<34>456 640<34>456 686<38>456
|
||||
//PAL 832<33>456 640<34>456 640<34>542 682<38>542
|
||||
|
||||
if (SCGetAspectRatio()!=SC_ASPECT_RATIO_16x9) {
|
||||
return(1.0f);
|
||||
}
|
||||
else {
|
||||
if ( (SCGetEuRgb60Mode() == SC_EURGB60_MODE_ON)
|
||||
|| (VIGetTvFormat() != VI_PAL)) {
|
||||
return(686.0f/832.0f);
|
||||
}
|
||||
else {
|
||||
return(682.0f/832.0f);
|
||||
}
|
||||
}
|
||||
|
||||
return (1.0f);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiStartHomeMenu(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
if ( !Wii::HomeMenu.IsActivated()
|
||||
&& ((Wii::HomeMenu.enableFlags & WII_HOME_DISABLE_HOME_BUTTON)==0)) {
|
||||
Wii::HomeMenu.Init( SCGetAspectRatio()==SC_ASPECT_RATIO_16x9, VIGetTvFormat() );
|
||||
}
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiEnableHomeMenu(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETBOOL(value)
|
||||
__SQ_GETEND
|
||||
Wii::EnableHomeMenu(value);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiGetHomeMenuRunning(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNBOOL(Wii::HomeMenu.IsActivated() == 1)
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiEnableResetAndPowerButtons(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETBOOL(value)
|
||||
__SQ_GETEND
|
||||
Wii::EnableResetAndPowerButtons(value);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiIs16_9(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNBOOL(SCGetAspectRatio()==SC_ASPECT_RATIO_16x9)
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiGetSquareRatioFor16_9(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNFLOAT(Wii::GetSquareRatioFor16_9());
|
||||
return 1;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiReturnToDataManager(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
WIIHome::PowerAndResetPreprocess();
|
||||
OSReturnToDataManager();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiInitStrap(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
if (Wii::Strap) {
|
||||
static const GXColor fg = {0x00, 0xff, 0xff, 0xff};
|
||||
static const GXColor bg = {0x00, 0x00, 0x00, 0x00};
|
||||
OSFatal ( fg, bg, "WiiInitStrap" );
|
||||
}
|
||||
Wii::Strap = new WIIWareStrap();
|
||||
Wii::Strap->Init();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
extern GSFramework *gEngine;
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiDeInitStrap(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
if (Wii::Strap) {
|
||||
Wii::Strap->DeInit();
|
||||
delete Wii::Strap;
|
||||
Wii::Strap = NULL;
|
||||
|
||||
// a quoi servait ce code d<>ja ???
|
||||
// VISetBlack(TRUE);
|
||||
// for (s32 i=0;i<2;i++) {
|
||||
// gEngine->GetRenderer()->ShowFrame();
|
||||
// VIWaitForRetrace();
|
||||
// }
|
||||
// VISetBlack(FALSE);
|
||||
// VIWaitForRetrace();
|
||||
}
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiDrawStrap(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
Wii::Strap->Draw();
|
||||
VIWaitForRetrace();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiGetVersion(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
static const char noe[] = "NOE";
|
||||
static const char noa[] = "NOA";
|
||||
__SQ_RETURNSTRING ((WiiErrorMngr::Version == WiiErrorMngr::VERSION_NOE) ? noe : noa);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiGetLastErrorStrId(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNSTRING (WiiErrorMngr::GetLastErrorStrId().c_str());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiGetLastErrorText(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNSTRING (WiiErrorMngr::GetLastErrorText(WiiErrorMngr::ForcedLocaleForGetLastErrorText).c_str());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiGetOptionText(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(optionStrID)
|
||||
const char* res = ((WiiErrorMngr::GetOptionText(optionStrID, WiiErrorMngr::ForcedLocaleForGetLastErrorText)).c_str());
|
||||
__SQ_GETEND
|
||||
|
||||
__SQ_RETURNSTRING(res);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSetGameTitle(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETSTRING(title)
|
||||
WiiErrorMngr::SetGameTitle(title);
|
||||
__SQ_GETEND
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSaveInit(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETINT(nbMetafiles)
|
||||
__SQ_GETINT(saveSizeInBytes)
|
||||
__SQ_GETINT(saveIconNbPictures)
|
||||
__SQ_GETEND
|
||||
|
||||
WiiSaveMngr::Init(nbMetafiles, saveSizeInBytes, saveIconNbPictures);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSaveExists(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_RETURNBOOL (WiiSaveMngr::SaveFileExists());
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSaveSave(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
// #define DEBUG_RESET_WHILE_SAVING
|
||||
// #define DEBUG_POWER_WHILE_SAVING
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_RESET_WHILE_SAVING
|
||||
WIIHome::reset_called = true;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_POWER_WHILE_SAVING
|
||||
WIIHome::power_called = true;
|
||||
#endif
|
||||
|
||||
WiiSaveMngr::Save();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
/*
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSaveLoad(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
// WiiSaveMngr::Save();
|
||||
__SQ_RETURN
|
||||
}
|
||||
*/
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSaveSetMetafile(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(2)
|
||||
__SQ_GETSAFEPTR(metafile, nMetaFile, typetag_Metafile)
|
||||
__SQ_GETINT(id)
|
||||
WiiSaveMngr::SetMetafile(metafile, id);
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSaveGetMetafile(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETINT(id)
|
||||
nMetaFile* ptr = WiiSaveMngr::GetMetafile(id);
|
||||
__SQ_RETURNMANAGEDSAFEPTR(ptr, typetag_Metafile)
|
||||
__SQ_GETEND
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSaveDelete(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
WiiSaveMngr::DeleteSaveFile();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiGameRestart(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
Wii::HomeMenu.PerformReset();
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiDumpMemInfo(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
#if __ENABLE_ENGINE_LOG__
|
||||
u32 freeMem1 = MEMGetTotalFreeSizeForExpHeap(((nWiiAllocator *)MEM1_allocator.vacc)->heap);
|
||||
OSReport("Mem1 Free = %do, %.2fko, %.2fMo\n", freeMem1, freeMem1/1024.0f, freeMem1/(1024.0f*1024.0f));
|
||||
|
||||
u32 freeMem2 = MEMGetTotalFreeSizeForExpHeap(Wii::MEM2_allocator.heap);
|
||||
OSReport("Mem2 Free = %do, %.2fko, %.2fMo\n", freeMem2, freeMem2/1024.0f, freeMem2/(1024.0f*1024.0f));
|
||||
#endif
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiRemoteDisconnect(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(1)
|
||||
__SQ_GETINT(id)
|
||||
|
||||
if (id >= WPAD_CHAN0 && id <= WPAD_CHAN3)
|
||||
WPADDisconnect(id);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
|
||||
/*
|
||||
//---------------------------------------------------------
|
||||
SQInteger WiiSetClearColor(HSQUIRRELVM vm)
|
||||
//---------------------------------------------------------
|
||||
{
|
||||
__SQ_GETSTART(3)
|
||||
__SQ_GETINT(r)
|
||||
__SQ_GETINT(g)
|
||||
__SQ_GETINT(b)
|
||||
__SQ_GETEND
|
||||
|
||||
GXColor c;
|
||||
c.a = 255;
|
||||
c.r = r;
|
||||
c.g = g;
|
||||
c.b = b;
|
||||
GXSetCopyClear(c, GX_MAX_Z24);
|
||||
|
||||
__SQ_RETURN
|
||||
}
|
||||
*/
|
||||
|
||||
//-------------------------------------------------------
|
||||
void RegisterWiiBinding(HSQUIRRELVM vm)
|
||||
//-------------------------------------------------------
|
||||
{
|
||||
/*#
|
||||
Topic: Wii
|
||||
Desc: NINTENDO Wii specific binding
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Section: WiiHome
|
||||
Desc: Wii Home menu
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: WiiEnableHomeMenu
|
||||
Proto: void:bool
|
||||
Desc: Enable or disables the home button.
|
||||
#*/
|
||||
sq_register(vm, WiiEnableHomeMenu, "WiiEnableHomeMenu", _SC(".b"));
|
||||
/*#
|
||||
Func: WiiGetHomeMenuRunning
|
||||
Proto: bool:void
|
||||
Desc: Returns the state of the Home menu.
|
||||
#*/
|
||||
sq_register(vm, WiiGetHomeMenuRunning, "WiiGetHomeMenuRunning", _SC("."));
|
||||
/*#
|
||||
Func: WiiStartHomeMenu
|
||||
Proto: void:void
|
||||
Desc: Launches Home menu (only if it is enabled).
|
||||
#*/
|
||||
sq_register(vm, WiiStartHomeMenu, "WiiStartHomeMenu", _SC("."));
|
||||
/*#
|
||||
Func: WiiReturnToDataManager
|
||||
Proto: void:void
|
||||
Desc: Launches the Home menu (only if it is enabled).
|
||||
#*/
|
||||
sq_register(vm, WiiReturnToDataManager, "WiiReturnToDataManager", _SC("."));
|
||||
|
||||
/*#
|
||||
Section: WiiStrap
|
||||
Desc: Wii strap screen functions
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: WiiInitStrap
|
||||
Proto: void:void
|
||||
Desc: Initializes strap screen data.
|
||||
#*/
|
||||
sq_register(vm, WiiInitStrap, "WiiInitStrap", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiDeInitStrap
|
||||
Proto: void:void
|
||||
Desc: Uninitialize strap screen data.
|
||||
#*/
|
||||
sq_register(vm, WiiDeInitStrap, "WiiDeInitStrap", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiDrawStrap
|
||||
Proto: void:void
|
||||
Desc: Draws strap screen data.
|
||||
#*/
|
||||
sq_register(vm, WiiDrawStrap, "WiiDrawStrap", _SC("."));
|
||||
|
||||
/*#
|
||||
Section: WiiSystem
|
||||
Desc: Wii system functions
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: WiiEnableResetButton
|
||||
Proto: void:bool
|
||||
Desc: Enable or disables the reset/shutdown button.
|
||||
#*/
|
||||
sq_register(vm, WiiEnableResetAndPowerButtons, "WiiEnableResetAndPowerButtons", _SC(".b"));
|
||||
|
||||
/*#
|
||||
Func: WiiIs16_9
|
||||
Proto: bool:void
|
||||
Desc: Returns true if the Wii system configuration is set to 16/9 mode.
|
||||
#*/
|
||||
sq_register(vm, WiiIs16_9, "WiiIs16_9", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiGetSquareRatioFor16_9
|
||||
Proto: float:void
|
||||
Desc: Returns the ratio to use to scale 2D images in order to have square pixels on any TV screen.
|
||||
#*/
|
||||
sq_register(vm, WiiGetSquareRatioFor16_9, "WiiGetSquareRatioFor16_9", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiGetVersion
|
||||
Proto: String:void
|
||||
Desc: Returns "NOE" (Europe) or "NOA" (America).
|
||||
#*/
|
||||
sq_register(vm, WiiGetVersion, "WiiGetVersion", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiGetLastErrorStrId
|
||||
Proto: String:void
|
||||
Desc: Returns ID of the last error, returns an empty string if none.
|
||||
#*/
|
||||
sq_register(vm, WiiGetLastErrorStrId, "WiiGetLastErrorStrId", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiGetLastErrorText
|
||||
Proto: String:void
|
||||
Desc: Returns a localized string describing last error.
|
||||
#*/
|
||||
sq_register(vm, WiiGetLastErrorText, "WiiGetLastErrorText", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiGetOptionText
|
||||
Proto: String:String error_id
|
||||
Desc: Returns a localized string describing a non blocking error option string ID.
|
||||
#*/
|
||||
sq_register(vm, WiiGetOptionText, "WiiGetOptionText", _SC(".s"));
|
||||
|
||||
/*#
|
||||
Func: WiiSetGameTitle
|
||||
Proto: void:String title
|
||||
Desc: Sets the game title that may be displayed in Wii error screens
|
||||
#*/
|
||||
sq_register(vm, WiiSetGameTitle, "WiiSetGameTitle", _SC(".s"));
|
||||
|
||||
/*#
|
||||
Section: WiiSave
|
||||
Desc: Wii save system functions
|
||||
#*/
|
||||
|
||||
/*#
|
||||
Func: WiiSaveInit
|
||||
Proto: void:int nbMetafiles, int saveSizeInBytes, int saveIconNbPictures
|
||||
Desc: Initialize the Wii save system information (does not perform any read/write to NAND).
|
||||
#*/
|
||||
sq_register(vm, WiiSaveInit, "WiiSaveInit", _SC(".iii"));
|
||||
/*#
|
||||
Func: WiiSaveExists
|
||||
Proto: bool:void
|
||||
Desc: Returns TRUE if save data exists (does not perform any write to NAND).
|
||||
#*/
|
||||
sq_register(vm, WiiSaveExists, "WiiSaveExists", _SC("."));
|
||||
/*#
|
||||
Func: WiiSaveSave
|
||||
Proto: void:void
|
||||
Desc: Saves data to the Wii NAND memory (WiiSaveInit / WiiSaveAddMetafile must have been called before calling this function).
|
||||
#*/
|
||||
sq_register(vm, WiiSaveSave, "WiiSaveSave", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiSaveLoad
|
||||
Proto: void:void
|
||||
Desc: TBD (WiiSaveInit / WiiSaveSetMetafile must have been called before calling this function).
|
||||
#*/
|
||||
// sq_register(vm, WiiSaveLoad, "WiiSaveLoad", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiSaveSetMetafile
|
||||
Proto: void:Metafile,int id
|
||||
Desc: TBD
|
||||
#*/
|
||||
sq_register(vm, WiiSaveSetMetafile, "WiiSaveSetMetafile", _SC(".xi"));
|
||||
|
||||
/*#
|
||||
Func: WiiSaveGetMetafile
|
||||
Proto: Metafile:int id
|
||||
Desc: TBD
|
||||
#*/
|
||||
sq_register(vm, WiiSaveGetMetafile, "WiiSaveGetMetafile", _SC(".i"));
|
||||
|
||||
/*#
|
||||
Func: WiiSaveDelete
|
||||
Proto: void:void
|
||||
Desc: deletes a game save data & save banner
|
||||
#*/
|
||||
sq_register(vm, WiiSaveDelete, "WiiSaveDelete", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiGameRestart
|
||||
Proto: void:void
|
||||
Desc: restarts the game (like pressing reset ...)
|
||||
#*/
|
||||
sq_register(vm, WiiGameRestart, "WiiGameRestart", _SC("."));
|
||||
|
||||
/*
|
||||
Func: WiiSetClearColor
|
||||
Proto: void:int r,int g,int b
|
||||
Desc: changes the wii clear color
|
||||
*/
|
||||
//sq_register(vm, WiiSetClearColor, "WiiSetClearColor", _SC(".iii"));
|
||||
|
||||
/*#
|
||||
Func: WiiDumpMemInfo
|
||||
Proto: void:void
|
||||
Desc: TBD
|
||||
#*/
|
||||
sq_register(vm, WiiDumpMemInfo, "WiiDumpMemInfo", _SC("."));
|
||||
|
||||
/*#
|
||||
Func: WiiRemoteDisconnect
|
||||
Proto: void:int id
|
||||
Desc: TBD
|
||||
#*/
|
||||
sq_register(vm, WiiRemoteDisconnect, "WiiRemoteDisconnect", _SC(".i"));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
48
include/modules/script_squirrel/mmf.cpp
Normal file
48
include/modules/script_squirrel/mmf.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "mmf.h"
|
||||
|
||||
/**
|
||||
*/
|
||||
CMMF::CMMF(LPCTSTR MMFName, int size, LPCTSTR mutexName) :
|
||||
m_nSize(size),
|
||||
m_hMutex(0)
|
||||
{
|
||||
m_hFileMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, m_nSize, MMFName);
|
||||
m_pSharedData = MapViewOfFile(m_hFileMapping, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
|
||||
|
||||
if(mutexName != NULL)
|
||||
m_hMutex = CreateMutex(NULL, FALSE, mutexName);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
CMMF::~CMMF(void)
|
||||
{
|
||||
UnmapViewOfFile(m_pSharedData);
|
||||
CloseHandle(m_hFileMapping);
|
||||
|
||||
if(m_hMutex)
|
||||
CloseHandle(m_hMutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the current contents of the MMF into pData (buffer must be big enough to receive m_nSize bytes).
|
||||
* Waits for locked mutex to be released if mutex name was specified during construction.
|
||||
*/
|
||||
void CMMF::Read(void* pData, bool read /* = TRUE */)
|
||||
{
|
||||
if(m_hMutex)
|
||||
WaitForSingleObject(m_hMutex, INFINITE);
|
||||
|
||||
memcpy(read ? pData : m_pSharedData, read ? m_pSharedData : pData, m_nSize);
|
||||
|
||||
if(m_hMutex)
|
||||
ReleaseMutex( m_hMutex );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the contents of pData into the MMF, waiting for the MMF lock to be released if applicable.
|
||||
*/
|
||||
void CMMF::Write(void* pData)
|
||||
{
|
||||
Read(pData, false);
|
||||
}
|
||||
266
include/modules/script_squirrel/squirrel_analyzer.cpp
Normal file
266
include/modules/script_squirrel/squirrel_analyzer.cpp
Normal file
@ -0,0 +1,266 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/squirrel_analyzer.h"
|
||||
#include "ascii/parser.h"
|
||||
#include "filesystem/filesystem.h"
|
||||
#include "platform.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::SquirrelAnalyzer;
|
||||
using namespace GS::AsciiParser;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/* static bool SymbolFindByNameFunctor(Symbol *s, const char *n) { return s->name == n; } */
|
||||
static bool SourceFindByNameFunctor(Source *s, const char *n) { return s->name == n; }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
struct ParserContext
|
||||
{
|
||||
const char *s, *e, *o;
|
||||
SharedList <Symbol *> *symbols;
|
||||
Symbol::Type type;
|
||||
|
||||
Offset CurrentOffset() const
|
||||
{
|
||||
Offset offset(1, 0);
|
||||
for (const char *p = o; p < e; ++offset.line)
|
||||
{
|
||||
const char *eol = RunToEOL(p, e);
|
||||
|
||||
if (eol > s)
|
||||
{
|
||||
offset.column = s - p;
|
||||
break;
|
||||
}
|
||||
if (eol >= e)
|
||||
return Offset(1, 0);
|
||||
|
||||
p = SkipEOL(eol, e);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
ParserContext(const char *_s, const char *_e, const char *_o, SharedList <Symbol *> *_symbols, Symbol::Type _type) : s(_s), e(_e), o(_o), symbols(_symbols), type(_type) {}
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ParseContext(ParserContext &);
|
||||
bool ParseMemberVariable(ParserContext &ctx)
|
||||
{
|
||||
AutoPtr <Variable> _var(new Variable);
|
||||
_var->offset = ctx.CurrentOffset();
|
||||
_var->var_type = Variable::VarMember;
|
||||
|
||||
const char *e = SkipEntry(ctx.s, ctx.e);
|
||||
_var->name.Set(ctx.s, e);
|
||||
|
||||
ctx.s = NextEntry(ctx.s, ctx.e) + 1;
|
||||
ctx.symbols->Add(_var.Detach());
|
||||
return true;
|
||||
}
|
||||
bool ParseGlobalVariable(ParserContext &ctx)
|
||||
{
|
||||
AutoPtr <Variable> _var(new Variable);
|
||||
_var->offset = ctx.CurrentOffset();
|
||||
_var->var_type = Variable::VarGlobal;
|
||||
|
||||
const char *e = SkipEntry(ctx.s, ctx.e);
|
||||
_var->name.Set(ctx.s, e);
|
||||
|
||||
ctx.s = NextEntry(ctx.s, ctx.e) + 2;
|
||||
ctx.symbols->Add(_var.Detach());
|
||||
return true;
|
||||
}
|
||||
bool ParseLocalVariable(ParserContext &ctx)
|
||||
{
|
||||
AutoPtr <Variable> _var(new Variable);
|
||||
_var->offset = ctx.CurrentOffset();
|
||||
_var->var_type = Variable::VarLocal;
|
||||
|
||||
const char *s = NextEntry(ctx.s, ctx.e);
|
||||
_var->name.Set(s, SkipEntry(s, ctx.e));
|
||||
ctx.symbols->Add(_var.Detach());
|
||||
|
||||
// parse subsequent declarations.
|
||||
s = NextEntry(s, ctx.e);
|
||||
|
||||
forever
|
||||
{
|
||||
/*
|
||||
// TODO a naive test won't do as there is no mandatory end-of-statement in Squirrel
|
||||
if (s[0] == '=')
|
||||
{
|
||||
// check if there are more variables declared by this statement
|
||||
}
|
||||
*/
|
||||
if (s[0] == ',')
|
||||
{
|
||||
s = NextEntry(s + 1, ctx.e);
|
||||
ctx.s = s;
|
||||
|
||||
_var = new Variable;
|
||||
_var->offset = ctx.CurrentOffset();
|
||||
_var->var_type = Variable::VarLocal;
|
||||
|
||||
_var->name.Set(s, SkipEntry(s, ctx.e));
|
||||
ctx.symbols->Add(_var.Detach());
|
||||
|
||||
s = NextEntry(s, ctx.e);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
ctx.s = s;
|
||||
return true;
|
||||
}
|
||||
bool ParseFunction(ParserContext &ctx)
|
||||
{
|
||||
AutoPtr <Function> _function(new Function);
|
||||
_function->offset = ctx.CurrentOffset();
|
||||
|
||||
const char *s = NextEntry(ctx.s, ctx.e);
|
||||
_function->name.Set(s, SkipEntry(s, ctx.e));
|
||||
|
||||
s = NextEntry(s, ctx.e);
|
||||
|
||||
// Parse prototype.
|
||||
if (s[0] != '(')
|
||||
return false;
|
||||
|
||||
const char *eoproto = RunToEOG(s, ctx.e, '(', ')');
|
||||
if (eoproto == NULL)
|
||||
return false;
|
||||
|
||||
_function->prototype.Set(s + 1, eoproto);
|
||||
s = NextEntry(eoproto + 1, ctx.e);
|
||||
|
||||
// Parse function content.
|
||||
if (s[0] != '{')
|
||||
return false;
|
||||
|
||||
const char *eofunc = RunToEOG(s, ctx.e, '{', '}');
|
||||
if (eofunc == NULL)
|
||||
eofunc = ctx.e;
|
||||
ParserContext func_ctx(s + 1, eofunc, ctx.o, &_function->symbols, _function->type);
|
||||
|
||||
ParseContext(func_ctx);
|
||||
|
||||
ctx.s = eofunc + 1;
|
||||
ctx.symbols->Add(_function.Detach());
|
||||
return true;
|
||||
}
|
||||
bool ParseClass(ParserContext &ctx)
|
||||
{
|
||||
AutoPtr <Class> _class(new Class);
|
||||
_class->offset = ctx.CurrentOffset();
|
||||
|
||||
ctx.s = NextEntry(ctx.s, ctx.e);
|
||||
_class->name.Set(ctx.s, SkipEntry(ctx.s, ctx.e));
|
||||
|
||||
const char *s = NextEntry(ctx.s, ctx.e);
|
||||
|
||||
if (!String::strccmp("extends", s))
|
||||
{
|
||||
s = NextEntry(s, ctx.e);
|
||||
_class->extends.Set(s, SkipEntry(s, ctx.e));
|
||||
|
||||
ctx.s = SkipEntry(s, ctx.e);
|
||||
|
||||
s = NextEntry(s, ctx.e);
|
||||
if (s == ctx.e)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse class content.
|
||||
if (s[0] != '{')
|
||||
return false;
|
||||
|
||||
const char *eoclass = RunToEOG(s, ctx.e, '{', '}');
|
||||
if (eoclass == NULL)
|
||||
eoclass = ctx.e;
|
||||
|
||||
ParserContext class_ctx(s + 1, eoclass, ctx.o, &_class->symbols, _class->type);
|
||||
ParseContext(class_ctx);
|
||||
|
||||
ctx.s = eoclass + 1;
|
||||
ctx.symbols->Add(_class.Detach());
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ParseContext(ParserContext &ctx)
|
||||
{
|
||||
for (bool r = true; r && (ctx.s < ctx.e); )
|
||||
{
|
||||
if (!String::strccmp("class", ctx.s))
|
||||
r = ParseClass(ctx);
|
||||
else if (!String::strccmp("function", ctx.s))
|
||||
r = ParseFunction(ctx);
|
||||
else if (!String::strccmp("local", ctx.s))
|
||||
r = ParseLocalVariable(ctx);
|
||||
else
|
||||
{
|
||||
const char *e = SkipEntry(ctx.s, ctx.e);
|
||||
String tmp(ctx.s, e);
|
||||
|
||||
const char *s = NextEntry(ctx.s, ctx.e);
|
||||
if (ctx.s == s)
|
||||
++ctx.s; // skip
|
||||
else
|
||||
{
|
||||
if ((s[0] == '<') && (s[1] == '-'))
|
||||
r = ParseGlobalVariable(ctx);
|
||||
else if ((ctx.type == Symbol::TypeClass) && (s[0] == '='))
|
||||
r = ParseMemberVariable(ctx);
|
||||
else
|
||||
ctx.s = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Source *ParseSource(const char *s, const char *e)
|
||||
{
|
||||
AutoPtr <Source> source(new Source);
|
||||
|
||||
ParserContext ctx(s, e, s, &source->symbols, Symbol::TypeNone);
|
||||
ParseContext(ctx);
|
||||
|
||||
return source.Detach();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Source *SquirrelAnalyzer::Analyze(const char *nut, Program &program, bool replace)
|
||||
{
|
||||
Source *old_source = ListFindEx(program.sources, SourceFindByNameFunctor, nut);
|
||||
if (old_source && !replace)
|
||||
return NULL;
|
||||
|
||||
String source;
|
||||
{
|
||||
Array <char> buffer;
|
||||
if (!Platform::Get().io->FileLoad(nut, buffer))
|
||||
return NULL;
|
||||
source.Set(buffer.c_ptr(), buffer.c_ptr() + buffer.GetCount());
|
||||
}
|
||||
|
||||
Source *new_source = ParseSource(source.c_str(), source.c_str() + source.Len());
|
||||
if (!new_source)
|
||||
return NULL;
|
||||
|
||||
new_source->name = nut;
|
||||
|
||||
program.sources.Remove(old_source);
|
||||
program.sources.Add(new_source);
|
||||
return new_source;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
88
include/modules/script_squirrel/squirrel_analyzer_debug.cpp
Normal file
88
include/modules/script_squirrel/squirrel_analyzer_debug.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/squirrel_analyzer.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::SquirrelAnalyzer;
|
||||
|
||||
|
||||
void DumpSymbols(const SharedList <Symbol *> &, int);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void DumpSymbol(const Symbol *symbol, int tab)
|
||||
{
|
||||
for (int n = 0; n < tab; ++n)
|
||||
__LOG__ << " ";
|
||||
|
||||
__LOG__ << "offset: line " << symbol->offset.line << ", column " << symbol->offset.column << " -> ";
|
||||
|
||||
switch (symbol->type)
|
||||
{
|
||||
case Symbol::TypeClass:
|
||||
if (Class *c = (Class *)symbol)
|
||||
{
|
||||
__LOG__ << "Class " << c->name;
|
||||
if (!c->extends.IsEmpty())
|
||||
__LOG__ << " extends: " << c->extends << "\n";
|
||||
__LOG__ << "\n";
|
||||
|
||||
DumpSymbols(c->symbols, tab + 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case Symbol::TypeFunction:
|
||||
if (Function *f = (Function *)symbol)
|
||||
{
|
||||
__LOG__ << "Function " << f->name << "(" << f->prototype << ")\n";
|
||||
DumpSymbols(f->symbols, tab + 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case Symbol::TypeVariable:
|
||||
if (Variable *v = (Variable *)symbol)
|
||||
switch (v->var_type)
|
||||
{
|
||||
case Variable::VarLocal: __LOG__ << "Local variable " << v->name << "\n"; break;
|
||||
case Variable::VarGlobal: __LOG__ << "Global variable " << v->name << "\n"; break;
|
||||
case Variable::VarMember: __LOG__ << "Member variable " << v->name << "\n"; break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
__LOG__ << "Variable " << symbol->name << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
void DumpSymbols(const SharedList <Symbol *> &symbols, int tab)
|
||||
{
|
||||
ListForeachPtr(Symbol *, symbol, symbols)
|
||||
DumpSymbol(symbol, tab);
|
||||
}
|
||||
void DumpSource(const Source *source)
|
||||
{
|
||||
ListForeachPtr(Symbol *, symbol, source->symbols)
|
||||
{
|
||||
switch (symbol->type)
|
||||
{
|
||||
case Symbol::TypeClass: __LOG__ << " Class"; break;
|
||||
case Symbol::TypeFunction: __LOG__ << " Function"; break;
|
||||
case Symbol::TypeVariable: __LOG__ << " Variable"; break;
|
||||
}
|
||||
|
||||
__LOG__ << " '" << symbol->name << "'\n";
|
||||
}
|
||||
}
|
||||
void DumpProgram(const Program &program)
|
||||
{
|
||||
ListForeachPtr(Source *, source, program.sources)
|
||||
{
|
||||
__LOG__ << "Source '" << source->name << "'\n";
|
||||
DumpSymbols(source->symbols, 4);
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
398
include/modules/script_squirrel/squirrel_debugger.cpp
Normal file
398
include/modules/script_squirrel/squirrel_debugger.cpp
Normal file
@ -0,0 +1,398 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "script_squirrel/squirrel_debugger.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script_squirrel/cobject/vector_decl.h"
|
||||
#include "math/vector.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
String SquirrelDebugger::FormatParameter(DebuggerVariable *var)
|
||||
{
|
||||
switch (var->type)
|
||||
{
|
||||
case OT_STRING:
|
||||
return String::Format("%s=%s", var->id.c_str(), var->v_string.c_str());
|
||||
case OT_FLOAT:
|
||||
return String::Format("%s=%.4f", var->id.c_str(), var->v_float);
|
||||
case OT_INTEGER:
|
||||
return String::Format("%s=%d", var->id.c_str(), var->v_int);
|
||||
case OT_BOOL:
|
||||
return String::Format("%s=%s", var->id.c_str(), var->v_bool ? "True" : "False");
|
||||
}
|
||||
return var->id;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static int DebuggerCompareVariable(DebuggerVariable *&v, const char *s) { return !String::Compare(v->id, s); }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
DebuggerVariable *SquirrelDebugger::InsertVariable(const char *name, AutoList <DebuggerVariable *> &debug_var, int level)
|
||||
{
|
||||
// Catch nesting limit.
|
||||
if (level == 3)
|
||||
return NULL;
|
||||
|
||||
// Try to locate variable in the current watch.
|
||||
DebuggerVariable *var = ListFindEx(debug_var, DebuggerCompareVariable, name);
|
||||
|
||||
// Retrieve stack variable type.
|
||||
bool check_change = false, has_changed = false;
|
||||
|
||||
SQObjectType sq_type = sq_gettype(vm, -1);
|
||||
|
||||
if (var)
|
||||
{
|
||||
// If type has changed, drop the whole member watch structure.
|
||||
if (var->type != (uint)sq_type)
|
||||
var->member_list.Clear();
|
||||
else
|
||||
check_change = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var = new DebuggerVariable;
|
||||
if (!var)
|
||||
__ERR__(__LOG_E__ << "Failed to allocate debugger watch structure.\n", NULL);
|
||||
|
||||
debug_var.Add(var);
|
||||
var->id = name;
|
||||
}
|
||||
|
||||
// Update the variable.
|
||||
var->referenced = true;
|
||||
var->type = sq_type;
|
||||
|
||||
String type = "Unknown", value;
|
||||
int limit = 64 / (level + 1); // Increasingly limit array exploration the deeper in the hierarchy we get.
|
||||
|
||||
switch (sq_type)
|
||||
{
|
||||
case OT_NULL:
|
||||
type = "Null";
|
||||
break;
|
||||
|
||||
case OT_TABLE:
|
||||
{
|
||||
type = "Table";
|
||||
|
||||
// Check item slot.
|
||||
sq_pushnull(vm); // Iterator.
|
||||
while (SQ_SUCCEEDED(sq_next(vm, -2)))
|
||||
{
|
||||
// Here -1 is the value and -2 is the key.
|
||||
const SQChar *slot_name;
|
||||
if (sq_getstring(vm, -2, &slot_name) == SQ_OK)
|
||||
InsertVariable(slot_name, var->member_list, level + 1);
|
||||
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_ARRAY:
|
||||
{
|
||||
type = "Array";
|
||||
SQInteger array_size = sq_getsize(vm, -1);
|
||||
value = String::Format("{ Length=%d, [...] }", array_size);
|
||||
|
||||
// Check item slot.
|
||||
sq_pushnull(vm); // Iterator.
|
||||
while (SQ_SUCCEEDED(sq_next(vm, -2)))
|
||||
{
|
||||
int idx;
|
||||
sq_getinteger(vm, -2, (SQInteger *)&idx);
|
||||
String slot_name = String::Format("[%d]", idx);
|
||||
InsertVariable(slot_name, var->member_list, level + 1);
|
||||
sq_pop(vm, 2);
|
||||
|
||||
if (--limit == 0)
|
||||
break;
|
||||
}
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_CLOSURE:
|
||||
type = "Function";
|
||||
break;
|
||||
|
||||
case OT_NATIVECLOSURE:
|
||||
type = "C/C++";
|
||||
break;
|
||||
|
||||
case OT_OUTER:
|
||||
type = "Outer";
|
||||
break;
|
||||
|
||||
case OT_USERDATA:
|
||||
type = "User data";
|
||||
break;
|
||||
|
||||
case OT_GENERATOR:
|
||||
type = "Generator";
|
||||
break;
|
||||
|
||||
case OT_USERPOINTER:
|
||||
break;
|
||||
|
||||
case OT_THREAD:
|
||||
type = "Thread";
|
||||
break;
|
||||
|
||||
case OT_FUNCPROTO:
|
||||
type = "Prototype";
|
||||
break;
|
||||
|
||||
case OT_CLASS:
|
||||
type = "Class definition";
|
||||
break;
|
||||
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
type = "Class instance";
|
||||
|
||||
Vector4 *v = NULL;
|
||||
|
||||
CObjectType typetag;
|
||||
if (CObject::GetType(vm, -1, typetag))
|
||||
{
|
||||
type = CObjectTypeToString(typetag);
|
||||
value = FormatUserObjectParameter(typetag);
|
||||
}
|
||||
else if (SQ_SUCCEEDED(sq_getinstanceup(vm, -1, (SQUserPointer*)&v, (SQUserPointer)&__Vector_decl)))
|
||||
{
|
||||
type = "Vector";
|
||||
value = String::Format("{%.2f, %.2f, %.2f, %.2f}", v->x, v->y, v->z, v->w);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Trying iterating over instance members.
|
||||
AutoList <String *> member_list;
|
||||
|
||||
sq_getclass(vm, -1);
|
||||
sq_pushnull(vm); // Iterator.
|
||||
while (SQ_SUCCEEDED(sq_next(vm, -2)))
|
||||
{
|
||||
switch (sq_gettype(vm, -1))
|
||||
{
|
||||
case OT_CLOSURE:
|
||||
case OT_NATIVECLOSURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
const SQChar *slot_name;
|
||||
if (sq_getstring(vm, -2, &slot_name) == SQ_OK)
|
||||
member_list.Add(new String(slot_name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
sq_pop(vm, 2);
|
||||
|
||||
// Get actual instance values.
|
||||
ListForeachPtr(String *, m, member_list)
|
||||
{
|
||||
sq_pushstring(vm, m->c_str(), m->Len());
|
||||
if (sq_get(vm, -2) == SQ_OK)
|
||||
InsertVariable(m->c_str(), var->member_list, level + 1);
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_WEAKREF:
|
||||
type = "Weakref";
|
||||
break;
|
||||
|
||||
case OT_BOOL:
|
||||
{
|
||||
type = "Bool";
|
||||
SQBool b;
|
||||
sq_getbool(vm, -1, &b);
|
||||
value = b ? "True" : "False";
|
||||
has_changed = check_change ? var->v_bool != asbool(b) : false;
|
||||
var->v_bool = b ? true : false;
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_STRING:
|
||||
{
|
||||
type = "String";
|
||||
const SQChar *s;
|
||||
sq_getstring(vm, -1, &s);
|
||||
value = String::Format("%s", s);
|
||||
has_changed = check_change ? var->v_string != s : false;
|
||||
var->v_string = s;
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_INTEGER:
|
||||
{
|
||||
type = "Integer";
|
||||
SQInteger i;
|
||||
sq_getinteger(vm, -1, &i);
|
||||
value = String::Format("%d", i);
|
||||
has_changed = check_change ? var->v_int != i : false;
|
||||
var->v_int = (int)i;
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_FLOAT:
|
||||
{
|
||||
type = "Float";
|
||||
SQFloat f;
|
||||
sq_getfloat(vm, -1, &f);
|
||||
value = String::Format("%.4f", f);
|
||||
has_changed = check_change ? var->v_float != f : false;
|
||||
var->v_float = f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Value for item with sub-items.
|
||||
if (var->member_list.GetCount() && value.IsEmpty())
|
||||
{
|
||||
value = "{ ";
|
||||
|
||||
int max = 4;
|
||||
ListForeachPtr(DebuggerVariable *, v, var->member_list)
|
||||
{
|
||||
value += max > 0 ? FormatParameter(v).c_str() : "...";
|
||||
value += (iterator.Next() == NULL) || (max == 0) ? " }" : ", ";
|
||||
|
||||
if (!max--)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var->type_string = type;
|
||||
var->modified = has_changed;
|
||||
var->value = value;
|
||||
|
||||
return var;
|
||||
}
|
||||
void SquirrelDebugger::RefreshStackFrameLocalsCache()
|
||||
{
|
||||
// Mark all variables as unreferenced.
|
||||
DereferenceVarTree(local_var_tree);
|
||||
|
||||
// Update local variables.
|
||||
const char *var_name;
|
||||
for (int n = 0; (var_name = sq_getlocal(vm, debug_stack_frame, n)) != NULL; ++n)
|
||||
InsertVariable(var_name, local_var_tree, 0);
|
||||
|
||||
// Drop unreferenced variables.
|
||||
ListForeachPtr(DebuggerVariable *, v, local_var_tree)
|
||||
if (!v->referenced)
|
||||
local_var_tree.Remove(v);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SquirrelDebugger::VariableToMetatagString(DebuggerVariable *v, String &s)
|
||||
{
|
||||
s += String::Format("<Variable=<Name=\"%s\">\n", v->id.c_str());
|
||||
|
||||
switch (v->type)
|
||||
{
|
||||
case OT_NULL: s += "<ScriptType=\"Null\">\n"; break;
|
||||
case OT_TABLE: s += "<ScriptType=\"Table\">\n"; break;
|
||||
case OT_ARRAY: s += "<ScriptType=\"Array\">\n"; break;
|
||||
case OT_USERDATA: s += "<ScriptType=\"UserData\">\n"; break;
|
||||
case OT_CLOSURE: s += "<ScriptType=\"Closure\">\n"; break;
|
||||
case OT_NATIVECLOSURE: s += "<ScriptType=\"NativeClosure\">\n"; break;
|
||||
case OT_GENERATOR: s += "<ScriptType=\"Generator\">\n"; break;
|
||||
case OT_USERPOINTER: s += "<ScriptType=\"UserPointer\">\n"; break;
|
||||
case OT_THREAD: s += "<ScriptType=\"Thread\">\n"; break;
|
||||
case OT_FUNCPROTO: s += "<ScriptType=\"FuncProto\">\n"; break;
|
||||
case OT_CLASS: s += "<ScriptType=\"Class\">\n"; break;
|
||||
case OT_INSTANCE: s += "<ScriptType=\"Instance\">\n"; break;
|
||||
case OT_WEAKREF: s += "<ScriptType=\"Weakref\">\n"; break;
|
||||
case OT_BOOL: s += "<ScriptType=\"Bool\">\n"; break;
|
||||
case OT_STRING: s += "<ScriptType=\"String\">\n"; break;
|
||||
case OT_INTEGER: s += "<ScriptType=\"Integer\">\n"; break;
|
||||
case OT_FLOAT: s += "<ScriptType=\"Float\">\n"; break;
|
||||
}
|
||||
|
||||
// Display type.
|
||||
s += String::Format("<Type=\"%s\">\n", v->type_string.c_str());
|
||||
|
||||
// Value.
|
||||
if (!v->value.IsEmpty())
|
||||
s += String::Format("<ValueString=\"%s\">\n", v->value.c_str());
|
||||
|
||||
if (v->modified)
|
||||
s += "<Modified>";
|
||||
|
||||
// Members.
|
||||
if (v->member_list.GetCount())
|
||||
{
|
||||
s += "<Members=\n";
|
||||
ListForeachPtr(DebuggerVariable *, m, v->member_list)
|
||||
VariableToMetatagString(m, s);
|
||||
s += ">\n";
|
||||
}
|
||||
|
||||
s += ">\n";
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SquirrelDebugger::GetStackFrameSource(const char *&source, int &line)
|
||||
{
|
||||
SQStackInfos si;
|
||||
|
||||
if (SQ_SUCCEEDED(sq_stackinfos(vm, debug_stack_frame, &si)))
|
||||
{
|
||||
source = (const char *)si.source;
|
||||
line = si.line;
|
||||
}
|
||||
else
|
||||
{
|
||||
source = NULL;
|
||||
line = -1;
|
||||
}
|
||||
}
|
||||
int SquirrelDebugger::GetStackFrameIndex()
|
||||
{
|
||||
int depth = 0;
|
||||
|
||||
SQStackInfos si;
|
||||
for (int c = 0; SQ_SUCCEEDED(sq_stackinfos(vm, c, &si)); ++c)
|
||||
if (String(si.source) != "NATIVE") // Skip native C frame.
|
||||
{
|
||||
depth = c;
|
||||
break;
|
||||
}
|
||||
|
||||
return depth;
|
||||
}
|
||||
int SquirrelDebugger::GetCallstackDepth()
|
||||
{
|
||||
int depth = 0;
|
||||
SQStackInfos si;
|
||||
while (SQ_SUCCEEDED(sq_stackinfos(vm, depth, &si)))
|
||||
depth++;
|
||||
return depth;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
SquirrelDebugger::SquirrelDebugger(SquirrelVM &svm)
|
||||
{
|
||||
vm = svm.VM();
|
||||
}
|
||||
522
include/modules/script_squirrel/squirrel_vm.cpp
Normal file
522
include/modules/script_squirrel/squirrel_vm.cpp
Normal file
@ -0,0 +1,522 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <ctime>
|
||||
#include "squirrel.h"
|
||||
#include "sqstdio.h"
|
||||
#include "sqstdmath.h"
|
||||
#include "sqstdstring.h"
|
||||
#include "sqstdaux.h"
|
||||
#include "sqstdblob.h"
|
||||
#include "sqstdsystem.h"
|
||||
#include "script_squirrel/squirrel_vm.h"
|
||||
#include "script_squirrel/cobject/cobject.h"
|
||||
#include "script/script_variant.h"
|
||||
#include "filesystem/io_handle.h"
|
||||
#include "filesystem/filesystem.h"
|
||||
#include "viewer_base/viewer_base.h"
|
||||
#include "platform.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS;
|
||||
using namespace GS::Script;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SquirrelVM::GetCallStack(AutoList <CallStackEntry *> &callstack)
|
||||
{
|
||||
callstack.Clear();
|
||||
|
||||
SQStackInfos si;
|
||||
for (SQInteger level = 0; SQ_SUCCEEDED(sq_stackinfos(vm, level, &si)); ++level)
|
||||
callstack.Add(new CallStackEntry(si.source, si.funcname, si.line));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static void SqPrintFunc(HSQUIRRELVM v, const SQChar *s, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
va_start(arglist, s);
|
||||
char lcl[4096];
|
||||
|
||||
#ifdef __PLATFORM_WINDOWS__
|
||||
vsprintf_s(lcl, 4095, s, arglist);
|
||||
#else
|
||||
vsprintf(lcl, s, arglist);
|
||||
#endif
|
||||
|
||||
__LOG__ << "[S] " << lcl << "\n";
|
||||
va_end(arglist);
|
||||
}
|
||||
static void SqDebugHook(HSQUIRRELVM v, SQInteger type, const SQChar *sourcename, SQInteger line, const SQChar *funcname)
|
||||
{
|
||||
if (SquirrelVM *vm = (SquirrelVM *)sq_getforeignptr(v))
|
||||
if (vm->GetEventHandler())
|
||||
vm->GetEventHandler()->OnStep((char)type, sourcename, line, funcname);
|
||||
}
|
||||
static void SqCompilerError(HSQUIRRELVM v, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
|
||||
{
|
||||
if (SquirrelVM *vm = (SquirrelVM *)sq_getforeignptr(v))
|
||||
{
|
||||
String msg("Script runtime Compilation exception:\n");
|
||||
msg += String::Format(" - (line %d) in \"%s\"\n", line, source);
|
||||
__LOG_E__ << "Squirrel Compiler Error: '" << msg << "'\n\n";
|
||||
|
||||
if (vm->GetEventHandler())
|
||||
vm->GetEventHandler()->OnCompilerError(desc, source, line);
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm *timeinfo = localtime(&now);
|
||||
char timestamp[64];
|
||||
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d_%H-%M-%S", timeinfo);
|
||||
|
||||
String logFileName = String::Format("g_engine_log_%s.txt", timestamp);
|
||||
|
||||
// Check if g_engine_log.txt exists and copy it
|
||||
if (Platform::Get().io->Exists("g_engine_log.txt"))
|
||||
{
|
||||
if (Platform::Get().io->FileCopy("g_engine_log.txt", logFileName.c_str()))
|
||||
{
|
||||
__LOG_E__ << "Engine log copied to: " << logFileName << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
__LOG_E__ << "Failed to copy engine log to: " << logFileName << "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__LOG_E__ << "Engine log file 'g_engine_log.txt' not found for copying\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
static SQInteger SqRuntimeError(HSQUIRRELVM v)
|
||||
{
|
||||
SquirrelVM *vm = (SquirrelVM *)sq_getforeignptr(v);
|
||||
|
||||
// Get error string.
|
||||
const SQChar *error = NULL;
|
||||
if (SQ_FAILED(sq_getstring(v, 2, &error)))
|
||||
error = "Unspecified runtime error";
|
||||
|
||||
// Could be null if called from a coroutine.
|
||||
if (vm && (vm->GetState() == IVM::StateOk))
|
||||
{
|
||||
vm->SetState(IVM::StateExceptionThrown);
|
||||
|
||||
// Redirect to the signal handler.
|
||||
if (vm->GetEventHandler())
|
||||
{
|
||||
vm->GetEventHandler()->OnRuntimeException(error);
|
||||
return sq_suspendvm(v); // All debugging hope is lost beyond this point as the Squirrel VM will unwind all exception stack frame.
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = String::Format("Script runtime exception:\n\n%s", error);
|
||||
|
||||
AutoList <IVM::CallStackEntry *> callstack;
|
||||
vm->GetCallStack(callstack);
|
||||
|
||||
msg += "\n\nCallstack:\n\n";
|
||||
ListForeachPtr(IVM::CallStackEntry *, cs, callstack)
|
||||
msg += String::Format(" - %s() (line %d) in \"%s\"\n", cs->function.c_str(), cs->line, cs->source.c_str());
|
||||
|
||||
__LOG_E__ << "Squirrel Compiler Error: '" << msg << "'\n";
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm *timeinfo = localtime(&now);
|
||||
char timestamp[64];
|
||||
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d_%H-%M-%S", timeinfo);
|
||||
|
||||
String logFileName = String::Format("g_engine_log_%s.txt", timestamp);
|
||||
|
||||
// Check if g_engine_log.txt exists and copy it
|
||||
if (Platform::Get().io->Exists("g_engine_log.txt"))
|
||||
{
|
||||
if (Platform::Get().io->FileCopy("g_engine_log.txt", logFileName.c_str()))
|
||||
{
|
||||
__LOG_E__ << "Engine log copied to: " << logFileName << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
__LOG_E__ << "Failed to copy engine log to: " << logFileName << "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__LOG_E__ << "Engine log file 'g_engine_log.txt' not found for copying\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return sq_suspendvm(v);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SquirrelVM::SetDebugInterface(IDebug *i, bool debug)
|
||||
{
|
||||
sq_enabledebuginfo(vm, debug);
|
||||
/* if (vm)
|
||||
{
|
||||
sq_enabledebuginfo(vm, debug);
|
||||
if (debug)
|
||||
sq_setnativedebughook(vm, SqDebugHook);
|
||||
}
|
||||
IVM::SetDebugInterface(i, debug);*/
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SquirrelVM::DumpCallStack(HSQUIRRELVM v, const char *desc, String *msg)
|
||||
{
|
||||
SQStackInfos si;
|
||||
// SQInteger level = 1; // Level 0 is the native closure we are in.
|
||||
|
||||
__LOG_V__ << "\n";
|
||||
String _msg(String::Format("Call stack (%s):\n", desc ? desc : "Requested"));
|
||||
__LOG_V__ << _msg.c_str();
|
||||
|
||||
for (SQInteger level = 1; SQ_SUCCEEDED(sq_stackinfos(v, level, &si)); ++level)
|
||||
{
|
||||
String _lg;
|
||||
|
||||
if (si.funcname)
|
||||
{
|
||||
if (si.line != -1)
|
||||
_lg = String::Format(" %d: %s() %s(%d)", level, si.funcname, si.source, si.line);
|
||||
else _lg = String::Format(" %d: %s() C/C++", level, si.funcname);
|
||||
}
|
||||
else
|
||||
_lg = String::Format(" %d: NOINFO", level);
|
||||
|
||||
__LOG_V__ << _lg << "\n";
|
||||
_msg += _lg;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
*msg = _msg;
|
||||
__LOG_V__ << "\n";
|
||||
}
|
||||
bool SquirrelVM::Compile(const char *source, uint size, const Object *context, const char *sourcename)
|
||||
{
|
||||
if (!source)
|
||||
return false;
|
||||
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, source, size, sourcename, true)))
|
||||
{
|
||||
sq_pushroottable(vm);
|
||||
sq_call(vm, 1, SQFalse, SQTrue);
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Object *SquirrelVM::GetObjectFromStack(int idx)
|
||||
{
|
||||
HSQOBJECT o;
|
||||
sq_getstackobj(vm, idx, &o);
|
||||
return new SquirrelObject(*this, o);
|
||||
}
|
||||
Object *SquirrelVM::GetObjectFromName(const char *name, const Object *context)
|
||||
{
|
||||
if (context)
|
||||
sq_pushobject(vm, ((const SquirrelObject *)context)->object);
|
||||
else sq_pushroottable(vm);
|
||||
|
||||
sq_pushstring(vm, name, -1);
|
||||
if (SQ_FAILED(sq_get(vm, -2)))
|
||||
{
|
||||
sq_pop(vm, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Object *o = GetObjectFromStack(-1);
|
||||
sq_pop(vm, 2);
|
||||
return o;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool SquirrelVM::SetupFunctionCall(const char *func, const Object *cache, const Object *context)
|
||||
{
|
||||
if (!vm || (GetState() != StateOk))
|
||||
return false;
|
||||
|
||||
if (cache)
|
||||
sq_pushobject(vm, ((SquirrelObject *)cache)->object);
|
||||
else
|
||||
{
|
||||
if (context)
|
||||
sq_pushobject(vm, ((SquirrelObject *)context)->object);
|
||||
else sq_pushroottable(vm);
|
||||
|
||||
sq_pushstring(vm, func, -1);
|
||||
if (SQ_FAILED(sq_get(vm, -2)))
|
||||
{
|
||||
sq_pop(vm, 1); // Cleanup root table.
|
||||
return false;
|
||||
}
|
||||
sq_remove(vm, -2); // Remove root table.
|
||||
}
|
||||
|
||||
// Push function environment.
|
||||
if (context)
|
||||
sq_pushobject(vm, ((SquirrelObject *)context)->object);
|
||||
else sq_pushroottable(vm);
|
||||
|
||||
call_arg_count = 1;
|
||||
return true;
|
||||
}
|
||||
bool SquirrelVM::SetFunctionCallContext(const Script::Variant &v)
|
||||
{
|
||||
return PushArgument(v);
|
||||
}
|
||||
bool SquirrelVM::PushNullArgument()
|
||||
{
|
||||
call_arg_count++;
|
||||
return PushNull();
|
||||
}
|
||||
bool SquirrelVM::PushArgument(const Script::Variant &v)
|
||||
{
|
||||
call_arg_count++;
|
||||
return PushVariant(v);
|
||||
}
|
||||
bool SquirrelVM::DoFunctionCall(Script::Variant *v)
|
||||
{
|
||||
if (GetState() != StateOk)
|
||||
return false;
|
||||
if (SQ_FAILED(sq_call(vm, call_arg_count, SQTrue, SQTrue)))
|
||||
return false;
|
||||
|
||||
if (v)
|
||||
GetVariantFromStack(-1, *v);
|
||||
sq_pop(vm, 2);
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool SquirrelVM::GetVariantFromStack(int idx, Script::Variant &v)
|
||||
{
|
||||
switch (sq_gettype(vm, idx))
|
||||
{
|
||||
case OT_STRING:
|
||||
{
|
||||
const SQChar *s;
|
||||
sq_getstring(vm, idx, &s);
|
||||
v.Set((const char *)s);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool b;
|
||||
sq_getbool(vm, idx, &b);
|
||||
v.Set(asbool(b));
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger i;
|
||||
sq_getinteger(vm, idx, &i);
|
||||
v.Set((int)i);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat f;
|
||||
sq_getfloat(vm, idx, &f);
|
||||
v.Set((float)f);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
HSQOBJECT o;
|
||||
sq_getstackobj(vm, idx, &o);
|
||||
v.Set(new SquirrelObject(*this, o), true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SquirrelVM::Get(const char *name, Script::Variant &prop, const Object *context)
|
||||
{
|
||||
if (context)
|
||||
sq_pushobject(vm, ((SquirrelObject *)context)->object);
|
||||
else sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
if (SQ_FAILED(sq_get(vm, -2)))
|
||||
{
|
||||
sq_pop(vm, 1);
|
||||
return false;
|
||||
}
|
||||
bool r = GetVariantFromStack(-1, prop);
|
||||
sq_pop(vm, 2);
|
||||
return r;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool SquirrelVM::PushNull()
|
||||
{
|
||||
sq_pushnull(vm);
|
||||
return true;
|
||||
}
|
||||
bool SquirrelVM::PushVariant(const Script::Variant &v)
|
||||
{
|
||||
switch (v.type)
|
||||
{
|
||||
case Variant::Type_Variant:
|
||||
switch (v.variant.GetType())
|
||||
{
|
||||
case GS::Variant::VariantString:
|
||||
sq_pushstring(vm, v.variant.s_value.c_str(), -1);
|
||||
break;
|
||||
case GS::Variant::VariantInteger:
|
||||
sq_pushinteger(vm, v.variant.i_value);
|
||||
break;
|
||||
case GS::Variant::VariantBool:
|
||||
sq_pushbool(vm, v.variant.b_value);
|
||||
break;
|
||||
case GS::Variant::VariantFloat:
|
||||
sq_pushfloat(vm, v.variant.f_value);
|
||||
break;
|
||||
|
||||
default:
|
||||
__LOG_E__ << "Unsupported variant type: " << v.type << ".\n";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case Variant::Type_ScriptObject:
|
||||
sq_pushobject(VM(), ((SquirrelObject *)v.object)->object);
|
||||
break;
|
||||
|
||||
case Variant::Type_UserObject:
|
||||
return CObject::Push(VM(), v.ptr, CObjectType(v.typetag));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SquirrelVM::Set(const char *name, const Script::Variant &v, const Object *context)
|
||||
{
|
||||
if (context)
|
||||
sq_pushobject(vm, ((SquirrelObject *)context)->object);
|
||||
else sq_pushroottable(vm);
|
||||
sq_pushstring(vm, name, -1);
|
||||
if (!PushVariant(v))
|
||||
{
|
||||
sq_pop(vm, 2);
|
||||
return false;
|
||||
}
|
||||
SQObjectType type = sq_gettype(vm, -3);
|
||||
if ((type == OT_CLASS) || (type == OT_TABLE))
|
||||
sq_newslot(vm, -3, false);
|
||||
else sq_set(vm, -3);
|
||||
sq_pop(vm, 1);
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Object *SquirrelVM::CreateArray()
|
||||
{
|
||||
sq_newarray(vm, 0);
|
||||
Object *o = GetObjectFromStack(-1);
|
||||
sq_pop(vm, 1);
|
||||
return o;
|
||||
}
|
||||
bool SquirrelVM::Append(const Script::Variant &prop, const Object *context)
|
||||
{
|
||||
if (context)
|
||||
sq_pushobject(vm, ((SquirrelObject *)context)->object);
|
||||
else sq_pushroottable(vm);
|
||||
if (!PushVariant(prop))
|
||||
{
|
||||
sq_pop(vm, 1);
|
||||
return false;
|
||||
}
|
||||
sq_arrayappend(vm, -2);
|
||||
sq_pop(vm, 1);
|
||||
return true;
|
||||
}
|
||||
Object *SquirrelVM::CreateTable()
|
||||
{
|
||||
sq_newtable(vm);
|
||||
Object *o = GetObjectFromStack(-1);
|
||||
sq_pop(vm, 1);
|
||||
return o;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool SquirrelVM::Open()
|
||||
{
|
||||
if (vm)
|
||||
return true;
|
||||
|
||||
vm = sq_open(1024);
|
||||
if (!vm)
|
||||
return false;
|
||||
|
||||
sq_setforeignptr(vm, (SQUserPointer)this);
|
||||
|
||||
sq_setcompilererrorhandler(vm, SqCompilerError);
|
||||
sq_setprintfunc(vm, SqPrintFunc, SqPrintFunc);
|
||||
sq_newclosure(vm, SqRuntimeError, 0);
|
||||
sq_seterrorhandler(vm);
|
||||
|
||||
sq_pushroottable(vm);
|
||||
sqstd_register_bloblib(vm);
|
||||
sqstd_register_iolib(vm);
|
||||
sqstd_register_systemlib(vm);
|
||||
sqstd_register_mathlib(vm);
|
||||
sqstd_register_stringlib(vm);
|
||||
sq_pop(vm, 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
void SquirrelVM::Close()
|
||||
{
|
||||
//if (vm)
|
||||
// sq_close(vm);
|
||||
|
||||
vm = NULL;
|
||||
state = StateOk;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SquirrelObject::SquirrelObject(SquirrelVM &_vm, HSQOBJECT _object) : Object(_vm)
|
||||
{
|
||||
object = _object;
|
||||
sq_addref(((SquirrelVM &)vm).VM(), &object);
|
||||
}
|
||||
SquirrelObject::~SquirrelObject()
|
||||
{
|
||||
sq_release(((SquirrelVM &)vm).VM(), &object);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SquirrelVM::SquirrelVM()
|
||||
{
|
||||
vm = NULL;
|
||||
call_arg_count = 0;
|
||||
}
|
||||
SquirrelVM::~SquirrelVM()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user