void Loop() { //kinda nothing yet //changing scene stuff foreach (GameObject obj in gameObjects) { obj.alive = false; obj.End(); } //get rid of any shaders display.DisableFilter(); //kill any slaves SlaveManager.CloseAll(); addBuffer = new List <GameObject>(sceneManager.initScene()); //mainInstance.addGameObject(new Chart("Nisemono")); running = true; while (running) { stopwatch.Start(); gameObjectsToAdd = new List <GameObject>(addBuffer); addBuffer.Clear(); foreach (GameObject obj in gameObjectsToAdd) { obj.Start(this); gameObjects.Add(obj); if (obj.type == objType.visual) { display.AddObject(obj); } } gameObjectsToAdd.Clear(); //calculate objects that exist toRemove.Clear(); foreach (GameObject obj in gameObjects) { if (obj.alive) { //run the components first or last? foreach (Component comp in obj.components) { if (comp.active) { comp.Update(deltaTime); } } obj.Update(deltaTime, this); } else { toRemove.Add(obj); obj.End(); } } foreach (GameObject obj in toRemove) { gameObjects.Remove(obj); display.RemoveObject(obj); } display.DrawFrame(deltaTime); input.UpdateInput(); // your code Thread.Sleep(1); //just in case stopwatch.Stop(); deltaTime = stopwatch.ElapsedMilliseconds * 0.001; //calculate framerate frames++; if (timePassed > 1000) { Console.Title = $"FPS: {frames}"; frames = 0; timePassed = 0; } timePassed += stopwatch.ElapsedMilliseconds; stopwatch.Reset(); //Console.WriteLine("frame"); } }
void Loop() { //kinda nothing yet //changing scene stuff foreach (GameObject obj in _gameObjects) { obj.alive = false; obj.End(); } //get rid of any shaders DisplayInstance.DisableFilter(); //kill any slaves SlaveManager.CloseAll(); _addBuffer = new List <GameObject>(SceneManagerInstance.initScene()); //mainInstance.addGameObject(new Chart("Nisemono")); Running = true; while (Running) { _stopwatch.Start(); _gameObjectsToAdd = new List <GameObject>(_addBuffer); _addBuffer.Clear(); foreach (GameObject obj in _gameObjectsToAdd) { obj.Start(this); _gameObjects.Add(obj); if (obj.GameObjectType == objType.visual) { DisplayInstance.AddObject(obj); } } _gameObjectsToAdd.Clear(); //calculate objects that exist _toRemove.Clear(); foreach (GameObject obj in _gameObjects) { if (obj.alive) { //run the components first or last? foreach (Component comp in obj.Components) { if (comp.Active) { comp.Update(_deltaTime); } } obj.Update(_deltaTime, this); } else { _toRemove.Add(obj); obj.End(); } } foreach (GameObject obj in _toRemove) { _gameObjects.Remove(obj); DisplayInstance.RemoveObject(obj); } DisplayInstance.DrawFrame(_deltaTime); InputInstance.UpdateInput(); // your code Thread.Sleep(1); //just in case _stopwatch.Stop(); _deltaTime = _stopwatch.ElapsedMilliseconds * 0.001; //calculate framerate _frames++; if (_timePassed > 1000) { Console.Title = $"FPS: {_frames}"; _frames = 0; _timePassed = 0; } _timePassed += _stopwatch.ElapsedMilliseconds; _stopwatch.Reset(); //Console.WriteLine("frame"); } }