map ai command send feature, debug window event queue feature, fix timeoverride, ai restores light settings after clearing setsignal

This commit is contained in:
milek7
2019-10-12 00:55:07 +02:00
parent 43fc2899aa
commit f6ce47f212
9 changed files with 99 additions and 32 deletions

View File

@@ -4263,15 +4263,13 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
if (NewCommand == "SetSignal") {
TSignals signal = (TSignals)std::lrint(NewValue1);
mvOccupied->iLights[0] = 0;
mvOccupied->iLights[1] = 0;
mvOccupied->WarningSignal = 0;
for (int i = Signal_START; i <= Signal_MAX; i++)
iDrivigFlags &= ~(1 << i);
if (NewValue2 > 0.5)
iDrivigFlags |= 1 << (uint32_t)signal;
else
CheckVehicles(); // restore light state
}
return false; // nierozpoznana - wysłać bezpośrednio do pojazdu

View File

@@ -523,33 +523,46 @@ debug_panel::render() {
}
// sections
ImGui::Separator();
render_section( "Vehicle", m_vehiclelines );
render_section( "Vehicle Engine", m_enginelines );
render_section( "Vehicle AI", m_ailines );
render_section( "Vehicle Scan Table", m_scantablelines );
render_section( "Scenario", m_scenariolines );
if( true == render_section( "Scenario Event Queue", m_eventqueuelines ) ) {
render_section( STR("Vehicle"), m_vehiclelines );
render_section( STR("Vehicle Engine"), m_enginelines );
render_section( STR("Vehicle AI"), m_ailines );
render_section( STR("Vehicle Scan Table"), m_scantablelines );
render_section( STR("Scenario"), m_scenariolines );
if( true == render_section( STR("Scenario Event Queue"), m_eventqueuelines ) ) {
// event queue filter
ImGui::Checkbox( "By This Vehicle Only", &m_eventqueueactivevehicleonly );
ImGui::Checkbox( STR_C("By This Vehicle Only"), &m_eventqueueactivevehicleonly );
if (DebugModeFlag) {
ImGui::NewLine();
ImGui::TextUnformatted(STR_C("Queue event:"));
ImGui::InputText(STR_C("Event"), queue_event_buf.data(), queue_event_buf.size());
ImGui::InputText(STR_C("Activator"), queue_event_activator_buf.data(), queue_event_activator_buf.size());
if (ImGui::Button("Queue")) {
command_relay relay;
std::string cmd_id = std::string(queue_event_buf.data()) + "%" + std::string(queue_event_activator_buf.data());
relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &cmd_id);
}
}
}
if( true == render_section( "Power Grid", m_powergridlines ) ) {
if( true == render_section( STR("Power Grid"), m_powergridlines ) ) {
// traction state debug
ImGui::Checkbox(
"Traction debug",
STR_C("Traction debug"),
&GfxRenderer.settings.traction_debug );
}
render_section( "Camera", m_cameralines );
render_section( STR("Camera"), m_cameralines );
if (m_input.vehicle && ImGui::CollapsingHeader(STR_C("Normal forces graph"))) {
ImGui::Text("Normal acceleration: %.2f m/s^2", AccN_acc_graph.last_val);
ImGui::Text(STR_C("Normal acceleration: %.2f m/s^2"), AccN_acc_graph.last_val);
AccN_acc_graph.render();
ImGui::Text("Normal jerk: %.2f m/s^3", AccN_jerk_graph.last_val);
ImGui::Text(STR_C("Normal jerk: %.2f m/s^3"), AccN_jerk_graph.last_val);
AccN_jerk_graph.render();
}
render_section( "Gfx Renderer", m_rendererlines );
render_section( STR("Gfx Renderer"), m_rendererlines );
// toggles
ImGui::Separator();
ImGui::Checkbox( "Debug Mode", &DebugModeFlag );
ImGui::Checkbox( STR_C("Debug Mode"), &DebugModeFlag );
}
ImGui::End();

View File

@@ -123,6 +123,9 @@ private:
graph_data AccN_acc_graph;
float last_AccN;
std::array<char, 128> queue_event_buf = { 0 };
std::array<char, 128> queue_event_activator_buf = { 0 };
bool m_eventqueueactivevehicleonly { false };
};

View File

@@ -58,6 +58,7 @@ struct scratch_data {
std::string name;
bool initialized { false };
bool time_initialized { false };
};
// basic element of rudimentary partitioning scheme for the section. fixed size, no further subdivision

View File

