[WIP] env_damage fires too often, sheep eat landscape #3434

Closed
emptyshore wants to merge 1 commits from emptyshore:sheep_destroy_landscape into master
Member

A quick look at MineClone2/MineClone2#3428

env_damage is executed every on_step without the regards to the timer.
The code assumes it executes once per second.

Add the missing timer check to make the handler execute every 1s.

A quick look at https://git.minetest.land/MineClone2/MineClone2/issues/3428 env_damage is executed every on_step without the regards to the timer. The code assumes it executes once per second. Add the missing timer check to make the handler execute every 1s.
Author
Member

Essentially, the check for eating grass runs constantly - when I dumped the log, the d20 dice roll (replace_rate=20) happens every 0.05s, which I presume is the on_step cadence, so with the sheep's replace_rate of 20, the eating rate is about one block per 20*0.05s = 1s - one block per second. Which is about equal to what I see - I can draw a dirt line with a sheep and a piece of wheat :)

This is just a sketch. Things to figure out:

  • why is there a double trigger in api.lua for env_damage?
  • what is the correct rate of eating?
  • was there a timer in the past? was this implemented in some other way?
Essentially, the check for eating grass runs constantly - when I dumped the log, the d20 dice roll (replace_rate=20) happens every 0.05s, which I presume is the on_step cadence, so with the sheep's replace_rate of 20, the eating rate is about one block per `20*0.05s = 1s` - one block per second. Which is about equal to what I see - I can draw a dirt line with a sheep and a piece of wheat :) This is just a sketch. Things to figure out: * why is there a double trigger in api.lua for env_damage? * what is the correct rate of eating? * was there a timer in the past? was this implemented in some other way?
emptyshore force-pushed sheep_destroy_landscape from 346a3e75ca to 7fb98efb30 2023-02-11 00:40:19 +01:00 Compare
emptyshore force-pushed sheep_destroy_landscape from 7fb98efb30 to a5f7ffd905 2023-02-11 00:44:49 +01:00 Compare
emptyshore force-pushed sheep_destroy_landscape from a5f7ffd905 to a7494584db 2023-02-11 00:46:26 +01:00 Compare

I've already self-assigned this and commented. Why did you pick this up?

I've already self-assigned this and commented. Why did you pick this up?

Essentially, the check for eating grass runs constantly - when I dumped the log, the d20 dice roll (replace_rate=20) happens every 0.05s, which I presume is the on_step cadence, so with the sheep's replace_rate of 20, the eating rate is about one block per 20*0.05s = 1s - one block per second. Which is about equal to what I see - I can draw a dirt line with a sheep and a piece of wheat :)

This is just a sketch. Things to figure out:

  • why is there a double trigger in api.lua for env_damage?

Merge conflict issue. My mistake. Picked up on my branch.

  • what is the correct rate of eating?
  • was there a timer in the past? was this implemented in some other way?

There was a timer it seems, that was called timer, and used for attack and labelled as attack time, even thought it was used for multiple other things. It would exit out of the mob_step and everything after that would stop processing. I've noticed historically this has broken many things.

I restructured to ensure all damage dealing code was at the start and to escape if a mob died. This was to avoid a number of crashes we've had historically. It unfortunately dropped out the timer.

The timer was used in a few places, and I'm thinking of the best way to cover all those cases without having a weird and illogical structure to the code. Some things were done that wasn't explicit, so I'm thinking of the best way to make this clearer.

> Essentially, the check for eating grass runs constantly - when I dumped the log, the d20 dice roll (replace_rate=20) happens every 0.05s, which I presume is the on_step cadence, so with the sheep's replace_rate of 20, the eating rate is about one block per `20*0.05s = 1s` - one block per second. Which is about equal to what I see - I can draw a dirt line with a sheep and a piece of wheat :) > > This is just a sketch. Things to figure out: > > * why is there a double trigger in api.lua for env_damage? Merge conflict issue. My mistake. Picked up on my branch. > * what is the correct rate of eating? > * was there a timer in the past? was this implemented in some other way? There was a timer it seems, that was called timer, and used for attack and labelled as attack time, even thought it was used for multiple other things. It would exit out of the mob_step and everything after that would stop processing. I've noticed historically this has broken many things. I restructured to ensure all damage dealing code was at the start and to escape if a mob died. This was to avoid a number of crashes we've had historically. It unfortunately dropped out the timer. The timer was used in a few places, and I'm thinking of the best way to cover all those cases without having a weird and illogical structure to the code. Some things were done that wasn't explicit, so I'm thinking of the best way to make this clearer.

I appreciated the enthusiasm, analysis and investigation, but will close in favour of as there was a few more pieces to factor in and the work was already in progress:

MineClone2/MineClone2#3435

You were bang on the money though, so good work, and the initiative is appreciated.

I appreciated the enthusiasm, analysis and investigation, but will close in favour of as there was a few more pieces to factor in and the work was already in progress: https://git.minetest.land/MineClone2/MineClone2/pulls/3435 You were bang on the money though, so good work, and the initiative is appreciated.
emptyshore deleted branch sheep_destroy_landscape 2023-02-11 21:50:00 +01:00
Author
Member

All g to close, at least some good came of it!

All g to close, at least some good came of it!

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: VoxeLibre/VoxeLibre#3434
No description provided.