]> git.pond.sub.org Git - empserver/commitdiff
subs: Simplify MOB_ACCESS mobility update
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 20 Jun 2016 18:13:32 +0000 (20:13 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:08:30 +0000 (20:08 +0200)
The do_upd_checking recursion guard is superfluous: do_mob_sect()
doesn't call anything.  Has been that way since MOB_ACCESS was added
in Empire 3.

Inline the remaining code of sct_do_upd_mob(), shp_do_upd_mob(),
pln_do_upd_mob(), lnd_do_upd_mob() in their only callers
sct_postread(), shp_postread(), pln_postread(), lnd_postread().
Rename do_mob_sect(), do_mob_ship(), do_mob_plane(), do_mob_land() to
mob_sect, mob_ship(), mob_plane(), mob_land() and give them external
linkage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/update.h
src/lib/subs/land.c
src/lib/subs/plane.c
src/lib/subs/sect.c
src/lib/subs/ship.c
src/lib/update/mobility.c

index b1d743403f3d60c979d917b9d136da693302f178..7a159f4ed36786cd206655628c61ebac6e60986e 100644 (file)
@@ -104,10 +104,10 @@ extern void prod_land(int, int, struct bp *, int);
 extern int get_materials(struct sctstr *, short[], int);
 /* mobility.c */
 extern void mob_inc_all(int);
-extern void sct_do_upd_mob(struct sctstr *sp);
-extern void shp_do_upd_mob(struct shpstr *sp);
-extern void lnd_do_upd_mob(struct lndstr *lp);
-extern void pln_do_upd_mob(struct plnstr *pp);
+extern void mob_inc_sect(struct sctstr *, int);
+extern void mob_inc_ship(struct shpstr *, int);
+extern void mob_inc_plane(struct plnstr *, int);
+extern void mob_inc_land(struct lndstr *, int);
 extern void mob_access_all(void);
 /* move_sat.c */
 extern void move_sat(struct plnstr *);
index 102786272ef13c3763b5ff59a0a3c72e9c6087eb..4d18700691fa26c8f02b9a37472e61e4f9fe7c8d 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Steve McClure, 1996
- *     Markus Armbruster, 2004-2011
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -40,6 +40,7 @@
 #include "optlist.h"
 #include "player.h"
 #include "prototypes.h"
+#include "server.h"
 #include "unit.h"
 #include "update.h"
 
@@ -54,9 +55,10 @@ lnd_postread(int n, void *ptr)
        memset(lp, 0, sizeof(struct lndstr));
     }
 
-    if (opt_MOB_ACCESS)
-       lnd_do_upd_mob(lp);
     player->owner = (player->god || lp->lnd_own == player->cnum);
+
+    if (opt_MOB_ACCESS && lp->lnd_own && !update_running)
+       mob_inc_land(lp, game_tick_to_now(&lp->lnd_access));
 }
 
 void
index a39560a21a9a1a0783583a37e87b0734c008596f..1c28368ff694c341f2449e8f9eab021a4b452c43 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006-2011
+ *     Markus Armbruster, 2006-2016
  */
 
 #include <config.h>
@@ -41,6 +41,7 @@
 #include "plane.h"
 #include "player.h"
 #include "prototypes.h"
+#include "server.h"
 #include "unit.h"
 #include "update.h"
 
@@ -54,9 +55,11 @@ pln_postread(int n, void *ptr)
                 pp->pln_uid, n);
        memset(pp, 0, sizeof(struct plnstr));
     }
+
     player->owner = (player->god || pp->pln_own == player->cnum);
-    if (opt_MOB_ACCESS)
-       pln_do_upd_mob(pp);
+
+    if (opt_MOB_ACCESS && pp->pln_own && !update_running)
+       mob_inc_plane(pp, game_tick_to_now(&pp->pln_access));
 }
 
 void
index 55e6c9e37011bd81ce5d536a9b5c55c3fb5eba69..a53ee52b6d1ab69f874d8774a4ede113c4acb2e2 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <ctype.h>
 #include "file.h"
