![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2005-2010 Intel Corporation. All Rights Reserved. 00003 00004 This file is part of Threading Building Blocks. 00005 00006 Threading Building Blocks is free software; you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License 00008 version 2 as published by the Free Software Foundation. 00009 00010 Threading Building Blocks is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00012 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Threading Building Blocks; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 As a special exception, you may use this file as part of a free software 00020 library without restriction. Specifically, if other files instantiate 00021 templates or use macros or inline functions from this file, or you compile 00022 this file and link it with other files to produce an executable, this 00023 file does not by itself cause the resulting executable to be covered by 00024 the GNU General Public License. This exception does not however 00025 invalidate any other reasons why the executable file might be covered by 00026 the GNU General Public License. 00027 */ 00028 00029 /* 00030 The original source for this example is 00031 Copyright (c) 1994-2008 John E. Stone 00032 All rights reserved. 00033 00034 Redistribution and use in source and binary forms, with or without 00035 modification, are permitted provided that the following conditions 00036 are met: 00037 1. Redistributions of source code must retain the above copyright 00038 notice, this list of conditions and the following disclaimer. 00039 2. Redistributions in binary form must reproduce the above copyright 00040 notice, this list of conditions and the following disclaimer in the 00041 documentation and/or other materials provided with the distribution. 00042 3. The name of the author may not be used to endorse or promote products 00043 derived from this software without specific prior written permission. 00044 00045 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 00046 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00047 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00048 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00049 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00050 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00051 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00052 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00053 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00054 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00055 SUCH DAMAGE. 00056 */ 00057 00058 /* 00059 * video.c - routines for putting pixels on a screen if one is available. 00060 * 00061 * $Id: video.cpp,v 1.20 2007-02-28 18:35:22 amalakho Exp $ 00062 */ 00063 00064 #include <stdio.h> 00065 #include <stdlib.h> 00066 #include <string.h> 00067 00068 #define VIDEO_WINMAIN_ARGS 00069 #include "types.h" 00070 #include "api.h" /* The ray tracing library API */ 00071 #include "getargs.h" /* command line argument/option parsing */ 00072 #include "parse.h" /* Support for my own file format */ 00073 #include "ui.h" 00074 #include "util.h" 00075 #include "video.h" 00076 00077 static SceneHandle global_scene; 00078 static int global_xsize; /* size of graphic image rendered in window (from hres, vres) */ 00079 static int global_ysize; 00080 static int global_xwinsize; /* size of window (may be larger than above) */ 00081 static int global_ywinsize; 00082 static char *global_window_title; 00083 static bool global_usegraphics; 00084 00085 static char *window_title_string (int argc, char **argv) 00086 { 00087 int i; 00088 char *name; 00089 00090 name = (char *) malloc (8192); 00091 00092 if(strrchr(argv[0], '\\')) strcpy (name, strrchr(argv[0], '\\')+1); 00093 else if(strrchr(argv[0], '/')) strcpy (name, strrchr(argv[0], '/')+1); 00094 else strcpy (name, *argv[0]?argv[0]:"Tachyon"); 00095 for (i = 1; i < argc; i++) { 00096 strcat (name, " "); 00097 strcat (name, argv[i]); 00098 } 00099 #ifdef _DEBUG 00100 strcat (name, " (DEBUG BUILD)"); 00101 #endif 00102 return name; 00103 } 00104 00105 static int main_init_parts (int argc, char **argv) 00106 { 00107 int rc; 00108 argoptions opt; 00109 char * filename; 00110 00111 global_window_title = window_title_string (argc, argv); 00112 00113 global_scene = rt_newscene(); 00114 00115 rt_initialize(&argc, &argv); 00116 00117 if ((rc = getargs(argc, argv, &opt)) == -1) { 00118 #if _WIN32||_WIN64 00119 rt_sleep(10000); 00120 #endif 00121 exit(rc); 00122 } 00123 00124 #ifdef DEFAULT_MODELFILE 00125 #if _WIN32||_WIN64 00126 #define _GLUE_FILENAME(x) "..\\dat\\" #x 00127 #else 00128 #define _GLUE_FILENAME(x) #x 00129 #endif 00130 #define GLUE_FILENAME(x) _GLUE_FILENAME(x) 00131 if(opt.foundfilename == -1) 00132 filename = GLUE_FILENAME(DEFAULT_MODELFILE); 00133 else 00134 #endif//DEFAULT_MODELFILE 00135 filename = opt.filename; 00136 00137 rc = readmodel(filename, global_scene); 00138 00139 if (rc != 0) { 00140 fprintf(stderr, "Parser returned a non-zero error code reading %s\n", filename); 00141 fprintf(stderr, "Aborting Render...\n"); 00142 rt_finalize(); 00143 return -1; 00144 } 00145 00146 /* process command line overrides */ 00147 useoptions(&opt, global_scene); 00148 00149 // need these early for create_graphics_window() so grab these here... 00150 scenedef *scene = (scenedef *) global_scene; 00151 global_xsize = scene->hres; 00152 global_ysize = scene->vres; 00153 global_xwinsize = global_xsize; 00154 global_ywinsize = global_ysize; // add some here to leave extra blank space on bottom for status etc. 00155 global_usegraphics = (scene->displaymode == RT_DISPLAY_ENABLED); 00156 00157 return 0; 00158 } 00159 00160 class tachyon_video : public video 00161 { 00162 void on_process() 00163 { 00164 char buf[128]; 00165 flt runtime; 00166 timerstart(); 00167 rt_renderscene(global_scene); 00168 timerstop(); 00169 runtime=timertime(); 00170 sprintf(buf, "\nCPU Time: %.3f seconds.", runtime); 00171 rt_ui_message(MSG_0, buf); buf[0] = ' '; 00172 strcat(global_window_title, buf); 00173 title = global_window_title; updating = true; 00174 show_title(); 00175 rt_finalize(); 00176 } 00177 void on_key(int key) { 00178 key &= 0xff; if(key == 27) running = false; 00179 } 00180 }; 00181 class video *video = 0; 00182 00183 void rt_finalize(void) { 00184 timerstart(); 00185 if(global_usegraphics) 00186 do { rt_sleep(10); timerstop(); } 00187 while(timertime() < 10 && video->next_frame()); 00188 #ifdef _WINDOWS 00189 else rt_sleep(10000); 00190 #endif 00191 } 00192 00193 int main (int argc, char **argv) 00194 { 00195 int rc; 00196 00197 tachyon_video tachyon; 00198 tachyon.threaded = true; 00199 tachyon.init_console(); 00200 00201 rc = main_init_parts (argc, argv); 00202 if (rc) return rc; 00203 00204 tachyon.title = global_window_title; 00205 tachyon.updating = global_usegraphics; 00206 // always using window even if(!global_usegraphics) 00207 global_usegraphics = 00208 tachyon.init_window(global_xwinsize, global_ywinsize); 00209 if(!tachyon.running) 00210 return -1; 00211 00212 video = &tachyon; 00213 tachyon.main_loop(); 00214 00215 return 0; 00216 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.