static void Main(string[] args) { new Thread(() => { viewer = GameSystemMonitor.Execute(); Application.Run(viewer); }).Start(); Console.WriteLine("==============================="); Console.WriteLine("Usage:"); Console.WriteLine("instantiate %1 [%2 %3 ...]"); Console.WriteLine("\tCreate a new entity which named %1, %2, %3...."); Console.WriteLine("kill %1 [%2 %3 ...]"); Console.WriteLine("\tKill a entity which named %1, %2, %3...."); Console.WriteLine("clear"); Console.WriteLine("\tClear all entities."); Console.WriteLine("attach %1 to %2"); Console.WriteLine("\tAttach %1(component) to %2(entity)."); Console.WriteLine("detach %1 to %2"); Console.WriteLine("\tDetach %1(component) from %2(entity)."); Console.WriteLine("quit | q"); Console.WriteLine("\tQuit this program."); Console.WriteLine("==============================="); Console.WriteLine(); while (true) { Console.Write(">"); var words = Console.ReadLine().ToLower().Trim().Split(' '); var command = words[0]; var arguments = (words.Length > 0) ? words.Skip(1).ToArray() : null; switch (command) { case "instantiate": if (arguments == null) { Console.WriteLine("Error: Not specified entity name."); break; } else { foreach (var name in arguments) { if (Entity.Find(e => e.Name == name) != null) { Console.WriteLine("Error: Already exists entity which same name."); break; } var entity = Entity.Instantiate(); entity.Name = name; } } break; case "kill": if (arguments == null) { Console.WriteLine("Error: Not specified entity name."); break; } else { foreach (var name in arguments) { var entity = Entity.Find(e => e.Name == name); if (entity == null) { Console.WriteLine("Error: Not exists specified entity."); break; } Entity.Kill(entity); } } break; case "clear": Entity.Clear(); break; case "attach": if (arguments.Length != 3) { Console.WriteLine("Error: Wrong command."); break; } if (arguments[1] != "to") { Console.WriteLine("Error: Wrong command."); break; } { var componentName = arguments[0]; var entityName = arguments[2]; var entity = Entity.Find(e => e.Name == entityName); var component = (componentName == "a") ? new A() : ((componentName == "b") ? new B() : null as EntityComponent); if (entity == null) { Console.WriteLine("Error: Not exists specified entity."); break; } if (component == null) { Console.WriteLine("Error: Not exists specified component."); break; } if (!entity.Has(component.GetType())) { entity.Attach(component); } } break; case "detach": if (arguments.Length != 3) { Console.WriteLine("Error: Wrong command."); break; } if (arguments[1] != "from") { Console.WriteLine("Error: Wrong command."); break; } { var componentName = arguments[0]; var entityName = arguments[2]; var entity = Entity.Find(e => e.Name == entityName); var componentType = (componentName == "a") ? typeof(A) : ((componentName == "b") ? typeof(B) : null as Type); if (entity == null) { Console.WriteLine("Error: Not exists specified entity."); break; } if (componentType == null) { Console.WriteLine("Error: Not exists specified component."); } if (entity.Has(componentType)) { entity.Detach(componentType); } } break; case "quit": Application.Exit(); break; case "q": Application.Exit(); break; default: Console.WriteLine("Error: Wrong command."); break; } Entity.Update(); } }
static void Main(string[] args) { #if DEBUG chdir("../../../"); #endif Window window = new Window(); window.Create("application-02", (int)DisplayWidth, (int)DisplayHeight); GraphicsDevice.Instance.Create(window, FullScreen); SoundDevice.Instance.Create(window.Handle); if (ShowDebugInfo) { runner = CommandRunner.Execute(); monitor = GameSystemMonitor.Execute(); } foreach (var file in Directory.GetFiles("res/mission/", "*.cs")) { var asm = ScriptCompiler.CompileAssemblyFromFile(new ScriptCompilerParameters() { BaseClassName = "Script", BatchScriptStyle = false, ClassName = "Mission", GenerateExecutable = false, GenerateInMemory = true, PythonScopeStyle = false, }, file); Missions.MissionAssemblies.Add(Path.GetFileNameWithoutExtension(file), asm); } window.Updated += () => { update(); GraphicsDevice.Instance.Clear(ColorCode.Black); #if true LoadingTask loadingTask = SceneManager.TryTransitScene(); if (loadingTask.Finished) { Entity.BroadcastMessage(UpdateMessage); Entity.BroadcastMessage(RenderMessage); Entity.BroadcastMessage(TranslucentRenderMessage); Entity.BroadcastMessage(DrawMessage); } else { LoadingView.Draw(loadingTask); } #endif GraphicsDevice.Instance.Present(); if (pressed(KeyCode.Escape)) { window.Close(); } Entity.Update(); }; try { initialize(); //SceneManager.FookScene(new MainScene()); SceneManager.FookScene(new TitleScene()); //SceneManager.FookScene(new MissionSelectScene()); window.Start(); } finally { Entity.Clear(); ResourceManager.CleanUp(); GC.Collect(); finalize(); GraphicsDevice.Instance.Dispose(); SoundDevice.Instance.Dispose(); if (ShowDebugInfo) { GameSystemMonitor.Shutdown(monitor); CommandRunner.Shutdown(runner); } } }
static void Main(string[] args) { chdir("../../../"); Window window = new Window(); window.Create("application-03", (int)DisplayWidth, (int)DisplayHeight); GraphicsDevice.Instance.Create(window, FullScreen); SoundDevice.Instance.Create(window.Handle); #if DEBUG var runner = CommandRunner.Execute(); var monitor = GameSystemMonitor.Execute(); #endif foreach (var file in Directory.GetFiles("res/mission/", "*.cs")) { var assembly = ScriptCompiler.CompileAssemblyFromFile(new ScriptCompilerParameters() { BaseClassName = "GameScript", BatchScriptStyle = false, ClassName = "Mission", GenerateExecutable = false, GenerateInMemory = true, PythonScopeStyle = false, }, file); Missions.MissionAssemblies.Add(Path.GetFileNameWithoutExtension(file), assembly); } SceneManager.SetNextScene(new TitleScene()); window.Updated += () => { EngineScript.update(); GameScript.update(); GraphicsDeviceContext.Instance.Clear(ColorCode.Black); if (SceneManager.Running) { DrawLoadingStatus(SceneManager.Scene); } else { if (SceneManager.Scene != null) { if (!SceneManager.Running) { SceneManager.NextScene(); } } else { Entity.BroadcastMessage(UpdateMessage); Entity.BroadcastMessage(RenderMessage); Entity.BroadcastMessage(TranslucentRenderMessage); Entity.BroadcastMessage(DrawMessage); } } GraphicsDeviceContext.Instance.Present(); if (pressed(KeyCode.Escape)) { window.Close(); } Entity.Update(); }; try { EngineScript.initialize(); GameScript.initialize(); window.Start(); } finally { #if DEBUG GameSystemMonitor.Shutdown(monitor); CommandRunner.Shutdown(runner); #endif Entity.Clear(); ResourceManager.CleanUp(); EngineScript.finalize(); GameScript.finalize(); GraphicsDeviceContext.Instance.Dispose(); GraphicsDevice.Instance.Dispose(); SoundDevice.Instance.Dispose(); } }