+#include "game.h"
 #include "lost.h"
 #include "misc.h"
 #include "nsc.h"
@@ -43,6 +44,7 @@
 #include "player.h"
 #include "prototypes.h"
 #include "sect.h"
+#include "server.h"
 #include "update.h"
 #include "xy.h"
 
@@ -52,8 +54,10 @@ sct_postread(int id, void *ptr)
     struct sctstr *sp = ptr;
 
     player->owner = (player->god || sp->sct_own == player->cnum);
-    if (opt_MOB_ACCESS)
-       sct_do_upd_mob(sp);
+
+    if (opt_MOB_ACCESS && sp->sct_own && sp->sct_type != SCT_SANCT
+       && !update_running)
+       mob_inc_sect(sp, game_tick_to_now(&sp->sct_access));
 }
 
 void
index f3f6a04d9a176476f0c1b2ca853de248d66185ed..3c75e84c9ec6936794e9ba8a3ea0fd060412a4d8 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 1996
- *     Markus Armbruster, 2004-2011
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -40,6 +40,7 @@
 #include "optlist.h"
 #include "player.h"
 #include "prototypes.h"
+#include "server.h"
 #include "ship.h"
 #include "unit.h"
 #include "update.h"
@@ -55,9 +56,10 @@ shp_postread(int n, void *ptr)
        memset(sp, 0, sizeof(struct shpstr));
     }
 
-    if (opt_MOB_ACCESS)
-       shp_do_upd_mob(sp);
     player->owner = (player->god || sp->shp_own == player->cnum);
+
+    if (opt_MOB_ACCESS & sp->shp_own && !update_running)
+       mob_inc_ship(sp, game_tick_to_now(&sp->shp_access));
 }
 
 void
index f4626f404730823fedeb0fdfd152fef5e24ae7ae..e77fe4b4a46eea2b20241c3dcb5c6e51516e0036 100644 (file)
 #include "optlist.h"
 #include "plane.h"
 #include "sect.h"
-#include "server.h"
 #include "ship.h"
 #include "update.h"
 
-static int do_upd_checking;
-
-static void do_mob_land(struct lndstr *, int);
-static void do_mob_plane(struct plnstr *, int);
-static void do_mob_sect(struct sctstr *sp, int etus);
-static void do_mob_ship(struct shpstr *, int);
-
-void
-sct_do_upd_mob(struct sctstr *sp)
-{
-    int etus;
-
-    if (do_upd_checking || update_running)
-       return;
-    if (sp->sct_own == 0)
-       return;
-    if (sp->sct_type == SCT_SANCT)
-       return;
-    etus = game_tick_to_now(&sp->sct_access);
-    if (etus == 0)
-       return;
-
-    do_upd_checking = 1;       /* avoid recursion */
-    do_mob_sect(sp, etus);
-    do_upd_checking = 0;
-}
-
-void
-shp_do_upd_mob(struct shpstr *sp)
-{
-    int etus;
-
-    if (do_upd_checking || update_running)
-       return;
-    if (sp->shp_own == 0)
-       return;
-    etus = game_tick_to_now(&sp->shp_access);
-    if (etus == 0)
-       return;
-
-    do_upd_checking = 1;       /* avoid recursion */
-    do_mob_ship(sp, etus);
-    do_upd_checking = 0;
-}
-
-void
-lnd_do_upd_mob(struct lndstr *lp)
-{
-    int etus;
-
-    if (do_upd_checking || update_running)
-       return;
-    if (lp->lnd_own == 0)
-       return;
-    etus = game_tick_to_now(&lp->lnd_access);
-    if (etus == 0)
-       return;
-
-    do_upd_checking = 1;       /* avoid recursion */
-    do_mob_land(lp, etus);
-    do_upd_checking = 0;
-}
-
-void
-pln_do_upd_mob(struct plnstr *pp)
-{
-    int etus;
-
-    if (do_upd_checking || update_running)
-       return;
-    if (pp->pln_own == 0)
-       return;
-    etus = game_tick_to_now(&pp->pln_access);
-    if (etus == 0)
-       return;
-
-    do_upd_checking = 1;       /* avoid recursion */
-    do_mob_plane(pp, etus);
-    do_upd_checking = 0;
-}
-
 /* Increase mobility of everything for @etus ETUs, update timestamps */
 void
 mob_inc_all(int etus)
