Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

MainMultiplay.cpp File Reference


Detailed Description

Implements the MultiplayMenu stuffs defined in MainFuncs.h.

Definition in file MainMultiplay.cpp.

#include "Network.h"
#include "Sound.h"
#include "Typer.h"
#include "..\AEngine\AEngine.h"
#include "Overhead.h"
#include "MainFuncs.h"
#include "Globals.h"

Include dependency graph for MainMultiplay.cpp:

Include dependency graph

Go to the source code of this file.

Namespaces

namespace  Steps

Functions

Box butMultiName (0.117f, 0.168f, 0.466f, 0.229f)
Box butMultiHost (0.120f, 0.258f, 0.324f, 0.305f)
Box butMultiJoin (0.119f, 0.349f, 0.325f, 0.402f)
Box butMultiIP (0.375f, 0.345f, 0.723f, 0.405f)
Box butMultiChatMsg (0.394f, 0.845f, 0.825f, 0.905f)
Box butMultiChat (0.852f, 0.845f, 0.953f, 0.900f)
Box butMultiLaunch (0.332f, 0.921f, 0.588f, 0.981f)
Box butMultiAbort (0.667f, 0.921f, 0.794f, 0.981f)
void switchToMultiplayMenu ()
void processIncomingMessages ()
void updateMultiplayMenu ()
void renderMultiplayMenu ()

Variables

TyperpTyper
Typer typerName
Typer typerIP
Typer typerChatMsg
int step
list< string > chatLog


Function Documentation

Box butMultiAbort 0.    667f,
0.    921f,
0.    794f,
0.    981f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

Box butMultiChat 0.    852f,
0.    845f,
0.    953f,
0.    900f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

Box butMultiChatMsg 0.    394f,
0.    845f,
0.    825f,
0.    905f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

Box butMultiHost 0.    120f,
0.    258f,
0.    324f,
0.    305f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

Box butMultiIP 0.    375f,
0.    345f,
0.    723f,
0.    405f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

Box butMultiJoin 0.    119f,
0.    349f,
0.    325f,
0.    402f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

Box butMultiLaunch 0.    332f,
0.    921f,
0.    588f,
0.    981f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

Box butMultiName 0.    117f,
0.    168f,
0.    466f,
0.    229f
 

Referenced by renderMultiplayMenu(), and updateMultiplayMenu().

void processIncomingMessages  
 

Definition at line 71 of file MainMultiplay.cpp.

References chatLog, NetworkMessages::COMMAND_CHAT(), NetworkMessages::COMMAND_START_GAME(), NetworkSubsystem::enQueueMsg(), net_recv(), Overhead::overhead_init(), step, and sys_setRandSeed().

Referenced by updateMultiplayMenu().

00072 {
00073         if( step != Steps::readyToLaunch ) return;              // no network connection yet
00074 
00075         string cmd;
00076         while( (cmd=net_recv()).length() > 0 )
00077         {
00078                 istringstream strm(cmd.c_str());
00079                 
00080                 string action;
00081                 strm >> action;
00082                 if (action == COMMAND_START_GAME)
00083                 {                       
00084                         string tmp;
00085                         strm >> tmp; //commitTime string
00086                         strm >> tmp; //commitTime int
00087                         strm >> tmp; //RANDOM_SEED_VALUE
00088                         int seed;
00089                         strm >> seed;
00090                         sys_setRandSeed(seed);
00091 
00092                         overhead_init();                                // switch to overhead
00093                         mode = MainModes::overhead;
00094                 }
00095                 else if (action == COMMAND_CHAT)                                // a chat msg
00096                 {
00097                         string msg;
00098                         getline(strm,msg);
00099                         chatLog.push_back( msg );
00100                 }
00101                 else
00102                         NetworkSubsystem::enQueueMsg(cmd);
00103         }
00104 }

void renderMultiplayMenu  
 

Definition at line 192 of file MainMultiplay.cpp.

References Globals::artWork, butMultiAbort(), butMultiChat(), butMultiChatMsg(), butMultiHost(), butMultiIP(), butMultiJoin(), butMultiLaunch(), butMultiName(), chatLog, drawBox(), Typer::getString(), input_getMouseX(), input_getMouseY(), Box::isContain(), Box::left, net_getAllPlayers(), overlay_image(), overlay_text(), overlay_textOut(), pTyper, step, Box::top, typerChatMsg, typerIP, typerName, UINT, and Vec2D.

Referenced by main_render().

