| 
						
						
						
					 | 
					 | 
					@ -1,3 +1,6 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					// This file takes renders vertex buffers and manages
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					// threads that invoke mesh building (found in cave_mesher.c)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include "stb_voxel_render.h" | 
					 | 
					 | 
					 | 
					#include "stb_voxel_render.h" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#define STB_GLEXT_DECLARE "glext_list.h" | 
					 | 
					 | 
					 | 
					#define STB_GLEXT_DECLARE "glext_list.h" | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -57,10 +60,6 @@ typedef struct | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} chunk_mesh; | 
					 | 
					 | 
					 | 
					} chunk_mesh; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					extern SDL_mutex * chunk_cache_mutex; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					extern SDL_mutex * chunk_get_mutex; | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					void scale_texture(unsigned char *src, int x, int y, int w, int h) | 
					 | 
					 | 
					 | 
					void scale_texture(unsigned char *src, int x, int y, int w, int h) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					{ | 
					 | 
					 | 
					 | 
					{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					   int i,j,k; | 
					 | 
					 | 
					 | 
					   int i,j,k; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -511,6 +510,8 @@ void world_init(void) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					   reset_cache_size(32); | 
					 | 
					 | 
					 | 
					   reset_cache_size(32); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					extern SDL_mutex * chunk_cache_mutex; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					int mesh_worker_handler(void *data) | 
					 | 
					 | 
					 | 
					int mesh_worker_handler(void *data) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					{ | 
					 | 
					 | 
					 | 
					{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					   mesh_worker *mw = data; | 
					 | 
					 | 
					 | 
					   mesh_worker *mw = data; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -549,6 +550,8 @@ int mesh_worker_handler(void *data) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      // when done, free the chunks
 | 
					 | 
					 | 
					 | 
					      // when done, free the chunks
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      // for efficiency we just take the mutex once around the whole thing,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      // though this spreads the mutex logic over two files
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      SDL_LockMutex(chunk_cache_mutex); | 
					 | 
					 | 
					 | 
					      SDL_LockMutex(chunk_cache_mutex); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      for (j=0; j < 4; ++j) | 
					 | 
					 | 
					 | 
					      for (j=0; j < 4; ++j) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					         for (i=0; i < 4; ++i) { | 
					 | 
					 | 
					 | 
					         for (i=0; i < 4; ++i) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -594,9 +597,6 @@ void prepare_threads(void) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					   if (num_mesh_workers > MAX_MESH_WORKERS) | 
					 | 
					 | 
					 | 
					   if (num_mesh_workers > MAX_MESH_WORKERS) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      num_mesh_workers = MAX_MESH_WORKERS; | 
					 | 
					 | 
					 | 
					      num_mesh_workers = MAX_MESH_WORKERS; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					   chunk_cache_mutex = SDL_CreateMutex(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					   chunk_get_mutex   = SDL_CreateMutex(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					   for (i=0; i < num_mesh_workers; ++i) { | 
					 | 
					 | 
					 | 
					   for (i=0; i < num_mesh_workers; ++i) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      mesh_worker *data = &mesh_data[i]; | 
					 | 
					 | 
					 | 
					      mesh_worker *data = &mesh_data[i]; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      data->request_received = SDL_CreateSemaphore(0); | 
					 | 
					 | 
					 | 
					      data->request_received = SDL_CreateSemaphore(0); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |