Example #1
0
SVGPaintServer* getPaintServerById(Document* document, const AtomicString& id)
{
    SVGResource* resource = getResourceById(document, id);
    if (resource && resource->isPaintServer())
        return static_cast<SVGPaintServer*>(resource);

    return 0;
}
SVGResourceFilter* getFilterById(Document* document, const AtomicString& id, const RenderObject* object)
{
    SVGResource* resource = getResourceById(document, id, object);
    if (resource && resource->isFilter())
        return static_cast<SVGResourceFilter*>(resource);

    return 0;
}
Example #3
0
void ResourceManager::handleDatabaseJobComplete(void* ref,DatabaseResult* result)
{
    RMAsyncContainer* asyncContainer = reinterpret_cast<RMAsyncContainer*>(ref);

    switch(asyncContainer->mQueryType)
    {
    case RMQuery_ResourceTypes:
    {
        ResourceType* resType;

        uint64 count = result->getRowCount();

        for(uint64 i = 0; i < count; i++)
        {
            resType = new ResourceType();

            result->getNextRow(mResourceTypebinding,resType);
            mResourceTypeMap.insert(std::make_pair(resType->mId,resType));
        }

        // query categories
        mDatabase->executeSqlAsync(this,new(mDBAsyncPool.ordered_malloc()) RMAsyncContainer(RMQuery_Categories),"SELECT * FROM %s.resource_categories ORDER BY id",mDatabase->galaxy());
    }
    break;

    case RMQuery_Categories:
    {
        ResourceCategory* category;

        uint64 count = result->getRowCount();

        for(uint64 i = 0; i < count; i++)
        {
            category = new ResourceCategory();

            result->getNextRow(mResourceCategorybinding,category);
            (getResourceCategoryById(category->mParentId))->insertCategory(category);
            mResourceCategoryMap.insert(std::make_pair(category->mId,category));
        }


        mDatabase->executeSqlAsync(this,new(mDBAsyncPool.ordered_malloc()) RMAsyncContainer(RMQuery_CurrentResources),
                                   "SELECT resources.id,resources.name,resources.type_id,"
                                   "resources.er,resources.cr,resources.cd,resources.dr,resources.fl,resources.hr,"
                                   "resources.ma,resources.oq,resources.sr,resources.ut,resources.pe,"
                                   "resources_spawn_config.noiseMapBoundsX1,resources_spawn_config.noiseMapBoundsX2,"
                                   "resources_spawn_config.noiseMapBoundsY1,resources_spawn_config.noiseMapBoundsY2,"
                                   "resources_spawn_config.noiseMapOctaves,resources_spawn_config.noiseMapFrequency,"
                                   "resources_spawn_config.noiseMapPersistence,resources_spawn_config.noiseMapScale,"
                                   "resources_spawn_config.noiseMapBias,"
                                   "resources_spawn_config.unitsTotal,resources_spawn_config.unitsLeft"
                                   " FROM %s.resources"
                                   " INNER JOIN %s.resources_spawn_config ON (resources.id = resources_spawn_config.resource_id)"
                                   " WHERE"
                                   " (resources_spawn_config.planet_id = %u) AND"
                                   " (resources.active = 1)",mDatabase->galaxy(),mDatabase->galaxy(),mZoneId);
        
    }
    break;

    case RMQuery_OldResources:
    {
        Resource* resource;

        uint64 count = result->getRowCount();
        //gLogger->log(LogManager::INFORMATION,"Loading %u Old Resources",count);

        for(uint64 i = 0; i < count; i++)
        {
            resource = new Resource();

            result->getNextRow(mResourceBinding,resource);

            if(getResourceById(resource->mId) == NULL)
            {
                resource->mType = getResourceTypeById(resource->mTypeId);
                resource->mCurrent = 0;
                mResourceIdMap.insert(std::make_pair(resource->mId,resource));
                mResourceCRCNameMap.insert(std::make_pair(resource->mName.getCrc(),resource));
                (getResourceCategoryById(resource->mType->mCatId))->insertResource(resource);
            }
            else
                delete(resource);
        }

		if (count)
		{
			LOG(INFO) << "Loaded " << count << " resources";
		}
    }
    break;

    case RMQuery_CurrentResources:
    {
        CurrentResource* resource;

        uint64 count = result->getRowCount();
        for(uint64 i = 0; i < count; i++)
        {
            resource = new CurrentResource(mWriteResourceMaps, mZoneName);

            result->getNextRow(mCurrentResourceBinding,resource);
            resource->mType = getResourceTypeById(resource->mTypeId);
            resource->mCurrent = 1;
            resource->buildDistributionMap();
			mResourceIdMap.insert(std::make_pair(resource->mId,resource));
            mResourceCRCNameMap.insert(std::make_pair(resource->mName.getCrc(),resource));
            (getResourceCategoryById(resource->mType->mCatId))->insertResource(resource);
        }

		if (count)
		{
			LOG(INFO) << "Generated " << count << " resource maps";
		}

        // query old and current resources not from this planet
        mDatabase->executeSqlAsync(this,new(mDBAsyncPool.ordered_malloc()) RMAsyncContainer(RMQuery_OldResources),
									"SELECT * FROM %s.resources "
									" INNER JOIN %s.resources_spawn_config ON (resources.id = resources_spawn_config.resource_id)"
									" WHERE (NOT ("
									" (resources_spawn_config.planet_id = %u) AND"
									" (resources.active = 1)))",mDatabase->galaxy(),mDatabase->galaxy(),mZoneId);
		// dont load the active resources of this zone again!!!
    }
    break;
    case RMQuery_DepleteResources:
    {
        // do we have a return?
        // if the return is 0 we need to do nothing else
        // if it is 1, we need to execute sql async to set the active resource to 0
        // this means the resource is depleted. (can we do this via a stored proc?)
        uint32 returnId = 0;
        DataBinding* binding = mDatabase->createDataBinding(1);
        binding->addField(DFT_uint32,0,4);
        result->getNextRow(binding,&returnId);
        mDatabase->destroyDataBinding(binding);
        if (returnId == 1)
        {
            // remove from map
            Resource* resource = asyncContainer->mCurrentResource;
            mResourceCRCNameMap.erase(resource->mName.getCrc());
            mResourceIdMap.erase(resource->getId());
            (getResourceCategoryById(resource->mType->mCatId))->removeResource(resource);
        }
    }
    default:
        break;
    }

    mDBAsyncPool.ordered_free(asyncContainer);
}