mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
Port more features
This commit is contained in:
parent
9745e3779c
commit
99c08fced6
@ -48,7 +48,7 @@ bool BatchingExample::init () {
|
|||||||
|
|
||||||
// Load the texture atlas. Note that the texture loader has to live
|
// Load the texture atlas. Note that the texture loader has to live
|
||||||
// as long as the Atlas, as the Atlas destructor will call TextureLoader::unload.
|
// as long as the Atlas, as the Atlas destructor will call TextureLoader::unload.
|
||||||
_atlas = new (__FILE__, __LINE__) Atlas("spineboy.atlas", &textureLoader);
|
_atlas = new (__FILE__, __LINE__) Atlas("spineboy.atlas", &textureLoader, true);
|
||||||
CCASSERT(_atlas, "Error reading atlas file.");
|
CCASSERT(_atlas, "Error reading atlas file.");
|
||||||
|
|
||||||
// This attachment loader configures attachments with data needed for cocos2d-x rendering.
|
// This attachment loader configures attachments with data needed for cocos2d-x rendering.
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||||
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset>
|
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset>
|
||||||
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v120_xp</PlatformToolset>
|
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v120_xp</PlatformToolset>
|
||||||
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
|
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset>
|
||||||
@ -109,7 +109,7 @@ xcopy "$(ProjectDir)..\Resources" "$(OutDir)" /D /E /I /F /Y
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<AdditionalIncludeDirectories>$(EngineRoot)external;$(EngineRoot)cocos\audio\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;..\Classes;..;%(AdditionalIncludeDirectories);$(_COCOS_HEADER_WIN32_BEGIN);$(_COCOS_HEADER_WIN32_END)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(EngineRoot)external;$(EngineRoot)cocos\audio\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;..\Classes;..;%(AdditionalIncludeDirectories);$(_COCOS_HEADER_WIN32_BEGIN);$(_COCOS_HEADER_WIN32_END);$(SolutionDir)..\..\..\spine-cpp\spine-cpp\include;$(SolutionDir)..\..\src;$(IncludePath)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
@ -121,7 +121,7 @@ xcopy "$(ProjectDir)..\Resources" "$(OutDir)" /D /E /I /F /Y
|
|||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>libcurl_imp.lib;websockets.lib;%(AdditionalDependencies);$(_COCOS_LIB_WIN32_BEGIN);$(_COCOS_LIB_WIN32_END)</AdditionalDependencies>
|
<AdditionalDependencies>%(AdditionalDependencies);$(_COCOS_LIB_WIN32_BEGIN);$(_COCOS_LIB_WIN32_END)</AdditionalDependencies>
|
||||||
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
|
<OutputFile>$(OutDir)$(ProjectName).exe</OutputFile>
|
||||||
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories);$(_COCOS_LIB_PATH_WIN32_BEGIN);$(_COCOS_LIB_PATH_WIN32_END)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories);$(_COCOS_LIB_PATH_WIN32_BEGIN);$(_COCOS_LIB_PATH_WIN32_END)</AdditionalLibraryDirectories>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
|||||||
@ -108,6 +108,7 @@ void SkeletonAnimation::initialize () {
|
|||||||
super::initialize();
|
super::initialize();
|
||||||
|
|
||||||
_ownsAnimationStateData = true;
|
_ownsAnimationStateData = true;
|
||||||
|
_updateOnlyIfVisible = false;
|
||||||
_state = new (__FILE__, __LINE__) AnimationState(new (__FILE__, __LINE__) AnimationStateData(_skeleton->getData()));
|
_state = new (__FILE__, __LINE__) AnimationState(new (__FILE__, __LINE__) AnimationStateData(_skeleton->getData()));
|
||||||
_state->setRendererObject(this);
|
_state->setRendererObject(this);
|
||||||
_state->setListener(animationCallback);
|
_state->setListener(animationCallback);
|
||||||
@ -125,6 +126,8 @@ SkeletonAnimation::~SkeletonAnimation () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonAnimation::update (float deltaTime) {
|
void SkeletonAnimation::update (float deltaTime) {
|
||||||
|
if (_updateOnlyIfVisible && (isAutoCulled() || !isVisible())) return;
|
||||||
|
|
||||||
super::update(deltaTime);
|
super::update(deltaTime);
|
||||||
|
|
||||||
deltaTime *= _timeScale;
|
deltaTime *= _timeScale;
|
||||||
@ -303,4 +306,8 @@ AnimationState* SkeletonAnimation::getState() const {
|
|||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkeletonAnimation::setUpdateOnlyIfVisible(bool status) {
|
||||||
|
_updateOnlyIfVisible = status;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,6 +99,7 @@ public:
|
|||||||
virtual void onTrackEntryEvent (TrackEntry* entry, EventType type, Event* event);
|
virtual void onTrackEntryEvent (TrackEntry* entry, EventType type, Event* event);
|
||||||
|
|
||||||
AnimationState* getState() const;
|
AnimationState* getState() const;
|
||||||
|
void setUpdateOnlyIfVisible(bool status);
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
SkeletonAnimation ();
|
SkeletonAnimation ();
|
||||||
@ -109,6 +110,7 @@ protected:
|
|||||||
AnimationState* _state;
|
AnimationState* _state;
|
||||||
|
|
||||||
bool _ownsAnimationStateData;
|
bool _ownsAnimationStateData;
|
||||||
|
bool _updateOnlyIfVisible;
|
||||||
bool _firstDraw;
|
bool _firstDraw;
|
||||||
|
|
||||||
StartListener _startListener;
|
StartListener _startListener;
|
||||||
|
|||||||
@ -198,7 +198,7 @@ void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, At
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
||||||
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader);
|
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
|
||||||
CCASSERT(_atlas, "Error reading atlas file.");
|
CCASSERT(_atlas, "Error reading atlas file.");
|
||||||
|
|
||||||
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
||||||
@ -230,7 +230,7 @@ void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
||||||
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader);
|
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
|
||||||
CCASSERT(_atlas, "Error reading atlas file.");
|
CCASSERT(_atlas, "Error reading atlas file.");
|
||||||
|
|
||||||
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
||||||
@ -253,6 +253,7 @@ void SkeletonRenderer::update (float deltaTime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
|
void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
|
||||||
|
_isAutoCulled = false;
|
||||||
// Early exit if the skeleton is invisible
|
// Early exit if the skeleton is invisible
|
||||||
if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0){
|
if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0){
|
||||||
return;
|
return;
|
||||||
@ -272,9 +273,12 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
const Camera* camera = Camera::getVisitingCamera();
|
const Camera* camera = Camera::getVisitingCamera();
|
||||||
const cocos2d::Rect brect = computeBoundingRect(worldCoords, coordCount / 2);
|
const cocos2d::Rect brect = computeBoundingRect(worldCoords, coordCount / 2);
|
||||||
_boundingRect = brect;
|
_boundingRect = brect;
|
||||||
if (camera && cullRectangle(transform, brect, *camera))
|
|
||||||
|
const bool autoCullingEnable = cocos2d::Director::getInstance()->isAutoCullingEnable();
|
||||||
|
if (autoCullingEnable && camera && cullRectangle(transform, brect, *camera))
|
||||||
{
|
{
|
||||||
VLA_FREE(worldCoords);
|
VLA_FREE(worldCoords);
|
||||||
|
_isAutoCulled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -617,6 +621,10 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SkeletonRenderer::isAutoCulled () const {
|
||||||
|
return _isAutoCulled;
|
||||||
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) {
|
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) {
|
||||||
|
|
||||||
#if !defined(USE_MATRIX_STACK_PROJECTION_ONLY)
|
#if !defined(USE_MATRIX_STACK_PROJECTION_ONLY)
|
||||||
|
|||||||
@ -48,7 +48,7 @@ namespace spine {
|
|||||||
|
|
||||||
void update (float deltaTime) override;
|
void update (float deltaTime) override;
|
||||||
void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
|
void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
|
||||||
//virtual bool isAutoCulled () const override;
|
bool isAutoCulled () const override;
|
||||||
cocos2d::Rect getBoundingBox () const override;
|
cocos2d::Rect getBoundingBox () const override;
|
||||||
void onEnter () override;
|
void onEnter () override;
|
||||||
void onExit () override;
|
void onExit () override;
|
||||||
@ -158,6 +158,7 @@ namespace spine {
|
|||||||
|
|
||||||
int _startSlotIndex;
|
int _startSlotIndex;
|
||||||
int _endSlotIndex;
|
int _endSlotIndex;
|
||||||
|
bool _isAutoCulled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,6 +67,7 @@ enum TextureWrap {
|
|||||||
class SP_API AtlasPage : public SpineObject, public HasRendererObject {
|
class SP_API AtlasPage : public SpineObject, public HasRendererObject {
|
||||||
public:
|
public:
|
||||||
String name;
|
String name;
|
||||||
|
String texturePath;
|
||||||
Format format;
|
Format format;
|
||||||
TextureFilter minFilter;
|
TextureFilter minFilter;
|
||||||
TextureFilter magFilter;
|
TextureFilter magFilter;
|
||||||
@ -100,9 +101,9 @@ class TextureLoader;
|
|||||||
|
|
||||||
class SP_API Atlas : public SpineObject {
|
class SP_API Atlas : public SpineObject {
|
||||||
public:
|
public:
|
||||||
Atlas(const String &path, TextureLoader *textureLoader);
|
Atlas(const String &path, TextureLoader *textureLoader, bool createTexture);
|
||||||
|
|
||||||
Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader);
|
Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture);
|
||||||
|
|
||||||
~Atlas();
|
~Atlas();
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ private:
|
|||||||
Vector<AtlasRegion *> _regions;
|
Vector<AtlasRegion *> _regions;
|
||||||
TextureLoader *_textureLoader;
|
TextureLoader *_textureLoader;
|
||||||
|
|
||||||
void load(const char *begin, int length, const char *dir);
|
void load(const char *begin, int length, const char *dir, bool createTexture);
|
||||||
|
|
||||||
class Str {
|
class Str {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
using namespace spine;
|
using namespace spine;
|
||||||
|
|
||||||
Atlas::Atlas(const String &path, TextureLoader *textureLoader) : _textureLoader(textureLoader) {
|
Atlas::Atlas(const String &path, TextureLoader *textureLoader, bool createTexture) : _textureLoader(textureLoader) {
|
||||||
int dirLength;
|
int dirLength;
|
||||||
char *dir;
|
char *dir;
|
||||||
int length;
|
int length;
|
||||||
@ -57,16 +57,16 @@ Atlas::Atlas(const String &path, TextureLoader *textureLoader) : _textureLoader(
|
|||||||
|
|
||||||
data = SpineExtension::readFile(path, &length);
|
data = SpineExtension::readFile(path, &length);
|
||||||
if (data) {
|
if (data) {
|
||||||
load(data, length, dir);
|
load(data, length, dir, createTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineExtension::free(data, __FILE__, __LINE__);
|
SpineExtension::free(data, __FILE__, __LINE__);
|
||||||
SpineExtension::free(dir, __FILE__, __LINE__);
|
SpineExtension::free(dir, __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader) : _textureLoader(
|
Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture) : _textureLoader(
|
||||||
textureLoader) {
|
textureLoader) {
|
||||||
load(data, length, dir);
|
load(data, length, dir, createTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::~Atlas() {
|
Atlas::~Atlas() {
|
||||||
@ -102,7 +102,7 @@ Vector<AtlasPage*> &Atlas::getPages() {
|
|||||||
return _pages;
|
return _pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::load(const char *begin, int length, const char *dir) {
|
void Atlas::load(const char *begin, int length, const char *dir, bool createTexture) {
|
||||||
static const char *formatNames[] = {"", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888",
|
static const char *formatNames[] = {"", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888",
|
||||||
"RGBA8888"};
|
"RGBA8888"};
|
||||||
static const char *textureFilterNames[] = {"", "Nearest", "Linear", "MipMap", "MipMapNearestNearest",
|
static const char *textureFilterNames[] = {"", "Nearest", "Linear", "MipMap", "MipMapNearestNearest",
|
||||||
@ -163,9 +163,15 @@ void Atlas::load(const char *begin, int length, const char *dir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (createTexture)
|
||||||
|
{
|
||||||
if (_textureLoader) _textureLoader->load(*page, String(path));
|
if (_textureLoader) _textureLoader->load(*page, String(path));
|
||||||
|
|
||||||
SpineExtension::free(path, __FILE__, __LINE__);
|
SpineExtension::free(path, __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
page->texturePath = String(path, true);
|
||||||
|
}
|
||||||
|
|
||||||
_pages.add(page);
|
_pages.add(page);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user