- screensaver: flesh out new SS a bit

svn path=/trunk/boinc/; revision=17162
This commit is contained in:
David Anderson 2009-02-06 00:29:00 +00:00
parent 258dac62b2
commit 515de57e76
6 changed files with 176 additions and 145 deletions

View File

@ -1277,3 +1277,8 @@ David 5 Feb 2009
cs_scheduler.cpp cs_scheduler.cpp
cs_statefile.cpp cs_statefile.cpp
David 5 Feb 2009
- screensaver: flesh out new SS a bit
clientscr/
ss_app.cpp

View File

@ -307,3 +307,5 @@ extern bool work_fetch_old;
#define CPU_PESSIMISM_FACTOR 0.9 #define CPU_PESSIMISM_FACTOR 0.9
// assume actual CPU utilization will be this multiple // assume actual CPU utilization will be this multiple
// of what we've actually measured recently // of what we've actually measured recently
#define WORK_FETCH_PERIOD 60

View File

@ -1,29 +0,0 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC 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 3 of the License, or (at your option) any later version.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include "boinc_api.h"
struct UC_SHMEM {
double update_time;
double fraction_done;
double cpu_time;
BOINC_STATUS status;
int countdown;
// graphics app sets this to 5 repeatedly,
// main program decrements it once/sec.
// If it's zero, don't bother updating shmem
};

View File

