From 2c941cd8b3cb1774f4982b86735e276597a91750 Mon Sep 17 00:00:00 2001 From: glx22 Date: Mon, 7 Jun 2021 23:24:37 +0200 Subject: Codechange: Use ChunkHandlers sub-classes --- src/saveload/goal_sl.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/saveload/goal_sl.cpp') diff --git a/src/saveload/goal_sl.cpp b/src/saveload/goal_sl.cpp index 2dac477d0..ae6b8577b 100644 --- a/src/saveload/goal_sl.cpp +++ b/src/saveload/goal_sl.cpp @@ -25,28 +25,32 @@ static const SaveLoad _goals_desc[] = { SLE_CONDVAR(Goal, completed, SLE_BOOL, SLV_182, SL_MAX_VERSION), }; -static void Save_GOAL() -{ - SlTableHeader(_goals_desc); +struct GOALChunkHandler : ChunkHandler { + GOALChunkHandler() : ChunkHandler('GOAL', CH_TABLE) {} - for (Goal *s : Goal::Iterate()) { - SlSetArrayIndex(s->index); - SlObject(s, _goals_desc); + void Save() const override + { + SlTableHeader(_goals_desc); + + for (Goal *s : Goal::Iterate()) { + SlSetArrayIndex(s->index); + SlObject(s, _goals_desc); + } } -} -static void Load_GOAL() -{ - const std::vector slt = SlCompatTableHeader(_goals_desc, _goals_sl_compat); + void Load() const override + { + const std::vector slt = SlCompatTableHeader(_goals_desc, _goals_sl_compat); - int index; - while ((index = SlIterateArray()) != -1) { - Goal *s = new (index) Goal(); - SlObject(s, slt); + int index; + while ((index = SlIterateArray()) != -1) { + Goal *s = new (index) Goal(); + SlObject(s, slt); + } } -} +}; -static const ChunkHandler GOAL{ 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_TABLE }; +static const GOALChunkHandler GOAL; static const ChunkHandlerRef goal_chunk_handlers[] = { GOAL, }; -- cgit v1.2.3-54-g00ecf