Skip to content

Commit

Permalink
redone the input system so you can know do keybindings with say etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Auvinen committed Mar 1, 2008
1 parent 0747c2d commit 08c4c8e
Show file tree
Hide file tree
Showing 14 changed files with 534 additions and 267 deletions.
Binary file modified data/console_bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 12 additions & 20 deletions src/engine/client/ec_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,26 +1306,6 @@ static void client_run()
}
}

/* screenshot button */
if(inp_key_down(config.key_screenshot))
gfx_screenshot();

/* some debug keys */
/*
if(config.debug)
{
if(inp_key_pressed(KEY_F1))
inp_mouse_mode_absolute();
if(inp_key_pressed(KEY_F2))
inp_mouse_mode_relative();
if(inp_key_pressed(KEY_F5))
{
ack_game_tick = -1;
client_send_input();
}
}*/

/* panic quit button */
if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed(KEY_LSHIFT) && inp_key_pressed('Q'))
break;
Expand Down Expand Up @@ -1455,12 +1435,23 @@ static void con_ping(void *result, void *user_data)
ping_start_time = time_get();
}

static void con_screenshot(void *result, void *user_data)
{
gfx_screenshot();
}

static void client_register_commands()
{
MACRO_REGISTER_COMMAND("quit", "", con_quit, 0x0);
MACRO_REGISTER_COMMAND("connect", "s", con_connect, 0x0);
MACRO_REGISTER_COMMAND("disconnect", "", con_disconnect, 0x0);
MACRO_REGISTER_COMMAND("ping", "", con_ping, 0x0);
MACRO_REGISTER_COMMAND("screenshot", "", con_screenshot, 0x0);
}

void client_save_line(const char *line)
{
engine_config_write_line(line);
}

int editor_main(int argc, char **argv);
Expand All @@ -1485,6 +1476,7 @@ int main(int argc, char **argv)
if(engine_config_write_start() == 0)
{
config_save();
modc_save_config();
engine_config_write_stop();
}

Expand Down
20 changes: 13 additions & 7 deletions src/engine/client/ec_inp.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ enum
static INPUT_EVENT input_events[INPUT_BUFFER_SIZE];
static int num_events = 0;

static void add_event(char c, int key)
static void add_event(char c, int key, int flags)
{
if(num_events != INPUT_BUFFER_SIZE)
{
input_events[num_events].ch = c;
input_events[num_events].key = key;
input_events[num_events].flags = flags;
num_events++;
}
}
Expand All @@ -87,17 +88,18 @@ INPUT_EVENT inp_get_event(int index)
return input_events[index];
}


static void char_callback(int character, int action)
{
if(action == GLFW_PRESS && character < 256)
add_event((char)character, 0);
add_event((char)character, 0, 0);
}

static void key_callback(int key, int action)
{
if(action == GLFW_PRESS)
add_event(0, key);
add_event(0, key, INPFLAG_PRESS);
else
add_event(0, key, INPFLAG_RELEASE);

if(action == GLFW_PRESS)
input_count[input_current^1][key].presses++;
Expand All @@ -109,7 +111,9 @@ static void key_callback(int key, int action)
static void mousebutton_callback(int button, int action)
{
if(action == GLFW_PRESS)
add_event(0, KEY_MOUSE_FIRST+button);
add_event(0, KEY_MOUSE_FIRST+button, INPFLAG_PRESS);
else
add_event(0, KEY_MOUSE_FIRST+button, INPFLAG_RELEASE);

if(action == GLFW_PRESS)
input_count[input_current^1][KEY_MOUSE_FIRST+button].presses++;
Expand All @@ -136,7 +140,8 @@ static void mousewheel_callback(int pos)
input_count[input_current^1][KEY_MOUSE_WHEEL_UP].releases++;
}

add_event(0, KEY_MOUSE_WHEEL_UP);
add_event(0, KEY_MOUSE_WHEEL_UP, INPFLAG_PRESS);
add_event(0, KEY_MOUSE_WHEEL_UP, INPFLAG_RELEASE);
}
else if(pos < 0)
{
Expand All @@ -146,7 +151,8 @@ static void mousewheel_callback(int pos)
input_count[input_current^1][KEY_MOUSE_WHEEL_DOWN].releases++;
}

