summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorAnand S <ClobberXD@gmail.com>2018-07-15 05:56:30 +0530
committersfan5 <sfan5@live.de>2019-09-19 20:14:16 +0200
commit47da640d7763ee1e00badb7476ac5afc4f864367 (patch)
treed12bee2e2cfc1b1c4a4a51e318d692b11ee5fbaf /src/script
parent5c9983400fb085167bf11f8a0483b8e8f6dd8a24 (diff)
downloadminetest-47da640d7763ee1e00badb7476ac5afc4f864367.tar.gz
minetest-47da640d7763ee1e00badb7476ac5afc4f864367.tar.bz2
minetest-47da640d7763ee1e00badb7476ac5afc4f864367.zip
Add support for per-player FOV overrides and multipliers
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_object.cpp33
-rw-r--r--src/script/lua_api/l_object.h6
2 files changed, 39 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 68cc1c0a9..1ad79024f 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -1249,6 +1249,37 @@ int ObjectRef::l_set_look_yaw(lua_State *L)
return 1;
}
+// set_fov(self, degrees[, is_multiplier])
+int ObjectRef::l_set_fov(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (!player)
+ return 0;
+
+ player->setFov({ static_cast<f32>(luaL_checknumber(L, 2)), readParam<bool>(L, 3) });
+ getServer(L)->SendPlayerFov(player->getPeerId());
+
+ return 0;
+}
+
+// get_fov(self)
+int ObjectRef::l_get_fov(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (!player)
+ return 0;
+
+ PlayerFovSpec fov_spec = player->getFov();
+ lua_pushnumber(L, fov_spec.fov);
+ lua_pushboolean(L, fov_spec.is_multiplier);
+
+ return 2;
+}
+
// set_breath(self, breath)
int ObjectRef::l_set_breath(lua_State *L)
{
@@ -1962,6 +1993,8 @@ luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, set_look_vertical),
luamethod(ObjectRef, set_look_yaw),
luamethod(ObjectRef, set_look_pitch),
+ luamethod(ObjectRef, get_fov),
+ luamethod(ObjectRef, set_fov),
luamethod(ObjectRef, get_breath),
luamethod(ObjectRef, set_breath),
luamethod(ObjectRef, get_attribute),
diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h
index 2390c5195..e817e1d33 100644
--- a/src/script/lua_api/l_object.h
+++ b/src/script/lua_api/l_object.h
@@ -215,6 +215,9 @@ private:
// add_player_velocity(self, {x=num, y=num, z=num})
static int l_add_player_velocity(lua_State *L);
+ // get_fov(self)
+ static int l_get_fov(lua_State *L);
+
// get_look_dir(self)
static int l_get_look_dir(lua_State *L);
@@ -232,6 +235,9 @@ private:
// get_look_yaw2(self)
static int l_get_look_horizontal(lua_State *L);
+ // set_fov(self, degrees, is_multiplier)
+ static int l_set_fov(lua_State *L);
+
// set_look_vertical(self, radians)
static int l_set_look_vertical(lua_State *L);