Ejemplo n.º 1
0
        public void Insert(IPartitionObject obj)
        {
            if (obj.CurrentPartitionTile != null)
            {
                SpatialPartitionManager.Remove(obj);
            }

            lock (tileLock) {
                Type type = obj.PartitionObjectType;
                if (PartitionObjects.TryGetValue(type, out QuickList <IPartitionObject> list))
                {
                    list.Add(obj);
                }
                else
                {
                    QuickList <IPartitionObject> newList = new QuickList <IPartitionObject> {
                        obj
                    };
                    PartitionObjects.Add(type, newList);
                }
                obj.CurrentPartitionTile = this;
                if (obj is IPartitionObjectExtended ext)
                {
                    ext.InsertedIntoPartition(this);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers a GameObject with the engine.
        /// </summary>
        /// <param name="go">GameObject which was created.</param>
        internal static void AddGameObject(GameObject go)
        {
            lock (gameObjectHandlerLock) {
                if (go.AddedToGameManager)
                {
                    return;
                }

                AllGameObjects.Add(go);
                CurrentScene.GameObjectsToRemove.Remove(go);
                if (go.IgnoreCulling)
                {
                    SpatialPartitionManager.AddIgnoredObject(go);
                }

                if (go.IsDynamic)
                {
                    DynamicGameObjects.Add(go);
                }
                else if (!go.IgnoreCulling)
                {
                    SpatialPartitionManager.Insert(go);
                }

                if (go.DestroyOnLoad)
                {
                    CurrentScene.AttachedGameObjects.Add(go);
                }
                go.AddedToGameManager = true;
                EngineUtility.TransformHierarchyDirty = true;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Unregisters a GameObject from the engine.
 /// </summary>
 /// <param name="go">GameObject which was destroyed.</param>
 /// <param name="destroyed">If the GameObject was destroyed.</param>
 internal static void RemoveGameObject(GameObject go, bool destroyed = false)
 {
     lock (gameObjectHandlerLock) {
         DynamicGameObjects.Remove(go);
         CurrentScene.GameObjectsToRemove.Add(go);
         SpatialPartitionManager.Remove(go);
         if (destroyed)
         {
             AllGameObjects.Remove(go);
         }
         go.AddedToGameManager = false;
         EngineUtility.TransformHierarchyDirty = true;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the engine.
        /// </summary>
        protected sealed override void Initialize()
        {
            FileMarshal.Setup();

            Content.RootDirectory = "Data";
            LoadEngineContent();
            LoadAssets();

            IsMouseVisible = true;
            GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
            IsFixedTimeStep   = Screen.IsFullHeadless;
            TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 60);
            InactiveSleepTime = IsEditor ? TimeSpan.FromSeconds(1.0f / 2000) : TimeSpan.FromSeconds(1.0f / 60); // Alt-tabbed update rate.

            // If the engine ISN'T initialized (i.e, in editor mode)...
            if (!isInitialized)
            {
                ThreadPool.SetMinThreads(Environment.ProcessorCount, 8);

                Config.Initialize();
                InputManager.Initialize(this);
                Reflection.Initialize();
                ModLoader.Initialize();
                GameLoop = new GameLoop();

                ParticleEngine.AllocationMode = Config.Performance.UseArrayPoolParticles
                    ? ParticleAllocationMode.ArrayPool
                    : ParticleAllocationMode.Array;
                ParticleEngine.Initialize();

                UIManager.Initialize();
                if (!Screen.IsFullHeadless)
                {
                    Core.Lighting.Initialize();
                }

                SpatialPartitionManager.Initialize(192, 192 * 8);
                Core.Physics.Initialize();

                Network.OnLogInfo    += (msg, important) => Console.LogInfo(msg, important, LogSource.Network);
                Network.OnLogWarning += (msg, exception) => {
                    if (!string.IsNullOrEmpty(msg))
                    {
                        Console.LogWarning(msg, LogSource.Network);
                    }
                    else
                    {
                        Console.LogWarning(exception, LogSource.Network);
                    }
                };
                Network.OnLogError += (msg, exception) => {
                    if (!string.IsNullOrEmpty(msg))
                    {
                        Console.LogError(msg, LogSource.Network);
                    }
                    else
                    {
                        Console.LogError(exception, LogSource.Network);
                    }
                };

                SetCurrentScene("_MAIN\\empty");
                if (!Screen.IsFullHeadless)
                {
                    Core.Rendering.Initialize(GraphicsDeviceManager, GraphicsDevice);
                    Console.InitializeStats(Core.Rendering.SpriteBatch);
                }

                // After core initialization. Console will work here.
                Console.Initialize();
                Console.LogInfo("Core engine loaded.", true);
                Console.LogInfo("Game loop loaded:", true);
                Console.LogInfo(GameLoop.ToString());

                Network.Initialize();
                Screen.Reset();
                Initalized?.Invoke();

                Console.LogInfo("Finished initialization.", true);
            }

            if (IsEditor)
            {
                Editor.ChangeInstance(this);
                Editor.OnInitialize(this);
            }

            OnInitialize();
            isInitialized = true;
        }