00193 {
00194         Vec2D mouse( input_getMouseX(), input_getMouseY() );                                            // Mouse Cursor
00195         overlay_image( Globals::artWork->mouse, mouse+Vec2D(0.025f,0.025f), Vec2D(0.05f,0.05f), BlendModes::KEY );
00196 
00197         // main menu screen
00198         overlay_image( artWork->main_multiplayTex, Vec2D(0.5f,0.5f), Vec2D(1.0f,1.0f) );
00199 
00200         // highlight the button that the mouse is currently over
00201         if( butMultiName.isContain(mouse) )             drawBox( butMultiName, Colors::gray );
00202         if( butMultiHost.isContain(mouse) )             drawBox( butMultiHost, Colors::yellow );
00203         if( butMultiJoin.isContain(mouse) )             drawBox( butMultiJoin, Colors::yellow );
00204         if( butMultiIP.isContain(mouse) )               drawBox( butMultiIP, Colors::gray );
00205         if( butMultiChatMsg.isContain(mouse) )  drawBox( butMultiChatMsg, Colors::gray );
00206         if( butMultiChat.isContain(mouse) )             drawBox( butMultiChat, Colors::yellow );
00207         if( butMultiLaunch.isContain(mouse) )   drawBox( butMultiLaunch, Colors::yellow );
00208         if( butMultiAbort.isContain(mouse) )    drawBox( butMultiAbort, Colors::yellow );
00209 
00210         // typer strings
00211         overlay_text() << typerName.getString();
00212         overlay_textOut( Vec2D( butMultiName.left+0.008f, butMultiName.top+0.017f), 1.0f, Colors::white );
00213         overlay_text() << typerIP.getString();
00214         overlay_textOut( Vec2D( butMultiIP.left+0.008f, butMultiIP.top+0.017f), 1.0f, Colors::white );
00215         overlay_text() << typerChatMsg.getString();
00216         overlay_textOut( Vec2D( butMultiChatMsg.left+0.008f, butMultiChatMsg.top+0.017f), 1.0f, Colors::white );
00217 
00218         // selected typer
00219         if( pTyper==&typerName )                drawBox( butMultiName, Colors::white );
00220         if( pTyper==&typerIP )                  drawBox( butMultiIP, Colors::white );
00221         if( pTyper==&typerChatMsg )             drawBox( butMultiChatMsg, Colors::white );
00222 
00223         // player list
00224         if( step==Steps::readyToLaunch )
00225         {
00226                 vector<string> &playersList = net_getAllPlayers();
00227                 for( UINT i=0; i<playersList.size(); i++ )
00228                         overlay_text() << playersList[i] << endl;
00229                 overlay_textOut( Vec2D(0.065f, 0.522f) );
00230         }
00231 
00232         // chat log
00233         while( chatLog.size()>9 ) chatLog.pop_front();
00234         for( list<string>::iterator iter=chatLog.begin(); iter!=chatLog.end(); iter++ ) 
00235                 overlay_text() << (*iter) << endl;
00236         overlay_textOut( Vec2D( 0.440f, 0.527f ), 1.0f, Colors::white );        
00237 }

void switchToMultiplayMenu  
 

Definition at line 59 of file MainMultiplay.cpp.

References pTyper, step, typerChatMsg, typerIP, and typerName.

Referenced by updateMainMenu().

00060 {
00061         mode = MainModes::multiplayMenu;
00062 
00063         typerName = Typer("Your Name");
00064         typerIP   = Typer("Host IP");
00065         typerChatMsg = Typer("Hello!");
00066         pTyper = &typerName;    
00067 
00068         step = Steps::enterName;
00069 }

void updateMultiplayMenu  
 

Definition at line 106 of file MainMultiplay.cpp.

References butMultiAbort(), butMultiChat(), butMultiChatMsg(), butMultiHost(), butMultiIP(), butMultiJoin(), butMultiLaunch(), butMultiName(), chatLog, NetworkMessages::COMMAND_CHAT(), NetworkMessages::COMMAND_START_GAME(), NetworkMessages::COMMIT_TIME(), Globals::currGameTick, Typer::getString(), Typer::input(), input_getMouseX(), input_getMouseY(), input_isKeyPressed(), input_isMouseLBClicked(), Box::isContain(), net_acceptMorePlayers(), net_amIServer(), net_connectToServer(), net_finalizeGame(), net_getSelfIP(), net_runAsServer(), net_send(), processIncomingMessages(), pTyper, NetworkMessages::RANDOM_SEED_VALUE(), step, switchToMainMenu(), sys_randInt(), typerChatMsg, typerIP, typerName, and Vec2D.

Referenced by main_update().

