Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2002:
[Freeciv-Dev] Re: dynamic timeout (PR#1356)
Home

[Freeciv-Dev] Re: dynamic timeout (PR#1356)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Mike Kaufman <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: dynamic timeout (PR#1356)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 3 Apr 2002 22:55:44 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Wed, Apr 03, 2002 at 01:05:37PM -0600, Mike Kaufman wrote:
> On Wed, Apr 03, 2002 at 08:39:25PM +0200, Raimar Falke wrote:
> > On Sat, Mar 30, 2002 at 09:25:43PM -0800, Mike Kaufman wrote:
> > > With help from Per, here is the next go around of the magically
> > > increasing timer. How it works:
> > > 
> > > set timeout <timeout>
> > > 
> > > people should hopefully be familiar with that part. The new part:
> > > 
> > > timeoutincrease <turn> <turninc> <value> <valuemult>
> > 
> > > Description:
> > >   Every <turn> turns, add <value> to timeout timer, 
> > >   then add <turninc> to <turn> and multiply <value> 
> > >   by <valuemult>.
> > 
> > Can you also post a formula?
> 
> no. the best formula is in update_timeout in gamehand.c
> this description is probably the most concise rendering of the algorithm
> (good job Per)

number of times the values were updated = k(turn) =
 -0.25 + sqrt((game.timeoutint^2)/(game.timeoutintinc^2) + 
(2*turn-game.timeoutint)/game.timeoutintinc + 0.25)

timeout(k) = game.timeout + game.timeoutinc * (game.timeoutincmult^k - 
1)/(game.timeoutincmult - 1)

All game.* values are the initial ones.

> > > sound complicated? yes it is, but with about a minute of thought you'll
> > > see how powerful and flexible it is.
> > > 
> > > I'm not terribly good at parsing text, so please try it out and try to
> > > break it.
> > 
> > > +/**************************************************************************
> > > +  Set timeout options.
> > > +**************************************************************************/
> > > +static void timeout_command(struct connection *caller, char *str) 
> > > +{
> > > +  char buf[MAX_LEN_CONSOLE_LINE];
> > > +  char *bptr = buf, *arg[4] = {NULL, NULL, NULL, NULL};
> > > +  int i = 0, noargs = 0, val[4];
> > > +  int *timeouts[4];
> > > +
> > > +  timeouts[0] = &game.timeoutint;
> > > +  timeouts[1] = &game.timeoutintinc;
> > > +  timeouts[2] = &game.timeoutinc;
> > > +  timeouts[3] = &game.timeoutincmult;
> > > +
> > > +  assert(str != NULL);
> > > +
> > > +  sz_strlcpy(buf, str);
> > > +  remove_trailing_spaces(buf);
> > 
> > > +  while(*bptr != '\0' && i < 4) {
> > > +    /* skip intervening whitespace */
> > > +    while(*bptr == ' ' || *bptr == '\t') {
> > > +      bptr++;
> > > +    }
> > > +
> > > +    arg[i++] = bptr;
> > > +
> > > +    /* skip arg */
> > > +    while(*bptr != ' ' && *bptr != '\t' && *bptr != '\0') {
> > > +      bptr++;
> > > +    }
> > > +
> > > +    if (*bptr == '\0') {
> > > +      break;
> > > +    } else {
> > > +      *(bptr++) = '\0';
> > > +    }
> > > +  }
> > 
> > This could be replaced with strtok. This may also a good time to
> > introduce a split method.

> Per wrote the original, and is firmly against using strtok.

Why? 

> Also, it seems strtok won't catch both tabs and spaces, so the
> string would have to run though a routine to change tabs to spaces
> first anyway. this is probably just as short.

No. You can specify more than one delimeter char.

> considering that we may have more options/commands eventually that require
> multiple arguments, a split function probably wouldn't be such a bad
> idea...
> 
> something like:
> 
> split(char *str_to_split, char **args, int num_args);

See the archives for the bloody details about what the signature
should look like.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Last year, out in California, at a PC users group, there was a demo of
  smart speech recognition software. Before the demonstrator could begin
  his demo, a voice called out from the audience: "Format c, return. Yes,
  return." Damned short demo, it was.


[Prev in Thread] Current Thread [Next in Thread]