]> Dogcows Code - chaz/carfire/commitdiff
Added a basic timeout feature so you'll at least get bumped back to the lobby after...
authorCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 1 Apr 2010 23:16:01 +0000 (23:16 +0000)
committerCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 1 Apr 2010 23:16:01 +0000 (23:16 +0000)
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

Project06/CS 3505 Project 06/CS 3505 Project 06/CS 3505/TestHarness.cs
Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs

index 883e8a09676d15b86615d228fa0a7c12042118af..2b32ef08d76863a0bb8af9c98d5d59f940dcb95b 100644 (file)
@@ -64,8 +64,8 @@ namespace CS_3505_Project_06.CS_3505
 \r
             for (int player = 0; player < 4; player++)\r
             {\r
-                if (isGameOver[player])\r
-                    continue;\r
+                //if (isGameOver[player])\r
+                //    continue;\r
 \r
                 if (inputs.mousePressedChanged[player])\r
                     mouseButton[player] = inputs.mousePressed[player];\r
index ae0396bb1901fb85ff767b1e7e6752202c790e0c..869812e58ad6147528dfc35b5770d72b38625c23 100644 (file)
@@ -1,5 +1,7 @@
 \r
-//#define DEBUG\r
+// Make sure DEBUG is undefined when turning in the project\r
+// or the grader will wonder why it's so laggy.\r
+#undef DEBUG\r
 \r
 using System;\r
 using System.Collections.Generic;\r
@@ -282,12 +284,17 @@ namespace CS_3505_Project_06
                 }\r
                 else if (mNetworkSession.SessionState == NetworkSessionState.Playing)\r
                 {\r
-                    if (mGame.IsGameOver(LocalGamerInfo) || mGame.IsTerminated(LocalGamerInfo))\r
+                    if (mGame.IsTerminated(LocalGamerInfo))\r
                     {\r
-                        // TODO: Should support moving back to the session lobby.\r
                         LeaveSession();\r
                         return;\r
                     }\r
+                    else if (mGame.IsGameOver(LocalGamerInfo))\r
+                    {\r
+                        ApplyEvents(LocalGamerInfo, GetEventsFromInput());\r
+                        mGame.Update(mTargetTimeSpan);\r
+                        return;\r
+                    }\r
 \r
                     if (HaveNeededEvents)\r
                     {\r
@@ -309,23 +316,15 @@ namespace CS_3505_Project_06
                     }\r
                     else // Stall!\r
                     {\r
-                        if (mStallCount == 0)\r
-                        {\r
-#if DEBUG\r
-                            Console.WriteLine("STAL: ====");\r
-#endif\r
-                        }\r
-                        else if (mStallCount % 60 == 0)\r
-                        {\r
-                            // DEBUG\r
-                            //Console.WriteLine("Stalled for " + mStallCount + " frames.");\r
-                        }\r
-\r
                         mStallCount++;\r
 \r
                         // Send a reliable event packet to each stalled gamer.\r
                         if (mStallCount == 1)\r
                         {\r
+#if DEBUG\r
+                            Console.WriteLine("STAL: ====");\r
+#endif\r
+\r
                             foreach (GamerInfo gamerInfo in GamerArray)\r
                             {\r
                                 if (gamerInfo.HighestFrameNumber < mGame.CurrentFrameNumber)\r
@@ -334,19 +333,11 @@ namespace CS_3505_Project_06
                                 }\r
                             }\r
                         }\r
-\r
-                        /*if (mStallCount > StallTimeout)\r
+                        else if (mStallCount > 600)\r
                         {\r
-                            DropLostGamers();\r
-                            mStallCount = 0;\r
+                            Console.WriteLine("One or more players have stalled excessively.  Leaving session...");\r
+                            LeaveSession();\r
                         }\r
-                        else if (mStallCount == 1)\r
-                        {\r
-                            SendLocalEvents\r
-                        }\r
-                        else if (mStallCount % 60 == 0)\r
-                        {\r
-                        } TODO */\r
                     }\r
                 }\r
             }\r
@@ -493,8 +484,7 @@ namespace CS_3505_Project_06
         enum PacketType\r
         {\r
             Chat = 1,\r
-            Event = 2,\r
-            Stall = 3\r
+            Event = 2\r
         }\r
 \r
         enum EventType\r
@@ -703,16 +693,6 @@ namespace CS_3505_Project_06
                         senderInfo.HighestFrameNumber = frameNumber;\r
                         break;\r
 \r
-                    case PacketType.Stall:\r
-\r
-                        GamerInfo senderInfo2 = mGamers[sender.Id];\r
-\r
-                        byte numStalledPeers = mPacketReader.ReadByte();\r
-                        byte[] stalledPeers = mPacketReader.ReadBytes(numStalledPeers);\r
-\r
-                        // TODO\r
-                        break;\r
-\r
                     default:\r
 \r
                         Console.WriteLine("Received unknown packet type: " + (int)packetId);\r
