From 22e0c9d67454738cbc1887e8163b8564475ba4b0 Mon Sep 17 00:00:00 2001 From: Charles Lohr Date: Sun, 4 Jul 2004 05:06:55 +0000 Subject: [PATCH] Added rudamentry testing code for in-game networking --- stepmania/src/NetworkSyncManager.cpp | 58 +++++++++++++++++++++++++++- stepmania/src/NetworkSyncManager.h | 1 + stepmania/src/StepMania.cpp | 1 + 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/stepmania/src/NetworkSyncManager.cpp b/stepmania/src/NetworkSyncManager.cpp index a7c23ba904..dbb214da1c 100644 --- a/stepmania/src/NetworkSyncManager.cpp +++ b/stepmania/src/NetworkSyncManager.cpp @@ -29,6 +29,7 @@ void NetworkSyncManager::Update( float fDeltaTime ) { } NetworkSyncManager::NetworkSyncManager() { NetPlayerClient = new EzSockets; + NetPlayerClient->blocking = false; m_ServerVersion = 0; useSMserver = false; @@ -103,7 +104,13 @@ void NetworkSyncManager::PostStartUp(CString ServerIP) ClearPacket(m_packet); + //Block until responce is received + //Move mode to blocking in order to give CPU back to the + //system, and not wait. + + NetPlayerClient->blocking=true; NetPlayerClient->ReadPack((char*)m_packet.Data,NETMAXBUFFERSIZE); + NetPlayerClient->blocking=false; //int command = Read1(m_packet); Read1(m_packet); @@ -252,9 +259,12 @@ void NetworkSyncManager::StartRequest() ClearPacket(m_packet); //Block until go is recieved. - NetPlayerClient->ReadPack((char *)&m_packet, NETMAXBUFFERSIZE); + //Switch to blocking mode (this is the only + //way I know how to get precievably instantanious results + NetPlayerClient->blocking=true; + NetPlayerClient->ReadPack((char *)&m_packet, NETMAXBUFFERSIZE); + NetPlayerClient->blocking=false; - //Ignore this packet for now } void NetworkSyncManager::DisplayStartupStatus() @@ -278,6 +288,50 @@ void NetworkSyncManager::DisplayStartupStatus() void NetworkSyncManager::Update(float fDeltaTime) { + ProcessInput(); +} + +void NetworkSyncManager::ProcessInput() +{ + //If we're disconnected, just exit + if (NetPlayerClient->state!=NetPlayerClient->skCONNECTED) + return; + + //load new data into buffer + + NetPlayerClient->update(); + + ClearPacket(m_packet); + + while (NetPlayerClient->ReadPack((char *)&m_packet, NETMAXBUFFERSIZE)>0) + { + int command = Read1(m_packet); + LOG->Trace("Received command from server:%d",command-128); + + //Check to make sure command is valid from server + if (command<128) + break; + + command+=-128; + + switch (command) { + case 0: //Ping packet responce + ClearPacket(m_packet); + Write1(m_packet,0); + NetPlayerClient->SendPack((char*)m_packet.Data,m_packet.Position); + break; + case 1: //These are in responce to when/if we send packet 0's + case 2: //This is already taken care of by the blocking code earlier on + case 3: //This is taken care of by the blocking start code + case 4: //Undefined + case 5: //Undefined + break; + case 6: //System message from server + CString SysMSG = ReadNT(m_packet); + SCREENMAN->SystemMessage(SysMSG); + break; + } + } } diff --git a/stepmania/src/NetworkSyncManager.h b/stepmania/src/NetworkSyncManager.h index e2ae67037b..cb3dda0f8d 100644 --- a/stepmania/src/NetworkSyncManager.h +++ b/stepmania/src/NetworkSyncManager.h @@ -35,6 +35,7 @@ public: private: #if !defined(WITHOUT_NETWORKING) + void ProcessInput(); void StartUp(); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index b54532dc53..0002bd1b6c 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1513,6 +1513,7 @@ static void GameLoop() GAMESTATE->Update( fDeltaTime ); SCREENMAN->Update( fDeltaTime ); MEMCARDMAN->Update( fDeltaTime ); + NSMAN->Update( fDeltaTime ); /* Important: Process input AFTER updating game logic, or input will be acting on song beat from last frame */ HandleInputEvents( fDeltaTime );