static void Main(string[] args) { using (var game = new Game()) { game.Run(); } }
private static void CheckTextureFormat(Game game, string textureUrl, AlphaFormat expectedFormat) { var expectedPixelFormat = PlaformAndAlphaToPixelFormats[Tuple.Create(Platform.Type, expectedFormat)]; var texture = game.Asset.Load<Texture>(textureUrl); Assert.AreEqual(expectedPixelFormat, texture.Format); game.Asset.Unload(texture); }
private void TestAddRemoveListenerImpl(Game game) { var audio = game.Audio; var notAddedToEntityListener = new AudioListenerComponent(); var addedToEntityListener = new AudioListenerComponent(); // Add a listenerComponent not present in the entity system yet and check that it is correctly added to the AudioSystem internal data structures Assert.DoesNotThrow(() => audio.AddListener(notAddedToEntityListener), "Adding a listener not present in the entity system failed"); Assert.IsTrue(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem does not contains the notAddedToEntityListener."); // Add a listenerComponent already present in the entity system and check that it is correctly added to the AudioSystem internal data structures var entity = new Entity("Test"); entity.Add(addedToEntityListener); throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Add(entity); Assert.DoesNotThrow(() => audio.AddListener(addedToEntityListener), "Adding a listener present in the entity system failed"); Assert.IsTrue(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem does not contains the addedToEntityListener."); // Add a listenerComponent already added to audio System and check that it does not crash Assert.DoesNotThrow(()=>audio.AddListener(addedToEntityListener), "Adding a listener already added to the audio system failed."); // Remove the listeners from the AudioSystem and check that they are removed from internal data structures. Assert.DoesNotThrow(() => audio.RemoveListener(notAddedToEntityListener), "Removing an listener not present in the entity system failed."); Assert.IsFalse(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem still contains the notAddedToEntityListener."); Assert.DoesNotThrow(() => audio.RemoveListener(addedToEntityListener), "Removing an listener present in the entity system fails"); Assert.IsFalse(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem still contains the addedToEntityListener."); // Remove a listener not present in the AudioSystem anymore and check the thrown exception Assert.Throws<ArgumentException>(() => audio.RemoveListener(addedToEntityListener), "Removing the a non-existing listener did not throw ArgumentException."); }
public void OneLoopTurnActionAftUpdate(Game game) { if (oneLoopTurnActionAftUpdate != null) oneLoopTurnActionAftUpdate(game, loopCount, loopCountSum); ++loopCount; loopCountSum += loopCount; }
private static void TestScriptAudioAccessImpl(Game game) { using (var script = new ScriptClass(game.Services)) { Assert.DoesNotThrow(() => script.AccessAudioService(), "Access to the audio service failed."); Assert.IsTrue(script.AudioServiceNotNull(), "The Audio service is null."); } }
private void EntityPositionUpdate(Game game, int loopCount, int loopCountSum) { rootSubEntity1.Transform.Position += new Vector3(loopCount, 2 * loopCount, 3 * loopCount); rootSubEntity2.Transform.Position += new Vector3(loopCount, 2 * loopCount, 3 * loopCount); listComp1Entity.Transform.Position += new Vector3(loopCount, 2 * loopCount, 3 * loopCount); listComp2Entity.Transform.Position -= new Vector3(loopCount, 2 * loopCount, 3 * loopCount); }
static void Main(string[] args) { // Profiler.EnableAll(); using (var game = new Game()) { game.Run(); } }
private static void TestSoundMusicLoadingImpl(Game game) { SoundMusic sound = null; Assert.DoesNotThrow(() => sound = game.Asset.Load<SoundMusic>("EffectBip"), "Failed to load the SoundMusic."); Assert.IsNotNull(sound, "The SoundMusic loaded is null."); sound.Play(); // Should hear the sound here. }
private void TestAudioEngineImpl(Game game) { var audio = game.Audio; AudioEngine audioEngine = null; Assert.DoesNotThrow(()=>audioEngine = audio.AudioEngine, "Failed to get the AudioEngine"); Assert.IsNotNull(audioEngine, "The audio engine is null"); Assert.IsFalse(audioEngine.IsDisposed, "The audio engine is disposed"); }
public LiveAssemblyReloader(Game game, AssemblyContainer assemblyContainer, List<Assembly> assembliesToUnregister, List<Assembly> assembliesToRegister) { if (game != null) this.entities.AddRange(game.SceneSystem.SceneInstance); this.game = game; this.assemblyContainer = assemblyContainer; this.assembliesToUnregister = assembliesToUnregister; this.assembliesToRegister = assembliesToRegister; }
public void TestAccessToAudio() { using (var game = new Game()) { AudioSystem audioInterface = null; Assert.DoesNotThrow(()=>audioInterface = game.Audio, "Failed to get the audio interface"); Assert.IsNotNull(audioInterface, "The audio interface supplied is null"); } }
static void Main(string[] args) { // Profiler.EnableAll(); using (var game = new Game()) { game.GraphicsDeviceManager.DeviceCreated += GraphicsDeviceManager_DeviceCreated; ParadoxInputDevice.NativeInputManager = game.Input; game.Run(); } }
private void TestAddAudioSysThenEntitySysSetup(Game game) { var audio = game.Audio; BuildEntityHierarchy(); CreateAndComponentToEntities(); audio.AddListener(listComp1); audio.AddListener(listComp2); listComp2Entity.Transform.RotationEulerXYZ = new Vector3((float)Math.PI/2,0,0); }
public void TestAttachDetachSounds() { var testInst = new AudioEmitterComponent(); using (var game = new Game()) { Game.InitializeAssetDatabase(); using (var audioStream1 = AssetManager.FileProvider.OpenStream("EffectToneA", VirtualFileMode.Open, VirtualFileAccess.Read)) using (var audioStream2 = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read)) using (var audioStream3 = AssetManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read)) { var sound1 = SoundEffect.Load(game.Audio.AudioEngine, audioStream1); var sound2 = SoundEffect.Load(game.Audio.AudioEngine, audioStream2); var sound3 = SoundEffect.Load(game.Audio.AudioEngine, audioStream3); // Attach two soundEffect and check that their controller are correctly created. AudioEmitterSoundController soundController1 = null; AudioEmitterSoundController soundController2 = null; Assert.DoesNotThrow(() => testInst.AttachSoundEffect(sound1), "Adding a first soundEffect failed"); Assert.DoesNotThrow(() => soundController1 = testInst.SoundEffectToController[sound1], "There are no sound controller for sound1."); Assert.IsNotNull(soundController1, "Sound controller for sound1 is null"); Assert.DoesNotThrow(() => testInst.AttachSoundEffect(sound2), "Adding a second soundEffect failed"); Assert.DoesNotThrow(() => soundController2 = testInst.SoundEffectToController[sound2], "There are no sound controller for sound1."); Assert.IsNotNull(soundController2, "Sound controller for sound2 is null"); // Remove the two soundEffect and check that their controller are correctly erased. Assert.DoesNotThrow(() => testInst.DetachSoundEffect(sound2), "Removing a first soundEffect failed"); Assert.IsFalse(testInst.SoundEffectToController.ContainsKey(sound2), "The controller for sound2 is still present in the list."); Assert.DoesNotThrow(() => testInst.DetachSoundEffect(sound1), "Removing a second soundEffect failed"); Assert.IsFalse(testInst.SoundEffectToController.ContainsKey(sound1), "The controller for sound1 is still present in the list."); Assert.IsTrue(testInst.SoundEffectToController.Keys.Count == 0, "There are some controller left in the component list."); // Check the exception thrwon by attachSoundEffect. Assert.Throws<ArgumentNullException>(() => testInst.AttachSoundEffect(null), "AttachSoundEffect did not throw ArgumentNullException"); Assert.Throws<InvalidOperationException>(() => testInst.AttachSoundEffect(sound3), "AttachSoundEffect did not throw InvalidOperationException."); // Check the exception thrown by detachSoundEffect. Assert.Throws<ArgumentNullException>(() => testInst.DetachSoundEffect(null), "DetachSoundEffect did not throw ArgumentNullException."); Assert.Throws<ArgumentException>(() => testInst.DetachSoundEffect(sound1), "DetachSoundEffect did not throw ArgumentException "); } } }
/// <summary> /// Load some default random <see cref="SoundEffect"/>, attach them to the emitter components, and query their controllers. /// </summary> /// <param name="game"></param> private void AddSoundEffectToEmitterComponents(Game game) { sounds = new List<SoundEffect> { game.Asset.Load<SoundEffect>("EffectBip"), game.Asset.Load<SoundEffect>("EffectToneA"), game.Asset.Load<SoundEffect>("EffectToneA"), }; emitComps[0].AttachSoundEffect(sounds[0]); emitComps[0].AttachSoundEffect(sounds[1]); emitComps[1].AttachSoundEffect(sounds[2]); soundControllers = new List<AudioEmitterSoundController> { emitComps[0].GetSoundEffectController(sounds[0]), emitComps[0].GetSoundEffectController(sounds[1]), emitComps[1].GetSoundEffectController(sounds[2]), }; }
private void TestEffectsAndMusicSetup(Game game) { BuildEntityHierarchy(); CreateAndAddListenerComponentToEntities(); CreateAndAddEmitterComponentToEntities(); AddSoundEffectToEmitterComponents(game); AddRootEntityToEntitySystem(game); game.Audio.AddListener(listComps[0]); }
private void TestRemoveListenerSetup(Game game) { BuildEntityHierarchy(); CreateAndAddListenerComponentToEntities(); CreateAndAddEmitterComponentToEntities(); AddSoundEffectToEmitterComponents(game); AddRootEntityToEntitySystem(game); // add an extra listener listComps.Add(new AudioListenerComponent()); listCompEntities.Add(new Entity()); listCompEntities[2].Add(listComps[2]); throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Add(listCompEntities[2]); // isolate the two listeners such that emitter 1 can be heard only by listener 1 and emitter 2 by listener 3 // and place emitters such that emitters 1 output on left ear and emitter 2 on right ear. listCompEntities[0].Transform.Position = listCompEntities[0].Transform.Position - new Vector3(1000,0,0); emitCompEntities[0].Transform.Position = emitCompEntities[0].Transform.Position - new Vector3(1, 0, 0); emitCompEntities[1].Transform.Position = emitCompEntities[1].Transform.Position + new Vector3(1, 0, 0); game.Audio.AddListener(listComps[2]); game.Audio.AddListener(listComps[0]); soundControllers[0].IsLooped = true; soundControllers[2].IsLooped = true; }
/// <inheritdoc/> public void GameStop() { if (game == null) return; game.Exit(); // Wait for game to actually exit? gameFinished.WaitOne(); game = null; }
/// <inheritdoc/> public void GameLaunch(string gameTypeName) { try { Log.Info("Running game with type {0}", gameTypeName); Type gameType; lock (loadedAssemblies) { gameType = GameEnumerateTypesHelper().FirstOrDefault(x => x.FullName == gameTypeName); } if (gameType == null) throw new InvalidOperationException(string.Format("Could not find type [{0}] in project [{1}]", gameTypeName, projectName)); game = (Game)Activator.CreateInstance(gameType); // TODO: Bind database Task.Run(() => { gameFinished.Reset(); try { using (game) { // Allow scripts to crash, we will still restart them game.Script.Scheduler.PropagateExceptions = false; game.Run(); } } catch (Exception e) { Log.Error("Exception while running game", e); } host.OnGameExited(); // Notify we are done gameFinished.Set(); }); } catch (Exception ex) { Log.Error("Game [{0}] from project [{1}] failed to run", ex, gameTypeName, projectName); } }
private void TestRemoveListenerLoopImpl(Game game, int loopCount, int loopCountSum) { if (loopCount == 0) { // check that initially the sound are hear via the two listeners. soundControllers[0].Play(); soundControllers[2].Play(); } // here we should hear the soundEffect 0 on left ear and the soundEffect 2 on right ear else if (loopCount == 60) { // remove listener 3 from the entity system => check that the sounds are now heard only via listener 1 throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Remove(listCompEntities[2]); } // here we should hear the soundEffect 0 on left ear only else if (loopCount == 120) { // remove listener 1 from the audio system => check that the sounds are not outputted anymore. game.Audio.RemoveListener(listComps[0]); } // here we should hear nothing. else if (loopCount == 180) { game.Exit(); } }
private void TestLocalizationCoherencyLoopImpl(Game game, int loopCount, int loopCountSum) { // useless motion on the root entities just to check that is does not disturb to calculations. rootSubEntity1.Transform.Position += new Vector3(1, 2, 3); listCompEntities[0].Transform.Position += new Vector3(3, 2, -1); // have the emitter turn clockwise around the listener. emitCompEntities[0].Transform.Position = new Vector3((float)Math.Cos(loopCount * Math.PI / 100), 0, (float)Math.Sin(loopCount * Math.PI / 100)); // the sound should turn around clockwise if (loopCount == 800) { game.Exit(); } }
private void TestLocalizationCoherencySetup(Game game) { BuildEntityHierarchy(); CreateAndAddListenerComponentToEntities(); CreateAndAddEmitterComponentToEntities(); AddSoundEffectToEmitterComponents(game); AddRootEntityToEntitySystem(game); game.Audio.AddListener(listComps[0]); soundControllers[0].IsLooped = true; soundControllers[0].Play(); }
private void TestAttenuationCoherencyLoopImpl(Game game, int loopCount, int loopCountSum) { // put away progressively the emitter. emitCompEntities[0].Transform.Position = new Vector3(0, 0, loopCount / 10f); // the sound should progressively attenuate if (loopCount == 800) { game.Exit(); } }
private void TestDopplerCoherencyLoopImpl(Game game, int loopCount, int loopCountSum) { // useless motion on the root entities just to check that is does not disturb to calculations. rootSubEntity1.Transform.Position += new Vector3(1, 2, 3); listCompEntities[0].Transform.Position += new Vector3(3, 2, -1); // apply a left to right motion to the emitter entity emitCompEntities[0].Transform.Position = new Vector3(20*(loopCount-200), 0, 2); // the sound should be modified in pitch depending on which side the emitter is // ( first pitch should be increased and then decreased) if (loopCount == 400) { game.Exit(); } }
private void TestDopplerCoherencySetup(Game game) { BuildEntityHierarchy(); CreateAndAddListenerComponentToEntities(); CreateAndAddEmitterComponentToEntities(); AddSoundEffectToEmitterComponents(game); AddRootEntityToEntitySystem(game); game.Audio.AddListener(listComps[0]); emitComps[0].DistanceScale = 200f; // increase distance scale so that the sound can be heard from far away too soundControllers[0].IsLooped = true; soundControllers[0].Play(); }
private void TestAddRemoveEmitterSetup(Game game) { BuildEntityHierarchy(); CreateAndAddListenerComponentToEntities(); AddRootEntityToEntitySystem(game); AddListenersToAudioSystem(game); // isolate the two listeners such that emitter 1 can be heard only by listener 1 and emitter 2 by listener 3 // and place emitters such that emitters 1 output on left ear and emitter 2 on right ear. listCompEntities[0].Transform.Position = listCompEntities[0].Transform.Position - new Vector3(1000, 0, 0); emitCompEntities[0].Transform.Position = emitCompEntities[0].Transform.Position - new Vector3(1, 0, 0); emitCompEntities[1].Transform.Position = emitCompEntities[1].Transform.Position + new Vector3(1, 0, 0); emitComps = new List<AudioEmitterComponent> { new AudioEmitterComponent(), new AudioEmitterComponent() }; emitCompEntities = new List<Entity> { new Entity(), new Entity()}; emitCompEntities[0].Add(emitComps[0]); emitCompEntities[1].Add(emitComps[1]); AddSoundEffectToEmitterComponents(game); }
private void TestSeveralControllersLoopImpl(Game game, int loopCount, int loopCountSum) { // have the emitter turn around the listener to check that all sounds are coming from the same emitter. emitCompEntities[0].Transform.Position = new Vector3((float)Math.Cos(loopCount * Math.PI / 30), 0, (float)Math.Sin(loopCount * Math.PI / 30)); if (loopCount == 0) { // start a first controller soundControllers[0].Play(); } // here we should hear SoundEffect 0 else if (loopCount == 30) { // start a second controller while controller 1 has not finished to play soundControllers[1].Play(); } // here we should hear SoundEffect 0 and 1 else if (loopCount == 60) { // start a third controller while controller 2 has not finished to play soundControllers[3].Play(); } // here we should hear the soundEffect 1 and 2 else if (loopCount == 120) { game.Exit(); } }
private void TestSeveralControllersSetup(Game game) { BuildEntityHierarchy(); CreateAndAddListenerComponentToEntities(); CreateAndAddEmitterComponentToEntities(); AddSoundEffectToEmitterComponents(game); AddRootEntityToEntitySystem(game); game.Audio.AddListener(listComps[0]); sounds.Add(game.Asset.Load<SoundEffect>("EffectToneE")); emitComps[0].AttachSoundEffect(sounds[3]); soundControllers.Add(emitComps[0].GetSoundEffectController(sounds[3])); }
private void TestEffectsAndMusicLoopImpl(Game game, int loopCount, int loopCountSum) { if (loopCount == 0) { // start the sound music in background. var music = game.Asset.Load<SoundMusic>("MusicFishLampMp3"); music.Play(); } // here we should hear the mp3. else if (loopCount == 240) { // check that AudioEmitterComponent can be played along with soundMusic. soundControllers[0].Play(); } // here we should hear the soundEffect 0 and the mp3. else if (loopCount == 260) { // check that two AudioEmitterComponent can be played along with a soundMusic. soundControllers[2].Play(); } // here we should hear the soundEffect 0 and 2 and the mp3. else if (loopCount == 500) { game.Exit(); } }
private void TestAddRemoveEmitterLoopImpl(Game game, int loopCount, int loopCountSum) { if (loopCount == 0) { // check there is no sound output if the emitterComponents are not added to the entity system. soundControllers[0].Play(); soundControllers[2].Play(); } // here we should hear nothing. else if (loopCount == 60) { // add emitter 1 to the entity system throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Add(emitCompEntities[0]); // check that emitter 1 can now be heard. soundControllers[0].Play(); soundControllers[2].Play(); } // here we should hear the soundEffect 0 on left ear only else if (loopCount == 120) { // add now emitter 2 to the entity system throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Add(emitCompEntities[1]); // test that now both emitters can be heard. soundControllers[0].Play(); soundControllers[2].Play(); } // here we should hear the soundEffect 0 on left ear and the soundEffect 2 on right ear else if (loopCount == 180) { // remove emitter 2 from the entity system throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Remove(emitCompEntities[1]); // test that now only emitter 1 can be heard. soundControllers[0].Play(); soundControllers[2].Play(); } // here we should hear the soundEffect 0 on left ear only else if (loopCount == 240) { // remove emitter 1 from the entity system throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Remove(emitCompEntities[0]); // check that there is not more audio output at all soundControllers[0].Play(); soundControllers[2].Play(); } // here we should hear nothing. else if (loopCount == 320) { game.Exit(); } }