abm / cactus / damage

User avatar
bosapara
Member
 
Posts: 559
Joined: Fri Apr 07, 2017 08:49
GitHub: bosapara

abm / cactus / damage

by bosapara » Sun Aug 26, 2018 17:27

abm for cactus damage isnt too much expensive for minetest perfomance?

Image

Code: Select all
minetest.register_abm({
   nodenames = {"default:cactus"},
   interval = 0.5,
   chance = 1,
   action = function(pos, node, active_object_count, active_object_count_wider)
      local players = minetest.get_objects_inside_radius(pos, 1)
         for i, player in ipairs(players) do
            player:set_hp(player:get_hp() - 3)
         end
   end,
})
 

User avatar
Casimir
Member
 
Posts: 1163
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

Re: abm / cactus / damage

by Casimir » Sun Aug 26, 2018 20:34

This is how I did it in Voxelgarden. Essentially it's just a smaller collision box, so you can stand "inside" the node, but with an smaller node box so it doesn't look strange.

Code: Select all
minetest.register_node("default:cactus", {
   description = "Cactus",
   drawtype = "nodebox",
   paramtype = "light",
   tiles = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"},
   groups = {snappy=1, choppy=3, flammable=2},
   node_box = {
      type = "fixed",
      fixed = {
         {-0.375, -0.5, -0.5, -0.375, 0.5, 0.5},
         {0.375, -0.5, -0.5, 0.375, 0.5, 0.5},
         {-0.5, -0.5, 0.375, 0.5, 0.5, 0.375},
         {-0.5, -0.5, -0.375, 0.5, 0.5, -0.375},
         {-0.375, -0.5, -0.375, 0.375, 0.5, 0.375},
      }
   },
   selection_box = {
      type = "fixed",
      fixed = {-0.375, -0.5, -0.375, 0.375, 0.5, 0.375}
   },
   collision_box = {
      type = "fixed",
      fixed = {
         {-0.1875, -0.5, -0.1875, 0.1875, 0.5, 0.1875},
      }
   },
   damage_per_second = 1,
   sounds = default.node_sound_wood_defaults(),
   after_dig_node = function(pos, node, metadata, digger)
      default.dig_up(pos, node, digger)
      default.dig_up(pos, {name = "default:cactus_fig"}, digger)
   end,
})


Image
 

User avatar
bosapara
Member
 
Posts: 559
Joined: Fri Apr 07, 2017 08:49
GitHub: bosapara

Re: abm / cactus / damage

by bosapara » Sun Aug 26, 2018 20:45

Casimir wrote:This is how I did it in Voxelgarden. Essentially it's just a smaller collision box, so you can stand "inside" the node, but with an smaller node box so it doesn't look strange.


Already checked this variant, unfortunately damage will not work when we walk at the cactus
 

User avatar
Krock
Developer
 
Posts: 4479
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: abm / cactus / damage

by Krock » Sun Aug 26, 2018 21:03

bosapara wrote:Already checked this variant, unfortunately damage will not work when we walk at on the cactus


Then try manipulating the Y value of the collision box a bit like this: (untested)
Code: Select all
   collision_box = {
      type = "fixed",
      fixed = {
         {-0.1875, -0.5, -0.1875, 0.1875, 0.45, 0.1875},
      }
   },
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
bosapara
Member
 
Posts: 559
Joined: Fri Apr 07, 2017 08:49
GitHub: bosapara

Re: abm / cactus / damage

by bosapara » Sun Aug 26, 2018 22:03

Krock wrote:Then try manipulating the Y value of the collision box a bit like this: (untested)


yep, almost, this works perfect:

Code: Select all
   collision_box = {
      type = "fixed",
      fixed = {
         {-0.1875, -0.5, -0.1875, 0.1875, 0.375, 0.1875},
    },
 

User avatar
Hybrid Dog
Member
 
Posts: 2735
Joined: Thu Nov 01, 2012 12:46

Re: abm / cactus / damage

by Hybrid Dog » Thu Aug 30, 2018 09:50

Sam shouldn't be damaged when standing on a cactus because he wears shoes.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪
 

User avatar
Hamlet
Member
 
Posts: 701
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: abm / cactus / damage

by Hamlet » Thu Aug 30, 2018 11:15

Technical question:

Given that the same can be achieved with node timers, which would be the best method?

Or, which is the best one for memory saving and server load?
 

User avatar
sorcerykid
Member
 
Posts: 1256
Joined: Fri Aug 26, 2016 15:36
Location: Illinois, USA
GitHub: sorcerykid
In-game: Nemo

Re: abm / cactus / damage

by sorcerykid » Thu Aug 30, 2018 17:20

This is the collision box setting I use for default:cactus on JT2, derived from rnd's "cactus hurt" patch.

Code: Select all
        collision_box = {
                type = "fixed",
                -- Adjust collision box so it damages players that are too
                -- close. We need to allow them to "enter" into the node a
                -- little bit for this to actually happen. The top is low
                -- enough that feet damage occurs if standing on it.
                fixed = { -7/16, -1/2, -7/16, 7/16, 5/16, 7/16 },
        },
 

User avatar
Krock
Developer
 
Posts: 4479
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: abm / cactus / damage

by Krock » Thu Aug 30, 2018 18:42

@Hamlet, @bosapara: Some additions in regard to the best performance, as there are currently four possibilities to do this:

1) ABMs
Pro: Is triggered for each cactus node, can damage players using `minetest.get_objects_inside_radius(pos, 1)`
Contra: Somewhat slow and triggers on irrelevant nodes. Don't use it.
2) Node Timers
Pro: Is triggered only for the top cactus node (requires optimizations in the mod)
Contra: Node Timers are triggered even when there's no player + requires optimizations to reduce the active node timers
3) register globalstep
Pro: Only checks positions where the players are
Contra: Also checks positions where no cactus is found nearby
4) Engine/built-in
Pro: Only checks positions where the players are + no Lua callbacks to execute
Contra: Also checks positions where no cactus is found nearby + the feet are inside the visible cactus (looks weird)

