Shadowrun: Awakened 29 September 2011 - Build 871
pover_video.cpp
Go to the documentation of this file.
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 // Support for GUI display for Polygon overlay demo
00030 
00031 #define VIDEO_WINMAIN_ARGS
00032 #include <iostream>
00033 #include "polyover.h"
00034 #include "polymain.h"
00035 #include "pover_video.h"
00036 #include "tbb/tick_count.h"
00037 #include "tbb/task_scheduler_init.h"
00038 #ifndef _WIN32
00039 #include <sys/time.h>
00040 #include <unistd.h>
00041 
00042 void rt_sleep(int msec) {
00043     usleep(msec*1000);
00044 }
00045 
00046 #else //_WIN32
00047 
00048 #undef OLDUNIXTIME
00049 #undef STDTIME
00050 
00051 #include <windows.h>
00052 
00053 void rt_sleep(int msec) {
00054     Sleep(msec);
00055 }
00056 
00057 #endif  /*  _WIN32  */
00058 
00059 using namespace std;
00060 
00061 bool g_next_frame() {
00062     if(++n_next_frame_calls >= frame_skips) { // the data race here is benign
00063         n_next_frame_calls = 0; 
00064         return gVideo->next_frame();
00065     } 
00066     return gVideo->running;
00067 }
00068 
00069 bool g_last_frame() {
00070     if(n_next_frame_calls) return gVideo->next_frame(); 
00071     return gVideo->running;
00072 }
00073 
00074 bool initializeVideo(int argc, char **argv) {
00075     //pover_video *l_video = new pover_video();
00076     //gVideo = l_video;
00077     gVideo->init_console();  // don't check return code.
00078     gVideo->title = g_windowTitle;
00079     g_useGraphics = gVideo->init_window(g_xwinsize, g_ywinsize);
00080     return true;
00081 }
00082 
00083 void pover_video::on_process() {
00084     tbb::tick_count t0, t1;
00085     double naiveParallelTime, domainSplitParallelTime;
00086     // create map1  These could be done in parallel, if the pseudorandom number generator were re-seeded.
00087     GenerateMap(&gPolymap1, gMapXSize, gMapYSize, gNPolygons, /*red*/255, /*green*/0, /*blue*/127);
00088     // create map2
00089     GenerateMap(&gPolymap2, gMapXSize, gMapYSize, gNPolygons, /*red*/0, /*green*/255, /*blue*/127);
00090         //
00091         // Draw source maps
00092     gDrawXOffset = map1XLoc;
00093     gDrawYOffset = map1YLoc;
00094         for(int i=0; i < int(gPolymap1->size()); i++) {
00095             gPolymap1->at(i)->drawPoly();
00096         }
00097     gDrawXOffset = map2XLoc;
00098     gDrawYOffset = map2YLoc;
00099         for(int i=0; i < int(gPolymap2->size()) ;i++) {
00100             gPolymap2->at(i)->drawPoly();
00101         }
00102         gDoDraw = true;
00103 
00104     // run serial map generation
00105     gDrawXOffset = maprXLoc;
00106     gDrawYOffset = maprYLoc;
00107     {
00108         RPolygon *xp = RPolygon::alloc_RPolygon(0, 0, gMapXSize-1, gMapYSize-1, 0, 0, 0);  // Clear the output space
00109         RPolygon::free_RPolygon( xp );
00110         t0 = tbb::tick_count::now();
00111         SerialOverlayMaps(&gResultMap, gPolymap1, gPolymap2);
00112         t1 = tbb::tick_count::now();
00113         cout << "Serial overlay took " << (t1-t0).seconds()*1000 << " msec" << std::endl;
00114         gSerialTime = (t1-t0).seconds()*1000;
00115 #if _DEBUG
00116         CheckPolygonMap(gResultMap);
00117         // keep the map for comparison purposes.
00118 #else
00119         for(int i=0; i<int(gResultMap->size());i++) {
00120             RPolygon::free_RPolygon(gResultMap->at(i));
00121         }
00122         delete gResultMap;
00123 #endif
00124         if(gCsvFile.is_open()) {
00125             gCsvFile << "Serial Time," << gSerialTime << std::endl;
00126             gCsvFile << "Threads,";
00127             if(gThreadsLow == THREADS_UNSET || gThreadsLow == tbb::task_scheduler_init::automatic) {
00128                 gCsvFile << "Threads,Automatic";
00129             }
00130             else {
00131                 for(int i=gThreadsLow; i <= gThreadsHigh; i++) {
00132                     gCsvFile << i;
00133                     if(i < gThreadsHigh) gCsvFile << ",";
00134                 }
00135             }
00136             gCsvFile << std::endl;
00137         }
00138         if(gIsGraphicalVersion) rt_sleep(2000);
00139     }
00140     // run naive parallel map generation
00141     {
00142         Polygon_map_t *resultMap;
00143         if(gCsvFile.is_open()) {
00144             gCsvFile << "Naive Time";
00145         }
00146         NaiveParallelOverlay(resultMap, *gPolymap1, *gPolymap2);
00147         delete resultMap;
00148         if(gIsGraphicalVersion) rt_sleep(2000);
00149     }
00150     // run split map generation
00151     {
00152         Polygon_map_t *resultMap;
00153         if(gCsvFile.is_open()) {
00154             gCsvFile << "Split Time";
00155         }
00156         SplitParallelOverlay(&resultMap, gPolymap1, gPolymap2);
00157         delete resultMap;
00158         if(gIsGraphicalVersion) rt_sleep(10000);
00159     }
00160 }

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net