refactor: remove arrayWithLength, replace with std::vector

Eliminates the custom arrayWithLength<T> wrapper and all typedefs, replacing with std::vector<T> directly.
This commit is contained in:
MatthewBeshay 2026-03-31 12:06:19 +11:00
parent 27a4964941
commit 7ddfaeb59e
414 changed files with 2412 additions and 2724 deletions

View file

@ -2904,9 +2904,9 @@ void CMinecraftApp::HandleXuiActions(void) {
// If there's a non-null level then, for our // If there's a non-null level then, for our
// purposes, the game has started // purposes, the game has started
bool gameStarted = false; bool gameStarted = false;
for (int j = 0; j < pMinecraft->levels.length; for (int j = 0; j < pMinecraft->levels.size();
j++) { j++) {
if (pMinecraft->levels.data[j] != nullptr) { if (pMinecraft->levels.data()[j] != nullptr) {
gameStarted = true; gameStarted = true;
break; break;
} }
@ -3683,9 +3683,8 @@ void CMinecraftApp::loadStringTable() {
} }
std::wstring localisationFile = L"languages.loc"; std::wstring localisationFile = L"languages.loc";
if (m_mediaArchive->hasFile(localisationFile)) { if (m_mediaArchive->hasFile(localisationFile)) {
byteArray locFile = m_mediaArchive->getFile(localisationFile); std::vector<uint8_t> locFile = m_mediaArchive->getFile(localisationFile);
m_stringTable = new StringTable(locFile.data, locFile.length); m_stringTable = new StringTable(locFile.data(), locFile.size());
delete[] locFile.data;
} else { } else {
m_stringTable = nullptr; m_stringTable = nullptr;
assert(false); assert(false);
@ -4713,12 +4712,12 @@ void CMinecraftApp::GetTPD(int iConfig, std::uint8_t** ppbData,
// if(fileSize!=0) // if(fileSize!=0)
// { // {
// FileInputStream fis(gtsFile); // FileInputStream fis(gtsFile);
// byteArray ba((int)fileSize); // std::vector<uint8_t> ba((int)fileSize);
// fis.read(ba); // fis.read(ba);
// fis.close(); // fis.close();
// //
// bRes=StorageManager.WriteTMSFile(iQuadrant,eStorageFacility,(wchar_t // bRes=StorageManager.WriteTMSFile(iQuadrant,eStorageFacility,(wchar_t
// *)wsFile->c_str(),ba.data, ba.length); // *)wsFile->c_str(),ba.data(), ba.size());
// //
// } // }
// #endif // #endif
@ -7266,7 +7265,7 @@ bool CMinecraftApp::hasArchiveFile(const std::wstring& filename) {
return m_mediaArchive->hasFile(filename); return m_mediaArchive->hasFile(filename);
} }
byteArray CMinecraftApp::getArchiveFile(const std::wstring& filename) { std::vector<uint8_t> CMinecraftApp::getArchiveFile(const std::wstring& filename) {
TexturePack* tPack = nullptr; TexturePack* tPack = nullptr;
Minecraft* pMinecraft = Minecraft::GetInstance(); Minecraft* pMinecraft = Minecraft::GetInstance();
if (pMinecraft && pMinecraft->skins) if (pMinecraft && pMinecraft->skins)

View file

@ -501,7 +501,7 @@ protected:
public: public:
int getArchiveFileSize(const std::wstring& filename); int getArchiveFileSize(const std::wstring& filename);
bool hasArchiveFile(const std::wstring& filename); bool hasArchiveFile(const std::wstring& filename);
byteArray getArchiveFile(const std::wstring& filename); std::vector<uint8_t> getArchiveFile(const std::wstring& filename);
private: private:
static int BannedLevelDialogReturned(void* pParam, int iPad, static int BannedLevelDialogReturned(void* pParam, int iPad,

View file

@ -343,7 +343,7 @@ ColourTable::ColourTable(ColourTable* defaultColours, std::uint8_t* pbData,
} }
void ColourTable::loadColoursFromData(std::uint8_t* pbData, void ColourTable::loadColoursFromData(std::uint8_t* pbData,
std::uint32_t dataLength) { std::uint32_t dataLength) {
byteArray src(pbData, dataLength); std::vector<uint8_t> src(pbData, pbData + dataLength);
ByteArrayInputStream bais(src); ByteArrayInputStream bais(src);
DataInputStream dis(&bais); DataInputStream dis(&bais);

View file

@ -393,8 +393,8 @@ bool DLCManager::readDLCDataFile(unsigned int& dwFilesProcessed,
bool fromArchive) { bool fromArchive) {
std::wstring wPath = convStringToWstring(path); std::wstring wPath = convStringToWstring(path);
if (fromArchive && app.getArchiveFileSize(wPath) >= 0) { if (fromArchive && app.getArchiveFileSize(wPath) >= 0) {
byteArray bytes = app.getArchiveFile(wPath); std::vector<uint8_t> bytes = app.getArchiveFile(wPath);
return processDLCDataFile(dwFilesProcessed, bytes.data, bytes.length, return processDLCDataFile(dwFilesProcessed, bytes.data(), bytes.size(),
pack); pack);
} else if (fromArchive) } else if (fromArchive)
return false; return false;

View file

@ -155,7 +155,8 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn,
unsigned int dSize) { unsigned int dSize) {
app.DebugPrintf("GameRuleManager::LoadingGameRules:\n"); app.DebugPrintf("GameRuleManager::LoadingGameRules:\n");
ByteArrayInputStream bais(byteArray(dIn, dSize)); std::vector<uint8_t> inputBuf(dIn, dIn + dSize);
ByteArrayInputStream bais(inputBuf);
DataInputStream dis(&bais); DataInputStream dis(&bais);
// Read file header. // Read file header.
@ -181,45 +182,43 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn,
// Decompress File Body // Decompress File Body
byteArray content(new std::uint8_t[decomp_len], decomp_len), std::vector<uint8_t> content(decomp_len);
compr_content(new std::uint8_t[compr_len], compr_len); std::vector<uint8_t> compr_content(compr_len);
dis.read(compr_content); dis.read(compr_content);
Compression::getCompression()->SetDecompressionType( Compression::getCompression()->SetDecompressionType(
(Compression::ECompressionTypes)compression_type); (Compression::ECompressionTypes)compression_type);
unsigned int contentSize = decomp_len;
Compression::getCompression()->DecompressLZXRLE( Compression::getCompression()->DecompressLZXRLE(
content.data, &content.length, compr_content.data, content.data(), &contentSize, compr_content.data(),
compr_content.length); compr_content.size());
content.resize(contentSize);
Compression::getCompression()->SetDecompressionType( Compression::getCompression()->SetDecompressionType(
SAVE_FILE_PLATFORM_LOCAL); SAVE_FILE_PLATFORM_LOCAL);
dis.close(); dis.close();
bais.close(); bais.close();
delete[] compr_content.data;
ByteArrayInputStream bais2(content); ByteArrayInputStream bais2(content);
DataInputStream dis2(&bais2); DataInputStream dis2(&bais2);
// Read StringTable. // Read StringTable.
byteArray bStringTable; unsigned int bStringTableSize = dis2.readInt();
bStringTable.length = dis2.readInt(); std::vector<uint8_t> bStringTable(bStringTableSize);
bStringTable.data = new std::uint8_t[bStringTable.length];
dis2.read(bStringTable); dis2.read(bStringTable);
StringTable* strings = StringTable* strings =
new StringTable(bStringTable.data, bStringTable.length); new StringTable(bStringTable.data(), bStringTable.size());
// Read RuleFile. // Read RuleFile.
byteArray bRuleFile; std::vector<uint8_t> bRuleFile(content.size() - bStringTable.size());
bRuleFile.length = content.length - bStringTable.length;
bRuleFile.data = new std::uint8_t[bRuleFile.length];
dis2.read(bRuleFile); dis2.read(bRuleFile);
// 4J-JEV: I don't believe that the path-name is ever used. // 4J-JEV: I don't believe that the path-name is ever used.
// DLCGameRulesFile *dlcgr = new DLCGameRulesFile(L"__PLACEHOLDER__"); // DLCGameRulesFile *dlcgr = new DLCGameRulesFile(L"__PLACEHOLDER__");
// dlcgr->addData(bRuleFile.data,bRuleFile.length); // dlcgr->addData(bRuleFile.data(),bRuleFile.size());
if (readRuleFile(lgo, bRuleFile.data, bRuleFile.length, strings)) { if (readRuleFile(lgo, bRuleFile.data(), bRuleFile.size(), strings)) {
// Set current gen options and ruleset. // Set current gen options and ruleset.
// createdLevelGenerationOptions->setFromSaveGame(true); // createdLevelGenerationOptions->setFromSaveGame(true);
lgo->setSrc(LevelGenerationOptions::eSrc_fromSave); lgo->setSrc(LevelGenerationOptions::eSrc_fromSave);
@ -229,7 +228,6 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn,
delete lgo; delete lgo;
} }
// delete [] content.data;
// Close and return. // Close and return.
dis2.close(); dis2.close();
@ -275,9 +273,9 @@ void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) {
compr_dos.writeByte( compr_dos.writeByte(
Compression::eCompressionType_None); // compression type Compression::eCompressionType_None); // compression type
for (int i = 0; i < 2; i++) compr_dos.writeByte(0x0); // Padding. for (int i = 0; i < 2; i++) compr_dos.writeByte(0x0); // Padding.
compr_dos.writeInt(0); // StringLookup.length compr_dos.writeInt(0); // StringLookup.size()
compr_dos.writeInt(0); // SchematicFiles.length compr_dos.writeInt(0); // SchematicFiles.size()
compr_dos.writeInt(0); // XmlObjects.length compr_dos.writeInt(0); // XmlObjects.size()
} else { } else {
StringTable* st = m_currentGameRuleDefinitions->getStringTable(); StringTable* st = m_currentGameRuleDefinitions->getStringTable();
@ -286,10 +284,12 @@ void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) {
"GameRuleManager::saveGameRules: StringTable == nullptr!"); "GameRuleManager::saveGameRules: StringTable == nullptr!");
} else { } else {
// Write string table. // Write string table.
byteArray stba; uint8_t* stbaPtr = nullptr;
unsigned int stbaSize = 0;
m_currentGameRuleDefinitions->getStringTable()->getData( m_currentGameRuleDefinitions->getStringTable()->getData(
&stba.data, &stba.length); &stbaPtr, &stbaSize);
compr_dos.writeInt(stba.length); std::vector<uint8_t> stba(stbaPtr, stbaPtr + stbaSize);
compr_dos.writeInt(stba.size());
compr_dos.write(stba); compr_dos.write(stba);
// Write game rule file to second // Write game rule file to second
@ -299,30 +299,29 @@ void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) {
} }
// Compress compr_dos and write to dos. // Compress compr_dos and write to dos.
byteArray compr_ba(new std::uint8_t[compr_baos.buf.length], std::vector<uint8_t> compr_ba(compr_baos.buf.size());
compr_baos.buf.length); unsigned int compr_ba_size = compr_ba.size();
Compression::getCompression()->CompressLZXRLE( Compression::getCompression()->CompressLZXRLE(
compr_ba.data, &compr_ba.length, compr_baos.buf.data, compr_ba.data(), &compr_ba_size, compr_baos.buf.data(),
compr_baos.buf.length); compr_baos.buf.size());
compr_ba.resize(compr_ba_size);
app.DebugPrintf("\tcompr_ba.length=%d.\n\tcompr_baos.buf.length=%d.\n", app.DebugPrintf("\tcompr_ba.size()=%d.\n\tcompr_baos.buf.size()=%d.\n",
compr_ba.length, compr_baos.buf.length); compr_ba.size(), compr_baos.buf.size());
dos.writeInt(compr_ba.length); // Write length dos.writeInt(compr_ba.size()); // Write length
dos.writeInt(compr_baos.buf.length); dos.writeInt(compr_baos.buf.size());
dos.write(compr_ba); dos.write(compr_ba);
delete[] compr_ba.data;
compr_dos.close(); compr_dos.close();
compr_baos.close(); compr_baos.close();
// -- END COMPRESSED -- // // -- END COMPRESSED -- //
// return // return
*dSize = baos.buf.length; *dSize = baos.buf.size();
*dOut = baos.buf.data; *dOut = new uint8_t[baos.buf.size()];
memcpy(*dOut, baos.buf.data(), baos.buf.size());
baos.buf.data = nullptr;
dos.close(); dos.close();
baos.close(); baos.close();
@ -357,9 +356,9 @@ void GameRuleManager::writeRuleFile(DataOutputStream* dos) {
file->save(&fileDos); file->save(&fileDos);
dos->writeUTF(filename); dos->writeUTF(filename);
// dos->writeInt(file->m_data.length); // dos->writeInt(file->m_data.size());
dos->writeInt(fileBaos.buf.length); dos->writeInt(fileBaos.buf.size());
dos->write((byteArray)fileBaos.buf); dos->write((std::vector<uint8_t>)fileBaos.buf);
fileDos.close(); fileDos.close();
fileBaos.close(); fileBaos.close();
@ -383,9 +382,9 @@ bool GameRuleManager::readRuleFile(
// std::uint32_t dataLength = 0; // std::uint32_t dataLength = 0;
// std::uint8_t *data = dlcFile->getData(dataLength); // std::uint8_t *data = dlcFile->getData(dataLength);
// byteArray data(pbData,dwLen); // std::vector<uint8_t> data(pbData,dwLen);
byteArray data(dIn, dSize); std::vector<uint8_t> data(dIn, dIn + dSize);
ByteArrayInputStream bais(data); ByteArrayInputStream bais(data);
DataInputStream dis(&bais); DataInputStream dis(&bais);
@ -414,22 +413,24 @@ bool GameRuleManager::readRuleFile(
} else { } else {
unsigned int uncompressedSize = dis.readInt(); unsigned int uncompressedSize = dis.readInt();
unsigned int compressedSize = dis.readInt(); unsigned int compressedSize = dis.readInt();
byteArray compressedBuffer(compressedSize); std::vector<uint8_t> compressedBuffer(compressedSize);
dis.read(compressedBuffer); dis.read(compressedBuffer);
byteArray decompressedBuffer = byteArray(uncompressedSize); std::vector<uint8_t> decompressedBuffer = std::vector<uint8_t>(uncompressedSize);
unsigned int decompressedSize = uncompressedSize;
switch (compressionType) { switch (compressionType) {
case Compression::eCompressionType_None: case Compression::eCompressionType_None:
memcpy(decompressedBuffer.data, compressedBuffer.data, memcpy(decompressedBuffer.data(), compressedBuffer.data(),
uncompressedSize); uncompressedSize);
break; break;
case Compression::eCompressionType_RLE: case Compression::eCompressionType_RLE:
app.DebugPrintf("De-compressing game rules with: RLE\n"); app.DebugPrintf("De-compressing game rules with: RLE\n");
Compression::getCompression()->Decompress( Compression::getCompression()->Decompress(
decompressedBuffer.data, &decompressedBuffer.length, decompressedBuffer.data(), &decompressedSize,
compressedBuffer.data, compressedSize); compressedBuffer.data(), compressedSize);
decompressedBuffer.resize(decompressedSize);
break; break;
default: default:
@ -441,8 +442,9 @@ bool GameRuleManager::readRuleFile(
// compression type. (need to assert that the data is compressed // compression type. (need to assert that the data is compressed
// with it though). // with it though).
Compression::getCompression()->DecompressLZXRLE( Compression::getCompression()->DecompressLZXRLE(
decompressedBuffer.data, &decompressedBuffer.length, decompressedBuffer.data(), &decompressedSize,
compressedBuffer.data, compressedSize); compressedBuffer.data(), compressedSize);
decompressedBuffer.resize(decompressedSize);
break; break;
/* 4J-JEV: /* 4J-JEV:
Each platform has only 1 method of compression, Each platform has only 1 method of compression,
@ -452,21 +454,19 @@ bool GameRuleManager::readRuleFile(
app.DebugPrintf("De-compressing game app.DebugPrintf("De-compressing game
rules with: LZX+RLE\n"); rules with: LZX+RLE\n");
Compression::getCompression()->DecompressLZXRLE( Compression::getCompression()->DecompressLZXRLE(
decompressedBuffer.data, &uncompressedSize, decompressedBuffer.data(), &uncompressedSize,
compressedBuffer.data, compressedSize); break; default: compressedBuffer.data(), compressedSize); break; default:
app.DebugPrintf("Invalid compression app.DebugPrintf("Invalid compression
type %d found\n", compressionType); type %d found\n", compressionType);
__debugbreak(); __debugbreak();
delete [] compressedBuffer.data; delete [] decompressedBuffer.data(); dis.close(); bais.reset();
[] decompressedBuffer.data; dis.close(); bais.reset();
if(!gameRulesAdded) delete gameRules; if(!gameRulesAdded) delete gameRules;
return false; return false;
*/ */
}; };
delete[] compressedBuffer.data;
contentBais = new ByteArrayInputStream(decompressedBuffer); contentBais = new ByteArrayInputStream(decompressedBuffer);
contentDis = new DataInputStream(contentBais); contentDis = new DataInputStream(contentBais);
@ -513,11 +513,11 @@ bool GameRuleManager::readRuleFile(
for (unsigned int i = 0; i < numFiles; i++) { for (unsigned int i = 0; i < numFiles; i++) {
std::wstring sFilename = contentDis->readUTF(); std::wstring sFilename = contentDis->readUTF();
int length = contentDis->readInt(); int length = contentDis->readInt();
byteArray ba(length); std::vector<uint8_t> ba(length);
contentDis->read(ba); contentDis->read(ba);
levelGenerator->loadSchematicFile(sFilename, ba.data, ba.length); levelGenerator->loadSchematicFile(sFilename, ba.data(), ba.size());
} }
LEVEL_GEN_ID lgoID = LEVEL_GEN_ID_NULL; LEVEL_GEN_ID lgoID = LEVEL_GEN_ID_NULL;

View file

@ -15,12 +15,11 @@
ConsoleSchematicFile::ConsoleSchematicFile() { ConsoleSchematicFile::ConsoleSchematicFile() {
m_xSize = m_ySize = m_zSize = 0; m_xSize = m_ySize = m_zSize = 0;
m_refCount = 1; m_refCount = 1;
m_data.data = nullptr; m_data.clear();
} }
ConsoleSchematicFile::~ConsoleSchematicFile() { ConsoleSchematicFile::~ConsoleSchematicFile() {
app.DebugPrintf("Deleting schematic file\n"); app.DebugPrintf("Deleting schematic file\n");
if (m_data.data != nullptr) delete[] m_data.data;
} }
void ConsoleSchematicFile::save(DataOutputStream* dos) { void ConsoleSchematicFile::save(DataOutputStream* dos) {
@ -33,16 +32,17 @@ void ConsoleSchematicFile::save(DataOutputStream* dos) {
dos->writeInt(m_ySize); dos->writeInt(m_ySize);
dos->writeInt(m_zSize); dos->writeInt(m_zSize);
byteArray ba(new std::uint8_t[m_data.length], m_data.length); std::vector<uint8_t> ba(m_data.size());
unsigned int baSize = ba.size();
Compression::getCompression()->CompressLZXRLE( Compression::getCompression()->CompressLZXRLE(
ba.data, &ba.length, m_data.data, m_data.length); ba.data(), &baSize, m_data.data(), m_data.size());
ba.resize(baSize);
dos->writeInt(ba.length); dos->writeInt(ba.size());
dos->write(ba); dos->write(ba);
save_tags(dos); save_tags(dos);
delete[] ba.data;
} }
} }
@ -67,30 +67,30 @@ void ConsoleSchematicFile::load(DataInputStream* dis) {
m_zSize = dis->readInt(); m_zSize = dis->readInt();
int compressedSize = dis->readInt(); int compressedSize = dis->readInt();
byteArray compressedBuffer(compressedSize); std::vector<uint8_t> compressedBuffer(compressedSize);
dis->readFully(compressedBuffer); dis->readFully(compressedBuffer);
if (m_data.data != nullptr) { m_data.clear();
delete[] m_data.data;
m_data.data = nullptr;
}
if (compressionType == Compression::eCompressionType_None) { if (compressionType == Compression::eCompressionType_None) {
m_data = compressedBuffer; m_data = compressedBuffer;
} else { } else {
unsigned int outputSize = m_xSize * m_ySize * m_zSize * 3 / 2; unsigned int outputSize = m_xSize * m_ySize * m_zSize * 3 / 2;
m_data = byteArray(outputSize); m_data = std::vector<uint8_t>(outputSize);
unsigned int m_dataSize = outputSize;
switch (compressionType) { switch (compressionType) {
case Compression::eCompressionType_RLE: case Compression::eCompressionType_RLE:
Compression::getCompression()->DecompressRLE( Compression::getCompression()->DecompressRLE(
m_data.data, &m_data.length, compressedBuffer.data, m_data.data(), &m_dataSize, compressedBuffer.data(),
compressedSize); compressedSize);
m_data.resize(m_dataSize);
break; break;
case APPROPRIATE_COMPRESSION_TYPE: case APPROPRIATE_COMPRESSION_TYPE:
Compression::getCompression()->DecompressLZXRLE( Compression::getCompression()->DecompressLZXRLE(
m_data.data, &m_data.length, compressedBuffer.data, m_data.data(), &m_dataSize, compressedBuffer.data(),
compressedSize); compressedSize);
m_data.resize(m_dataSize);
break; break;
default: default:
app.DebugPrintf( app.DebugPrintf(
@ -100,13 +100,13 @@ void ConsoleSchematicFile::load(DataInputStream* dis) {
Compression::getCompression()->SetDecompressionType( Compression::getCompression()->SetDecompressionType(
(Compression::ECompressionTypes)compressionType); (Compression::ECompressionTypes)compressionType);
Compression::getCompression()->DecompressLZXRLE( Compression::getCompression()->DecompressLZXRLE(
m_data.data, &m_data.length, compressedBuffer.data, m_data.data(), &m_dataSize, compressedBuffer.data(),
compressedSize); compressedSize);
m_data.resize(m_dataSize);
Compression::getCompression()->SetDecompressionType( Compression::getCompression()->SetDecompressionType(
APPROPRIATE_COMPRESSION_TYPE); APPROPRIATE_COMPRESSION_TYPE);
}; };
delete[] compressedBuffer.data;
} }
// READ TAGS // // READ TAGS //
@ -212,11 +212,11 @@ int64_t ConsoleSchematicFile::applyBlocksAndData(LevelChunk* chunk,
int rowBlockCount = getYSize() * getZSize(); int rowBlockCount = getYSize() * getZSize();
int totalBlockCount = getXSize() * rowBlockCount; int totalBlockCount = getXSize() * rowBlockCount;
byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); std::vector<uint8_t> blockData = std::vector<uint8_t>(Level::CHUNK_TILE_COUNT);
PIXBeginNamedEvent(0, "Getting block data"); PIXBeginNamedEvent(0, "Getting block data");
chunk->getBlockData(blockData); chunk->getBlockData(blockData);
PIXEndNamedEvent(); PIXEndNamedEvent();
byteArray dataData = byteArray(Level::HALF_CHUNK_TILE_COUNT); std::vector<uint8_t> dataData = std::vector<uint8_t>(Level::HALF_CHUNK_TILE_COUNT);
PIXBeginNamedEvent(0, "Getting Data data"); PIXBeginNamedEvent(0, "Getting Data data");
chunk->getDataData(dataData); chunk->getDataData(dataData);
PIXEndNamedEvent(); PIXEndNamedEvent();
@ -283,7 +283,7 @@ int64_t ConsoleSchematicFile::applyBlocksAndData(LevelChunk* chunk,
} }
// 4J Stu - Hack for ME pack to replace sand with end stone in schematics // 4J Stu - Hack for ME pack to replace sand with end stone in schematics
// for(int i = 0; i < blockData.length; ++i) // for(int i = 0; i < blockData.size(); ++i)
//{ //{
// if(blockData[i] == Tile::sand_Id || blockData[i] == Tile::sandStone_Id) // if(blockData[i] == Tile::sand_Id || blockData[i] == Tile::sandStone_Id)
// { // {
@ -294,12 +294,10 @@ int64_t ConsoleSchematicFile::applyBlocksAndData(LevelChunk* chunk,
PIXBeginNamedEvent(0, "Setting Block data"); PIXBeginNamedEvent(0, "Setting Block data");
chunk->setBlockData(blockData); chunk->setBlockData(blockData);
PIXEndNamedEvent(); PIXEndNamedEvent();
delete[] blockData.data; // 4jcraft changed to array delete
chunk->recalcHeightmapOnly(); chunk->recalcHeightmapOnly();
PIXBeginNamedEvent(0, "Setting Data data"); PIXBeginNamedEvent(0, "Setting Data data");
chunk->setDataData(dataData); chunk->setDataData(dataData);
PIXEndNamedEvent(); PIXEndNamedEvent();
delete[] dataData.data; // 4jcraft, same here
// A basic pass through to roughly do the lighting. At this point of // A basic pass through to roughly do the lighting. At this point of
// post-processing, we don't have all the neighbouring chunks loaded in, so // post-processing, we don't have all the neighbouring chunks loaded in, so
@ -627,11 +625,11 @@ void ConsoleSchematicFile::generateSchematicFile(
// Write zSize // Write zSize
if (dos != nullptr) dos->writeInt(zSize); if (dos != nullptr) dos->writeInt(zSize);
// byteArray rawBuffer = level->getBlocksAndData(xStart, yStart, zStart, // std::vector<uint8_t> rawBuffer = level->getBlocksAndData(xStart, yStart, zStart,
// xSize, ySize, zSize, false); // xSize, ySize, zSize, false);
int xRowSize = ySize * zSize; int xRowSize = ySize * zSize;
int blockCount = xSize * xRowSize; int blockCount = xSize * xRowSize;
byteArray result(blockCount * 3 / 2); std::vector<uint8_t> result(blockCount * 3 / 2);
// Position pointers into the data when not ordered by chunk // Position pointers into the data when not ordered by chunk
int p = 0; int p = 0;
@ -679,24 +677,23 @@ void ConsoleSchematicFile::generateSchematicFile(
switch (compressionType) { switch (compressionType) {
case Compression::eCompressionType_LZXRLE: case Compression::eCompressionType_LZXRLE:
Compression::getCompression()->CompressLZXRLE( Compression::getCompression()->CompressLZXRLE(
ucTemp, &inputSize, result.data, (unsigned int)result.length); ucTemp, &inputSize, result.data(), (unsigned int)result.size());
break; break;
case Compression::eCompressionType_RLE: case Compression::eCompressionType_RLE:
Compression::getCompression()->CompressRLE( Compression::getCompression()->CompressRLE(
ucTemp, &inputSize, result.data, (unsigned int)result.length); ucTemp, &inputSize, result.data(), (unsigned int)result.size());
break; break;
case Compression::eCompressionType_None: case Compression::eCompressionType_None:
default: default:
memcpy(ucTemp, result.data, inputSize); memcpy(ucTemp, result.data(), inputSize);
break; break;
}; };
delete[] result.data; std::vector<uint8_t> buffer = std::vector<uint8_t>(ucTemp, ucTemp + inputSize);
byteArray buffer = byteArray(ucTemp, inputSize); delete[] ucTemp;
if (dos != nullptr) dos->writeInt(inputSize); if (dos != nullptr) dos->writeInt(inputSize);
if (dos != nullptr) dos->write(buffer); if (dos != nullptr) dos->write(buffer);
delete[] buffer.data;
CompoundTag tag; CompoundTag tag;
ListTag<CompoundTag>* tileEntitiesTag = ListTag<CompoundTag>* tileEntitiesTag =
@ -785,7 +782,7 @@ void ConsoleSchematicFile::generateSchematicFile(
if (dos != nullptr) NbtIo::write(&tag, dos); if (dos != nullptr) NbtIo::write(&tag, dos);
} }
void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, std::vector<uint8_t>* data,
int x0, int y0, int z0, int x1, int x0, int y0, int z0, int x1,
int y1, int z1, int& blocksP, int y1, int z1, int& blocksP,
int& dataP, int& blockLightP, int& dataP, int& blockLightP,
@ -797,21 +794,21 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
// int zs = z1 - z0; // int zs = z1 - z0;
// if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH) // if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH)
//{ //{
// byteArray blockData = byteArray(data->data + blocksP, // std::vector<uint8_t> blockData = std::vector<uint8_t>(data->data + blocksP,
// Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData); // Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData);
// blocksP += blockData.length; // blocksP += blockData.size();
// byteArray dataData = byteArray(data->data + dataP, 16384); // std::vector<uint8_t> dataData = std::vector<uint8_t>(data->data + dataP, 16384);
// chunk->getBlockLightData(dataData); // chunk->getBlockLightData(dataData);
// dataP += dataData.length; // dataP += dataData.size();
// byteArray blockLightData = byteArray(data->data + blockLightP, 16384); // std::vector<uint8_t> blockLightData = std::vector<uint8_t>(data->data + blockLightP, 16384);
// chunk->getBlockLightData(blockLightData); // chunk->getBlockLightData(blockLightData);
// blockLightP += blockLightData.length; // blockLightP += blockLightData.size();
// byteArray skyLightData = byteArray(data->data + skyLightP, 16384); // std::vector<uint8_t> skyLightData = std::vector<uint8_t>(data->data + skyLightP, 16384);
// chunk->getSkyLightData(skyLightData); // chunk->getSkyLightData(skyLightData);
// skyLightP += skyLightData.length; // skyLightP += skyLightData.size();
// return; // return;
//} //}
@ -834,7 +831,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
bHasUpper = true; bHasUpper = true;
} }
byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); std::vector<uint8_t> blockData = std::vector<uint8_t>(Level::CHUNK_TILE_COUNT);
chunk->getBlockData(blockData); chunk->getBlockData(blockData);
for (int x = x0; x < x1; x++) for (int x = x0; x < x1; x++)
for (int z = z0; z < z1; z++) { for (int z = z0; z < z1; z++) {
@ -842,7 +839,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
int slot = x << Level::genDepthBitsPlusFour | int slot = x << Level::genDepthBitsPlusFour |
z << Level::genDepthBits | lowerY0; z << Level::genDepthBits | lowerY0;
int len = lowerY1 - lowerY0; int len = lowerY1 - lowerY0;
System::arraycopy(blockData, slot, data, blocksP, len); std::copy(blockData.data() + slot, blockData.data() + slot + len, data->data() + blocksP);
blocksP += len; blocksP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -850,13 +847,12 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
z << Level::genDepthBits | upperY0) + z << Level::genDepthBits | upperY0) +
Level::COMPRESSED_CHUNK_SECTION_TILES; Level::COMPRESSED_CHUNK_SECTION_TILES;
int len = upperY1 - upperY0; int len = upperY1 - upperY0;
System::arraycopy(blockData, slot, data, blocksP, len); std::copy(blockData.data() + slot, blockData.data() + slot + len, data->data() + blocksP);
blocksP += len; blocksP += len;
} }
} }
delete blockData.data;
byteArray dataData = byteArray(Level::CHUNK_TILE_COUNT); std::vector<uint8_t> dataData = std::vector<uint8_t>(Level::CHUNK_TILE_COUNT);
chunk->getDataData(dataData); chunk->getDataData(dataData);
for (int x = x0; x < x1; x++) for (int x = x0; x < x1; x++)
for (int z = z0; z < z1; z++) { for (int z = z0; z < z1; z++) {
@ -865,7 +861,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
z << Level::genDepthBits | lowerY0) >> z << Level::genDepthBits | lowerY0) >>
1; 1;
int len = (lowerY1 - lowerY0) / 2; int len = (lowerY1 - lowerY0) / 2;
System::arraycopy(dataData, slot, data, dataP, len); std::copy(dataData.data() + slot, dataData.data() + slot + len, data->data() + dataP);
dataP += len; dataP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -874,15 +870,14 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
Level::COMPRESSED_CHUNK_SECTION_TILES) >> Level::COMPRESSED_CHUNK_SECTION_TILES) >>
1; 1;
int len = (upperY1 - upperY0) / 2; int len = (upperY1 - upperY0) / 2;
System::arraycopy(dataData, slot, data, dataP, len); std::copy(dataData.data() + slot, dataData.data() + slot + len, data->data() + dataP);
dataP += len; dataP += len;
} }
} }
delete dataData.data;
// 4J Stu - Allow ignoring light data // 4J Stu - Allow ignoring light data
if (blockLightP > -1) { if (blockLightP > -1) {
byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); std::vector<uint8_t> blockLightData = std::vector<uint8_t>(Level::HALF_CHUNK_TILE_COUNT);
chunk->getBlockLightData(blockLightData); chunk->getBlockLightData(blockLightData);
for (int x = x0; x < x1; x++) for (int x = x0; x < x1; x++)
for (int z = z0; z < z1; z++) { for (int z = z0; z < z1; z++) {
@ -891,8 +886,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
z << Level::genDepthBits | lowerY0) >> z << Level::genDepthBits | lowerY0) >>
1; 1;
int len = (lowerY1 - lowerY0) / 2; int len = (lowerY1 - lowerY0) / 2;
System::arraycopy(blockLightData, slot, data, blockLightP, std::copy(blockLightData.data() + slot, blockLightData.data() + slot + len, data->data() + blockLightP);
len);
blockLightP += len; blockLightP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -901,17 +895,15 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
1) + 1) +
(Level::COMPRESSED_CHUNK_SECTION_TILES / 2); (Level::COMPRESSED_CHUNK_SECTION_TILES / 2);
int len = (upperY1 - upperY0) / 2; int len = (upperY1 - upperY0) / 2;
System::arraycopy(blockLightData, slot, data, blockLightP, std::copy(blockLightData.data() + slot, blockLightData.data() + slot + len, data->data() + blockLightP);
len);
blockLightP += len; blockLightP += len;
} }
} }
delete blockLightData.data;
} }
// 4J Stu - Allow ignoring light data // 4J Stu - Allow ignoring light data
if (skyLightP > -1) { if (skyLightP > -1) {
byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); std::vector<uint8_t> skyLightData = std::vector<uint8_t>(Level::HALF_CHUNK_TILE_COUNT);
chunk->getSkyLightData(skyLightData); chunk->getSkyLightData(skyLightData);
for (int x = x0; x < x1; x++) for (int x = x0; x < x1; x++)
for (int z = z0; z < z1; z++) { for (int z = z0; z < z1; z++) {
@ -920,7 +912,7 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
z << Level::genDepthBits | lowerY0) >> z << Level::genDepthBits | lowerY0) >>
1; 1;
int len = (lowerY1 - lowerY0) / 2; int len = (lowerY1 - lowerY0) / 2;
System::arraycopy(skyLightData, slot, data, skyLightP, len); std::copy(skyLightData.data() + slot, skyLightData.data() + slot + len, data->data() + skyLightP);
skyLightP += len; skyLightP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -929,19 +921,18 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
1) + 1) +
(Level::COMPRESSED_CHUNK_SECTION_TILES / 2); (Level::COMPRESSED_CHUNK_SECTION_TILES / 2);
int len = (upperY1 - upperY0) / 2; int len = (upperY1 - upperY0) / 2;
System::arraycopy(skyLightData, slot, data, skyLightP, len); std::copy(skyLightData.data() + slot, skyLightData.data() + slot + len, data->data() + skyLightP);
skyLightP += len; skyLightP += len;
} }
} }
delete skyLightData.data;
} }
return; return;
} }
void ConsoleSchematicFile::setBlocksAndData( void ConsoleSchematicFile::setBlocksAndData(
LevelChunk* chunk, byteArray blockData, byteArray dataData, LevelChunk* chunk, std::vector<uint8_t>& blockData, std::vector<uint8_t>& dataData,
byteArray inputData, int x0, int y0, int z0, int x1, int y1, int z1, std::vector<uint8_t> inputData, int x0, int y0, int z0, int x1, int y1, int z1,
int& blocksP, int& dataP, int& blockLightP, int& skyLightP) { int& blocksP, int& dataP, int& blockLightP, int& skyLightP) {
bool bHasLower, bHasUpper; bool bHasLower, bHasUpper;
bHasLower = bHasUpper = false; bHasLower = bHasUpper = false;
@ -968,7 +959,7 @@ void ConsoleSchematicFile::setBlocksAndData(
int slot = x << Level::genDepthBitsPlusFour | int slot = x << Level::genDepthBitsPlusFour |
z << Level::genDepthBits | lowerY0; z << Level::genDepthBits | lowerY0;
int len = lowerY1 - lowerY0; int len = lowerY1 - lowerY0;
System::arraycopy(inputData, blocksP, &blockData, slot, len); std::copy(inputData.data() + blocksP, inputData.data() + blocksP + len, blockData.data() + slot);
blocksP += len; blocksP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -976,7 +967,7 @@ void ConsoleSchematicFile::setBlocksAndData(
z << Level::genDepthBits | upperY0) + z << Level::genDepthBits | upperY0) +
Level::COMPRESSED_CHUNK_SECTION_TILES; Level::COMPRESSED_CHUNK_SECTION_TILES;
int len = upperY1 - upperY0; int len = upperY1 - upperY0;
System::arraycopy(inputData, blocksP, &blockData, slot, len); std::copy(inputData.data() + blocksP, inputData.data() + blocksP + len, blockData.data() + slot);
blocksP += len; blocksP += len;
} }
} }
@ -990,7 +981,7 @@ void ConsoleSchematicFile::setBlocksAndData(
z << Level::genDepthBits | lowerY0) >> z << Level::genDepthBits | lowerY0) >>
1; 1;
int len = (lowerY1 - lowerY0) / 2; int len = (lowerY1 - lowerY0) / 2;
System::arraycopy(inputData, dataP, &dataData, slot, len); std::copy(inputData.data() + dataP, inputData.data() + dataP + len, dataData.data() + slot);
dataP += len; dataP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -999,14 +990,14 @@ void ConsoleSchematicFile::setBlocksAndData(
Level::COMPRESSED_CHUNK_SECTION_TILES) >> Level::COMPRESSED_CHUNK_SECTION_TILES) >>
1; 1;
int len = (upperY1 - upperY0) / 2; int len = (upperY1 - upperY0) / 2;
System::arraycopy(inputData, dataP, &dataData, slot, len); std::copy(inputData.data() + dataP, inputData.data() + dataP + len, dataData.data() + slot);
dataP += len; dataP += len;
} }
} }
PIXEndNamedEvent(); PIXEndNamedEvent();
// 4J Stu - Allow ignoring light data // 4J Stu - Allow ignoring light data
if (blockLightP > -1) { if (blockLightP > -1) {
byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); std::vector<uint8_t> blockLightData = std::vector<uint8_t>(Level::HALF_CHUNK_TILE_COUNT);
chunk->getBlockLightData(blockLightData); chunk->getBlockLightData(blockLightData);
for (int x = x0; x < x1; x++) for (int x = x0; x < x1; x++)
for (int z = z0; z < z1; z++) { for (int z = z0; z < z1; z++) {
@ -1015,8 +1006,7 @@ void ConsoleSchematicFile::setBlocksAndData(
z << Level::genDepthBits | lowerY0) >> z << Level::genDepthBits | lowerY0) >>
1; 1;
int len = (lowerY1 - lowerY0) / 2; int len = (lowerY1 - lowerY0) / 2;
System::arraycopy(inputData, blockLightP, &blockLightData, std::copy(inputData.data() + blockLightP, inputData.data() + blockLightP + len, blockLightData.data() + slot);
slot, len);
blockLightP += len; blockLightP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -1025,18 +1015,16 @@ void ConsoleSchematicFile::setBlocksAndData(
1) + 1) +
(Level::COMPRESSED_CHUNK_SECTION_TILES / 2); (Level::COMPRESSED_CHUNK_SECTION_TILES / 2);
int len = (upperY1 - upperY0) / 2; int len = (upperY1 - upperY0) / 2;
System::arraycopy(inputData, blockLightP, &blockLightData, std::copy(inputData.data() + blockLightP, inputData.data() + blockLightP + len, blockLightData.data() + slot);
slot, len);
blockLightP += len; blockLightP += len;
} }
} }
chunk->setBlockLightData(blockLightData); chunk->setBlockLightData(blockLightData);
delete blockLightData.data;
} }
// 4J Stu - Allow ignoring light data // 4J Stu - Allow ignoring light data
if (skyLightP > -1) { if (skyLightP > -1) {
byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); std::vector<uint8_t> skyLightData = std::vector<uint8_t>(Level::HALF_CHUNK_TILE_COUNT);
chunk->getSkyLightData(skyLightData); chunk->getSkyLightData(skyLightData);
for (int x = x0; x < x1; x++) for (int x = x0; x < x1; x++)
for (int z = z0; z < z1; z++) { for (int z = z0; z < z1; z++) {
@ -1045,8 +1033,7 @@ void ConsoleSchematicFile::setBlocksAndData(
z << Level::genDepthBits | lowerY0) >> z << Level::genDepthBits | lowerY0) >>
1; 1;
int len = (lowerY1 - lowerY0) / 2; int len = (lowerY1 - lowerY0) / 2;
System::arraycopy(inputData, skyLightP, &skyLightData, slot, std::copy(inputData.data() + skyLightP, inputData.data() + skyLightP + len, skyLightData.data() + slot);
len);
skyLightP += len; skyLightP += len;
} }
if (bHasUpper) { if (bHasUpper) {
@ -1054,13 +1041,11 @@ void ConsoleSchematicFile::setBlocksAndData(
z << Level::genDepthBits | upperY0) + z << Level::genDepthBits | upperY0) +
(Level::COMPRESSED_CHUNK_SECTION_TILES / 2); (Level::COMPRESSED_CHUNK_SECTION_TILES / 2);
int len = (upperY1 - upperY0) / 2; int len = (upperY1 - upperY0) / 2;
System::arraycopy(inputData, skyLightP, &skyLightData, slot, std::copy(inputData.data() + skyLightP, inputData.data() + skyLightP + len, skyLightData.data() + slot);
len);
skyLightP += len; skyLightP += len;
} }
} }
chunk->setSkyLightData(skyLightData); chunk->setSkyLightData(skyLightData);
delete skyLightData.data;
} }
} }

