/** * The constructor needs to scan the whole PTX file to find out the bounding box. Unluckily. * TODO: during the scan all the points are read and transformed. Afterwards, during loading * the points are read again and transformed again. It should be nice to save the * transformed points in a temporary file. That would mean a LAS file or something similar. * Unuseful. It's better to convert the PTX to LAS files. * TODO: it seems theat the PTXPointReader is asked to produce the bounding box more than once. * Maybe it should be saved somewhere. Chez moi, scanning 14m points needs 90 secs. The * process speed of the PTX file is about 1m points every 50 secs. */ PTXPointReader::PTXPointReader(string path) { this->path = path; if (fs::is_directory(path)) { // if directory is specified, find all ptx files inside directory for (fs::directory_iterator it(path); it != fs::directory_iterator(); it++) { fs::path filepath = it->path(); if (fs::is_regular_file(filepath)) { if (icompare(fs::path(filepath).extension().string(), ".ptx")) { files.push_back(filepath.string()); } } } } else { files.push_back(path); } // open first file this->currentFile = files.begin(); this->stream = new fstream(*(this->currentFile), ios::in); this->currentChunk = 0; skipline(*this->stream); loadChunk(this->stream, this->currentChunk, this->tr); }
void MapImpl::set(int x, int y, int z, const MapCell & cell) { if (!myPruneThread.joinable()) myPruneThread.start_thread(); uint64_t hash = myBank->put(cell); std::shared_ptr<Chunk> chunk = getChunk(x, y, z); boost::unique_lock<boost::shared_mutex> guard(chunk->lock); if(!chunk->accessor) { loadChunk(chunk); } // boost::upgrade_to_unique_lock<boost::shared_mutex> lock(guard); if (hash == myBackgroundValue) chunk->accessor->setValueOff( ovdb::Coord(x % myChunkSize.x(), y % myChunkSize.y(), z % myChunkSize.z()), hash); else chunk->accessor->setValue( ovdb::Coord(x % myChunkSize.x(), y % myChunkSize.y(), z % myChunkSize.z()), hash); chunk->dirty = true; // if (!myChunks.empty() && (myAccessCounter++ % myAccessTolerance == 0)) // prune(false); }
void VstPlugin::loadSettings( const QDomElement & _this ) { if( _this.hasAttribute( "program" ) ) { setProgram( _this.attribute( "program" ).toInt() ); } const int num_params = _this.attribute( "numparams" ).toInt(); // if it exists try to load settings chunk if( _this.hasAttribute( "chunk" ) ) { loadChunk( QByteArray::fromBase64( _this.attribute( "chunk" ).toUtf8() ) ); } else if( num_params > 0 ) { // no chunk, restore individual parameters QMap<QString, QString> dump; for( int i = 0; i < num_params; ++i ) { const QString key = "param" + QString::number( i ); dump[key] = _this.attribute( key ); } setParameterDump( dump ); } }
void DeviceAudioDX11::pumpAllStreaming (void) { #if DT2_MULTITHREADED_AUDIO AutoSpinLockRecursive lock(&_lock); #endif for (DTuint c = 0; c < _channels.size(); ++c) { DeviceAudioDX11Channel &channel = _channels[c]; SoundSource *source = channel._source; if (!source) continue; XAUDIO2_VOICE_STATE state; channel._x_voice->GetState(&state); while (state.BuffersQueued < NUM_BUFFERS) { if (loadChunk (channel)) { SoundPacket &packet = channel._packets[channel._current_packet]; // Enqueue the buffer XAUDIO2_BUFFER x_buffer; x_buffer.Flags = 0; x_buffer.AudioBytes = packet.getNumBytes(); x_buffer.pAudioData = packet.getBuffer(); x_buffer.PlayBegin = 0; x_buffer.PlayLength = 0; x_buffer.LoopBegin = XAUDIO2_NO_LOOP_REGION; x_buffer.LoopLength = 0; x_buffer.LoopCount = 0; x_buffer.pContext = &channel; channel._x_voice->SubmitSourceBuffer(&x_buffer); } else { channel._x_voice->Discontinuity(); break; } channel._x_voice->GetState(&state); } } }
bool PTXPointReader::doReadNextPoint() { if (this->stream->eof()) { this->stream->close(); this->currentFile++; if (this->currentFile != files.end()) { this->stream = new fstream(*(this->currentFile), ios::in); this->currentChunk = 0; skipline(*stream); loadChunk(stream, currentChunk, tr); } else { return false; } } vector<double> split; getlined(*stream, split); if (1 == split.size()) { this->currentChunk++; loadChunk(stream, currentChunk, tr); getlined(*stream, split); } auto size1 = split.size(); if (size1 > 3) { this->p = transform(tr, split[0], split[1], split[2]); double intensity = split[3]; this->p.intensity = (unsigned short)(65535.0 * intensity); if (4 == size1) { this->p.color.x = (unsigned char)(intensity * 255.0); this->p.color.y = (unsigned char)(intensity * 255.0); this->p.color.z = (unsigned char)(intensity * 255.0); } else if (7 == size1) { this->p.color.x = (unsigned char)(split[4]); this->p.color.y = (unsigned char)(split[5]); this->p.color.z = (unsigned char)(split[6]); } } else { this->p.intensity = INVALID_INTENSITY; } return true; }
/** Execute the algorithm. */ void LoadEventAndCompress::exec() { std::string filename = getPropertyValue("Filename"); double filterBadPulses = getProperty("FilterBadPulses"); m_chunkingTable = determineChunk(filename); Progress progress(this, 0, 1, 2); // first run is free progress.report("Loading Chunk"); MatrixWorkspace_sptr resultWS = loadChunk(0); progress.report("Process Chunk"); resultWS = processChunk(resultWS, filterBadPulses); // load the other chunks const size_t numRows = m_chunkingTable->rowCount(); progress.resetNumSteps(numRows, 0, 1); for (size_t i = 1; i < numRows; ++i) { MatrixWorkspace_sptr temp = loadChunk(i); temp = processChunk(temp, filterBadPulses); auto plusAlg = createChildAlgorithm("Plus"); plusAlg->setProperty("LHSWorkspace", resultWS); plusAlg->setProperty("RHSWorkspace", temp); plusAlg->setProperty("OutputWorkspace", resultWS); plusAlg->setProperty("ClearRHSWorkspace", true); plusAlg->executeAsChildAlg(); resultWS = plusAlg->getProperty("OutputWorkspace"); progress.report(); } Workspace_sptr total = assemble(resultWS); // Don't bother compressing combined workspace. DetermineChunking is designed // to prefer loading full banks so no further savings should be available. setProperty("OutputWorkspace", total); }
void setupEntities(ShaderProgram* program){ spriteSheetTexture = LoadTexture(RESOURCE_FOLDER"tiles_spritesheet2.png"); setupMainMenu(program); initPlayer(); loadChunk( createMapChunk(std::make_pair(0,0), NULL), false); loadChunk( createMapChunk(std::make_pair(1,0), NULL), false); loadChunk( createMapChunk(std::make_pair(1,1), NULL), false); loadChunk( createMapChunk(std::make_pair(0,1), NULL), false); loadChunk( createMapChunk(std::make_pair(-1,0), NULL), false); loadChunk( createMapChunk(std::make_pair(-1,-1), NULL), false); loadChunk( createMapChunk(std::make_pair(0,-1), NULL), false); loadChunk( createMapChunk(std::make_pair(1,-1), NULL), false); loadChunk( createMapChunk(std::make_pair(-1,1), NULL), false); LoadTexture(RESOURCE_FOLDER"tiles_spritesheet2.png"); }
// **************************************************************************** // __declspec(dllexport) int GetBlock(float _fX, float _fY, float _fZ) { int x = (int)_fX; int y = (int)_fY; int z = (int)_fZ; uint16 Type = Map.Get(x,y,z); if(Type == 65535)//not in RAM { if(!loadChunk(x-(x%ChunkLength), y-(y%ChunkLength), z-(z%ChunkLength)))//generate createChunk(x-(x%ChunkLength), y-(y%ChunkLength), z-(z%ChunkLength)); Type = Map.Get(x,y,z); } return Type; }
void loadRegion(std::istream &in) { FileUtils::streamRead(in, _locationTable.get(), 4096); FileUtils::streamRead(in, _timestampTable.get(), 4096); std::memset(_regionGrid.get(), 0, 512*256*512*sizeof(ElementType)); std::memset(_biomes.get(), 0xFF, 512*512*sizeof(uint8)); _regionHeight = 0; for (int i = 0; i < 1024; ++i) { int chunkX = i % 32; int chunkZ = i / 32; uint32 offset = 4*1024*( (uint32(_locationTable[i*4 + 0]) << 16) + (uint32(_locationTable[i*4 + 1]) << 8) + uint32(_locationTable[i*4 + 2])); uint32 length = uint32(_locationTable[i*4 + 3])*4*1024; if (offset == 0 || length == 0) continue; in.seekg(offset); FileUtils::streamRead(in, _compressedChunk.get(), length); uint32 chunkLength = (uint32(_compressedChunk[0]) << 24) + (uint32(_compressedChunk[1]) << 16) + (uint32(_compressedChunk[2]) << 8) + uint32(_compressedChunk[3]); if (_compressedChunk[4] != 2) { // Only accept Zlib compression tfm::printf("Ignoring chunk %i, %i with unsupported compression mode %i\n", chunkX, chunkZ, _compressedChunk[4]); std::cout.flush(); continue; } uLongf destLength = DecompressedChunkSize; if (uncompress(_decompressedChunk.get(), &destLength, _compressedChunk.get() + 5, chunkLength) != Z_OK) { tfm::printf("Decompression failed for chunk %i, %i\n", chunkX, chunkZ); std::cout.flush(); continue; } MemBuf buffer(reinterpret_cast<char *>(_decompressedChunk.get()), destLength); std::istream bufferStream(&buffer); loadChunk(bufferStream, i % 32, i/32); } }
const MapCell & MapImpl::get(int x, int y, int z) const { std::shared_ptr<Chunk> chunk = getChunk(x, y, z); boost::upgrade_lock<boost::shared_mutex> guard(chunk->lock); if(!chunk->accessor) { boost::upgrade_to_unique_lock<boost::shared_mutex> lock(guard); loadChunk(chunk); } // if (myAccessCounter++ % myAccessTolerance == 0) // prune(false); const MapCell & value = myBank->get(chunk->accessor->getValue( ovdb::Coord(x % myChunkSize.x(), y % myChunkSize.y(), z % myChunkSize.z()))); return value; }
static BOOL GT2_Load(BOOL curious) { GT_CHUNK *tmp; _mm_fseek(modreader, 0, SEEK_SET); while ((tmp = loadChunk()) != NULL) { #ifdef MIKMOD_DEBUG /* FIXME: to be completed */ fprintf(stderr, "%c%c%c%c\n", tmp->id[0], tmp->id[1], tmp->id[2], tmp->id[3]); #endif freeChunk(tmp); } _mm_errno = MMERR_LOADING_HEADER; return 0; }
// **************************************************************************** // // Load a map a generate a new one if file does not exists __declspec(dllexport) bool LoadBlockMap(wchar_t* _pcFileName) { ConcatpwChar(_pcFileName, L"\\"); Map.Dir = (wchar_t*) malloc(wss.str().length()+1); wcscpy(Map.Dir, wss.str().c_str()); CreateDirectoryW(_pcFileName, NULL); Map.IndexHigh = 0; Map.Ini();//inizialise, pointers get NULLed if(!loadChunk(0,0,0)) //ini map with 1 chunk loaded so that pChunkArray[0] is spezified createChunk( 0, 0, 0); Map.pChunkArray[0] = Map.pChunkArray[1]; // Errors are not supported! // Try open ConcatpwChar(Map.Dir,_pcFileName, L".map"); FILE* pFile = _wfopen(sss, L"rb"); if(!pFile) { // Seed random to file name uint32 dwSeed = 0; while(*_pcFileName) { dwSeed += *_pcFileName; // Only remark the real file not the path if(*_pcFileName == '/' || *_pcFileName == '\\') dwSeed = 0; ++_pcFileName; } PerlinObject2D.SetSeed(dwSeed); PerlinObject3D.SetSeed(dwSeed*1009 + 71); return false; } else { // Read and check for version... FileHeader FH; fread(&FH, sizeof(FileHeader), 1, pFile); if(FH.uiFileSignature != *(unsigned int*)FILE_SIGNATURE) return false; PerlinObject2D.SetSeed(FH.uiSeed2D); PerlinObject3D.SetSeed(FH.uiSeed3D); fclose(pFile); return true; } }
void loadWorld() { // Load in the world for (int rx = 0; rx < REGION_LENGTH; rx++) { for (int ry = 0; ry < REGION_WIDTH; ry++) { for (int cx = 0; cx < WORLD_LENGTH; cx++) { for (int cy = 0; cy < WORLD_WIDTH; cy++) { if (!loadChunk(rx, ry, cx, cy)){ printf("WORLD HAS NOT BEEN GENERATED!!!\n"); return; } } } } } }
void ServerConnector::loadAndPruneChunks() { ChunkPosition currentPosition = world()->chunkPosition(me()->v_position.x, me()->v_position.z); QList<ChunkPosition> wantedChunks; // The chunks we still want to be active // Create a list of the wanted chunks for(int x = - i_viewDistance; x < i_viewDistance+1; ++x) { for(int z = - i_viewDistance; z < i_viewDistance+1; ++z) { ChunkPosition position = ChunkPosition(currentPosition.first + x, currentPosition.second + z); wantedChunks.push_back(position); } } // Let's see if we have to prune unwanted ones... for (int i = 0; i < m_loadedChunks.size(); ++i) { ChunkPosition processingChunk = m_loadedChunks.at(i); // If the chunk is wanted if(wantedChunks.contains(processingChunk)) { // delete it from the wanted ones wantedChunks.removeOne(processingChunk); } else { // The chunk is unwanted, get rid of it unloadChunk(processingChunk); // Delete it from the loaded chunks list m_loadedChunks.removeAt(i); i--; } } // Now we load the chunks that were not in the loaded chunks for (int i = 0; i < wantedChunks.size(); ++i) { ChunkPosition processingChunk = wantedChunks.at(i); loadChunk(processingChunk); m_loadedChunks.push_back(processingChunk); } }
void DeviceAudioDX11::primeStreaming (DeviceAudioDX11Channel &channel) { // Load the buffer for (DTuint i = 0; i < NUM_BUFFERS; ++i) { if (loadChunk (channel)) { SoundPacket &packet = channel._packets[channel._current_packet]; // Enqueue the buffer XAUDIO2_BUFFER x_buffer; x_buffer.Flags = 0; x_buffer.AudioBytes = packet.getNumBytes(); x_buffer.pAudioData = packet.getBuffer(); x_buffer.PlayBegin = 0; x_buffer.PlayLength = 0; x_buffer.LoopBegin = XAUDIO2_NO_LOOP_REGION; x_buffer.LoopLength = 0; x_buffer.LoopCount = 0; x_buffer.pContext = &channel; channel._x_voice->SubmitSourceBuffer(&x_buffer); } else { channel._x_voice->Discontinuity(); break; } } channel._needs_priming = false; }
Music::Music(void) { Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048); vMusic.push_back(loadMusic("overworld")); vMusic.push_back(loadMusic("overworld-fast")); vMusic.push_back(loadMusic("underground")); vMusic.push_back(loadMusic("underground-fast")); vMusic.push_back(loadMusic("underwater")); vMusic.push_back(loadMusic("underwater-fast")); vMusic.push_back(loadMusic("castle")); vMusic.push_back(loadMusic("castle-fast")); vMusic.push_back(loadMusic("lowtime")); vMusic.push_back(loadMusic("starmusic")); vMusic.push_back(loadMusic("starmusic-fast")); vMusic.push_back(loadMusic("scorering")); vChunk.push_back(loadChunk("coin")); vChunk.push_back(loadChunk("blockbreak")); vChunk.push_back(loadChunk("blockhit")); vChunk.push_back(loadChunk("boom")); vChunk.push_back(loadChunk("bowserfall")); vChunk.push_back(loadChunk("bridgebreak")); vChunk.push_back(loadChunk("bulletbill")); vChunk.push_back(loadChunk("death")); vChunk.push_back(loadChunk("fire")); vChunk.push_back(loadChunk("fireball")); vChunk.push_back(loadChunk("gameover")); vChunk.push_back(loadChunk("intermission")); vChunk.push_back(loadChunk("jump")); vChunk.push_back(loadChunk("jumpbig")); vChunk.push_back(loadChunk("levelend")); vChunk.push_back(loadChunk("lowtime")); vChunk.push_back(loadChunk("mushroomappear")); vChunk.push_back(loadChunk("mushroomeat")); vChunk.push_back(loadChunk("oneup")); vChunk.push_back(loadChunk("pause")); vChunk.push_back(loadChunk("shrink")); vChunk.push_back(loadChunk("rainboom")); vChunk.push_back(loadChunk("shot")); vChunk.push_back(loadChunk("shrink")); vChunk.push_back(loadChunk("stomp")); vChunk.push_back(loadChunk("swim")); vChunk.push_back(loadChunk("vine")); vChunk.push_back(loadChunk("castleend")); vChunk.push_back(loadChunk("princessmusic")); setVolume(100); this->currentMusic = mNOTHING; }
void PTXPointReader::scanForAABB() { // read bounding box double x(0), y(0), z(0); // TODO: verify that this initial values are ok double minx = std::numeric_limits<float>::max(); double miny = std::numeric_limits<float>::max(); double minz = std::numeric_limits<float>::max(); double maxx = -std::numeric_limits<float>::max(); double maxy = -std::numeric_limits<float>::max(); double maxz = -std::numeric_limits<float>::max(); double intensity(0); bool firstPoint = true; bool pleaseStop = false; long currentChunk = 0; long count = 0; double tr[16]; vector<double> split; for (const auto &file : files) { fstream stream(file, ios::in); currentChunk = 0; getlined(stream, split); while (!pleaseStop) { if (1 == split.size()) { if (!loadChunk(&stream, currentChunk, tr)) { break; } } while (true) { getlined(stream, split); if (4 == split.size() || 7 == split.size()) { x = split[0]; y = split[1]; z = split[2]; intensity = split[3]; if (0.5 != intensity) { Point p = transform(tr, x, y, z); if (firstPoint) { maxx = minx = p.position.x; maxy = miny = p.position.y; maxz = minz = p.position.z; firstPoint = false; } else { minx = p.position.x < minx ? p.position.x : minx; maxx = p.position.x > maxx ? p.position.x : maxx; miny = p.position.y < miny ? p.position.y : miny; maxy = p.position.y > maxy ? p.position.y : maxy; minz = p.position.z < minz ? p.position.z : minz; maxz = p.position.z > maxz ? p.position.z : maxz; } count++; if (0 == count % 1000000) cout << "AABB-SCANNING: " << count << " points; " << currentChunk << " chunks" << endl; } } else { break; } } if (stream.eof()) { pleaseStop = true; break; } currentChunk++; } stream.close(); } counts[path] = count; AABB lAABB(Vector3<double>(minx, miny, minz), Vector3<double>(maxx, maxy, maxz)); PTXPointReader::aabbs[path] = lAABB; }
void loadIfEmpty(pair<int, int> p ){ if (ChunkMap.find(p) == ChunkMap.end()) { loadChunk(createMapChunk(p, NULL), true); } }