mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 17:04:52 +01:00
5bb9157c10
The first rule of D4 (docs/world-format-eu07.md, section 13). basic_table keeps the order of each item: while the statements of a scenery load out of the order of the file (EU07_WORLD_REPLAY_ORDER), the place of its statement in the file (table_statement_order(), set by the loader for each statement it replays), otherwise one after the item before. A repeated name goes to the item of the later order, which with the statements loading in the order of the file is the item inserted later, as it always was; nothing changes for a load in that order. Events keep their own rule (the first one keeps the name): they are statements of the whole package, which load in the order of the file among themselves whatever order the regions take. Checked in the game (--test 120 s, seed 1, world.binary 1) on drawinowo.scn, with 35 repeated track names: replayed with the regions first and the whole package after them, the 13 physics logs are the same bit for bit as from the files, and so are the 1064 lines of the error log, the 35 repeated names among them. In the order of the file by moves on the tape too. Tests: the later item takes the name, the item of the later statement takes it while statements load out of order, an item added after the load is the newest.
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "utilities/Names.h"
|
|
|
|
#include <string>
|
|
|
|
// the table of names: a repeated name goes to the later item, and while the statements of a scenery load out of the order of the file,
|
|
// to the item of the later statement (docs/world-format-eu07.md, D4)
|
|
|
|
namespace {
|
|
|
|
struct named {
|
|
std::string label;
|
|
std::string const &name() const { return label; }
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("a repeated name goes to the item inserted later, as it always did") {
|
|
basic_table<named> table;
|
|
auto *first{new named{"tor1"}};
|
|
auto *second{new named{"tor1"}};
|
|
CHECK(table.insert(first));
|
|
CHECK_FALSE(table.insert(second));
|
|
CHECK(table.find("tor1") == second);
|
|
}
|
|
|
|
TEST_CASE("with the statements loading out of order, a repeated name goes to the item of the later statement") {
|
|
basic_table<named> table;
|
|
auto *later{new named{"tor1"}};
|
|
auto *earlier{new named{"tor1"}};
|
|
// the statement 20 of the file loads first, the statement 5 after it
|
|
table_statement_order() = 20;
|
|
CHECK(table.insert(later));
|
|
table_statement_order() = 5;
|
|
CHECK_FALSE(table.insert(earlier));
|
|
table_statement_order().reset();
|
|
CHECK(table.find("tor1") == later);
|
|
// an item added after the load, at no statement, is the newest one
|
|
auto *added{new named{"tor1"}};
|
|
CHECK_FALSE(table.insert(added));
|
|
CHECK(table.find("tor1") == added);
|
|
}
|