2008-01-28 22:42:05 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
// platform-independent part of graphics library
|
|
|
|
//
|
2007-05-22 21:26:47 +00:00
|
|
|
#include "util.h"
|
2007-05-23 21:02:19 +00:00
|
|
|
#include "app_ipc.h"
|
|
|
|
#include "shmem.h"
|
|
|
|
#include "boinc_api.h"
|
|
|
|
#include "graphics2.h"
|
2007-05-22 21:26:47 +00:00
|
|
|
|
2007-10-04 21:58:56 +00:00
|
|
|
double boinc_max_fps = 30.;
|
2008-01-29 19:51:26 +00:00
|
|
|
double boinc_max_gfx_cpu_frac = 0.2;
|
|
|
|
// needs to be fairly low. Graphics apps run at normal priority,
|
|
|
|
// so they can prevent main app from getting any time
|
2007-05-22 20:12:45 +00:00
|
|
|
|
|
|
|
bool throttled_app_render(int x, int y, double t) {
|
|
|
|
static double total_render_time = 0;
|
|
|
|
static double time_until_render = 0;
|
|
|
|
static double last_now = 0;
|
|
|
|
static double elapsed_time = 0;
|
|
|
|
double now, t0, t1, diff, frac;
|
|
|
|
bool ok_to_render = true;
|
|
|
|
|
|
|
|
now = dtime();
|
|
|
|
diff = now - last_now;
|
|
|
|
last_now = now;
|
|
|
|
|
|
|
|
// ignore interval if negative or more than 1 second
|
|
|
|
//
|
|
|
|
if ((diff<0) || (diff>1.0)) {
|
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enforce frames/sec restriction
|
|
|
|
//
|
|
|
|
if (boinc_max_fps) {
|
|
|
|
time_until_render -= diff;
|
|
|
|
if (time_until_render < 0) {
|
|
|
|
time_until_render += 1./boinc_max_fps;
|
|
|
|
} else {
|
|
|
|
ok_to_render = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// enforce max CPU time restriction
|
|
|
|
//
|
|
|
|
if (boinc_max_gfx_cpu_frac) {
|
|
|
|
elapsed_time += diff;
|
|
|
|
if (elapsed_time) {
|
|
|
|
frac = total_render_time/elapsed_time;
|
|
|
|
if (frac > boinc_max_gfx_cpu_frac) {
|
|
|
|
ok_to_render = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// render if allowed
|
|
|
|
//
|
|
|
|
if (ok_to_render) {
|
|
|
|
if (boinc_max_gfx_cpu_frac) {
|
|
|
|
boinc_calling_thread_cpu_time(t0);
|
|
|
|
}
|
|
|
|
app_graphics_render(x, y, t);
|
|
|
|
if (boinc_max_gfx_cpu_frac) {
|
|
|
|
boinc_calling_thread_cpu_time(t1);
|
|
|
|
total_render_time += t1 - t0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-22 21:26:47 +00:00
|
|
|
|
2007-05-23 21:02:19 +00:00
|
|
|
void get_window_title(char* buf, int len) {
|
|
|
|
APP_INIT_DATA aid;
|
|
|
|
boinc_get_init_data(aid);
|
|
|
|
if (aid.app_version) {
|
|
|
|
snprintf(buf, len,
|
|
|
|
"%s version %.2f [workunit: %s]",
|
|
|
|
aid.app_name, aid.app_version/100.0, aid.wu_name
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
snprintf(buf, len,
|
|
|
|
"%s [workunit: %s]",
|
|
|
|
aid.app_name, aid.wu_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|