Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

Removed inner module from generated code. Implemented component update sending. #66

Merged
merged 18 commits into from
Feb 20, 2019

Conversation

dgavedissian
Copy link
Collaborator

Still doesn't seem to quite work yet. Not sure why.

match op {
WorkerOp::ReserveEntityIdsResponse(response) => {
if let StatusCode::Success(response_data) = response.status_code {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make this failure tolerant pretty easy 😉

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify what you mean here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commands can fail and you can effectively retry the command with a bit of book keeping

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good to know! I ended up removing the logic that depends on the request succeeding (i.e. it now unconditionally creates the entity without first reserving an ID), but I can still add the logic for repeating the request if you'd like 🙂

@@ -358,7 +358,7 @@ impl ProtocolLoggingParameters {
CString::new(self.log_prefix.clone()).expect("Received 0 byte in supplied log prefix.");

Worker_ProtocolLoggingParameters {
log_prefix: log_prefix_cstr.as_ptr(),
log_prefix: "protocol-log-".as_ptr() as _,//log_prefix_cstr.as_ptr(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed offline - we need to change this implementation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Will fix this properly later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed the safety issue here by having ProtocolLoggingParameters own the CString directly. In order to avoid leaking implementation details (i.e. that it's using CString under the hood), I've made all the fields private and added setters. I've also added a note in the doc comment about allowing us to add parameters without breaking changes (similar to CommandParameters), though if that's not appropriate here let me know.

I've also opted to use expect() on the result of the CString conversion instead of returning a Result<_, NulError>. After giving it more thought, I don't think it makes a ton of sense to expose that error directly. While it's technically possible for a Rust string to contain a nul byte in the middle, it's both incredibly unlikely to happen in practice, and it's likely indicative of an error in the user's code.

@randomPoison
Copy link
Collaborator

randomPoison commented Feb 18, 2019

With @davedissian's permission, I've gone ahead and finished up this PR. I've setup the example project to demonstrate component updates by adding a Rotate component that causes the entities to rotate in a circle a specified center point with a specified radius. I've also set this up so that it demonstrates changes in authority, such that a given worker will only try to update entities that it has authority over. The gif below shows entities moving smoothly while moving through the areas of authority of four different workers:

spatialos-rotate

The following gif also shows multiple entities moving in and out of a single worker's area of authority/intersted:

spatialos-rotate-authority

@jamiebrynes7 @davedissian I'm going to give the code another review pass myself, but it should be ready for you to re-review at this point.

@randomPoison randomPoison requested review from randomPoison and removed request for randomPoison February 18, 2019 17:06
Copy link
Owner

@jamiebrynes7 jamiebrynes7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments, but generally LGTM

let component_update = update.get::<example::Rotate>().unwrap();
let state = world.get_mut(&update.entity_id).unwrap();
let rotate = state.rotate.as_mut().unwrap();
rotate.merge(component_update.clone());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the merge method take the update by reference rather than value?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with it taking the update by value. If merge were to take the update object by reference, then it would need to copy the individual fields in order to apply them to the component. Since it ultimately needs the component data by value, it makes more sense to take the update by value, that way the calling code can determine if the value needs to be cloned. This seems to be the more common convention in Rust (i.e. let the calling code decide whether or not the clone the data).

@randomPoison randomPoison merged commit f027d0e into master Feb 20, 2019
@randomPoison randomPoison deleted the generated-code-2 branch February 20, 2019 02:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants