Author Topic: Networked Game Structure  (Read 3325 times)

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Networked Game Structure
« on: May 13, 2014, 08:03:22 PM »
Hi Aren,

I currently have a game which has a structure like this: (classes in bold)

- Each connected player has control of a Planet
- Each planet contains 12+ BuildingSlot gameobjects, each of which can contain a building of any type.
-- Player can trigger construction of Building gameobjects in these slots (Building is subclassed by many unique building types)
-- These buildings have their own unique properties to sync (e.g.: reload time for weapons), as well properties common to each (health, construction progress, etc)
-- Buildings may be destroyed by the actions of other players

I currently have it set up so the Planet, BuildingSlot and Building all have their own TNObject, to prevent all the building logic taking place in the root Planet object.

I've read around some previous topics in this board and it looks like you recommend against having nested TNObjects, I'm wondering how you would recommend structuring a system like this in that case. I'd like to avoid bundling all my building logic and communication in one place if possible.

Any advice would be appreciated.

Thanks!

djray2k

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 4
  • Posts: 74
  • Blockey Hockey!
    • View Profile
    • Walking Talking Grilling Bear Studios
Re: Networked Game Structure
« Reply #1 on: May 13, 2014, 09:22:36 PM »
My opinion (as I always preface since I'm no expert) would be to just have the Planets (or player) maintain TNObjects.

Any kind of upgrade could be easily called all within the same TNObject. If you needed to update the amount of Buildingslots, update when a building is created, update the status of a building, all these things could work with one TNObject.

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Networked Game Structure
« Reply #2 on: May 14, 2014, 05:27:13 AM »
I can definitely see it working with a single TNObject on the root Planet. It just seems... wrong to put all the logic in once place like that. I'm not very experienced with networking, so maybe that's just how it has to be done.


Misc. question: Are reliable (TCP) messages executed in the exact same order on every client?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Networked Game Structure
« Reply #3 on: May 14, 2014, 07:15:09 AM »
You can use many TNObjects if it's easier for you. It's not a good idea to instantiate TNObjects frequently (think: bullets), but if you want to have many TNObjects in the scene, you can. For objects that simply exist in the scene it's really up to whatever is more convenient in your case.

Yes, main traffic is always received in the same order it gets sent.

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Networked Game Structure
« Reply #4 on: May 14, 2014, 07:31:10 AM »
Are there any complications I should expect when using nested TNObjects? I've browsed through the code for TNObject, and it looks like there is quite a bit of parenting logic in there. RFC calls seem to seek out methods in all MonoBehaviours that are in child gameobjects, not just the ones attached to the same object as the TNObject behaviour.

EDIT: Another question: Should RFC ids be unique across all objects, or unique within an object? IE can I have Class1 with a method with RFC ID 1, and Class2 also having a method with ID 1 and not have any problems?
« Last Edit: May 14, 2014, 11:32:57 AM by Simie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Networked Game Structure
« Reply #5 on: May 15, 2014, 12:24:28 AM »
It's not a good idea to nest TNObjects in dynamically instantiated prefabs, but you can nest them freely in a static object (read: object that's not instantiated via TNManager.Create). The reason for that is that when you do TNManager.Create, it will generate a single TNet ID for your prefab, not multiple. There is no concept of hierarchy on the server, so when you destroy a TNObject, it doesn't go searching for its children.

RFC IDs should only be unique per-TNObject. Meaning each TNObject can have up to 255 specific RFC IDs. If you need more than that for some reason, just stick to unique function names (though can't imagine why you would).

I personally use function names everywhere except functions that are sent more than a few times per second.

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Networked Game Structure
« Reply #6 on: May 15, 2014, 09:48:29 AM »
If I were to create an object via TNManager.Create, then another by TNManager.Create, and parent the second object to the first, would that cause problems? I've got them parented so the planet moving will move all the buildings attached to it. I could move them out and update the positions in Update() if you think parenting would be a bad idea.


Another misc question: Any reason why System.Double isn't one of the default supported types for RFC parameters? Took me a while to track down why an RFC call was failing (the error wasn't particularly helpful... actually, the error was fine, I don't know why I didn't realise sooner) until I found that double's don't serialize correctly.
« Last Edit: May 15, 2014, 10:00:17 AM by Simie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Networked Game Structure
« Reply #7 on: May 15, 2014, 12:09:38 PM »
Depends... will one of them be destroyed at any point? If you happen to destroy the parent, then the child will be gone too -- something TNServer won't know about. If they won't be destroyed, then it should be safe enough.

TNet 1.9.0b supports serialization of just about everything, including doubles. What version are you on?

Simie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Networked Game Structure
« Reply #8 on: May 15, 2014, 01:18:56 PM »
The parent objects won't be destroyed, so it should be fine then. Thanks.

I'm on 1.9.0b. I had to add System.Double to TNSerializer.cs (in WriteObject(), GetType(int) and GetPrefix(Type))


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Networked Game Structure
« Reply #9 on: May 16, 2014, 03:09:41 PM »
Curious. Well, I'll add it.