我在这里发布了第一个问题,所以我提前请求原谅我的问题 - 格式化缺乏经验。
我的2D图形游戏通常在我的系统上运行完美。但是,当Norton Internet Security的ccSvcHst.exe进程以非常高的CPU利用率运行时,它与游戏进行了奇怪的交互。我已经确定了受影响的特定Java代码行。
// Graphics setup, just trying to give some background
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = e.getDefaultScreenDevice();
GraphicsConfiguration grafConf = device.getDefaultConfiguration();
Frame f = new JFrame(grafConf);
device.setFullScreenWindow(f);
f.createBufferStrategy(2);
BufferStrategy buffStrat = f.getBufferStrategy();
Graphics grafx = buffStrat.getDrawGraphics();
// Create some sprites to draw here...
// Launch a game loop to execute every 15ms
Timer timer = new Timer();
TimerTask task = new TimerTask() { public void run() { gameLoop(); }};
timer.schedule(task,0,15);
public void gameLoop() {
BufferedImage erase = getEraseBI();
// Erase each the 64x64 sprites...
int x, y; x = getX(1); y = getY(1);
long t1start = System.currentTimeMillis();
grafx.drawImage(erase, x, y, null);
long t1end = System.currentTimeMillis();
x = getX(2); y = getY(2);
long t2start = System.currentTimeMillis();
grafx.drawImage(erase, x, y, null);
long t2end = System.currentTimeMillis();
// and so on, for each sprite to erase
// Move stuff and redraw it; no problems here...
// Now flip the page to show what we’ve drawn
long show1 = System.currentTimeMillis();
buffStrat.show();
long show2 = System.currentTimeMillis();
grafx.dispose();
grafx = buffStrat.getDrawGraphics();
}
通常,drawImage()和buffStrat.show()调用执行得如此之快,以至于两次之间的差异显示为0.但是几分钟之后,当有超过十几个精灵要擦除时,或者更多的drawImage()调用(但不是全部),以及buffStrat.show()调用突然需要25-35ms而不是0.这种行为一直持续到游戏停止。重新启动系统可以清除高CPU ccSvcHst状态,恢复正常,稳定,3小时直播,无任何问题的游戏性能。
没有进入关于诺顿工具优点的政治讨论,我只是好奇 - 还有其他人看过Java图形和NIS ccSvcHst.exe之间的这种交互吗?