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 _IssueCommand_StartBroadcasting() { lock (m_commandLock) { if (m_waitingCommand != null) { return; } m_waitingCommand = new Game.Broadcasting.StartBroadcastingCommand(null); } }
private void _IssueCommand_FinishBroadcasting() { lock (m_commandLock) { if (m_waitingCommand != null) { return; } m_waitingCommand = new Game.Broadcasting.FinishBroadcastingCommand(); } }
private Core.LogicCommand _GetFrameCommand() { lock (m_commandLock) { Core.LogicCommand existingCommand = m_waitingCommand; if (existingCommand != null) { m_waitingCommand = null; return(existingCommand); } } return(Core.LogicCommand.IdleCommand); }
/// <summary> /// Process a game step proceeding logic /// </summary> /// <param name="targetWorld">World to apply step logic process</param> /// <param name="stepCommand">A command given to current step</param> /// <returns>Step processing result</returns> public StepResult ProcessStep(World targetWorld, Core.LogicCommand stepCommand) { Core.CommandResult commandResult = m_commandProcessor.ApplyCommand(targetWorld, stepCommand); m_updateProcessor.UpdateWorldOneStep(targetWorld); // Gather Results List <Core.Game.Item> receivedItems = targetWorld.MyHome.RefreshAndGetArrivedItems(); return(new StepResult() { commandResult = commandResult, receivedItems = receivedItems }); }
private void _IssueCommand_ShoppingPurchase(long shopId, long shopItemId) { lock (m_commandLock) { if (m_waitingCommand != null) { return; } m_waitingCommand = new Core.LogicCommands.ShoppingPurchaseCommand() { purchasingShopId = shopId, purchasingItemId = shopItemId }; } }
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(); } }
/// <summary> /// Apply command to the world /// </summary> /// <param name="targetWorld">Target world</param> /// <param name="stepCommand">Applying command</param> /// <returns>Result of command processing</returns> public Core.CommandResult ApplyCommand(World targetWorld, Core.LogicCommand stepCommand) { switch (stepCommand.CoarseType) { case Core.LogicCommand.CommandCoarseType.kIdle: return(Core.CommandResult.SimpleSuccess); case Core.LogicCommand.CommandCoarseType.kBroadcasting: Broadcasting.BroadcastingCommand broadcastingCommand = stepCommand as Broadcasting.BroadcastingCommand; return(broadcastingCommand.DoCommand(targetWorld)); case Core.LogicCommand.CommandCoarseType.kShopping: Core.LogicCommands.ShoppingCommand shoppingCommand = stepCommand as Core.LogicCommands.ShoppingCommand; return(m_shoppingCommandProcessor.ProcessCommand(targetWorld, shoppingCommand)); } return(new Core.CommandResult(false, new CommandFailReason_CannotProcess())); }
/// <summary> /// Proceed a game step /// </summary> /// <param name="stepCommand">A command given to current step</param> /// <returns>Step processing result</returns> public Processing.StepResult ProceedStep(Core.LogicCommand stepCommand) { return(m_stepProcessor.ProcessStep(m_world, stepCommand)); }
private void _InitializeCommandSystem() { m_waitingCommand = null; m_commandLock = new object(); }