Example #1
0
        protected override void OnUpdate(float delta)
        {
            base.OnUpdate(delta);

            if (menuWindow != null && menuWindow.Disposed)
            {
                menuWindow = null;
            }

            //Game mode
            if (sceneViewport != null)
            {
                var inputEnabled = InputEnabled;

                //send input enabled changed
                if (gameMode != null && gameModeLastSentInputEnabled != inputEnabled)
                {
                    gameModeLastSentInputEnabled = inputEnabled;
                    gameMode.ProcessInputMessage(this, new InputMessageInputEnabledChanged(inputEnabled));
                }

                //update mouse relative mode
                {
                    if (gameMode != null && inputEnabled)
                    {
                        sceneViewport.MouseRelativeMode = gameMode.IsNeedMouseRelativeMode();
                    }
                    else
                    {
                        sceneViewport.MouseRelativeMode = false;
                    }

                    //send message
                    if (gameMode != null && gameModeLastSentMouseRelativeMode != sceneViewport.MouseRelativeMode)
                    {
                        gameModeLastSentMouseRelativeMode = sceneViewport.MouseRelativeMode;
                        gameMode.ProcessInputMessage(this, new InputMessageMouseRelativeModeChanged(gameModeLastSentMouseRelativeMode));
                    }
                }
            }

            // Update sound listener.
            if (scene != null && sceneViewport != null)
            {
                var settings = sceneViewport.CameraSettings;
                SoundWorld.SetListener(scene, settings.Position, Vector3.Zero, settings.Rotation);
            }
            else
            {
                SoundWorld.SetListenerReset();
            }

            // Scene simulation.
            if (scene != null && scene.HierarchyController != null)
            {
                scene.HierarchyController.PerformSimulationSteps();
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="game"></param>
        public FXPlayback(GameWorld world)
        {
            this.world = world;
            this.game  = world.Game;
            this.rw    = game.RenderSystem.RenderWorld;
            this.sw    = game.SoundSystem.SoundWorld;

            Game_Reloading(this, EventArgs.Empty);
            game.Reloading += Game_Reloading;
        }
Example #3
0
        public ModelManager(GameWorld world)
        {
            this.world = world;
            this.game  = world.Game;
            this.rs    = game.RenderSystem;
            this.rw    = game.RenderSystem.RenderWorld;
            this.sw    = game.SoundSystem.SoundWorld;

            Game_Reloading(this, EventArgs.Empty);
            game.Reloading += Game_Reloading;

            models = new LinkedList <ModelInstance>();
        }
Example #4
0
        protected override void OnUpdate(float delta)
        {
            base.OnUpdate(delta);

            // Update background scene.
            if (currentDisplayBackgroundSceneOption != SimulationApp.DisplayBackgroundScene)
            {
                currentDisplayBackgroundSceneOption = SimulationApp.DisplayBackgroundScene;

                if (currentDisplayBackgroundSceneOption && EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Simulation)
                {
                    var fileName = BackgroundScene.GetByReference;
                    if (!string.IsNullOrEmpty(fileName) && VirtualFile.Exists(fileName))
                    {
                        LoadScene(fileName);
                    }
                    else
                    {
                        LoadScene("");
                    }
                }
                else
                {
                    LoadScene("");
                }
            }

            // Update sound listener.
            if (scene != null && sceneViewport != null)
            {
                var settings = sceneViewport.CameraSettings;
                SoundWorld.SetListener(scene, settings.Position, Vector3.Zero, settings.Rotation);
            }
            else
            {
                SoundWorld.SetListenerReset();
            }

            // Scene simulation.
            if (scene != null && scene.HierarchyController != null)
            {
                scene.HierarchyController.PerformSimulationSteps();
            }

            if (!firstRender)
            {
                fadeInTimer += delta;
            }
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sfxSystem"></param>
        /// <param name="fxEvent"></param>
        public FXInstance(FXPlayback sfxSystem, FXEvent fxEvent, FXFactory fxFactory, bool looped)
        {
            this.fxAtom     = fxEvent.FXAtom;
            this.fxPlayback = sfxSystem;
            this.rw         = sfxSystem.rw;
            this.sw         = sfxSystem.sw;
            this.fxEvent    = fxEvent;

            AddParticleStage(fxFactory.ParticleStage1, fxEvent, looped);
            AddParticleStage(fxFactory.ParticleStage2, fxEvent, looped);
            AddParticleStage(fxFactory.ParticleStage3, fxEvent, looped);
            AddParticleStage(fxFactory.ParticleStage4, fxEvent, looped);

            AddLightStage(fxFactory.LightStage, fxEvent, looped);
            AddSoundStage(fxFactory.SoundStage, fxEvent, looped);
        }
Example #6
0
        public override void StartAudioStream()
        {
            if (sound != null)
            {
                return;
            }

            SoundModes mode       = SoundModes.Loop | SoundModes.Stream;
            int        channels   = vorbisInfo.channels;
            int        bufferSize = soundBufferSize;

            if (oggFile.Sound3D)
            {
                mode |= SoundModes.Mode3D;
                if (vorbisInfo.channels == 2)
                {
                    channels    = 1;
                    bufferSize /= 2;
                }
            }

            sound = SoundWorld.SoundCreateDataBuffer(mode, channels, vorbisInfo.rate, bufferSize, ReadData);

            if (sound == null)
            {
                return;
            }

            //!!!!attachedToScene
            channel = SoundWorld.SoundPlay(null, sound, EngineApp.DefaultSoundChannelGroup, 1, true);

            if (channel != null)
            {
                if (oggFile.Sound3D)
                {
                    channel.Position = oggFile.SoundPosition;
                }
                channel.Volume = oggFile.Volume;
                channel.Pause  = oggFile.Pause;
            }
        }
Example #7
0
        void Play(bool loop)
        {
            var soundComponent = ObjectForPreview as Component_Sound;

            if (soundComponent != null && soundComponent.Result != null)
            {
                long   length   = 0;
                string fileName = soundComponent.LoadFile.Value.ResourceName;
                if (!string.IsNullOrEmpty(fileName))
                {
                    try
                    {
                        length = VirtualFile.GetLength(fileName);
                        //using( var stream = VirtualFile.Open( fileName ) )
                        //	length = (int)stream.Length;
                    }
                    catch { }
                }

                if (length != 0)
                {
                    SoundModes mode = 0;
                    if (Path.GetExtension(fileName).ToLower() == ".ogg" && length > 400000)
                    {
                        mode |= SoundModes.Stream;
                    }
                    if (loop)
                    {
                        mode |= SoundModes.Loop;
                    }

                    sound = soundComponent.Result.LoadSoundByMode(mode);
                    if (sound != null)
                    {
                        channel = SoundWorld.SoundPlay(null, sound, EngineApp.DefaultSoundChannelGroup, .5f);
                    }
                }
            }
        }
Example #8
0
        void UpdateSoundSystem()
        {
            //listener
            {
                var documentWithViewport = EditorAPI.SelectedDocumentWindow as DocumentWindowWithViewport;
                var viewport             = documentWithViewport?.ViewportControl?.Viewport;

                var scene = viewport?.AttachedScene;
                if (scene != null && scene.EnabledInHierarchy)
                {
                    var settings = viewport.CameraSettings;
                    SoundWorld.SetListener(scene, settings.Position, Vector3.Zero, settings.Rotation);
                }
                else
                {
                    SoundWorld.SetListenerReset();
                }
            }

            //volume
            EngineApp.DefaultSoundChannelGroup.Volume = ProjectSettings.Get.SoundVolume;
        }
Example #9
0
        public bool Load(string fileName, bool canChangeUIControl)
        {
            DestroyLoadedObject(canChangeUIControl);

            playFileName = fileName;

            SoundWorld.SetListenerReset();

            if (!string.IsNullOrEmpty(playFileName) && VirtualFile.Exists(playFileName))
            {
                string extension = Path.GetExtension(PlayFileName).Replace(".", "").ToLower();
                if (extension == "scene")
                {
                    return(LoadScene(canChangeUIControl));
                }
                if (extension == "ui")
                {
                    return(LoadUIControl());
                }
            }

            return(false);
        }
        public static void EngineApp_AppCreateAfter()
        {
            Log.Handlers.InvisibleInfoHandler += InvisibleLog_Handlers_InfoHandler;
            Log.Handlers.InfoHandler          += Log_Handlers_InfoHandler;
            Log.Handlers.WarningHandler       += Log_Handlers_WarningHandler;
            Log.Handlers.ErrorHandler         += Log_Handlers_ErrorHandler;
            Log.Handlers.FatalHandler         += Log_Handlers_FatalHandler;

            EngineApp.RegisterConfigParameter += EngineApp_RegisterConfigParameter;

            EngineConsole.Init();
            //!!!!
            //GameControlsManager.Init();

            //UIControl engineLoadingWindow = ResourceManager.LoadSeparateInstance<UIControl>( "Base\\UI\\Windows\\EngineLoadingWindow.ui", false, null );
            //if( engineLoadingWindow != null )
            //	MainViewport.UIContainer.AddComponent( engineLoadingWindow );

            ////Subcribe to callbacks during engine loading. We will render scene from callback.
            //LongOperationCallbackManager.Subscribe( LongOperationCallbackManager_LoadingCallback, programLoadingWindow );

            EngineApp.Tick += EngineApp_Tick;

            ////finish initialization of materials and hide loading window.
            ////!!!!!!
            ////LongOperationCallbackManager.Unsubscribe();
            //if( engineLoadingWindow != null )
            //	engineLoadingWindow.RemoveFromParent( true );

            //subscribe to main viewport events
            {
                MainViewport.KeyDown                 += MainViewport_KeyDown;
                MainViewport.KeyPress                += MainViewport_KeyPress;
                MainViewport.KeyUp                   += MainViewport_KeyUp;
                MainViewport.MouseDown               += MainViewport_MouseDown;
                MainViewport.MouseUp                 += MainViewport_MouseUp;
                MainViewport.MouseDoubleClick        += MainViewport_MouseDoubleClick;
                MainViewport.MouseMove               += MainViewport_MouseMove;
                MainViewport.MouseWheel              += MainViewport_MouseWheel;
                MainViewport.JoystickEvent           += MainViewport_JoystickEvent;
                MainViewport.SpecialInputDeviceEvent += MainViewport_SpecialInputDeviceEvent;

                //!!!!!Tick +=

                MainViewport.UpdateBegin        += MainViewport_UpdateBegin;
                MainViewport.UpdateBeforeOutput += MainViewport_UpdateBeforeOutput;
                MainViewport.UpdateEnd          += MainViewport_UpdateEnd;
            }

            //change application title
            if (EngineApp.CreatedInsideEngineWindow != null)
            {
                EngineApp.CreatedInsideEngineWindow.Title = ProjectSettings.Get.ProjectName;
            }

            //update sound volume
            if (EngineApp.DefaultSoundChannelGroup != null)
            {
                EngineApp.DefaultSoundChannelGroup.Volume = soundVolume;
            }

            //create music channel group
            musicChannelGroup = SoundWorld.CreateChannelGroup("Music");
            if (musicChannelGroup != null)
            {
                SoundWorld.MasterChannelGroup.AddGroup(musicChannelGroup);
                musicChannelGroup.Volume = musicVolume;
            }


            PlayerInv.Name = "PlayerInv";
            PlayerInv.InitialItems.Add("Water, 20");
            PlayerInv.InitialItems.Add("Seed, 4");
            PlayerInv.InitialItems.Add("Empty, 0");
            PlayerInv.InitialItems.Add("Empty, 0");
            PlayerInv.InitialItems.Add("Empty, 0");
            PlayerInv.CalcInitialItems();
            PlayerInv.CalcImagePaths();
        }
Example #11
0
        protected override void OnEnabledInSimulation()
        {
            instance = this;

            if (Components["Button Scenes"] != null)
            {
                ((UIButton)Components["Button Scenes"]).Click += ButtonScenes_Click;
            }
            if (Components["Button Options"] != null)
            {
                ((UIButton)Components["Button Options"]).Click += ButtonOptions_Click;
            }
            if (Components["Button Exit"] != null)
            {
                ((UIButton)Components["Button Exit"]).Click += ButtonExit_Click;
            }

            //play buttons
            if (Components["Button Play Sci-fi Demo"] != null)
            {
                var button   = (UIButton)Components["Button Play Sci-fi Demo"];
                var fileName = @"Samples\Sci-fi Demo\Scenes\Sci-fi Demo.scene";
                button.AnyData = fileName;
                button.Click  += ButtonPlay_Click;
                if (button.Visible)
                {
                    button.Visible = VirtualFile.Exists(fileName);
                }
            }
            if (Components["Button Play Nature Demo"] != null)
            {
                var button   = (UIButton)Components["Button Play Nature Demo"];
                var fileName = @"Samples\Nature Demo\Scenes\Nature Demo.scene";
                button.AnyData = fileName;
                button.Click  += ButtonPlay_Click;
                if (button.Visible)
                {
                    button.Visible = VirtualFile.Exists(fileName);
                }
            }
            if (Components["Button Play Simple Game"] != null)
            {
                var button   = (UIButton)Components["Button Play Simple Game"];
                var fileName = @"Samples\Simple Game\SimpleGameLevel1.scene";
                button.AnyData = fileName;
                button.Click  += ButtonPlay_Click;
                if (button.Visible)
                {
                    button.Visible = VirtualFile.Exists(fileName);
                }
            }
            if (Components["Button Play Character Scene"] != null)
            {
                var button   = (UIButton)Components["Button Play Character Scene"];
                var fileName = @"Samples\Starter Content\Scenes\Character.scene";
                button.AnyData = fileName;
                button.Click  += ButtonPlay_Click;
                if (button.Visible)
                {
                    button.Visible = VirtualFile.Exists(fileName);
                }
            }
            if (Components["Button Play Spaceship 2D"] != null)
            {
                var button   = (UIButton)Components["Button Play Spaceship 2D"];
                var fileName = @"Samples\Starter Content\Scenes\Spaceship control 2D.scene";
                button.AnyData = fileName;
                button.Click  += ButtonPlay_Click;
                if (button.Visible)
                {
                    button.Visible = VirtualFile.Exists(fileName);
                }
            }
            if (Components["Button Play Character 2D"] != null)
            {
                var button   = (UIButton)Components["Button Play Character 2D"];
                var fileName = @"Samples\Starter Content\Scenes\Character 2D.scene";
                button.AnyData = fileName;
                button.Click  += ButtonPlay_Click;
                if (button.Visible)
                {
                    button.Visible = VirtualFile.Exists(fileName);
                }
            }

            // Update sound listener.
            SoundWorld.SetListenerReset();

            // Load background scene.
            currentDisplayBackgroundSceneOption = SimulationApp.DisplayBackgroundScene;
            if (currentDisplayBackgroundSceneOption && EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Simulation)
            {
                var fileName = BackgroundScene.GetByReference;
                if (!string.IsNullOrEmpty(fileName) && VirtualFile.Exists(fileName))
                {
                    LoadScene(fileName);
                }
                else
                {
                    LoadScene("");
                }
            }
            else
            {
                LoadScene("");
            }
        }
Example #12
0
		//

		public OpenALDataStreamSound( SoundMode mode, int channels, int frequency, int bufferSize,
			SoundWorld.DataReadDelegate dataReadCallback )
		{
			this.channels = channels;
			this.frequency = frequency;
			this.dataReadCallback = dataReadCallback;
			this.bufferSize = bufferSize;

			if( !GenerateBuffers( 2 ) )
			{
				Log.Warning( "OpenALSoundSystem: Creating data stream sound failed." );
				return;
			}

			Init( null, mode, 100000.0f, channels, frequency );
		}
Example #13
0
		unsafe public DirectDataStreamSound( SoundMode mode, int channels, int frequency, int bufferSize,
			SoundWorld.DataReadDelegate dataReadCallback )
		{
			this.dataReadCallback = dataReadCallback;
			this.creationBufferSize = bufferSize;

			waveFormat = (WAVEFORMATEX*)NativeUtils.Alloc( NativeMemoryAllocationType.SoundAndVideo,
				sizeof( WAVEFORMATEX ) );
			NativeUtils.ZeroMemory( (IntPtr)waveFormat, sizeof( WAVEFORMATEX ) );
			waveFormat->wFormatTag = DSound.WAVE_FORMAT_PCM;
			waveFormat->nChannels = (ushort)channels;
			waveFormat->nSamplesPerSec = (uint)frequency;
			waveFormat->wBitsPerSample = 16;
			waveFormat->nBlockAlign = (ushort)( ( waveFormat->nChannels * waveFormat->wBitsPerSample ) / 8 );
			waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

			Init( null, mode, 100000.0f, channels, frequency );
		}