[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src game/game.c game/loadgame.c inclu...
From: |
address@hidden |
Subject: |
[Stratagus-CVS] stratagus/src game/game.c game/loadgame.c inclu... |
Date: |
16 Jan 2004 21:35:40 +1100 |
CVSROOT: /home/strat
Module name: stratagus
Changes by: <address@hidden> 04/01/16 21:35:39
Modified files:
src/game : game.c loadgame.c
src/include : missile.h unittype.h
src/missile : missile.c
src/stratagus : mainloop.c
src/unit : unit.c unit_draw.c unittype.c
src/video : cursor.c
Log message:
Dynamically Load UnitType, and MissileType Sprites only when needed
Patches:
Index: stratagus/src/game/game.c
diff -u stratagus/src/game/game.c:1.123 stratagus/src/game/game.c:1.124
--- stratagus/src/game/game.c:1.123 Thu Jan 15 13:04:51 2004
+++ stratagus/src/game/game.c Fri Jan 16 21:35:33 2004
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: game.c,v 1.123 2004/01/15 02:04:51 jsalmon3 Exp $
+// $Id: game.c,v 1.124 2004/01/16 10:35:33 wizzard Exp $
//@{
@@ -403,7 +403,6 @@
LoadCursors(ThisPlayer->RaceName);
InitMissileTypes();
- LoadMissileSprites();
InitConstructions();
LoadConstructions();
LoadUnitTypes();
Index: stratagus/src/game/loadgame.c
diff -u stratagus/src/game/loadgame.c:1.77 stratagus/src/game/loadgame.c:1.78
--- stratagus/src/game/loadgame.c:1.77 Fri Jan 9 16:44:36 2004
+++ stratagus/src/game/loadgame.c Fri Jan 16 21:35:33 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: loadgame.c,v 1.77 2004/01/09 05:44:36 jsalmon3 Exp $
+// $Id: loadgame.c,v 1.78 2004/01/16 10:35:33 wizzard Exp $
//@{
@@ -176,7 +176,6 @@
#if 0
LoadPlayers();
#endif
- LoadMissileSprites();
LoadConstructions();
LoadDecorations();
LoadUnitTypes();
Index: stratagus/src/include/missile.h
diff -u stratagus/src/include/missile.h:1.79
stratagus/src/include/missile.h:1.80
--- stratagus/src/include/missile.h:1.79 Sun Jan 11 07:53:59 2004
+++ stratagus/src/include/missile.h Fri Jan 16 21:35:33 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: missile.h,v 1.79 2004/01/10 20:53:59 jsalmon3 Exp $
+// $Id: missile.h,v 1.80 2004/01/16 10:35:33 wizzard Exp $
#ifndef __MISSILE_H__
#define __MISSILE_H__
@@ -502,8 +502,8 @@
// In missile.c
- /// load the graphics for the missiles
-extern void LoadMissileSprites(void);
+ /// load the graphics for a missile type
+extern void LoadMissileSprite(MissileType* mtype);
/// allocate an empty missile-type slot
extern MissileType* NewMissileTypeSlot(char*);
/// Get missile-type by ident
@@ -518,7 +518,7 @@
extern int CheckMissileToBeDrawn(const Missile* missile);
/// Draw all missiles
-extern void DrawMissile(const MissileType* mtype, int frame, int x, int y);
+extern void DrawMissile(MissileType* mtype, int frame, int x, int y);
extern int FindAndSortMissiles(const Viewport* vp, Missile** table);
/// handle all missiles
Index: stratagus/src/include/unittype.h
diff -u stratagus/src/include/unittype.h:1.138
stratagus/src/include/unittype.h:1.139
--- stratagus/src/include/unittype.h:1.138 Thu Jan 15 13:05:39 2004
+++ stratagus/src/include/unittype.h Fri Jan 16 21:35:33 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unittype.h,v 1.138 2004/01/15 02:05:39 jsalmon3 Exp $
+// $Id: unittype.h,v 1.139 2004/01/16 10:35:33 wizzard Exp $
#ifndef __UNITTYPE_H__
#define __UNITTYPE_H__
@@ -809,6 +809,7 @@
extern void DrawUnitType(const UnitType* type, Graphic* sprite, int frame, int
x, int y);
extern void InitUnitTypes(int reset_player_stats); /// Init unit-type table
+extern void LoadUnitTypeSprite(UnitType* unittype); /// Load the sprite for a
unittype
extern void LoadUnitTypes(void); /// Load the unit-type data
extern void CleanUnitTypes(void); /// Cleanup unit-type
module
Index: stratagus/src/missile/missile.c
diff -u stratagus/src/missile/missile.c:1.125
stratagus/src/missile/missile.c:1.126
--- stratagus/src/missile/missile.c:1.125 Thu Jan 15 13:06:47 2004
+++ stratagus/src/missile/missile.c Fri Jan 16 21:35:34 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: missile.c,v 1.125 2004/01/15 02:06:47 jsalmon3 Exp $
+// $Id: missile.c,v 1.126 2004/01/16 10:35:34 wizzard Exp $
//@{
@@ -143,32 +143,27 @@
----------------------------------------------------------------------------*/
/**
-** Load the graphics for the missiles.
+** Load the graphics for a missile type
+**
+** @param missile Type of missile to Load
*/
-global void LoadMissileSprites(void)
+global void LoadMissileSprite(MissileType* mtype)
{
- int i;
const char* file;
- if (!MissileTypes) {
- return;
- }
- for (i = 0; MissileTypes[i].OType; ++i) {
- if ((file = MissileTypes[i].File)) {
- char* buf;
-
- buf = alloca(strlen(file) + 9 + 1);
- file = strcat(strcpy(buf, "graphics/"), file);
- ShowLoadProgress("Missile %s", file);
- MissileTypes[i].Sprite = LoadSprite(
- file, MissileTypes[i].Width,
MissileTypes[i].Height);
- FlipGraphic(MissileTypes[i].Sprite);
-
- // Correct the number of frames in graphic
- DebugCheck(MissileTypes[i].Sprite->NumFrames <
MissileTypes[i].SpriteFrames);
- MissileTypes[i].Sprite->NumFrames =
MissileTypes[i].SpriteFrames;
- // FIXME: Don't use NumFrames as number of frames.
- }
+ if ((file = mtype->File)) {
+ char* buf;
+
+ buf = alloca(strlen(file) + 9 + 1);
+ file = strcat(strcpy(buf, "graphics/"), file);
+ mtype->Sprite = LoadSprite(
+ file, mtype->Width, mtype->Height);
+ FlipGraphic(mtype->Sprite);
+
+ // Correct the number of frames in graphic
+ DebugCheck(mtype->Sprite->NumFrames < mtype->SpriteFrames);
+ mtype->Sprite->NumFrames = mtype->SpriteFrames;
+ // FIXME: Don't use NumFrames as number of frames.
}
}
@@ -659,8 +654,12 @@
** @param x Screen pixel X position
** @param y Screen pixel Y position
*/
-global void DrawMissile(const MissileType* mtype, int frame, int x, int y)
+global void DrawMissile(MissileType* mtype, int frame, int x, int y)
{
+ if (!mtype->Sprite) {
+ LoadMissileSprite(mtype);
+ }
+
if (mtype->Flip) {
if (frame < 0) {
if (mtype->Transparency == 50) {
@@ -1122,7 +1121,7 @@
totalx = MapDistance(missile->DX, missile->DY,
missile->SourceX, missile->SourceY);
dx = MapDistance(missile->X, missile->Y, missile->SourceX,
missile->SourceY);
- totalf = VideoGraphicFrames(missile->Type->Sprite) /
NumDirections;
+ totalf = missile->Type->SpriteFrames / NumDirections;
df = missile->SpriteFrame / NumDirections;
if ((sign == 1 && dx * totalf <= df * totalx) ||
(sign == -1 && dx * totalf > df * totalx)) {
@@ -1131,13 +1130,13 @@
}
missile->SpriteFrame += sign * NumDirections;
if (sign > 0) {
- if (missile->SpriteFrame >=
VideoGraphicFrames(missile->Type->Sprite)) {
- missile->SpriteFrame -=
VideoGraphicFrames(missile->Type->Sprite);
+ if (missile->SpriteFrame >= missile->Type->SpriteFrames) {
+ missile->SpriteFrame -= missile->Type->SpriteFrames;
AnimationIsFinished = 1;
}
} else {
if (missile->SpriteFrame < 0) {
- missile->SpriteFrame +=
VideoGraphicFrames(missile->Type->Sprite);
+ missile->SpriteFrame += missile->Type->SpriteFrames;
AnimationIsFinished = 1;
}
}
@@ -1145,7 +1144,7 @@
missile->SpriteFrame = -missile->SpriteFrame;
}
DebugLevel3Fn("Frame %d of %d\n" _C_
- missile->SpriteFrame _C_
VideoGraphicFrames(missile->Type->Sprite));
+ missile->SpriteFrame _C_ missile->Type->SpriteFrames);
return AnimationIsFinished;
}
@@ -1171,7 +1170,7 @@
}
totalx = abs(missile->DX - missile->SourceX);
dx = abs(missile->X - missile->SourceX);
- f = VideoGraphicFrames(missile->Type->Sprite) /
missile->Type->NumDirections;
+ f = missile->Type->SpriteFrames / missile->Type->NumDirections;
f = 2 * f - 1;
for (i = 1, j = 1; i <= f; ++i) {
if (dx * f / i < totalx) {
@@ -1305,7 +1304,7 @@
DebugCheck(file == NULL);
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.125
2004/01/15 02:06:47 jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: missile-types $Id: missile.c,v 1.126
2004/01/16 10:35:34 wizzard Exp $\n\n");
//
// Original number to internal missile-type name.
@@ -1427,7 +1426,7 @@
Missile* const* missiles;
CLprintf(file,"\n--- -----------------------------------------\n");
- CLprintf(file,"--- MODULE: missiles $Id: missile.c,v 1.125 2004/01/15
02:06:47 jsalmon3 Exp $\n\n");
+ CLprintf(file,"--- MODULE: missiles $Id: missile.c,v 1.126 2004/01/16
10:35:34 wizzard Exp $\n\n");
for (missiles = GlobalMissiles; *missiles; ++missiles) {
SaveMissile(*missiles, file);
Index: stratagus/src/stratagus/mainloop.c
diff -u stratagus/src/stratagus/mainloop.c:1.179
stratagus/src/stratagus/mainloop.c:1.180
--- stratagus/src/stratagus/mainloop.c:1.179 Thu Jan 15 13:07:39 2004
+++ stratagus/src/stratagus/mainloop.c Fri Jan 16 21:35:35 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: mainloop.c,v 1.179 2004/01/15 02:07:39 jsalmon3 Exp $
+// $Id: mainloop.c,v 1.180 2004/01/16 10:35:35 wizzard Exp $
//@{
@@ -408,6 +408,9 @@
y = missiletable[j]->Y - vp->MapY * TileSizeY +
vp->Y;
// FIXME: I should copy SourcePlayer for second
level missiles.
if (missiletable[j]->SourceUnit &&
missiletable[j]->SourceUnit->Player) {
+ if (!missiletable[j]->Type->Sprite) {
+
LoadMissileSprite(missiletable[j]->Type);
+ }
GraphicPlayerPixels(missiletable[j]->SourceUnit->Player,
missiletable[j]->Type->Sprite);
}
@@ -433,6 +436,9 @@
y = missiletable[j]->Y - vp->MapY * TileSizeY + vp->Y;
// FIXME: I should copy SourcePlayer for second level
missiles.
if (missiletable[j]->SourceUnit &&
missiletable[j]->SourceUnit->Player) {
+ if (!missiletable[j]->Type->Sprite) {
+
LoadMissileSprite(missiletable[j]->Type);
+ }
GraphicPlayerPixels(missiletable[j]->SourceUnit->Player,
missiletable[j]->Type->Sprite);
}
Index: stratagus/src/unit/unit.c
diff -u stratagus/src/unit/unit.c:1.358 stratagus/src/unit/unit.c:1.359
--- stratagus/src/unit/unit.c:1.358 Fri Jan 16 02:15:08 2004
+++ stratagus/src/unit/unit.c Fri Jan 16 21:35:36 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.c,v 1.358 2004/01/15 15:15:08 nobody_ Exp $
+// $Id: unit.c,v 1.359 2004/01/16 10:35:36 wizzard Exp $
//@{
@@ -2800,7 +2800,7 @@
*/
global void LetUnitDie(Unit* unit)
{
- const UnitType* type;
+ UnitType* type;
unit->HP = 0;
unit->Moving = 0;
@@ -2861,6 +2861,9 @@
type->TileHeight !=
type->CorpseType->TileHeight);
type = unit->Type = type->CorpseType;
+ if (!type->Sprite) {
+ LoadUnitTypeSprite(type);
+ }
unit->IX = (type->Width -
VideoGraphicWidth(type->Sprite)) / 2;
unit->IY = (type->Height -
VideoGraphicHeight(type->Sprite)) / 2;
@@ -3770,7 +3773,7 @@
int j;
CLprintf(file, "\n--- -----------------------------------------\n");
- CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.358 2004/01/15
15:15:08 nobody_ Exp $\n\n");
+ CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.359 2004/01/16
10:35:36 wizzard Exp $\n\n");
#if 0
//
Index: stratagus/src/unit/unit_draw.c
diff -u stratagus/src/unit/unit_draw.c:1.205
stratagus/src/unit/unit_draw.c:1.206
--- stratagus/src/unit/unit_draw.c:1.205 Thu Jan 15 13:11:09 2004
+++ stratagus/src/unit/unit_draw.c Fri Jan 16 21:35:36 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_draw.c,v 1.205 2004/01/15 02:11:09 jsalmon3 Exp $
+// $Id: unit_draw.c,v 1.206 2004/01/16 10:35:36 wizzard Exp $
//@{
@@ -660,7 +660,7 @@
{
#if 0
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.205
2004/01/15 02:11:09 jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.206
2004/01/16 10:35:36 wizzard Exp $\n\n");
CLprintf(file, "(mana-sprite \"%s\" %d %d %d %d)\n",
ManaSprite.File, ManaSprite.HotX, ManaSprite.HotY,
@@ -1900,7 +1900,7 @@
Graphic* sprite;
ResourceInfo* resinfo;
ConstructionFrame* cframe;
- const UnitType* type;
+ UnitType* type;
if (unit->Type->Revealer) { // Revealers
are not drawn
DebugLevel3Fn("Drawing revealer %d\n" _C_ UnitNumber(unit));
@@ -1928,6 +1928,10 @@
constructed = unit->Seen.Constructed;
state = unit->Seen.State;
cframe = unit->Seen.CFrame;
+ }
+
+ if (!type->Sprite) {
+ LoadUnitTypeSprite(type);
}
if ((!UnitVisible(unit, ThisPlayer)) && frame == UnitNotSeen) {
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.140 stratagus/src/unit/unittype.c:1.141
--- stratagus/src/unit/unittype.c:1.140 Thu Jan 15 17:44:28 2004
+++ stratagus/src/unit/unittype.c Fri Jan 16 21:35:37 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unittype.c,v 1.140 2004/01/15 06:44:28 jsalmon3 Exp $
+// $Id: unittype.c,v 1.141 2004/01/16 10:35:37 wizzard Exp $
//@{
@@ -1187,7 +1187,7 @@
// char** sp;
CLprintf(file, "\n--- -----------------------------------------\n");
- CLprintf(file, "--- MODULE: unittypes $Id: unittype.c,v 1.140
2004/01/15 06:44:28 jsalmon3 Exp $\n\n");
+ CLprintf(file, "--- MODULE: unittypes $Id: unittype.c,v 1.141
2004/01/16 10:35:37 wizzard Exp $\n\n");
#if 0
// Original number to internal unit-type name.
@@ -1354,91 +1354,81 @@
}
/**
-** Load the graphics for the unit-types.
+** Loads the Sprite for a unit type
+**
+** @param unittype type of unit to load
*/
-global void LoadUnitTypes(void)
+global void LoadUnitTypeSprite(UnitType* unittype)
{
- UnitType* type;
const char* file;
- char buf[1000];
- int i;
- int res;
+ char buf[4096];
ResourceInfo* resinfo;
+ int res;
+ UnitType* type;
- for (i = 0; i < NumUnitTypes; ++i) {
- type = UnitTypes[i];
- if ((file = type->ShadowFile)) {
- file = strcat(strcpy(buf, "graphics/"), file);
- ShowLoadProgress("Unit `%s'", file);
- type->ShadowSprite = LoadSprite(file, type->ShadowWidth,
- type->ShadowHeight);
- FlipGraphic(type->ShadowSprite);
- }
-
- // Load empty/loaded graphics
- if (type->Harvester) {
- for (res = 0; res < MaxCosts; ++res) {
- if ((resinfo = type->ResInfo[res])) {
- if ((file = resinfo->FileWhenLoaded)) {
- file = strcat(strcpy(buf,
"graphics/"), file);
- ShowLoadProgress("Unit `%s'",
file);
- resinfo->SpriteWhenLoaded =
LoadSprite(file, type->Width,
- type->Height);
-
FlipGraphic(resinfo->SpriteWhenLoaded);
- }
- if ((file = resinfo->FileWhenEmpty)) {
- file = strcat(strcpy(buf,
"graphics/"), file);
- ShowLoadProgress("Unit `%s'",
file);
- resinfo->SpriteWhenEmpty =
LoadSprite(file, type->Width,
- type->Height);
-
FlipGraphic(resinfo->SpriteWhenEmpty);
- }
- }
- }
+ if (unittype->SameSprite) {
+ type = UnitTypeByIdent(unittype->SameSprite);
+ if (!type) {
+ PrintFunction();
+ fprintf(stdout, "Unit-type %s not found\n",
type->SameSprite);
+ ExitFatal(-1);
}
+ } else {
+ type = unittype;
+ }
- //
- // Unit-type uses the same sprite as an other.
- //
- if (type->SameSprite) {
- continue;
+ if ((file = type->ShadowFile)) {
+ file = strcat(strcpy(buf, "graphics/"), file);
+ type->ShadowSprite = LoadSprite(file, type->ShadowWidth,
+ type->ShadowHeight);
+ FlipGraphic(type->ShadowSprite);
+ }
+
+ if (type->Harvester) {
+ for (res = 0; res < MaxCosts; ++res) {
+ if ((resinfo = type->ResInfo[res])) {
+ if ((file = resinfo->FileWhenLoaded)) {
+ file = strcat(strcpy(buf, "graphics/"),
file);
+ resinfo->SpriteWhenLoaded =
LoadSprite(file, type->Width,
+ type->Height);
+ FlipGraphic(resinfo->SpriteWhenLoaded);
+ }
+ if ((file = resinfo->FileWhenEmpty)) {
+ file = strcat(strcpy(buf, "graphics/"),
file);
+ resinfo->SpriteWhenEmpty =
LoadSprite(file, type->Width,
+ type->Height);
+ FlipGraphic(resinfo->SpriteWhenEmpty);
+ }
+ }
}
+ }
- //
- // FIXME: must handle terrain different!
- //
+ file = type->File[TheMap.Terrain];
+ if (!file) { // default one
+ file = type->File[0];
+ }
+ if (file) {
+ strcpy(buf, "graphics/");
+ strcat(buf, file);
+ type->Sprite = LoadSprite(buf, type->Width, type->Height);
+ FlipGraphic(type->Sprite);
+ }
- file = type->File[TheMap.Terrain];
- if (!file) { //
default one
- file = type->File[0];
- }
- if (file) {
- char* buf;
-
- buf = alloca(strlen(file) + 9 + 1);
- file = strcat(strcpy(buf, "graphics/"), file);
- ShowLoadProgress("Unit `%s'", file);
- type->Sprite = LoadSprite(file, type->Width,
type->Height);
- FlipGraphic(type->Sprite);
- }
+ if (unittype->SameSprite) {
+ unittype->Sprite = type->Sprite;
}
+}
+
+/**
+** Load the graphics for the unit-types.
+*/
+global void LoadUnitTypes(void)
+{
+ UnitType* type;
+ int i;
for (i = 0; i<NumUnitTypes; ++i) {
type = UnitTypes[i];
- //
- // Unit-type uses the same sprite as an other.
- //
- if (type->SameSprite) {
- const UnitType* unittype;
-
- unittype = UnitTypeByIdent(type->SameSprite);
- if (!unittype) {
- PrintFunction();
- fprintf(stdout, "Unit-type %s not found\n",
type->SameSprite);
- ExitFatal(-1);
- }
- type->Sprite = unittype->Sprite;
- }
//
// Lookup icons.
Index: stratagus/src/video/cursor.c
diff -u stratagus/src/video/cursor.c:1.93 stratagus/src/video/cursor.c:1.94
--- stratagus/src/video/cursor.c:1.93 Thu Jan 15 13:14:07 2004
+++ stratagus/src/video/cursor.c Fri Jan 16 21:35:38 2004
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: cursor.c,v 1.93 2004/01/15 02:14:07 jsalmon3 Exp $
+// $Id: cursor.c,v 1.94 2004/01/16 10:35:38 wizzard Exp $
//@{
@@ -510,6 +510,9 @@
//
// Draw building
//
+ if (!CursorBuilding->Sprite) {
+ LoadUnitTypeSprite(CursorBuilding);
+ }
frame = CursorBuilding->Animations->Still[0].Frame +
(CursorBuilding->Building ? 0 : CursorBuilding->NumDirections /
2 + 1 - 1);
PushClipping();
@@ -828,7 +831,7 @@
int i;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: cursors $Id: cursor.c,v 1.93 2004/01/15
02:14:07 jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: cursors $Id: cursor.c,v 1.94 2004/01/16
10:35:38 wizzard Exp $\n\n");
for (i = 0; Cursors[i].OType; ++i) {
CLprintf(file, "(define-cursor '%s '%s\n",
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src game/game.c game/loadgame.c inclu...,
address@hidden <=