More savegame fixes.

This commit is contained in:
nobody_ 2004-01-29 20:36:23 +00:00
parent 5aac6400a7
commit 5a73e6db0e
6 changed files with 30 additions and 35 deletions

View file

@ -306,6 +306,7 @@ global void CreateGame(char* filename, WorldMap* map)
char* s;
if (SaveGameLoading) {
SaveGameLoading = 0;
// Load game, already created game with Init/LoadModules
return;
}

View file

@ -774,7 +774,6 @@ global void GameMainLoop(void)
EnableDrawRefresh();
GameCursor = TheUI.Point.Cursor;
GameRunning = 1;
SaveGameLoading = 0;
showtip = 0;
RealVideoSyncSpeed = VideoSyncSpeed;
@ -788,6 +787,9 @@ global void GameMainLoop(void)
while (GameRunning) {
// Can't find a better place.
// TODO: rewrite this mainloop junk. And menu system. MY BRAIN HURTS!!!
SaveGameLoading = 0;
#if defined(DEBUG)
if (setjmp(MainLoopJmpBuf)) {
GamePaused = 1;

View file

@ -324,12 +324,12 @@ local int CclMissile(lua_State* l)
DebugCheck(!missile);
value = LuaToString(l, j + 1);
missile->SourceUnit = UnitSlots[strtol(value + 1, 0, 16)];
missile->SourceUnit->Refs++;
RefsIncrease(missile->SourceUnit);
} else if (!strcmp(value, "target")) {
DebugCheck(!missile);
value = LuaToString(l, j + 1);
missile->TargetUnit = UnitSlots[strtol(value + 1, 0, 16)];
missile->TargetUnit->Refs++;
RefsIncrease(missile->TargetUnit);
} else if (!strcmp(value, "damage")) {
DebugCheck(!missile);
missile->Damage = LuaToNumber(l, j + 1);

View file

@ -637,11 +637,7 @@ local int CclUnit(lua_State* l)
const char* s;
int args;
int j;
int savrefs;
#ifdef DEBUG
savrefs = 0;
#endif
args = lua_gettop(l);
j = 0;
@ -693,7 +689,7 @@ local int CclUnit(lua_State* l)
} else if (!strcmp(value, "current-sight-range")) {
unit->CurrentSightRange = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "refs")) {
savrefs = LuaToNumber(l, j + 1);
unit->Refs = LuaToNumber(l, j + 1);
} else if (!strcmp(value, "host-info")) {
int x;
int y;
@ -959,23 +955,22 @@ local int CclUnit(lua_State* l)
MapMarkUnitSight(unit);
}
// Units Dieing may have sight
if (unit->Removed && unit->Orders[0].Action == UnitActionDie) {
MapMarkUnitSight(unit);
}
// Place on map
if (!unit->Removed && !unit->Destroyed && !unit->Type->Vanishes) {
unit->Removed = 1;
PlaceUnit(unit, unit->X, unit->Y);
}
if (unit->UnitSlot) {
if (unit->UnitSlot && (unit->Destroyed || unit->Orders->Action == UnitActionDie)) {
UnitCacheRemove(unit);
UnitCacheInsert(unit);
}
// FIXME: johns: works only for debug code.
// Units Dieing may have sight
if (unit->Removed && unit->Orders[0].Action == UnitActionDie) {
MapMarkUnitSight(unit);
}
if (unit->Moving) {
NewResetPath(unit);
}
@ -984,8 +979,6 @@ local int CclUnit(lua_State* l)
unit->Colors = &unit->RescuedFrom->UnitColors;
}
// Fix references. REFERENCES GET SAVED!.
unit->Refs = savrefs;
DebugLevel3Fn("unit #%d parsed\n" _C_ slot);
return 0;

View file

@ -141,7 +141,9 @@ global void FreeUnitMemory(Unit* unit)
global void RefsIncrease(Unit* unit)
{
RefsDebugCheck(!unit->Refs || unit->Destroyed);
++unit->Refs;
if (!SaveGameLoading) {
++unit->Refs;
}
}
/**
@ -152,13 +154,15 @@ global void RefsIncrease(Unit* unit)
global void RefsDecrease(Unit* unit)
{
RefsDebugCheck(!unit->Refs);
if (unit->Destroyed) {
if (!--unit->Refs) {
ReleaseUnit(unit);
if (!SaveGameLoading) {
if (unit->Destroyed) {
if (!--unit->Refs) {
ReleaseUnit(unit);
}
} else {
--unit->Refs;
RefsDebugCheck(!unit->Refs);
}
} else {
--unit->Refs;
RefsDebugCheck(!unit->Refs);
}
}
@ -192,7 +196,7 @@ global void ReleaseUnit(Unit* unit)
if (--unit->Refs > 0) {
DebugLevel2Fn("%lu:More references of %d #%d\n" _C_ GameCycle _C_
UnitNumber(unit) _C_ unit->Refs);
UnitNumber(unit) _C_ unit->Refs);
return;
}
}
@ -217,7 +221,7 @@ global void ReleaseUnit(Unit* unit)
unit->Next = 0;
ReleasedTail = &unit->Next;
unit->Refs = GameCycle + NetworkMaxLag; // could be reuse after this time
unit->Refs = GameCycle + (NetworkMaxLag << 1); // could be reuse after this time
DebugLevel2Fn("%lu:No more references, only wait for network lag, unit %d\n" _C_
GameCycle _C_ UnitNumber(unit));
unit->Type = 0; // for debugging.
@ -285,13 +289,8 @@ global void InitUnit(Unit* unit, UnitType* type)
DebugCheck(!type);
// Refs need to be *increased* by 1, not *set* to 1, because if InitUnit()
// is called from game loading code, Refs can already have a nonzero
// value (thanks to forward references in the save file). Incrementing
// should not matter during in-game unit creation because in that case
// Refs is 0 anyway.
++unit->Refs;
// Set refs to 1. This is the "I am alive ref", lost in ReleaseUnit.
unit->Refs = 1;
//
// Build all unit table
@ -3073,7 +3072,7 @@ global void HitUnit(Unit* attacker, Unit* target, int damage)
0, 0);
missile->SourceUnit = target;
target->Burning = 1;
target->Refs++;
RefsIncrease(target);
}
}

View file

@ -1635,7 +1635,7 @@ local void DrawInformations(const Unit* unit, const UnitType* type, int x, int y
const UnitStats* stats;
int r;
#if 1 // This is for showing vis counts and refs.
#if 0 // 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',