2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-05 16:27:27 +00:00

refactor: fix x64 compilation for ObjLoading

This commit is contained in:
Jan
2025-04-26 10:11:28 +01:00
committed by Jan Laupetin
parent ee4301952a
commit 5d0c94e430
34 changed files with 212 additions and 212 deletions

View File

@@ -56,9 +56,9 @@ namespace
[[nodiscard]] std::unique_ptr<iobjstream> GetEntryStream(const Hash nameHash, const Hash dataHash) const override
{
IPakIndexEntryKey wantedKey{};
wantedKey.nameHash = nameHash;
wantedKey.dataHash = dataHash;
const IPakIndexEntryKey wantedKey{
{.dataHash = dataHash, .nameHash = nameHash}
};
for (auto& entry : m_index_entries)
{
@@ -209,5 +209,5 @@ IIPak::Hash IIPak::HashString(const std::string& str)
IIPak::Hash IIPak::HashData(const void* data, const size_t dataSize)
{
return crc32(0, static_cast<const Bytef*>(data), dataSize);
return crc32(0, static_cast<const Bytef*>(data), static_cast<unsigned>(dataSize));
}

View File

@@ -2,6 +2,7 @@
#include "ObjContainer/IPak/IPakTypes.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <minilzo.h>
@@ -24,7 +25,7 @@ IPakEntryReadStream::IPakEntryReadStream(
m_current_command_offset(0),
m_pos(startOffset),
m_base_pos(startOffset),
m_end_pos(startOffset + entrySize),
m_end_pos(startOffset + static_cast<int64_t>(entrySize)),
m_buffer_start_pos(0),
m_buffer_end_pos(0)
{
@@ -53,8 +54,7 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
{
// Cannot load more than IPAK_CHUNK_COUNT_PER_READ chunks without overflowing the buffer
assert(chunkCount <= IPAK_CHUNK_COUNT_PER_READ);
if (chunkCount > IPAK_CHUNK_COUNT_PER_READ)
chunkCount = IPAK_CHUNK_COUNT_PER_READ;
chunkCount = std::min(chunkCount, IPAK_CHUNK_COUNT_PER_READ);
// The start position must be aligned to IPAK_CHUNK_SIZE
assert(startPos % IPAK_CHUNK_SIZE == 0);
@@ -66,7 +66,7 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
return true;
}
const auto endPos = startPos + static_cast<int64_t>(chunkCount) * IPAK_CHUNK_SIZE;
const auto endPos = startPos + static_cast<int64_t>(chunkCount) * static_cast<int64_t>(IPAK_CHUNK_SIZE);
// Check whether the start position is already part of the loaded data
// We might be able to reuse previously loaded data
@@ -133,7 +133,7 @@ bool IPakEntryReadStream::ValidateBlockHeader(const IPakDataBlockHeader* blockHe
}
// We expect the current file to be continued where we left off
if (blockHeader->countAndOffset.offset != m_file_head)
if (static_cast<int64_t>(blockHeader->countAndOffset.offset) != m_file_head)
{
// A matching offset is only relevant if a command contains data
for (unsigned currentCommand = 0; currentCommand < blockHeader->countAndOffset.count; currentCommand++)
@@ -228,7 +228,7 @@ bool IPakEntryReadStream::ProcessCommand(const size_t commandSize, const int com
m_current_command_buffer = m_decompress_buffer;
m_current_command_length = outputSize;
m_current_command_offset = 0;
m_file_head += outputSize;
m_file_head += static_cast<int64_t>(outputSize);
}
else
{
@@ -240,9 +240,9 @@ bool IPakEntryReadStream::ProcessCommand(const size_t commandSize, const int com
m_current_command_buffer = &m_chunk_buffer[m_pos - m_buffer_start_pos];
m_current_command_length = commandSize;
m_current_command_offset = 0;
m_file_head += commandSize;
m_file_head += static_cast<int64_t>(commandSize);
}
m_pos += commandSize;
m_pos += static_cast<int64_t>(commandSize);
return true;
}
@@ -326,7 +326,7 @@ std::streambuf::int_type IPakEntryReadStream::uflow()
std::streamsize IPakEntryReadStream::xsgetn(char* ptr, const std::streamsize count)
{
auto* destBuffer = reinterpret_cast<uint8_t*>(ptr);
int64_t countRead = 0;
std::streamsize countRead = 0;
while (countRead < count)
{
@@ -337,12 +337,11 @@ std::streamsize IPakEntryReadStream::xsgetn(char* ptr, const std::streamsize cou
}
auto sizeToRead = count - countRead;
if (sizeToRead > m_current_command_length - m_current_command_offset)
sizeToRead = m_current_command_length - m_current_command_offset;
sizeToRead = std::min(sizeToRead, static_cast<std::streamsize>(m_current_command_length - m_current_command_offset));
if (sizeToRead > 0)
{
assert(static_cast<size_t>(count - countRead) >= static_cast<size_t>(sizeToRead));
assert(count - countRead >= sizeToRead);
memcpy(&destBuffer[countRead], &m_current_command_buffer[m_current_command_offset], static_cast<size_t>(sizeToRead));
countRead += sizeToRead;
m_current_command_offset += static_cast<size_t>(sizeToRead);

View File

@@ -1,9 +1,9 @@
#include "SoundBank.h"
#include "Utils/FileUtils.h"
#include "zlib.h"
#include <cstring>
#include <format>
#include <memory>
#include <sstream>
#include <vector>
@@ -67,18 +67,18 @@ protected:
if (dir == std::ios_base::end)
{
if (off > m_size)
if (off > static_cast<off_type>(m_size))
return pos_type(-1);
return seekpos(m_size - off, mode);
return seekpos(static_cast<off_type>(m_size) - off, mode);
}
return seekpos(m_offset + off, mode);
return seekpos(static_cast<pos_type>(m_offset) + off, mode);
}
pos_type seekpos(const pos_type pos, std::ios_base::openmode mode) override
{
if (pos < 0 || pos >= m_size)
if (pos < 0 || pos >= static_cast<pos_type>(m_size))
return pos_type(-1);
m_stream.seekg(m_base_offset + pos);
@@ -96,7 +96,7 @@ public:
{
}
_NODISCARD bool is_open() const override
[[nodiscard]] bool is_open() const override
{
return m_open;
}
@@ -116,13 +116,13 @@ SoundBankEntryInputStream::SoundBankEntryInputStream()
SoundBankEntryInputStream::SoundBankEntryInputStream(std::unique_ptr<std::istream> stream, SoundAssetBankEntry entry)
: m_stream(std::move(stream)),
m_entry(entry)
m_entry(std::move(entry))
{
}
bool SoundBankEntryInputStream::IsOpen() const
{
return m_stream.get() != nullptr;
return m_stream != nullptr;
}
bool SoundBank::ReadHeader()
@@ -130,49 +130,50 @@ bool SoundBank::ReadHeader()
m_stream->read(reinterpret_cast<char*>(&m_header), sizeof(m_header));
if (m_stream->gcount() != sizeof(m_header))
{
printf("Unexpected eof when trying to load sndbank header.\n");
std::cerr << "Unexpected eof when trying to load sndbank header.\n";
return false;
}
if (m_header.magic != MAGIC)
{
std::cout << "Invalid sndbank magic 0x" << std::hex << m_header.magic << "\n";
std::cerr << std::format("Invalid sndbank magic 0x{:x}\n", m_header.magic);
return false;
}
if (m_header.version != VERSION)
{
std::cout << "Unsupported sndbank version " << m_header.version << " (should be " << VERSION << ")\n";
std::cerr << std::format("Unsupported sndbank version {} (should be {})\n", m_header.version, VERSION);
return false;
}
if (m_header.entrySize != sizeof(SoundAssetBankEntry))
{
std::cout << "Invalid sndbank entry size 0x" << std::hex << m_header.entrySize << " (should be 0x" << std::hex << sizeof(SoundAssetBankEntry) << ")\n";
std::cerr << std::format("Invalid sndbank entry size 0x{:x} (should be 0x{:x})\n", m_header.entrySize, sizeof(SoundAssetBankEntry));
return false;
}
if (m_header.fileSize != m_file_size)
{
std::cout << "Invalid sndbank " << m_file_size << " (header expects " << m_header.fileSize << ")\n";
std::cerr << std::format("Invalid sndbank {} (header expects {})\n", m_file_size, m_header.fileSize);
return false;
}
if (m_header.entryCount && (m_header.entryOffset <= 0 || m_header.entryOffset + sizeof(SoundAssetBankEntry) * m_header.entryCount > m_file_size))
if (m_header.entryCount
&& (m_header.entryOffset <= 0 || m_header.entryOffset + sizeof(SoundAssetBankEntry) * m_header.entryCount > static_cast<size_t>(m_file_size)))
{
std::cout << "Invalid sndbank entry offset " << m_header.entryOffset << " (filesize is " << m_file_size << ")\n";
std::cerr << std::format("Invalid sndbank entry offset {} (filesize is {})\n", m_header.entryOffset, m_file_size);
return false;
}
if (m_header.checksumOffset <= 0 || m_header.checksumOffset + sizeof(SoundAssetBankChecksum) * m_header.entryCount > m_file_size)
if (m_header.checksumOffset <= 0 || m_header.checksumOffset + sizeof(SoundAssetBankChecksum) * m_header.entryCount > static_cast<size_t>(m_file_size))
{
std::cout << "Invalid sndbank checksum offset " << m_header.checksumOffset << " (filesize is " << m_file_size << ")\n";
std::cerr << std::format("Invalid sndbank checksum offset {} (filesize is {})\n", m_header.checksumOffset, m_file_size);
return false;
}
if (m_header.dependencyCount * m_header.dependencySize > sizeof(SoundAssetBankHeader::dependencies))
{
std::cout << "Invalid sndbank dependency sizes (count is " << m_header.dependencyCount << "; size is " << m_header.dependencySize << ")\n";
std::cerr << std::format("Invalid sndbank dependency sizes (count is {}; size is {})\n", m_header.dependencyCount, m_header.dependencySize);
return false;
}
@@ -201,13 +202,13 @@ bool SoundBank::ReadEntries()
if (m_stream->gcount() != sizeof(entry))
{
std::cout << "Failed to read sound bank entry at index " << i << "\n";
std::cerr << std::format("Failed to read sound bank entry at index {}\n", i);
return false;
}
if (entry.offset == 0 || entry.offset + entry.size >= m_file_size)
{
std::cout << "Invalid sound bank entry data offset " << entry.offset << " (filesize is " << m_header.fileSize << ")\n";
std::cerr << std::format("Invalid sound bank entry data offset {} (filesize is {})\n", entry.offset, m_header.fileSize);
return false;
}
@@ -229,7 +230,7 @@ bool SoundBank::ReadChecksums()
if (m_stream->gcount() != sizeof(checksum))
{
std::cout << "Failed to read sound bank checksum at index " << i << "\n";
std::cerr << std::format("Failed to read sound bank checksum at index {}\n", i);
return false;
}