diff --git a/src/chunk.c b/src/chunk.c index 367d8d6..2ef8275 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -37,6 +37,8 @@ struct chunk_d { struct chunk_worker chunk_workers[CHUNK_WORKERS_MAX]; +int chunk_enabled_cores; + pthread_rwlock_t* chunk_map_locks; pthread_mutex_t chunk_minimap_lock; @@ -48,12 +50,14 @@ static int chunk_sort(const void* a, const void* b) { } void chunk_init() { + chunk_enabled_cores = min(max(window_cpucores()/2,1),CHUNK_WORKERS_MAX); + log_info("%i cores enabled for chunk generation",chunk_enabled_cores); pthread_mutex_init(&chunk_minimap_lock,NULL); chunk_map_locks = malloc(map_size_x*map_size_z*sizeof(pthread_rwlock_t)); CHECK_ALLOCATION_ERROR(chunk_map_locks); for(int k=0;k #endif #ifdef __APPLE__ diff --git a/src/window.c b/src/window.c index f04980d..f4eb2f2 100644 --- a/src/window.c +++ b/src/window.c @@ -3,18 +3,18 @@ This file is part of BetterSpades. - BetterSpades is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - BetterSpades is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with BetterSpades. If not, see . + BetterSpades is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BetterSpades is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BetterSpades. If not, see . */ #include "common.h" @@ -22,57 +22,57 @@ #ifdef USE_GLFW static void window_impl_mouseclick(GLFWwindow* window, int button, int action, int mods) { - int b = 0; - switch(button) { - case GLFW_MOUSE_BUTTON_LEFT: - b = WINDOW_MOUSE_LMB; - break; - case GLFW_MOUSE_BUTTON_RIGHT: - b = WINDOW_MOUSE_RMB; - break; - case GLFW_MOUSE_BUTTON_MIDDLE: - b = WINDOW_MOUSE_MMB; - break; - } - int a = -1; - switch(action) { - case GLFW_RELEASE: - a = WINDOW_RELEASE; - break; - case GLFW_PRESS: - a = WINDOW_PRESS; - break; - } - mouse_click(hud_window,b,a,mods>0); + int b = 0; + switch(button) { + case GLFW_MOUSE_BUTTON_LEFT: + b = WINDOW_MOUSE_LMB; + break; + case GLFW_MOUSE_BUTTON_RIGHT: + b = WINDOW_MOUSE_RMB; + break; + case GLFW_MOUSE_BUTTON_MIDDLE: + b = WINDOW_MOUSE_MMB; + break; + } + int a = -1; + switch(action) { + case GLFW_RELEASE: + a = WINDOW_RELEASE; + break; + case GLFW_PRESS: + a = WINDOW_PRESS; + break; + } + mouse_click(hud_window,b,a,mods>0); } static void window_impl_mouse(GLFWwindow* window, double x, double y) { - mouse(hud_window,x,y); + mouse(hud_window,x,y); } static void window_impl_mousescroll(GLFWwindow* window, double xoffset, double yoffset) { - mouse_scroll(hud_window,xoffset,yoffset); + mouse_scroll(hud_window,xoffset,yoffset); } static void window_impl_error(int i, const char* s) { - on_error(i,s); + on_error(i,s); } static void window_impl_reshape(GLFWwindow* window, int width, int height) { - reshape(hud_window,width,height); + reshape(hud_window,width,height); } static void window_impl_textinput(GLFWwindow* window, unsigned int codepoint) { - text_input(hud_window,codepoint); + text_input(hud_window,codepoint); } static void window_impl_keys(GLFWwindow* window, int key, int scancode, int action, int mods) { - int a = -1; - switch(action) { - case GLFW_RELEASE: - a = WINDOW_RELEASE; - break; - case GLFW_PRESS: - a = WINDOW_PRESS; - break; - } - int tr = window_key_translate(key,0); - if(tr>=0) - keys(hud_window,tr,scancode,a,mods>0); + int a = -1; + switch(action) { + case GLFW_RELEASE: + a = WINDOW_RELEASE; + break; + case GLFW_PRESS: + a = WINDOW_PRESS; + break; + } + int tr = window_key_translate(key,0); + if(tr>=0) + keys(hud_window,tr,scancode,a,mods>0); else tr = WINDOW_KEY_UNKNOWN; if(hud_active->input_keyboard) @@ -84,48 +84,47 @@ char* window_keyname(int keycode) { } float window_time() { - return glfwGetTime(); + return glfwGetTime(); } int window_pressed_keys[64] = {0}; const char* window_clipboard() { - return glfwGetClipboardString(hud_window->impl); + return glfwGetClipboardString(hud_window->impl); } int window_key_translate(int key, int dir) { - return config_key_translate(key,dir); + return config_key_translate(key,dir); } int window_key_down(int key) { - return window_pressed_keys[key]; + return window_pressed_keys[key]; } void window_mousemode(int mode) { - int s = glfwGetInputMode(hud_window->impl,GLFW_CURSOR); - if((s==GLFW_CURSOR_DISABLED && mode==WINDOW_CURSOR_ENABLED) - || (s==GLFW_CURSOR_NORMAL && mode==WINDOW_CURSOR_DISABLED)) { - glfwSetInputMode(hud_window->impl,GLFW_CURSOR,mode==WINDOW_CURSOR_ENABLED?GLFW_CURSOR_NORMAL:GLFW_CURSOR_DISABLED); - } + int s = glfwGetInputMode(hud_window->impl,GLFW_CURSOR); + if((s==GLFW_CURSOR_DISABLED && mode==WINDOW_CURSOR_ENABLED) + || (s==GLFW_CURSOR_NORMAL && mode==WINDOW_CURSOR_DISABLED)) + glfwSetInputMode(hud_window->impl,GLFW_CURSOR,mode==WINDOW_CURSOR_ENABLED?GLFW_CURSOR_NORMAL:GLFW_CURSOR_DISABLED); } void window_mouseloc(double* x, double* y) { - glfwGetCursorPos(hud_window->impl,x,y); + glfwGetCursorPos(hud_window->impl,x,y); } void window_swapping(int value) { - glfwSwapInterval(value); + glfwSwapInterval(value); } void window_init() { - static struct window_instance i; - hud_window = &i; + static struct window_instance i; + hud_window = &i; - glfwWindowHint(GLFW_VISIBLE,0); + glfwWindowHint(GLFW_VISIBLE,0); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,1); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,1); - glfwSetErrorCallback(window_impl_error); + glfwSetErrorCallback(window_impl_error); if(!glfwInit()) { log_fatal("GLFW3 init failed"); @@ -178,12 +177,12 @@ void window_deinit() { } void window_update() { - glfwSwapBuffers(hud_window->impl); - glfwPollEvents(); + glfwSwapBuffers(hud_window->impl); + glfwPollEvents(); } int window_closed() { - return glfwWindowShouldClose(hud_window->impl); + return glfwWindowShouldClose(hud_window->impl); } #endif @@ -200,28 +199,27 @@ char* window_keyname(int keycode) { } float window_time() { - return ((double)SDL_GetTicks())/1000.0F; + return ((double)SDL_GetTicks())/1000.0F; } int window_pressed_keys[64] = {0}; const char* window_clipboard() { - return SDL_HasClipboardText()?SDL_GetClipboardText():NULL; + return SDL_HasClipboardText()?SDL_GetClipboardText():NULL; } int window_key_translate(int key, int dir) { - return config_key_translate(key,dir); + return config_key_translate(key,dir); } int window_key_down(int key) { - return window_pressed_keys[key]; + return window_pressed_keys[key]; } void window_mousemode(int mode) { int s = SDL_GetRelativeMouseMode(); - if((s && mode==WINDOW_CURSOR_ENABLED) || (!s && mode==WINDOW_CURSOR_DISABLED)) { + if((s && mode==WINDOW_CURSOR_ENABLED) || (!s && mode==WINDOW_CURSOR_DISABLED)) SDL_SetRelativeMouseMode(mode==WINDOW_CURSOR_ENABLED?0:1); - } } void window_mouseloc(double* x, double* y) { @@ -232,7 +230,7 @@ void window_mouseloc(double* x, double* y) { } void window_swapping(int value) { - SDL_GL_SetSwapInterval(value); + SDL_GL_SetSwapInterval(value); } void window_init() { @@ -248,7 +246,7 @@ void window_init() { SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8); - //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); SDL_GLContext* ctx = SDL_GL_CreateContext(hud_window->impl); } @@ -269,8 +267,6 @@ void window_update() { break; case SDL_KEYDOWN: { - if(event.key.keysym.sym==SDLK_p) - exit(0); int tr = window_key_translate(event.key.keysym.sym,0); if(tr>=0) keys(hud_window,tr,event.key.keysym.sym,WINDOW_PRESS,0); @@ -350,17 +346,14 @@ void window_update() { } int window_closed() { - return quit; + return quit; } #endif int window_cpucores() { #ifdef OS_LINUX - int count; - int size = sizeof(int); - sysctlbyname("hw.ncpu",&count,&size,NULL,0); - return count; + return get_nprocs(); #endif #ifdef OS_WINDOWS SYSTEM_INFO info;