void preload_images() { double start_time = platform_get_time(); #if !defined(CHOWDREN_IS_DESKTOP) && !defined(CHOWDREN_IS_ANDROID) #if defined(CHOWDREN_PRELOAD_IMAGES) || defined(CHOWDREN_PRELOAD_ALL) AssetFile fp; fp.open(); FileStream stream(fp); #ifdef CHOWDREN_IS_3DS Render::set_storage(true); #endif for (int i = 0; i < IMAGE_COUNT; i++) { unsigned short handle = stream.read_uint16(); Image * image = get_internal_image(handle); image->upload_texture(); #if !defined(CHOWDREN_PRELOAD_ALL) && defined(CHOWDREN_IS_3DS) if (Render::is_vram_full()) break; #endif image->set_static(); } #ifdef CHOWDREN_IS_3DS Render::set_storage(false); #endif #endif #endif double dt = platform_get_time() - start_time; std::cout << "Image preload took " << dt << std::endl; }
void Media::init() { ChowdrenAudio::open_audio(); double start_time = platform_get_time(); AssetFile fp; fp.open(); #ifdef CHOWDREN_IS_WIIU // experimental code to load faster unsigned int start = AssetFile::get_offset(0, AssetFile::SOUND_DATA); unsigned int size = AssetFile::get_size(AssetFile::SOUND_DATA); startup_data = new unsigned char[size]; startup_size = size; fp.seek(start); fp.read(startup_data, size); for (int i = 0; i < SOUND_COUNT; i++) { add_cache(i); } delete[] startup_data; #else for (int i = 0; i < SOUND_COUNT; i++) { fp.set_item(i, AssetFile::SOUND_DATA); add_cache(i, fp); } #endif std::cout << "Sound bank took " << (platform_get_time() - start_time) << std::endl; }
void Image::load() { flags |= USED; if (tex != 0 || image != NULL) return; if (flags & FILE) { ((FileImage*)this)->load_file(); return; } open_image_file(); image_file.set_item(handle, AssetFile::IMAGE_DATA); FileStream stream(image_file); hotspot_x = stream.read_int16(); hotspot_y = stream.read_int16(); action_x = stream.read_int16(); action_y = stream.read_int16(); int size = stream.read_uint32(); int w, h, channels; image = load_image(image_file, size, &w, &h, &channels); width = w; height = h; if (image == NULL) { std::cout << "Could not load image " << handle << std::endl; std::cout << stbi_failure_reason() << std::endl; return; } }
bool load_fonts(FontList & fonts) { AssetFile fp; fp.open(); FileStream stream(fp); for (int i = 0; i < FONT_COUNT; i++) { fp.set_item(i, AssetFile::FONT_DATA); unsigned int count = stream.read_uint32(); for (unsigned int i = 0; i < count; i++) { FTTextureFont * font = new FTTextureFont(stream); fonts.push_back(font); } } return fonts.size() > 0; }
void Image::load() { flags |= USED; if (tex != 0 || image != NULL) return; if (flags & FILE) { ((FileImage*)this)->load_file(); return; } unsigned int size, out_size; unsigned char * buf; int ret; if (startup_data) { unsigned int start = AssetFile::get_offset(0, AssetFile::IMAGE_DATA); unsigned int self = AssetFile::get_offset(handle, AssetFile::IMAGE_DATA); unsigned int offset = self - start; ArrayStream stream((char*)startup_data, startup_size); stream.seek(offset); load_image_info(*this, stream, size, out_size); buf = &startup_data[stream.pos]; ret = stbi_zlib_decode_buffer((char*)image, out_size, (const char*)buf, size); } else { open_image_file(); image_file.set_item(handle, AssetFile::IMAGE_DATA); FileStream stream(image_file); load_image_info(*this, stream, size, out_size); buf = new unsigned char[size]; image_file.read(buf, size); ret = stbi_zlib_decode_buffer((char*)image, out_size, (const char*)buf, size); delete[] buf; } if (ret < 0) { std::cout << "Could not load image " << handle << std::endl; std::cout << stbi_failure_reason() << std::endl; stbi_image_free(image); image = NULL; } }
void preload_images() { #ifndef CHOWDREN_IS_DESKTOP #if defined(CHOWDREN_PRELOAD_IMAGES) || defined(CHOWDREN_PRELOAD_ALL) AssetFile fp; fp.open(); FileStream stream(fp); glc_set_storage(true); for (int i = 0; i < IMAGE_COUNT; i++) { unsigned short handle = stream.read_uint16(); Image * image = get_internal_image(handle); image->upload_texture(); #ifndef CHOWDREN_PRELOAD_ALL if (glc_is_vram_full()) break; #endif image->set_static(); } glc_set_storage(false); #endif #endif }
void open_image_file() { if (image_file.is_open()) return; image_file.open(); }
void CacheDB::InsertAssetFile( AssetFile* assetFile, M_AssetFiles* assetFiles, std::set< Nocturnal::Path >& visited, bool* cancel ) { if ( CheckCancelQuery( cancel ) ) { return; } if ( !assetFile || !assetFiles ) { return; } // Insert the dependencies first since we will need their row in the DB to reference them to the parents if ( assetFile->HasDependencies() ) { std::set< Nocturnal::Path > assetDependencies = assetFile->GetDependencies(); std::set< Nocturnal::Path >::const_iterator itr = assetDependencies.begin(); std::set< Nocturnal::Path >::const_iterator end = assetDependencies.end(); for ( ; itr != end; ++itr ) { if ( CheckCancelQuery( cancel ) ) { return; } Nocturnal::Path filePath = (*itr); if ( visited.find( filePath ) == visited.end() ) { visited.insert( filePath ); M_AssetFiles::iterator foundFile = assetFiles->find( filePath.Hash() ); if ( foundFile != assetFiles->end() ) { AssetFile* assetDependency = foundFile->second; if ( HasAssetChangedOnDisk( filePath ) ) { InsertAssetFile( assetDependency, assetFiles, visited, cancel ); } else { // This dependency is already in the DB so make sure we put the rowID on it u64 rowID = SelectAssetRowID( assetDependency->GetPath().Hash(), NULL, NULL, cancel ); assetDependency->SetRowID( rowID ); } } } } } if ( CheckCancelQuery( cancel ) ) { return; } // u64 assetTypeID = SelectIDByName( m_SelectAssetTypeIDHandle, assetFile->GetAssetType(), s_InsertAssetTypeSQL, cancel ); if ( assetFile->GetFileFilter().empty() ) { Log::Error( "No file filter for file '%s'\n", assetFile->GetFilePath().c_str() ); return; } u64 fileTypeID = SelectIDByName( m_SelectFileTypeIDHandle, assetFile->GetFileFilter().c_str(), s_InsertFileTypeSQL, cancel ); if ( CheckCancelQuery( cancel ) ) { return; } #pragma TODO( "Figure out what to do about making paths relative to the asset root" ) std::string relativeFilePath = assetFile->GetPath().Get(); RCS::File rcsFile( assetFile->GetPath().Get() ); rcsFile.GetInfo(); SQL::SQLiteString insertSqlString( s_InsertAssetFileSQL, (i64) assetFile->GetPath().Hash(), relativeFilePath.c_str(), assetFile->GetShortName().c_str(), (i64) fileTypeID, (i64) 0, //p4UserID, (i64) 0, //assetTypeID, (i64) assetFile->GetSize(), (i64) rcsFile.m_LocalRevision ); SQL::SQLiteString updateSqlString( s_UpdateAssetFileSQL, relativeFilePath.c_str(), assetFile->GetShortName().c_str(), (i64) fileTypeID, (i64) 0, //p4UserID, (i64) 0, //assetTypeID, (i64) assetFile->GetSize(), (i64) rcsFile.m_LocalRevision, (i64) assetFile->GetPath().Hash() ); // insert the asset u64 rowID = SelectAssetRowID( assetFile->GetPath().Hash(), insertSqlString.GetString(), updateSqlString.GetString(), cancel ); assetFile->SetRowID( rowID ); InsertAssetAttributes( assetFile, cancel ); InsertAssetUsages( assetFile, assetFiles, visited, cancel ); if ( WildcardMatch( "entity.*", assetFile->GetPath().FullExtension().c_str() ) ) { InsertAssetShaders( assetFile, assetFiles, visited, cancel ); } else if ( WildcardMatch( "scene.*", assetFile->GetPath().FullExtension().c_str() ) ) { InsertLevelEntities( assetFile, assetFiles, visited, cancel ); } }