Example #1
0
DragonBonesData * JSONDataParser::parseDragonBonesData(const char* rawData, float scale)
{
    if (rawData)
    {
        rapidjson::Document document;
        document.Parse(rawData);

        std::string version = _getString(document, VERSION, "");
        this->_isParentCooriinate = version == DATA_VERSION_2_3 || version == DATA_VERSION_3_0;
        this->_armatureScale = scale;

        if (version == DATA_VERSION || version == DATA_VERSION_4_0 || this->_isParentCooriinate)
        {
            const auto data = BaseObject::borrowObject<DragonBonesData>();
            data->name = _getString(document, NAME, "");
            data->frameRate = _getNumber(document, FRAME_RATE, (unsigned)24);

            if (document.HasMember(ARMATURE))
            {
                this->_data = data;

                for (const auto& armatureObject : document[ARMATURE].GetArray())
                {
                    data->addArmature(_parseArmature(armatureObject));
                }

                this->_data = nullptr;
            }

            return data;
        }
        else
        {
            DRAGONBONES_ASSERT(false, "Nonsupport data version.");
        }
    }
    else
    {
        DRAGONBONES_ASSERT(false, "Argument error.");
    }

    return nullptr;
}
Example #2
0
void JSONDataParser::parseTextureAtlasData(const char* rawData, TextureAtlasData& textureAtlasData, float scale)
{
    if (rawData)
    {
        rapidjson::Document document;
        document.Parse(rawData);

        textureAtlasData.format = _getTextureFormat(_getString(document, FORMAT, ""));
        textureAtlasData.name = _getString(document, NAME, "");
        textureAtlasData.imagePath = _getString(document, IMAGE_PATH, "");

        if (scale > 0.f)
        {
            textureAtlasData.scale = scale;
        }
        else
        {
            scale = textureAtlasData.scale = _getNumber(document, SCALE, textureAtlasData.scale);
        }

        scale = 1.f / scale;

        if (document.HasMember(SUB_TEXTURE))
        {
            for (const auto& textureObject : document[SUB_TEXTURE].GetArray())
            {
                const auto textureData = textureAtlasData.generateTexture();
                textureData->name = _getString(textureObject, NAME, "");
                textureData->rotated = _getBoolean(textureObject, ROTATED, false);
                textureData->region.x = _getNumber(textureObject, X, 0.f) * scale;
                textureData->region.y = _getNumber(textureObject, Y, 0.f) * scale;
                textureData->region.width = _getNumber(textureObject, WIDTH, 0.f) * scale;
                textureData->region.height = _getNumber(textureObject, HEIGHT, 0.f) * scale;

                const auto frameWidth = _getNumber(textureObject, FRAME_WIDTH, -1.f);
                const auto frameHeight = _getNumber(textureObject, FRAME_HEIGHT, -1.f);
                if (frameWidth > 0.f && frameHeight > 0.f)
                {
                    textureData->frame = TextureData::generateRectangle();
                    textureData->frame->x = _getNumber(textureObject, FRAME_X, 0.f) * scale;
                    textureData->frame->y = _getNumber(textureObject, FRAME_Y, 0.f) * scale;
                    textureData->frame->width = frameWidth * scale;
                    textureData->frame->height = frameHeight * scale;
                }

                textureAtlasData.addTexture(textureData);
            }
        }
    }
    else
    {
        DRAGONBONES_ASSERT(false, "Argument error.");
    }
}
void TextureAtlasData::addTexture(TextureData* value)
{
    if (textures.find(value->name) != textures.cend()) 
    {
        DRAGONBONES_ASSERT(false, "Same texture: " + value->name);
        return;
    }

    textures[value->name] = value;
    value->parent = this;
}
Example #4
0
void AnimationData::addSlotTimeline(SlotTimelineData* value)
{
    if (value && value->slot && slotTimelines.find(value->slot->name) == slotTimelines.end())
    {
        slotTimelines[value->slot->name] = value;
    }
    else
    {
        DRAGONBONES_ASSERT(false, "Argument error.");
    }
}
Example #5
0
void AnimationData::addBoneTimeline(BoneTimelineData* value)
{
    if (value && value->bone && boneTimelines.find(value->bone->name) == boneTimelines.end())
    {
        boneTimelines[value->bone->name] = value;
    }
    else
    {
        DRAGONBONES_ASSERT(false, "Argument error.");
    }
}
Example #6
0
void AnimationData::addFFDTimeline(FFDTimelineData* value)
{
    if (value && value->skin && value->slot)
    {
        const auto& skinName = value->skin->name;
        const auto& slotName = value->slot->slot->name;
        const auto& displayIndex = to_string(value->displayIndex); // std::to_string

        auto& skin = ffdTimelines[skinName];
        auto& slot = skin[slotName];
        if (slot.find(displayIndex) == slot.end())
        {
            slot[displayIndex] = value;
        }
        else
        {
            DRAGONBONES_ASSERT(false, "Argument error.");
        }
    }
    else
    {
        DRAGONBONES_ASSERT(false, "Argument error.");
    }
}
void BaseObject::_returnObject(BaseObject* object)
{
    const auto classTypeIndex = object->getClassTypeIndex();
    const auto maxCountIterator = _maxCountMap.find(classTypeIndex);
    const auto maxCount = maxCountIterator != _maxCountMap.end() ? maxCountIterator->second : _defaultMaxCount;
    
    auto& pool = _poolsMap[classTypeIndex];
    if (pool.size() < maxCount)
    {
        if (std::find(pool.cbegin(), pool.cend(), object) == pool.cend())
        {
            pool.push_back(object);
        }
        else 
        {
            DRAGONBONES_ASSERT(false, "The object aleady in pool.");
        }
    }
    else
    {
        delete object;
    }
}