mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 12:09:19 +02:00
Three things that turn out to be one thing: a session with people in it needs
to be able to say who they are, and a machine that only referees one should not
have to open a window to do it.
Names. A peer id is what the protocol addresses; "player 4" is no use to anybody
reading a lobby. CLIENT_HELLO carries a requested nickname now, and the server
decides what it actually is: trimmed of control characters and runs of spaces,
capped at 24, and made unique - two people called Marcin are two people and the
lobby has to say which is which. The result goes out as PEER_ROSTER whenever
somebody joins or leaves, and to a joining peer just before its snapshot, so the
crew section resolves to names rather than numbers. The name comes from
multiplayer.nickname in the ini or --nick on the command line, falling back to
the account name and, failing that, to the old numbering. The host is a peer
like any other here too, and registers its own name at startup.
Chat, on the key left of 1. Going up a line carries only its text: who said it
is decided by the connection it arrived on, never by the field in the packet,
which is what stops anybody putting words in anybody's mouth. The server tidies
and caps it, says it, and passes it on - a client waits to hear itself back, so
that everybody sees the conversation in the same order. While the box has the
keyboard imgui swallows the input before the driver mode sees it, so typing "d"
types "d" instead of opening the doors of whatever you are driving; that also
means the key that opened the panel cannot close it, hence escape.
And --nogui. No glfw, no window, no imgui, the null renderer, sound off, log to
the console it was started from, and nobody in a cab - the scenario is left to
its own drivers and this process is a referee rather than a participant. Every
window-dependent path is guarded on an empty window list rather than on a flag
scattered through the code, and the loop is paced at fifty steps a second
because nothing is waiting on a swapchain to slow it down. Chat lines go to the
log, which is what a machine with no window has instead of a chat panel.
eu07.exe -s scenario.scn --host 0.0.0.0:7420 --nogui --nick Dispatcher
147 lines
4.5 KiB
C++
147 lines
4.5 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();
|
|
// 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;
|
|
void
|
|
queue_quit(bool direct);
|
|
bool
|
|
is_server() const;
|
|
bool
|
|
is_client() const;
|
|
// asks the session authority to put us on the crew of given vehicle, or take us off it
|
|
void
|
|
request_vehicle_claim( network::NetworkEntityId const Entity );
|
|
void
|
|
request_vehicle_leave( network::NetworkEntityId const Entity );
|
|
// tells the network layer the scenario finished loading
|
|
void
|
|
network_scenario_loaded();
|
|
// says something to the rest of the session
|
|
void
|
|
say( std::string const &Text );
|
|
|
|
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;
|
|
// true when the run is over: the window was closed, or, with no window, we were asked
|
|
// to stop
|
|
bool should_close() 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;
|
|
// consecutive authoritative steps whose state digest did not match ours. purely a
|
|
// diagnostic: a client runs its own physics, so it is never expected to match exactly
|
|
std::uint64_t m_statemismatches { 0 };
|
|
|
|
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;
|