Announcement

Collapse
No announcement yet.

Requesting information from the server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Requesting information from the server

    Hi all!
    I'm new to US, and havn't really got full understanding of replication and what I can do and how yet.
    I have a HUD-class that draws some neat stuff, but as of now it only works offline, since I cant figure out a way of requesting certain information from the server.
    I have an RTS-kinda view with mousepointer and such, and in the HUD I want to ask the server where the mousepointer is in board-coordinates (my game being a boardgame) and if certain actions are allowed on that square. Hence I want to ask the GameInfo/GameReplicationInfo/other class(?) some questions such as "can I move to square 1, 5?" returning a boolean to the HUD so I can draw different stuff depending on what the answers are.

    That is, in PostRender(Canvas c) in HUD, I want to ask the server a question (not being only a variable on the server, but something calculated on request) and draw stuff depending on the answer I get (or the object(s) returned). Is this doable?

    If my question is in anyway unclear, don't hesitate to flame me some so I can express myself better.

    /Joel

    #2
    You are approaching this the wrong way. Replication generally is slow. It may take several ticks to get an answer to something sent to the server. Partially this is caused by the way the level update loop works:
    1. Read received network packets and translate them into actor spawning, property updates and function calls.
    2. Tick all actors (i.e. for each actor: call Tick(), execute state code, update timers and process physics updates)
    3. Render the level
    4. Go back to #1.

    This obviously requires are information to be available before rendering starts. Questions like "Is it possible to move to square X,Y?" must be decided by the client based on information from the server. Of course the server should validate any movement commands issued by the client, but it should provide enough information to the client to accurately display the current state of the game and any options the player has.
    Since you seem to have your own GameReplicationInfo class I suggest using that to provide clients with the necessary details about the game state so all your HUD code needs to do is accessing the GameReplicationInfo via Level.GRI and query the values directly. To do this, you should declare replicated variables and have the server update them whenever a relevant change in the game state occurs.

    Comment


      #3
      Thanks Wormbo. I'm really cought up in other architectures ways of solving things, with how replication works it should have been obvious not to try to ask the server, but instead let the server replicate values appropriate. I'll try to solve it in a US-kind of way now...

      However, I read something about dynamic arrays not being able to be replicated? And normal arrays having a limit to how much data can be replicated? If you are dependant on arrays in different forms, how is this normally solved if you need it replicated?

      Thanks.

      /Joel

      Comment


        #4
        Static arrays replicate perfectly fine, their elements are treated as separate properties by replication logic and may arrive out of order (time of arrival; indices stay intact, of course) at the client. If you want to force the entire array to be replicated at once, put it into a struct. Struct properties are generally replicated as a single unit. The only thing to watch out for is that the entire struct must fit into a single data packet. The same applies to strings.

        Dynamic arrays cannot be replicated, that's correct, but there are several replacement strategies.
        For example you could use a PlayerReplicationInfo and have a series of ping-pong-like replicated function calls send the individual array elements separately to each client. This is done with weapon and vehicle stats data in UT2004.
        If you know the length of the array will never exceed a certain (sane) value, you can simply use a static array with an additional length property.
        Or you use the (complex, but pretty clever) idea Mychaeel applied in Jailbreak to replicate capture times: Have a decently-sized static array that can hold the minimum number of elements you want the client to know about. Then have two properties that mark the number of elements used in the array and the index of the first element. The array is filled starting at index 0 and size 0. As long as the array isn't full, the size variable is incremented for every element stored in the array. Once the array is full, elements are stored starting at index 0 again, but the start variable is set to the next-higher element index. Clients only need to start reading the the designated start index and continue at index 0 if they reach the end of the array.

        Comment


          #5
          Having solved that problem I had, I'm not really sure wether to start a new thread or to make this my personal ImnoobsoIneedsomehelp-thread...

          Anyways, I'm having problems with getting the interaction-class spawn on clients... I think I had it working before, but I have to have done something stupid to make it not work...

          In my PlayerController-class I have added the section suggested on the wiki under PlayerWaiting, begin:
          Code:
          if ((Viewport(Player) != None) && (!bHasInteraction))
                  {
          	        Player.InteractionMaster.AddInteraction("DnD.DnDInteraction", Player);
          	        bHasInteraction = True;
                  }
          The remoteRole is set to ROLE_SimulatedProxy with bAlwaysRelevant = true. Not sure wether this is correct or not, being so new to replication. No interaction is spawned on the client and it feels like I have tried everything... but I'm most probably just overlooking something really stupid...

          I don't know exactly what info you need to give good suggestions to solutions, but I'm happy to provide anything you might muster.

          Thanks

          /Joel

          Comment


            #6
            Problem above solved, in some kind of way... I dont really get why that solution I had read on the wiki didn't work, but now the interactions are up and running.

            I discovered something strange today when I was coding though... I have a few arrays that are 1024 in size, and well, it didn't seem as though they replicated correctly. I had the arrays filled at server, but at client only the first 256 (up to index 255) were actually something, the rest of the values were at 0 (for ints, (0, 0, 0) for vects). I didn't really get why it was like that since ppl have been saying that static arrays are replicated index by index. I split the arrays in to 4 different arrays of 256 entrys each, and it worked perfectly. What could have been wrong?

            PS. replication is really strange and somewhat annoying, but atleast I'm starting to understand how it works and what is wrong if something isn't replicated. DS.

            Comment


              #7
              Replication is almost an art and a religion. I'm hoping some of the rumoured changes in the UE3 code base in regards to replication are going to be the god send they sounded like.

              Comment


                #8
                It's not really all that terrible - the worst part i think is getting everything to run where you want it to run. You need to have a design of how your code is going to work, so that you can analyze it and figure out exactly which parts are needed on the client and which parts aren't, and then it's pretty simple, really.

                Comment

                Working...
                X