void Space::UpdateChunks( float dt ) { const Vec2i chunk_index = CurrentChunkIndex(); if( SETTINGS->GetValue<bool>( "show_pos" ) ) { std::stringstream ss; Vec2i ip = satellite.GetPos(); ss << "pos: " << ip << " in chunk " << chunk_index << '\n'; Tree::VisualDebug( ss.str() ); } // Not yet checked chunk if( checked_chunks.find( chunk_index ) == checked_chunks.end() ) { // Allocate this chunk (probably done but it gets checked anyway AllocateChunk( chunk_index ); // Allocate surrounding chunks AllocateChunk( chunk_index.x - 1, chunk_index.y ); AllocateChunk( chunk_index.x + 1, chunk_index.y ); AllocateChunk( chunk_index.x, chunk_index.y - 1 ); AllocateChunk( chunk_index.x, chunk_index.y + 1 ); AllocateChunk( chunk_index.x - 1, chunk_index.y - 1 ); AllocateChunk( chunk_index.x - 1, chunk_index.y + 1 ); AllocateChunk( chunk_index.x + 1, chunk_index.y - 1 ); AllocateChunk( chunk_index.x + 1, chunk_index.y + 1 ); } // Debug current chunks if( SETTINGS->GetValue<bool>( "chunk_count" ) ) { std::stringstream ss; ss << chunks.size() << " chunks\n"; Tree::VisualDebug( ss.str() ); } // Update all visible chunks! UpdateChunk( chunk_index, dt ); UpdateChunk( chunk_index.x - 1, chunk_index.y, dt ); UpdateChunk( chunk_index.x + 1, chunk_index.y, dt ); UpdateChunk( chunk_index.x, chunk_index.y - 1, dt ); UpdateChunk( chunk_index.x, chunk_index.y + 1, dt ); UpdateChunk( chunk_index.x - 1, chunk_index.y - 1, dt ); UpdateChunk( chunk_index.x - 1, chunk_index.y + 1, dt ); UpdateChunk( chunk_index.x + 1, chunk_index.y - 1, dt ); UpdateChunk( chunk_index.x + 1, chunk_index.y + 1, dt ); }
void GLRadiosityRenderer::UpdateDirtyChunks() { int dirtyChunkIds[256]; int numDirtyChunks = 0; int nearDirtyChunks = 0; // first, check only chunks in near range Vector3 eyePos = renderer->GetSceneDef().viewOrigin; int eyeX = (int)(eyePos.x) >> ChunkSizeBits; int eyeY = (int)(eyePos.y) >> ChunkSizeBits; int eyeZ = (int)(eyePos.z) >> ChunkSizeBits; for (size_t i = 0; i < chunks.size(); i++) { Chunk &c = chunks[i]; int dx = (c.cx - eyeX) & (chunkW - 1); int dy = (c.cy - eyeY) & (chunkH - 1); int dz = (c.cz - eyeZ); if (dx >= 6 && dx <= chunkW - 6) continue; if (dy >= 6 && dy <= chunkW - 6) continue; if (dz >= 6 || dz <= -6) continue; if (c.dirty) { dirtyChunkIds[numDirtyChunks++] = static_cast<int>(i); nearDirtyChunks++; if (numDirtyChunks >= 256) break; } } // far chunks if (numDirtyChunks == 0) { for (size_t i = 0; i < chunks.size(); i++) { Chunk &c = chunks[i]; if (c.dirty) { dirtyChunkIds[numDirtyChunks++] = static_cast<int>(i); if (numDirtyChunks >= 256) break; } } } // limit update count per frame for (int i = 0; i < 8; i++) { if (numDirtyChunks <= 0) break; int idx = SampleRandomInt(0, numDirtyChunks - 1); Chunk &c = chunks[dirtyChunkIds[idx]]; // remove from list (fast) if (idx < numDirtyChunks - 1) { std::swap(dirtyChunkIds[idx], dirtyChunkIds[numDirtyChunks - 1]); } numDirtyChunks--; UpdateChunk(c.cx, c.cy, c.cz); } /* printf("%d (%d near) chunk update left\n", GetNumDirtyChunks(), nearDirtyChunks);*/ }
void ChunkedUpdateDrawingArea::setSize(const IntSize& viewSize) { ASSERT_ARG(viewSize, !viewSize.isEmpty()); // We don't want to wait for an update until we display. m_isWaitingForUpdate = false; m_webPage->setSize(viewSize); // Layout if necessary. m_webPage->layoutIfNeeded(); if (m_paintingIsSuspended) { ASSERT(!m_displayTimer.isActive()); // Painting is suspended, just send back an empty update chunk. WebProcess::shared().connection()->send(DrawingAreaProxyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In(UpdateChunk())); return; } // Create a new UpdateChunk and paint into it. UpdateChunk updateChunk(IntRect(0, 0, viewSize.width(), viewSize.height())); paintIntoUpdateChunk(&updateChunk); m_displayTimer.stop(); WebProcess::shared().connection()->send(DrawingAreaProxyMessage::DidSetSize, m_webPage->pageID(), CoreIPC::In(updateChunk)); }
void Space::UpdateChunk( int x, int y, float dt ) { UpdateChunk( Vec2i( x, y ), dt ); }