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/
 | 
					int/
 | 
				
			||||||
*.aps
 | 
					*.aps
 | 
				
			||||||
*.res
 | 
					*.res
 | 
				
			||||||
 | 
					*.nfpack
 | 
				
			||||||
@ -61,9 +61,6 @@ void MainState::update(float deltaTime) {
 | 
				
			|||||||
			camera->moveLeft(speed * 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()));
 | 
						text.setText("FPS: " + std::to_string(app->getFPS()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (button.isClicked() || app->isKeyPressed(NFI_R))
 | 
						if (button.isClicked() || app->isKeyPressed(NFI_R))
 | 
				
			||||||
@ -79,6 +76,12 @@ void MainState::update(float deltaTime) {
 | 
				
			|||||||
		sound2.stop();
 | 
							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))
 | 
						if (app->isKeyPressed(NFI_ESCAPE))
 | 
				
			||||||
		app->quit();
 | 
							app->quit();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -102,6 +105,5 @@ void MainState::render(nf::Renderer& renderer) {
 | 
				
			|||||||
void MainState::onExit() {
 | 
					void MainState::onExit() {
 | 
				
			||||||
	Log("MainState onExit!");
 | 
						Log("MainState onExit!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	circle = 0.0f;
 | 
					 | 
				
			||||||
	entities.clear();
 | 
						entities.clear();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -27,7 +27,5 @@ private:
 | 
				
			|||||||
	nf::Sound sound;
 | 
						nf::Sound sound;
 | 
				
			||||||
	nf::Sound sound2;
 | 
						nf::Sound sound2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float circle;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	std::vector<nf::Entity*> entities;
 | 
						std::vector<nf::Entity*> entities;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							@ -10,7 +10,7 @@
 | 
				
			|||||||
namespace nf {
 | 
					namespace nf {
 | 
				
			||||||
	Entity::Entity() :
 | 
						Entity::Entity() :
 | 
				
			||||||
		m_constructed(false),
 | 
							m_constructed(false),
 | 
				
			||||||
		m_createdAtLoad(false),
 | 
							m_member(false),
 | 
				
			||||||
		m_type(Type::STATIC),
 | 
							m_type(Type::STATIC),
 | 
				
			||||||
		m_model(nullptr),
 | 
							m_model(nullptr),
 | 
				
			||||||
		m_position(0.0),
 | 
							m_position(0.0),
 | 
				
			||||||
@ -18,9 +18,8 @@ namespace nf {
 | 
				
			|||||||
		m_scale(1.0),
 | 
							m_scale(1.0),
 | 
				
			||||||
		m_update(false)
 | 
							m_update(false)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (Application::getApp() && Application::getApp()->getCurrentState())
 | 
							if (!Application::getApp() || !Application::getApp()->getCurrentState())
 | 
				
			||||||
			if (Application::getApp()->getCurrentState()->isLoading())
 | 
								m_member = true;
 | 
				
			||||||
				m_createdAtLoad = true;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Entity::create(Asset* modelAsset, Type type) {
 | 
						void Entity::create(Asset* modelAsset, Type type) {
 | 
				
			||||||
@ -46,11 +45,10 @@ namespace nf {
 | 
				
			|||||||
		if (type != Type::DETAIL)
 | 
							if (type != Type::DETAIL)
 | 
				
			||||||
			Application::getApp()->getPhysicsEngine()->addActor(this);
 | 
								Application::getApp()->getPhysicsEngine()->addActor(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!Application::getApp()->getCurrentState()->isRunning())
 | 
							if (m_member)
 | 
				
			||||||
			if (m_createdAtLoad)
 | 
					 | 
				
			||||||
				Application::getApp()->getCurrentState()->m_entsToDelete.push_back(this);
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
			Application::getApp()->getCurrentState()->m_nfObjects.push_back(this);
 | 
								Application::getApp()->getCurrentState()->m_nfObjects.push_back(this);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								Application::getApp()->getCurrentState()->m_entsToDelete.push_back(this);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool Entity::isConstructed() {
 | 
						bool Entity::isConstructed() {
 | 
				
			||||||
 | 
				
			|||||||
@ -19,8 +19,6 @@ namespace nf {
 | 
				
			|||||||
			Error("Model exceedes 32 texture limit!");
 | 
								Error("Model exceedes 32 texture limit!");
 | 
				
			||||||
		std::string obj = model->data;
 | 
							std::string obj = model->data;
 | 
				
			||||||
		size_t startMtlPos = obj.find("newmtl");
 | 
							size_t startMtlPos = obj.find("newmtl");
 | 
				
			||||||
		if (startMtlPos == std::string::npos)
 | 
					 | 
				
			||||||
			Error("No materials found in model!");
 | 
					 | 
				
			||||||
		std::string mtl = obj.substr(startMtlPos);
 | 
							std::string mtl = obj.substr(startMtlPos);
 | 
				
			||||||
		struct TempMaterial {
 | 
							struct TempMaterial {
 | 
				
			||||||
			std::vector<float> outVB;
 | 
								std::vector<float> outVB;
 | 
				
			||||||
 | 
				
			|||||||
@ -49,7 +49,7 @@ namespace nf {
 | 
				
			|||||||
		~Entity();
 | 
							~Entity();
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		bool m_constructed;
 | 
							bool m_constructed;
 | 
				
			||||||
		bool m_createdAtLoad;
 | 
							bool m_member;
 | 
				
			||||||
		Type m_type;
 | 
							Type m_type;
 | 
				
			||||||
		Model* m_model;
 | 
							Model* m_model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user