Created AnimViewMap

This commit is contained in:
2021-01-22 19:10:47 -05:00
parent b0440a4e12
commit 827a114752
10 changed files with 302 additions and 266 deletions

View File

@@ -1,6 +1,7 @@
#include "world.hpp"
#include "idalloc.hpp"
#include "animqueue.hpp"
#include <iostream>
LuaDefineType(World);
@@ -60,10 +61,6 @@ void World::init_standalone() {
player->be_a_player();
}
std::vector<int64_t> World::scan_radius(const std::string &plane, float x, float y, float radius) {
return plane_map_.scan_radius(plane, x, y, radius);
}
Tangible *World::tangible_get(int64_t id) {
auto iter = tangibles_.find(id);
if (iter == tangibles_.end()) {
@@ -73,6 +70,25 @@ Tangible *World::tangible_get(int64_t id) {
}
}
void World::update_view_map(AnimViewMap *vm, int64_t player_id, float radius) {
vm->clear_updated_bits();
// Update the player's AnimView first.
vm->update_one(tangible_get(player_id)->anim_queue_);
const AnimView *player_view = vm->get_one(player_id);
// Find out where's the center of the world.
std::string plane = player_view->get_plane();
util::XYZ xyz = player_view->get_xyz();
// Update AnimViews for every tangible near the player.
for (int64_t id : plane_map_.scan_radius(plane, xyz.x, xyz.y, 100.0)) {
vm->update_one(tangible_get(id)->anim_queue_);
}
vm->delete_non_updated();
}
Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) {
LuaVar tangibles, metatab;
LuaRet database;
@@ -86,6 +102,7 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) {
assert(t->world_ == nullptr);
t->world_ = this;
t->plane_item_.set_id(id);
t->anim_queue_.set_id(id);
plane_map_.track(&t->plane_item_);
// Create the tangible's database and metatable.