cleaned up autoscreenshot code

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3847 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-12-03 07:53:41 +00:00
parent 9dac9599a5
commit 913bc3389f
2 changed files with 44 additions and 42 deletions
+2 -25
View File
@@ -383,30 +383,6 @@ void updateworld(int curtime, int lastmillis) // main game update loop
gets2c();
showrespawntimer();
if(autoscreenshotat)
{
if(autoscreenshotat > 0 && lastmillis > autoscreenshotat)
{
// force scoreboard on and give it time to display ..
showscores(true);
autoscreenshotat = -1 * (lastmillis + 141);
}
else if(autoscreenshotat < 0 && lastmillis > -1 * autoscreenshotat)
{
extern void screenshot(char *imagepath);
char fmttimestr[15]; // flowtron assumes "%b" is always 3 chars (true at least for DE and EN)
time_t t = time(NULL);
struct tm * timeinfo;
timeinfo = localtime (&t);
strftime(fmttimestr, 15, "%Y%b%d_%H%M", timeinfo); // 14 + "\0"
extern string smapname;
extern int screenshottype;
s_sprintfd(endscoreshot)("screenshots/%s_%s_%s.%s", modestr(gamemode, true), behindpath(clientmap), fmttimestr, screenshottype ? "jpg" : "bmp");
screenshot(endscoreshot);
autoscreenshotat = 0;
}
}
// Added by Rick: let bots think
if(m_botmode) BotManager.Think();
@@ -598,7 +574,8 @@ void timeupdate(int timeremain)
if(!timeremain)
{
intermission = true;
if(autoscreenshot) autoscreenshotat = lastmillis + 3141;
extern bool needsautoscreenshot;
if(autoscreenshot) needsautoscreenshot = true;
player1->attacking = false;
conoutf("intermission:");
conoutf("game has ended!");
+42 -17
View File
@@ -141,20 +141,27 @@ void setprocesspriority(bool high)
VARP(screenshottype, 0, 1, 1);
VARP(jpegquality, 10, 70, 100);
const char *maketimestr()
{
static string buf;
time_t rawtime;
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
if(!timeinfo) return NULL;
int len = strftime(buf, sizeof(buf), "%Y%b%d_%H%M%S", timeinfo);
if(!len || len>=(int)sizeof(buf)) return NULL;
return buf;
}
void jpeg_screenshot(char *imagepath)
{
if(!imagepath[0])
{
const char *timestr = maketimestr();
if(!timestr) return;
static string buf;
time_t rawtime;
struct tm *timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
if(!timeinfo) return;
int len = strftime(buffer, sizeof(buffer), "%Y%b%d_%H%M%S", timeinfo);
if(!len || len>=(int)sizeof(buffer)) return;
s_sprintf(buf)("screenshots/%s.jpg", buffer);
s_sprintf(buf)("screenshots/%s.jpg", timestr);
imagepath = buf;
}
FILE *jpegfile = fopen(imagepath, "wb");
@@ -197,26 +204,28 @@ void jpeg_screenshot(char *imagepath)
void bmp_screenshot(char *imagepath)
{
if(!imagepath[0])
{
const char *timestr = maketimestr();
if(!timestr) return;
static string buf;
s_sprintf(buf)("screenshots/%s.jpg", timestr);
imagepath = buf;
}
SDL_Surface *image = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0);
if(!image) return;
uchar *tmp = new uchar[screen->w*screen->h*3];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, screen->w, screen->h, GL_RGB, GL_UNSIGNED_BYTE, tmp);
uchar *dst = (uchar *)image->pixels;
loopi(scr_h)
loopi(screen->h)
{
memcpy(dst, &tmp[3*screen->w*(screen->h-i-1)], 3*screen->w);
endianswap(dst, 3, screen->w);
dst += image->pitch;
}
delete[] tmp;
if(!imagepath[0])
{
static string buf;
systemtime();
s_sprintf(buf)("screenshots/%d.bmp", now_utc);
imagepath = buf;
}
SDL_SaveBMP(image, findfile(path(imagepath), "wb"));
SDL_FreeSurface(image);
}
@@ -231,6 +240,18 @@ void screenshot(char *imagepath)
}
}
bool needsautoscreenshot = false;
void makeautoscreenshot()
{
needsautoscreenshot = false;
const char *timestr = maketimestr();
if(!timestr) return;
s_sprintfd(filename)("screenshots/%s_%s_%s.%s", modestr(gamemode, true), behindpath(getclientmap()), timestr, screenshottype==1 ? "jpg" : "bmp");
screenshot(filename);
}
COMMAND(screenshot, ARG_1STR);
COMMAND(quit, ARG_NONE);
@@ -761,6 +782,8 @@ int main(int argc, char **argv)
if(lastmillis) updateworld(curtime, lastmillis);
if(needsautoscreenshot) showscores(true);
serverslice(0);
fps = (1000.0f/elapsed+fps*10)/11;
@@ -775,6 +798,8 @@ int main(int argc, char **argv)
if(frames>4) SDL_GL_SwapBuffers();
}
if(needsautoscreenshot) makeautoscreenshot();
#ifdef _DEBUG
if(millis>lastflush+60000) {
fflush(stdout); lastflush = millis;