Shadowrun: Awakened 29 September 2011 - Build 871
trace_rest.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 /*
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  * trace.c - This file contains the functions for firing primary rays
00060  *           and handling subsequent calculations
00061  *
00062  *   $Id: trace_rest.cpp,v 1.4 2007-02-22 17:54:16 dpoulsen Exp $
00063  */
00064 
00065 #include "machine.h"
00066 #include "types.h"
00067 #include "macros.h"
00068 #include "vector.h"
00069 #include "tgafile.h"
00070 #include "trace.h"
00071 #include "light.h"
00072 #include "shade.h"
00073 #include "camera.h"
00074 #include "util.h"
00075 #include "intersect.h"
00076 #include "global.h"
00077 #include "ui.h"
00078 #include "video.h"
00079 
00080 color trace(ray * primary) {
00081   if (primary->depth > 0) {
00082     VNorm(&primary->d);
00083     reset_intersection(primary->intstruct);
00084     intersect_objects(primary);
00085     return shader(primary);
00086   }
00087 
00088   /* if ray is truncated, return the background as its color */
00089   return primary->scene->background;
00090 }
00091 
00092 void * thread_io(void * parms) {
00093   thr_io_parms p;
00094 
00095   p= *((thr_io_parms *) parms);
00096   writetgaregion(p.tga, p.iwidth, p.iheight, p.startx, p.starty, 
00097         p.stopx, p.stopy, p.buffer);
00098   free(p.buffer); /* free the buffer once we are done with it.. */
00099   free(parms);
00100 
00101   return(NULL);
00102 }
00103 
00104 void trace_shm(scenedef scene, /*char * buffer,  */ int startx, int stopx, int starty, int stopy) {
00105 
00106   thr_parms * parms;
00107 
00108   parms = (thr_parms *) rt_getmem(sizeof(thr_parms));  
00109 
00110   parms->tid=0;
00111   parms->nthr=1;
00112   parms->scene=scene;
00113   parms->startx=startx;
00114   parms->stopx=stopx;
00115   parms->starty=starty;
00116   parms->stopy=stopy;
00117 
00118   thread_trace(parms);
00119 
00120   rt_freemem(parms);
00121 }
00122 
00123 void trace_region(scenedef scene, void * tga, int startx, int starty, int stopx, int stopy) {
00124 
00125   if (scene.verbosemode) {
00126     char msgtxt[2048];
00127     sprintf(msgtxt, "Node %3d tracing region  %4d, %4d  --->  %4d, %4d \n", 0, startx,starty,stopx,stopy);
00128     rt_ui_message(MSG_0, msgtxt);
00129   }
00130 
00131   trace_shm(scene, /*buffer,*/ startx, stopx, starty, stopy);
00132 /* not used now
00133   writetgaregion(tga, scene.hres, scene.vres, 
00134                  startx, starty, stopx, stopy, global_buffer);
00135 
00136   if (scene.rawimage != NULL) {
00137     int x, y;
00138     int totalx = stopx - startx + 1;
00139     for (y=starty; y<=stopy; y++) {
00140       for (x=0; x<scene.hres; x++) {
00141         scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3] = global_buffer[(y-starty)*totalx*3 + x*3 + 2];
00142         scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +1] = global_buffer[(y-starty)*totalx*3 + x*3 + 1];
00143         scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +2] = global_buffer[(y-starty)*totalx*3 + x*3];
00144       }
00145     }
00146   }
00147 */
00148 }

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