mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 04:39:18 +02:00
obstacle inserting
This commit is contained in:
@@ -278,33 +278,16 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
|
|||||||
}
|
}
|
||||||
else if (mode == nodebank_panel::ADD) {
|
else if (mode == nodebank_panel::ADD) {
|
||||||
const std::string *src = ui->get_active_node_template();
|
const std::string *src = ui->get_active_node_template();
|
||||||
|
std::string name = "editor_" + std::to_string(LocalRandom(0.0, 100000.0));
|
||||||
|
|
||||||
if (!src)
|
if (!src)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cParser parser(*src);
|
TAnimModel *cloned = simulation::State.create_model(*src, name, Camera.Pos + GfxRenderer.Mouse_Position());
|
||||||
parser.getTokens(); // "node"
|
|
||||||
parser.getTokens(2); // ranges
|
|
||||||
|
|
||||||
scene::node_data nodedata;
|
|
||||||
parser >> nodedata.range_max >> nodedata.range_min;
|
|
||||||
|
|
||||||
parser.getTokens(2); // name, type
|
|
||||||
nodedata.name = "editor_" + std::to_string(LocalRandom(0.0, 100000.0));
|
|
||||||
nodedata.type = "model";
|
|
||||||
|
|
||||||
scene::scratch_data scratch;
|
|
||||||
|
|
||||||
TAnimModel *cloned = simulation::State.deserialize_model(parser, scratch, nodedata);
|
|
||||||
|
|
||||||
if (!cloned)
|
if (!cloned)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cloned->mark_dirty();
|
|
||||||
cloned->location(Camera.Pos + GfxRenderer.Mouse_Position());
|
|
||||||
simulation::Instances.insert(cloned);
|
|
||||||
simulation::Region->insert(cloned);
|
|
||||||
|
|
||||||
if (!m_dragging)
|
if (!m_dragging)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -175,9 +175,8 @@ void state_manager::process_commands() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TAnimModel *
|
TAnimModel * state_manager::create_model(const std::string &src, const std::string &name, const glm::dvec3 &position) {
|
||||||
state_manager::deserialize_model(cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata) {
|
return m_serializer.create_model(src, name, position);
|
||||||
return m_serializer.deserialize_model(Input, Scratchpad, Nodedata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -38,10 +38,9 @@ public:
|
|||||||
// process input commands
|
// process input commands
|
||||||
void
|
void
|
||||||
process_commands();
|
process_commands();
|
||||||
|
// create model from node string
|
||||||
// temporary for editor
|
|
||||||
TAnimModel *
|
TAnimModel *
|
||||||
deserialize_model(cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata);
|
create_model(const std::string &src, const std::string &name, const glm::dvec3 &position);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// members
|
// members
|
||||||
|
|||||||
@@ -1002,6 +1002,33 @@ state_serializer::export_as_text(std::string const &Scenariofile) const {
|
|||||||
WriteLog( "Scenery data export done." );
|
WriteLog( "Scenery data export done." );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TAnimModel *state_serializer::create_model(const std::string &src, const std::string &name, const glm::dvec3 &position) {
|
||||||
|
cParser parser(src);
|
||||||
|
parser.getTokens(); // "node"
|
||||||
|
parser.getTokens(2); // ranges
|
||||||
|
|
||||||
|
scene::node_data nodedata;
|
||||||
|
parser >> nodedata.range_max >> nodedata.range_min;
|
||||||
|
|
||||||
|
parser.getTokens(2); // name, type
|
||||||
|
nodedata.name = name;
|
||||||
|
nodedata.type = "model";
|
||||||
|
|
||||||
|
scene::scratch_data scratch;
|
||||||
|
|
||||||
|
TAnimModel *cloned = deserialize_model(parser, scratch, nodedata);
|
||||||
|
|
||||||
|
if (!cloned)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
cloned->mark_dirty();
|
||||||
|
cloned->location(position);
|
||||||
|
simulation::Instances.insert(cloned);
|
||||||
|
simulation::Region->insert(cloned);
|
||||||
|
|
||||||
|
return cloned;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
state_serializer::export_nodes_to_stream(std::ostream &scmfile, bool Dirty) const {
|
state_serializer::export_nodes_to_stream(std::ostream &scmfile, bool Dirty) const {
|
||||||
// groups
|
// groups
|
||||||
|
|||||||
@@ -41,9 +41,8 @@ public:
|
|||||||
// stores class data in specified file, in legacy (text) format
|
// stores class data in specified file, in legacy (text) format
|
||||||
void
|
void
|
||||||
export_as_text(std::string const &Scenariofile) const;
|
export_as_text(std::string const &Scenariofile) const;
|
||||||
|
// create new model from node stirng
|
||||||
// temporary public for editor
|
TAnimModel * create_model(std::string const &src, std::string const &name, const glm::dvec3 &position);
|
||||||
TAnimModel * deserialize_model( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// methods
|
// methods
|
||||||
@@ -73,6 +72,7 @@ private:
|
|||||||
TTractionPowerSource * deserialize_tractionpowersource( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
TTractionPowerSource * deserialize_tractionpowersource( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
||||||
TMemCell * deserialize_memorycell( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
TMemCell * deserialize_memorycell( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
||||||
TEventLauncher * deserialize_eventlauncher( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
TEventLauncher * deserialize_eventlauncher( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
||||||
|
TAnimModel * deserialize_model( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
||||||
TDynamicObject * deserialize_dynamic( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
TDynamicObject * deserialize_dynamic( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
||||||
sound_source * deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
sound_source * deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
||||||
void init_time();
|
void init_time();
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ init() {
|
|||||||
|
|
||||||
"Straight |",
|
"Straight |",
|
||||||
"Divert /",
|
"Divert /",
|
||||||
|
"Insert obstacle:",
|
||||||
|
|
||||||
"master controller",
|
"master controller",
|
||||||
"second controller",
|
"second controller",
|
||||||
@@ -260,6 +261,7 @@ init() {
|
|||||||
|
|
||||||
u8"Prosto |",
|
u8"Prosto |",
|
||||||
u8"W bok /",
|
u8"W bok /",
|
||||||
|
u8"Wstaw przeszkodę:",
|
||||||
|
|
||||||
u8"nastawnik jazdy",
|
u8"nastawnik jazdy",
|
||||||
u8"nastawnik dodatkowy",
|
u8"nastawnik dodatkowy",
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ enum string {
|
|||||||
|
|
||||||
map_straight,
|
map_straight,
|
||||||
map_divert,
|
map_divert,
|
||||||
|
map_obstacle_insert,
|
||||||
|
|
||||||
cab_mainctrl,
|
cab_mainctrl,
|
||||||
cab_scndctrl,
|
cab_scndctrl,
|
||||||
|
|||||||
@@ -259,13 +259,11 @@ void ui::map_panel::render_contents()
|
|||||||
register_popup(std::make_unique<ui::disambiguation_popup>(*this, std::move(objects)));
|
register_popup(std::make_unique<ui::disambiguation_popup>(*this, std::move(objects)));
|
||||||
else if (objects.size() == 1)
|
else if (objects.size() == 1)
|
||||||
handle_map_object_click(*this, objects.begin()->second);
|
handle_map_object_click(*this, objects.begin()->second);
|
||||||
|
else {
|
||||||
glm::vec3 nearest = simulation::Region->find_nearest_track_point(world_pos);
|
glm::vec3 nearest = simulation::Region->find_nearest_track_point(world_pos);
|
||||||
if (!glm::isnan(nearest.x)) {
|
if (!glm::isnan(nearest.x) && glm::distance(world_pos, nearest) < (0.03f / zoom))
|
||||||
WriteLog(glm::to_string(nearest));
|
register_popup(std::make_unique<obstacle_window>(*this, std::move(nearest)));
|
||||||
}
|
}
|
||||||
//scene::basic_section &clicked_section = simulation::Region->section(world_pos);
|
|
||||||
//clicked_section.
|
|
||||||
}
|
}
|
||||||
else if (!objects.empty()) {
|
else if (!objects.empty()) {
|
||||||
handle_map_object_hover(objects.begin()->second);
|
handle_map_object_hover(objects.begin()->second);
|
||||||
@@ -411,3 +409,34 @@ void ui::switch_window::render_content()
|
|||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui::obstacle_window::obstacle_window(ui_panel &panel, glm::dvec3 const &pos)
|
||||||
|
: popup(panel), m_position(pos)
|
||||||
|
{
|
||||||
|
std::ifstream file;
|
||||||
|
file.open("obstaclebank.txt", std::ios_base::in | std::ios_base::binary);
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
std::istringstream entry(line);
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
std::string data;
|
||||||
|
std::getline(entry, name, ':');
|
||||||
|
std::getline(entry, data, ':');
|
||||||
|
|
||||||
|
m_obstacles.push_back(std::make_pair(name, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui::obstacle_window::render_content()
|
||||||
|
{
|
||||||
|
ImGui::TextUnformatted(LOC_STR(map_obstacle_insert));
|
||||||
|
for (auto const &entry : m_obstacles) {
|
||||||
|
if (ImGui::Button(entry.first.c_str())) {
|
||||||
|
std::string name("obstacle_" + std::to_string(LocalRandom(0.0, 100000.0)));
|
||||||
|
TAnimModel *cloned = simulation::State.create_model(entry.second, name, m_position);
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,16 @@ public:
|
|||||||
virtual void render_content() override;
|
virtual void render_content() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class obstacle_window : public popup {
|
||||||
|
glm::dvec3 m_position;
|
||||||
|
std::vector<std::pair<std::string, std::string>> m_obstacles;
|
||||||
|
|
||||||
|
public:
|
||||||
|
obstacle_window(ui_panel &panel, glm::dvec3 const &pos);
|
||||||
|
|
||||||
|
virtual void render_content() override;
|
||||||
|
};
|
||||||
|
|
||||||
class map_panel : public ui_panel {
|
class map_panel : public ui_panel {
|
||||||
std::unique_ptr<gl::program> m_shader;
|
std::unique_ptr<gl::program> m_shader;
|
||||||
std::unique_ptr<gl::framebuffer> m_msaa_fb;
|
std::unique_ptr<gl::framebuffer> m_msaa_fb;
|
||||||
|
|||||||
Reference in New Issue
Block a user