|
@@ -1,10 +1,10 @@
|
|
/******************************************************************************
|
|
/******************************************************************************
|
|
* Spine Runtimes Software License
|
|
* Spine Runtimes Software License
|
|
* Version 2.3
|
|
* Version 2.3
|
|
- *
|
|
|
|
|
|
+ *
|
|
* Copyright (c) 2013-2015, Esoteric Software
|
|
* Copyright (c) 2013-2015, Esoteric Software
|
|
* All rights reserved.
|
|
* All rights reserved.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* You are granted a perpetual, non-exclusive, non-sublicensable and
|
|
* You are granted a perpetual, non-exclusive, non-sublicensable and
|
|
* non-transferable license to use, install, execute and perform the Spine
|
|
* non-transferable license to use, install, execute and perform the Spine
|
|
* Runtimes Software (the "Software") and derivative works solely for personal
|
|
* Runtimes Software (the "Software") and derivative works solely for personal
|
|
@@ -16,7 +16,7 @@
|
|
* or other intellectual property or proprietary rights notices on or in the
|
|
* or other intellectual property or proprietary rights notices on or in the
|
|
* Software, including any copy thereof. Redistributions in binary or source
|
|
* Software, including any copy thereof. Redistributions in binary or source
|
|
* form must include this license and terms.
|
|
* form must include this license and terms.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
@@ -38,102 +38,72 @@ USING_NS_CC;
|
|
using std::max;
|
|
using std::max;
|
|
|
|
|
|
namespace spine {
|
|
namespace spine {
|
|
-
|
|
|
|
-static SkeletonBatch* instance = nullptr;
|
|
|
|
-
|
|
|
|
-void SkeletonBatch::setBufferSize (int vertexCount) {
|
|
|
|
- if (instance) delete instance;
|
|
|
|
- instance = new SkeletonBatch(vertexCount);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SkeletonBatch* SkeletonBatch::getInstance () {
|
|
|
|
- if (!instance) instance = new SkeletonBatch(8192);
|
|
|
|
- return instance;
|
|
|
|
-}
|
|
|
|
|
|
|
|
-void SkeletonBatch::destroyInstance () {
|
|
|
|
- if (instance) {
|
|
|
|
- delete instance;
|
|
|
|
- instance = nullptr;
|
|
|
|
|
|
+ static SkeletonBatch* instance = nullptr;
|
|
|
|
+
|
|
|
|
+ SkeletonBatch* SkeletonBatch::getInstance () {
|
|
|
|
+ if (!instance) instance = new SkeletonBatch();
|
|
|
|
+ return instance;
|
|
}
|
|
}
|
|
-}
|
|
|
|
-
|
|
|
|
-SkeletonBatch::SkeletonBatch (int capacity) :
|
|
|
|
- _capacity(capacity), _position(0)
|
|
|
|
-{
|
|
|
|
- _buffer = new V3F_C4B_T2F[capacity];
|
|
|
|
- _firstCommand = new Command();
|
|
|
|
- _command = _firstCommand;
|
|
|
|
-
|
|
|
|
- Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_AFTER_DRAW_RESET_POSITION, [this](EventCustom* eventCustom){
|
|
|
|
- this->update(0);
|
|
|
|
- });;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SkeletonBatch::~SkeletonBatch () {
|
|
|
|
- Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(EVENT_AFTER_DRAW_RESET_POSITION);
|
|
|
|
-
|
|
|
|
- Command* command = _firstCommand;
|
|
|
|
- while (command) {
|
|
|
|
- Command* next = command->next;
|
|
|
|
- delete command;
|
|
|
|
- command = next;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- delete [] _buffer;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void SkeletonBatch::update (float delta) {
|
|
|
|
- _position = 0;
|
|
|
|
- _command = _firstCommand;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState,
|
|
|
|
- BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags
|
|
|
|
-) {
|
|
|
|
- if (_position + triangles.vertCount > _capacity) {
|
|
|
|
- int newCapacity = max(_capacity + _capacity / 2, _position + triangles.vertCount);
|
|
|
|
- V3F_C4B_T2F* newBuffer = new V3F_C4B_T2F[newCapacity];
|
|
|
|
- memcpy(newBuffer, _buffer, _position);
|
|
|
|
-
|
|
|
|
- int newPosition = 0;
|
|
|
|
- Command* command = _firstCommand;
|
|
|
|
- while (newPosition < _position) {
|
|
|
|
- command->triangles->verts = newBuffer + newPosition;
|
|
|
|
- newPosition += command->triangles->vertCount;
|
|
|
|
- command = command->next;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- delete [] _buffer;
|
|
|
|
- _buffer = newBuffer;
|
|
|
|
- _capacity = newCapacity;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- memcpy(_buffer + _position, triangles.verts, sizeof(V3F_C4B_T2F) * triangles.vertCount);
|
|
|
|
- _command->triangles->verts = _buffer + _position;
|
|
|
|
- _position += triangles.vertCount;
|
|
|
|
-
|
|
|
|
- _command->triangles->vertCount = triangles.vertCount;
|
|
|
|
- _command->triangles->indexCount = triangles.indexCount;
|
|
|
|
- _command->triangles->indices = triangles.indices;
|
|
|
|
-
|
|
|
|
- _command->trianglesCommand->init(globalZOrder, textureID, glProgramState, blendFunc, *_command->triangles, transform, transformFlags);
|
|
|
|
- renderer->addCommand(_command->trianglesCommand);
|
|
|
|
-
|
|
|
|
- if (!_command->next) _command->next = new Command();
|
|
|
|
- _command = _command->next;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SkeletonBatch::Command::Command () :
|
|
|
|
- next(nullptr)
|
|
|
|
-{
|
|
|
|
- trianglesCommand = new TrianglesCommand();
|
|
|
|
- triangles = new TrianglesCommand::Triangles();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SkeletonBatch::Command::~Command () {
|
|
|
|
- delete triangles;
|
|
|
|
- delete trianglesCommand;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+ void SkeletonBatch::destroyInstance () {
|
|
|
|
+ if (instance) {
|
|
|
|
+ delete instance;
|
|
|
|
+ instance = nullptr;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SkeletonBatch::SkeletonBatch ()
|
|
|
|
+ {
|
|
|
|
+ _firstCommand = new Command();
|
|
|
|
+ _command = _firstCommand;
|
|
|
|
+
|
|
|
|
+ Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_AFTER_DRAW_RESET_POSITION, [this](EventCustom* eventCustom){
|
|
|
|
+ this->update(0);
|
|
|
|
+ });;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SkeletonBatch::~SkeletonBatch () {
|
|
|
|
+ Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(EVENT_AFTER_DRAW_RESET_POSITION);
|
|
|
|
+
|
|
|
|
+ Command* command = _firstCommand;
|
|
|
|
+ while (command) {
|
|
|
|
+ Command* next = command->next;
|
|
|
|
+ delete command;
|
|
|
|
+ command = next;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void SkeletonBatch::update (float delta) {
|
|
|
|
+ _command = _firstCommand;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState,
|
|
|
|
+ BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags
|
|
|
|
+ ) {
|
|
|
|
+ _command->triangles->verts = triangles.verts;
|
|
|
|
+
|
|
|
|
+ _command->triangles->vertCount = triangles.vertCount;
|
|
|
|
+ _command->triangles->indexCount = triangles.indexCount;
|
|
|
|
+ _command->triangles->indices = triangles.indices;
|
|
|
|
+
|
|
|
|
+ _command->trianglesCommand->init(globalZOrder, textureID, glProgramState, blendFunc, *_command->triangles, transform);
|
|
|
|
+ renderer->addCommand(_command->trianglesCommand);
|
|
|
|
+
|
|
|
|
+ if (!_command->next) _command->next = new Command();
|
|
|
|
+ _command = _command->next;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SkeletonBatch::Command::Command () :
|
|
|
|
+ next(nullptr)
|
|
|
|
+ {
|
|
|
|
+ trianglesCommand = new TrianglesCommand();
|
|
|
|
+ triangles = new TrianglesCommand::Triangles();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SkeletonBatch::Command::~Command () {
|
|
|
|
+ delete triangles;
|
|
|
|
+ delete trianglesCommand;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|