protected GameHost(string gameName = @"") { AppDomain.CurrentDomain.UnhandledException += exceptionHandler; FileSafety.DeleteCleanupDirectory(); Dependencies.CacheAs(this); Dependencies.CacheAs(Storage = GetStorage(gameName)); Name = gameName; Logger.GameIdentifier = gameName; threads = new List <GameThread> { (DrawThread = new DrawThread(DrawFrame) { OnThreadStart = DrawInitialize, }), (UpdateThread = new UpdateThread(UpdateFrame) { OnThreadStart = UpdateInitialize, Monitor = { HandleGC = true }, }), (InputThread = new InputThread(null)), //never gets started. }; var path = System.IO.Path.GetDirectoryName(FullPath); if (path != null) { Environment.CurrentDirectory = path; } }
public void Start() { if (Running) { return; } Running = true; ConfigManager.LoadConfigAsync().ContinueWith((Task loadTask) => { Logger.Log("Config loaded successfully"); ConfigManager.SaveConfigAsync().ContinueWith((Task saveTask) => { Logger.Log("Config saved"); }); WallpaperRenderer.Initialize(); ThreadManager.Run(InputThread = new InputThread(UpdateInput)); ThreadManager.Run(BrowserThread = new BrowserThread(BrowserInit)); ThreadManager.Run(WallpaperThread = new RenderThread(RenderInit)); ThreadManager.Run(ControllerThread = new ControllerThread(ControllerInit)); }); while (Running) { System.Threading.Thread.Sleep(1); } ; }
protected BasicGameHost(string gameName = @"") { Dependencies.Cache(this); name = gameName; threads = new[] { drawThread = new GameThread(DrawFrame, @"DrawThread") { OnThreadStart = DrawInitialize, }, updateThread = new GameThread(UpdateFrame, @"UpdateThread") { OnThreadStart = UpdateInitialize, Monitor = { HandleGC = true } }, inputThread = new InputThread(null, @"MainThread") //never gets started. }; MaximumUpdateHz = GameThread.DEFAULT_ACTIVE_HZ; MaximumDrawHz = (DisplayDevice.Default?.RefreshRate ?? 0) * 4; // Note, that RegisterCounters only has an effect for the first // BasicGameHost to be passed into it; i.e. the first BasicGameHost // to be instantiated. FrameStatistics.RegisterCounters(this); Environment.CurrentDirectory = Path.GetDirectoryName(FullPath); setActive(true); AddInternal(inputManager = new UserInputManager(this)); }
protected GameHost(string gameName = @"") { Instance = this; AppDomain.CurrentDomain.UnhandledException += exceptionHandler; Dependencies.Cache(this); Name = gameName; threads = new List <GameThread> { (DrawThread = new GameThread(DrawFrame, @"Draw") { OnThreadStart = DrawInitialize, }), (UpdateThread = new GameThread(UpdateFrame, @"Update") { OnThreadStart = UpdateInitialize, Monitor = { HandleGC = true } }), (InputThread = new InputThread(null, @"Input")) //never gets started. }; MaximumUpdateHz = GameThread.DEFAULT_ACTIVE_HZ; MaximumDrawHz = (DisplayDevice.Default?.RefreshRate ?? 0) * 4; Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(FullPath); }
protected GameHost(string gameName = @"") { Instance = this; AppDomain.CurrentDomain.UnhandledException += exceptionHandler; Dependencies.Cache(this); Name = gameName; Logger.GameIdentifier = gameName; threads = new List <GameThread> { (DrawThread = new DrawThread(DrawFrame, @"Draw") { OnThreadStart = DrawInitialize, }), (UpdateThread = new UpdateThread(UpdateFrame, @"Update") { OnThreadStart = UpdateInitialize, Monitor = { HandleGC = true }, }), (InputThread = new InputThread(null, @"Input")), //never gets started. }; var path = System.IO.Path.GetDirectoryName(FullPath); if (path != null) { Environment.CurrentDirectory = path; } }
public ControlsThread(InputThread Input, RobotThread Robot, ThreadPriority Priority = ThreadPriority.Normal) : base("Controls Thread", Priority) { inputThread = Input; robotThread = Robot; robotThread.OnConnected += RobotThread_OnConnected; robotThread.OnDisconnecting += RobotThread_OnDisconnecting; }
public static void restartInputThread(Client client) { InputThread inputThreadObj = new InputThread(client); Thread inputThread = new Thread(new ThreadStart(inputThreadObj.run)); inputThread.Start(); }
public WebWallpaper() { Controller = new WallpaperController(this); WallpaperManager = new WallpaperManager(this); Input = WallpaperManager; renderThread = new WallpaperThread(RenderTask); inputThread = new InputThread(InputTask); }
static bool Prefix(InputThread __instance) { int _pos = Traverse.Create(__instance).Field("_pos").GetValue <int>(); GamePadState state = Traverse.Create(__instance).Field("state").GetValue <GamePadState>(); InputStruct _lastFrameData = Traverse.Create(__instance).Field("_lastFrameData").GetValue <InputStruct>(); if (_pos < __instance._maxLength) { if (state.IsConnected) { __instance.inputsIn[_pos].leftX = __instance.leftXFilter.Filter((double)state.ThumbSticks.Left.X); __instance.inputsIn[_pos].leftY = __instance.leftYFilter.Filter((double)state.ThumbSticks.Left.Y); __instance.inputsIn[_pos].rightX = __instance.rightXFilter.Filter((double)state.ThumbSticks.Right.X); __instance.inputsIn[_pos].rightY = __instance.rightYFilter.Filter((double)state.ThumbSticks.Right.Y); RotateInput(ref __instance.inputsIn[_pos]); __instance.inputsIn[_pos].time = DateTime.UtcNow.Ticks; __instance.inputsIn[_pos].leftXVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].leftX, _lastFrameData.leftX, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); __instance.inputsIn[_pos].leftYVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].leftY, _lastFrameData.leftY, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); __instance.inputsIn[_pos].rightXVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].rightX, _lastFrameData.rightX, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); __instance.inputsIn[_pos].rightYVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].rightY, _lastFrameData.rightY, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); _lastFrameData.leftX = __instance.inputsIn[_pos].leftX; _lastFrameData.leftY = __instance.inputsIn[_pos].leftY; _lastFrameData.rightX = __instance.inputsIn[_pos].rightX; _lastFrameData.rightY = __instance.inputsIn[_pos].rightY; _lastFrameData.time = __instance.inputsIn[_pos].time; Traverse.Create(__instance).Field("_lastFrameData").SetValue(_lastFrameData); Traverse.Create(__instance).Field("_pos").SetValue(_pos + 1); return(false); } if (__instance.inputController == null || Traverse.Create(__instance.inputController).Field("player").GetValue() == null) { return(false); } __instance.inputsIn[_pos].leftX = __instance.leftXFilter.Filter((double)((Mathf.Abs(Traverse.Create(__instance).Method("GetAxisLX").GetValue <float>()) < 0.1f) ? 0f : Traverse.Create(__instance).Method("GetAxisLX").GetValue <float>())); __instance.inputsIn[_pos].leftY = __instance.leftYFilter.Filter((double)Traverse.Create(__instance).Method("GetAxisLY").GetValue <float>()); __instance.inputsIn[_pos].rightX = __instance.rightXFilter.Filter((double)((Mathf.Abs(Traverse.Create(__instance).Method("GetAxisRX").GetValue <float>()) < 0.1f) ? 0f : Traverse.Create(__instance).Method("GetAxisRX").GetValue <float>())); __instance.inputsIn[_pos].rightY = __instance.rightYFilter.Filter((double)Traverse.Create(__instance).Method("GetAxisRY").GetValue <float>()); RotateInput(ref __instance.inputsIn[_pos]); __instance.inputsIn[_pos].time = DateTime.UtcNow.Ticks; __instance.inputsIn[_pos].leftXVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].leftX, _lastFrameData.leftX, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); __instance.inputsIn[_pos].leftYVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].leftY, _lastFrameData.leftY, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); __instance.inputsIn[_pos].rightXVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].rightX, _lastFrameData.rightX, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); __instance.inputsIn[_pos].rightYVel = Traverse.Create(__instance).Method("GetVel", __instance.inputsIn[_pos].rightY, _lastFrameData.rightY, __instance.inputsIn[_pos].time, _lastFrameData.time).GetValue <float>(); _lastFrameData.leftX = __instance.inputsIn[_pos].leftX; _lastFrameData.leftY = __instance.inputsIn[_pos].leftY; _lastFrameData.rightX = __instance.inputsIn[_pos].rightX; _lastFrameData.rightY = __instance.inputsIn[_pos].rightY; _lastFrameData.time = __instance.inputsIn[_pos].time; Traverse.Create(__instance).Field("_lastFrameData").SetValue(_lastFrameData); Traverse.Create(__instance).Field("_pos").SetValue(_pos + 1); } return(false); }
//Initialize window, create threads / thread switchers, and initialize logger. public MainInterface() { try { Thread.CurrentThread.Name = "Main UI"; } catch (Exception) { } if (!InitializeLogging()) { return; } Log.Info("Logging initialized."); InitializeComponent(); Log.Info("Program initialized."); inputThread = new InputThread(ThreadPriority.Normal); cameraThread = new CameraThread(ThreadPriority.Normal); robotThread = new RobotThread(ThreadPriority.Normal); controlsThread = new ControlsThread(inputThread, robotThread, ThreadPriority.Normal); Log.Info("Threads initialized."); settings = new AppSettings(robotThread); }
public InputVisualizer(InputThread input) { this.input = input; InitializeComponent(); }
public static void Start( ) { InputThread.Start( ); }
/// <summary> /// Construct a new ThreadRunner instance. /// </summary> /// <param name="mainThread">The main window thread. Used for input in multi-threaded execution; all game logic in single-threaded execution.</param> /// <exception cref="NotImplementedException"></exception> public ThreadRunner(InputThread mainThread) { this.mainThread = mainThread; AddThread(mainThread); }
private static void ResetConsole() { InputThread.Abort(); Running = false; Main(); }
protected override ThreadRunner CreateThreadRunner(InputThread mainThread) => threadRunner = new ManualThreadRunner(mainThread);
static void Main(string[] args) { Client client = null; try { client = new Client(); //(new Thread(new ConnectionChecker(client.socket)) + start()); } catch (IOException e) { Console.WriteLine("Error connecting to the server."); Environment.Exit(1); } ConnectionChecker connCheker = new ConnectionChecker(client.getSocket(), client); Thread connCheckerThread = new Thread(new ThreadStart(connCheker.run)); connCheckerThread.Start(); InputThread inputThreadObj = new InputThread(client); Thread inputThread = new Thread(new ThreadStart(inputThreadObj.run)); inputThread.Start(); //(new Thread(new GUI(client)) + start()); bool running = true; Console.WriteLine(("Successfully connected to market with ID: " + (client.getID() + ". Type \'help\' for list of commands."))); while (running) { Console.Write("> "); String input = Console.ReadLine(); switch (input) { case "balance": client.sendCommand("balance"); break; case "buy": client.sendCommand("buy"); break; case "sell": Console.WriteLine("sell"); bool gettingRecip = true; int recipient = 0; while (gettingRecip) { Console.WriteLine("Enter an id who you would like to sell to: "); try{ recipient = Convert.ToInt32(Console.ReadLine()); if (recipient != null) { gettingRecip = false; } else { Console.WriteLine("Please enter a valid user ID"); } } catch (System.FormatException e) { Console.WriteLine("Please enter a valid user ID"); } } //Send server commands. client.sendCommand("sell"); client.sendCommand(recipient.ToString()); break; case "quit": client.sendCommand("quit"); Console.WriteLine("Disconnecting from server..."); Environment.Exit(1); break; case "help": Console.WriteLine("Available commands:\n> balance\n> sell\n> status\n> connections"); break; case "status": client.sendCommand("status"); break; case "connections": client.sendCommand("connections"); break; default: Console.WriteLine("Invalid command, type \'help\' for a list of all commands."); break; } } }
public ManualThreadRunner(InputThread mainThread) : base(mainThread) { RunOnce.Set(); }