16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 17:29:18 +02:00
This commit is contained in:
milek7
2019-01-20 15:31:48 +01:00
parent 84153aac80
commit 1ef74838ee
10 changed files with 55 additions and 48 deletions

View File

@@ -119,6 +119,7 @@ set(SOURCES
"network/message.cpp" "network/message.cpp"
"network/manager.cpp" "network/manager.cpp"
"network/backend/asio.cpp" "network/backend/asio.cpp"
"network/backend/file.cpp"
"widgets/vehiclelist.cpp" "widgets/vehiclelist.cpp"

View File

@@ -317,8 +317,8 @@ void command_queue::push_commands(const commands_map &commands) {
} }
void void
command_relay::post( user_command const Command, double const Param1, double const Param2, command_relay::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) const {
auto const &command = simulation::Commands_descriptions[ static_cast<std::size_t>( Command ) ]; 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; return;
} }
if (Position == glm::vec3(0.0f))
Position = Global.pCamera.Pos;
uint32_t combined_recipient = static_cast<uint32_t>( command.target ) | Recipient; 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); simulation::Commands.push(commanddata, combined_recipient);
} }

View File

@@ -349,7 +349,7 @@ public:
// posts specified command for the specified recipient // posts specified command for the specified recipient
void void
post(user_command const Command, double const Param1, double const Param2, 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;
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -182,6 +182,16 @@ driver_mode::update() {
// variable step simulation time routines // 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 ) ) { if( ( simulation::Train == nullptr ) && ( false == FreeFlyModeFlag ) ) {
// intercept cases when the driven train got removed after entering portal // intercept cases when the driven train got removed after entering portal
InOutKey(); InOutKey();
@@ -258,33 +268,23 @@ driver_mode::enter() {
simulation::Vehicles.find( Global.asHumanCtrlVehicle ) : simulation::Vehicles.find( Global.asHumanCtrlVehicle ) :
nullptr ) }; nullptr ) };
Camera.Init(Global.FreeCameraInit[0], Global.FreeCameraInitAngle[0], nPlayerTrain ); Camera.Init(Global.FreeCameraInit[0], Global.FreeCameraInitAngle[0], nullptr );
Global.pCamera = Camera; Global.pCamera = Camera;
Global.pDebugCamera = DebugCamera; Global.pDebugCamera = DebugCamera;
FreeFlyModeFlag = true;
DebugCamera = Camera;
if (nPlayerTrain) if (nPlayerTrain)
{ {
// M7TODO: restore WriteLog( "Trying to enter player train, \"" + Global.asHumanCtrlVehicle + "\"" );
/*
WriteLog( "Initializing player train, \"" + Global.asHumanCtrlVehicle + "\"" );
Global.pCamera.Pos = nPlayerTrain->GetPosition(); m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0, nPlayerTrain->GetPosition());
m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0); change_train = nPlayerTrain->name();
*/
FreeFlyModeFlag = true;
Camera.m_owner = nullptr;
DebugCamera = Camera;
} }
else else if (Global.asHumanCtrlVehicle != "ghostview")
{ {
if (Global.asHumanCtrlVehicle != "ghostview") Error("Bad scenario: failed to locate player train, \"" + Global.asHumanCtrlVehicle + "\"" );
{
Error("Bad scenario: failed to locate player train, \"" + Global.asHumanCtrlVehicle + "\"" );
}
FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie
Camera.m_owner = nullptr;
DebugCamera = Camera;
} }
// if (!Global.bMultiplayer) //na razie włączone // if (!Global.bMultiplayer) //na razie włączone
@@ -379,7 +379,6 @@ driver_mode::on_event_poll() {
void void
driver_mode::update_camera( double const Deltatime ) { driver_mode::update_camera( double const Deltatime ) {
Camera.Pos = Global.pCamera.Pos; // M7TODO
auto *controlled = ( auto *controlled = (
simulation::Train ? simulation::Train ?
@@ -686,15 +685,11 @@ driver_mode::OnKeyDown(int cKey) {
// only available in free fly mode // only available in free fly mode
break; 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) { if (dynamic) {
TTrain *train = simulation::Trains.find(dynamic->name()); m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0);
if (train) {
simulation::Train = train; change_train = dynamic->name();
InOutKey();
} else {
m_relay.post(user_command::entervehicle, 0.0, 0.0, GLFW_PRESS, 0);
}
} }
break; break;

View File

@@ -109,4 +109,5 @@ private:
double m_secondaryupdateaccumulator { m_secondaryupdaterate }; // keeps track of elapsed simulation time, for less important fixed step routines double m_secondaryupdateaccumulator { m_secondaryupdaterate }; // keeps track of elapsed simulation time, for less important fixed step routines
int iPause { 0 }; // wykrywanie zmian w zapauzowaniu int iPause { 0 }; // wykrywanie zmian w zapauzowaniu
command_relay m_relay; command_relay m_relay;
std::string change_train; // train name awaiting entering
}; };

0
network/backend/file.cpp Normal file
View File

22
network/backend/file.h Normal file
View 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();
};
}

View File

@@ -113,11 +113,6 @@ command_queue::commands_map network::connection::pop_commands()
// server // 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) void network::server::push_delta(double dt, double sync, const command_queue::commands_map &commands)
{ {
if (dt == 0.0 && commands.empty()) 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.sync = sync;
msg.commands = commands; 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) for (auto c : clients)
if (c->state == connection::ACTIVE) if (c->state == connection::ACTIVE)
c->send_message(msg); c->send_message(msg);

View File

@@ -54,12 +54,10 @@ namespace network
void handle_message(connection &conn, const message &msg); void handle_message(connection &conn, const message &msg);
std::vector<std::shared_ptr<connection>> clients; std::vector<std::shared_ptr<connection>> clients;
std::fstream recorder;
command_queue::commands_map client_commands_queue; command_queue::commands_map client_commands_queue;
public: public:
server();
void push_delta(double dt, double sync, const command_queue::commands_map &commands); void push_delta(double dt, double sync, const command_queue::commands_map &commands);
command_queue::commands_map pop_commands(); command_queue::commands_map pop_commands();
}; };

View File

@@ -20,9 +20,7 @@ void ui::vehiclelist_panel::render_contents() {
else if (ImGui::TreeNode(vehicle, label.c_str())) { else if (ImGui::TreeNode(vehicle, label.c_str())) {
vehicle = vehicle->Next(); vehicle = vehicle->Next();
while (vehicle) { while (vehicle) {
if (ImGui::Button(vehicle->name().c_str())) { ImGui::TextUnformatted(vehicle->name().c_str());
Global.pCamera.Pos = vehicle->GetPosition();
}
vehicle = vehicle->Next(); vehicle = vehicle->Next();
} }
ImGui::TreePop(); ImGui::TreePop();