private static void EnsureConfigurationSystem() { lock (s_initLock) { if (s_initState < InitState.Usable) { s_initState = InitState.Started; try { try { s_configSystem = new ClientConfigurationSystem(); s_initState = InitState.Usable; } catch (Exception exception) { s_initError = new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_client_config_init_error"), exception); throw s_initError; } } catch { s_initState = InitState.Completed; throw; } } } }
internal InitStateChangedEvent(InitState state, int errCode, string errMessage) { this._state = state; this._errCode = errCode; this._errMessage = errMessage; }
private static void EnsureConfigurationSystem() { // If a configuration system has not yet been set, // create the DefaultConfigurationSystem for exe's. lock (s_initLock) { if (s_initState < InitState.Usable) { s_initState = InitState.Started; try { try { // Create the system, but let it initialize itself // when GetConfig is called, so that it can handle its // own re-entrancy issues during initialization. // When initialization is complete, the DefaultConfigurationSystem // will call CompleteConfigInit to mark initialization as // having completed. // Note: the ClientConfigurationSystem has a 2-stage initialization, // and that's why s_initState isn't set to InitState.Completed yet. s_configSystem = new ClientConfigurationSystem(); s_initState = InitState.Usable; } catch (Exception e) { s_initError = new ConfigurationErrorsException(SR.GetString(SR.Config_client_config_init_error), e); throw s_initError; } } catch { s_initState = InitState.Completed; throw; } } } }
internal static void CompleteConfigInit() { lock (s_initLock) { s_initState = InitState.Completed; } }
// Called by ASP.NET to allow hierarchical configuration settings and ASP.NET specific extenstions. internal static void SetConfigurationSystem(IInternalConfigSystem configSystem, bool initComplete) { lock (s_initLock) { // It is an error if the configuration system has already been set. if (s_initState != InitState.NotStarted) throw new InvalidOperationException(SR.Config_system_already_set); s_configSystem = configSystem; s_initState = initComplete ? InitState.Completed : InitState.Usable; } }
internal static void Initialize() { lock (typeof(DiagnosticsConfiguration)) { if (initState != InitState.NotInitialized || ConfigurationSettings.SetConfigurationSystemInProgress) return; // Prevent recursion initState = InitState.Initializing; try { configTable = GetConfigTable(); } finally { initState = InitState.Initialized; } } }
private void Shutdown() { if (this.bodyInitState != InitState.Initialized) return; this.bodyInitState = InitState.Disposing; this.CleanupJoints(); this.CleanupBody(); this.GameObj.Transform.EventTransformChanged -= this.OnTransformChanged; this.ProcessCollisionEvents(); this.bodyInitState = InitState.Disposed; }
public WorldGenerationConsole() : base(80, 23) { // Create loading animation that looks like a sequence of / - \ | loadingAnimation = new AnimatedSurface("default", 1, 1); loadingAnimation.Frames.Clear(); var frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 92; frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 124; frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 47; frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 45; loadingAnimation.AnimationDuration = 1f; loadingAnimation.Repeat = true; messageData = new Console(80, 1); Children.Add(messageData); // Custom keyboard handler KeyboardHandler = (cons, info) => { if (info.IsKeyDown(Keys.Left)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left - 1, cons.TextSurface.RenderArea.Top, 80 * 2, 24 * 2); } if (info.IsKeyDown(Keys.Right)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left + 1, cons.TextSurface.RenderArea.Top, 80 * 2, 24 * 2); } if (info.IsKeyDown(Keys.Up)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left, cons.TextSurface.RenderArea.Top - 1, 80 * 2, 24 * 2); } if (info.IsKeyDown(Keys.Down)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left, cons.TextSurface.RenderArea.Top + 1, 80 * 2, 24 * 2); } if (info.IsKeyReleased(Keys.Enter)) { state = InitState.BeforeGeneration; } if (info.IsKeyReleased(Keys.Space)) { var oldRenderArea = cons.TextSurface.RenderArea; var oldFont = cons.TextSurface.Font; if (textSurface == generator.HeightMapRenderer) { textSurface = generator.HeatMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Heat"); } else if (textSurface == generator.HeatMapRenderer) { textSurface = generator.MoistureMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Moisture"); } else if (textSurface == generator.MoistureMapRenderer) { textSurface = generator.BiomeMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Biome "); } else { textSurface = generator.HeightMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Height "); } cons.TextSurface.RenderArea = oldRenderArea; cons.TextSurface.Font = oldFont; } return(true); }; }
static ConfigurationManager() { s_initState = InitState.NotStarted; s_initLock = new object(); }
AppController() { CurrentState = new InitState(); }
AppController () { CurrentState = new InitState (); }
private static void EnsureConfigurationSystem(SqlConfigurationData data) { lock (SqlConfigurationManager.initLock) { if (SqlConfigurationManager.initState >= SqlConfigurationManager.InitState.Usable) { return; } SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Started; try { try { SqlConfigurationManager.configSystem = new SqlConfigurationSystem(data); SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Usable; } catch (Exception exception1) { throw new ConfigurationErrorsException(Properties.Resources.ExceptionConfigurationInitialization, exception1); } } catch { SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Completed; throw; } } }
/**********************************************************************/ // Initialize Managers in order, layer by layer IEnumerator InitLayers() { // Go through the layers int layerNum = 1; foreach (ManagerInitLayer layer in m_managerInitLayers) { Debug.Log("Initializing Managers Layer " + layerNum + ": " + layer.LayerName); List <ManagerBase> workMgr = new List <ManagerBase>(); // List of Managers currently initializing // Instantiate GameObjects from Manager prefabs and Initialize foreach (ManagerBase mgr in layer.m_mgrs) { ManagerBase newMgr = mgr.gameObject.GetComponent <ManagerBase>(); if (newMgr != null) { workMgr.Add(newMgr); AddManagerToCache(newMgr); newMgr.InitState = InitState.Initializing; StartCoroutine(newMgr.RunInitialization()); } else { Debug.LogError("ManagerLocator.InitLayers: Unable to Init Manager due to missing ManagerBase component - " + mgr.name); } } // Wait for all Managers on this layer to finish bool layerFinished = false; while (!layerFinished) { layerFinished = true; foreach (ManagerBase mgr in workMgr) { if (mgr.InitState == InitState.Failed) { InitState = InitState.Failed; break; } if (mgr.InitState != InitState.Initialized) { layerFinished = false; break; } } yield return(null); } Debug.Log("ManagerInitLayer: Layer " + layerNum + " Finished"); if (InitState == InitState.Failed) { // Initialization has failed. RunInitializationFail(); yield break; } layerNum++; } _initComplete = true; }
private Module FindInjectableModule(Type type, InitState state, bool force) => modules.FirstOrDefault( x => (x.Status == InitState.Done || x.Status == InitState.SetOnly && state == InitState.SetOnly || force) && type.IsAssignableFrom(x.Type));
private void GotoState(InitState state) { _state = state; switch (state) { case InitState.Running: StartCommand.IsEnabled = false; StartExCommand.IsEnabled = false; StopCommand.IsEnabled = true; StopExCommand.IsEnabled = true; PauseCommand.IsEnabled = true; ResumeCommand.IsEnabled = false; StartCmdVisibility = Visibility.Hidden; StopCmdVisibility = Visibility.Visible; PauseCmdVisibility = Visibility.Visible; ResumeCmdVisibility = Visibility.Hidden; IsUsernameEnabled = false; IsCombosEnabled = false; FeedbackColor = _black; FeedbackText = string.Format("Restarting..."); _timer.Enabled = true; _timer_Elapsed(this, null); IsAbmeldenVisible = Visibility.Hidden; break; case InitState.NotRunningLogged: StartCommand.IsEnabled = true; StartExCommand.IsEnabled = true; StopCommand.IsEnabled = false; StopExCommand.IsEnabled = false; PauseCommand.IsEnabled = false; ResumeCommand.IsEnabled = false; StartCmdVisibility = Visibility.Visible; StopCmdVisibility = Visibility.Hidden; PauseCmdVisibility = Visibility.Hidden; ResumeCmdVisibility = Visibility.Hidden; IsUsernameEnabled = true; IsCombosEnabled = true; FeedbackColor = _red; IsAbmeldenVisible = Visibility.Visible; _timer.Enabled = false; break; case InitState.NotRunningNotLogged: StartCommand.IsEnabled = false; StartExCommand.IsEnabled = false; StopCommand.IsEnabled = false; StopExCommand.IsEnabled = false; PauseCommand.IsEnabled = false; ResumeCommand.IsEnabled = false; StartCmdVisibility = Visibility.Hidden; StopCmdVisibility = Visibility.Hidden; PauseCmdVisibility = Visibility.Hidden; ResumeCmdVisibility = Visibility.Hidden; IsUsernameEnabled = true; IsCombosEnabled = false; FeedbackText = ""; FeedbackColor = _red; IsAbmeldenVisible = Visibility.Hidden; _timer.Enabled = false; SelectedProjekt = null; SelectedLohnkategorie = null; SelectedTarifkategorie = null; Text = null; break; case InitState.Paused: StartCommand.IsEnabled = false; StartExCommand.IsEnabled = false; StopCommand.IsEnabled = true; StopExCommand.IsEnabled = true; PauseCommand.IsEnabled = false; ResumeCommand.IsEnabled = true; StartCmdVisibility = Visibility.Hidden; StopCmdVisibility = Visibility.Visible; PauseCmdVisibility = Visibility.Hidden; ResumeCmdVisibility = Visibility.Visible; IsUsernameEnabled = true; IsCombosEnabled = false; FeedbackColor = _red; IsAbmeldenVisible = Visibility.Hidden; _timer.Enabled = false; //SelectedProjekt = null; //SelectedLohnkategorie = null; //SelectedTarifkategorie = null; //Text = null; _timer_Elapsed(null, null); break; } RaisePropertyChanged("UserData"); }
public void LoadContent(InitState state) { spriteBatch = CoreGlobals.SpriteBatch; font = CoreGlobals.GameFont; using (var stream = File.OpenRead(FileSystem.RootPath + BrickbreakerMod.Path + "BrickBreakerTP.png")) SpriteSheet = Texture2D.FromStream(CoreGlobals.GraphicsDevice, stream); //24x16 images SourceRect = new AnimationFrame[15]; SourceRect[(int)PowerUp.PowerUpType.WIDE_PADDLE] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(0, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.STICKY_BALL] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(24, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.BIG_BALL] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(48, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.HEAVY_BALL] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(72, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.TRIPLE_BALLS] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(96, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.RESET_SPEED] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(120, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.BULLETS] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(144, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.EXTRA_LIFE] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(168, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.SLOW_BALL] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(192, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.NARROW_PADDLE] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(216, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.INVERT_CONTROLS] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(240, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.RANDOM_BOUNCE] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(264, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.INCREASE_SPEED] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(288, 0, 24, 16) } }; SourceRect[(int)PowerUp.PowerUpType.CURVE_BALL] = new AnimationFrame() { Rect = new Rectangle[] { new Rectangle(312, 0, 24, 16) } }; //8x8 image ballSprite = new Rectangle(336, 0, 8, 8); }
/// <summary> /// /// </summary> static SqlConfigurationManager() { SqlConfigurationManager.initState = SqlConfigurationManager.InitState.NotStarted; SqlConfigurationManager.initLock = new object(); }
/// <summary> /// Updates the initialization process. /// </summary> private void UpdateInitState() { switch (m_initState) { case InitState.NONE: AdvanceInitState(); break; case InitState.INIT_SHARED_SYSTEMS: // Get references to the shared systems m_uiSystem = this.gameObject.AddDerivedIfNoBase <UISystemBase, UISystem>(); m_soundSystem = this.gameObject.AddDerivedIfNoBase <SoundSystemBase, SoundSystem>(); m_dataSystem = new DataSystem(); // Initialize shared systems m_uiSystem.Initialize(); m_soundSystem.Initialize(); m_dataSystem.Initialize(); #if SHOW_STATE_LOGS Debug.Log("Initializing shared systems..."); #endif AdvanceInitState(); break; case InitState.WAIT_INIT_SHARED_SYSTEMS: // Wait for shared systems to finish initialization #if SHOW_STATE_LOGS Debug.Log("Waiting for shared system initialization to finish..."); #endif if (m_uiSystem.IsInitialized && m_soundSystem.IsInitialized && m_dataSystem.IsInitialized) { AdvanceInitState(); } break; // TODO: Temporary state - should be moved to different classes case InitState.CREATE_SHARED_OBJECTS: #if SHOW_STATE_LOGS Debug.Log("Creating shared objects..."); #endif CreateSharedObjects(); AdvanceInitState(); break; case InitState.INIT_LOCATOR: #if SHOW_STATE_LOGS Debug.Log("Initializing Service Locator..."); #endif Locator.ProvideUISystem(m_uiSystem); Locator.ProvideSoundSystem(m_soundSystem); Locator.ProvideDataSystem(m_dataSystem); // If game is loaded from the Main scene (index 0) if (Application.loadedLevel == 0) { AdvanceInitState(); } // If game is loaded from a different scene else { // No need to load a different scene // Just load the SceneMaster m_initState = InitState.LOAD_SCENE_MASTER; } break; // The following states are cycled through whenever scenes are switched case InitState.LOAD_SCENE: #if SHOW_STATE_LOGS Debug.Log("Loading scene..."); #endif // Block input while next scene is loading m_faderUI.SetBlockInput(); StartLoading(m_sceneInfo.GetSceneNameOf(m_nextScene)); AdvanceInitState(); break; case InitState.WAIT_LOAD_SCENE: // Wait for scene to finish loading in the background #if SHOW_STATE_LOGS Debug.Log("Waiting for scene to load in the background..."); #endif if (m_async != null && m_async.progress >= READY_TO_LOAD_PROGRESS) { // Start fade out if (m_enableFadeAnim) { m_faderUI.FadeOut(true); } AdvanceInitState(); } break; case InitState.UNLOAD_CUR_SCENE: // If starting from Main scene, there will be nothing to unload #if SHOW_STATE_LOGS Debug.Log("Unloading current scene..."); #endif if (Application.loadedLevel == 0 || m_sceneMaster.Unload()) { AdvanceInitState(); } break; case InitState.WAIT_UNLOAD_CUR_SCENE: // If starting from Main scene, there will be nothing to unload #if SHOW_STATE_LOGS Debug.Log("Waiting for current scene to finish unloading..."); #endif if (Application.loadedLevel == 0 || !m_sceneMaster.IsInitialized) { // If scene fading is enabled, wait for scene to fade out first if (!m_enableFadeAnim || (m_enableFadeAnim && m_faderUI.FaderState == FaderUI.FadeAnimationState.FADED_OUT)) { // Clean up non-persistent sounds m_soundSystem.DeleteAllSoundObjects(false); AdvanceInitState(); } } break; case InitState.SWITCH_SCENE: // Load the next scene #if SHOW_STATE_LOGS Debug.Log("Switching scene..."); #endif ActivateScene(); // Initialization will continue in OnLevelWasLoaded break; case InitState.LOAD_SCENE_MASTER: #if SHOW_STATE_LOGS Debug.Log("Loading scene master in scene " + Application.loadedLevelName); #endif if (m_sceneMaster.Load()) { // Provide SceneMaster to the service locator Locator.ProvideSceneMaster(m_sceneMaster); AdvanceInitState(); } break; case InitState.WAIT_LOAD_SCENE_MASTER: #if SHOW_STATE_LOGS Debug.Log("Waiting for scene master to load..."); #endif if (m_sceneMaster.IsInitialized) { // Start fade in if (m_enableFadeAnim) { m_faderUI.FadeIn(); } AdvanceInitState(); } break; case InitState.DONE: #if SHOW_STATE_LOGS if (BuildInfo.IsDebugMode) { Debug.Log("Main initialization complete"); } #endif // Switch to IDLE state // If the SceneMaster switches the scene, this state change will be overridden AdvanceInitState(); // Update scene enum for the current scene m_curScene = m_nextScene; // Start the scene - pass control over to the active scene master m_sceneMaster.StartScene(); break; case InitState.IDLE: break; } }
internal static void CompleteConfigInit() { lock (SqlConfigurationManager.initLock) { SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Completed; } }
/// <summary> /// Returns whether the current <see cref="InitState"/> can be considered active. This is true /// after initialization and during disposal. /// </summary> /// <param name="state"></param> /// <returns></returns> public static bool IsActive(this InitState state) { return(state == InitState.Initialized || state == InitState.Disposing); }
internal static void Refresh() { ConfigurationManager.RefreshSection("system.diagnostics"); // There might still be some persistant state left behind for // ConfigPropertyCollection (for ex, swtichelements), probably for perf. // We need to explicitly cleanup any unrecognized attributes that we // have added during last deserialization, so that they are re-added // during the next Config.GetSection properly and we get a chance to // populate the Attributes collection for re-deserialization. // Another alternative could be to expose the properties collection // directly as Attributes collection (currently we keep a local // hashtable which we explicitly need to keep in sycn and hence the // cleanup logic below) but the down side of that would be we need to // explicitly compute what is recognized Vs unrecognized from that // collection when we expose the unrecognized Attributes publically SystemDiagnosticsSection configSectionSav = configSection; if (configSectionSav != null) { if (configSectionSav.Switches != null) { foreach (SwitchElement swelem in configSectionSav.Switches) swelem.ResetProperties(); } if (configSectionSav.SharedListeners != null) { foreach (ListenerElement lnelem in configSectionSav.SharedListeners) lnelem.ResetProperties(); } if (configSectionSav.Sources != null) { foreach (SourceElement srelem in configSectionSav.Sources) srelem.ResetProperties(); } } configSection = null; initState = InitState.NotInitialized; Initialize(); }
/// <summary> /// Generates the noise table which may be used by materials. /// /// Since this is time-intensive, it is recommended that this method be run in a /// non-GUI thread during a loading screen or during startup. /// </summary> /// <param name="device">The device which will be used to render textures.</param> public static void LoadContent(GraphicsDevice device, ContentManager contentManager) { initialized = InitState.InProgress; graphicsDevice = device; spriteBatch = new SpriteBatch(graphicsDevice); content = contentManager; edgeExpand = content.Load<Effect>("GalacTexContent/EdgeExpand"); // Generate noise volume which may be used by instances GenerateNoiseTexture(NOISE_TEXTURE_RESOLUTION, NOISE_PERIOD); initialized = InitState.Initialized; if (ContentLoaded != null) { ContentLoaded(); } }
public static int InitTaskMethod(object obj) { Memory.Log.WriteLine($"{nameof(Memory)} :: {nameof(Memory)} :: {nameof(Init)}"); CancellationToken token = (CancellationToken)obj; if (!token.IsCancellationRequested) { Memory.Strings = new Strings(); } // requires strings because it uses an array generated in strings. // saves data will reference kernel_bin. if (!token.IsCancellationRequested) { Kernel_Bin = new Kernel_bin(); } List <Task> tasks = new List <Task>(); if (!token.IsCancellationRequested) { // this has a soft requirement on kernel_bin. It checks for null so should work without it. tasks.Add(Task.Run(() => { MItems = Items_In_Menu.Read(); }, token)); //loads all savegames from steam2013 or cd2000 or steam2019 directories. first come first serve. //TODO allow chosing of which save folder to use. tasks.Add(Task.Run(Saves.Init, token)); //tasks.Add(Task.Run(() => InitState = Saves.Data.LoadInitOut(), token)); tasks.Add(Task.Run(InitStrings, token)); //this initializes the field module, it's worth to have this at the beginning tasks.Add(Task.Run(Fields.Initializer.Init, token)); //this initializes the encounters tasks.Add(Task.Run(Init_debugger_battle.Init)); if (graphics?.GraphicsDevice != null) // all below require graphics to work. to load textures graphics device needed. { //this initializes the fonts and drawing system- holds fonts in-memory tasks.Add(Task.Run(() => { font = new Font(); }, token)); // card images in menu. tasks.Add(Task.Run(() => { Cards = Cards.Load(); }, token)); tasks.Add(Task.Run(() => { Card_Game = new Card.Game(); }, token)); tasks.Add(Task.Run(() => { Faces = Faces.Load(); }, token)); tasks.Add(Task.Run(() => { Icons = Icons.Load(); }, token)); tasks.Add(Task.Run(() => { Magazines = Magazine.Load(); }, token)); } Task.WaitAll(tasks.ToArray()); InitState = Saves.Data.LoadInitOut(); State = InitState?.Clone(); if (graphics?.GraphicsDevice != null) // all below require graphics to work. to load textures graphics device needed. { //// requires font, faces, and icons. currently cards only used in debug menu. will //// have support for cards when added to menu. //if (!token.IsCancellationRequested) // Menu.Module.Init(); // requires font, faces, and icons. currently cards only used in debug menu. will // have support for cards when added to menu. if (!token.IsCancellationRequested) { Menu.InitStaticMembers(); } } } //EXE_Offsets test = new EXE_Offsets(); Inited = true; return(0); }
public static bool EnsureInitialized() { // Only initialize once. // If we are initialized, all is good. if (InitState.Initialized == (InitState)s_inilializationState) { return(true); } // Not initialized. Start trying to initialize. while (true) { // IF we were NotInitialized, then switch to Initializing: InitState prevInitState = (InitState)Interlocked.CompareExchange( ref s_inilializationState, (int)InitState.Initializing, (int)InitState.NotInitialized); // We were in an Error state. We are still in Error state now. => Give up. if (prevInitState == InitState.Error) { return(false); } // We were in Initialized state. We are still in Initialized state. => Success. if (prevInitState == InitState.Initialized) { return(true); } if (prevInitState == InitState.Initializing) { // We were in Initializing state. // This means that another thread is currently initializing the loader. // We will perform a short blocking wait and then look again by repeating the loop. // Such a small delay is OK. It tends to only happen early on (before initialization is complete) and rare. Thread.Sleep(10); } else if (prevInitState == InitState.NotInitialized) { // We were in NotInitialized state. That means we won the race and changed state to Initializing. // Exit the loop and proceed with the initialization work. break; } else { throw new InvalidOperationException($"Unexpected inilialization state. {nameof(DynamicLoader)}.{s_inilializationState} = {prevInitState}"); } } // We exited the above loop to here. That means that we won the race and changed state to Initializing. // Let's initialize. try { Log.Info(LogComponentMoniker, $"Started initializing {nameof(DynamicLoader)}.", "Environment.Version", Environment.Version, "BCL Assembly Name", typeof(object).Assembly.FullName, "CurrentAppDomain.Id", AppDomain.CurrentDomain.Id, "CurrentAppDomain.FriendlyName", AppDomain.CurrentDomain.FriendlyName, "CurrentAppDomain.IsDefault", AppDomain.CurrentDomain.IsDefaultAppDomain()); AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoadEventHandler; SetupDynamicInvokers(); Log.Info(LogComponentMoniker, $"Completed initializing {nameof(DynamicLoader)}."); Interlocked.Exchange(ref s_inilializationState, (int)InitState.Initialized); return(true); } catch (Exception ex) { Log.Error(LogComponentMoniker, $"Error initializing {nameof(DynamicLoader)}.", ex); DynamicInvoker.Current = null; Interlocked.Exchange(ref s_inilializationState, (int)InitState.Error); return(false); } }
protected virtual void OnFixedUpdate(float timeMult) { if (nextLevelInit.HasValue) { bool playersReady = true; foreach (Player player in players) { // Exit type is already provided playersReady &= player.OnLevelChanging(ExitType.None); } if (playersReady) { if (levelChangeTimer > 0) { levelChangeTimer -= timeMult; } else { root.ChangeLevel(nextLevelInit.Value); nextLevelInit = null; initState = InitState.Disposed; return; } } } if (difficulty != GameDifficulty.Multiplayer) { if (players.Count > 0) { Vector3 pos = players[0].Transform.Pos; int tx1 = (int)pos.X >> 5; int ty1 = (int)pos.Y >> 5; int tx2 = tx1; int ty2 = ty1; #if ENABLE_SPLITSCREEN for (int i = 1; i < players.Count; i++) { Vector3 pos2 = players[i].Transform.Pos; int tx = (int)pos2.X >> 5; int ty = (int)pos2.Y >> 5; if (tx1 > tx) { tx1 = tx; } else if (tx2 < tx) { tx2 = tx; } if (ty1 > ty) { ty1 = ty; } else if (ty2 < ty) { ty2 = ty; } } #endif // ToDo: Remove this branching #if PLATFORM_ANDROID const int ActivateTileRange = 20; #else const int ActivateTileRange = 26; #endif tx1 -= ActivateTileRange; ty1 -= ActivateTileRange; tx2 += ActivateTileRange; ty2 += ActivateTileRange; for (int i = 0; i < actors.Count; i++) { if (actors[i].OnTileDeactivate(tx1 - 2, ty1 - 2, tx2 + 2, ty2 + 2)) { i--; } } eventMap.ActivateEvents(tx1, ty1, tx2, ty2, initState != InitState.Initializing); } eventMap.ProcessGenerators(timeMult); } ResolveCollisions(); // Ambient Light Transition if (ambientLightCurrent != ambientLightTarget) { float step = timeMult * 0.012f; if (MathF.Abs(ambientLightCurrent - ambientLightTarget) < step) { ambientLightCurrent = ambientLightTarget; } else { ambientLightCurrent += step * ((ambientLightTarget < ambientLightCurrent) ? -1 : 1); } } // Weather if (weatherType != WeatherType.None && commonResources.Graphics != null) { // ToDo: Apply weather effect to all other cameras too Vector3 viewPos = cameras[0].Transform.Pos; for (int i = 0; i < weatherIntensity; i++) { TileMap.DebrisCollisionAction collisionAction; if (weatherOutdoors) { collisionAction = TileMap.DebrisCollisionAction.Disappear; } else { collisionAction = (MathF.Rnd.NextFloat() > 0.7f ? TileMap.DebrisCollisionAction.None : TileMap.DebrisCollisionAction.Disappear); } Vector3 debrisPos = viewPos + MathF.Rnd.NextVector3((LevelRenderSetup.TargetSize.X / -2) - 40, (LevelRenderSetup.TargetSize.Y * -2 / 3), MainPlaneZ, LevelRenderSetup.TargetSize.X + 120, LevelRenderSetup.TargetSize.Y, 0); if (weatherType == WeatherType.Rain) { GraphicResource res = commonResources.Graphics["Rain"]; Material material = res.Material.Res; Texture texture = material.MainTexture.Res; float scale = MathF.Rnd.NextFloat(0.4f, 1.1f); float speedX = MathF.Rnd.NextFloat(2.2f, 2.7f) * scale; float speedY = MathF.Rnd.NextFloat(7.6f, 8.6f) * scale; debrisPos.Z = MainPlaneZ * scale; tileMap.CreateDebris(new TileMap.DestructibleDebris { Pos = debrisPos, Size = res.Base.FrameDimensions, Speed = new Vector2(speedX, speedY), Scale = scale, Angle = MathF.Atan2(speedY, speedX), Alpha = 1f, Time = 180f, Material = material, MaterialOffset = texture.LookupAtlas(res.FrameOffset + MathF.Rnd.Next(res.FrameCount)), CollisionAction = collisionAction }); } else { GraphicResource res = commonResources.Graphics["Snow"]; Material material = res.Material.Res; Texture texture = material.MainTexture.Res; float scale = MathF.Rnd.NextFloat(0.4f, 1.1f); float speedX = MathF.Rnd.NextFloat(-1.6f, -1.2f) * scale; float speedY = MathF.Rnd.NextFloat(3f, 4f) * scale; float accel = MathF.Rnd.NextFloat(-0.008f, 0.008f) * scale; debrisPos.Z = MainPlaneZ * scale; tileMap.CreateDebris(new TileMap.DestructibleDebris { Pos = debrisPos, Size = res.Base.FrameDimensions, Speed = new Vector2(speedX, speedY), Acceleration = new Vector2(accel, -MathF.Abs(accel)), Scale = scale, Angle = MathF.Rnd.NextFloat() * MathF.TwoPi, AngleSpeed = speedX * 0.02f, Alpha = 1f, Time = 180f, Material = material, MaterialOffset = texture.LookupAtlas(res.FrameOffset + MathF.Rnd.Next(res.FrameCount)), CollisionAction = collisionAction }); } } } // Active Boss if (activeBoss != null && activeBoss.Scene == null) { activeBoss = null; Hud hud = rootObject.GetComponent <Hud>(); if (hud != null) { hud.ActiveBoss = null; } InitLevelChange(ExitType.Normal, null); } if (initState == InitState.Initializing) { initState = InitState.Initialized; } collisionsCountA = 0; collisionsCountB = 0; collisionsCountC = 0; }
/// <summary> /// Unloads all static assets. /// </summary> public static void Unload() { noiseTexture.Dispose(); graphicsDevice = null; spriteBatch.Dispose(); initialized = InitState.NotInitialized; }
/// <summary> /// Updates the initialization process. /// </summary> private void UpdateInitState() { switch (m_initState) { case InitState.NONE: AdvanceInitState(); break; case InitState.INIT_SHARED_SYSTEMS: #if SHOW_STATE_LOGS Debug.Log("Initializing shared systems..."); #endif // Find or create containers for shared MonoBehaviour systems GameObject uiManagerObj = GameObject.Find(UI_MANAGER_OBJ_NAME); if (uiManagerObj == null) { uiManagerObj = new GameObject(UI_MANAGER_OBJ_NAME); } GameObject soundManagerObj = GameObject.Find(SOUND_MANAGER_OBJ_NAME); if (soundManagerObj == null) { soundManagerObj = new GameObject(SOUND_MANAGER_OBJ_NAME); } // Create and store references to shared systems m_uiManager = uiManagerObj.AddComponentNoDupe <UIManager>(); m_soundManager = soundManagerObj.AddComponentNoDupe <SoundManager>(); m_dataSystem = new SoomlaDataSystem(); m_notifSystem = new NotificationSystem(); m_playServicesSystem = new PlayServicesSystem(); // Shared systems are not destroyed on scene switches DontDestroyOnLoad(uiManagerObj); DontDestroyOnLoad(soundManagerObj); // Initialize shared systems m_uiManager.Initialize(); m_soundManager.Initialize(); m_dataSystem.Initialize(); m_playServicesSystem.Initialize(m_enableSavedGames); m_notifSystem.Initialize(m_enablePushNotifs); // Add FPSDisplay component m_fpsDisplay = this.gameObject.AddComponentNoDupe <FPSDisplay>(); AdvanceInitState(); break; case InitState.WAIT_INIT_SHARED_SYSTEMS: #if SHOW_STATE_LOGS Debug.Log("Waiting for shared system initialization to finish..."); #endif // Wait for shared systems to finish initialization if (m_uiManager.IsInitialized && m_soundManager.IsInitialized && m_dataSystem.IsInitialized && m_playServicesSystem.IsInitialized && m_notifSystem.IsInitialized) { AdvanceInitState(); } break; case InitState.INIT_LOCATOR: #if SHOW_STATE_LOGS Debug.Log("Initializing Service Locator..."); #endif Locator.ProvideUIManager(m_uiManager); Locator.ProvideSoundManager(m_soundManager); Locator.ProvideDataSystem(m_dataSystem); Locator.ProvidePlayServicesSystem(m_playServicesSystem); Locator.ProvideNotifSystem(m_notifSystem); // If game is loaded from the Main scene (index 0) if (Application.loadedLevel == 0) { AdvanceInitState(); } // If game is loaded from a different scene else { // No need to load a different scene // Just load the SceneMaster m_initState = InitState.LOAD_SCENE_MASTER; } break; // The following states are cycled through whenever scenes are switched case InitState.LOAD_SCENE: #if SHOW_STATE_LOGS Debug.Log("Loading scene..."); #endif // Block input while next scene is loading m_uiManager.SetBlockInput(); StartLoading(m_sceneInfo.GetSceneNameOf(m_nextScene)); AdvanceInitState(); break; case InitState.WAIT_LOAD_SCENE: // Wait for scene to finish loading in the background #if SHOW_STATE_LOGS Debug.Log("Waiting for scene to load in the background..."); #endif if (m_async != null && m_async.progress >= READY_TO_LOAD_PROGRESS) { // Start fade out if (m_enableFadeAnim) { // There is nothing to fade out if starting from Main scene if (Application.loadedLevel != 0) { m_uiManager.StartFadeOut(true); } } AdvanceInitState(); } break; case InitState.UNLOAD_CUR_SCENE: #if SHOW_STATE_LOGS Debug.Log("Unloading current scene..."); #endif // If starting from Main scene, there will be nothing to unload if (Application.loadedLevel == 0 || m_sceneMaster.Unload()) { AdvanceInitState(); } break; case InitState.WAIT_UNLOAD_CUR_SCENE: #if SHOW_STATE_LOGS Debug.Log("Waiting for current scene to finish unloading..."); #endif // If starting from Main scene, there will be nothing to unload if (Application.loadedLevel == 0 || !m_sceneMaster.IsInitialized) { // If scene fading is enabled, wait for scene to fade out first if (!m_enableFadeAnim || (m_enableFadeAnim && m_uiManager.IsFadedOut())) { // Clean up non-persistent sounds m_soundManager.DeleteAllSoundObjects(false); AdvanceInitState(); } } break; case InitState.SWITCH_SCENE: // Load the next scene #if SHOW_STATE_LOGS Debug.Log("Switching scene..."); #endif ActivateScene(); // Initialization will continue in OnLevelWasLoaded break; case InitState.LOAD_SCENE_MASTER: #if SHOW_STATE_LOGS Debug.Log("Loading scene master in scene " + Application.loadedLevelName); #endif if (m_sceneMaster.Load()) { // Provide SceneMaster to the service locator Locator.ProvideSceneMaster(m_sceneMaster); AdvanceInitState(); } break; case InitState.WAIT_LOAD_SCENE_MASTER: #if SHOW_STATE_LOGS Debug.Log("Waiting for scene master to load..."); #endif if (m_sceneMaster.IsInitialized) { // Start fade in if (m_enableFadeAnim) { m_uiManager.StartFadeIn(); } // Fire the SceneInitialized event if (sceneInitializedInvoker != null) { sceneInitializedInvoker(this, new System.EventArgs()); } AdvanceInitState(); } break; case InitState.DONE: #if SHOW_STATE_LOGS if (BuildInfo.IsDebugMode) { Debug.Log("Main initialization complete"); } #endif // Switch to IDLE state // If the SceneMaster switches the scene, this state change will be overridden AdvanceInitState(); // Keep track of previous scene m_prevScene = m_curScene; // Update scene enum for the current scene m_curScene = m_nextScene; // Start the scene - pass control over to the active scene master m_sceneMaster.StartScene(); break; case InitState.IDLE: break; } }
public void SetState(NPC_EnemyState newState) { if (currentState != newState) { if (_endState != null) { _endState(); } switch (newState) { case NPC_EnemyState.IDLE_STATIC: _initState = StateInit_IdleStatic; _updateState = StateUpdate_IdleStatic; _endState = StateEnd_IdleStatic; break; case NPC_EnemyState.IDLE_ROAMER: _initState = StateInit_IdleRoamer; _updateState = StateUpdate_IdleRoamer; _endState = StateEnd_IdleRoamer; break; case NPC_EnemyState.IDLE_PATROL: _initState = StateInit_IdlePatrol; _updateState = StateUpdate_IdlePatrol; _endState = StateEnd_IdlePatrol; break; case NPC_EnemyState.INSPECT: _initState = StateInit_Inspect; _updateState = StateUpdate_Inspect; _endState = StateEnd_Inspect; break; case NPC_EnemyState.ATTACK: _initState = StateInit_Attack; _updateState = StateUpdate_Attack; _endState = StateEnd_Attack; break; } _initState(); currentState = newState; } }
public void LoadContent(InitState state) { spriteBatch = CoreGlobals.SpriteBatch; font = CoreGlobals.Content.Load <SpriteFont>(@"Fonts\Arcade"); }
// Mark intiailization as having completed. internal static void CompleteConfigInit() { lock (s_initLock) { s_initState = InitState.Completed; } }
internal static void SetConfigurationSystem(IInternalConfigSystem configSystem, bool initComplete) { lock (s_initLock) { if (s_initState != InitState.NotStarted) { throw new InvalidOperationException(System.Configuration.SR.GetString("Config_system_already_set")); } s_configSystem = configSystem; if (initComplete) { s_initState = InitState.Completed; } else { s_initState = InitState.Usable; } } }
void Start() { currentState = new InitState(); }
private void Initialize() { if (this.bodyInitState != InitState.Disposed) return; this.bodyInitState = InitState.Initializing; // Register for tranformation changes to keep the RigidBody in sync. Make sure to register only once. this.GameObj.Transform.EventTransformChanged -= this.OnTransformChanged; this.GameObj.Transform.EventTransformChanged += this.OnTransformChanged; // Initialize body and joints this.InitBody(); if (this.joints != null) { foreach (JointInfo info in this.joints) info.UpdateJoint(); } this.bodyInitState = InitState.Initialized; }
private void Initialize() { if (this.bodyInitState != InitState.Disposed) return; this.bodyInitState = InitState.Initializing; this.GameObj.Transform.EventTransformChanged += this.OnTransformChanged; this.InitBody(); // Initialize joints if (this.joints != null) { foreach (JointInfo info in this.joints) info.UpdateJoint(); } this.bodyInitState = InitState.Initialized; }
//------------------------------------------------------------------------- void CheckForSmoothMovesBoneAnimationParent(out InitState hasSmoothMovesBoneAnimationParent, out Component smoothMovesBoneAnimationParent, out string fullNodeString) { string tempNodeString = ""; smoothMovesBoneAnimationParent = FindBoneAnimationParent(this.transform, ref tempNodeString); if (smoothMovesBoneAnimationParent != null) { hasSmoothMovesBoneAnimationParent = InitState.Yes; fullNodeString = tempNodeString; return; } else { hasSmoothMovesBoneAnimationParent = InitState.No; fullNodeString = null; return; } }
//set public for tests! /// <summary> /// /// </summary> /// <param name="configSystem"></param> /// <param name="initComplete"></param> public static void SetConfigurationSystem(SqlConfigurationSystem configSystem, bool initComplete) { lock (SqlConfigurationManager.initLock) { if (SqlConfigurationManager.initState != SqlConfigurationManager.InitState.NotStarted) { throw new InvalidOperationException(Properties.Resources.ExceptionConfigurationAlreadySet); } SqlConfigurationManager.configSystem = configSystem; if (initComplete) { SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Completed; } else { SqlConfigurationManager.initState = SqlConfigurationManager.InitState.Usable; } } }
private void Shutdown() { if (this.bodyInitState != InitState.Initialized) return; this.bodyInitState = InitState.Disposing; // Clean up body and joints this.CleanupJoints(); this.CleanupBody(); // Unregister for transformation change events. this.GameObj.Transform.EventTransformChanged -= this.OnTransformChanged; // Finally process all collision events we didn't get around to yet. this.ProcessCollisionEvents(); this.bodyInitState = InitState.Disposed; }
public DeployerController(DeployerContext context) { _context = context; State = new InitState(_context); }
internal static void Initialize() { // Initialize() is also called by other components outside of Trace (such as PerformanceCounter) // as a result using one lock for this critical section and another for Trace API critical sections // (such as Trace.WriteLine) could potentially lead to deadlock between 2 threads that are // executing these critical sections (and consequently obtaining the 2 locks) in the reverse order. // Using the same lock for DiagnosticsConfiguration as well as TraceInternal avoids this issue. // Sequential locks on TraceInternal.critSec by the same thread is a non issue for this critical section. lock (TraceInternal.critSec) { // because some of the code used to load config also uses diagnostics // we can't block them while we initialize from config. Therefore we just // return immediately and they just use the default values. if ( initState != InitState.NotInitialized || ConfigurationManagerInternalFactory.Instance.SetConfigurationSystemInProgress) { return; } initState = InitState.Initializing; // used for preventing recursion try { configSection = GetConfigSection(); } finally { initState = InitState.Initialized; } } }
protected virtual void OnFixedUpdate(float timeMult) { eventMap.ProcessGenerators(timeMult); ResolveCollisions(); // ToDo: Weather /*if (weatherType != WeatherType.None && commonResources.Graphics != null) * { * // ToDo: Apply weather effect to all other cameras too * Vector3 viewPos = cameras[0].Transform.Pos; * for (int i = 0; i < weatherIntensity; i++) * { * TileMap.DebrisCollisionAction collisionAction; * if (weatherOutdoors) * { * collisionAction = TileMap.DebrisCollisionAction.Disappear; * } * else * { * collisionAction = (MathF.Rnd.NextFloat() > 0.7f * ? TileMap.DebrisCollisionAction.None * : TileMap.DebrisCollisionAction.Disappear); * } * * Vector3 debrisPos = viewPos + MathF.Rnd.NextVector3((LevelRenderSetup.TargetSize.X / -2) - 40, * (LevelRenderSetup.TargetSize.Y * -2 / 3), MainPlaneZ, * LevelRenderSetup.TargetSize.X + 120, LevelRenderSetup.TargetSize.Y, 0); * * if (weatherType == WeatherType.Rain) * { * GraphicResource res = commonResources.Graphics["Rain"]; * Material material = res.Material.Res; * Texture texture = material.MainTexture.Res; * * float scale = MathF.Rnd.NextFloat(0.4f, 1.1f); * float speedX = MathF.Rnd.NextFloat(2.2f, 2.7f) * scale; * float speedY = MathF.Rnd.NextFloat(7.6f, 8.6f) * scale; * * debrisPos.Z = MainPlaneZ * scale; * * tileMap.CreateDebris(new TileMap.DestructibleDebris * { * Pos = debrisPos, * Size = res.Base.FrameDimensions, * Speed = new Vector2(speedX, speedY), * * Scale = scale, * Angle = MathF.Atan2(speedY, speedX), * Alpha = 1f, * * Time = 180f, * * Material = material, * MaterialOffset = texture.LookupAtlas(res.FrameOffset + MathF.Rnd.Next(res.FrameCount)), * * CollisionAction = collisionAction * }); * } * else * { * GraphicResource res = commonResources.Graphics["Snow"]; * Material material = res.Material.Res; * Texture texture = material.MainTexture.Res; * * float scale = MathF.Rnd.NextFloat(0.4f, 1.1f); * float speedX = MathF.Rnd.NextFloat(-1.6f, -1.2f) * scale; * float speedY = MathF.Rnd.NextFloat(3f, 4f) * scale; * float accel = MathF.Rnd.NextFloat(-0.008f, 0.008f) * scale; * * debrisPos.Z = MainPlaneZ * scale; * * tileMap.CreateDebris(new TileMap.DestructibleDebris * { * Pos = debrisPos, * Size = res.Base.FrameDimensions, * Speed = new Vector2(speedX, speedY), * Acceleration = new Vector2(accel, -MathF.Abs(accel)), * * Scale = scale, * Angle = MathF.Rnd.NextFloat(MathF.TwoPi), * AngleSpeed = speedX * 0.02f, * Alpha = 1f, * * Time = 180f, * * Material = material, * MaterialOffset = texture.LookupAtlas(res.FrameOffset + MathF.Rnd.Next(res.FrameCount)), * * CollisionAction = collisionAction * }); * } * } * }*/ // Active Boss if (activeBoss != null && activeBoss.Scene == null) { activeBoss = null; // ToDo InitLevelChange(ExitType.Normal, null); } if (initState == InitState.Initializing) { initState = InitState.Initialized; } //collisionsCountA = 0; //collisionsCountB = 0; //collisionsCountC = 0; }
internal static void Initialize() { // because some of the code used to load config also uses diagnostics // we can't block them while we initialize from config. Therefore we just // return immediately and they just use the default values. lock (typeof(DiagnosticsConfiguration)) { if (initState != InitState.NotInitialized || ConfigurationSettings.SetConfigurationSystemInProgress) return; initState = InitState.Initializing; // used for preventing recursion try { configTable = GetConfigTable(); } finally { initState = InitState.Initialized; } } }
public static bool EnsureInitialized() { // Only initialize once: if (InitState.Initialized == (InitState)s_InilializationState) { return(true); } while (true) { InitState prevInitState = (InitState)Interlocked.CompareExchange( ref s_InilializationState, (int)InitState.Initializing, (int)InitState.NotInitialized); if (prevInitState == InitState.Error) { return(false); } else if (prevInitState == InitState.Initialized) { return(true); } else if (prevInitState == InitState.Initializing) { // Another thread is initializing the loader. // Perform a short blocking wait. // This is OK, becasue it can only happen early on, before initialization is complete. Thread.Sleep(10); } else if (prevInitState == InitState.NotInitialized) { // That means we won the race and set it to InitState_Initializing. // Let's do it! break; } else { throw new InvalidOperationException($"Unexpected inilialization state. {nameof(DynamicLoader)}.{s_InilializationState} = {prevInitState}"); } } try { Log.Debug(LogComonentMoniker, $"Initializing {nameof(DynamicLoader)}."); Log.Debug(LogComonentMoniker, $"Runtime version: {Environment.Version}."); Log.Debug(LogComonentMoniker, $"BCL version: {typeof(object).Assembly.FullName}."); Log.Debug(LogComonentMoniker, ""); bool success = PerformInitialization(); Log.Debug(LogComonentMoniker, $"Initialization success: {success}."); Interlocked.Exchange(ref s_InilializationState, success ? (int)InitState.Initialized : (int)InitState.Error); return(success); } catch (Exception ex) { Log.Error(LogComonentMoniker, ex); Interlocked.Exchange(ref s_InilializationState, (int)InitState.Error); return(false); } }