add_event(0, KEY_MOUSE_WHEEL_DOWN);
add_event(0, KEY_MOUSE_WHEEL_DOWN, INPFLAG_PRESS);
add_event(0, KEY_MOUSE_WHEEL_DOWN, INPFLAG_RELEASE);
}
glfwSetMouseWheel(0);
}
Expand Down
3 changes: 0 additions & 3 deletions src/engine/e_config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ MACRO_CONFIG_INT(gfx_fsaa_samples, 0, 0, 16)
MACRO_CONFIG_INT(gfx_refresh_rate, 0, 0, 0)
MACRO_CONFIG_INT(gfx_debug_resizable, 0, 0, 0)

MACRO_CONFIG_INT(key_screenshot, 267, 32, 512)
MACRO_CONFIG_INT(inp_mousesens, 100, 5, 100000)

/*MACRO_CONFIG_STR(masterserver, 128, "master.teewars.com")*/

MACRO_CONFIG_STR(sv_name, 128, "unnamed server")
MACRO_CONFIG_STR(sv_bindaddr, 128, "")
MACRO_CONFIG_INT(sv_port, 8303, 0, 0)
Expand Down
46 changes: 38 additions & 8 deletions src/engine/e_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,14 @@ void console_print(const char *str)
print_callback(str);
}

void console_execute_line(const char *str)

void console_execute_line_stroked(int stroke, const char *str)
{
LEXER_RESULT result;
int error;
char strokestr[8] = {'0', 0};
if(stroke)
strokestr[0] = '1';

if ((error = lex(str, &result)))
printf("ERROR: %d\n", error);
Expand All @@ -355,16 +359,36 @@ void console_execute_line(const char *str)

command = console_find_command(name);

if (command)
if(command)
{
if (console_validate(command, &result))
int is_stroke_command = 0;
if(name[0] == '+')
{
char buf[256];
str_format(buf, sizeof(buf), "Invalid arguments... Usage: %s %s", command->name, command->params);
console_print(buf);
/* insert the stroke direction token */
int i;
for(i = result.num_tokens-2; i > 1; i--)
{
result.tokens[i+1] = result.tokens[i];
}

result.tokens[1].type = TOKEN_INT;
result.tokens[1].stored_string = strokestr;
result.num_tokens++;

is_stroke_command = 1;
}

if(stroke || is_stroke_command)
{
if (console_validate(command, &result))
{
char buf[256];
str_format(buf, sizeof(buf), "Invalid arguments... Usage: %s %s", command->name, command->params);
console_print(buf);
}
else
command->callback(&result, command->user_data);
}
else
command->callback(&result, command->user_data);
}
else
{
Expand All @@ -375,6 +399,12 @@ void console_execute_line(const char *str)
}
}

void console_execute_line(const char *str)
{
console_execute_line_stroked(1, str);
}


void console_execute_file(const char *filename)
{
IOHANDLE file;
Expand Down
1 change: 1 addition & 0 deletions src/engine/e_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef struct COMMAND_t
void console_init();
void console_register(COMMAND *cmd);
void console_execute_line(const char *str);
void console_execute_line_stroked(int stroke, const char *str);
void console_execute_file(const char *filename);
void console_print(const char *str);
void console_register_print_callback(void (*callback)(const char *));
Expand Down
8 changes: 8 additions & 0 deletions src/engine/e_if_inp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
/*
Structure: INPUT_EVENT
*/
enum
{
INPFLAG_PRESS=1,
INPFLAG_RELEASE=2,
INPFLAG_REPEAT=4
};

typedef struct
{
int flags;
char ch;
int key;
} INPUT_EVENT;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/server/es_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ static void server_process_client_packet(NETPACKET *packet)
server_send_msg(cid);

clients[cid].authed = 1;
dbg_msg("server", "cid=%d authed", cid);
server_send_rcon_line(cid, "Authentication successful. Remote console access granted.");
dbg_msg("server", "cid=%d authed", cid);
}
else
{
Expand Down
Loading

0 comments on commit 08c4c8e

Please sign in to comment.