16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00
Files
maszyna/application/application.h
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

139 lines
4.1 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "application/applicationmode.h"
#include "scripting/PyInt.h"
#include "network/manager.h"
#include "utilities/headtrack.h"
#ifdef WITH_UART
#include "utilities/uart.h"
#endif
class eu07_application {
const int MAX_NETWORK_PER_FRAME = 1000;
public:
// types
enum mode {
launcher = 0,
scenarioloader,
driver,
editor,
count_
};
// constructors
eu07_application() = default;
// methods
int
init( int Argc, char *Argv[] );
int
run();
// Headless text -> eu7v2 bake (+optional roundtrip verify). Runs without a
// window / renderer / audio. Returns a process exit code (0 == OK).
static bool
wants_eu7v2_headless( int Argc, char *Argv[] );
static int
run_eu7v2_headless( int Argc, char *Argv[] );
// issues request for a worker thread to perform specified task. returns: true if task was scheduled
#ifdef WITH_DISCORD_RPC
void DiscordRPCService(); // discord rich presence service function (runs as separate thread)
#endif
bool
request( python_taskqueue::task_request const &Task );
// ensures the main thread holds the python gil and can safely execute python calls
void
acquire_python_lock();
// frees the python gil and swaps out the main thread
void
release_python_lock();
void
exit();
void
render_ui();
void
begin_ui_frame();
// switches application to specified mode
bool
pop_mode();
bool
push_mode( eu07_application::mode const Mode );
void
set_title( std::string const &Title );
void
set_progress( float const Progress = 0.f, float const Subtaskprogress = 0.f );
void
set_tooltip( std::string const &Tooltip );
void
set_cursor( int const Mode );
void
set_cursor_pos( double const Horizontal, double const Vertical );
void queue_screenshot();
// input handlers
void on_key( int const Key, int const Scancode, int const Action, int const Mods );
void on_char( unsigned int const Char );
void on_cursor_pos( double const Horizontal, double const Vertical );
void on_mouse_button( int const Button, int const Action, int const Mods );
void on_scroll( double const Xoffset, double const Yoffset );
void on_focus_change(bool focus);
void on_window_resize(int w, int h);
// gives access to specified window, creates a new window if index == -1
GLFWwindow *
window( int const Windowindex = 0, bool visible = false, int width = 1, int height = 1, GLFWmonitor *monitor = nullptr, bool keep_ownership = true, bool share_ctx = true );
GLFWmonitor * find_monitor( const std::string &str ) const;
std::string describe_monitor( GLFWmonitor *monitor ) const;
// generate network sync verification number
double
generate_sync();
void
queue_quit(bool direct);
bool
is_server() const;
bool
is_client() const;
private:
// types
using modeptr_array = std::array<std::shared_ptr<application_mode>, static_cast<std::size_t>( mode::count_ )>;
using mode_stack = std::stack<mode>;
// methods
bool needs_ogl() const;
void init_debug();
void init_console();
void init_files();
int init_settings( int Argc, char *Argv[] );
int init_locale();
int init_glfw();
void init_callbacks();
int init_ogl();
int init_ui();
int init_gfx();
int init_audio();
int init_data();
int init_modes();
bool init_network();
int run_crashgui();
// members
bool m_screenshot_queued = false;
modeptr_array m_modes { nullptr }; // collection of available application behaviour modes
mode_stack m_modestack; // current behaviour mode
python_taskqueue m_taskqueue;
std::vector<GLFWwindow *> m_windows;
int m_glfwversion;
std::optional<network::manager> m_network;
std::optional<headtrack> m_headtrack;
};
extern eu07_application Application;