Skip to content

Commit

Permalink
add dots rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
stutxo committed Aug 4, 2023
1 parent de5c395 commit 0234ec2
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 45 deletions.
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>☔ rain.run</title>
<script type="module">import init from './satrunner-97f64ddd025fac7b.js';init('./satrunner-97f64ddd025fac7b_bg.wasm');</script>
<script type="module">import init from './satrunner-f07d44c627de5047.js';init('./satrunner-f07d44c627de5047_bg.wasm');</script>


<style>
Expand All @@ -17,8 +17,8 @@
}
</style>

<link rel="preload" href="./satrunner-97f64ddd025fac7b_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="./satrunner-97f64ddd025fac7b.js"></head>
<link rel="preload" href="./satrunner-f07d44c627de5047_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="./satrunner-f07d44c627de5047.js"></head>

<body>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_34(arg0, arg1) {
wasm.wasm_bindgen__convert__closures__invoke0_mut__h685c35a5e5871f40(arg0, arg1);
wasm.wasm_bindgen__convert__closures__invoke0_mut__h00c77c3b0fdeba02(arg0, arg1);
}

function __wbg_adapter_37(arg0, arg1, arg2) {
Expand Down Expand Up @@ -724,6 +724,10 @@ function __wbg_get_imports() {
const ret = getObject(arg0).toString();
return addHeapObject(ret);
};
imports.wbg.__wbg_setTimeout_75cb9b6991a4031d = function() { return handleError(function (arg0, arg1) {
const ret = setTimeout(getObject(arg0), arg1);
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_createFramebuffer_223c1212ad76affc = function(arg0) {
const ret = getObject(arg0).createFramebuffer();
return isLikeNone(ret) ? 0 : addHeapObject(ret);
Expand Down Expand Up @@ -1120,6 +1124,10 @@ function __wbg_get_imports() {
imports.wbg.__wbg_removeEventListener_5de660c02ed784e4 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
getObject(arg0).removeEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));
}, arguments) };
imports.wbg.__wbg_clearTimeout_76877dbc010e786d = function(arg0) {
const ret = clearTimeout(takeObject(arg0));
return addHeapObject(ret);
};
imports.wbg.__wbg_readyState_b25418fd198bf715 = function(arg0) {
const ret = getObject(arg0).readyState;
return ret;
Expand Down Expand Up @@ -1885,64 +1893,68 @@ function __wbg_get_imports() {
imports.wbg.__wbg_cancelAnimationFrame_9b68e9588c6543bc = function() { return handleError(function (arg0, arg1) {
getObject(arg0).cancelAnimationFrame(arg1);
}, arguments) };
imports.wbg.__wbindgen_closure_wrapper2774 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 208, __wbg_adapter_34);
imports.wbg.__wbindgen_closure_wrapper2743 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 211, __wbg_adapter_34);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37388 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37411 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper37393 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2373, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37416 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2369, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper37397 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2373, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37420 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2369, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper37400 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2373, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37423 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2369, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper37403 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2373, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37426 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2369, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper37406 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2373, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37429 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2369, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper37409 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2373, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37432 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2369, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper37574 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper37597 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper38902 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper38881 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper38905 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_34);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper38884 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_34);
imports.wbg.__wbindgen_closure_wrapper38907 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper38886 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper38910 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper38889 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper38917 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 211, __wbg_adapter_34);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper42809 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_34);
imports.wbg.__wbindgen_closure_wrapper42841 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_34);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper44058 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2367, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper44093 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2371, __wbg_adapter_37);
return addHeapObject(ret);
};

