Skip to content

Commit 561a01c

Browse files
committedAug 30, 2017
Zoom: Move enabling zoom to a new player object property
Default enabled for no change in default behaviour. Remove 'zoom' privilege.
1 parent bd6b903 commit 561a01c

8 files changed

+20
-11
lines changed
 

‎builtin/game/privileges.lua

-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ core.register_privilege("rollback", {
8282
description = "Can use the rollback functionality",
8383
give_to_singleplayer = false,
8484
})
85-
core.register_privilege("zoom", {
86-
description = "Can zoom the camera",
87-
give_to_singleplayer = false,
88-
})
8985
core.register_privilege("debug", {
9086
description = "Allows enabling various debug options that may affect gameplay",
9187
give_to_singleplayer = false,

‎src/camera.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
453453

454454
// Get FOV
455455
f32 fov_degrees;
456-
if (player->getPlayerControl().zoom && m_client->checkLocalPrivilege("zoom")) {
456+
if (player->getPlayerControl().zoom && player->getCanZoom()) {
457457
fov_degrees = m_cache_zoom_fov;
458458
} else {
459459
fov_degrees = m_cache_fov;

‎src/content_cao.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ void GenericCAO::processMessage(const std::string &data)
12391239
collision_box.MinEdge *= BS;
12401240
collision_box.MaxEdge *= BS;
12411241
player->setCollisionbox(collision_box);
1242+
player->setCanZoom(m_prop.can_zoom);
12421243
}
12431244

12441245
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())

‎src/content_sao.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
801801
m_prop.is_visible = true;
802802
m_prop.makes_footstep_sound = true;
803803
m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS;
804+
m_prop.can_zoom = true;
804805
m_hp = m_prop.hp_max;
805806
}
806807

‎src/localplayer.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ class LocalPlayer : public Player
124124
v3s16 getLightPosition() const;
125125

126126
void setYaw(f32 yaw) { m_yaw = yaw; }
127-
128127
f32 getYaw() const { return m_yaw; }
129128

130129
void setPitch(f32 pitch) { m_pitch = pitch; }
131-
132130
f32 getPitch() const { return m_pitch; }
133131

134132
inline void setPosition(const v3f &position)
@@ -143,6 +141,9 @@ class LocalPlayer : public Player
143141

144142
void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }
145143

144+
bool getCanZoom() const { return m_can_zoom; }
145+
void setCanZoom(bool can_zoom) { m_can_zoom = can_zoom; }
146+
146147
private:
147148
void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
148149
void accelerateVertical(const v3f &target_speed, const f32 max_increase);
@@ -178,6 +179,7 @@ class LocalPlayer : public Player
178179
bool camera_barely_in_ceiling = false;
179180
aabb3f m_collisionbox = aabb3f(-BS * 0.30f, 0.0f, -BS * 0.30f, BS * 0.30f,
180181
BS * 1.75f, BS * 0.30f);
182+
bool m_can_zoom = true;
181183

182184
GenericCAO *m_cao = nullptr;
183185
Client *m_client;

‎src/object_properties.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ std::string ObjectProperties::dump()
6363
<< "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" ";
6464
os << ", selectionbox=" << PP(selectionbox.MinEdge) << "," << PP(selectionbox.MaxEdge);
6565
os << ", pointable=" << pointable;
66+
os << ", can_zoom=" << can_zoom;
6667
return os.str();
6768
}
6869

@@ -104,6 +105,7 @@ void ObjectProperties::serialize(std::ostream &os) const
104105
writeF1000(os, automatic_face_movement_max_rotation_per_sec);
105106
os << serializeString(infotext);
106107
os << serializeString(wield_item);
108+
writeU8(os, can_zoom);
107109

108110
// Add stuff only at the bottom.
109111
// Never remove anything, because we don't want new versions of this
@@ -150,4 +152,5 @@ void ObjectProperties::deSerialize(std::istream &is)
150152
automatic_face_movement_max_rotation_per_sec = readF1000(is);
151153
infotext = deSerializeString(is);
152154
wield_item = deSerializeString(is);
155+
can_zoom = readU8(is);
153156
}

‎src/object_properties.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ struct ObjectProperties
4444
v2s16 initial_sprite_basepos;
4545
bool is_visible = true;
4646
bool makes_footstep_sound = false;
47-
float automatic_rotate = 0.0f;
4847
f32 stepheight = 0.0f;
48+
bool can_zoom = true;
49+
float automatic_rotate = 0.0f;
4950
bool automatic_face_movement_dir = false;
5051
f32 automatic_face_movement_dir_offset = 0.0f;
5152
bool backface_culling = true;

‎src/script/common/c_content.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,11 @@ void read_object_properties(lua_State *L, int index,
260260

261261
getboolfield(L, -1, "is_visible", prop->is_visible);
262262
getboolfield(L, -1, "makes_footstep_sound", prop->makes_footstep_sound);
263-
getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
264263
if (getfloatfield(L, -1, "stepheight", prop->stepheight))
265264
prop->stepheight *= BS;
265+
getboolfield(L, -1, "can_zoom", prop->can_zoom);
266+
267+
getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
266268
lua_getfield(L, -1, "automatic_face_movement_dir");
267269
if (lua_isnumber(L, -1)) {
268270
prop->automatic_face_movement_dir = true;
@@ -344,10 +346,13 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
344346
lua_setfield(L, -2, "is_visible");
345347
lua_pushboolean(L, prop->makes_footstep_sound);
346348
lua_setfield(L, -2, "makes_footstep_sound");
347-
lua_pushnumber(L, prop->automatic_rotate);
348-
lua_setfield(L, -2, "automatic_rotate");
349349
lua_pushnumber(L, prop->stepheight / BS);
350350
lua_setfield(L, -2, "stepheight");
351+
lua_pushboolean(L, prop->can_zoom);
352+
lua_setfield(L, -2, "can_zoom");
353+
354+
lua_pushnumber(L, prop->automatic_rotate);
355+
lua_setfield(L, -2, "automatic_rotate");
351356
if (prop->automatic_face_movement_dir)
352357
lua_pushnumber(L, prop->automatic_face_movement_dir_offset);
353358
else

0 commit comments

Comments
 (0)
Please sign in to comment.