Navigation Menu

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

Builtin item: Tidy up the code #4370

Merged
merged 3 commits into from Aug 24, 2017

Conversation

SmallJoker
Copy link
Member

@SmallJoker SmallJoker commented Jul 28, 2016

This commit changes the behaviour of try_merge_with:

  • self collects all similar items around instead of splitting (and deleting)

@t4im
Copy link
Contributor

t4im commented Jul 29, 2016

If you already change assumed gravity, then you should probably get the value from movement_gravity, not hardcode it.

That won't account for realm specific overrides on players, but at least then it's consistent with server wide settings.

@SmallJoker
Copy link
Member Author

I need more opinions how the behaviour of the builtin item should be. From my side it looks okay.

@SmallJoker SmallJoker force-pushed the cleanup_builtin_item branch 2 times, most recently from c626eeb to faca89f Compare July 29, 2016 18:58
@tenplus1
Copy link
Contributor

tenplus1 commented Aug 6, 2016

I would adjust merge radius to 1.0, but everything else works a-ok that I'm using changes on Xanadu server.

@SmallJoker SmallJoker force-pushed the cleanup_builtin_item branch 3 times, most recently from e12dab4 to 4908238 Compare August 7, 2016 11:52
@SmallJoker
Copy link
Member Author

Comments for the last commit:
The age of an item will be reset when it merged with others. This makes sense because the total entity count decreased, so there's no problem in keeping one item longer.
Also changed the merge radius to 1m, this will collect more items and result in less items on the floor.

I'm glad to see that everything runs fine on Xanadu, this means there were no problems found with these changes.

@SmallJoker
Copy link
Member Author

Rebased.
@sofar I tried using your modified wool code + the palette submitted by juhdanad but I have no clue how to reproduce #5407 (comment) 1) using current HEAD and 2) with this pull applied.

@SmallJoker SmallJoker added the Rebase needed The PR needs to be rebased by its author. label May 21, 2017
@SmallJoker SmallJoker removed the Rebase needed The PR needs to be rebased by its author. label Jun 14, 2017
Copy link
Member

@rubenwardy rubenwardy left a comment

Choose a reason for hiding this comment

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

haven't tested

local count = math.min(stack:get_count(), max_count)
local size = 0.2 + 0.1 * (count / max_count)

if not core.registered_items[itemname] then
Copy link
Member

Choose a reason for hiding this comment

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

odd how the old code didn't take aliases into account


local stack = ItemStack(entity.itemstring)
local name = stack:get_name()
if own_stack:get_name() ~= name
Copy link
Member

Choose a reason for hiding this comment

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

with use breaks after binary operators

return false
-- Merge the remote stack into this one

local pos = object:getpos()
Copy link
Member

Choose a reason for hiding this comment

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

get_pos


local pos = object:getpos()
pos.y = pos.y + ((total_count - count) / max_count) * 0.15
self.object:moveto(pos)
Copy link
Member

Choose a reason for hiding this comment

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

move_to

-- Don't infinetly fall into unloaded map
self.object:setvelocity({x = 0, y = 0, z = 0})

local pos = self.object:getpos()
Copy link
Member

Choose a reason for hiding this comment

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

get_pos()

self.object:setvelocity({x = 0, y = 0, z = 0})

local pos = self.object:getpos()
local node = minetest.get_node({
Copy link
Member

Choose a reason for hiding this comment

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

core as in builtin

return
end

self.object:setvelocity({x=0, y=0, z=0})
Copy link
Member

Choose a reason for hiding this comment

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

set_velocity

})

if is_falling then
self.object:setacceleration({x = 0, y = -gravity, z = 0})
Copy link
Member

Choose a reason for hiding this comment

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

set_acceleration


if is_falling then
self.object:setacceleration({x = 0, y = -gravity, z = 0})
else
self.object:setacceleration({x = 0, y = 0, z = 0})
Copy link
Member

