Exemplo n.º 1
0
        private bool ManualCreateTypes()
        {
            var q = classes
                    .Select(_clazz => new Tuple <ClassInfo, ManualTypeCreateAttribute>(_clazz, _clazz.TypeClassType.GetCustomAttribute <ManualTypeCreateAttribute>(false)))
                    .Where(_t => _t.Item2 != null)
                    .Select(_t => new Tuple <ClassInfo, string>(_t.Item1, _t.Item2.TypeName ?? _t.Item1.EntityClassType.Name))
            ;

            int totalCount = q.Count();
            int readyCount = 0;

            foreach (Tuple <ClassInfo, string> tx in q)
            {
                EntityType entityType = ManualCreateType(tx.Item2, tx.Item1);
                readyCount++;
                LongOperationNotifier.Notify("手工创建EntityType ({0}/{1}): {2}", readyCount, totalCount, entityType);
                if (entityType == null)
                {
                    LongOperationNotifier.Notify("手工创建EntityType失败, ClassInfo: {0}", tx.Item1);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
 internal bool Load(TextBlock textBlock)
 {
     LongOperationNotifier.Notify("Entity: LoadingGenerateHierarchy: " + this.ToString());
     foreach (TextBlock current in textBlock.Children)
     {
         if (!(current.Name != "entity"))
         {
             EntityType entityType = EntityTypes.Instance.GetByName(current.GetAttribute("type"));
             if (entityType == null)
             {
                 EntityType entityType2    = null;
                 string     typeName       = current.GetAttribute("type");
                 string     className      = current.GetAttribute("classPrompt");
                 Entities.EntityTypeInfo a = Entities.Instance.FindEntityTypeInfo(typeName);
                 if (a == null)
                 {
                     bool flag = false;
                     if (!EntitySystemWorld.Instance.OnLoadNotDefinedEntityType(typeName, className, ref entityType2, ref flag))
                     {
                         if (!EntitySystemWorld.Instance.IsEditor())
                         {
                             Log.Error("Entity: Load: not defined type \"{0}\".", typeName);
                         }
                         bool result = false;
                         return(result);
                     }
                     if (flag)
                     {
                         Entities.Instance.A(typeName, entityType2);
                     }
                 }
                 else
                 {
                     entityType2 = a.newEntityType;
                 }
                 if (entityType2 == null)
                 {
                     continue;
                 }
                 entityType = entityType2;
             }
             bool flag2 = true;
             this.OnPreLoadChildEntity(entityType, current, ref flag2);
             if (flag2)
             {
                 uint   uin    = uint.Parse(current.GetAttribute("uin"));
                 Entity entity = Entities.Instance._CreateInternal(entityType, this, uin, 0u);
                 if (!entity.Load(current))
                 {
                     bool result = false;
                     return(result);
                 }
                 entity.loadingTextBlock = current;
                 Entities.Instance.aAF.Add(new Entities.EntityTextBlock(entity, current));
                 this.OnAddChild(entity);
             }
         }
     }
     return(true);
 }
Exemplo n.º 3
0
 private void PostCreateInitLoadedEntities()
 {
     LongOperationNotifier.Notify("Entities: PostCreateInitLoadedEntities");
     foreach (EntityTextBlock current in this.aAF)
     {
         if (current.entity.LogicObject != null)
         {
             current.entity.LogicObject.C();
         }
         current.entity.A(true);
     }
     foreach (EntityTextBlock current2 in this.aAF)
     {
         LongOperationNotifier.Notify("Entities: PostCreateInitLoadedEntities: OnPostCreate: " + current2.entity.ToString());
         if (current2.entity.isPostCreated)
         {
             Log.Fatal("Entities: PostCreateInitLoadedEntities : entity.postCreated.");
         }
         OnPostCreateEntity(current2.entity, true);
     }
     foreach (Entities.EntityTextBlock current3 in this.aAF)
     {
         LongOperationNotifier.Notify("Entities: PostCreateInitLoadedEntities: OnPostCreate2: " + current3.entity.ToString());
         OnPostCreateEntity2(current3.entity, true);
         current3.entity.loadingTextBlock = null;
         current3.entity.isPostCreated    = true;
         if (EntitySystemWorld.Instance.IsServer() && current3.entity.Type.NetworkType == EntityNetworkTypes.Synchronized)
         {
             //current3.entity.SendEntityPostCreateMessage(EntitySystemWorld.Instance.RemoteEntityWorlds);
         }
     }
 }
Exemplo n.º 4
0
        protected override bool OnCreate()
        {
            if (!base.OnCreate())
            {
                return(false);
            }

            LongOperationNotifier.Setup();

            Log.Info(">> 初始化 EntitySystemWorld...");
            if (!EntitySystemWorld.Init(new EntitySystemWorld()))
            {
                Log.Info(">> EntitySystemWorld 初始化失败!");
                return(false);
            }

            WorldType worldType = EntitySystemWorld.Instance.DefaultWorldType;

            if (!EntitySystemWorld.Instance.WorldCreate(WorldSimulationTypes.Editor, worldType))
            {
                Log.Info(">> 创建世界失败, WorldType: {0}", worldType);
                return(false);
            }

            instance = this;

            DesignerInterface.Init(new DesignerInterfaceImpl());
            EntityWorld.Setup();

            if (MainForm.Instance != null)
            {
                /*
                 * if (MainForm.Instance.ResourcesForm != null)
                 * {
                 *  MainForm.Instance.ResourcesForm.ResourceChange += new ResourcesForm.ResourceChangeDelegate(this.OnResourceChange);
                 *  MainForm.Instance.ResourcesForm.IsResourceEditModeActive += new ResourcesForm.IsResourceEditModeActiveDelegate(this.OnIsResourceEditMode);
                 *  MainForm.Instance.ResourcesForm.ResourceBeginEditMode += new ResourcesForm.ResourceBeginEditModeDelegate(this.OnResourceBeginEditMode);
                 *  MainForm.Instance.ResourcesForm.ResourceRename += new ResourcesForm.ResourceRenameDelegate(this.OnResourceRename);
                 * }
                 * //*/
                if (MainForm.Instance.PropertiesForm != null)
                {
                    MainForm.Instance.PropertiesForm.ReadOnly = true;
                }
            }
            ResourceUtils.OnUITypeEditorEditValue += ResourceUtils_OnUITypeEditorEditValue;

            AddonManager.PreInit();
            InitResourceTypeManager();

            UndoSystem.Init(64);

            //EntitySystemWorld.Instance.Simulation = true;
            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads a map from file.
        /// </summary>
        /// <param name="virtualFileName">The file name of virtual file system.</param>
        /// <returns><b>true</b> if the map has been loaded; otherwise, <b>false</b>.</returns>
        public static bool MapLoad(string virtualFileName)
        {
            virtualFileName = PathUtils.NormalizeSlashes(virtualFileName);
            LongOperationNotifier.Notify("加载地图: {0}", virtualFileName);

            if (World.Instance == null)
            {
                Log.Fatal("MapSystemWorld: MapLoad: World.Instance == null.");
                return(false);
            }

            MapDestroy();
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(virtualFileName);

            if (textBlock == null)
            {
                return(false);
            }

            string  mapTypeName = textBlock.GetAttribute("type");
            MapType mapType     = EntityTypes.Instance.GetByName(mapTypeName) as MapType;

            if (mapType == null)
            {
                Log.Error("地图加载错误: 地图类型 \"{0}\" 未定义。", mapTypeName);
                return(false);
            }

            Entities.Instance.Internal_InitUINOffset();
            uint uin = uint.Parse(textBlock.GetAttribute("uin"));
            Map  map = (Map)Entities.Instance._CreateInternal(mapType, World.Instance, uin, 0u);

            map.virtualFileName = virtualFileName;
            if (!Entities.Instance.Internal_LoadEntityTreeFromTextBlock(map, textBlock, true, null))
            {
                MapDestroy();
                return(false);
            }
            //TODO

            /*
             * if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor)
             * {
             *  map.GetDataForEditor().ClearAll();
             * }
             * //*/

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            EntitySystemWorld.Instance.ResetExecutedTime();
            return(true);
        }
Exemplo n.º 6
0
        private EntityType loadEntityTypeFromFile(string p)
        {
            LongOperationNotifier.Notify("加载type文件: {0}", p);
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(p);

            if (textBlock == null)
            {
                return(null);
            }

            EntityType result = loadEntityType(textBlock, p, p);    // loadEntityTypeFromFile

            return(result);
        }
Exemplo n.º 7
0
        public bool LoadGroupOfTypes(string virtualDirectory, SearchOption searchOption, out List <EntityType> loadedTypes)
        {
            LongOperationNotifier.Notify("从资源目录中搜索type文件: {0}", virtualDirectory);
            loadedTypes = null;
            string[] typeFiles = new string[0];
            try
            {
                typeFiles = VirtualDirectory.GetFiles(virtualDirectory, "*.type", searchOption);
            }
            catch
            {
                Log.Error("EntityTypes: Getting list of type files failed.");
                return(false);
            }

#if DEBUG_ENTITY
            string _targetDirectory = VirtualFileSystem.GetRealPathByVirtual(virtualDirectory);
            Log.Info(">> 搜索资源目录: {0}, 找到{1}个type文件", _targetDirectory, typeFiles.Length);
#endif
            loadedTypes = new List <EntityType>(typeFiles.Length);
            for (int i = 0; i < typeFiles.Length; i++)
            {
                string     typeFile   = typeFiles[i];
                EntityType entityType = loadEntityTypeFromFile(typeFile);
                if (entityType == null)
                {
                    Log.Error("EntityTypes: Entity type loading failed \"{0}\".", typeFile);

                    LongOperationNotifier.Notify("加载type文件失败: {0}", typeFile);
                    return(false);
                }
                loadedTypes.Add(entityType);

                LongOperationNotifier.Notify("加载type文件 ({0}/{1}): {2}", i + 1, typeFiles.Length, typeFile);

#if DEBUG_ENTITY
                Log.Info(">> #{0:000} EntityType: {1}, 文件: {2}", i + 1, entityType, typeFile);
#endif
            }

            foreach (EntityType type in loadedTypes)
            {
                bool loadFailure = !loadTypeFromLoadedTextBlock(type);
                if (loadFailure)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 8
0
        private void loadEntityFromAssembly()
        {
            var q = EntitySystemWorld.Instance.EntityClassTypes.Where(_type => typeof(Entity).IsAssignableFrom(_type));

            int totalCount = q.Count();
            int readyCount = 0;

            foreach (Type type in q)
            {
                addClassInfo(type);
                readyCount++;
                LongOperationNotifier.Notify("初始化EntityType类型信息 ({0}/{1}): {2}", readyCount, totalCount, type);
#if DEBUG_ENTITY
                Log.Info(">> Entity类型: {0} ", type);
#endif
            }
        }
Exemplo n.º 9
0
        private void LoadLogicClasses()
        {
            List <Assembly> list = new List <Assembly>();

            foreach (string current in EntitySystemWorld.Instance.LogicSystemSystemClassesAssemblies)
            {
                Assembly item = AssemblyUtils.LoadAssemblyByRealFileName(current, false);
                list.Add(item);
            }

            Dictionary <Type, Type> typeDic = new Dictionary <Type, Type>();

            foreach (Assembly current in list)
            {
                string assemblyMessage = string.Format("搜索LogicClass, 程序集: {0}", current.GetName().Name);

                Type[] types = current.GetTypes().Where(_type => !typeDic.ContainsKey(_type)).ToArray();
                for (int i = 0; i < types.Length; i++)
                {
                    Type type = types[i];

                    List <Type> typeList    = new List <Type>();
                    Type        typeCurrent = type;
                    while (typeCurrent != null)
                    {
                        typeList.Add(typeCurrent);
                        typeCurrent = typeCurrent.BaseType;
                    }
                    var typeQuery = typeList.Where(_type => !typeDic.ContainsKey(_type))
                                    .Where(_type => {
                        LogicSystemBrowsableAttribute[] _rAttrs = (LogicSystemBrowsableAttribute[])_type.GetCustomAttributes(typeof(LogicSystemBrowsableAttribute), true);
                        bool _typeBrowsable = _rAttrs.Where(_attr => !_attr.Browsable).Count() == 0;
                        return(_typeBrowsable);
                    })
                    ;
                    typeQuery.Any(_type => {
                        DefineLogicClass(_type);
                        return(false);
                    });

                    LongOperationNotifier.Notify("{0}, {1}/{2}", assemblyMessage, i + 1, types.Length);
                }
            }
        }
Exemplo n.º 10
0
        private bool loadTypeFromLoadedTextBlock(EntityType entityType)
        {
            LongOperationNotifier.Notify("从TextBlock初始化EntityType: {0}", entityType.FilePath);
            bool loadFromTextBlockFailure = !entityType.loadEntityTypeFromTextBlock(entityType.textBlock);

            if (loadFromTextBlockFailure)
            {
                return(false);
            }

            bool initByTextBlockFailure = !entityType._OnLoad(entityType.textBlock);

            if (initByTextBlockFailure)
            {
                return(false);
            }

            entityType._OnLoaded();
            entityType.textBlock = null;
            return(true);
        }
Exemplo n.º 11
0
        public EntityType LoadType(string p)
        {
            LongOperationNotifier.Notify("加载EntityType: {0}", p);
            TextBlock textBlock = TextBlockUtils.LoadFromVirtualFile(p);

            if (textBlock == null || textBlock.Children.Count != 1)
            {
                return(null);
            }

            TextBlock tc = textBlock.Children[0];

            if (tc.Name != "type")
            {
                return(null);
            }

            EntityType entityType = loadEntityType(textBlock, p, p);    // LoadType

            return(entityType);
        }
Exemplo n.º 12
0
 protected override void OnShutdown()
 {
     base.OnShutdown();
     LongOperationNotifier.Shutdown();
 }
Exemplo n.º 13
0
        private bool _Startup()
        {
            #region 缺省
            Entity.tickDelta = 20;
            #endregion

            TextBlock textBlock = null;
            if (VirtualFile.Exists("Base/Constants/EntitySystem.config"))
            {
                textBlock = TextBlockUtils.LoadFromVirtualFile("Base/Constants/EntitySystem.config");

                if (textBlock != null)
                {
                }
            }

            if (JxEngineApp.Instance != null)
            {
                Entity.tickDelta = JxEngineApp.Instance.LoopInterval;
            }

            CreateEntityClassAssembly(typeof(EntitySystemWorld).Assembly);
            CreateEntityClassAssembly(Assembly.GetExecutingAssembly());

            /*
             *          Assembly item = AssemblyUtils.LoadAssemblyByRealFileName("MapSystem.dll", false);
             *          entityClassAssemblies.Add(item);
             * //*/

            ComponentManager.ComponentInfo[] componentsByType = ComponentManager.Instance.GetComponentsByType(ComponentManager.ComponentTypeFlags.EntityClasses, true);

            for (int i = 0; i < componentsByType.Length; i++)
            {
                ComponentManager.ComponentInfo            componentInfo = componentsByType[i];
                ComponentManager.ComponentInfo.PathInfo[] allEntryPointsForThisPlatform = componentInfo.GetAllEntryPointsForThisPlatform();

                LongOperationNotifier.Notify("初始化组件({0}/{1}): {2}, 入口数: {3}",
                                             i + 1, componentsByType.Length, componentInfo.FullName, allEntryPointsForThisPlatform.Length);
                for (int j = 0; j < allEntryPointsForThisPlatform.Length; j++)
                {
                    ComponentManager.ComponentInfo.PathInfo pathInfo = allEntryPointsForThisPlatform[j];
                    Assembly assembly = AssemblyUtils.LoadAssemblyByRealFileName(pathInfo.Path, false);
                    CreateEntityClassAssembly(assembly);
                }
            }
            if (textBlock != null)
            {
                TextBlock logicSystemBlock = textBlock.FindChild("logicSystem");
                if (logicSystemBlock != null)
                {
                    TextBlock logicSystemClassAssembliesBlock = logicSystemBlock.FindChild("systemClassesAssemblies");
                    if (logicSystemClassAssembliesBlock != null)
                    {
                        foreach (TextBlock current in logicSystemClassAssembliesBlock.Children)
                        {
                            string assemblyFileName = current.GetAttribute("file");
                            logicSystemSystemClassesAssemblies.Add(assemblyFileName);
                        }
                    }
                }
            }
            LogicSystemClasses.Init();
            if (!EntityTypes.Init())
            {
                return(false);
            }

            if (textBlock != null)
            {
                string defaultWorldType = textBlock.GetAttribute("defaultWorldType");
                if (!string.IsNullOrEmpty(defaultWorldType))
                {
                    this.defaultWorldType = EntityTypes.Instance.GetByName(defaultWorldType) as WorldType;
                    if (this.defaultWorldType == null)
                    {
                        this.defaultWorldType = EntityTypes.Instance.GetByName(typeof(DefaultWorld).Name) as WorldType;
                    }
                }

                if (this.defaultWorldType == null)
                {
                    Log.Fatal("EntitySystemWorld: Init: World type \"{0}\" is not defined or it is not a WorldType (Base\\Constants\\EntitySystem.config: \"defaultWorldType\" attribute).", defaultWorldType);
                    return(false);
                }
            }

            Log.Info(">> 默认WorldType: {0}", defaultWorldType);
            return(true);
        }
Exemplo n.º 14
0
 internal bool LoadEntityFromBlock(TextBlock block)
 {
     LongOperationNotifier.Notify("Entity: Load: " + this.ToString());
     return(this.OnLoad(block));
 }