18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 06:35:21 +01:00

Merge branch 'feat/world-sections' into feat/world-unbounded

This commit is contained in:
maj00r
2026-12-03 02:13:35 +01:00
3 changed files with 71 additions and 2 deletions
+3
View File
@@ -341,9 +341,12 @@ state_serializer::deserialize_ordered( deserializer_state &State, std::chrono::s
auto const end { index + 1 < statements.size() ? statements[ index + 1 ].offset : State.tape.size() - 1 };
State.replayer.seek( static_cast<std::size_t>( item.offset ), static_cast<std::size_t>( end ), item.start, State.tapefiles );
restore_transformations( State.scratchpad.location, State.replaytable.contexts[ item.context ] );
// a repeated name goes to the item of the later statement in the file, whatever the order they load in (D4)
table_statement_order() = index;
if( auto const token { State.input.getToken<std::string>() }; false == token.empty() ) {
deserialize_statement( State, token );
}
table_statement_order().reset();
if( std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::steady_clock::now() - Started ).count() >= 200 ) {
Application.set_progress( static_cast<int>( 100 * State.ordercursor / State.order.size() ), static_cast<int>( 100 * State.ordercursor / State.order.size() ) );
return true;
+43
View File
@@ -0,0 +1,43 @@
#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);
}
+25 -2
View File
@@ -12,6 +12,18 @@ http://mozilla.org/MPL/2.0/.
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cstdint>
#include <optional>
#include <vector>
// the place in the scenery file of the statement being loaded, while the statements of a scenery load in another order than the
// file's (docs/world-format-eu07.md, D4): a repeated name then goes to the item of the later statement, as a load in the order of the
// file gives it, whatever order the statements load in. none otherwise: the item inserted later takes the name, as it always did
inline std::optional<std::uint64_t> &
table_statement_order() {
static std::optional<std::uint64_t> order;
return order;
}
template <typename Type_>
class basic_table {
@@ -27,6 +39,11 @@ public:
bool
insert( Type_ *Item, std::string itemname ) {
m_items.emplace_back( Item );
// the order of the item: its statement in the file while statements load out of order, after every item before otherwise
auto const order { table_statement_order().value_or( m_lastorder + 1 ) };
m_lastorder = std::max( m_lastorder, order );
m_orders.resize( m_items.size(), 0 );
m_orders.back() = order;
if( true == itemname.empty() || itemname == "none" ) {
return true;
}
@@ -36,8 +53,11 @@ public:
if( true == mapping.second ) {
return true;
}
// item with this name already exists; update mapping to point to the new one, for backward compatibility
mapping.first->second = itemhandle;
// item with this name already exists; update mapping to point to the later one, for backward compatibility. with the
// statements loading in the order of the file the later one is the one inserted now, as it always was
if( order >= m_orders[ mapping.first->second ] ) {
mapping.first->second = itemhandle;
}
return false; }
bool insert (Type_ *Item)
{
@@ -117,6 +137,9 @@ protected:
// members
type_sequence m_items;
index_map m_itemmap;
// the order of each item, and the latest one, see insert()
std::vector<std::uint64_t> m_orders;
std::uint64_t m_lastorder { 0 };
public:
// data access