commit 6710d462
More cleanup. Cannot compile without NETWORK for the moment
git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@151 9d7177f8-192b-0410-8f35-a16a89829b06
Changed files
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(ticks<gameStartedAt)
- bp.time = 0;
- else
- bp.time = (Uint32)(ticks-gameStartedAt);
- for (int i=0; i<6; i++)
- for (int j=0; j<13; j++)
- {
- if (board[i][j]%10<7)
- bp.brick[i][j]=board[i][j]%10+1;
- if ((board[i][j]/1000000)%10==1)
- {
- //Ordinary garbage
- int aInt=0; //N=1, S=2, W=4, E=8
- if (i==0)
- aInt+=4;
- else if ((board[i-1][j])!=(board[i][j]))
- aInt+=4;
- if (i==5)
- aInt+=8;
- else if ((board[i+1][j])!=(board[i][j]))
- aInt+=8;
- if (j==0)
- aInt+=2;
- else if ((board[i][j-1])!=(board[i][j]))
- aInt+=2;
- if ((board[i][j+1])!=(board[i][j]))
- aInt+=1;
- switch (aInt)
- {
- case 8:
- bp.brick[i][j]=8;
- break;
- case 7:
- bp.brick[i][j]=10;
- break;
- case 11:
- bp.brick[i][j]=11;
- break;
- case 9:
- bp.brick[i][j]=12;
- break;
- case 5:
- bp.brick[i][j]=13;
- break;
- case 6:
- bp.brick[i][j]=14;
- break;
- case 10:
- bp.brick[i][j]=15;
- break;
- case 3: //M
- bp.brick[i][j]=16;
- break;
- case 0:
- bp.brick[i][j]=17;
- break;
- case 1:
- bp.brick[i][j]=18;
- break;
- case 2:
- bp.brick[i][j]=19;
- break;
- case 4:
- bp.brick[i][j]=20;
- break;
- default:
- bp.brick[i][j]=0;
- };
- //cout << "garbage added to replay: " << aInt << endl;
- }
- if ((board[i][j]/1000000)%10==2)
- {
- //Gray garbage
- bp.brick[i][j]=21;
- }
- if ((board[i][j]/BLOCKHANG)%10==1) //If "get ready"
- bp.brick[i][j]+=30;
- }
- bp.cursorX = (Uint8)cursorx;
- bp.cursorY = (Uint8)cursory;
- bp.score = (Uint32)score;
- bp.pixels = (Uint8)pixels;
- bp.chain = (Uint8)chain;
- bp.speed = (Uint8)speedLevel;
- Uint8 result = 0;
- if (bGameOver)
- result+=1;
- if (hasWonTheGame)
- result+=2;
- if (bDraw)
- result+=4;
- bp.result = (Uint8)result;
- return bp;
-}
-
-//Takes a package and sets the board like it
-void BlockGame::setBoard(boardPackage bp)
-{
- //gameStartedAt = ticks-bp.time;
- for (int i=0; i<6; i++)
- for (int j=0; j<13; j++)
- {
- //if(bp.brick[i][j]/8==0)
- board[i][j]=bp.brick[i][j]-1;
- //else
- // board[i][j]=-1;
- }
- cursorx=bp.cursorX;
- cursory=bp.cursorY;
- score=bp.score;
- pixels=bp.pixels;
- chain=bp.chain;
- speedLevel=bp.speed;
- Uint8 result = bp.result;
- bGameOver = false; //Make sure that it is initialized!
- if(result%2==1)
- {
- bGameOver=true;
- result-=1;
- }
- if (result%4==2)
- {
- hasWonTheGame = true;
- result-=2;
- }
- if (result==4)
- {
- bDraw = true;
- }
-}
//Test if LineNr is an empty line, returns false otherwise.
bool BlockGame::LineEmpty(int lineNr)
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp
index 50153f1..1a92851 100644
--- a/source/code/BlockGame.hpp
+++ b/source/code/BlockGame.hpp
@@ -229,10 +229,6 @@ public:
#endif
//Prints "draw" and ends the game
void setDraw();
- //Function to get a boardpackage
- boardPackage getPackage();
- //Takes a package and sets the board like it
- void setBoard(boardPackage bp);
private:
#if NETWORK
#define garbageStackSize 10
diff --git a/source/code/NetworkThing.hpp b/source/code/NetworkThing.hpp
index 9308462..95740cf 100644
--- a/source/code/NetworkThing.hpp
+++ b/source/code/NetworkThing.hpp
@@ -319,10 +319,6 @@ public:
memcpy(&tick,event.packet->data,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" <<endl;
}
@@ -68,6 +68,7 @@ public:
void doAction();
};
+
Button_changekey::Button_changekey(SDLKey* key, string keyname)
{
m_key2change = key;
@@ -104,73 +105,83 @@ void InitMenues()
void runGame(int gametype,int level);
-void runSinglePlayerEndless(Button* b)
+static void runSinglePlayerEndless(Button* b)
{
runGame(0,0);
}
-void runSinglePlayerTimeTrial(Button* b)
+static void runSinglePlayerTimeTrial(Button* b)
{
runGame(1,0);
}
-void runStageClear(Button* b)
+static void runStageClear(Button* b)
{
runGame(2,0);
}
-void runSinglePlayerPuzzle(Button* b)
+static void runSinglePlayerPuzzle(Button* b)
{
runGame(3,0);
}
-void runSinglePlayerVs(Button* b)
+static void runSinglePlayerVs(Button* b)
{
runGame(4,b->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<char*>(&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<char*>(&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;