Jump to content

C++ Lagging


TonyF
 Share

Recommended Posts

Hi,

 

I have started a c++ project and am using the zombie DLC as an initial placeholder.

 

I have noticed that i can load in a maximum of about 5 zombie models (no animations or scripts running) and then the framerate goes down for every additional zombie i add to a max of 10.

 

If i put the default prefab zombie into the map then i can put 10 in without lag.

 

I have tried both debug and release modes.

Oddly when i add in extra models and my framerate goes down so does my GPU usage which i have no idea why (Goes from 10% to more or less nothing / CPU sits on about 12%).

 

I do suppress GL_Invalid_Operation as that prevents debug mode in both lua only and C++ debug modes.

 

Any ideas why i am getting such poor performance?

 

I have also tried publishing the game and running it on a separate computer and the performance was identical. The other PC was NVIDIA and this one is AMD.

Link to comment
Share on other sites

What processor do you have? If you have an eight-core, then you are maxing it out (and who knows, there might be other limits imposed by the OS to limit your program's CPU usage). Your GPU usage probably goes down because of this since it's waiting for the CPU to catch up.

 

Anyway, what does your map (if you have one) and code look like?

Link to comment
Share on other sites

I have a quad core i7 with hyperthreading enabled (8 cores).

 

My map is a square base with a texture on it and a couple stock cubes. (I have also used the default 'start' map).

 

I am currently doing a test with 10 zombies. The framerate has gone down to 10fps and camera movement is laggy.

 

In regards to the CPU, the game process is running at 8% CPU capacity and the total CPU usage is 12%. There is also no single core that is remotely maxing out.

 

Maybe i am running animations incorrectly? I just did an ultra simplified test using the default C++ project and a single ground floor cube.

 

In the startup function i have

Vec3 Pos = Vec3(0,0,0);

for (int i = 0; i < 10; i++) {

entity = Prefab::Load("Prefabs/Enemy/zombie1.pfb");

Pos.x += 1;

entity->SetPosition(Pos);

}

 

And in the main loop i have

 

float t = Time::GetCurrent() * 0.02;

for (int i = 0; i < 10; i++) {

entity->SetAnimationFrame(t, 1.0, 2, true);

}

 

This will give me an FPS of 50 and release mode then subsequent models will drop it lower.

 

I also just did a test of commenting the above out and using the zombie prefab which uses the lua script and i get about 35fps on release mode.

 

I am coming to a bit of a loss as to whats going on or what i can try.

Link to comment
Share on other sites

Have you tried using Entity::Instance() or Entity::Copy() instead? Like:

 

Vec3 Pos = Vec3(0,0,0);
Model* ent = Prefab::Load("Prefabs/Enemy/zombie1.pfb");

for (int i = 0; i < 10; i++) {
 entity[i] = (Model*)ent->Copy(); // or entity[i] = (Model*)ent->Instance()
 Pos.x += 1;
 entity[i]->SetPosition(Pos);
}

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

Thanks for the replies guys.

 

I tried this 'Model* ent = Prefab::Load("Prefabs/Enemy/zombie1.pfb");' Although Prefab::Load returns an entity.

 

10 Zombies loaded the way i initially had is about 43 fps.

If i load a single prefab entity and then call ->Instance() as suggested i get 15 fps

If i load a single prefab entity and then call ->Copy() as suggested i get 15 fps AND i dont see the models ??

If i load the model (Not the prefab) and then call ->Instance() i get 43 fps

If i load the model (Not the prefab) and then call ->Copy() i get 39 fps AND i dont see the models ??

 

Out of the above options loading the Prefab each time (is more efficient that instancing) or loading the model and then instancing it gives identical performance (which is interesting in my case).

Link to comment
Share on other sites

Each time you load the prefab, are the textures and materials loaded as well, or are they only loaded once during the load of the first prefab? I would guess they're only loaded once and then just referred to for each prefab, but if they're not, that would impair performance somewhat.

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...