[Freeciv-Dev] Re: dynamic timeout (PR#1356)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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)
>
> > 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. 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.
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);
-mike
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Gregory Berkolaiko, 2002/04/01
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Raimar Falke, 2002/04/03
- [Freeciv-Dev] Re: dynamic timeout (PR#1356),
Mike Kaufman <=
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Raimar Falke, 2002/04/07
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Mike Kaufman, 2002/04/07
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Raimar Falke, 2002/04/07
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Mike Kaufman, 2002/04/07
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Raimar Falke, 2002/04/07
- [Freeciv-Dev] Re: dynamic timeout (PR#1356), Raimar Falke, 2002/04/08
|
|