diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 43aab07..d795dda 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -572,141 +572,7 @@ void BlockGame::setDraw() Stats::getInstance()->addOne("totalDraws"); } -//Function to get a boardpackage -boardPackage BlockGame::getPackage() -{ - boardPackage bp; - if(ticksdata,sizeof(Sint32)); memcpy(&action,event.packet->data+sizeof(Sint32),sizeof(Sint32)); param = (const char*) (event.packet->data+sizeof(Sint32)*3); - //boardPackage bpack; - //cout << "Package size: "<< event.packet->dataLength << " should be: " << sizeof(boardPackage) << endl; - //memcpy(&bpack,(const char*)event.packet->data,sizeof(boardPackage)); - //bgAway->setBoard(bpack); bgAway->PerformAction(tick,action,param); } if (event.channelID==1) //reliable (used for GameOver notifications only!) diff --git a/source/code/main.cpp b/source/code/main.cpp index 61b5132..627244a 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -3020,6 +3020,12 @@ void changePuzzleLevels() } +#if NETWORK +#include "NetworkThing.hpp" +//#include "MenuSystem.h" + NetworkThing nt; +#endif + static BlockGameSdl *player1; static BlockGameSdl *player2; @@ -3120,10 +3126,20 @@ void StartReplay(string filename) player1->playReplay(50,100,SDL_GetTicks(),r1); } -#if NETWORK -#include "NetworkThing.hpp" -//#include "MenuSystem.h" -#endif +void StartHostServer() +{ + player1->SetGameOver(); + player2->SetGameOver(); + nt.startServer(); +} + +void StartJoinServer() +{ + player1->SetGameOver(); + player2->SetGameOver(); + nt.connectToServer(Config::getInstance()->getString("address0")); +} + //The main function, quite big... too big int main(int argc, char *argv[]) @@ -3495,7 +3511,7 @@ int main(int argc, char *argv[]) #if NETWORK - NetworkThing nt = NetworkThing(); + //NetworkThing nt = NetworkThing(); nt.setBGpointers(&theGame,&theGame2); #endif @@ -3646,7 +3662,7 @@ int runGame(int gametype, int level) #if NETWORK - NetworkThing nt = NetworkThing(); + //NetworkThing nt = NetworkThing(); nt.setBGpointers(&theGame,&theGame2); #endif @@ -3729,6 +3745,12 @@ int runGame(int gametype, int level) case 11: StartTwoPlayerVs(); break; + case 12: + StartHostServer(); + break; + case 13: + StartJoinServer(); + break; case 0: default: StartSinglePlayerEndless(); diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index ce0cb05..29392ad 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp @@ -30,7 +30,7 @@ Copyright (C) 2011 Poul Sander using namespace std; //Menu -void PrintHi() +static void PrintHi(Button* b) { cout << "Hi" <iGeneric1); } -void runTwoPlayerTimeTrial(Button* b) +static void runTwoPlayerTimeTrial(Button* b) { runGame(10,0); } -void runTwoPlayerVs(Button* b) +static void runTwoPlayerVs(Button* b) { runGame(11,0); } -void buttonActionMusic(Button* b) +static void runHostGame(Button* b) +{ + runGame(12,0); +} + +static void runJoinGame(Button* b) +{ + runGame(13,0); +} + +static void buttonActionMusic(Button* b) { MusicEnabled = !MusicEnabled; b->setLabel(MusicEnabled? "Music: On" : "Music: Off"); } -void buttonActionSound(Button* b) +static void buttonActionSound(Button* b) { SoundEnabled = !SoundEnabled; b->setLabel(SoundEnabled? _("Sound: On") : _("Sound: Off") ); } -void buttonActionFullscreen(Button* b) +static void buttonActionFullscreen(Button* b) { bFullscreen = !bFullscreen; b->setLabel(bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") ); ResetFullscreen(); } -void buttonActionPlayer1Name(Button *b) +static void buttonActionPlayer1Name(Button *b) { if (OpenDialogbox(200,100,player1name)) return; //must save if true } -void buttonActionPlayer2Name(Button *b) +static void buttonActionPlayer2Name(Button *b) { if (OpenDialogbox(200,100,player2name)) return; //must save if true } -void buttonActionPortChange(Button *b) +static void buttonActionPortChange(Button *b) { char port[30]; snprintf(port,sizeof(port),"%i",Config::getInstance()->getInt("portv4") ); @@ -183,7 +194,7 @@ void buttonActionPortChange(Button *b) } } -void buttonActionIpChange(Button *b) +static void buttonActionIpChange(Button *b) { char ip[30]; snprintf(ip,sizeof(ip),"%s",Config::getInstance()->getString("address0").c_str() ); @@ -196,7 +207,7 @@ void buttonActionIpChange(Button *b) } } -void buttonActionHighscores(Button *b) +static void buttonActionHighscores(Button *b) { OpenScoresDisplay(); } @@ -229,7 +240,7 @@ static void ChangeKeysMenu2(Button *b) ChangeKeysMenu(2); } -void ConfigureMenu(Button *b) +static void ConfigureMenu(Button *b) { Menu cm(&screen,_("Configuration"),true); Button bMusic,bSound,buttonFullscreen,bPlayer1Name,bPlayer2Name; @@ -258,7 +269,7 @@ void ConfigureMenu(Button *b) cm.run(); } -void SinglePlayerVsMenu(Button *b) +static void SinglePlayerVsMenu(Button *b) { Menu spvs(&screen,_("Single player VS"),true); Button d1,d2,d3,d4,d5,d6,d7; @@ -300,10 +311,14 @@ void SinglePlayerVsMenu(Button *b) spvs.run(); } -void NetworkMenu(Button *b) +static void NetworkMenu(Button *b) { Menu nm(&screen,_("Network"),true); Button bPort, bIp, bHost, bJoin; + bHost.setLabel(_("Host game")); + bHost.setAction(runHostGame); + bJoin.setLabel(_("Join game")); + bJoin.setAction(runJoinGame); format fi(_("Address: %1%") ); fi % Config::getInstance()->getString("address0"); bIp.setLabel(fi.str()); @@ -312,13 +327,15 @@ void NetworkMenu(Button *b) fp % Config::getInstance()->getString("portv4"); bPort.setLabel(fp.str()); bPort.setAction(buttonActionPortChange); + nm.addButton(&bHost); + nm.addButton(&bJoin); nm.addButton(&bIp); nm.addButton(&bPort); nm.run(); } -void MultiplayerMenu(Button *b) +static void MultiplayerMenu(Button *b) { Menu mm(&screen,_("Multiplayer"),true); Button bTT, bVs, bNet; diff --git a/source/code/replay.cpp b/source/code/replay.cpp index 0fe4408..f20f2fa 100644 --- a/source/code/replay.cpp +++ b/source/code/replay.cpp @@ -79,7 +79,6 @@ bool Replay::saveReplay(string filename,Replay p2) if (saveFile) { Uint32 version = 4; - boardPackage bp; saveFile.write(reinterpret_cast(&version),sizeof(Uint32)); //Fileversion Uint8 nrOfReplays = 2; @@ -154,7 +153,6 @@ bool Replay::loadReplay2(string filename) { case 3: Uint8 nrOfPlayers; - boardPackage bp; loadFile.read(reinterpret_cast(&nrOfPlayers),sizeof(Uint8)); if (nrOfPlayers<2) { diff --git a/source/code/replay.h b/source/code/replay.h index 3119f4b..8237a4a 100644 --- a/source/code/replay.h +++ b/source/code/replay.h @@ -39,20 +39,6 @@ able to give a realistic replay using namespace std; -//board_package, stores a board can be used for network play and replay -struct boardPackage //92 bytes -{ - Uint32 time; //game time - Uint8 brick[6][13]; - Uint8 pixels; //pixels pushed - Uint8 cursorX; //Cursor coordinate - Uint8 cursorY; // -||- - Uint32 score; - Uint8 speed; - Uint8 chain; - Uint8 result; //0=none,1=gameOver,2=winner,4=draw -}; - struct Action { Sint32 time;