16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 07:39:19 +02:00

obstacle inserting

This commit is contained in:
milek7
2019-03-15 15:46:49 +01:00
parent 7ca562211a
commit f1c8c8f1cd
9 changed files with 84 additions and 34 deletions

View File

@@ -278,33 +278,16 @@ editor_mode::on_mouse_button( int const Button, int const Action, int const Mods
}
else if (mode == nodebank_panel::ADD) {
const std::string *src = ui->get_active_node_template();
std::string name = "editor_" + std::to_string(LocalRandom(0.0, 100000.0));
if (!src)
return;
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 = "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);
TAnimModel *cloned = simulation::State.create_model(*src, name, Camera.Pos + GfxRenderer.Mouse_Position());
if (!cloned)
return;
cloned->mark_dirty();
cloned->location(Camera.Pos + GfxRenderer.Mouse_Position());
simulation::Instances.insert(cloned);
simulation::Region->insert(cloned);
if (!m_dragging)
return;

View File

@@ -175,9 +175,8 @@ void state_manager::process_commands() {
}
}
TAnimModel *
state_manager::deserialize_model(cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata) {
return m_serializer.deserialize_model(Input, Scratchpad, Nodedata);
TAnimModel * state_manager::create_model(const std::string &src, const std::string &name, const glm::dvec3 &position) {
return m_serializer.create_model(src, name, position);
}
void

View File

@@ -38,10 +38,9 @@ public:
// process input commands
void
process_commands();
// temporary for editor
// create model from node string
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:
// members

View File

@@ -1002,6 +1002,33 @@ state_serializer::export_as_text(std::string const &Scenariofile) const {
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
state_serializer::export_nodes_to_stream(std::ostream &scmfile, bool Dirty) const {
// groups

View File

@@ -41,9 +41,8 @@ public:
// stores class data in specified file, in legacy (text) format
void
export_as_text(std::string const &Scenariofile) const;
// temporary public for editor
TAnimModel * deserialize_model( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
// create new model from node stirng
TAnimModel * create_model(std::string const &src, std::string const &name, const glm::dvec3 &position);
private:
// methods
@@ -73,6 +72,7 @@ private:
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 );
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 );
sound_source * deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
void init_time();

View File

@@ -89,6 +89,7 @@ init() {
"Straight |",
"Divert /",
"Insert obstacle:",
"master controller",
"second controller",
@@ -260,6 +261,7 @@ init() {
u8"Prosto |",
u8"W bok /",
u8"Wstaw przeszkodę:",
u8"nastawnik jazdy",
u8"nastawnik dodatkowy",

View File

@@ -78,6 +78,7 @@ enum string {
map_straight,
map_divert,
map_obstacle_insert,
cab_mainctrl,
cab_scndctrl,

View File

@@ -259,13 +259,11 @@ void ui::map_panel::render_contents()
register_popup(std::make_unique<ui::disambiguation_popup>(*this, std::move(objects)));
else if (objects.size() == 1)
handle_map_object_click(*this, objects.begin()->second);
glm::vec3 nearest = simulation::Region->find_nearest_track_point(world_pos);
if (!glm::isnan(nearest.x)) {
WriteLog(glm::to_string(nearest));
else {
glm::vec3 nearest = simulation::Region->find_nearest_track_point(world_pos);
if (!glm::isnan(nearest.x) && glm::distance(world_pos, nearest) < (0.03f / zoom))
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()) {
handle_map_object_hover(objects.begin()->second);
@@ -411,3 +409,34 @@ void ui::switch_window::render_content()
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();
}
}
}

View File

@@ -38,6 +38,16 @@ public:
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 {
std::unique_ptr<gl::program> m_shader;
std::unique_ptr<gl::framebuffer> m_msaa_fb;