stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src action/actions.c unit/script_unit...


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src action/actions.c unit/script_unit...
Date: 30 Jan 2004 04:36:55 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/30 04:36:54

Modified files:
        src/action     : actions.c 
        src/unit       : script_unit.c unit.c unit_draw.c 

Log message:
        Load-save fixes.
        Load-save reference counts.
        Only remove unit from the units array until after refs is 0.
        Rearrange UnitActions, cleaner.

Patches:
Index: stratagus/src/action/actions.c
diff -u stratagus/src/action/actions.c:1.116 
stratagus/src/action/actions.c:1.117
--- stratagus/src/action/actions.c:1.116        Wed Jan 28 07:57:23 2004
+++ stratagus/src/action/actions.c      Fri Jan 30 04:36:50 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: actions.c,v 1.116 2004/01/27 20:57:23 jsalmon3 Exp $
+//      $Id: actions.c,v 1.117 2004/01/29 17:36:50 nobody_ Exp $
 
 //@{
 
@@ -487,12 +487,12 @@
 global void UnitActions(void)
 {
        Unit* table[UnitMax];
-       Unit** tpos;
-       Unit** tend;
        Unit* unit;
        int blinkthiscycle;
        int buffsthiscycle;
        int regenthiscycle;
+       int i;
+       int tabsize;
 
        buffsthiscycle = regenthiscycle =
                blinkthiscycle = !(GameCycle % CYCLES_PER_SECOND);
@@ -500,19 +500,17 @@
        //
        // Must copy table, units could be removed.
        //
-       tend = table + NumUnits;
        memcpy(table, Units, sizeof(Unit*) * NumUnits);
 
        //
        // Check for dead/destroyed units in table...
+       // Filter them out
        //
-       for (tpos = table; tpos < tend; ++tpos) {
-               unit = *tpos;
-                       if (unit->Destroyed) {          // Ignore destroyed 
units
-                       DebugLevel0Fn("Destroyed unit %d in table, should be 
ok\n" _C_
-                               UnitNumber(unit));
-                       unit = 0;
-                       continue;
+       for (i = tabsize = 0; i < NumUnits; ++i) {
+               if (!table[i]->Destroyed) {             // Ignore destroyed 
units
+                       table[tabsize++] = table[i];
+               } else {
+                       DebugLevel3Fn("Destroyed unit %d in table, should be 
ok\n" _C_ table[i]->Slot);
                }
        }
 
@@ -523,48 +521,38 @@
 
        // 1) Blink flag.
        if (blinkthiscycle) {
-               for (tpos = table; tpos < tend; ++tpos) {
-                       if ((unit = *tpos)) {
-                               if (unit->Blink) {
-                                       --unit->Blink;
-                               }
+               for (i = 0; i < tabsize; ++i) {
+                       if (table[i]->Blink) {
+                               --table[i]->Blink;
                        }
                }
        }
 
        // 2) Buffs...
        if (buffsthiscycle) {
-               for (tpos = table; tpos < tend; ++tpos) {
-                       if ((unit = *tpos)) {
-                               HandleBuffs(unit, CYCLES_PER_SECOND);
-                       }
+               for (i = 0; i < tabsize; ++i) {
+                       HandleBuffs(table[i], CYCLES_PER_SECOND);
                }
        }
 
        // 3) Increase health mana, burn and stuff
        if (regenthiscycle) {
-               for (tpos = table; tpos < tend; ++tpos) {
-                       if ((unit = *tpos)) {
-                               HandleRegenerations(unit);
-                       }
+               for (i = 0; i < tabsize; ++i) {
+                       HandleRegenerations(table[i]);
                }
        }
 
        //
        // Do all actions
        //
-       for (tpos = table; tpos < tend; ++tpos) {
-               unit = *tpos;
-               if (!tpos) {
-                       continue;
-               }
+       for (i = 0; i < tabsize; ++i) {
+               unit = table[i];
 
                if (--unit->Wait) {                     // Wait until counter 
reached
                        continue;
                }
 
                HandleUnitAction(unit);
-               DebugCheck(*tpos != unit);              // Removed is evil.
 
 #ifdef DEBUG_ACTIONS
                //
Index: stratagus/src/unit/script_unit.c
diff -u stratagus/src/unit/script_unit.c:1.100 
stratagus/src/unit/script_unit.c:1.101
--- stratagus/src/unit/script_unit.c:1.100      Thu Jan 29 23:50:36 2004
+++ stratagus/src/unit/script_unit.c    Fri Jan 30 04:36:52 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: script_unit.c,v 1.100 2004/01/29 12:50:36 nobody_ Exp $
+//      $Id: script_unit.c,v 1.101 2004/01/29 17:36:52 nobody_ Exp $
 
 //@{
 
@@ -261,7 +261,7 @@
                        if (!UnitSlots[slot]) {
                                DebugLevel0Fn("FIXME: Forward reference not 
supported\n");
                        }
-                       ++UnitSlots[slot]->Refs;
+                       //++UnitSlots[slot]->Refs;
 
                } else if (!strcmp(value, "tile")) {
                        ++j;
@@ -399,7 +399,7 @@
                        slot = strtol(value + 1, NULL, 16);
                        DebugCheck(!UnitSlots[slot]);
                        unit->Data.Builded.Worker = UnitSlots[slot];
-                       ++UnitSlots[slot]->Refs;
+                       //++UnitSlots[slot]->Refs;
                } else if (!strcmp(value, "progress")) {
                        lua_rawgeti(l, -1, j + 1);
                        unit->Data.Builded.Progress = LuaToNumber(l, -1);
@@ -637,7 +637,11 @@
        const char* s;
        int args;
        int j;
+       int savrefs;
 
+#ifdef DEBUG
+       savrefs = 0;
+#endif
        args = lua_gettop(l);
        j = 0;
 
@@ -688,6 +692,8 @@
                        unit->Next = UnitSlots[(int)LuaToNumber(l, j + 1)];
                } else if (!strcmp(value, "current-sight-range")) {
                        unit->CurrentSightRange = LuaToNumber(l, j + 1);
+               } else if (!strcmp(value, "refs")) {
+                       savrefs = LuaToNumber(l, j + 1);
                } else if (!strcmp(value, "host-info")) {
                        int x;
                        int y;
@@ -876,7 +882,7 @@
                                slot = strtol(value + 1, NULL, 16);
                                AddUnitInContainer(UnitSlots[slot], unit);
                                DebugCheck(!UnitSlots[slot]);
-                               ++UnitSlots[slot]->Refs;
+                               //++UnitSlots[slot]->Refs;
                        }
                } else if (!strcmp(value, "order-count")) {
                        unit->OrderCount = LuaToNumber(l, j + 1);
@@ -893,6 +899,7 @@
                        AssignUnitToPlayer (unit, player);
                        unit->HP = hp;
                        if (unit->Orders[0].Action == UnitActionBuilded) {
+                               DebugLevel0Fn("HACK: the building is not ready 
yet\n");
                                // HACK: the building is not ready yet
                                unit->Player->UnitTypesCount[type->Slot]--;
                        }
@@ -949,7 +956,7 @@
 
        //  Revealers are units that can see while removed
        if (unit->Removed && unit->Type->Revealer) {
-                       MapMarkUnitSight(unit);
+               MapMarkUnitSight(unit);
        }
 
        // Units Dieing may have sight
@@ -963,6 +970,11 @@
                PlaceUnit(unit, unit->X, unit->Y);
        }
 
+       if (unit->UnitSlot) {
+               UnitCacheRemove(unit);
+               UnitCacheInsert(unit);
+       }
+
        // FIXME: johns: works only for debug code.
        if (unit->Moving) {
                NewResetPath(unit);
@@ -971,6 +983,9 @@
        if (unit->RescuedFrom) {
                unit->Colors = &unit->RescuedFrom->UnitColors;
        }
+       
+       // Fix references. REFERENCES GET SAVED!.
+       unit->Refs = savrefs;
        DebugLevel3Fn("unit #%d parsed\n" _C_ slot);
 
        return 0;
Index: stratagus/src/unit/unit.c
diff -u stratagus/src/unit/unit.c:1.378 stratagus/src/unit/unit.c:1.379
--- stratagus/src/unit/unit.c:1.378     Thu Jan 29 23:50:36 2004
+++ stratagus/src/unit/unit.c   Fri Jan 30 04:36:52 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: unit.c,v 1.378 2004/01/29 12:50:36 nobody_ Exp $
+//      $Id: unit.c,v 1.379 2004/01/29 17:36:52 nobody_ Exp $
 
 //@{
 
@@ -171,6 +171,7 @@
 */
 global void ReleaseUnit(Unit* unit)
 {
+       Unit* temp;
        DebugLevel2Fn("%lu:Unit %p %d `%s'\n" _C_ GameCycle _C_
                unit _C_ UnitNumber(unit) _C_ unit->Type->Ident);
 
@@ -182,18 +183,9 @@
        //              First release, remove from lists/tables.
        //
        if (!unit->Destroyed) {
-               Unit* temp;
                DebugLevel0Fn("First release %d\n" _C_ unit->Slot);
 
                //
-               //              Remove the unit from the global units table.
-               //
-               DebugCheck(*unit->UnitSlot != unit);
-               temp = Units[--NumUnits];
-               temp->UnitSlot = unit->UnitSlot;
-               *unit->UnitSlot = temp;
-               Units[NumUnits] = NULL;
-               //
                //              Are more references remaining?
                //
                unit->Destroyed = 1;                            // mark as 
destroyed
@@ -213,9 +205,16 @@
        //              memory.
        //
        *ReleasedTail = unit;
-       if (!EditorRunning) {
-               UnitCacheRemove(unit);
-       }
+       UnitCacheRemove(unit);
+       //
+       //              Remove the unit from the global units table.
+       //
+       DebugCheck(*unit->UnitSlot != unit);
+       temp = Units[--NumUnits];
+       temp->UnitSlot = unit->UnitSlot;
+       *unit->UnitSlot = temp;
+       Units[NumUnits] = NULL;
+
        unit->Next = 0;
        ReleasedTail = &unit->Next;
        unit->Refs = GameCycle + NetworkMaxLag;         // could be reuse after 
this time
@@ -450,7 +449,7 @@
        int w;
        unsigned flags;
 
-       DebugCheck(!unit->Removed || unit->Destroyed);
+       DebugCheck(!unit->Removed);
 
        type = unit->Type;
 
@@ -3524,6 +3523,7 @@
        }
 
        CLprintf(file, "\"tile\", {%d, %d}, ", unit->X, unit->Y);
+       CLprintf(file, "\"refs\", %d, ", unit->Refs);
 #if 0
        // latimerius: why is this so complex?
        // JOHNS: An unit can be owned by a new player and have still the old 
stats
@@ -3770,7 +3770,7 @@
        int j;
 
        CLprintf(file, "\n--- -----------------------------------------\n");
-       CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.378 2004/01/29 
12:50:36 nobody_ Exp $\n\n");
+       CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.379 2004/01/29 
17:36:52 nobody_ Exp $\n\n");
 
 #if 0
        //
Index: stratagus/src/unit/unit_draw.c
diff -u stratagus/src/unit/unit_draw.c:1.216 
stratagus/src/unit/unit_draw.c:1.217
--- stratagus/src/unit/unit_draw.c:1.216        Thu Jan 29 23:50:37 2004
+++ stratagus/src/unit/unit_draw.c      Fri Jan 30 04:36:53 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: unit_draw.c,v 1.216 2004/01/29 12:50:37 nobody_ Exp $
+//      $Id: unit_draw.c,v 1.217 2004/01/29 17:36:53 nobody_ Exp $
 
 //@{
 
@@ -644,7 +644,7 @@
 {
 #if 0
        CLprintf(file, "\n;;; -----------------------------------------\n");
-       CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.216 
2004/01/29 12:50:37 nobody_ Exp $\n\n");
+       CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.217 
2004/01/29 17:36:53 nobody_ Exp $\n\n");
 
        CLprintf(file, "(mana-sprite \"%s\"  %d %d  %d %d)\n",
                ManaSprite.File, ManaSprite.HotX, ManaSprite.HotY,
@@ -1635,7 +1635,7 @@
        const UnitStats* stats;
        int r;
 
-#if 0 // This is for showing vis counts and refs.
+#if 1 // This is for showing vis counts and refs.
        char buf[10];
        sprintf(buf, "%d%c%c%d", unit->VisCount[ThisPlayer->Player],
                unit->Seen.ByPlayer & (1 << ThisPlayer->Player) ? 'Y' : 'N',




reply via email to

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