예제 #1
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            int i;

            // The state might already have been created using
            // the Initial State Partner above. If so, then we
            // don't want to create a new one!
            if (_state == null)
            {
                _state = new SoarMazeSimulatorState();
                // Do any other initialization here for the default
                // settings that you might want ...
            }

            // TT Feb-2007 - Shock! Horror! Setting the maze in the config
            // file did not work because it was initialized in the constructor
            // for the State!
            // The maze here is one with lots of different objects including some balls
            // Note the path - It is relative to where dsshost is started from
            // Other samples are:
            // ModelSmall.gif -- A smaller model than the one above
            // office.bmp -- A black and white image of an "office" maze
            // Jul-2007:
            // Changed the location of the files
            if (_state.Maze == null || _state.Maze == "")
                _state.Maze = "Apps/Soar/SoarMazeSimulator/ModelLarge.bmp";

            // Make sure that there is a floor texture
            // Plenty of others to try, e.g. concrete.jpg.
            if (_state.GroundTexture == null || _state.GroundTexture == "")
                _state.GroundTexture = "cellfloor.jpg";

            // TT Dec-2006 - This is a fudge to support upgrading from
            // prior versions where the RobotType did not exist. When
            // MSRS loades the config file, it does not populate any
            // of the fields that are missing. Therefore the RobotType
            // is null and this causes the code to crash later on.
            if (_state.RobotType == null)
                _state.RobotType = "Pioneer3DX";

            // Now initialize our internal copies of state info
            // This is a little bit of insurance against a bad
            // config file ...
            // Copy as many textures as available up to the max
            for (i = 0; (i < 16) && (i < _state.WallTextures.Length); i++)
            {
                _WallTextures[i] = _state.WallTextures[i];
            }
            // Fill any remaining textures with empty string
            for ( ; i < 16; i++)
                _WallTextures[i] = "";

            // Copy as many colors as specified
            // NOTE: The constructor for the State sets all of the
            // colors to the standard ones, so any that are not
            // specified will default to them.
            for (i = 0; (i < 16) && (i < _state.WallColors.Length); i++)
            {
                _WallColors[i] = _state.WallColors[i];
            }
            // Fill any remaining colors with the defaults
            for (; i < 16; i++)
                _WallColors[i] = SoarMazeSimulatorState.DefaultColors[i];

            // Copy as many heights as specified
            for (i = 0; (i < 16) && (i < _state.HeightMap.Length); i++)
            {
                _WallHeights[i] = _state.HeightMap[i];
            }
            // Fill any remaining heights with the defaults
            for (; i < 16; i++)
                _WallHeights[i] = 5.0f;

            // Copy as many weights as specified
            for (i = 0; (i < 16) && (i < _state.MassMap.Length); i++)
            {
                _WallMasses[i] = _state.MassMap[i];
            }
            // Fill any remaining weights with the defaults
            for (; i < 16; i++)
                _WallMasses[i] = 0.0f;

            // Copy as many sphere flags as specified
            for (i = 0; (i < 16) && (i < _state.UseSphere.Length); i++)
            {
                _UseSphere[i] = _state.UseSphere[i];
            }
            // Fill any remaining flags with false
            for (; i < 16; i++)
                _UseSphere[i] = false;

            if (_state.SphereScale <= 0.0f)
                _state.SphereScale = 1.0f;

            if (_state.HeightScale <= 0.0f)
                _state.HeightScale = 1.0f;

            // Copy back our private versions which might have the
            // effect of extending the state
            _state.WallColors = _WallColors;
            _state.WallTextures = _WallTextures;
            _state.HeightMap = _WallHeights;
            _state.MassMap = _WallMasses;
            _state.UseSphere = _UseSphere;

            // Now save the State
            // This creates a new file the first time it is run
            // Later, it re-reads the existing file, but by then
            // the file has been populated with the defaults
            SaveState(_state);

            // Listen on the main port for requests and call the appropriate handler.
            ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");

            // Cache references to simulation/rendering and physics
            _physicsEngine = PhysicsEngine.GlobalInstance;
            _simEnginePort = SimulationEngine.GlobalInstancePort;

            // TT Dec-2006 - Set up the initial camera view
            SetupCamera();

            // Add objects (entities) in our simulated world
            PopulateWorld();
        }
예제 #2
0
 public virtual IEnumerator<ITask> ReplaceHandler(Replace replace)
 {
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }