Updated stuff

This commit is contained in:
Olle Rosenquist 2007-07-22 11:53:15 +00:00
parent 2165a728c2
commit 26dd1c20ce
8 changed files with 725 additions and 569 deletions

View file

@ -18,9 +18,10 @@
#include <engine/versions.h> #include <engine/versions.h>
#include <engine/config.h> #include <engine/config.h>
#include <engine/network.h> //#include <engine/network.h>
#include <mastersrv/mastersrv.h> #include <mastersrv/mastersrv.h>
#include "client.h"
using namespace baselib; using namespace baselib;
@ -274,20 +275,7 @@ void client_connect(const char *server_address_str)
// --- client --- // --- client ---
// TODO: remove this class // TODO: remove this class
class client void client::send_info()
{
public:
int info_request_begin;
int info_request_end;
int snapshot_part;
int debug_font; // TODO: rfemove this line
// data to hold three snapshots
// previous,
void send_info()
{ {
recived_snapshots = 0; recived_snapshots = 0;
@ -300,14 +288,14 @@ public:
client_send_msg(); client_send_msg();
} }
void send_entergame() void client::send_entergame()
{ {
msg_pack_start_system(NETMSG_ENTERGAME, MSGFLAG_VITAL); msg_pack_start_system(NETMSG_ENTERGAME, MSGFLAG_VITAL);
msg_pack_end(); msg_pack_end();
client_send_msg(); client_send_msg();
} }
void send_error(const char *error) void client::send_error(const char *error)
{ {
/* /*
pack(NETMSG_CLIENT_ERROR, "s", error); pack(NETMSG_CLIENT_ERROR, "s", error);
@ -321,7 +309,7 @@ public:
*/ */
} }
void send_input() void client::send_input()
{ {
msg_pack_start_system(NETMSG_INPUT, 0); msg_pack_start_system(NETMSG_INPUT, 0);
msg_pack_int(input_data_size); msg_pack_int(input_data_size);
@ -331,20 +319,20 @@ public:
client_send_msg(); client_send_msg();
} }
void disconnect() void client::disconnect()
{ {
send_error("disconnected"); send_error("disconnected");
set_state(STATE_OFFLINE); set_state(STATE_OFFLINE);
map_unload(); map_unload();
} }
bool load_data() bool client::load_data()
{ {
debug_font = gfx_load_texture("data/debug_font.png"); debug_font = gfx_load_texture("data/debug_font.png");
return true; return true;
} }
void debug_render() void client::debug_render()
{ {
gfx_blend_normal(); gfx_blend_normal();
gfx_texture_set(debug_font); gfx_texture_set(debug_font);
@ -367,7 +355,7 @@ public:
} }
void render() void client::render()
{ {
gfx_clear(0.0f,0.0f,0.0f); gfx_clear(0.0f,0.0f,0.0f);
@ -420,7 +408,7 @@ public:
} }
} }
void run(const char *direct_connect_server) void client::run(const char *direct_connect_server)
{ {
local_start_time = time_get(); local_start_time = time_get();
snapshot_part = 0; snapshot_part = 0;
@ -515,7 +503,7 @@ public:
break; break;
// be nice // be nice
//thread_sleep(1); thread_sleep(1);
if(reporttime < time_get()) if(reporttime < time_get())
{ {
@ -525,9 +513,9 @@ public:
reporttime += reportinterval; reporttime += reportinterval;
} }
if (input::pressed(input::esc)) /*if (input::pressed(input::esc))
if (get_state() == STATE_CONNECTING || get_state() == STATE_ONLINE) if (get_state() == STATE_CONNECTING || get_state() == STATE_ONLINE)
disconnect(); disconnect();*/
// update frametime // update frametime
frametime = (time_get()-frame_start_time)/(float)time_freq(); frametime = (time_get()-frame_start_time)/(float)time_freq();
@ -542,14 +530,14 @@ public:
snd_shutdown(); snd_shutdown();
} }
void error(const char *msg) void client::error(const char *msg)
{ {
dbg_msg("game", "error: %s", msg); dbg_msg("game", "error: %s", msg);
send_error(msg); send_error(msg);
set_state(STATE_BROKEN); set_state(STATE_BROKEN);
} }
void serverbrowse_request(int id) void client::serverbrowse_request(int id)
{ {
dbg_msg("client", "requesting server info from %d.%d.%d.%d:%d", dbg_msg("client", "requesting server info from %d.%d.%d.%d:%d",
servers.addresses[id].ip[0], servers.addresses[id].ip[1], servers.addresses[id].ip[2], servers.addresses[id].ip[0], servers.addresses[id].ip[1], servers.addresses[id].ip[2],
@ -564,7 +552,7 @@ public:
servers.request_times[id] = time_get(); servers.request_times[id] = time_get();
} }
void serverbrowse_update() void client::serverbrowse_update()
{ {
int64 timeout = time_freq(); int64 timeout = time_freq();
int64 now = time_get(); int64 now = time_get();
@ -587,7 +575,7 @@ public:
} }
} }
void process_packet(NETPACKET *packet) void client::process_packet(NETPACKET *packet)
{ {
if(packet->client_id == -1) if(packet->client_id == -1)
{ {
@ -806,7 +794,7 @@ public:
} }
} }
void pump_network() void client::pump_network()
{ {
net.update(); net.update();
@ -831,10 +819,11 @@ public:
while(net.recv(&packet)) while(net.recv(&packet))
process_packet(&packet); process_packet(&packet);
} }
};
int editor_main(int argc, char **argv); int editor_main(int argc, char **argv);
client main_client;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
dbg_msg("client", "starting..."); dbg_msg("client", "starting...");
@ -880,8 +869,7 @@ int main(int argc, char **argv)
else else
{ {
// start the client // start the client
client c; main_client.run(direct_connect_server);
c.run(direct_connect_server);
} }
return 0; return 0;
} }

View file

@ -0,0 +1,48 @@
#ifndef __CLIENT_H
#define __CLIENT_H
#include <engine/network.h>
// --- client ---
// TODO: remove this class
class client
{
public:
int info_request_begin;
int info_request_end;
int snapshot_part;
int debug_font; // TODO: rfemove this line
// data to hold three snapshots
// previous,
void send_info();
void send_entergame();
void send_error(const char *error);
void send_input();
void disconnect();
bool load_data();
void debug_render();
void render();
void run(const char *direct_connect_server);
void error(const char *msg);
void serverbrowse_request(int id);
void serverbrowse_update();
void process_packet(NETPACKET *packet);
void pump_network();
};
#endif

View file

@ -249,7 +249,7 @@ public:
reporttime += time_freq()*reportinterval; reporttime += time_freq()*reportinterval;
} }
totaltime += time_get()-t; totaltime += time_get()-t;
thread_sleep(1); //thread_sleep(1);
} }
mods_shutdown(); mods_shutdown();

View file

@ -4,11 +4,15 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <engine/config.h> #include <engine/config.h>
#include <engine/client/ui.h>
#include <engine/client/client.h>
#include "../game.h" #include "../game.h"
#include "mapres_image.h" #include "mapres_image.h"
#include "mapres_tilemap.h" #include "mapres_tilemap.h"
#include "data.h" #include "data.h"
#include "menu.h"
extern client main_client;
using namespace baselib; using namespace baselib;
data_container *data = 0x0; data_container *data = 0x0;
@ -17,6 +21,11 @@ int charids[16] = {2,10,0,4,12,6,14,1,9,15,13,11,7,5,8,3};
static int gametype = GAMETYPE_DM; static int gametype = GAMETYPE_DM;
static int skinseed = 0; static int skinseed = 0;
static int menu_team = 0;
static int menu_quit = 0;
static bool chat_active = false;
static bool menu_active = false;
static vec2 mouse_pos; static vec2 mouse_pos;
static vec2 local_player_pos; static vec2 local_player_pos;
@ -25,6 +34,7 @@ static obj_player *local_player;
struct client_data struct client_data
{ {
char name[64]; char name[64];
int team;
} client_datas[MAX_CLIENTS]; } client_datas[MAX_CLIENTS];
inline float frandom() { return rand()/(float)(RAND_MAX); } inline float frandom() { return rand()/(float)(RAND_MAX); }
@ -373,7 +383,6 @@ public:
}; };
static projectile_particles proj_particles; static projectile_particles proj_particles;
static bool chat_active = false;
static char chat_input[512]; static char chat_input[512];
static unsigned chat_input_len; static unsigned chat_input_len;
static const int chat_max_lines = 10; static const int chat_max_lines = 10;
@ -436,7 +445,10 @@ void modc_entergame()
chat_reset(); chat_reset();
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{
client_datas[i].name[0] = 0; client_datas[i].name[0] = 0;
client_datas[i].team = 0;
}
for(int i = 0; i < killmsg_max; i++) for(int i = 0; i < killmsg_max; i++)
killmsgs[i].tick = -100000; killmsgs[i].tick = -100000;
@ -909,7 +921,7 @@ static void render_player(obj_player *prev, obj_player *player)
draw_sprite(p.x, p.y, data->weapons[iw].visual_size); draw_sprite(p.x, p.y, data->weapons[iw].visual_size);
} }
if (player->weapon == WEAPON_TYPE_GUN || player->weapon == WEAPON_TYPE_SHOTGUN) if (player->weapon == WEAPON_GUN || player->weapon == WEAPON_SHOTGUN)
{ {
// check if we're firing stuff // check if we're firing stuff
if (true)///prev->attackticks) if (true)///prev->attackticks)
@ -987,12 +999,73 @@ void render_sun(float x, float y)
gfx_quads_end(); gfx_quads_end();
} }
void ingamemenu_render()
{
if (!local_player)
return;
gfx_mapscreen(0, 0, 800, 600);
// Ingame menu - quit and change team (if tdm)
float mx,my;
int rx, ry;
inp_mouse_relative(&rx, &ry);
mouse_pos.x += rx;
mouse_pos.y += ry;
if(mouse_pos.x < 0) mouse_pos.x = 0;
if(mouse_pos.y < 0) mouse_pos.y = 0;
if(mouse_pos.x > gfx_screenwidth()) mouse_pos.x = gfx_screenwidth();
if(mouse_pos.y > gfx_screenheight()) mouse_pos.y = gfx_screenheight();
// update the ui
mx = (mouse_pos.x/(float)gfx_screenwidth())*800.0f;
my = (mouse_pos.y/(float)gfx_screenheight())*600.0f;
int buttons = 0;
if(inp_key_pressed(input::mouse_1)) buttons |= 1;
if(inp_key_pressed(input::mouse_2)) buttons |= 2;
if(inp_key_pressed(input::mouse_3)) buttons |= 4;
ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
gfx_texture_set(cursor_texture);
gfx_quads_begin();
gfx_quads_setcolor(1,1,1,1);
gfx_quads_drawTL(mx,my,24,24);
gfx_quads_end();
char buf[128];
if (gametype == GAMETYPE_TDM)
{
// Switch team
ui_do_label(100,100,"Switch Team",40);
sprintf(buf,"Team: %s",local_player->team ? "A" : "B");
if (ui_do_button(&menu_team, buf, 0, 30, 150, 170, 48, draw_teewars_button))
{
msg_pack_start(MSG_SWITCHTEAM, MSGFLAG_VITAL);
msg_pack_end();
client_send_msg();
menu_active = false;
}
}
if (ui_do_button(&menu_quit, "Quit", 0, 30, 350, 170, 48, draw_teewars_button))
{
//if (get_state() == STATE_CONNECTING || get_state() == STATE_ONLINE)
main_client.disconnect();
}
}
void modc_render() void modc_render()
{ {
animstate idlestate; animstate idlestate;
anim_eval(&data->animations[ANIM_BASE], 0, &idlestate); anim_eval(&data->animations[ANIM_BASE], 0, &idlestate);
anim_eval_add(&idlestate, &data->animations[ANIM_IDLE], 0, 1.0f); anim_eval_add(&idlestate, &data->animations[ANIM_IDLE], 0, 1.0f);
if (inp_key_down(input::esc))
{
menu_active = !menu_active;
}
if (!menu_active)
{
if(inp_key_down(input::enter)) if(inp_key_down(input::enter))
{ {
if(chat_active) if(chat_active)
@ -1036,6 +1109,7 @@ void modc_render()
} }
} }
}
input::clear_char(); // TODO: bypasses the engine interface input::clear_char(); // TODO: bypasses the engine interface
input::clear_key(); // TODO: bypasses the engine interface input::clear_key(); // TODO: bypasses the engine interface
@ -1063,7 +1137,7 @@ void modc_render()
input.target_y = (int)mouse_pos.y; //(int)(a*256.0f); input.target_y = (int)mouse_pos.y; //(int)(a*256.0f);
input.activeweapon = -1; input.activeweapon = -1;
if(!chat_active) if(!chat_active && !menu_active)
{ {
input.left = inp_key_pressed(config.key_move_left); input.left = inp_key_pressed(config.key_move_left);
input.right = inp_key_pressed(config.key_move_right); input.right = inp_key_pressed(config.key_move_right);
@ -1157,8 +1231,11 @@ void modc_render()
{ {
void *prev = snap_find_item(SNAP_PREV, item.type, item.id); void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if(prev) if(prev)
{
client_datas[((obj_player *)data)->clientid].team = ((obj_player *)data)->team;
render_player((obj_player *)prev, (obj_player *)data); render_player((obj_player *)prev, (obj_player *)data);
} }
}
else if(item.type == OBJTYPE_PROJECTILE) else if(item.type == OBJTYPE_PROJECTILE)
{ {
void *prev = snap_find_item(SNAP_PREV, item.type, item.id); void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
@ -1188,9 +1265,12 @@ void modc_render()
gfx_quads_begin(); gfx_quads_begin();
// render cursor // render cursor
if (!menu_active)
{
select_sprite(data->weapons[local_player->weapon%data->num_weapons].sprite_cursor); select_sprite(data->weapons[local_player->weapon%data->num_weapons].sprite_cursor);
float cursorsize = 64; float cursorsize = 64;
draw_sprite(local_player_pos.x+mouse_pos.x, local_player_pos.y+mouse_pos.y, cursorsize); draw_sprite(local_player_pos.x+mouse_pos.x, local_player_pos.y+mouse_pos.y, cursorsize);
}
// render ammo count // render ammo count
// render gui stuff // render gui stuff
@ -1252,22 +1332,26 @@ void modc_render()
// render victim tee // render victim tee
x -= 24.0f; x -= 24.0f;
//int skin = gametype == GAMETYPE_TDM ? skinseed + player->team : player->clientid; int skin = gametype == GAMETYPE_TDM ? skinseed + client_datas[killmsgs[r].victim].team : killmsgs[r].victim;
render_tee(&idlestate, killmsgs[r].victim, vec2(1,0), vec2(x, y+28)); render_tee(&idlestate, skin, vec2(1,0), vec2(x, y+28));
x -= 32.0f; x -= 32.0f;
// render weapon // render weapon
x -= 44.0f; x -= 44.0f;
if (killmsgs[r].weapon >= 0)
{
gfx_texture_set(data->images[IMAGE_WEAPONS].id); gfx_texture_set(data->images[IMAGE_WEAPONS].id);
gfx_quads_begin(); gfx_quads_begin();
select_sprite(data->weapons[killmsgs[r].weapon].sprite_body); select_sprite(data->weapons[killmsgs[r].weapon].sprite_body);
draw_sprite(x, y+28, 96); draw_sprite(x, y+28, 96);
gfx_quads_end(); gfx_quads_end();
}
x -= 52.0f; x -= 52.0f;
// render killer tee // render killer tee
x -= 24.0f; x -= 24.0f;
render_tee(&idlestate, killmsgs[r].killer, vec2(1,0), vec2(x, y+28)); skin = gametype == GAMETYPE_TDM ? skinseed + client_datas[killmsgs[r].killer].team : killmsgs[r].killer;
render_tee(&idlestate, skin, vec2(1,0), vec2(x, y+28));
x -= 32.0f; x -= 32.0f;
// render killer name // render killer name
@ -1278,6 +1362,12 @@ void modc_render()
} }
} }
if (menu_active)
{
ingamemenu_render();
return;
}
// render chat // render chat
{ {
gfx_mapscreen(0,0,400,300); gfx_mapscreen(0,0,400,300);
@ -1410,7 +1500,8 @@ void modc_render()
// Team deathmatch // Team deathmatch
gfx_blend_normal(); gfx_blend_normal();
float x = 50.0f; float w = 650.0f;
float x = width-w-50.0f;
float y = 150.0f; float y = 150.0f;
gfx_texture_set(-1); gfx_texture_set(-1);
@ -1483,7 +1574,12 @@ void modc_render()
gfx_pretty_text(offsetx + x+128, offsets[player->team], 48, client_datas[player->clientid].name); gfx_pretty_text(offsetx + x+128, offsets[player->team], 48, client_datas[player->clientid].name);
int skin = skinseed + player->team; int skin = skinseed + player->team;
render_tee(&idlestate, skin, vec2(1,0), vec2(offsetx + x+90, y+24)); render_tee(&idlestate, skin, vec2(1,0), vec2(offsetx + x+90, offsets[player->team]+24));
sprintf(buf, "%4d", player->latency);
float tw = gfx_pretty_text_width(48.0f, buf);
gfx_pretty_text(offsetx + x + 220, y, 48, buf);
offsets[player->team] += 58.0f; offsets[player->team] += 58.0f;
} }
} }

17
src/game/client/menu.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef __MENU_H
#define __MENU_H
extern int cursor_texture;
void draw_image_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
void draw_single_part_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
void draw_menu_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
void draw_teewars_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
int ui_do_key_reader(void *id, float x, float y, float w, float h, int key);
int ui_do_combo_box(void *id, float x, float y, float w, char *lines, int line_count, int selected_index);
int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int str_size);
int ui_do_check_box(void *id, float x, float y, float w, float h, int value);
int do_scroll_bar_horiz(void *id, float x, float y, float width, int steps, int last_index);
int do_scroll_bar_vert(void *id, float x, float y, float height, int steps, int last_index);
#endif

View file

@ -49,6 +49,7 @@ enum
MSG_CHAT, MSG_CHAT,
MSG_SETNAME, MSG_SETNAME,
MSG_KILLMSG, MSG_KILLMSG,
MSG_SWITCHTEAM,
}; };
enum enum
@ -157,11 +158,6 @@ struct obj_player
enum enum
{ {
WEAPON_TYPE_GUN = 0,
WEAPON_TYPE_ROCKET = 1,
WEAPON_TYPE_SHOTGUN = 2,
WEAPON_TYPE_MELEE = 3,
WEAPON_NUMWEAPONS,
//WEAPON_TYPE_SNIPER = 2, //WEAPON_TYPE_SNIPER = 2,
POWERUP_TYPE_HEALTH = 0, POWERUP_TYPE_HEALTH = 0,

View file

@ -4,5 +4,5 @@ MACRO_CONFIG_INT(key_jump, 32, 32, 512)
MACRO_CONFIG_INT(key_fire, 384, 32, 512) MACRO_CONFIG_INT(key_fire, 384, 32, 512)
MACRO_CONFIG_INT(key_hook, 385, 32, 512) MACRO_CONFIG_INT(key_hook, 385, 32, 512)
MACRO_CONFIG_INT(scorelimit, 20, 0, 1000) MACRO_CONFIG_INT(scorelimit, 2, 0, 1000)
MACRO_CONFIG_INT(timelimit, 0, 0, 1000) MACRO_CONFIG_INT(timelimit, 0, 0, 1000)

View file

@ -1640,6 +1640,13 @@ void mods_message(int msg, int client_id)
msg_pack_end(); msg_pack_end();
server_send_msg(-1); server_send_msg(-1);
} }
else if (msg == MSG_SWITCHTEAM)
{
// Switch team on given client and kill/respawn him
players[client_id].team = !players[client_id].team;
players[client_id].die(client_id, -1);
players[client_id].score--;
}
} }
void mods_init() void mods_init()
@ -1662,19 +1669,19 @@ void mods_init()
{ {
case ITEM_WEAPON_GUN: case ITEM_WEAPON_GUN:
type = POWERUP_TYPE_WEAPON; type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_GUN; subtype = WEAPON_GUN;
break; break;
case ITEM_WEAPON_SHOTGUN: case ITEM_WEAPON_SHOTGUN:
type = POWERUP_TYPE_WEAPON; type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_SHOTGUN; subtype = WEAPON_SHOTGUN;
break; break;
case ITEM_WEAPON_ROCKET: case ITEM_WEAPON_ROCKET:
type = POWERUP_TYPE_WEAPON; type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_ROCKET; subtype = WEAPON_ROCKET;
break; break;
case ITEM_WEAPON_HAMMER: case ITEM_WEAPON_HAMMER:
type = POWERUP_TYPE_WEAPON; type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_MELEE; subtype = WEAPON_HAMMER;
break; break;
case ITEM_HEALTH: case ITEM_HEALTH:
@ -1684,6 +1691,10 @@ void mods_init()
case ITEM_ARMOR: case ITEM_ARMOR:
type = POWERUP_TYPE_ARMOR; type = POWERUP_TYPE_ARMOR;
break; break;
case ITEM_NINJA:
type = POWERUP_TYPE_NINJA;
subtype = WEAPON_NINJA;
break;
}; };
powerup *ppower = new powerup(type, subtype); powerup *ppower = new powerup(type, subtype);