简体   繁体   English

Eclipse调试问题

[英]Eclipse Debugging Issue

I have a game using the LWJGL and Slick2D made in Java. 我有一个使用Java制作的LWJGL和Slick2D的游戏。 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. 这段代码在Eclipse的“运行”模式下似乎可以正常运行,但是当我在Eclipse的“调试”模式下启动程序时,游戏的运行速度非常缓慢,而且异常运行。 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 使用Eclipse IDE以调试模式加速Tomcat

Why does Java code slow down in debugger? 为什么Java代码在调试器中会变慢?

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. 如果您确实确实需要提高性能,那么bmargulies注释是有效的。 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. 因此,将e.getX()e.getY()调用e.getY() for循环上方,以便它们仅被调用一次并将它们保存在本地var中。 Same with empty.length (if these doesn't change with each loop iteration that is). empty.length相同(如果在每次循环迭代中它们都不变)。

And possibly even save empty[x] into a local variable as array item dereferencing is slower than local variable access. 甚至可能将empty[x]保存到局部变量中,因为数组项解引用比局部变量访问慢。

You also do a test for x>0 and y>0 . 您还要对x>0y>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. 如果您仅对+ ve值感兴趣,则可以测试e.getX()+18e.getY()+18以查看它们是否在循环之前+ ve,因为您甚至不必执行它们。 (eg if e.getX()+18<=0 you don't have to do the x loop. Same for y ) (例如,如果e.getX()+18<=0 ,则不必执行x循环。对于y相同)

Beware of premature optimisation though. 不过要提防过早的优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM