Page 3 of 3

Re: Remove out of map projectiles! Or how to clean the beach

Posted: Wed Jul 01, 2015 7:15 pm
by bongobeat
thanks for both scripts. Don't know which I will use. The idea of destroying the projectile after it leaves the map suits me, because I like the nice reflecting colors of any attack spell on the water :lol:
Well, have to test it with a long play, to see if it slow down the fps.

Re: Remove out of map projectiles! Or how to clean the beach

Posted: Wed Jul 01, 2015 7:48 pm
by AndakRainor
Hey ! To slow down the fps with my last script you would need over 9000 entities in only one tile AND on a map border ! Don't tell me you want to do that :twisted:

Re: Remove out of map projectiles! Or how to clean the beach

Posted: Wed Jul 01, 2015 7:58 pm
by Azel
AndakRainor wrote:Hey ! To slow down the fps with my last script you would need over 9000 entities in only one tile AND on a map border ! Don't tell me you want to do that :twisted:
Haste + Flame Wave spamfest? Could be fun :P

Re: Remove out of map projectiles! Or how to clean the beach

Posted: Thu Jul 02, 2015 8:36 pm
by bongobeat
who knows?
suddenly an army of spiting frog land on the beach, that could be fun

Re: Remove out of map projectiles! Or how to clean the beach

Posted: Thu Oct 08, 2015 8:30 am
by Azel
AndakRainor wrote:Here is a reworked version of the script. You can safely use it in only one script entity anywhere in your dungeon:

Code: Select all

performanceHit = 0.001 -- must be in [0.000001, 0.01]
vanishDistance = 300 -- in meters = tiles * 3

level = 1
tile = -1

--entities = 0
--duration = 0
--maps = 1

function check()
  local begin = Time.systemTime()
  local levels = Dungeon.getMaxLevels()
  local pHit = 0
  repeat 
    local map = Dungeon.getMap(level)
    local X, Y = map:getWidth()-1, map:getHeight()-1
    tile = tile+1
    local x, y
    if tile<X then x=tile y=0
    elseif tile<X+Y then x=X y=tile-X
    elseif tile<X+X+Y then x=X+X+Y-tile y=Y
    elseif tile<X+X+Y+Y then x=0 y=X+X+Y+Y-tile
    else
      tile=0 x=0 y=0 level = level % levels + 1
      map = Dungeon.getMap(level)
      X, Y = map:getWidth()-1, map:getHeight()-1
      --maps = maps+1
    end
    for e in map:entitiesAt(x,y) do
      if e.projectile then
        local w = e:getWorldPosition()
        --hudPrint(e.name.." at map("..e.x..", "..e.y..") world("..w.x..", "..w.y..", "..w.z..")")
        if w.x < -vanishDistance or w.y < -vanishDistance-21 or w.z < -vanishDistance
        or w.x > X*3+3+vanishDistance or w.y > vanishDistance+21 or w.z > Y*3+3+vanishDistance
        then e:destroy() end
      end
      --entities = entities + 1
    end
    pHit = Time.systemTime() - begin
  until pHit >= performanceHit
  local delay = pHit/performanceHit - pHit
  delayedCall(self.go.id, delay, "check")
  --duration = duration + pHit * 1000000000
  --print("time/map = "..math.floor(duration/maps).."ns, entities/map = "..math.floor(entities/maps)..", time/entity = "..math.floor(duration/entities).."ns, frame = 1/60s, entity/frame = "..math.floor(entities/duration * 1000000000/60)..", delay = "..math.floor(delay*1000).."ms")
end

check()
As the previous ones, it auto starts and is called periodically.
You can set the performanceHit and vanishDistance values to your liking. The first one is a ratio of time used to run the script, so it should be a small value, near 0, but never 0 or it won't work. The second is in meters, as it is used with tests on the projectiles world positions instead of time spend out of maps. It does not test all entities in a map anymore but only those on borders. If you want to see what it does, you can uncomment the commented lines (times are shown in ns = nanoseconds).

Here is the data I got when testing performance hits with my previous scripts (hours of data);

Code: Select all

+-----------------+----------------+------------------+-----------------+---------------------+
|    loop type    |  time per map  | entities per map | time per entity | entities per frame* |
|                 | (milliseconds) |                  | (milliseconds)  |  (perf hit limit)   |
+-----------------+----------------+------------------+-----------------+---------------------+
|  all entities   | 1.724          | 1350             | 0.001275        | 13063               |
+-----------------+----------------+------------------+-----------------+---------------------+
| entities at x,y | 0.267          | 132              | 0.002016        | 8264                |
+-----------------+----------------+------------------+-----------------+---------------------+
(*): frame = 1/60 s = 16.667 ms
I'm adding this to my Mod today and testing it out!

Re: Remove out of map projectiles! Or how to clean the beach

Posted: Fri Oct 09, 2015 7:08 pm
by AndakRainor
So, how did it work for you ? Hoping you are happy with it :)

Re: Remove out of map projectiles! Or how to clean the beach

Posted: Fri Oct 09, 2015 11:19 pm
by Azel
Yessir, it's working fabulous. There are very few locations that allow players to sneak a fireball out over open water (usually because I place the Party at a high Elevation in an Open Area); but your script cleans it up very nicely. Players are reporting a good gaming experience thus far in my Mod, which contains this very script. Thanks for creating this, AndakRainor, you saved my bootay! :mrgreen: