home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / main.c < prev    next >
C/C++ Source or Header  |  1996-03-19  |  5KB  |  216 lines

  1. // This is the main program of the VR-386 port of
  2. // the REND386 V5.0 demo program.  It may be used as
  3. // a template for your own software.  Some changed
  4. // to INIT.C may also be needed.
  5.  
  6. // 9/1/94 by Dave Stampe
  7.  
  8. /*
  9.  This code is part of the VR-386 project, created by Dave Stampe.
  10.  VR-386 is a desendent of REND386, created by Dave Stampe and
  11.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  12.  Stampre for VR-386.
  13.  
  14.  Copyright (c) 1994 by Dave Stampe:
  15.  May be freely used to write software for release into the public domain
  16.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  17.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  18.  this software or source code into their products!  Usually there is no
  19.  charge for under 50-100 items for low-cost or shareware products, and terms
  20.  are reasonable.  Any royalties are used for development, so equipment is
  21.  often acceptable payment.
  22.  
  23.  ATTRIBUTION:  If you use any part of this source code or the libraries
  24.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  25.  and any other authors in your documentation, source code, and at startup
  26.  of your program.  Let's keep the freeware ball rolling!
  27.  
  28.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  29.  REND386, improving programmer access by rewriting the code and supplying
  30.  a standard API.  If you write improvements, add new functions rather
  31.  than rewriting current functions.  This will make it possible to
  32.  include you improved code in the next API release.  YOU can help advance
  33.  VR-386.  Comments on the API are welcome.
  34.  
  35.  CONTACT: dstampe@psych.toronto.edu
  36. */
  37.  
  38.  
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <math.h>
  43. #include <ctype.h>   /* toupper() */
  44. #include <string.h>
  45. #include <mem.h>     /* memmove() */
  46. #include <dos.h>
  47. #include <alloc.h>   /* coreleft */
  48.  
  49. #include "pointer.h"
  50. #include "vr_api.h"
  51. #include "intmath.h"
  52. #include "pcdevice.h"
  53. #include "splits.h"
  54. #include "oldtasks.h"
  55. #include "vrconst.h"
  56.  
  57. #include "f3dkitd.h"  /* for load_dac_colors() */
  58.  
  59.  
  60. BOOL running = 0;
  61. BOOL in_graphics = 0;
  62.  
  63. /************* STEREOSCOPIC DATA ***************/
  64.  
  65. extern STEREO default_stereo;
  66. extern WORD stereo_type;
  67.  
  68. /************ OPTIONS FLAGS ***************/
  69.  
  70. extern int use_ht;
  71. extern int have_ptr;
  72. extern int have_glove;
  73.  
  74. extern int use_BW;
  75. extern int swap_eyes;
  76. extern int use_glove;
  77.  
  78. TASK *tasklist = NULL;
  79.  
  80.  
  81.  
  82. int mouse_nav = 0;    // use mouse as joystick
  83. extern use_keyjoy;    // use keys as joystick
  84. int flymode = 0;
  85.  
  86. // some options
  87.  
  88. int animatemode = 1;
  89. int do_horizon = 1;
  90. int show_location = 1; /* if set, we display the current location on-screen */
  91. int show_compass = 1; /* if set, we display the 3-D compass on-screen */
  92. int show_framerate = 1; /* if set, we display the frames/second rate */
  93. int do_screen_clear = 1; /* by default, we clear the screen on each frame */
  94. int use_frame = 0; /* if set, draw a "frame" */
  95.  
  96.  
  97.  
  98. // some test values
  99.  
  100. unsigned hcolors[20] = { 0xaf, 0xae, 0xad, 0xac, 0x79, 0x7a, 0x7b, 0x7c };
  101.  
  102. test_h()
  103. {
  104.  set_horizon(8, hcolors, 48);
  105. }
  106.  
  107.  
  108. /********** CLOSE PROGRAM ***********/
  109.  
  110. static char *closing_msg[] = {
  111.     "",
  112.     NULL };
  113.  
  114.  
  115. void wrap(void) /* end program */
  116. {
  117.     int i;
  118.     exit_handler();
  119.     for (i = 0; closing_msg[i]; ++i)
  120.        fprintf(stderr, "%s\n", closing_msg[i]);
  121. }
  122.  
  123.  
  124. /************** MAIN PROGRAM ***************/
  125.  
  126.  
  127. refresh_display()
  128. {
  129.   update_body_links();
  130.   screen_refresh(current_camera);
  131.  
  132.   position_changed = 0;
  133.   world_changed = 0;
  134.   display_changed = 0;
  135. }
  136.  
  137.  
  138.  
  139. extern char *title[];   // world title display (3 seconds)
  140.  
  141. void main(int argc, char *argv[])
  142. {
  143.   int i;
  144.   long t;
  145.  
  146.   if (getenv("REND386"))                     // start up path
  147.     strcpy(loadpath, getenv("REND386"));
  148.  
  149.   title_screen();              // title screen
  150.  
  151.   preload_initialize(argc, argv);
  152.  
  153.   create_default_segs();         /* for animations */
  154.   create_default_lights();              // for world loading
  155.  
  156.   read_input_files(argc, argv);     // get any files to be loaded
  157.  
  158.   atexit(wrap);
  159.  
  160.   load_memory_report();
  161.  
  162.   wait_for_title();
  163.  
  164.   video_initialize();
  165.  
  166.   device_initialize();
  167.  
  168.   test_h();  // TEST MULTI HORIZON
  169.  
  170.   if (title[0])
  171.     {
  172.       refresh_display();
  173.       poptext(title);
  174.       get_response(0);
  175.       t = current_time();
  176.       while ((current_time()-t) < 3000)
  177.     {
  178.       if (get_response(0)) break;
  179.     }
  180.       while (kbhit()) getch();
  181.       refresh_display();
  182.     }
  183.  
  184.   running = 1;
  185.   while (running)    // THE EXECUTE LOOP
  186.     {
  187.         // process any keys (do BEFORE joystick_process)
  188.        key_process();
  189.         // mouse joy device mode
  190.        joy_set_mode( ((mouse_nav!=0)?MJOY_ENABLE:0) | ((flymode!=0)?MJOY_VELOCITY:0) );
  191.         // navigate
  192.        joystick_process();
  193.         // menu, object selection: do AFTER joy (mouse counters)
  194.        mouse_process();
  195.         // head tracker
  196.        if (use_ht) head_tracker_process(0);
  197.         // gloves, 3D pointers
  198.        if (use_glove)
  199.      {
  200.        if(!have_ptr) glove_process();
  201.        else pointer_process();
  202.      }
  203.         // animation
  204.        if (animatemode==-1) animatemode = 0; /* single step OFF */
  205.        if (animatemode)
  206.      {
  207.        run_tasks(tasklist);
  208.        do_animations();
  209.      }
  210.         // update screen if needed
  211.        if (position_changed || display_changed || world_changed)
  212.          refresh_display();
  213.      }
  214. }
  215.  
  216.