Spritesheet::Spritesheet(const Texture& in, int tw, int th, float cx, float cy) : tilesX(0) , tilesY(0) , tex(in) , meshes() { generateMeshes(tw, th, cx, cy); }
void BuiltinResources::preprocess(bool forceImport, time_t lastUpdateTime) { // Hidden dependency: Textures need to be generated before shaders as they may use the default textures generateTextures(); Path dataListsFilePath = mBuiltinRawDataFolder + DATA_LIST_JSON; SPtr<DataStream> dataListStream = FileSystem::openFile(dataListsFilePath); json dataListJSON = json::parse(dataListStream->getAsString().c_str()); json skinJSON = dataListJSON["Skin"]; json cursorsJSON = dataListJSON["Cursors"]; json iconsJSON = dataListJSON["Icons"]; json includesJSON = dataListJSON["Includes"]; json shadersJSON = dataListJSON["Shaders"]; Path rawSkinFolder = mBuiltinRawDataFolder + SKIN_FOLDER; Path rawCursorFolder = mBuiltinRawDataFolder + CURSOR_FOLDER; Path rawIconFolder = mBuiltinRawDataFolder + ICON_FOLDER; Path rawShaderFolder = mBuiltinRawDataFolder + SHADER_FOLDER; Path rawShaderIncludeFolder = mBuiltinRawDataFolder + SHADER_INCLUDE_FOLDER; // Update DataList.json if needed bool updatedDataLists = false; updatedDataLists |= BuiltinResourcesHelper::updateJSON( rawCursorFolder, BuiltinResourcesHelper::AssetType::Normal, cursorsJSON); updatedDataLists |= BuiltinResourcesHelper::updateJSON( rawIconFolder, BuiltinResourcesHelper::AssetType::Normal, iconsJSON); updatedDataLists |= BuiltinResourcesHelper::updateJSON( rawShaderIncludeFolder, BuiltinResourcesHelper::AssetType::Normal, includesJSON); updatedDataLists |= BuiltinResourcesHelper::updateJSON( rawShaderFolder, BuiltinResourcesHelper::AssetType::Normal, shadersJSON); updatedDataLists |= BuiltinResourcesHelper::updateJSON( rawSkinFolder, BuiltinResourcesHelper::AssetType::Sprite, skinJSON); dataListStream->close(); if(updatedDataLists) { FileSystem::remove(dataListsFilePath); dataListJSON["Skin"] = skinJSON; dataListJSON["Cursors"] = cursorsJSON; dataListJSON["Icons"] = iconsJSON; dataListJSON["Includes"] = includesJSON; dataListJSON["Shaders"] = shadersJSON; String jsonString = dataListJSON.dump(4).c_str(); dataListStream = FileSystem::createAndOpenFile(dataListsFilePath); dataListStream->writeString(jsonString); dataListStream->close(); } Path skinFolder = mBuiltinDataFolder + SKIN_FOLDER; Path iconFolder = mBuiltinDataFolder + ICON_FOLDER; Path shaderIncludeFolder = mBuiltinDataFolder + SHADER_INCLUDE_FOLDER; Path shaderDependenciesFile = mBuiltinDataFolder + "ShaderDependencies.json"; // If forcing import, clear all data folders since everything will be recreated anyway if(forceImport) { FileSystem::remove(mEngineCursorFolder); FileSystem::remove(iconFolder); FileSystem::remove(shaderIncludeFolder); FileSystem::remove(mEngineShaderFolder); FileSystem::remove(skinFolder); FileSystem::remove(shaderDependenciesFile); } // Read shader dependencies JSON json shaderDependenciesJSON; if(FileSystem::exists(shaderDependenciesFile)) { SPtr<DataStream> stream = FileSystem::openFile(shaderDependenciesFile); shaderDependenciesJSON = json::parse(stream->getAsString().c_str()); stream->close(); } // Import cursors { BuiltinResourcesHelper::updateManifest( mEngineCursorFolder, cursorsJSON, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal); Vector<bool> importFlags = BuiltinResourcesHelper::generateImportFlags( cursorsJSON, rawCursorFolder, lastUpdateTime, forceImport); BuiltinResourcesHelper::importAssets( cursorsJSON, importFlags, rawCursorFolder, mEngineCursorFolder, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal); } // Import icons { BuiltinResourcesHelper::updateManifest( iconFolder, iconsJSON, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal); Vector<bool> importFlags = BuiltinResourcesHelper::generateImportFlags( iconsJSON, rawIconFolder, lastUpdateTime, forceImport); BuiltinResourcesHelper::importAssets( iconsJSON, importFlags, rawIconFolder, iconFolder, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal); } // Import shaders { BuiltinResourcesHelper::updateManifest( shaderIncludeFolder, includesJSON, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal); BuiltinResourcesHelper::updateManifest( mEngineShaderFolder, shadersJSON, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal); Vector<bool> includeImportFlags = BuiltinResourcesHelper::generateImportFlags( includesJSON, rawShaderIncludeFolder, lastUpdateTime, forceImport); Vector<bool> shaderImportFlags = BuiltinResourcesHelper::generateImportFlags( shadersJSON, rawShaderFolder, lastUpdateTime, forceImport, &shaderDependenciesJSON, rawShaderIncludeFolder); // Hidden dependency: Includes must be imported before shaders, but import flags for shaders must be generated // before includes are imported, since the process checks if imports changed BuiltinResourcesHelper::importAssets( includesJSON, includeImportFlags, rawShaderIncludeFolder, shaderIncludeFolder, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal, nullptr, true); BuiltinResourcesHelper::importAssets( shadersJSON, shaderImportFlags, rawShaderFolder, mEngineShaderFolder, mResourceManifest, BuiltinResourcesHelper::AssetType::Normal, &shaderDependenciesJSON, true); } // Import GUI sprites { BuiltinResourcesHelper::updateManifest( skinFolder, skinJSON, mResourceManifest, BuiltinResourcesHelper::AssetType::Sprite); Vector<bool> skinImportFlags = BuiltinResourcesHelper::generateImportFlags( skinJSON, rawSkinFolder, lastUpdateTime, forceImport); BuiltinResourcesHelper::importAssets( skinJSON, skinImportFlags, rawSkinFolder, skinFolder, mResourceManifest, BuiltinResourcesHelper::AssetType::Sprite); } // Update shader dependencies JSON { String jsonString = shaderDependenciesJSON.dump(4).c_str(); dataListStream = FileSystem::createAndOpenFile(shaderDependenciesFile); dataListStream->writeString(jsonString); dataListStream->close(); } // Import font BuiltinResourcesHelper::importFont( mBuiltinRawDataFolder + DefaultFontFilename, DefaultFontFilename, mBuiltinDataFolder, { DefaultFontSize }, false, UUID("c9f08cab-f9c9-47c4-96e0-1066a8d4455b"), mResourceManifest); // Generate & save GUI skin { SPtr<GUISkin> skin = generateGUISkin(); Path outputPath = mBuiltinDataFolder + (GUISkinFile + u8".asset"); HResource skinResource = gResources()._createResourceHandle(skin, UUID("c1bf9a9d-4355-4841-a538-25e67730ec4b")); gResources().save(skinResource, outputPath, true); mResourceManifest->registerResource(skinResource.getUUID(), outputPath); } // Generate & save meshes generateMeshes(); Resources::instance().unloadAllUnused(); }