Jump to content

Photo

Why do we need the F1 to go fast?


  • Please log in to reply
20 replies to this topic

#16 Russ

Russ

    Caelan, the Encouraging

  • Administrators
  • Location:Washington

Posted 24 January 2017 - 09:50 AM

Consider:
 
for ( int q = 1; q < Screen->NumLWeapons(); q ++ )

This is making a function call that checks the number of lweapons, per iteration. If there are 24 lweapons, it is calling NumLWeapons twenty-four times.
 
versus
 
for ( int q = Screen->NumLWeapons(); q > 0; q-- )
 
This makes the function call only once, and the loop results are the same, because both run in one frame.

I actually had no idea it worked like this. I don't think I've ever done it the top way, but only cuz I was taught to do it the bottom way. Huh... well today I learned. Thanks for the tip!

#17 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 24 January 2017 - 11:00 AM

I try to avoid using it when playing people's quests because I find it disrespectful towards their hard work to be trying to F1 force my way through it. It communicates "I find what you made boring enough that I need F1 to get through it faster". But that's just me. I will use it if I have to go through dialog that I've already read after I die to a boss or something like that though.

 

I mostly use it for testing though, when applying the F11 Cheat to walk through solid objects, you can cross entire maps very quickly when you mix that with F1, though Q I believe can be used for the same purpose then. 



#18 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 24 January 2017 - 11:07 PM

I actually had no idea it worked like this. I don't think I've ever done it the top way, but only cuz I was taught to do it the bottom way. Huh... well today I learned. Thanks for the tip!

 

Aye, well, loop iteration direction does not alwaya accomplish the same result efficiently. Occasionally, it makes sense to map something out in one direction, and then process it in the other.

 

As an example, with the TBA parser, to determine how many instructions the user has issued, I parse a string backwards, ignore any trailing spaces, and count instructions by determining if a series of characters following a space, does not have a series of spaces between them. Then, knowing how many instructions there are, and at what index the last instruction ends, I parse them, adding each to a word buffer, determining what instruction it is, and adding it to the heap.

 

If I only did this in one drection, i would have to reorder the instructions on the heap, instead, FILO, instead of FIFO. I may do that to eliminate the second parsing later, but only if there is an efficiency concern. It's simpler to construct the stack and heap to work as FIFO.

 

The main thing, is to keep the number of instructions per frame to a minimum, when possible. You can do a forward loop with ncs without losing speed like this:

 

int nn = Screen->NumNPCs(); int q;

for ( ; q < nn; q++ )

 

...as this isn't calling a function per frame--you stored the variable first. Using SizeOfArray() in loops is similar, and pre-storing it speeds up the iteration in a forward direction.



#19 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 25 January 2017 - 03:44 PM

On the C++ side, Game->GetNum* is faster than reading a variable, which needs to be fetched from the stack. But in ZASM, it gets wrapped in some extra code, so it's difficult to say which is really faster in practice.
Comparing to a literal is faster than comparing to a variable, and if(x) is faster than the equivalent if(x!=0).

#20 Item

Item

    Senior

  • Banned

Posted 25 January 2017 - 03:46 PM

On the C++ side, Game->GetNum* is faster than reading a variable, which needs to be fetched from the stack. But in ZASM, it gets wrapped in some extra code, so it's difficult to say which is really faster in practice.
Comparing to a literal is faster than comparing to a variable, and if(x) is faster than the equivalent if(x!=0).

Basically the F1 is for practice of speed?

(nice) 



#21 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 25 January 2017 - 06:44 PM

Honestly, I don't know why the option to uncap exists. I think it's a holdover from the DOS days; I vaguely recall that the game used to run better uncapped on some systems. I might be imagining that, though.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users