Reducing Lag

Freeform discussion about anything related to modding Transcendence.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

I believe that F50's solution was made before some of the new vector functions in 99c.

sysVectorAngle is the new one in 0.99 :D
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

Now it dosn't work at all:

Code: Select all

			<Gravity>
				(enum (sysFindObject gSource "sN:200") target
					(block (target distance playerPos targetPos bestDist bestDegree)
						
						(setq distance (objGetDistance target gSource))
						(setq playerPos (objGetPos gSource))
						(setq targetPos (objGetPos target))
						(setq bestDist 100000)
						(setq bestDegree 0)
						(setq angle (sysVectorAngle 
						(sysVectorSubtract 
							targetPos 
							playerPos 
						) 
									)
						)	
				(setq vector2 (sysVectorPolarOffset Nil angle 10))
						(objIncVel target (sysVectorDivide vector2 (add(distance) 1)))
					)
				)

			</Gravity>
[schilcote] It doesn't have to be good, it just has to not be "wow is that the only thing you could think of" bad
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Typo:

Code: Select all

...
(add(distance) 1)
...
Should be:

Code: Select all

(add distance 1)
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

Well, you should know, shouldn't you? :) I'll try it out.

Oh, DigDug? The mod uses that anomaly graphic thingy, is that okay?

EDIT:
Gah, still won't work, the vectorDivide is dividing by 0. I'm pretty sure it's impossible for distance to be 0, because I'm adding one to it, so it must be the vector. I might just completely rewrite it from scratch, I understand vectors from playing Garrys Mod.
[schilcote] It doesn't have to be good, it just has to not be "wow is that the only thing you could think of" bad
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Another possible fix is to remove "target" from the variable declaration in the block.

Code: Select all

(enum (sysFindObject gSource "sN:200") target
    (block (target distance...)
...
Since you are using "target" as the variable for enum, declaring it in the block just overrides it. That means that target will always be Nil inside the block.

And (objGetDistance) will return Nil if "target" is Nil. Therefore, the variable "distance" will be Nil.

And, unfortunately:

(add Nil 1) -> Nil
Last edited by george moromisato on Wed Jul 08, 2009 3:50 am, edited 1 time in total.
User avatar
Arisaya
Fleet Admiral
Fleet Admiral
Posts: 5535
Joined: Tue Feb 05, 2008 1:10 am
Location: At the VSS Shipyards in the frontier, designing new ships.

george moromisato wrote: And, unfortunately:

(add Nil 1) -> Nil
Is that intended, or is this a bug?
So he'd have to not define it in the block, or re-define it as zero, then calculate?
(shpOrder gPlayership 'barrelRoll)

<New tutorials, modding resources, and official extension stuff coming to this space soon!>
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

schilcote wrote: Gah, still won't work, the vectorDivide is dividing by 0. I'm pretty sure it's impossible for distance to be 0, because I'm adding one to it, so it must be the vector.
Try cleaning it up a little, then maybe it becomes more apparent. Put in a few dbgLogs to see where the error could be. When you have expressions being evaluated inside expressions, sometimes their errors don't really make it out. Make sure that you are not defining and using global variables by mistake (ie, make sure all local variables are defined in the (block (.....)) part).

When weird error begin to happen, this is what I do... Split everything out, print the whole lot, see what is going on, and then reasemble it in shorter version, and without the debugging. Try to run this:

Code: Select all

<Gravity>
    (block (ships)
        (setq ships (sysFindObjects "sN:200"))
        (dbgLog "Ships found: " ships)  
        (enum ships target     
            (block (distance targetPos playerPos angle direction push) 
                ;; who is the target           
                (dbgLog "Target: " (objGetName target 1))
                ;; are you sure you dont wan't gPlayerShip?
                (setq distance (objGetDistance target gSource))
                ;; is a sane distance actually found?
                (dbgLog "Distance: " distance)  
                (setq playerPos (objGetPos gSource))
                (setq targetPos (objGetPos target))
                (setq angle (sysVectorAngle     
                    (sysVectorSubtract              
                        targetPos                       
                        playerPos                       
                    )
                ))
                ;; what is the angle found?    
                (dbgLog "Angle: " angle)        
                ;; find the direction we want to push that target in
                ;; this will be relative to System Origin
                (setq direction (sysVectorPolarOffset Nil angle 10))
                ;; lets print it, just for fun 
                (dbgLog "Direction Vector: " direction) 
                ;; and lets find the force we want to push with
                (setq push (sysVectorDivide
                    direction
                    (add distance 1)
                ))
                ;; and print it
                (dbgLog "Push Vector: " push)   
                ;; finally we do the actual push
                (objIncVel target push)         
            )
        )
    )
</Gravity>
And you should be able to spot the error in the log. It is basically the same script as you posted, just every operation is ending up in its own value, and being printed. It will probably lag quite horribly, since it's writing volumes, but will run at fine speed when the dbgLogs are taken out. Let us know how it goes

.]
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Wolfy wrote:
george moromisato wrote: And, unfortunately:

(add Nil 1) -> Nil
Is that intended, or is this a bug?
So he'd have to not define it in the block, or re-define it as zero, then calculate?
As we say in the business, it's working as coded.

I think I should change it so that Nil evaluates to 0 inside of a math function. [I already changed it so that Nil evaluates to 0 in comparison functions. Thus, (eq Nil 0) -> True, and (gr 1 Nil) -> True]
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

Yep, it works now. Yay!

George, how often does Transcendence physics compute (does Transcendence have a physics engine)?
[schilcote] It doesn't have to be good, it just has to not be "wow is that the only thing you could think of" bad
Post Reply