initialize cache mutexes in right file
This commit is contained in:
parent
cd17050ca4
commit
5a0dcc90d6
@ -1,3 +1,5 @@
|
|||||||
|
// This file takes minecraft chunks (decoded by cave_parse) and
|
||||||
|
// uses stb_voxel_render to turn them into vertex buffers.
|
||||||
|
|
||||||
#define STB_GLEXT_DECLARE "glext_list.h"
|
#define STB_GLEXT_DECLARE "glext_list.h"
|
||||||
#include "stb_gl.h"
|
#include "stb_gl.h"
|
||||||
@ -452,6 +454,7 @@ void reset_cache_size(int size)
|
|||||||
cache_size = size;
|
cache_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this must be called inside mutex
|
||||||
void deref_fastchunk(fast_chunk *fc)
|
void deref_fastchunk(fast_chunk *fc)
|
||||||
{
|
{
|
||||||
if (fc) {
|
if (fc) {
|
||||||
@ -672,6 +675,9 @@ void mesh_init(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
chunk_cache_mutex = SDL_CreateMutex();
|
||||||
|
chunk_get_mutex = SDL_CreateMutex();
|
||||||
|
|
||||||
for (i=0; i < 256; ++i) {
|
for (i=0; i < 256; ++i) {
|
||||||
memcpy(minecraft_tex1_for_blocktype[i], minecraft_info[i]+1, 6);
|
memcpy(minecraft_tex1_for_blocktype[i], minecraft_info[i]+1, 6);
|
||||||
minecraft_trans_for_blocktype[i] = (minecraft_info[i][0] != C_solid && minecraft_info[i][0] != C_water);
|
minecraft_trans_for_blocktype[i] = (minecraft_info[i][0] != C_solid && minecraft_info[i][0] != C_water);
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user