123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #include <spine/SkeletonBatch.h>
- #include <spine/extension.h>
- #include <algorithm>
- USING_NS_CC;
- #define EVENT_AFTER_DRAW_RESET_POSITION "director_after_draw"
- using std::max;
- namespace spine {
- static SkeletonBatch* instance = nullptr;
- SkeletonBatch* SkeletonBatch::getInstance () {
- if (!instance) instance = new SkeletonBatch();
- return instance;
- }
- 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
- ) {
- if (_command->triangles->verts) {
- free(_command->triangles->verts);
- _command->triangles->verts = NULL;
- }
-
- _command->triangles->verts = (V3F_C4B_T2F *)malloc(sizeof(V3F_C4B_T2F) * triangles.vertCount);
- memcpy(_command->triangles->verts, triangles.verts, sizeof(V3F_C4B_T2F) * 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);
- 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 () {
- if (triangles->verts) {
- free(triangles->verts);
- }
- delete triangles;
- delete trianglesCommand;
- }
- }
|