Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom: Set zoom FOV per-player using a player object property #6650

Closed
wants to merge 1 commit into from
Closed

Zoom: Set zoom FOV per-player using a player object property #6650

wants to merge 1 commit into from

Conversation

paramat
Copy link
Contributor

@paramat paramat commented Nov 20, 2017

Zoom: Set zoom FOV per-player using a player object property

Remove player object property 'can zoom'.
Add player object property 'zoom fov'.
Remove clientside setting for 'zoom fov'.
Object property default is 15 degrees in creative mode, zoom disabled
in survival mode.

Needed due to zoom now loading and/or generating distant world
according to zoom FOV.

Update object properties serialisation version to 3.
///////////////

Merge minetest/minetest_game#1956 soon after this.

Together with lhofhansl's recent work this will allow a game to provide an item which enables a particular zoom FOV, which in turn allows a certain distance of world to be loaded in when using zoom.
For example a powerful telescope item that allows a zoom FOV of 1 degree, which is capable of loading (and/or generating) world 2000 nodes away.

A server mod can still disable zooming for a player by setting zoom FOV to 0. So the functionality of the previous 'can zoom' property is kept.

@paramat paramat added @ Server / Client / Env. Feature ✨ PRs that add or enhance a feature labels Nov 20, 2017
@@ -109,7 +109,7 @@ void ObjectProperties::serialize(std::ostream &os) const
writeF1000(os, automatic_face_movement_max_rotation_per_sec);
os << serializeString(infotext);
os << serializeString(wield_item);
writeU8(os, can_zoom);
writeF1000(os, zoom_fov);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to just change this and not move it? The comment for this section says to only add stuff to the bottom and not remove anything, but maybe that doesn't apply since we are breaking compatibility and 'can zoom' was added during 0.5.0dev.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause an offset in the ObjectProperties' network packet (before: 8 bits, now: 32 bits)
Yes, we are in backwards compat breakage but nevertheless you should either raise the version number here from 2 to 3 or deprecate this single byte.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising version just for this seems excessive.
Maybe it's best to keep using 'can zoom' also.
By deprecation i assume you mean keep writing 'can zoom' but set it to a fixed bool and don't read it? I don't like the messiness of that.

lua_pushboolean(L, prop->can_zoom);
lua_setfield(L, -2, "can_zoom");
lua_pushnumber(L, prop->zoom_fov);
lua_setfield(L, -2, "zoom_fov");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, i always do docs last.

@paramat paramat added the WIP The PR is still being worked on by its author and not ready yet. label Nov 20, 2017
@paramat
Copy link
Contributor Author

paramat commented Nov 21, 2017

Not sure which of the 3 options to do:
Raise version 2>3.
Deprecate the byte (packets then have an unused byte).
Keep 'can zoom' and just add 'zoom fov'.

EDIT: I decided to raise version to 3.

@ghost
Copy link

ghost commented Nov 21, 2017 via email

@paramat
Copy link
Contributor Author

paramat commented Nov 22, 2017

Updated with version raised to 3.

@paramat
Copy link
Contributor Author

paramat commented Nov 24, 2017

Has a bug. I'm not actually changing m_cache_zoom_fov.

@paramat paramat removed the WIP The PR is still being worked on by its author and not ready yet. label Nov 24, 2017
@paramat
Copy link
Contributor Author

paramat commented Nov 24, 2017

Ok fixed, retested and docs added, ready for review.

@paramat
Copy link
Contributor Author

paramat commented Nov 28, 2017

Tested with MTG PR.
Only thing i'm not confident about is my increasing of object property version number.

