Séparation Chunk::Update et VertexBuffer::SetMeshData, Cleanup
This commit is contained in:
		| @@ -51,34 +51,42 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) { | ||||
| 	if (x > 0) { | ||||
| 		for (int ax = 0; ax < WORLD_SIZE_X; ++ax) | ||||
| 			for (int ay = 0; ay < WORLD_SIZE_Y; ++ay) | ||||
| 				if (ax - x >= 0) | ||||
| 				if (ax - x >= 0) { | ||||
| 					m_chunks.Set(ax - x, ay, | ||||
| 						m_chunks.Remove(ax, ay)); | ||||
| 					if (ax == WORLD_SIZE_X - 1) m_chunks.Get(ax - x, ay)->MakeDirty(); | ||||
| 				} | ||||
| 				else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); | ||||
| 	} | ||||
| 	else if (x < 0) { | ||||
| 		for (int ax = WORLD_SIZE_X - 1; ax >= 0; --ax) | ||||
| 			for (int ay = WORLD_SIZE_Y - 1; ay >= 0; --ay) | ||||
| 				if (ax - x < WORLD_SIZE_X) | ||||
| 				if (ax - x < WORLD_SIZE_X) { | ||||
| 					m_chunks.Set(ax - x, ay, | ||||
| 						m_chunks.Remove(ax, ay)); | ||||
| 					if (ax + x == 0) m_chunks.Get(ax + x, ay)->MakeDirty(); | ||||
| 				} | ||||
| 				else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); | ||||
| 	} | ||||
|  | ||||
| 	if (y > 0) { | ||||
| 		for (int ax = 0; ax < WORLD_SIZE_X; ++ax) | ||||
| 			for (int ay = 0; ay < WORLD_SIZE_Y; ++ay) | ||||
| 				if (ay - y >= 0) | ||||
| 				if (ay - y >= 0) { | ||||
| 					m_chunks.Set(ax, ay - y, | ||||
| 						m_chunks.Remove(ax, ay)); | ||||
| 					if (ay == WORLD_SIZE_Y) m_chunks.Get(ax, ay - y)->MakeDirty(); | ||||
| 				} | ||||
| 				else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); | ||||
| 	} | ||||
| 	else if (y < 0) { | ||||
| 		for (int ax = WORLD_SIZE_X - 1; ax >= 0; --ax) | ||||
| 			for (int ay = WORLD_SIZE_Y - 1; ay >= 0; --ay) | ||||
| 				if (ay - y < WORLD_SIZE_Y) | ||||
| 				if (ay - y < WORLD_SIZE_Y) { | ||||
| 					m_chunks.Set(ax, ay - y, | ||||
| 						m_chunks.Remove(ax, ay)); | ||||
| 					if (ay - x == 0) m_chunks.Get(ax, ay - y)->MakeDirty(); | ||||
| 				} | ||||
| 				else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay)); | ||||
| 	} | ||||
|  | ||||
| @@ -289,14 +297,14 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY | ||||
| 	int side = 0; | ||||
| 	int threads = 0; | ||||
| 	std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS]; | ||||
| 	//std::future<Chunk*> updateThList[THREADS_UPDATE_CHUNKS]; | ||||
| 	std::future<Chunk*> updateThList[THREADS_UPDATE_CHUNKS]; | ||||
|  | ||||
| 	if (frameGenerate > 0) --frameGenerate; | ||||
| 	if (frameUpdate > 0) --frameUpdate; | ||||
| 	if (frameDelete > 0) --frameDelete; | ||||
|  | ||||
| 	if (!frameGenerate) | ||||
| 		while (side * CHUNK_SIZE_X <= VIEW_DISTANCE * 2) { | ||||
| 		while (side * CHUNK_SIZE_X <= VIEW_DISTANCE * 2 + CHUNK_SIZE_X) { | ||||
| 			int tx = -side, ty = -side; | ||||
| 			int chx = 0; | ||||
| 			int chy = 0; | ||||
| @@ -370,10 +378,13 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY | ||||
| 					break; | ||||
| 				int chx = cx + tx * CHUNK_SIZE_X; | ||||
| 				int chy = cy + ty * CHUNK_SIZE_Z; | ||||
| 				if (ChunkAt(chx, 1, chy) && | ||||
| 				if (ChunkAt(chx, 1, chy) &&  | ||||
| 					ChunkAt(chx, 1, chy)->IsDirty()) { | ||||
| 					ChunkAt(chx, 1, chy)->Update(blockinfo, this); | ||||
| 					if (threads++ == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 					updateThList[threads++] = | ||||
| 						std::async(std::launch::async, | ||||
| 							[](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { | ||||
| 								chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); | ||||
| 					if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 				} | ||||
| 			}	 | ||||
| 			for (; ty <= side; ++ty) { | ||||
| @@ -381,10 +392,13 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY | ||||
| 					break; | ||||
| 				int chx = cx + tx * CHUNK_SIZE_X; | ||||
| 				int chy = cy + ty * CHUNK_SIZE_Z; | ||||
| 				if (ChunkAt(chx, 1, chy) && | ||||
| 				if (ChunkAt(chx, 1, chy) &&  | ||||
| 					ChunkAt(chx, 1, chy)->IsDirty()) { | ||||
| 					ChunkAt(chx, 1, chy)->Update(blockinfo, this); | ||||
| 					if (threads++ == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 					updateThList[threads++] = | ||||
| 						std::async(std::launch::async, | ||||
| 							[](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { | ||||
| 								chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); | ||||
| 					if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 				} | ||||
| 			}	 | ||||
| 			for (; tx >= -side; --tx) { | ||||
| @@ -392,10 +406,13 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY | ||||
| 					break; | ||||
| 				int chx = cx + tx * CHUNK_SIZE_X; | ||||
| 				int chy = cy + ty * CHUNK_SIZE_Z; | ||||
| 				if (ChunkAt(chx, 1, chy) && | ||||
| 				if (ChunkAt(chx, 1, chy) &&  | ||||
| 					ChunkAt(chx, 1, chy)->IsDirty()) { | ||||
| 					ChunkAt(chx, 1, chy)->Update(blockinfo, this); | ||||
| 					if (threads++ == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 					updateThList[threads++] = | ||||
| 						std::async(std::launch::async, | ||||
| 							[](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { | ||||
| 								chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); | ||||
| 					if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 				} | ||||
| 			}	 | ||||
| 			for (; ty >= -side; --ty) { | ||||
| @@ -403,36 +420,27 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY | ||||
| 					break; | ||||
| 				int chx = cx + tx * CHUNK_SIZE_X; | ||||
| 				int chy = cy + ty * CHUNK_SIZE_Z; | ||||
| 				if (ChunkAt(chx, 1, chy) && | ||||
| 					ChunkAt(chx, 1, chy)->IsDirty()) { | ||||
| 					ChunkAt(chx, 1, chy)->Update(blockinfo, this); | ||||
| 					if (threads++ == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 				} | ||||
| 				/*if (ChunkAt(chx, 1, chy) && // Version multithread d'UpdateChunks qui ne fonctionne pas. | ||||
| 				if (ChunkAt(chx, 1, chy) &&  | ||||
| 					ChunkAt(chx, 1, chy)->IsDirty()) { | ||||
| 					updateThList[threads++] = | ||||
| 						std::async(std::launch::async, | ||||
| 							[](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { | ||||
| 								chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); | ||||
| 					if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; | ||||
| 				}*/ | ||||
| 				} | ||||
| 			}		 | ||||
| 			if (frameUpdate) | ||||
| 				break; | ||||
| 			++side; | ||||
| 		} | ||||
|  | ||||
| 	/*if (threads > 0) { | ||||
| 		for (int i = 0; i < threads; ++i) | ||||
| 			updateThList[i].wait(); | ||||
|  | ||||
| 	if (threads > 0) { | ||||
| 		for (int i = 0; i < threads; ++i) { | ||||
| 			int x, y; | ||||
| 			updateThList[i].wait(); | ||||
| 			Chunk* chunk = updateThList[i].get(); | ||||
| 			chunk->GetPosition(x, y); | ||||
| 			m_chunks.Set(x - m_center[0], y - m_center[1], chunk); | ||||
| 			chunk->FlushMeshToVBO(); | ||||
| 		} | ||||
| 	}*/ | ||||
| 	} | ||||
|  | ||||
| 	CleanUpWorld(frameDelete); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user