Permalink
Browse files

Initial commit.

  • Loading branch information...
James McLean
James McLean committed Jun 5, 2015
0 parents commit 5426d7939d4747c9b9cf264c883e3e670600bc46
Showing with 1,233 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +26 −0 LICENSE.md
  3. +14 −0 README.md
  4. +55 −0 box.gd
  5. +242 −0 box.xml
  6. +4 −0 defaults.cfg
  7. +114 −0 demo.gd
  8. +767 −0 demo.xml
  9. +9 −0 engine.cfg
  10. BIN icon.png
  11. +1 −0 icon.png.flags
@@ -0,0 +1 @@
.fscache
@@ -0,0 +1,26 @@
The MIT License (MIT)
=====================
Copyright © `2015` `James McLean`
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
# Godot Networked Physics Demo (Work in Progress)
In light of what I learned since I made the [snapshot interpolation demo](https://github.com/jrimclean/network-demo-tcp.git), I have decided to write a new demo. This time I'm using a technique called state synchronization.
Both the client and the server run the physical simulation. State snapshots are sent from the server to the client at an adjustable rate. With each update, the physical state on the client is snapped to the new state.
To start a dedicated server with the headless version of Godot type, "godotserver -server" in the project directory.
## Todo:
* Everything
## License
Copyright (c) 2015 James McLean
Licensed under the MIT license.
55 box.gd
@@ -0,0 +1,55 @@
extends RigidBody2D
const EVENT_START_DRAG = 0
const EVENT_END_DRAG = 1
const EVENT_DRAGGING = 2
const SCALE_FACTOR = 25
var dragging = false
var host = true;
var stream = null
func _ready():
set_process_input(true)
pass
func _input_event(viewport, event, shape_idx):
if (event.type == InputEvent.MOUSE_BUTTON and event.pressed):
start_dragging()
func _input(event):
if (event.type == InputEvent.MOUSE_MOTION and dragging):
var rect = get_tree().get_root().get_rect()
var pos = event.pos
if (pos.x <= 0 or pos.y <= 0 or pos.x >= (rect.size.x - 1) or pos.y >= (rect.size.y - 1)):
stop_dragging()
else:
drag(pos)
elif (event.type == InputEvent.MOUSE_BUTTON and not event.pressed and dragging):
stop_dragging()
func start_dragging():
dragging = true
if (host):
set_gravity_scale(0)
set_linear_velocity(Vector2(0,0))
func stop_dragging():
dragging = false
if (host):
set_gravity_scale(1)
set_applied_force(Vector2(0,0))
else:
stream.put_var(["stop_drag", get_name()])
func drag(pos):
if (host):
set_applied_force((pos - get_pos()) * SCALE_FACTOR)
else:
stream.put_var(["drag", get_name(), pos])
242 box.xml
@@ -0,0 +1,242 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resource_file type="PackedScene" subresource_count="4" version="1.1" version_name="Godot Engine v1.1.stable.custom_build">
<ext_resource path="res://box.gd" type="Script"></ext_resource>
<ext_resource path="res://icon.png" type="Texture"></ext_resource>
<resource type="RectangleShape2D" path="local://1">
<real name="custom_solver_bias"> 0 </real>
<vector2 name="extents"> 10, 10 </vector2>
</resource>
<main_resource>
<dictionary name="_bundled" shared="false">
<string> "conn_count" </string>
<int> 0 </int>
<string> "conns" </string>
<int_array len="0"> </int_array>
<string> "names" </string>
<string_array len="53">
<string> "box" </string>
<string> "RigidBody2D" </string>
<string> "_import_path" </string>
<string> "visibility/visible" </string>
<string> "visibility/opacity" </string>
<string> "visibility/self_opacity" </string>
<string> "visibility/light_mask" </string>
<string> "transform/pos" </string>
<string> "transform/rot" </string>
<string> "transform/scale" </string>
<string> "z/z" </string>
<string> "z/relative" </string>
<string> "input/pickable" </string>
<string> "shape_count" </string>
<string> "shapes/0/shape" </string>
<string> "shapes/0/transform" </string>
<string> "shapes/0/trigger" </string>
<string> "collision/layers" </string>
<string> "collision/mask" </string>
<string> "mode" </string>
<string> "mass" </string>
<string> "friction" </string>
<string> "bounce" </string>
<string> "gravity_scale" </string>
<string> "custom_integrator" </string>
<string> "continuous_cd" </string>
<string> "contacts_reported" </string>
<string> "contact_monitor" </string>
<string> "sleeping" </string>
<string> "can_sleep" </string>
<string> "velocity/linear" </string>
<string> "velocity/angular" </string>
<string> "damp_override/linear" </string>
<string> "damp_override/angular" </string>
<string> "script/script" </string>
<string> "__meta__" </string>
<string> "sprite" </string>
<string> "Sprite" </string>
<string> "texture" </string>
<string> "centered" </string>
<string> "offset" </string>
<string> "flip_h" </string>
<string> "flip_v" </string>
<string> "vframes" </string>
<string> "hframes" </string>
<string> "frame" </string>
<string> "modulate" </string>
<string> "region" </string>
<string> "region_rect" </string>
<string> "collision" </string>
<string> "CollisionShape2D" </string>
<string> "shape" </string>
<string> "trigger" </string>
</string_array>
<string> "node_count" </string>
<int> 3 </int>
<string> "nodes" </string>
<int_array len="155"> -1, -1, 1, 0, -1, 34, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 1, 12, 1, 13, 3, 14, 8, 15, 9, 16, 10, 17, 3, 18, 3, 19, 7, 20, 2, 21, 2, 22, 5, 23, 2, 24, 10, 25, 7, 26, 7, 27, 10, 28, 10, 29, 1, 30, 4, 31, 5, 32, 11, 33, 11, 34, 12, 35, 13, 0, 0, 0, 37, 36, -1, 21, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 1, 38, 14, 39, 1, 40, 4, 41, 10, 42, 10, 43, 3, 44, 3, 45, 7, 46, 15, 47, 10, 48, 16, 0, 0, 0, 50, 49, -1, 12, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 17, 8, 5, 9, 18, 10, 7, 11, 1, 51, 8, 52, 10, 0 </int_array>
<string> "variants" </string>
<array len="19" shared="false">
<node_path> "" </node_path>
<bool> True </bool>
<real> 1 </real>
<int> 1 </int>
<vector2> 0, 0 </vector2>
<real> 0 </real>
<vector2> 1, 1 </vector2>
<int> 0 </int>
<resource resource_type="Shape2D" path="local://1"> </resource>
<matrix32> 3.20152, -0, 0, 3.20152, 0.199575, 0.185632 </matrix32>
<bool> False </bool>
<real> -1 </real>
<resource resource_type="Script" path="res://box.gd"> </resource>
<dictionary shared="false">
<string> "__editor_plugin_screen__" </string>
<string> "2D" </string>
<string> "__editor_plugin_states__" </string>
<dictionary shared="false">
<string> "2D" </string>
<dictionary shared="false">
<string> "ofs" </string>
<vector2> -742.988, -339.381 </vector2>
<string> "snap_grid" </string>
<bool> False </bool>
<string> "snap_offset" </string>
<vector2> 0, 0 </vector2>
<string> "snap_pixel" </string>
<bool> False </bool>
<string> "snap_relative" </string>
<bool> False </bool>
<string> "snap_rotation" </string>
<bool> False </bool>
<string> "snap_rotation_offset" </string>
<real> 0 </real>
<string> "snap_rotation_step" </string>
<real> 0.261799 </real>
<string> "snap_show_grid" </string>
<bool> False </bool>
<string> "snap_step" </string>
<vector2> 10, 10 </vector2>
<string> "zoom" </string>
<real> 1 </real>
</dictionary>
<string> "3D" </string>
<dictionary shared="false">
<string> "ambient_light_color" </string>
<color> 0.15, 0.15, 0.15, 1 </color>
<string> "default_light" </string>
<bool> True </bool>
<string> "default_srgb" </string>
<bool> False </bool>
<string> "deflight_rot_x" </string>
<real> 0.942478 </real>
<string> "deflight_rot_y" </string>
<real> 0.628319 </real>
<string> "fov" </string>
<real> 45 </real>
<string> "show_grid" </string>
<bool> True </bool>
<string> "show_origin" </string>
<bool> True </bool>
<string> "viewport_mode" </string>
<int> 1 </int>
<string> "viewports" </string>
<array len="4" shared="false">
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "listener" </string>
<bool> True </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "listener" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "listener" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "listener" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
</array>
<string> "zfar" </string>
<real> 500 </real>
<string> "znear" </string>
<real> 0.1 </real>
</dictionary>
<string> "Script" </string>
<dictionary shared="false">
<string> "current" </string>
<int> 0 </int>
<string> "sources" </string>
<array len="1" shared="false">
<string> "res://box.gd" </string>
</array>
</dictionary>
</dictionary>
<string> "__editor_run_settings__" </string>
<dictionary shared="false">
<string> "custom_args" </string>
<string> "-l $scene" </string>
<string> "run_mode" </string>
<int> 0 </int>
</dictionary>
</dictionary>
<resource resource_type="Texture" path="res://icon.png"> </resource>
<color> 1, 1, 1, 1 </color>
<rect2> 0, 0, 0, 0 </rect2>
<vector2> 0.199575, 0.185632 </vector2>
<vector2> 3.20152, 3.20152 </vector2>
</array>
<string> "version" </string>
<int> 1 </int>
</dictionary>
</main_resource>
</resource_file>
@@ -0,0 +1,4 @@
[defaults]
network_fps=40
ip="127.0.0.1"
port=3000
Oops, something went wrong.

0 comments on commit 5426d79

Please sign in to comment.