Expand Down Expand Up @@ -1986,7 +1998,7 @@ async function __wbg_init(input) {
if (wasm !== undefined) return wasm;

if (typeof input === 'undefined') {
input = new URL('satrunner-97f64ddd025fac7b_bg.wasm', import.meta.url);
input = new URL('satrunner-f07d44c627de5047_bg.wasm', import.meta.url);
}
const imports = __wbg_get_imports();

Expand Down
Binary file not shown.
34 changes: 31 additions & 3 deletions src/game_core/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ use speedy::Readable;

use crate::{
game_core::sprites::{spawn_enemies, spawn_player},
game_util::resources::{ClientTick, NetworkStuff, Objects},
game_util::{
components::{Bolt, Rain},
resources::{BoltPool, ClientTick, NetworkStuff, Objects, RainPool},
},
network::messages::NetworkMessage,
GameStage,
};

use super::player::{Enemy, Player};
use super::{
objects::{handle_bolt_behind, handle_rain_behind},
player::{Enemy, Player},
};

pub fn handle_server(
mut incoming: ResMut<NetworkStuff>,
Expand All @@ -20,6 +26,13 @@ pub fn handle_server(
mut objects: ResMut<Objects>,
asset_server: Res<AssetServer>,
mut next_state: ResMut<NextState<GameStage>>,
mut rain_pool: ResMut<RainPool>,
mut rain: Query<(&Rain, &mut Visibility, &mut Transform), (Without<Player>, Without<Enemy>)>,
mut bolt_pool: ResMut<BoltPool>,
mut bolt: Query<
(&Bolt, &mut Visibility, &mut Transform),
(Without<Player>, Without<Enemy>, Without<Rain>),
>,
) {
if let Some(ref mut receive_rx) = incoming.read {
while let Ok(Some(message)) = receive_rx.try_next() {
Expand All @@ -40,12 +53,27 @@ pub fn handle_server(
player.adjust_iter = game_update.adjustment_iteration;

while ticks_behind < 0 {
player.apply_input(&mut t, &client_tick);
ticks_behind += 1;

//we need to run handle dots/bolts here

// info!(
// "adjusting: {}, player iter {:?}",
// ticks_behind, player.adjust_iter
// );
handle_rain_behind(
&mut objects,
&mut rain_pool,
&mut rain,
&client_tick,
);
handle_bolt_behind(
&mut objects,
&mut bolt_pool,
&mut bolt,
&client_tick,
);
player.apply_input(&mut t, &client_tick);
if let Some(tick) = &mut client_tick.tick {
*tick += 1;
}
Expand Down
129 changes: 127 additions & 2 deletions src/game_core/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::game_util::{
resources::{BoltPool, ClientTick, Objects, RainPool},
};

use super::player::Player;
use super::player::{Enemy, Player};

pub const X_BOUNDS: f32 = 1000.0;
pub const Y_BOUNDS: f32 = 500.0;
Expand All @@ -23,7 +23,7 @@ pub fn handle_rain(
mut objects: ResMut<Objects>,
mut rain_pool: ResMut<RainPool>,
mut rain: Query<(&Rain, &mut Visibility, &mut Transform), Without<Player>>,
client_tick: Res<ClientTick>,
client_tick: ResMut<ClientTick>,
) {
if client_tick.pause == 0 {
if let Some(rng_seed) = objects.rng_seed {
Expand Down Expand Up @@ -137,3 +137,128 @@ pub fn handle_bolt(
}
}
}

pub fn handle_rain_behind(
mut objects: &mut ResMut<Objects>,
mut rain_pool: &mut ResMut<RainPool>,
mut rain: &mut Query<
(&Rain, &mut Visibility, &mut Transform),
(Without<Player>, Without<Enemy>),
>,
client_tick: &ResMut<ClientTick>,
) {
if client_tick.pause == 0 {
if let Some(rng_seed) = objects.rng_seed {
let seed = rng_seed ^ client_tick.tick.unwrap();
let mut rng = ChaCha8Rng::seed_from_u64(seed);

let x_position: f32 = rng.gen_range(-X_BOUNDS..X_BOUNDS);

let y_position: f32 = Y_BOUNDS;

if client_tick.tick.unwrap_or(0) % 10 != 0 {
let pos_start = Vec3::new(x_position, y_position, 0.0);
let new_pos = ObjectPos {
tick: client_tick.tick.unwrap(),
pos: pos_start,
};
objects.rain_pos.push(new_pos);
}

for object in objects.rain_pos.iter_mut() {
object.pos.y += FALL_SPEED * -0.5;
}

objects.rain_pos.retain(|object| {
object.pos.y >= -Y_BOUNDS
&& object.pos.y <= Y_BOUNDS
&& object.pos.x >= -X_BOUNDS
&& object.pos.x <= X_BOUNDS
});

let mut pool_iter = rain_pool.0.iter_mut();

for object in objects.rain_pos.iter() {
if let Some(pool) = pool_iter.next() {
match rain.get_mut(*pool) {
Ok((_particles, mut visibility, mut transform)) => {
transform.translation = object.pos;
*visibility = Visibility::Visible;
}
Err(err) => {
info!("Error: {:?}", err);
}
}
}
}

for pool in pool_iter {
if let Ok((_particle, mut visibility, _transform)) = rain.get_mut(*pool) {
*visibility = Visibility::Hidden;
}
}
}
}
}

pub fn handle_bolt_behind(
mut objects: &mut ResMut<Objects>,
mut bolt_pool: &mut ResMut<BoltPool>,
mut bolt: &mut Query<
(&Bolt, &mut Visibility, &mut Transform),
(Without<Player>, Without<Enemy>, Without<Rain>),
>,
client_tick: &ResMut<ClientTick>,
) {
if client_tick.pause == 0 {
if let Some(rng_seed) = objects.rng_seed {
let seed = rng_seed ^ (client_tick.tick.unwrap());
let mut rng = ChaCha8Rng::seed_from_u64(seed);

let x_position: f32 = rng.gen_range(-X_BOUNDS..X_BOUNDS);

let y_position: f32 = Y_BOUNDS;
if client_tick.tick.unwrap_or(0) % 10 == 0 {
let pos_start = Vec3::new(x_position, y_position, 0.0);
let new_pos = ObjectPos {
tick: client_tick.tick.unwrap(),
pos: pos_start,
};
objects.bolt_pos.push(new_pos);
}

for object in objects.bolt_pos.iter_mut() {
object.pos.y += FALL_SPEED * -0.5;
}

objects.bolt_pos.retain(|object| {
object.pos.y >= -Y_BOUNDS
&& object.pos.y <= Y_BOUNDS
&& object.pos.x >= -X_BOUNDS
&& object.pos.x <= X_BOUNDS
});

let mut pool_iter = bolt_pool.0.iter_mut();

for object in objects.bolt_pos.iter() {
if let Some(pool) = pool_iter.next() {
match bolt.get_mut(*pool) {
Ok((_particles, mut visibility, mut transform)) => {
transform.translation = object.pos;
*visibility = Visibility::Visible;
}
Err(err) => {
info!("Error: {:?}", err);
}
}
}
}

for pool in pool_iter {
if let Ok((_particle, mut visibility, _transform)) = bolt.get_mut(*pool) {
*visibility = Visibility::Hidden;
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {
.add_systems(Startup, (websocket, pool_rain, pool_bolt))
.add_systems(Update, setup_menu.run_if(in_state(GameStage::Menu)))
.add_systems(Update, (handle_server, score_board, check_disconnected))
.add_systems(FixedUpdate, (tick, handle_rain, enemy_loop, handle_bolt))
.add_systems(FixedUpdate, (tick, enemy_loop, handle_rain, handle_bolt))
.add_systems(Update, (input).run_if(in_state(GameStage::InGame)))
.add_systems(
Update,
Expand Down
Loading

0 comments on commit 0234ec2

Please sign in to comment.