Panda3D

physxMemoryWriteBuffer.cxx

00001 // Filename: physxMemoryWriteBuffer.cxx
00002 // Created by:  enn0x (11Oct09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "physxMemoryWriteBuffer.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: PhysxMemoryWriteBuffer::Constructor
00019 //       Access: Public
00020 //  Description:
00021 ////////////////////////////////////////////////////////////////////
00022 PhysxMemoryWriteBuffer::PhysxMemoryWriteBuffer() : currentSize(0), maxSize(0), data(NULL)
00023 {
00024 
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: PhysxMemoryWriteBuffer::Destructor
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 PhysxMemoryWriteBuffer::~PhysxMemoryWriteBuffer()
00033 {
00034   NxGetPhysicsSDKAllocator()->free(data);
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: PhysxMemoryWriteBuffer::storeByte
00039 //       Access: Public
00040 //  Description:
00041 ////////////////////////////////////////////////////////////////////
00042 NxStream &PhysxMemoryWriteBuffer::storeByte(NxU8 b)
00043 {
00044   storeBuffer(&b, sizeof(NxU8));
00045   return *this;
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: PhysxMemoryWriteBuffer::storeWord
00050 //       Access: Public
00051 //  Description:
00052 ////////////////////////////////////////////////////////////////////
00053 NxStream &PhysxMemoryWriteBuffer::storeWord(NxU16 w)
00054 {
00055   storeBuffer(&w, sizeof(NxU16));
00056   return *this;
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: PhysxMemoryWriteBuffer::storeDword
00061 //       Access: Public
00062 //  Description:
00063 ////////////////////////////////////////////////////////////////////
00064 NxStream &PhysxMemoryWriteBuffer::storeDword(NxU32 d)
00065 {
00066   storeBuffer(&d, sizeof(NxU32));
00067   return *this;
00068 }
00069 
00070 ////////////////////////////////////////////////////////////////////
00071 //     Function: PhysxMemoryWriteBuffer::storeFloat
00072 //       Access: Public
00073 //  Description:
00074 ////////////////////////////////////////////////////////////////////
00075 NxStream &PhysxMemoryWriteBuffer::storeFloat(NxReal f)
00076 {
00077   storeBuffer(&f, sizeof(NxReal));
00078   return *this;
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: PhysxMemoryWriteBuffer::storeDouble
00083 //       Access: Public
00084 //  Description:
00085 ////////////////////////////////////////////////////////////////////
00086 NxStream &PhysxMemoryWriteBuffer::storeDouble(NxF64 f)
00087 {
00088   storeBuffer(&f, sizeof(NxF64));
00089   return *this;
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: PhysxMemoryWriteBuffer::storeBuffer
00094 //       Access: Public
00095 //  Description:
00096 ////////////////////////////////////////////////////////////////////
00097 NxStream &PhysxMemoryWriteBuffer::storeBuffer(const void *buffer, NxU32 size)
00098 {
00099   NxU32 expectedSize = currentSize + size;
00100   if (expectedSize > maxSize)
00101   {
00102     maxSize = expectedSize + 4096;
00103 
00104     NxU8 *newData = (NxU8 *)NxGetPhysicsSDKAllocator()->malloc(maxSize, NX_MEMORY_PERSISTENT);
00105     if(data)
00106     {
00107       memcpy(newData, data, currentSize);
00108       NxGetPhysicsSDKAllocator()->free(data);
00109     }
00110     data = newData;
00111   }
00112   memcpy(data + currentSize, buffer, size);
00113   currentSize += size;
00114   return *this;
00115 }
00116 
 All Classes Functions Variables Enumerations