So I'm writing a turn based game that involves scrolling a map made of squares which light up as you mouse over them. Everything is drawn on a frame with a 2 buffer strategy. The rendering is done in a separate thread that loops continuously. When I sleep the render thread for a few milliseconds after each frame to push the fps down to around 30, the squares light up very responsively but the scrolling map jitters pretty bad. If I don't sleep the thread, it sits at around 60 fps and the map scrolls really smoothly, but there is noticeable delay between the mouse passing over a square and it lighting up. The code for identifying which square to light is very simple and quick and the processor doesn't seem taxed, so I don't think that the render thread is slowing things down too much. I'm a little stumped as to what is causing the delay, maybe the mouseEvents aren't spawning fast enough? Any ideas would be greatly appreciated as I'm pretty stumped.
Remove the sleep(), and try adding a yield() to the rendering thread. This is *not* a permanent solution, but it may give you an idea of what the problem might be. If yield() solves the problem, then it means your program might be suffering from starvation. The rendering thread is hogging the processor and it's not pausing enough to let the event dispatch thread do its work as well.
I've tried using Thread.yield(), but that seems to have no effect. I get pretty good results using a sleep of around 14 milliseconds; that seems to keep the fps at 60 and keeps the mouse responsive. It's kind of weird that completely removing the sleep doesn't result in any fps gains though. Also, I'm sorry but I don't know what an SSCCE is :/
I think you should do it anyways, not just for us. It will help you analyze non-trivial problems. Sometimes, with complicated problems, you cannot replicate the problem with the SSCCE. In this case, you start looking at the differrences between your code and SSCCE to figure out where it's going wrong. On the other hand, if the problem does happen with the SSCCE, atleast you have a simpler version of the actual code that you can do trial and error with. You can try different solutions to fix the SSCCE to find one that works, and then apply only the actual fix to the actual source.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com