Author Topic: Pseudo HB  (Read 316 times)

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Pseudo HB
« on: August 16, 2011, 05:31:27 pm »


                <listens really hard...>

Keeping in mind that I have only recently returned to the fold (any derision should, therefore, be meant in good humor), I have a question about the pseudo-HB I keep hearing about.

My original idea (that seems to work well so far) is a HB-driven "odometer" function;

  On HB
    increment nRoundCt
    if nRoundCt>20
      call add_hour
      nRoundCt = 0

Similarly, add_hour calls add_day and add_day calls add_month, etc.

Thus the actual HB script only calls another function every 2 mins, which only calls a third function every 48 mins, etc. This allows me to set definite schedules (such as the changing phases of the moon, seasons, etc) and tie them into the higher-order (seldom-firing) functions.

Doing a search of the Vault (a few different ways), I find several mentions of pseudo-HB, but no explanation.

When the cycle-misers, er, script-gods on this forum speak of a pseudo-HB, are they talking about something like this? Or are they talking about using a rather random, but common event (like OnEnter/Exit) to fire scripts? Or something completely different?

I'm always interested in better ways to do things :-)

<...to the sound of icescream dripping>
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Pseudo HB
« Reply #1 on: August 16, 2011, 06:03:28 pm »


               A pseudo HB is just a recursive function. It keeps calling itself over and over with a delay.

void MyHBFunction()
{
    //do stuff
    DelayCommand(6.0, MyHBFunction());
}


But keep in mind that there are issues that go into lengthy debates and conversations about how/when to use them. They can cause memory leakage. They use more computer resources, etc, etc. Not to deter you from using them. I have. But I also make sure that they end at some point.

void MyHBFunction()
{
    //do stuff
    if (conditional met)
    DelayCommand(6.0, MyHBFunction());
}


Hope this helps somewhat.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Pseudo HB
« Reply #2 on: August 16, 2011, 06:23:46 pm »


               <stares into endless reflections...>

GhostOfGod wrote...

A pseudo HB is just a recursive function. It keeps calling itself over and over with a delay.

...

But keep in mind that there are issues that go into lengthy debates and conversations about how/when to use them. They can cause memory leakage. They use more computer resources, etc, etc. Not to deter you from using them. I have. But I also make sure that they end at some point.


Yee-gads! I hope they end! 

Umm, not that I want to start one of those debates, but I really don't see any advantage to using delay in a loop, over running a counter and trap-door off the HB.

Isn't the HB much more efficient than delay?

Hope this helps somewhat.


It does. I actually never even considered ssloopsendle, er endlessloops... um, not since... a long time ago.
(semaphores in the Amiga kernal, anyone? <sighs>)

<...of the one he loves. ssloveendlessloveendlessloveendle...>
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Pseudo HB
« Reply #3 on: August 16, 2011, 08:58:21 pm »


               Pseudos consume roughly 5 times the cpu of an equivalent heartbeat. You should use them if you'll be running the given script less than 20% of the mod's uptime. If you need it running more often than that, use a normal heartbeat.

Our mod uses only the module heartbeat, and heartbeats on a number of critters, but only those whose specially-code abilities require them - the rest have had them removed. Everything else runs off of pseudos.

Why use heartbeats on creatures, when they're unlikely to be around 20% of the time or more (you should be spawning them in from encounter or trigger, not placing them in the area)? Because they self-terminate like a pseudo can be coded to, when the creature is killed. All the benefits of both methods.

I have extensive experience tangling with pseudo vs hearbeat issues, and I'm happy to field any further questions you might have.

Funky
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Pseudo HB
« Reply #4 on: August 16, 2011, 09:06:52 pm »


               Oh, I talk about pseudos and when to use them in my delagging tutorial in the 1.69 Lexicon. Here's the relevant section:

Eliminate Unnecessary Scriptcalls

In the spirit of #2 above, you simply don't want scripts firing if they don't need to be. One generally wasteful type of script is the heartbeat script, since they run all the time while their object is valid - in the case of the module and areas, whenever the module is running. Heartbeats are FINE if used sensibly, and kept efficient, but you shouldn't use them if you don't need them, or if there's a more efficient alternative. Often, you can replace a heartbeat script with a pseudo-heartbeat, a kind of function that fires itself recursively on a delay you specify until the conditions that you specify are met. They are basically heartbeats with user-specified intervals (instead of the fixed ~6 second heartbeat event) and specific on/off switches to ensure that they aren't running when they aren't needed. They are, however, roughly five times as cpu-intensive as a heartbeat with identical function, and they tie up memory with their variables while they run, so you should reserve pseudo-heartbeats for relatively short term use. A rough guideline is to use them if they'll be running for 5-10% of the mod's uptime or less, though that is not a scientifically-arrived-at number. In our mod, the only heartbeats we didn't convert in some way were the module heartbeat and a few monster heartbeats - the rest were removed as unneeded or converted to another event or a pseudo. As with inefficient scripts, lag from unnecessary scriptcalls is server lag.


Funky
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Pseudo HB
« Reply #5 on: August 16, 2011, 10:39:09 pm »


               <blushes crimson...>

FunkySwerve wrote...

Oh, I talk about pseudos and when to use them in my delagging tutorial in the 1.69 Lexicon. Here's the relevant section:


Oh, my stars...

Do you know I've been using the Lexicon for a reference for 3 months and I never even looked under Lyceum...

I am always interested in what you say.  I especially like the thoroughness of your post-mortems.  Not just that something is wrong, but why, and options for fixing it.

Pardon me if I bury my nose in a couple scrolls :-P

<...and turns into a bookworm>
               
               

               


                     Modifié par Rolo Kipp, 16 août 2011 - 09:40 .