Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify input serialization and input dictionary logic (e.g. validation) #266

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion addons/netfox/netfox.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,21 @@ var SETTINGS = [
"value": 64,
"type": TYPE_INT
},
{
"name": "netfox/rollback/serialized_inputs_history_limit",
"value": 64,
"type": TYPE_INT
},
{
"name": "netfox/rollback/serialized_states_history_limit",
"value": 64,
"type": TYPE_INT
},
{
"name": "netfox/rollback/input_redundancy",
"value": 3,
"type": TYPE_INT
"type": TYPE_INT,
"hint_string": "When an input is sent, which previous tick inputs should we send with it? By having this above 1, inputs are batched together so if a packet is lost which contains an input, the next packets will provide it"
},
{
"name": "netfox/rollback/display_offset",
Expand All @@ -76,6 +87,24 @@ var SETTINGS = [
"name": "netfox/events/enabled",
"value": true,
"type": TYPE_BOOL
},
# Serialization
{
"name": "netfox/serialization/enable_input_serialization",
"value": true,
"type": TYPE_BOOL,
"hint_string": "Enabling this, the input is serialized before sending it, instead of sending a dictionary of string properties and its values. Enabling this is recommended to save bandwidth, at the slight cost of CPU."
},
{
"name": "netfox/serialization/enable_state_serialization",
"value": true,
"type": TYPE_BOOL,
"hint_string": "Enabling this, the state is serialized before sending it, instead of sending a dictionary of string properties and its values. Enabling this is recommended to save bandwidth, at the slight cost of CPU. Note that this serialization isn't diff state, but the state itself just in binary format."
},
{
"name": "netfox/serialization/enable_state_diffs",
"value": true,
"type": TYPE_BOOL,
}
]

Expand Down
2 changes: 1 addition & 1 deletion addons/netfox/properties/property-cache.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func _init(p_root: Node):

func get_entry(path: String) -> PropertyEntry:
if not _cache.has(path):
var parsed = PropertyEntry.parse(root, path)
var parsed: PropertyEntry = PropertyEntry.parse(root, path)
if not parsed.is_valid():
_logger.warning("Invalid property path: %s" % path)
_cache[path] = parsed
Expand Down
2 changes: 2 additions & 0 deletions addons/netfox/properties/property-entry.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class_name PropertyEntry
var _path: String
var node: Node
var property: String
var type: Variant.Type ## See typeof()

func get_value() -> Variant:
return node.get_indexed(property)
Expand All @@ -28,4 +29,5 @@ static func parse(root: Node, path: String) -> PropertyEntry:
result.node = root.get_node(NodePath(path))
result.property = path.erase(0, path.find(":") + 1)
result._path = path
result.type = typeof(result.get_value())
return result
2 changes: 1 addition & 1 deletion addons/netfox/properties/property-snapshot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Object
class_name PropertySnapshot

static func extract(properties: Array[PropertyEntry]) -> Dictionary:
var result = {}
var result: Dictionary = {}
for property in properties:
result[property.to_string()] = property.get_value()
result.make_read_only()
Expand Down
15 changes: 15 additions & 0 deletions addons/netfox/rollback/network-rollback.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ var history_limit: int:
set(v):
push_error("Trying to set read-only variable history_limit")

var serialized_states_history_limit: int:
get:
return ProjectSettings.get_setting("netfox/rollback/serialized_states_history_limit", 24)
set(v):
push_error("Trying to set read-only variable serialized_states_history_limit")

var serialized_inputs_history_limit: int:
get:
return ProjectSettings.get_setting("netfox/rollback/serialized_inputs_history_limit", 24)
set(v):
push_error("Trying to set read-only variable serialized_inputs_history_limit")
## Offset into the past for display.
##
## After the rollback, we have the option to not display the absolute latest
Expand Down Expand Up @@ -48,6 +59,10 @@ var tick: int:
set(v):
push_error("Trying to set read-only variable tick")

var enable_input_serialization: bool = ProjectSettings.get_setting("netfox/serialization/enable_input_serialization", true)
var enable_state_serialization: bool = ProjectSettings.get_setting("netfox/serialization/enable_state_serialization", true)
var enable_state_diffs: bool = ProjectSettings.get_setting("netfox/serialization/enable_state_diffs", true)

## Event emitted before running the network rollback loop
signal before_loop()

Expand Down
Loading