Riffle::Riffle(int id) : AEntity(id) { _name = "5"; addSystem(C_POSITION); addSystem(C_HITBOX); // std::cout << "Je créé un rifle" << std::endl; }
int main() { auto window = sf::RenderWindow(sf::VideoMode(800,600), "Mouse Cursor Input Test"); //event manager requires a target window to operate correctly auto eventManager = EventManager::getInstance(); //we set the target window to our render window eventManager->setWindow(&window); auto eventSystem = std::shared_ptr<EventSystem> (new EventSystem()); eventSystem->registerClosed_Callback([&] (int ID, int eventIndex) { window.close(); return 0; }); //populate the system manager auto systemManager = SystemManager::getInstance(); systemManager->addSystem(std::shared_ptr<systemType> (new SpriteSystem(window))); systemManager->addSystem(std::shared_ptr<systemType> (new InputSystem())); systemManager->addSystem(std::shared_ptr<systemType> (std::static_pointer_cast<systemType> (eventSystem))); //populate our entity manager auto entityManager = EntityManager::getInstance(); entityManager->addEntity(createCursorEntity("MouseCursor")); while(window.isOpen()) { window.clear(); eventManager->pollEvents(); systemManager->processSystemList(); window.display(); } return 0; }
// ============================================================================ // Constructor AntiAirBattery::AntiAirBattery ( World* pWorld, double location, double angle ) : Machine ( pWorld ) { setLayers( PhysLayerBuildings ); setRenderLayer( LayerBuildings ); setName("Flak"); double locationY = world()->ground()->height( location ); b2Vec2 basePos( location, locationY ); b2Vec2 bodyPos( location, locationY + 1.5 ); // create damage manager _dmMain = new DamageManager(); addDamageManager( _dmMain ); _bodyMain = BodyProvider::loadBody( "installations/flak1-body.body" ); _bodyMain->setPosition( bodyPos ); _bodyMain->create( pWorld ); addBody( _bodyMain, BodyRendered1 ); _bodyBase = BodyProvider::loadBody( "installations/flak1-base.body" ); _bodyBase->setPosition( basePos ); _bodyBase->create( pWorld ); addBody( _bodyBase, BodyRendered1 ); setMainBody( _bodyBase ); _bodyMain->setDamageManager( _dmMain ); // create gun _sysGun = Gun::berezin( this, "Gun" ); _sysGun->setBody( _bodyMain ); _sysGun->setMuzzle( QPointF( 0.0, 0.0 ) ); _sysGun->setMuzzleShift( 4.0 ); _sysGun->setNormal( QPointF( cos( angle), sin(angle) ) ); addSystem( _sysGun, SystemSimulated ); // create operator _sysOperator = new AntiAirGunOperator( this, "operator" ); _sysOperator->setGun( _sysGun ); _sysOperator->setMinAngle( 0.5 ); _sysOperator->setMaxAngle( M_PI/2 ); _sysOperator->setDamageCapacity( 100E3 ); addSystem( _sysOperator, SystemSimulated ); _lastDisplayedAngle = 0.5; // min angle from zenith; // add systems to damage manager _dmMain->addSystem( _sysGun, 1 ); _dmMain->addSystem( _sysOperator, 1 ); _dmMain->addSystem( NULL, 2 ); }
Bot::Bot(int id) : AEntity(id), _health(50), _y(0) { _timerShoot = new Timer(true); _sprite = "sprite1.png"; _name = _sprite; _type = E_BOT; addSystem(C_HEALTH); addSystem(C_POSITION); addSystem(C_HITBOX); generateX(); generateY(); dynamic_cast<SystemPos*>(_systemManager->getSystemByComponent(C_POSITION))->update(_x, _y); dynamic_cast<SystemHitbox*>(_systemManager->getSystemByComponent(C_HITBOX))->update(refreshHitbox()); }
ArmyEngine::ArmyEngine() : window(sf::RenderWindow(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), WINDOW_TITLE)), componentFactory(ComponentFactory()), entityFactory(EntityFactory()) { //removing the cursor this->window.setMouseCursorVisible(false); //First, assign the window to all of the required entities that have dependance on it. // event manager needs the window to get the events auto eventManager = EventManager::getInstance(); eventManager->setWindow(&(this->window)); // assign stateSystem this->stateSystem = std::shared_ptr<StateSystem>(new StateSystem()); //assign and create our eventSystem this->eventSystem = std::shared_ptr<EventSystem>(new EventSystem()); // spriteSystem needs the window to draw auto spriteSystem = std::shared_ptr<systemType> (new SpriteSystem(window)); //Assign the systems to our system manager auto systemManager = SystemManager::getInstance(); systemManager->addSystem(std::static_pointer_cast<systemType> (this->eventSystem)); systemManager->addSystem(spriteSystem); systemManager->addSystem(std::shared_ptr<systemType>(new InputSystem())); systemManager->addSystem(std::shared_ptr<systemType> (new CollisionSystem())); systemManager->addSystem(std::static_pointer_cast<systemType> (this->stateSystem)); //default event handling //by default, closing will end the program this->addEventCallback(EnumEventType::EVENT_CLOSED, [&] (int ID) { window.close(); return 0; }); }
ParticleSystem& ParticleController::findSystem(Particle::Type type) { //find an idle system and use it auto result = std::find_if(m_systems.begin(), m_systems.end(), [type](const ParticleSystem& ps) { return (ps.getType() == type && !ps.started()); }); if (result != m_systems.end()) { return (*result); } //else append a new system else { return addSystem(type); } }
void GameStateOne::doInit(void) { // First call our base class implementation IState::doInit(); //Assets #ifndef NDEBUG mStatManager.doInit(); mStatManager.setShow(true); #endif sf::Texture* anSpriteTexture = mApp.mAssetManager.getHandler<sf::Texture>(). getReference("resources/Sprites.png", GQE::AssetLoadNow, GQE::AssetLoadFromFile, GQE::AssetDropAtZero); sf::Texture* anTileTexture = mApp.mAssetManager.getHandler<sf::Texture>(). getReference("resources/Tiles1.png", GQE::AssetLoadNow, GQE::AssetLoadFromFile, GQE::AssetDropAtZero); mApp.mAssetManager.loadAllAssets(); //Prototypes auto boxProto = new Box(); auto basicShipProto = new BasicShip(this); auto simpleBulletProto = new SimpleBullet(); auto playerProto = new Player(); auto machinegunProto = new Machinegun(); auto shipPropellerProto = new ShipPropeller(mParticles); mRenderSystem = new RenderSystem(*this, mRenderManager, LENGTHFACTOR); mPlayerSystem = new PlayerSystem(*this, mView, LENGTHFACTOR); mPhysicSystem = new PhysicSystem(*this, mWorld); mAnimationSystem = new AnimationSystem(*this); mHealthSystem = new HealthSystem(*this); mActorSystem = new ActorSystem(*this); mNodeSystem = new NodeSystem(*this); mInputSystem = new InputSystem(*this); playerProto->addSystem(mPlayerSystem); machinegunProto->addSystem(mNodeSystem); machinegunProto->addSystem(mInputSystem); machinegunProto->addSystem(mRenderSystem); machinegunProto->addSystem(mHealthSystem); machinegunProto->addSystem(mPhysicSystem); simpleBulletProto->addSystem(mRenderSystem); simpleBulletProto->addSystem(mHealthSystem); simpleBulletProto->addSystem(mPhysicSystem); shipPropellerProto->addSystem(mNodeSystem); shipPropellerProto->addSystem(mInputSystem); shipPropellerProto->addSystem(mRenderSystem); shipPropellerProto->addSystem(mHealthSystem); shipPropellerProto->addSystem(mPhysicSystem); basicShipProto->addSystem(mNodeSystem); basicShipProto->addSystem(mRenderSystem); basicShipProto->addSystem(mActorSystem); basicShipProto->addSystem(mHealthSystem); basicShipProto->addSystem(mPhysicSystem); boxProto->addSystem(mRenderSystem); boxProto->addSystem(mAnimationSystem); boxProto->addSystem(mHealthSystem); boxProto->addSystem(mPhysicSystem); mPrototypes.addPrototype(boxProto); mPrototypes.addPrototype(basicShipProto); mPrototypes.addPrototype(simpleBulletProto); mPrototypes.addPrototype(playerProto); mPrototypes.addPrototype(machinegunProto); mPrototypes.addPrototype(shipPropellerProto); //RenderUnits mRenderManager.addLayer(BACKGROUND, anTileTexture); mRenderManager.addLayer(FOREGROUND, anTileTexture); mRenderManager.addLayer(OBJECTS, anSpriteTexture); mRenderManager.addLayer(PARTICLES_1, anSpriteTexture); mRenderManager.addLayer(PARTICLES_2, anSpriteTexture); mRenderManager.getLayer(OBJECTS).mUpdatable = true; mRenderManager.getLayer(PARTICLES_1).mUpdatable = true; mRenderManager.getLayer(PARTICLES_2).mUpdatable = true; mRenderManager.getLayer(BACKGROUND).mUpdatable = false; mRenderManager.getLayer(FOREGROUND).mUpdatable = false; //Update Rate mApp.setUpdateRate(UPDATE_RATE); mApp.mWindow.setView(mView); mView.setRotation(0); mView.setSize(mApp.mVideoMode.width,mApp.mVideoMode.height); //Others mParticles.setSize(1024); mParticles.setXFactor(16); mParticles.setYFactor(16); mParticles.initFromFile("resources/Particles.xml"); mParticles.addAffector(DisolveAffector::create(2)); //MapLoader MapLoader anMapLoader("resources/map1.tmx"); anMapLoader.loadTiles(mRenderManager); anMapLoader.loadShapes(mWorld); mCollisionListener = new CollisionListener(); mWorld.SetContactListener(mCollisionListener); }
GameEntitySystem::GameEntitySystem() { highestEntityPresetIndex = 0; entityPresetCount = 0; GameScene newScene; sceneList.push_back(newScene); entityList = &sceneList[0].entityList; entityGroupList = &sceneList[0].entityGroupList; highestEntityIndex = &sceneList[0].highestEntityIndex; availableIDList = &sceneList[0].availableIDList; entityCount = &sceneList[0].entityCount; deadList = &sceneList[0].deadList; isInUpdateLoop = 0; entityList->reserve(1024); LifeSystem *lifeSystem = new LifeSystem(); addSystem(lifeSystem); DynamicsSystem *dynamicsSystem = new DynamicsSystem(); addSystem(dynamicsSystem); PhysicsSystem *physicsSystem = new PhysicsSystem(); addSystem(physicsSystem); AnimationSystem *animationSystem = new AnimationSystem(); addSystem(animationSystem); RenderingSystem *renderingSystem = new RenderingSystem(); addSystem(renderingSystem); PositionComponent positionComponent; addScriptComponentInterface(&positionComponent, sizeof(positionComponent), "position"); addScriptComponentVariable("position", GameComponentVariable_Float, "x"); addScriptComponentVariable("position", GameComponentVariable_Float, "y"); addScriptComponentVariable("position", GameComponentVariable_Float, "z"); MovementComponent movementComponent; addScriptComponentInterface(&movementComponent, sizeof(movementComponent), "movement"); addScriptComponentVariable("movement", GameComponentVariable_Float, "velocityX"); addScriptComponentVariable("movement", GameComponentVariable_Float, "velocityY"); addScriptComponentVariable("movement", GameComponentVariable_Float, "velocityZ"); addScriptComponentVariable("movement", GameComponentVariable_Float, "accelerationX"); addScriptComponentVariable("movement", GameComponentVariable_Float, "accelerationY"); addScriptComponentVariable("movement", GameComponentVariable_Float, "accelerationZ"); PhysicsComponent physicsComponent; addScriptComponentInterface(&physicsComponent, sizeof(physicsComponent), "physics"); addScriptComponentVariable("physics", GameComponentVariable_Bool, "isDynamic"); addScriptComponentVariable("physics", GameComponentVariable_Float, "width"); addScriptComponentVariable("physics", GameComponentVariable_Float, "height"); addScriptComponentVariable("physics", GameComponentVariable_Float, "density"); addScriptComponentVariable("physics", GameComponentVariable_Float, "restitution"); addScriptComponentVariable("physics", GameComponentVariable_Float, "friction"); WidthHeightComponent widthHeightComponent; addScriptComponentInterface(&widthHeightComponent, sizeof(widthHeightComponent), "dimensions"); addScriptComponentVariable("dimensions", GameComponentVariable_Float, "width"); addScriptComponentVariable("dimensions", GameComponentVariable_Float, "height"); LifeSpanComponent lifeSpanComponent; addScriptComponentInterface(&lifeSpanComponent, sizeof(lifeSpanComponent), "lifeSpan"); addScriptComponentVariable("lifeSpan", GameComponentVariable_Float, "length"); RenderComponent renderComponent; addScriptComponentInterface(&renderComponent, sizeof(renderComponent), "render"); TransformationComponent transformationComponent; addScriptComponentInterface(&transformationComponent, sizeof(transformationComponent), "transformation"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "scaleX"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "scaleY"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "rotationX"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "rotationY"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "rotationZ"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "centerX"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "centerY"); addScriptComponentVariable("transformation", GameComponentVariable_Float, "centerZ"); ColorComponent colorComponent; addScriptComponentInterface(&colorComponent, sizeof(colorComponent), "color"); addScriptComponentVariable("color", GameComponentVariable_Float, "r"); addScriptComponentVariable("color", GameComponentVariable_Float, "g"); addScriptComponentVariable("color", GameComponentVariable_Float, "b"); addScriptComponentVariable("color", GameComponentVariable_Float, "a"); TextureComponent textureComponent; addScriptComponentInterface(&textureComponent, sizeof(textureComponent), "texture"); addScriptComponentVariable("texture", GameComponentVariable_Int, "texturePointer"); addScriptComponentVariable("texture", GameComponentVariable_Float, "sourcePositionX"); addScriptComponentVariable("texture", GameComponentVariable_Float, "sourcePositionY"); addScriptComponentVariable("texture", GameComponentVariable_Float, "sourceWidth"); addScriptComponentVariable("texture", GameComponentVariable_Float, "sourceHeight"); SpriteSheetAnimationComponent spriteSheetAnimationComponent; addScriptComponentInterface(&spriteSheetAnimationComponent, sizeof(spriteSheetAnimationComponent), "spriteSheetAnimation"); addScriptComponentVariable("spriteSheetAnimation", GameComponentVariable_Short, "currentFrame"); addScriptComponentVariable("spriteSheetAnimation", GameComponentVariable_Short, "currentRow"); addScriptComponentVariable("spriteSheetAnimation", GameComponentVariable_Short, "frameCount"); addScriptComponentVariable("spriteSheetAnimation", GameComponentVariable_Short, "direction"); addScriptComponentVariable("spriteSheetAnimation", GameComponentVariable_Short, "columnCount"); addScriptComponentVariable("spriteSheetAnimation", GameComponentVariable_Float, "frameInterval"); addScriptComponentVariable("spriteSheetAnimation", GameComponentVariable_Float, "passedTime"); }
int main() { auto entityManager = EntityManager::getInstance(); //create entities auto entity = std::shared_ptr<entityType> (new MainEntity("Cursor", 0)); entityManager->addEntity(entity); auto shapeComponent = std::shared_ptr<componentType> (new ShapeComponent("CursorHeight")); entity->addComponent(shapeComponent); shapeComponent->setAttribute_string(ATTRIBUTE_SHAPE_TYPE, SHAPETYPE_RECTANGLE); shapeComponent->setAttribute_float(ATTRIBUTE_WIDTH, 2.0f); shapeComponent->setAttribute_float(ATTRIBUTE_HEIGHT, 10.0f); shapeComponent->setAttribute_float(ATTRIBUTE_RADIUS, 5.0); shapeComponent->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_ALPHA, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 255); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 0); shapeComponent->setAttribute_float(ATTRIBUTE_OFFSET_X, 4.0); shapeComponent->setAttribute_float(ATTRIBUTE_OFFSET_Y, 0.0); shapeComponent->setAttribute_float(ATTRIBUTE_ZBUFFER, 1.1f); shapeComponent->update(); auto shapeComponent2 = std::shared_ptr<componentType> (new ShapeComponent("CursorWidth")); entity->addComponent(shapeComponent2); shapeComponent2->setAttribute_string(ATTRIBUTE_SHAPE_TYPE, SHAPETYPE_RECTANGLE); shapeComponent2->setAttribute_float(ATTRIBUTE_WIDTH, 10.0f); shapeComponent2->setAttribute_float(ATTRIBUTE_HEIGHT, 2.0f); shapeComponent2->setAttribute_float(ATTRIBUTE_RADIUS, 5.0); shapeComponent2->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_ALPHA, 0); shapeComponent2->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 255); shapeComponent2->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); shapeComponent2->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 0); shapeComponent2->setAttribute_float(ATTRIBUTE_OFFSET_X, 0.0); shapeComponent2->setAttribute_float(ATTRIBUTE_OFFSET_Y, 4.0); shapeComponent2->setAttribute_float(ATTRIBUTE_ZBUFFER, 1.1f); shapeComponent2->update(); auto collisionComponent = std::shared_ptr<componentType> (new CollisionComponent("Cursor Collision")); entity->addComponent(collisionComponent); collisionComponent->setAttribute_string(ATTRIBUTE_COLLISION_BOUND_TYPE, COLLISION_BOUND_RECTANGLE); collisionComponent->setAttribute_float(ATTRIBUTE_WIDTH, 5.0); collisionComponent->setAttribute_float(ATTRIBUTE_HEIGHT, 5.0); collisionComponent->setAttribute_string(ATTRIBUTE_COLLISION_TAG, "Cursor"); auto positionComponent = std::shared_ptr<componentType> (new PositionComponent("CursorPosition")); entity->addComponent(positionComponent); positionComponent->setAttribute_float(ATTRIBUTE_POSITION_X, 400); positionComponent->setAttribute_float(ATTRIBUTE_POSITION_Y, 300); positionComponent->setAttribute_float(ATTRIBUTE_OFFSET_X, -5.0); positionComponent->setAttribute_float(ATTRIBUTE_OFFSET_Y, -5.0); auto inputComponent = std::shared_ptr<componentType> (new InputComponent("Cursor Input")); entity->addComponent(inputComponent); inputComponent->setAttribute_string(ATTRIBUTE_INPUT_TYPE, INPUT_MOUSE_MOVE); inputComponent->setAttribute_string(ATTRIBUTE_CALLBACK, MOUSEINPUTCALLBACK); auto callbackManager = CallbackManager::getInstance(); callbackManager->addCallback(MOUSEINPUTCALLBACK, (functionEventTemplate) [] (int ID, int eventIndex) { auto entity = EntityManager::getInstance()->getEntityById(ID); sf::Event theEvent = *EventManager::getInstance()->getEvents()[eventIndex]; float xPosition = static_cast<float> (theEvent.mouseMove.x); float yPosition = static_cast<float> (theEvent.mouseMove.y); //apply the position of the mouse to the position of the entity auto positionComponent = entity->getComponentByName("CursorPosition"); positionComponent->setAttribute_float("Position_X", xPosition); positionComponent->setAttribute_float("Position_Y", yPosition); return 0; }); auto entity2 = std::shared_ptr<entityType> (new MainEntity("Collidable Button", 1)); entityManager->addEntity(entity2); auto shapeComponent3 = std::shared_ptr<componentType> (new ShapeComponent("Button Shape")); entity2->addComponent(shapeComponent3); shapeComponent3->setAttribute_string(ATTRIBUTE_SHAPE_TYPE, SHAPETYPE_RECTANGLE); shapeComponent3->setAttribute_float(ATTRIBUTE_WIDTH, 300.0f); shapeComponent3->setAttribute_float(ATTRIBUTE_HEIGHT, 200.0f); shapeComponent3->setAttribute_float(ATTRIBUTE_RADIUS, 5.0); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_RED, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_BLUE, 255); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_GREEN, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_OUTLINE_COLOR_ALPHA, 255); shapeComponent3->setAttribute_float(ATTRIBUTE_OUTLINE_THICKNESS, 5.0); shapeComponent3->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); shapeComponent3->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 255); shapeComponent3->setAttribute_float(ATTRIBUTE_OFFSET_X, 0.0); shapeComponent3->setAttribute_float(ATTRIBUTE_OFFSET_Y, 0.0); shapeComponent3->setAttribute_float(ATTRIBUTE_ZBUFFER, 0.0); shapeComponent3->update(); auto textComponent = std::shared_ptr<componentType> (new TextComponent("Text")); entity2->addComponent(textComponent); textComponent->setAttribute_string(ATTRIBUTE_TEXT_STRING, "Not collided with"); textComponent->setAttribute_int(ATTRIBUTE_TEXT_SIZE, 30); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_ALPHA, 200); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 20); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 20); textComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 20); textComponent->update(); auto positionComponent2 = std::shared_ptr<componentType> (new PositionComponent("BoxPosition")); entity2->addComponent(positionComponent2); positionComponent2->setAttribute_float(ATTRIBUTE_POSITION_X, 100.0); positionComponent2->setAttribute_float(ATTRIBUTE_POSITION_Y, 150.0); positionComponent2->setAttribute_float(ATTRIBUTE_OFFSET_X, 0); positionComponent2->setAttribute_float(ATTRIBUTE_OFFSET_Y, 0); auto collisionComponent2 = std::shared_ptr<componentType> (new CollisionComponent("CollisionButton")); entity2->addComponent(collisionComponent2); collisionComponent2->setAttribute_string(ATTRIBUTE_COLLISION_BOUND_TYPE, COLLISION_BOUND_RECTANGLE); collisionComponent2->setAttribute_float(ATTRIBUTE_WIDTH, 300.0); collisionComponent2->setAttribute_float(ATTRIBUTE_HEIGHT, 200.0); collisionComponent2->setAttribute_string(ATTRIBUTE_COLLISION_TAG, "Button"); //adding callbacks for when collisions occur auto collisionManager = CollisionManager::getInstance(); collisionManager->addCallback(collisionTagTuple("Button", "Cursor"), (functionCollisionTemplate) [] (collisionParamTuple paramTuple) { int entityID1, entityID2; std::string compName1, compName2; bool bRegistered; std::tie(entityID1, compName1, entityID2, compName2, bRegistered) = paramTuple; //grab the button entity auto buttonEntity = EntityManager::getInstance()->getEntityById(entityID1); //grab the shape component within that entity auto shapeComponent = buttonEntity->getComponentByName("Button Shape"); auto textComponent = buttonEntity->getComponentByName("Text"); if (bRegistered) { //change the shape component to have new outline shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 255); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); textComponent->setAttribute_string(ATTRIBUTE_TEXT_STRING, "Collided!"); std::cout << "Collision!" << std::endl; } else { shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_RED, 0); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_GREEN, 255); shapeComponent->setAttribute_int(ATTRIBUTE_FILL_COLOR_BLUE, 0); textComponent->setAttribute_string(ATTRIBUTE_TEXT_STRING, "Not Collided"); } shapeComponent->update(); textComponent->update(); return 0; }); //Start working on the window instance and system auto window = sf::RenderWindow(sf::VideoMode(800,600), "Mouse Cursor Input Test"); //remove the mouse cursor window.setMouseCursorVisible(false); auto eventManager = EventManager::getInstance(); //we set the target window to our render window eventManager->setWindow(&window); auto eventSystem = std::shared_ptr<EventSystem> (new EventSystem()); eventSystem->registerClosed_Callback([&] (int ID, int eventIndex) { window.close(); return 0; }); //populate the system manager auto systemManager = SystemManager::getInstance(); systemManager->addSystem(std::shared_ptr<systemType> (new SpriteSystem(window))); systemManager->addSystem(std::shared_ptr<systemType> (new InputSystem())); systemManager->addSystem(std::shared_ptr<systemType> (new CollisionSystem())); systemManager->addSystem(std::shared_ptr<systemType> (std::static_pointer_cast<systemType> (eventSystem))); while(window.isOpen()) { window.clear(); eventManager->pollEvents(); systemManager->processSystemList(); window.display(); } return 0; }
template<typename TType, typename ...TArgs> TType* addSystem(TArgs&... args) { addSystem(TypeIdGrabber::getUniqueTypeID<TType>(), new TType(m_game, args...)); };
PhysicsBasedPreconditioner::PhysicsBasedPreconditioner (const InputParameters & params) : MoosePreconditioner(params), Preconditioner<Number>(MoosePreconditioner::_communicator), _nl(_fe_problem.getNonlinearSystem()) { unsigned int num_systems = _nl.sys().n_vars(); _systems.resize(num_systems); _preconditioners.resize(num_systems); _off_diag.resize(num_systems); _off_diag_mats.resize(num_systems); _pre_type.resize(num_systems); { // Setup the Coupling Matrix so MOOSE knows what we're doing NonlinearSystem & nl = _fe_problem.getNonlinearSystem(); unsigned int n_vars = nl.nVariables(); // The coupling matrix is held and released by FEProblem, so it is not released in this object CouplingMatrix * cm = new CouplingMatrix(n_vars); bool full = false; //getParam<bool>("full"); // TODO: add a FULL option for PBP if (!full) { // put 1s on diagonal for (unsigned int i = 0; i < n_vars; i++) (*cm)(i, i) = 1; // off-diagonal entries std::vector<std::vector<unsigned int> > off_diag(n_vars); for (unsigned int i = 0; i < getParam<std::vector<std::string> >("off_diag_row").size(); i++) { unsigned int row = nl.getVariable(0, getParam<std::vector<std::string> >("off_diag_row")[i]).number(); unsigned int column = nl.getVariable(0, getParam<std::vector<std::string> >("off_diag_column")[i]).number(); (*cm)(row, column) = 1; } // TODO: handle coupling entries between NL-vars and SCALAR-vars } else { for (unsigned int i = 0; i < n_vars; i++) for (unsigned int j = 0; j < n_vars; j++) (*cm)(i,j) = 1; } _fe_problem.setCouplingMatrix(cm); } // PC types const std::vector<std::string> & pc_types = getParam<std::vector<std::string> >("preconditioner"); for (unsigned int i = 0; i < num_systems; i++) _pre_type[i] = Utility::string_to_enum<PreconditionerType>(pc_types[i]); // solve order const std::vector<std::string> & solve_order = getParam<std::vector<std::string> >("solve_order"); _solve_order.resize(solve_order.size()); for (unsigned int i = 0; i < solve_order.size(); i++) _solve_order[i] = _nl.sys().variable_number(solve_order[i]); // diag and off-diag systems unsigned int n_vars = _nl.sys().n_vars(); // off-diagonal entries const std::vector<std::string> & odr = getParam<std::vector<std::string> >("off_diag_row"); const std::vector<std::string> & odc = getParam<std::vector<std::string> >("off_diag_column"); std::vector<std::vector<unsigned int> > off_diag(n_vars); for (unsigned int i = 0; i < odr.size(); i++) { unsigned int row = _nl.sys().variable_number(odr[i]); unsigned int column = _nl.sys().variable_number(odc[i]); off_diag[row].push_back(column); } // Add all of the preconditioning systems for (unsigned int var = 0; var < n_vars; var++) addSystem(var, off_diag[var], _pre_type[var]); // We don't want to be computing the big Jacobian! _nl.sys().nonlinear_solver->jacobian = NULL; _nl.sys().nonlinear_solver->attach_preconditioner(this); _fe_problem.solverParams()._type = Moose::ST_JFNK; }
PhysicsBasedPreconditioner::PhysicsBasedPreconditioner(const InputParameters & params) : MoosePreconditioner(params), Preconditioner<Number>(MoosePreconditioner::_communicator), _nl(_fe_problem.getNonlinearSystemBase()), _init_timer(registerTimedSection("init", 2)), _apply_timer(registerTimedSection("apply", 1)) { unsigned int num_systems = _nl.system().n_vars(); _systems.resize(num_systems); _preconditioners.resize(num_systems); _off_diag.resize(num_systems); _off_diag_mats.resize(num_systems); _pre_type.resize(num_systems); { // Setup the Coupling Matrix so MOOSE knows what we're doing NonlinearSystemBase & nl = _fe_problem.getNonlinearSystemBase(); unsigned int n_vars = nl.nVariables(); // The coupling matrix is held and released by FEProblemBase, so it is not released in this // object std::unique_ptr<CouplingMatrix> cm = libmesh_make_unique<CouplingMatrix>(n_vars); bool full = false; // getParam<bool>("full"); // TODO: add a FULL option for PBP if (!full) { // put 1s on diagonal for (unsigned int i = 0; i < n_vars; i++) (*cm)(i, i) = 1; // off-diagonal entries std::vector<std::vector<unsigned int>> off_diag(n_vars); for (unsigned int i = 0; i < getParam<std::vector<std::string>>("off_diag_row").size(); i++) { unsigned int row = nl.getVariable(0, getParam<std::vector<std::string>>("off_diag_row")[i]).number(); unsigned int column = nl.getVariable(0, getParam<std::vector<std::string>>("off_diag_column")[i]).number(); (*cm)(row, column) = 1; } // TODO: handle coupling entries between NL-vars and SCALAR-vars } else { for (unsigned int i = 0; i < n_vars; i++) for (unsigned int j = 0; j < n_vars; j++) (*cm)(i, j) = 1; } _fe_problem.setCouplingMatrix(std::move(cm)); } // PC types const std::vector<std::string> & pc_types = getParam<std::vector<std::string>>("preconditioner"); for (unsigned int i = 0; i < num_systems; i++) _pre_type[i] = Utility::string_to_enum<PreconditionerType>(pc_types[i]); // solve order const std::vector<std::string> & solve_order = getParam<std::vector<std::string>>("solve_order"); _solve_order.resize(solve_order.size()); for (unsigned int i = 0; i < solve_order.size(); i++) _solve_order[i] = _nl.system().variable_number(solve_order[i]); // diag and off-diag systems unsigned int n_vars = _nl.system().n_vars(); // off-diagonal entries const std::vector<std::string> & odr = getParam<std::vector<std::string>>("off_diag_row"); const std::vector<std::string> & odc = getParam<std::vector<std::string>>("off_diag_column"); std::vector<std::vector<unsigned int>> off_diag(n_vars); for (unsigned int i = 0; i < odr.size(); i++) { unsigned int row = _nl.system().variable_number(odr[i]); unsigned int column = _nl.system().variable_number(odc[i]); off_diag[row].push_back(column); } // Add all of the preconditioning systems for (unsigned int var = 0; var < n_vars; var++) addSystem(var, off_diag[var], _pre_type[var]); _nl.nonlinearSolver()->attach_preconditioner(this); if (_fe_problem.solverParams()._type != Moose::ST_JFNK) mooseError("PBP must be used with JFNK solve type"); }