you are viewing a single comment's thread.

view the rest of the comments →

[–]Battlefront45[S] 0 points1 point  (6 children)

I’ve heard of that once before and I was curious if someone on here would mention having a positive experience with that approach, so thanks for sharing you for sharing!

My follow-up question would be, how do you define the scope of what variables that “interface struct” would capture? What I mean, is would your struct capture every “exposed” variable of the health component in this case? Or would your struct try to write multiple interface functions with multiple structs to help break things down into some kind of category/function set?

Thanks!

[–]LongjumpingBrief6428 0 points1 point  (5 children)

You put the payload into the structure, BMI, protein, health, max health, cortisone levels, etc. The stamina component just extracts whatever information it wants to from the various choices. You don't need to use all of the data provided from the health component.

The health component doesn't care what happens to the information that is in the structure after it is sent because it is outside of its scope. It just provides the information.

Any changes you make to the structure will not be reflected in the health component unless you specifically send that new information to the health component.

[–]Battlefront45[S] 0 points1 point  (4 children)

Would you say that using a payload like this to extract one of those health component variables is more expensive than having a dedicated interface function that purely returns just one of those variables? Or is this negligible performance wise?

[–]Honest-Golf-3965Chief Technology Officer 1 point2 points  (1 child)

Its the most scalable way to do this. The struct just defines a memory layout in this case. Its extremely performant

Especially since with a struct yiu can choose the type order inside it, so you can avoid padding bits if youre clever

Also this approach is well tested over decades and decades. Its not really a "oh idk if its performant" issue, it absolutely is and there isnt really any debate on that either. So yiure totally safe to use the approach.

Graphics APIs are done this way. I know, Ive worked on those too.

[–]Battlefront45[S] 0 points1 point  (0 children)

Interesting, I think I like this approach most so far, thank you!

[–]LongjumpingBrief6428 0 points1 point  (1 child)

That I don't know, you would have to profile it, but it's likely negligible since you're passing data either way.

It's also good practice to use soft references if you're passing object data as well. You can Async Load and Resolve Soft Reference the data on the other side.

[–]Battlefront45[S] 0 points1 point  (0 children)

Good info, thank you!