Jump to content

Low FPS when player collides with phy. objects(C++)


Jorns2
 Share

Recommended Posts

Hi, i use c++ and when player collides with physical objects (i have some boxes on map (20-30)  fps drop to 2-4 ms and lags.

If player collides only with terrain everything is ok. I have noticed when game starts after compiling code on start lags and after 2-3 seconds fps go to 60. And after collision with physical objects drop fps again. Where is the problem.

 

Here is some code:

 

#include "Leadwerks.h"

using namespace Leadwerks;

Entity* player;
const int playerAngleModifier = 3;
int playerAngle=0;
int playerMovement = 0;
int playerMovementSpeed = 7;



void ListEntities(Entity* entity, Object* extra)
{
	
	if (entity->GetKeyValue("type") == "player")
	{
		System::Print(entity->GetKeyValue("type"));
		player = entity;
	}
}


int main(int argc, const char *argv[])
{
	Leadwerks::Window* window = Leadwerks::Window::Create("TEST", 0, 0, 1366, 768, Leadwerks::Window::Fullscreen);
	Context* context = Context::Create(window);
	World* world = World::Create();



	


	

	Map::Load("Maps/Prva mapa.map", ListEntities);


	Camera* camera = Camera::Create();
	camera->SetPosition(player->GetPosition()+Vec3(0,15,0));
	camera->SetRotation(90, 0, 0);
	camera->SetFOV(45);
	Listener::Create(player);



	while (true)
	{
		if (window->Closed() || window->KeyDown(Key::Escape)) return false;

	
		if (window->KeyDown(Key::Up))
		{
			playerMovement = playerMovementSpeed - (playerMovementSpeed * 2);
		}
		else if (window->KeyDown(Key::Down))
		{
		playerMovement = playerMovementSpeed;
		}
		if (window->KeyDown(Key::Left))
		{
			playerAngle = playerAngle - playerAngleModifier;
		}
		else if (window->KeyDown(Key::Right))
		{
			playerAngle = playerAngle + playerAngleModifier;
		}



		player->SetRotation(0, playerAngle, 0);
		player->SetInput(playerAngle, playerMovement, 0);
		camera->SetPosition(player->GetPosition() + Vec3(0, 15, 0));


		playerMovement = 0;




		Leadwerks::Time::Update();
		world->Update(1);
		world->Render();
		float text = Math::Round(Time::UPS());

		context->SetBlendMode(Blend::Alpha);
		context->DrawText( "FPS:" + std::to_string(text), 2, 10);
		context->Sync(true);


	}
	return 0;
}

 

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