Skip to content

Commit d7926d8

Browse files
authored
Merge pull request #152 from Jupeyy/pr_client_improvements13
Various improvements & fixes
2 parents a2fe267 + 8026e35 commit d7926d8

File tree

21 files changed

+781
-338
lines changed

21 files changed

+781
-338
lines changed

data

game/client-ui/src/emote_wheel/main_frame.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ pub fn render(ui: &mut egui::Ui, pipe: &mut UiRenderPipe<UserData>, ui_state: &m
252252
);
253253
}
254254

255-
ui.painter().circle(
255+
ui_state.add_glass_elipse(
256256
egui::pos2(mouse.x as f32, mouse.y as f32),
257-
10.0,
258-
Color32::from_white_alpha(100),
259-
Stroke::NONE,
257+
egui::vec2(75.0, 75.0),
258+
2.2,
259+
Color32::from_rgba_unmultiplied(200, 200, 255, 255),
260260
);
261261
}

game/client-ui/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn render_tee_for_ui_with_skin(
102102
let tee_render_info = TeeRenderInfo {
103103
color_body,
104104
color_feet,
105-
got_air_jump: false,
105+
got_air_jump: true,
106106
feet_flipped: false,
107107
size: self.size,
108108
eye_left: self.eyes,

game/client-ui/src/vote/main_frame.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,24 @@ pub fn render(ui: &mut egui::Ui, pipe: &mut UiRenderPipe<UserData>, ui_state: &m
116116
},
117117
Color32::RED,
118118
);
119-
at.x -= no_size / 2.0 - 5.0;
120-
ui.painter().text(
121-
at,
122-
egui::Align2::LEFT_CENTER,
119+
at = rect.left_center();
120+
let galley = ui.painter().layout_no_wrap(
123121
format!("{:.1}%", no_perc * 100.0),
124122
FontId::default(),
125123
Color32::WHITE,
126124
);
125+
let size = galley.size();
126+
ui.painter().galley(
127+
if size.x + 10.0 < rect.width() {
128+
at + egui::vec2(5.0, -size.y / 2.0)
129+
} else {
130+
rect.right_center()
131+
- egui::vec2(size.x, size.y / 2.0)
132+
- egui::vec2(5.0, 0.0)
133+
},
134+
galley,
135+
Color32::WHITE,
136+
);
127137
}
128138

129139
if yes_perc > 0.0 {
@@ -142,13 +152,21 @@ pub fn render(ui: &mut egui::Ui, pipe: &mut UiRenderPipe<UserData>, ui_state: &m
142152
},
143153
Color32::GREEN,
144154
);
145-
at.x += yes_size / 2.0 - 5.0;
146-
ui.painter().text(
147-
at,
148-
egui::Align2::RIGHT_CENTER,
155+
at = rect.right_center();
156+
let galley = ui.painter().layout_no_wrap(
149157
format!("{:.1}%", yes_perc * 100.0),
150158
FontId::default(),
151-
Color32::BLACK,
159+
Color32::DARK_GRAY,
160+
);
161+
let size = galley.size();
162+
ui.painter().galley(
163+
if size.x + 10.0 < rect.width() {
164+
at - egui::vec2(size.x, size.y / 2.0) - egui::vec2(5.0, 0.0)
165+
} else {
166+
rect.left_center() + egui::vec2(5.0, -size.y / 2.0)
167+
},
168+
galley,
169+
Color32::DARK_GRAY,
152170
);
153171
}
154172

game/legacy-proxy/src/client.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::BTreeMap, net::SocketAddr, time::Duration};
1+
use std::{collections::BTreeMap, net::SocketAddr};
22

