Skip to content

Feature/spine support#82

Open
ChensenCHX wants to merge 19 commits intomasterfrom
feature/spine-support
Open

Feature/spine support#82
ChensenCHX wants to merge 19 commits intomasterfrom
feature/spine-support

Conversation

@ChensenCHX
Copy link
Collaborator

support for spine 4.2

@Demonese
Copy link
Contributor

Demonese commented Oct 31, 2025

请提供一个 CMake option 控制该功能是否启用,Spine 需要拥有一个有效的 Spine 编辑器许可证,你不要默认集成进引擎里。

@ChensenCHX
Copy link
Collaborator Author

已添加 默认为OFF

@ChensenCHX ChensenCHX self-assigned this Oct 31, 2025
}
LAPP.updateGraph2DBlendMode(mode);

auto vertices = new core::Graphics::IRenderer::DrawVertex[n_vertices];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么每帧都分配新的顶点数组

auto skeleton = data->getSkeleton();
auto& skeletonRenderer = spine::LuaSTGSkeletonRenderer::Instance();
spine::RenderCommand* command = skeletonRenderer.render(*skeleton);
while (command) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少合批处理,DrawCall 数量过多


return 1;
}
static int setBoneState(lua_State* L)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以考虑让这些 api 支持链式调用,对 spine 来说这种场景较多

Comment on lines +19 to +22
std::unordered_map<std::string_view, Bone*> bonecache;
std::unordered_map<std::string_view, Animation*> animationcache;
std::unordered_map <std::string_view, Skin*> skincache;
std::unordered_map <std::string_view, LuaSTGSlotCacheHelper> slotcache;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

潜在的代码问题,且性能可能不如直接用字符串或 hash

#define GETUDATA(p, i) SpineInstance* (p) = static_cast<SpineInstance*>(luaL_checkudata(L, (i), LUASTG_LUA_TYPENAME_SPINE));
struct Wrapper
{
static int CreateSpineInstance(lua_State* L) noexcept
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

创建的 instance 指针管理似乎有误,会导致资源允许在实例存活期间被卸载,这会导致潜在的空指针异常

Comment on lines +107 to +111
{
lua_State* L = LAPP.GetLuaEngine();
if (animation_callback != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, animation_callback);
if (event_callback != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, event_callback);
if (self_weak_table != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, self_weak_table);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

潜在的空指针错误

Comment on lines +598 to +603

auto listener = [data](spine::AnimationState* state, spine::EventType type, spine::TrackEntry* entry, spine::Event* event)
{
lua_State* L = LAPP.GetLuaEngine();
int stack_top = lua_gettop(L);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

潜在的悬空指针错误

lua_pushnumber(L, event->getBalance());
lua_pushnumber(L, event->getVolume());

lua_call(L, 8, 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不安全的调用


return 1;
}
static int setEventListener(lua_State* L)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

回调缺少重入保护机制,可能在回调中触发回调
比如在回调中设置新的 animation 时

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议改用类似这种风格的 api 设计

spine.events:on("animation", function(event)
    print(event.type, event.animation)
end)


auto listener = [data](spine::AnimationState* state, spine::EventType type, spine::TrackEntry* entry, spine::Event* event)
{
lua_State* L = LAPP.GetLuaEngine();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能在不安全的线程被调用


auto* ctx = LAPP.GetAppModel()->getRenderer();
core::Graphics::IRenderer::DrawVertex vertex[3];
vertex[0].z = 0.5f; vertex[1].z = 0.5f; vertex[2].z = 0.5f;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

真的要硬编码写死 z = 0.5

Copy link

@BAKAOLC BAKAOLC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以多参考一下已有的实现方案进行设计
比如 cocos,甚至 luastg-x 那边的实现方案也是能参考的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants