Skip to content

Commit

Permalink
See desc
Browse files Browse the repository at this point in the history
* camera zooms when spectating an aiming player
* proper join/refresh buttons with tooltips on server list
* client replies with supported extensions
  • Loading branch information
xtreme8000 committed Apr 4, 2019
1 parent 20668ba commit 8132915
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/camera.c
Expand Up @@ -31,12 +31,13 @@ float camera_height = 0.8F;
float camera_eye_height = 0.0F;
float camera_movement_x = 0.0F, camera_movement_y = 0.0F, camera_movement_z = 0.0F;
float camera_speed = 32.0F;
long camera_last_key = 0;

float camera_fov_scaled() {
if(camera_mode==CAMERAMODE_FPS && players[local_player_id].held_item==TOOL_GUN && players[local_player_id].input.buttons.rmb && !players[local_player_id].input.keys.sprint) {
int render_fpv = (camera_mode==CAMERAMODE_FPS) || ((camera_mode==CAMERAMODE_BODYVIEW || camera_mode==CAMERAMODE_SPECTATOR) && cameracontroller_bodyview_mode);
int local_id = (camera_mode==CAMERAMODE_FPS)?local_player_id:cameracontroller_bodyview_player;

if(render_fpv && players[local_id].held_item==TOOL_GUN && players[local_id].input.buttons.rmb && !players[local_id].input.keys.sprint)
return camera_fov*atan(tan((camera_fov/180.0F*PI)/2)/2.0F)*2.0F;
}
return camera_fov;
}

Expand Down
1 change: 0 additions & 1 deletion src/camera.h
Expand Up @@ -36,7 +36,6 @@ extern float camera_height;
extern float camera_eye_height;
extern float camera_movement_x, camera_movement_y, camera_movement_z;
extern float camera_speed;
extern long camera_last_key;

struct Camera_HitType {
char type;
Expand Down
68 changes: 47 additions & 21 deletions src/hud.c
Expand Up @@ -26,6 +26,14 @@ struct hud hud_mapload;
struct hud* hud_active;
struct window_instance* hud_window;

static int is_inside_centered(double mx, double my, int x, int y, int w, int h) {
return mx>=x-w/2 && mx<x+w/2 && my>=y-h/2 && my<y+h/2;
}

static int is_inside(double mx, double my, int x, int y, int w, int h) {
return mx>=x && mx<x+w && my>=y && my<y+h;
}

void hud_init() {
hud_change(&hud_serverlist);
}
Expand Down Expand Up @@ -993,9 +1001,11 @@ static void hud_ingame_mouseclick(int button, int action, int mods) {
if(camera_mode==CAMERAMODE_BODYVIEW || camera_mode==CAMERAMODE_SPECTATOR) {
if(camera_mode==CAMERAMODE_SPECTATOR)
cameracontroller_bodyview_mode = 1;
do {
for(int k=0;k<PLAYERS_MAX*2;k++) {
if(player_can_spectate(&players[cameracontroller_bodyview_player]))
break;
cameracontroller_bodyview_player = (cameracontroller_bodyview_player+1)%PLAYERS_MAX;
} while(!player_can_spectate(&players[cameracontroller_bodyview_player]));
}
cameracontroller_bodyview_zoom = 0.0F;
}
}
Expand Down Expand Up @@ -1041,11 +1051,13 @@ static void hud_ingame_mouseclick(int button, int action, int mods) {
if(camera_mode==CAMERAMODE_BODYVIEW || camera_mode==CAMERAMODE_SPECTATOR) {
if(camera_mode==CAMERAMODE_SPECTATOR)
cameracontroller_bodyview_mode = 1;
do {
for(int k=0;k<PLAYERS_MAX*2;k++) {
if(player_can_spectate(&players[cameracontroller_bodyview_player]))
break;
cameracontroller_bodyview_player = (cameracontroller_bodyview_player-1)%PLAYERS_MAX;
if(cameracontroller_bodyview_player<0)
cameracontroller_bodyview_player = PLAYERS_MAX-1;
} while(!player_can_spectate(&players[cameracontroller_bodyview_player]));
}
cameracontroller_bodyview_zoom = 0.0F;
}
}
Expand Down Expand Up @@ -1535,6 +1547,15 @@ static void hud_serverlist_pingcomplete() {
pthread_mutex_unlock(&serverlist_lock);
}

static int render_tooltip(char* str, float x, float y, float scaley) {
if(*str) {
glColor3f(1.0F,1.0F,1.0F);
texture_draw_empty(x+5*scaley,settings.window_height-y+5*scaley,font_length(16*scaley,str)+10*scaley,26*scaley);
glColor3f(0.0F,0.0F,0.0F);
font_render(x+10*scaley,settings.window_height-y,16*scaley,str);
}
}

static void hud_serverlist_render(float scalex, float scaley) {
glColor3f(0.5F,0.5F,0.5F);
float t = window_time()*0.03125F;
Expand Down Expand Up @@ -1563,7 +1584,8 @@ static void hud_serverlist_render(float scalex, float scaley) {
texture_draw_sector(&texture_ui_input,settings.window_width/2.0F-300*scaley+8*scaley,485*scaley,(400-32)*scaley,32*scaley,0.25F,0.0F,0.5F,1.0F);
texture_draw_sector(&texture_ui_input,settings.window_width/2.0F-300*scaley+(400-32+8)*scaley,485*scaley,8*scaley,32*scaley,0.75F,0.0F,0.25F,1.0F);

texture_draw(&texture_ui_join,settings.window_width/2.0F+105*scaley,485*scaley,32*scaley,32*scaley);
texture_draw(&texture_ui_join,settings.window_width/2.0F+90*scaley,485*scaley,32*scaley,32*scaley);
texture_draw(&texture_ui_reload,settings.window_width/2.0F+130*scaley,485*scaley,32*scaley,32*scaley);

int a = strlen(chat[0][0]);
chat[0][0][a] = '_';
Expand All @@ -1577,9 +1599,6 @@ static void hud_serverlist_render(float scalex, float scaley) {
font_render((settings.window_width-600*scaley)/2.0F+490*scaley,450*scaley,18*scaley,"Mode");
font_render((settings.window_width-600*scaley)/2.0F+560*scaley,450*scaley,18*scaley,"Ping");

//texture_draw(&texture_ui_reload,(settings.window_width-600*scaley)/2.0F+375*scaley,500*scaley,32*scaley,32*scaley);
//texture_draw(&texture_ui_join,(settings.window_width-600*scaley)/2.0F+327*scaley,500*scaley,32*scaley,32*scaley);

if(serverlist_scroll>0)
serverlist_scroll = 0;
if(serverlist_scroll<-(server_count*20-430+50)*scaley)
Expand Down Expand Up @@ -1743,6 +1762,14 @@ static void hud_serverlist_render(float scalex, float scaley) {
}
}

double x,y;
window_mouseloc(&x,&y);
if(is_inside(x,settings.window_height-y,settings.window_width/2.0F+90*scaley,(485-32)*scaley,32*scaley,32*scaley))
render_tooltip("Join address",x,y,scaley);

if(is_inside(x,settings.window_height-y,settings.window_width/2.0F+130*scaley,(485-32)*scaley,32*scaley,32*scaley))
render_tooltip("Refresh",x,y,scaley);

if(render_status_icon) {
glColor3f(1.0F,1.0F,1.0F);
texture_draw_rotated(serverlist_con_established?&texture_ui_wait:&texture_ui_alert,settings.window_width/2.0F,settings.window_height/2.0F,48*scaley,48*scaley,serverlist_con_established?-window_time()*5.0F:0.0F);
Expand Down Expand Up @@ -1806,6 +1833,15 @@ static void hud_serverlist_mouseclick(int button, int action, int mods) {
&& y>=settings.window_height-(450*scaley-(430-50)*scaley*progress)) {
hud_serverlist_drag = 1;
}


//texture_draw(&texture_ui_join,settings.window_width/2.0F+90*scaley,485*scaley,32*scaley,32*scaley);
if(is_inside(x,settings.window_height-y,settings.window_width/2.0F+90*scaley,(485-32)*scaley,32*scaley,32*scaley)
&& strlen(chat[0][0])>0)
server_c(chat[0][0]);

if(is_inside(x,settings.window_height-y,settings.window_width/2.0F+130*scaley,(485-32)*scaley,32*scaley,32*scaley))
hud_change(&hud_serverlist);
}

if(hud_serverlist_drag && action==WINDOW_RELEASE)
Expand All @@ -1816,6 +1852,7 @@ void hud_serverlist_mouselocation(double x, double y) {
if(hud_serverlist_drag) {
float scaley = settings.window_height/600.0F;
serverlist_scroll = -((y-160*scaley)*(20*server_count*scaley-380*scaley))/(380*scaley);
return;
}
}

Expand Down Expand Up @@ -1859,14 +1896,6 @@ static void hud_settings_init() {
chat[0][0][0] = 0;
}

static int is_inside_centered(double mx, double my, int x, int y, int w, int h) {
return mx>=x-w/2 && mx<x+w/2 && my>=y-h/2 && my<y+h/2;
}

static int is_inside(double mx, double my, int x, int y, int w, int h) {
return mx>=x && mx<x+w && my>=y && my<y+h;
}

static void hud_settings_render(float scalex, float scaley) {
glColor3f(0.5F,0.5F,0.5F);
float t = window_time()*0.03125F;
Expand Down Expand Up @@ -1949,11 +1978,8 @@ static void hud_settings_render(float scalex, float scaley) {
if(k>0)
col_offset = ((k+1)&1)?314*scaley:0;

if(*a->help && is_inside(x,settings.window_height-y,(settings.window_width-600*scaley)/2.0F+col_offset,(435-40*row_offset)*scaley,300*scaley,32*scaley)) {
glColor3f(1.0F,1.0F,1.0F);
texture_draw_empty(x+5*scaley,settings.window_height-y+5*scaley,font_length(16*scaley,a->help)+10*scaley,26*scaley);
glColor3f(0.0F,0.0F,0.0F);
font_render(x+10*scaley,settings.window_height-y,16*scaley,a->help);
if(is_inside(x,settings.window_height-y,(settings.window_width-600*scaley)/2.0F+col_offset,(435-40*row_offset)*scaley,300*scaley,32*scaley)) {
render_tooltip(a->help,x,y,scaley);
break;
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/network.c
Expand Up @@ -871,10 +871,20 @@ void read_PacketVersionGet(void* data, int len) {

void read_PacketExtInfo(void* data, int len) {
struct PacketExtInfo* p = (struct PacketExtInfo*)data;
if(len>=p->length*sizeof(p->entries[0])+1) {
if(len>=p->length*sizeof(struct PacketExtInfoEntry)+1) {
log_info("Server supports the following extensions:");
for(int k=0;k<p->length;k++)
for(int k=0;k<p->length;k++) {
log_info("Extension 0x%02X of version %i",p->entries[k].id,p->entries[k].version);
if(p->entries[k].id>=192)
log_info("(which is packetless)");
}

struct PacketExtInfo reply;
reply.length = 3;
reply.entries[0] = (struct PacketExtInfoEntry) {.id = EXT_256PLAYERS, .version = 1 };
reply.entries[1] = (struct PacketExtInfoEntry) {.id = EXT_MESSAGES, .version = 1 };
reply.entries[2] = (struct PacketExtInfoEntry) {.id = EXT_KICKREASON, .version = 1 };
network_send(PACKET_EXTINFO_ID,&reply,reply.length*sizeof(struct PacketExtInfoEntry)+1);
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/network.h
Expand Up @@ -75,8 +75,8 @@ extern unsigned char network_keys_last;
extern unsigned char network_buttons_last;
extern unsigned char network_tool_last;

#define VERSION_075 3
#define VERSION_076 4
#define VERSION_075 3
#define VERSION_076 4

extern void* compressed_chunk_data;
extern int compressed_chunk_data_size;
Expand Down Expand Up @@ -409,10 +409,16 @@ struct PacketProgressBar {
#define PACKET_EXTINFO_ID 60
struct PacketExtInfo {
unsigned char length;
struct {
struct PacketExtInfoEntry {
unsigned char id;
unsigned char version;
} entries[256];
};

enum Extension {
EXT_256PLAYERS = 0xC0,
EXT_MESSAGES = 0xC1,
EXT_KICKREASON = 0xC2,
};

#pragma pack(pop)

0 comments on commit 8132915

Please sign in to comment.