修改游戏底层矩阵相关
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#include "squirrel/SquirrelEx.h"
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
#include "Sqr_CommonFunc.hpp"
|
||||
#include "EngineFrame/Component/Sprite.h"
|
||||
#include "EngineFrame/Component/Canvas.h"
|
||||
#include "EngineFrame/Component/Text.h"
|
||||
|
||||
static SQInteger _file_releasehook(SQUserPointer p, SQInteger SQ_UNUSED_ARG(size))
|
||||
{
|
||||
@@ -27,6 +28,27 @@ static SQInteger SQR_CreateActor(HSQUIRRELVM v)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger SQR_SetName(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
const SQChar *name;
|
||||
sq_getstring(v, 3, &name);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetName(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger SQR_GetName(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
sq_pushstring(v, Aobj->GetName().c_str(), -1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger SQR_AddChild(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
@@ -76,7 +98,7 @@ static SQInteger SQR_GetPos(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
VecFPos Pos = Aobj->GetPos();
|
||||
Vec2 Pos = Aobj->GetPos();
|
||||
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("x"), -1);
|
||||
@@ -95,7 +117,7 @@ static SQInteger SQR_SetPos(HSQUIRRELVM v)
|
||||
|
||||
if (sq_gettop(v) == 3)
|
||||
{
|
||||
VecFPos Pos;
|
||||
Vec2 Pos;
|
||||
sq_pushnull(v); // null iterator
|
||||
while (SQ_SUCCEEDED(sq_next(v, 3)))
|
||||
{
|
||||
@@ -125,7 +147,7 @@ static SQInteger SQR_SetPos(HSQUIRRELVM v)
|
||||
sq_getfloat(v, 3, &X);
|
||||
sq_getfloat(v, 4, &Y);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetPos(VecFPos(X, Y));
|
||||
Aobj->SetPos(Vec2(X, Y));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -135,7 +157,7 @@ static SQInteger SQR_GetWorldPos(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
VecFPos Pos = Aobj->GetWorldPos();
|
||||
Vec2 Pos = Aobj->GetWorldPos();
|
||||
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("x"), -1);
|
||||
@@ -172,7 +194,7 @@ static SQInteger SQR_GetScale(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
VecFPos Pos = Aobj->GetScale();
|
||||
Vec2 Pos = Aobj->GetScale();
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("x"), -1);
|
||||
sq_pushfloat(v, Pos.x);
|
||||
@@ -190,7 +212,7 @@ static SQInteger SQR_SetScale(HSQUIRRELVM v)
|
||||
|
||||
if (sq_gettop(v) == 3)
|
||||
{
|
||||
VecFPos Pos;
|
||||
Vec2 Pos;
|
||||
sq_pushnull(v); // null iterator
|
||||
while (SQ_SUCCEEDED(sq_next(v, 3)))
|
||||
{
|
||||
@@ -220,7 +242,7 @@ static SQInteger SQR_SetScale(HSQUIRRELVM v)
|
||||
sq_getfloat(v, 3, &X);
|
||||
sq_getfloat(v, 4, &Y);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetScale(VecFPos(X, Y));
|
||||
Aobj->SetScale(Vec2(X, Y));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -232,6 +254,7 @@ static SQInteger SQR_GetRotation(HSQUIRRELVM v)
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
|
||||
sq_pushfloat(v, Aobj->GetRotation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger SQR_SetRotation(HSQUIRRELVM v)
|
||||
@@ -314,6 +337,26 @@ static SQInteger SQR_SetVisible(HSQUIRRELVM v){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger SQR_GetVisible(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
sq_pushbool(v, Aobj->GetVisible());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger SQR_SetBlendMode(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
SQInteger Value;
|
||||
sq_getinteger(v, 3, &Value);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetBlendMode((LE_BlEND_MODE)Value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger SQR_CreateSprite(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *ImgPath;
|
||||
@@ -326,6 +369,77 @@ static SQInteger SQR_CreateSprite(HSQUIRRELVM v)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger SQR_CreateCanvas(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger Width, Height;
|
||||
sq_getinteger(v, 2, &Width);
|
||||
sq_getinteger(v, 3, &Height);
|
||||
RefPtr<Canvas> act = new Canvas(VecSize(Width, Height));
|
||||
act->Retain();
|
||||
sq_pushuserpointer(v, act.Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger SQR_Canvas_DrawImg(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
const SQChar *ImgPath;
|
||||
SQInteger Idx;
|
||||
Vec2 Pos;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
sq_getstring(v, 3, &ImgPath);
|
||||
sq_getinteger(v, 4, &Idx);
|
||||
sq_GetVec2(v, 5, &Pos);
|
||||
Canvas *Aobj = (Canvas *)A_obj;
|
||||
Aobj->DrawImg(ImgPath, Idx, Pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger SQR_Canvas_DrawImgRect(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
const SQChar *ImgPath;
|
||||
SQInteger Idx;
|
||||
SDL_FRect Rect;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
sq_getstring(v, 3, &ImgPath);
|
||||
sq_getinteger(v, 4, &Idx);
|
||||
sq_GetFRect(v, 5, &Rect);
|
||||
Canvas *Aobj = (Canvas *)A_obj;
|
||||
Aobj->DrawImg(ImgPath, Idx, Rect);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger SQR_CreateText(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *Str;
|
||||
SQInteger FontIndex, FontColor;
|
||||
SDL_Color color;
|
||||
sq_getstring(v, 2, &Str);
|
||||
sq_getinteger(v, 3, &FontIndex);
|
||||
sq_getinteger(v, 4, &FontColor);
|
||||
color.a = (FontColor >> 24) & 0xFF;
|
||||
color.r = (FontColor >> 16) & 0xFF;
|
||||
color.g = (FontColor >> 8) & 0xFF;
|
||||
color.b = FontColor & 0xFF;
|
||||
RefPtr<Text> act = new Text();
|
||||
act->Init(Str, Global_Game::GetInstance().Fonts[FontIndex], color);
|
||||
act->Retain();
|
||||
sq_pushuserpointer(v, act.Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger SQR_Text_SetText(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer A_obj;
|
||||
const SQChar *Str;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
sq_getstring(v, 3, &Str);
|
||||
Text *Aobj = (Text *)A_obj;
|
||||
Aobj->SetText(Str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void RegisterUINutApi(const SQChar *funcName, SQFUNCTION funcAddr, HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushroottable(v);
|
||||
@@ -344,6 +458,8 @@ static void RegisterUI()
|
||||
RegisterUINutApi(_SC("sq_RegisterDestruction"), SQR_RegisterDestruction, v);
|
||||
|
||||
RegisterUINutApi(_SC("sq_CreateActor"), SQR_CreateActor, v);
|
||||
RegisterUINutApi(_SC("sq_SetName"), SQR_SetName, v);
|
||||
RegisterUINutApi(_SC("sq_GetName"), SQR_GetName, v);
|
||||
RegisterUINutApi(_SC("sq_AddChild"), SQR_AddChild, v);
|
||||
RegisterUINutApi(_SC("sq_RemoveChild"), SQR_RemoveChild, v);
|
||||
RegisterUINutApi(_SC("sq_GetZOrder"), SQR_GetZOrder, v);
|
||||
@@ -360,6 +476,15 @@ static void RegisterUI()
|
||||
RegisterUINutApi(_SC("sq_GetSize"), SQR_GetSize, v);
|
||||
RegisterUINutApi(_SC("sq_SetSize"), SQR_SetSize, v);
|
||||
RegisterUINutApi(_SC("sq_SetVisible"), SQR_SetVisible, v);
|
||||
RegisterUINutApi(_SC("sq_GetVisible"), SQR_GetVisible, v);
|
||||
RegisterUINutApi(_SC("sq_SetBlendMode"), SQR_SetBlendMode, v);
|
||||
|
||||
RegisterUINutApi(_SC("sq_CreateSprite"), SQR_CreateSprite, v);
|
||||
|
||||
RegisterUINutApi(_SC("sq_CreateCanvas"), SQR_CreateCanvas, v);
|
||||
RegisterUINutApi(_SC("sq_Canvas_DrawImg"), SQR_Canvas_DrawImg, v);
|
||||
RegisterUINutApi(_SC("sq_Canvas_DrawImgRect"), SQR_Canvas_DrawImgRect, v);
|
||||
|
||||
RegisterUINutApi(_SC("sq_CreateText"), SQR_CreateText, v);
|
||||
RegisterUINutApi(_SC("sq_Text_SetText"), SQR_Text_SetText, v);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
void SquirrelManager::Init()
|
||||
{
|
||||
SDL_Log("开始初始化sqr管理器!");
|
||||
// 系统函数
|
||||
RegisterSystem();
|
||||
// UI函数
|
||||
RegisterUI();
|
||||
// 基础对象
|
||||
@@ -11,4 +13,6 @@ void SquirrelManager::Init()
|
||||
RegisterActiveObject();
|
||||
// 角色对象
|
||||
RegisterCharacterObject();
|
||||
//资产
|
||||
RegisterAsset();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
#include "Global/Global_Game.h"
|
||||
#include "Asset/Squirrel/Sqr_System.hpp"
|
||||
#include "Asset/Squirrel/Sqr_UI.hpp"
|
||||
#include "Asset/Squirrel/Sqr_BaseObject.hpp"
|
||||
#include "Asset/Squirrel/Sqr_ActiveObject.hpp"
|
||||
#include "Asset/Squirrel/Sqr_CharacterObject.hpp"
|
||||
#include "Asset/Squirrel/Sqr_Asset.hpp"
|
||||
class SquirrelManager
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user