Skip to content

Commit

Permalink
organize all available statetype variables in a states[] array (#17)
Browse files Browse the repository at this point in the history
* organize all available statetype variables in a states[] array

This replaces the current relying on a specific order in which global variables
are stored in the executable for e.g. saving and restoring of savegames and thus
does not require the -fno-toplevel-reorder compiler flag anymore.

Fixes #15.

* add the files containing the states[] array

* simplify pointer arithmetics in SaveTheGame()/LoadTheGame()

* display a message and quit the game when an invalid savegame is loaded

There is currently no other way to "unload" the savegame.

* back to main menu on failure instead of quitting

* add copyright headers to newly added files

* prevent crashes for subsequent games when loading invalid savegame

* add some minimalistic comments
  • Loading branch information
fabiangreffrath authored Jul 13, 2020
1 parent e1fe31c commit f7e2b2c
Show file tree
Hide file tree
Showing 10 changed files with 1,156 additions and 1,473 deletions.
14 changes: 1 addition & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ CFLAGS += -Wreturn-type
CFLAGS += -Wwrite-strings
CFLAGS += -Wcast-align

# In contrast to Doom, which has all its possible game states
# enumerated and stored in a single huge info.c:states[] array, the
# Wolf3d engine has them as global variables in wl_act2.cpp. The
# savegame code relies on the order of these variables remaining
# constant in the executable and the difference of these variables'
# addresses relative to a certain reference as well. This should be a
# valid assumption for a given executable, but might change when the
# code is compiled again - turning the savegames saved wit the prior
# compilate useless. This compiler flag prevents the reordering of the
# global variables and thus keeps savegames functional across engine
# rebuilds.
CFLAGS += -fno-toplevel-reorder


CCFLAGS += $(CFLAGS)
CCFLAGS += -std=gnu99
Expand Down Expand Up @@ -79,6 +66,7 @@ SRCS += wl_parallax.cpp
SRCS += wl_play.cpp
SRCS += wl_state.cpp
SRCS += wl_text.cpp
SRCS += states.cpp

DEPS = $(filter %.d, $(SRCS:.c=.d) $(SRCS:.cpp=.d))
OBJS = $(filter %.o, $(SRCS:.c=.o) $(SRCS:.cpp=.o))
Expand Down
515 changes: 515 additions & 0 deletions states.cpp

Large diffs are not rendered by default.

Loading

0 comments on commit f7e2b2c

Please sign in to comment.