public static void RunFrame() { var inputs = new ulong[ngs.players.Length]; for (int i = 0; i < inputs.Length; ++i) { inputs[i] = VectorWar.ReadInputs(ngs.players[i].controllerId); } gs.Update(inputs, 0); }
/// <summary> /// Runs the game loop inside the form. /// </summary> async Task HandleApplicationIdle(VectorWar form, GGPOSession ggpo) { while (true) { while (IsApplicationIdle()) { now = Utility.GetCurrentTime(); await(Task) form.Invoke((TaskMethodInvoker) delegate { ggpo.Idle((int)Math.Max(0, next - now - 1)); return(Task.CompletedTask); }); if (now >= next) { await(Task) form.Invoke((TaskMethodInvoker) delegate { GameUpdate(); return(Task.CompletedTask); }); await(Task) form.Invoke((TaskMethodInvoker) delegate { Refresh(); return(Task.CompletedTask); }); next = now + (uint)(1000 / 60f); } } } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var app = new VectorWar(); int offset = 0; int localPlayer = 0; // Window offsets for the different players Point[] windowOffsets = new Point[] { new Point(64, 64), new Point(740, 64), new Point(64, 600), new Point(700, 600), }; if (args.Length < 3) { Syntax(); return; } var localPort = int.Parse(args[offset++]); var numPlayers = int.Parse(args[offset++]); if (numPlayers < 0 || args.Length < offset + numPlayers) { Syntax(); return; } if (args[offset] == "spectate") { string[] hostSplit = GetNetworkInfo(args[offset + 1]); var hostIp = hostSplit[0]; var hostPort = int.Parse(hostSplit[1]); app.InitSpectator(localPort, numPlayers, hostIp, hostPort); } else { GGPOPlayer[] players = new GGPOPlayer[GGPOSharp.Constants.MaxSpectators + GGPOSharp.Constants.MaxPlayers]; int i; for (i = 0; i < numPlayers; i++) { string arg = args[offset++]; players[i].playerId = i + 1; if (arg.Equals("local", StringComparison.InvariantCultureIgnoreCase)) { players[i].type = GGPOPlayerType.Local; localPlayer = i; continue; } players[i].type = GGPOPlayerType.Remote; string[] remoteSplit = GetNetworkInfo(arg); players[i].ipAddress = remoteSplit[0]; players[i].port = int.Parse(remoteSplit[1]); } // Additional arguments past the number of players are spectators int numSpectators = 0; while (offset < args.Length) { players[i].type = GGPOPlayerType.Spectator; string[] remoteSplit = GetNetworkInfo(args[offset++]); players[i].ipAddress = remoteSplit[0]; players[i].playerId = int.Parse(remoteSplit[1]); i++; numSpectators++; } if (localPlayer < windowOffsets.Length) { app.Location = windowOffsets[localPlayer]; } app.Init(localPort, numPlayers, players, numSpectators); } //app.SyncTest = true; Application.Run(app); }