private void _GameLoop() { while (m_isGameRun) { DateTime currentFrameTime = DateTime.UtcNow; TimeSpan currentUpdateInterval = m_updateInterval[m_currentGameSpeed]; if (currentFrameTime - m_lastUpdateTime >= currentUpdateInterval) { Core.LogicCommand frameCommand = _GetFrameCommand(); Game.Processing.StepResult stepProcessResult = m_game.ProceedStep(frameCommand); _ProcessFrameResultLogic(frameCommand, stepProcessResult); m_lastUpdateTime = currentFrameTime; } if (!m_isUIUpdating && m_isGameRun) { this.BeginInvoke(m_gameUIUpdateFuncDelegate); } _UpdateSoundSystem(); Application.DoEvents(); Thread.Yield(); } }
private void _ProcessFrameResultLogic(Core.LogicCommand frameCommand, Game.Processing.StepResult stepProcessResult) { if (frameCommand.CoarseType == Core.LogicCommand.CommandCoarseType.kShopping) { Core.LogicCommands.ShoppingCommand shoppingCommand = frameCommand as Core.LogicCommands.ShoppingCommand; if (shoppingCommand.CommandType == Core.LogicCommands.ShoppingCommandType.kBuy) { if (stepProcessResult.commandResult.isSuccess) { Core.Game.Shopping.Order order = (stepProcessResult.commandResult.payloadData as Game.Shop.PurchaseCommandResult).placedOrder; Core.Game.Shopping.IShopItem purchasedItem = order.orderedShopItem; WriteLog(string.Format("(Order No. {0}) Purchaed \"{1}\" at {2} money.", order.serialNumber, purchasedItem.View.SellingItemName, purchasedItem.Price)); _SoundPlayPurchase(); } } } else if (frameCommand.CoarseType == Core.LogicCommand.CommandCoarseType.kBroadcasting) { if (stepProcessResult.commandResult.isSuccess) { if (frameCommand is Game.Broadcasting.StartBroadcastingCommand) { _SetSoundStreamingOn(); } else if (frameCommand is Game.Broadcasting.FinishBroadcastingCommand) { _SetSoundStreamingOff(); } } } // Process Receive if (stepProcessResult.receivedItems.Count > 0) { foreach (Core.Game.Item currentReceivedItem in stepProcessResult.receivedItems) { m_inventoryUIWaitingQueue.Enqueue(new InventoryListItemEntry(currentReceivedItem)); WriteLog(string.Format("Item Received!! - {0}: {1}", currentReceivedItem.View.VisibleName, currentReceivedItem.View.Description)); ++m_itemCount; } _SoundPlayReceived(); } }