Viewer is ready to go, I think
This commit is contained in:
@@ -38,27 +38,54 @@ World::World() {
|
||||
|
||||
// Initialize the SourceDB
|
||||
source_db_.initialize(lua_state_);
|
||||
source_db_.rebuild();
|
||||
}
|
||||
|
||||
// Do an initial lua source update and then environment rebuild.
|
||||
void Tangible::be_a_player() {
|
||||
if (id_player_pool_ == nullptr) {
|
||||
id_player_pool_.reset(new IdPlayerPool(&world_->id_global_pool_));
|
||||
}
|
||||
}
|
||||
|
||||
void World::init_standalone() {
|
||||
// Load the lua source from disk then rebuild the environment.
|
||||
source_db_.update();
|
||||
source_db_.rebuild();
|
||||
|
||||
// Run unit tests.
|
||||
source_db_.run_unittests();
|
||||
|
||||
// Create the player tangible.
|
||||
Tangible *player = tangible_make(lua_state_, 1, false);
|
||||
player->be_a_player();
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(lua_State *L) {
|
||||
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()) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return &iter->second;
|
||||
}
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) {
|
||||
LuaVar tangibles, metatab;
|
||||
LuaRet database;
|
||||
LuaStack LS(L, tangibles, database, metatab);
|
||||
|
||||
// Get a fresh ID.
|
||||
int64_t id = id_global_pool_.alloc_id_for_thread(L);
|
||||
// Allocate an ID if we don't already have one.
|
||||
if (id == 0) id = id_global_pool_.alloc_id_for_thread(L);
|
||||
|
||||
// Create the C++ part of the structure.
|
||||
Tangible *t = &tangibles_[id];
|
||||
assert(t->world_ == nullptr);
|
||||
t->world_ = this;
|
||||
t->plane_item_.set_id(id);
|
||||
plane_map_.track(&t->plane_item_);
|
||||
|
||||
// Create the tangible's database and metatable.
|
||||
@@ -77,6 +104,7 @@ Tangible *World::tangible_make(lua_State *L) {
|
||||
// LS.setfield(metatab, "__metatable", LuaNil);
|
||||
|
||||
LS.result();
|
||||
if (!pushdb) lua_pop(L, 1);
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -101,6 +129,6 @@ LuaDefine(tangible_get, "c") {
|
||||
}
|
||||
|
||||
LuaDefine(tangible_make, "c") {
|
||||
World::fetch(L)->tangible_make(L);
|
||||
World::fetch(L)->tangible_make(L, 0, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user