void ShaderUnloadTask::doRun() { CDNArchive::clearArchive(mArchiveName); SharedResourcePtr resource = mResource.lock(); if (resource) { resource->unloaded(true, mEpoch); } }
void ShaderDependencyTask::operator()() { SharedResourcePtr resourcePtr = mResource.lock(); if (!resourcePtr) { finish(false); return; } resourcePtr->parsed(true); finish(true); }
void ShaderDependencyTask::run() { SharedResourcePtr resourcePtr = mResource.lock(); if (!resourcePtr) { signalCompletion(false); return; } resourcePtr->parsed(true); signalCompletion(); }
SharedResourcePtr GraphicsResourceManager::getResourceAsset(const URI &id, GraphicsResource::Type resourceType) { WeakResourcePtr curWeakPtr; SharedResourcePtr curSharedPtr; if (ResourceManager::getSingleton().isMHashScheme(id)) { try { curWeakPtr = getResource(RemoteFileId(id).fingerprint().convertToHexString()); curSharedPtr = curWeakPtr.lock(); } catch (std::invalid_argument &ia) { } } if (!curSharedPtr) { curWeakPtr = getResource(id.toString()); curSharedPtr = curWeakPtr.lock(); } if (curSharedPtr) return curSharedPtr; else { try { if (ResourceManager::getSingleton().isMHashScheme(id)) { // std::invalid_argument may be thrown, but is caught by the "catch" below. RemoteFileId resourceId(id); if (resourceType == GraphicsResource::MESH) { curSharedPtr = GraphicsResource::construct<GraphicsResourceMesh>(resourceId); } else if (resourceType == GraphicsResource::MATERIAL) { curSharedPtr = GraphicsResource::construct<GraphicsResourceMaterial>(resourceId); } else if (resourceType == GraphicsResource::TEXTURE) { curSharedPtr = GraphicsResource::construct<GraphicsResourceTexture>(resourceId); } else if (resourceType == GraphicsResource::SHADER) { curSharedPtr = GraphicsResource::construct<GraphicsResourceShader>(resourceId); } else { assert(false); } } else { curSharedPtr = GraphicsResource::construct<GraphicsResourceName>(id, resourceType); } mIDResourceMap[curSharedPtr->getID()] = curSharedPtr; mResources.insert(curSharedPtr.get()); } catch (std::invalid_argument& exc) { } return curSharedPtr; } }
SharedResourcePtr receiveResource ( SimpleTcpEndPoint client ) { unsigned long long index = 0; ByteBuffer message; client.receive ( message ); received += message.getLength(); SharedResourcePtr result = ResourceHolder::FromBuffer(message,index); recvResources[result->getUUID()] = result; ResourceHolder::RegisterResource(result); if ( recvCB.find ( result->mTypeID) != recvCB.end () ) { (*recvCB[result->mTypeID]) ( result ); } return result; }
SharedResourcePtr GraphicsResourceManager::getResourceEntity(const SpaceObjectReference &id, GraphicsEntity *graphicsEntity) { WeakResourcePtr curWeakPtr = getResource(id.toString()); SharedResourcePtr curSharedPtr = curWeakPtr.lock(); if (curSharedPtr) return curSharedPtr; else { curSharedPtr = GraphicsResource::construct<GraphicsResourceEntity>(id, graphicsEntity); mIDResourceMap[id.toString()] = curSharedPtr; mEntities.insert(curSharedPtr.get()); return curSharedPtr; } }
/* bool MeshUnloadTask::mainThreadUnload(String name) { Ogre::MeshManager::getSingleton().unload(name); // operationCompleted(Ogre::BackgroundProcessTicket(), Ogre::BackgroundProcessResult()); return false; } */ void MeshUnloadTask::doRun() { /*I REALLY wish this were true*/ // SequentialWorkQueue::getSingleton().queueWork(std::tr1::bind(&MeshUnloadTask::mainThreadUnload, this, mHash)); String hash = mHash; //CDNArchive::canonicalMhashName(mHash); Ogre::MeshManager* meshManager = Ogre::MeshManager::getSingletonPtr(); meshManager->remove(hash); Ogre::ResourcePtr meshResource = meshManager->getByName(hash); assert(meshResource.isNull()); SharedResourcePtr resource = mResource.lock(); if (resource) resource->unloaded(true, mEpoch); }
void OnReceiveWorld ( SharedResourcePtr resource ) { std::cout << "World::" << resource->getName().toStdString() << std::endl; Assets::WorldPtr world = resource.dynamicCast<Assets::World> (); for ( int i = 0 ; i < world->getSize < QUuid > ( "Cells" ) ; i ++ ) { fetchResource ( world->get < QUuid > ( "Cells", i ) ); } }
void OnReceiveWorldCell ( SharedResourcePtr resource ) { std::cout << "WorldCell::" << resource->getName().toStdString() << std::endl; Assets::WorldCellPtr cell = resource.dynamicCast<Assets::WorldCell> (); for ( int i = 0 ; i < cell->getSize < QUuid > ( "GameObjects" ) ; i ++ ) { fetchResource ( cell->get < QUuid > ( "GameObjects", i ) ); } }
void OnReceiveMesh ( SharedResourcePtr resource ) { std::cout << "Mesh::" << resource->getName().toStdString() << std::endl; Assets::MeshPtr mesh = resource.dynamicCast<Assets::Mesh> (); for ( unsigned int i = 0 ; i < mesh->getSize < Assets::MaterialGroup* > ( "MaterialGroups" ) ; i ++ ) { Assets::MaterialGroup* grp = mesh->get < Assets::MaterialGroup* > ( "MaterialGroups", i ); fetchResource ( grp->get < QUuid > ( "Material" ) ); } }
void MeshDependencyTask::operator()() { SharedResourcePtr resourcePtr = mResource.lock(); if (!resourcePtr) { finish(false); return; } if (OPTION_ENABLE_TEXTURES->as<bool>()) { GraphicsResourceManager *grm = GraphicsResourceManager::getSingletonPtr(); MemoryBuffer::iterator itr, iend; for (itr = mBuffer.begin(), iend = mBuffer.end() - 7; itr != iend; ++itr) { if (*itr == 'm' && (*(itr + 1)) == 'e' && (*(itr + 2)) == 'r' && (*(itr + 3)) == 'u' && (*(itr + 4)) == ':' && (*(itr + 5)) == '/' && (*(itr + 6)) == '/') { String matDep = ""; while (itr != iend + 4) { if (*itr == '.' && (*(itr + 1) == 'o') && (*(itr + 2) == 's')) { matDep += ".os"; break; } matDep += *itr; ++itr; } SharedResourcePtr hashResource = grm->getResourceAsset(URI(matDep), GraphicsResource::MATERIAL); resourcePtr->addDependency(hashResource); } } } resourcePtr->setCost(mBuffer.size()); resourcePtr->parsed(true); finish(true); }
void OnReceiveGameEntity ( SharedResourcePtr resource ) { std::cout << "GameEntity::" << resource->getName().toStdString() << std::endl; Assets::GameEntityPtr ge = resource.dynamicCast<Assets::GameEntity> (); for ( int i = 0 ; i < ge->getSize < Assets::GameEntityElement* > ( "Elements" ) ; i ++ ) { Assets::GameEntityElement* elt = ge->get < Assets::GameEntityElement* > ( "Elements", i ); for ( int j = 0 ; j < elt->getSize < QUuid > ( "Resources" ) ; j ++ ) { fetchResource ( elt->get < QUuid > ( "Resources", j ) ); } } }
int main(int argc, char *argv[]) { /* __attach(); __attachInterfaces(); __attachGenerics(); __attachAssets();*/ __attachQImage(); __attachWavefront(); FileDescriptor file ( argv[1]); ResourceHolder::Load(file); ResourceHolder::Usage(); foreach ( QUuid id, ResourceHolder::AllKeys() ) { SharedResourcePtr res = ResourceHolder::GetByUUID(id); res->Usage(); ByteBuffer buffer = ResourceHolder::ToBuffer( res ); unsigned long long index = 0; SharedResourcePtr ptr = ResourceHolder::FromBuffer(buffer,index); ptr->Usage(); }
void OnReceiveWavefrontMaterial ( SharedResourcePtr resource ) { QUuid fake; std::cout << "WavefrontMaterial::" << resource->getName().toStdString() << std::endl; Assets::MaterialPtr material = resource.dynamicCast<WavefrontMaterial> (); if ( fake != material->get < Texture > ( "AmbientMap" ).imageID ) fetchResource ( material->get < Texture > ( "AmbientMap" ).imageID ); if ( fake != material->get < Texture > ( "DiffuseMap" ).imageID ) fetchResource ( material->get < Texture > ( "DiffuseMap" ).imageID ); if ( fake != material->get < Texture > ( "SpecularMap" ).imageID ) fetchResource ( material->get < Texture > ( "SpecularMap" ).imageID ); if ( fake != material->get < Texture > ( "SpecularExponentMap" ).imageID ) fetchResource ( material->get < Texture > ( "SpecularExponentMap" ).imageID ); if ( fake != material->get < Texture > ( "DissolveMap" ).imageID ) fetchResource ( material->get < Texture > ( "DissolveMap" ).imageID ); if ( fake != material->get < Texture > ( "DecalMap" ).imageID ) fetchResource ( material->get < Texture > ( "DecalMap" ).imageID ); if ( fake != material->get < Texture > ( "DisplacementMap" ).imageID ) fetchResource ( material->get < Texture > ( "DisplacementMap" ).imageID ); if ( fake != material->get < Texture > ( "BumpMap" ).imageID ) fetchResource ( material->get < Texture > ( "BumpMap" ).imageID ); if ( fake != material->get < Texture > ( "ReflectionMap" ).imageID ) fetchResource ( material->get < Texture > ( "ReflectionMap" ).imageID ); }
void addDependency(SharedResourcePtr newResource) { assert(newResource); mDependencies.insert(newResource); newResource->addDependent(getWeakPtr()); }
void OnReceiveLight ( SharedResourcePtr resource ) { std::cout << "Light::" << resource->getName().toStdString() << std::endl; Assets::LightPtr light = resource.dynamicCast<Assets::Light> (); }
void OnReceiveGameObject ( SharedResourcePtr resource ) { std::cout << "GameObject::" << resource->getName().toStdString() << std::endl; Assets::GameObjectPtr go = resource.dynamicCast<Assets::GameObject> (); fetchResource ( go->get < QUuid > ( "Entity" ) ); }
bool ServerManager::interpret(QUuid client){ if(client == NULL){ std::cout << "erreur : client incorrect." << std::endl; return false; } if(connection == 0) { std::cout << "Error : no socket bound" << std::endl; return false; } if(!connection->isStarted()){ std::cout << "erreur : connection non démarrée." << std::endl; return false; } //std::cout << "Client OK" << std::endl; EncByteBuffer requete, reponse; requete.setType(-2); SharedResourcePtr res; QUuid req, q; EncByteBuffer resource; long long unsigned int l; while(requete.getType() == -2) { if(connection->isStarted()){ //std::cout << "EncTcpStartPoint try receiving" << std::endl; if(! connection->receive(client, requete) ) { std::cout << "Not able to receive" <<std::endl; return false; } if(!connection->hasEndPoint() ){ std::cout << "No end to receive frome" <<std::endl; return false; } //std::cout << "After receiving " << requete.getType() << "/" << requete.getLength() << std::endl; } else { std::cout << "Connection dropped" << std::endl; return false; } } //std::cout << "Receiving request" << std::endl; //std::cout << "Type " << requete.getType() << " , length " << requete.getLength() << std::endl; switch(requete.getType()){ case ServerManager::SHARED_R : //std::cout << "Received Request for resource " << std::endl; l = requete.getLength(); req = QUuid((const char*)(requete.getData())); std:: cout << "Getting " << req.toString().toStdString() << std::endl; res = ServerManager::getInstance()->getRessource(req); reponse.setType(SHARED_R); if(res.isNull()) { reponse = EncByteBuffer(ERROR); reponse.append(ByteBuffer((unsigned char*)(req.toByteArray().data()), req.toByteArray().size())); } else{ resource = ResourceHolder::ToBuffer(res); reponse.append(resource); } break; case ServerManager::TEST : reponse.setType(TEST); l = requete.getLength(); ::fromBuffer(requete, l, req); res = ServerManager::getInstance()->getRessource(req); reponse.append(ByteBuffer((unsigned char*)(q.toByteArray().data()), q.toByteArray().size())); break; case ServerManager::WORLD : std::cout << "Error : Unexpected type WORLD." << std::endl; return false; break; default : std::cout << "Error : Unknown type " << requete.getType() << std::endl; return false; break; } if(! connection->send(client, reponse )){ std::cout << "Couldn't send" << std::endl; return false; } return true; }
void OnReceiveImage ( SharedResourcePtr resource ) { std::cout << "Image::" << resource->getName().toStdString() << std::endl; Assets::ImagePtr image = resource.dynamicCast<Assets::Image> (); }