Make write routines take ints, floats and shorts by value not by address
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 1 Nov 2010 13:40:12 +0000 (13:40 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 1 Nov 2010 13:40:12 +0000 (13:40 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3342 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/demo.c
ball/game_server.c
share/binary.c
share/binary.h
share/cmd.c
share/solid.c

index 05c887c..c4931ff 100644 (file)
@@ -109,12 +109,12 @@ static void demo_header_write(fs_file fp, struct demo *d)
 
     strftime(datestr, DATELEN, "%Y-%m-%dT%H:%M:%S", gmtime(&d->date));
 
-    put_index(fp, &magic);
-    put_index(fp, &version);
-    put_index(fp, &zero);
-    put_index(fp, &zero);
-    put_index(fp, &zero);
-    put_index(fp, &d->mode);
+    put_index(fp, magic);
+    put_index(fp, version);
+    put_index(fp, zero);
+    put_index(fp, zero);
+    put_index(fp, zero);
+    put_index(fp, d->mode);
 
     put_string(fp, d->player);
     put_string(fp, datestr);
@@ -122,12 +122,12 @@ static void demo_header_write(fs_file fp, struct demo *d)
     put_string(fp, d->shot);
     put_string(fp, d->file);
 
-    put_index(fp, &d->time);
-    put_index(fp, &d->goal);
-    put_index(fp, &d->goal_e);
-    put_index(fp, &d->score);
-    put_index(fp, &d->balls);
-    put_index(fp, &d->times);
+    put_index(fp, d->time);
+    put_index(fp, d->goal);
+    put_index(fp, d->goal_e);
+    put_index(fp, d->score);
+    put_index(fp, d->balls);
+    put_index(fp, d->times);
 }
 
 /*---------------------------------------------------------------------------*/
@@ -316,9 +316,9 @@ void demo_play_stat(int status, int coins, int timer)
 
         fs_seek(demo_fp, 8, SEEK_SET);
 
-        put_index(demo_fp, &timer);
-        put_index(demo_fp, &coins);
-        put_index(demo_fp, &status);
+        put_index(demo_fp, timer);
+        put_index(demo_fp, coins);
+        put_index(demo_fp, status);
 
         fs_seek(demo_fp, pos, SEEK_SET);
     }
index 18a8f58..cd6824d 100644 (file)
@@ -148,10 +148,10 @@ int input_put(fs_file fout)
 {
     if (server_state)
     {
-        put_short(fout, &input_current.x);
-        put_short(fout, &input_current.z);
-        put_short(fout, &input_current.r);
-        put_short(fout, &input_current.c);
+        put_short(fout, input_current.x);
+        put_short(fout, input_current.z);
+        put_short(fout, input_current.r);
+        put_short(fout, input_current.c);
 
         return 1;
     }
index 4093d3b..871c98a 100644 (file)
@@ -22,9 +22,9 @@
 
 /*---------------------------------------------------------------------------*/
 
-void put_float(fs_file fout, const float *f)
+void put_float(fs_file fout, float f)
 {
-    const unsigned char *p = (const unsigned char *) f;
+    unsigned char *p = (unsigned char *) &f;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
     fs_putc((int) p[3], fout);
@@ -39,9 +39,9 @@ void put_float(fs_file fout, const float *f)
 #endif
 }
 
-void put_index(fs_file fout, const int *i)
+void put_index(fs_file fout, int i)
 {
-    const unsigned char *p = (const unsigned char *) i;
+    unsigned char *p = (unsigned char *) &i;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
     fs_putc((int) p[3], fout);
@@ -56,9 +56,9 @@ void put_index(fs_file fout, const int *i)
 #endif
 }
 
-void put_short(fs_file fout, const short *s)
+void put_short(fs_file fout, short s)
 {
-    const unsigned char *p = (const unsigned char *) s;
+    unsigned char *p = (unsigned char *) &s;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
     fs_putc((int) p[1], fout);
@@ -74,7 +74,7 @@ void put_array(fs_file fout, const float *v, size_t n)
     size_t i;
 
     for (i = 0; i < n; i++)
-        put_float(fout, v + i);
+        put_float(fout, v[i]);
 }
 
 /*---------------------------------------------------------------------------*/
index fc0c0d5..436547a 100644 (file)
@@ -15,9 +15,9 @@
 #define ARRAY_BYTES(n)  (FLOAT_BYTES * (n))
 #define STRING_BYTES(s) (strlen(s) + 1)
 
-void put_float(fs_file, const float *);
-void put_index(fs_file, const int   *);
-void put_short(fs_file, const short *);
+void put_float(fs_file, float);
+void put_index(fs_file, int);
+void put_short(fs_file, short);
 void put_array(fs_file, const float *, size_t);
 
 void get_float(fs_file, float *);
index c97604c..3e036e6 100644 (file)
@@ -50,7 +50,7 @@ static int cmd_stats = 0;
     short cmd_bytes = BYTES;                                            \
                                                                         \
     /* Write command size info (right after the command type). */       \
-    put_short(fp, &cmd_bytes);                                          \
+    put_short(fp, cmd_bytes);                                           \
                                                                         \
     /* Start the stats output. */                                       \
     if (cmd_stats) printf("put");                                       \
@@ -96,8 +96,8 @@ GET_FUNC(CMD_MAKE_BALL) { } END_FUNC;
 PUT_FUNC(CMD_MAKE_ITEM)
 {
     put_array(fp, cmd->mkitem.p, 3);
-    put_index(fp, &cmd->mkitem.t);
-    put_index(fp, &cmd->mkitem.n);
+    put_index(fp, cmd->mkitem.t);
+    put_index(fp, cmd->mkitem.n);
 }
 END_FUNC;
 
@@ -116,7 +116,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_PICK_ITEM)
 {
-    put_index(fp, &cmd->pkitem.hi);
+    put_index(fp, cmd->pkitem.hi);
 }
 END_FUNC;
 
