/// <summary> /// /// </summary> /// <param name="model"></param> public Blueprint LoadFromXML(XmlHouseData model) { this.Blueprint = new Blueprint(model.Size, model.Size); VM.Context.Blueprint = Blueprint; VM.Context.Architecture = new VMArchitecture(model.Size, model.Size, Blueprint, VM.Context); var arch = VM.Context.Architecture; foreach (var floor in model.World.Floors){ arch.SetFloor(floor.X, floor.Y, (sbyte)(floor.Level+1), new FloorTile { Pattern = (ushort)floor.Value }, true); } foreach (var wall in model.World.Walls) { arch.SetWall((short)wall.X, (short)wall.Y, (sbyte)(wall.Level+1), new WallTile() //todo: these should read out in their intended formats - a cast shouldn't be necessary { Segments = wall.Segments, TopLeftPattern = (ushort)wall.TopLeftPattern, TopRightPattern = (ushort)wall.TopRightPattern, BottomLeftPattern = (ushort)wall.BottomLeftPattern, BottomRightPattern = (ushort)wall.BottomRightPattern, TopLeftStyle = (ushort)wall.LeftStyle, TopRightStyle = (ushort)wall.RightStyle }); } arch.RegenRoomMap(); VM.Context.RegeneratePortalInfo(); foreach (var obj in model.Objects) { //if (obj.Level == 0) continue; //if (obj.GUID == "0xE9CEB12F") obj.GUID = "0x01A0FD79"; //replace onlinejobs door with a normal one //if (obj.GUID == "0x346FE2BC") obj.GUID = "0x98E0F8BD"; //replace kitchen door with a normal one CreateObject(obj); } if (VM.UseWorld) { foreach (var obj in model.Sounds) { VM.Context.Ambience.SetAmbience(VM.Context.Ambience.GetAmbienceFromGUID(obj.ID), (obj.On == 1)); World.State.WorldSize = model.Size; } Blueprint.Terrain = CreateTerrain(model); } var testObject = new XmlHouseDataObject(); //test npc controller, not normally present on a job lot. testObject.GUID = "0x70F69082"; testObject.X = 0; testObject.Y = 0; testObject.Level = 1; testObject.Dir = 0; CreateObject(testObject); arch.Tick(); return this.Blueprint; }
public VMArchitecture(int width, int height, Blueprint blueprint, VMContext context) { this.Context = context; this.Width = width; this.Height = height; var numTiles = width * height; this.WallsAt = new List<int>[Stories]; this.Walls = new WallTile[Stories][]; this.VisWalls = new WallTile[Stories][]; this.Floors = new FloorTile[Stories][]; this.VisFloors = new FloorTile[Stories][]; this.ObjectSupport = new bool[Stories][]; //true if there's an object support in the specified position this.Supported = new bool[Stories-1][]; //no supported array for bottom floor. true if this tile is supported. if (blueprint != null) blueprint.Supported = Supported; this.Rooms = new VMRoomMap[Stories]; for (int i = 0; i < Stories; i++) { this.WallsAt[i] = new List<int>(); this.Walls[i] = new WallTile[numTiles]; this.VisWalls[i] = new WallTile[numTiles]; this.Floors[i] = new FloorTile[numTiles]; this.VisFloors[i] = new FloorTile[numTiles]; this.ObjectSupport[i] = new bool[numTiles]; if (i<Stories-1) this.Supported[i] = new bool[numTiles]; this.Rooms[i] = new VMRoomMap(); } this.RoomData = new List<VMRoom>(); this.WorldUI = blueprint; this.Commands = new List<VMArchitectureCommand>(); this.Commands = new List<VMArchitectureCommand>(); WallsDirty = true; FloorsDirty = true; RealMode = true; Redraw = true; }
public void Init(Blueprint blueprint) { this.Blueprint = blueprint; }
private bool OffsetValid(Vector3 off, Blueprint blueprint) { return off.X >= 0 && off.Y >= 0 && off.X < blueprint.Width && off.Y < blueprint.Height; }
public VMArchitecture(VMArchitectureMarshal input, VMContext context, Blueprint blueprint) : this(input.Width, input.Height, blueprint, context) { Load(input); }
public virtual void Load(VMContextMarshal input) { Blueprint = new Blueprint(input.Architecture.Width, input.Architecture.Height); Architecture = new VMArchitecture(input.Architecture, this, Blueprint); Clock = new VMClock(input.Clock); if (VM.UseWorld) { foreach (var active in input.Ambience.ActiveSounds) Ambience.SetAmbience(active, true); World.State.WorldSize = input.Architecture.Width; Blueprint.Terrain = new TerrainComponent(new Rectangle(1, 1, input.Architecture.Width - 2, input.Architecture.Height - 2)); Blueprint.Terrain.Initialize(this.World.State.Device, this.World.State); World.InitBlueprint(Blueprint); } RandomSeed = input.RandomSeed; }
public override void Update(UpdateState state) { base.Update(state); if (TempVM == null && GUID != 0) { var world = new ExternalWorld(GameFacade.GraphicsDevice); world.Initialize(GameFacade.Scenes); var context = new VMContext(world); TempVM = new VM(context, new VMServerDriver(37565, null), new VMNullHeadlineProvider()); TempVM.Init(); var blueprint = new Blueprint(32, 32); blueprint.Light = new RoomLighting[] { new RoomLighting() { OutsideLight = 100 }, new RoomLighting() { OutsideLight = 100 }, new RoomLighting() { OutsideLight = 100 }, }; blueprint.OutsideColor = Color.White; blueprint.GenerateRoomLights(); blueprint.RoomColors[2].A /= 2; world.State._2D.AmbientLight.SetData(blueprint.RoomColors); world.InitBlueprint(blueprint); context.Blueprint = blueprint; context.Architecture = new VMArchitecture(1, 1, blueprint, TempVM.Context); } if (GUID != oldGUID) { SetGUIDLocal(GUID, TempVM); state.SharedData["ExternalDraw"] = true; } if (ForceRedraw) { state.SharedData["ExternalDraw"] = true; ForceRedraw = false; } if (TempVM != null) TempVM.Update(); }
public override void Update(UpdateState state) { base.Update(state); if (TempVM == null && GUID != 0) { var world = new ExternalWorld(GameFacade.GraphicsDevice); world.Initialize(GameFacade.Scenes); var context = new VMContext(world); TempVM = new VM(context, new VMServerDriver(37565, null), new VMNullHeadlineProvider()); TempVM.Init(); var blueprint = new Blueprint(1, 1); world.InitBlueprint(blueprint); context.Blueprint = blueprint; context.Architecture = new VMArchitecture(1, 1, blueprint, TempVM.Context); } if (GUID != oldGUID) { SetGUIDLocal(GUID); state.SharedData["ExternalDraw"] = true; } }
public void RegenTerrain(GraphicsDevice device, WorldState world, Blueprint blueprint) { if (VertexBuffer != null) { IndexBuffer.Dispose(); BladeIndexBuffer.Dispose(); VertexBuffer.Dispose(); } /** Convert rectangle to world units **/ var quads = Size.Width; var quadWidth = WorldSpace.GetWorldFromTile((float)Size.Width / (float)quads); var quadHeight = WorldSpace.GetWorldFromTile((float)Size.Height / (float)quads); var numQuads = quads * quads; TerrainVertex[] Geom = new TerrainVertex[numQuads * 4]; int[] Indexes = new int[numQuads * 6]; int[] BladeIndexes = new int[numQuads * 6]; NumPrimitives = (numQuads * 2); int geomOffset = 0; int indexOffset = 0; int bindexOffset = 0; var offsetX = WorldSpace.GetWorldFromTile(Size.X); var offsetY = WorldSpace.GetWorldFromTile(Size.Y); for (var y = 0; y < quads; y++) { for (var x = 0; x < quads; x++) { var tl = new Vector3(offsetX + (x * quadWidth), 0.0f, offsetY + (y * quadHeight)); var tr = new Vector3(tl.X + quadWidth, 0.0f, tl.Z); var bl = new Vector3(tl.X, 0.0f, tl.Z + quadHeight); var br = new Vector3(tl.X + quadWidth, 0.0f, tl.Z + quadHeight); Indexes[indexOffset++] = geomOffset; Indexes[indexOffset++] = (geomOffset + 1); Indexes[indexOffset++] = (geomOffset + 2); Indexes[indexOffset++] = (geomOffset + 2); Indexes[indexOffset++] = (geomOffset + 3); Indexes[indexOffset++] = geomOffset; short tx = (short)(x + 1), ty = (short)(y + 1); if (blueprint.GetFloor(tx,ty,1).Pattern == 0 && (blueprint.GetWall(tx,ty, 1).Segments & (WallSegments.HorizontalDiag | WallSegments.VerticalDiag)) == 0) { BladeIndexes[bindexOffset++] = geomOffset; BladeIndexes[bindexOffset++] = (geomOffset + 1); BladeIndexes[bindexOffset++] = (geomOffset + 2); BladeIndexes[bindexOffset++] = (geomOffset + 2); BladeIndexes[bindexOffset++] = (geomOffset + 3); BladeIndexes[bindexOffset++] = geomOffset; } Color tlCol = Color.Lerp(LightGreen, LightBrown, GrassState[y * quads + x]); Color trCol = Color.Lerp(LightGreen, LightBrown, GrassState[y * quads + ((x + 1) % quads)]); Color blCol = Color.Lerp(LightGreen, LightBrown, GrassState[((y + 1) % quads) * quads + x]); Color brCol = Color.Lerp(LightGreen, LightBrown, GrassState[((y + 1) % quads) * quads + ((x + 1) % quads)]); Geom[geomOffset++] = new TerrainVertex(tl, tlCol.ToVector4(), new Vector2(x * 64, y * 64), GrassState[y * quads + x]); Geom[geomOffset++] = new TerrainVertex(tr, trCol.ToVector4(), new Vector2((x + 1) * 64, y * 64), GrassState[y * quads + ((x + 1) % quads)]); Geom[geomOffset++] = new TerrainVertex(br, brCol.ToVector4(), new Vector2((x + 1) * 64, (y + 1) * 64), GrassState[((y + 1) % quads) * quads + ((x + 1) % quads)]); Geom[geomOffset++] = new TerrainVertex(bl, blCol.ToVector4(), new Vector2(x * 64, (y + 1) * 64), GrassState[((y + 1) % quads) * quads + x]); } } var rand = new Random(); VertexBuffer = new VertexBuffer(device, typeof(TerrainVertex), Geom.Length, BufferUsage.None); VertexBuffer.SetData(Geom); IndexBuffer = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, sizeof(int) * Indexes.Length, BufferUsage.None); IndexBuffer.SetData(Indexes); BladePrimitives = (bindexOffset / 3); BladeIndexBuffer = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, sizeof(int) * Indexes.Length, BufferUsage.None); BladeIndexBuffer.SetData(BladeIndexes); GeomLength = Geom.Length; }
public void InitBlueprint(Blueprint blueprint) { this.Blueprint = blueprint; _2DWorld.Init(blueprint); _3DWorld.Init(blueprint); HasInitBlueprint = true; HasInit = HasInitGPU & HasInitBlueprint; }
public WeatherController(Blueprint bp) { Bp = bp; Particles = bp.Particles; }