Entities can now be created dynamically
This commit is contained in:
		
							parent
							
								
									aa58238162
								
							
						
					
					
						commit
						43c3d3930f
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -3,3 +3,4 @@ bin/
 | 
			
		||||
int/
 | 
			
		||||
*.aps
 | 
			
		||||
*.res
 | 
			
		||||
*.nfpack
 | 
			
		||||
@ -61,9 +61,6 @@ void MainState::update(float deltaTime) {
 | 
			
		||||
			camera->moveLeft(speed * deltaTime);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//test.setPosition(nf::Vec3(std::sin(circle) * 10.0, 5.0, std::cos(circle) * 10.0));
 | 
			
		||||
	circle += 1.5f * deltaTime;
 | 
			
		||||
 | 
			
		||||
	text.setText("FPS: " + std::to_string(app->getFPS()));
 | 
			
		||||
 | 
			
		||||
	if (button.isClicked() || app->isKeyPressed(NFI_R))
 | 
			
		||||
@ -79,6 +76,12 @@ void MainState::update(float deltaTime) {
 | 
			
		||||
		sound2.stop();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (app->isKeyPressed(NFI_K)) {
 | 
			
		||||
		entities.push_back(new nf::Entity);
 | 
			
		||||
		entities.back()->create(ap["2mats.obj"], nf::Entity::Type::DYNAMIC);
 | 
			
		||||
		entities.back()->setPosition(camera->getPosition());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (app->isKeyPressed(NFI_ESCAPE))
 | 
			
		||||
		app->quit();
 | 
			
		||||
}
 | 
			
		||||
@ -102,6 +105,5 @@ void MainState::render(nf::Renderer& renderer) {
 | 
			
		||||
void MainState::onExit() {
 | 
			
		||||
	Log("MainState onExit!");
 | 
			
		||||
 | 
			
		||||
	circle = 0.0f;
 | 
			
		||||
	entities.clear();
 | 
			
		||||
}
 | 
			
		||||
@ -27,7 +27,5 @@ private:
 | 
			
		||||
	nf::Sound sound;
 | 
			
		||||
	nf::Sound sound2;
 | 
			
		||||
 | 
			
		||||
	float circle;
 | 
			
		||||
 | 
			
		||||
	std::vector<nf::Entity*> entities;
 | 
			
		||||
};
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@ -10,7 +10,7 @@
 | 
			
		||||
namespace nf {
 | 
			
		||||
	Entity::Entity() :
 | 
			
		||||
		m_constructed(false),
 | 
			
		||||
		m_createdAtLoad(false),
 | 
			
		||||
		m_member(false),
 | 
			
		||||
		m_type(Type::STATIC),
 | 
			
		||||
		m_model(nullptr),
 | 
			
		||||
		m_position(0.0),
 | 
			
		||||
@ -18,9 +18,8 @@ namespace nf {
 | 
			
		||||
		m_scale(1.0),
 | 
			
		||||
		m_update(false)
 | 
			
		||||
	{
 | 
			
		||||
		if (Application::getApp() && Application::getApp()->getCurrentState())
 | 
			
		||||
			if (Application::getApp()->getCurrentState()->isLoading())
 | 
			
		||||
				m_createdAtLoad = true;
 | 
			
		||||
		if (!Application::getApp() || !Application::getApp()->getCurrentState())
 | 
			
		||||
			m_member = true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void Entity::create(Asset* modelAsset, Type type) {
 | 
			
		||||
@ -46,11 +45,10 @@ namespace nf {
 | 
			
		||||
		if (type != Type::DETAIL)
 | 
			
		||||
			Application::getApp()->getPhysicsEngine()->addActor(this);
 | 
			
		||||
 | 
			
		||||
		if (!Application::getApp()->getCurrentState()->isRunning())
 | 
			
		||||
			if (m_createdAtLoad)
 | 
			
		||||
				Application::getApp()->getCurrentState()->m_entsToDelete.push_back(this);
 | 
			
		||||
			else
 | 
			
		||||
		if (m_member)
 | 
			
		||||
			Application::getApp()->getCurrentState()->m_nfObjects.push_back(this);
 | 
			
		||||
		else
 | 
			
		||||
			Application::getApp()->getCurrentState()->m_entsToDelete.push_back(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	bool Entity::isConstructed() {
 | 
			
		||||
 | 
			
		||||
@ -19,8 +19,6 @@ namespace nf {
 | 
			
		||||
			Error("Model exceedes 32 texture limit!");
 | 
			
		||||
		std::string obj = model->data;
 | 
			
		||||
		size_t startMtlPos = obj.find("newmtl");
 | 
			
		||||
		if (startMtlPos == std::string::npos)
 | 
			
		||||
			Error("No materials found in model!");
 | 
			
		||||
		std::string mtl = obj.substr(startMtlPos);
 | 
			
		||||
		struct TempMaterial {
 | 
			
		||||
			std::vector<float> outVB;
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ namespace nf {
 | 
			
		||||
		~Entity();
 | 
			
		||||
	private:
 | 
			
		||||
		bool m_constructed;
 | 
			
		||||
		bool m_createdAtLoad;
 | 
			
		||||
		bool m_member;
 | 
			
		||||
		Type m_type;
 | 
			
		||||
		Model* m_model;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user