home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / rayshade.lzh / main.c < prev    next >
C/C++ Source or Header  |  1990-10-01  |  6KB  |  230 lines

  1. char rcsid[] =
  2.     "$Id: main.c,v 3.0.1.4 90/04/04 14:50:44 craig Exp $";
  3. /*
  4.  * main.c
  5.  *
  6.  * Copyright (C) 1989, Craig E. Kolb
  7.  *
  8.  * This software may be freely copied, modified, and redistributed,
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * There is no warranty or other guarantee of fitness for this software,
  12.  * it is provided solely .  Bug reports or fixes may be sent
  13.  * to the author, who may or may not act on them as he desires.
  14.  *
  15.  * You may not include this software in a program or other software product
  16.  * without supplying the source, or without informing the end-user that the
  17.  * source is available for no extra charge.
  18.  *
  19.  * If you modify this software, you should include a notice giving the
  20.  * name of the person performing the modification, the date of modification,
  21.  * and the reason for such modification.
  22.  *
  23.  * $Log:    main.c,v $
  24.  * Revision 3.0.1.4  90/04/04  14:50:44  craig
  25.  * patch5: Removed check of return value of times().
  26.  * 
  27.  * Revision 3.0.1.3  90/03/07  21:33:09  craig
  28.  * patch4: Return value of times() is now checked.
  29.  * patch4: Workers is externed iff LINDA is defined.
  30.  * 
  31.  * Revision 3.0.1.2  89/12/07  22:54:39  craig
  32.  * patch2: Renamed utime and stime to avoid name clashes.
  33.  * 
  34.  * Revision 3.0.1.1  89/11/16  18:28:21  craig
  35.  * patch1: Statistics are now reported in Linda implementation.
  36.  * 
  37.  * Revision 3.0  89/10/27  17:05:45  craig
  38.  * Baseline for first official release.
  39.  * 
  40.  */
  41. #include <stdio.h>
  42. #include <signal.h>
  43. #ifdef SYSV
  44. #include <sys/types.h>
  45. #include <sys/times.h>
  46. #include <sys/param.h>
  47. #else
  48. #ifndef AZTEC_C
  49. #ifdef OSK
  50. #include <setsys.h>
  51. #include <procid.h>
  52. #include <time.h>
  53. #else
  54. #include <sys/time.h>
  55. #include <sys/resource.h>
  56. #endif
  57. #endif
  58. #endif
  59. #include "constants.h"
  60. #include "typedefs.h"
  61. #include "defaults.h"
  62.  
  63. unsigned long    EyeRays,    /* # of eye rays spawned */
  64.         ShadowRays,    /* # of shadow rays spawned */
  65.         ReflectRays,    /* # of reflected rays */
  66.         RefractRays,    /* # of refracted rays */
  67.         HitRays,    /* # of rays which hit something. */
  68.         BVTests,    /* # of bounding volume tests. */
  69.         SuperSampled;    /* # of supersampled pixels. */
  70. double        ftmp;        /* Used by fabs() macro. */
  71. double        Utime, Stime;    /* user, system CPU time */
  72. FILE        *fstats;    /* Statistics file */
  73.  
  74. /*
  75.  * LINDA silliness.
  76.  */
  77. #ifdef LINDA
  78. rayshade_main(argc, argv)
  79. #else
  80. main(argc, argv)
  81. #endif
  82. int argc;
  83. char **argv;
  84. {
  85.     unsigned long TotalRays;
  86.     extern int Verbose, Cache, Jittered;
  87.     extern unsigned long CacheWorked, CacheFailed, ShadowHits;
  88. #ifdef LINDA
  89.     extern int Workers;
  90. #endif
  91.  
  92.     /*
  93.       * Initialize variables, etc.
  94.      */
  95.     setup();
  96.     /*
  97.      * Parse options from command line.
  98.      */
  99.     parse_options(argc, argv);
  100.     /*
  101.      * Process input file.
  102.      */
  103.     if (Verbose) {
  104.         print_version();
  105.         fprintf(fstats,"Reading input file...\n");
  106.         fflush(fstats);
  107.     }
  108.     read_input_file();
  109.     /*
  110.      * Set variables which weren't set on command line
  111.      * or in input file.
  112.      */
  113.     cleanup();
  114.     /*
  115.      * Start new picture.
  116.      */
  117.     startpic(argv);
  118.     /*
  119.      * Set up viewing parameters.
  120.      */
  121.     viewing();
  122.     /*
  123.      * Set up world.
  124.      */
  125.     if (Verbose)
  126.         fprintf(fstats,"Setting up voxels...\n");
  127.     SetupWorld();
  128.     get_cpu_time(&Utime, &Stime);
  129.     fprintf(fstats,"Preprocessing time:\t");
  130.     fprintf(fstats,"%2.2lfu  %2.2lfs\n",Utime, Stime);
  131.     fprintf(fstats,"Starting trace.\n");
  132.     fflush(fstats);
  133.     /*
  134.      * Trace the image.
  135.      */
  136.     raytrace();
  137.     /*
  138.      * Close the image file.
  139.      */
  140.     endpic();
  141. #ifndef LINDA
  142.     get_cpu_time(&Utime, &Stime);
  143. #endif
  144.  
  145.     TotalRays = EyeRays + ShadowRays + ReflectRays + RefractRays;
  146.     ShadowHits += CacheWorked;
  147.     HitRays += ShadowHits;
  148. #ifdef LINDA
  149.     fprintf(fstats,"Workers:\t\t\t%d\n",Workers);
  150. #endif
  151.     fprintf(fstats,"Eye rays:\t\t\t%ld\n", EyeRays);
  152.     fprintf(fstats,"Shadow rays:\t\t\t%ld\n",ShadowRays);
  153.     fprintf(fstats,"Reflected rays:\t\t\t%ld\n",ReflectRays);
  154.     fprintf(fstats,"Refracted rays:\t\t\t%ld\n",RefractRays);
  155.     fprintf(fstats,"Total rays:\t\t\t%ld\n", TotalRays);
  156.     if (TotalRays != 0.)
  157.         fprintf(fstats,"Intersecting rays:\t\t%ld (%3.3f%%)\n",
  158.             HitRays, 100. * (float)HitRays / (float)TotalRays);
  159.     if (ShadowRays != 0) {
  160.         if (Cache)
  161.             fprintf(fstats,"Shadow cache hits:\t\t%ld (%ld misses)\n",
  162.                 CacheWorked, CacheFailed);
  163.         fprintf(fstats,"Total shadow hits:\t\t%ld (%3.3f%%)\n",
  164.             ShadowHits, 100.*(float)ShadowHits / (float)ShadowRays);
  165.     }
  166.     if (!Jittered)
  167.         fprintf(fstats,"Supersampled pixels:\t\t%ld\n",SuperSampled);
  168.     fprintf(fstats,"B.V. intersection tests:\t%ld\n", BVTests);
  169.     print_prim_stats();
  170. #ifdef LINDA
  171.     fprintf(fstats,"Average CPU time/processor:\t");
  172. #else
  173.     fprintf(fstats,"Total CPU time (sec):\t\t");
  174. #endif
  175.     fprintf(fstats,"%2.2lf (%2.2lfu + %2.2lfs)\n",Utime+Stime, Utime, Stime);
  176.     if (TotalRays != 0.)
  177.         fprintf(fstats,"Seconds / ray:\t\t\t%4.4lf\n",
  178.                 (Utime + Stime) / (double)TotalRays);
  179.     if (HitRays != 0.)
  180.         fprintf(fstats, "Seconds / intersecting ray:\t%4.4lf\n",
  181.                 (Utime + Stime) / (double)HitRays);
  182.     PrintMemoryStats();
  183.     exit(0);
  184. }
  185.  
  186. #ifdef SYSV
  187. get_cpu_time(usertime, systime)
  188. double *usertime, *systime;
  189. {
  190.     struct tms time;
  191.  
  192.     (void)times(&time);
  193.     *usertime = (double)time.tms_utime / (double)HZ;
  194.     *systime = (double)time.tms_stime / (double)HZ;
  195. }
  196. #else
  197. #ifdef OSK
  198. get_cpu_time(usertime, systime)
  199. double *usertime, *systime;
  200. {
  201.    short ts;
  202.    procid pd;
  203.  
  204.    ts = _getsys(D_TckSec,2);
  205.    _get_process_desc(getpid(),sizeof(pd),&pd);
  206.    *usertime = (double)pd._uticks/(double)ts;
  207.    *systime = (double)pd._sticks/(double)ts;
  208. }
  209. #else
  210. #ifdef AZTEC_C
  211. get_cpu_time()
  212. {
  213. }
  214. #else    /* !SYSV && !AZTEC_C */
  215. get_cpu_time(usertime, systime)
  216. double *usertime, *systime;
  217. {
  218.     struct rusage usage;
  219.  
  220.     getrusage(RUSAGE_SELF, &usage);
  221.  
  222.     *usertime = (double)usage.ru_utime.tv_sec +
  223.             (double)usage.ru_utime.tv_usec / 1000000.;
  224.     *systime = (double)usage.ru_stime.tv_sec +
  225.             (double)usage.ru_stime.tv_usec / 1000000.;
  226. }
  227. #endif
  228. #endif
  229. #endif
  230.