mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
network-aware obstacles, other changes
This commit is contained in:
@@ -129,6 +129,7 @@ set(SOURCES
|
||||
"widgets/popup.cpp"
|
||||
"widgets/time.cpp"
|
||||
"widgets/vehicleparams.cpp"
|
||||
"widgets/trainingcontrol.cpp"
|
||||
|
||||
"ref/glad/src/glad.c"
|
||||
|
||||
|
||||
@@ -1982,7 +1982,7 @@ event_manager::update() {
|
||||
|
||||
if (launcher->check_activation_key()) {
|
||||
WriteLog( "Eventlauncher: " + launcher->name() );
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(launcher->Event1), 0.0, GLFW_PRESS, 0);
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &launcher->Event1->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
53
Train.cpp
53
Train.cpp
@@ -1789,20 +1789,18 @@ void TTrain::OnCommand_batterydisable( TTrain *Train, command_data const &Comman
|
||||
|
||||
void TTrain::OnCommand_pantographtogglefront( TTrain *Train, command_data const &cmd )
|
||||
{
|
||||
command_data Command = cmd;
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
if( cmd.action == GLFW_PRESS ) {
|
||||
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
||||
if( false == Train->mvControlled->PantFrontUp ) {
|
||||
// turn on...
|
||||
OnCommand_pantographraisefront( Train, Command );
|
||||
OnCommand_pantographraisefront( Train, cmd );
|
||||
}
|
||||
else {
|
||||
// ...or turn off
|
||||
OnCommand_pantographlowerfront( Train, Command );
|
||||
OnCommand_pantographlowerfront( Train, cmd );
|
||||
}
|
||||
}
|
||||
else if( Command.action == GLFW_RELEASE ) {
|
||||
else if( cmd.action == GLFW_RELEASE ) {
|
||||
// impulse switches return automatically to neutral position
|
||||
// NOTE: this routine is used also by dedicated raise and lower commands
|
||||
if( Train->mvOccupied->PantSwitchType == "impulse" ) {
|
||||
@@ -1825,20 +1823,19 @@ void TTrain::OnCommand_pantographtogglefront( TTrain *Train, command_data const
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_pantographtogglerear( TTrain *Train, command_data const &cmd ) {
|
||||
command_data Command = cmd;
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
if( cmd.action == GLFW_PRESS ) {
|
||||
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
||||
if( false == Train->mvControlled->PantRearUp ) {
|
||||
// turn on...
|
||||
OnCommand_pantographraiserear( Train, Command );
|
||||
OnCommand_pantographraiserear( Train, cmd );
|
||||
}
|
||||
else {
|
||||
// ...or turn off
|
||||
OnCommand_pantographlowerrear( Train, Command );
|
||||
OnCommand_pantographlowerrear( Train, cmd );
|
||||
}
|
||||
}
|
||||
else if( Command.action == GLFW_RELEASE ) {
|
||||
else if( cmd.action == GLFW_RELEASE ) {
|
||||
// impulse switches return automatically to neutral position
|
||||
// NOTE: this routine is used also by dedicated raise and lower commands
|
||||
if( Train->mvOccupied->PantSwitchType == "impulse" ) {
|
||||
@@ -5003,32 +5000,38 @@ void TTrain::OnCommand_cabchangebackward( TTrain *Train, command_data const &Com
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_vehiclemove(TTrain *Train, const command_data &Command) {
|
||||
if (Command.action == GLFW_RELEASE || !DebugModeFlag)
|
||||
return;
|
||||
|
||||
TDynamicObject *d = Train->DynamicObject;
|
||||
void TTrain::vehiclemove(float distance) {
|
||||
TDynamicObject *d = DynamicObject;
|
||||
while( d ) {
|
||||
d->Move( Command.param1 * d->DirectionGet() );
|
||||
d->Move( distance * d->DirectionGet() );
|
||||
d = d->Next(); // pozostałe też
|
||||
}
|
||||
d = Train->DynamicObject->Prev();
|
||||
d = DynamicObject->Prev();
|
||||
while( d ) {
|
||||
d->Move( Command.param1 * d->DirectionGet() );
|
||||
d->Move( distance * d->DirectionGet() );
|
||||
d = d->Prev(); // w drugą stronę też
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_vehiclemove(TTrain *Train, const command_data &Command) {
|
||||
if (Command.action == GLFW_RELEASE || !DebugModeFlag)
|
||||
return;
|
||||
|
||||
Train->vehiclemove(Command.param1);
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_vehiclemoveforwards(TTrain *Train, const command_data &Command) {
|
||||
command_data modified = Command;
|
||||
modified.param1 = 100.0;
|
||||
OnCommand_vehiclemove(Train, modified);
|
||||
if (Command.action == GLFW_RELEASE || !DebugModeFlag)
|
||||
return;
|
||||
|
||||
Train->vehiclemove(100.0);
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_vehiclemovebackwards(TTrain *Train, const command_data &Command) {
|
||||
command_data modified = Command;
|
||||
modified.param1 = -100.0;
|
||||
OnCommand_vehiclemove(Train, modified);
|
||||
if (Command.action == GLFW_RELEASE || !DebugModeFlag)
|
||||
return;
|
||||
|
||||
Train->vehiclemove(-100.0);
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_vehicleboost(TTrain *Train, const command_data &Command) {
|
||||
|
||||
2
Train.h
2
Train.h
@@ -353,6 +353,8 @@ class TTrain
|
||||
static void OnCommand_vehiclemovebackwards( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_vehicleboost( TTrain *Train, command_data const &Command );
|
||||
|
||||
void vehiclemove(float distance);
|
||||
|
||||
|
||||
// members
|
||||
TDynamicObject *DynamicObject { nullptr }; // przestawia zmiana pojazdu [F5]
|
||||
|
||||
@@ -244,6 +244,8 @@ commanddescription_sequence Commands_descriptions = {
|
||||
{ "entervehicle", command_target::simulation, command_mode::oneoff },
|
||||
{ "queueevent", command_target::simulation, command_mode::oneoff },
|
||||
{ "setlight", command_target::simulation, command_mode::oneoff },
|
||||
{ "insertmodel", command_target::simulation, command_mode::oneoff },
|
||||
{ "deletemodel", command_target::simulation, command_mode::oneoff },
|
||||
};
|
||||
|
||||
} // simulation
|
||||
@@ -332,7 +334,7 @@ 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, glm::vec3 Position) const {
|
||||
int const Action, uint16_t Recipient, glm::vec3 Position, const std::string *Payload) const {
|
||||
|
||||
auto const &command = simulation::Commands_descriptions[ static_cast<std::size_t>( Command ) ];
|
||||
|
||||
@@ -356,6 +358,8 @@ command_relay::post(user_command const Command, double const Param1, double cons
|
||||
|
||||
uint32_t combined_recipient = static_cast<uint32_t>( command.target ) | Recipient;
|
||||
command_data commanddata({Command, Action, Param1, Param2, Timer::GetDeltaTime(), FreeFlyModeFlag, Position });
|
||||
if (Payload)
|
||||
commanddata.payload = *Payload;
|
||||
|
||||
simulation::Commands.push(commanddata, combined_recipient);
|
||||
}
|
||||
|
||||
@@ -238,6 +238,8 @@ enum class user_command {
|
||||
entervehicle,
|
||||
queueevent,
|
||||
setlight,
|
||||
insertmodel,
|
||||
deletemodel,
|
||||
|
||||
none = -1
|
||||
};
|
||||
@@ -278,6 +280,8 @@ struct command_data {
|
||||
|
||||
bool freefly;
|
||||
glm::vec3 location;
|
||||
|
||||
std::string payload;
|
||||
};
|
||||
|
||||
// command_queues: collects and holds commands from input sources, for processing by their intended recipients
|
||||
@@ -363,7 +367,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, glm::vec3 Position = glm::vec3(0.0f) ) const;
|
||||
int const Action, uint16_t Recipient, glm::vec3 Position = glm::vec3(0.0f) , const std::string *Payload = nullptr) const;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -644,7 +644,7 @@ driver_mode::OnKeyDown(int cKey) {
|
||||
// z [Shift] uruchomienie eventu
|
||||
if( ( false == Global.iPause ) // podczas pauzy klawisze nie działają
|
||||
&& ( KeyEvents[ i ] != nullptr ) ) {
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(KeyEvents[i]), 0.0, GLFW_PRESS, 0);
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &KeyEvents[i]->name());
|
||||
}
|
||||
}
|
||||
else if( Global.ctrlState ) {
|
||||
|
||||
@@ -69,7 +69,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
|
||||
|| ( event->m_sibling != 0 ) ) {
|
||||
// tylko jawne albo niejawne Multiple
|
||||
command_relay relay;
|
||||
relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(event), 0.0, GLFW_PRESS, 0);
|
||||
relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &event->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ void ::network::request_command::serialize(std::ostream &stream) const
|
||||
|
||||
sn_utils::s_bool(stream, data.freefly);
|
||||
sn_utils::s_vec3(stream, data.location);
|
||||
|
||||
sn_utils::s_str(stream, data.payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +69,8 @@ void network::request_command::deserialize(std::istream &stream)
|
||||
data.freefly = sn_utils::d_bool(stream);
|
||||
data.location = sn_utils::d_vec3(stream);
|
||||
|
||||
data.payload = sn_utils::d_str(stream);
|
||||
|
||||
sequence.emplace_back(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -656,9 +656,9 @@ basic_cell::launch_event( TEventLauncher *Launcher, bool local_only ) {
|
||||
}
|
||||
} else {
|
||||
if (Global.shiftState && Launcher->Event2 != nullptr)
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(Launcher->Event2), 0.0, GLFW_PRESS, 0);
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &Launcher->Event2->name());
|
||||
else if (Launcher->Event1)
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(Launcher->Event1), 0.0, GLFW_PRESS, 0);
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &Launcher->Event1->name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,16 +130,17 @@ void state_manager::process_commands() {
|
||||
|
||||
if (commanddata.command == user_command::queueevent) {
|
||||
uint32_t id = std::round(commanddata.param1);
|
||||
basic_event *ev = Events.FindEventById(id); // TODO: depends on vector position
|
||||
Events.AddToQuery(ev, nullptr);
|
||||
basic_event *ev = Events.FindEvent(commanddata.payload);
|
||||
if (ev)
|
||||
Events.AddToQuery(ev, nullptr);
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::setlight) {
|
||||
uint32_t id = commanddata.action;
|
||||
int light = std::round(commanddata.param1);
|
||||
float state = commanddata.param2;
|
||||
if (id < simulation::Instances.sequence().size())
|
||||
simulation::Instances.sequence()[id]->LightSet(light, state); // TODO: depends on vector position
|
||||
TAnimModel *model = simulation::Instances.find(commanddata.payload);
|
||||
if (model)
|
||||
model->LightSet(light, state);
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::setdatetime) {
|
||||
@@ -161,6 +162,21 @@ void state_manager::process_commands() {
|
||||
Global.AirTemperature = commanddata.param1;
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::insertmodel) {
|
||||
std::istringstream ss(commanddata.payload);
|
||||
|
||||
std::string name;
|
||||
std::string data;
|
||||
std::getline(ss, name, ':');
|
||||
std::getline(ss, data, ':');
|
||||
|
||||
simulation::State.create_model(data, name, commanddata.location);
|
||||
}
|
||||
|
||||
if (commanddata.command == user_command::deletemodel) {
|
||||
simulation::State.delete_model(simulation::Instances.find(commanddata.payload));
|
||||
}
|
||||
|
||||
if (DebugModeFlag) {
|
||||
if (commanddata.command == user_command::timejump) {
|
||||
Time.update(commanddata.param1);
|
||||
|
||||
@@ -384,8 +384,7 @@ void ui::semaphore_window::render_content()
|
||||
if (level >= 3.0f)
|
||||
level = 0.0f;
|
||||
|
||||
int id = simulation::Instances.find_id(model->name());
|
||||
m_relay.post(user_command::setlight, (double)i, level, id, 0);
|
||||
m_relay.post(user_command::setlight, (double)i, level, GLFW_PRESS, 0, glm::vec3(0.0f), &model->name());
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(2);
|
||||
@@ -407,7 +406,7 @@ void ui::semaphore_window::render_content()
|
||||
|
||||
if (ImGui::Button(displayname.c_str()))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(item), 0.0, GLFW_PRESS, 0);
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &item->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,13 +419,13 @@ void ui::switch_window::render_content()
|
||||
|
||||
if (ImGui::Button(LOC_STR(map_straight)))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(m_switch->straight_event), 0.0, GLFW_PRESS, 0);
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_switch->straight_event->name());
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
if (ImGui::Button(LOC_STR(map_divert)))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(m_switch->divert_event), 0.0, GLFW_PRESS, 0);
|
||||
m_relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &m_switch->divert_event->name());
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
@@ -467,12 +466,13 @@ void ui::obstacle_insert_window::render_content()
|
||||
{
|
||||
std::string name("obstacle_" + std::to_string(LocalRandom(0.0, 100000.0)));
|
||||
|
||||
TAnimModel *cloned = simulation::State.create_model(entry.second, name, m_position);
|
||||
std::string payload(name + ':' + entry.second);
|
||||
m_relay.post(user_command::insertmodel, 0.0, 0.0, GLFW_PRESS, 0, m_position, &payload);
|
||||
|
||||
auto obstacle = std::make_shared<map::obstacle>();
|
||||
obstacle->name = entry.first;
|
||||
obstacle->location = m_position;
|
||||
obstacle->model = cloned;
|
||||
obstacle->model_name = name;
|
||||
map::Objects.entries.push_back(std::move(obstacle));
|
||||
|
||||
std::vector<gfx::basic_vertex> vertices;
|
||||
@@ -490,7 +490,7 @@ ui::obstacle_remove_window::obstacle_remove_window(ui_panel &panel, std::shared_
|
||||
void ui::obstacle_remove_window::render_content()
|
||||
{
|
||||
if (ImGui::Button(LOC_STR(map_obstacle_remove))) {
|
||||
simulation::State.delete_model(m_obstacle->model);
|
||||
m_relay.post(user_command::deletemodel, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(), &m_obstacle->model_name);
|
||||
|
||||
auto &entries = map::Objects.entries;
|
||||
for (auto it = entries.rbegin(); it != entries.rend(); it++) {
|
||||
|
||||
@@ -46,6 +46,7 @@ class obstacle_insert_window : public popup
|
||||
{
|
||||
glm::dvec3 m_position;
|
||||
std::vector<std::pair<std::string, std::string>> m_obstacles;
|
||||
command_relay m_relay;
|
||||
|
||||
public:
|
||||
obstacle_insert_window(ui_panel &panel, glm::dvec3 const &pos);
|
||||
@@ -56,6 +57,7 @@ class obstacle_insert_window : public popup
|
||||
class obstacle_remove_window : public popup
|
||||
{
|
||||
std::shared_ptr<map::obstacle> m_obstacle;
|
||||
command_relay m_relay;
|
||||
|
||||
public:
|
||||
obstacle_remove_window(ui_panel &panel, std::shared_ptr<map::obstacle> &&obstacle);
|
||||
|
||||
@@ -36,7 +36,7 @@ struct track_switch : public map_object
|
||||
// training obstacle description
|
||||
struct obstacle : public map_object
|
||||
{
|
||||
TAnimModel *model;
|
||||
std::string model_name;
|
||||
};
|
||||
|
||||
struct objects
|
||||
|
||||
5
widgets/trainingcontrol.cpp
Normal file
5
widgets/trainingcontrol.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "widgets/trainingcontrol.h"
|
||||
|
||||
void ui::trainingcontrol_panel::render_contents() {
|
||||
|
||||
}
|
||||
10
widgets/trainingcontrol.h
Normal file
10
widgets/trainingcontrol.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "uilayer.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
class trainingcontrol_panel : public ui_panel
|
||||
{
|
||||
public:
|
||||
void render_contents() override;
|
||||
};
|
||||
} // namespace ui
|
||||
Reference in New Issue
Block a user