Move map download progress to players list, so you can still chat while it happens. Also update players list instantly, instead of every 2 seconds (except slider changes, which are updated every 0.5 seconds). Also fix taken position detection (fixes bug #1137).

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@8602 4a71c877-e1ca-e34f-864e-861f7616d084
master
Guangcong Luo 2009-12-04 05:50:40 +00:00 committed by Git SVN Gateway
parent 8edc0bd26a
commit aabbca68d8
6 changed files with 56 additions and 22 deletions

View File

@ -212,6 +212,10 @@ static BOOL allow_joining = false;
static bool server_not_there = false;
static GAMESTRUCT game;
// update flags
bool netPlayersUpdated;
int mapDownloadProgress;
/**
* Socket used for these purposes:
* * Host a game, be a server.
@ -2306,6 +2310,7 @@ static BOOL NETprocessSystemMessage(void)
case NET_PLAYER_STATS:
{
recvMultiStats();
netPlayersUpdated = true;
break;
}
case NET_PLAYER_INFO:
@ -2346,6 +2351,7 @@ static BOOL NETprocessSystemMessage(void)
{
NETBroadcastPlayerInfo(index);
}
netPlayersUpdated = true;
break;
}
case NET_PLAYER_JOINED:
@ -2360,6 +2366,7 @@ static BOOL NETprocessSystemMessage(void)
(unsigned int)index, tcp_socket);
MultiPlayerJoin(index);
netPlayersUpdated = true;
break;
}
// This message type is when player is leaving 'nicely', and socket is still valid.
@ -3233,6 +3240,9 @@ BOOL NEThostGame(const char* SessionName, const char* PlayerName,
debug(LOG_NET, "NEThostGame(%s, %s, %d, %d, %d, %d, %u)", SessionName, PlayerName,
one, two, three, four, plyrs);
mapDownloadProgress = 100;
netPlayersUpdated = true;
NETaddRedirects();
NET_InitPlayers();
NetPlay.maxPlayers = MAX_PLAYERS;
@ -3483,6 +3493,9 @@ BOOL NETjoinGame(UDWORD gameNumber, const char* playername)
debug(LOG_NET, "Trying to join gameNumber (%u)...", gameNumber);
mapDownloadProgress = 100;
netPlayersUpdated = true;
if (hostname == masterserver_name)
{
hostname = NULL;

View File

@ -226,6 +226,10 @@ typedef struct {
extern NETPLAY NetPlay;
extern NETMSG NetMsg;
// update flags
extern bool netPlayersUpdated;
extern int mapDownloadProgress;
// ////////////////////////////////////////////////////////////////////////
// functions available to you.
extern int NETinit(BOOL bFirstCall); // init

View File

@ -1454,20 +1454,22 @@ static void addColourChooser(UDWORD player)
}
//add the position chooser.
for(i=0;i<game.maxPlayers;i++)
for (i=0;i<game.maxPlayers;i++)
{
addMultiBut(psWScreen,MULTIOP_COLCHOOSER_FORM, MULTIOP_PLAYCHOOSER+i,
(i*(iV_GetImageWidth(FrontImages,IMAGE_PLAYER0) +5)+7),//x
23, //y
iV_GetImageWidth(FrontImages,IMAGE_WEE_GUY)+7, //w
iV_GetImageHeight(FrontImages,IMAGE_WEE_GUY), //h
"Player number", IMAGE_WEE_GUY, IMAGE_WEE_GUY, 10 + i);
}
if(isHumanPlayer(NetPlay.players[i].position) && i!=selectedPlayer )
{
widgSetButtonState(psWScreen,MULTIOP_PLAYCHOOSER+i ,WBUT_DISABLE);
}
for (i=0;i<game.maxPlayers;i++)
{
if (isHumanPlayer(i) && i!=selectedPlayer )
{
widgSetButtonState(psWScreen, MULTIOP_PLAYCHOOSER+NetPlay.players[i].position, WBUT_DISABLE);
}
}
bColourChooserUp = true;
@ -1485,6 +1487,7 @@ static void changeTeam(UBYTE player, UBYTE team)
NetPlay.players[player].team = team;
debug(LOG_WZ, "set %d as new team for player %d", team, player);
NETBroadcastPlayerInfo(player);
netPlayersUpdated = true;
}
static BOOL SendTeamRequest(UBYTE player, UBYTE chosenTeam)
@ -1527,9 +1530,11 @@ BOOL recvTeamRequest()
return false;
}
resetReadyStatus(false);
changeTeam(player, team);
if (NetPlay.players[player].team != team)
{
resetReadyStatus(false);
}
changeTeam(player, team); // we do this regardless, in case of sync issues
return true;
}
@ -1580,6 +1585,7 @@ static BOOL changeReadyStatus(UBYTE player, BOOL bReady)
drawReadyButton(player);
NetPlay.players[player].ready = bReady;
NETBroadcastPlayerInfo(player);
netPlayersUpdated = true;
return true;
}
@ -1602,6 +1608,7 @@ static BOOL changePosition(UBYTE player, UBYTE position)
}
}
debug(LOG_ERROR, "Failed to swap positions for player %d, position %d", (int)player, (int)position);
netPlayersUpdated = true;
return false;
}
@ -1621,6 +1628,7 @@ static BOOL changeColour(UBYTE player, UBYTE col)
NetPlay.players[player].colour = col;
NETBroadcastPlayerInfo(player);
NETBroadcastPlayerInfo(i);
netPlayersUpdated = true;
return true;
}
}
@ -2341,6 +2349,7 @@ static void processMultiopWidgets(UDWORD id)
game.alliance = NO_ALLIANCES; //0;
resetReadyStatus(false);
netPlayersUpdated = true;
if(bHosted)
{
@ -2357,6 +2366,7 @@ static void processMultiopWidgets(UDWORD id)
game.alliance = ALLIANCES; //1;
resetReadyStatus(false);
netPlayersUpdated = true;
if(bHosted)
{
@ -2849,7 +2859,6 @@ void runMultiOptions(void)
frontendMultiMessages();
// keep sending the map if required.
if(bSendingMap)
{
@ -2857,9 +2866,9 @@ void runMultiOptions(void)
}
// update boxes?
if(lastrefresh > gameTime)lastrefresh= 0;
if ((gameTime - lastrefresh) >2000)
if (netPlayersUpdated || (NetPlay.isHost && mouseDown(MOUSE_LMB) && gameTime-lastrefresh>500))
{
netPlayersUpdated = false;
lastrefresh= gameTime;
if (!multiRequestUp && (bHosted || ingame.localJoiningInProgress))
{
@ -3056,6 +3065,8 @@ BOOL startMultiOptions(BOOL bReenter)
game.maxPlayers = iniparser_getint(dict, "challenge:MaxPlayers", game.maxPlayers); // TODO, read from map itself, not here!!
game.scavengers = iniparser_getboolean(dict, "challenge:Scavengers", game.scavengers);
game.alliance = ALLIANCES_TEAMS;
netPlayersUpdated = true;
mapDownloadProgress = 100;
game.power = iniparser_getint(dict, "challenge:Power", game.power);
game.base = iniparser_getint(dict, "challenge:Bases", game.base + 1) - 1; // count from 1 like the humans do
for (i = 0; i < MAX_PLAYERS; i++)
@ -3273,7 +3284,16 @@ void displayPlayer(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *p
//bluboxes.
drawBlueBox(x,y,psWidget->width,psWidget->height); // right
if (ingame.localOptionsReceived && NetPlay.players[j].allocated) // only draw if real player!
if (mapDownloadProgress != 100 && j == selectedPlayer)
{
static char mapProgressString[MAX_STR_LENGTH] = {'\0'};
snprintf(mapProgressString, MAX_STR_LENGTH, _("Map: %d%% downloaded"), mapDownloadProgress);
iV_SetFont(font_regular); // font
iV_SetTextColour(WZCOL_TEXT_BRIGHT);
iV_DrawText(mapProgressString, x + 5, y + 22);
return;
}
else if (ingame.localOptionsReceived && NetPlay.players[j].allocated) // only draw if real player!
{
//bluboxes.
drawBlueBox(x,y,psWidget->width,psWidget->height); // right
@ -3754,6 +3774,7 @@ void setLockedTeamsMode(void)
widgSetButtonState(psWScreen, MULTIOP_ALLIANCE_Y,0);
widgSetButtonState(psWScreen, MULTIOP_ALLIANCE_TEAMS,WBUT_LOCK);
game.alliance = ALLIANCES_TEAMS; //2
netPlayersUpdated = true;
if(bHosted)
{
sendOptions();

View File

@ -238,6 +238,7 @@ BOOL MultiPlayerLeave(UDWORD playerIndex)
CBPlayerLeft = playerIndex;
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_PLAYERLEFT);
netPlayersUpdated = true;
return true;
}

View File

@ -174,6 +174,7 @@ void recvOptions()
NETuint8_t(&alliances[i][j]);
}
}
netPlayersUpdated = true;
// Free any structure limits we may have in-place
if (ingame.numStructureLimits)

View File

@ -1580,10 +1580,8 @@ UBYTE sendMap(void)
// Another player is broadcasting a map, recv a chunk. Returns false if not yet done.
BOOL recvMapFileData()
{
UBYTE done;
done = NETrecvFile();
if(done == 100)
mapDownloadProgress = NETrecvFile();
if (mapDownloadProgress == 100)
{
addConsoleMessage("MAP DOWNLOADED!",DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
sendTextMessage("MAP DOWNLOADED",true); //send
@ -1598,11 +1596,6 @@ BOOL recvMapFileData()
}
return true;
}
else
{
flushConsoleMessages();
CONPRINTF(ConsoleString,(ConsoleString,"MAP:%d%%",done));
}
return false;
}
@ -1919,4 +1912,5 @@ void resetReadyStatus(bool bSendOptions)
{
sendOptions();
}
netPlayersUpdated = true;
}