mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
work
This commit is contained in:
@@ -119,6 +119,7 @@ set(SOURCES
|
||||
"network/message.cpp"
|
||||
"network/manager.cpp"
|
||||
"network/backend/asio.cpp"
|
||||
"network/backend/file.cpp"
|
||||
|
||||
"widgets/vehiclelist.cpp"
|
||||
|
||||
|
||||
@@ -317,8 +317,8 @@ void command_queue::push_commands(const commands_map &commands) {
|
||||
}
|
||||
|
||||
void
|
||||
command_relay::post( user_command const Command, double const Param1, double const Param2,
|
||||
int const Action, uint16_t Recipient) const {
|
||||
command_relay::post(user_command const Command, double const Param1, double const Param2,
|
||||
int const Action, uint16_t Recipient, glm::vec3 Position) const {
|
||||
|
||||
auto const &command = simulation::Commands_descriptions[ static_cast<std::size_t>( Command ) ];
|
||||
|
||||
@@ -337,8 +337,11 @@ command_relay::post( user_command const Command, double const Param1, double con
|
||||
return;
|
||||
}
|
||||
|
||||
if (Position == glm::vec3(0.0f))
|
||||
Position = Global.pCamera.Pos;
|
||||
|
||||
uint32_t combined_recipient = static_cast<uint32_t>( command.target ) | Recipient;
|
||||
command_data commanddata({Command, Action, Param1, Param2, Timer::GetDeltaTime(), FreeFlyModeFlag, Global.pCamera.Pos });
|
||||
command_data commanddata({Command, Action, Param1, Param2, Timer::GetDeltaTime(), FreeFlyModeFlag, Position });
|
||||
|
||||
simulation::Commands.push(commanddata, combined_recipient);
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ public:
|
||||
// posts specified command for the specified recipient
|
||||
void
|
||||
post(user_command const Command, double const Param1, double const Param2,
|
||||
int const Action, uint16_t Recipient ) const;
|
||||
int const Action, uint16_t Recipient, glm::vec3 Position = glm::vec3(0.0f) ) const;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -182,6 +182,16 @@ driver_mode::update() {
|
||||
|
||||
// variable step simulation time routines
|
||||
|
||||
if (!change_train.empty()) {
|
||||
TTrain *train = simulation::Trains.find(change_train);
|
||||
if (train) {
|
||||
simulation::Train = train;
|
||||
InOutKey();
|
||||
m_relay.post(user_command::aidriverdisable, 0.0, 0.0, GLFW_PRESS, 0);
|
||||
change_train.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if( ( simulation::Train == nullptr ) && ( false == FreeFlyModeFlag ) ) {
|
||||
// intercept cases when the driven train got removed after entering portal
|
||||
InOutKey();
|
||||
@@ -258,33 +268,23 @@ driver_mode::enter() {
|
||||
simulation::Vehicles.find( Global.asHumanCtrlVehicle ) :
|
||||
nullptr ) };
|
||||
|
||||
Camera.Init(Global.FreeCameraInit[0], Global.FreeCameraInitAngle[0], nPlayerTrain );
|
||||
Camera.Init(Global.FreeCameraInit[0], Global.FreeCameraInitAngle[0], nullptr );
|
||||
Global.pCamera = Camera;
|
||||
Global.pDebugCamera = DebugCamera;
|
||||
|
||||
FreeFlyModeFlag = true;
|
||||
DebugCamera = Camera;
|
||||
|
||||
if (nPlayerTrain)
|
||||
{
|
||||
// M7TODO: restore
|
||||
/*
|
||||
WriteLog( "Initializing player train, \"" + Global.asHumanCtrlVehicle + "\"" );
|
||||
WriteLog( "Trying to enter player train, \"" + Global.asHumanCtrlVehicle + "\"" );
|
||||
|
||||
Global.pCamera.Pos = nPlayerTrain->GetPosition();
|
||||
m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0);
|
||||
*/
|
||||
|
||||
FreeFlyModeFlag = true;
|
||||
Camera.m_owner = nullptr;
|
||||
DebugCamera = Camera;
|
||||
m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0, nPlayerTrain->GetPosition());
|
||||
change_train = nPlayerTrain->name();
|
||||
}
|
||||
else
|
||||
else if (Global.asHumanCtrlVehicle != "ghostview")
|
||||
{
|
||||
if (Global.asHumanCtrlVehicle != "ghostview")
|
||||
{
|
||||
Error("Bad scenario: failed to locate player train, \"" + Global.asHumanCtrlVehicle + "\"" );
|
||||
}
|
||||
FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie
|
||||
Camera.m_owner = nullptr;
|
||||
DebugCamera = Camera;
|
||||
Error("Bad scenario: failed to locate player train, \"" + Global.asHumanCtrlVehicle + "\"" );
|
||||
}
|
||||
|
||||
// if (!Global.bMultiplayer) //na razie włączone
|
||||
@@ -379,7 +379,6 @@ driver_mode::on_event_poll() {
|
||||
|
||||
void
|
||||
driver_mode::update_camera( double const Deltatime ) {
|
||||
Camera.Pos = Global.pCamera.Pos; // M7TODO
|
||||
|
||||
auto *controlled = (
|
||||
simulation::Train ?
|
||||
@@ -686,15 +685,11 @@ driver_mode::OnKeyDown(int cKey) {
|
||||
// only available in free fly mode
|
||||
break;
|
||||
|
||||
TDynamicObject *dynamic = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 50, true, false ) );
|
||||
TDynamicObject *dynamic = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Camera.Pos, 50, true, false ) );
|
||||
if (dynamic) {
|
||||
TTrain *train = simulation::Trains.find(dynamic->name());
|
||||
if (train) {
|
||||
simulation::Train = train;
|
||||
InOutKey();
|
||||
} else {
|
||||
m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0);
|
||||
}
|
||||
m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0);
|
||||
|
||||
change_train = dynamic->name();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -109,4 +109,5 @@ private:
|
||||
double m_secondaryupdateaccumulator { m_secondaryupdaterate }; // keeps track of elapsed simulation time, for less important fixed step routines
|
||||
int iPause { 0 }; // wykrywanie zmian w zapauzowaniu
|
||||
command_relay m_relay;
|
||||
std::string change_train; // train name awaiting entering
|
||||
};
|
||||
|
||||
0
network/backend/file.cpp
Normal file
0
network/backend/file.cpp
Normal file
22
network/backend/file.h
Normal file
22
network/backend/file.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "network/network.h"
|
||||
|
||||
namespace network::file
|
||||
{
|
||||
class server : public network::server
|
||||
{
|
||||
private:
|
||||
std::fstream stream;
|
||||
|
||||
public:
|
||||
server();
|
||||
};
|
||||
|
||||
class client : public network::client
|
||||
{
|
||||
private:
|
||||
std::fstream stream;
|
||||
|
||||
public:
|
||||
client();
|
||||
};
|
||||
}
|
||||
@@ -113,11 +113,6 @@ command_queue::commands_map network::connection::pop_commands()
|
||||
|
||||
// server
|
||||
|
||||
network::server::server()
|
||||
{
|
||||
recorder.open("recorder.bin", std::ios::trunc | std::ios::out | std::ios::binary);
|
||||
}
|
||||
|
||||
void network::server::push_delta(double dt, double sync, const command_queue::commands_map &commands)
|
||||
{
|
||||
if (dt == 0.0 && commands.empty())
|
||||
@@ -128,12 +123,6 @@ void network::server::push_delta(double dt, double sync, const command_queue::co
|
||||
msg.sync = sync;
|
||||
msg.commands = commands;
|
||||
|
||||
sn_utils::ls_uint32(recorder, 0x37305545);
|
||||
sn_utils::ls_uint32(recorder, 0);
|
||||
sn_utils::ls_uint16(recorder, (uint16_t)msg.type);
|
||||
msg.serialize(recorder);
|
||||
recorder.flush();
|
||||
|
||||
for (auto c : clients)
|
||||
if (c->state == connection::ACTIVE)
|
||||
c->send_message(msg);
|
||||
|
||||
@@ -54,12 +54,10 @@ namespace network
|
||||
void handle_message(connection &conn, const message &msg);
|
||||
|
||||
std::vector<std::shared_ptr<connection>> clients;
|
||||
std::fstream recorder;
|
||||
|
||||
command_queue::commands_map client_commands_queue;
|
||||
|
||||
public:
|
||||
server();
|
||||
void push_delta(double dt, double sync, const command_queue::commands_map &commands);
|
||||
command_queue::commands_map pop_commands();
|
||||
};
|
||||
|
||||
@@ -20,9 +20,7 @@ void ui::vehiclelist_panel::render_contents() {
|
||||
else if (ImGui::TreeNode(vehicle, label.c_str())) {
|
||||
vehicle = vehicle->Next();
|
||||
while (vehicle) {
|
||||
if (ImGui::Button(vehicle->name().c_str())) {
|
||||
Global.pCamera.Pos = vehicle->GetPosition();
|
||||
}
|
||||
ImGui::TextUnformatted(vehicle->name().c_str());
|
||||
vehicle = vehicle->Next();
|
||||
}
|
||||
ImGui::TreePop();
|
||||
|
||||
Reference in New Issue
Block a user