public static Map.BlockSet LoadBlockSet(out string error) { error = null; SqlConnection conn = GameApplication.Current.ConnectionManager.OpenConnection(); var blockSet = new Map.BlockSet() { Blocks = new ConcurrentDictionary <int, Map.Block>() }; try { SqlCommand comm = new SqlCommand("select * from Block", conn); using (var reader = comm.ExecuteReader()) { while (reader.Read()) { int ID = (int)reader["ID"]; int materialIndex = (int)reader["materialIndex"]; float colorA = Convert.ToSingle(reader["ColorA"]); float colorR = Convert.ToSingle(reader["ColorR"]); float colorG = Convert.ToSingle(reader["ColorG"]); float colorB = Convert.ToSingle(reader["ColorB"]); bool isDestructible = (bool)reader["IsDestructible"]; int priority = (int)reader["Priority"]; bool isVegetationEnabled = (bool)reader["IsVegetationEnabled"]; blockSet.Blocks.GetOrAdd(ID, new Map.Block() { IsDestructible = isDestructible, IsVegetationEnabled = isVegetationEnabled, VertexColor = new Color(colorR, colorG, colorB, colorA), MaterialIndex = materialIndex, Priority = priority, ID = ID }); } } return(blockSet); } catch (Exception ex) { error = ex.ToString(); return(blockSet); } finally { GameApplication.Current.ConnectionManager.CloseConnection(conn); } }
public bool Start(out string error) { error = null; //Start instance and loading resources AllInMemory = true;// tudo em memoria BlockSet = new Map.BlockSet(); LastChunkMemoryID = -1; WorldMap = new Map.Map(); WorldMap.MapID = 1; WorldMap.MapCustomer = new WorldMapCustomer(); WorldMap.MinSize = new Utils.Vector3i(6, 6, 6); //224 blocos altura max, 10x10 chunks de area WorldMap.MaxSize = new Utils.Vector3i(10, 224, 10); MapLimits = Utils.Vector3i.zero; Console.WriteLine("Loading BlockSet..."); BlockSet = DAO.Terrain.Block.LoadBlockSet(out error); if (!String.IsNullOrWhiteSpace(error)) { return(false); } var first = BlockSet.Blocks.Values.FirstOrDefault(); WorldMap.DefaultBlock = first; Console.WriteLine("Loading Chunks and Blocks..."); long totalChunks = DAO.Terrain.ChunkData.DataBaseCount(out error); if (!String.IsNullOrWhiteSpace(error)) { return(false); } //define capacidade do cache em memoria int ChunkIndexCapacity; if (totalChunks > int.MaxValue) { ChunkIndexCapacity = int.MaxValue; } else { ChunkIndexCapacity = (int)totalChunks; } ChunksByMemoryID = new ConcurrentDictionary <int, List <Data.ChunkData> >(8, ChunkIndexCapacity); ChunksByDataBaseID = new ConcurrentDictionary <int, List <Data.ChunkData> >(16, ChunkIndexCapacity); PositionIndexedChunks = new ConcurrentDictionary <int, List <Data.ChunkData> >(8, ChunkIndexCapacity); //define capacidade da fila de insert e update de terrenos ChunkInsertQueue = new Queue <Data.ChunkData>(10000); BlockInsertOrUpdateQueue = new Queue <Data.BlockData>(100000); if (!DAO.Terrain.ChunkData.LoadAllToApplication(out error)) { return(false); } Console.WriteLine("Terrain loaded!"); return(true); }