ProgressHook.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "StdH.h"
  13. #include <Engine/Base/CTString.h>
  14. #include <Engine/Base/ProgressHook.h>
  15. #include <Engine/Network/Network.h>
  16. #include <Engine/Network/CommunicationInterface.h>
  17. static void (*_pLoadingHook_t)(CProgressHookInfo *pgli) = NULL; // hook for loading/connecting
  18. static CProgressHookInfo _phiLoadingInfo; // info passed to the hook
  19. BOOL _bRunNetUpdates = FALSE;
  20. static CTimerValue tvLastUpdate;
  21. static BOOL bTimeInitialized = FALSE;
  22. extern FLOAT net_fSendRetryWait;
  23. // set hook for loading/connecting
  24. void SetProgressHook(void (*pHook)(CProgressHookInfo *pgli))
  25. {
  26. _pLoadingHook_t = pHook;
  27. }
  28. // call loading/connecting hook
  29. void SetProgressDescription(const CTString &strDescription)
  30. {
  31. _phiLoadingInfo.phi_strDescription = strDescription;
  32. }
  33. void CallProgressHook_t(FLOAT fCompleted)
  34. {
  35. if (_pLoadingHook_t!=NULL) {
  36. _phiLoadingInfo.phi_fCompleted = fCompleted;
  37. _pLoadingHook_t(&_phiLoadingInfo);
  38. if (!bTimeInitialized) {
  39. tvLastUpdate = _pTimer->GetHighPrecisionTimer();
  40. bTimeInitialized = TRUE;
  41. }
  42. CTimerValue tvNow = _pTimer->GetHighPrecisionTimer();
  43. if ((tvNow-tvLastUpdate) > CTimerValue(net_fSendRetryWait*1.1)) {
  44. if (_pNetwork->ga_IsServer) {
  45. // handle server messages
  46. _cmiComm.Server_Update();
  47. } else {
  48. // handle client messages
  49. _cmiComm.Client_Update();
  50. }
  51. tvLastUpdate = _pTimer->GetHighPrecisionTimer();
  52. }
  53. }
  54. }