@ -28,33 +28,53 @@
#else #else
#include <math.h> #include <math.h>
#endif #endif
#include <string>
#include <vector>
#include "diagnostics.h" #include "diagnostics.h"
#include "parse.h"
#include "util.h"
#include "gutil.h" #include "gutil.h"
#include "boinc_gl.h" #include "boinc_gl.h"
#include "app_ipc.h"
#include "boinc_api.h"
#include "graphics2.h" #include "graphics2.h"
#include "txf_util.h" #include "txf_util.h"
#include "screensaver_opengl.h" #include "network.h"
#include "gui_rpc_client.h"
#include "app_ipc.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include "mac_app_icon.h" #include "mac_app_icon.h"
#endif #endif
using std::string;
using std::vector;
float white[4] = {1., 1., 1., 1.}; float white[4] = {1., 1., 1., 1.};
TEXTURE_DESC logo; TEXTURE_DESC logo;
int width, height; // window dimensions int width, height; // window dimensions
APP_INIT_DATA uc_aid;
bool mouse_down = false; bool mouse_down = false;
int mouse_x, mouse_y; int mouse_x, mouse_y;
double pitch_angle, roll_angle, viewpoint_distance=10; double pitch_angle, roll_angle, viewpoint_distance=10;
float color[4] = {.7, .2, .5, 1}; float color[4] = {.7, .2, .5, 1};
// the color of the 3D object. // the color of the 3D object.
// Can be changed using preferences // Can be changed using preferences
UC_SHMEM* shmem = NULL;
RPC_CLIENT rpc;
CC_STATE cc_state;
struct APP_SLIDES {
string name;
int index;
double switch_time;
vector<TEXTURE_DESC> slides;
APP_SLIDES(string n): name(n), index(0), switch_time(0) {}
};
struct PROJECT_IMAGES {
string url;
TEXTURE_DESC icon;
vector<APP_SLIDES> app_slides;
};
vector<PROJECT_IMAGES> project_images;
// set up lighting model // set up lighting model
// //
@ -75,56 +95,120 @@ static void draw_logo() {
} }
} }
static void draw_text() { void icon_path(PROJECT* p, char* buf) {
static float x=0, y=0; char dir[256];
static float dx=0.0003, dy=0.0007; url_to_project_dir((char*)p->master_url.c_str(), dir);
char buf[256]; sprintf(buf, "%s/stat_icon", dir);
x += dx; }
y += dy;
if (x < 0 || x > .5) dx *= -1; void slideshow(PROJECT* p) {
if (y < 0 || y > .5) dy *= -1; char dir[256], buf[256];
double fd = 0, cpu=0, dt; int i;
if (shmem) {
fd = shmem->fraction_done; url_to_project_dir((char*)p->master_url.c_str(), dir);
cpu = shmem->cpu_time; for (i=0; i<99; i++) {
} sprintf(buf, "%s/slideshow_%02d", dir, i);
sprintf(buf, "User: %s", uc_aid.user_name);
txf_render_string(.1, x, y, 0, 500, white, 0, buf);
sprintf(buf, "Team: %s", uc_aid.team_name);
txf_render_string(.1, x, y+.1, 0, 500, white, 0, buf);
sprintf(buf, "%% Done: %f", 100*fd);
txf_render_string(.1, x, y+.2, 0, 500, white, 0, buf);
sprintf(buf, "CPU time: %f", cpu);
txf_render_string(.1, x, y+.3, 0, 500, white, 0, buf);
if (shmem) {
dt = dtime() - shmem->update_time;
if (dt > 10) {
boinc_close_window_and_quit("shmem not updated");
} else if (dt > 5) {
txf_render_string(.1, 0, 0, 0, 500, white, 0, "App not running - exiting in 5 seconds");
} else if (shmem->status.suspended) {
txf_render_string(.1, 0, 0, 0, 500, white, 0, "App suspended");
}
} else {
txf_render_string(.1, 0, 0, 0, 500, white, 0, "No shared mem");
} }
} }
static void draw_3d_stuff() { PROJECT_IMAGES* get_project_images(PROJECT* p) {
static float x=0, y=0, z=10; unsigned int i;
static float dx=0.3, dy=0.2, dz=0.5; char dir[256], path[256], filename[256];
x += dx;
y += dy; for (i=0; i<project_images.size(); i++) {
z += dz; PROJECT_IMAGES& pi = project_images[i];
if (x < -15 || x > 15) dx *= -1; if (pi.url == p->master_url) return &pi;
if (y < -15 || y > 15) dy *= -1; }
if (z < 0 || z > 40) dz *= -1; PROJECT_IMAGES pim;
float pos[3]; pim.url = p->master_url;
pos[0] = x; url_to_project_dir((char*)p->master_url.c_str(), dir);
pos[1] = y; sprintf(path, "%s/stat_icon", dir);
pos[2] = z; boinc_resolve_filename(path, filename, 256);
drawSphere(pos, 4); pim.icon.load_image_file(filename);
drawCylinder(false, pos, 6, 6); for (i=0; i<cc_state.apps.size(); i++) {
APP& app = *cc_state.apps[i];
if (app.project != p) continue;
APP_SLIDES as(app.name);
for (int j=0; j<99; j++) {
sprintf(path, "%s/slideshow_%s_%02d", dir, app.name, j);
boinc_resolve_filename(path, filename, 256);
TEXTURE_DESC td;
int retval = td.load_image_file(filename);
if (retval) break;
as.slides.push_back(td);
}
pim.app_slides.push_back(as);
}
project_images.push_back(pim);
}
void show_result(RESULT* r, float x, float& y) {
PROGRESS progress;
char buf[256];
float prog_pos[] = {x, y, 0};
float prog_c[] = {.5, .4, .1, 0.5};
float prog_ci[] = {.1, .8, .2, 1.};
txf_render_string(.1, x, y, 0, 8., white, 0, (char*)r->app->user_friendly_name.c_str());
y -= 3;
progress.init(prog_pos, 10., 1., 0.8, prog_c, prog_ci);
progress.draw(r->fraction_done);
mode_unshaded();
sprintf(buf, "%.2f%%", r->fraction_done*100);
txf_render_string(.1, x+15, y, 0, 8., white, 0, buf);
y -= 3;
}
void show_coords() {
int i;
char buf[256];
for (i=-100; i< 101; i+=5) {
sprintf(buf, "%d", i);
float x = (float)i;
txf_render_string(.1, x, 0, 0, 10., white, 0, buf);
}
for (i=-100; i< 101; i+=5) {
sprintf(buf, "%d", i);
float y = (float)i;
txf_render_string(.1, 0, y, 0, 10., white, 0, buf);
}
}
void show_project(PROJECT* p, float x, float& y) {
unsigned int i;
PROJECT_IMAGES* pim = get_project_images(p);
txf_render_string(.1, x, y, 0, 5., white, 0, (char*)p->project_name.c_str());
if (pim->icon.present) {
float pos[3] = {x, y, 1};
float size[2] = {3., 3.};
pim->icon.draw(pos, size, 0, 0);
}
y -= 3;
for (i=0; i<cc_state.results.size(); i++) {
RESULT* r = cc_state.results[i];
if (r->project != p) continue;
if (!r->active_task) continue;
if (r->active_task_state != PROCESS_EXECUTING) continue;
show_result(r, x, y);
}
}
void show_projects() {
char buf[256];
float x=-45, y=30;
unsigned int i;
for (i=0; i<cc_state.projects.size(); i++) {
PROJECT* p = cc_state.projects[i];
show_project(p, x, y);
y -= 2;
}
}
int update_data(double t) {
static double state_time = 0;
if (state_time < t) {
int retval = rpc.get_state(cc_state);
if (retval) return retval;
state_time = t;
}
} }
void set_viewpoint(double dist) { void set_viewpoint(double dist) {
@ -155,17 +239,10 @@ static void init_camera(double dist) {
set_viewpoint(dist); set_viewpoint(dist);
} }
void app_graphics_render(int xs, int ys, double time_of_day) { void app_graphics_render(int xs, int ys, double t) {
// boinc_graphics_get_shmem() must be called after int retval = update_data(t);
// boinc_parse_init_data_file() if (retval) {
// Put this in the main loop to allow retries if the boinc_close_window_and_quit("RPC failed");
// worker application has not yet created shared memory
//
if (shmem == NULL) {
shmem = (UC_SHMEM*)boinc_graphics_get_shmem("uppercase");
}
if (shmem) {
shmem->countdown = 5;
} }
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -181,15 +258,15 @@ void app_graphics_render(int xs, int ys, double time_of_day) {
// //
init_camera(viewpoint_distance); init_camera(viewpoint_distance);
scale_screen(width, height); scale_screen(width, height);
mode_shaded(color); //mode_shaded(color);
draw_3d_stuff();
// draw text on top // draw text on top
// //
mode_unshaded(); //mode_unshaded();
mode_ortho(); //mode_ortho();
draw_text(); show_projects();
ortho_done(); show_coords();
//ortho_done();
} }
void app_graphics_resize(int w, int h){ void app_graphics_resize(int w, int h){
@ -232,59 +309,27 @@ void boinc_app_key_press(int, int){}
void boinc_app_key_release(int, int){} void boinc_app_key_release(int, int){}
void app_graphics_init() { void app_graphics_init() {
char path[256];
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
txf_load_fonts("."); txf_load_fonts(".");
logo.load_image_file("boinc_logo_black.jpg");
boinc_resolve_filename("logo.jpg", path, sizeof(path));
logo.load_image_file(path);
init_lights(); init_lights();
} }
static void parse_project_prefs(char* buf) {
char cs[256];
COLOR c;
double hue;
double max_frames_sec, max_gfx_cpu_pct;
if (!buf) return;
if (parse_str(buf, "<color_scheme>", cs, 256)) {
if (!strcmp(cs, "Tahiti Sunset")) {
hue = .9;
} else if (!strcmp(cs, "Desert Sands")) {
hue = .1;
} else {
hue = .5;
}
HLStoRGB(hue, .5, .5, c);
color[0] = c.r;
color[1] = c.g;
color[2] = c.b;
color[3] = 1;
}
if (parse_double(buf, "<max_frames_sec>", max_frames_sec)) {
boinc_max_fps = max_frames_sec;
}
if (parse_double(buf, "<max_gfx_cpu_pct>", max_gfx_cpu_pct)) {
boinc_max_gfx_cpu_frac = max_gfx_cpu_pct/100;
}
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS); int retval;
#ifdef _WIN32
WinsockInitialize();
#endif
retval = rpc.init("localhost");
if (retval) exit(retval);
#ifdef __APPLE__ #ifdef __APPLE__
setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData)); setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData));
#endif #endif
boinc_parse_init_data_file();
boinc_get_init_data(uc_aid);
if (uc_aid.project_preferences) {
parse_project_prefs(uc_aid.project_preferences);
}
boinc_graphics_loop(argc, argv); boinc_graphics_loop(argc, argv);
boinc_finish_diag(); boinc_finish_diag();
#ifdef _WIN32
WinsockCleanup();
#endif
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -81,7 +81,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="opengl32.lib glu32.lib glaux.lib odbc32.lib odbccp32.lib libcmt.lib libcpmt.lib" AdditionalDependencies="opengl32.lib glu32.lib glaux.lib odbc32.lib odbccp32.lib libcmt.lib wsock32.lib libcpmt.lib"
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\$(ProjectName).exe" OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\$(ProjectName).exe"
LinkIncremental="0" LinkIncremental="0"
SuppressStartupBanner="true" SuppressStartupBanner="true"
@ -280,7 +280,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="libcmtd.lib libcpmtd.lib kernel32.lib user32.lib gdi32.lib opengl32.lib glu32.lib glaux.lib ole32.lib delayimp.lib" AdditionalDependencies="libcmtd.lib libcpmtd.lib kernel32.lib user32.lib gdi32.lib opengl32.lib glu32.lib glaux.lib ole32.lib delayimp.lib wsock32.lib wininet.lib"
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\$(ProjectName).exe" OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\$(ProjectName).exe"
LinkIncremental="0" LinkIncremental="0"
SuppressStartupBanner="true" SuppressStartupBanner="true"
@ -820,6 +820,14 @@
Name="Source Files" Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
> >
<File
RelativePath="..\lib\gui_rpc_client.cpp"
>
</File>
<File
RelativePath="..\lib\gui_rpc_client_ops.cpp"
>
</File>
<File <File
RelativePath="..\clientscr\ss_app.cpp" RelativePath="..\clientscr\ss_app.cpp"
> >