mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
Merge branch 'socialpoint' into 3.8-beta
This commit is contained in:
commit
1dadeb48a4
@ -2,14 +2,14 @@ cmake_minimum_required(VERSION 2.8)
|
||||
set(EXAMPLE_DIR "${CMAKE_CURRENT_LIST_DIR}/example")
|
||||
if (NOT EXISTS ${EXAMPLE_DIR}/cocos2d)
|
||||
message("Downloading cocos2dx, this may take some time!")
|
||||
file(DOWNLOAD "https://digitalocean.cocos2d-x.org/Cocos2D-X/cocos2d-x-3.17.1.zip" "${EXAMPLE_DIR}/cocos2dx.zip")
|
||||
file(DOWNLOAD "https://digitalocean.cocos2d-x.org/Cocos2D-X/cocos2d-x-3.17.2.zip" "${EXAMPLE_DIR}/cocos2dx.zip")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E tar x ${EXAMPLE_DIR}/cocos2dx.zip
|
||||
WORKING_DIRECTORY ${EXAMPLE_DIR}
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E rename
|
||||
"${EXAMPLE_DIR}/cocos2d-x-3.17.1" "${EXAMPLE_DIR}/cocos2d"
|
||||
"${EXAMPLE_DIR}/cocos2d-x-3.17.2" "${EXAMPLE_DIR}/cocos2d"
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory "${EXAMPLE_DIR}/cocos2d/cocos/editor-support/spine"
|
||||
|
||||
@ -48,7 +48,7 @@ bool BatchingExample::init () {
|
||||
|
||||
// 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.
|
||||
_atlas = new (__FILE__, __LINE__) Atlas("spineboy.atlas", &textureLoader);
|
||||
_atlas = new (__FILE__, __LINE__) Atlas("spineboy.atlas", &textureLoader, true);
|
||||
CCASSERT(_atlas, "Error reading atlas file.");
|
||||
|
||||
// This attachment loader configures attachments with data needed for cocos2d-x rendering.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29009.5
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spine-cocos2d-x", "spine-cocos2d-x.vcxproj", "{76A39BB2-9B84-4C65-98A5-654D86B86F2A}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
@ -10,8 +10,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spine-cocos2d-x", "spine-co
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\cocos2d\cocos\2d\libcocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d", "..\cocos2d\external\Box2D\proj.win32\libbox2d.vcxproj", "{929480E7-23C0-4DF6-8456-096D71547116}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "librecast", "..\cocos2d\external\recast\proj.win32\librecast.vcxproj", "{41E34993-647E-4282-8384-4AB1AE31A452}"
|
||||
EndProject
|
||||
Global
|
||||
@ -28,10 +26,6 @@ Global
|
||||
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.Build.0 = Release|Win32
|
||||
{929480E7-23C0-4DF6-8456-096D71547116}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{929480E7-23C0-4DF6-8456-096D71547116}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{929480E7-23C0-4DF6-8456-096D71547116}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{929480E7-23C0-4DF6-8456-096D71547116}.Release|Win32.Build.0 = Release|Win32
|
||||
{41E34993-647E-4282-8384-4AB1AE31A452}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{41E34993-647E-4282-8384-4AB1AE31A452}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{41E34993-647E-4282-8384-4AB1AE31A452}.Release|Win32.ActiveCfg = Release|Win32
|
||||
@ -40,4 +34,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E20D34B0-B32B-44B5-B42D-0028D1ED286F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@ -19,11 +19,12 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<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)' == '14.0'">v140</PlatformToolset>
|
||||
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v140_xp</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
@ -32,6 +33,7 @@
|
||||
<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' and exists('$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A')">v140_xp</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
@ -62,13 +64,6 @@
|
||||
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LibraryPath>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LibraryPath>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
@ -114,7 +109,7 @@ xcopy "$(ProjectDir)..\Resources" "$(OutDir)" /D /E /I /F /Y
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<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>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
@ -126,7 +121,7 @@ xcopy "$(ProjectDir)..\Resources" "$(OutDir)" /D /E /I /F /Y
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<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>
|
||||
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories);$(_COCOS_LIB_PATH_WIN32_BEGIN);$(_COCOS_LIB_PATH_WIN32_END)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@ -325,9 +320,6 @@ xcopy "$(ProjectDir)..\Resources" "$(OutDir)" /D /E /I /F /Y
|
||||
<Project>{98a51ba8-fc3a-415b-ac8f-8c7bd464e93e}</Project>
|
||||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\cocos2d\external\Box2D\proj.win32\libbox2d.vcxproj">
|
||||
<Project>{929480e7-23c0-4df6-8456-096d71547116}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="game.rc" />
|
||||
|
||||
@ -111,6 +111,7 @@ void SkeletonAnimation::initialize () {
|
||||
super::initialize();
|
||||
|
||||
_ownsAnimationStateData = true;
|
||||
_updateOnlyIfVisible = false;
|
||||
_state = new (__FILE__, __LINE__) AnimationState(new (__FILE__, __LINE__) AnimationStateData(_skeleton->getData()));
|
||||
_state->setRendererObject(this);
|
||||
_state->setListener(animationCallback);
|
||||
@ -128,6 +129,8 @@ SkeletonAnimation::~SkeletonAnimation () {
|
||||
}
|
||||
|
||||
void SkeletonAnimation::update (float deltaTime) {
|
||||
if (_updateOnlyIfVisible && !isVisible()) return;
|
||||
|
||||
super::update(deltaTime);
|
||||
|
||||
deltaTime *= _timeScale;
|
||||
@ -306,4 +309,8 @@ AnimationState* SkeletonAnimation::getState() const {
|
||||
return _state;
|
||||
}
|
||||
|
||||
void SkeletonAnimation::setUpdateOnlyIfVisible(bool status) {
|
||||
_updateOnlyIfVisible = status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -99,6 +99,7 @@ public:
|
||||
virtual void onTrackEntryEvent (TrackEntry* entry, EventType type, Event* event);
|
||||
|
||||
AnimationState* getState() const;
|
||||
void setUpdateOnlyIfVisible(bool status);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
SkeletonAnimation ();
|
||||
@ -109,6 +110,7 @@ protected:
|
||||
AnimationState* _state;
|
||||
|
||||
bool _ownsAnimationStateData;
|
||||
bool _updateOnlyIfVisible;
|
||||
bool _firstDraw;
|
||||
|
||||
StartListener _startListener;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -34,9 +34,9 @@
|
||||
#include "cocos2d.h"
|
||||
|
||||
namespace spine {
|
||||
|
||||
|
||||
class AttachmentVertices;
|
||||
|
||||
|
||||
/* Draws a skeleton. */
|
||||
class SkeletonRenderer: public cocos2d::Node, public cocos2d::BlendProtocol {
|
||||
public:
|
||||
@ -45,48 +45,50 @@ namespace spine {
|
||||
static SkeletonRenderer* createWithData (SkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||
static SkeletonRenderer* createWithFile (const std::string& skeletonDataFile, Atlas* atlas, float scale = 1);
|
||||
static SkeletonRenderer* createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
|
||||
|
||||
virtual void update (float deltaTime) override;
|
||||
virtual void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
|
||||
virtual void drawDebug (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags);
|
||||
virtual cocos2d::Rect getBoundingBox () const override;
|
||||
virtual void onEnter () override;
|
||||
virtual void onExit () override;
|
||||
|
||||
Skeleton* getSkeleton();
|
||||
|
||||
|
||||
void update (float deltaTime) override;
|
||||
void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
|
||||
cocos2d::Rect getBoundingBox () const override;
|
||||
void onEnter () override;
|
||||
void onExit () override;
|
||||
|
||||
Skeleton* getSkeleton() const;
|
||||
|
||||
void setTimeScale(float scale);
|
||||
float getTimeScale() const;
|
||||
|
||||
|
||||
/* */
|
||||
void setDebugSlotsEnabled(bool enabled);
|
||||
bool getDebugSlotsEnabled() const;
|
||||
|
||||
|
||||
void setDebugBonesEnabled(bool enabled);
|
||||
bool getDebugBonesEnabled() const;
|
||||
|
||||
|
||||
void setDebugMeshesEnabled(bool enabled);
|
||||
bool getDebugMeshesEnabled() const;
|
||||
|
||||
|
||||
void setDebugBoundingRectEnabled(bool enabled);
|
||||
bool getDebugBoundingRectEnabled() const;
|
||||
|
||||
// --- Convenience methods for common Skeleton_* functions.
|
||||
void updateWorldTransform ();
|
||||
|
||||
|
||||
void setToSetupPose ();
|
||||
void setBonesToSetupPose ();
|
||||
void setSlotsToSetupPose ();
|
||||
|
||||
|
||||
/* Returns 0 if the bone was not found. */
|
||||
Bone* findBone (const std::string& boneName) const;
|
||||
/* Returns 0 if the slot was not found. */
|
||||
Slot* findSlot (const std::string& slotName) const;
|
||||
|
||||
|
||||
/* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are
|
||||
* attached if the corresponding attachment from the old skin was attached.
|
||||
* @param skin May be empty string ("") for no skin.*/
|
||||
void setSkin (const std::string& skinName);
|
||||
/** @param skin May be 0 for no skin.*/
|
||||
void setSkin (const char* skinName);
|
||||
|
||||
|
||||
/* Returns 0 if the slot or attachment was not found. */
|
||||
Attachment* getAttachment (const std::string& slotName, const std::string& attachmentName) const;
|
||||
/* Returns false if the slot or attachment was not found.
|
||||
@ -94,52 +96,50 @@ namespace spine {
|
||||
bool setAttachment (const std::string& slotName, const std::string& attachmentName);
|
||||
/* @param attachmentName May be 0 for no attachment. */
|
||||
bool setAttachment (const std::string& slotName, const char* attachmentName);
|
||||
|
||||
|
||||
/* Enables/disables two color tinting for this instance. May break batching */
|
||||
void setTwoColorTint(bool enabled);
|
||||
/* Whether two color tinting is enabled */
|
||||
bool isTwoColorTint();
|
||||
|
||||
|
||||
/* Sets the vertex effect to be used, set to 0 to disable vertex effects */
|
||||
void setVertexEffect(VertexEffect* effect);
|
||||
|
||||
|
||||
/* Sets the range of slots that should be rendered. Use -1, -1 to clear the range */
|
||||
void setSlotsRange(int startSlotIndex, int endSlotIndex);
|
||||
|
||||
|
||||
// --- BlendProtocol
|
||||
virtual void setBlendFunc (const cocos2d::BlendFunc& blendFunc)override;
|
||||
virtual const cocos2d::BlendFunc& getBlendFunc () const override;
|
||||
virtual void setOpacityModifyRGB (bool value) override;
|
||||
virtual bool isOpacityModifyRGB () const override;
|
||||
|
||||
// Frees global memory used for temporay vertex transformations.
|
||||
static void destroyScratchBuffers();
|
||||
|
||||
void setBlendFunc (const cocos2d::BlendFunc& blendFunc)override;
|
||||
const cocos2d::BlendFunc& getBlendFunc () const override;
|
||||
void setOpacityModifyRGB (bool value) override;
|
||||
bool isOpacityModifyRGB () const override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
SkeletonRenderer ();
|
||||
SkeletonRenderer(Skeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false);
|
||||
SkeletonRenderer (SkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||
SkeletonRenderer (const std::string& skeletonDataFile, Atlas* atlas, float scale = 1);
|
||||
SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
|
||||
|
||||
|
||||
virtual ~SkeletonRenderer ();
|
||||
|
||||
|
||||
void initWithSkeleton(Skeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false);
|
||||
void initWithData (SkeletonData* skeletonData, bool ownsSkeletonData = false);
|
||||
void initWithJsonFile (const std::string& skeletonDataFile, Atlas* atlas, float scale = 1);
|
||||
void initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
|
||||
void initWithBinaryFile (const std::string& skeletonDataFile, Atlas* atlas, float scale = 1);
|
||||
void initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
|
||||
|
||||
|
||||
virtual void initialize ();
|
||||
|
||||
|
||||
protected:
|
||||
void setSkeletonData (SkeletonData* skeletonData, bool ownsSkeletonData);
|
||||
void setupGLProgramState(bool twoColorTintEnabled);
|
||||
|
||||
virtual void drawDebug (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags);
|
||||
|
||||
bool _ownsSkeletonData;
|
||||
bool _ownsSkeleton;
|
||||
bool _ownsAtlas;
|
||||
bool _ownsAtlas = false;
|
||||
Atlas* _atlas;
|
||||
AttachmentLoader* _attachmentLoader;
|
||||
cocos2d::CustomCommand _debugCommand;
|
||||
@ -150,13 +150,15 @@ namespace spine {
|
||||
bool _debugSlots;
|
||||
bool _debugBones;
|
||||
bool _debugMeshes;
|
||||
bool _debugBoundingRect;
|
||||
SkeletonClipping* _clipper;
|
||||
VertexEffect* _effect;
|
||||
|
||||
cocos2d::Rect _boundingRect;
|
||||
|
||||
int _startSlotIndex;
|
||||
int _endSlotIndex;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* SPINE_SKELETONRENDERER_H_ */
|
||||
|
||||
@ -66,8 +66,6 @@ static void setAttachmentVertices(MeshAttachment* attachment) {
|
||||
Cocos2dAtlasAttachmentLoader::Cocos2dAtlasAttachmentLoader(Atlas* atlas): AtlasAttachmentLoader(atlas) {
|
||||
}
|
||||
|
||||
Cocos2dAtlasAttachmentLoader::~Cocos2dAtlasAttachmentLoader() { }
|
||||
|
||||
void Cocos2dAtlasAttachmentLoader::configureAttachment(Attachment* attachment) {
|
||||
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
|
||||
setAttachmentVertices((RegionAttachment*)attachment);
|
||||
@ -102,34 +100,31 @@ GLuint filter (TextureFilter filter) {
|
||||
return GL_LINEAR;
|
||||
}
|
||||
|
||||
Cocos2dTextureLoader::Cocos2dTextureLoader() : TextureLoader() { }
|
||||
Cocos2dTextureLoader::~Cocos2dTextureLoader() { }
|
||||
|
||||
void Cocos2dTextureLoader::load(AtlasPage& page, const spine::String& path) {
|
||||
Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(path.buffer());
|
||||
CCASSERT(texture != nullptr, "Invalid image");
|
||||
texture->retain();
|
||||
|
||||
Texture2D::TexParams textureParams = {filter(page.minFilter), filter(page.magFilter), wrap(page.uWrap), wrap(page.vWrap)};
|
||||
texture->setTexParameters(textureParams);
|
||||
|
||||
page.setRendererObject(texture);
|
||||
page.width = texture->getPixelsWide();
|
||||
page.height = texture->getPixelsHigh();
|
||||
if (texture)
|
||||
{
|
||||
texture->retain();
|
||||
Texture2D::TexParams textureParams = { filter(page.minFilter), filter(page.magFilter), wrap(page.uWrap), wrap(page.vWrap) };
|
||||
texture->setTexParameters(textureParams);
|
||||
page.setRendererObject(texture);
|
||||
page.width = texture->getPixelsWide();
|
||||
page.height = texture->getPixelsHigh();
|
||||
}
|
||||
}
|
||||
|
||||
void Cocos2dTextureLoader::unload(void* texture) {
|
||||
((Texture2D*)texture)->release();
|
||||
if (texture)
|
||||
{
|
||||
((Texture2D*)texture)->release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Cocos2dExtension::Cocos2dExtension() : DefaultSpineExtension() { }
|
||||
|
||||
Cocos2dExtension::~Cocos2dExtension() { }
|
||||
|
||||
char *Cocos2dExtension::_readFile(const spine::String &path, int *length) {
|
||||
Data data = FileUtils::getInstance()->getDataFromFile(FileUtils::getInstance()->fullPathForFilename(path.buffer()));
|
||||
if (data.isNull()) return 0;
|
||||
if (data.isNull()) return nullptr;
|
||||
|
||||
// avoid buffer overflow (int is shorter than ssize_t in certain platforms)
|
||||
#if COCOS2D_VERSION >= 0x00031200
|
||||
|
||||
@ -41,15 +41,11 @@ namespace spine {
|
||||
class Cocos2dAtlasAttachmentLoader: public AtlasAttachmentLoader {
|
||||
public:
|
||||
Cocos2dAtlasAttachmentLoader(Atlas* atlas);
|
||||
virtual ~Cocos2dAtlasAttachmentLoader();
|
||||
virtual void configureAttachment(Attachment* attachment);
|
||||
};
|
||||
|
||||
class Cocos2dTextureLoader: public TextureLoader {
|
||||
public:
|
||||
Cocos2dTextureLoader();
|
||||
|
||||
virtual ~Cocos2dTextureLoader();
|
||||
|
||||
virtual void load(AtlasPage& page, const String& path);
|
||||
|
||||
@ -58,9 +54,6 @@ namespace spine {
|
||||
|
||||
class Cocos2dExtension: public DefaultSpineExtension {
|
||||
public:
|
||||
Cocos2dExtension();
|
||||
|
||||
virtual ~Cocos2dExtension();
|
||||
|
||||
protected:
|
||||
virtual char *_readFile(const String &path, int *length);
|
||||
|
||||
@ -67,6 +67,7 @@ enum TextureWrap {
|
||||
class SP_API AtlasPage : public SpineObject, public HasRendererObject {
|
||||
public:
|
||||
String name;
|
||||
String texturePath;
|
||||
Format format;
|
||||
TextureFilter minFilter;
|
||||
TextureFilter magFilter;
|
||||
@ -76,10 +77,8 @@ public:
|
||||
|
||||
explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888), minFilter(TextureFilter_Nearest),
|
||||
magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge),
|
||||
vWrap(TextureWrap_ClampToEdge) {
|
||||
vWrap(TextureWrap_ClampToEdge), width(0), height(0) {
|
||||
}
|
||||
|
||||
virtual ~AtlasPage() { }
|
||||
};
|
||||
|
||||
class SP_API AtlasRegion : public SpineObject {
|
||||
@ -101,9 +100,9 @@ class TextureLoader;
|
||||
|
||||
class SP_API Atlas : public SpineObject {
|
||||
public:
|
||||
Atlas(const String &path, TextureLoader *textureLoader);
|
||||
Atlas(const String &path, TextureLoader *textureLoader, bool createTexture = true);
|
||||
|
||||
Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader);
|
||||
Atlas(const char *data, int length, const char *dir, TextureLoader *textureLoader, bool createTexture = true);
|
||||
|
||||
~Atlas();
|
||||
|
||||
@ -121,7 +120,7 @@ private:
|
||||
Vector<AtlasRegion *> _regions;
|
||||
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 {
|
||||
public:
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
|
||||
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;
|
||||
char *dir;
|
||||
int length;
|
||||
@ -57,16 +57,16 @@ Atlas::Atlas(const String &path, TextureLoader *textureLoader) : _textureLoader(
|
||||
|
||||
data = SpineExtension::readFile(path, &length);
|
||||
if (data) {
|
||||
load(data, length, dir);
|
||||
load(data, length, dir, createTexture);
|
||||
}
|
||||
|
||||
SpineExtension::free(data, __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) {
|
||||
load(data, length, dir);
|
||||
load(data, length, dir, createTexture);
|
||||
}
|
||||
|
||||
Atlas::~Atlas() {
|
||||
@ -102,7 +102,7 @@ Vector<AtlasPage*> &Atlas::getPages() {
|
||||
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",
|
||||
"RGBA8888"};
|
||||
static const char *textureFilterNames[] = {"", "Nearest", "Linear", "MipMap", "MipMapNearestNearest",
|
||||
@ -163,9 +163,15 @@ void Atlas::load(const char *begin, int length, const char *dir) {
|
||||
}
|
||||
}
|
||||
|
||||
if (_textureLoader) _textureLoader->load(*page, String(path));
|
||||
|
||||
SpineExtension::free(path, __FILE__, __LINE__);
|
||||
if (createTexture)
|
||||
{
|
||||
if (_textureLoader) _textureLoader->load(*page, String(path));
|
||||
SpineExtension::free(path, __FILE__, __LINE__);
|
||||
}
|
||||
else
|
||||
{
|
||||
page->texturePath = String(path, true);
|
||||
}
|
||||
|
||||
_pages.add(page);
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user