Quality of life with road lines edge data (lots, buildings, etc.)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#undef NDEBUG
|
||||
#include <cassert>
|
||||
#include <core/set.h>
|
||||
#include <core/io/json.h>
|
||||
#include <scene/main/viewport.h>
|
||||
@@ -18,6 +20,7 @@
|
||||
|
||||
void StreamWorld::create_tilemap()
|
||||
{
|
||||
tiles.clear();
|
||||
data()->for_each_building(
|
||||
[this](const String &key, void *hdata) {
|
||||
const struct BuildingsData::building &b =
|
||||
@@ -174,20 +177,33 @@ void StreamWorld::unload_building(const String &key)
|
||||
|
||||
void StreamWorld::request_item(int type, const String &bkey)
|
||||
{
|
||||
String id = data()->get_building(bkey).id;
|
||||
bool debug = false;
|
||||
/* bkey can contain "::"'s so need to replae them with underscores */
|
||||
String ekey = bkey;
|
||||
if (bkey.begins_with("road__")) {
|
||||
print_line("loading building: " + ekey);
|
||||
debug = true;
|
||||
}
|
||||
String id = data()->get_building(ekey).id;
|
||||
if (debug)
|
||||
print_line("building id: " + id);
|
||||
if (id == "empty")
|
||||
return;
|
||||
switch (type) {
|
||||
case 0:
|
||||
if (debug)
|
||||
print_line("add to scene id: " + id);
|
||||
if (!data()->has_scene(id))
|
||||
data()->create_scene_data(id, bkey);
|
||||
data()->create_scene_data(id, ekey);
|
||||
else
|
||||
data()->add_scene_item(id, bkey);
|
||||
data()->add_scene_item(id, ekey);
|
||||
if (debug)
|
||||
print_line("added to scene id: " + id);
|
||||
break;
|
||||
case 1: {
|
||||
print_line("Removing key:" + bkey);
|
||||
print_line("Removing key:" + ekey);
|
||||
if (data()->has_scene(id)) {
|
||||
data()->remove_scene_item(id, bkey);
|
||||
data()->remove_scene_item(id, ekey);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
@@ -354,10 +370,43 @@ void StreamWorld::run_command(const String &command,
|
||||
remove_generated_stuff();
|
||||
update_items();
|
||||
} else if (command == "rebuild_roads") {
|
||||
std::vector<String> erased_keys;
|
||||
erased_keys.reserve(data()->get_building_count());
|
||||
String prefix = "road__";
|
||||
int i;
|
||||
data()->for_each_building(
|
||||
[&erased_keys, prefix](const String &key, void *data) {
|
||||
if (key.begins_with(prefix)) {
|
||||
erased_keys.push_back(key);
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
print_line("delete buildings: " + itos(erased_keys.size()) +
|
||||
" prefix: " + prefix);
|
||||
for (i = erased_keys.size() - 1; i >= 0; i--) {
|
||||
unload_building(erased_keys[i]);
|
||||
data()->destroy_building(erased_keys[i]);
|
||||
assert(!data()->has_building(erased_keys[i]));
|
||||
}
|
||||
/* FIXME */
|
||||
if (args.size() > 0)
|
||||
RoadProcessing::road_setup(this, args[0]);
|
||||
else
|
||||
RoadProcessing::road_setup(this, 0);
|
||||
create_tilemap();
|
||||
update_view();
|
||||
data()->scene_update();
|
||||
update_items();
|
||||
#if 0
|
||||
data()->for_each_building(
|
||||
[this](const String &key, void *mdata) {
|
||||
print_line("Building key: " + key);
|
||||
// FIXME do not load building every time
|
||||
if (key.begins_with("road__"))
|
||||
load_building(key);
|
||||
},
|
||||
nullptr);
|
||||
#endif
|
||||
print_line("road_rebuild done");
|
||||
} else if (command == "remove_road_meshes") {
|
||||
RoadProcessing::remove_road_meshes(this);
|
||||
@@ -368,7 +417,9 @@ void StreamWorld::run_command(const String &command,
|
||||
terrain->set_generator(gen);
|
||||
update_items();
|
||||
RoadProcessing::road_setup(this, 0);
|
||||
create_tilemap();
|
||||
update_view();
|
||||
update_items();
|
||||
assert(false);
|
||||
} else
|
||||
print_error("No command " + command);
|
||||
@@ -394,10 +445,27 @@ void StreamWorld::_notification(int which)
|
||||
}
|
||||
ERR_FAIL_COND_MSG(!current_scene, "No current scene");
|
||||
RoadProcessing::road_setup(this, 0);
|
||||
#if 0
|
||||
data()->for_each_building(
|
||||
[this](const String &key, void *mdata) {
|
||||
print_line("Building key: " + key);
|
||||
// FIXME do not load building every time
|
||||
if (key.begins_with("road__")) {
|
||||
load_building(key);
|
||||
assert(false);
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
assert(false);
|
||||
#endif
|
||||
create_tilemap();
|
||||
set_process(true);
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
break;
|
||||
update_view();
|
||||
data()->scene_update();
|
||||
update_items();
|
||||
update_view();
|
||||
assert(terrain);
|
||||
assert(viewer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user