www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: qjvictor on December 09, 2006, 12:58:28 am

Title: JPCT eats so much CPU and Memory
Post by: qjvictor on December 09, 2006, 12:58:28 am
We developed a game with web start, the problem is that it seems the jPCT takes so much cpu and memory.
I think it is not the problem caused by my code. because I access http://www.jpct.net/demos.html and click some very simple demos,
it also takes much cup and memory.

Anybody has solution for this issue?

Thanks.
Title: JPCT eats so much CPU and Memory
Post by: manumoi on December 09, 2006, 07:55:55 pm
Hello

what do you mean by "so much"? What is the complexity of your environment? And what renderer are you using?
Title: JPCT eats so much CPU and Memory
Post by: eye1 on December 11, 2006, 10:34:25 am
Use sleep between renderings. I do rendering 25 times per minute and it only uses 2,3 percent of CPU (opengl mode)
Title: JPCT eats so much CPU and Memory
Post by: qjvictor on December 11, 2006, 04:19:29 pm
Thanks.
You mean in the loop to render the screen, use Thread.sleep?
I will try.
Thanks anyway.
Title: JPCT eats so much CPU and Memory
Post by: eye1 on December 11, 2006, 04:49:33 pm
I use it like this

Code: [Select]

       //fps.. like 25
      int sleepTime = 1000 / fps;
      long first = System.currentTimeMillis();
      long second = 0;
      long actualSleepTime = 0;
      while (bRender) {
         //do some stuff in world here
         buffer.clear();
         world.renderScene(buffer);
         world.draw(buffer);
         buffer.update();
         buffer.displayGLOnly();
         second = System.currentTimeMillis();
         actualSleepTime = sleepTime - (second - first);
         if (actualSleepTime < 0) {
            actualSleepTime = 0;
         }
         try {
            Thread.sleep(actualSleepTime);
         }
         catch (InterruptedException ie) {}
         first=second;
      }


Title: JPCT eats so much CPU and Memory
Post by: qjvictor on December 11, 2006, 08:13:08 pm
The problem is that I must render the screen in every 10 ms.
Maybe that's the reason the jpct eats so much cpu.
Title: JPCT eats so much CPU and Memory
Post by: eye1 on December 11, 2006, 10:44:21 pm
There can also be other reasons, like complex objects you are rendering (lot of polygons)...
Title: JPCT eats so much CPU and Memory
Post by: EgonOlsen on December 12, 2006, 09:47:07 pm
It eats up what you are giving to it. The demos are designed to run at full speed, which results in 100% cpu usage on a single core machine. If you don't want that, render less frames. As said, at a sleep if possible. And how much is much? You may try to use Config.saveMemory=true to save seom memory at the cost of...well, of almost nothing. Just try it and see if it helps.