object deletion during save operations

Not sure why my earlier attempt was unsuccessful.  This one isn't as
comprehensive but is simpler and better yet, works as intended.

When saving a level or exiting the program, objects can be deleted
directly rather than having to pass though the objs_deleted list.
This commit is contained in:
PatR
2025-04-17 16:59:49 -07:00
parent 8b7cbbdb0f
commit 07b59e783e
3 changed files with 12 additions and 4 deletions
+1
View File
@@ -794,6 +794,7 @@ struct sinfo {
int exiting; /* an exit handler is executing */ int exiting; /* an exit handler is executing */
int saving; /* creating a save file */ int saving; /* creating a save file */
int restoring; /* reloading a save file */ int restoring; /* reloading a save file */
int freeingdata; /* in saveobjchn(), mode FREEING */
int in_getlev; /* in getlev() */ int in_getlev; /* in getlev() */
int in_moveloop; /* normal gameplay in progress */ int in_moveloop; /* normal gameplay in progress */
int in_impossible; /* reporting a warning */ int in_impossible; /* reporting a warning */
+9 -4
View File
@@ -2739,10 +2739,15 @@ dealloc_obj(struct obj *obj)
obj->where = OBJ_LUAFREE; obj->where = OBJ_LUAFREE;
return; return;
} }
/* mark object as deleted, put it into queue to be freed */ if (!program_state.freeingdata) {
obj->where = OBJ_DELETED; /* mark object as deleted, put it into queue to be freed */
obj->nobj = go.objs_deleted; obj->where = OBJ_DELETED;
go.objs_deleted = obj; obj->nobj = go.objs_deleted;
go.objs_deleted = obj;
} else {
/* when saving, there's no need to stage deletions on objs_deleted */
dealloc_obj_real(obj);
}
} }
/* actually deallocate the object */ /* actually deallocate the object */
+2
View File
@@ -853,7 +853,9 @@ saveobjchn(NHFILE *nhfp, struct obj **obj_p)
setworn((struct obj *) 0, setworn((struct obj *) 0,
otmp->owornmask & (W_BALL | W_CHAIN)); otmp->owornmask & (W_BALL | W_CHAIN));
otmp->owornmask = 0L; /* no longer care */ otmp->owornmask = 0L; /* no longer care */
program_state.freeingdata++;
dealloc_obj(otmp); dealloc_obj(otmp);
program_state.freeingdata--;
} }
otmp = otmp2; otmp = otmp2;
} }