pxStream.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "T3D/physics/physX/pxStream.h"
  24. #include "console/console.h"
  25. #include "console/consoleTypes.h"
  26. #include "core/strings/stringFunctions.h"
  27. PxMemStream::PxMemStream()
  28. : mMemStream( 1024 )
  29. {
  30. }
  31. PxMemStream::~PxMemStream()
  32. {
  33. }
  34. void PxMemStream::resetPosition()
  35. {
  36. mMemStream.setPosition( 0 );
  37. }
  38. NxU8 PxMemStream::readByte() const
  39. {
  40. NxU8 out;
  41. mMemStream.read( &out );
  42. return out;
  43. }
  44. NxU16 PxMemStream::readWord() const
  45. {
  46. NxU16 out;
  47. mMemStream.read( &out );
  48. return out;
  49. }
  50. NxU32 PxMemStream::readDword() const
  51. {
  52. NxU32 out;
  53. mMemStream.read( &out );
  54. return out;
  55. }
  56. float PxMemStream::readFloat() const
  57. {
  58. float out;
  59. mMemStream.read( &out );
  60. return out;
  61. }
  62. double PxMemStream::readDouble() const
  63. {
  64. double out;
  65. mMemStream.read( &out );
  66. return out;
  67. }
  68. void PxMemStream::readBuffer( void *buffer, NxU32 size ) const
  69. {
  70. mMemStream.read( size, buffer );
  71. }
  72. NxStream& PxMemStream::storeByte( NxU8 b )
  73. {
  74. mMemStream.write( b );
  75. return *this;
  76. }
  77. NxStream& PxMemStream::storeWord( NxU16 w )
  78. {
  79. mMemStream.write( w );
  80. return *this;
  81. }
  82. NxStream& PxMemStream::storeDword( NxU32 d )
  83. {
  84. mMemStream.write( d );
  85. return *this;
  86. }
  87. NxStream& PxMemStream::storeFloat( NxReal f )
  88. {
  89. mMemStream.write( f );
  90. return *this;
  91. }
  92. NxStream& PxMemStream::storeDouble( NxF64 f )
  93. {
  94. mMemStream.write( f );
  95. return *this;
  96. }
  97. NxStream& PxMemStream::storeBuffer( const void *buffer, NxU32 size )
  98. {
  99. mMemStream.write( size, buffer );
  100. return *this;
  101. }
  102. bool gPhysXLogWarnings = false;
  103. PxConsoleStream::PxConsoleStream()
  104. {
  105. }
  106. PxConsoleStream::~PxConsoleStream()
  107. {
  108. }
  109. void PxConsoleStream::reportError( NxErrorCode code, const char *message, const char* file, int line )
  110. {
  111. #ifdef TORQUE_DEBUG
  112. // If we're in debug mode and the error code is serious then
  113. // pop up a message box to make sure we see it.
  114. if ( code < NXE_DB_INFO )
  115. {
  116. UTF8 info[1024];
  117. dSprintf( info, 1024, "File: %s\nLine: %d\n%s", file, line, message );
  118. Platform::AlertOK( "PhysX Error", info );
  119. }
  120. #endif
  121. // In all other cases we just dump the message to the console.
  122. if ( code == NXE_DB_WARNING )
  123. {
  124. if ( gPhysXLogWarnings )
  125. Con::printf( "PhysX Warning:\n %s(%d) : %s\n", file, line, message );
  126. }
  127. else
  128. Con::printf( "PhysX Error:\n %s(%d) : %s\n", file, line, message );
  129. }
  130. NxAssertResponse PxConsoleStream::reportAssertViolation (const char *message, const char *file,int line)
  131. {
  132. // Assert if we're in debug mode...
  133. bool triggerBreak = false;
  134. #ifdef TORQUE_DEBUG
  135. triggerBreak = PlatformAssert::processAssert( PlatformAssert::Fatal, file, line, message );
  136. #endif
  137. // In all other cases we just dump the message to the console.
  138. Con::errorf( "PhysX Assert:\n %s(%d) : %s\n", file, line, message );
  139. return triggerBreak ? NX_AR_BREAKPOINT : NX_AR_CONTINUE;
  140. }
  141. void PxConsoleStream::print( const char *message )
  142. {
  143. Con::printf( "PhysX Says: %s\n", message );
  144. }