From: Charles Date: Thu, 1 Apr 2010 23:16:01 +0000 (+0000) Subject: Added a basic timeout feature so you'll at least get bumped back to the lobby after... X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=204e28e04eadd2d7da52d72eb229a9c6c89581ae;p=chaz%2Fcarfire Added a basic timeout feature so you'll at least get bumped back to the lobby after a long stall. Made some tweaks so the gameover and termination features of the test harness work better. git-svn-id: https://bd85.net/svn/cs3505_group@49 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/CS 3505/TestHarness.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/CS 3505/TestHarness.cs index 883e8a0..2b32ef0 100644 --- a/Project06/CS 3505 Project 06/CS 3505 Project 06/CS 3505/TestHarness.cs +++ b/Project06/CS 3505 Project 06/CS 3505 Project 06/CS 3505/TestHarness.cs @@ -64,8 +64,8 @@ namespace CS_3505_Project_06.CS_3505 for (int player = 0; player < 4; player++) { - if (isGameOver[player]) - continue; + //if (isGameOver[player]) + // continue; if (inputs.mousePressedChanged[player]) mouseButton[player] = inputs.mousePressed[player]; diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs index ae0396b..869812e 100644 --- a/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs +++ b/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs @@ -1,5 +1,7 @@  -//#define DEBUG +// Make sure DEBUG is undefined when turning in the project +// or the grader will wonder why it's so laggy. +#undef DEBUG using System; using System.Collections.Generic; @@ -282,12 +284,17 @@ namespace CS_3505_Project_06 } else if (mNetworkSession.SessionState == NetworkSessionState.Playing) { - if (mGame.IsGameOver(LocalGamerInfo) || mGame.IsTerminated(LocalGamerInfo)) + if (mGame.IsTerminated(LocalGamerInfo)) { - // TODO: Should support moving back to the session lobby. LeaveSession(); return; } + else if (mGame.IsGameOver(LocalGamerInfo)) + { + ApplyEvents(LocalGamerInfo, GetEventsFromInput()); + mGame.Update(mTargetTimeSpan); + return; + } if (HaveNeededEvents) { @@ -309,23 +316,15 @@ namespace CS_3505_Project_06 } else // Stall! { - if (mStallCount == 0) - { -#if DEBUG - Console.WriteLine("STAL: ===="); -#endif - } - else if (mStallCount % 60 == 0) - { - // DEBUG - //Console.WriteLine("Stalled for " + mStallCount + " frames."); - } - mStallCount++; // Send a reliable event packet to each stalled gamer. if (mStallCount == 1) { +#if DEBUG + Console.WriteLine("STAL: ===="); +#endif + foreach (GamerInfo gamerInfo in GamerArray) { if (gamerInfo.HighestFrameNumber < mGame.CurrentFrameNumber) @@ -334,19 +333,11 @@ namespace CS_3505_Project_06 } } } - - /*if (mStallCount > StallTimeout) + else if (mStallCount > 600) { - DropLostGamers(); - mStallCount = 0; + Console.WriteLine("One or more players have stalled excessively. Leaving session..."); + LeaveSession(); } - else if (mStallCount == 1) - { - SendLocalEvents - } - else if (mStallCount % 60 == 0) - { - } TODO */ } } } @@ -493,8 +484,7 @@ namespace CS_3505_Project_06 enum PacketType { Chat = 1, - Event = 2, - Stall = 3 + Event = 2 } enum EventType @@ -703,16 +693,6 @@ namespace CS_3505_Project_06 senderInfo.HighestFrameNumber = frameNumber; break; - case PacketType.Stall: - - GamerInfo senderInfo2 = mGamers[sender.Id]; - - byte numStalledPeers = mPacketReader.ReadByte(); - byte[] stalledPeers = mPacketReader.ReadBytes(numStalledPeers); - - // TODO - break; - default: Console.WriteLine("Received unknown packet type: " + (int)packetId); @@ -1001,6 +981,7 @@ namespace CS_3505_Project_06 foreach (GamerInfo gamerInfo in mGamers.Values) { + if (mGame.IsGameOver(gamerInfo)) continue; if (gamerInfo.HighestFrameNumber < currentFrame) return false; } @@ -1015,44 +996,47 @@ namespace CS_3505_Project_06 foreach (GamerInfo gamerInfo in GamerArray) { if (gamerInfo.Events[index] == null) continue; + ApplyEvents(gamerInfo, gamerInfo.Events[index]); + gamerInfo.Events[index] = null; + } + } - foreach (EventInfo eventInfo in gamerInfo.Events[index]) + void ApplyEvents(GamerInfo gamerInfo, List events) + { + foreach (EventInfo eventInfo in events) + { + KeyboardEventInfo keyboardEventInfo = eventInfo as KeyboardEventInfo; + if (keyboardEventInfo != null) { - KeyboardEventInfo keyboardEventInfo = eventInfo as KeyboardEventInfo; - if (keyboardEventInfo != null) - { #if DEBUG - Console.WriteLine(" KEY: " + keyboardEventInfo.FrameOfApplication + "\t" + keyboardEventInfo.Key + "," + keyboardEventInfo.IsKeyDown); + Console.WriteLine(" KEY: " + keyboardEventInfo.FrameOfApplication + "\t" + keyboardEventInfo.Key + "," + keyboardEventInfo.IsKeyDown); #endif - mGame.ApplyKeyInput(gamerInfo, keyboardEventInfo.Key, keyboardEventInfo.IsKeyDown); - continue; - } + mGame.ApplyKeyInput(gamerInfo, keyboardEventInfo.Key, keyboardEventInfo.IsKeyDown); + continue; + } - MouseButtonEventInfo mouseButtonEventInfo = eventInfo as MouseButtonEventInfo; - if (mouseButtonEventInfo != null) - { + MouseButtonEventInfo mouseButtonEventInfo = eventInfo as MouseButtonEventInfo; + if (mouseButtonEventInfo != null) + { #if DEBUG - Console.WriteLine(" BTN: " + mouseButtonEventInfo.FrameOfApplication + "\t" + mouseButtonEventInfo.IsButtonDown); + Console.WriteLine(" BTN: " + mouseButtonEventInfo.FrameOfApplication + "\t" + mouseButtonEventInfo.IsButtonDown); #endif - mGame.ApplyMouseButtonInput(gamerInfo, mouseButtonEventInfo.IsButtonDown); - continue; - } + mGame.ApplyMouseButtonInput(gamerInfo, mouseButtonEventInfo.IsButtonDown); + continue; + } - MouseMotionEventInfo mouseMotionEventInfo = eventInfo as MouseMotionEventInfo; - if (mouseMotionEventInfo != null) - { + MouseMotionEventInfo mouseMotionEventInfo = eventInfo as MouseMotionEventInfo; + if (mouseMotionEventInfo != null) + { #if DEBUG - Console.WriteLine(" MMV: " + mouseMotionEventInfo.FrameOfApplication + "\t" + mouseMotionEventInfo.X + "," + mouseMotionEventInfo.Y); + Console.WriteLine(" MMV: " + mouseMotionEventInfo.FrameOfApplication + "\t" + mouseMotionEventInfo.X + "," + mouseMotionEventInfo.Y); #endif - mGame.ApplyMouseLocationInput(gamerInfo, mouseMotionEventInfo.X, mouseMotionEventInfo.Y); - continue; - } + mGame.ApplyMouseLocationInput(gamerInfo, mouseMotionEventInfo.X, mouseMotionEventInfo.Y); + continue; } - - gamerInfo.Events[index] = null; } }