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

mvps: improve object move #367

Merged
merged 4 commits into from
Oct 8, 2017
Merged

Conversation

Desour
Copy link
Contributor

@Desour Desour commented Sep 9, 2017

Objects with big collision boxes are moved.
Objects in stack are moved, not only at front. Ergo fixes #361.
Objects lying on top of the nodestack aren't moved anymore. Bad? Edit: fixed.

Copy link
Contributor

@numberZero numberZero left a comment

Choose a reason for hiding this comment

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

Mostly good.

obj:setpos(np)
if ok then
local ent = obj:get_luaentity()
if not ent or not mesecon.is_mvps_unmov(ent.name) then
Copy link
Contributor

Choose a reason for hiding this comment

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

if ent and ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not (ent and …)

local nn = minetest.get_node(np)
local node_def = minetest.registered_nodes[nn.name]
if (node_def and not node_def.walkable) or
math.abs(obj_pos[dir_k]) <= #nodestack - 0.5 + math.abs(pos[dir_k]) then
Copy link
Contributor

Choose a reason for hiding this comment

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

What if signs of pos[dir_k] and obj_pos[dir_k] are different?

local edge1, edge2
if k ~= dir_k then
edge1 = v - 0.5
edge2 = v + 0.5
Copy link
Contributor

Choose a reason for hiding this comment

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

Objects lying on top of the nodestack aren't moved anymore. Bad?

You mean, when pushing horizontally? That’s acceptable, but may be fixed by increasing (slightly) constant here, if I understand the code correctly.

if edge1 > edge2 then
edge1, edge2 = edge2, edge1
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

edges may be pre-calculated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

? This works well enough imo, I can't find a simpler way.

Copy link
Contributor

Choose a reason for hiding this comment

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

This exact way, but before for id, obj in pairs(minetest.object_refs) do and not in the inner loop.

local objects = minetest.get_objects_inside_radius(p_above, 1)
for _, obj in ipairs(objects) do
table.insert(objects_to_move, obj)
for id, obj in pairs(minetest.object_refs) do
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems horribly, but that’s the only way; MT itself does the same, all the time...

@Desour
Copy link
Contributor Author

Desour commented Oct 3, 2017

Comments addressed.

obj:setpos(np)
if ok then
local ent = obj:get_luaentity()
if not (ent and mesecon.is_mvps_unmov(ent.name)) then
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work at all?
The correct way seems to be if ent and not mesecon.is_mvps_unmov(ent.name) then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is correct, don't forget players.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry.
Then the previous variant was better. But such clever code needs a comment, at least.
And, well, there is is_player.

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, if obj:is_player() or not mesecon.is_mvps_unmov(obj:get_luaentity().name) then?

if edge1 > edge2 then
edge1, edge2 = edge2, edge1
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This exact way, but before for id, obj in pairs(minetest.object_refs) do and not in the inner loop.

local np = vector.add(obj_pos, dir)
-- Move only if destination is not solid or object is inside stack:
local nn = minetest.get_node(np)
local node_def = minetest.registered_nodes[nn.name]
local nodestack_front = (#nodestack - 0.5 + math.abs(pos[dir_k]))
nodestack_front = nodestack_front * pos[dir_k]/math.abs(pos[dir_k])
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird math. Can you write something simpler? Remember that you have dir_l.
Or let me do that (a bit later).

Make the check logic obvious. Also, it won't try to move unknown or bogus things, if any.
@numberZero numberZero merged commit c4a1aa0 into minetest-mods:master Oct 8, 2017
@Desour Desour deleted the mvps_move_obj branch October 8, 2017 16:42
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.

Piston with node doesn't push players/entities with most drawtypes
2 participants