From cbe6b403b1779b3ff470694faa7f8d8b505d0f77 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 29 Jan 2008 19:55:25 +0000 Subject: [PATCH] - example app: parse and from project-specific prefs. This gives the user a couple of ways of limiting CPU usage for graphics. - example app: define APP_GRAPHICS in project file, not source svn path=/trunk/boinc_samples/; revision=14636 --- checkin_notes | 12 +++++++++++- example_app/uc2.C | 18 +++++++----------- example_app/uc2_graphics.C | 9 +++++++++ win_build/uc2.vcproj | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/checkin_notes b/checkin_notes index 6ccdf44931..198bf50823 100644 --- a/checkin_notes +++ b/checkin_notes @@ -512,8 +512,18 @@ Charlie 28 Nov 2007 UpperCase2.xcodeproj/ project.pbxproj -David 6 Jan 2007 +David 6 Jan 2008 - small bug fix wrapper/ wrapper.C + +David 28 Jan 2008 + - example app: parse and + from project-specific prefs. This gives the user a couple + of ways of limiting CPU usage for graphics. + - example app: define APP_GRAPHICS in project file, not source + + example_app/ + uc2.C + uc2_graphics.C diff --git a/example_app/uc2.C b/example_app/uc2.C index bab76119de..0a113f4de9 100755 --- a/example_app/uc2.C +++ b/example_app/uc2.C @@ -17,19 +17,21 @@ // or write to the Free Software Foundation, Inc., // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// This program serves as both +// - An example BOINC application, illustrating the use of the BOINC API +// - A program for testing various features of BOINC +// // NOTE: this file exists as both // boinc/apps/upper_case.C // and // boinc_samples/example_app/uc2.C // If you update one, please update the other! -// This is the primary sample BOINC application; -// it shows most of the features of the BOINC API. -// +// The program converts a mixed-case file to upper case: // read "in", convert to upper case, write to "out" // -// command line options (use for debugging various scenarios): -// -run_slow: sleep 1 second after each character; useful for debugging +// command line options +// -run_slow: sleep 1 second after each character // -cpu_time N: use about N CPU seconds after copying files // -early_exit: exit(10) after 30 chars // -early_crash: crash after 30 chars @@ -55,8 +57,6 @@ #include "mfile.h" #include "graphics2.h" -#define APP_GRAPHICS - #ifdef APP_GRAPHICS #include "uc2.h" UC_SHMEM* shmem; @@ -93,16 +93,12 @@ int do_checkpoint(MFILE& mf, int nchars) { fprintf(f, "%d", nchars); fclose(f); - fprintf(stderr, "APP: upper_case checkpointing\n"); - retval = mf.flush(); if (retval) return retval; boinc_resolve_filename_s(CHECKPOINT_FILE, resolved_name); retval = boinc_rename("temp", resolved_name.c_str()); if (retval) return retval; - //use_some_cpu(); - fprintf(stderr, "APP: upper_case checkpoint done\n"); return 0; } diff --git a/example_app/uc2_graphics.C b/example_app/uc2_graphics.C index a55048ffdb..6f5ba0eeb2 100644 --- a/example_app/uc2_graphics.C +++ b/example_app/uc2_graphics.C @@ -49,6 +49,8 @@ bool mouse_down = false; int mouse_x, mouse_y; double pitch_angle, roll_angle, viewpoint_distance=10; float color[4] = {.7, .2, .5, 1}; + // the color of the 3D object. + // Can be changed using preferences UC_SHMEM* shmem = NULL; // set up lighting model @@ -234,6 +236,7 @@ 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, "", cs, 256)) { if (!strcmp(cs, "Tahiti Sunset")) { @@ -249,6 +252,12 @@ static void parse_project_prefs(char* buf) { color[2] = c.b; color[3] = 1; } + if (parse_double(buf, "", max_frames_sec)) { + boinc_max_fps = max_frames_sec; + } + if (parse_double(buf, "", max_gfx_cpu_pct)) { + boinc_max_gfx_cpu_frac = max_gfx_cpu_pct/100; + } } int main(int argc, char** argv) { diff --git a/win_build/uc2.vcproj b/win_build/uc2.vcproj index 88c90ecfd1..d4ed8ee7dc 100644 --- a/win_build/uc2.vcproj +++ b/win_build/uc2.vcproj @@ -53,7 +53,7 @@ InlineFunctionExpansion="1" FavorSizeOrSpeed="1" AdditionalIncludeDirectories=".;../../boinc;../../boinc/api;../../boinc/lib;../image_libs;../jpeglib;../glut" - PreprocessorDefinitions="WIN32;NDEBUG;_MT;_CONSOLE" + PreprocessorDefinitions="WIN32;NDEBUG;_MT;_CONSOLE;APP_GRAPHICS" StringPooling="false" RuntimeLibrary="0" EnableFunctionLevelLinking="true"