00107 {
00108         Vec2D mouse( input_getMouseX(), input_getMouseY() );
00109         if( input_isMouseLBClicked() )
00110         {
00111                 if( butMultiAbort.isContain(mouse) )                    // abort
00112                 {
00113                         //net_disconnect();
00114                         switchToMainMenu();
00115                         step = Steps::enterName;
00116                         return;
00117                 }
00118 
00119                 // select typer
00120                 if( butMultiName.isContain(mouse) )             pTyper = &typerName;
00121                 if( butMultiIP.isContain(mouse) )               pTyper = &typerIP;
00122                 if( butMultiChatMsg.isContain(mouse) )  pTyper = &typerChatMsg;
00123 
00124                 // host or join
00125                 if(step==Steps::enterName && typerName.getString() != "Your Name") step = Steps::hostOrJoin;
00126                 if( step==Steps::hostOrJoin )
00127                 {
00128                         if( butMultiHost.isContain(mouse) )                             // Host Game
00129                         {
00130                                 step = Steps::readyToLaunch;                            
00131                                 net_runAsServer( net_getSelfIP(), typerName.getString(), 8 );
00132                                 chatLog.push_back( "Hosting Process Complete.  IP = " + net_getSelfIP() );
00133                         }
00134 
00135                         if( butMultiJoin.isContain(mouse) )                             // Join Game
00136                         {                               
00137                                 if( !net_connectToServer( typerIP.getString(), typerName.getString() ))
00138                                 {
00139                                         chatLog.push_back( "Cannot Join with That Host" );
00140                                         return;
00141                                 }
00142                                 chatLog.push_back( "Joining Process Complete." );
00143                                 step = Steps::readyToLaunch;
00144                         }
00145                 }
00146 
00147                 // launch
00148                 if( step==Steps::readyToLaunch && butMultiLaunch.isContain(mouse) )
00149                         if( net_amIServer() )
00150                         {                               
00151                                 currGameTick = 0;
00152                                 stringstream sstr;
00153                                 
00154                                 if( net_amIServer() ) net_finalizeGame();
00155 
00156                                 sstr << COMMAND_START_GAME << " " << COMMIT_TIME << " " << currGameTick << " " << RANDOM_SEED_VALUE << " " << sys_randInt();
00157                                 net_send(sstr.str());
00158                         }
00159 
00160                 // chat by clicking Chat button
00161                 if( step==Steps::readyToLaunch && butMultiChat.isContain(mouse) )
00162                 {
00163                         ostringstream strm;
00164                         strm << COMMAND_CHAT << " [" << typerName.getString() << "] " << typerChatMsg.getString();
00165                         net_send(strm.str());
00166                         typerChatMsg = Typer();
00167                 }
00168         }
00169 
00170         // type to InputString Typer Box
00171         if( step==Steps::enterName || step==Steps::hostOrJoin )                 // type name or ip
00172                 if( pTyper==&typerName || pTyper==&typerIP )
00173                         pTyper->input();
00174         if( step==Steps::readyToLaunch && pTyper==&typerChatMsg )               // type chat
00175                 pTyper->input();
00176 
00177         // chat by pressing enter while chat box is active
00178         if( step==Steps::readyToLaunch && input_isKeyPressed(KeyCodes::key_RETURN) && pTyper==&typerChatMsg )
00179         {
00180                 ostringstream strm;
00181                 strm << COMMAND_CHAT << " [" << typerName.getString() << "] " << typerChatMsg.getString();
00182                 net_send(strm.str());
00183                 typerChatMsg = Typer();
00184         }
00185 
00186         // check for more players
00187         if( step==Steps::readyToLaunch ) net_acceptMorePlayers();
00188 
00189         processIncomingMessages();
00190 }


Variable Documentation

list<string> chatLog
 

Definition at line 56 of file MainMultiplay.cpp.

Referenced by processIncomingMessages(), renderMultiplayMenu(), and updateMultiplayMenu().

Typer* pTyper
 

Definition at line 35 of file MainMultiplay.cpp.

Referenced by renderMultiplayMenu(), switchToMultiplayMenu(), and updateMultiplayMenu().

int step
 

Definition at line 47 of file MainMultiplay.cpp.

Referenced by processIncomingMessages(), renderMultiplayMenu(), switchToMultiplayMenu(), and updateMultiplayMenu().

Typer typerChatMsg
 

Definition at line 36 of file MainMultiplay.cpp.

Referenced by renderMultiplayMenu(), switchToMultiplayMenu(), and updateMultiplayMenu().

Typer typerIP
 

Definition at line 36 of file MainMultiplay.cpp.

Referenced by renderMultiplayMenu(), switchToMultiplayMenu(), and updateMultiplayMenu().

Typer typerName
 

Definition at line 36 of file MainMultiplay.cpp.

Referenced by renderMultiplayMenu(), switchToMultiplayMenu(), and updateMultiplayMenu().


Generated on Wed Apr 23 05:51:27 2003 for Modern Warfare by doxygen1.3-rc2