Reducing Lag

Freeform discussion about anything related to modding Transcendence.
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

I made a mod for that competition thingy. Thing is, when I use it, it lags Transcendence to the point of complete unusability, about 1/15 of an FPS. I've managed to reduce it a little, but it still renders the game pretty much unplayable. I just had an idea that might solve the problem, but if that dosn't work, how can I reduce the lag? The mod uses (enum (sysFindObject gSource "s") (it should be ts, but that lags 10 times worse.).
[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
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.

Hmmm... is this consistent for EVERY system? try spawning an empty system, then add maybe 10 things that fall under "s" and keep bumping it up


btw- what are your computer specs?
(shpOrder gPlayership 'barrelRoll)

<New tutorials, modding resources, and official extension stuff coming to this space soon!>
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

How often are you searching the system?
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

maybe you can restrict the radius of the search to only 300-350 ls ?
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

Well, I got it down to a workable level, but it turned out that I wasn't actually using the enum (it just set itself to gPlayerShip), and when I set it up to do so, the lag returned. I got it down by reducing the search radius, but I don't think the effect will really work if I turn down the radius further. I am searching the system every 30 ticks, but changing that number dosn't seem to affect the lag by much, and again, turning up the delay would probably start to degrade the effect.

My computer has a good amount of horsepower, 2 cores at 2.26 GHz, with 3 GB of RAM and plenty of virtual memory too.
[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
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Are you writing a lot of statements to the Log? If so, try turning them of for a moment, or switch them out with (dbgOutput ..) statements. Usually the place i get the most lag is when disk i/o is ocurring. Looping over every ship in a system every 30ticks should not make your pc skip a beat (unless you are calculating an obcene amount of stuff per iteration).

.]
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

No dbgLog. I'm just going through every ship within 200 LS and running some vector math on it.
[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
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Hmm, that is odd. Could you post a snippet? (I know, competition and all). Perhaps there is something fishy going on. I have tested sysFindObject quite a lot with large ranges, and doing vector math on the results, and apart from a slight hit sometimes when finding many objects, everything ran smoothly (on a rather crappy notebook even)

.]
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

yeah, I sysFindObject all the ships in the system and run 3000 lines of code on each of them every 30 ticks using onUpdate in the Weapons Randomizer mod, and there is only a hiccup when you enter a new system.
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

Yeah, I don't see how this can lag at all, here's the repeating code:

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)
		(for count 0 600
		(block (vector currDist)
			(setq vector (sysVectorPolarOffset targetPos count distance))
								(setq currDist (sysVectorDistance vector playerPos)) 
								(if (ls currDist BestDist)
									(block Nil
										(setq bestDegree count)
										(setq bestDist currDist)
									)
								)
							)
						)
						(setq vector2 (sysVectorPolarOffset Nil bestDegree 10))
						(objIncVel target (sysVectorDivide vector2 (objGetDistance target gSource)))
					)
				)

			</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
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Hmm. I have not actually tried it, but I suspect the (for count 0 600 ..) is a bit on the high end. Imagine if you find 20 objects, you will be iterating 12000 times. That you should definitely be able to feel. If you doubt that, then try to run a for loop 12000 times and calculate what you are already doing in there. You should feel the same lag.

I can't really see why you need that for loop at all. What is it supposed to do? Have you tried removing it?

.]
User avatar
Periculi
Fleet Officer
Fleet Officer
Posts: 1282
Joined: Sat Oct 13, 2007 7:48 pm
Location: Necroposting in a forum near you

hmm... yeah, that might be causing some lag.

(psst - you don't need to define target in the block since it's already being defined in the enum...)

Looks like that (for count 0 600 is trying to find a direction? Would 360 be usable? Also - isn't there a difference between BestDist and bestDist? I forget, but I thought that T-Lisp was case sensitive for variables like that- which means that (if (ls currDist BestDist) never worked with the value set for bestDist. I could be wrong, it's been a while and a bunch of other script languages since I have done much with T-Lisp.
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

I did quite a lot of testing with getting angles and such from vectors. I'm not sure if this is of help to what you need to do, but this is the easiest way i found of getting an angle between two objects:

Code: Select all

;; calculate the angle. This is the tscript way
;; of doing atan((Ay-By)/(Ax-Bx))
;; Thanks to Atarlost for the trig!!

(setq angle (sysVectorAngle
    (sysVectorSubtract
        (objGetPos b)
        (objGetPos a)
    )
))

.]
schilcote
Militia Captain
Militia Captain
Posts: 726
Joined: Sat Feb 02, 2008 7:22 pm

I didn't write that code myself, and it isn't really designed for this purpose. I'm adapting it from F50's Tractor Beam mod. I'll remove that repeaty thingy and see what happens. I've no idea what it does.
[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
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

It is used for finding the approximated best angle from one object, to another. You start by getting the distance between you and a target, then start by getting the vector at that distance at 0 degrees. Then find the distance of that vector to the target. If the distance is smaller, then the angle is better. Continue around 360 degrees (no reason todo it more times) and you should have the best angle, within 1 degree.

The small snippet i posted above will provide you the same result, only more exact. I believe that F50's solution was made before some of the new vector functions in 99c.

.]
Post Reply