From 7b73f1505212f7235db0987fb4e52549fdd73fb5 Mon Sep 17 00:00:00 2001 From: Jakob Fries Date: Fri, 18 Jan 2008 15:55:03 +0000 Subject: Console is now accessable in-game and has more commands: connect, disconnect, quit. --- src/engine/client/ec_client.c | 3 +++ src/engine/client/ec_inp.c | 6 +++++ src/engine/e_interface.h | 22 +++++++++++++++++ src/game/client/gc_client.cpp | 2 +- src/game/client/gc_console.cpp | 54 ++++++++++++++++++++++++++++++++---------- src/game/client/gc_hooks.cpp | 32 ++++++++++++++++++------- 6 files changed, 97 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index 6a3b4220..5957312a 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -1193,6 +1193,9 @@ int editor_main(int argc, char **argv); int main(int argc, char **argv) { + /* preinit the mod */ + modc_preinit(); + /* init the engine */ dbg_msg("client", "starting..."); engine_init("Teewars", argc, argv); diff --git a/src/engine/client/ec_inp.c b/src/engine/client/ec_inp.c index cac69669..57216ac4 100644 --- a/src/engine/client/ec_inp.c +++ b/src/engine/client/ec_inp.c @@ -177,6 +177,12 @@ int inp_mouse_doubleclick() return release_delta < (time_freq() >> 2); } +void inp_clear_key_states() +{ + mem_zero(keyboard_state, sizeof(keyboard_state)); + mem_zero(input_count, sizeof(input_count)); +} + int inp_key_presses(int key) { return input_count[input_current][key].presses; diff --git a/src/engine/e_interface.h b/src/engine/e_interface.h index 534c29e1..73d2e01e 100644 --- a/src/engine/e_interface.h +++ b/src/engine/e_interface.h @@ -845,6 +845,15 @@ void mods_postsnap(); /* Group: Client Callbacks */ + +/* + Function: modc_preinit + Called when the client starts, but before the engine is initialized. + + Remarks: +*/ +void modc_preinit(); + /* Function: modc_init Called when the client starts. @@ -1222,6 +1231,19 @@ void inp_mouse_mode_relative(); */ int inp_mouse_doubleclick(); +/* + Function: TODO + + Arguments: + arg1 - desc + + Returns: + + See Also: + +*/ +void inp_clear_key_states(); + /* Function: TODO diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp index d72efe8e..bbb00c27 100644 --- a/src/game/client/gc_client.cpp +++ b/src/game/client/gc_client.cpp @@ -1183,7 +1183,7 @@ void render_game() { if(chat_mode != CHATMODE_NONE) { - if(inp_key_down(KEY_ENTER)) + if(inp_key_down(KEY_ENTER) || inp_key_down(KEY_KP_ENTER)) { // send message if(chat_input_len) diff --git a/src/game/client/gc_console.cpp b/src/game/client/gc_console.cpp index 595560b6..ddfb4b48 100644 --- a/src/game/client/gc_console.cpp +++ b/src/game/client/gc_console.cpp @@ -40,13 +40,35 @@ static void client_console_print(const char *str) //dbg_msg("console", "FROM CLIENT!! %s", str); } +static void connect_command(struct lexer_result *result, void *user_data) +{ + const char *address; + extract_result_string(result, 1, &address); + client_connect(address); +} + +static void disconnect_command(struct lexer_result *result, void *user_data) +{ + client_disconnect(); +} + +static void quit_command(struct lexer_result *result, void *user_data) +{ + client_quit(); +} + void client_console_init() { console_register_print_callback(client_console_print); + MACRO_REGISTER_COMMAND("quit", "", quit_command, 0x0); + MACRO_REGISTER_COMMAND("connect", "s", connect_command, 0x0); + MACRO_REGISTER_COMMAND("disconnect", "", disconnect_command, 0x0); } void console_handle_input() { + int was_active = active; + for(int i = 0; i < inp_num_events(); i++) { INPUTEVENT e = inp_get_event(i); @@ -76,17 +98,23 @@ void console_handle_input() console_input_len--; } } - else if(e.key == KEY_ENTER) + else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER) { - console_execute(console_input); - console_input[0] = 0; - console_input_len = 0; + if (console_input_len) + { + console_execute(console_input); + console_input[0] = 0; + console_input_len = 0; + } } } } - if (active) + if (was_active || active) + { inp_clear_events(); + inp_clear_key_states(); + } } void console_toggle() @@ -108,15 +136,17 @@ void console_render() { float font_size = 12.0f; - float row_spacing = font_size*1.4f; - float width = gfx_text_width(0, 12, console_input, -1); - float x = 3, y = console_height - row_spacing - 2; + float row_height = font_size*1.4f; + float width = gfx_text_width(0, font_size, console_input, -1); + float x = 3, y = console_height - row_height - 2; int backlog_index = backlog_len-1; + float prompt_width = gfx_text_width(0, font_size, ">", -1)+2; - gfx_text(0, x, y, font_size, console_input, -1); - gfx_text(0, x+width+1, y, font_size, "_", -1); + gfx_text(0, x, y, font_size, ">", -1); + gfx_text(0, x+prompt_width, y, font_size, console_input, -1); + gfx_text(0, x+prompt_width+width+1, y, font_size, "_", -1); - y -= row_spacing; + y -= row_height; while (y > 0.0f && backlog_index >= 0) { @@ -124,7 +154,7 @@ void console_render() gfx_text(0, x, y, font_size, line, -1); backlog_index--; - y -= row_spacing; + y -= row_height; } } } diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp index d70e84a5..34196eaa 100644 --- a/src/game/client/gc_hooks.cpp +++ b/src/game/client/gc_hooks.cpp @@ -25,6 +25,10 @@ extern void menu_init(); extern bool menu_active; extern bool menu_game_active; +extern "C" void modc_preinit() +{ + client_console_init(); +} extern "C" void modc_init() { @@ -37,8 +41,6 @@ extern "C" void modc_init() gfx_text_set_default_font(&default_font); menu_init(); - - client_console_init(); // setup sound channels snd_set_channel(CHN_GUI, 1.0f, 0.0f); @@ -299,6 +301,8 @@ extern "C" void modc_render() if(client_state() == CLIENTSTATE_ONLINE) { render_game(); + if (console_active()) + console_render(); // handle team switching // TODO: FUGLY!!! @@ -314,10 +318,8 @@ extern "C" void modc_render() { menu_render(); if (console_active()) - { console_render(); - return; - } + return; } // @@ -346,10 +348,22 @@ extern "C" int modc_snap_input(int *data) else { input_data.state = STATE_PLAYING; - input_data.left = inp_key_state(config.key_move_left); - input_data.right = inp_key_state(config.key_move_right); - input_data.hook = inp_key_state(config.key_hook); - input_data.jump = inp_key_state(config.key_jump); + + // TODO: this doesn't feel too pretty... look into it? + if (console_active()) + { + input_data.left = 0; + input_data.right = 0; + input_data.hook = 0; + input_data.jump = 0; + } + else + { + input_data.left = inp_key_state(config.key_move_left); + input_data.right = inp_key_state(config.key_move_right); + input_data.hook = inp_key_state(config.key_hook); + input_data.jump = inp_key_state(config.key_jump); + } } // stress testing -- cgit 1.4.1