Choose a reason for hiding this comment

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

set_acceleration

@SmallJoker
Copy link
Member Author

Thanks for the review. Does it look right now?

Copy link
Member

@rubenwardy rubenwardy left a comment

Choose a reason for hiding this comment

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

👍 needs testing however

self.object:set_acceleration({x = 0, y = 0, z = 0})
end

-- Collect the items around to merge with
Copy link
Contributor

@paramat paramat Aug 23, 2017

Choose a reason for hiding this comment

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

Previously, merging is only attempted if the item has 'physical_state' true (in motion). The merging function is intensive so should not run for stationary ('physical_state' false) items, which are the majority of items present in a world.
Although i'm not too sure, this new code looks like it can run merging for stationary items?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not an issue, as this code part is only executed when the physical state changes. For stationary items this code part will not be executed at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok.

@paramat
Copy link
Contributor

paramat commented Aug 23, 2017

I'm ok with the changes to 'try merge with'.

My fixing of items on ice (which may be added to this PR) means your changes to 'on step' cannot be done in the same way.
For example, now that we have sliding on ice, an item can be in motion ('physical_state' true) without falling, because it is supported by a node and is moving horizontally.

So, 'on step' needs to be copied from #6300 and then possibly developed from that code.
Apart from my line comment everything else seems ok as far as i can tell.

@paramat paramat added the WIP The PR is still being worked on by its author and not ready yet. label Aug 23, 2017
Use setting movement_gravity
Reset age on merge
Set merge radius to 1.0m
@SmallJoker SmallJoker removed the WIP The PR is still being worked on by its author and not ready yet. label Aug 24, 2017
local slip_factor = 4.0 / (slippery + 4)
self.object:set_acceleration({
x = -vel.x * slip_factor,
y = 0,
Copy link
Contributor

@paramat paramat Aug 24, 2017

Choose a reason for hiding this comment

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

It's possible that a walkable node is detected below before the item has hit it, so detecting a walkable node below should not set always set acceleration to zero. This will be difficult to notice visually but is incorrect physics.

The item is physical when it is in motion so that it uses it's collisionbox to stop moving vertically, then when vertical velocity becomes zero (we need to detect this, as in the previous code) we know it has hit a node and is supported by it and we can then set vertical motion to zero.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seeting motion to zero when a walkable node below is detected may result in the item floating above or slightly buried in the node.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I'm using the collisionbox height now to detect the node below to ensure that the item is correctly lying on the node.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok good.

local slippery = core.get_item_group(node.name, "slippery")
is_slippery = slippery ~= 0
if is_slippery then
is_physical = true
Copy link
Contributor

@paramat paramat Aug 24, 2017

Choose a reason for hiding this comment

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

It's possible that a walkable node is detected below before the item has hit it, because we don't know the size and offset of the item's collisionbox (and these vary). If the node is not slippery then this code sets physical to false (no motion), which is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Abrupt stops of the item when a non-slippery node was detected is fixed now.

Copy link
Contributor

Choose a reason for hiding this comment

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

screenshot_20170824_211702

Yes i noticed floating.

@paramat paramat added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Aug 24, 2017
@paramat
Copy link
Contributor

paramat commented Aug 24, 2017

Will retest.

@paramat
Copy link
Contributor

paramat commented Aug 24, 2017

Ok seems to work now so 👍

@SmallJoker SmallJoker merged commit d3f1743 into minetest:master Aug 24, 2017
@SmallJoker SmallJoker deleted the cleanup_builtin_item branch December 14, 2017 15:56
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 11, 2019
New code structure
Use setting movement_gravity
Reset age on merge
Set merge radius to 1.0m
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 23, 2019
New code structure
Use setting movement_gravity
Reset age on merge
Set merge radius to 1.0m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Action / change needed Code still needs changes (PR) / more information requested (Issues) @ Server / Client / Env. >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants