Example #1
0
        /// <summary>
        /// Setup the CESharp EntityFramework, including registering of discovered CESharp entity classes and assumption of already spawned CESharp entites.
        /// </summary>
        internal static void OnEngineStart()
        {
            EntityProperty.RegisterConverters();
            s_managedEntities              = new Dictionary <EntityId, Entity>();
            ClassRegistry                  = new EntityClassRegistry();
            s_entitySystemSink             = new EntitySystemSink();
            s_entitySystemSink.Spawn      += OnSpawn;
            s_entitySystemSink.Event      += OnEvent;
            s_entitySystemSink.Remove     += OnRemove;
            s_entityUpdateListener         = new EntityUpdateListener();
            s_entityUpdateListener.Update += OnUpdate;

            CollisionEventListener.Instance = new CollisionEventListener();
        }
Example #2
0
        /// <summary>
        /// Clean up the Entity Framework, including shutting down of all handled CESharp entities and disabling of CESharp entity classes.
        /// </summary>
        public static void Destroy(InterDomainHandler handler)
        {
            foreach (BaseEntity ent in s_managedEntities.Values)
            {
                handler.StoreEntity(ent);
                ent.OnShutdown();
            }

            s_managedEntities.Clear();
            //s_entityClassRegistry.UnregisterAll ();
            s_entityClassRegistry.DisableAll();
            s_entityClassRegistry          = null;
            s_entityUpdateListener.Update -= OnUpdate;
            s_entityUpdateListener.Dispose();
            s_entityUpdateListener     = null;
            s_entitySystemSink.Spawn  -= OnSpawn;
            s_entitySystemSink.Event  -= OnEvent;
            s_entitySystemSink.Remove -= OnRemove;
            s_entitySystemSink.Dispose();
            s_entitySystemSink = null;
        }
Example #3
0
        /// <summary>
        /// Setup the CESharp EntityFramework, including registering of discovered CESharp entity classes and assumption of already spawned CESharp entites.
        /// </summary>
        public static void Instantiate(InterDomainHandler handler)
        {
            EntityProperty.RegisterConverters();
            s_managedEntities     = new Dictionary <uint, BaseEntity> ();
            s_entityClassRegistry = new EntityClassRegistry();
            s_entityClassRegistry.RegisterAll();
            s_entitySystemSink             = new EntitySystemSink();
            s_entitySystemSink.Spawn      += OnSpawn;
            s_entitySystemSink.Event      += OnEvent;
            s_entitySystemSink.Remove     += OnRemove;
            s_entityUpdateListener         = new EntityUpdateListener();
            s_entityUpdateListener.Update += OnUpdate;

            // Assume already spawned entities
            IEntityIt it = Global.gEnv.pEntitySystem.GetEntityIterator();

            if (it != null)
            {
                it.MoveFirst();

                IEntity pEntity = null;
                while (!it.IsEnd())
                {
                    pEntity = it.Next();

                    EntityClass managedClass = s_entityClassRegistry.GetEntityClass(pEntity);
                    if (managedClass == null)
                    {
                        continue;
                    }

                    Log.Info("[EntityFramework] Assume entity: {0} ({1})", pEntity.GetName(), managedClass.ProtoType.Name);
                    BaseEntity instance = managedClass.CreateInstance(pEntity);
                    handler.RetrieveEntity(instance);
                    s_managedEntities.Add(pEntity.GetId(), instance);
                }
            }
        }