16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-20 12:39:17 +02:00
Files
maszyna/eu07-parser/include/eu07/scene/cursor.hpp
maj00r beacc00932 Add headless parallel eu7v2 scenario bake with streaming and PLCE placements
Enable --eu7v2-bake from the main binary: parallel module pool, bounded-RAM
spool flush, streaming terrain triangles, flat include/model parsing, and
eu7v2 emit/load with optional verify. Large placement .scm files emit lean
PLCE records and bake referenced .inc modules separately for reuse.

- CLI: --eu7v2-bake, --eu7v2-verify, --eu7v2-mem-limit-gb, --eu7v2-threads,
  --eu7v2-max-parse; wire max_threads through to the bake parser
- eu7v2 v2 records: PLCE placements, runtime emitter/loader, batch verify
- Parallel bake pool with session cache; drop heavy-serial parse gate in spool
  mode; parse concurrency matches thread count
- Streaming terrain: batched parallel parse+bake, scan/bake pipeline, shape
  spool with persistent buffered I/O and flush-before-read
- Parallel flat-file streaming for models/includes; pack/model spool for
  low-memory incremental flush
- Optional 50 GB private-bytes guard during headless bake

Braniewo_szeroki: 160 modules, verify PASS, ~34s bake (nmt100 ~17s vs ~190s
serial baseline).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-17 21:15:42 +02:00

63 lines
1.7 KiB
C++

#pragma once
#include <eu07/parser.hpp>
#include <cstddef>
#include <stdexcept>
#include <string_view>
#include <vector>
namespace eu07::scene {
class TokenStream {
public:
explicit TokenStream(const std::vector<SourceToken>& tokens) noexcept
: tokens_(&tokens) {}
[[nodiscard]] bool empty() const noexcept { return index_ >= tokens_->size(); }
[[nodiscard]] const SourceToken& peek() const {
if (empty()) {
throw std::runtime_error("TokenStream: koniec strumienia");
}
return (*tokens_)[index_];
}
// Returns a reference into the underlying token vector (which outlives the
// stream), so callers that only read a field (e.g. .sourceLine) or bind to
// const& pay no per-token std::string copy. Callers that need an owning
// copy still get one via copy-initialisation, exactly as before.
[[nodiscard]] const SourceToken& consume() {
const SourceToken& token = peek();
++index_;
return token;
}
void skip(const std::size_t count = 1) {
if (index_ + count > tokens_->size()) {
throw std::runtime_error("TokenStream: przekroczenie konca");
}
index_ += count;
}
[[nodiscard]] std::size_t index() const noexcept { return index_; }
[[nodiscard]] std::size_t remaining() const noexcept {
return tokens_->size() - index_;
}
[[nodiscard]] bool peekIs(const std::string_view keyword) const {
return !empty() && peek().value == keyword;
}
[[nodiscard]] std::size_t checkpoint() const noexcept { return index_; }
void rewind(const std::size_t position) { index_ = position; }
private:
const std::vector<SourceToken>* tokens_;
std::size_t index_ = 0;
};
} // namespace eu07::scene