diff --git a/Minecraft.World/BufferedOutputStream.cpp b/Minecraft.World/BufferedOutputStream.cpp index 4f9edbf6..2833a24a 100644 --- a/Minecraft.World/BufferedOutputStream.cpp +++ b/Minecraft.World/BufferedOutputStream.cpp @@ -58,7 +58,7 @@ void BufferedOutputStream::write(byteArray b, unsigned int offset, unsigned int { for(unsigned int i = 0; i < length; i++ ) { - write( b[offset+i] ); + write(static_cast(b[offset+i])); } } } @@ -84,4 +84,4 @@ void BufferedOutputStream::write(unsigned int b) { flush(); } -} \ No newline at end of file +} diff --git a/Minecraft.World/ByteArrayInputStream.cpp b/Minecraft.World/ByteArrayInputStream.cpp index 29f6fc26..bd4bcd52 100644 --- a/Minecraft.World/ByteArrayInputStream.cpp +++ b/Minecraft.World/ByteArrayInputStream.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "InputOutputStream.h" +#include // Creates ByteArrayInputStream that uses buf as its buffer array. The initial value of pos is offset and // the initial value of count is the minimum of offset+length and buf.length. The buffer array is not copied. @@ -50,7 +51,7 @@ int ByteArrayInputStream::read() } else { - return buf[pos++]; + return static_cast(buf[pos++]); } } @@ -118,7 +119,7 @@ void ByteArrayInputStream::close() // n - the number of bytes to be skipped. // Returns: // the actual number of bytes skipped. -__int64 ByteArrayInputStream::skip(__int64 n) +int64_t ByteArrayInputStream::skip(int64_t n) { int newPos = pos + n; diff --git a/Minecraft.World/ByteBuffer.cpp b/Minecraft.World/ByteBuffer.cpp index 12229b15..3c5f8a6d 100644 --- a/Minecraft.World/ByteBuffer.cpp +++ b/Minecraft.World/ByteBuffer.cpp @@ -2,6 +2,7 @@ #include "IntBuffer.h" #include "FloatBuffer.h" +#include #include "ByteBuffer.h" ByteBuffer::ByteBuffer( unsigned int capacity ) : Buffer( capacity ) @@ -104,7 +105,7 @@ int ByteBuffer::getSize() //The byte at the given index //Throws: //IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit -BYTE ByteBuffer::get(int index) +byte ByteBuffer::get(int index) { assert( index < m_limit ); assert( index >= 0 ); @@ -124,10 +125,10 @@ int ByteBuffer::getInt() int value = 0; - int b1 = buffer[ m_position ]; - int b2 = buffer[ m_position+1 ]; - int b3 = buffer[ m_position+2 ]; - int b4 = buffer[ m_position+3 ]; + int b1 = static_cast(buffer[ m_position ]); + int b2 = static_cast(buffer[ m_position+1 ]); + int b3 = static_cast(buffer[ m_position+2 ]); + int b4 = static_cast(buffer[ m_position+3 ]); m_position += 4; @@ -154,10 +155,10 @@ int ByteBuffer::getInt(unsigned int index) assert( index+3 < m_limit ); int value = 0; - int b1 = buffer[ index ]; - int b2 = buffer[ index+1 ]; - int b3 = buffer[ index+2 ]; - int b4 = buffer[ index+3 ]; + int b1 = static_cast(buffer[ index ]); + int b2 = static_cast(buffer[ index+1 ]); + int b3 = static_cast(buffer[ index+2 ]); + int b4 = static_cast(buffer[ index+3 ]); if( byteOrder == BYTE_ORDER_BIG_ENDIAN ) { @@ -182,14 +183,14 @@ int64_t ByteBuffer::getLong() int64_t value = 0; - int64_t b1 = buffer[ m_position ]; - int64_t b2 = buffer[ m_position+1 ]; - int64_t b3 = buffer[ m_position+2 ]; - int64_t b4 = buffer[ m_position+3 ]; - int64_t b5 = buffer[ m_position+4 ]; - int64_t b6 = buffer[ m_position+5 ]; - int64_t b7 = buffer[ m_position+6 ]; - int64_t b8 = buffer[ m_position+7 ]; + int64_t b1 = static_cast(buffer[ m_position ]); + int64_t b2 = static_cast(buffer[ m_position+1 ]); + int64_t b3 = static_cast(buffer[ m_position+2 ]); + int64_t b4 = static_cast(buffer[ m_position+3 ]); + int64_t b5 = static_cast(buffer[ m_position+4 ]); + int64_t b6 = static_cast(buffer[ m_position+5 ]); + int64_t b7 = static_cast(buffer[ m_position+6 ]); + int64_t b8 = static_cast(buffer[ m_position+7 ]); m_position += 8; @@ -216,8 +217,8 @@ short ByteBuffer::getShort() short value = 0; - short b1 = buffer[ m_position ]; - short b2 = buffer[ m_position+1 ]; + short b1 = static_cast(buffer[ m_position ]); + short b2 = static_cast(buffer[ m_position+1 ]); m_position += 2; @@ -277,17 +278,17 @@ ByteBuffer *ByteBuffer::putInt(int value) if( byteOrder == BYTE_ORDER_BIG_ENDIAN ) { - buffer[m_position] = (value >> 24) & 0xFF; - buffer[m_position+1] = (value >> 16) & 0xFF; - buffer[m_position+2] = (value >> 8) & 0xFF; - buffer[m_position+3] = value & 0xFF; + buffer[m_position] = static_cast((value >> 24) & 0xFF); + buffer[m_position+1] = static_cast((value >> 16) & 0xFF); + buffer[m_position+2] = static_cast((value >> 8) & 0xFF); + buffer[m_position+3] = static_cast(value & 0xFF); } else if( byteOrder == BYTE_ORDER_LITTLE_ENDIAN ) { - buffer[m_position] = value & 0xFF; - buffer[m_position+1] = (value >> 8) & 0xFF; - buffer[m_position+2] = (value >> 16) & 0xFF; - buffer[m_position+3] = (value >> 24) & 0xFF; + buffer[m_position] = static_cast(value & 0xFF); + buffer[m_position+1] = static_cast((value >> 8) & 0xFF); + buffer[m_position+2] = static_cast((value >> 16) & 0xFF); + buffer[m_position+3] = static_cast((value >> 24) & 0xFF); } m_position += 4; @@ -309,17 +310,17 @@ ByteBuffer *ByteBuffer::putInt(unsigned int index, int value) if( byteOrder == BYTE_ORDER_BIG_ENDIAN ) { - buffer[index] = (value >> 24) & 0xFF; - buffer[index+1] = (value >> 16) & 0xFF; - buffer[index+2] = (value >> 8) & 0xFF; - buffer[index+3] = value & 0xFF; + buffer[index] = static_cast((value >> 24) & 0xFF); + buffer[index+1] = static_cast((value >> 16) & 0xFF); + buffer[index+2] = static_cast((value >> 8) & 0xFF); + buffer[index+3] = static_cast(value & 0xFF); } else if( byteOrder == BYTE_ORDER_LITTLE_ENDIAN ) { - buffer[index] = value & 0xFF; - buffer[index+1] = (value >> 8) & 0xFF; - buffer[index+2] = (value >> 16) & 0xFF; - buffer[index+3] = (value >> 24) & 0xFF; + buffer[index] = static_cast(value & 0xFF); + buffer[index+1] = static_cast((value >> 8) & 0xFF); + buffer[index+2] = static_cast((value >> 16) & 0xFF); + buffer[index+3] = static_cast((value >> 24) & 0xFF); } return this; @@ -339,13 +340,13 @@ ByteBuffer *ByteBuffer::putShort(short value) if( byteOrder == BYTE_ORDER_BIG_ENDIAN ) { - buffer[m_position] = (value >> 8) & 0xFF; - buffer[m_position+1] = value & 0xFF; + buffer[m_position] = static_cast((value >> 8) & 0xFF); + buffer[m_position+1] = static_cast(value & 0xFF); } else if( byteOrder == BYTE_ORDER_LITTLE_ENDIAN ) { - buffer[m_position] = value & 0xFF; - buffer[m_position+1] = (value >> 8) & 0xFF; + buffer[m_position] = static_cast(value & 0xFF); + buffer[m_position+1] = static_cast((value >> 8) & 0xFF); } m_position += 2; @@ -379,25 +380,25 @@ ByteBuffer *ByteBuffer::putLong(int64_t value) if( byteOrder == BYTE_ORDER_BIG_ENDIAN ) { - buffer[m_position] = (value >> 56) & 0xFF; - buffer[m_position+1] = (value >> 48) & 0xFF; - buffer[m_position+2] = (value >> 40) & 0xFF; - buffer[m_position+3] = (value >> 32) & 0xFF; - buffer[m_position+4] = (value >> 24) & 0xFF; - buffer[m_position+5] = (value >> 16) & 0xFF; - buffer[m_position+6] = (value >> 8) & 0xFF; - buffer[m_position+7] = value & 0xFF; + buffer[m_position] = static_cast((value >> 56) & 0xFF); + buffer[m_position+1] = static_cast((value >> 48) & 0xFF); + buffer[m_position+2] = static_cast((value >> 40) & 0xFF); + buffer[m_position+3] = static_cast((value >> 32) & 0xFF); + buffer[m_position+4] = static_cast((value >> 24) & 0xFF); + buffer[m_position+5] = static_cast((value >> 16) & 0xFF); + buffer[m_position+6] = static_cast((value >> 8) & 0xFF); + buffer[m_position+7] = static_cast(value & 0xFF); } else if( byteOrder == BYTE_ORDER_LITTLE_ENDIAN ) { - buffer[m_position] = value & 0xFF; - buffer[m_position+1] = (value >> 8) & 0xFF; - buffer[m_position+2] = (value >> 16) & 0xFF; - buffer[m_position+3] = (value >> 24) & 0xFF; - buffer[m_position+4] = (value >> 32) & 0xFF; - buffer[m_position+5] = (value >> 40) & 0xFF; - buffer[m_position+6] = (value >> 48) & 0xFF; - buffer[m_position+7] = (value >> 56) & 0xFF; + buffer[m_position] = static_cast(value & 0xFF); + buffer[m_position+1] = static_cast((value >> 8) & 0xFF); + buffer[m_position+2] = static_cast((value >> 16) & 0xFF); + buffer[m_position+3] = static_cast((value >> 24) & 0xFF); + buffer[m_position+4] = static_cast((value >> 32) & 0xFF); + buffer[m_position+5] = static_cast((value >> 40) & 0xFF); + buffer[m_position+6] = static_cast((value >> 48) & 0xFF); + buffer[m_position+7] = static_cast((value >> 56) & 0xFF); } return this; @@ -475,4 +476,4 @@ ByteBuffer_IO::~ByteBuffer_IO() // delete buffer; RenderManager.freeIOMem(buffer); } -#endif // __PS3__ \ No newline at end of file +#endif // __PS3__ diff --git a/Minecraft.World/C4JThread.cpp b/Minecraft.World/C4JThread.cpp index d07bb9ca..93f70913 100644 --- a/Minecraft.World/C4JThread.cpp +++ b/Minecraft.World/C4JThread.cpp @@ -96,12 +96,12 @@ C4JThread::C4JThread( C4JThreadStartFunc* startFunc, void* param, const char* th if( !strcmp(threadName, "Chunk update") ) { CPU = SCE_KERNEL_CPU_MASK_USER_2; - m_priority = g_DefaultPriority + 1; + m_priority = g_DefaultPriority + 1; } if( !strcmp(threadName, "Server" ) ) { CPU = SCE_KERNEL_CPU_MASK_USER_1; - m_priority = g_DefaultPriority + 1; + m_priority = g_DefaultPriority + 1; } // make sure Tile Update doesn't go on cpu 0 because it will hold up the main thread. And it can't go on cpu 1 because Chunk Update crashes. if( !strcmp(threadName, "Tile update") ) @@ -187,7 +187,7 @@ C4JThread::~C4JThread() { if( (*it) == this ) { - ms_threadList.erase(it); + ms_threadList.erase(it); LeaveCriticalSection(&ms_threadListCS); return; } @@ -256,9 +256,9 @@ void C4JThread::Run() #ifdef __PS3__ // prio specifies the priority value of the PPU thread within the range from 0 to 3071 where 0 is the highest. // One of the following values is set to flags: - // 0 - non-joinable non-interrupt thread - // SYS_PPU_THREAD_CREATE_JOINABLE - Create a joinable thread - // SYS_PPU_THREAD_CREATE_INTERRUPT - Create an interrupt thread + // 0 - non-joinable non-interrupt thread + // SYS_PPU_THREAD_CREATE_JOINABLE - Create a joinable thread + // SYS_PPU_THREAD_CREATE_INTERRUPT - Create an interrupt thread uint64_t flags = 0; int err = sys_ppu_thread_create(&m_threadID, entryPoint, (uint64_t)this, m_priority, m_stackSize, flags, m_threadName); #elif defined __ORBIS__ @@ -305,11 +305,11 @@ void C4JThread::SetPriority( int priority ) #ifdef __PS3__ switch(priority) { - case THREAD_PRIORITY_LOWEST: m_priority = 1003; break; - case THREAD_PRIORITY_BELOW_NORMAL: m_priority = 1002; break; + case THREAD_PRIORITY_LOWEST: m_priority = 1003; break; + case THREAD_PRIORITY_BELOW_NORMAL: m_priority = 1002; break; case THREAD_PRIORITY_NORMAL: m_priority = 1001; break; // same as main thread - case THREAD_PRIORITY_ABOVE_NORMAL: m_priority = 1000; break; - case THREAD_PRIORITY_HIGHEST: m_priority = 999; break; + case THREAD_PRIORITY_ABOVE_NORMAL: m_priority = 1000; break; + case THREAD_PRIORITY_HIGHEST: m_priority = 999; break; } if(m_threadID != 0) sys_ppu_thread_set_priority(m_threadID, m_priority); @@ -318,11 +318,11 @@ void C4JThread::SetPriority( int priority ) switch(priority) { - case THREAD_PRIORITY_LOWEST: m_priority = SCE_KERNEL_PRIO_FIFO_LOWEST; break; - case THREAD_PRIORITY_BELOW_NORMAL: m_priority = SCE_KERNEL_PRIO_FIFO_LOWEST + ((SCE_KERNEL_PRIO_FIFO_DEFAULT-SCE_KERNEL_PRIO_FIFO_LOWEST)/2); break; + case THREAD_PRIORITY_LOWEST: m_priority = SCE_KERNEL_PRIO_FIFO_LOWEST; break; + case THREAD_PRIORITY_BELOW_NORMAL: m_priority = SCE_KERNEL_PRIO_FIFO_LOWEST + ((SCE_KERNEL_PRIO_FIFO_DEFAULT-SCE_KERNEL_PRIO_FIFO_LOWEST)/2); break; case THREAD_PRIORITY_NORMAL: m_priority = SCE_KERNEL_PRIO_FIFO_DEFAULT; break; // same as main thread - case THREAD_PRIORITY_ABOVE_NORMAL: m_priority = SCE_KERNEL_PRIO_FIFO_DEFAULT + ((SCE_KERNEL_PRIO_FIFO_HIGHEST-SCE_KERNEL_PRIO_FIFO_DEFAULT)/2); break; - case THREAD_PRIORITY_HIGHEST: m_priority = SCE_KERNEL_PRIO_FIFO_HIGHEST; break; + case THREAD_PRIORITY_ABOVE_NORMAL: m_priority = SCE_KERNEL_PRIO_FIFO_DEFAULT + ((SCE_KERNEL_PRIO_FIFO_HIGHEST-SCE_KERNEL_PRIO_FIFO_DEFAULT)/2); break; + case THREAD_PRIORITY_HIGHEST: m_priority = SCE_KERNEL_PRIO_FIFO_HIGHEST; break; } if( m_threadID != 0 ) @@ -333,21 +333,21 @@ void C4JThread::SetPriority( int priority ) int Mid = g_DefaultPriority;//(SCE_KERNEL_LOWEST_PRIORITY_USER + SCE_KERNEL_HIGHEST_PRIORITY_USER) / 2; switch(priority) { - case THREAD_PRIORITY_LOWEST: - m_priority = SCE_KERNEL_LOWEST_PRIORITY_USER; - break; - case THREAD_PRIORITY_BELOW_NORMAL: - m_priority = Mid + 1; - break; - case THREAD_PRIORITY_NORMAL: - m_priority = Mid; + case THREAD_PRIORITY_LOWEST: + m_priority = SCE_KERNEL_LOWEST_PRIORITY_USER; + break; + case THREAD_PRIORITY_BELOW_NORMAL: + m_priority = Mid + 1; + break; + case THREAD_PRIORITY_NORMAL: + m_priority = Mid; break; // same as main thread - case THREAD_PRIORITY_ABOVE_NORMAL: - m_priority = Mid - 1; - break; - case THREAD_PRIORITY_HIGHEST: - m_priority = SCE_KERNEL_HIGHEST_PRIORITY_USER; - break; + case THREAD_PRIORITY_ABOVE_NORMAL: + m_priority = Mid - 1; + break; + case THREAD_PRIORITY_HIGHEST: + m_priority = SCE_KERNEL_HIGHEST_PRIORITY_USER; + break; } // sceKernelChangeThreadPriority(m_threadID, m_priority); @@ -472,10 +472,10 @@ C4JThread::Event::Event(EMode mode/* = e_modeAutoClear*/) attr.attr_pshared = SYS_SYNC_NOT_PROCESS_SHARED; attr.key = 0; attr.flags = 0; - attr.type = SYS_SYNC_WAITER_SINGLE; + attr.type = SYS_SYNC_WAITER_SINGLE; attr.name[0] = '\0'; sys_event_flag_attribute_initialize(attr); - + int err = sys_event_flag_create(&m_event, &attr, 0); #elif defined __ORBIS__ @@ -616,7 +616,7 @@ C4JThread::EventArray::EventArray( int size, EMode mode/* = e_modeAutoClear*/) attr.attr_pshared = SYS_SYNC_NOT_PROCESS_SHARED; attr.key = 0; attr.flags = 0; - attr.type = SYS_SYNC_WAITER_SINGLE; + attr.type = SYS_SYNC_WAITER_SINGLE; attr.name[0] = '\0'; sys_event_flag_attribute_initialize(attr); int err = sys_event_flag_create(&m_events, &attr, 0); @@ -972,7 +972,7 @@ void C4JThread::EventArray::Cancel() { sys_event_flag_cancel(m_events, nullptr); } -#endif +#endif @@ -1048,7 +1048,7 @@ void C4JThread::EventQueue::threadPoll() if(err == WAIT_OBJECT_0) { bool bListEmpty = true; - do + do { EnterCriticalSection(&m_critSect); void* updateParam = m_queue.front(); @@ -1097,4 +1097,4 @@ void C4JThread::PopAffinity() assert(err == SCE_OK); } -#endif // __ORBIS__ \ No newline at end of file +#endif // __ORBIS__ diff --git a/Minecraft.World/CompoundTag.h b/Minecraft.World/CompoundTag.h index 33f94c3b..02547a02 100644 --- a/Minecraft.World/CompoundTag.h +++ b/Minecraft.World/CompoundTag.h @@ -147,26 +147,26 @@ public: bool contains(const wstring& name, int typeId) { auto it = tags.find(name); - + if (it != tags.end()) { - int foundType = it->second->getId(); + int foundType = static_cast(it->second->getId()); if (foundType == typeId) return true; - - + + if (typeId == 99) return (unsigned int)(foundType - 1) <= 5; - + return false; } else { - + return typeId == 0; } } - + byte getByte(const wstring &name) { if (tags.find(name) == tags.end()) return (byte)0; @@ -234,7 +234,7 @@ public: CompoundTag* getCompound(const wstring& name) { - if (contains(name, Tag::TAG_Compound)) + if (contains(name, static_cast(Tag::TAG_Compound))) { return static_cast(get(name)); } @@ -249,7 +249,7 @@ public: bool getBoolean(const wstring &string) { - return getByte(string)!=0; + return getByte(string) != static_cast(0); } void remove(const wstring &name) @@ -336,6 +336,3 @@ public: } }; - - - diff --git a/Minecraft.World/ConsoleSaveFileInputStream.cpp b/Minecraft.World/ConsoleSaveFileInputStream.cpp index db997918..29dfb08e 100644 --- a/Minecraft.World/ConsoleSaveFileInputStream.cpp +++ b/Minecraft.World/ConsoleSaveFileInputStream.cpp @@ -25,7 +25,7 @@ ConsoleSaveFileInputStream::ConsoleSaveFileInputStream(ConsoleSaveFile *saveFile //the next byte of data, or -1 if the end of the file is reached. int ConsoleSaveFileInputStream::read() { - byte byteRead = 0; + byte byteRead = static_cast(0); DWORD numberOfBytesRead; BOOL result = m_saveFile->readFile( @@ -46,7 +46,7 @@ int ConsoleSaveFileInputStream::read() return -1; } - return byteRead; + return static_cast(byteRead); } //Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available. diff --git a/Minecraft.World/DataInputStream.cpp b/Minecraft.World/DataInputStream.cpp index 0cd21a7e..36b03dd1 100644 --- a/Minecraft.World/DataInputStream.cpp +++ b/Minecraft.World/DataInputStream.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "BasicTypeContainers.h" +#include #include "DataInputStream.h" @@ -138,7 +139,7 @@ bool DataInputStream::readFully(byteArray b) } else { - b[i] = byteRead; + b[i] = static_cast(byteRead); } } return true; @@ -554,4 +555,4 @@ int64_t DataInputStream::skip(int64_t n) int DataInputStream::skipBytes(int n) { return skip(n); -} \ No newline at end of file +} diff --git a/Minecraft.World/DataOutputStream.cpp b/Minecraft.World/DataOutputStream.cpp index d8d4eb02..8ccf9bec 100644 --- a/Minecraft.World/DataOutputStream.cpp +++ b/Minecraft.World/DataOutputStream.cpp @@ -68,7 +68,7 @@ void DataOutputStream::close() //v - a byte value to be written. void DataOutputStream::writeByte(byte a) { - stream->write( a ); + stream->write(static_cast(a)); } //Converts the double argument to a long using the doubleToLongBits method in class Double, @@ -184,7 +184,7 @@ void DataOutputStream::writeChars(const wstring& str) //v - a boolean value to be written. void DataOutputStream::writeBoolean(bool b) { - stream->write( b ? static_cast(1) : static_cast(0) ); + stream->write( b ? static_cast(1) : static_cast(0) ); // TODO 4J Stu - Error handling? written += 1; } @@ -279,4 +279,4 @@ void DataOutputStream::writePlayerUID(PlayerUID player) OutputStream* DataOutputStream::getChildOutputStream() { return stream; -} \ No newline at end of file +} diff --git a/Minecraft.World/FileInputStream.cpp b/Minecraft.World/FileInputStream.cpp index a1846440..c4ae3d78 100644 --- a/Minecraft.World/FileInputStream.cpp +++ b/Minecraft.World/FileInputStream.cpp @@ -29,6 +29,8 @@ FileInputStream::FileInputStream(const File &file) FILE_FLAG_SEQUENTIAL_SCAN, // file attributes nullptr // Unsupported ); +#elif defined(__linux__) + m_fileHandle = open(pchFilename, O_RDONLY); #else m_fileHandle = CreateFile( pchFilename, // file name @@ -59,7 +61,7 @@ FileInputStream::~FileInputStream() //the next byte of data, or -1 if the end of the file is reached. int FileInputStream::read() { - byte byteRead = 0; + byte byteRead = static_cast(0); DWORD numberOfBytesRead; BOOL bSuccess = ReadFile( @@ -82,7 +84,7 @@ int FileInputStream::read() return -1; } - return byteRead; + return static_cast(byteRead); } //Reads up to b.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available. @@ -200,4 +202,4 @@ int64_t FileInputStream::skip(int64_t n) #else return 0; #endif -} \ No newline at end of file +} diff --git a/Minecraft.World/FileInputStream.h b/Minecraft.World/FileInputStream.h index 99ce776f..36383415 100644 --- a/Minecraft.World/FileInputStream.h +++ b/Minecraft.World/FileInputStream.h @@ -15,6 +15,10 @@ public: virtual int64_t skip(int64_t n); private: +#ifdef __linux__ + int m_fileHandle; +#else HANDLE m_fileHandle; +#endif -}; \ No newline at end of file +}; diff --git a/Minecraft.World/FileOutputStream.cpp b/Minecraft.World/FileOutputStream.cpp index 6bb6df41..6d3bdce9 100644 --- a/Minecraft.World/FileOutputStream.cpp +++ b/Minecraft.World/FileOutputStream.cpp @@ -21,7 +21,11 @@ // //Parameters: //file - the file to be opened for writing. +#ifdef __linux__ +FileOutputStream::FileOutputStream(const File &file) : m_fileHandle( -1 ) +#else FileOutputStream::FileOutputStream(const File &file) : m_fileHandle( INVALID_HANDLE_VALUE ) +#endif { if( file.exists() && file.isDirectory()) { @@ -58,7 +62,11 @@ FileOutputStream::FileOutputStream(const File &file) : m_fileHandle( INVALID_HAN ); #endif +#ifdef __linux__ + if( m_fileHandle == -1 ) +#else if( m_fileHandle == INVALID_HANDLE_VALUE ) +#endif { // TODO 4J Stu - Any form of error/exception handling DWORD error = GetLastError(); @@ -67,12 +75,12 @@ FileOutputStream::FileOutputStream(const File &file) : m_fileHandle( INVALID_HAN FileOutputStream::~FileOutputStream() { -#ifdef _WIN32 - if( m_fileHandle != INVALID_HANDLE_VALUE ) - CloseHandle( m_fileHandle ); +#ifdef __linux__ + if( m_fileHandle != -1 ) + ::close( m_fileHandle ); #else if( m_fileHandle != INVALID_HANDLE_VALUE ) - ::close( m_fileHandle ); + CloseHandle( m_fileHandle ); #endif } @@ -179,10 +187,10 @@ void FileOutputStream::write(byteArray b, unsigned int offset, unsigned int leng //If this stream has an associated channel then the channel is closed as well. void FileOutputStream::close() { -#ifdef _WIN32 +#ifdef __linux__ + int result = ::close( m_fileHandle ); +#else BOOL result = CloseHandle( m_fileHandle ); -#else // __linux__ - int result = ::close( m_fileHandle ); #endif // _WIN32 if( result == 0 ) { @@ -190,5 +198,9 @@ void FileOutputStream::close() } // Stop the dtor from trying to close it again - m_fileHandle = INVALID_HANDLE_VALUE; +#ifdef __linux__ + m_fileHandle = -1; +#else + m_fileHandle = INVALID_HANDLE_VALUE; +#endif } diff --git a/Minecraft.World/FileOutputStream.h b/Minecraft.World/FileOutputStream.h index bb8df059..2c14814a 100644 --- a/Minecraft.World/FileOutputStream.h +++ b/Minecraft.World/FileOutputStream.h @@ -15,5 +15,9 @@ public: virtual void flush() {} private: - HANDLE m_fileHandle; -}; \ No newline at end of file +#ifdef __linux__ + int m_fileHandle; +#else + HANDLE m_fileHandle; +#endif +}; diff --git a/Minecraft.World/ListTag.h b/Minecraft.World/ListTag.h index dd9698c5..80150a4c 100644 --- a/Minecraft.World/ListTag.h +++ b/Minecraft.World/ListTag.h @@ -20,7 +20,7 @@ public: void write(DataOutput *dos) { if (list.size() > 0) type = (list[0])->getId(); - else type = 1; + else type = static_cast(1); dos->writeByte(type); dos->writeInt(static_cast(list.size())); @@ -45,7 +45,7 @@ public: list.push_back(tag); } } - + byte getId() { return TAG_List; } @@ -56,7 +56,7 @@ public: return wstring( buf ); } - void print(char *prefix, ostream out) + void print(char *prefix, wostream& out) { Tag::print(prefix, out); @@ -152,4 +152,4 @@ public: -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Socket.cpp b/Minecraft.World/Socket.cpp index ce30e1a5..babd8376 100644 --- a/Minecraft.World/Socket.cpp +++ b/Minecraft.World/Socket.cpp @@ -5,6 +5,7 @@ #include "ThreadName.h" #include "../Minecraft.Client/ServerConnection.h" #include +#include #include "../Minecraft.Client/PS3/PS3Extras/ShutdownManager.h" // This current socket implementation is for the creation of a single local link. 2 sockets can be created, one for either end of this local @@ -125,7 +126,7 @@ void Socket::setPlayer(INetworkPlayer *player) } } -void Socket::pushDataToQueue(const BYTE * pbData, DWORD dwDataSize, bool fromHost /*= true*/) +void Socket::pushDataToQueue(const byte * pbData, DWORD dwDataSize, bool fromHost /*= true*/) { int queueIdx = SOCKET_CLIENT_END; if(!fromHost) @@ -276,7 +277,7 @@ int Socket::SocketInputStreamLocal::read() byte retval = s_hostQueue[m_queueIdx].front(); s_hostQueue[m_queueIdx].pop(); LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]); - return retval; + return static_cast(retval); } LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]); } @@ -394,7 +395,7 @@ int Socket::SocketInputStreamNetwork::read() byte retval = m_socket->m_queueNetwork[m_queueIdx].front(); m_socket->m_queueNetwork[m_queueIdx].pop(); LeaveCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]); - return retval; + return static_cast(retval); } LeaveCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]); } diff --git a/Minecraft.World/Socket.h b/Minecraft.World/Socket.h index c4ec9fc8..61165f68 100644 --- a/Minecraft.World/Socket.h +++ b/Minecraft.World/Socket.h @@ -119,7 +119,7 @@ public: Socket(bool response = false); // 4J - Create a local socket, for end 0 or 1 of a connection Socket(INetworkPlayer *player, bool response = false, bool hostLocal = false); // 4J - Create a socket for an INetworkPlayer SocketAddress *getRemoteSocketAddress(); - void pushDataToQueue(const BYTE * pbData, DWORD dwDataSize, bool fromHost = true); + void pushDataToQueue(const byte* pbData, DWORD dwDataSize, bool fromHost = true); static void addIncomingSocket(Socket *socket); InputStream *getInputStream(bool isServerConnection); void setSoTimeout(int a ); @@ -131,4 +131,4 @@ public: bool isClosing() { return m_endClosed[SOCKET_CLIENT_END] || m_endClosed[SOCKET_SERVER_END]; } BYTE getSmallId() { return networkPlayerSmallId; } -}; \ No newline at end of file +}; diff --git a/Minecraft.World/ThreadName.cpp b/Minecraft.World/ThreadName.cpp index 040c7541..7022a269 100644 --- a/Minecraft.World/ThreadName.cpp +++ b/Minecraft.World/ThreadName.cpp @@ -13,13 +13,13 @@ void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName ) { #ifndef __PS3__ THREADNAME_INFO info; - + info.dwType = 0x1000; info.szName = szThreadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; - -#if ( (defined(_WINDOWS64) || defined(__linux__)) | defined _DURANGO ) + +#if (defined(_WINDOWS64) || defined(_DURANGO)) __try { RaiseException(0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR *)&info); @@ -37,5 +37,17 @@ void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName ) { } #endif +#if defined(__linux__) + (void)dwThreadID; + if (!szThreadName) return; + + // Note: Linux limits thread names to 15 chars, if you try to use a bigger one it will fail silently and be hard to debug + // we truncate in case this happens + char truncated[16]; + + std::strncpy(truncated, szThreadName, sizeof(truncated) - 1); + truncated[sizeof(truncated) - 1] = '\0'; + pthread_setname_np(pthread_self(), truncated); +#endif #endif // __PS3__ } diff --git a/Minecraft.World/system.cpp b/Minecraft.World/system.cpp index 9cab8553..feb46691 100644 --- a/Minecraft.World/system.cpp +++ b/Minecraft.World/system.cpp @@ -16,7 +16,7 @@ template void System::arraycopy(arrayWithLength src, unsigned int s ArrayCopyFunctionDefinition(Node *) ArrayCopyFunctionDefinition(Biome *) -void System::arraycopy(arrayWithLength src, unsigned int srcPos, arrayWithLength *dst, unsigned int dstPos, unsigned int length) +void System::arraycopy(arrayWithLength src, unsigned int srcPos, arrayWithLength *dst, unsigned int dstPos, unsigned int length) { assert( srcPos >=0 && srcPos <= src.length); assert( srcPos + length <= src.length ); @@ -102,6 +102,13 @@ int64_t System::currentTimeMillis() sceRtcGetCurrentClockLocalTime(&Time); int64_t systTime = (((((((Time.day * 24) + Time.hour) * 60) + Time.minute) * 60) + Time.second) * 1000) + (Time.microsecond / 1000); return systTime;*/ +#elif defined(__linux__) + struct timeval tv; + gettimeofday(&tv, NULL); + + // Convert to milliseconds since unix epoch instead of windows file time + // time is expecting calculation to be between 10-30 ms. + return static_cast(tv.tv_sec * 1000LL + tv.tv_sec / 1000); #else