From 1c1677f02300e5ab10bca9c74ce7f49d4605b9d6 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sat, 12 Jan 2008 12:08:26 +0000 Subject: merged 0.3.3 changes over to trunk --- src/engine/client/ec_client.c | 23 ++++++++++++- src/engine/client/ec_gfx.c | 34 ++++++++++--------- src/engine/client/ec_inp.c | 71 ++++++++++++++++++++++++++-------------- src/engine/client/ec_snd.c | 27 +++++++++++++-- src/engine/client/ec_srvbrowse.c | 6 ++++ 5 files changed, 118 insertions(+), 43 deletions(-) (limited to 'src/engine/client') diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index d35121de..b07edf78 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -304,6 +304,24 @@ int client_connection_problems() return netclient_gotproblems(net); } +void client_direct_input(int *input, int size) +{ + int i; + msg_pack_start_system(NETMSG_INPUT, 0); + msg_pack_int(ack_game_tick); + msg_pack_int(current_predtick); + msg_pack_int(size); + + for(i = 0; i < size/4; i++) + msg_pack_int(input[i]); + + msg_pack_end(); + client_send_msg(); + + dbg_msg("client", "sent direct input"); +} + + static void client_send_input() { int64 now = time_get(); @@ -312,7 +330,7 @@ static void client_send_input() if(current_predtick <= 0) return; - /* fetch input */ + /* fetch input */ size = modc_snap_input(inputs[current_input].data); msg_pack_start_system(NETMSG_INPUT, 0); @@ -1006,6 +1024,9 @@ static void client_run() /* update input */ inp_update(); + + /* update sound */ + snd_update(); /* refocus */ if(!gfx_window_active()) diff --git a/src/engine/client/ec_gfx.c b/src/engine/client/ec_gfx.c index 0562a24f..70712ded 100644 --- a/src/engine/client/ec_gfx.c +++ b/src/engine/client/ec_gfx.c @@ -489,20 +489,22 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_f gluBuild2DMipmaps(GL_TEXTURE_2D, store_oglformat, w, h, oglformat, GL_UNSIGNED_BYTE, texdata); /* calculate memory usage */ - int pixel_size = 4; - if(store_format == IMG_RGB) - pixel_size = 3; - else if(store_format == IMG_ALPHA) - pixel_size = 1; - - textures[tex].memsize = w*h*pixel_size; - if(mipmap) { - while(w > 2 && h > 2) + int pixel_size = 4; + if(store_format == IMG_RGB) + pixel_size = 3; + else if(store_format == IMG_ALPHA) + pixel_size = 1; + + textures[tex].memsize = w*h*pixel_size; + if(mipmap) { - w>>=1; - h>>=1; - textures[tex].memsize += w*h*pixel_size; + while(w > 2 && h > 2) + { + w>>=1; + h>>=1; + textures[tex].memsize += w*h*pixel_size; + } } } @@ -544,7 +546,9 @@ int gfx_load_mip_texture_raw(int w, int h, int format, const void *data) int gfx_load_texture(const char *filename, int store_format) { int l = strlen(filename); + int id; IMAGE_INFO img; + if(l < 3) return 0; if(gfx_load_png(&img, filename)) @@ -552,7 +556,7 @@ int gfx_load_texture(const char *filename, int store_format) if (store_format == IMG_AUTO) store_format = img.format; - int id = gfx_load_texture_raw(img.width, img.height, img.format, img.data, store_format); + id = gfx_load_texture_raw(img.width, img.height, img.format, img.data, store_format); mem_free(img.data); return id; } @@ -1101,7 +1105,7 @@ void gfx_pretty_text(float x, float y, float size, const char *text, int max_wid float gfx_pretty_text_width(float size, const char *text_, int length) { return gfx_text_width(gfx_font_set, size, text_, length); - + /* const float spacing = 0.05f; float w = 0.0f; const unsigned char *text = (unsigned char *)text_; @@ -1126,7 +1130,7 @@ float gfx_pretty_text_width(float size, const char *text_, int length) text++; } - return w; + return w;*/ } diff --git a/src/engine/client/ec_inp.c b/src/engine/client/ec_inp.c index 154342f4..cac69669 100644 --- a/src/engine/client/ec_inp.c +++ b/src/engine/client/ec_inp.c @@ -48,19 +48,56 @@ void inp_mouse_relative(int *x, int *y) last_y = ny; } -static char last_c = 0; -static int last_k = 0; +enum +{ + INPUT_BUFFER_SIZE=32 +}; + +static INPUTEVENT input_events[INPUT_BUFFER_SIZE]; +static int num_events = 0; + +static void add_event(char c, int key) +{ + if(num_events != INPUT_BUFFER_SIZE) + { + input_events[num_events].ch = c; + input_events[num_events].key = key; + num_events++; + } +} + +int inp_num_events() +{ + return num_events; +} + +void inp_clear_events() +{ + num_events = 0; +} + +INPUTEVENT inp_get_event(int index) +{ + if(index < 0 || index >= num_events) + { + INPUTEVENT e = {0,0}; + return e; + } + + return input_events[index]; +} + static void char_callback(int character, int action) { if(action == GLFW_PRESS && character < 256) - last_c = (char)character; + add_event((char)character, 0); } static void key_callback(int key, int action) { if(action == GLFW_PRESS) - last_k = key; + add_event(0, key); if(action == GLFW_PRESS) input_count[input_current^1][key].presses++; @@ -72,7 +109,7 @@ static void key_callback(int key, int action) static void mousebutton_callback(int button, int action) { if(action == GLFW_PRESS) - last_k = KEY_MOUSE_FIRST+button; + add_event(0, KEY_MOUSE_FIRST+button); if(action == GLFW_PRESS) input_count[input_current^1][KEY_MOUSE_FIRST+button].presses++; @@ -99,7 +136,7 @@ static void mousewheel_callback(int pos) input_count[input_current^1][KEY_MOUSE_WHEEL_UP].releases++; } - last_k = KEY_MOUSE_WHEEL_UP; + add_event(0, KEY_MOUSE_WHEEL_UP); } else if(pos < 0) { @@ -109,7 +146,7 @@ static void mousewheel_callback(int pos) input_count[input_current^1][KEY_MOUSE_WHEEL_DOWN].releases++; } - last_k = KEY_MOUSE_WHEEL_DOWN; + add_event(0, KEY_MOUSE_WHEEL_DOWN); } glfwSetMouseWheel(0); } @@ -124,22 +161,6 @@ void inp_init() glfwSetMouseWheelCallback(mousewheel_callback); } -char inp_last_char() -{ - return last_c; -} - -int inp_last_key() -{ - return last_k; -} - -void inp_clear() -{ - last_k = 0; - last_c = 0; -} - void inp_mouse_mode_absolute() { glfwEnable(GLFW_MOUSE_CURSOR); @@ -147,8 +168,8 @@ void inp_mouse_mode_absolute() void inp_mouse_mode_relative() { - //if (!config.gfx_debug_resizable) - //glfwDisable(GLFW_MOUSE_CURSOR); + /*if (!config.gfx_debug_resizable)*/ + glfwDisable(GLFW_MOUSE_CURSOR); } int inp_mouse_doubleclick() diff --git a/src/engine/client/ec_snd.c b/src/engine/client/ec_snd.c index 152eac53..49f050c9 100644 --- a/src/engine/client/ec_snd.c +++ b/src/engine/client/ec_snd.c @@ -55,6 +55,7 @@ static int center_x = 0; static int center_y = 0; static int mixing_rate = 48000; +static volatile int sound_volume = 100; void snd_set_channel(int cid, float vol, float pan) { @@ -135,10 +136,13 @@ static void mix(short *final_out, unsigned frames) { int mix_buffer[MAX_FRAMES*2] = {0}; int i, s; + int master_vol; /* aquire lock while we are mixing */ lock_wait(sound_lock); + master_vol = sound_volume; + for(i = 0; i < NUM_VOICES; i++) { if(voices[i].snd) @@ -208,12 +212,12 @@ static void mix(short *final_out, unsigned frames) } } + + /* release the lock */ lock_release(sound_lock); { - int master_vol = config.snd_volume; - /* clamp accumulated values */ /* TODO: this seams slow */ for(i = 0; i < frames; i++) @@ -283,6 +287,25 @@ int snd_init() err = Pa_StartStream(stream); sound_enabled = 1; + snd_update(); /* update the volume */ + return 0; +} + +int snd_update() +{ + /* update volume */ + int wanted_volume = config.snd_volume; + + if(!gfx_window_active() && config.snd_nonactive_mute) + wanted_volume = 0; + + if(wanted_volume != sound_volume) + { + lock_wait(sound_lock); + sound_volume = wanted_volume; + lock_release(sound_lock); + } + return 0; } diff --git a/src/engine/client/ec_srvbrowse.c b/src/engine/client/ec_srvbrowse.c index d9b3f4ff..3a07d86a 100644 --- a/src/engine/client/ec_srvbrowse.c +++ b/src/engine/client/ec_srvbrowse.c @@ -149,6 +149,10 @@ static void client_serverbrowse_filter() filtered = 1; else if(config.b_filter_pw && serverlist[i]->info.flags&1) filtered = 1; + else if(config.b_filter_ping < serverlist[i]->info.latency) + filtered = 1; + else if(!(config.b_filter_gametype&(1<info.game_type))) + filtered = 1; else if(config.b_filter_string[0] != 0) { if(strstr(serverlist[i]->info.name, config.b_filter_string) == 0) @@ -167,6 +171,8 @@ static int client_serverbrowse_sorthash() i |= config.b_filter_full<<5; i |= config.b_filter_pw<<6; i |= config.b_sort_order<<7; + i |= config.b_filter_gametype<<8; + i |= config.b_filter_ping<<16; return i; } -- cgit 1.4.1