33
use anyhow::anyhow;
44
use arrayvec::ArrayVec;
@@ -208,8 +208,6 @@ pub struct ClientData {
208208
pub latest_input: snap_obj::PlayerInput,
209209
pub latest_char_input: CharacterInput,
210210

211-
pub connect_time: Duration,
212-
213211
pub player_info: NetworkCharacterInfo,
214212

215213
pub latest_inputs: BTreeMap<i32, (CharacterInput, snap_obj::PlayerInput)>,
@@ -226,7 +224,6 @@ impl ProxyClient {
226224
pub fn new(
227225
player_info: NetworkCharacterInfo,
228226
socket: SocketClient,
229-
connect_time: Duration,
230227
id: u64,
231228
secondary_player: bool,
232229
) -> Self {
@@ -255,8 +252,6 @@ impl ProxyClient {
255252
inp
256253
},
257254

258-
connect_time,
259-
260255
player_info,
261256

262257
latest_inputs: Default::default(),

game/legacy-proxy/src/lib.rs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ struct Client {
347347
log: ConnectingLog,
348348

349349
last_snapshot: Snapshot,
350+
351+
start_time: Duration,
350352
}
351353

352354
impl Client {
@@ -356,6 +358,7 @@ impl Client {
356358
addr: SocketAddr,
357359
log: ConnectingLog,
358360
) -> anyhow::Result<LegacyProxy> {
361+
let proxy_start = time.now();
359362
let fs = io.fs.clone();
360363

361364
log.log("Preparing proxy socket");
@@ -437,7 +440,7 @@ impl Client {
437440
Connless::RequestInfo(msg::connless::RequestInfo { token: tokens[0] }),
438441
);
439442
let start_time = time.now();
440-
let mut last_req = start_time;
443+
let mut last_req = None;
441444
let mut last_reconnect = start_time;
442445
while server_info.is_none()
443446
&& !is_finished_thread.load(std::sync::atomic::Ordering::SeqCst)
@@ -511,8 +514,12 @@ impl Client {
511514

512515
let cur_time = time.now();
513516
// send new request
514-
if cur_time.saturating_sub(last_req) > Duration::from_secs(5) {
515-
log.log("Sending new info request after 5s timeout");
517+
if last_req.is_none_or(|last_req| {
518+
cur_time.saturating_sub(last_req) > Duration::from_secs(1)
519+
}) {
520+
if last_req.is_some() {
521+
log.log("Sending new info request after 1s timeout");
522+
}
516523
let token = rand::rng().next_u32() as u8;
517524
conless.sendc(
518525
addr,
@@ -521,7 +528,7 @@ impl Client {
521528

522529
tokens.push(token);
523530

524-
last_req = cur_time;
531+
last_req = Some(cur_time);
525532
}
526533

527534
// try to reconnect
@@ -675,6 +682,8 @@ impl Client {
675682
is_finished: is_finished_thread,
676683

677684
log,
685+
686+
start_time: proxy_start,
678687
};
679688

680689
app.run_loop().unwrap();
@@ -1584,7 +1593,7 @@ impl Client {
15841593
}
15851594
}
15861595
SnapObj::ClientInfo(client_info) => {
1587-
if let Some((character_id, info)) = Self::player_info_mut(id, base, snapshot) {
1596+
if let Some((_, info)) = Self::player_info_mut(id, base, snapshot) {
15881597
fn ints_to_net_str<const MAX_LENGTH: usize>(
15891598
int_arr: &[i32],
15901599
) -> NetworkString<MAX_LENGTH> {
@@ -1596,14 +1605,14 @@ impl Client {
15961605
.map(NetworkString::new_lossy)
15971606
.unwrap_or_default()
15981607
}
1599-
let mut player_info = (*info.player_info).clone();
16001608

16011609
// Apply as much info from known player info as possible
1602-
if character_id == player_id {
1603-
player_info = player.player_info.clone();
1604-
} else if let Some(dummy) = base.local_players.get(&id) {
1605-
player_info = dummy.player_info.clone();
1606-
}
1610+
let mut player_info = if let Some(dummy) = base.local_players.get(&id) {
1611+
dummy.player_info.clone()
1612+
} else {
1613+
// fall back to player info, since legacy servers don't send enough info
1614+
player.player_info.clone()
1615+
};
16071616

16081617
// Then overwrite the info the server knows about
16091618
player_info.name = ints_to_net_str(client_info.name.as_slice());
@@ -3528,13 +3537,7 @@ impl Client {
35283537

35293538
self.players.insert(
35303539
self.base.id_generator.next_id(),
3531-
ProxyClient::new(
3532-
Default::default(),
3533-
sock_loop,
3534-
self.time.now(),
3535-
0,
3536-
false,
3537-
),
3540+
ProxyClient::new(Default::default(), sock_loop, 0, false),
35383541
);
35393542
}
35403543
}
@@ -3564,13 +3567,7 @@ impl Client {
35643567

35653568
self.players.insert(
35663569
self.base.id_generator.next_id(),
3567-
ProxyClient::new(
3568-
Default::default(),
3569-
sock_loop,
3570-
self.time.now(),
3571-
0,
3572-
false,
3573-
),
3570+
ProxyClient::new(Default::default(), sock_loop, 0, false),
35743571
);
35753572
}
35763573
ClientToServerMessage::Ready(msg) => {
@@ -3619,13 +3616,7 @@ impl Client {
36193616
let player_id = self.base.id_generator.next_id();
36203617
self.players.insert(
36213618
player_id,
3622-
ProxyClient::new(
3623-
ev.player_info,
3624-
sock_loop,
3625-
self.time.now(),
3626-
ev.id,
3627-
true,
3628-
),
3619+
ProxyClient::new(ev.player_info, sock_loop, ev.id, true),
36293620
);
36303621
if let Some(con_id) = self.con_id {
36313622
self.server_network.send_unordered_to(
@@ -4531,10 +4522,9 @@ impl Client {
45314522
self.server_network.send_unordered_to(
45324523
&ServerToClientMessage::ServerInfo {
45334524
info: server_info,
4534-
overhead: self
4535-
.time
4536-
.now()
4537-
.saturating_sub(player.data.connect_time),
4525+
// the proxy is not really good at estimating the first ping
4526+
// so give it the whole startup time as overhead instead
4527+
overhead: self.time.now().saturating_sub(self.start_time),
45384528
},
45394529
&con_id,
45404530
);

lib/api-ui/src/ui_impl.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use api::{GRAPHICS, GRAPHICS_BACKEND, read_param_from_host, upload_return_val};
44

55
use graphics_types::types::WindowProps;
66
use ui_base::{
7-
types::{BlurShape, RawInputWrapper, RawOutputWrapper, UiFonts, UiRenderPipe},
7+
types::{BlurShape, GlassShape, RawInputWrapper, RawOutputWrapper, UiFonts, UiRenderPipe},
88
ui::UiContainer,
99
ui_render::render_ui,
1010
};
@@ -44,7 +44,7 @@ fn ui_run_impl(
4444
inp: RawInputWrapper,
4545
zoom_level: Option<f32>,
4646
mut user_data: U,
47-
) -> (egui::PlatformOutput, Vec<BlurShape>) {
47+
) -> (egui::PlatformOutput, Vec<BlurShape>, Vec<GlassShape>) {
4848
API_UI.with(|g| g.borrow_mut().zoom_level.set(zoom_level));
4949
GRAPHICS.with(|g| g.resized(window_props));
5050

@@ -88,6 +88,7 @@ fn ui_run_impl(
8888
(
8989
platform_output,
9090
API_UI.with(|ui| std::mem::take(&mut ui.borrow_mut().ui_state.blur_shapes)),
91+
API_UI.with(|ui| std::mem::take(&mut ui.borrow_mut().ui_state.glass_shapes)),
9192
)
9293
}
9394

@@ -108,10 +109,12 @@ pub fn ui_run() {
108109
let inp = read_param_from_host::<RawInputWrapper>(2);
109110
let zoom_level = read_param_from_host::<Option<f32>>(3);
110111

111-
let (output, blur_shapes) = ui_run_impl(cur_time, window_props, inp, zoom_level, ());
112+
let (output, blur_shapes, glass_shapes) =
113+
ui_run_impl(cur_time, window_props, inp, zoom_level, ());
112114
upload_return_val(RawOutputWrapper {
113115
output,
114116
blur_shapes,
117+
glass_shapes,
115118
zoom_level: API_UI.with(|g| g.borrow().zoom_level.get()),
116119
});
117120
}

lib/graphics-backend-traits/src/plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub enum SubRenderPassAttributes {
159159
StandardBlurPipeline,
160160
Standard3dPipeline,
161161
BlurPipeline,
162+
GlassPipeline,
162163
PrimExPipeline,
163164
PrimExRotationlessPipeline,
164165
SpriteMultiPipeline,

0 commit comments

Comments
 (0)