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


      //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.