@@ -133,8 +133,8 @@ END_FUNC;
 
 PUT_FUNC(CMD_TILT_ANGLES)
 {
-    put_float(fp, &cmd->tiltangles.x);
-    put_float(fp, &cmd->tiltangles.z);
+    put_float(fp, cmd->tiltangles.x);
+    put_float(fp, cmd->tiltangles.z);
 }
 END_FUNC;
 
@@ -153,7 +153,7 @@ END_FUNC;
 PUT_FUNC(CMD_SOUND)
 {
     put_string(fp, cmd->sound.n);
-    put_float(fp, &cmd->sound.a);
+    put_float(fp, cmd->sound.a);
 }
 END_FUNC;
 
@@ -175,7 +175,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_TIMER)
 {
-    put_float(fp, &cmd->timer.t);
+    put_float(fp, cmd->timer.t);
 }
 END_FUNC;
 
@@ -192,7 +192,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_STATUS)
 {
-    put_index(fp, &cmd->status.t);
+    put_index(fp, cmd->status.t);
 }
 END_FUNC;
 
@@ -209,7 +209,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_COINS)
 {
-    put_index(fp, &cmd->coins.n);
+    put_index(fp, cmd->coins.n);
 }
 END_FUNC;
 
@@ -242,8 +242,8 @@ GET_FUNC(CMD_JUMP_EXIT) { } END_FUNC;
 
 PUT_FUNC(CMD_BODY_PATH)
 {
-    put_index(fp, &cmd->bodypath.bi);
-    put_index(fp, &cmd->bodypath.pi);
+    put_index(fp, cmd->bodypath.bi);
+    put_index(fp, cmd->bodypath.pi);
 }
 END_FUNC;
 
@@ -261,8 +261,8 @@ END_FUNC;
 
 PUT_FUNC(CMD_BODY_TIME)
 {
-    put_index(fp, &cmd->bodytime.bi);
-    put_float(fp, &cmd->bodytime.t);
+    put_index(fp, cmd->bodytime.bi);
+    put_float(fp, cmd->bodytime.t);
 }
 END_FUNC;
 
@@ -288,7 +288,7 @@ GET_FUNC(CMD_GOAL_OPEN) { } END_FUNC;
 
 PUT_FUNC(CMD_SWCH_ENTER)
 {
-    put_index(fp, &cmd->swchenter.xi);
+    put_index(fp, cmd->swchenter.xi);
 }
 END_FUNC;
 
@@ -305,7 +305,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_SWCH_TOGGLE)
 {
-    put_index(fp, &cmd->swchenter.xi);
+    put_index(fp, cmd->swchenter.xi);
 }
 END_FUNC;
 
@@ -322,7 +322,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_SWCH_EXIT)
 {
-    put_index(fp, &cmd->swchenter.xi);
+    put_index(fp, cmd->swchenter.xi);
 }
 END_FUNC;
 
