ZFileSectorLoader::~ZFileSectorLoader() { if (WorkingEmptySector) { delete WorkingEmptySector; WorkingEmptySector = 0; } if (WorkingFullSector) { delete WorkingFullSector; WorkingFullSector = 0; } ZVoxelSector * Sector; if (ReadySectorList) { while (( Sector = ReadySectorList->PullFromList() )) { if (COMPILEOPTION_ALLOWSAVE) Sector->Save(UniverseNum); delete Sector; } delete ReadySectorList; ReadySectorList = 0; } if (EjectedSectorList) { EjectedSectorList->FreeRemainingContent(); delete EjectedSectorList; EjectedSectorList = 0; } UniverseNum = 0; }
bool ZFileSectorLoader::LoadSector(Long x, Long y, Long z) { ZVoxelSector * NewSector; bool Redo, TryLoad; if ( !RequestTag.find(x,y,z) ) { NewSector = SectorRecycling->PullFromList(); // Try recycling some old used sector. if (!NewSector) { NewSector = new ZVoxelSector( GameEnv->Basic_Renderer->GetCuller() ); } TryLoad = true; do { Redo = false; NewSector->Pos_x = x; NewSector->Pos_y = y; NewSector->Pos_z = z; NewSector->SetVoxelTypeManager(VoxelTypeManager); if (TryLoad && NewSector->Load(UniverseNum)) { // Does this sector must be regenerated ? if ( 0==(NewSector->Flag_IsModified & ZVoxelSector::CHANGE_SAVEMASK) ) { if (COMPILEOPTION_ALLOWSAVE) NewSector->DeleteSave(UniverseNum); NewSector->ReinitSector(); Redo = true; TryLoad = false; continue; } } else { SectorCreator->GenerateSector(NewSector); } } while (Redo); // Set the options for further edge faceculling. NewSector->Flag_NeedFullCulling = false; NewSector->PartialCulling = DRAWFACE_ALL; // Add it in the tag RequestTag.Add(x,y,z); // Partial face culling on the sector. Edges must be completed later when other sectors will be availlable. LimitedUpdateFaceCulling(NewSector ); //NoDrawFaceCulling(NewSector); // Push it to the list for integration in the world on the main thread. ReadySectorList->PushToList(NewSector); return(true); } return(false); }
void ZFileSectorLoader::MakeTasks() { Long x,y,z; UByte Pri; // Sector Loading while (1) { if (RequestList[5].PullFromList(x,y,z)) {Pri = 4; } else if (RequestList[4].PullFromList(x,y,z)) {Pri = 4; } else if (RequestList[3].PullFromList(x,y,z)) {Pri = 3; } else if (RequestList[2].PullFromList(x,y,z)) {Pri = 2; } else if (RequestList[1].PullFromList(x,y,z)) {Pri = 1; } else if (RequestList[0].PullFromList(x,y,z)) {Pri = 0; } else break; if (LoadSector(x,y,z) /*&& Pri<4*/) break; } // Sector Unloading ZVoxelSector * Sector; while ( (Sector = EjectedSectorList->PullFromList()) ) { RequestTag.Remove(Sector->Pos_x, Sector->Pos_y, Sector->Pos_z); printf("Deleted : %lx, %lu L2 Start:%lu End:%lu nEntries:%lu\n", Sector,++debug_deletecount,EjectedSectorList->debug_getstart(),EjectedSectorList->debug_GetEnd(),EjectedSectorList->debug_GetnEntries() ); if (COMPILEOPTION_ALLOWSAVE) { #if COMPILEOPTION_SAVEONLYMODIFIED==1 if (Sector->IsMustBeSaved()) #endif { Sector->Save(UniverseNum); } } //delete Sector; Sector->ReinitSector(); SectorRecycling->PushToList(Sector); } return; }
bool ZWorldConverter::WorldConvert(char const * Path) { struct dirent * Entry; ZVoxelSector Sector; DIR * Directory; ZString FileSpec, FileName; if (!(Directory = opendir(Path))) { return(false); } while (( Entry = readdir(Directory) )) { FileName = Entry->d_name; FileSpec = Path; FileSpec << "/" << FileName; // printf("%s %x\n",Entry->d_name, Entry->d_type); if (Entry->d_type == DT_DIR) { } else if (Entry->d_type == DT_REG) { if (FileName.Lefts(6)=="Sector") { printf("Loading Sector %s\n", FileSpec.String); Sector.Load(0,FileSpec.String); SectorConvert(&Sector); Sector.Save(0,FileSpec.String); } } } closedir(Directory); return(true); }