Merge branch 'master' of https://github.com/c4games/engine-x into master
This commit is contained in:
halx99 2020-08-05 18:12:31 +08:00
parent 4713580381
commit 8af53505c1
7 changed files with 81 additions and 86 deletions

View File

@ -57,7 +57,7 @@ set(lua_bindings_manual_files
manual/network/lua_cocos2dx_network_manual.cpp
manual/network/lua_xml_http_request.cpp
manual/network/lua_downloader.cpp
#manual/spine/lua_cocos2dx_spine_manual.cpp
manual/spine/lua_cocos2dx_spine_manual.cpp
manual/spine/LuaSkeletonAnimation.cpp
manual/ui/lua_cocos2dx_ui_manual.cpp
manual/audioengine/lua_cocos2dx_audioengine_manual.cpp
@ -88,7 +88,7 @@ set(lua_bindings_auto_files
auto/lua_cocos2dx_controller_auto.cpp
auto/lua_cocos2dx_extension_auto.cpp
auto/lua_cocos2dx_physics_auto.cpp
#auto/lua_cocos2dx_spine_auto.cpp
auto/lua_cocos2dx_spine_auto.cpp
auto/lua_cocos2dx_studio_auto.cpp
auto/lua_cocos2dx_csloader_auto.cpp
auto/lua_cocos2dx_ui_auto.cpp

View File

@ -1,5 +1,5 @@
#include "scripting/lua-bindings/auto/lua_cocos2dx_spine_auto.hpp"
#include "editor-support/spine/spine-cocos2dx.h"
#include "spine/spine-cocos2dx.h"
#include "scripting/lua-bindings/manual/tolua_fix.h"
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"

View File

@ -43,7 +43,7 @@ int lua_module_register(lua_State* L)
register_ui_module(L);
register_extension_module(L);
//TODO arnold
// register_spine_module(L);
register_spine_module(L);
register_cocos3d_module(L);
register_audioengine_module(L);
#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION

View File

@ -48,8 +48,7 @@ LuaSkeletonAnimation::~LuaSkeletonAnimation()
LuaSkeletonAnimation* LuaSkeletonAnimation::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale)
{
LuaSkeletonAnimation* node = new (std::nothrow) LuaSkeletonAnimation();
spine::Atlas* atlas = new spine::Atlas(atlasFile, nullptr);
node->initWithJsonFile(skeletonDataFile, atlas, scale);
node->initWithJsonFile(skeletonDataFile, atlasFile, scale);
node->autorelease();
return node;
}

View File

@ -29,8 +29,8 @@
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"
#include "scripting/lua-bindings/manual/cocos2d/LuaScriptHandlerMgr.h"
#include "scripting/lua-bindings/manual/CCLuaValue.h"
#include "editor-support/spine/spine.h"
#include "editor-support/spine/spine-cocos2dx.h"
#include "spine/spine.h"
#include "spine/spine-cocos2dx.h"
#include "scripting/lua-bindings/manual/spine/LuaSkeletonAnimation.h"
#include "scripting/lua-bindings/manual/CCLuaEngine.h"
@ -99,7 +99,7 @@ tolua_lerror:
return 0;
}
int executeSpineEvent(LuaSkeletonAnimation* skeletonAnimation, int handler, spEventType eventType, spTrackEntry* entry, spEvent* event = nullptr )
int executeSpineEvent(LuaSkeletonAnimation* skeletonAnimation, int handler, spine::EventType eventType, spine::TrackEntry* entry, spine::Event* event = nullptr )
{
if (nullptr == skeletonAnimation || 0 == handler)
return 0;
@ -114,36 +114,36 @@ int executeSpineEvent(LuaSkeletonAnimation* skeletonAnimation, int handler, spEv
int ret = 0;
std::string animationName = (entry && entry->animation) ? entry->animation->name : "";
std::string animationName = (entry && entry->getAnimation()) ? entry->getAnimation()->getName().buffer() : "";
std::string eventTypeName = "";
switch (eventType) {
case spEventType::SP_ANIMATION_START:
case spine::EventType::EventType_Start:
{
eventTypeName = "start";
}
break;
case spEventType::SP_ANIMATION_INTERRUPT:
case spine::EventType::EventType_Interrupt:
{
eventTypeName = "interrupt";
}
break;
case spEventType::SP_ANIMATION_END:
case spine::EventType::EventType_End:
{
eventTypeName = "end";
}
break;
case spEventType::SP_ANIMATION_DISPOSE:
case spine::EventType::EventType_Dispose:
{
eventTypeName = "dispose";
}
break;
case spEventType::SP_ANIMATION_COMPLETE:
case spine::EventType::EventType_Complete:
{
eventTypeName = "complete";
}
break;
case spEventType::SP_ANIMATION_EVENT:
case spine::EventType::EventType_Event:
{
eventTypeName = "event";
}
@ -155,17 +155,17 @@ int executeSpineEvent(LuaSkeletonAnimation* skeletonAnimation, int handler, spEv
LuaValueDict spineEvent;
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("type", LuaValue::stringValue(eventTypeName)));
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("trackIndex", LuaValue::intValue(entry->trackIndex)));
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("trackIndex", LuaValue::intValue(entry->getTrackIndex())));
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("animation", LuaValue::stringValue(animationName)));
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("loopCount", LuaValue::intValue(std::floor(entry->trackTime / entry->animationEnd))));
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("loopCount", LuaValue::intValue(std::floor(entry->getTrackTime() / entry->getAnimationEnd()))));
if (nullptr != event)
{
LuaValueDict eventData;
eventData.insert(eventData.end(), LuaValueDict::value_type("name", LuaValue::stringValue(event->data->name)));
eventData.insert(eventData.end(), LuaValueDict::value_type("intValue", LuaValue::intValue(event->data->intValue)));
eventData.insert(eventData.end(), LuaValueDict::value_type("floatValue", LuaValue::floatValue(event->data->floatValue)));
eventData.insert(eventData.end(), LuaValueDict::value_type("stringValue", LuaValue::stringValue(event->data->stringValue)));
eventData.insert(eventData.end(), LuaValueDict::value_type("name", LuaValue::stringValue(event->getData().getName().buffer())));
eventData.insert(eventData.end(), LuaValueDict::value_type("intValue", LuaValue::intValue(event->getData().getIntValue())));
eventData.insert(eventData.end(), LuaValueDict::value_type("floatValue", LuaValue::floatValue(event->getData().getFloatValue())));
eventData.insert(eventData.end(), LuaValueDict::value_type("stringValue", LuaValue::stringValue(event->getData().getStringValue().buffer())));
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("eventData", LuaValue::dictValue(eventData)));
}
@ -191,52 +191,52 @@ int tolua_Cocos2d_CCSkeletonAnimation_registerSpineEventHandler00(lua_State* tol
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
if (NULL != self ) {
int handler = ( toluafix_ref_function(tolua_S,2,0));
spEventType eventType = static_cast<spEventType>((int)tolua_tonumber(tolua_S, 3, 0));
spine::EventType eventType = static_cast<spine::EventType>((int)tolua_tonumber(tolua_S, 3, 0));
switch (eventType) {
case spEventType::SP_ANIMATION_START:
case spine::EventType::EventType_Start:
{
self->setStartListener([=](spTrackEntry* entry){
self->setStartListener([=](spine::TrackEntry* entry){
executeSpineEvent(self, handler, eventType, entry);
});
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_START);
}
break;
case spEventType::SP_ANIMATION_INTERRUPT:
case spine::EventType::EventType_Interrupt:
{
self->setInterruptListener([=](spTrackEntry* entry){
self->setInterruptListener([=](spine::TrackEntry* entry){
executeSpineEvent(self, handler, eventType, entry);
});
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_INTERRUPT);
}
break;
case spEventType::SP_ANIMATION_END:
case spine::EventType::EventType_End:
{
self->setEndListener([=](spTrackEntry* entry){
self->setEndListener([=](spine::TrackEntry* entry){
executeSpineEvent(self, handler, eventType, entry);
});
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_END);
}
break;
case spEventType::SP_ANIMATION_DISPOSE:
case spine::EventType::EventType_Dispose:
{
self->setDisposeListener([=](spTrackEntry* entry){
self->setDisposeListener([=](spine::TrackEntry* entry){
executeSpineEvent(self, handler, eventType, entry);
});
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_DISPOSE);
}
break;
case spEventType::SP_ANIMATION_COMPLETE:
case spine::EventType::EventType_Complete:
{
self->setCompleteListener([=](spTrackEntry* entry){
self->setCompleteListener([=](spine::TrackEntry* entry){
executeSpineEvent(self, handler, eventType, entry);
});
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_COMPLETE);
}
break;
case spEventType::SP_ANIMATION_EVENT:
case spine::EventType::EventType_Event:
{
self->setEventListener([=](spTrackEntry* entry, spEvent* event){
self->setEventListener([=](spine::TrackEntry* entry, spine::Event* event){
executeSpineEvent(self, handler, eventType, entry, event);
});
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_EVENT);
@ -270,28 +270,28 @@ int tolua_Cocos2d_CCSkeletonAnimation_unregisterSpineEventHandler00(lua_State* t
{
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
if (NULL != self ) {
spEventType eventType = static_cast<spEventType>((int)tolua_tonumber(tolua_S, 2, 0));
spine::EventType eventType = static_cast<spine::EventType>((int)tolua_tonumber(tolua_S, 2, 0));
ScriptHandlerMgr::HandlerType handlerType = ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_START;
switch (eventType) {
case spEventType::SP_ANIMATION_START:
case spine::EventType::EventType_Start:
handlerType = ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_START;
self->setStartListener(nullptr);
break;
case spEventType::SP_ANIMATION_INTERRUPT:
case spine::EventType::EventType_Interrupt:
handlerType = ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_INTERRUPT;
break;
case spEventType::SP_ANIMATION_END:
case spine::EventType::EventType_End:
handlerType = ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_END;
self->setEndListener(nullptr);
break;
case spEventType::SP_ANIMATION_DISPOSE:
case spine::EventType::EventType_Dispose:
handlerType = ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_DISPOSE;
break;
case spEventType::SP_ANIMATION_COMPLETE:
case spine::EventType::EventType_Complete:
handlerType = ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_COMPLETE;
self->setCompleteListener(nullptr);
break;
case spEventType::SP_ANIMATION_EVENT:
case spine::EventType::EventType_Event:
handlerType = ScriptHandlerMgr::HandlerType::EVENT_SPINE_ANIMATION_EVENT;
self->setEventListener(nullptr);
break;

View File

@ -48,6 +48,7 @@ namespace spine {
bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect);
Color4B ColorToColor4B(const Color& color);
bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex);
bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex);
}
// C Variable length array
@ -301,18 +302,7 @@ namespace spine {
for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) {
Slot* slot = _skeleton->getDrawOrder()[i];;
if (slotIsOutRange(*slot, _startSlotIndex, _endSlotIndex)) {
_clipper->clipEnd(*slot);
continue;
}
if (!slot->getAttachment()) {
_clipper->clipEnd(*slot);
continue;
}
// Early exit if slot is invisible
if (slot->getColor().a == 0 || !slot->getBone().isActive()) {
if (nothingToDraw(*slot, _startSlotIndex, _endSlotIndex)) {
_clipper->clipEnd(*slot);
continue;
}
@ -324,12 +314,6 @@ namespace spine {
RegionAttachment* attachment = static_cast<RegionAttachment*>(slot->getAttachment());
attachmentVertices = static_cast<AttachmentVertices*>(attachment->getRendererObject());
// Early exit if attachment is invisible
if (attachment->getColor().a == 0) {
_clipper->clipEnd(*slot);
continue;
}
float* dstTriangleVertices = nullptr;
int dstStride = 0; // in floats
if (hasSingleTint) {
@ -556,7 +540,7 @@ namespace spine {
}
}
} else {
#if COCOS2D_VERSION < 0x00040000
TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);
#else
@ -641,6 +625,7 @@ namespace spine {
#endif
DrawNode* drawNode = DrawNode::create();
drawNode->setGlobalZOrder(getGlobalZOrder());
// Draw bounding rectangle
if (_debugBoundingRect) {
@ -874,11 +859,17 @@ namespace spine {
}
void SkeletonRenderer::onEnter () {
#if CC_ENABLE_SCRIPT_BINDING && COCOS2D_VERSION < 0x00040000
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return;
#endif
Node::onEnter();
scheduleUpdate();
}
void SkeletonRenderer::onExit () {
#if CC_ENABLE_SCRIPT_BINDING && COCOS2D_VERSION < 0x00040000
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit)) return;
#endif
Node::onExit();
unscheduleUpdate();
}
@ -928,21 +919,32 @@ namespace spine {
return startSlotIndex > index || endSlotIndex < index;
}
bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex) {
Attachment *attachment = slot.getAttachment();
if (!attachment ||
slotIsOutRange(slot, startSlotIndex, endSlotIndex) ||
!slot.getBone().isActive() ||
slot.getColor().a == 0)
return true;
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
if (static_cast<RegionAttachment*>(attachment)->getColor().a == 0)
return true;
}
else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
if (static_cast<MeshAttachment*>(attachment)->getColor().a == 0)
return true;
}
return false;
}
int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex) {
int coordCount = 0;
for (size_t i = 0; i < skeleton.getSlots().size(); ++i) {
Slot& slot = *skeleton.getSlots()[i];
if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) {
continue;
}
Attachment* const attachment = slot.getAttachment();
if (!attachment) {
continue;
}
if (slotIsOutRange(slot, startSlotIndex, endSlotIndex)) {
continue;
}
// Early exit if slot is invisible
if (slot.getColor().a == 0) {
continue;
}
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
coordCount += 8;
}
@ -962,16 +964,10 @@ namespace spine {
#endif
for (size_t i = 0; i < skeleton.getSlots().size(); ++i) {
/*const*/ Slot& slot = *skeleton.getDrawOrder()[i]; // match the draw order of SkeletonRenderer::Draw
if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) {
continue;
}
Attachment* const attachment = slot.getAttachment();
if (!attachment) {
continue;
}
if (slotIsOutRange(slot, startSlotIndex, endSlotIndex)) {
continue;
}
if (slot.getColor().a == 0) {
continue;
}
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
RegionAttachment* const regionAttachment = static_cast<RegionAttachment*>(attachment);
assert(dstPtr + 8 <= dstEnd);
@ -1003,7 +999,7 @@ namespace spine {
BlendFunc makeBlendFunc(BlendMode blendMode, bool premultipliedAlpha) {
BlendFunc blendFunc;
#if COCOS2D_VERSION < 0x00040000
switch (blendMode) {
case BlendMode_Additive:
@ -1049,15 +1045,15 @@ namespace spine {
bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect) {
if (Camera::getVisitingCamera() == nullptr)
return false;
auto director = Director::getInstance();
auto scene = director->getRunningScene();
if (!scene || (scene && Camera::getDefaultCamera() != Camera::getVisitingCamera()))
return false;
Rect visibleRect(director->getVisibleOrigin(), director->getVisibleSize());
// transform center point to screen space
float hSizeX = rect.size.width/2;
float hSizeY = rect.size.height/2;
@ -1068,7 +1064,7 @@ namespace spine {
// convert content size to world coordinates
float wshw = std::max(fabsf(hSizeX * transform.m[0] + hSizeY * transform.m[4]), fabsf(hSizeX * transform.m[0] - hSizeY * transform.m[4]));
float wshh = std::max(fabsf(hSizeX * transform.m[1] + hSizeY * transform.m[5]), fabsf(hSizeX * transform.m[1] - hSizeY * transform.m[5]));
// enlarge visible rect half size in screen coord
visibleRect.origin.x -= wshw;
visibleRect.origin.y -= wshh;

View File

@ -167,7 +167,7 @@ Cocos2dExtension::Cocos2dExtension() : DefaultSpineExtension() { }
Cocos2dExtension::~Cocos2dExtension() { }
char *Cocos2dExtension::_readFile(const spine::String &path, int *length) {
Data data = FileUtils::getInstance()->getDataFromFile(FileUtils::getInstance()->fullPathForFilename(path.buffer()));
Data data = FileUtils::getInstance()->getDataFromFile(path.buffer());
if (data.isNull()) return nullptr;
// avoid buffer overflow (int is shorter than ssize_t in certain platforms)