public Universe(ISaveFile saveFile, Mod mod) { SaveFile = saveFile; _mod = mod; _startWorld = new World(this); _startWorld.Generator = new WorldGenerator(_startWorld); _modData = new ModData { Materials = mod.Materials.Values.Select((m, i) => { m.Index = i; return m; }).ToList(), Models = mod.MobTypes.Values.Select((m, i) => { m.Model.Index = i; return m.Model; }).ToList(), }; for (int i = 0; i < 20; ++i) { MobType type = null; if (_mod.MobTypes.Count > 0) { string nextMobType = _mod.MobTypes.Keys.ElementAt(i % _mod.MobTypes.Count); type = _mod.MobTypes[nextMobType]; } var e = new Entity() { PositionData = new PositionData(), IsAiControlled = true, MobName = type?.Name, ModelIndex = type?.Model.Index }; Movement.Respawn(e.PositionData); _entities.Add(e); } var thread = new Thread(() => RunUniverse()); thread.IsBackground = true; thread.Start(); }
public World(Universe universe, ModData modData) { Universe = universe; ModData = modData; }
public async Task SetModAsync(ModData mod) { Bind(); _textures.Clear(); _textures.Add(null); foreach (var texture in mod.Materials.Select(m => m.Texture)) { texture.Index = _textures.Count; _textures.Add(texture); } _count = _textures.Count; // Find a texture size that fits all material textures. for (_size = 1; _size * _size < _count; _size += _size) { } _textureEntries = new TextureEntry[_count]; double tf = (double)ushort.MaxValue / _size; double to = (double)ushort.MaxValue / (_size * TextureSize); await TextureHelper.DrawTextureAsync( _textureId, _size * TextureSize, _size * TextureSize, graphics => { int x = 0, y = 0; for (int i = 0; i < _count; ++i) { var texture = _textures[i]; System.Drawing.Brush brush; if (texture == null) { brush = System.Drawing.Brushes.White; } else { var color = new Color(texture.Color); brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb((int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255))); } var x0 = x * TextureSize; var y0 = y * TextureSize; graphics.FillRectangle(brush, new System.Drawing.Rectangle(x0, y0, TextureSize, TextureSize)); _textureEntries[i] = new TextureEntry { PixelX0 = x0, PixelY0 = y0, PixelX1 = x0 + TextureSize, PixelY1 = y0 + TextureSize, X0 = (ushort)(x * tf + to), Y0 = (ushort)(y * tf + to), X1 = (ushort)((x + 1) * tf - to), Y1 = (ushort)((y + 1) * tf - to), }; ++x; if (x == _size) { x = 0; ++y; } } }, null); RunTextureGeneration(); }