コード例 #1
0
ファイル: tester.cpp プロジェクト: pmarathe25/GameEngine2D
int main() {
    ResourceManager resourceManager = ResourceManager();
    resourceManager.addResourceDirectory("res/");
    sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "ECS Test");
    EntityManager entityManager = EntityManager(&window, 100);
    for (int i = 1; i < 10000; ++i) {
        int temp = entityManager.createEntity(sf::Vector2f(WINDOW_X * float(rand()) / RAND_MAX, WINDOW_Y * float(rand()) / RAND_MAX));
        entityManager.attachComponent(temp, RenderComponent(resourceManager.getTexture("player.png")));
        entityManager.attachComponent(temp, PhysicsComponent(sf::Vector2f(100 * (float(rand()) / RAND_MAX - 0.5), 100 * (float(rand()) / RAND_MAX - 0.5))));
    }
    // Remove some entities.
    for (int i = 1; i < 3; ++i) {
        entityManager.destroyEntity(i);
    }
    // Remove some components.
    for (int i = 3; i < 10; ++i) {
        entityManager.detachComponent(i, RENDER);
    }
    sf::Clock clock;
    while (window.isOpen()) {
        // Handle events.
        sf::Event event;
        while (window.pollEvent(event)) {
          if(event.type == sf::Event::Closed) {
              window.close();
          }
        }
        float frametime = clock.restart().asSeconds();
        std::cout << (1 / frametime) << std::endl;
        window.clear(sf::Color::White);
        entityManager.update(frametime);
        window.display();
    }
}
コード例 #2
0
ファイル: main.cpp プロジェクト: eoma/totem-edk
int main(int /*argc*/, char** /*argv*/)
{
	std::cout << "--------------------------" << std::endl;
	std::cout << "EXPLODING BOMBS EXAMPLE!" << std::endl;
	std::cout << "--------------------------" << std::endl;
	std::cout << "This example displays the interaction between multiple entities via uncoupled components." << std::endl;
	std::cout << "--------------------------" << std::endl;
	std::cout << "CREATING ENTITIES" << std::endl;
	std::cout << "--------------------------" << std::endl;
	EntityManager mgr;
	auto boxA = make_box("BoxA", mgr);
	auto boxB = make_box("BoxB", mgr);
	auto bombA = make_bomb("BombA", mgr);
	auto bombB = make_bomb("BombB", mgr);

	std::cout << "--------------------------" << std::endl;
	std::cout << "SETTING PROPERTIES" << std::endl;
	std::cout << "--------------------------" << std::endl;
	std::cout << "Position of " << bombA->get_name() << " is " << bombA->get<Vec2i>(PROPERTY_POSITION).get().x << ", " << bombA->get<Vec2i>(PROPERTY_POSITION).get().y << std::endl;
	bombB->get<Vec2i>(PROPERTY_POSITION) = Vec2i(2,0);
	boxA->get<Vec2i>(PROPERTY_POSITION) = Vec2i(2,1);
	boxB->get<Vec2i>(PROPERTY_POSITION) = Vec2i(5,0);

	boxA->get<int>(PROPERTY_HEALTH) = 150;
	boxB->get<int>(PROPERTY_HEALTH) = 150;
	std::cout << "Health of " << bombA->get_name() << " is " << bombA->get<int>(PROPERTY_HEALTH) << std::endl;
	std::cout << "Health of " << bombB->get_name() << " is " << bombB->get<int>(PROPERTY_HEALTH) << std::endl;

	std::cout << "--------------------------" << std::endl;
	std::cout << "START EXPLOSION" << std::endl;
	std::cout << "--------------------------" << std::endl;
	bombA->get<int>(PROPERTY_HEALTH) = 0;

	std::cout << "--------------------------" << std::endl;
	std::cout << "UPDATE ENTITY MANAGER STATE" << std::endl;
	std::cout << "--------------------------" << std::endl;
	mgr.update();

	std::cout << "--------------------------" << std::endl;
	std::cout << "ENTITIES IN ENTITY MANAGER" << std::endl;
	std::cout << "--------------------------" << std::endl;
	for(auto entity : mgr.get_entities())
	{
		std::cout << entity->get_name() << std::endl;
	}
	std::cout << "--------------------------" << std::endl;
	system("pause");
	return 0;
}
コード例 #3
0
ファイル: Main_Test_Physique.cpp プロジェクト: Ruddle/Bismuth
int main(int argc, char** argv)
{
	EntityManager *em = new EntityManager();

	SphereDetectionComponent* dcCam = new SphereDetectionComponent(1);
	StateComponent* scCam = new StateComponent();
	PhysicComponent* pcCam = new PhysicComponent(dcCam, scCam);
	mat4 projection = glm::perspective(70.0*M_PI / 180.0, 16.0 / 9.0, 0.1, 100.0);
	Camera* cam = new Camera(projection, pcCam);


	SphereDetectionComponent* dc1 = new SphereDetectionComponent(1);
	StateComponent* sc1 = new StateComponent();
	PhysicComponent* pc1 = new PhysicComponent(dc1, sc1);
	GraphicComponent* gc1 = new GraphicComponent();
	Entity* en1 = new Entity(gc1, pc1);
	em->add(en1);

	SphereDetectionComponent* dc2 = new SphereDetectionComponent(1);
	StateComponent* sc2 = new StateComponent();
	PhysicComponent* pc2 = new PhysicComponent(dc2, sc2);
	GraphicComponent* gc2 = new GraphicComponent();
	Entity* en2 = new Entity(gc2, pc2);
	em->add(en2);


	SphereDetectionComponent* dc3 = new SphereDetectionComponent(1);
	StateComponent* sc3 = new StateComponent();
	PhysicComponent* pc3 = new PhysicComponent(dc3, sc3);
	GraphicComponent* gc3 = new GraphicComponent();
	Entity* en3 = new Entity(gc3, pc3);
	em->add(en3);



	for (int i = 0; i < 100; i++)
	{
		en2->getPhysicComponent()->getStateComponent()->setPosition(vec3(0, 0, 5-(float)i/2.0));
		en3->getPhysicComponent()->getStateComponent()->setPosition(vec3(0, 3 - (float)i / 4.0,0));

		em->collision();
		em->update();

		std::set<Contact*> contact_en1 = en1->getPhysicComponent()->getContact();

		int j = 0;
		cout << "frame n " << i << endl;
		for (std::set<Contact*>::iterator it = contact_en1.begin(); it != contact_en1.end(); it++)
		{
			j++;
			cout << "Contact du solide 1 :" << endl;
			cout << "Contact n " << j << " Xpos = " << (*it)->position.x << " Ypos = " << (*it)->position.y << " Zpos = " << (*it)->position.z << endl;
			cout << "Contact n " << j << " Xnor = " << (*it)->normal.x << " Ynor = " << (*it)->normal.y << " Znor = " << (*it)->normal.z << endl;
		}

		cout << endl;

	}


	system("PAUSE");

}