@@ -1001,6 +981,7 @@ namespace CS_3505_Project_06
 \r
                 foreach (GamerInfo gamerInfo in mGamers.Values)\r
                 {\r
+                    if (mGame.IsGameOver(gamerInfo)) continue;\r
                     if (gamerInfo.HighestFrameNumber < currentFrame) return false;\r
                 }\r
 \r
@@ -1015,44 +996,47 @@ namespace CS_3505_Project_06
             foreach (GamerInfo gamerInfo in GamerArray)\r
             {\r
                 if (gamerInfo.Events[index] == null) continue;\r
+                ApplyEvents(gamerInfo, gamerInfo.Events[index]);\r
+                gamerInfo.Events[index] = null;\r
+            }\r
+        }\r
 \r
-                foreach (EventInfo eventInfo in gamerInfo.Events[index])\r
+        void ApplyEvents(GamerInfo gamerInfo, List<EventInfo> events)\r
+        {\r
+            foreach (EventInfo eventInfo in events)\r
+            {\r
+                KeyboardEventInfo keyboardEventInfo = eventInfo as KeyboardEventInfo;\r
+                if (keyboardEventInfo != null)\r
                 {\r
-                    KeyboardEventInfo keyboardEventInfo = eventInfo as KeyboardEventInfo;\r
-                    if (keyboardEventInfo != null)\r
-                    {\r
 #if DEBUG\r
-                        Console.WriteLine(" KEY: " + keyboardEventInfo.FrameOfApplication + "\t" + keyboardEventInfo.Key + "," + keyboardEventInfo.IsKeyDown);\r
+                    Console.WriteLine(" KEY: " + keyboardEventInfo.FrameOfApplication + "\t" + keyboardEventInfo.Key + "," + keyboardEventInfo.IsKeyDown);\r
 #endif\r
 \r
-                        mGame.ApplyKeyInput(gamerInfo, keyboardEventInfo.Key, keyboardEventInfo.IsKeyDown);\r
-                        continue;\r
-                    }\r
+                    mGame.ApplyKeyInput(gamerInfo, keyboardEventInfo.Key, keyboardEventInfo.IsKeyDown);\r
+                    continue;\r
+                }\r
 \r
-                    MouseButtonEventInfo mouseButtonEventInfo = eventInfo as MouseButtonEventInfo;\r
-                    if (mouseButtonEventInfo != null)\r
-                    {\r
+                MouseButtonEventInfo mouseButtonEventInfo = eventInfo as MouseButtonEventInfo;\r
+                if (mouseButtonEventInfo != null)\r
+                {\r
 #if DEBUG\r
-                        Console.WriteLine(" BTN: " + mouseButtonEventInfo.FrameOfApplication + "\t" + mouseButtonEventInfo.IsButtonDown);\r
+                    Console.WriteLine(" BTN: " + mouseButtonEventInfo.FrameOfApplication + "\t" + mouseButtonEventInfo.IsButtonDown);\r
 #endif\r
 \r
-                        mGame.ApplyMouseButtonInput(gamerInfo, mouseButtonEventInfo.IsButtonDown);\r
-                        continue;\r
-                    }\r
+                    mGame.ApplyMouseButtonInput(gamerInfo, mouseButtonEventInfo.IsButtonDown);\r
+                    continue;\r
+                }\r
 \r
-                    MouseMotionEventInfo mouseMotionEventInfo = eventInfo as MouseMotionEventInfo;\r
-                    if (mouseMotionEventInfo != null)\r
-                    {\r
+                MouseMotionEventInfo mouseMotionEventInfo = eventInfo as MouseMotionEventInfo;\r
+                if (mouseMotionEventInfo != null)\r
+                {\r
 #if DEBUG\r
-                        Console.WriteLine(" MMV: " + mouseMotionEventInfo.FrameOfApplication + "\t" + mouseMotionEventInfo.X + "," + mouseMotionEventInfo.Y);\r
+                    Console.WriteLine(" MMV: " + mouseMotionEventInfo.FrameOfApplication + "\t" + mouseMotionEventInfo.X + "," + mouseMotionEventInfo.Y);\r
 #endif\r
 \r
-                        mGame.ApplyMouseLocationInput(gamerInfo, mouseMotionEventInfo.X, mouseMotionEventInfo.Y);\r
-                        continue;\r
-                    }\r
+                    mGame.ApplyMouseLocationInput(gamerInfo, mouseMotionEventInfo.X, mouseMotionEventInfo.Y);\r
+                    continue;\r
                 }\r
-\r
-                gamerInfo.Events[index] = null;\r
             }\r
         }\r
 \r
This page took 0.027232 seconds and 4 git commands to generate.