public TAsset GetByName(string name) { var instanceId = AssetHash.GetHash(name); // Find existing cached item. foreach (var assetScope in _assetScopes) { if (assetScope.Assets.TryGetValue(instanceId, out var result)) { return(result); } } // If we can, create new item and cache it. if (_loader != null) { var newValue = _loader.Load(name, _assetStore.LoadContext); _assetScopes.Peek().Assets.Add(instanceId, newValue); newValue.InternalId = _nextId; _byInternalId.Add(_nextId, newValue); _nextId++; _list.Add(newValue); return(newValue); } return(null); }
internal AssetStore( FileSystem fileSystem, string language, GraphicsDevice graphicsDevice, StandardGraphicsResources standardGraphicsResources, ShaderResourceManager shaderResources, OnDemandAssetLoadStrategy loadStrategy) { LoadContext = new AssetLoadContext( fileSystem, language, graphicsDevice, standardGraphicsResources, shaderResources, this); _scopedSingleAssetStorage = new List <IScopedSingleAssetStorage>(); _singleAssetStorageByTypeId = new Dictionary <uint, IScopedSingleAssetStorage>(); void AddSingleAssetStorage <TAsset>(ScopedSingleAsset <TAsset> assetStorage) where TAsset : BaseSingletonAsset, new() { _scopedSingleAssetStorage.Add(assetStorage); var typeId = AssetHash.GetHash(typeof(TAsset).Name); _singleAssetStorageByTypeId.Add(typeId, assetStorage); } AddSingleAssetStorage(AIData = new ScopedSingleAsset <AIData>()); AddSingleAssetStorage(AnimationSoundClientBehaviorGlobalSetting = new ScopedSingleAsset <AnimationSoundClientBehaviorGlobalSetting>()); AddSingleAssetStorage(AptButtonTooltipMap = new ScopedSingleAsset <AptButtonTooltipMap>()); AddSingleAssetStorage(ArmySummaryDescription = new ScopedSingleAsset <ArmySummaryDescription>()); AddSingleAssetStorage(AudioSettings = new ScopedSingleAsset <AudioSettings>()); AddSingleAssetStorage(AwardSystem = new ScopedSingleAsset <AwardSystem>()); AddSingleAssetStorage(BannerUI = new ScopedSingleAsset <BannerUI>()); AddSingleAssetStorage(ChallengeGenerals = new ScopedSingleAsset <ChallengeGenerals>()); AddSingleAssetStorage(CreateAHeroSystem = new ScopedSingleAsset <CreateAHeroSystem>()); AddSingleAssetStorage(Credits = new ScopedSingleAsset <Credits>()); AddSingleAssetStorage(DrawGroupInfo = new ScopedSingleAsset <DrawGroupInfo>()); AddSingleAssetStorage(Environment = new ScopedSingleAsset <Environment>()); AddSingleAssetStorage(Fire = new ScopedSingleAsset <Fire>()); AddSingleAssetStorage(FireLogicSystem = new ScopedSingleAsset <FireLogicSystem>()); AddSingleAssetStorage(FormationAssistant = new ScopedSingleAsset <FormationAssistant>()); AddSingleAssetStorage(GameData = new ScopedSingleAsset <GameData>()); AddSingleAssetStorage(InGameNotificationBox = new ScopedSingleAsset <InGameNotificationBox>()); AddSingleAssetStorage(InGameUI = new ScopedSingleAsset <InGameUI>()); AddSingleAssetStorage(Language = new ScopedSingleAsset <Language>()); AddSingleAssetStorage(LinearCampaign = new ScopedSingleAsset <LinearCampaign>()); AddSingleAssetStorage(LargeGroupAudioUnusedKnownKeys = new ScopedSingleAsset <LargeGroupAudioUnusedKnownKeys>()); AddSingleAssetStorage(LivingWorldMapInfo = new ScopedSingleAsset <LivingWorldMapInfo>()); AddSingleAssetStorage(LivingWorldAutoResolveResourceBonus = new ScopedSingleAsset <LivingWorldAutoResolveResourceBonus>()); AddSingleAssetStorage(LivingWorldAutoResolveSciencePurchasePointBonus = new ScopedSingleAsset <LivingWorldAutoResolveSciencePurchasePointBonus>()); AddSingleAssetStorage(MiscAudio = new ScopedSingleAsset <MiscAudio>()); AddSingleAssetStorage(MiscEvaData = new ScopedSingleAsset <MiscEvaData>()); AddSingleAssetStorage(MissionObjectiveList = new ScopedSingleAsset <MissionObjectiveList>()); AddSingleAssetStorage(MouseData = new ScopedSingleAsset <MouseData>()); AddSingleAssetStorage(MultiplayerSettings = new ScopedSingleAsset <MultiplayerSettings>()); AddSingleAssetStorage(OnlineChatColors = new ScopedSingleAsset <OnlineChatColors>()); AddSingleAssetStorage(Pathfinder = new ScopedSingleAsset <Pathfinder>()); AddSingleAssetStorage(StrategicHud = new ScopedSingleAsset <StrategicHud>()); AddSingleAssetStorage(WaterTransparency = new ScopedSingleAsset <WaterTransparency>()); AddSingleAssetStorage(Weather = new ScopedSingleAsset <Weather>()); _scopedAssetCollections = new List <IScopedAssetCollection>(); _byTypeId = new Dictionary <uint, IScopedAssetCollection>(); void AddAssetCollection <TAsset>(ScopedAssetCollection <TAsset> assetCollection) where TAsset : BaseAsset { _scopedAssetCollections.Add(assetCollection); var typeId = AssetHash.GetHash(typeof(TAsset).Name); _byTypeId.Add(typeId, assetCollection); } AddAssetCollection(AIBases = new ScopedAssetCollection <AIBase>(this)); AddAssetCollection(AIDozerAssignments = new ScopedAssetCollection <AIDozerAssignment>(this)); AddAssetCollection(AmbientStreams = new ScopedAssetCollection <AmbientStream>(this)); AddAssetCollection(Animations = new ScopedAssetCollection <Animation>(this)); AddAssetCollection(ArmorTemplates = new ScopedAssetCollection <ArmorTemplate>(this)); AddAssetCollection(ArmyDefinitions = new ScopedAssetCollection <ArmyDefinition>(this)); AddAssetCollection(AudioEvents = new ScopedAssetCollection <AudioEvent>(this)); AddAssetCollection(AudioFiles = new ScopedAssetCollection <AudioFile>(this, loadStrategy.CreateAudioFileLoader())); AddAssetCollection(AudioLods = new ScopedAssetCollection <AudioLod>(this)); AddAssetCollection(AutoResolveArmors = new ScopedAssetCollection <AutoResolveArmor>(this)); AddAssetCollection(AutoResolveBodies = new ScopedAssetCollection <AutoResolveBody>(this)); AddAssetCollection(AutoResolveCombatChains = new ScopedAssetCollection <AutoResolveCombatChain>(this)); AddAssetCollection(AutoResolveHandicapLevels = new ScopedAssetCollection <AutoResolveHandicapLevel>(this)); AddAssetCollection(AutoResolveLeaderships = new ScopedAssetCollection <AutoResolveLeadership>(this)); AddAssetCollection(AutoResolveReinforcementSchedules = new ScopedAssetCollection <AutoResolveReinforcementSchedule>(this)); AddAssetCollection(AutoResolveWeapons = new ScopedAssetCollection <AutoResolveWeapon>(this)); AddAssetCollection(BannerTypes = new ScopedAssetCollection <BannerType>(this)); AddAssetCollection(BenchProfiles = new ScopedAssetCollection <BenchProfile>(this)); AddAssetCollection(BridgeTemplates = new ScopedAssetCollection <BridgeTemplate>(this)); AddAssetCollection(CampaignTemplates = new ScopedAssetCollection <CampaignTemplate>(this)); AddAssetCollection(CommandButtons = new ScopedAssetCollection <CommandButton>(this)); AddAssetCollection(CommandMaps = new ScopedAssetCollection <CommandMap>(this)); AddAssetCollection(CommandSets = new ScopedAssetCollection <CommandSet>(this)); AddAssetCollection(ControlBarResizers = new ScopedAssetCollection <ControlBarResizer>(this)); AddAssetCollection(ControlBarSchemes = new ScopedAssetCollection <ControlBarScheme>(this)); AddAssetCollection(CrateDatas = new ScopedAssetCollection <CrateData>(this)); AddAssetCollection(CrowdResponses = new ScopedAssetCollection <CrowdResponse>(this)); AddAssetCollection(DamageFXs = new ScopedAssetCollection <DamageFX>(this)); AddAssetCollection(DialogEvents = new ScopedAssetCollection <DialogEvent>(this)); AddAssetCollection(DynamicGameLods = new ScopedAssetCollection <DynamicGameLod>(this)); AddAssetCollection(EmotionNuggets = new ScopedAssetCollection <EmotionNugget>(this)); AddAssetCollection(EvaEvents = new ScopedAssetCollection <EvaEvent>(this)); AddAssetCollection(ExperienceLevels = new ScopedAssetCollection <ExperienceLevel>(this)); AddAssetCollection(ExperienceScalarTables = new ScopedAssetCollection <ExperienceScalarTable>(this)); AddAssetCollection(FactionVictoryDatas = new ScopedAssetCollection <FactionVictoryData>(this)); AddAssetCollection(FontDefaultSettings = new ScopedAssetCollection <FontDefaultSetting>(this)); AddAssetCollection(FontSubstitutions = new ScopedAssetCollection <FontSubstitution>(this)); AddAssetCollection(FXLists = new ScopedAssetCollection <FXListData>(this)); AddAssetCollection(FXParticleSystemTemplates = new ScopedAssetCollection <FXParticleSystemTemplate>(this)); AddAssetCollection(GuiTextures = new ScopedAssetCollection <GuiTextureAsset>(this, loadStrategy.CreateGuiTextureLoader())); AddAssetCollection(HeaderTemplates = new ScopedAssetCollection <HeaderTemplate>(this)); AddAssetCollection(HouseColors = new ScopedAssetCollection <HouseColor>(this)); AddAssetCollection(LargeGroupAudioMaps = new ScopedAssetCollection <LargeGroupAudioMap>(this)); AddAssetCollection(LivingWorldAITemplates = new ScopedAssetCollection <LivingWorldAITemplate>(this)); AddAssetCollection(LivingWorldAnimObjects = new ScopedAssetCollection <LivingWorldAnimObject>(this)); AddAssetCollection(LivingWorldArmyIcons = new ScopedAssetCollection <LivingWorldArmyIcon>(this)); AddAssetCollection(LivingWorldBuildings = new ScopedAssetCollection <LivingWorldBuilding>(this)); AddAssetCollection(LivingWorldBuildingIcons = new ScopedAssetCollection <LivingWorldBuildingIcon>(this)); AddAssetCollection(LivingWorldBuildPlotIcons = new ScopedAssetCollection <LivingWorldBuildPlotIcon>(this)); AddAssetCollection(LivingWorldCampaigns = new ScopedAssetCollection <LivingWorldCampaign>(this)); AddAssetCollection(LivingWorldObjects = new ScopedAssetCollection <LivingWorldObject>(this)); AddAssetCollection(LivingWorldPlayerArmies = new ScopedAssetCollection <LivingWorldPlayerArmy>(this)); AddAssetCollection(LivingWorldPlayerTemplates = new ScopedAssetCollection <LivingWorldPlayerTemplate>(this)); AddAssetCollection(LivingWorldRegionCampaigns = new ScopedAssetCollection <LivingWorldRegionCampaign>(this)); AddAssetCollection(LivingWorldRegionEffects = new ScopedAssetCollection <LivingWorldRegionEffects>(this)); AddAssetCollection(LivingWorldSounds = new ScopedAssetCollection <LivingWorldSound>(this)); AddAssetCollection(LocomotorTemplates = new ScopedAssetCollection <LocomotorTemplate>(this)); AddAssetCollection(LodPresets = new ScopedAssetCollection <LodPreset>(this)); AddAssetCollection(MapCaches = new ScopedAssetCollection <MapCache>(this)); AddAssetCollection(MappedImages = new ScopedAssetCollection <MappedImage>(this)); AddAssetCollection(MeshNameMatches = new ScopedAssetCollection <MeshNameMatches>(this)); AddAssetCollection(Models = new ScopedAssetCollection <Model>(this, loadStrategy.CreateModelLoader())); AddAssetCollection(ModelAnimations = new ScopedAssetCollection <Graphics.Animation.W3DAnimation>(this, loadStrategy.CreateAnimationLoader())); AddAssetCollection(ModelBoneHierarchies = new ScopedAssetCollection <ModelBoneHierarchy>(this, loadStrategy.CreateModelBoneHierarchyLoader())); AddAssetCollection(ModelMeshes = new ScopedAssetCollection <ModelMesh>(this)); // TODO: ModelMesh loader? AddAssetCollection(ModifierLists = new ScopedAssetCollection <ModifierList>(this)); AddAssetCollection(MouseCursors = new ScopedAssetCollection <MouseCursor>(this)); AddAssetCollection(MultiplayerColors = new ScopedAssetCollection <MultiplayerColor>(this)); AddAssetCollection(MultiplayerStartingMoneyChoices = new ScopedAssetCollection <MultiplayerStartingMoneyChoice>(this)); AddAssetCollection(Multisounds = new ScopedAssetCollection <Multisound>(this)); AddAssetCollection(MusicTracks = new ScopedAssetCollection <MusicTrack>(this)); AddAssetCollection(ObjectCreationLists = new ScopedAssetCollection <ObjectCreationList>(this)); AddAssetCollection(ObjectDefinitions = new ScopedAssetCollection <ObjectDefinition>(this)); AddAssetCollection(PlayerAITypes = new ScopedAssetCollection <PlayerAIType>(this)); AddAssetCollection(PlayerTemplates = new ScopedAssetCollection <PlayerTemplate>(this)); AddAssetCollection(Ranks = new ScopedAssetCollection <Rank>(this)); AddAssetCollection(RegionCampaigns = new ScopedAssetCollection <RegionCampaign>(this)); AddAssetCollection(RoadTemplates = new ScopedAssetCollection <RoadTemplate>(this)); AddAssetCollection(Sciences = new ScopedAssetCollection <Science>(this)); AddAssetCollection(ScoredKillEvaAnnouncers = new ScopedAssetCollection <ScoredKillEvaAnnouncer>(this)); AddAssetCollection(ShellMenuSchemes = new ScopedAssetCollection <ShellMenuScheme>(this)); AddAssetCollection(SkirmishAIDatas = new ScopedAssetCollection <SkirmishAIData>(this)); AddAssetCollection(SkyboxTextureSets = new ScopedAssetCollection <SkyboxTextureSet>(this)); AddAssetCollection(SpecialPowers = new ScopedAssetCollection <SpecialPower>(this)); AddAssetCollection(StanceTemplates = new ScopedAssetCollection <StanceTemplate>(this)); AddAssetCollection(StaticGameLods = new ScopedAssetCollection <StaticGameLod>(this)); AddAssetCollection(StreamedSounds = new ScopedAssetCollection <StreamedSound>(this)); AddAssetCollection(Subsystems = new ScopedAssetCollection <LoadSubsystem>(this)); AddAssetCollection(TerrainTextures = new ScopedAssetCollection <TerrainTexture>(this)); AddAssetCollection(Textures = new ScopedAssetCollection <TextureAsset>(this, loadStrategy.CreateTextureLoader())); AddAssetCollection(Upgrades = new ScopedAssetCollection <UpgradeTemplate>(this)); AddAssetCollection(VictorySystemDatas = new ScopedAssetCollection <VictorySystemData>(this)); AddAssetCollection(Videos = new ScopedAssetCollection <Video>(this)); AddAssetCollection(WaterSets = new ScopedAssetCollection <WaterSet>(this)); AddAssetCollection(WaterTextureLists = new ScopedAssetCollection <WaterTextureList>(this)); AddAssetCollection(WeaponTemplates = new ScopedAssetCollection <WeaponTemplate>(this)); AddAssetCollection(WeatherDatas = new ScopedAssetCollection <WeatherData>(this)); AddAssetCollection(WindowTransitions = new ScopedAssetCollection <WindowTransition>(this)); }