X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FNetworkGame.cs;fp=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FNetworkGame.cs;h=869812e58ad6147528dfc35b5770d72b38625c23;hp=ae0396bb1901fb85ff767b1e7e6752202c790e0c;hb=204e28e04eadd2d7da52d72eb229a9c6c89581ae;hpb=d77039298ad2420042b26799c0afdb916572f2b0 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; } }