@@ -149,10 +149,20 @@ void state_manager::process_commands() {
}
if (commanddata.command == user_command::queueevent) {
uint32_t id = std::round(commanddata.param1);
basic_event *ev = Events.FindEvent(commanddata.payload);
std::istringstream ss(commanddata.payload);
std::string event_name;
std::string vehicle_name;
std::getline(ss, event_name, '%');
std::getline(ss, vehicle_name, '%');
basic_event *ev = Events.FindEvent(event_name);
TDynamicObject *vehicle = nullptr;
if (!vehicle_name.empty())
vehicle = simulation::Vehicles.find(vehicle_name);
if (ev)
Events.AddToQuery(ev, nullptr);
Events.AddToQuery(ev, vehicle);
}
if (commanddata.command == user_command::setlight) {

View File

@@ -312,7 +312,8 @@ state_serializer::deserialize_firstinit( cParser &Input, scene::scratch_data &Sc
simulation::Events.InitLaunchers();
simulation::Memory.InitCells();
init_time();
if (!Scratchpad.time_initialized)
init_time();
Scratchpad.initialized = true;
}
@@ -638,6 +639,11 @@ state_serializer::deserialize_time( cParser &Input, scene::scratch_data &Scratch
// remaining sunrise and sunset parameters are no longer used, as they're now calculated dynamically
// anything else left in the section has no defined meaning
skip_until( Input, "endtime" );
if (!Scratchpad.time_initialized)
Scratchpad.time_initialized = true;
init_time();
}
void

View File

@@ -1 +1 @@
#define VERSION_INFO "M7 (sim) 15.09.2019"
#define VERSION_INFO "M7 (sim) 11.10.2019"

View File

@@ -567,30 +567,62 @@ void ui::obstacle_remove_window::render_content()
}
ui::vehicle_click_window::vehicle_click_window(ui_panel &panel, std::shared_ptr<map::vehicle> &&obstacle)
: popup(panel), m_obstacle(obstacle) { }
: popup(panel), m_vehicle(obstacle) { }
void ui::vehicle_click_window::render_content()
{
std::string name = m_obstacle->name + "%SetSignal";
if (!m_obstacle->dynobj->MoverParameters->Battery) {
std::string name_enable = m_obstacle->name + "%Prepare_engine";
if (!m_vehicle->dynobj->MoverParameters->Battery) {
std::string name_enable = m_vehicle->name + "%Prepare_engine";
m_relay.post(user_command::sendaicommand, 1.0, 1.0, GLFW_PRESS, 0, glm::vec3(), &name_enable);
}
if (ImGui::Button(u8"wyłącz")) {
ImGui::TextUnformatted(STR_C("Light signal:"));
if (ImGui::Button(STR_C("none"))) {
std::string name = m_vehicle->name + "%SetSignal";
m_relay.post(user_command::sendaicommand, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(), &name);
ImGui::CloseCurrentPopup();
}
if (ImGui::Button(u8"Pc6")) {
if (ImGui::Button(STR_C("Pc6"))) {
std::string name = m_vehicle->name + "%SetSignal";
m_relay.post(user_command::sendaicommand, Signal_Pc6, 1.0, GLFW_PRESS, 0, glm::vec3(), &name);
ImGui::CloseCurrentPopup();
}
if (ImGui::Button(u8"A1")) {
if (ImGui::Button(STR_C("A1"))) {
std::string name = m_vehicle->name + "%SetSignal";
m_relay.post(user_command::sendaicommand, Signal_A1, 1.0, GLFW_PRESS, 0, glm::vec3(), &name);
ImGui::CloseCurrentPopup();
}
if (DebugModeFlag) {
ImGui::NewLine();
ImGui::TextUnformatted(STR_C("Send command:"));
ImGui::InputText(STR_C("Command"), command_buf.data(), command_buf.size());
static std::vector<std::string> possible_commands =
{"CabSignal","Overhead","Emergency_brake","Timetable:","SetVelocity","SetProximityVelocity","ShuntVelocity",
"Wait_for_orders","Prepare_engine","Change_direction","Obey_train","Bank","Shunt","Loose_shunt",
"Jump_to_first_order","Jump_to_order","Warning_signal","Radio_channel","SetLights","SetSignal"};
ImGui::SameLine();
if (ImGui::BeginCombo("##cmd_select", nullptr, ImGuiComboFlags_NoPreview | ImGuiComboFlags_HeightLarge))
{
for (size_t i = 0; i < possible_commands.size(); i++)
if (ImGui::Selectable(possible_commands[i].c_str(), false))
memcpy(command_buf.data(), possible_commands[i].c_str(), possible_commands[i].size() + 1);
ImGui::EndCombo();
}
ImGui::InputInt(STR_C("Param 1"), &command_param1);
ImGui::InputInt(STR_C("Param 2"), &command_param2);
if (ImGui::Button(STR_C("Send"))) {
std::string name = m_vehicle->name + "%" + std::string(command_buf.data());
m_relay.post(user_command::sendaicommand, command_param1, command_param2, GLFW_PRESS, 0, glm::vec3(), &name);
ImGui::CloseCurrentPopup();
}
}
}

View File

@@ -67,9 +67,13 @@ class obstacle_remove_window : public popup
class vehicle_click_window : public popup
{
std::shared_ptr<map::vehicle> m_obstacle;
std::shared_ptr<map::vehicle> m_vehicle;
command_relay m_relay;
std::array<char, 128> command_buf = { 0 };
int command_param1 = 0;
int command_param2 = 0;
public:
vehicle_click_window(ui_panel &panel, std::shared_ptr<map::vehicle> &&obstacle);