Viewer is ready to go, I think

This commit is contained in:
2021-01-22 17:35:23 -05:00
parent 351b923d68
commit b0440a4e12
11 changed files with 234 additions and 34 deletions

View File

@@ -0,0 +1,88 @@
#include "viewer.hpp"
Viewer::Viewer() {
world_.reset(new World);
world_->init_standalone();
}
Viewer::~Viewer() {
}
int64_t Viewer::get_player_id() {
return 1;
}
void Viewer::update_view() {
// Get ready to delete views that aren't in use.
//
for (auto pair : anim_view_) {
pair.second.set_updated(false);
}
// Update the player's AnimView first.
//
Tangible *player = world_->tangible_get(1);
AnimView *player_view = &anim_view_[1];
player_view->update_from(player->anim_queue_);
// Find out where's the center of the world.
//
std::string plane = player_view->get_plane();
util::XYZ xyz = player_view->get_xyz();
// Get a list of everything near the player.
//
tangibles_ = world_->scan_radius(plane, xyz.x, xyz.y, 100.0);
// Update AnimViews for every tangible near the player.
//
for (int64_t id : tangibles_) {
Tangible *tan = world_->tangible_get(id);
assert (tan != nullptr);
anim_view_[id].update_from(tan->anim_queue_);
}
// Delete any AnimView that was not updated.
//
for (auto iter = anim_view_.begin(); iter != anim_view_.end(); ) {
if (iter->second.updated()) {
iter++;
} else {
iter = anim_view_.erase(iter);
}
}
}
const std::vector<int64_t> &Viewer::get_tangibles_near_player() {
return tangibles_;
}
AnimView *Viewer::get_animation_view(int64_t id) {
auto iter = anim_view_.find(id);
if (iter == anim_view_.end()) {
return nullptr;
} else {
return &iter->second;
}
}
// Get the menu of the specified tangible.
//
std::vector<std::string> Viewer::get_menu(int64_t id) {
std::vector<std::string> result;
result.push_back("north");
result.push_back("south");
result.push_back("east");
result.push_back("west");
result.push_back("build");
result.push_back("destroy");
return result;
}
void Viewer::choose_menu_item(int64_t id, const std::string &item) {
}
void Viewer::advance_clock() {
};