stratagus-cvs
[Top][All Lists]
Advanced

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

[Stratagus-CVS] stratagus/src game/game.c include/stratagus.h s...


From: address@hidden
Subject: [Stratagus-CVS] stratagus/src game/game.c include/stratagus.h s...
Date: 17 Jan 2004 05:17:32 +1100

CVSROOT:        /home/strat
Module name:    stratagus
Changes by:      <address@hidden>       04/01/17 05:17:29

Modified files:
        src/game       : game.c 
        src/include    : stratagus.h 
        src/stratagus  : spells.c 
        src/ui         : menus.c 
        src/unit       : unit.c unit_draw.c unittype.c 
        src/video      : cursor.c font.c graphic.c 

Log message:
        Small valgrind fixes.

Patches:
Index: stratagus/src/game/game.c
diff -u stratagus/src/game/game.c:1.125 stratagus/src/game/game.c:1.126
--- stratagus/src/game/game.c:1.125     Sat Jan 17 02:17:23 2004
+++ stratagus/src/game/game.c   Sat Jan 17 05:17:19 2004
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: game.c,v 1.125 2004/01/16 15:17:23 wizzard Exp $
+//      $Id: game.c,v 1.126 2004/01/16 18:17:19 nobody_ Exp $
 
 //@{
 