View file

@ -57,7 +57,7 @@ private:
std::vector<std::pair<Vec3, CompoundTag*> > m_entities; std::vector<std::pair<Vec3, CompoundTag*> > m_entities;
public: public:
byteArray m_data; std::vector<uint8_t> m_data;
public: public:
ConsoleSchematicFile(); ConsoleSchematicFile();
@ -82,8 +82,8 @@ public:
int xEnd, int yEnd, int zEnd, int xEnd, int yEnd, int zEnd,
bool bSaveMobs, bool bSaveMobs,
Compression::ECompressionTypes); Compression::ECompressionTypes);
static void setBlocksAndData(LevelChunk* chunk, byteArray blockData, static void setBlocksAndData(LevelChunk* chunk, std::vector<uint8_t>& blockData,
byteArray dataData, byteArray data, int x0, std::vector<uint8_t>& dataData, std::vector<uint8_t> data, int x0,
int y0, int z0, int x1, int y1, int z1, int y0, int z0, int x1, int y1, int z1,
int& blocksP, int& dataP, int& blockLightP, int& blocksP, int& dataP, int& blockLightP,
int& skyLightP); int& skyLightP);
@ -92,7 +92,7 @@ private:
void save_tags(DataOutputStream* dos); void save_tags(DataOutputStream* dos);
void load_tags(DataInputStream* dis); void load_tags(DataInputStream* dis);
static void getBlocksAndData(LevelChunk* chunk, byteArray* data, int x0, static void getBlocksAndData(LevelChunk* chunk, std::vector<uint8_t>* data, int x0,
int y0, int z0, int x1, int y1, int z1, int y0, int z0, int x1, int y1, int z1,
int& blocksP, int& dataP, int& blockLightP, int& blocksP, int& dataP, int& blockLightP,
int& skyLightP); int& skyLightP);

View file

@ -360,7 +360,7 @@ ConsoleSchematicFile* LevelGenerationOptions::loadSchematicFile(
} }
ConsoleSchematicFile* schematic = nullptr; ConsoleSchematicFile* schematic = nullptr;
byteArray data(pbData, dataLength); std::vector<uint8_t> data(pbData, pbData + dataLength);
ByteArrayInputStream bais(data); ByteArrayInputStream bais(data);
DataInputStream dis(&bais); DataInputStream dis(&bais);
schematic = new ConsoleSchematicFile(); schematic = new ConsoleSchematicFile();

View file

@ -973,7 +973,7 @@ void SonyLeaderboardManager::initReadScoreStruct(ReadScore& out,
// Convert to std::wstring and copy name. // Convert to std::wstring and copy name.
std::wstring wstrName = std::wstring wstrName =
convStringToWstring(std::string(rankData.npId.handle.data)).c_str(); convStringToWstring(std::string(rankData.npId.handle.data())).c_str();
// memcpy(&out.m_name, wstrName.c_str(), XUSER_NAME_SIZE); // memcpy(&out.m_name, wstrName.c_str(), XUSER_NAME_SIZE);
out.m_name = wstrName; out.m_name = wstrName;
} }

View file

