home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- //////////////////////////////////////////////////////////////////////
- // Simulation.c++ - implementation of the simulation class
- //
- // This is the main loop.
- //////////////////////////////////////////////////////////////////////
-
- #include <math.h>
- #include "Car.h"
- #include "Road.h"
- #include "Driver.h"
- #include "Sound.h"
- #include "Simulation.h"
-
- Simulation::Simulation(
- SbString roadfile, SbString carfile, SbString path,
- int num_robots, Boolean quiet, Boolean race)
- {
- // initial guest at frames per second, will get updated soon
- _fps = 60.0;
-
- // set up audio
- if (quiet)
- _sound_capable = FALSE;
- else
- _sound_capable = audio_lib_capable();
-
- _play_sound = _sound_capable;
-
- _path = path.getString();
- SbString slash("/");
- _path += slash;
-
- SbString pathroad(_path.getString());
- pathroad += roadfile;
- _road = new Road(pathroad);
-
- // create list of cars in this simulation
- _car_list = new SbPList();
-
- // create the local car, always at position 0 in car list
- SbString pathcar(_path.getString());
- pathcar += carfile;
- _car_list->append(new Car(this, pathcar, _road, LOCAL_CAR));
-
- // add some robot cars
- for (int i = 0; i < num_robots; i++)
- _car_list->append(new Car(this, pathcar, _road, ROBOT_CAR));
-
- // if racing, add other car
- if (race)
- printf("Yup. We're racing!\n");
- /*
- {
- _network = new Network();
- SbPlist other_cars = _network->getOthers();
-
- for (int i = 0; i < other_cars.length(); i++)
- _car_list->append(other_cars[i]);
- }
- else
- _network = NULL;
- */
-
- }
-
-
- Simulation::~Simulation()
- {
- delete _road;
-
- // work-around for c++ delete bug
- for (int i = 0; i < _car_list->length(); i++)
- delete (Car *)((* _car_list)[i]);
-
- delete _car_list;
- }
-
-
- void Simulation::go()
- {
- Boolean done = FALSE;
-
- while (! done)
- {
- int num_cars = _car_list->length();
-
- // it is ok for the process to go sleep if we are the only
- // car, or the driver is looking at the help screen.
- Boolean ok_to_sleep = (num_cars == 1) ||
- ((Car *)(* _car_list)[0])->get_driver()->helping();
-
- for (int i = 0; i < num_cars ; i++)
- // OK for update process to sleep if there is only one car
- ((Car *)(* _car_list)[i])->update(ok_to_sleep);
-
- // frames per second seen by the local driver
- _fps = ((Car *)(* _car_list)[0])->get_driver()->get_fps();
-
- // done if the local car is done
- done = ((Car *)(* _car_list)[0])->done();
- }
- }
-
-