LINK: Kill the last global variables
git-svn-id: https://svn.code.sf.net/p/vbam/code/branches/bgk-link@1134 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
50fe276a0f
commit
8896c123c4
|
@ -8,7 +8,7 @@
|
|||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
int vbaid = 0;
|
||||
static int vbaid = 0;
|
||||
const char *MakeInstanceFilename(const char *Input)
|
||||
{
|
||||
if (vbaid == 0)
|
||||
|
@ -256,7 +256,7 @@ static sf::IPAddress joybusHostAddr = sf::IPAddress::LocalHost;
|
|||
u8 tspeed = 3;
|
||||
u8 transfer = 0;
|
||||
static LINKDATA *linkmem = NULL;
|
||||
int linkid = 0;
|
||||
static int linkid = 0;
|
||||
#if (defined __WIN32__ || defined _WIN32)
|
||||
HANDLE linksync[4];
|
||||
#else
|
||||
|
@ -274,7 +274,7 @@ char linkevent[] =
|
|||
#endif
|
||||
"VBA link event ";
|
||||
static int i, j;
|
||||
int linktimeout = 1000;
|
||||
static int linktimeout = 1000;
|
||||
static LANLINKDATA lanlink;
|
||||
u16 linkdata[4];
|
||||
static lserver ls;
|
||||
|
@ -1343,6 +1343,20 @@ void GetLinkServerHost(char * const host, size_t size) {
|
|||
strncpy(host, lc.serveraddr.ToString().c_str(), size);
|
||||
}
|
||||
|
||||
void SetLinkTimeout(int value) {
|
||||
linktimeout = value;
|
||||
}
|
||||
|
||||
int GetLinkPlayerId() {
|
||||
if (GetLinkMode() == LINK_DISCONNECTED) {
|
||||
return -1;
|
||||
} else if (linkid > 0) {
|
||||
return linkid;
|
||||
} else {
|
||||
return vbaid;
|
||||
}
|
||||
}
|
||||
|
||||
static void ReInitLink()
|
||||
{
|
||||
int f = linkmem->linkflags;
|
||||
|
|
|
@ -79,6 +79,14 @@ extern bool SetLinkServerHost(const char *host);
|
|||
*/
|
||||
extern void GetLinkServerHost(char * const host, size_t size);
|
||||
|
||||
/**
|
||||
* Set the value in milliseconds of the timeout after which a connection is
|
||||
* deemed lost.
|
||||
*
|
||||
* @param value timeout
|
||||
*/
|
||||
extern void SetLinkTimeout(int value);
|
||||
|
||||
/**
|
||||
* Verify that the link between the emulators is still active
|
||||
*/
|
||||
|
@ -89,6 +97,13 @@ extern void CheckLinkConnection();
|
|||
*/
|
||||
extern void CloseLink();
|
||||
|
||||
/**
|
||||
* Get the id of the player of this VBA instance
|
||||
*
|
||||
* @return id. -1 means disconnected, 0 means master, > 0 means slave
|
||||
*/
|
||||
extern int GetLinkPlayerId();
|
||||
|
||||
// register definitions
|
||||
#define COMM_SIODATA32_L 0x120
|
||||
#define COMM_SIODATA32_H 0x122
|
||||
|
@ -126,9 +141,6 @@ extern void StartLink(u16);
|
|||
extern void StartGPLink(u16);
|
||||
extern void LinkUpdate(int);
|
||||
extern void CleanLocalLink();
|
||||
extern int vbaid;
|
||||
extern int linktimeout;
|
||||
extern int linkid;
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -2134,6 +2134,8 @@ EVT_HANDLER(LinkConfigure, "Link options...")
|
|||
|
||||
update_opts();
|
||||
|
||||
SetLinkTimeout(gopts.linktimeout);
|
||||
|
||||
LinkMode oldLinkMode = GetLinkMode();
|
||||
LinkMode newLinkMode = getOptionsLinkMode();
|
||||
bool dolphinHostChanged = jh != gopts.joybus_host;
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
wxString connmsg;
|
||||
wxString title;
|
||||
|
||||
SetLinkTimeout(gopts.linktimeout);
|
||||
EnableSpeedHacks(gopts.lanlink_speed);
|
||||
EnableLinkServer(server, n_players - 1);
|
||||
|
||||
|
@ -2971,7 +2972,7 @@ bool MainFrame::InitMore(void)
|
|||
addbe(cb);
|
||||
getlab("LinkTimeoutLab");
|
||||
addbe(lab);
|
||||
getsc("LinkTimeout", linktimeout);
|
||||
getsc("LinkTimeout", gopts.linktimeout);
|
||||
addbe(sc);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -279,9 +279,10 @@ void GameArea::LoadGame(const wxString &name)
|
|||
wxString bname = loaded_game.GetFullName();
|
||||
#ifndef NO_LINK
|
||||
// MakeInstanceFilename doesn't do wxString, so just add slave ID here
|
||||
if(vbaid) {
|
||||
int playerId = GetLinkPlayerId();
|
||||
if(playerId >= 0) {
|
||||
bname.append(wxT('-'));
|
||||
bname.append(wxChar(wxT('1') + vbaid));
|
||||
bname.append(wxChar(wxT('1') + playerId));
|
||||
}
|
||||
#endif
|
||||
bname.append(wxT(".sav"));
|
||||
|
@ -331,10 +332,11 @@ void GameArea::SetFrameTitle()
|
|||
} else
|
||||
tit = wxT("VisualBoyAdvance-M " VERSION);
|
||||
#ifndef NO_LINK
|
||||
if(vbaid > 0 || linkid > 0) {
|
||||
tit.append(_(" player "));
|
||||
tit.append(wxChar(wxT('1') + (linkid > 0 ? linkid : vbaid)));
|
||||
}
|
||||
int playerId = GetLinkPlayerId();
|
||||
if (playerId >= 0) {
|
||||
tit.append(_(" player "));
|
||||
tit.append(wxChar(wxT('1') + playerId));
|
||||
}
|
||||
#endif
|
||||
wxGetApp().frame->SetTitle(tit);
|
||||
}
|
||||
|
@ -516,10 +518,11 @@ void GameArea::SaveBattery(bool quiet)
|
|||
// MakeInstanceFilename doesn't do wxString, so just add slave ID here
|
||||
wxString bname = game_name();
|
||||
#ifndef NO_LINK
|
||||
if(vbaid) {
|
||||
bname.append(wxT('-'));
|
||||
bname.append(wxChar(wxT('1') + vbaid));
|
||||
}
|
||||
int playerId = GetLinkPlayerId();
|
||||
if (playerId >= 0) {
|
||||
bname.append(wxT('-'));
|
||||
bname.append(wxChar(wxT('1') + playerId));
|
||||
}
|
||||
#endif
|
||||
bname.append(wxT(".sav"));
|
||||
wxFileName bat(batdir, bname);
|
||||
|
|
Loading…
Reference in New Issue