void Parser::blockBody(MethodGenerationContext* mgenc, bool seen_period, bool is_inlined) { if (accept(Exit)) result(mgenc); else if (sym == EndBlock) { if (seen_period) { // a POP has been generated which must be elided (blocks always // return the value of the last expression, regardless of whether it // was terminated with a . or not) mgenc->RemoveLastBytecode(); } if (!is_inlined) { bcGen->EmitRETURNLOCAL(mgenc); mgenc->SetFinished(); } } else if (sym == EndTerm) { // it does not matter whether a period has been seen, as the end of the // method has been found (EndTerm) - so it is safe to emit a "return // self" bcGen->EmitPUSHARGUMENT(mgenc, 0, 0); bcGen->EmitRETURNLOCAL(mgenc); mgenc->SetFinished(); } else { expression(mgenc); if (accept(Period)) { bcGen->EmitPOP(mgenc); blockBody(mgenc, true, is_inlined); } } }
void Parser::blockContents(MethodGenerationContext* mgenc, bool is_inlined) { if (accept(Or)) { locals(mgenc); expect(Or); } blockBody(mgenc, false, is_inlined); }
EntityPtr EntityFactory::createAnimatedEntity(const string& path, float width, float height) { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(0.0f, 0.0f, width, height)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); TexturePtr texture(GCC_NEW Texture("")); shared_ptr<TextureDrawable> textureDrawable(GCC_NEW TextureDrawable(texture)); graphicsSystem->registerDrawable(entity->id, textureDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable)); AnimationSystemPtr animationSystem = makeShared(mSystemManager->getSystemByType<AnimationSystem>(SystemType::ANIMATION)); AnimationSetPtr animationSet = animationSystem->createAnimationSet(path); AnimationHandlerPtr animationHandler(GCC_NEW AnimationHandler(textureDrawable, animationSet, animationSet->fps)); animationSystem->registerAnimation(entity->id, animationHandler); AnimationComponentPtr animationComponent(GCC_NEW AnimationComponent(entity->id, animationHandler)); InputSystemPtr inputSystem(makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT))); InputListenerPtr inputListener(GCC_NEW InputListener(entity->id)); inputSystem->registerEventListener(inputListener); InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener)); entity->addComponent(ComponentPtr(physicsComponent)); entity->addComponent(ComponentPtr(drawableComponent)); entity->addComponent(ComponentPtr(animationComponent)); entity->addComponent(ComponentPtr(inputComponent)); return entity; }
EntityPtr EntityFactory::createDefault() { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(0, 0, 16, 16)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); physicsComponent->setCollider(GCC_NEW Collider(0, 0, 16, 16)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); DrawablePtr blockDrawable(GCC_NEW BlockDrawable(16, 16, 255, 0, 0, 255)); graphicsSystem->registerDrawable(entity->id, blockDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, blockDrawable)); InputSystemPtr inputSystem = makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT)); InputListenerPtr inputListener(GCC_NEW InputListener(entity->id)); inputSystem->registerEventListener(inputListener); InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener)); entity->addComponent(ComponentPtr(physicsComponent)); entity->addComponent(ComponentPtr(drawableComponent)); entity->addComponent(ComponentPtr(inputComponent)); return entity; }
EntityPtr EntityFactory::createTexturedEntity(const string& assetTag, float tx, float ty, float w, float h) { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(0.0f, 0.0f, w, h)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); TexturePtr texture(GCC_NEW Texture(assetTag, tx, ty, w, h)); DrawablePtr textureDrawable(GCC_NEW TextureDrawable(texture)); graphicsSystem->registerDrawable(entity->id, textureDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable)); InputSystemPtr inputSystem = makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT)); InputListenerPtr inputListener(GCC_NEW InputListener(entity->id)); inputSystem->registerEventListener(inputListener); InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener)); entity->addComponent(ComponentPtr(physicsComponent)); entity->addComponent(ComponentPtr(drawableComponent)); entity->addComponent(ComponentPtr(inputComponent)); return entity; }
EntityPtr EntityFactory::createPhysicsEntity(float x, float y, float width, float height) { EntitySystemPtr entitySystem(makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY))); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(x, y, width, height)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); physicsComponent->setCollider(GCC_NEW Collider(x, y, width, height)); entity->addComponent(ComponentPtr(physicsComponent)); return entity; }
EntityPtr WidgetFactory::createPanel(float x, float y, float width, float height) { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(x, y, width, height)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); DrawablePtr textureDrawable(GCC_NEW PanelDrawable(width, height, *mPanelConfig.get())); graphicsSystem->registerDrawable(entity->id, textureDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable)); entity->addComponent(physicsComponent); entity->addComponent(drawableComponent); return entity; }
EntityPtr WidgetFactory::createButton(std::function<void()> callback, float x, float y, float width, float height) { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(x, y, width, height)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); DrawablePtr textureDrawable(GCC_NEW ButtonDrawable(width, height, *mButtonConfig.get())); graphicsSystem->registerDrawable(entity->id, textureDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable)); ButtonComponentPtr buttonComponent(GCC_NEW ButtonComponent(entity->id)); buttonComponent->setCallback(callback); entity->addComponent(physicsComponent); entity->addComponent(drawableComponent); entity->addComponent(buttonComponent); return entity; }