> > You should probably regularly poll the server to determine the end of
> > turn time and base yourself on that. I have the following code:
> >
> > connection.turnfinished()
> > waitfor = connection.time()
> > while waitfor > 1:
> >    time.sleep(1)
> >    waitfor = connection.time()
> > time.sleep(2)
> >
> > The problem is that the end-of-turn time can be changed while you are
> > waiting for it, so you have to poll the server to see if your value is
> > still up to date. My code seems to work pretty fine for the job.
> 
> Hm, so you're waiting for 2 milliseconds after the turn has finished,
> to commence your own "start of turn" sequence? I did that, too, at
> first, but my mentor alerted me to the problem that the server may
> choose any length of time between end of turn, and start of new turn.
> If it's longer than 2ms (or 2 secs), the code will no longer work. You
> can do a sequence of 2 loops: one waits for connection.time() = 0,

The above code is 2 seconds.

> then goes to another, that waits for connection.time() > 0, which is
> the start of the next turn. Or else, what I did, is have the Visitor
> push a "turn start" flag in the client, and then set up a loop which
> waits for the value there to change.

You probably don't want to loop like that for a number of reasons,
 1. You could miss the turn change.
 2. It's unreliable.
 3. It's consuming extra resources.

The servers will send you an asyncronous frame when turn generation
occurs (or when the turn length changes). On the java library I have no
idea how to find this frame, but in Python you do something like this,

while <condition>:
        self.connection.pump()

        pending = self.connection.buffered['frames-async']
        while len(pending) > 0:
                if not isinstance(pending[0], tpobjects.TimeRemaining):
                        break
                frame = pending.pop(0)
                if frame.time == 0:
                        # Turn generation just occurred..
                else:
                        # EOT time changed...

        # You only need the sleep if you are in non-blocking mode
        time.sleep(1)

Hope that helps.

Tim 'Mithro' Ansell


_______________________________________________
tp-devel mailing list
[email protected]
http://www.thousandparsec.net/tp/mailman.php/listinfo/tp-devel

Reply via email to