@ -6,7 +6,7 @@ StringTable::StringTable(void) {}
// Load string table from a binary blob, filling out with the current // Load string table from a binary blob, filling out with the current
// localisation data only // localisation data only
StringTable::StringTable(std::uint8_t* pbData, unsigned int dataSize) { StringTable::StringTable(std::uint8_t* pbData, unsigned int dataSize) {
src = byteArray(pbData, dataSize); src = std::vector<uint8_t>(pbData, pbData + dataSize);
ProcessStringTableData(); ProcessStringTableData();
} }
@ -67,7 +67,7 @@ void StringTable::ProcessStringTableData(void) {
if (foundLang) { if (foundLang) {
dis.skip(bytesToSkip); dis.skip(bytesToSkip);
byteArray langData(dataSize); std::vector<uint8_t> langData(dataSize);
dis.read(langData); dis.read(langData);
dis.close(); dis.close();
@ -119,12 +119,12 @@ void StringTable::ProcessStringTableData(void) {
} }
StringTable::~StringTable(void) { StringTable::~StringTable(void) {
// delete src.data; TODO 4J-JEV: ? // delete src.data(); TODO 4J-JEV: ?
} }
void StringTable::getData(std::uint8_t** ppData, unsigned int* pSize) { void StringTable::getData(std::uint8_t** ppData, unsigned int* pSize) {
*ppData = src.data; *ppData = src.data();
*pSize = src.length; *pSize = src.size();
} }
const wchar_t* StringTable::getString(const std::wstring& id) { const wchar_t* StringTable::getString(const std::wstring& id) {

View file

@ -11,7 +11,7 @@ private:
std::unordered_map<std::wstring, std::wstring> m_stringsMap; std::unordered_map<std::wstring, std::wstring> m_stringsMap;
std::vector<std::wstring> m_stringsVec; std::vector<std::wstring> m_stringsVec;
byteArray src; std::vector<uint8_t> src;
public: public:
// enum eLocale // enum eLocale

View file

@ -265,13 +265,13 @@ int Socket::SocketInputStreamLocal::read() {
// Try and get an input array of bytes, blocking until enough bytes are // Try and get an input array of bytes, blocking until enough bytes are
// available // available
int Socket::SocketInputStreamLocal::read(byteArray b) { int Socket::SocketInputStreamLocal::read(std::vector<uint8_t>& b) {
return read(b, 0, b.length); return read(b, 0, b.size());
} }
// Try and get an input range of bytes, blocking until enough bytes are // Try and get an input range of bytes, blocking until enough bytes are
// available // available
int Socket::SocketInputStreamLocal::read(byteArray b, unsigned int offset, int Socket::SocketInputStreamLocal::read(std::vector<uint8_t>& b, unsigned int offset,
unsigned int length) { unsigned int length) {
while (m_streamOpen) { while (m_streamOpen) {
{ {
@ -318,11 +318,11 @@ void Socket::SocketOutputStreamLocal::write(unsigned int b) {
} }
} }
void Socket::SocketOutputStreamLocal::write(byteArray b) { void Socket::SocketOutputStreamLocal::write(const std::vector<uint8_t>& b) {
write(b, 0, b.length); write(b, 0, b.size());
} }
void Socket::SocketOutputStreamLocal::write(byteArray b, unsigned int offset, void Socket::SocketOutputStreamLocal::write(const std::vector<uint8_t>& b, unsigned int offset,
unsigned int length) { unsigned int length) {
if (m_streamOpen != true) { if (m_streamOpen != true) {
return; return;
@ -378,13 +378,13 @@ int Socket::SocketInputStreamNetwork::read() {
// Try and get an input array of bytes, blocking until enough bytes are // Try and get an input array of bytes, blocking until enough bytes are
// available // available
int Socket::SocketInputStreamNetwork::read(byteArray b) { int Socket::SocketInputStreamNetwork::read(std::vector<uint8_t>& b) {
return read(b, 0, b.length); return read(b, 0, b.size());
} }
// Try and get an input range of bytes, blocking until enough bytes are // Try and get an input range of bytes, blocking until enough bytes are
// available // available
int Socket::SocketInputStreamNetwork::read(byteArray b, unsigned int offset, int Socket::SocketInputStreamNetwork::read(std::vector<uint8_t>& b, unsigned int offset,
unsigned int length) { unsigned int length) {
while (m_streamOpen) { while (m_streamOpen) {
{ {
@ -420,24 +420,21 @@ Socket::SocketOutputStreamNetwork::SocketOutputStreamNetwork(Socket* socket,
void Socket::SocketOutputStreamNetwork::write(unsigned int b) { void Socket::SocketOutputStreamNetwork::write(unsigned int b) {
if (m_streamOpen != true) return; if (m_streamOpen != true) return;
byteArray barray; std::uint8_t bb = (std::uint8_t)b;
std::uint8_t bb; std::vector<uint8_t> barray(1, bb);
bb = (std::uint8_t)b;
barray.data = &bb;
barray.length = 1;
write(barray, 0, 1); write(barray, 0, 1);
} }
void Socket::SocketOutputStreamNetwork::write(byteArray b) { void Socket::SocketOutputStreamNetwork::write(const std::vector<uint8_t>& b) {
write(b, 0, b.length); write(b, 0, b.size());
} }
void Socket::SocketOutputStreamNetwork::write(byteArray b, unsigned int offset, void Socket::SocketOutputStreamNetwork::write(const std::vector<uint8_t>& b, unsigned int offset,
unsigned int length) { unsigned int length) {
writeWithFlags(b, offset, length, 0); writeWithFlags(b, offset, length, 0);
} }
void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, void Socket::SocketOutputStreamNetwork::writeWithFlags(const std::vector<uint8_t>& b,
unsigned int offset, unsigned int offset,
unsigned int length, unsigned int length,
int flags) { int flags) {
@ -463,7 +460,7 @@ void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b,
} }
} else { } else {
XRNM_SEND_BUFFER buffer; XRNM_SEND_BUFFER buffer;
buffer.pbyData = &b[offset]; buffer.pbyData = const_cast<uint8_t*>(&b[offset]);
buffer.dwDataSize = length; buffer.dwDataSize = length;
INetworkPlayer* hostPlayer = g_NetworkManager.GetHostPlayer(); INetworkPlayer* hostPlayer = g_NetworkManager.GetHostPlayer();

View file

@ -27,7 +27,7 @@ public:
class SocketOutputStream : public OutputStream { class SocketOutputStream : public OutputStream {
public: public:
// The flags are those that can be used for the QNet SendData function // The flags are those that can be used for the QNet SendData function
virtual void writeWithFlags(byteArray b, unsigned int offset, virtual void writeWithFlags(const std::vector<uint8_t>& b, unsigned int offset,
unsigned int length, int flags) { unsigned int length, int flags) {
write(b, offset, length); write(b, offset, length);
} }
@ -45,8 +45,8 @@ private:
SocketInputStreamLocal(int queueIdx); SocketInputStreamLocal(int queueIdx);
virtual int read(); virtual int read();
virtual int read(byteArray b); virtual int read(std::vector<uint8_t>& b);
virtual int read(byteArray b, unsigned int offset, unsigned int length); virtual int read(std::vector<uint8_t>& b, unsigned int offset, unsigned int length);
virtual void close(); virtual void close();
virtual int64_t skip(int64_t n) { virtual int64_t skip(int64_t n) {
return n; return n;
@ -65,8 +65,8 @@ private:
SocketOutputStreamLocal(int queueIdx); SocketOutputStreamLocal(int queueIdx);
virtual void write(unsigned int b); virtual void write(unsigned int b);
virtual void write(byteArray b); virtual void write(const std::vector<uint8_t>& b);
virtual void write(byteArray b, unsigned int offset, virtual void write(const std::vector<uint8_t>& b, unsigned int offset,
unsigned int length); unsigned int length);
virtual void close(); virtual void close();
virtual void flush() {} virtual void flush() {}
@ -81,8 +81,8 @@ private:
SocketInputStreamNetwork(Socket* socket, int queueIdx); SocketInputStreamNetwork(Socket* socket, int queueIdx);
virtual int read(); virtual int read();
virtual int read(byteArray b); virtual int read(std::vector<uint8_t>& b);
virtual int read(byteArray b, unsigned int offset, unsigned int length); virtual int read(std::vector<uint8_t>& b, unsigned int offset, unsigned int length);
virtual void close(); virtual void close();
virtual int64_t skip(int64_t n) { virtual int64_t skip(int64_t n) {
return n; return n;
@ -98,10 +98,10 @@ private:
SocketOutputStreamNetwork(Socket* socket, int queueIdx); SocketOutputStreamNetwork(Socket* socket, int queueIdx);
virtual void write(unsigned int b); virtual void write(unsigned int b);
virtual void write(byteArray b); virtual void write(const std::vector<uint8_t>& b);
virtual void write(byteArray b, unsigned int offset, virtual void write(const std::vector<uint8_t>& b, unsigned int offset,
unsigned int length); unsigned int length);
virtual void writeWithFlags(byteArray b, unsigned int offset, virtual void writeWithFlags(const std::vector<uint8_t>& b, unsigned int offset,
unsigned int length, int flags); unsigned int length, int flags);
virtual void close(); virtual void close();
virtual void flush() {} virtual void flush() {}

View file

@ -45,13 +45,13 @@ ArchiveFile::ArchiveFile(File file) {
FileInputStream fis(file); FileInputStream fis(file);
#if defined(_WINDOWS64) #if defined(_WINDOWS64)
byteArray readArray(file.length()); std::vector<uint8_t> readArray(file.length());
fis.read(readArray, 0, file.length()); fis.read(readArray, 0, file.length());
ByteArrayInputStream bais(readArray); ByteArrayInputStream bais(readArray);
DataInputStream dis(&bais); DataInputStream dis(&bais);
m_cachedData = readArray.data; m_cachedData = readArray.data();
#else #else
DataInputStream dis(&fis); DataInputStream dis(&fis);
#endif #endif
@ -86,8 +86,8 @@ int ArchiveFile::getFileSize(const std::wstring& filename) {
return hasFile(filename) ? m_index.at(filename)->filesize : -1; return hasFile(filename) ? m_index.at(filename)->filesize : -1;
} }
byteArray ArchiveFile::getFile(const std::wstring& filename) { std::vector<uint8_t> ArchiveFile::getFile(const std::wstring& filename) {
byteArray out; std::vector<uint8_t> out;
auto it = m_index.find(filename); auto it = m_index.find(filename);
if (it == m_index.end()) { if (it == m_index.end()) {
@ -102,17 +102,17 @@ byteArray ArchiveFile::getFile(const std::wstring& filename) {
PMetaData data = it->second; PMetaData data = it->second;
#if defined(_WINDOWS64) #if defined(_WINDOWS64)
out = byteArray(data->filesize); out = std::vector<uint8_t>(data->filesize);
memcpy(out.data, m_cachedData + data->ptr, data->filesize); memcpy(out.data(), m_cachedData + data->ptr, data->filesize);
#else #else
const unsigned int fileSize = static_cast<unsigned int>(data->filesize); const unsigned int fileSize = static_cast<unsigned int>(data->filesize);
std::uint8_t* pbData = new std::uint8_t[fileSize == 0 ? 1 : fileSize]; std::uint8_t* pbData = new std::uint8_t[fileSize == 0 ? 1 : fileSize];
out = byteArray(pbData, fileSize); out = std::vector<uint8_t>(pbData, pbData + fileSize);
const PortableFileIO::BinaryReadResult readResult = const PortableFileIO::BinaryReadResult readResult =
PortableFileIO::ReadBinaryFileSegment( PortableFileIO::ReadBinaryFileSegment(
m_sourcefile.getPath(), static_cast<std::size_t>(data->ptr), m_sourcefile.getPath(), static_cast<std::size_t>(data->ptr),
out.data, static_cast<std::size_t>(data->filesize)); out.data(), static_cast<std::size_t>(data->filesize));
if (readResult.status != PortableFileIO::BinaryReadStatus::ok) { if (readResult.status != PortableFileIO::BinaryReadStatus::ok) {
app.DebugPrintf("Failed to read archive file segment\n"); app.DebugPrintf("Failed to read archive file segment\n");
@ -121,7 +121,7 @@ byteArray ArchiveFile::getFile(const std::wstring& filename) {
#endif #endif
// Compressed filenames are preceeded with an asterisk. // Compressed filenames are preceeded with an asterisk.
if (data->isCompressed && out.data != nullptr) { if (data->isCompressed && !out.empty()) {
/* 4J-JEV: /* 4J-JEV:
* If a compressed file is accessed before compression object is * If a compressed file is accessed before compression object is
* initialized it will crash here (Compression::getCompression). * initialized it will crash here (Compression::getCompression).
@ -136,16 +136,15 @@ byteArray ArchiveFile::getFile(const std::wstring& filename) {
std::uint8_t* uncompressedBuffer = std::uint8_t* uncompressedBuffer =
new std::uint8_t[decompressedSize]; new std::uint8_t[decompressedSize];
Compression::getCompression()->Decompress( Compression::getCompression()->Decompress(
uncompressedBuffer, &decompressedSize, out.data + 4, uncompressedBuffer, &decompressedSize, out.data() + 4,
out.length - 4); out.size() - 4);
delete[] out.data;
out.data = uncompressedBuffer; out = std::vector<uint8_t>(uncompressedBuffer, uncompressedBuffer + decompressedSize);
out.length = decompressedSize; delete[] uncompressedBuffer;
} }
assert(out.data != nullptr); // THERE IS NO FILE WITH THIS NAME! assert(!out.empty()); // THERE IS NO FILE WITH THIS NAME!
} }
return out; return out;

View file

@ -31,5 +31,5 @@ public:
std::vector<std::wstring>* getFileList(); std::vector<std::wstring>* getFileList();
bool hasFile(const std::wstring& filename); bool hasFile(const std::wstring& filename);
int getFileSize(const std::wstring& filename); int getFileSize(const std::wstring& filename);
byteArray getFile(const std::wstring& filename); std::vector<uint8_t> getFile(const std::wstring& filename);
}; };

View file

@ -198,7 +198,7 @@ void IUIScene_AnvilMenu::updateItemName() {
m_repairMenu->setItemName(m_itemName); m_repairMenu->setItemName(m_itemName);
// Convert to byteArray // Convert to std::vector<uint8_t>
ByteArrayOutputStream baos; ByteArrayOutputStream baos;
DataOutputStream dos(&baos); DataOutputStream dos(&baos);
dos.writeUTF(m_itemName); dos.writeUTF(m_itemName);

View file

@ -267,7 +267,7 @@ void IUIScene_BeaconMenu::handleTick() {
m_initPowerButtons = false; m_initPowerButtons = false;
for (int tier = 0; tier <= 2; tier++) { for (int tier = 0; tier <= 2; tier++) {
int count = BeaconTileEntity:: int count = BeaconTileEntity::
BEACON_EFFECTS_EFFECTS; // BEACON_EFFECTS[tier].length; BEACON_EFFECTS_EFFECTS; // BEACON_EFFECTS[tier].size();
int totalWidth = count * 22 + (count - 1) * 2; int totalWidth = count * 22 + (count - 1) * 2;
for (int c = 0; c < count; c++) { for (int c = 0; c < count; c++) {
@ -295,7 +295,7 @@ void IUIScene_BeaconMenu::handleTick() {
int tier = 3; int tier = 3;
int count = BeaconTileEntity::BEACON_EFFECTS_EFFECTS + int count = BeaconTileEntity::BEACON_EFFECTS_EFFECTS +
1; // BEACON_EFFECTS[tier].length + 1; 1; // BEACON_EFFECTS[tier].size() + 1;
int totalWidth = count * 22 + (count - 1) * 2; int totalWidth = count * 22 + (count - 1) * 2;
for (int c = 0; c < count - 1; c++) { for (int c = 0; c < count - 1; c++) {

View file

@ -614,7 +614,7 @@ void IUIScene_CraftingMenu::CheckRecipesAvailable() {
if (m_pPlayer && m_pPlayer->inventory) { if (m_pPlayer && m_pPlayer->inventory) {
// dump out the inventory // dump out the inventory
/* for (unsigned int k = 0; k < /* for (unsigned int k = 0; k <
m_pPlayer->inventory->items.length; k++) m_pPlayer->inventory->items.size(); k++)
{ {
if (m_pPlayer->inventory->items[k] != nullptr) if (m_pPlayer->inventory->items[k] != nullptr)
{ {
@ -696,7 +696,7 @@ void IUIScene_CraftingMenu::CheckRecipesAvailable() {
int iTotalCount = 0; int iTotalCount = 0;
// Does the player have this ingredient? // Does the player have this ingredient?
for (unsigned int k = 0; k < m_pPlayer->inventory->items.length; for (unsigned int k = 0; k < m_pPlayer->inventory->items.size();
k++) { k++) {
if (m_pPlayer->inventory->items[k] != nullptr) { if (m_pPlayer->inventory->items[k] != nullptr) {
// do they have the ingredient, and the aux value // do they have the ingredient, and the aux value
@ -723,7 +723,7 @@ void IUIScene_CraftingMenu::CheckRecipesAvailable() {
// inventory // inventory
for (unsigned int l = 0; for (unsigned int l = 0;
l < m_pPlayer->inventory->items.length; l < m_pPlayer->inventory->items.size();
l++) { l++) {
if (m_pPlayer->inventory->items[l] != if (m_pPlayer->inventory->items[l] !=
nullptr) { nullptr) {

View file

@ -505,7 +505,7 @@ void IUIScene_CreativeMenu::staticCtor() {
ITEM(Item::horseArmorGold_Id) ITEM(Item::horseArmorGold_Id)
ITEM(Item::horseArmorMetal_Id) ITEM(Item::horseArmorMetal_Id)
for (unsigned int i = 0; i < Enchantment::enchantments.length; ++i) { for (unsigned int i = 0; i < Enchantment::enchantments.size(); ++i) {
Enchantment* enchantment = Enchantment::enchantments[i]; Enchantment* enchantment = Enchantment::enchantments[i];
if (enchantment == nullptr || enchantment->category == nullptr) if (enchantment == nullptr || enchantment->category == nullptr)
continue; continue;
@ -1450,12 +1450,12 @@ void IUIScene_CreativeMenu::BuildFirework(
// diamonds give trails // diamonds give trails
if (trail) expTag->putBoolean(FireworksItem::TAG_E_TRAIL, true); if (trail) expTag->putBoolean(FireworksItem::TAG_E_TRAIL, true);
intArray colorArray(colors.size()); std::vector<int> colorArray(colors.size());
for (int i = 0; i < colorArray.length; i++) { for (int i = 0; i < colorArray.size(); i++) {
colorArray[i] = colors.at(i); colorArray[i] = colors.at(i);
} }
expTag->putIntArray(FireworksItem::TAG_E_COLORS, colorArray); expTag->putIntArray(FireworksItem::TAG_E_COLORS, colorArray);
// delete colorArray.data; // delete colorArray.data();
expTag->putByte(FireworksItem::TAG_E_TYPE, type); expTag->putByte(FireworksItem::TAG_E_TYPE, type);
@ -1467,8 +1467,8 @@ void IUIScene_CreativeMenu::BuildFirework(
std::vector<int> colors; std::vector<int> colors;
colors.push_back(DyePowderItem::COLOR_RGB[fadeColor]); colors.push_back(DyePowderItem::COLOR_RGB[fadeColor]);
intArray colorArray(colors.size()); std::vector<int> colorArray(colors.size());
for (int i = 0; i < colorArray.length; i++) { for (int i = 0; i < colorArray.size(); i++) {
colorArray[i] = colors.at(i); colorArray[i] = colors.at(i);
} }
expTag->putIntArray(FireworksItem::TAG_E_FADECOLORS, colorArray); expTag->putIntArray(FireworksItem::TAG_E_FADECOLORS, colorArray);

View file

@ -47,7 +47,7 @@ UIScene_DebugOverlay::UIScene_DebugOverlay(int iPad, void* initData,
m_buttonListItems.init(eControl_Items); m_buttonListItems.init(eControl_Items);
int listId = 0; int listId = 0;
for (unsigned int i = 0; i < Item::items.length; ++i) { for (unsigned int i = 0; i < Item::items.size(); ++i) {
if (Item::items[i] != nullptr) { if (Item::items[i] != nullptr) {
m_itemIds.push_back(i); m_itemIds.push_back(i);
m_buttonListItems.addItem( m_buttonListItems.addItem(

View file

@ -1300,7 +1300,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromDisk(
int64_t fileSize = saveFile->length(); int64_t fileSize = saveFile->length();
FileInputStream fis(*saveFile); FileInputStream fis(*saveFile);
byteArray ba(fileSize); std::vector<uint8_t> ba(fileSize);
fis.read(ba); fis.read(ba);
fis.close(); fis.close();
@ -1319,7 +1319,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromDisk(
g_NetworkManager.HostGame(0, isClientSide, isPrivate, maxPlayers, 0); g_NetworkManager.HostGame(0, isClientSide, isPrivate, maxPlayers, 0);
LoadSaveDataThreadParam* saveData = LoadSaveDataThreadParam* saveData =
new LoadSaveDataThreadParam(ba.data, ba.length, saveFile->getName()); new LoadSaveDataThreadParam(ba.data(), ba.size(), saveFile->getName());
NetworkGameInitData* param = new NetworkGameInitData(); NetworkGameInitData* param = new NetworkGameInitData();
param->seed = 0; param->seed = 0;
@ -1364,7 +1364,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromCloud() {
int64_t fileSize = cloudFile.length(); int64_t fileSize = cloudFile.length();
FileInputStream fis(cloudFile); FileInputStream fis(cloudFile);
byteArray ba(fileSize); std::vector<uint8_t> ba(fileSize);
fis.read(ba); fis.read(ba);
fis.close(); fis.close();
@ -1383,7 +1383,7 @@ void UIScene_LoadOrJoinMenu::LoadSaveFromCloud() {
g_NetworkManager.HostGame(0, isClientSide, isPrivate, maxPlayers, 0); g_NetworkManager.HostGame(0, isClientSide, isPrivate, maxPlayers, 0);
LoadSaveDataThreadParam* saveData = LoadSaveDataThreadParam* saveData =
new LoadSaveDataThreadParam(ba.data, ba.length, cloudFile.getName()); new LoadSaveDataThreadParam(ba.data(), ba.size(), cloudFile.getName());
NetworkGameInitData* param = new NetworkGameInitData(); NetworkGameInitData* param = new NetworkGameInitData();
param->seed = app.getRemoteStorage()->getSaveSeed(); param->seed = app.getRemoteStorage()->getSaveSeed();
@ -1882,9 +1882,9 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) {
break; break;
case eSaveTransfer_CreatingNewSave: { case eSaveTransfer_CreatingNewSave: {
unsigned int fileSize = StorageManager.GetSaveSize(); unsigned int fileSize = StorageManager.GetSaveSize();
byteArray ba(fileSize); std::vector<uint8_t> ba(fileSize);
StorageManager.GetSaveData(ba.data, &fileSize); StorageManager.GetSaveData(ba.data(), &fileSize);
assert(ba.length == fileSize); assert(ba.size() == fileSize);
StorageManager.ResetSaveData(); StorageManager.ResetSaveData();
{ {
@ -1925,7 +1925,7 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) {
#if defined(SPLIT_SAVES) #if defined(SPLIT_SAVES)
ConsoleSaveFileOriginal oldFormatSave( ConsoleSaveFileOriginal oldFormatSave(
wSaveName, ba.data, ba.length, false, wSaveName, ba.data(), ba.size(), false,
app.getRemoteStorage()->getSavePlatform()); app.getRemoteStorage()->getSavePlatform());
pSave = new ConsoleSaveFileSplit(&oldFormatSave, false, pSave = new ConsoleSaveFileSplit(&oldFormatSave, false,
pMinecraft->progressRenderer); pMinecraft->progressRenderer);
@ -1936,13 +1936,12 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) {
pClass->m_eSaveTransferState = eSaveTransfer_Saving; pClass->m_eSaveTransferState = eSaveTransfer_Saving;
#else #else
pSave = new ConsoleSaveFileOriginal( pSave = new ConsoleSaveFileOriginal(
wSaveName, ba.data, ba.length, false, wSaveName, ba.data(), ba.size(), false,
app.getRemoteStorage()->getSavePlatform()); app.getRemoteStorage()->getSavePlatform());
pClass->m_eSaveTransferState = eSaveTransfer_Converting; pClass->m_eSaveTransferState = eSaveTransfer_Converting;
pMinecraft->progressRenderer->progressStage( pMinecraft->progressRenderer->progressStage(
IDS_SAVETRANSFER_STAGE_CONVERTING); IDS_SAVETRANSFER_STAGE_CONVERTING);
#endif #endif
delete ba.data;
} break; } break;
case eSaveTransfer_Converting: { case eSaveTransfer_Converting: {
pSave->ConvertToLocalPlatform(); // check if we need to convert pSave->ConvertToLocalPlatform(); // check if we need to convert

View file

@ -53,7 +53,7 @@ UIScene_MainMenu::UIScene_MainMenu(int iPad, void* initData,
std::wstring filename = L"splashes.txt"; std::wstring filename = L"splashes.txt";
if (app.hasArchiveFile(filename)) { if (app.hasArchiveFile(filename)) {
byteArray splashesArray = app.getArchiveFile(filename); std::vector<uint8_t> splashesArray = app.getArchiveFile(filename);
ByteArrayInputStream bais(splashesArray); ByteArrayInputStream bais(splashesArray);
InputStreamReader isr(&bais); InputStreamReader isr(&bais);
BufferedReader br(&isr); BufferedReader br(&isr);

View file

@ -451,7 +451,6 @@ void UIController::tick() {
int64_t currentTime = System::currentTimeMillis(); int64_t currentTime = System::currentTimeMillis();
for (auto it = m_cachedMovieData.begin(); it != m_cachedMovieData.end();) { for (auto it = m_cachedMovieData.begin(); it != m_cachedMovieData.end();) {
if (it->second.m_expiry < currentTime) { if (it->second.m_expiry < currentTime) {
delete[] it->second.m_ba.data;
it = m_cachedMovieData.erase(it); it = m_cachedMovieData.erase(it);
} else { } else {
++it; ++it;
@ -535,13 +534,12 @@ IggyLibrary UIController::loadSkin(const std::wstring& skinPath,
// 4J Stu - We need to load the platformskin before the normal skin, as the // 4J Stu - We need to load the platformskin before the normal skin, as the
// normal skin requires some elements from the platform skin // normal skin requires some elements from the platform skin
if (!skinPath.empty() && app.hasArchiveFile(skinPath)) { if (!skinPath.empty() && app.hasArchiveFile(skinPath)) {
byteArray baFile = app.getArchiveFile(skinPath); std::vector<uint8_t> baFile = app.getArchiveFile(skinPath);
const std::u16string convSkinName = wstring_to_u16string(skinName); const std::u16string convSkinName = wstring_to_u16string(skinName);
lib = IggyLibraryCreateFromMemoryUTF16( lib = IggyLibraryCreateFromMemoryUTF16(
convSkinName.data(), (void*)baFile.data, baFile.length, nullptr); convSkinName.data(), (void*)baFile.data(), baFile.size(), nullptr);
delete[] baFile.data;
#if defined(_DEBUG) #if defined(_DEBUG)
IggyMemoryUseInfo memoryInfo; IggyMemoryUseInfo memoryInfo;
rrbool res; rrbool res;
@ -675,12 +673,12 @@ void UIController::CleanUpSkinReload() {
m_queuedMessageBoxData.clear(); m_queuedMessageBoxData.clear();
} }
byteArray UIController::getMovieData(const std::wstring& filename) { std::vector<uint8_t> UIController::getMovieData(const std::wstring& filename) {
// Cache everything we load in the current tick // Cache everything we load in the current tick
int64_t targetTime = System::currentTimeMillis() + (1000LL * 60); int64_t targetTime = System::currentTimeMillis() + (1000LL * 60);
auto it = m_cachedMovieData.find(filename); auto it = m_cachedMovieData.find(filename);
if (it == m_cachedMovieData.end()) { if (it == m_cachedMovieData.end()) {
byteArray baFile = app.getArchiveFile(filename); std::vector<uint8_t> baFile = app.getArchiveFile(filename);
CachedMovieData cmd; CachedMovieData cmd;
cmd.m_ba = baFile; cmd.m_ba = baFile;
cmd.m_expiry = targetTime; cmd.m_expiry = targetTime;
@ -1092,9 +1090,9 @@ GDrawTexture* RADLINK UIController::TextureSubstitutionCreateCallback(
if (it != uiController->m_substitutionTextures.end()) { if (it != uiController->m_substitutionTextures.end()) {
app.DebugPrintf("Found substitution texture %ls, with %d bytes\n", app.DebugPrintf("Found substitution texture %ls, with %d bytes\n",
(wchar_t*)texture_name, it->second.length); (wchar_t*)texture_name, it->second.size());
BufferedImage image(it->second.data, it->second.length); BufferedImage image(it->second.data(), it->second.size());
if (image.getData() != nullptr) { if (image.getData() != nullptr) {
image.preMultiplyAlpha(); image.preMultiplyAlpha();
Textures* t = Minecraft::GetInstance()->textures; Textures* t = Minecraft::GetInstance()->textures;
@ -1145,7 +1143,7 @@ void UIController::registerSubstitutionTexture(const std::wstring& textureName,
// Remove it if it already exists // Remove it if it already exists
unregisterSubstitutionTexture(textureName, false); unregisterSubstitutionTexture(textureName, false);
m_substitutionTextures[textureName] = byteArray(pbData, dwLength); m_substitutionTextures[textureName] = std::vector<uint8_t>(pbData, pbData + dwLength);
} }
void UIController::unregisterSubstitutionTexture( void UIController::unregisterSubstitutionTexture(
@ -1153,7 +1151,6 @@ void UIController::unregisterSubstitutionTexture(
auto it = m_substitutionTextures.find(textureName); auto it = m_substitutionTextures.find(textureName);
if (it != m_substitutionTextures.end()) { if (it != m_substitutionTextures.end()) {
if (deleteData) delete[] it->second.data;
m_substitutionTextures.erase(it); m_substitutionTextures.erase(it);
} }
} }

View file

@ -136,10 +136,10 @@ private:
static std::uint32_t m_dwTrialTimerLimitSecs; static std::uint32_t m_dwTrialTimerLimitSecs;
std::unordered_map<std::wstring, byteArray> m_substitutionTextures; std::unordered_map<std::wstring, std::vector<uint8_t>> m_substitutionTextures;
typedef struct _CachedMovieData { typedef struct _CachedMovieData {
byteArray m_ba; std::vector<uint8_t> m_ba;
int64_t m_expiry; int64_t m_expiry;
} CachedMovieData; } CachedMovieData;
std::unordered_map<std::wstring, CachedMovieData> m_cachedMovieData; std::unordered_map<std::wstring, CachedMovieData> m_cachedMovieData;
@ -216,7 +216,7 @@ private:
static int reloadSkinThreadProc(void* lpParam); static int reloadSkinThreadProc(void* lpParam);
public: public:
byteArray getMovieData(const std::wstring& filename); std::vector<uint8_t> getMovieData(const std::wstring& filename);
// INPUT // INPUT
private: private:

View file

@ -289,9 +289,9 @@ void UIScene::loadMovie() {
} }
} }
byteArray baFile = ui.getMovieData(moviePath.c_str()); std::vector<uint8_t> baFile = ui.getMovieData(moviePath.c_str());
int64_t beforeLoad = ui.iggyAllocCount; int64_t beforeLoad = ui.iggyAllocCount;
swf = IggyPlayerCreateFromMemory(baFile.data, baFile.length, nullptr); swf = IggyPlayerCreateFromMemory(baFile.data(), baFile.size(), nullptr);
int64_t afterLoad = ui.iggyAllocCount; int64_t afterLoad = ui.iggyAllocCount;
IggyPlayerInitializeAndTickRS(swf); IggyPlayerInitializeAndTickRS(swf);
int64_t afterTick = ui.iggyAllocCount; int64_t afterTick = ui.iggyAllocCount;

View file

@ -24,7 +24,7 @@ public:
int getWidth(); int getWidth();
int getHeight(); int getHeight();
void getRGB(int startX, int startY, int w, int h, intArray out, int offset, void getRGB(int startX, int startY, int w, int h, std::vector<int>& out, int offset,
int scansize, int level = 0); // 4J Added level param int scansize, int level = 0); // 4J Added level param
int* getData(); // 4J added int* getData(); // 4J added
int* getData(int level); // 4J added int* getData(int level); // 4J added

View file

@ -92,8 +92,8 @@ BufferedImage::BufferedImage(const std::wstring& File,
} else { } else {
std::wstring archiveKey = L"res/" + fileName; std::wstring archiveKey = L"res/" + fileName;
if (app.hasArchiveFile(archiveKey)) { if (app.hasArchiveFile(archiveKey)) {
byteArray ba = app.getArchiveFile(archiveKey); std::vector<uint8_t> ba = app.getArchiveFile(archiveKey);
hr = RenderManager.LoadTextureData(ba.data, ba.length, hr = RenderManager.LoadTextureData(ba.data(), ba.size(),
&ImageInfo, &data[l]); &ImageInfo, &data[l]);
} }
} }
@ -182,7 +182,7 @@ int BufferedImage::getWidth() { return width; }
int BufferedImage::getHeight() { return height; } int BufferedImage::getHeight() { return height; }
void BufferedImage::getRGB(int startX, int startY, int w, int h, intArray out, void BufferedImage::getRGB(int startX, int startY, int w, int h, std::vector<int>& out,
int offset, int scansize, int level) { int offset, int scansize, int level) {
int ww = width >> level; int ww = width >> level;
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
@ -219,7 +219,7 @@ BufferedImage* BufferedImage::getSubimage(int x, int y, int w, int h) {
// TODO - 4J Implement // TODO - 4J Implement
BufferedImage* img = new BufferedImage(w, h, 0); BufferedImage* img = new BufferedImage(w, h, 0);
intArray arrayWrapper(img->data[0], w * h); std::vector<int> arrayWrapper(img->data[0], img->data[0] + w * h);
this->getRGB(x, y, w, h, arrayWrapper, 0, w); this->getRGB(x, y, w, h, arrayWrapper, 0, w);
int level = 1; int level = 1;
@ -230,7 +230,7 @@ BufferedImage* BufferedImage::getSubimage(int x, int y, int w, int h) {
int xx = x >> level; int xx = x >> level;
int yy = y >> level; int yy = y >> level;
img->data[level] = new int[ww * hh]; img->data[level] = new int[ww * hh];
intArray levelWrapper(img->data[level], ww * hh); std::vector<int> levelWrapper(img->data[level], img->data[level] + ww * hh);
this->getRGB(xx, yy, ww, hh, levelWrapper, 0, ww, level); this->getRGB(xx, yy, ww, hh, levelWrapper, 0, ww, level);
++level; ++level;

View file

@ -104,7 +104,7 @@ Minecraft::Minecraft(Component* mouseComponent, Canvas* parent,
timer = new Timer(SharedConstants::TICKS_PER_SECOND); timer = new Timer(SharedConstants::TICKS_PER_SECOND);
oldLevel = nullptr; // 4J Stu added oldLevel = nullptr; // 4J Stu added
level = nullptr; level = nullptr;
levels = MultiPlayerLevelArray(3); // 4J Added levels = std::vector<MultiPlayerLevel*>(3); // 4J Added
levelRenderer = nullptr; levelRenderer = nullptr;
player = nullptr; player = nullptr;
cameraTargetPlayer = nullptr; cameraTargetPlayer = nullptr;
@ -1542,7 +1542,7 @@ void Minecraft::run_middle() {
// 4J - added - now do the equivalent of level::animateTick, // 4J - added - now do the equivalent of level::animateTick,
// but taking into account the positions of all our players // but taking into account the positions of all our players
for (int l = 0; l < levels.length; l++) { for (int l = 0; l < levels.size(); l++) {
if (levels[l]) { if (levels[l]) {
levels[l]->animateTickDoWork(); levels[l]->animateTickDoWork();
} }
@ -3549,7 +3549,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) {
SparseDataStorage::tick(); // 4J added SparseDataStorage::tick(); // 4J added
} }
for (unsigned int i = 0; i < levels.length; ++i) { for (unsigned int i = 0; i < levels.size(); ++i) {
if (player->level != levels[i]) if (player->level != levels[i])
continue; // Don't tick if the current player isn't in this continue; // Don't tick if the current player isn't in this
// level // level
@ -3722,7 +3722,7 @@ void Minecraft::setLevel(MultiPlayerLevel* level, int message /*=-1*/,
// non-nullptr // non-nullptr
gameRenderer->DisableUpdateThread(); gameRenderer->DisableUpdateThread();
for (unsigned int i = 0; i < levels.length; ++i) { for (unsigned int i = 0; i < levels.size(); ++i) {
// 4J We only need to save out in multiplayer is we are setting the // 4J We only need to save out in multiplayer is we are setting the
// level to nullptr If we ever go back to making single player only then // level to nullptr If we ever go back to making single player only then
// this will not work properly! // this will not work properly!
@ -4192,9 +4192,9 @@ void Minecraft::main() {
L"Player" + _toString<int64_t>(System::currentTimeMillis() % 1000); L"Player" + _toString<int64_t>(System::currentTimeMillis() % 1000);
sessionId = L"-"; sessionId = L"-";
/* 4J - TODO - get a session ID from somewhere? /* 4J - TODO - get a session ID from somewhere?
if (args.length > 0) name = args[0]; if (args.size() > 0) name = args[0];
sessionId = "-"; sessionId = "-";
if (args.length > 1) sessionId = args[1]; if (args.size() > 1) sessionId = args[1];
*/ */
} }

View file

@ -98,7 +98,7 @@ public:
LevelRenderer* levelRenderer; LevelRenderer* levelRenderer;
std::shared_ptr<MultiplayerLocalPlayer> player; std::shared_ptr<MultiplayerLocalPlayer> player;
MultiPlayerLevelArray levels; std::vector<MultiPlayerLevel*> levels;
std::shared_ptr<MultiplayerLocalPlayer> localplayers[XUSER_MAX_COUNT]; std::shared_ptr<MultiplayerLocalPlayer> localplayers[XUSER_MAX_COUNT];
MultiPlayerGameMode* localgameModes[XUSER_MAX_COUNT]; MultiPlayerGameMode* localgameModes[XUSER_MAX_COUNT];

View file

@ -55,7 +55,7 @@ Font::Font(Options* options, const std::wstring& name, Textures* textures,
int w = img->getWidth(); int w = img->getWidth();
int h = img->getHeight(); int h = img->getHeight();
intArray rawPixels(w * h); std::vector<int> rawPixels(w * h);
img->getRGB(0, 0, w, h, rawPixels, 0, w); img->getRGB(0, 0, w, h, rawPixels, 0, w);
for (int i = 0; i < charC; i++) { for (int i = 0; i < charC; i++) {

View file

@ -66,7 +66,7 @@ void JoinMultiplayerScreen::buttonClicked(Button* button) {
// 4J - TODO // 4J - TODO
// minecraft->setScreen(new ConnectScreen(minecraft, parts[0], // minecraft->setScreen(new ConnectScreen(minecraft, parts[0],
// parts.length > 1 ? parseInt(parts[1], 25565) : 25565)); // parts.size() > 1 ? parseInt(parts[1], 25565) : 25565));
} }
} }

View file

@ -13,7 +13,7 @@ bool Minimap::genLUT = true; // 4J added
Minimap::Minimap(Font* font, Options* options, Textures* textures, Minimap::Minimap(Font* font, Options* options, Textures* textures,
bool optimised) { bool optimised) {
this->pixels = intArray(w * h); this->pixels = std::vector<int>(w * h);
this->options = options; this->options = options;
this->font = font; this->font = font;
BufferedImage* img = new BufferedImage(w, h, BufferedImage::TYPE_INT_ARGB); BufferedImage* img = new BufferedImage(w, h, BufferedImage::TYPE_INT_ARGB);

View file

@ -14,7 +14,7 @@ private:
static bool genLUT; // 4J added static bool genLUT; // 4J added
int renderCount; // 4J added int renderCount; // 4J added
bool m_optimised; // 4J Added bool m_optimised; // 4J Added
intArray pixels; std::vector<int> pixels;
int mapTexture; int mapTexture;
Options* options; Options* options;
Font* font; Font* font;

View file

@ -4,9 +4,9 @@
#include "geom/ModelPart.h" #include "geom/ModelPart.h"
BlazeModel::BlazeModel() : Model() { BlazeModel::BlazeModel() : Model() {
upperBodyParts = ModelPartArray(12); upperBodyParts = std::vector<ModelPart*>(12);
for (unsigned int i = 0; i < upperBodyParts.length; i++) { for (unsigned int i = 0; i < upperBodyParts.size(); i++) {
upperBodyParts[i] = new ModelPart(this, 0, 16); upperBodyParts[i] = new ModelPart(this, 0, 16);
upperBodyParts[i]->addBox(0, 0, 0, 2, 8, 2); upperBodyParts[i]->addBox(0, 0, 0, 2, 8, 2);
} }
@ -17,7 +17,7 @@ BlazeModel::BlazeModel() : Model() {
// 4J added - compile now to avoid random performance hit first time cubes // 4J added - compile now to avoid random performance hit first time cubes
// are rendered 4J Stu - Not just performance, but alpha+depth tests don't // are rendered 4J Stu - Not just performance, but alpha+depth tests don't
// work right unless we compile here // work right unless we compile here
for (unsigned int i = 0; i < upperBodyParts.length; i++) { for (unsigned int i = 0; i < upperBodyParts.size(); i++) {
upperBodyParts[i]->compile(1.0f / 16.0f); upperBodyParts[i]->compile(1.0f / 16.0f);
} }
head->compile(1.0f / 16.0f); head->compile(1.0f / 16.0f);
@ -31,7 +31,7 @@ void BlazeModel::render(std::shared_ptr<Entity> entity, float time, float r,
setupAnim(time, r, bob, yRot, xRot, scale, entity); setupAnim(time, r, bob, yRot, xRot, scale, entity);
head->render(scale, usecompiled); head->render(scale, usecompiled);
for (unsigned int i = 0; i < upperBodyParts.length; i++) { for (unsigned int i = 0; i < upperBodyParts.size(); i++) {
upperBodyParts[i]->render(scale, usecompiled); upperBodyParts[i]->render(scale, usecompiled);
} }
} }

View file

@ -3,7 +3,7 @@
class BlazeModel : public Model { class BlazeModel : public Model {
private: private:
ModelPartArray upperBodyParts; std::vector<ModelPart*> upperBodyParts;
ModelPart* head; ModelPart* head;
public: public:

View file

@ -11,7 +11,7 @@ GhastModel::GhastModel() : Model() {
body->y += (8 + 16) + yoffs; body->y += (8 + 16) + yoffs;
Random* random = new Random(1660); Random* random = new Random(1660);
for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.length for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.size()
{ {
tentacles[i] = new ModelPart(this, 0, 0); tentacles[i] = new ModelPart(this, 0, 0);
@ -37,7 +37,7 @@ void GhastModel::setupAnim(float time, float r, float bob, float yRot,
float xRot, float scale, float xRot, float scale,
std::shared_ptr<Entity> entity, std::shared_ptr<Entity> entity,
unsigned int uiBitmaskOverrideAnim) { unsigned int uiBitmaskOverrideAnim) {
for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.length for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.size()
{ {
tentacles[i]->xRot = 0.2f * Mth::sin(bob * 0.3f + i) + 0.4f; tentacles[i]->xRot = 0.2f * Mth::sin(bob * 0.3f + i) + 0.4f;
} }
@ -52,7 +52,7 @@ void GhastModel::render(std::shared_ptr<Entity> entity, float time, float r,
glTranslatef(0, .6f, 0); glTranslatef(0, .6f, 0);
body->render(scale, usecompiled); body->render(scale, usecompiled);
for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.length for (int i = 0; i < TENTACLESLENGTH; i++) // 4J - 9 was tentacles.size()
{ {
tentacles[i]->render(scale, usecompiled); tentacles[i]->render(scale, usecompiled);
} }

View file

@ -13,21 +13,21 @@ const int SilverfishModel::BODY_TEXS[BODY_COUNT][2] = {
}; };
SilverfishModel::SilverfishModel() { SilverfishModel::SilverfishModel() {
bodyParts = ModelPartArray(BODY_COUNT); bodyParts = std::vector<ModelPart*>(BODY_COUNT);
float placement = -3.5f; float placement = -3.5f;
for (unsigned int i = 0; i < bodyParts.length; i++) { for (unsigned int i = 0; i < bodyParts.size(); i++) {
bodyParts[i] = new ModelPart(this, BODY_TEXS[i][0], BODY_TEXS[i][1]); bodyParts[i] = new ModelPart(this, BODY_TEXS[i][0], BODY_TEXS[i][1]);
bodyParts[i]->addBox(BODY_SIZES[i][0] * -0.5f, 0, bodyParts[i]->addBox(BODY_SIZES[i][0] * -0.5f, 0,
BODY_SIZES[i][2] * -0.5f, BODY_SIZES[i][0], BODY_SIZES[i][2] * -0.5f, BODY_SIZES[i][0],
BODY_SIZES[i][1], BODY_SIZES[i][2]); BODY_SIZES[i][1], BODY_SIZES[i][2]);
bodyParts[i]->setPos(0.0f, 24.0f - (float)BODY_SIZES[i][1], placement); bodyParts[i]->setPos(0.0f, 24.0f - (float)BODY_SIZES[i][1], placement);
zPlacement[i] = placement; zPlacement[i] = placement;
if (i < bodyParts.length - 1) { if (i < bodyParts.size() - 1) {
placement += (BODY_SIZES[i][2] + BODY_SIZES[i + 1][2]) * .5f; placement += (BODY_SIZES[i][2] + BODY_SIZES[i + 1][2]) * .5f;
} }
} }
bodyLayers = ModelPartArray(3); bodyLayers = std::vector<ModelPart*>(3);
bodyLayers[0] = new ModelPart(this, 20, 0); bodyLayers[0] = new ModelPart(this, 20, 0);
bodyLayers[0]->addBox(-5, 0, BODY_SIZES[2][2] * -0.5f, 10, 8, bodyLayers[0]->addBox(-5, 0, BODY_SIZES[2][2] * -0.5f, 10, 8,
BODY_SIZES[2][2]); BODY_SIZES[2][2]);
@ -43,7 +43,7 @@ SilverfishModel::SilverfishModel() {
// 4J added - compile now to avoid random performance hit first time cubes // 4J added - compile now to avoid random performance hit first time cubes
// are rendered // are rendered
for (unsigned int i = 0; i < bodyParts.length; i++) { for (unsigned int i = 0; i < bodyParts.size(); i++) {
bodyParts[i]->compile(1.0f / 16.0f); bodyParts[i]->compile(1.0f / 16.0f);
} }
bodyLayers[0]->compile(1.0f / 16.0f); bodyLayers[0]->compile(1.0f / 16.0f);
@ -58,10 +58,10 @@ void SilverfishModel::render(std::shared_ptr<Entity> entity, float time,
float scale, bool usecompiled) { float scale, bool usecompiled) {
setupAnim(time, r, bob, yRot, xRot, scale, entity); setupAnim(time, r, bob, yRot, xRot, scale, entity);
for (unsigned int i = 0; i < bodyParts.length; i++) { for (unsigned int i = 0; i < bodyParts.size(); i++) {
bodyParts[i]->render(scale, usecompiled); bodyParts[i]->render(scale, usecompiled);
} }
for (unsigned int i = 0; i < bodyLayers.length; i++) { for (unsigned int i = 0; i < bodyLayers.size(); i++) {
bodyLayers[i]->render(scale, usecompiled); bodyLayers[i]->render(scale, usecompiled);
} }
} }
@ -70,7 +70,7 @@ void SilverfishModel::setupAnim(float time, float r, float bob, float yRot,
float xRot, float scale, float xRot, float scale,
std::shared_ptr<Entity> entity, std::shared_ptr<Entity> entity,
unsigned int uiBitmaskOverrideAnim) { unsigned int uiBitmaskOverrideAnim) {
for (unsigned int i = 0; i < bodyParts.length; i++) { for (unsigned int i = 0; i < bodyParts.size(); i++) {
bodyParts[i]->yRot = Mth::cos(bob * .9f + i * .15f * M_PI) * M_PI * .05f * bodyParts[i]->yRot = Mth::cos(bob * .9f + i * .15f * M_PI) * M_PI * .05f *
(1 + abs((int)i - 2)); (1 + abs((int)i - 2));
bodyParts[i]->x = bodyParts[i]->x =

View file

@ -7,8 +7,8 @@ private:
static const int BODY_COUNT = 7; static const int BODY_COUNT = 7;
private: private:
ModelPartArray bodyParts; std::vector<ModelPart*> bodyParts;
ModelPartArray bodyLayers; std::vector<ModelPart*> bodyLayers;
float zPlacement[BODY_COUNT]; float zPlacement[BODY_COUNT];
static const int BODY_SIZES[BODY_COUNT][3]; static const int BODY_SIZES[BODY_COUNT][3];

View file

@ -14,7 +14,7 @@ void SkiModel::_init(bool leftSki) {
xOffTex = 14; xOffTex = 14;
} }
cubes = ModelPartArray(2); cubes = std::vector<ModelPart*>(2);
cubes[0] = new ModelPart(this, xOffTex, 0); cubes[0] = new ModelPart(this, xOffTex, 0);
cubes[1] = new ModelPart(this, xOffTex, 5); cubes[1] = new ModelPart(this, xOffTex, 5);
@ -28,7 +28,7 @@ void SkiModel::_init(bool leftSki) {
void SkiModel::render(std::shared_ptr<Entity> entity, float time, float r, void SkiModel::render(std::shared_ptr<Entity> entity, float time, float r,
float bob, float yRot, float xRot, float scale, float bob, float yRot, float xRot, float scale,
bool usecompiled) { bool usecompiled) {
for (int i = 0; i < cubes.length; i++) { for (int i = 0; i < cubes.size(); i++) {
cubes[i]->render(scale, usecompiled); cubes[i]->render(scale, usecompiled);
} }
} }

View file

@ -4,7 +4,7 @@
class SkiModel : public Model { class SkiModel : public Model {
public: public:
ModelPartArray cubes; std::vector<ModelPart*> cubes;
private: private:
bool leftSki; bool leftSki;

View file

@ -9,12 +9,12 @@ SquidModel::SquidModel() : Model() {
body->addBox(-6, -8, -6, 12, 16, 12); body->addBox(-6, -8, -6, 12, 16, 12);
body->y += (8 + 16) + yoffs; body->y += (8 + 16) + yoffs;
for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.length for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.size()
{ {
tentacles[i] = new ModelPart(this, 48, 0); tentacles[i] = new ModelPart(this, 48, 0);
double angle = i * M_PI * 2.0 / double angle = i * M_PI * 2.0 /
(double)TENTACLES_LENGTH; // 4J - 8 was tentacles.length (double)TENTACLES_LENGTH; // 4J - 8 was tentacles.size()
float xo = Mth::cos((float)angle) * 5; float xo = Mth::cos((float)angle) * 5;
float yo = Mth::sin((float)angle) * 5; float yo = Mth::sin((float)angle) * 5;
tentacles[i]->addBox(-1, 0, -1, 2, 18, 2); tentacles[i]->addBox(-1, 0, -1, 2, 18, 2);
@ -24,7 +24,7 @@ SquidModel::SquidModel() : Model() {
tentacles[i]->y = (float)(31 + yoffs); tentacles[i]->y = (float)(31 + yoffs);
angle = i * M_PI * -2.0 / (double)TENTACLES_LENGTH + angle = i * M_PI * -2.0 / (double)TENTACLES_LENGTH +
M_PI * .5; // 4J - 8 was tentacles.length M_PI * .5; // 4J - 8 was tentacles.size()
tentacles[i]->yRot = (float)angle; tentacles[i]->yRot = (float)angle;
// 4J added - compile now to avoid random performance hit first time // 4J added - compile now to avoid random performance hit first time
@ -38,7 +38,7 @@ void SquidModel::setupAnim(float time, float r, float bob, float yRot,
float xRot, float scale, float xRot, float scale,
std::shared_ptr<Entity> entity, std::shared_ptr<Entity> entity,
unsigned int uiBitmaskOverrideAnim) { unsigned int uiBitmaskOverrideAnim) {
for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.length for (int i = 0; i < TENTACLES_LENGTH; i++) // 4J - 8 was tentacles.size()
{ {
// tentacle angle is calculated in SquidRenderer // tentacle angle is calculated in SquidRenderer
tentacles[i]->xRot = bob; tentacles[i]->xRot = bob;
@ -52,7 +52,7 @@ void SquidModel::render(std::shared_ptr<Entity> entity, float time, float r,
body->render(scale, usecompiled); body->render(scale, usecompiled);
for (int i = 0; i < TENTACLES_LENGTH; for (int i = 0; i < TENTACLES_LENGTH;
i++) // 4J - 8 was tentacles.length // 4J Stu - Was 9 but I made it 8 i++) // 4J - 8 was tentacles.size() // 4J Stu - Was 9 but I made it 8
// as the array is [0,8) // as the array is [0,8)
{ {
tentacles[i]->render(scale, usecompiled); tentacles[i]->render(scale, usecompiled);

View file

@ -7,7 +7,7 @@ WitherBossModel::WitherBossModel() {
texWidth = 64; texWidth = 64;
texHeight = 64; texHeight = 64;
upperBodyParts = ModelPartArray(3); upperBodyParts = std::vector<ModelPart*>(3);
upperBodyParts[0] = new ModelPart(this, 0, 16); upperBodyParts[0] = new ModelPart(this, 0, 16);
upperBodyParts[0]->addBox(-10, 3.9f, -.5f, 20, 3, 3); upperBodyParts[0]->addBox(-10, 3.9f, -.5f, 20, 3, 3);
@ -23,7 +23,7 @@ WitherBossModel::WitherBossModel() {
upperBodyParts[2] = new ModelPart(this, 12, 22); upperBodyParts[2] = new ModelPart(this, 12, 22);
upperBodyParts[2]->addBox(0, 0, 0, 3, 6, 3); upperBodyParts[2]->addBox(0, 0, 0, 3, 6, 3);
heads = ModelPartArray(3); heads = std::vector<ModelPart*>(3);
heads[0] = new ModelPart(this, 0, 0); heads[0] = new ModelPart(this, 0, 0);
heads[0]->addBox(-4, -4, -4, 8, 8, 8); heads[0]->addBox(-4, -4, -4, 8, 8, 8);
heads[1] = new ModelPart(this, 32, 0); heads[1] = new ModelPart(this, 32, 0);
@ -43,10 +43,10 @@ void WitherBossModel::render(std::shared_ptr<Entity> entity, float time,
float scale, bool usecompiled) { float scale, bool usecompiled) {
setupAnim(time, r, bob, yRot, xRot, scale, entity); setupAnim(time, r, bob, yRot, xRot, scale, entity);
for (int i = 0; i < heads.length; i++) { for (int i = 0; i < heads.size(); i++) {
heads[i]->render(scale, usecompiled); heads[i]->render(scale, usecompiled);
} }
for (int i = 0; i < upperBodyParts.length; i++) { for (int i = 0; i < upperBodyParts.size(); i++) {
upperBodyParts[i]->render(scale, usecompiled); upperBodyParts[i]->render(scale, usecompiled);
} }
} }

View file

@ -4,8 +4,8 @@
class WitherBossModel : public Model { class WitherBossModel : public Model {
private: private:
ModelPartArray upperBodyParts; std::vector<ModelPart*> upperBodyParts;
ModelPartArray heads; std::vector<ModelPart*> heads;
public: public:
WitherBossModel(); WitherBossModel();

View file

@ -134,12 +134,12 @@ void DragonModel::render(std::shared_ptr<Entity> entity, float time, float r,
float rotScale = 1.5f; float rotScale = 1.5f;
double startComponents[3]; double startComponents[3];
doubleArray start = doubleArray(startComponents, 3); std::vector<double> start = std::vector<double>(startComponents, startComponents + 3);
dragon->getLatencyPos(start, 6, a); dragon->getLatencyPos(start, 6, a);
double latencyPosAComponents[3], latencyPosBComponents[3]; double latencyPosAComponents[3], latencyPosBComponents[3];
doubleArray latencyPosA = doubleArray(latencyPosAComponents, 3); std::vector<double> latencyPosA = std::vector<double>(latencyPosAComponents, latencyPosAComponents + 3);
doubleArray latencyPosB = doubleArray(latencyPosBComponents, 3); std::vector<double> latencyPosB = std::vector<double>(latencyPosBComponents, latencyPosBComponents + 3);
dragon->getLatencyPos(latencyPosA, 5, a); dragon->getLatencyPos(latencyPosA, 5, a);
dragon->getLatencyPos(latencyPosB, 10, a); dragon->getLatencyPos(latencyPosB, 10, a);
float rot2 = rotWrap(latencyPosA[0] - latencyPosB[0]); float rot2 = rotWrap(latencyPosA[0] - latencyPosB[0]);
@ -152,7 +152,7 @@ void DragonModel::render(std::shared_ptr<Entity> entity, float time, float r,
yy = 20.0f; yy = 20.0f;
zz = -12.0f; zz = -12.0f;
double pComponents[3]; double pComponents[3];
doubleArray p = doubleArray(pComponents, 3); std::vector<double> p = std::vector<double>(pComponents, pComponents + 3);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
dragon->getLatencyPos(p, 5 - i, a); dragon->getLatencyPos(p, 5 - i, a);

View file

@ -50,7 +50,7 @@ void ModelPart::construct(Model* model, int xTexOffs, int yTexOffs) {
} }
void ModelPart::addChild(ModelPart* child) { void ModelPart::addChild(ModelPart* child) {
// if (children == nullptr) children = new ModelPartArray; // if (children == nullptr) children = new std::vector<ModelPart*>;
children.push_back(child); children.push_back(child);
} }

View file

@ -603,7 +603,7 @@ void ClientConnection::handleAddEntity(
e->getSubEntities(); e->getSubEntities();
if (subEntities != nullptr) { if (subEntities != nullptr) {
int offs = packet->id - e->entityId; int offs = packet->id - e->entityId;
// for (int i = 0; i < subEntities.length; i++) // for (int i = 0; i < subEntities.size(); i++)
for (auto it = subEntities->begin(); it != subEntities->end(); for (auto it = subEntities->begin(); it != subEntities->end();
++it) { ++it) {
(*it)->entityId += offs; (*it)->entityId += offs;
@ -915,7 +915,7 @@ void ClientConnection::handleMoveEntitySmall(
void ClientConnection::handleRemoveEntity( void ClientConnection::handleRemoveEntity(
std::shared_ptr<RemoveEntitiesPacket> packet) { std::shared_ptr<RemoveEntitiesPacket> packet) {
for (int i = 0; i < packet->ids.length; i++) { for (int i = 0; i < packet->ids.size(); i++) {
level->removeEntity(packet->ids[i]); level->removeEntity(packet->ids[i]);
} }
} }
@ -1087,7 +1087,7 @@ void ClientConnection::handleBlockRegionUpdate(
int y1 = packet->y + packet->ys; int y1 = packet->y + packet->ys;
if (packet->bIsFullChunk) { if (packet->bIsFullChunk) {
y1 = Level::maxBuildHeight; y1 = Level::maxBuildHeight;
if (packet->buffer.length > 0) { if (packet->buffer.size() > 0) {
PIXBeginNamedEvent(0, "Reordering to XZY"); PIXBeginNamedEvent(0, "Reordering to XZY");
LevelChunk::reorderBlocksAndDataToXZY(packet->y, packet->xs, LevelChunk::reorderBlocksAndDataToXZY(packet->y, packet->xs,
packet->ys, packet->zs, packet->ys, packet->zs,
@ -1998,7 +1998,7 @@ void ClientConnection::handleAddMob(std::shared_ptr<AddMobPacket> packet) {
std::vector<std::shared_ptr<Entity> >* subEntities = mob->getSubEntities(); std::vector<std::shared_ptr<Entity> >* subEntities = mob->getSubEntities();
if (subEntities != nullptr) { if (subEntities != nullptr) {
int offs = packet->id - mob->entityId; int offs = packet->id - mob->entityId;
// for (int i = 0; i < subEntities.length; i++) // for (int i = 0; i < subEntities.size(); i++)
for (auto it = subEntities->begin(); it != subEntities->end(); ++it) { for (auto it = subEntities->begin(); it != subEntities->end(); ++it) {
// subEntities[i].entityId += offs; // subEntities[i].entityId += offs;
(*it)->entityId += offs; (*it)->entityId += offs;
@ -2975,8 +2975,9 @@ void ClientConnection::handleLevelEvent(
void ClientConnection::handleAwardStat( void ClientConnection::handleAwardStat(
std::shared_ptr<AwardStatPacket> packet) { std::shared_ptr<AwardStatPacket> packet) {
std::vector<uint8_t> paramData = packet->getParamData();
minecraft->localplayers[m_userIndex]->awardStatFromServer( minecraft->localplayers[m_userIndex]->awardStatFromServer(
GenericStats::stat(packet->statId), packet->getParamData()); GenericStats::stat(packet->statId), paramData);
} }
void ClientConnection::handleUpdateMobEffect( void ClientConnection::handleUpdateMobEffect(
@ -3269,7 +3270,7 @@ void ClientConnection::handleServerSettingsChanged(
if (packet->action == ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS) { if (packet->action == ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS) {
app.SetGameHostOption(eGameHostOption_All, packet->data); app.SetGameHostOption(eGameHostOption_All, packet->data);
} else if (packet->action == ServerSettingsChangedPacket::HOST_DIFFICULTY) { } else if (packet->action == ServerSettingsChangedPacket::HOST_DIFFICULTY) {
for (unsigned int i = 0; i < minecraft->levels.length; ++i) { for (unsigned int i = 0; i < minecraft->levels.size(); ++i) {
if (minecraft->levels[i] != nullptr) { if (minecraft->levels[i] != nullptr) {
app.DebugPrintf( app.DebugPrintf(
"ClientConnection::handleServerSettingsChanged - " "ClientConnection::handleServerSettingsChanged - "
@ -3306,8 +3307,8 @@ void ClientConnection::handleUpdateGameRuleProgressPacket(
if (string != nullptr) { if (string != nullptr) {
std::wstring message(string); std::wstring message(string);
message = GameRuleDefinition::generateDescriptionString( message = GameRuleDefinition::generateDescriptionString(
packet->m_definitionType, message, packet->m_data.data, packet->m_definitionType, message, packet->m_data.data(),
packet->m_data.length); packet->m_data.size());
if (minecraft->localgameModes[m_userIndex] != nullptr) { if (minecraft->localgameModes[m_userIndex] != nullptr) {
minecraft->localgameModes[m_userIndex]->getTutorial()->setMessage( minecraft->localgameModes[m_userIndex]->getTutorial()->setMessage(
message, packet->m_icon, packet->m_auxValue); message, packet->m_icon, packet->m_auxValue);
@ -3322,7 +3323,6 @@ void ClientConnection::handleUpdateGameRuleProgressPacket(
app.SetSpecialTutorialCompletionFlag(m_userIndex, app.SetSpecialTutorialCompletionFlag(m_userIndex,
packet->m_dataTag - 1); packet->m_dataTag - 1);
} }
delete[] packet->m_data.data;
} }
// 4J Stu - TU-1 hotfix // 4J Stu - TU-1 hotfix

View file

@ -17,13 +17,14 @@ MultiPlayerChunkCache::MultiPlayerChunkCache(Level* level) {
hasData = new bool[XZSIZE * XZSIZE]; hasData = new bool[XZSIZE * XZSIZE];
memset(hasData, 0, sizeof(bool) * XZSIZE * XZSIZE); memset(hasData, 0, sizeof(bool) * XZSIZE * XZSIZE);
std::vector<uint8_t> emptyBlocks(16 * 16 * Level::maxBuildHeight);
emptyChunk = new EmptyLevelChunk( emptyChunk = new EmptyLevelChunk(
level, byteArray(16 * 16 * Level::maxBuildHeight), 0, 0); level, emptyBlocks, 0, 0);
// For normal world dimension, create a chunk that can be used to create the // For normal world dimension, create a chunk that can be used to create the
// illusion of infinite water at the edge of the world // illusion of infinite water at the edge of the world
if (level->dimension->id == 0) { if (level->dimension->id == 0) {
byteArray bytes = byteArray(16 * 16 * 128); std::vector<uint8_t> bytes = std::vector<uint8_t>(16 * 16 * 128);
// Superflat.... make grass, not water... // Superflat.... make grass, not water...
if (level->getLevelData()->getGenerator() == LevelType::lvl_flat) { if (level->getLevelData()->getGenerator() == LevelType::lvl_flat) {
@ -54,7 +55,6 @@ MultiPlayerChunkCache::MultiPlayerChunkCache(Level* level) {
waterChunk = new WaterLevelChunk(level, bytes, 0, 0); waterChunk = new WaterLevelChunk(level, bytes, 0, 0);
delete[] bytes.data;
if (level->getLevelData()->getGenerator() == LevelType::lvl_flat) { if (level->getLevelData()->getGenerator() == LevelType::lvl_flat) {
for (int x = 0; x < 16; x++) for (int x = 0; x < 16; x++)
@ -189,7 +189,7 @@ LevelChunk* MultiPlayerChunkCache::create(int x, int z) {
} else { } else {
// Passing an empty array into the LevelChunk ctor, which it now // Passing an empty array into the LevelChunk ctor, which it now
// detects and sets up the chunk as compressed & empty // detects and sets up the chunk as compressed & empty
byteArray bytes; std::vector<uint8_t> bytes;
chunk = new LevelChunk(level, bytes, x, z); chunk = new LevelChunk(level, bytes, x, z);

View file

@ -286,25 +286,22 @@ void MultiplayerLocalPlayer::hurtTo(float newHealth,
} }
} }
void MultiplayerLocalPlayer::awardStat(Stat* stat, byteArray param) { void MultiplayerLocalPlayer::awardStat(Stat* stat, const std::vector<uint8_t>& param) {
if (stat == nullptr) { if (stat == nullptr) {
delete[] param.data;
return; return;
} }
if (stat->awardLocallyOnly) { if (stat->awardLocallyOnly) {
LocalPlayer::awardStat(stat, param); LocalPlayer::awardStat(stat, param);
} else { } else {
delete[] param.data;
return; return;
} }
} }
void MultiplayerLocalPlayer::awardStatFromServer(Stat* stat, byteArray param) { void MultiplayerLocalPlayer::awardStatFromServer(Stat* stat, std::vector<uint8_t>& param) {
if (stat != nullptr && !stat->awardLocallyOnly) { if (stat != nullptr && !stat->awardLocallyOnly) {
LocalPlayer::awardStat(stat, param); LocalPlayer::awardStat(stat, param);
} else }
delete[] param.data;
} }
void MultiplayerLocalPlayer::onUpdateAbilities() { void MultiplayerLocalPlayer::onUpdateAbilities() {

View file

@ -70,8 +70,8 @@ public:
virtual void closeContainer(); virtual void closeContainer();
void clientSideCloseContainer(); void clientSideCloseContainer();
virtual void hurtTo(float newHealth, ETelemetryChallenges damageSource); virtual void hurtTo(float newHealth, ETelemetryChallenges damageSource);
virtual void awardStat(Stat* stat, byteArray param); virtual void awardStat(Stat* stat, const std::vector<uint8_t>& param);
void awardStatFromServer(Stat* stat, byteArray param); void awardStatFromServer(Stat* stat, std::vector<uint8_t>& param);
void onUpdateAbilities(); void onUpdateAbilities();
bool isLocalPlayer(); bool isLocalPlayer();

View file

@ -90,8 +90,8 @@ void FireworksParticles::FireworksStarter::tick() {
int type = compoundTag->getByte(FireworksItem::TAG_E_TYPE); int type = compoundTag->getByte(FireworksItem::TAG_E_TYPE);
bool trail = compoundTag->getBoolean(FireworksItem::TAG_E_TRAIL); bool trail = compoundTag->getBoolean(FireworksItem::TAG_E_TRAIL);
bool flicker = compoundTag->getBoolean(FireworksItem::TAG_E_FLICKER); bool flicker = compoundTag->getBoolean(FireworksItem::TAG_E_FLICKER);
intArray colors = compoundTag->getIntArray(FireworksItem::TAG_E_COLORS); std::vector<int> colors = compoundTag->getIntArray(FireworksItem::TAG_E_COLORS);
intArray fadeColors = std::vector<int> fadeColors =
compoundTag->getIntArray(FireworksItem::TAG_E_FADECOLORS); compoundTag->getIntArray(FireworksItem::TAG_E_FADECOLORS);
if (type == FireworksItem::TYPE_BIG) { if (type == FireworksItem::TYPE_BIG) {
@ -106,10 +106,10 @@ void FireworksParticles::FireworksStarter::tick() {
150.0 / 245.0, -197.0 / 245.0, 150.0 / 245.0, -197.0 / 245.0,
0.0, -88.0 / 245.0, 0.0, -88.0 / 245.0,
}; };
coords2DArray coordsArray(6, 2); std::vector<std::vector<double>> coordsArray(6, std::vector<double>(2));
for (unsigned int i = 0; i < coordsArray.length; ++i) { for (unsigned int i = 0; i < coordsArray.size(); ++i) {
for (unsigned int j = 0; j < coordsArray[i]->length; ++j) { for (unsigned int j = 0; j < coordsArray[i].size(); ++j) {
coordsArray[i]->data[j] = coords[i][j]; coordsArray[i][j] = coords[i][j];
} }
} }
@ -117,19 +117,16 @@ void FireworksParticles::FireworksStarter::tick() {
createParticleShape(.5, coordsArray, colors, fadeColors, trail, createParticleShape(.5, coordsArray, colors, fadeColors, trail,
flicker, false); flicker, false);
for (unsigned int i = 0; i < coordsArray.length; ++i) { // vector cleans up automatically
delete[] coordsArray[i]->data;
}
delete[] coordsArray.data;
} else if (type == FireworksItem::TYPE_CREEPER) { } else if (type == FireworksItem::TYPE_CREEPER) {
double coords[12][2] = { double coords[12][2] = {
0.0, 0.2, 0.2, 0.2, 0.2, 0.6, 0.6, 0.6, 0.6, 0.2, 0.2, 0.2, 0.0, 0.2, 0.2, 0.2, 0.2, 0.6, 0.6, 0.6, 0.6, 0.2, 0.2, 0.2,
0.2, 0.0, 0.4, 0.0, 0.4, -0.6, 0.2, -0.6, 0.2, -0.4, 0.0, -0.4, 0.2, 0.0, 0.4, 0.0, 0.4, -0.6, 0.2, -0.6, 0.2, -0.4, 0.0, -0.4,
}; };
coords2DArray coordsArray(12, 2); std::vector<std::vector<double>> coordsArray(12, std::vector<double>(2));
for (unsigned int i = 0; i < coordsArray.length; ++i) { for (unsigned int i = 0; i < coordsArray.size(); ++i) {
for (unsigned int j = 0; j < coordsArray[i]->length; ++j) { for (unsigned int j = 0; j < coordsArray[i].size(); ++j) {
coordsArray[i]->data[j] = coords[i][j]; coordsArray[i][j] = coords[i][j];
} }
} }
@ -137,10 +134,7 @@ void FireworksParticles::FireworksStarter::tick() {
createParticleShape(.5, coordsArray, colors, fadeColors, trail, createParticleShape(.5, coordsArray, colors, fadeColors, trail,
flicker, true); flicker, true);
for (unsigned int i = 0; i < coordsArray.length; ++i) { // vector cleans up automatically
delete[] coordsArray[i]->data;
}
delete[] coordsArray.data;
} else if (type == FireworksItem::TYPE_BURST) { } else if (type == FireworksItem::TYPE_BURST) {
createParticleBurst(colors, fadeColors, trail, flicker); createParticleBurst(colors, fadeColors, trail, flicker);
} else { } else {
@ -187,7 +181,7 @@ bool FireworksParticles::FireworksStarter::isFarAwayFromCamera() {
void FireworksParticles::FireworksStarter::createParticle( void FireworksParticles::FireworksStarter::createParticle(
double x, double y, double z, double xa, double ya, double za, double x, double y, double z, double xa, double ya, double za,
intArray rgbColors, intArray fadeColors, bool trail, bool flicker) { const std::vector<int>& rgbColors, const std::vector<int>& fadeColors, bool trail, bool flicker) {
std::shared_ptr<FireworksSparkParticle> fireworksSparkParticle = std::shared_ptr<FireworksSparkParticle> fireworksSparkParticle =
std::shared_ptr<FireworksSparkParticle>( std::shared_ptr<FireworksSparkParticle>(
new FireworksSparkParticle(level, x, y, z, xa, ya, za, engine)); new FireworksSparkParticle(level, x, y, z, xa, ya, za, engine));
@ -195,17 +189,17 @@ void FireworksParticles::FireworksStarter::createParticle(
fireworksSparkParticle->setTrail(trail); fireworksSparkParticle->setTrail(trail);
fireworksSparkParticle->setFlicker(flicker); fireworksSparkParticle->setFlicker(flicker);
int color = random->nextInt(rgbColors.length); int color = random->nextInt(rgbColors.size());
fireworksSparkParticle->setColor(rgbColors[color]); fireworksSparkParticle->setColor(rgbColors[color]);
if (/*fadeColors != nullptr &&*/ fadeColors.length > 0) { if (/*fadeColors != nullptr &&*/ fadeColors.size() > 0) {
fireworksSparkParticle->setFadeColor( fireworksSparkParticle->setFadeColor(
fadeColors[random->nextInt(fadeColors.length)]); fadeColors[random->nextInt(fadeColors.size())]);
} }
engine->add(fireworksSparkParticle); engine->add(fireworksSparkParticle);
} }
void FireworksParticles::FireworksStarter::createParticleBall( void FireworksParticles::FireworksStarter::createParticleBall(
double baseSpeed, int steps, intArray rgbColors, intArray fadeColors, double baseSpeed, int steps, const std::vector<int>& rgbColors, const std::vector<int>& fadeColors,
bool trail, bool flicker) { bool trail, bool flicker) {
double xx = x; double xx = x;
double yy = y; double yy = y;
@ -236,10 +230,10 @@ void FireworksParticles::FireworksStarter::createParticleBall(
} }
void FireworksParticles::FireworksStarter::createParticleShape( void FireworksParticles::FireworksStarter::createParticleShape(
double baseSpeed, coords2DArray coords, intArray rgbColors, double baseSpeed, std::vector<std::vector<double>> coords, const std::vector<int>& rgbColors,
intArray fadeColors, bool trail, bool flicker, bool flat) { const std::vector<int>& fadeColors, bool trail, bool flicker, bool flat) {
double sx = coords[0]->data[0]; double sx = coords[0][0];
double sy = coords[0]->data[1]; double sy = coords[0][1];
{ {
createParticle(x, y, z, sx * baseSpeed, sy * baseSpeed, 0, rgbColors, createParticle(x, y, z, sx * baseSpeed, sy * baseSpeed, 0, rgbColors,
@ -254,9 +248,9 @@ void FireworksParticles::FireworksStarter::createParticleShape(
double ox = sx; double ox = sx;
double oy = sy; double oy = sy;
for (int c = 1; c < coords.length; c++) { for (int c = 1; c < coords.size(); c++) {
double tx = coords[c]->data[0]; double tx = coords[c][0];
double ty = coords[c]->data[1]; double ty = coords[c][1];
for (double subStep = .25; subStep <= 1.0; subStep += .25) { for (double subStep = .25; subStep <= 1.0; subStep += .25) {
double xa = (ox + (tx - ox) * subStep) * baseSpeed; double xa = (ox + (tx - ox) * subStep) * baseSpeed;
@ -277,7 +271,7 @@ void FireworksParticles::FireworksStarter::createParticleShape(
} }
void FireworksParticles::FireworksStarter::createParticleBurst( void FireworksParticles::FireworksStarter::createParticleBurst(
intArray rgbColors, intArray fadeColors, bool trail, bool flicker) { const std::vector<int>& rgbColors, const std::vector<int>& fadeColors, bool trail, bool flicker) {
double baseOffX = random->nextGaussian() * .05; double baseOffX = random->nextGaussian() * .05;
double baseOffZ = random->nextGaussian() * .05; double baseOffZ = random->nextGaussian() * .05;

View file

@ -25,14 +25,14 @@ public:
virtual void tick(); virtual void tick();
bool isFarAwayFromCamera(); bool isFarAwayFromCamera();
void createParticle(double x, double y, double z, double xa, double ya, void createParticle(double x, double y, double z, double xa, double ya,
double za, intArray rgbColors, intArray fadeColors, double za, const std::vector<int>& rgbColors, const std::vector<int>& fadeColors,
bool trail, bool flicker); bool trail, bool flicker);
void createParticleBall(double baseSpeed, int steps, intArray rgbColors, void createParticleBall(double baseSpeed, int steps, const std::vector<int>& rgbColors,
intArray fadeColors, bool trail, bool flicker); const std::vector<int>& fadeColors, bool trail, bool flicker);
void createParticleShape(double baseSpeed, coords2DArray coords, void createParticleShape(double baseSpeed, std::vector<std::vector<double>> coords,
intArray rgbColors, intArray fadeColors, const std::vector<int>& rgbColors, const std::vector<int>& fadeColors,
bool trail, bool flicker, bool flat); bool trail, bool flicker, bool flat);
void createParticleBurst(intArray rgbColors, intArray fadeColors, void createParticleBurst(const std::vector<int>& rgbColors, const std::vector<int>& fadeColors,
bool trail, bool flicker); bool trail, bool flicker);
public: public:

View file

@ -797,9 +797,8 @@ void LocalPlayer::displayClientMessage(int messageId) {
minecraft->gui->displayClientMessage(messageId, GetXboxPad()); minecraft->gui->displayClientMessage(messageId, GetXboxPad());
} }
void LocalPlayer::awardStat(Stat* stat, byteArray param) { void LocalPlayer::awardStat(Stat* stat, const std::vector<uint8_t>& param) {
int count = CommonStats::readParam(param); int count = CommonStats::readParam(param);
delete[] param.data;
if (!app.CanRecordStatsAndAchievements()) return; if (!app.CanRecordStatsAndAchievements()) return;
if (stat == nullptr) return; if (stat == nullptr) return;
@ -1596,7 +1595,7 @@ void LocalPlayer::handleCollectItem(std::shared_ptr<ItemInstance> item) {
if (item != nullptr) { if (item != nullptr) {
unsigned int itemCountAnyAux = 0; unsigned int itemCountAnyAux = 0;
unsigned int itemCountThisAux = 0; unsigned int itemCountThisAux = 0;
for (unsigned int k = 0; k < inventory->items.length; ++k) { for (unsigned int k = 0; k < inventory->items.size(); ++k) {
if (inventory->items[k] != nullptr) { if (inventory->items[k] != nullptr) {
// do they have the item // do they have the item
if (inventory->items[k]->id == item->id) { if (inventory->items[k]->id == item->id) {
@ -1623,6 +1622,6 @@ void LocalPlayer::handleCollectItem(std::shared_ptr<ItemInstance> item) {
} }
void LocalPlayer::SetPlayerAdditionalModelParts( void LocalPlayer::SetPlayerAdditionalModelParts(
std::vector<ModelPart*> pAdditionalModelParts) { std::vector<ModelPart*>& pAdditionalModelParts) {
m_pAdditionalModelParts = pAdditionalModelParts; m_pAdditionalModelParts = pAdditionalModelParts;
} }

View file

@ -143,7 +143,7 @@ public:
virtual void respawn(); virtual void respawn();
virtual void animateRespawn(); virtual void animateRespawn();
virtual void displayClientMessage(int messageId); virtual void displayClientMessage(int messageId);
virtual void awardStat(Stat* stat, byteArray param); virtual void awardStat(Stat* stat, const std::vector<uint8_t>& param);
virtual int ThirdPersonView() { return m_iThirdPersonView; } virtual int ThirdPersonView() { return m_iThirdPersonView; }
// 4J - have changed 3rd person view to be 0 if not enabled, 1 for mode like // 4J - have changed 3rd person view to be 0 if not enabled, 1 for mode like
// original, 2 reversed mode // original, 2 reversed mode
@ -231,7 +231,7 @@ public:
virtual void handleCollectItem(std::shared_ptr<ItemInstance> item); virtual void handleCollectItem(std::shared_ptr<ItemInstance> item);
void SetPlayerAdditionalModelParts( void SetPlayerAdditionalModelParts(
std::vector<ModelPart*> pAdditionalModelParts); std::vector<ModelPart*>& pAdditionalModelParts);
private: private:
std::vector<ModelPart*> m_pAdditionalModelParts; std::vector<ModelPart*> m_pAdditionalModelParts;

View file

@ -262,9 +262,9 @@ void Chunk::rebuild() {
#else #else
static unsigned char tileIds[16 * 16 * Level::maxBuildHeight]; static unsigned char tileIds[16 * 16 * Level::maxBuildHeight];
#endif #endif
byteArray tileArray = byteArray(tileIds, 16 * 16 * Level::maxBuildHeight); std::vector<uint8_t> tileArray(16 * 16 * Level::maxBuildHeight);
level->getChunkAt(x, z)->getBlockData( level->getChunkAt(x, z)->getBlockData(tileArray);
tileArray); // 4J - TODO - now our data has been re-arranged, we could memcpy(tileIds, tileArray.data(), 16 * 16 * Level::maxBuildHeight); // 4J - TODO - now our data has been re-arranged, we could
// just extra the vertical slice of this chunk rather than // just extra the vertical slice of this chunk rather than
// the whole thing // the whole thing

View file

@ -163,7 +163,7 @@ GameRenderer::GameRenderer(Minecraft* mc) {
} }
delete img; delete img;
for (int i = 0; i < NUM_LIGHT_TEXTURES; i++) for (int i = 0; i < NUM_LIGHT_TEXTURES; i++)
lightPixels[i] = intArray(16 * 16); lightPixels[i] = std::vector<int>(16 * 16);
#if defined(MULTITHREAD_ENABLE) #if defined(MULTITHREAD_ENABLE)
m_updateEvents = new C4JThread::EventArray( m_updateEvents = new C4JThread::EventArray(

View file

@ -67,7 +67,7 @@ private:
// lightTexture per level, to support // lightTexture per level, to support
// split screen // split screen
int getLightTexture(int iPad, Level* level); // 4J added int getLightTexture(int iPad, Level* level); // 4J added
intArray lightPixels[NUM_LIGHT_TEXTURES]; std::vector<int> lightPixels[NUM_LIGHT_TEXTURES];
float fov[4]; float fov[4];
float oFov[4]; float oFov[4];

View file

@ -160,7 +160,7 @@ LevelRenderer::LevelRenderer(Minecraft* mc, Textures* textures) {
// sortedChunks[i] = nullptr; // 4J - removed - not // sortedChunks[i] = nullptr; // 4J - removed - not
// sorting // sorting
// our chunks anymore // our chunks anymore
chunks[i] = ClipChunkArray(); chunks[i] = std::vector<ClipChunk>();
lastPlayerCount[i] = 0; lastPlayerCount[i] = 0;
} }
@ -373,14 +373,12 @@ void LevelRenderer::setLevel(int playerIndex, MultiPlayerLevel* level) {
} else { } else {
// printf("NULLing player %d, chunks @ // printf("NULLing player %d, chunks @
// 0x%x\n",playerIndex,chunks[playerIndex]); // 0x%x\n",playerIndex,chunks[playerIndex]);
if (chunks[playerIndex].data != nullptr) { if (!chunks[playerIndex].empty()) {
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
chunks[playerIndex][i].chunk->_delete(); chunks[playerIndex][i].chunk->_delete();
delete chunks[playerIndex][i].chunk; delete chunks[playerIndex][i].chunk;
} }
delete chunks[playerIndex].data; chunks[playerIndex].clear();
chunks[playerIndex].data = nullptr;
chunks[playerIndex].length = 0;
// delete sortedChunks[playerIndex]; // 4J - // delete sortedChunks[playerIndex]; // 4J -
// removed - not sorting our chunks anymore // removed - not sorting our chunks anymore
// sortedChunks[playerIndex] = nullptr; // 4J - removed - not // sortedChunks[playerIndex] = nullptr; // 4J - removed - not
@ -447,17 +445,16 @@ void LevelRenderer::allChanged(int playerIndex) {
yChunks = Level::maxBuildHeight / CHUNK_SIZE; yChunks = Level::maxBuildHeight / CHUNK_SIZE;
zChunks = dist; zChunks = dist;
if (chunks[playerIndex].data != nullptr) { if (!chunks[playerIndex].empty()) {
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
chunks[playerIndex][i].chunk->_delete(); chunks[playerIndex][i].chunk->_delete();
delete chunks[playerIndex][i].chunk; delete chunks[playerIndex][i].chunk;
} }
delete chunks[playerIndex].data;
// delete sortedChunks[playerIndex]; // 4J - removed // delete sortedChunks[playerIndex]; // 4J - removed
//- not sorting our chunks anymore //- not sorting our chunks anymore
} }
chunks[playerIndex] = ClipChunkArray(xChunks * yChunks * zChunks); chunks[playerIndex] = std::vector<ClipChunk>(xChunks * yChunks * zChunks);
// sortedChunks[playerIndex] = new vector<Chunk *>(xChunks * yChunks * // sortedChunks[playerIndex] = new vector<Chunk *>(xChunks * yChunks *
// zChunks); // 4J - removed - not sorting our chunks anymore // zChunks); // 4J - removed - not sorting our chunks anymore
int id = 0; int id = 0;
@ -744,14 +741,14 @@ int LevelRenderer::render(std::shared_ptr<LivingEntity> player, int layer,
glColor4f(1, 1, 1, 1); glColor4f(1, 1, 1, 1);
mc->gameRenderer->turnOnLightLayer(alpha); mc->gameRenderer->turnOnLightLayer(alpha);
int count = renderChunks(0, (int)chunks[playerIndex].length, layer, alpha); int count = renderChunks(0, (int)chunks[playerIndex].size(), layer, alpha);
mc->gameRenderer->turnOffLightLayer(alpha); mc->gameRenderer->turnOffLightLayer(alpha);
return count; return count;
} }
int LevelRenderer::renderChunks(int from, int to, int layer, double alpha) { int LevelRenderer::renderChunks(int from, int to, int layer, double alpha) {
int playerIndex = mc->player->GetXboxPad(); int playerIndex = mc->player->GetXboxPad();
if (chunks[playerIndex].data == nullptr) return 0; if (chunks[playerIndex].empty()) return 0;
mc->gameRenderer->turnOnLightLayer(alpha); mc->gameRenderer->turnOnLightLayer(alpha);
std::shared_ptr<LivingEntity> player = mc->cameraTargetPlayer; std::shared_ptr<LivingEntity> player = mc->cameraTargetPlayer;
double xOff = player->xOld + (player->x - player->xOld) * alpha; double xOff = player->xOld + (player->x - player->xOld) * alpha;
@ -764,16 +761,16 @@ int LevelRenderer::renderChunks(int from, int to, int layer, double alpha) {
bool first = true; bool first = true;
int count = 0; int count = 0;
ClipChunk* pClipChunk = chunks[playerIndex].data; ClipChunk* pClipChunk = chunks[playerIndex].data();
unsigned char emptyFlag = LevelRenderer::CHUNK_FLAG_EMPTY0 << layer; unsigned char emptyFlag = LevelRenderer::CHUNK_FLAG_EMPTY0 << layer;
static thread_local std::vector<ClipChunk*> sortList; static thread_local std::vector<ClipChunk*> sortList;
sortList.clear(); sortList.clear();
if (sortList.capacity() < (size_t)chunks[playerIndex].length) { if (sortList.capacity() < (size_t)chunks[playerIndex].size()) {
sortList.reserve(chunks[playerIndex].length); sortList.reserve(chunks[playerIndex].size());
} }
{ {
FRAME_PROFILE_SCOPE(ChunkCollect); FRAME_PROFILE_SCOPE(ChunkCollect);
for (int i = 0; i < chunks[playerIndex].length; i++, pClipChunk++) { for (int i = 0; i < chunks[playerIndex].size(); i++, pClipChunk++) {
if (!pClipChunk->visible) if (!pClipChunk->visible)
continue; // This will be set if the chunk isn't visible, or continue; // This will be set if the chunk isn't visible, or
// isn't compiled, or has both empty flags set // isn't compiled, or has both empty flags set
@ -1775,9 +1772,9 @@ bool LevelRenderer::updateDirtyChunks() {
// shared_ptr it should live as long as we need it // shared_ptr it should live as long as we need it
std::shared_ptr<LocalPlayer> player = mc->localplayers[p]; std::shared_ptr<LocalPlayer> player = mc->localplayers[p];
if (player == nullptr) continue; if (player == nullptr) continue;
if (chunks[p].data == nullptr) continue; if (chunks[p].empty()) continue;
if (level[p] == nullptr) continue; if (level[p] == nullptr) continue;
if (chunks[p].length != xChunks * zChunks * CHUNK_Y_COUNT) if (chunks[p].size() != xChunks * zChunks * CHUNK_Y_COUNT)
continue; continue;
int px = (int)player->x; int px = (int)player->x;
int py = (int)player->y; int py = (int)player->y;
@ -2432,7 +2429,7 @@ bool inline clip(float* bb, float* frustum) {
// gives better performances but mostly breaks chunk rendering // gives better performances but mostly breaks chunk rendering
void LevelRenderer::cull(Culler* culler, float a) { void LevelRenderer::cull(Culler* culler, float a) {
int playerIndex = mc->player->GetXboxPad(); int playerIndex = mc->player->GetXboxPad();
if (chunks[playerIndex].data == nullptr) return; if (chunks[playerIndex].empty()) return;
FrustumCuller* fc = (FrustumCuller*)culler; FrustumCuller* fc = (FrustumCuller*)culler;
FrustumData* fd = fc->frustum; FrustumData* fd = fc->frustum;
@ -2450,7 +2447,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
#if defined(OCCLUSION_MODE_NONE) #if defined(OCCLUSION_MODE_NONE)
// just check if chunk is compiled and non-empty // just check if chunk is compiled and non-empty
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
ClipChunk* cc = &chunks[playerIndex][i]; ClipChunk* cc = &chunks[playerIndex][i];
if (cc->globalIdx < 0) { if (cc->globalIdx < 0) {
cc->visible = false; cc->visible = false;
@ -2467,7 +2464,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
#elif defined(OCCLUSION_MODE_FRUSTUM) #elif defined(OCCLUSION_MODE_FRUSTUM)
// Just ~~monika~~ frustum culling // Just ~~monika~~ frustum culling
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
ClipChunk* cc = &chunks[playerIndex][i]; ClipChunk* cc = &chunks[playerIndex][i];
if (cc->globalIdx < 0) { if (cc->globalIdx < 0) {
cc->visible = false; cc->visible = false;
@ -2497,7 +2494,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
// For now, fall back to frustum culling // For now, fall back to frustum culling
#warning \ #warning \
"OCCLUSION_MODE_HARDWARE is not implemented yet, falling back to frustum culling" "OCCLUSION_MODE_HARDWARE is not implemented yet, falling back to frustum culling"
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
ClipChunk* cc = &chunks[playerIndex][i]; ClipChunk* cc = &chunks[playerIndex][i];
if (cc->globalIdx < 0) { if (cc->globalIdx < 0) {
cc->visible = false; cc->visible = false;
@ -2547,7 +2544,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
int minCx = INT_MAX, minCy = INT_MAX, minCz = INT_MAX; int minCx = INT_MAX, minCy = INT_MAX, minCz = INT_MAX;
int maxCx = INT_MIN, maxCy = INT_MIN, maxCz = INT_MIN; int maxCx = INT_MIN, maxCy = INT_MIN, maxCz = INT_MIN;
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
ClipChunk* cc = &chunks[playerIndex][i]; ClipChunk* cc = &chunks[playerIndex][i];
cc->visible = false; cc->visible = false;
if (cc->globalIdx < 0) continue; if (cc->globalIdx < 0) continue;
@ -2576,7 +2573,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
} }
memset(m_bfsGrid.data(), 0, gridSize * sizeof(ClipChunk*)); memset(m_bfsGrid.data(), 0, gridSize * sizeof(ClipChunk*));
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
ClipChunk* cc = &chunks[playerIndex][i]; ClipChunk* cc = &chunks[playerIndex][i];
if (cc->globalIdx < 0) continue; if (cc->globalIdx < 0) continue;
int lx = intFloorDiv(cc->chunk->x, CHUNK_XZSIZE) - minCx; int lx = intFloorDiv(cc->chunk->x, CHUNK_XZSIZE) - minCx;
@ -2617,7 +2614,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
if (!startChunk) { if (!startChunk) {
float minDist = 1e30f; float minDist = 1e30f;
for (unsigned int i = 0; i < chunks[playerIndex].length; i++) { for (unsigned int i = 0; i < chunks[playerIndex].size(); i++) {
ClipChunk* cc = &chunks[playerIndex][i]; ClipChunk* cc = &chunks[playerIndex][i];
if (cc->globalIdx < 0) continue; if (cc->globalIdx < 0) continue;
float midX = cc->chunk->x + CHUNK_XZSIZE * 0.5f; float midX = cc->chunk->x + CHUNK_XZSIZE * 0.5f;
@ -2642,17 +2639,17 @@ void LevelRenderer::cull(Culler* culler, float a) {
static thread_local std::vector<BFSNode> q; static thread_local std::vector<BFSNode> q;
q.clear(); q.clear();
q.reserve(chunks[playerIndex].length); q.reserve(chunks[playerIndex].size());
int qHead = 0; int qHead = 0;
int visitedSize = chunks[playerIndex].length; int visitedSize = chunks[playerIndex].size();
if (m_bfsVisitedFaces[playerIndex].size() < visitedSize) { if (m_bfsVisitedFaces[playerIndex].size() < visitedSize) {
m_bfsVisitedFaces[playerIndex].resize(visitedSize, 0); m_bfsVisitedFaces[playerIndex].resize(visitedSize, 0);
} }
memset(m_bfsVisitedFaces[playerIndex].data(), 0, visitedSize); memset(m_bfsVisitedFaces[playerIndex].data(), 0, visitedSize);
q.push_back({startChunk, -1}); q.push_back({startChunk, -1});
m_bfsVisitedFaces[playerIndex][startChunk - chunks[playerIndex].data] = m_bfsVisitedFaces[playerIndex][startChunk - chunks[playerIndex].data()] =
0x3F; 0x3F;
static const int OFFSETS[6][3] = { static const int OFFSETS[6][3] = {
@ -2725,7 +2722,7 @@ void LevelRenderer::cull(Culler* culler, float a) {
ClipChunk* neighbor = getChunkAt(nx, ny, nz); ClipChunk* neighbor = getChunkAt(nx, ny, nz);
if (!neighbor) continue; if (!neighbor) continue;
int nIdx = neighbor - chunks[playerIndex].data; int nIdx = neighbor - chunks[playerIndex].data();
int nextIncFace = outFace ^ 1; int nextIncFace = outFace ^ 1;
if ((m_bfsVisitedFaces[playerIndex][nIdx] & (1 << nextIncFace)) != if ((m_bfsVisitedFaces[playerIndex][nIdx] & (1 << nextIncFace)) !=
@ -4058,8 +4055,8 @@ int LevelRenderer::checkAllPresentChunks(bool* faultFound) {
int playerIndex = mc->player->GetXboxPad(); // 4J added int playerIndex = mc->player->GetXboxPad(); // 4J added
int presentCount = 0; int presentCount = 0;
ClipChunk* pClipChunk = chunks[playerIndex].data; ClipChunk* pClipChunk = chunks[playerIndex].data();
for (int i = 0; i < chunks[playerIndex].length; i++, pClipChunk++) { for (int i = 0; i < chunks[playerIndex].size(); i++, pClipChunk++) {
if (pClipChunk->chunk->y == 0) { if (pClipChunk->chunk->y == 0) {
bool chunkPresent = level[0]->reallyHasChunk( bool chunkPresent = level[0]->reallyHasChunk(
pClipChunk->chunk->x >> 4, pClipChunk->chunk->z >> 4); pClipChunk->chunk->x >> 4, pClipChunk->chunk->z >> 4);

View file

@ -170,7 +170,7 @@ private:
Textures* textures; Textures* textures;
// std::vector<Chunk *> *sortedChunks[4]; // 4J - removed - not // std::vector<Chunk *> *sortedChunks[4]; // 4J - removed - not
// sorting our chunks anymore // sorting our chunks anymore
ClipChunkArray chunks[4]; // 4J - now one per player std::vector<ClipChunk> chunks[4]; // 4J - now one per player
int lastPlayerCount[4]; // 4J - added int lastPlayerCount[4]; // 4J - added
int xChunks, yChunks, zChunks; int xChunks, yChunks, zChunks;
int chunkLists; int chunkLists;

View file

@ -63,7 +63,7 @@ Tesselator::Tesselator(int size) {
this->size = size; this->size = size;
_array = new intArray(size); _array = new std::vector<int>(size);
vboMode = vboMode =
USE_VBO; // 4J removed - && USE_VBO; // 4J removed - &&
@ -91,7 +91,7 @@ void Tesselator::end() {
// 0xffffffff) so DrawVertices skips glColor for these vertices, // 0xffffffff) so DrawVertices skips glColor for these vertices,
// letting any caller-set GL colour (e.g. sky colour) pass through // letting any caller-set GL colour (e.g. sky colour) pass through
// unmodified. // unmodified.
unsigned int* pColData = (unsigned int*)_array->data; unsigned int* pColData = (unsigned int*)_array->data();
pColData += 5; pColData += 5;
for (int i = 0; i < vertices; i++) { for (int i = 0; i < vertices; i++) {
*pColData = 0x00000000; *pColData = 0x00000000;
@ -101,7 +101,7 @@ void Tesselator::end() {
if (mode == GL_QUADS && TRIANGLE_MODE) { if (mode == GL_QUADS && TRIANGLE_MODE) {
// glDrawArrays(GL_TRIANGLES, 0, vertices); // 4J - changed for xbox // glDrawArrays(GL_TRIANGLES, 0, vertices); // 4J - changed for xbox
RenderManager.DrawVertices( RenderManager.DrawVertices(
C4JRender::PRIMITIVE_TYPE_TRIANGLE_LIST, vertices, _array->data, C4JRender::PRIMITIVE_TYPE_TRIANGLE_LIST, vertices, _array->data(),
useCompactFormat360 useCompactFormat360
? C4JRender::VERTEX_TYPE_COMPRESSED ? C4JRender::VERTEX_TYPE_COMPRESSED
: C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, : C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1,
@ -118,20 +118,20 @@ void Tesselator::end() {
int vertexCount = vertices; int vertexCount = vertices;
if (useCompactFormat360) { if (useCompactFormat360) {
RenderManager.DrawVertices( RenderManager.DrawVertices(
(C4JRender::ePrimitiveType)mode, vertexCount, _array->data, (C4JRender::ePrimitiveType)mode, vertexCount, _array->data(),
C4JRender::VERTEX_TYPE_COMPRESSED, C4JRender::VERTEX_TYPE_COMPRESSED,
C4JRender::PIXEL_SHADER_TYPE_STANDARD); C4JRender::PIXEL_SHADER_TYPE_STANDARD);
} else { } else {
if (useProjectedTexturePixelShader) { if (useProjectedTexturePixelShader) {
RenderManager.DrawVertices( RenderManager.DrawVertices(
(C4JRender::ePrimitiveType)mode, vertexCount, (C4JRender::ePrimitiveType)mode, vertexCount,
_array->data, _array->data(),
C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN, C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN,
C4JRender::PIXEL_SHADER_TYPE_PROJECTION); C4JRender::PIXEL_SHADER_TYPE_PROJECTION);
} else { } else {
RenderManager.DrawVertices( RenderManager.DrawVertices(
(C4JRender::ePrimitiveType)mode, vertexCount, (C4JRender::ePrimitiveType)mode, vertexCount,
_array->data, _array->data(),
C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1, C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1,
C4JRender::PIXEL_SHADER_TYPE_STANDARD); C4JRender::PIXEL_SHADER_TYPE_STANDARD);
} }
@ -321,7 +321,7 @@ void Tesselator::packCompactQuad() {
m_iz[i] -= basez << 7; m_iz[i] -= basez << 7;
} }
// Now write the data out // Now write the data out
unsigned int* data = (unsigned int*)&_array->data[p]; unsigned int* data = (unsigned int*)&_array->data()[p];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
data[i * 2 + 0] = (m_ix[i] << 8) | (m_iy[i]); data[i * 2 + 0] = (m_ix[i] << 8) | (m_iy[i]);
@ -454,7 +454,7 @@ void Tesselator::vertex(float x, float y, float z) {
ipackedcol -= 32768; // -32768 to 32767 range ipackedcol -= 32768; // -32768 to 32767 range
ipackedcol &= 0xffff; ipackedcol &= 0xffff;
std::int16_t* pShortData = (std::int16_t*)&_array->data[p]; std::int16_t* pShortData = (std::int16_t*)&_array->data()[p];
pShortData[0] = (((int)((x + xo) * 1024.0f)) & 0xffff); pShortData[0] = (((int)((x + xo) * 1024.0f)) & 0xffff);
pShortData[1] = (((int)((y + yo) * 1024.0f)) & 0xffff); pShortData[1] = (((int)((y + yo) * 1024.0f)) & 0xffff);
@ -490,16 +490,16 @@ void Tesselator::vertex(float x, float y, float z) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
int offs = 8 * (3 - i); int offs = 8 * (3 - i);
if (hasTexture) { if (hasTexture) {
_array->data[p + 3] = _array->data[p - offs + 3]; _array->data()[p + 3] = _array->data()[p - offs + 3];
_array->data[p + 4] = _array->data[p - offs + 4]; _array->data()[p + 4] = _array->data()[p - offs + 4];
} }
if (hasColor) { if (hasColor) {
_array->data[p + 5] = _array->data[p - offs + 5]; _array->data()[p + 5] = _array->data()[p - offs + 5];
} }
_array->data[p + 0] = _array->data[p - offs + 0]; _array->data()[p + 0] = _array->data()[p - offs + 0];
_array->data[p + 1] = _array->data[p - offs + 1]; _array->data()[p + 1] = _array->data()[p - offs + 1];
_array->data[p + 2] = _array->data[p - offs + 2]; _array->data()[p + 2] = _array->data()[p - offs + 2];
vertices++; vertices++;
p += 8; p += 8;
@ -507,15 +507,15 @@ void Tesselator::vertex(float x, float y, float z) {
} }
if (hasTexture) { if (hasTexture) {
float* fdata = (float*)(_array->data + p + 3); float* fdata = (float*)(_array->data() + p + 3);
*fdata++ = uu; *fdata++ = uu;
*fdata++ = v; *fdata++ = v;
} }
if (hasColor) { if (hasColor) {
_array->data[p + 5] = col; _array->data()[p + 5] = col;
} }
if (hasNormal) { if (hasNormal) {
_array->data[p + 6] = _normal; _array->data()[p + 6] = _normal;
} }
if (hasTexture2) { if (hasTexture2) {
// 4jcraft: we will be lighting the blocks right in here // 4jcraft: we will be lighting the blocks right in here
@ -524,20 +524,20 @@ void Tesselator::vertex(float x, float y, float z) {
std::int16_t tex2V; std::int16_t tex2V;
packLinuxLightmapCoords(_tex2, tex2U, tex2V); packLinuxLightmapCoords(_tex2, tex2U, tex2V);
logLinuxPackedLightmapCoords("standard", _tex2, tex2U, tex2V); logLinuxPackedLightmapCoords("standard", _tex2, tex2U, tex2V);
std::int16_t* pShortArray = (std::int16_t*)&_array->data[p + 7]; std::int16_t* pShortArray = (std::int16_t*)&_array->data()[p + 7];
pShortArray[0] = tex2U; pShortArray[0] = tex2U;
pShortArray[1] = tex2V; pShortArray[1] = tex2V;
#else #else
_array->data[p + 7] = _tex2; _array->data()[p + 7] = _tex2;
#endif #endif
} else { } else {
// -512 each for u/v will mean that the renderer will use global // -512 each for u/v will mean that the renderer will use global
// settings (set via RenderManager.StateSetVertexTextureUV) rather // settings (set via RenderManager.StateSetVertexTextureUV) rather
// than these local ones // than these local ones
*(unsigned int*)(&_array->data[p + 7]) = 0xfe00fe00; *(unsigned int*)(&_array->data()[p + 7]) = 0xfe00fe00;
} }
float* fdata = (float*)(_array->data + p); float* fdata = (float*)(_array->data() + p);
*fdata++ = (x + xo); *fdata++ = (x + xo);
*fdata++ = (y + yo); *fdata++ = (y + yo);
*fdata++ = (z + zo); *fdata++ = (z + zo);

View file

@ -13,7 +13,7 @@ private:
static const int MAX_MEMORY_USE = 16 * 1024 * 1024; static const int MAX_MEMORY_USE = 16 * 1024 * 1024;
static const int MAX_FLOATS = MAX_MEMORY_USE / 4 / 2; static const int MAX_FLOATS = MAX_MEMORY_USE / 4 / 2;
intArray* _array; std::vector<int>* _array;
int vertices; int vertices;
float u, v; float u, v;

View file

@ -330,21 +330,20 @@ void Textures::loadIndexedTextures() {
} }
} }
intArray Textures::loadTexturePixels(TEXTURE_NAME texId, std::vector<int> Textures::loadTexturePixels(TEXTURE_NAME texId,
const std::wstring& resourceName) { const std::wstring& resourceName) {
TexturePack* skin = skins->getSelected(); TexturePack* skin = skins->getSelected();
{ {
intArray id = pixelsMap[resourceName]; std::vector<int> id = pixelsMap[resourceName];
// 4J - if resourceName isn't in the map, it should add an element and // 4J - if resourceName isn't in the map, it should add an element and
// as that will use the default constructor, its internal data pointer // as that will use the default constructor, its vector will be empty
// will be nullptr if (!id.empty()) return id;
if (id.data != nullptr) return id;
} }
// 4J - removed try/catch // 4J - removed try/catch
// try { // try {
intArray res; std::vector<int> res;
// wstring in = skin->getResource(resourceName); // wstring in = skin->getResource(resourceName);
if (false) // 4J - removed - was ( in == nullptr) if (false) // 4J - removed - was ( in == nullptr)
{ {
@ -368,14 +367,14 @@ intArray Textures::loadTexturePixels(TEXTURE_NAME texId,
*/ */
} }
intArray Textures::loadTexturePixels(BufferedImage* img) { std::vector<int> Textures::loadTexturePixels(BufferedImage* img) {
int w = img->getWidth(); int w = img->getWidth();
int h = img->getHeight(); int h = img->getHeight();
intArray pixels(w * h); std::vector<int> pixels(w * h);
return loadTexturePixels(img, pixels); return loadTexturePixels(img, pixels);
} }
intArray Textures::loadTexturePixels(BufferedImage* img, intArray pixels) { std::vector<int> Textures::loadTexturePixels(BufferedImage* img, std::vector<int>& pixels) {
int w = img->getWidth(); int w = img->getWidth();
int h = img->getHeight(); int h = img->getHeight();
img->getRGB(0, 0, w, h, pixels, 0, w); img->getRGB(0, 0, w, h, pixels, 0, w);
@ -442,7 +441,7 @@ void Textures::bindTextureLayers(ResourceLocation* resource) {
} else { } else {
// Cache by layer signature so the merge cost is only paid once per // Cache by layer signature so the merge cost is only paid once per
// horse texture combination. // horse texture combination.
intArray mergedPixels; std::vector<int> mergedPixels;
int mergedWidth = 0; int mergedWidth = 0;
int mergedHeight = 0; int mergedHeight = 0;
bool hasMergedPixels = false; bool hasMergedPixels = false;
@ -461,14 +460,14 @@ void Textures::bindTextureLayers(ResourceLocation* resource) {
int width = image->getWidth(); int width = image->getWidth();
int height = image->getHeight(); int height = image->getHeight();
intArray layerPixels = loadTexturePixels(image); std::vector<int> layerPixels = loadTexturePixels(image);
delete image; delete image;
if (!hasMergedPixels) { if (!hasMergedPixels) {
mergedWidth = width; mergedWidth = width;
mergedHeight = height; mergedHeight = height;
mergedPixels = intArray(width * height); mergedPixels = std::vector<int>(width * height);
memcpy(mergedPixels.data, layerPixels.data, memcpy(mergedPixels.data(), layerPixels.data(),
width * height * sizeof(int)); width * height * sizeof(int));
hasMergedPixels = true; hasMergedPixels = true;
} else if (width == mergedWidth && height == mergedHeight) { } else if (width == mergedWidth && height == mergedHeight) {
@ -506,15 +505,13 @@ void Textures::bindTextureLayers(ResourceLocation* resource) {
} }
} }
delete[] layerPixels.data;
} }
if (hasMergedPixels) { if (hasMergedPixels) {
BufferedImage* mergedImage = new BufferedImage( BufferedImage* mergedImage = new BufferedImage(
mergedWidth, mergedHeight, BufferedImage::TYPE_INT_ARGB); mergedWidth, mergedHeight, BufferedImage::TYPE_INT_ARGB);
memcpy(mergedImage->getData(), mergedPixels.data, memcpy(mergedImage->getData(), mergedPixels.data(),
mergedWidth * mergedHeight * sizeof(int)); mergedWidth * mergedHeight * sizeof(int));
delete[] mergedPixels.data;
id = getTexture(mergedImage, C4JRender::TEXTURE_FORMAT_RxGyBzAw, id = getTexture(mergedImage, C4JRender::TEXTURE_FORMAT_RxGyBzAw,
false); false);
} else { } else {
@ -699,15 +696,15 @@ void Textures::loadTexture(BufferedImage* img, int id, bool blur, bool clamp) {
int w = img->getWidth(); int w = img->getWidth();
int h = img->getHeight(); int h = img->getHeight();
intArray rawPixels(w * h); std::vector<int> rawPixels(w * h);
img->getRGB(0, 0, w, h, rawPixels, 0, w); img->getRGB(0, 0, w, h, rawPixels, 0, w);
if (options != nullptr && options->anaglyph3d) { if (options != nullptr && options->anaglyph3d) {
rawPixels = anaglyph(rawPixels); rawPixels = anaglyph(rawPixels);
} }
byteArray newPixels(w * h * 4); std::vector<uint8_t> newPixels(w * h * 4);
for (unsigned int i = 0; i < rawPixels.length; i++) { for (unsigned int i = 0; i < rawPixels.size(); i++) {
int a = (rawPixels[i] >> 24) & 0xff; int a = (rawPixels[i] >> 24) & 0xff;
int r = (rawPixels[i] >> 16) & 0xff; int r = (rawPixels[i] >> 16) & 0xff;
int g = (rawPixels[i] >> 8) & 0xff; int g = (rawPixels[i] >> 8) & 0xff;
@ -722,10 +719,8 @@ void Textures::loadTexture(BufferedImage* img, int id, bool blur, bool clamp) {
ByteBuffer* pixels = MemoryTracker::createByteBuffer(w * h * 4); ByteBuffer* pixels = MemoryTracker::createByteBuffer(w * h * 4);
pixels->clear(); pixels->clear();
pixels->put(newPixels); pixels->put(newPixels);
pixels->position(0)->limit(newPixels.length); pixels->position(0)->limit(newPixels.size());
delete[] rawPixels.data;
delete[] newPixels.data;
if (MIPMAP) { if (MIPMAP) {
// 4J-PB - In the new XDK, the CreateTexture will fail if the number of // 4J-PB - In the new XDK, the CreateTexture will fail if the number of
@ -810,9 +805,9 @@ void Textures::loadTexture(BufferedImage* img, int id, bool blur, bool clamp) {
MemSect(0); MemSect(0);
} }
intArray Textures::anaglyph(intArray rawPixels) { std::vector<int> Textures::anaglyph(std::vector<int>& rawPixels) {
intArray result(rawPixels.length); std::vector<int> result(rawPixels.size());
for (unsigned int i = 0; i < rawPixels.length; i++) { for (unsigned int i = 0; i < rawPixels.size(); i++) {
int a = (rawPixels[i] >> 24) & 0xff; int a = (rawPixels[i] >> 24) & 0xff;
int r = (rawPixels[i] >> 16) & 0xff; int r = (rawPixels[i] >> 16) & 0xff;
int g = (rawPixels[i] >> 8) & 0xff; int g = (rawPixels[i] >> 8) & 0xff;
@ -825,12 +820,11 @@ intArray Textures::anaglyph(intArray rawPixels) {
result[i] = a << 24 | rr << 16 | gg << 8 | bb; result[i] = a << 24 | rr << 16 | gg << 8 | bb;
} }
delete[] rawPixels.data;
return result; return result;
} }
void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) { void Textures::replaceTexture(std::vector<int>& rawPixels, int w, int h, int id) {
bind(id); bind(id);
// Removed in Java // Removed in Java
@ -846,8 +840,8 @@ void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) {
rawPixels = anaglyph(rawPixels); rawPixels = anaglyph(rawPixels);
} }
byteArray newPixels(w * h * 4); std::vector<uint8_t> newPixels(w * h * 4);
for (unsigned int i = 0; i < rawPixels.length; i++) { for (unsigned int i = 0; i < rawPixels.size(); i++) {
int a = (rawPixels[i] >> 24) & 0xff; int a = (rawPixels[i] >> 24) & 0xff;
int r = (rawPixels[i] >> 16) & 0xff; int r = (rawPixels[i] >> 16) & 0xff;
int g = (rawPixels[i] >> 8) & 0xff; int g = (rawPixels[i] >> 8) & 0xff;
@ -871,8 +865,7 @@ void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) {
ByteBuffer* pixels = MemoryTracker::createByteBuffer( ByteBuffer* pixels = MemoryTracker::createByteBuffer(
w * h * 4); // 4J - now creating dynamically w * h * 4); // 4J - now creating dynamically
pixels->put(newPixels); pixels->put(newPixels);
pixels->position(0)->limit(newPixels.length); pixels->position(0)->limit(newPixels.size());
delete[] newPixels.data;
// New // New
// glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL12.GL_BGRA, // glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL12.GL_BGRA,
@ -887,7 +880,7 @@ void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) {
// 4J - added. This is a more minimal version of replaceTexture that assumes the // 4J - added. This is a more minimal version of replaceTexture that assumes the
// texture bytes are already in order, and so doesn't do any of the extra // texture bytes are already in order, and so doesn't do any of the extra
// copying round that the original java version does // copying round that the original java version does
void Textures::replaceTextureDirect(intArray rawPixels, int w, int h, int id) { void Textures::replaceTextureDirect(const std::vector<int>& rawPixels, int w, int h, int id) {
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
// Remove in Java // Remove in Java
@ -899,13 +892,13 @@ void Textures::replaceTextureDirect(intArray rawPixels, int w, int h, int id) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
RenderManager.TextureDataUpdate(0, 0, w, h, rawPixels.data, 0); RenderManager.TextureDataUpdate(0, 0, w, h, const_cast<int*>(rawPixels.data()), 0);
} }
// 4J - added. This is a more minimal version of replaceTexture that assumes the // 4J - added. This is a more minimal version of replaceTexture that assumes the
// texture bytes are already in order, and so doesn't do any of the extra // texture bytes are already in order, and so doesn't do any of the extra
// copying round that the original java version does // copying round that the original java version does
void Textures::replaceTextureDirect(shortArray rawPixels, int w, int h, void Textures::replaceTextureDirect(const std::vector<short>& rawPixels, int w, int h,
int id) { int id) {
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
@ -918,7 +911,7 @@ void Textures::replaceTextureDirect(shortArray rawPixels, int w, int h,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
RenderManager.TextureDataUpdate(0, 0, w, h, rawPixels.data, 0); RenderManager.TextureDataUpdate(0, 0, w, h, const_cast<short*>(rawPixels.data()), 0);
} }
void Textures::releaseTexture(int id) { void Textures::releaseTexture(int id) {

View file

@ -274,7 +274,7 @@ private:
static int preLoadedIdx[TN_COUNT]; static int preLoadedIdx[TN_COUNT];
std::unordered_map<std::wstring, int> idMap; std::unordered_map<std::wstring, int> idMap;
std::unordered_map<std::wstring, intArray> pixelsMap; std::unordered_map<std::wstring, std::vector<int>> pixelsMap;
std::unordered_map<int, BufferedImage*> loadedImages; std::unordered_map<int, BufferedImage*> loadedImages;
// IntBuffer *pixels; // 4J - removed so we don't have a permanent // IntBuffer *pixels; // 4J - removed so we don't have a permanent
// buffer kicking round using up 1MB // buffer kicking round using up 1MB
@ -299,12 +299,12 @@ private:
void loadIndexedTextures(); // 4J Added void loadIndexedTextures(); // 4J Added
public: public:
intArray loadTexturePixels(TEXTURE_NAME texId, std::vector<int> loadTexturePixels(TEXTURE_NAME texId,
const std::wstring& resourceName); const std::wstring& resourceName);
private: private:
intArray loadTexturePixels(BufferedImage* img); std::vector<int> loadTexturePixels(BufferedImage* img);
intArray loadTexturePixels(BufferedImage* img, intArray pixels); std::vector<int> loadTexturePixels(BufferedImage* img, std::vector<int>& pixels);
void setTextureFormat(const std::wstring& resourceName); // 4J added void setTextureFormat(const std::wstring& resourceName); // 4J added
public: public:
@ -334,13 +334,13 @@ public:
void loadTexture(BufferedImage* img, int id, bool blur, bool clamp); void loadTexture(BufferedImage* img, int id, bool blur, bool clamp);
private: private:
intArray anaglyph(intArray rawPixels); std::vector<int> anaglyph(std::vector<int>& rawPixels);
public: public:
void replaceTexture(intArray rawPixels, int w, int h, int id); void replaceTexture(std::vector<int>& rawPixels, int w, int h, int id);
void replaceTextureDirect(intArray rawPixels, int w, int h, void replaceTextureDirect(const std::vector<int>& rawPixels, int w, int h,
int id); // 4J added as optimisation int id); // 4J added as optimisation
void replaceTextureDirect(shortArray rawPixels, int w, int h, void replaceTextureDirect(const std::vector<short>& rawPixels, int w, int h,
int id); // 4J added as optimisation int id); // 4J added as optimisation
void releaseTexture(int id); void releaseTexture(int id);
int loadHttpTexture(const std::wstring& url, const std::wstring& backup); int loadHttpTexture(const std::wstring& url, const std::wstring& backup);

View file

@ -49,14 +49,14 @@ void Frustum::calculateFrustum() {
// queries. // queries.
// Camera::prepare() already captures both matrices every frame :) // Camera::prepare() already captures both matrices every frame :)
// i spent an ungodly amount of time on this simple fix. // i spent an ungodly amount of time on this simple fix.
memcpy(proj.data, RenderManager.MatrixGet(GL_PROJECTION_MATRIX), memcpy(proj.data(), RenderManager.MatrixGet(GL_PROJECTION_MATRIX),
16 * sizeof(float)); 16 * sizeof(float));
memcpy(modl.data, RenderManager.MatrixGet(GL_MODELVIEW_MATRIX), memcpy(modl.data(), RenderManager.MatrixGet(GL_MODELVIEW_MATRIX),
16 * sizeof(float)); 16 * sizeof(float));
float* p = proj.data; float* p = proj.data();
float* m = modl.data; float* m = modl.data();
float* c = clip.data; float* c = clip.data();
c[0] = m[0] * p[0] + m[1] * p[4] + m[2] * p[8] + m[3] * p[12]; c[0] = m[0] * p[0] + m[1] * p[4] + m[2] * p[8] + m[3] * p[12];
c[1] = m[0] * p[1] + m[1] * p[5] + m[2] * p[9] + m[3] * p[13]; c[1] = m[0] * p[1] + m[1] * p[5] + m[2] * p[9] + m[3] * p[13];

View file

@ -8,15 +8,12 @@ FrustumData::FrustumData() {
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
this->m_Frustum[i] = new float[4]; this->m_Frustum[i] = new float[4];
} }
proj = floatArray(16); proj = std::vector<float>(16);
modl = floatArray(16); modl = std::vector<float>(16);
clip = floatArray(16); clip = std::vector<float>(16);
} }
FrustumData::~FrustumData() { FrustumData::~FrustumData() {
delete[] proj.data;
delete[] modl.data;
delete[] clip.data;
for (int i = 0; i < 6; i++) delete[] m_Frustum[i]; for (int i = 0; i < 6; i++) delete[] m_Frustum[i];
delete[] m_Frustum; delete[] m_Frustum;
} }

View file

@ -19,9 +19,9 @@ public:
static const int D = 3; // The distance the plane is from the origin static const int D = 3; // The distance the plane is from the origin
float** m_Frustum; float** m_Frustum;
floatArray proj; std::vector<float> proj;
floatArray modl; std::vector<float> modl;
floatArray clip; std::vector<float> clip;
FrustumData(); FrustumData();
~FrustumData(); ~FrustumData();

View file

@ -30,7 +30,7 @@ void EnderDragonRenderer::setupRotations(std::shared_ptr<LivingEntity> _mob,
// 4J - reorganised a bit so we can free allocations // 4J - reorganised a bit so we can free allocations
double lpComponents[3]; double lpComponents[3];
doubleArray lp = doubleArray(lpComponents, 3); std::vector<double> lp = std::vector<double>(lpComponents, lpComponents + 3);
mob->getLatencyPos(lp, 7, a); mob->getLatencyPos(lp, 7, a);
float yr = lp[0]; float yr = lp[0];
// mob->getLatencyPos(lp, 5, a); // mob->getLatencyPos(lp, 5, a);

View file

@ -72,7 +72,7 @@ void Stitcher::stitch() {
stitchedTexture = nullptr; stitchedTexture = nullptr;
// for (int i = 0; i < textureHolders.length; i++) // for (int i = 0; i < textureHolders.size(); i++)
for (auto it = texturesToBeStitched.begin(); for (auto it = texturesToBeStitched.begin();
it != texturesToBeStitched.end(); ++it) { it != texturesToBeStitched.end(); ++it) {
TextureHolder* textureHolder = *it; // textureHolders[i]; TextureHolder* textureHolder = *it; // textureHolders[i];

View file

@ -88,33 +88,31 @@ void Texture::_init(const std::wstring& name, int mode, int width, int height,
if (width == -1 || height == -1) { if (width == -1 || height == -1) {
valid = false; valid = false;
} else { } else {
byteArray tempBytes = byteArray(width * height * depth * 4); std::vector<uint8_t> tempBytes = std::vector<uint8_t>(width * height * depth * 4);
for (int index = 0; index < tempBytes.length; index++) { for (int index = 0; index < tempBytes.size(); index++) {
tempBytes[index] = 0; tempBytes[index] = 0;
} }
data[0] = ByteBuffer::allocateDirect(tempBytes.length); data[0] = ByteBuffer::allocateDirect(tempBytes.size());
data[0]->clear(); data[0]->clear();
data[0]->put(tempBytes); data[0]->put(tempBytes);
data[0]->position(0)->limit(tempBytes.length); data[0]->position(0)->limit(tempBytes.size());
delete[] tempBytes.data;
if (mipmapped) { if (mipmapped) {
for (unsigned int level = 1; level < m_iMipLevels; ++level) { for (unsigned int level = 1; level < m_iMipLevels; ++level) {
int ww = width >> level; int ww = width >> level;
int hh = height >> level; int hh = height >> level;
byteArray tempBytes = byteArray(ww * hh * depth * 4); std::vector<uint8_t> tempBytes = std::vector<uint8_t>(ww * hh * depth * 4);
for (int index = 0; index < tempBytes.length; index++) { for (int index = 0; index < tempBytes.size(); index++) {
tempBytes[index] = 0; tempBytes[index] = 0;
} }
data[level] = ByteBuffer::allocateDirect(tempBytes.length); data[level] = ByteBuffer::allocateDirect(tempBytes.size());
data[level]->clear(); data[level]->clear();
data[level]->put(tempBytes); data[level]->put(tempBytes);
data[level]->position(0)->limit(tempBytes.length); data[level]->position(0)->limit(tempBytes.size());
delete[] tempBytes.data;
} }
} }
@ -265,7 +263,7 @@ void Texture::blit(int x, int y, Texture* source, bool rotated) {
} }
} }
void Texture::transferFromBuffer(intArray buffer) { void Texture::transferFromBuffer(const std::vector<int>& buffer) {
// if (depth == 1) { // if (depth == 1) {
// return; // return;
// } // }
@ -353,11 +351,11 @@ void Texture::transferFromImage(BufferedImage* image) {
// #endif // #endif
int* byteRemap = ((format == TFMT_BGRA) ? byteRemapBGRA : byteRemapRGBA); int* byteRemap = ((format == TFMT_BGRA) ? byteRemapBGRA : byteRemapRGBA);
intArray tempPixels = intArray(width * height); std::vector<int> tempPixels = std::vector<int>(width * height);
int transparency = image->getTransparency(); int transparency = image->getTransparency();
image->getRGB(0, 0, width, height, tempPixels, 0, imgWidth); image->getRGB(0, 0, width, height, tempPixels, 0, imgWidth);
byteArray tempBytes = byteArray(width * height * 4); std::vector<uint8_t> tempBytes = std::vector<uint8_t>(width * height * 4);
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
int intIndex = y * width + x; int intIndex = y * width + x;
@ -384,13 +382,12 @@ void Texture::transferFromImage(BufferedImage* image) {
} }
MemSect(51); MemSect(51);
data[0] = ByteBuffer::allocateDirect(tempBytes.length); data[0] = ByteBuffer::allocateDirect(tempBytes.size());
MemSect(0); MemSect(0);
data[0]->clear(); data[0]->clear();
data[0]->put(tempBytes); data[0]->put(tempBytes);
data[0]->limit(tempBytes.length); data[0]->limit(tempBytes.size());
delete[] tempBytes.data;
if (mipmapped || image->getData(1) != nullptr) { if (mipmapped || image->getData(1) != nullptr) {
mipmapped = true; mipmapped = true;
@ -398,7 +395,7 @@ void Texture::transferFromImage(BufferedImage* image) {
int ww = width >> level; int ww = width >> level;
int hh = height >> level; int hh = height >> level;
byteArray tempBytes = byteArray(ww * hh * 4); std::vector<uint8_t> tempBytes = std::vector<uint8_t>(ww * hh * 4);
unsigned int* tempData = new unsigned int[ww * hh]; unsigned int* tempData = new unsigned int[ww * hh];
if (image->getData(level)) { if (image->getData(level)) {
@ -469,17 +466,15 @@ void Texture::transferFromImage(BufferedImage* image) {
} }
MemSect(51); MemSect(51);
data[level] = ByteBuffer::allocateDirect(tempBytes.length); data[level] = ByteBuffer::allocateDirect(tempBytes.size());
MemSect(0); MemSect(0);
data[level]->clear(); data[level]->clear();
data[level]->put(tempBytes); data[level]->put(tempBytes);
data[level]->limit(tempBytes.length); data[level]->limit(tempBytes.size());
delete[] tempBytes.data;
delete[] tempData; delete[] tempData;
} }
} }
delete[] tempPixels.data;
if (immediateUpdate) { if (immediateUpdate) {
updateOnGPU(); updateOnGPU();

View file

@ -87,7 +87,7 @@ public:
void writeAsPNG(const std::wstring& filename); void writeAsPNG(const std::wstring& filename);
void blit(int x, int y, Texture* source); void blit(int x, int y, Texture* source);
void blit(int x, int y, Texture* source, bool rotated); void blit(int x, int y, Texture* source, bool rotated);
void transferFromBuffer(intArray buffer); void transferFromBuffer(const std::vector<int>& buffer);
void transferFromImage(BufferedImage* image); void transferFromImage(BufferedImage* image);
int getManagerId(); int getManagerId();
int getGlId(); int getGlId();

View file

@ -64,7 +64,7 @@ void SignRenderer::render(std::shared_ptr<TileEntity> _sign, double x, double y,
// Get the current language setting from the console // Get the current language setting from the console
std::uint32_t dwLanguage = XGetLanguage(); std::uint32_t dwLanguage = XGetLanguage();
for (int i = 0; i < MAX_SIGN_LINES; i++) // 4J - was sign.messages.length for (int i = 0; i < MAX_SIGN_LINES; i++) // 4J - was sign.messages.size()
{ {
if (sign->IsVerified()) { if (sign->IsVerified()) {
if (sign->IsCensored()) { if (sign->IsCensored()) {
@ -99,11 +99,11 @@ void SignRenderer::render(std::shared_ptr<TileEntity> _sign, double x, double y,
msg = L"> " + msg + L" <"; msg = L"> " + msg + L" <";
font->draw(msg, -font->width(msg) / 2, font->draw(msg, -font->width(msg) / 2,
i * 10 - (MAX_SIGN_LINES) * 5, i * 10 - (MAX_SIGN_LINES) * 5,
col); // 4J - (MAX_SIGN_LINES) was sign.messages.length col); // 4J - (MAX_SIGN_LINES) was sign.messages.size()
} else { } else {
font->draw(msg, -font->width(msg) / 2, font->draw(msg, -font->width(msg) / 2,
i * 10 - (MAX_SIGN_LINES) * 5, i * 10 - (MAX_SIGN_LINES) * 5,
col); // 4J - (MAX_SIGN_LINES) was sign.messages.length col); // 4J - (MAX_SIGN_LINES) was sign.messages.size()
} }
} }
glDepthMask(true); glDepthMask(true);

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "../renderer/Textures.h" #include "../renderer/Textures.h"
typedef arrayWithLength<_TEXTURE_NAME> textureNameArray; typedef std::vector<_TEXTURE_NAME> textureNameArray;
class ResourceLocation { class ResourceLocation {
private: private:
textureNameArray m_texture; textureNameArray m_texture;
@ -15,8 +15,7 @@ public:
} }
ResourceLocation(_TEXTURE_NAME texture) { ResourceLocation(_TEXTURE_NAME texture) {
m_texture = textureNameArray(1); m_texture = {texture};
m_texture[0] = texture;
m_preloaded = true; m_preloaded = true;
} }
@ -25,23 +24,23 @@ public:
m_preloaded = false; m_preloaded = false;
} }
ResourceLocation(intArray textures) { ResourceLocation(std::vector<int> textures) {
m_texture = textureNameArray(textures.length); m_texture.resize(textures.size());
for (unsigned int i = 0; i < textures.length; ++i) { for (unsigned int i = 0; i < textures.size(); ++i) {
m_texture[i] = (_TEXTURE_NAME)textures[i]; m_texture[i] = (_TEXTURE_NAME)textures[i];
} }
m_preloaded = true; m_preloaded = true;
} }
~ResourceLocation() { delete m_texture.data; } ~ResourceLocation() = default;
_TEXTURE_NAME getTexture() { return m_texture[0]; } _TEXTURE_NAME getTexture() { return m_texture[0]; }
_TEXTURE_NAME getTexture(int idx) { return m_texture[idx]; } _TEXTURE_NAME getTexture(int idx) { return m_texture[idx]; }
int getTextureCount() { return m_texture.length; } int getTextureCount() { return m_texture.size(); }
std::wstring getPath() { return m_path; } std::wstring getPath() { return m_path; }
bool isPreloaded() { return m_preloaded; } bool isPreloaded() { return m_preloaded; }
}; };

View file

@ -169,15 +169,14 @@ void AbstractTexturePack::loadDefaultColourTable() {
if (coloursFile.exists()) { if (coloursFile.exists()) {
uint32_t dataLength = coloursFile.length(); uint32_t dataLength = coloursFile.length();
byteArray data(dataLength); std::vector<uint8_t> data(dataLength);
FileInputStream fis(coloursFile); FileInputStream fis(coloursFile);
fis.read(data, 0, dataLength); fis.read(data, 0, dataLength);
fis.close(); fis.close();
if (m_colourTable != nullptr) delete m_colourTable; if (m_colourTable != nullptr) delete m_colourTable;
m_colourTable = new ColourTable(data.data, dataLength); m_colourTable = new ColourTable(data.data(), dataLength);
delete[] data.data;
} else { } else {
app.DebugPrintf("Failed to load the default colours table\n"); app.DebugPrintf("Failed to load the default colours table\n");
app.FatalLoadError(); app.FatalLoadError();
@ -186,11 +185,10 @@ void AbstractTexturePack::loadDefaultColourTable() {
void AbstractTexturePack::loadDefaultHTMLColourTable() { void AbstractTexturePack::loadDefaultHTMLColourTable() {
if (app.hasArchiveFile(L"HTMLColours.col")) { if (app.hasArchiveFile(L"HTMLColours.col")) {
byteArray textColours = app.getArchiveFile(L"HTMLColours.col"); std::vector<uint8_t> textColours = app.getArchiveFile(L"HTMLColours.col");
m_colourTable->loadColoursFromData(textColours.data, m_colourTable->loadColoursFromData(textColours.data(),
textColours.length); textColours.size());
delete[] textColours.data;
} }
} }

View file

@ -207,11 +207,10 @@ void DLCTexturePack::loadColourTable() {
// Load the text colours // Load the text colours
if (app.hasArchiveFile(L"HTMLColours.col")) { if (app.hasArchiveFile(L"HTMLColours.col")) {
byteArray textColours = app.getArchiveFile(L"HTMLColours.col"); std::vector<uint8_t> textColours = app.getArchiveFile(L"HTMLColours.col");
m_colourTable->loadColoursFromData(textColours.data, m_colourTable->loadColoursFromData(textColours.data(),
textColours.length); textColours.size());
delete[] textColours.data;
} }
} }

View file

@ -14,9 +14,9 @@ DefaultTexturePack::DefaultTexturePack()
void DefaultTexturePack::loadIcon() { void DefaultTexturePack::loadIcon() {
if (app.hasArchiveFile(L"Graphics\\TexturePackIcon.png")) { if (app.hasArchiveFile(L"Graphics\\TexturePackIcon.png")) {
byteArray ba = app.getArchiveFile(L"Graphics\\TexturePackIcon.png"); std::vector<uint8_t> ba = app.getArchiveFile(L"Graphics\\TexturePackIcon.png");
m_iconData = ba.data; m_iconData = ba.data();
m_iconSize = static_cast<std::uint32_t>(ba.length); m_iconSize = static_cast<std::uint32_t>(ba.size());
} }
} }

View file

@ -30,7 +30,7 @@ TitleScreen::TitleScreen() {
std::wstring filename = L"splashes.txt"; std::wstring filename = L"splashes.txt";
if (app.hasArchiveFile(filename)) { if (app.hasArchiveFile(filename)) {
byteArray splashesArray = app.getArchiveFile(filename); std::vector<uint8_t> splashesArray = app.getArchiveFile(filename);
ByteArrayInputStream bais(splashesArray); ByteArrayInputStream bais(splashesArray);
InputStreamReader isr(&bais); InputStreamReader isr(&bais);
BufferedReader br(&isr); BufferedReader br(&isr);

View file

@ -339,7 +339,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource,
ProgressRenderer* mcprogress = Minecraft::GetInstance()->progressRenderer; ProgressRenderer* mcprogress = Minecraft::GetInstance()->progressRenderer;
// 4J TODO - free levels here if there are already some? // 4J TODO - free levels here if there are already some?
levels = ServerLevelArray(3); levels = std::vector<ServerLevel*>(3);
int gameTypeId = settings->getInt( int gameTypeId = settings->getInt(
L"gamemode", L"gamemode",
@ -412,7 +412,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource,
// ConsoleSaveFile( L"" ), L"", L"", 0); // original // ConsoleSaveFile( L"" ), L"", L"", 0); // original
// McRegionLevelStorage *storage = new McRegionLevelStorage(File(L"."), // McRegionLevelStorage *storage = new McRegionLevelStorage(File(L"."),
// name, true); // TODO // name, true); // TODO
for (unsigned int i = 0; i < levels.length; i++) { for (unsigned int i = 0; i < levels.size(); i++) {
if (s_bServerHalted || !g_NetworkManager.IsInSession()) { if (s_bServerHalted || !g_NetworkManager.IsInSession()) {
return false; return false;
} }
@ -510,19 +510,18 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource,
ConsoleSaveFile* csf = getLevel(0)->getLevelStorage()->getSaveFile(); ConsoleSaveFile* csf = getLevel(0)->getLevelStorage()->getSaveFile();
if (csf->doesFileExist(filepath)) { if (csf->doesFileExist(filepath)) {
unsigned int numberOfBytesRead; unsigned int numberOfBytesRead;
byteArray ba_gameRules; std::vector<uint8_t> ba_gameRules;
FileEntry* fe = csf->createFile(filepath); FileEntry* fe = csf->createFile(filepath);
ba_gameRules.length = fe->getFileSize(); ba_gameRules.resize(fe->getFileSize());
ba_gameRules.data = new std::uint8_t[ba_gameRules.length];
csf->setFilePointer(fe, 0, SaveFileSeekOrigin::Begin); csf->setFilePointer(fe, 0, SaveFileSeekOrigin::Begin);
csf->readFile(fe, ba_gameRules.data, ba_gameRules.length, csf->readFile(fe, ba_gameRules.data(), ba_gameRules.size(),
&numberOfBytesRead); &numberOfBytesRead);
assert(numberOfBytesRead == ba_gameRules.length); assert(numberOfBytesRead == ba_gameRules.size());
app.m_gameRules.loadGameRules(ba_gameRules.data, ba_gameRules.length); app.m_gameRules.loadGameRules(ba_gameRules.data(), ba_gameRules.size());
csf->closeHandle(fe); csf->closeHandle(fe);
} }
@ -544,7 +543,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource* storageSource,
// 4J Stu - This loop is changed in 1.0.1 to only process the first level // 4J Stu - This loop is changed in 1.0.1 to only process the first level
// (ie the overworld), but I think we still want to do them all // (ie the overworld), but I think we still want to do them all
int i = 0; int i = 0;
for (int i = 0; i < levels.length; i++) { for (int i = 0; i < levels.size(); i++) {
// logger.info("Preparing start region for level " + i); // logger.info("Preparing start region for level " + i);
if (i == 0 || settings->getBoolean(L"allow-nether", true)) { if (i == 0 || settings->getBoolean(L"allow-nether", true)) {
ServerLevel* level = levels[i]; ServerLevel* level = levels[i];
@ -773,7 +772,7 @@ void MinecraftServer::endProgress() {
void MinecraftServer::saveAllChunks() { void MinecraftServer::saveAllChunks() {
// logger.info("Saving chunks"); // logger.info("Saving chunks");
for (unsigned int i = 0; i < levels.length; i++) { for (unsigned int i = 0; i < levels.size(); i++) {
// 4J Stu - Due to the way save mounting is handled on XboxOne, we can // 4J Stu - Due to the way save mounting is handled on XboxOne, we can
// actually save after the player has signed out. // actually save after the player has signed out.
if (m_bPrimaryPlayerSignedOut) break; if (m_bPrimaryPlayerSignedOut) break;
@ -781,7 +780,7 @@ void MinecraftServer::saveAllChunks() {
// level.dat with the data from the nethers leveldata. Fix for #7418 - // level.dat with the data from the nethers leveldata. Fix for #7418 -
// Functional: Gameplay: Saving after sleeping in a bed will place // Functional: Gameplay: Saving after sleeping in a bed will place
// player at nighttime when restarting. // player at nighttime when restarting.
ServerLevel* level = levels[levels.length - 1 - i]; ServerLevel* level = levels[levels.size() - 1 - i];
if (level) // 4J - added check as level can be nullptr if we end up in if (level) // 4J - added check as level can be nullptr if we end up in
// stopServer really early on due to network failure // stopServer really early on due to network failure
{ {
@ -790,7 +789,7 @@ void MinecraftServer::saveAllChunks() {
// Only close the level storage when we have saved the last level, // Only close the level storage when we have saved the last level,
// otherwise we need to recreate the region files when saving the // otherwise we need to recreate the region files when saving the
// next levels // next levels
if (i == (levels.length - 1)) { if (i == (levels.size() - 1)) {
level->closeLevelStorage(); level->closeLevelStorage();
} }
} }
@ -807,20 +806,20 @@ void MinecraftServer::saveGameRules() {
} else } else
#endif #endif
{ {
byteArray ba; uint8_t* baPtr = nullptr;
ba.data = nullptr; unsigned int baSize = 0;
app.m_gameRules.saveGameRules(&ba.data, &ba.length); app.m_gameRules.saveGameRules(&baPtr, &baSize);
if (ba.data != nullptr) { if (baPtr != nullptr) {
std::vector<uint8_t> ba(baPtr, baPtr + baSize);
ConsoleSaveFile* csf = ConsoleSaveFile* csf =
getLevel(0)->getLevelStorage()->getSaveFile(); getLevel(0)->getLevelStorage()->getSaveFile();
FileEntry* fe = FileEntry* fe =
csf->createFile(ConsoleSavePath(GAME_RULE_SAVENAME)); csf->createFile(ConsoleSavePath(GAME_RULE_SAVENAME));
csf->setFilePointer(fe, 0, SaveFileSeekOrigin::Begin); csf->setFilePointer(fe, 0, SaveFileSeekOrigin::Begin);
unsigned int length; unsigned int length;
csf->writeFile(fe, ba.data, ba.length, &length); csf->writeFile(fe, ba.data(), ba.size(), &length);
delete[] ba.data;
csf->closeHandle(fe); csf->closeHandle(fe);
} }
@ -842,13 +841,13 @@ void MinecraftServer::Suspend() {
if (players != nullptr) { if (players != nullptr) {
players->saveAll(nullptr); players->saveAll(nullptr);
} }
for (unsigned int j = 0; j < levels.length; j++) { for (unsigned int j = 0; j < levels.size(); j++) {
if (s_bServerHalted) break; if (s_bServerHalted) break;
// 4J Stu - Save the levels in reverse order so we don't overwrite // 4J Stu - Save the levels in reverse order so we don't overwrite
// the level.dat with the data from the nethers leveldata. Fix for // the level.dat with the data from the nethers leveldata. Fix for
// #7418 - Functional: Gameplay: Saving after sleeping in a bed will // #7418 - Functional: Gameplay: Saving after sleeping in a bed will
// place player at nighttime when restarting. // place player at nighttime when restarting.
ServerLevel* level = levels[levels.length - 1 - j]; ServerLevel* level = levels[levels.size() - 1 - j];
level->Suspend(); level->Suspend();
} }
if (!s_bServerHalted) { if (!s_bServerHalted) {
@ -907,7 +906,7 @@ void MinecraftServer::stopServer(bool didInit) {
// the level.dat with the data from the nethers leveldata. Fix for // the level.dat with the data from the nethers leveldata. Fix for
// #7418 - Functional: Gameplay: Saving after sleeping in a bed will // #7418 - Functional: Gameplay: Saving after sleeping in a bed will
// place player at nighttime when restarting. // place player at nighttime when restarting.
// for (unsigned int i = levels.length - 1; i >= 0; i--) // for (unsigned int i = levels.size() - 1; i >= 0; i--)
//{ //{
// ServerLevel *level = levels[i]; // ServerLevel *level = levels[i];
// if (level != nullptr) // if (level != nullptr)
@ -937,7 +936,7 @@ void MinecraftServer::stopServer(bool didInit) {
// files have completed saving. // files have completed saving.
// 4J-PB remove the server levels // 4J-PB remove the server levels
unsigned int iServerLevelC = levels.length; unsigned int iServerLevelC = levels.size();
for (unsigned int i = 0; i < iServerLevelC; i++) { for (unsigned int i = 0; i < iServerLevelC; i++) {
if (levels[i] != nullptr) { if (levels[i] != nullptr) {
delete levels[i]; delete levels[i];
@ -1149,7 +1148,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) {
} }
if (MinecraftServer::setTimeAtEndOfTick) { if (MinecraftServer::setTimeAtEndOfTick) {
MinecraftServer::setTimeAtEndOfTick = false; MinecraftServer::setTimeAtEndOfTick = false;
for (unsigned int i = 0; i < levels.length; i++) { for (unsigned int i = 0; i < levels.size(); i++) {
// if (i == 0 || // if (i == 0 ||
// settings->getBoolean(L"allow-nether", true)) // settings->getBoolean(L"allow-nether", true))
//// 4J removed - we always have nether //// 4J removed - we always have nether
@ -1161,7 +1160,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) {
} }
if (MinecraftServer::setTimeOfDayAtEndOfTick) { if (MinecraftServer::setTimeOfDayAtEndOfTick) {
MinecraftServer::setTimeOfDayAtEndOfTick = false; MinecraftServer::setTimeOfDayAtEndOfTick = false;
for (unsigned int i = 0; i < levels.length; i++) { for (unsigned int i = 0; i < levels.size(); i++) {
if (i == 0 || settings->getBoolean(L"allow-nether", true)) { if (i == 0 || settings->getBoolean(L"allow-nether", true)) {
ServerLevel* level = levels[i]; ServerLevel* level = levels[i];
level->setDayTime(MinecraftServer::setTimeOfDay); level->setDayTime(MinecraftServer::setTimeOfDay);
@ -1189,7 +1188,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) {
std::shared_ptr<UpdateProgressPacket>( std::shared_ptr<UpdateProgressPacket>(
new UpdateProgressPacket(20))); new UpdateProgressPacket(20)));
for (unsigned int j = 0; j < levels.length; j++) { for (unsigned int j = 0; j < levels.size(); j++) {
if (s_bServerHalted) break; if (s_bServerHalted) break;
// 4J Stu - Save the levels in reverse order so we // 4J Stu - Save the levels in reverse order so we
// don't overwrite the level.dat with the data from // don't overwrite the level.dat with the data from
@ -1197,7 +1196,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) {
// Functional: Gameplay: Saving after sleeping in a // Functional: Gameplay: Saving after sleeping in a
// bed will place player at nighttime when // bed will place player at nighttime when
// restarting. // restarting.
ServerLevel* level = levels[levels.length - 1 - j]; ServerLevel* level = levels[levels.size() - 1 - j];
level->save( level->save(
true, true,
Minecraft::GetInstance()->progressRenderer, Minecraft::GetInstance()->progressRenderer,
@ -1423,7 +1422,7 @@ void MinecraftServer::tick() {
pMinecraft->options->difficulty) ) ); pMinecraft->options->difficulty) ) );
}*/ }*/
for (unsigned int i = 0; i < levels.length; i++) { for (unsigned int i = 0; i < levels.size(); i++) {
// if (i == 0 || settings->getBoolean(L"allow-nether", true)) // if (i == 0 || settings->getBoolean(L"allow-nether", true))
// // 4J removed - we always have nether // // 4J removed - we always have nether
{ {
@ -1715,7 +1714,7 @@ void MinecraftServer::cycleSlowQueueIndex() {
// which case it will return false and nothing is set up. // which case it will return false and nothing is set up.
bool MinecraftServer::flagEntitiesToBeRemoved(unsigned int* flags) { bool MinecraftServer::flagEntitiesToBeRemoved(unsigned int* flags) {
bool removedFound = false; bool removedFound = false;
for (unsigned int i = 0; i < levels.length; i++) { for (unsigned int i = 0; i < levels.size(); i++) {
ServerLevel* level = levels[i]; ServerLevel* level = levels[i];
if (level) { if (level) {
level->flagEntitiesToBeRemoved(flags, &removedFound); level->flagEntitiesToBeRemoved(flags, &removedFound);

View file

@ -77,7 +77,7 @@ private:
public: public:
ServerConnection* connection; ServerConnection* connection;
Settings* settings; Settings* settings;
ServerLevelArray levels; std::vector<ServerLevel*> levels;
private: private:
PlayerList* players; PlayerList* players;

View file

@ -328,7 +328,7 @@ void PlayerList::updateEntireScoreboard(ServerScoreboard* scoreboard,
//} //}
} }
void PlayerList::setLevel(ServerLevelArray levels) { void PlayerList::setLevel(std::vector<ServerLevel*>& levels) {
playerIo = levels[0]->getLevelStorage()->getPlayerIO(); playerIo = levels[0]->getLevelStorage()->getPlayerIO();
} }

View file

@ -78,7 +78,7 @@ protected:
std::shared_ptr<ServerPlayer> player); std::shared_ptr<ServerPlayer> player);
public: public:
void setLevel(ServerLevelArray levels); void setLevel(std::vector<ServerLevel*>& levels);
void changeDimension(std::shared_ptr<ServerPlayer> player, void changeDimension(std::shared_ptr<ServerPlayer> player,
ServerLevel* from); ServerLevel* from);
int getMaxRange(); int getMaxRange();

View file

@ -12,7 +12,7 @@
EGameCommand TeleportCommand::getId() { return eGameCommand_Teleport; } EGameCommand TeleportCommand::getId() { return eGameCommand_Teleport; }
void TeleportCommand::execute(std::shared_ptr<CommandSender> source, void TeleportCommand::execute(std::shared_ptr<CommandSender> source,
byteArray commandData) { std::vector<uint8_t>& commandData) {
ByteArrayInputStream bais(commandData); ByteArrayInputStream bais(commandData);
DataInputStream dis(&bais); DataInputStream dis(&bais);
@ -49,20 +49,20 @@ void TeleportCommand::execute(std::shared_ptr<CommandSender> source,
} }
} }
// if (args.length >= 1) { // if (args.size() >= 1) {
// MinecraftServer server = MinecraftServer.getInstance(); // MinecraftServer server = MinecraftServer.getInstance();
// ServerPlayer victim; // ServerPlayer victim;
// if (args.length == 2 || args.length == 4) { // if (args.size() == 2 || args.size() == 4) {
// victim = server.getPlayers().getPlayer(args[0]); // victim = server.getPlayers().getPlayer(args[0]);
// if (victim == null) throw new PlayerNotFoundException(); // if (victim == null) throw new PlayerNotFoundException();
// } else { // } else {
// victim = (ServerPlayer) convertSourceToPlayer(source); // victim = (ServerPlayer) convertSourceToPlayer(source);
// } // }
// if (args.length == 3 || args.length == 4) { // if (args.size() == 3 || args.size() == 4) {
// if (victim.level != null) { // if (victim.level != null) {
// int pos = args.length - 3; // int pos = args.size() - 3;
// int maxPos = Level.MAX_LEVEL_SIZE; // int maxPos = Level.MAX_LEVEL_SIZE;
// int x = convertArgToInt(source, args[pos++], -maxPos, // int x = convertArgToInt(source, args[pos++], -maxPos,
// maxPos); int y = convertArgToInt(source, // maxPos); int y = convertArgToInt(source,
@ -73,9 +73,9 @@ void TeleportCommand::execute(std::shared_ptr<CommandSender> source,
// logAdminAction(source, "commands.tp.coordinates", // logAdminAction(source, "commands.tp.coordinates",
// victim.getAName(), x, y, z); // victim.getAName(), x, y, z);
// } // }
// } else if (args.length == 1 || args.length == 2) { // } else if (args.size() == 1 || args.size() == 2) {
// ServerPlayer destination = // ServerPlayer destination =
// server.getPlayers().getPlayer(args[args.length - 1]); if // server.getPlayers().getPlayer(args[args.size() - 1]); if
// (destination == null) throw new PlayerNotFoundException(); // (destination == null) throw new PlayerNotFoundException();
// victim.connection.teleport(destination.x, destination.y, // victim.connection.teleport(destination.x, destination.y,

View file

@ -6,7 +6,7 @@ class TeleportCommand : public Command {
public: public:
virtual EGameCommand getId(); virtual EGameCommand getId();
virtual void execute(std::shared_ptr<CommandSender> source, virtual void execute(std::shared_ptr<CommandSender> source,
byteArray commandData); std::vector<uint8_t>& commandData);
static std::shared_ptr<GameCommandPacket> preparePacket( static std::shared_ptr<GameCommandPacket> preparePacket(
PlayerUID subject, PlayerUID destination); PlayerUID subject, PlayerUID destination);

View file

@ -17,7 +17,7 @@ PlayerChunkMap::PlayerChunk::PlayerChunk(int x, int z, PlayerChunkMap* pcm)
: pos(x, z) { : pos(x, z) {
// 4J - added initialisers // 4J - added initialisers
changes = 0; changes = 0;
changedTiles = shortArray(MAX_CHANGES_BEFORE_RESEND); changedTiles = std::vector<short>(MAX_CHANGES_BEFORE_RESEND);
xChangeMin = xChangeMax = 0; xChangeMin = xChangeMax = 0;
yChangeMin = yChangeMax = 0; yChangeMin = yChangeMax = 0;
zChangeMin = zChangeMax = 0; zChangeMin = zChangeMax = 0;
@ -29,7 +29,7 @@ PlayerChunkMap::PlayerChunk::PlayerChunk(int x, int z, PlayerChunkMap* pcm)
parent->getLevel()->cache->create(x, z); parent->getLevel()->cache->create(x, z);
} }
PlayerChunkMap::PlayerChunk::~PlayerChunk() { delete changedTiles.data; } PlayerChunkMap::PlayerChunk::~PlayerChunk() {}
// 4J added - construct an an array of flags that indicate which entities are // 4J added - construct an an array of flags that indicate which entities are
// still waiting to have network packets sent out to say that they have been // still waiting to have network packets sent out to say that they have been

View file

@ -37,7 +37,7 @@ public:
// int x, z; // int x, z;
ChunkPos pos; ChunkPos pos;
shortArray changedTiles; std::vector<short> changedTiles;
int changes; int changes;
int xChangeMin, xChangeMax; int xChangeMin, xChangeMax;
int yChangeMin, yChangeMax; int yChangeMin, yChangeMax;

View file

@ -23,8 +23,9 @@ ServerChunkCache::ServerChunkCache(ServerLevel* level, ChunkStorage* storage,
autoCreate = false; // 4J added autoCreate = false; // 4J added
std::vector<uint8_t> emptyBlocks(Level::CHUNK_TILE_COUNT);
emptyChunk = emptyChunk =
new EmptyLevelChunk(level, byteArray(Level::CHUNK_TILE_COUNT), 0, 0); new EmptyLevelChunk(level, emptyBlocks, 0, 0);
this->level = level; this->level = level;
this->storage = storage; this->storage = storage;

View file

@ -42,7 +42,7 @@
#include "../../../../Common/ShutdownManager.h" #include "../../../../Common/ShutdownManager.h"
#include "PlayerChunkMap.h" #include "PlayerChunkMap.h"
WeighedTreasureArray ServerLevel::RANDOM_BONUS_ITEMS; std::vector<WeighedTreasure*> ServerLevel::RANDOM_BONUS_ITEMS;
C4JThread* ServerLevel::m_updateThread = nullptr; C4JThread* ServerLevel::m_updateThread = nullptr;
C4JThread::EventArray* ServerLevel::m_updateTrigger; C4JThread::EventArray* ServerLevel::m_updateTrigger;
@ -65,7 +65,7 @@ void ServerLevel::staticCtor() {
m_updateThread->setProcessor(CPU_CORE_TILE_UPDATE); m_updateThread->setProcessor(CPU_CORE_TILE_UPDATE);
m_updateThread->run(); m_updateThread->run();
RANDOM_BONUS_ITEMS = WeighedTreasureArray(20); RANDOM_BONUS_ITEMS = std::vector<WeighedTreasure*>(20);
RANDOM_BONUS_ITEMS[0] = new WeighedTreasure(Item::stick_Id, 0, 1, 3, 10); RANDOM_BONUS_ITEMS[0] = new WeighedTreasure(Item::stick_Id, 0, 1, 3, 10);
RANDOM_BONUS_ITEMS[1] = new WeighedTreasure(Tile::wood_Id, 0, 1, 3, 10); RANDOM_BONUS_ITEMS[1] = new WeighedTreasure(Tile::wood_Id, 0, 1, 3, 10);
@ -1008,7 +1008,7 @@ void ServerLevel::entityAdded(std::shared_ptr<Entity> e) {
entitiesById[e->entityId] = e; entitiesById[e->entityId] = e;
std::vector<std::shared_ptr<Entity> >* es = e->getSubEntities(); std::vector<std::shared_ptr<Entity> >* es = e->getSubEntities();
if (es != nullptr) { if (es != nullptr) {
// for (int i = 0; i < es.length; i++) // for (int i = 0; i < es.size(); i++)
for (auto it = es->begin(); it != es->end(); ++it) { for (auto it = es->begin(); it != es->end(); ++it) {
entitiesById.insert( entitiesById.insert(
intEntityMap::value_type((*it)->entityId, (*it))); intEntityMap::value_type((*it)->entityId, (*it)));
@ -1022,7 +1022,7 @@ void ServerLevel::entityRemoved(std::shared_ptr<Entity> e) {
entitiesById.erase(e->entityId); entitiesById.erase(e->entityId);
std::vector<std::shared_ptr<Entity> >* es = e->getSubEntities(); std::vector<std::shared_ptr<Entity> >* es = e->getSubEntities();
if (es != nullptr) { if (es != nullptr) {
// for (int i = 0; i < es.length; i++) // for (int i = 0; i < es.size(); i++)
for (auto it = es->begin(); it != es->end(); ++it) { for (auto it = es->begin(); it != es->end(); ++it) {
entitiesById.erase((*it)->entityId); entitiesById.erase((*it)->entityId);
} }

View file

@ -41,7 +41,7 @@ private:
MobSpawner* mobSpawner; MobSpawner* mobSpawner;
int emptyTime; int emptyTime;
bool m_bAtLeastOnePlayerSleeping; // 4J Added bool m_bAtLeastOnePlayerSleeping; // 4J Added
static WeighedTreasureArray static std::vector<WeighedTreasure*>
RANDOM_BONUS_ITEMS; // 4J - brought forward from 1.3.2 RANDOM_BONUS_ITEMS; // 4J - brought forward from 1.3.2
std::vector<TileEventData> tileEvents[2]; std::vector<TileEventData> tileEvents[2];

View file

@ -52,7 +52,7 @@ ServerPlayer::ServerPlayer(MinecraftServer* server, Level* level,
latency = 0; latency = 0;
wonGame = false; wonGame = false;
m_enteredEndExitPortal = false; m_enteredEndExitPortal = false;
// lastCarried = arrayWithLength<std::shared_ptr<ItemInstance>>(5); // lastCarried = std::vector<std::shared_ptr<ItemInstance>>(5);
lastActionTime = 0; lastActionTime = 0;
viewDistance = server->getPlayers()->getViewDistance(); viewDistance = server->getPlayers()->getViewDistance();
@ -133,7 +133,6 @@ ServerPlayer::ServerPlayer(MinecraftServer* server, Level* level,
} }
ServerPlayer::~ServerPlayer() { ServerPlayer::~ServerPlayer() {
// delete [] lastCarried.data;
} }
// 4J added - add bits to a flag array that is passed in, to represent those // 4J added - add bits to a flag array that is passed in, to represent those
@ -185,13 +184,12 @@ void ServerPlayer::readAdditionalSaveData(CompoundTag* entityTag) {
GameRulesInstance* grs = gameMode->getGameRules(); GameRulesInstance* grs = gameMode->getGameRules();
if (entityTag->contains(L"GameRules") && grs != nullptr) { if (entityTag->contains(L"GameRules") && grs != nullptr) {
byteArray ba = entityTag->getByteArray(L"GameRules"); std::vector<uint8_t> ba = entityTag->getByteArray(L"GameRules");
ByteArrayInputStream bais(ba); ByteArrayInputStream bais(ba);
DataInputStream dis(&bais); DataInputStream dis(&bais);
grs->read(&dis); grs->read(&dis);
dis.close(); dis.close();
bais.close(); bais.close();
// delete [] ba.data;
} }
} }
@ -204,7 +202,7 @@ void ServerPlayer::addAdditonalSaveData(CompoundTag* entityTag) {
DataOutputStream dos(&baos); DataOutputStream dos(&baos);
grs->write(&dos); grs->write(&dos);
entityTag->putByteArray(L"GameRules", baos.buf); entityTag->putByteArray(L"GameRules", baos.buf);
baos.buf.data = nullptr; baos.buf.clear();
dos.close(); dos.close();
baos.close(); baos.close();
} }
@ -256,7 +254,7 @@ void ServerPlayer::flushEntitiesToRemove() {
while (!entitiesToRemove.empty()) { while (!entitiesToRemove.empty()) {
int sz = entitiesToRemove.size(); int sz = entitiesToRemove.size();
int amount = std::min(sz, RemoveEntitiesPacket::MAX_PER_PACKET); int amount = std::min(sz, RemoveEntitiesPacket::MAX_PER_PACKET);
intArray ids(amount); std::vector<int> ids(amount);
int pos = 0; int pos = 0;
auto it = entitiesToRemove.begin(); auto it = entitiesToRemove.begin();
@ -1310,20 +1308,17 @@ void ServerPlayer::setPlayerInput(float xxa, float yya, bool jumping,
} }
} }
void ServerPlayer::awardStat(Stat* stat, byteArray param) { void ServerPlayer::awardStat(Stat* stat, const std::vector<uint8_t>& param) {
if (stat == nullptr) { if (stat == nullptr) {
delete[] param.data;
return; return;
} }
if (!stat->awardLocallyOnly) { if (!stat->awardLocallyOnly) {
int count = *((int*)param.data); int count = *((int*)param.data());
delete[] param.data;
connection->send(std::shared_ptr<AwardStatPacket>( connection->send(std::shared_ptr<AwardStatPacket>(
new AwardStatPacket(stat->id, count))); new AwardStatPacket(stat->id, count)));
} else }
delete[] param.data;
} }
void ServerPlayer::disconnect() { void ServerPlayer::disconnect() {

View file

@ -140,7 +140,7 @@ public:
void doCloseContainer(); void doCloseContainer();
void setPlayerInput(float xa, float ya, bool jumping, bool sneaking); void setPlayerInput(float xa, float ya, bool jumping, bool sneaking);
virtual void awardStat(Stat* stat, byteArray param); virtual void awardStat(Stat* stat, const std::vector<uint8_t>& param);
void disconnect(); void disconnect();
void resetSentInfo(); void resetSentInfo();

View file

@ -1216,7 +1216,7 @@ void PlayerConnection::handleSetCreativeModeSlot(
packet->slotNum < (InventoryMenu::USE_ROW_SLOT_START + packet->slotNum < (InventoryMenu::USE_ROW_SLOT_START +
Inventory::getSelectionSize())); Inventory::getSelectionSize()));
bool validItem = item == nullptr || bool validItem = item == nullptr ||
(item->id < Item::items.length && item->id >= 0 && (item->id < Item::items.size() && item->id >= 0 &&
Item::items[item->id] != nullptr); Item::items[item->id] != nullptr);
bool validData = bool validData =
item == nullptr || item == nullptr ||
@ -1586,8 +1586,7 @@ void PlayerConnection::handleCustomPayload(
customPayloadPacket->identifier) == 0) { customPayloadPacket->identifier) == 0) {
AnvilMenu* menu = dynamic_cast<AnvilMenu*>(player->containerMenu); AnvilMenu* menu = dynamic_cast<AnvilMenu*>(player->containerMenu);
if (menu) { if (menu) {
if (customPayloadPacket->data.data == nullptr || if (customPayloadPacket->data.empty()) {
customPayloadPacket->data.length < 1) {
menu->setItemName(L""); menu->setItemName(L"");
} else { } else {
ByteArrayInputStream bais(customPayloadPacket->data); ByteArrayInputStream bais(customPayloadPacket->data);

View file

@ -156,7 +156,7 @@ void ServerConnection::handleServerSettingsChanged(
Minecraft* pMinecraft = Minecraft::GetInstance(); Minecraft* pMinecraft = Minecraft::GetInstance();
if (packet->action == ServerSettingsChangedPacket::HOST_DIFFICULTY) { if (packet->action == ServerSettingsChangedPacket::HOST_DIFFICULTY) {
for (unsigned int i = 0; i < pMinecraft->levels.length; ++i) { for (unsigned int i = 0; i < pMinecraft->levels.size(); ++i) {
if (pMinecraft->levels[i] != nullptr) { if (pMinecraft->levels[i] != nullptr) {
app.DebugPrintf( app.DebugPrintf(
"ClientConnection::handleServerSettingsChanged - " "ClientConnection::handleServerSettingsChanged - "

View file

@ -1,82 +1,10 @@
#pragma once #pragma once
#include <cassert> #include <cassert>
#include <cstdint>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <vector>
// Note - this is meant to be a really simple wrapper round a pointer just to be
// able to add a length value to arrays.
// As such, it shouldn't delete its data in a destructor as shallow copies will
// be made of this and we don't want to free the data just because one of those
// has gone out of scope
template <class T>
class arrayWithLength {
public:
T* data;
unsigned int length;
arrayWithLength() {
data = nullptr;
length = 0;
}
arrayWithLength(unsigned int elements, bool bClearArray = true) {
assert(elements != 0);
data = new T[elements];
if (bClearArray) {
memset((void*)data, 0, sizeof(T) * elements);
}
this->length = elements;
}
// 4J Stu Added this ctor so I static init arrays in the Item derivation
// tree
arrayWithLength(T data[], unsigned int elements) {
this->data = data;
this->length = elements;
}
//~arrayWithLength() { delete[] data; }
void resize(unsigned int elements) {
assert(elements > length);
T* temp = new T[elements];
memset((void*)temp, 0, sizeof(T) * elements);
if (data != nullptr) {
std::copy(data, data + length, temp);
delete[] data;
}
data = temp;
length = elements;
}
T& operator[](unsigned int i) { return data[i]; }
T operator[](unsigned int i) const { return data[i]; }
};
// TODO 4J Stu - This looks right, but is it?
template <class T>
class array2DWithLength {
typedef arrayWithLength<T>* _parrayWithLength;
public:
_parrayWithLength* data;
unsigned int length;
array2DWithLength() {
data = nullptr;
length = 0;
}
array2DWithLength(unsigned int dimA, unsigned int dimB) {
data = new _parrayWithLength[dimA];
this->length = dimA;
for (unsigned int i = 0; i < length; i++)
data[i] = new arrayWithLength<T>(dimB);
}
_parrayWithLength& operator[](unsigned int i) { return data[i]; }
_parrayWithLength operator[](unsigned int i) const { return data[i]; }
};
class Biome; class Biome;
class LevelChunk; class LevelChunk;
@ -99,32 +27,3 @@ class Layer;
class ModelPart; class ModelPart;
class Enchantment; class Enchantment;
class ClipChunk; class ClipChunk;
typedef arrayWithLength<double> doubleArray;
typedef array2DWithLength<double> coords2DArray;
typedef arrayWithLength<uint8_t> byteArray;
typedef arrayWithLength<char> charArray;
typedef arrayWithLength<short> shortArray;
typedef arrayWithLength<int> intArray;
typedef arrayWithLength<float> floatArray;
typedef arrayWithLength<Biome*> BiomeArray;
typedef arrayWithLength<LevelChunk*> LevelChunkArray;
typedef array2DWithLength<LevelChunk*> LevelChunk2DArray;
typedef arrayWithLength<Node*> NodeArray;
typedef arrayWithLength<Item*> ItemArray;
typedef arrayWithLength<Tile*> TileArray;
typedef arrayWithLength<Stat*> StatArray;
typedef arrayWithLength<MobCategory*> MobCategoryArray;
typedef arrayWithLength<File*> FileArray;
typedef arrayWithLength<ServerLevel*> ServerLevelArray;
typedef arrayWithLength<MultiPlayerLevel*> MultiPlayerLevelArray;
typedef arrayWithLength<Level*> LevelArray;
typedef arrayWithLength<LevelRenderer*> LevelRendererArray;
typedef arrayWithLength<WeighedRandomItem*> WeighedRandomItemArray;
typedef arrayWithLength<WeighedTreasure*> WeighedTreasureArray;
typedef arrayWithLength<std::shared_ptr<Layer> > LayerArray;
// typedef arrayWithLength<Cube *> CubeArray;
typedef arrayWithLength<ModelPart*> ModelPartArray;
typedef arrayWithLength<Enchantment*> EnchantmentArray;
typedef arrayWithLength<ClipChunk> ClipChunkArray;

View file

@ -45,18 +45,18 @@ int ConsoleSaveFileInputStream::read() {
return static_cast<int>(byteRead); return static_cast<int>(byteRead);
} }
// Reads up to b.length bytes of data from this input stream into an array of // Reads up to b.size() bytes of data from this input stream into an array of
// bytes. This method blocks until some input is available. Parameters: b - the // bytes. This method blocks until some input is available. Parameters: b - the
// buffer into which the data is read. Returns: the total number of bytes read // buffer into which the data is read. Returns: the total number of bytes read
// into the buffer, or -1 if there is no more data because the end of the file // into the buffer, or -1 if there is no more data because the end of the file
// has been reached. // has been reached.
int ConsoleSaveFileInputStream::read(byteArray b) { int ConsoleSaveFileInputStream::read(std::vector<uint8_t>& b) {
unsigned int numberOfBytesRead; unsigned int numberOfBytesRead;
bool result = bool result =
m_saveFile->readFile(m_file, m_saveFile->readFile(m_file,
&b.data, // data buffer b.data(), // data buffer
b.length, // number of bytes to read b.size(), // number of bytes to read
&numberOfBytesRead // number of bytes read &numberOfBytesRead // number of bytes read
); );
@ -78,10 +78,10 @@ int ConsoleSaveFileInputStream::read(byteArray b) {
// b len - the maximum number of bytes read. Returns: the total number of bytes // b len - the maximum number of bytes read. Returns: the total number of bytes
// read into the buffer, or -1 if there is no more data because the end of the // read into the buffer, or -1 if there is no more data because the end of the
// file has been reached. // file has been reached.
int ConsoleSaveFileInputStream::read(byteArray b, unsigned int offset, int ConsoleSaveFileInputStream::read(std::vector<uint8_t>& b, unsigned int offset,
unsigned int length) { unsigned int length) {
// 4J Stu - We don't want to read any more than the array buffer can hold // 4J Stu - We don't want to read any more than the array buffer can hold
assert(length <= (b.length - offset)); assert(length <= (b.size() - offset));
unsigned int numberOfBytesRead; unsigned int numberOfBytesRead;

View file

@ -15,8 +15,8 @@ public:
const ConsoleSavePath& file); const ConsoleSavePath& file);
ConsoleSaveFileInputStream(ConsoleSaveFile* saveFile, FileEntry* file); ConsoleSaveFileInputStream(ConsoleSaveFile* saveFile, FileEntry* file);
virtual int read(); virtual int read();
virtual int read(byteArray b); virtual int read(std::vector<uint8_t>& b);
virtual int read(byteArray b, unsigned int offset, unsigned int length); virtual int read(std::vector<uint8_t>& b, unsigned int offset, unsigned int length);
virtual void close(); virtual void close();
virtual int64_t skip(int64_t n) { return n; } virtual int64_t skip(int64_t n) { return n; }

View file

@ -819,7 +819,7 @@ void ConsoleSaveFileOriginal::ConvertRegionFile(File sourceFile) {
sourceRegionFile.getChunkDataInputStream(x, z); sourceRegionFile.getChunkDataInputStream(x, z);
if (dis) { if (dis) {
byteArray inData(1024 * 1024); std::vector<uint8_t> inData(1024 * 1024);
int read = dis->read(inData); int read = dis->read(inData);
dis->close(); dis->close();
dis->deleteChildStream(); dis->deleteChildStream();
@ -832,7 +832,7 @@ void ConsoleSaveFileOriginal::ConvertRegionFile(File sourceFile) {
dos->close(); dos->close();
dos->deleteChildStream(); dos->deleteChildStream();
delete dos; delete dos;
delete inData.data; // vector cleans up automatically
} }
} }
} }

View file

@ -55,21 +55,21 @@ void ConsoleSaveFileOutputStream::write(unsigned int b) {
} }
} }
// Writes b.length bytes from the specified byte array to this file output // Writes b.size() bytes from the specified byte array to this file output
// stream. Parameters: b - the data. // stream. Parameters: b - the data.
void ConsoleSaveFileOutputStream::write(byteArray b) { void ConsoleSaveFileOutputStream::write(const std::vector<uint8_t>& b) {
unsigned int numberOfBytesWritten; unsigned int numberOfBytesWritten;
bool result = bool result =
m_saveFile->writeFile(m_file, m_saveFile->writeFile(m_file,
&b.data, // data buffer b.data(), // data buffer
b.length, // number of bytes to write b.size(), // number of bytes to write
&numberOfBytesWritten // number of bytes written &numberOfBytesWritten // number of bytes written
); );
if (!result) { if (!result) {
// TODO 4J Stu - Some kind of error handling // TODO 4J Stu - Some kind of error handling
} else if (numberOfBytesWritten == 0 || numberOfBytesWritten != b.length) { } else if (numberOfBytesWritten == 0 || numberOfBytesWritten != b.size()) {
// File pointer is past the end of the file // File pointer is past the end of the file
} }
} }
@ -77,10 +77,10 @@ void ConsoleSaveFileOutputStream::write(byteArray b) {
// Writes len bytes from the specified byte array starting at offset off to this // Writes len bytes from the specified byte array starting at offset off to this
// file output stream. Parameters: b - the data. off - the start offset in the // file output stream. Parameters: b - the data. off - the start offset in the
// data. len - the number of bytes to write. // data. len - the number of bytes to write.
void ConsoleSaveFileOutputStream::write(byteArray b, unsigned int offset, void ConsoleSaveFileOutputStream::write(const std::vector<uint8_t>& b, unsigned int offset,
unsigned int length) { unsigned int length) {
// 4J Stu - We don't want to write any more than the array buffer holds // 4J Stu - We don't want to write any more than the array buffer holds
assert(length <= (b.length - offset)); assert(length <= (b.size() - offset));
unsigned int numberOfBytesWritten; unsigned int numberOfBytesWritten;

View file

@ -15,8 +15,8 @@ public:
const ConsoleSavePath& file); const ConsoleSavePath& file);
ConsoleSaveFileOutputStream(ConsoleSaveFile* saveFile, FileEntry* file); ConsoleSaveFileOutputStream(ConsoleSaveFile* saveFile, FileEntry* file);
virtual void write(unsigned int b); virtual void write(unsigned int b);
virtual void write(byteArray b); virtual void write(const std::vector<uint8_t>& b);
virtual void write(byteArray b, unsigned int offset, unsigned int length); virtual void write(const std::vector<uint8_t>& b, unsigned int offset, unsigned int length);
virtual void close(); virtual void close();
virtual void flush() {} virtual void flush() {}

View file

@ -1542,7 +1542,7 @@ void ConsoleSaveFileSplit::ConvertRegionFile(File sourceFile) {
sourceRegionFile.getChunkDataInputStream(x, z); sourceRegionFile.getChunkDataInputStream(x, z);
if (dis) { if (dis) {
byteArray inData(1024 * 1024); std::vector<uint8_t> inData(1024 * 1024);
int read = dis->read(inData); int read = dis->read(inData);
dis->close(); dis->close();
dis->deleteChildStream(); dis->deleteChildStream();
@ -1555,7 +1555,6 @@ void ConsoleSaveFileSplit::ConvertRegionFile(File sourceFile) {
dos->close(); dos->close();
dos->deleteChildStream(); dos->deleteChildStream();
delete dos; delete dos;
delete inData.data;
} }
} }
} }

View file

@ -109,8 +109,8 @@ void FileHeader::WriteHeader(void* saveMem) {
for (unsigned int i = 0; i < fileTable.size(); ++i) { for (unsigned int i = 0; i < fileTable.size(); ++i) {
// wprintf(L"File: %ls, Start = %d, Length = %d, End = %d\n", // wprintf(L"File: %ls, Start = %d, Length = %d, End = %d\n",
// fileTable[i]->data.filename, fileTable[i]->data.startOffset, // fileTable[i]->data.filename, fileTable[i]->data.startOffset,
// fileTable[i]->data.length, fileTable[i]->data.startOffset + // fileTable[i]->data.size(), fileTable[i]->data.startOffset +
// fileTable[i]->data.length); // fileTable[i]->data.size());
memcpy((void*)headerPosition, &fileTable[i]->data, memcpy((void*)headerPosition, &fileTable[i]->data,
sizeof(FileEntrySaveData)); sizeof(FileEntrySaveData));
// assert(numberOfBytesWritten == sizeof(FileEntrySaveData)); // assert(numberOfBytesWritten == sizeof(FileEntrySaveData));

View file

@ -370,7 +370,7 @@ int32_t Compression::DecompressWithType(void* pDestination,
pbDestSize[3 - i] = pbSource[i]; pbDestSize[3 - i] = pbSource[i];
} }
byteArray uncompr = byteArray(*pDestSize); std::vector<uint8_t> uncompr = std::vector<uint8_t>(*pDestSize);
// Build decompression stream // Build decompression stream
z_stream strm; z_stream strm;

View file

@ -29,7 +29,7 @@ public:
virtual EGameCommand getId() = 0; virtual EGameCommand getId() = 0;
virtual int getPermissionLevel(); virtual int getPermissionLevel();
virtual void execute(std::shared_ptr<CommandSender> source, virtual void execute(std::shared_ptr<CommandSender> source,
byteArray commandData) = 0; std::vector<uint8_t>& commandData) = 0;
virtual bool canExecute(std::shared_ptr<CommandSender> source); virtual bool canExecute(std::shared_ptr<CommandSender> source);
static void logAdminAction(std::shared_ptr<CommandSender> source, static void logAdminAction(std::shared_ptr<CommandSender> source,

Some files were not shown because too many files have changed in this diff Show more