@@ -141,30 +59,31 @@ mob_inc_all(int etus)
     for (i = 0; (sectp = getsectid(i)); i++) {
        sectp->sct_timestamp = now;
        if (!opt_MOB_ACCESS)
-           do_mob_sect(sectp, etus);
+           mob_inc_sect(sectp, etus);
     }
 
     for (i = 0; (sp = getshipp(i)); i++) {
        sp->shp_timestamp = now;
        if (!opt_MOB_ACCESS)
-           do_mob_ship(sp, etus);
+           mob_inc_ship(sp, etus);
     }
 
     for (i = 0; (pp = getplanep(i)); i++) {
        pp->pln_timestamp = now;
        if (!opt_MOB_ACCESS)
-           do_mob_plane(pp, etus);
+           mob_inc_plane(pp, etus);
     }
 
     for (i = 0; (lp = getlandp(i)); i++) {
        lp->lnd_timestamp = now;
        if (!opt_MOB_ACCESS)
-           do_mob_land(lp, etus);
+           mob_inc_land(lp, etus);
     }
 }
 
-static void
-do_mob_sect(struct sctstr *sp, int etus)
+/* Increase @sp's mobility for @etus ETUs */
+void
+mob_inc_sect(struct sctstr *sp, int etus)
 {
     int value;
 
@@ -182,8 +101,9 @@ do_mob_sect(struct sctstr *sp, int etus)
     sp->sct_mobil = value;
 }
 
-static void
-do_mob_ship(struct shpstr *sp, int etus)
+/* Increase @sp's mobility for @etus ETUs */
+void
+mob_inc_ship(struct shpstr *sp, int etus)
 {
     int value;
 
@@ -199,8 +119,9 @@ do_mob_ship(struct shpstr *sp, int etus)
     sp->shp_mobil = (signed char)value;
 }
 
-static void
-do_mob_land(struct lndstr *lp, int etus)
+/* Increase @lp's mobility for @etus ETUs */
+void
+mob_inc_land(struct lndstr *lp, int etus)
 {
     int value;
 
@@ -230,8 +151,9 @@ do_mob_land(struct lndstr *lp, int etus)
     lp->lnd_mobil = value;
 }
 
-static void
-do_mob_plane(struct plnstr *pp, int etus)
+/* Increase @pp's mobility for @etus ETUs */
+void
+mob_inc_plane(struct plnstr *pp, int etus)
 {
     int value;
 
@@ -264,14 +186,14 @@ mob_access_all(void)
        return;
 
     for (i = 0; (sectp = getsectid(i)); i++)
-       do_mob_sect(sectp, game_reset_tick(&sectp->sct_access));
+       mob_inc_sect(sectp, game_reset_tick(&sectp->sct_access));
 
     for (i = 0; (sp = getshipp(i)); i++)
-       do_mob_ship(sp, game_reset_tick(&sp->shp_access));
+       mob_inc_ship(sp, game_reset_tick(&sp->shp_access));
 
     for (i = 0; (pp = getplanep(i)); i++)
-       do_mob_plane(pp, game_reset_tick(&pp->pln_access));
+       mob_inc_plane(pp, game_reset_tick(&pp->pln_access));
 
     for (i = 0; (lp = getlandp(i)); i++)
-       do_mob_land(lp, game_reset_tick(&lp->lnd_access));
+       mob_inc_land(lp, game_reset_tick(&lp->lnd_access));
 }