public MapRenderable3D(LogicalMap3D logicalMap, LabyrinthData labyrinthData, TilemapRequest properties) { if (logicalMap == null) { throw new ArgumentNullException(nameof(logicalMap)); } if (labyrinthData == null) { throw new ArgumentNullException(nameof(labyrinthData)); } On <SlowClockEvent>(OnSlowClock); On <RenderEvent>(_ => Update(false)); On <SortMapTilesEvent>(e => _isSorting = e.IsSorting); On <PaletteChangedEvent>(_ => { var paletteManager = Resolve <IPaletteManager>(); if (_tilemap != null) { _tilemap.DayFloors.Palette = paletteManager.Palette; _tilemap.DayWalls.Palette = paletteManager.Palette; } }); _logicalMap = logicalMap; _labyrinthData = labyrinthData; _properties = properties; _logicalMap.Dirty += (_, args) => { if (args.Type is IconChangeType.Floor or IconChangeType.Ceiling or IconChangeType.Wall) { _dirty.Add(_logicalMap.Index(args.X, args.Y)); } }; }
public Collider3D(LogicalMap3D logicalMap) { _logicalMap = logicalMap; }
protected override void Subscribed() { if (_labyrinthData != null) { Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue, 1.0f)); return; } var assets = Resolve <IAssetManager>(); var state = Resolve <IGameState>(); var factory = Resolve <ICoreFactory>(); _labyrinthData = assets.LoadLabyrinthData(_mapData.LabDataId); if (_labyrinthData == null) { return; } _logicalMap = new LogicalMap3D(_mapData, _labyrinthData, state.TemporaryMapChanges, state.PermanentMapChanges); var properties = new TilemapRequest { Id = MapId, Width = (uint)_logicalMap.Width, Scale = _labyrinthData.TileSize, Origin = _labyrinthData.TileSize.Y / 2 * Vector3.UnitY, HorizontalSpacing = _labyrinthData.TileSize * Vector3.UnitX, VerticalSpacing = _labyrinthData.TileSize * Vector3.UnitZ, AmbientLightLevel = _labyrinthData.Lighting, FogColor = _labyrinthData.FogColor, ObjectYScaling = _labyrinthData.ObjectYScaling, Pipeline = DungeonTilemapPipeline.Normal }; _selection = AttachChild(new Selection3D()); AttachChild(new MapRenderable3D(_logicalMap, _labyrinthData, properties)); AttachChild(new ScriptManager()); AttachChild(new Collider3D(_logicalMap)); if (!_labyrinthData.BackgroundId.IsNone) { var background = assets.LoadTexture(_labyrinthData.BackgroundId); _skybox = factory.CreateSkybox(background); } var palette = assets.LoadPalette(_logicalMap.PaletteId); uint backgroundColour = palette.GetPaletteAtTime(0)[_labyrinthData.BackgroundColour]; _backgroundRed = (backgroundColour & 0xff) / 255.0f; _backgroundGreen = (backgroundColour & 0xff00 >> 8) / 255.0f; _backgroundBlue = (backgroundColour & 0xff0000 >> 16) / 255.0f; //if(_labyrinthData.CameraHeight != 0) // Debugger.Break(); //if(_labyrinthData.Unk12 != 0) // 7=1|2|4 (Jirinaar), 54=32|16|4|2, 156=128|16|8|2 (Tall town) // Debugger.Break(); // Raise(new LogEvent(LogEvent.Level.Info, $"WallHeight: {_labyrinthData.WallHeight} MaxObj: {maxObjectHeightRaw} EffWallWidth: {_labyrinthData.EffectiveWallWidth}")); foreach (var npc in _logicalMap.Npcs) { if (npc.SpriteOrGroup.IsNone) { continue; } if (npc.SpriteOrGroup.Type != AssetType.ObjectGroup) { Warn($"[3DMap] Tried to load npc with object group of incorrect type: {npc.SpriteOrGroup}"); continue; } if (npc.SpriteOrGroup.Id >= _labyrinthData.ObjectGroups.Count) { Warn($"[3DMap] Tried to load object group {npc.SpriteOrGroup.Id}, but the max group id is {_labyrinthData.ObjectGroups.Count-1}."); continue; } var objectData = _labyrinthData.ObjectGroups[npc.SpriteOrGroup.Id]; // TODO: Verify SpriteOrGroup is an ObjectGroup // TODO: Build proper NPC objects with AI, sound effects etc foreach (var subObject in objectData.SubObjects) { AttachChild(MapObject.Build(npc.Waypoints[0].X, npc.Waypoints[0].Y, _labyrinthData, subObject, properties)); } } for (int y = 0; y < _logicalMap.Height; y++) { for (int x = 0; x < _logicalMap.Width; x++) { var group = _logicalMap.GetObject(x, y); if (group == null) { continue; } foreach (var subObject in group.SubObjects) { AttachChild(MapObject.Build(x, y, _labyrinthData, subObject, properties)); } } } Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue, 1.0f)); }