A few animation primitives
This commit is contained in:
@@ -37,6 +37,12 @@ World::World() {
|
|||||||
assert (lua_gettop(state()) == 0);
|
assert (lua_gettop(state()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tangible::update_plane_item() {
|
||||||
|
util::XYZ xyz = anim_queue_.get_xyz();
|
||||||
|
std::string plane = anim_queue_.get_plane();
|
||||||
|
plane_item_.set_pos(plane, xyz.x, xyz.y, xyz.z);
|
||||||
|
}
|
||||||
|
|
||||||
void Tangible::be_a_player() {
|
void Tangible::be_a_player() {
|
||||||
if (id_player_pool_ == nullptr) {
|
if (id_player_pool_ == nullptr) {
|
||||||
id_player_pool_.reset(new IdPlayerPool(&world_->id_global_pool_));
|
id_player_pool_.reset(new IdPlayerPool(&world_->id_global_pool_));
|
||||||
@@ -78,6 +84,25 @@ Tangible *World::tangible_get(int64_t id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tangible *World::tangible_get(lua_State *L, int idx) {
|
||||||
|
Tangible *result = nullptr;
|
||||||
|
int top = lua_gettop(L);
|
||||||
|
if (lua_istable(L, idx)) {
|
||||||
|
lua_getmetatable(L, idx);
|
||||||
|
if (lua_istable(L, -1)) {
|
||||||
|
lua_pushstring(L, "id");
|
||||||
|
lua_rawget(L, -2);
|
||||||
|
lua_Number id = lua_tonumber(L, -1);
|
||||||
|
result = tangible_get(int64_t(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lua_settop(L, top);
|
||||||
|
if (result == nullptr) {
|
||||||
|
luaL_error(L, "parameter is not a tangible");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<int64_t> World::get_near(int64_t player_id, float radius) {
|
std::vector<int64_t> World::get_near(int64_t player_id, float radius) {
|
||||||
Tangible *player = tangible_get(player_id);
|
Tangible *player = tangible_get(player_id);
|
||||||
|
|
||||||
@@ -327,14 +352,31 @@ void World::run_scheduled_threads(int64_t clk) {
|
|||||||
LS.result();
|
LS.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaDefine(tangible_get, "c") {
|
LuaDefine(tangible_xyz, "c") {
|
||||||
LuaArg id;
|
LuaArg tanobj;
|
||||||
LuaRet database;
|
LuaRet X, Y, Z;
|
||||||
LuaVar tangibles;
|
LuaStack LS(L, tanobj, X, Y, Z);
|
||||||
LuaStack LS(L, id, database, tangibles);
|
World *w = World::fetch_global_pointer(L);
|
||||||
|
Tangible *tan = w->tangible_get(L, tanobj.index());
|
||||||
|
util::XYZ xyz = tan->anim_queue_.get_xyz();
|
||||||
|
LS.set(X, xyz.x);
|
||||||
|
LS.set(Y, xyz.y);
|
||||||
|
LS.set(Z, xyz.z);
|
||||||
|
return LS.result();
|
||||||
|
}
|
||||||
|
|
||||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
LuaDefine(tangible_walkto, "c") {
|
||||||
LS.rawget(database, tangibles, id);
|
LuaArg tanobj, x, y, z;
|
||||||
|
LuaStack LS(L, tanobj, x, y, z);
|
||||||
|
World *w = World::fetch_global_pointer(L);
|
||||||
|
lua_Number nx = LS.cknumber(x);
|
||||||
|
lua_Number ny = LS.cknumber(y);
|
||||||
|
lua_Number nz = LS.cknumber(z);
|
||||||
|
Tangible *tan = w->tangible_get(L, tanobj.index());
|
||||||
|
int64_t id = w->id_global_pool_.alloc_id_for_thread(L);
|
||||||
|
tan->anim_queue_.add(id, "walk");
|
||||||
|
tan->anim_queue_.set_xyz(util::XYZ(nx, ny, nz));
|
||||||
|
tan->update_plane_item();
|
||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public:
|
|||||||
std::unique_ptr<IdPlayerPool> id_player_pool_;
|
std::unique_ptr<IdPlayerPool> id_player_pool_;
|
||||||
|
|
||||||
void be_a_player();
|
void be_a_player();
|
||||||
|
void update_plane_item();
|
||||||
};
|
};
|
||||||
|
|
||||||
class World {
|
class World {
|
||||||
@@ -111,6 +112,13 @@ public:
|
|||||||
//
|
//
|
||||||
Tangible *tangible_get(int64_t id);
|
Tangible *tangible_get(int64_t id);
|
||||||
|
|
||||||
|
// Get a pointer to the specified tangible.
|
||||||
|
//
|
||||||
|
// The value on the lua stack should be a valid lua tangible. If not,
|
||||||
|
// a lua error is generated.
|
||||||
|
//
|
||||||
|
Tangible *tangible_get(lua_State *L, int idx);
|
||||||
|
|
||||||
// Delete a tangible with the specified ID.
|
// Delete a tangible with the specified ID.
|
||||||
//
|
//
|
||||||
// If the tangible doesn't exist, does nothing.
|
// If the tangible doesn't exist, does nothing.
|
||||||
|
|||||||
@@ -9,18 +9,26 @@ end
|
|||||||
|
|
||||||
function player.action.north(actor, place, dialog)
|
function player.action.north(actor, place, dialog)
|
||||||
print("Moving north")
|
print("Moving north")
|
||||||
|
x,y,z = tangible.xyz(place);
|
||||||
|
tangible.walkto(place, x, y+1, z);
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.action.south(actor, place, dialog)
|
function player.action.south(actor, place, dialog)
|
||||||
print("Moving south")
|
print("Moving south")
|
||||||
|
x,y,z = tangible.xyz(place);
|
||||||
|
tangible.walkto(place, x, y-1, z);
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.action.east(actor, place, dialog)
|
function player.action.east(actor, place, dialog)
|
||||||
print("Moving east")
|
print("Moving east")
|
||||||
|
x,y,z = tangible.xyz(place);
|
||||||
|
tangible.walkto(place, x+1, y, z);
|
||||||
end
|
end
|
||||||
|
|
||||||
function player.action.west(actor, place, dialog)
|
function player.action.west(actor, place, dialog)
|
||||||
print("Moving west")
|
print("Moving west")
|
||||||
|
x,y,z = tangible.xyz(place)
|
||||||
|
tangible.walkto(place, x-1, y, z);
|
||||||
wait(0)
|
wait(0)
|
||||||
print("Moving west again")
|
print("Moving west again")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user