From cb434944885d5e5caa857deb3273712c4c223031 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 22 Apr 2012 16:28:09 +0000 Subject: [PATCH] (svn r24165) -Codechange: Split parts of static NewGRFClass::Assign() into non-static Insert(). --- src/newgrf_class.h | 2 ++ src/newgrf_class_func.h | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/newgrf_class.h b/src/newgrf_class.h index e1edefae66..df7734819d 100644 --- a/src/newgrf_class.h +++ b/src/newgrf_class.h @@ -39,6 +39,8 @@ public: uint32 global_id; ///< Global ID for class, e.g. 'DFLT', 'WAYP', etc. StringID name; ///< Name of this class. + void Insert(Tspec *spec); + static void Reset(); static Tid Allocate(uint32 global_id); static void Assign(Tspec *spec); diff --git a/src/newgrf_class_func.h b/src/newgrf_class_func.h index 0421258ecf..339e7d7a56 100644 --- a/src/newgrf_class_func.h +++ b/src/newgrf_class_func.h @@ -70,6 +70,18 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocate(uint32 global_id) return (Tid)0; } +/** + * Insert a spec into the class. + * @param spec The spec to insert. + */ +DEFINE_NEWGRF_CLASS_METHOD(void)::Insert(Tspec *spec) +{ + uint i = this->count++; + this->spec = ReallocT(this->spec, this->count); + + this->spec[i] = spec; +} + /** * Assign a spec to one of the classes. * @param spec The spec to assign. @@ -78,12 +90,7 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocate(uint32 global_id) DEFINE_NEWGRF_CLASS_METHOD(void)::Assign(Tspec *spec) { assert(spec->cls_id < Tmax); - NewGRFClass *cls = &classes[spec->cls_id]; - - uint i = cls->count++; - cls->spec = ReallocT(cls->spec, cls->count); - - cls->spec[i] = spec; + Get(spec->cls_id)->Insert(spec); } /** @@ -169,6 +176,7 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetByGrf(uint32 grfid, byte local_id, template void name::ResetClass(); \ template void name::Reset(); \ template Tid name::Allocate(uint32 global_id); \ + template void name::Insert(Tspec *spec); \ template void name::Assign(Tspec *spec); \ template NewGRFClass *name::Get(Tid cls_id); \ template uint name::GetCount(); \