/// <summary> /// Loads a world from file. /// </summary> /// <param name="worldSimulationType">The world similation type.</param> /// <param name="virtualFileName">The file name of virtual file system.</param> /// <returns><b>true</b> if the world has been loaded; otherwise, <b>false</b>.</returns> public static bool WorldLoad(WorldSimulationTypes worldSimulationType, string virtualFileName) { if (EntitySystemWorld.Instance == null) { Log.Fatal("MapSystemWorld: WorldLoad: EntitySystemWorld.Instance == null"); return(false); } virtualFileName = PathUtils.NormalizeSlashes(virtualFileName); MapDestroy(); EntitySystemWorld.Instance.WorldDestroy(); TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(virtualFileName); if (textBlock == null) { return(false); } string worldTypeName = textBlock.GetAttribute("type"); WorldType worldType = EntityTypes.Instance.GetByName(worldTypeName) as WorldType; if (worldType == null) { Log.Error("世界加载失败: 世界类型 \"{0}\" 未定义。", worldTypeName); return(false); } WorldLoad(textBlock); if (!EntitySystemWorld.Instance.WorldCreateWithoutPostCreate(worldSimulationType, worldType)) { MapDestroy(); EntitySystemWorld.Instance.WorldDestroy(); return(false); } Entities.Instance.Internal_InitUINOffset(); Map.WorldFileName = virtualFileName; if (!Entities.Instance.Internal_LoadEntityTreeFromTextBlock(World.Instance, textBlock, true, null)) { MapDestroy(); EntitySystemWorld.Instance.WorldDestroy(); return(false); } /* * if (Map.Instance != null && EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor) * { * Map.Instance.GetDataForEditor().ClearAll(); * } * //*/ Map.WorldFileName = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); EntitySystemWorld.Instance.ResetExecutedTime(); return(true); }
public bool WorldCreate(WorldSimulationTypes worldSimulationType, WorldType worldType) { if (worldType == null) { Log.Fatal("EntitySystemWorld: WorldCreate: worldType == null."); return(false); } if (!WorldCreateWithoutPostCreate(worldSimulationType, worldType)) { return(false); } World.Instance.PostCreate(); return(true); }
public bool WorldCreateWithoutPostCreate(WorldSimulationTypes worldSimulationType, WorldType worldType) { WorldDestroy(); if (worldType == null) { return(false); } this.worldSimulationType = worldSimulationType; Entities.Init(); uint networkUIN = 0u; Entities.Instance._CreateInternal(worldType, null, 0u, networkUIN); return(true); }