@@ -339,7 +339,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_UPDATES_PER_SECOND)
 {
-    put_index(fp, &cmd->ups.n);
+    put_index(fp, cmd->ups.n);
 }
 END_FUNC;
 
@@ -356,7 +356,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_BALL_RADIUS)
 {
-    put_float(fp, &cmd->ballradius.r);
+    put_float(fp, cmd->ballradius.r);
 }
 END_FUNC;
 
@@ -497,7 +497,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_CURRENT_BALL)
 {
-    put_index(fp, &cmd->currball.ui);
+    put_index(fp, cmd->currball.ui);
 }
 END_FUNC;
 
@@ -514,8 +514,8 @@ END_FUNC;
 
 PUT_FUNC(CMD_PATH_FLAG)
 {
-    put_index(fp, &cmd->pathflag.pi);
-    put_index(fp, &cmd->pathflag.f);
+    put_index(fp, cmd->pathflag.pi);
+    put_index(fp, cmd->pathflag.f);
 }
 END_FUNC;
 
@@ -533,7 +533,7 @@ END_FUNC;
 
 PUT_FUNC(CMD_STEP_SIMULATION)
 {
-    put_float(fp, &cmd->stepsim.dt);
+    put_float(fp, cmd->stepsim.dt);
 }
 END_FUNC;
 
@@ -552,8 +552,8 @@ PUT_FUNC(CMD_MAP)
 {
     put_string(fp, cmd->map.name);
 
-    put_index(fp, &cmd->map.version.x);
-    put_index(fp, &cmd->map.version.y);
+    put_index(fp, cmd->map.version.x);
+    put_index(fp, cmd->map.version.y);
 }
 END_FUNC;
 
index cd2254d..4285b3f 100644 (file)
@@ -383,12 +383,12 @@ int sol_load_only_head(struct s_file *fp, const char *filename)
 
 static void sol_stor_mtrl(fs_file fout, struct s_mtrl *mp)
 {
-    put_array(fout,  mp->d, 4);
-    put_array(fout,  mp->a, 4);
-    put_array(fout,  mp->s, 4);
-    put_array(fout,  mp->e, 4);
-    put_array(fout,  mp->h, 1);
-    put_index(fout, &mp->fl);
+    put_array(fout, mp->d, 4);
+    put_array(fout, mp->a, 4);
+    put_array(fout, mp->s, 4);
+    put_array(fout, mp->e, 4);
+    put_array(fout, mp->h, 1);
+    put_index(fout, mp->fl);
 
     fs_write(mp->f, 1, PATHMAX, fout);
 }
@@ -400,14 +400,14 @@ static void sol_stor_vert(fs_file fout, struct s_vert *vp)
 
 static void sol_stor_edge(fs_file fout, struct s_edge *ep)
 {
-    put_index(fout, &ep->vi);
-    put_index(fout, &ep->vj);
+    put_index(fout, ep->vi);
+    put_index(fout, ep->vj);
 }
 
 static void sol_stor_side(fs_file fout, struct s_side *sp)
 {
-    put_array(fout,  sp->n, 3);
-    put_float(fout, &sp->d);
+    put_array(fout, sp->n, 3);
+    put_float(fout, sp->d);
 }
 
 static void sol_stor_texc(fs_file fout, struct s_texc *tp)
