rewind a demo, set time remaining

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6424 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lucas GAUTHERON
2011-05-14 12:11:51 +00:00
parent 79dc0e46e2
commit 414572e574
6 changed files with 74 additions and 14 deletions
+36
View File
@@ -9,6 +9,7 @@ ENetHost *clienthost = NULL;
ENetPeer *curpeer = NULL, *connpeer = NULL;
int connmillis = 0, connattempts = 0, discmillis = 0;
bool watchingdemo = false;
string demofile;
extern bool clfail, cllock;
extern int searchlan;
@@ -763,6 +764,39 @@ void listdemos()
addmsg(SV_LISTDEMOS, "r");
}
void shiftgametime(int newmillis)
{
newmillis = max(0, newmillis);
int gamemillis = gametimecurrent + (lastmillis - lastgametimeupdate);
if(!watchingdemo) { conoutf("You have to be watching a demo to change game time"); return; }
if(newmillis > gametimemaximum) { conoutf("Invalid time specified"); return; }
if(newmillis < gamemillis)
{
// if rewinding
if(!demofile || !demofile[0]) return;
watchingdemo = false;
callvote(SA_MAP, demofile, "-1");
nextmillis = newmillis;
}
else
{
nextmillis = newmillis - gamemillis;
}
}
void setminutesremaining(int minutes)
{
shiftgametime(gametimemaximum - minutes * 60000);
}
void rewinddemo(int seconds)
{
int gamemillis = gametimecurrent+(lastmillis-lastgametimeupdate);
shiftgametime(gamemillis-seconds*1000);
}
COMMAND(sendmap, ARG_1STR);
COMMAND(getmap, ARG_NONE);
COMMAND(deleteservermap, ARG_1STR);
@@ -770,3 +804,5 @@ COMMAND(resetsecuremaps, ARG_NONE);
COMMAND(securemap, ARG_1STR);
COMMAND(getdemo, ARG_2STR);
COMMAND(listdemos, ARG_NONE);
COMMANDN(setmr, setminutesremaining, ARG_1INT);
COMMANDN(rewind, rewinddemo, ARG_1INT);
+11 -3
View File
@@ -52,7 +52,7 @@ struct serverstate servstate = { 0 };
playerent *player1 = newplayerent(); // our client
vector<playerent *> players; // other clients
int lastmillis = 0, totalmillis = 0;
int lastmillis = 0, totalmillis = 0, nextmillis = 0;
int lasthit = 0;
int curtime = 0;
string clientmap = "";
@@ -951,13 +951,21 @@ VAR(gametimecurrent, 1, 0, 0);
VAR(gametimemaximum, 1, 0, 0);
VAR(lastgametimeupdate, 1, 0, 0);
void timeupdate(int milliscur, int millismax)
void silenttimeupdate(int milliscur, int millismax)
{
if( lastmillis - lastgametimeupdate < 1000 ) return; // avoid double-output, but possibly omit new message if joined 1s before server switches to next minute
lastgametimeupdate = lastmillis;
gametimecurrent = milliscur;
gametimemaximum = millismax;
minutesremaining = (gametimemaximum - gametimecurrent + 60000 - 1) / 60000;
}
void timeupdate(int milliscur, int millismax)
{
bool display = lastmillis - lastgametimeupdate > 1000; // avoid double-output
silenttimeupdate(milliscur, millismax);
if(!display) return;
if(!minutesremaining)
{
intermission = true;
+3 -1
View File
@@ -1268,7 +1268,9 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
case SV_DEMOPLAYBACK:
{
watchingdemo = demoplayback = getint(p)!=0;
extern string demofile;
getstring(demofile, p);
watchingdemo = demoplayback = demofile && demofile[0];
if(demoplayback)
{
player1->resetspec();
+1 -1
View File
@@ -33,7 +33,7 @@ extern bool editmode;
extern vector<entity> ents; // map entities
extern vector<int> eh_ents; // edithide entities
extern vec worldpos, camup, camright, camdir; // current target of the crosshair in the world
extern int lastmillis, totalmillis; // last time
extern int lastmillis, totalmillis, nextmillis; // last time
extern int curtime; // current frame time
extern int interm;
extern int gamemode, nextmode;
+5
View File
@@ -1193,6 +1193,11 @@ int main(int argc, char **argv)
if(millis<totalmillis) millis = totalmillis;
limitfps(millis, totalmillis);
int elapsed = millis-totalmillis;
if(nextmillis && watchingdemo)
{
elapsed += nextmillis;
nextmillis = 0;
}
if(multiplayer(false)) curtime = elapsed;
else
{
+18 -9
View File
@@ -725,14 +725,14 @@ void enddemoplayback()
delete demoplayback;
demoplayback = NULL;
loopv(clients) sendf(i, 1, "ri3", SV_DEMOPLAYBACK, 0, i);
loopv(clients) sendf(i, 1, "risi", SV_DEMOPLAYBACK, "", i);
sendservmsg("demo playback finished");
loopv(clients) sendwelcome(clients[i]);
}
void setupdemoplayback()
void setupdemoplayback(bool send = true)
{
demoheader hdr;
string msg;
@@ -753,14 +753,16 @@ void setupdemoplayback()
if(msg[0])
{
if(demoplayback) { delete demoplayback; demoplayback = NULL; }
sendservmsg(msg);
if(send) sendservmsg(msg);
return;
}
formatstring(msg)("playing demo \"%s\"", file);
sendservmsg(msg);
sendf(-1, 1, "ri3", SV_DEMOPLAYBACK, 1, -1);
if(send)
{
formatstring(msg)("playing demo \"%s\"", file);
sendservmsg(msg);
sendf(-1, 1, "risi", SV_DEMOPLAYBACK, smapname, -1);
}
if(demoplayback->read(&nextplayback, sizeof(nextplayback))!=sizeof(nextplayback))
{
@@ -3719,7 +3721,14 @@ void serverslice(uint timeout) // main server update, called from cube main lo
servertime = ((diff + 3 * servertime)>>2);
if (servertime > 40) serverlagged = servmillis;
if(m_demo) readdemo();
#ifndef STANDALONE
if(m_demo)
{
readdemo();
extern void silenttimeupdate(int milliscur, int millismax);
silenttimeupdate(gamemillis, gamelimit);
}
#endif
if(minremain>0)
{