void AssetTracker::OnAssetChanged( const Reflect::ObjectChangeArgs &args ) { Asset *pAsset = const_cast<Asset *>(Reflect::AssertCast< Asset >( args.m_Object )); pAsset->SetFlags( Asset::FLAG_CHANGED_SINCE_LOADED ); e_AssetChanged.Raise( AssetEventArgs( pAsset ) ); }
Asset* AssetManager::LoadAsset(const std::string& fileName) { IdIter iter = mAssetNameReferece.find(fileName); if (iter == mAssetNameReferece.end()) { //load asset AvailableAsset* asset = AvailableAsset::GetAvailableAssetFromFileName(fileName, false); if (!asset) { //asset never exists MessageBox(0, std::wstring(fileName.begin(), fileName.end()).c_str(), L"Asset not found", MB_OK); throw AssetException(AssetException::ASSETFILENOTFOUND); } meta::metafunction_method* loader = AssetManager::getInstance()->getmeta().getfunctionbyname("Load" + asset->Type()); if (!loader) { //loader doesn't exist throw AssetException(AssetException::ASSETFAILEDTOLOAD); } Asset* newAsset = loader->invoke(AssetManager::getInstance(), fileName).GetAs<Asset*>(); if (newAsset == 0) { Log("Asset failed to load for unknown reason: " + fileName); return 0; } newAsset->SetName(fileName); newAsset->SetType(asset->Type()); //add to the lists if (newAsset) InsertAssetInMap(newAsset); return newAsset; } //asset exists return mAssetContainer[iter->second]; }
inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& buffer, unsigned int count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, bool isIndices = false) { if (!count || !data) return Ref<Accessor>(); unsigned int numCompsIn = AttribType::GetNumComponents(typeIn); unsigned int numCompsOut = AttribType::GetNumComponents(typeOut); unsigned int bytesPerComp = ComponentTypeSize(compType); size_t offset = buffer->byteLength; size_t length = count * numCompsOut * bytesPerComp; buffer->Grow(length); // bufferView Ref<BufferView> bv = a.bufferViews.Create(a.FindUniqueID(meshName, "view")); bv->buffer = buffer; bv->byteOffset = unsigned(offset); bv->byteLength = length; //! The target that the WebGL buffer should be bound to. bv->target = isIndices ? BufferViewTarget_ELEMENT_ARRAY_BUFFER : BufferViewTarget_ARRAY_BUFFER; // accessor Ref<Accessor> acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor")); acc->bufferView = bv; acc->byteOffset = 0; acc->byteStride = 0; acc->componentType = compType; acc->count = count; acc->type = typeOut; // copy the data acc->WriteData(count, data, numCompsIn*bytesPerComp); return acc; }
void ParticleColliderComponent::initialize() { if( !d->item ) { d->item = GluonGraphics::Engine::instance()->createItem( "default" ); } if( d->material ) { Asset* materialAsset = qobject_cast<Asset*>( d->material->parent() ); if( materialAsset ) materialAsset->load(); Asset* texture = 0; if( d->material->property( "texture0" ).type() == QVariant::String ) { QString theName( d->material->property( "texture0" ).toString() ); QString theObjectName = GluonObject::nameToObjectName( theName ); texture = gameProject()->findChild<Asset*>( theObjectName ); if( !texture ) debug( QString( "Texture failed to load - attempted to load texture named %1 (searched for %2)" ).arg( theName ).arg( theObjectName ) ); } else texture = qobject_cast<Asset*>( GluonCore::GluonObjectFactory::instance()->wrappedObject( d->material->property( "texture0" ) ) ); if( texture ) texture->load(); d->item->setMaterialInstance( d->material ); } }
Asset* AssetManager::LoadSubShaders(const std::string& subshaderFile) { std::string fullPath = GetAbsolutePathOfFile(subshaderFile); std::wstring filepath = std::wstring(fullPath.begin(),fullPath.end()); SUBSHADERTYPE sstype = GetSubShaderTypeFromFile(fullPath); Asset* pSubShader = 0;; switch (sstype) { case VERTEX_SHADER: pSubShader = new SubShader<ID3D11VertexShader>(filepath, sstype); break; case PIXEL_SHADER: pSubShader = new SubShader<ID3D11PixelShader>(filepath, sstype); break; case COMPUTE_SHADER: pSubShader = new SubShader<ID3D11ComputeShader>(filepath, sstype); break; case GEOMETRY_SHADER: pSubShader = new SubShader<ID3D11GeometryShader>(filepath, sstype); break; } pSubShader->SetAutoUnload(false); pSubShader->AddUseCounter(); return pSubShader; }
/// Perform shutdown of the Asset system. /// /// This releases all final references to objects and releases all allocated memory. This should be called during /// the shutdown process after all types have been unregistered as well as after calling AssetType::Shutdown(). /// /// @see AssetType::Shutdown() void Asset::Shutdown() { HELIUM_TRACE( TraceLevels::Info, TXT( "Shutting down Asset system.\n" ) ); #if !HELIUM_RELEASE size_t objectCountActual = sm_objects.GetUsedSize(); if( objectCountActual != 0 ) { HELIUM_TRACE( TraceLevels::Error, TXT( "%" ) PRIuSZ TXT( " asset(s) still referenced during shutdown!\n" ), objectCountActual ); size_t objectCount = sm_objects.GetSize(); for( size_t objectIndex = 0; objectIndex < objectCount; ++objectIndex ) { if( !sm_objects.IsElementValid( objectIndex ) ) { continue; } Asset* pObject = sm_objects[ objectIndex ]; if( !pObject ) { continue; } #if HELIUM_ENABLE_MEMORY_TRACKING Helium::RefCountProxy<Reflect::Object> *pProxy = pObject->GetRefCountProxy(); HELIUM_ASSERT(pProxy); HELIUM_TRACE( TraceLevels::Error, TXT( " - 0x%p: %s (%" ) PRIu16 TXT( " strong ref(s), %" ) PRIu16 TXT( " weak ref(s))\n" ), pProxy, ( pObject ? *pObject->GetPath().ToString() : TXT( "(cleared reference)" ) ), pProxy->GetStrongRefCount(), pProxy->GetWeakRefCount() ); #else HELIUM_TRACE( TraceLevels::Error, TXT( "- %s\n" ), *pObject->GetPath().ToString() ); #endif } } #endif // !HELIUM_RELEASE sm_objects.Clear(); sm_wpFirstTopLevelObject.Release(); delete sm_pNameInstanceIndexMap; sm_pNameInstanceIndexMap = NULL; delete sm_pEmptyNameInstanceIndexMap; sm_pEmptyNameInstanceIndexMap = NULL; delete sm_pEmptyInstanceIndexSet; sm_pEmptyInstanceIndexSet = NULL; sm_serializationBuffer.Clear(); }
QDebug operator<<(QDebug debug, const Asset& asset) { debug.nospace() << "Asset{mnem=" << asset.mnem() // << ",display=" << asset.display() // << ",type=" << asset.type() // << '}'; return debug; }
Asset* AssetSystem::get(const char* pFileName) { Asset* pAsset = addPending(pFileName); if (pAsset && !pAsset->getLoaded()) { pAsset->load(); } return pAsset; }
/// Construct an instance of this object in-place. /// /// @param[in] pMemory Memory buffer in which to construct an instance of this object. /// @param[in] pDestroyCallback Callback to use when notifying that this object should be destroyed (when its /// reference count reaches zero). This must be specified. /// /// @return Pointer to the constructed object instance. /// /// @see InPlaceDestroy(), GetInstanceSize() Asset* Asset::InPlaceConstruct( void* pMemory, CUSTOM_DESTROY_CALLBACK* pDestroyCallback ) const { HELIUM_ASSERT( pMemory ); HELIUM_ASSERT( pDestroyCallback ); Asset* pObject = new( pMemory ) Asset; pObject->SetCustomDestroyCallback( pDestroyCallback ); return pObject; }
void BeamRendererComponent::Private::loadMaterial( GluonGraphics::MaterialInstance* material ) { Asset* materialAsset = qobject_cast<Asset*>( material->parent() ); if( materialAsset ) materialAsset->load(); Asset* texture = Game::instance()->gameProject()->findChild<Asset*>( material->property( "texture0" ).toString() ); if( texture ) texture->load(); }
Shader* GetShader(std::string relative_path){ Asset* assetClass = get_asset(relative_path); if (assetClass == NULL || assetClass->getType() != SHADER) return NULL; Shader* shader = static_cast<Shader *>(assetClass); if (shader) return shader; return NULL; }
Texture* GetTexture(std::string relative_path){ Asset* assetClass = get_asset(relative_path); if (assetClass == NULL || assetClass->getType() != TEXTURE) return NULL; Texture* texture = static_cast<Texture *>(assetClass); if (texture) return texture; return NULL; }
CameraControllerComponent::~CameraControllerComponent() { if( d->material ) { d->material->deref(); Asset* materialAsset = qobject_cast<Asset*>( d->material->parent() ); if( materialAsset ) materialAsset->deref(); } delete d; }
status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, const char* name) { Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); if (!asset) return NO_INIT; SkBitmap bitmap; SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(), &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode); asset->close(); delete asset; // ensure we can call getPixels(). No need to call unlock, since the // bitmap will go out of scope when we return from this method. bitmap.lockPixels(); const int w = bitmap.width(); const int h = bitmap.height(); const void* p = bitmap.getPixels(); GLint crop[4] = { 0, h, w, -h }; texture->w = w; texture->h = h; glGenTextures(1, &texture->name); glBindTexture(GL_TEXTURE_2D, texture->name); switch (bitmap.getConfig()) { case SkBitmap::kA8_Config: glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, p); break; case SkBitmap::kARGB_4444_Config: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, p); break; case SkBitmap::kARGB_8888_Config: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, p); break; case SkBitmap::kRGB_565_Config: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); break; default: break; } glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); return NO_ERROR; }
Asset *Helium::Asset::GetSourceAsset() { HELIUM_ASSERT( !m_path.IsEmpty() ); Asset *pAssetWithSourceFile = this; while ( pAssetWithSourceFile && pAssetWithSourceFile->GetAssetType()->GetFlags() & AssetType::FLAG_GENERATED_FROM_OWNER ) { pAssetWithSourceFile = pAssetWithSourceFile->GetOwner(); } return pAssetWithSourceFile; }
int main() { //Set up debug and info logging StreamAppender *appender = new StreamAppender(Logger::DEBUG | Logger::INFO, std::cout); Logger::add_appender(appender); fps::enable_fps_logging(true); //Create a window WindowManager &window_manager = WindowManager::get_instance(); EasyWindow *easy_window = create_easy_window(640, 480); Window *window = easy_window->window; window->set_keyboard_callback(key_callback); //Create an object to add to the world Renderer *renderer = new Renderer(FLAT_VERTEX_SHADER, FLAT_FRAGMENT_SHADER); Mesh *mesh = new Mesh(2, Mesh::TRIANGLES); mesh->set_vertex_attribute(0, 3, 3, g_vertex_buffer_data); mesh->set_vertex_attribute(1, 3, 3, cube_colors); //Create an asset to wrap all of the above Asset *asset = new Asset; asset->set_mesh(mesh); asset->set_renderer(renderer); //Create a renderable to actually draw on the screen Renderable *renderable = new Renderable; renderable->asset = asset; renderable->set_position(0.0f, 0.0f, 0.3f); easy_window->world->add_child(renderable); //Set up the viewpoint viewpoint = new Viewpoint; viewpoint->set_far(100.0f); viewpoint->set_near(1.0f); viewpoint->set_position(0.0f, 0.0f, -0.5f); easy_window->screen->set_viewpoint(viewpoint); while(!window->get_should_close()) { window->render(); window_manager.poll(); fps::fps_tick(); } destroy_easy_window(easy_window); delete viewpoint; //Clean up and exit Logger::shutdown(); delete appender; }
/// Tick the async loading of binary serialized data from the object cache for the given load request. /// /// @param[in] pRequest Load request. /// /// @return True if the cache load process has completed, false if it still requires processing. bool CachePackageLoader::TickCacheLoad( LoadRequest* pRequest ) { HELIUM_ASSERT( pRequest ); HELIUM_ASSERT( !( pRequest->flags & LOAD_FLAG_PRELOADED ) ); AsyncLoader* pAsyncLoader = AsyncLoader::GetInstance(); HELIUM_ASSERT( pAsyncLoader ); size_t bytesRead = 0; if( !pAsyncLoader->TrySyncRequest( pRequest->asyncLoadId, bytesRead ) ) { return false; } SetInvalid( pRequest->asyncLoadId ); if( bytesRead == 0 || IsInvalid( bytesRead ) ) { HELIUM_ASSERT( pRequest->pEntry ); HELIUM_TRACE( TraceLevels::Error, "CachePackageLoader: Failed to read cache data for object \"%s\".\n", *pRequest->pEntry->path.ToString() ); } else { uint8_t* pBufferEnd = pRequest->pAsyncLoadBuffer + bytesRead; pRequest->pPropertyDataEnd = pBufferEnd; pRequest->pPersistentResourceDataEnd = pBufferEnd; if( ReadCacheData( pRequest ) ) { return true; } } // An error occurred attempting to load the property data, so mark any existing object as fully loaded (nothing // else will be done with the object itself from here on out). DefaultAllocator().Free( pRequest->pAsyncLoadBuffer ); pRequest->pAsyncLoadBuffer = NULL; Asset* pObject = pRequest->spObject; if( pObject ) { pObject->SetFlags( Asset::FLAG_PRELOADED | Asset::FLAG_LINKED ); pObject->ConditionalFinalizeLoad(); } pRequest->flags |= LOAD_FLAG_PRELOADED | LOAD_FLAG_ERROR; return true; }
void SceneView3D::HandleDragEnded(StringHash eventType, VariantMap& eventData) { using namespace DragEnded; UIDragObject* dragObject = static_cast<UIDragObject*>(eventData[P_DRAGOBJECT].GetPtr()); if (dragNode_.NotNull()) { VariantMap neventData; neventData[EditorActiveNodeChange::P_NODE] = dragNode_; SendEvent(E_EDITORACTIVENODECHANGE, neventData); } if (dragObject && dragObject->GetObject()->GetType() == ToolCore::Asset::GetTypeStatic()) { Asset* asset = (ToolCore::Asset*) dragObject->GetObject(); if (asset->GetImporterTypeName() == "MaterialImporter") { Material* material = GetSubsystem<ResourceCache>()->GetResource<Material>(asset->GetPath()); if (material) { material = material; Ray camRay = GetCameraRay(); PODVector<RayQueryResult> result; RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_GEOMETRY, 0x7fffffff); octree_->RaycastSingle(query); if (query.result_.Size()) { const RayQueryResult& r = result[0]; if (r.drawable_ && (r.drawable_->GetType() == StaticModel::GetTypeStatic() || r.drawable_->GetType() == AnimatedModel::GetTypeStatic())) { ((StaticModel*)r.drawable_)->SetMaterial(material); } } } } } dragAssetGUID_ = ""; dragNode_ = 0; }
void AssetSystem::loadPending() { // Can't cache the element count here because loading may cause // new assets to be added to the table. for (int x = 0; x < mLoadedAssetTable.getElementCount(); x++) { Asset* asset = mLoadedAssetTable.get(x); if (!asset->getLoaded()) { asset->load(); } } }
string Assets::Name(AssetID id) { if (!id.Valid()) { Console::Error() << "[Dynacoe::Assets]: Failed to get name of asset: asset not found!"<< Console::End; return ""; } Asset * asset = assetList[id.type][id.handle]; if (!asset) { Console::Error() << "[Dynacoe::Assets]: Failed to get name of asset: asset not found!"<< Console::End; return ""; } return asset->GetAssetName(); }
void Bitmap_RLE8::Save(Asset& asset) const { if (asset.Create()) { asset.Write(Pixie_Rle_Header,StrLen(Pixie_Rle_Header)); int version=0; asset.Write(&version); int celCount=1; asset.Write(&celCount); WriteToAsset(&asset); asset.Close(); } }
/// Update resource precaching for the given object load request. /// /// @param[in] pRequest Load request to update. /// /// @return True if resource precaching still requires processing, false if not. bool AssetLoader::TickPrecache( LoadRequest* pRequest ) { HELIUM_ASSERT( pRequest ); HELIUM_ASSERT( !( pRequest->stateFlags & LOAD_FLAG_LOADED ) ); Asset* pObject = pRequest->spObject; if( pObject ) { // TODO: SHouldn't this be in the linking phase? if ( !pRequest->resolver.TryFinishPrecachingDependencies() ) { return false; } pRequest->resolver.Clear(); // Perform any pre-precaching work (note that we don't precache anything for the default template object for // a given type). OnPrecacheReady( pObject, pRequest->pPackageLoader ); if( !pObject->GetAnyFlagSet( Asset::FLAG_BROKEN ) && !pObject->IsDefaultTemplate() && pObject->NeedsPrecacheResourceData() ) { if( !( pRequest->stateFlags & LOAD_FLAG_PRECACHE_STARTED ) ) { if( !pObject->BeginPrecacheResourceData() ) { HELIUM_TRACE( TraceLevels::Error, TXT( "AssetLoader: Failed to begin precaching object \"%s\".\n" ), *pObject->GetPath().ToString() ); pObject->SetFlags( Asset::FLAG_PRECACHED | Asset::FLAG_BROKEN ); AtomicOrRelease( pRequest->stateFlags, LOAD_FLAG_PRECACHED | LOAD_FLAG_ERROR ); return true; } AtomicOrRelease( pRequest->stateFlags, LOAD_FLAG_PRECACHE_STARTED ); } if( !pObject->TryFinishPrecacheResourceData() ) { return false; } } pObject->SetFlags( Asset::FLAG_PRECACHED ); } AtomicOrRelease( pRequest->stateFlags, LOAD_FLAG_PRECACHED ); return true; }
void WebRequest::handleBrowserURL(GURL url) { std::string data("data:text/html;charset=utf-8,"); if (url.spec() == "browser:incognito") { AssetManager* assetManager = globalAssetManager(); Asset* asset = assetManager->open("webkit/incognito_mode_start_page.html", Asset::ACCESS_BUFFER); if (asset) { data.append((const char*)asset->getBuffer(false), asset->getLength()); delete asset; } } GURL dataURL(data.c_str()); handleDataURL(dataURL); }
Asset* AssetSystem::getNewInstance(const char* pFileName) { Asset* pAsset = get(pFileName); Asset* pInstance = NULL; if (pAsset) { pInstance = pAsset->instance(); if (pInstance) { mInstancedAssetTable.add(pFileName, pAsset); } } return pInstance; }
ImageFormat_TGA::ImageFormat_TGA(const Asset& asset): image_(0) { int size=asset.GetSize(); char* buffer=new char[size]; asset.Open(); asset.Read(buffer,size); asset.Close(); image_=new tga_image; tga_read_from_Buffer(static_cast<tga_image*>(image_),buffer); delete[] buffer; }
void ProjectPanel::OnLoadForEdit( wxCommandEvent& event ) { wxDataViewItemArray selection; int numSelected = m_DataViewCtrl->GetSelections( selection ); for (int i = 0; i < numSelected; ++i) { Asset *pAsset = static_cast<Asset *>( selection[i].GetID() ); if (pAsset && pAsset->IsPackage()) { ForciblyFullyLoadedPackageManager::GetStaticInstance()->ForceFullyLoadPackage(pAsset->GetPath()); } } }
/// Update the stored path for this object. /// /// This should be called whenever the name of this object or one of its parents changes. void Asset::UpdatePath() { // Update this object's path first. HELIUM_VERIFY( m_path.Set( m_name, IsPackage(), ( m_spOwner ? m_spOwner->m_path : AssetPath( NULL_NAME ) ), m_instanceIndex ) ); // Update the path of each child object. for( Asset* pChild = m_wpFirstChild; pChild != NULL; pChild = pChild->m_wpNextSibling ) { pChild->UpdatePath(); } }
bool AudioFormat_YM::TestAsset(const Asset& asset) { if (asset.Open()) { char buffer[7]; asset.Read(buffer,7); asset.Close(); if (StrNCmp(&buffer[2],"-lh5-",5)==0 || StrNCmp(buffer,"YM3!",4)==0) { return true; } } return false; }
bool ImageFormat_GIF::TestAsset(const Asset& asset) { if (asset.Open()) { char buffer[3]; asset.Read(buffer,3); asset.Close(); if (StrNCmp(buffer,"GIF",3)==0) { return true; } } return false; }
/// Update loading finalization for the given object load request. /// /// @param[in] pRequest Load request to update. /// /// @return True if load finalization has completed, false if not. bool AssetLoader::TickFinalizeLoad( LoadRequest* pRequest ) { HELIUM_ASSERT( pRequest ); Asset* pObject = pRequest->spObject; if( pObject ) { pObject->ConditionalFinalizeLoad(); } // Loading now complete. OnLoadComplete( pRequest->path, pObject, pRequest->pPackageLoader ); AtomicOrRelease( pRequest->stateFlags, LOAD_FLAG_LOADED ); return true; }