@@ -417,48 +417,48 @@ static void sol_stor_texc(fs_file fout, struct s_texc *tp)
 
 static void sol_stor_geom(fs_file fout, struct s_geom *gp)
 {
-    put_index(fout, &gp->mi);
-    put_index(fout, &gp->ti);
-    put_index(fout, &gp->si);
-    put_index(fout, &gp->vi);
-    put_index(fout, &gp->tj);
-    put_index(fout, &gp->sj);
-    put_index(fout, &gp->vj);
-    put_index(fout, &gp->tk);
-    put_index(fout, &gp->sk);
-    put_index(fout, &gp->vk);
+    put_index(fout, gp->mi);
+    put_index(fout, gp->ti);
+    put_index(fout, gp->si);
+    put_index(fout, gp->vi);
+    put_index(fout, gp->tj);
+    put_index(fout, gp->sj);
+    put_index(fout, gp->vj);
+    put_index(fout, gp->tk);
+    put_index(fout, gp->sk);
+    put_index(fout, gp->vk);
 }
 
 static void sol_stor_lump(fs_file fout, struct s_lump *lp)
 {
-    put_index(fout, &lp->fl);
-    put_index(fout, &lp->v0);
-    put_index(fout, &lp->vc);
-    put_index(fout, &lp->e0);
-    put_index(fout, &lp->ec);
-    put_index(fout, &lp->g0);
-    put_index(fout, &lp->gc);
-    put_index(fout, &lp->s0);
-    put_index(fout, &lp->sc);
+    put_index(fout, lp->fl);
+    put_index(fout, lp->v0);
+    put_index(fout, lp->vc);
+    put_index(fout, lp->e0);
+    put_index(fout, lp->ec);
+    put_index(fout, lp->g0);
+    put_index(fout, lp->gc);
+    put_index(fout, lp->s0);
+    put_index(fout, lp->sc);
 }
 
 static void sol_stor_node(fs_file fout, struct s_node *np)
 {
-    put_index(fout, &np->si);
-    put_index(fout, &np->ni);
-    put_index(fout, &np->nj);
-    put_index(fout, &np->l0);
-    put_index(fout, &np->lc);
+    put_index(fout, np->si);
+    put_index(fout, np->ni);
+    put_index(fout, np->nj);
+    put_index(fout, np->l0);
+    put_index(fout, np->lc);
 }
 
 static void sol_stor_path(fs_file fout, struct s_path *pp)
 {
-    put_array(fout,  pp->p, 3);
-    put_float(fout, &pp->t);
-    put_index(fout, &pp->pi);
-    put_index(fout, &pp->f);
-    put_index(fout, &pp->s);
-    put_index(fout, &pp->fl);
+    put_array(fout, pp->p, 3);
+    put_float(fout, pp->t);
+    put_index(fout, pp->pi);
+    put_index(fout, pp->f);
+    put_index(fout, pp->s);
+    put_index(fout, pp->fl);
 
     if (pp->fl & P_ORIENTED)
         put_array(fout, pp->e, 4);
@@ -466,64 +466,64 @@ static void sol_stor_path(fs_file fout, struct s_path *pp)
 
 static void sol_stor_body(fs_file fout, struct s_body *bp)
 {
-    put_index(fout, &bp->pi);
-    put_index(fout, &bp->ni);
-    put_index(fout, &bp->l0);
-    put_index(fout, &bp->lc);
-    put_index(fout, &bp->g0);
-    put_index(fout, &bp->gc);
+    put_index(fout, bp->pi);
+    put_index(fout, bp->ni);
+    put_index(fout, bp->l0);
+    put_index(fout, bp->lc);
+    put_index(fout, bp->g0);
+    put_index(fout, bp->gc);
 }
 
 static void sol_stor_item(fs_file fout, struct s_item *hp)
 {
-    put_array(fout,  hp->p, 3);
-    put_index(fout, &hp->t);
-    put_index(fout, &hp->n);
+    put_array(fout, hp->p, 3);
+    put_index(fout, hp->t);
+    put_index(fout, hp->n);
 }
 
 static void sol_stor_goal(fs_file fout, struct s_goal *zp)
 {
-    put_array(fout,  zp->p, 3);
-    put_float(fout, &zp->r);
+    put_array(fout, zp->p, 3);
+    put_float(fout, zp->r);
 }
 
 static void sol_stor_swch(fs_file fout, struct s_swch *xp)
 {
-    put_array(fout,  xp->p, 3);
-    put_float(fout, &xp->r);
-    put_index(fout, &xp->pi);
-    put_float(fout, &xp->t0);
-    put_float(fout, &xp->t);
-    put_index(fout, &xp->f0);
-    put_index(fout, &xp->f);
-    put_index(fout, &xp->i);
+    put_array(fout, xp->p, 3);
+    put_float(fout, xp->r);
+    put_index(fout, xp->pi);
+    put_float(fout, xp->t0);
+    put_float(fout, xp->t);
+    put_index(fout, xp->f0);
+    put_index(fout, xp->f);
+    put_index(fout, xp->i);
 }
 
 static void sol_stor_bill(fs_file fout, struct s_bill *rp)
 {
-    put_index(fout, &rp->fl);
-    put_index(fout, &rp->mi);
-    put_float(fout, &rp->t);
-    put_float(fout, &rp->d);
-    put_array(fout,  rp->w,  3);
-    put_array(fout,  rp->h,  3);
-    put_array(fout,  rp->rx, 3);
-    put_array(fout,  rp->ry, 3);
-    put_array(fout,  rp->rz, 3);
-    put_array(fout,  rp->p,  3);
+    put_index(fout, rp->fl);
+    put_index(fout, rp->mi);
+    put_float(fout, rp->t);
+    put_float(fout, rp->d);
+    put_array(fout, rp->w,  3);
+    put_array(fout, rp->h,  3);
+    put_array(fout, rp->rx, 3);
+    put_array(fout, rp->ry, 3);
+    put_array(fout, rp->rz, 3);
+    put_array(fout, rp->p,  3);
 }
 
 static void sol_stor_jump(fs_file fout, struct s_jump *jp)
 {
-    put_array(fout,  jp->p, 3);
-    put_array(fout,  jp->q, 3);
-    put_float(fout, &jp->r);
+    put_array(fout, jp->p, 3);
+    put_array(fout, jp->q, 3);
+    put_float(fout, jp->r);
 }
 
 static void sol_stor_ball(fs_file fout, struct s_ball *bp)
 {
-    put_array(fout,  bp->p, 3);
-    put_float(fout, &bp->r);
+    put_array(fout, bp->p, 3);
+    put_float(fout, bp->r);
 }
 
 static void sol_stor_view(fs_file fout, struct s_view *wp)
@@ -534,8 +534,8 @@ static void sol_stor_view(fs_file fout, struct s_view *wp)
 
 static void sol_stor_dict(fs_file fout, struct s_dict *dp)
 {
-    put_index(fout, &dp->ai);
-    put_index(fout, &dp->aj);
+    put_index(fout, dp->ai);
+    put_index(fout, dp->aj);
 }
 
 static void sol_stor_file(fs_file fout, struct s_file *fp)
@@ -544,29 +544,29 @@ static void sol_stor_file(fs_file fout, struct s_file *fp)
     int magic   = MAGIC;
     int version = SOL_VER_CURRENT;
 
-    put_index(fout, &magic);
-    put_index(fout, &version);
-
-    put_index(fout, &fp->ac);
-    put_index(fout, &fp->dc);
-    put_index(fout, &fp->mc);
-    put_index(fout, &fp->vc);
-    put_index(fout, &fp->ec);
-    put_index(fout, &fp->sc);
-    put_index(fout, &fp->tc);
-    put_index(fout, &fp->gc);
-    put_index(fout, &fp->lc);
-    put_index(fout, &fp->nc);
-    put_index(fout, &fp->pc);
-    put_index(fout, &fp->bc);
-    put_index(fout, &fp->hc);
-    put_index(fout, &fp->zc);
-    put_index(fout, &fp->jc);
-    put_index(fout, &fp->xc);
-    put_index(fout, &fp->rc);
-    put_index(fout, &fp->uc);
-    put_index(fout, &fp->wc);
-    put_index(fout, &fp->ic);
+    put_index(fout, magic);
+    put_index(fout, version);
+
+    put_index(fout, fp->ac);
+    put_index(fout, fp->dc);
+    put_index(fout, fp->mc);
+    put_index(fout, fp->vc);
+    put_index(fout, fp->ec);
+    put_index(fout, fp->sc);
+    put_index(fout, fp->tc);
+    put_index(fout, fp->gc);
+    put_index(fout, fp->lc);
+    put_index(fout, fp->nc);
+    put_index(fout, fp->pc);
+    put_index(fout, fp->bc);
+    put_index(fout, fp->hc);
+    put_index(fout, fp->zc);
+    put_index(fout, fp->jc);
+    put_index(fout, fp->xc);
+    put_index(fout, fp->rc);
+    put_index(fout, fp->uc);
+    put_index(fout, fp->wc);
+    put_index(fout, fp->ic);
 
     fs_write(fp->av, 1, fp->ac, fout);
 
@@ -588,7 +588,7 @@ static void sol_stor_file(fs_file fout, struct s_file *fp)
     for (i = 0; i < fp->rc; i++) sol_stor_bill(fout, fp->rv + i);
     for (i = 0; i < fp->uc; i++) sol_stor_ball(fout, fp->uv + i);
     for (i = 0; i < fp->wc; i++) sol_stor_view(fout, fp->wv + i);
-    for (i = 0; i < fp->ic; i++) put_index(fout, fp->iv + i);
+    for (i = 0; i < fp->ic; i++) put_index(fout, fp->iv[i]);
 }
 
 /*---------------------------------------------------------------------------*/