@@ -284,7 +284,11 @@
        if (filename) {
                s = NULL;
                // FIXME: LibraryFile here?
-               strcpy(CurrentMapPath, filename);
+               if (CurrentMapPath != filename) {
+                       //  strcpy is not safe if parameters overlap.
+                       //  Or at least this is what valgrind says.
+                       strcpy(CurrentMapPath, filename);
+               }
                if (filename[0] != '/' && filename[0] != '.') {
                        s = filename = strdcat3(StratagusLibPath, "/", 
filename);
                }
Index: stratagus/src/include/stratagus.h
diff -u stratagus/src/include/stratagus.h:1.34 
stratagus/src/include/stratagus.h:1.35
--- stratagus/src/include/stratagus.h:1.34      Fri Jan 16 02:15:08 2004
+++ stratagus/src/include/stratagus.h   Sat Jan 17 05:17:20 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: stratagus.h,v 1.34 2004/01/15 15:15:08 nobody_ Exp $
+//      $Id: stratagus.h,v 1.35 2004/01/16 18:17:20 nobody_ Exp $
 
 #ifndef __STRATAGUS_H__
 #define __STRATAGUS_H__
@@ -38,10 +38,10 @@
 ============================================================================*/
 
 // Unit On Map cache
-#define UNIT_ON_MAP
+// #define UNIT_ON_MAP
 
 // New unit cache
-// #define NEW_UNIT_CACHE
+#define NEW_UNIT_CACHE
 
        //
        //              Default speed for many things, set it higher for faster 
actions.
Index: stratagus/src/stratagus/spells.c
diff -u stratagus/src/stratagus/spells.c:1.136 
stratagus/src/stratagus/spells.c:1.137
--- stratagus/src/stratagus/spells.c:1.136      Thu Jan 15 09:31:08 2004
+++ stratagus/src/stratagus/spells.c    Sat Jan 17 05:17:21 2004
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: spells.c,v 1.136 2004/01/14 22:31:08 nobody_ Exp $
+//     $Id: spells.c,v 1.137 2004/01/16 18:17:21 nobody_ Exp $
 
 /*
 **             And when we cast our final spell
@@ -1240,12 +1240,21 @@
 void CleanSpells(void)
 {
        SpellType* spell;
+       SpellActionType *act;
+       SpellActionType *nextact;
 
        DebugLevel0("Cleaning spells.\n");
        for (spell = SpellTypeTable; spell < SpellTypeTable + SpellTypeCount; 
++spell) {
                free(spell->IdentName);
                free(spell->Name);
-               free(spell->Action);
+
+               act = spell->Action;
+               while (act) {
+                       nextact = act->Next;
+                       free(act);
+                       act = nextact;
+               }
+
                if (spell->Condition) {
                        free(spell->Condition->BoolFlag);
                        free(spell->Condition);
Index: stratagus/src/ui/menus.c
diff -u stratagus/src/ui/menus.c:1.607 stratagus/src/ui/menus.c:1.608
--- stratagus/src/ui/menus.c:1.607      Sat Jan 17 02:17:32 2004
+++ stratagus/src/ui/menus.c    Sat Jan 17 05:17:23 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: menus.c,v 1.607 2004/01/16 15:17:32 wizzard Exp $
+//      $Id: menus.c,v 1.608 2004/01/16 18:17:23 nobody_ Exp $
 
 //@{
 
@@ -6815,7 +6815,7 @@
                        mi->d.pulldown.options[n++] = 
strdup(PlayerRaces.Display[i]);
                }
        }
-       mi->d.pulldown.options[n++] = strdup("Map Default");
+       mi->d.pulldown.options[n++] = "Map Default";
        mi->d.pulldown.noptions = n;
        mi->d.pulldown.defopt = n - 1;
 }
@@ -6836,7 +6836,7 @@
        mi->d.pulldown.options = (unsigned char**)malloc(n * sizeof(unsigned 
char*));
        n = 0;
        if (mapdefault) {
-               mi->d.pulldown.options[n++] = strdup("Map Default");
+               mi->d.pulldown.options[n++] = "Map Default";
        }
        for (i = 0; i < NumTilesets; ++i) {
                mi->d.pulldown.options[n++] = strdup(Tilesets[i]->Name);
Index: stratagus/src/unit/unit.c
diff -u stratagus/src/unit/unit.c:1.360 stratagus/src/unit/unit.c:1.361
--- stratagus/src/unit/unit.c:1.360     Sat Jan 17 02:17:36 2004
+++ stratagus/src/unit/unit.c   Sat Jan 17 05:17:25 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: unit.c,v 1.360 2004/01/16 15:17:36 wizzard Exp $
+//      $Id: unit.c,v 1.361 2004/01/16 18:17:25 nobody_ Exp $
 
 //@{
 
@@ -225,6 +225,9 @@
        DebugLevel2Fn("%lu:No more references, only wait for network lag, unit 
%d\n" _C_
                GameCycle _C_ UnitNumber(unit));
        unit->Type = NULL;                                              // for 
debugging.
+#ifdef NEW_UNIT_CACHE
+       free(unit->CacheLinks);
+#endif
 }
 
 /**
@@ -3773,7 +3776,7 @@
        int j;
 
        CLprintf(file, "\n--- -----------------------------------------\n");
-       CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.360 2004/01/16 
15:17:36 wizzard Exp $\n\n");
+       CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.361 2004/01/16 
18:17:25 nobody_ Exp $\n\n");
 
 #if 0
        //
Index: stratagus/src/unit/unit_draw.c
diff -u stratagus/src/unit/unit_draw.c:1.208 
stratagus/src/unit/unit_draw.c:1.209
--- stratagus/src/unit/unit_draw.c:1.208        Sat Jan 17 02:17:36 2004
+++ stratagus/src/unit/unit_draw.c      Sat Jan 17 05:17:26 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: unit_draw.c,v 1.208 2004/01/16 15:17:36 wizzard Exp $
+//      $Id: unit_draw.c,v 1.209 2004/01/16 18:17:26 nobody_ Exp $
 
 //@{
 
@@ -114,42 +114,35 @@
 **
 **             @return                         Color for selection, or NULL if 
not selected.
 */
-local Uint32* SelectionColor(const Unit* unit)
+local Uint32 SelectionColor(const Unit* unit)
 {
-       static Uint32 color;
-
-       // FIXME: make these colors customizable via CVS
+       // FIXME: make these colors customizable with scripts.
 
        if (EditorRunning && unit == UnitUnderCursor &&
                        EditorState == EditorSelecting) {
-               color = ColorWhite;
-               return &color;
+               return ColorWhite;
        }
 
        if (unit->Selected || (unit->Blink & 1)) {
                if (unit->Player->Player == PlayerNumNeutral) {
-                       color = ColorYellow;
-                       return &color;
+                       return ColorYellow;
                }
                // FIXME: better allied?
                if (unit->Player == ThisPlayer) {
-                       color = ColorGreen;
-                       return &color;
+                       return ColorGreen;
                }
                if (IsEnemy(ThisPlayer, unit)) {
-                       color = ColorRed;
-                       return &color;
+                       return ColorRed;
                }
-               return &unit->Player->Color;
+               return unit->Player->Color;
        }
 
        // If building mark all own buildings
        if (CursorBuilding && unit->Type->Building &&
                        unit->Player == ThisPlayer) {
-               color = ColorGray;
-               return &color;
+               return ColorGray;
        }
-       return NULL;
+       return 0;
 }
 
 /**
@@ -159,25 +152,23 @@
 */
 global void DrawUnitSelection(const Unit* unit)
 {
-       Uint32* color;
        int x;
        int y;
        UnitType* type;
+       Uint32 color;
 
        type = unit->Type;
 
        color = SelectionColor(unit);
-       if (!color) {
-               return;
+       if (color) {
+               x = Map2ViewportX(CurrentViewport, unit->X) + unit->IX +
+                       type->TileWidth * TileSizeX / 2 - type->BoxWidth / 2 -
+                       (type->Width - VideoGraphicWidth(type->Sprite)) / 2;
+               y = Map2ViewportY(CurrentViewport, unit->Y) + unit->IY +
+                       type->TileHeight * TileSizeY / 2 - type->BoxHeight/2 -
+                       (type->Height - VideoGraphicHeight(type->Sprite)) / 2;
+               DrawSelection(color, x, y, x + type->BoxWidth, y + 
type->BoxHeight);
        }
-       x = Map2ViewportX(CurrentViewport, unit->X) + unit->IX +
-               type->TileWidth * TileSizeX / 2 - type->BoxWidth / 2 -
-               (type->Width - VideoGraphicWidth(type->Sprite)) / 2;
-       y = Map2ViewportY(CurrentViewport, unit->Y) + unit->IY +
-               type->TileHeight * TileSizeY / 2 - type->BoxHeight/2 -
-               (type->Height - VideoGraphicHeight(type->Sprite)) / 2;
-       DrawSelection(*color, x, y, x + type->BoxWidth, y + type->BoxHeight);
-       free(color);
 }
 
 /**
@@ -658,7 +649,7 @@
 {
 #if 0
        CLprintf(file, "\n;;; -----------------------------------------\n");
-       CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.208 
2004/01/16 15:17:36 wizzard Exp $\n\n");
+       CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.209 
2004/01/16 18:17:26 nobody_ Exp $\n\n");
 
        CLprintf(file, "(mana-sprite \"%s\"  %d %d  %d %d)\n",
                ManaSprite.File, ManaSprite.HotX, ManaSprite.HotY,
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.142 stratagus/src/unit/unittype.c:1.143
--- stratagus/src/unit/unittype.c:1.142 Sat Jan 17 02:17:37 2004
+++ stratagus/src/unit/unittype.c       Sat Jan 17 05:17:26 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: unittype.c,v 1.142 2004/01/16 15:17:37 wizzard Exp $
+//      $Id: unittype.c,v 1.143 2004/01/16 18:17:26 nobody_ Exp $
 
 //@{
 
@@ -1187,7 +1187,7 @@
 //     char** sp;
 
        CLprintf(file, "\n--- -----------------------------------------\n");
-       CLprintf(file, "--- MODULE: unittypes $Id: unittype.c,v 1.142 
2004/01/16 15:17:37 wizzard Exp $\n\n");
+       CLprintf(file, "--- MODULE: unittypes $Id: unittype.c,v 1.143 
2004/01/16 18:17:26 nobody_ Exp $\n\n");
 #if 0
        // Original number to internal unit-type name.
 
@@ -1491,7 +1491,7 @@
                if (!(anims = type->Animations)) {              // Must be 
handled?
                        continue;
                }
-                       for (j = i; j < NumUnitTypes; ++j) {            // 
Remove all uses.
+               for (j = i; j < NumUnitTypes; ++j) {            // Remove all 
uses.
                        if (anims == UnitTypes[j]->Animations) {
                                UnitTypes[j]->Animations = NULL;
                        }
@@ -1508,6 +1508,14 @@
                }
                if (anims->Die) {
                        free(anims->Die);
+               }
+               if (anims->Repair) {
+                       free(anims->Repair);
+               }
+               for (i = 0; i < MaxCosts; ++i) {
+                       if (anims->Harvest[i]) {
+                               free(anims->Harvest[i]);
+                       }
                }
                free(anims);
        }
Index: stratagus/src/video/cursor.c
diff -u stratagus/src/video/cursor.c:1.95 stratagus/src/video/cursor.c:1.96
--- stratagus/src/video/cursor.c:1.95   Fri Jan 16 23:02:28 2004
+++ stratagus/src/video/cursor.c        Sat Jan 17 05:17:28 2004
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: cursor.c,v 1.95 2004/01/16 12:02:28 wizzard Exp $
+//      $Id: cursor.c,v 1.96 2004/01/16 18:17:28 nobody_ Exp $
 
 //@{
 
@@ -833,7 +833,7 @@
        int i;
 
        CLprintf(file, "\n;;; -----------------------------------------\n");
-       CLprintf(file, ";;; MODULE: cursors $Id: cursor.c,v 1.95 2004/01/16 
12:02:28 wizzard Exp $\n\n");
+       CLprintf(file, ";;; MODULE: cursors $Id: cursor.c,v 1.96 2004/01/16 
18:17:28 nobody_ Exp $\n\n");
 
        for (i = 0; Cursors[i].OType; ++i) {
                CLprintf(file, "(define-cursor '%s '%s\n",
@@ -880,7 +880,6 @@
                free(Cursors[i].Ident);
                free(Cursors[i].Race);
                free(Cursors[i].File);
-               VideoSafeFree(Cursors[i].Sprite);
        }
        free(Cursors);
        Cursors = NULL;
Index: stratagus/src/video/font.c
diff -u stratagus/src/video/font.c:1.81 stratagus/src/video/font.c:1.82
--- stratagus/src/video/font.c:1.81     Sat Jan 17 02:17:38 2004
+++ stratagus/src/video/font.c  Sat Jan 17 05:17:28 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: font.c,v 1.81 2004/01/16 15:17:38 wizzard Exp $
+//      $Id: font.c,v 1.82 2004/01/16 18:17:28 nobody_ Exp $
 
 //@{
 
@@ -895,6 +895,7 @@
 global void CleanFonts(void)
 {
        unsigned i;
+       FontColorMapping *fcmp, *fcmpn;
 
        for (i = 0; i < sizeof(Fonts) / sizeof(*Fonts); ++i) {
                free(Fonts[i].File);
@@ -903,6 +904,12 @@
                Fonts[i].Graphic = NULL;
        }
 
+       fcmp = FontColorMappings;
+       while (fcmp) {
+               fcmpn = fcmp->Next;
+               free(fcmp);
+               fcmp = fcmpn;
+       }
        FontColorMappings = NULL;
 }
 
Index: stratagus/src/video/graphic.c
diff -u stratagus/src/video/graphic.c:1.65 stratagus/src/video/graphic.c:1.66
--- stratagus/src/video/graphic.c:1.65  Thu Jan 15 17:57:08 2004
+++ stratagus/src/video/graphic.c       Sat Jan 17 05:17:28 2004
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: graphic.c,v 1.65 2004/01/15 06:57:08 jsalmon3 Exp $
+//      $Id: graphic.c,v 1.66 2004/01/16 18:17:28 nobody_ Exp $
 
 //@{
 
@@ -283,7 +283,7 @@
        for (i = 0; i < s->h; ++i) {
                for (j = 0; j < s->w; ++j) {
                        ((char*)s->pixels)[j + i * s->w] =
-                               ((char*)graphic->Surface->pixels)[s->w - j + i 
* s->w];
+                               ((char*)graphic->Surface->pixels)[s->w - j - 1 
+ i * s->w];
                }
        }
        SDL_UnlockSurface(s);




reply via email to

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