Changeset - r6229:a69564e4eb2e
[Not reviewed]
master
0 7 0
maedhros - 17 years ago 2007-03-06 19:33:28
maedhros@openttd.org
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
mutually exclusive. At the same time, add an INITIALISED state which makes it
possible to check if a grf is not yet active but will be later on during the
GLS_ACTIVATION loading stage.
7 files changed with 62 insertions and 49 deletions:
0 comments (0 inline, 0 general)
src/network/network_udp.cpp
Show inline comments
 
@@ -288,8 +288,8 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_U
 
		struct sockaddr_in out_addr;
 

	
 
		for (c = item->info.grfconfig; c != NULL; c = c->next) {
 
			if (HASBIT(c->flags, GCF_NOT_FOUND)) item->info.compatible = false;
 
			if (!HASBIT(c->flags, GCF_NOT_FOUND) || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
 
			if (c->status == GCS_NOT_FOUND) item->info.compatible = false;
 
			if (c->status == GCS_NOT_FOUND || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
 
			in_request[in_request_count] = c;
 
			in_request_count++;
 
		}
 
@@ -392,7 +392,7 @@ void ClientNetworkUDPSocketHandler::Hand
 
		 * already resolved name for this GRF (another server has sent the
 
		 * name of the GRF already */
 
		config->name     = FindUnknownGRFName(config->grfid, config->md5sum, true);
 
		SETBIT(config->flags, GCF_NOT_FOUND);
 
		config->status   = GCS_NOT_FOUND;
 
	} else {
 
		config->filename = f->filename;
 
		config->name     = f->name;
src/newgrf.cpp
Show inline comments
 
@@ -2535,24 +2535,24 @@ static void SkipIf(byte *buf, int len)
 
		switch (condtype) {
 
			/* Tests 6 to 10 are only for param 0x88, GRFID checks */
 
			case 6: /* Is GRFID active? */
 
				result = HASBIT(c->flags, GCF_ACTIVATED);
 
				result = c->status == GCS_ACTIVATED;
 
				break;
 

	
 
			case 7: /* Is GRFID non-active? */
 
				result = !HASBIT(c->flags, GCF_ACTIVATED);
 
				result = c->status != GCS_ACTIVATED;
 
				break;
 

	
 
			case 8: /* GRFID is not but will be active? */
 
				result = !HASBIT(c->flags, GCF_ACTIVATED) && !HASBIT(c->flags, GCF_DISABLED);
 
				result = c->status == GCS_INITIALISED;
 
				break;
 

	
 
			case 9: /* GRFID is or will be active? */
 
				result = !HASBIT(c->flags, GCF_NOT_FOUND) && !HASBIT(c->flags, GCF_DISABLED);
 
				result = c->status == GCS_ACTIVATED || c->status == GCS_INITIALISED;
 
				break;
 

	
 
			case 10: /* GRFID is not nor will be active */
 
				/* This is the only condtype that doesn't get ignored if the GRFID is not found */
 
				result = c == NULL || HASBIT(c->flags, GCF_DISABLED) || HASBIT(c->flags, GCF_NOT_FOUND);
 
				result = c == NULL || c->flags == GCS_DISABLED || c->status == GCS_NOT_FOUND;
 
				break;
 

	
 
			default: grfmsg(1, "Unsupported GRF test %d. Ignoring", condtype); return;
 
@@ -2616,7 +2616,7 @@ static void SkipIf(byte *buf, int len)
 
		_skip_sprites = -1;
 

	
 
		/* If an action 8 hasn't been encountered yet, disable the grf. */
 
		if (!HASBIT(_cur_grfconfig->flags, GCF_ACTIVATED)) SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
 
		if (_cur_grfconfig->status != GCS_ACTIVATED) _cur_grfconfig->status = GCS_DISABLED;
 
	}
 
}
 

	
 
@@ -2673,7 +2673,7 @@ static void GRFInfo(byte *buf, int len)
 

	
 
	_cur_grffile->grfid = grfid;
 
	_cur_grffile->grf_version = version;
 
	SETBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
 
	_cur_grfconfig->status = _cur_stage < GLS_ACTIVATION ? GCS_INITIALISED : GCS_ACTIVATED;
 

	
 
	/* Do swap the GRFID for displaying purposes since people expect that */
 
	DEBUG(grf, 1, "Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name);
 
@@ -2779,8 +2779,7 @@ static void GRFLoadError(byte *buf, int 
 
	} else if (severity == 3) {
 
		/* This is a fatal error, so make sure the GRF is deactivated and no
 
		 * more of it gets loaded. */
 
		SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
 
		CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
 
		_cur_grfconfig->status = GCS_DISABLED;
 

	
 
		_skip_sprites = -1;
 
	}
 
@@ -2981,8 +2980,7 @@ static void ParamSet(byte *buf, int len)
 
								if (op != 4 && op != 5) {
 
									/* Deactivate GRF */
 
									grfmsg(0, "GRM: Unable to allocate %d vehicles, deactivating", count);
 
									SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
 
									CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
 
									_cur_grfconfig->status = GCS_DISABLED;
 

	
 
									_skip_sprites = -1;
 
									return;
 
@@ -3000,8 +2998,7 @@ static void ParamSet(byte *buf, int len)
 
									/* Check if the allocated sprites will fit below the original sprite limit */
 
									if (_cur_spriteid + count >= 16384) {
 
										grfmsg(0, "GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
 
										SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
 
										CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
 
										_cur_grfconfig->status = GCS_DISABLED;
 

	
 
										_skip_sprites = -1;
 
										return;
 
@@ -3218,8 +3215,7 @@ static void GRFInhibit(byte *buf, int le
 
		/* Unset activation flag */
 
		if (file != NULL && file != _cur_grfconfig) {
 
			grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename);
 
			SETBIT(file->flags, GCF_DISABLED);
 
			CLRBIT(file->flags, GCF_ACTIVATED);
 
			file->status = GCS_DISABLED;
 
		}
 
	}
 
}
 
@@ -3950,11 +3946,9 @@ void LoadNewGRFFile(GRFConfig *config, u
 
	if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
 
		_cur_grffile = GetFileByFilename(filename);
 
		if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename);
 
		if (stage == GLS_ACTIVATION && !HASBIT(config->flags, GCF_ACTIVATED)) return;
 
		if (stage == GLS_ACTIVATION && config->status != GCS_INITIALISED) return;
 
	}
 

	
 
	if (stage == GLS_ACTIVATION) CLRBIT(config->flags, GCF_ACTIVATED);
 

	
 
	FioOpenFile(file_index, filename);
 
	_file_index = file_index; // XXX
 

	
 
@@ -4037,7 +4031,7 @@ void LoadNewGRF(uint load_index, uint fi
 
		_cur_stage = stage;
 
		_cur_spriteid = load_index;
 
		for (c = _grfconfig; c != NULL; c = c->next) {
 
			if (HASBIT(c->flags, GCF_DISABLED) || HASBIT(c->flags, GCF_NOT_FOUND)) continue;
 
			if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
 

	
 
			// TODO usererror()
 
			if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename);
src/newgrf_config.cpp
Show inline comments
 
@@ -60,7 +60,7 @@ static bool CalcGRFMD5Sum(GRFConfig *con
 
bool FillGRFDetails(GRFConfig *config, bool is_static)
 
{
 
	if (!FioCheckFileExists(config->filename)) {
 
		SETBIT(config->flags, GCF_NOT_FOUND);
 
		config->status = GCS_NOT_FOUND;
 
		return false;
 
	}
 

	
 
@@ -210,14 +210,14 @@ void ResetGRFConfig(bool defaults)
 
/** Check if all GRFs in the GRF config from a savegame can be loaded.
 
 * @return will return any of the following 3 values:<br>
 
 * <ul>
 
 * <li> GCF_ACTIVATED: No problems occured, all GRF files were found and loaded
 
 * <li> GCF_COMPATIBLE: For one or more GRF's no exact match was found, but a
 
 * <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded
 
 * <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a
 
 *     compatible GRF with the same grfid was found and used instead
 
 * <li> GCF_NOT_FOUND: For one or more GRF's no match was found at all
 
 * <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all
 
 * </ul> */
 
GCF_Flags IsGoodGRFConfigList(void)
 
GRFListCompatibility IsGoodGRFConfigList(void)
 
{
 
	GCF_Flags res = GCF_ACTIVATED;
 
	GRFListCompatibility res = GLC_ALL_GOOD;
 

	
 
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
 
		const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
 
@@ -233,7 +233,7 @@ GCF_Flags IsGoodGRFConfigList(void)
 
				SETBIT(c->flags, GCF_COMPATIBLE);
 

	
 
				/* Non-found has precedence over compatibility load */
 
				if (res != GCF_NOT_FOUND) res = GCF_COMPATIBLE;
 
				if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
 
				goto compatible_grf;
 
			}
 

	
 
@@ -241,8 +241,8 @@ GCF_Flags IsGoodGRFConfigList(void)
 
			md5sumToString(buf, lastof(buf), c->md5sum);
 
			DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf);
 

	
 
			SETBIT(c->flags, GCF_NOT_FOUND);
 
			res = GCF_NOT_FOUND;
 
			c->status = GCS_NOT_FOUND;
 
			res = GLC_NOT_FOUND;
 
		} else {
 
compatible_grf:
 
			DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename);
src/newgrf_config.h
Show inline comments
 
@@ -7,9 +7,6 @@
 

	
 
/* GRF config bit flags */
 
typedef enum {
 
	GCF_DISABLED,  ///< GRF file is disabled
 
	GCF_NOT_FOUND, ///< GRF file was not found in the local cache
 
	GCF_ACTIVATED, ///< GRF file is active
 
	GCF_SYSTEM,    ///< GRF file is an openttd-internal system grf
 
	GCF_UNSAFE,    ///< GRF file is unsafe for static usage
 
	GCF_STATIC,    ///< GRF file is used statically (can be used in any MP game)
 
@@ -17,6 +14,20 @@ typedef enum {
 
	GCF_COPY,      ///< The data is copied from a grf in _all_grfs
 
} GCF_Flags;
 

	
 
typedef enum {
 
	GCS_UNKNOWN,      ///< The status of this grf file is unknown
 
	GCS_DISABLED,     ///< GRF file is disabled
 
	GCS_NOT_FOUND,    ///< GRF file was not found in the local cache
 
	GCS_INITIALISED,  ///< GRF file has been initialised
 
	GCS_ACTIVATED     ///< GRF file has been activated
 
} GRFStatus;
 

	
 
typedef enum {
 
	GLC_ALL_GOOD,
 
	GLC_COMPATIBLE,
 
	GLC_NOT_FOUND
 
} GRFListCompatibility;
 

	
 
typedef struct GRFIdentifier {
 
	uint32 grfid;
 
	uint8 md5sum[16];
 
@@ -37,6 +48,7 @@ typedef struct GRFConfig : public GRFIde
 
	GRFError *error;
 

	
 
	uint8 flags;
 
	GRFStatus status;
 
	uint32 param[0x80];
 
	uint8 num_params;
 

	
 
@@ -64,7 +76,7 @@ void AppendToGRFConfigList(GRFConfig **d
 
void ClearGRFConfig(GRFConfig **config);
 
void ClearGRFConfigList(GRFConfig **config);
 
void ResetGRFConfig(bool defaults);
 
GCF_Flags IsGoodGRFConfigList(void);
 
GRFListCompatibility IsGoodGRFConfigList(void);
 
bool FillGRFDetails(GRFConfig *config, bool is_static);
 
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
 

	
src/newgrf_gui.cpp
Show inline comments
 
@@ -91,8 +91,8 @@ static void ShowNewGRFInfo(const GRFConf
 
	}
 

	
 
	/* Show flags */
 
	if (HASBIT(c->flags, GCF_NOT_FOUND))  y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w);
 
	if (HASBIT(c->flags, GCF_DISABLED))   y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w);
 
	if (c->status == GCS_NOT_FOUND)        y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w);
 
	if (c->status == GCS_DISABLED)         y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w);
 
	if (HASBIT(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w);
 

	
 
	/* Draw GRF info if it exists */
 
@@ -335,16 +335,23 @@ static void NewGRFWndProc(Window *w, Win
 
					SpriteID pal;
 

	
 
					/* Pick a colour */
 
					if (HASBIT(c->flags, GCF_NOT_FOUND) || HASBIT(c->flags, GCF_DISABLED)) {
 
						pal = PALETTE_TO_RED;
 
					} else if (HASBIT(c->flags, GCF_STATIC)) {
 
					switch (c->status) {
 
						case GCS_NOT_FOUND:
 
						case GCS_DISABLED:
 
							pal = PALETTE_TO_RED;
 
							break;
 
						case GCS_ACTIVATED:
 
							pal = PALETTE_TO_GREEN;
 
							break;
 
						default:
 
							pal = PALETTE_TO_BLUE;
 
							break;
 
					}
 

	
 
					if (HASBIT(c->flags, GCF_STATIC)) {
 
						pal = PALETTE_TO_GREY;
 
					} else if (HASBIT(c->flags, GCF_COMPATIBLE)) {
 
						pal = PALETTE_TO_ORANGE;
 
					} else if (HASBIT(c->flags, GCF_ACTIVATED)) {
 
						pal = PALETTE_TO_GREEN;
 
					} else {
 
						pal = PALETTE_TO_BLUE;
 
					}
 

	
 
					DrawSprite(SPR_SQUARE, pal, 5, y + 2);
src/openttd.cpp
Show inline comments
 
@@ -1209,12 +1209,12 @@ bool AfterLoadGame(void)
 
	if (_opt.road_side) _opt.road_side = 1;
 

	
 
	/* Check if all NewGRFs are present, we are very strict in MP mode */
 
	GCF_Flags gcf_res = IsGoodGRFConfigList();
 
	if (_networking && gcf_res != GCF_ACTIVATED) return false;
 
	GRFListCompatibility gcf_res = IsGoodGRFConfigList();
 
	if (_networking && gcf_res != GLC_ALL_GOOD) return false;
 

	
 
	switch (gcf_res) {
 
		case GCF_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break;
 
		case GCF_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break;
 
		case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break;
 
		case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break;
 
		default: break;
 
	}
 

	
src/settings.cpp
Show inline comments
 
@@ -1530,7 +1530,7 @@ static GRFConfig *GRFLoadConfig(IniFile 
 
		if (!FillGRFDetails(c, is_static)) {
 
			const char *msg;
 

	
 
			if (HASBIT(c->flags, GCF_NOT_FOUND)) {
 
			if (c->status == GCS_NOT_FOUND) {
 
				msg = "not found";
 
			} else if (HASBIT(c->flags, GCF_UNSAFE)) {
 
				msg = "unsafe for static use";
0 comments (0 inline, 0 general)