Changeset - r6108:580a9fc2a546
[Not reviewed]
master
0 3 0
Darkvater - 17 years ago 2007-02-22 16:16:44
darkvater@openttd.org
(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
3 files changed with 15 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/newgrf_config.cpp
Show inline comments
 
@@ -169,31 +169,31 @@ static void RemoveDuplicatesFromGRFConfi
 
 * @param dst the head of the list to add to
 
 */
 
void AppendStaticGRFConfigs(GRFConfig **dst)
 
{
 
	GRFConfig **tail = dst;
 
	while (*tail != NULL) tail = &(*tail)->next;
 

	
 
	CopyGRFConfigList(tail, _grfconfig_static);
 
	RemoveDuplicatesFromGRFConfigList(*dst);
 
}
 

	
 
/** Appends an element to a list of GRFs
 
 * @param dst the head of the list to add to
 
 * @param el the element that is being added (as a copy) */
 
void AppendToGRFConfigList(GRFConfig **dst, const GRFConfig *el)
 
 * @param dst the head of the list to add to */
 
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
 
{
 
	GRFConfig **tail = dst;
 
	while (*tail != NULL) tail = &(*tail)->next;
 
	CopyGRFConfigList(tail, el);
 
	*tail = el;
 

	
 
	RemoveDuplicatesFromGRFConfigList(*dst);
 
}
 

	
 

	
 
/* Reset the current GRF Config to either blank or newgame settings */
 
void ResetGRFConfig(bool defaults)
 
{
 
	GRFConfig **c = &_grfconfig;
 

	
 
	if (defaults) {
 
		c = CopyGRFConfigList(c, _grfconfig_newgame);
 
	} else {
 
@@ -442,42 +442,40 @@ char *GRFBuildParamList(char *dst, const
 
static const SaveLoad _grfconfig_desc[] = {
 
	SLE_STR(GRFConfig, filename,   SLE_STR, 0x40),
 
	SLE_VAR(GRFConfig, grfid,      SLE_UINT32),
 
	SLE_ARR(GRFConfig, md5sum,     SLE_UINT8, 16),
 
	SLE_ARR(GRFConfig, param,      SLE_UINT32, 0x80),
 
	SLE_VAR(GRFConfig, num_params, SLE_UINT8),
 
	SLE_END()
 
};
 

	
 

	
 
static void Save_NGRF(void)
 
{
 
	GRFConfig *c;
 
	int index = 0;
 

	
 
	for (c = _grfconfig; c != NULL; c = c->next) {
 
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
 
		if (HASBIT(c->flags, GCF_STATIC)) continue;
 
		SlSetArrayIndex(index++);
 
		SlObject(c, _grfconfig_desc);
 
	}
 
}
 

	
 

	
 
static void Load_NGRF(void)
 
{
 
	GRFConfig c;
 
	memset(&c, 0, sizeof(GRFConfig));
 

	
 
	ClearGRFConfigList(&_grfconfig);
 
	while (SlIterateArray() != -1) {
 
		SlObject(&c, _grfconfig_desc);
 
		AppendToGRFConfigList(&_grfconfig, &c);
 
		GRFConfig *c = CallocT<GRFConfig>(1);
 
		SlObject(c, _grfconfig_desc);
 
		AppendToGRFConfigList(&_grfconfig, c);
 
	}
 

	
 
	/* Append static NewGRF configuration */
 
	AppendStaticGRFConfigs(&_grfconfig);
 
}
 

	
 
extern const ChunkHandler _newgrf_chunk_handlers[] = {
 
	{ 'NGRF', Save_NGRF, Load_NGRF, CH_ARRAY | CH_LAST }
 
};
 

	
 

	
src/newgrf_config.h
Show inline comments
 
@@ -41,25 +41,25 @@ extern GRFConfig *_grfconfig;
 

	
 
/* First item in list of default GRF set up */
 
extern GRFConfig *_grfconfig_newgame;
 

	
 
/* First item in list of static GRF set up */
 
extern GRFConfig *_grfconfig_static;
 

	
 
void ScanNewGRFFiles(void);
 
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum = NULL);
 
GRFConfig *GetGRFConfig(uint32 grfid);
 
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src);
 
void AppendStaticGRFConfigs(GRFConfig **dst);
 
void AppendToGRFConfigList(GRFConfig **dst, const GRFConfig *el);
 
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
 
void ClearGRFConfig(GRFConfig **config);
 
void ClearGRFConfigList(GRFConfig **config);
 
void ResetGRFConfig(bool defaults);
 
GCF_Flags IsGoodGRFConfigList(void);
 
bool FillGRFDetails(GRFConfig *config, bool is_static);
 
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
 

	
 
/* In newgrf_gui.c */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
 

	
 
#ifdef ENABLE_NETWORK
 
/* For communication about GRFs over the network */
src/oldloader.cpp
Show inline comments
 
@@ -1358,36 +1358,34 @@ static bool LoadTTDPatchExtraChunks(Load
 
		uint16 id = ReadUint16(ls);
 
		uint32 len = ReadUint32(ls);
 

	
 
		switch (id) {
 
			/* List of GRFIDs, used in the savegame. 0x8004 is the new ID
 
			 * They are saved in a 'GRFID:4 active:1' format, 5 bytes for each entry */
 
			case 0x2:
 
			case 0x8004: {
 
				/* Skip the first element: TTDP hack for the Action D special variables (FFFF0000 01) */
 
				ReadUint32(ls); ReadByte(ls); len -= 5;
 

	
 
				ClearGRFConfigList(&_grfconfig);
 
				GRFConfig c;
 
				memset(&c, 0, sizeof(GRFConfig));
 

	
 
				while (len != 0) {
 
					uint32 grfid = ReadUint32(ls);
 

	
 
					if (ReadByte(ls) == 1) {
 
						c.grfid = grfid;
 
						c.filename = "TTDP game, no information";
 
						GRFConfig *c = CallocT<GRFConfig>(1);
 
						c->grfid = grfid;
 
						c->filename = strdup("TTDP game, no information");
 

	
 
						AppendToGRFConfigList(&_grfconfig, &c);
 
						DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c.grfid));
 
						AppendToGRFConfigList(&_grfconfig, c);
 
						DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c->grfid));
 
					}
 
					len -= 5;
 
				};
 

	
 
				/* Append static NewGRF configuration */
 
				AppendStaticGRFConfigs(&_grfconfig);
 
			} break;
 

	
 
			case 0x3: { /* TTDPatch version and configuration */
 
				uint32 ttdpv = ReadUint32(ls);
 
				DEBUG(oldloader, 3, "Game saved with TTDPatch version %d.%d.%d r%d", GB(ttdpv, 24, 8), GB(ttdpv, 20, 4), GB(ttdpv, 16, 4), GB(ttdpv, 0, 16));
 
				len -= 4;
0 comments (0 inline, 0 general)