From 1e90dad2456f383c2624acc85ab62445440e1156 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 19 Mar 2012 09:37:10 +0000 Subject: Basic cWindow thread-safety git-svn-id: http://mc-server.googlecode.com/svn/trunk@420 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cFurnaceEntity.cpp | 58 ++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) (limited to 'source/cFurnaceEntity.cpp') diff --git a/source/cFurnaceEntity.cpp b/source/cFurnaceEntity.cpp index 3c4a7403d..389d4af54 100644 --- a/source/cFurnaceEntity.cpp +++ b/source/cFurnaceEntity.cpp @@ -122,11 +122,7 @@ bool cFurnaceEntity::Tick( float a_Dt ) cWindow* Window = GetWindow(); if( Window ) { - const std::list< cPlayer* > & OpenedBy = Window->GetOpenedBy(); - for( std::list< cPlayer* >::const_iterator itr = OpenedBy.begin(); itr != OpenedBy.end(); ++itr ) - { - Window->SendWholeWindow( (*itr)->GetClientHandle() ); - } + Window->BroadcastWholeWindow(); } m_TimeCooked = 0.f; @@ -135,19 +131,13 @@ bool cFurnaceEntity::Tick( float a_Dt ) cWindow* Window = GetWindow(); if( Window ) { - const std::list< cPlayer* > & OpenedBy = Window->GetOpenedBy(); - for( std::list< cPlayer* >::const_iterator itr = OpenedBy.begin(); itr != OpenedBy.end(); ++itr ) - { - cClientHandle* Client = (*itr)->GetClientHandle(); - - cPacket_InventoryProgressBar Progress; - Progress.m_ProgressBar = 0; - Progress.m_WindowID = (char)Window->GetWindowID(); - Progress.m_Value = (short)( m_TimeCooked * (180.f/m_CookTime) ); - if( Progress.m_Value > 180 ) Progress.m_Value = 180; - if( Progress.m_Value < 0 ) Progress.m_Value = 0; - Client->Send( Progress ); - } + cPacket_InventoryProgressBar Progress; + Progress.m_ProgressBar = 0; + Progress.m_WindowID = (char)Window->GetWindowID(); + Progress.m_Value = (short)( m_TimeCooked * (180.f/m_CookTime) ); + if( Progress.m_Value > 180 ) Progress.m_Value = 180; + if( Progress.m_Value < 0 ) Progress.m_Value = 0; + Window->Broadcast(Progress); } } } @@ -161,30 +151,26 @@ bool cFurnaceEntity::Tick( float a_Dt ) m_BurnTime = 0; if( StartCooking() && Window ) { - const std::list< cPlayer* > & OpenedBy = Window->GetOpenedBy(); - for( std::list< cPlayer* >::const_iterator itr = OpenedBy.begin(); itr != OpenedBy.end(); ++itr ) - { - Window->SendWholeWindow( (*itr)->GetClientHandle() ); - } + Window->BroadcastWholeWindow(); } } if( Window ) { - const std::list< cPlayer* > & OpenedBy = Window->GetOpenedBy(); - for( std::list< cPlayer* >::const_iterator itr = OpenedBy.begin(); itr != OpenedBy.end(); ++itr ) - { - cClientHandle* Client = (*itr)->GetClientHandle(); + cPacket_InventoryProgressBar Progress; + Progress.m_WindowID = (char)Window->GetWindowID(); + Progress.m_ProgressBar = 1; - cPacket_InventoryProgressBar Progress; - Progress.m_WindowID = (char)Window->GetWindowID(); - Progress.m_ProgressBar = 1; - - if( m_BurnTime > 0.f ) Progress.m_Value = (short)( m_TimeBurned * (150.f/m_BurnTime) ); - else Progress.m_Value = 0; - if( Progress.m_Value > 150 ) Progress.m_Value = 150; - if( Progress.m_Value < 0 ) Progress.m_Value = 0; - Client->Send( Progress ); + if ( m_BurnTime > 0.f ) + { + Progress.m_Value = (short)( m_TimeBurned * (150.f / m_BurnTime) ); + if ( Progress.m_Value > 150 ) Progress.m_Value = 150; + if ( Progress.m_Value < 0 ) Progress.m_Value = 0; + } + else + { + Progress.m_Value = 0; } + Window->Broadcast( Progress ); } return ((m_CookingItem != 0) || (m_TimeBurned < m_BurnTime)) && m_BurnTime > 0.f; // Keep on ticking, if there's more to cook, or if it's cooking } -- cgit v1.2.3