Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
4.9 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "winlite.h"
  8. #include "sys_utils.h"
  9. #include "engineinterface.h"
  10. // dgoodenough - select the correct stubs header based on current console
  11. // PS3_BUILDFIX#if defined( _PS3 )
  12. #if defined( _PS3 )
  13. #include "ps3/ps3_win32stubs.h"
  14. #endif
  15. #if defined( _X360 )
  16. #include "xbox/xbox_win32stubs.h"
  17. #endif
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. // dgoodenough - All changes in this file duplicate the changes made for
  21. // portal2, i.e. they stub them out on PS3
  22. // PS3_BUILDFIX
  23. // FIXME - I've added a FIXME tag here because despite the changes made for portal2,
  24. // I'm not at all happy about nuking some of these. In particular removing mutices
  25. // and the "WaitForSingleObject" functionality seems like a recipe for disaster in
  26. // a multithreaded environment. Bottom line, I wouldn't mind having a second set of
  27. // eyes give this a once over.
  28. // @wge Doing the same for OSX. Same concerns apply.
  29. #if defined( _OSX ) || defined (LINUX)
  30. // @wge - adapted from portal2/sys_utils.cpp
  31. const unsigned int SYS_NO_ERROR = 0;
  32. const unsigned int SYS_ERROR_INVALID_HANDLE = -1;
  33. #elif !defined( _PS3 )
  34. const unsigned int SYS_NO_ERROR = NO_ERROR;
  35. const unsigned int SYS_ERROR_INVALID_HANDLE = ERROR_INVALID_HANDLE;
  36. #endif
  37. void Sys_SetLastError(unsigned long error)
  38. {
  39. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  40. ::SetLastError(error);
  41. #endif
  42. }
  43. unsigned long Sys_GetLastError()
  44. {
  45. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  46. return ::GetLastError();
  47. #else
  48. return 0;
  49. #endif
  50. }
  51. WHANDLE Sys_CreateMutex(const char *mutexName)
  52. {
  53. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  54. return (WHANDLE)::CreateMutex(NULL, FALSE, TEXT(mutexName));
  55. #else
  56. return 0;
  57. #endif
  58. }
  59. void Sys_ReleaseMutex(WHANDLE mutexHandle)
  60. {
  61. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  62. ::ReleaseMutex((HANDLE)mutexHandle);
  63. #endif
  64. }
  65. #if defined( _OSX ) || defined (LINUX)
  66. // @wge - adapted from portal2/sys_utils.cpp
  67. const unsigned int SYS_WAIT_OBJECT_0 = WAIT_OBJECT_0;
  68. const unsigned int SYS_WAIT_ABANDONED = -2;
  69. #elif !defined( _PS3 )
  70. const unsigned int SYS_WAIT_OBJECT_0 = WAIT_OBJECT_0;
  71. const unsigned int SYS_WAIT_ABANDONED = WAIT_ABANDONED;
  72. #endif
  73. unsigned int Sys_WaitForSingleObject(WHANDLE mutexHandle, int milliseconds)
  74. {
  75. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  76. return WaitForSingleObject((HANDLE)mutexHandle, milliseconds);
  77. #else
  78. return -1;
  79. #endif
  80. }
  81. unsigned int Sys_RegisterWindowMessage(const char *msgName)
  82. {
  83. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  84. return ::RegisterWindowMessage(msgName);
  85. #else
  86. return 0;
  87. #endif
  88. }
  89. WHANDLE Sys_FindWindow(const char *className, const char *windowName)
  90. {
  91. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  92. return (WHANDLE)::FindWindow(className, windowName);
  93. #else
  94. return 0;
  95. #endif
  96. }
  97. void Sys_EnumWindows(void *callbackFunction, int lparam)
  98. {
  99. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  100. ::EnumWindows((WNDENUMPROC)callbackFunction, lparam);
  101. #endif
  102. }
  103. void Sys_GetWindowText(WHANDLE wnd, char *buffer, int bufferSize)
  104. {
  105. // dgoodenough - duplicate changes in portal2, i.e. stub these out on PS3
  106. // PS3_BUILDFIX
  107. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  108. ::GetWindowText((HWND)wnd, buffer, bufferSize - 1);
  109. #else
  110. buffer[0] = 0;
  111. #endif
  112. }
  113. void Sys_PostMessage(WHANDLE wnd, unsigned int msg, unsigned int wParam, unsigned int lParam)
  114. {
  115. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  116. ::PostMessageA((HWND)wnd, msg, wParam, lParam);
  117. #endif
  118. }
  119. void Sys_SetCursorPos(int x, int y)
  120. {
  121. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  122. ::SetCursorPos(x, y);
  123. // engine->SetCursorPos(x,y); // SRC version
  124. #endif
  125. }
  126. #if !defined( _OSX ) && !defined (LINUX)
  127. static ATOM staticWndclassAtom = 0;
  128. static WNDCLASS staticWndclass = { NULL };
  129. static LRESULT CALLBACK staticProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
  130. {
  131. #if !defined( _PS3 ) && !defined( _OSX ) && !defined (LINUX)
  132. return DefWindowProc(hwnd,msg,wparam,lparam);
  133. #else
  134. return 0;
  135. #endif
  136. }
  137. #endif
  138. WHANDLE Sys_CreateWindowEx(const char *windowName)
  139. {
  140. /*
  141. if (!staticWndclassAtom)
  142. {
  143. memset( &staticWndclass,0,sizeof(staticWndclass) );
  144. staticWndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  145. staticWndclass.lpfnWndProc = staticProc;
  146. staticWndclass.hInstance = GetModuleHandle(NULL);
  147. staticWndclass.hIcon = 0;
  148. staticWndclass.lpszClassName = windowName;
  149. staticWndclassAtom = ::RegisterClass( &staticWndclass );
  150. DWORD error = ::GetLastError();
  151. }
  152. return (WHANDLE)::CreateWindow(windowName, windowName, 0, 0, 0, 0, 0, 0, 0, GetModuleHandle(NULL), 0);
  153. */
  154. return (WHANDLE)1;
  155. }
  156. void Sys_DestroyWindow(WHANDLE wnd)
  157. {
  158. //::DestroyWindow((HWND)wnd);
  159. }