console now has proper backlog and command history. kill command added. predicted hooks no longer make a sound when hitting a player.

This commit is contained in:
Jakob Fries 2008-02-04 00:13:34 +00:00
parent be33e56abc
commit d76661b3be
7 changed files with 125 additions and 36 deletions

View file

@ -208,7 +208,9 @@ void *ringbuf_item_ptr(void *p)
void *ringbuf_first(RINGBUFFER *rb) void *ringbuf_first(RINGBUFFER *rb)
{ {
return ringbuf_next(rb, rb->last_alloc+1); if(rb->last_alloc && rb->last_alloc->next)
return ringbuf_next(rb, rb->last_alloc->next+1);
return 0x0;
} }
void *ringbuf_last(RINGBUFFER *rb) void *ringbuf_last(RINGBUFFER *rb)

View file

@ -1,3 +1,5 @@
#ifndef _RINGBUFFER_H
#define _RINGBUFFER_H
typedef struct typedef struct
{ {
@ -20,3 +22,5 @@ void *ringbuf_prev(RINGBUFFER *rb, void *current);
void *ringbuf_next(RINGBUFFER *rb, void *current); void *ringbuf_next(RINGBUFFER *rb, void *current);
void *ringbuf_first(RINGBUFFER *rb); void *ringbuf_first(RINGBUFFER *rb);
void *ringbuf_last(RINGBUFFER *rb); void *ringbuf_last(RINGBUFFER *rb);
#endif

View file

@ -334,6 +334,14 @@ void send_emoticon(int emoticon)
client_send_msg(); client_send_msg();
} }
void send_kill(int client_id)
{
msg_pack_start(MSG_KILL, MSGFLAG_VITAL);
msg_pack_int(client_id);
msg_pack_end();
client_send_msg();
}
void anim_seq_eval(sequence *seq, float time, keyframe *frame) void anim_seq_eval(sequence *seq, float time, keyframe *frame)
{ {
if(seq->num_frames == 0) if(seq->num_frames == 0)

View file

@ -5,6 +5,7 @@ extern "C" {
#include <engine/e_client_interface.h> #include <engine/e_client_interface.h>
#include <engine/e_config.h> #include <engine/e_config.h>
#include <engine/e_console.h> #include <engine/e_console.h>
#include <engine/e_ringbuffer.h>
#include <engine/client/ec_font.h> #include <engine/client/ec_font.h>
} }
@ -24,23 +25,24 @@ enum
CONSOLE_CLOSING, CONSOLE_CLOSING,
}; };
static char console_history_data[65536];
static RINGBUFFER *console_history;
static char console_backlog_data[65536];
static RINGBUFFER *console_backlog;
static unsigned int console_input_len = 0; static unsigned int console_input_len = 0;
static char console_input[256] = {0}; static char console_input[256] = {0};
static int console_state = CONSOLE_CLOSED; static int console_state = CONSOLE_CLOSED;
static float state_change_end = 0.0f; static float state_change_end = 0.0f;
static const float state_change_duration = 0.1f; static const float state_change_duration = 0.1f;
static char backlog[256][256] = {{0}};
static int backlog_len;
static float time_now() static float time_now()
{ {
static long long time_start = time_get(); static long long time_start = time_get();
return float(time_get()-time_start)/float(time_freq()); return float(time_get()-time_start)/float(time_freq());
} }
static void client_console_print(const char *str) static void client_console_print(const char *str)
{ {
int len = strlen(str); int len = strlen(str);
@ -48,24 +50,8 @@ static void client_console_print(const char *str)
if (len > 255) if (len > 255)
len = 255; len = 255;
if (backlog_len >= 256) char *entry = (char *)ringbuf_allocate(console_backlog, len+1);
{ memcpy(entry, str, len+1);
static int warning = 0;
if (!warning)
{
puts("console backlog full");
warning = 1;
}
return;
}
memcpy(backlog[backlog_len], str, len);
backlog[backlog_len][len] = 0;
backlog_len++;
//dbg_msg("console", "FROM CLIENT!! %s", str);
} }
@ -76,12 +62,37 @@ static void con_team(void *result, void *user_data)
send_switch_team(new_team); send_switch_team(new_team);
} }
void client_console_init() static void command_history(void *result, void *user_data)
{ {
console_register_print_callback(client_console_print); char *entry = (char *)ringbuf_first(console_history);
MACRO_REGISTER_COMMAND("team", "i", con_team, 0x0);
while (entry)
{
dbg_msg("console/history", entry);
entry = (char *)ringbuf_next(console_history, entry);
}
} }
void send_kill(int client_id);
static void command_kill(void *result, void *user_data)
{
send_kill(-1);
}
void client_console_init()
{
console_history = ringbuf_init(console_history_data, sizeof(console_history_data));
console_backlog = ringbuf_init(console_backlog_data, sizeof(console_backlog_data));
console_register_print_callback(client_console_print);
MACRO_REGISTER_COMMAND("team", "i", con_team, 0x0);
MACRO_REGISTER_COMMAND("history", "", command_history, 0x0);
MACRO_REGISTER_COMMAND("kill", "", command_kill, 0x0);
}
static char *console_history_entry = 0x0;
void console_handle_input() void console_handle_input()
{ {
@ -105,6 +116,8 @@ void console_handle_input()
console_input[console_input_len] = e.ch; console_input[console_input_len] = e.ch;
console_input[console_input_len+1] = 0; console_input[console_input_len+1] = 0;
console_input_len++; console_input_len++;
console_history_entry = 0x0;
} }
} }
@ -114,15 +127,67 @@ void console_handle_input()
{ {
console_input[console_input_len-1] = 0; console_input[console_input_len-1] = 0;
console_input_len--; console_input_len--;
console_history_entry = 0x0;
} }
} }
else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER) else if(e.key == KEY_ENTER || e.key == KEY_KP_ENTER)
{ {
if (console_input_len) if (console_input_len)
{ {
char *entry = (char *)ringbuf_allocate(console_history, console_input_len+1);
memcpy(entry, console_input, console_input_len+1);
console_execute(console_input); console_execute(console_input);
console_input[0] = 0; console_input[0] = 0;
console_input_len = 0; console_input_len = 0;
console_history_entry = 0x0;
}
}
else if (e.key == KEY_UP)
{
if (console_history_entry)
{
char *test = (char *)ringbuf_prev(console_history, console_history_entry);
if (test)
console_history_entry = test;
}
else
console_history_entry = (char *)ringbuf_last(console_history);
if (console_history_entry)
{
unsigned int len = strlen(console_history_entry);
if (len < sizeof(console_input) - 1)
{
memcpy(console_input, console_history_entry, len+1);
console_input_len = len;
}
}
}
else if (e.key == KEY_DOWN)
{
if (console_history_entry)
console_history_entry = (char *)ringbuf_next(console_history, console_history_entry);
if (console_history_entry)
{
unsigned int len = strlen(console_history_entry);
if (len < sizeof(console_input) - 1)
{
memcpy(console_input, console_history_entry, len+1);
console_input_len = len;
}
}
else
{
console_input[0] = 0;
console_input_len = 0;
} }
} }
} }
@ -208,7 +273,6 @@ void console_render()
float row_height = font_size*1.4f; float row_height = font_size*1.4f;
float width = gfx_text_width(0, font_size, console_input, -1); float width = gfx_text_width(0, font_size, console_input, -1);
float x = 3, y = console_height - row_height - 2; 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; float prompt_width = gfx_text_width(0, font_size, ">", -1)+2;
gfx_text(0, x, y, font_size, ">", -1); gfx_text(0, x, y, font_size, ">", -1);
@ -222,13 +286,13 @@ void console_render()
y -= row_height; y -= row_height;
while (y > 0.0f && backlog_index >= 0) char *entry = (char *)ringbuf_last(console_backlog);
while (y > 0.0f && entry)
{ {
const char *line = backlog[backlog_index]; gfx_text(0, x, y, font_size, entry, -1);
gfx_text(0, x, y, font_size, line, -1);
backlog_index--;
y -= row_height; y -= row_height;
entry = (char *)ringbuf_prev(console_backlog, entry);
} }
} }
} }

