Skip to content

Commit

Permalink
Console is now accessable in-game and has more commands: connect, dis…
Browse files Browse the repository at this point in the history
…connect, quit.
  • Loading branch information
serpis committed Jan 18, 2008
1 parent 57c4765 commit 7b73f15
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 22 deletions.
3 changes: 3 additions & 0 deletions src/engine/client/ec_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/engine/client/ec_inp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions src/engine/e_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1222,6 +1231,19 @@ void inp_mouse_mode_relative();
*/
int inp_mouse_doubleclick();

/*
Function: TODO
Arguments:
arg1 - desc
Returns:
See Also:
<other_func>
*/
void inp_clear_key_states();

/*
Function: TODO
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/gc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 42 additions & 12 deletions src/game/client/gc_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand All @@ -108,23 +136,25 @@ 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)
{
const char *line = backlog[backlog_index];
gfx_text(0, x, y, font_size, line, -1);

backlog_index--;
y -= row_spacing;
y -= row_height;
}
}
}
Expand Down
32 changes: 23 additions & 9 deletions src/game/client/gc_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
Expand Down Expand Up @@ -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!!!
Expand All @@ -314,10 +318,8 @@ extern "C" void modc_render()
{
menu_render();
if (console_active())
{
console_render();
return;
}
return;
}

//
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b73f15

Please sign in to comment.