Skip to content

Commit

Permalink
reduced bandwidth by only sending changing inputs #15
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Jul 4, 2014
1 parent 3db19a6 commit d49215e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion output/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ config_table = {
window_x = 0,
window_y = 0,
bpp = 24,
resolution_w = 1800,
resolution_w = 1300,
resolution_h = 1000,
doublebuffer = 1,

Expand Down
2 changes: 1 addition & 1 deletion output/hypersomnia/scripts/loaders/basic_map_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ return function(map_filename, scene_object)
scene_object.world_camera = create_world_camera_entity(world, scene_object.sprite_library["blank"])
scene_object.world_camera.script.owner_scene = scene_object

if config_table.multiple_clients_view then
if config_table.multiple_clients_view == 1 then
scene_object.world_camera.script.min_zoom = -400
scene_object.world_camera.script:set_zoom_level(-400)
end
Expand Down
6 changes: 4 additions & 2 deletions output/hypersomnia/scripts/systems/client_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function client_system:send_all_data()
self.net_channel:post_unreliable_bs(self.substep_unreliable)
local output_bs = self.net_channel:send()

--print("Sending: \n\n" .. auto_string_indent(output_bs.content) .. "\n\n")
self.network:send(output_bs, send_priority.IMMEDIATE_PRIORITY, send_reliability.UNRELIABLE, 0, self.server_guid, false)
if output_bs:size() > 0 then
print("Sending: \n\n" .. auto_string_indent(output_bs.content) .. "\n\n")
self.network:send(output_bs, send_priority.IMMEDIATE_PRIORITY, send_reliability.UNRELIABLE, 0, self.server_guid, false)
end
end
end
30 changes: 17 additions & 13 deletions output/hypersomnia/scripts/systems/input_prediction_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,38 @@ function input_prediction_system:substep()
local history_entry = {
-- position here is only for debugging
position = b2Vec2(self.targets[i].cpp_entity.physics.body:GetPosition()),
vel = b2Vec2(self.targets[i].cpp_entity.physics.body:GetLinearVelocity()),
moving_left = movement.moving_left,
moving_right = movement.moving_right,
moving_forward = movement.moving_forward,
moving_backward = movement.moving_backward
}
--clearl()
clearl()

prediction.state_history[prediction.first_state + prediction.count] = history_entry
prediction.count = prediction.count + 1

if prediction.count > 60 then
if prediction.count > 1000 then
prediction.state_history[prediction.first_state] = nil
prediction.first_state = prediction.first_state + 1
prediction.count = prediction.count - 1
end

--for j=prediction.first_state, prediction.first_state+prediction.count-1 do
-- debuglb2(rgba(255, 255, 255, 255), prediction.state_history[j].position)
--end
for j=prediction.first_state, prediction.first_state+prediction.count-1 do
debuglb2(rgba(255, 255, 255, 255), prediction.state_history[j].position)
end

self.owner_entity_system.all_systems["client"].substep_unreliable:WriteBitstream(protocol.write_msg("INPUT_SNAPSHOT", {
at_step = prediction.first_state + prediction.count - 1,
moving_left = movement.moving_left,
moving_right = movement.moving_right,
moving_forward = movement.moving_forward,
moving_backward = movement.moving_backward
}))
--self.owner_entity_system.all_systems["client"].substep_unreliable:WriteBitstream(protocol.write_msg("INPUT_SNAPSHOT", {

if prediction.count <= 1 or not table.compare(history_entry, prediction.state_history[prediction.first_state + prediction.count - 2], { position = true } )
--or not table.compare(history_entry, prediction.state_history[prediction.first_state + prediction.count - 3], { position = true } )
then
local to_send = {}
rewrite(to_send, history_entry, { position = true } )

to_send.at_step = prediction.first_state + prediction.count - 1

self.owner_entity_system.all_systems["client"].net_channel:post_reliable_bs(protocol.write_msg("INPUT_SNAPSHOT", to_send))
end

self.owner_entity_system.all_systems["client"].cmd_requested = true
end
Expand Down
10 changes: 7 additions & 3 deletions output/hypersomnia/scripts/systems/orientation_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ function orientation_system:update()
orientation.crosshair_entity.transform.current.pos = target.synchronization.modules.crosshair.position
else--if orientation:cmd_rate_ready() then
orientation:cmd_rate_reset()
local current_pos = vec2(orientation.crosshair_entity.transform.current.pos)

self.owner_entity_system.all_systems["client"].net_channel:post_unreliable_bs(protocol.write_msg("CROSSHAIR_SNAPSHOT", {
position = orientation.crosshair_entity.transform.current.pos
}))
--if orientation.last_pos == nil or (orientation.last_pos - current_pos):length() > 1 then
-- orientation.last_pos = current_pos
-- self.owner_entity_system.all_systems["client"].net_channel:post_unreliable_bs(protocol.write_msg("CROSSHAIR_SNAPSHOT", {
-- position = current_pos
-- }))
--end


--self.owner_entity_system.all_systems["client"].cmd_requested = true
Expand Down

0 comments on commit d49215e

Please sign in to comment.