Eclipse Debugging Issue
I have a game using the LWJGL and Slick2D made in Java. I recently added this code to get if a pixel is empty:
for (Entity e : onscreenents)
if (e.getBlockID() == 1 || e.getBlockID() == -2)
for (int x = e.getX()开发者_开发知识库; x < e.getX() + 18; x++)
for (int y = e.getY(); y < e.getY() + 18; y++)
if (x > 0 && y > 0 && x < empty.length && y < empty[x].length)
empty[x][y] = false;
This code seems to run fine in the Run mode of Eclipse but when I start the program in the Debug mode of Eclipse, the game runs really slowly and is very glitchy. Removing this block of code makes the debug mode run as smooth as the Run mode.
Does anyone know why this is happening and if it is my fault or not? It would really help :)
These may help:
Speeding up Tomcat in debug mode with Eclipse IDE
Why does Java code slow down in debugger?
Why does the debugged program slow down so much when using method entry debugging?
If you really do need performance improvements, then bmargulies comment is valid. Try moving the invariants out of the loop(s) so they are only calculated once.
So move e.getX()
and e.getY()
calls above the for loops so they are called only once and save them in local vars. Same with empty.length
(if these doesn't change with each loop iteration that is).
And possibly even save empty[x]
into a local variable as array item dereferencing is slower than local variable access.
You also do a test for x>0
and y>0
. If you're only interested in +ve values, then you could test e.getX()+18
and e.getY()+18
to see if they are +ve before the loops, as you may not even have to perform them. (e.g. if e.getX()+18<=0
you don't have to do the x
loop. Same for y
)
Beware of premature optimisation though.
精彩评论