public void Setup() { var builder = new ContainerBuilder(); // Set up our mock Log and register it to the container var loggerMock = new Mock <ILoggingService>(MockBehavior.Strict); builder.RegisterInstance(loggerMock.Object).As <ILoggingService>(); // Set up the worlds service mock and register it to the container var worldServiceMock = new Mock <IWorldService>(); worldServiceMock .Setup(service => service.GetAllWorlds()) .Returns(() => { var world = new DefaultWorld(); //world.AddTimeOfDayState(new TimeOfDayState()); var completionSource = new TaskCompletionSource <IEnumerable <IWorld> >(); completionSource.SetResult(new[] { world }); return(completionSource.Task); }); builder.RegisterInstance(worldServiceMock.Object).As <IWorldService>(); // Build the IoC container. container = builder.Build(); }
public async Task Initializes_loaded_worlds() { // Arrange var world = new DefaultWorld(); bool worldLoaded = false; world.Loaded += (sender, args) => worldLoaded = true; world.AddTimeOfDayState(new TimeOfDayState()); // Set up the world service to return our mocked World. var worldServiceMock = new Mock <IWorldService>(); worldServiceMock .Setup(service => service.GetAllWorlds()) .ReturnsAsync(new List <DefaultWorld> { world }); var logService = this.container.Resolve <ILoggingService>(); // Provide our custom service for this test instead of the shared // world service generated by the unit test set up code. var game = new DefaultGame(logService, worldServiceMock.Object); // Act await game.Initialize(); // Assert Assert.IsTrue(worldLoaded); }
private static void TestCase05() { World w = new DefaultWorld(); Tuple p = Tuple.Point(-2, 2, -2); Assert.False(w.IsShadowed(w.Lights[0], p)); }
private static void TestCase04() { // ShadeHit() with a reflective, transparent material World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Shape floor = new Plane(); floor.Transform = Transformation.Translation(0, -1, 0); floor.Material.Reflective = 0.5f; floor.Material.Transparency = 0.5f; floor.Material.RefractiveIndex = 1.5f; w.Shapes.Add(floor); Shape ball = new Sphere(); ball.Material.Color = Tuple.Color(1, 0, 0); ball.Material.Ambient = 0.5f; ball.Transform = Transformation.Translation(0, -3.5f, -0.5f); w.Shapes.Add(ball); List <Intersection> xs = Intersection.Aggregate(new Intersection(Sqrt(2), floor)); Computation comps = new Computation(xs[0], r, xs); LightingModel l = new PhongReflection(); Tuple color = l.ShadeHit(w, comps, 5); Assert.Equal(Tuple.Color(0.93391f, 0.69643f, 0.69243f), color); }
private static void TestCase03() { World w = new DefaultWorld(); Tuple p = Tuple.Point(10, -10, 10); Assert.True(w.IsShadowed(w.Lights[0], p)); }
private static void TestCase07() { World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); LightingModel phong = new PhongReflection(); Tuple c = phong.ColorAt(w, r); Assert.Equal(Tuple.Color(0.38066f, 0.47583f, 0.2855f), c); }
/// <summary> /// Creates a temporary world. /// </summary> private void CreateTemporaryWorld() { var world = new DefaultWorld(); world.Initialize(); this.Worlds.Add(world); // TODO: Create DefaultRealm, DefaultZone and DefaultRoom. }
private static void TestCase04() { World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); Shape shape = w.Shapes[0]; Intersection i = new Intersection(4, shape); Computation comps = new Computation(i, r); LightingModel phong = new PhongReflection(); Tuple c = phong.ShadeHit(w, comps); Assert.Equal(Tuple.Color(0.38066f, 0.47583f, 0.2855f), c); }
private static void TestCase03() { World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); List <Intersection> xs = w.Intersection(r); Assert.True(xs.Count == 4); Assert.Equal(4, xs[0].T); Assert.Equal(4.5, xs[1].T); Assert.Equal(5.5, xs[2].T); Assert.Equal(6, xs[3].T); }
public void Dispose() { ServerWorld?.Dispose(); ClientWorld?.Dispose(); DefaultWorld?.Dispose(); ServerWorld = null; ClientWorld = null; DefaultWorld = null; ClientServerBootstrap.SystemStates = _oldState; }
private static void TestCase05() { // The refracted color with an opaque surface World w = new DefaultWorld(); Shape shape = w.Shapes[0]; Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); List <Intersection> xs = Intersection.Aggregate(new Intersection(4, shape), new Intersection(6, shape)); Computation comps = new Computation(xs[0], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 5); Assert.Equal(Tuple.Color(0, 0, 0), c); }
private static void TestCase08() { World w = new DefaultWorld(); Shape outer = w.Shapes[0]; outer.Material.Ambient = 1; Shape inner = w.Shapes[1]; inner.Material.Ambient = 1; Ray r = new Ray(Tuple.Point(0, 0, 0.75f), Tuple.Vector(0, 0, -1)); LightingModel phong = new PhongReflection(); Tuple c = phong.ColorAt(w, r); Assert.Equal(c, inner.Material.Color); }
private static void TestCase03() { // The reflected color for a nonreflective material World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1)); Shape shape = w.Shapes[1]; shape.Material.Ambient = 1; Intersection i = new Intersection(1, shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ReflectedColor(w, comps); Assert.Equal(Tuple.Color(0, 0, 0), color); }
public void Tick(float dt) { ElapsedTime += dt; DefaultWorld.SetTime(new TimeData(ElapsedTime, dt)); ServerWorld?.SetTime(new TimeData(ElapsedTime, dt)); ClientWorld?.SetTime(new TimeData(ElapsedTime, dt)); ServerWorld?.GetExistingSystem <ServerInitializationSystemGroup>().Update(); ClientWorld.GetExistingSystem <ClientInitializationSystemGroup>().Update(); DefaultWorld.GetExistingSystem <ChainServerSimulationSystem>().Update(); DefaultWorld.GetExistingSystem <ChainClientSimulationSystem>().Update(); ClientWorld.GetExistingSystem <ClientPresentationSystemGroup>().Update(); }
private static void TestCase07() { // The refracted color under total internal reflection World w = new DefaultWorld(); Shape shape = w.Shapes[0]; shape.Material.Transparency = 1; shape.Material.RefractiveIndex = 1.5f; Ray r = new Ray(Tuple.Point(0, 0, Sqrt(2) / 2), Tuple.Vector(0, 1, 0)); List <Intersection> xs = Intersection.Aggregate(new Intersection(-Sqrt(2) / 2, shape), new Intersection(Sqrt(2) / 2, shape)); Computation comps = new Computation(xs[1], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 5); Assert.Equal(Tuple.Color(0, 0, 0), c); }
private static void TestCase06() { // The refracted color at the maximum recursive depth World w = new DefaultWorld(); Shape shape = w.Shapes[0]; shape.Material.Transparency = 1; shape.Material.RefractiveIndex = 1.5f; Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); List <Intersection> xs = Intersection.Aggregate(new Intersection(4, shape), new Intersection(6, shape)); Computation comps = new Computation(xs[0], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 0); Assert.Equal(Tuple.Color(0, 0, 0), c); }
private static void TestCase07() { // The reflected color at the maximum recursive depth World w = new DefaultWorld(); Shape shape = new Plane(); shape.Material.Reflective = 0.5f; shape.Transform = Transformation.Translation(0, -1, 0); w.Shapes.Add(shape); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Intersection i = new Intersection(Sqrt(2), shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ReflectedColor(w, comps, 0); Assert.Equal(Tuple.Color(0, 0, 0), color); }
private static void TestCase05() { // ShadeHit() with a reflective material World w = new DefaultWorld(); Shape shape = new Plane(); shape.Material.Reflective = 0.5f; shape.Transform = Transformation.Translation(0, -1, 0); w.Shapes.Add(shape); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Intersection i = new Intersection(Sqrt(2), shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ShadeHit(w, comps); Assert.Equal(Tuple.Color(0.87677f, 0.92436f, 0.82918f), color); }
private static void TestCase04() { World w = new DefaultWorld(); Camera c = new Camera(11, 11, PI / 2.0f); Tuple from = Tuple.Point(0, 0, -5); Tuple to = Tuple.Point(0, 0, 0); Tuple up = Tuple.Vector(0, 1, 0); c.Transform = Transformation.LookAt(from, to, up); LightingModel l = new PhongReflection(); Canvas image = Canvas.Render(c, w, l); Assert.Equal(image.PixelAt(5, 5), Tuple.Color(0.38066f, 0.47583f, 0.2855f)); }
private static void TestCase04() { // The reflected color for a reflective material World w = new DefaultWorld(); Shape shape = new Plane(); shape.Material.Reflective = 0.5f; shape.Transform = Transformation.Translation(0, -1, 0); w.Shapes.Add(shape); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Intersection i = new Intersection(Sqrt(2), shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ReflectedColor(w, comps); Assert.Equal(0.19032f, color.X, 3); Assert.Equal(0.2379f, color.Y, 3); Assert.Equal(0.14274f, color.Z, 3); }
private static void TestCase05() { World w = new DefaultWorld(); w.Lights[0] = new PointLight(Tuple.Point(0, 0.25f, 0), Tuple.Color(1, 1, 1)); Ray r = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1)); Shape shape = w.Shapes[1]; Intersection i = new Intersection(0.5f, shape); Computation comps = new Computation(i, r); LightingModel phong = new PhongReflection(); Tuple c = phong.Lighting(comps.Object.Material, comps.Object, w.Lights[0], comps.Point, comps.Eyev, comps.Normalv, false); Assert.Equal(Tuple.Color(0.90498f, 0.90498f, 0.90498f), c); }
private static void TestCase02() { World w = new DefaultWorld(); Light light = new PointLight(Tuple.Point(-10, 10, -10), Tuple.Color(1, 1, 1)); Shape s1 = new Sphere(); s1.Material.Color = Tuple.Color(0.8f, 1, 0.6f); s1.Material.Diffuse = 0.7f; s1.Material.Specular = 0.2f; Shape s2 = new Sphere(); s2.Transform = Transformation.Scaling(0.5f, 0.5f, 0.5f); Assert.Equal(light, w.Lights[0]); Assert.Contains(s1, w.Shapes); Assert.Contains(s2, w.Shapes); }
private static void TestCase08() { // The refracted color with a refracted ray World w = new DefaultWorld(); Shape A = w.Shapes[0]; A.Material.Ambient = 1; A.Material.Pattern = new PositionPattern(); Shape B = w.Shapes[1]; B.Material.Transparency = 1; B.Material.RefractiveIndex = 1.5f; Ray r = new Ray(Tuple.Point(0, 0, 0.1f), Tuple.Vector(0, 1, 0)); List <Intersection> xs = Intersection.Aggregate(new Intersection(-0.9899f, A), new Intersection(-0.4899f, B), new Intersection(0.4899f, B), new Intersection(0.9899f, A)); Computation comps = new Computation(xs[2], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 5); Assert.Equal(Tuple.Color(0, 0.99888f, 0.04725f), c); }
protected override IDeterminismTestSystem GetTestSystem() => DefaultWorld.GetExistingSystem <HavokPhysicsDeterminismTestSystem>();
public void OnServerInit() { Logger.log(Logger.LogLevel.INFO, "######################## Initalise ########################"); cursor = Cursor.getCursor(); RandomManager.GetRandom(); Test.Text3DTest.Init(); ItemInit.Init(); DefaultItems.Init(); DayTime.Init(); DayTime.setTime(0, 12, 0); #if SSM_AI AI.AISystem.Init(); #endif DefaultWorld.Init(); DamageScript.Init(); #if SSM_CHAT //chat = new Chat(); //chat.Init(); //important: register notification types for notification areas! NotificationManager.GetNotificationManager().AddNotificationArea(100, 100, 50, 8, new NotificationType[] { NotificationType.ChatMessage, NotificationType.ServerMessage, NotificationType.PlayerStatusMessage, NotificationType.MobsiMessage, NotificationType.Sound }); CommandInterpreter.GetCommandInterpreter(); Chat.GetChat(); EventNotifier.GetEventNotifier(); #endif Modules.Init(); //Modules.addModule(new Test.ListTestModule()); #if SSM_ACCOUNT AccountSystem accSystem = new AccountSystem(); accSystem.Init(); #endif #if SSM_WEB Web.http_server.Init(); #endif Logger.log(Logger.LogLevel.INFO, "###################### End Initalise ######################"); }
/// <summary> /// Constructs the world. /// </summary> /// <param name="game">The game.</param> private async Task ConstructWorld(IGame game) { // Set up the Room var bedroom = new DefaultRoom { IsEnabled = true }; var hallway = new DefaultRoom { IsEnabled = true }; // Set up the Zone var weatherStates = new List <IWeatherState> { new ClearWeather(), new RainyWeather(), new ThunderstormWeather() }; DefaultZone zone = new DefaultZone(); zone.Name = "Country Side"; zone.Rooms = new List <DefaultRoom>() { bedroom }; zone.WeatherStates = weatherStates; zone.WeatherUpdateFrequency = 6; zone.WeatherChanged += (sender, weatherArgs) => Console.WriteLine($"{zone.Name} zone weather has changed to {weatherArgs.CurrentState.Name}"); DefaultZone zone2 = new DefaultZone(); zone2.Name = "Castle Rock"; zone2.Rooms = new List <DefaultRoom> { hallway }; zone2.WeatherStates = weatherStates; zone2.WeatherUpdateFrequency = 2; zone2.WeatherChanged += (sender, weatherArgs) => Console.WriteLine($"{zone2.Name} zone weather has changed to {weatherArgs.CurrentState.Name}"); // Set up the World. IWorld world = new DefaultWorld(); world.GameDayToRealHourRatio = 0.4; world.HoursPerDay = 10; world.Name = "Sample World"; world.SetNotificationManager(game.NotificationCenter); var morningState = new TimeOfDayState { Name = "Morning", StateStartTime = new TimeOfDay { Hour = 2 } }; var afternoonState = new TimeOfDayState { Name = "Afternoon", StateStartTime = new TimeOfDay { Hour = 5 } }; var nightState = new TimeOfDayState { Name = "Night", StateStartTime = new TimeOfDay { Hour = 8 } }; world.AddTimeOfDayState(morningState); world.AddTimeOfDayState(afternoonState); world.AddTimeOfDayState(nightState); world.TimeOfDayChanged += World_TimeOfDayChanged; // Set up the Realm. DefaultRealm realm = new DefaultRealm(world, new TimeOfDay { Hour = 3, HoursPerDay = 10 }); realm.TimeZoneOffset = new TimeOfDay { Hour = 3, Minute = 10, HoursPerDay = world.HoursPerDay }; realm.Name = "Realm 1"; realm.SetNotificationManager(game.NotificationCenter); // Initialize the environment. Task task = world.Initialize(); task.Wait(); await world.AddRealmToWorld(realm); realm.AddZoneToRealm(zone); realm.AddZoneToRealm(zone2); await game.AddWorld(world); }
public async Task <IEnumerable <IWorld> > GetWorlds() { // Return our previously cached worlds. if (WorldRepository.worldCache.Count > 0) { return(new List <IWorld>(WorldRepository.worldCache)); } IEnumerable <string> worldFiles = this.storageService.GetAllFilesByExtension(".world", "Worlds"); var worlds = new List <IWorld>(); foreach (string file in worldFiles) { IWorld world = new DefaultWorld(); world.CreationDate = Convert.ToDateTime(await this.storageService.LoadValueFromKeyAsync( file, world.GetPropertyName(p => p.CreationDate))); // Restore the worlds Time of Day States IEnumerable <TimeOfDayState> availableStates = await this.timeOfDayStateRepository.GetTimeOfDayStates(); IEnumerable <string> worldStates = await this.storageService.LoadMultipleValuesFromKeyAsync( file, world.GetPropertyName(p => p.TimeOfDayStates)); foreach (TimeOfDayState state in availableStates.Where(s => worldStates.Any(worldState => worldState == s.Name))) { world.AddTimeOfDayState(state); } // Restore the previous time of day state of the world // TODO: Some time look at preserving not just the state, but the state.CurrentTime as well. string currentTimeOfDayState = await this.storageService.LoadValueFromKeyAsync( file, world.GetPropertyName(p => p.CurrentTimeOfDay)); world.CurrentTimeOfDay = world.TimeOfDayStates.First(state => state.Name == currentTimeOfDayState); world.GameDayToRealHourRatio = Convert.ToInt32( await this.storageService.LoadValueFromKeyAsync( file, world.GetPropertyName(p => p.GameDayToRealHourRatio))); world.HoursPerDay = Convert.ToInt32( await this.storageService.LoadValueFromKeyAsync( file, world.GetPropertyName(p => p.HoursPerDay))); Guid parsedGuid = Guid.Empty; if (!Guid.TryParse( await this.storageService.LoadValueFromKeyAsync( file, world.GetPropertyName(p => p.Id)), out parsedGuid)) { throw new InvalidOperationException($"Unable to restore the Id for {file}"); } else { world.Id = parsedGuid; } world.IsEnabled = Convert.ToBoolean( await this.storageService.LoadValueFromKeyAsync( file, world.GetPropertyName(p => p.IsEnabled))); world.Name = await this.storageService.LoadValueFromKeyAsync( file, world.GetPropertyName(p => p.Name)); } // WorldRepository.worldCache = new ConcurrentBag<DefaultWorld>(worlds); return(worlds); }