Skip to content

Commit

Permalink
Immediately mark objects as destroyed in save
Browse files Browse the repository at this point in the history
Obsoletes SHOW_FLAG_DESTROYED except as a flag in the save file.
  • Loading branch information
dscharrer committed Nov 11, 2013
1 parent 4ec4181 commit c116db5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/ai/Paths.cpp
Expand Up @@ -208,13 +208,14 @@ void ARX_PATH_UpdateAllZoneInOutInside() {
for(long tt = 0; tt < f; tt++) {
long i = count;
Entity * io = entities[i];


if(count < entities.size()
&& io
&& io->ioflags & (IO_NPC | IO_ITEM)
&& io->show != SHOW_FLAG_MEGAHIDE
&& io->show != SHOW_FLAG_DESTROYED
) {
arx_assert(io->show != SHOW_FLAG_DESTROYED);
ARX_PATH * p = ARX_PATH_CheckInZone(io);
ARX_PATH * op = io->inzone;

Expand Down
34 changes: 17 additions & 17 deletions src/game/Entity.cpp
Expand Up @@ -63,6 +63,7 @@ ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.

#include "gui/Interface.h"

#include "scene/ChangeLevel.h"
#include "scene/GameSound.h"
#include "scene/Interactive.h"
#include "scene/Light.h"
Expand Down Expand Up @@ -315,18 +316,6 @@ void Entity::cleanReferences() {
}
gameFlags &= ~GFLAG_ISINTREATZONE;

if(obj) {
while(obj->nblinked) {
if(obj->linked[0].lgroup != -1 && obj->linked[0].obj) {
Entity * linked = obj->linked[0].io;
if(linked && ValidIOAddress(linked)) {
EERIE_LINKEDOBJ_UnLinkObjectFromObject(obj, linked->obj);
linked->destroy();
}
}
}
}

ARX_INTERACTIVE_DestroyDynamicInfo(this);

RemoveFromAllInventories(this);
Expand All @@ -347,13 +336,24 @@ void Entity::cleanReferences() {

void Entity::destroy() {

if(scriptload) {
delete this;
} else {
show = SHOW_FLAG_DESTROYED;
cleanReferences();
if(!scriptload) {
currentSavedGameStoreEntityDeletion(long_name());
}

if(obj) {
while(obj->nblinked) {
if(obj->linked[0].lgroup != -1 && obj->linked[0].obj) {
Entity * linked = obj->linked[0].io;
if(linked && ValidIOAddress(linked)) {
EERIE_LINKEDOBJ_UnLinkObjectFromObject(obj, linked->obj);
linked->destroy();
}
}
}
}

delete this;

}

void Entity::destroyOne() {
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entity.h
Expand Up @@ -216,7 +216,7 @@ enum EntityVisilibity {
SHOW_FLAG_KILLED = 7, // Deprecated, use SHOW_FLAG_DESTROYED instead
SHOW_FLAG_MEGAHIDE = 8,
SHOW_FLAG_ON_PLAYER = 9,
SHOW_FLAG_DESTROYED = 255
SHOW_FLAG_DESTROYED = 255 // Only used in save files
};

struct AnimationBlendStatus {
Expand Down
2 changes: 1 addition & 1 deletion src/game/NPC.cpp
Expand Up @@ -976,13 +976,13 @@ void ARX_PHYSICS_Apply() {
ARX_NPC_ManagePoison(io);

if((io->ioflags & IO_ITEM)
&& (io->show != SHOW_FLAG_DESTROYED)
&& (io->gameFlags & GFLAG_GOREEXPLODE)
&& float(arxtime) - io->animBlend.lastanimtime > 300
&& io->obj
&& !io->obj->vertexlist.empty()
)
{
arx_assert(io->show != SHOW_FLAG_DESTROYED);
long cnt = (io->obj->vertexlist.size() << 12) + 1;

cnt = clamp(cnt, 2, 10);
Expand Down
13 changes: 10 additions & 3 deletions src/scene/ChangeLevel.cpp
Expand Up @@ -262,13 +262,18 @@ bool currentSavedGameHasEntity(const std::string & ident) {
if(pSaveBlock) {
return pSaveBlock->hasFile(ident);
} else {
LogError << "Tried to access the current saved game state before a game was started";
ARX_DEAD_CODE();
return false;
}
}

void currentSavedGameStoreEntityDeletion(const std::string & idString) {

if(!pSaveBlock) {
ARX_DEAD_CODE();
return;
}

// Save a minimal entity save file containing just enough info so we know not to load it
ARX_CHANGELEVEL_IO_SAVE ais;
memset(&ais, 0, sizeof(ARX_CHANGELEVEL_IO_SAVE));
Expand Down Expand Up @@ -481,8 +486,7 @@ static bool ARX_CHANGELEVEL_Push_Index(long num) {
if(entities[i] != NULL
&& !(entities[i]->ioflags & IO_NOSAVE)
&& !IsInPlayerInventory(entities[i])
&& !IsPlayerEquipedWith(entities[i])
&& (entities[i]->show != SHOW_FLAG_DESTROYED)) {
&& !IsPlayerEquipedWith(entities[i])) {
ARX_CHANGELEVEL_IO_INDEX aii;
memset(&aii, 0, sizeof(aii));
strncpy(aii.filename,
Expand Down Expand Up @@ -881,6 +885,9 @@ static long ARX_CHANGELEVEL_Push_IO(const Entity * io, long level) {
return -1;
}

arx_assert(io->show != SHOW_FLAG_DESTROYED);
arx_assert(io->show != SHOW_FLAG_KILLED);

// Sets Savefile Name
string savefile = io->long_name();

Expand Down
5 changes: 1 addition & 4 deletions src/script/ScriptEvent.cpp
Expand Up @@ -180,10 +180,7 @@ static bool checkInteractiveObject(Entity * io, ScriptMessage msg, ScriptResult
return true;
}

if(io->show == SHOW_FLAG_DESTROYED) {
ret = ACCEPT;
return true;
}
arx_assert(io->show != SHOW_FLAG_DESTROYED);

if(io->ioflags & IO_FREEZESCRIPT) {
ret = (msg == SM_LOAD) ? ACCEPT : REFUSE;
Expand Down

0 comments on commit c116db5

Please sign in to comment.