diff options
author | Darkvater <darkvater@openttd.org> | 2007-02-18 22:37:33 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2007-02-18 22:37:33 +0000 |
commit | 6d4d0720234d495aafe0c4e738166dbc1546a6c4 (patch) | |
tree | ca35c1232210af03e01d5af5ef3885f5f501e743 /src | |
parent | b260be6e2a7391cc0b33bc9ca96b1f7cf02af05b (diff) | |
download | openttd-6d4d0720234d495aafe0c4e738166dbc1546a6c4.tar.xz |
(svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_config.cpp | 28 | ||||
-rw-r--r-- | src/newgrf_config.h | 1 |
2 files changed, 16 insertions, 13 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 877d05981..24d9727ff 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -115,7 +115,7 @@ void ClearGRFConfigList(GRFConfig **config) /** Copy a GRF Config list * @param dst pointer to destination list - * @param srt pointer to source list values + * @param src pointer to source list values * @return pointer to the last value added to the destination list */ GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src) { @@ -179,6 +179,17 @@ void AppendStaticGRFConfigs(GRFConfig **dst) 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) +{ + GRFConfig **tail = dst; + while (*tail != NULL) tail = &(*tail)->next; + CopyGRFConfigList(tail, el); + RemoveDuplicatesFromGRFConfigList(*dst); +} + /* Reset the current GRF Config to either blank or newgame settings */ void ResetGRFConfig(bool defaults) @@ -454,23 +465,14 @@ static void Save_NGRF(void) static void Load_NGRF(void) { - GRFConfig *first = NULL; - GRFConfig **last = &first; - + GRFConfig *c = CallocT<GRFConfig>(1); while (SlIterateArray() != -1) { - GRFConfig *c = CallocT<GRFConfig>(1); SlObject(c, _grfconfig_desc); - - /* Append our configuration to the list */ - *last = c; - last = &c->next; + AppendToGRFConfigList(&_grfconfig, c); } + free(c); /* Append static NewGRF configuration */ - CopyGRFConfigList(last, _grfconfig_static); - - ClearGRFConfigList(&_grfconfig); - _grfconfig = first; AppendStaticGRFConfigs(&_grfconfig); } diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 38c1e4a46..97104d934 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -49,6 +49,7 @@ 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 ClearGRFConfig(GRFConfig **config); void ClearGRFConfigList(GRFConfig **config); void ResetGRFConfig(bool defaults); |