ProcessNPC.cpp
上传用户:szopptop
上传日期:2013-04-23
资源大小:1047k
文件大小:3k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. void WINAPI ProcessMerchants();
  3. void WINAPI ProcessEvents();
  4. /*
  5. void DoRunRace(CNPCObject* pNPCObject)
  6. {
  7. switch (pNPCObject->m_wObjectType)
  8. {
  9. case _OBJECT_NPC:
  10. ((CChickenObject*)pNPCObject)->RunRace();
  11. break;
  12. }
  13. }
  14. */
  15. UINT WINAPI ProcessNPC(LPVOID lpParameter)
  16. {
  17. FILETIME ftKernelTimeStart, ftKernelTimeEnd;
  18. FILETIME ftUserTimeStart, ftUserTimeEnd;
  19. FILETIME ftDummy, ftTotalTimeElapsed;
  20. __int64 qwKernelTimeElapsed, qwUserTimeElapsed, qwTotalTimeElapsed;
  21. TCHAR wszThreadTime[32];
  22. DWORD dwCurrentTick;
  23. int nHour = 0;
  24. while (TRUE)
  25. {
  26. GetThreadTimes(GetCurrentThread(), &ftDummy, &ftDummy, &ftKernelTimeStart, &ftUserTimeStart);
  27. if (g_fTerminated) 
  28. {
  29. return 0L;
  30. }
  31. if (g_xScripterList.GetCount())
  32. {
  33. PLISTNODE pListNode = g_xScripterList.GetHead();
  34. while (pListNode)
  35. {
  36. CScripterObject* pObject = g_xScripterList.GetData(pListNode);
  37. if (GetTickCount() - pObject->m_dwRunTime >= pObject->m_dwRunNextTick)
  38. {
  39. pObject->m_dwRunTime = GetTickCount();
  40. pObject->Operate();
  41. }
  42. pListNode = g_xScripterList.GetNext(pListNode);
  43. }
  44. }
  45. //
  46. ProcessMerchants();
  47. //
  48. ProcessEvents();
  49. //
  50. dwCurrentTick = GetTickCount();
  51. if (g_xNPCObjList.GetCount())
  52. {
  53. PLISTNODE pListNode = g_xNPCObjList.GetHead();
  54. while (pListNode)
  55. {
  56. CNPCObject* pNPCObject = g_xNPCObjList.GetData(pListNode);
  57. if (dwCurrentTick - pNPCObject->m_dwRunTime >= pNPCObject->m_dwRunNextTick)
  58. {
  59. pNPCObject->m_dwRunTime = dwCurrentTick;
  60. if (dwCurrentTick - pNPCObject->m_dwSearchTime >= pNPCObject->m_dwSearchTick)
  61. {
  62. pNPCObject->m_dwSearchTime = dwCurrentTick;
  63. pNPCObject->SearchViewRange();
  64. }
  65. // DoRunRace(pNPCObject);
  66. // pNPCObject->RunRace();
  67. }
  68. pListNode = g_xNPCObjList.GetNext(pListNode);
  69. }
  70. }
  71. nHour = GetTime();
  72. if (nHour == 23 || nHour == 11)
  73. g_nMirDayTime = 2; // 历翅
  74. else if (nHour == 4 || nHour == 15)
  75. g_nMirDayTime = 0; // 货寒
  76. else if ((nHour >= 0 && nHour <= 3) || (nHour >= 12 && nHour <= 14))
  77. g_nMirDayTime = 3;
  78. else
  79. g_nMirDayTime = 1;
  80. GetThreadTimes(GetCurrentThread(), &ftDummy, &ftDummy, &ftKernelTimeEnd, &ftUserTimeEnd);
  81. qwKernelTimeElapsed = FileTimeToQuadWord(&ftKernelTimeEnd) - FileTimeToQuadWord(&ftKernelTimeStart);
  82. qwUserTimeElapsed = FileTimeToQuadWord(&ftUserTimeEnd) - FileTimeToQuadWord(&ftUserTimeStart);
  83. qwTotalTimeElapsed = qwKernelTimeElapsed + qwUserTimeElapsed;
  84. QuadTimeToFileTime(qwTotalTimeElapsed, &ftTotalTimeElapsed);
  85. wsprintf(wszThreadTime, _TEXT("%lu%lu ns"), ftTotalTimeElapsed.dwHighDateTime, ftTotalTimeElapsed.dwLowDateTime);
  86. SendMessage(g_hStatusBar, SB_SETTEXT, MAKEWORD(5, 0), (LPARAM)wszThreadTime);
  87. SleepEx(1, TRUE);
  88. }
  89. return 0L;
  90. }