src/camera.cpp Outdated
if (player->getPlayerControl().zoom && player->getCanZoom()) {
fov_degrees = m_cache_zoom_fov;
// Disable zoom with zoom FOV = 0
if (player->getPlayerControl().zoom && player->getZoomFOV() != 0.0f) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps change this to player->getZoomFOV() > 0.001f for floating point errors and invalid input from Lua-side (as negative values sometimes disable other features)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@@ -60,6 +59,7 @@ struct ObjectProperties
std::string wield_item;
bool static_save = true;
float eye_height = 1.625f;
float zoom_fov = 15.0f;
Copy link
Member

@SmallJoker SmallJoker Dec 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the server will force a zoom fov of 15 as soon the ObjectProperties are sent to the player. The client has no control about the limits.

Copy link
Contributor Author

@paramat paramat Dec 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this struct does not set the defaults for properties, these values are overriden in content_sao, however currently to the wrong value (the server's zoom_fov setting).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But see my other line comments for a related problem.

@paramat
Copy link
Contributor Author

paramat commented Dec 1, 2017

Is the way i increased object property version correct?
I need to add a mention of this to network protocol, but any need to increase protocol number?

@paramat
Copy link
Contributor Author

paramat commented Dec 1, 2017

IRC:

Krock paramat, the object property version change was done correctly. the network version could be raised too, but is not required as we're breaking the backwards compatibility and clients will get an error when connecting to the server

@paramat paramat added the WIP The PR is still being worked on by its author and not ready yet. label Dec 1, 2017
@paramat
Copy link
Contributor Author

paramat commented Dec 2, 2017

Updated but more testing coming.

m_hp = m_prop.hp_max;
m_breath = m_prop.breath_max;
// Allow the client to set a limited range of zoom FOV, a more powerful
// zoom can only be set by server mods.
m_prop.zoom_fov = rangelim(g_settings->getFloat("zoom_fov"), 15.0f, 160.0f);
Copy link
Contributor Author

@paramat paramat Dec 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this, seems this will get the 'zoom_fov' of the server not the client.
My testing has been with 2 instances of MT, both with identical zoom_fov settings, which may have caused false testing results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is, when any property is set, all of these are set, which will then override the client's 'zoom_fov' setting. I need to work on this.

bool getCanZoom() const { return m_can_zoom; }
void setCanZoom(bool can_zoom) { m_can_zoom = can_zoom; }
float getZoomFOV() const { return m_zoom_fov; }
void setZoomFOV(float zoom_fov) { m_zoom_fov = zoom_fov; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i think this should only be changed if the value is being altered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that won't work, the server has no idea what the client's local setting is.

@paramat
Copy link
Contributor Author

paramat commented Dec 2, 2017

This is getting more tricky the more i think about it.

@paramat
Copy link
Contributor Author

paramat commented Dec 2, 2017

The client's local zoomFOV setting is the problem and has to be removed, unfortunately. All other object properties are not client-settable which is why they avoid the problems i'm encountering.
This is probably for the best as zoom now loads and/or generates distant world, so should really be under full control of server mods, as zoom now gives players significant powers and advantages. If necessary a server mod can set zoomFOV per-player to their desired values.

@paramat
Copy link
Contributor Author

paramat commented Dec 2, 2017

Updated but in testing.

Remove player object property 'can zoom'.
Add player object property 'zoom fov'.
Remove clientside setting for 'zoom fov'.
Object property default is 15 degrees in creative mode, zoom disabled
in survival mode.

Needed due to zoom now loading and/or generating distant world
according to zoom FOV.

Update object properties serialisation version to 3.
@paramat paramat removed the WIP The PR is still being worked on by its author and not ready yet. label Dec 3, 2017
@paramat
Copy link
Contributor Author

paramat commented Dec 3, 2017

Updated and tested, ready for merge.
@SmallJoker

The client 'zoom fov' setting is removed. As zoom now loads and/or generated distant world beyond the server's send/generate distances, zoom FOV should be under server control (not client setting or CSM).
The default zoom FOV is 15 degrees in creative mode, disabled (using the value 0) in survival mode.
Server mods are needed for a zoom FOV other than 15 degrees.

-- ^ For players only. Zoom FOV in degrees.
-- Note that zoom loads and/or generates world beyond the server's maximum
-- send and generate distances, so acts like a telescope.
-- Smaller zoomFOV values increase the distance loaded and/or generated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessary to provide this information, as people expect this to happen anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those used to MT don't expect it, so it's a warning about this powerful ability.

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, code and functionality-wise.

@paramat
Copy link
Contributor Author

paramat commented Dec 4, 2017

f470cb7

@lhofhansl
Copy link
Contributor

So in creative mode a "zoom-tool" can still override the default 15 degrees zoom FOV, right?

@paramat
Copy link
Contributor Author

paramat commented Dec 11, 2017

Yes as in the binoculars mod:

function binoculars.update_player_property(player)
	local creative_enabled =
		(creative_mod and creative.is_enabled_for(player:get_player_name())) or
		creative_mode_cache
	local new_zoom_fov = 0

	if player:get_inventory():contains_item(
			"main", "binoculars:binoculars") then
		new_zoom_fov = 10
	elseif creative_enabled then
		new_zoom_fov = 15
	end

	-- Only set property if necessary to avoid player mesh reload
	if player:get_properties().zoom_fov ~= new_zoom_fov then
		player:set_properties({zoom_fov = new_zoom_fov})
	end
end

@paramat paramat deleted the zoomfovpop branch December 18, 2017 22:06
@lhofhansl
Copy link
Contributor

lhofhansl commented Dec 20, 2017

Trying this a bit. I'm not a fan of not being to able to control the zoom in creative mode anymore (if just for testing higher zooms). In fact I think this should be a prominent config option (which can overridden by mods)

@paramat

@paramat
Copy link
Contributor Author

paramat commented Dec 20, 2017

You can set zoomFOV easily in creative with a 3 line mod. A tiny bit less convenient but no issue.

You mean you prefer clientside control of zoomFOV in creative mode? If so i disagree with that due to the power zoom now has, it may be creative mode but i don't think clients can have that power clientside, after all it loads distant terrain and overrides the server's own send and generate distances. The server should obviously have control over it.

It's like CSM, things that can significantly affect a server can't be clientside.

Servers can use a mod that gives players the ability to choose their own zoomFOV, or can set any zoomFOV they want for creative.
The clientside zoomFOV setting made everything complex, i had to remove it to make the feature work.

@lhofhansl
Copy link
Contributor

I see. Client can still set the FOV (though there's a lower limit of 30). It seems inconsistent not to be able to set the zoom fov. The fact that there's perhaps more server load is a but specious; that applies to the normal fov as well, which can be set to 180 degrees, which causes about 3x the server load.

I get the point, though.

In that case I would prefer that there be absolutely no zoom by default (i.e. unless granted by some mod in some way, such as now done in MT game). The hardcoded 15 is definitely arbitrary.

@paramat
Copy link
Contributor Author

paramat commented Dec 24, 2017

I kept 15 for creative because that was the former default and i expected there would be complaints if it was disabled by default in creative, but i personally don't mind if it's disabled by default in creative mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants