commit x64 compilation from lulu cause the other branch dont seems to compile properly at home

This commit is contained in:
2026-07-17 16:08:20 +02:00
parent c0f3eeb00d
commit 0efa4ee6f7
625 changed files with 117283 additions and 4426 deletions

View 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
#*/
}

View 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);
}

View 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);
}

View 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"));
}
//------------------------------------------------------------------------------

View 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);
}

View 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"));
}

View 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"));
}
//------------------------------------------------------------------------------

View 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"));
}

View 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"));
}

View 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"));
}

View 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&amp;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("."));
}

View 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"));
}
//------------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View 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);
}
//------------------------------------------------------------------------------

View 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);
}
//------------------------------------------------------------------------------

View File

@ -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"));
}
//------------------------------------------------------------------------------

View 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"));
}
//------------------------------------------------------------------------------

View 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);
}
//------------------------------------------------------------------------------

View 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);
}
//------------------------------------------------------------------------------

View 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);
}
//-----------------------------------------------------------------------------

View 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"));
}
//------------------------------------------------------------------------------

View 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"));
}
//------------------------------------------------------------------------------

View 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);
}
//------------------------------------------------------------------------------

View 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);
}

View 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("."));
}
//------------------------------------------------------------------------------

View 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("."));
}

View 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);
}
//------------------------------------------------------------------------------

View 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"));
}
//------------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -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"));
}
//------------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View 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"));
}
//------------------------------------------------------------------------------

View 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);
}

View File

@ -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);

View 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);
}
//------------------------------------------------------------------------------

View 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);
}
//------------------------------------------------------------------------------

View 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"));
}
//------------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View 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