View file

@ -186,7 +186,7 @@ extern "C" void modc_predict()
snd_play_random(CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos); snd_play_random(CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos);
} }
//if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); //if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos); //if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos);
if(events&COREEVENT_HOOK_ATTACH_GROUND) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos); if(events&COREEVENT_HOOK_ATTACH_GROUND) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos);
//if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
} }

View file

@ -43,6 +43,7 @@ enum
MSG_WEAPON_PICKUP, MSG_WEAPON_PICKUP,
MSG_SOUND_GLOBAL, MSG_SOUND_GLOBAL,
MSG_TUNE_PARAMS, MSG_TUNE_PARAMS,
MSG_KILL,
}; };
enum enum

View file

@ -1320,6 +1320,9 @@ void player::tick_defered()
void player::die(int killer, int weapon) void player::die(int killer, int weapon)
{ {
if (dead || team == -1)
return;
int mode_special = gameobj->on_player_death(this, get_player(killer), weapon); int mode_special = gameobj->on_player_death(this, get_player(killer), weapon);
dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d", dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d",
@ -2067,6 +2070,13 @@ void mods_message(int msg, int client_id)
int emoteicon = msg_unpack_int(); int emoteicon = msg_unpack_int();
send_emoticon(client_id, emoteicon % 16); send_emoticon(client_id, emoteicon % 16);
} }
else if (msg == MSG_KILL)
{
//int kill_client_id = msg_unpack_int(); // to be used to kill players from rcon? hihi
player *pplayer = get_player(client_id);
pplayer->die(client_id, -1);
}
} }
extern unsigned char internal_data[]; extern unsigned char internal_data[];