std::vector<ChunkDesc> TLJPak::collect_chunk_desc() { std::vector<ChunkDesc> firstsweep; // Collect chunks for(int i = 0; i < int(files.size()); ++i) { if (files[i].is_file()) firstsweep.push_back(ChunkDesc(files[i].offset, files[i].filesize)); } std::sort(firstsweep.begin(), firstsweep.end(), ChunkSort()); std::vector<ChunkDesc> chunk_lst; // Remove any duplicates for(int i = 0; i < int(firstsweep.size()); ++i) { if (chunk_lst.size() == 0 || chunk_lst.back() != firstsweep[i]) { chunk_lst.push_back(firstsweep[i]); } } assert(chunk_lst.size() > 0); // Check for holes (might not be needed) for(int i = 1; i < int(chunk_lst.size()); ++i) { // some files themself are '0' padded as well! //std::cout << chunk_lst[i].offset << std::endl; if (chunk_lst[i].offset != (chunk_lst[i-1].offset + chunk_lst[i-1].size)) { chunk_lst[i].padding = chunk_lst[i].offset - (chunk_lst[i-1].offset + chunk_lst[i-1].size); if (0) std::cout << "Hole in file: got " << chunk_lst[i].offset << " expected " << chunk_lst[i-1].offset + chunk_lst[i-1].size << " distance " << chunk_lst[i].padding << std::endl; } } return chunk_lst; }
void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ) { ASSERT(m_PluginInterface != nullptr); ASSERT(m_ChunkSink != nullptr); ASSERT(m_ChunkSink->IsChunkQueued(a_ChunkX, a_ChunkZ)); cChunkDesc ChunkDesc(a_ChunkX, a_ChunkZ); m_PluginInterface->CallHookChunkGenerating(ChunkDesc); m_Generator->DoGenerate(a_ChunkX, a_ChunkZ, ChunkDesc); m_PluginInterface->CallHookChunkGenerated(ChunkDesc); #ifdef _DEBUG // Verify that the generator has produced valid data: ChunkDesc.VerifyHeightmap(); #endif m_ChunkSink->OnChunkGenerated(ChunkDesc); }
void TLJPak::generate_filetable() { //std::cout << "generate_filetable()" << std::endl; int pos = 12 + 4 + 4 + 4 + // Header files.size() * 4 * 5 + // Filetable nametable.size() + // Nametable indextable.size()*4 // Indextable ; header_padding = pos; // Round pos up to a multiple of 2048, not sure if its needed, but // thats how the original .paks look like if ((pos % 2048) != 0) pos = ((pos / 2048) + 1) * 2048; //int start_pos = pos; header_padding = pos - header_padding; //std::cout << "Start Pos: " << pos << " " << header_padding << std::endl; std::vector<ChunkDesc> chunk_descs; for(int i = 0; i < int(chunks.size()); ++i) { chunk_descs.push_back(ChunkDesc(pos, chunks[i].size())); pos += chunks[i].size(); } for(int i = 0; i < int(files.size()); ++i) { assert(files[i].chunk_id != -1); files[i].offset = chunk_descs[files[i].chunk_id].offset; if (files[i].filesize != 0) files[i].filesize = chunk_descs[files[i].chunk_id].size; } }
void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { cChunkDesc ChunkDesc(a_ChunkX, a_ChunkZ); cRoot::Get()->GetPluginManager()->CallHookChunkGenerating(m_World, a_ChunkX, a_ChunkZ, &ChunkDesc); m_Generator->DoGenerate(a_ChunkX, a_ChunkZ, ChunkDesc); cRoot::Get()->GetPluginManager()->CallHookChunkGenerated(m_World, a_ChunkX, a_ChunkZ, &ChunkDesc); #ifdef _DEBUG // Verify that the generator has produced valid data: ChunkDesc.VerifyHeightmap(); #endif cChunkDef::BlockNibbles BlockMetas; ChunkDesc.CompressBlockMetas(BlockMetas); m_World->SetChunkData( a_ChunkX, a_ChunkZ, ChunkDesc.GetBlockTypes(), BlockMetas, NULL, NULL, // We don't have lighting, chunk will be lighted when needed &ChunkDesc.GetHeightMap(), &ChunkDesc.GetBiomeMap(), ChunkDesc.GetEntities(), ChunkDesc.GetBlockEntities(), true ); }