diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-08-29 05:34:18 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-08-29 05:34:18 +0000 |
| commit | 0511e1152a13ad99b51a819a75ef457404e86d4c (patch) | |
| tree | d8e31b98f18f7e027ee72a9792248072d93e5852 /src/game/client/components | |
| parent | b22dd1488cdae53d27215fda051fea9bfc72ac1d (diff) | |
| download | zcatch-0511e1152a13ad99b51a819a75ef457404e86d4c.tar.gz zcatch-0511e1152a13ad99b51a819a75ef457404e86d4c.zip | |
added sound component
Diffstat (limited to 'src/game/client/components')
| -rw-r--r-- | src/game/client/components/camera.cpp | 3 | ||||
| -rw-r--r-- | src/game/client/components/chat.cpp | 8 | ||||
| -rw-r--r-- | src/game/client/components/console.cpp | 85 | ||||
| -rw-r--r-- | src/game/client/components/debughud.cpp | 6 | ||||
| -rw-r--r-- | src/game/client/components/hud.cpp | 2 | ||||
| -rw-r--r-- | src/game/client/components/items.cpp | 14 | ||||
| -rw-r--r-- | src/game/client/components/menus.cpp | 4 | ||||
| -rw-r--r-- | src/game/client/components/menus_browser.cpp | 4 | ||||
| -rw-r--r-- | src/game/client/components/players.cpp | 8 | ||||
| -rw-r--r-- | src/game/client/components/sounds.cpp | 42 | ||||
| -rw-r--r-- | src/game/client/components/sounds.hpp | 21 |
11 files changed, 84 insertions, 113 deletions
diff --git a/src/game/client/components/camera.cpp b/src/game/client/components/camera.cpp index 32442031..a9727ccf 100644 --- a/src/game/client/components/camera.cpp +++ b/src/game/client/components/camera.cpp @@ -38,8 +38,5 @@ void CAMERA::on_render() center = gameclient.local_character_pos + camera_offset; } - - // set listner pos - snd_set_listener_pos(center.x, center.y); } diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 1bdc7e85..9f48b292 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -7,6 +7,8 @@ #include <game/client/gameclient.hpp> #include <game/client/gc_client.hpp> +#include <game/client/components/sounds.hpp> + #include "chat.hpp" void CHAT::on_reset() @@ -17,8 +19,6 @@ void CHAT::on_reset() current_line = 0; } - - void CHAT::con_say(void *result, void *user_data) { ((CHAT*)user_data)->say(0, console_arg_string(result, 0)); @@ -87,9 +87,9 @@ void CHAT::on_message(int msgtype, void *rawmsg) add_line(msg->cid, msg->team, msg->message); if(msg->cid >= 0) // TODO: repair me - snd_play(CHN_GUI, data->sounds[SOUND_CHAT_CLIENT].sounds[0].id, 0); + gameclient.sounds->play(SOUNDS::CHN_GUI, SOUND_CHAT_CLIENT, 0, vec2(0,0)); else - snd_play(CHN_GUI, data->sounds[SOUND_CHAT_SERVER].sounds[0].id, 0); + gameclient.sounds->play(SOUNDS::CHN_GUI, SOUND_CHAT_SERVER, 0, vec2(0,0)); } } diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 8b1abfaa..f9ec4ae3 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -360,12 +360,6 @@ void CONSOLE::on_init() /* -static void client_console_print(const char *str) -{ - // TODO: repair me - //local_console.print_line(str); -} - void console_rcon_print(const char *line) { // TODO: repair me @@ -378,16 +372,6 @@ static void con_team(void *result, void *user_data) send_switch_team(console_arg_int(result, 0)); } -static void con_say(void *result, void *user_data) -{ - chat_say(0, console_arg_string(result, 0)); -} - -static void con_sayteam(void *result, void *user_data) -{ - chat_say(1, console_arg_string(result, 0)); -} - void send_kill(int client_id); static void con_kill(void *result, void *user_data) @@ -421,16 +405,6 @@ static void con_key_input_nextprev_weapon(void *result, void *user_data) input_data.wanted_weapon = 0; } -static void con_toggle_local_console(void *result, void *user_data) -{ - console_toggle(0); -} - -static void con_toggle_remote_console(void *result, void *user_data) -{ - console_toggle(1); -} - static void con_emote(void *result, void *user_data) { send_emoticon(console_arg_int(result, 0)); @@ -458,30 +432,8 @@ void client_console_init() MACRO_REGISTER_COMMAND("dump_binds", "", con_dump_binds, 0x0); // chatting - MACRO_REGISTER_COMMAND("say", "r", con_say, 0x0); - MACRO_REGISTER_COMMAND("say_team", "r", con_sayteam, 0x0); - MACRO_REGISTER_COMMAND("chat", "s", con_chat, 0x0); MACRO_REGISTER_COMMAND("emote", "i", con_emote, 0); - - // game commands - MACRO_REGISTER_COMMAND("+left", "", con_key_input_state, &input_direction_left); - MACRO_REGISTER_COMMAND("+right", "", con_key_input_state, &input_direction_right); - MACRO_REGISTER_COMMAND("+jump", "", con_key_input_state, &input_data.jump); - MACRO_REGISTER_COMMAND("+hook", "", con_key_input_state, &input_data.hook); - MACRO_REGISTER_COMMAND("+fire", "", con_key_input_counter, &input_data.fire); - MACRO_REGISTER_COMMAND("+weapon1", "", con_key_input_weapon, (void *)1); - MACRO_REGISTER_COMMAND("+weapon2", "", con_key_input_weapon, (void *)2); - MACRO_REGISTER_COMMAND("+weapon3", "", con_key_input_weapon, (void *)3); - MACRO_REGISTER_COMMAND("+weapon4", "", con_key_input_weapon, (void *)4); - MACRO_REGISTER_COMMAND("+weapon5", "", con_key_input_weapon, (void *)5); - - MACRO_REGISTER_COMMAND("+nextweapon", "", con_key_input_nextprev_weapon, &input_data.next_weapon); - MACRO_REGISTER_COMMAND("+prevweapon", "", con_key_input_nextprev_weapon, &input_data.prev_weapon); - MACRO_REGISTER_COMMAND("+emote", "", con_key_input_state, &emoticon_selector_active); - MACRO_REGISTER_COMMAND("+scoreboard", "", con_key_input_state, &scoreboard_active); - - binds_default(); } bool console_input_cli(INPUT_EVENT e, void *user_data) @@ -524,41 +476,4 @@ bool console_input_normal_binds(INPUT_EVENT e, void *user_data) return false; return console_execute_event(e); } - -void console_toggle(int type) -{ - if(console_type != type && (console_state == CONSOLE_OPEN || console_state == CONSOLE_OPENING)) - { - // don't toggle console, just switch what console to use - } - else - { - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_OPEN) - { - state_change_end = time_now()+state_change_duration; - } - else - { - float progress = state_change_end-time_now(); - float reversed_progress = state_change_duration-progress; - - state_change_end = time_now()+reversed_progress; - } - - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING) - console_state = CONSOLE_OPENING; - else - console_state = CONSOLE_CLOSING; - } - - console_type = type; -} - - - -int console_active() -{ - return console_state != CONSOLE_CLOSED; -} - */ diff --git a/src/game/client/components/debughud.cpp b/src/game/client/components/debughud.cpp index 7ec7b88f..0c8b0b91 100644 --- a/src/game/client/components/debughud.cpp +++ b/src/game/client/components/debughud.cpp @@ -31,7 +31,7 @@ void DEBUGHUD::render_netcorrections() float velspeed = length(vec2(gameclient.snap.local_character->vx/256.0f, gameclient.snap.local_character->vy/256.0f))*50; - float ramp = velocity_ramp(velspeed, tuning.velramp_start, tuning.velramp_range, tuning.velramp_curvature); + float ramp = velocity_ramp(velspeed, gameclient.tuning.velramp_start, gameclient.tuning.velramp_range, gameclient.tuning.velramp_curvature); char buf[512]; str_format(buf, sizeof(buf), "%.0f\n%.0f\n%.2f\n%d %s\n%d %d", @@ -59,7 +59,7 @@ void DEBUGHUD::render_tuning() { char buf[128]; float current, standard; - tuning.get(i, ¤t); + gameclient.tuning.get(i, ¤t); standard_tuning.get(i, &standard); if(standard == current) @@ -96,7 +96,7 @@ void DEBUGHUD::render_tuning() for(int i = 0; i < 100; i++) { float speed = i/100.0f * 3000; - float ramp = velocity_ramp(speed, tuning.velramp_start, tuning.velramp_range, tuning.velramp_curvature); + float ramp = velocity_ramp(speed, gameclient.tuning.velramp_start, gameclient.tuning.velramp_range, gameclient.tuning.velramp_curvature); float rampedspeed = (speed * ramp)/1000.0f; gfx_lines_draw((i-1)*2, y+height-pv*height, i*2, y+height-rampedspeed*height); //gfx_lines_draw((i-1)*2, 200, i*2, 200); diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 05df0702..cee7a8bb 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -173,7 +173,7 @@ void HUD::render_tunewarning() // render warning about non standard tuning bool flash = time_get()/(time_freq()/2)%2 == 0; - if(config.cl_warning_tuning && memcmp(&standard_tuning, &tuning, sizeof(TUNING_PARAMS)) != 0) + if(config.cl_warning_tuning && memcmp(&standard_tuning, &gameclient.tuning, sizeof(TUNING_PARAMS)) != 0) { const char *text = "Warning! Server is running non-standard tuning."; if(flash) diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 15cc7524..43a3224a 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -23,18 +23,18 @@ void ITEMS::render_projectile(const NETOBJ_PROJECTILE *current, int itemid) float speed = 0; if(current->type == WEAPON_GRENADE) { - curvature = tuning.grenade_curvature; - speed = tuning.grenade_speed; + curvature = gameclient.tuning.grenade_curvature; + speed = gameclient.tuning.grenade_speed; } else if(current->type == WEAPON_SHOTGUN) { - curvature = tuning.shotgun_curvature; - speed = tuning.shotgun_speed; + curvature = gameclient.tuning.shotgun_curvature; + speed = gameclient.tuning.shotgun_speed; } else if(current->type == WEAPON_GUN) { - curvature = tuning.gun_curvature; - speed = tuning.gun_speed; + curvature = gameclient.tuning.gun_curvature; + speed = gameclient.tuning.gun_speed; } float ct = (client_tick()-current->start_tick)/(float)SERVER_TICK_SPEED + client_ticktime()*1/(float)SERVER_TICK_SPEED; @@ -151,7 +151,7 @@ void ITEMS::render_laser(const struct NETOBJ_LASER *current) float ticks = client_tick() + client_intratick() - current->start_tick; float ms = (ticks/50.0f) * 1000.0f; - float a = ms / tuning.laser_bounce_delay; + float a = ms / gameclient.tuning.laser_bounce_delay; a = clamp(a, 0.0f, 1.0f); float ia = 1-a; diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index e3212ceb..05af1c7b 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -11,9 +11,9 @@ #include "menus.hpp" #include "skins.hpp" +#include <engine/e_client_interface.h> + extern "C" { - #include <engine/e_client_interface.h> - #include <engine/e_config.h> #include <engine/client/ec_font.h> } diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 05ca620b..fae6df5b 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -2,9 +2,9 @@ #include <string.h> // strcmp, strlen, strncpy #include <stdlib.h> // atoi +#include <engine/e_client_interface.h> + extern "C" { - #include <engine/e_client_interface.h> - #include <engine/e_config.h> #include <engine/client/ec_font.h> } diff --git a/src/game/client/components/players.cpp b/src/game/client/components/players.cpp index 3178b82f..ed8d0c17 100644 --- a/src/game/client/components/players.cpp +++ b/src/game/client/components/players.cpp @@ -1,8 +1,3 @@ - -extern "C" { - #include <engine/e_config.h> -} - #include <engine/e_client_interface.h> #include <game/generated/g_protocol.hpp> #include <game/generated/gc_data.hpp> @@ -17,6 +12,7 @@ extern "C" { #include <game/client/components/flow.hpp> #include <game/client/components/skins.hpp> #include <game/client/components/effects.hpp> +#include <game/client/components/sounds.hpp> #include "players.hpp" @@ -178,7 +174,7 @@ void PLAYERS::render_player( static int64 skid_sound_time = 0; if(time_get()-skid_sound_time > time_freq()/10) { - snd_play_random(CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, position); + gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, position); skid_sound_time = time_get(); } diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp new file mode 100644 index 00000000..569bbf01 --- /dev/null +++ b/src/game/client/components/sounds.cpp @@ -0,0 +1,42 @@ +#include <engine/e_client_interface.h> +#include <game/generated/gc_data.hpp> +#include <game/client/gameclient.hpp> +#include <game/client/components/camera.hpp> +#include "sounds.hpp" + +void SOUNDS::on_init() +{ + // setup sound channels + snd_set_channel(SOUNDS::CHN_GUI, 1.0f, 0.0f); + snd_set_channel(SOUNDS::CHN_MUSIC, 1.0f, 0.0f); + snd_set_channel(SOUNDS::CHN_WORLD, 0.9f, 1.0f); + snd_set_channel(SOUNDS::CHN_GLOBAL, 1.0f, 0.0f); +} + +void SOUNDS::on_render() +{ + // set listner pos + snd_set_listener_pos(gameclient.camera->center.x, gameclient.camera->center.y); +} + +void SOUNDS::play(int chn, int setid, float vol, vec2 pos) +{ + SOUNDSET *set = &data->sounds[setid]; + + if(!set->num_sounds) + return; + + if(set->num_sounds == 1) + { + snd_play_at(chn, set->sounds[0].id, 0, pos.x, pos.y); + return; + } + + // play a random one + int id; + do { + id = rand() % set->num_sounds; + } while(id == set->last); + snd_play_at(chn, set->sounds[id].id, 0, pos.x, pos.y); + set->last = id; +} diff --git a/src/game/client/components/sounds.hpp b/src/game/client/components/sounds.hpp new file mode 100644 index 00000000..5e3dfd6e --- /dev/null +++ b/src/game/client/components/sounds.hpp @@ -0,0 +1,21 @@ +#include <game/client/component.hpp> + +class SOUNDS : public COMPONENT +{ +public: + // sound channels + enum + { + CHN_GUI=0, + CHN_MUSIC, + CHN_WORLD, + CHN_GLOBAL, + }; + + virtual void on_init(); + virtual void on_render(); + + void play(int chn, int setid, float vol, vec2 pos); +}; + + |