Idea (3) and (4) have generally a better efficiency because there are more cactus nodes than players in the loaded mapblocks. However, if there are many players in a world where cactus is (near to) non-existent, then it's idea (2) which is the next best solution when you want to avoid the visual side-effect of (4).
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
TenPlus1
Member
 
Posts: 2672
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Re: abm / cactus / damage

by TenPlus1 » Fri Aug 31, 2018 05:54

My PlayerPlus mod handles everything inside a single globalstep so that it's less strain on a server and will do cactus damage, suffocation, player knockback, walking speed changes, on_walk_over nodes and has player_monoids and pova support for the changes...

https://notabug.org/tenplus1/playerplus
 

Astrobe
Member
 
Posts: 303
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Fri Aug 31, 2018 15:46

Krock wrote:@Hamlet, @bosapara: Some additions in regard to the best performance, as there are currently four possibilities to do this:

1) ABMs
2) Node Timers
3) register globalstep
4) Engine/built-in


5) "on_collide" callback for players and entities
Pros: it solves all sorts of other problems
Cons: backport to version 0.0.1 needed because it should have been there right from the beginning.
 

User avatar
Krock
Developer
 
Posts: 4479
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: abm / cactus / damage

by Krock » Fri Aug 31, 2018 16:15

Astrobe wrote:5) "on_collide" callback for players and entities

I think you forgot the part with "Lua function call performance" and "redundant callback call flood". It's not like this was requested before, or anything like that. (sarcasm)

Letting the engine handle this internally by the given node definition is actually the best approach performance-wise in this case.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

Astrobe
Member
 
Posts: 303
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Fri Aug 31, 2018 18:35

"redundant callback call flood": just have the user to rearm the callback once fired (like we do with after()), so that mods can deal with the problem with a timer if needed. Works in this case, it works with arrows, it works with mobs.

"Lua function call performance": compared to either the broken collision detection Lua code I have seen (with get_object_in_radius) or the correct but expensive collision box checks, it doesn't look that bad to me.

Offloading the burden to Lua scripts just hurts everyone more. But yeah, keep the issue closed and keep adding ad hoc solutions instead.
 

User avatar
Hybrid Dog
Member
 
Posts: 2735
Joined: Thu Nov 01, 2012 12:46

Re: abm / cactus / damage

by Hybrid Dog » Fri Aug 31, 2018 18:36

With server-provided CSM an on_collide function could be executed client-side.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪
 

Astrobe
Member
 
Posts: 303
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Sun Sep 02, 2018 07:47

I don't want to be look like the stubborn guy who takes down any other solution than his, but I have two issues with CSM.

First, I don't like the idea of running random code from a random source. Browsers do this all the time. It lead to abuse, so now there are browser extensions to block JS.

More importantly, the second problem is that you don't know the client machine specs (could be a gaming PC, could be a low-end tablet), so you don't know how much you can offload to them.

Suppose we do the on_collide stuff via CSM. We assume that it's no big deal for the client machine. Now add Paramat's Snowdrift that adds some particle handling stuff to the workload of the client. Is it still ok? Then add a couple of other mods that delegate other awesome stuff to the client and when your players say the game is "laggy", you will have no idea if it's a network problem or if that was because your players had a cactus bumping party under heavy rain.
 

Astrobe
Member
 
Posts: 303
Joined: Sun Apr 01, 2018 10:46

Re: abm / cactus / damage

by Astrobe » Sun Sep 02, 2018 08:27

For the collision box solution above, since that hack makes the character "enter" the node, you might want to disable backface culling; for instance:
Code: Select all
   tiles = {"default_cactus_top.png", "default_cactus_top.png", {name="default_cactus_side.png", backface_culling=false}},
 

User avatar
Hamlet
Member
 
Posts: 701
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: abm / cactus / damage

by Hamlet » Mon Sep 03, 2018 11:31

Krock wrote:1) ABMs
[...]
2) Node Timers
[...]
3) register globalstep
[...]
4) Engine/built-in
[...]

Idea (3) and (4) have generally a better efficiency because there are more cactus nodes than players in the loaded mapblocks. However, if there are many players in a world where cactus is (near to) non-existent, then it's idea (2) which is the next best solution when you want to avoid the visual side-effect of (4).


Thanks, your answer has cleared my doubts; when I will rewrite "Killer Nodes" I will use the fourth method - I thought about using node timers instead of ABMs, but running timers when there aren't players around isn't an option.

I don't mind about the visual glitch: after all we already have mobs that often end with their heads buried into nodes due to how collision boxes work.

Thanks again. :)
 


Return to General Discussion



Who is online

Users browsing this forum: No registered users and 28 guests