Example #1
0
Controller::Controller(Model* model, View* view) : m_model(model), m_view(view) {

    validateMouseAlgorithm(P()->mouseAlgorithm());
    m_mouseAlgorithm = MouseAlgorithms::getMouseAlgorithm(P()->mouseAlgorithm());
    validateMouseInterfaceType(P()->mouseAlgorithm(), m_mouseAlgorithm->interfaceType());
    validateMouseInitialDirection(P()->mouseAlgorithm(), m_mouseAlgorithm->initialDirection());
    validateMouseWheelSpeedFraction(P()->mouseAlgorithm(), m_mouseAlgorithm->wheelSpeedFraction());

    initAndValidateMouse(
        P()->mouseAlgorithm(),
        m_mouseAlgorithm->mouseFile(),
        STRING_TO_INTERFACE_TYPE.at(m_mouseAlgorithm->interfaceType()),
        getInitialDirection(m_mouseAlgorithm->initialDirection()),
        m_model->getMouse()
    );

    // TODO: MACK - validate here (non-negative)
    m_view->initTileGraphicText(
        std::make_pair(
            m_mouseAlgorithm->tileTextNumberOfRows(),
            m_mouseAlgorithm->tileTextNumberOfCols()));

    // This may seem sloppy, but it's best to assign the values directly by
    // name so that we don't accidentally mix them up (which is easy to do)
    MouseInterfaceOptions options;
    options.allowOmniscience = m_mouseAlgorithm->allowOmniscience();
    options.declareWallOnRead = m_mouseAlgorithm->declareWallOnRead();
    options.declareBothWallHalves = m_mouseAlgorithm->declareBothWallHalves();
    options.tileTextNumberOfRows = m_mouseAlgorithm->tileTextNumberOfRows();
    options.tileTextNumberOfCols = m_mouseAlgorithm->tileTextNumberOfCols();
    options.setTileTextWhenDistanceDeclared =
        m_mouseAlgorithm->setTileTextWhenDistanceDeclared();
    options.setTileBaseColorWhenDistanceDeclaredCorrectly =
        m_mouseAlgorithm->setTileBaseColorWhenDistanceDeclaredCorrectly();
    options.useTileEdgeMovements = m_mouseAlgorithm->useTileEdgeMovements();
    options.wheelSpeedFraction = m_mouseAlgorithm->wheelSpeedFraction();
    options.interfaceType =
        STRING_TO_INTERFACE_TYPE.at(m_mouseAlgorithm->interfaceType());
    
    // Initialize the mouse interface
    m_mouseInterface = new MouseInterface(
        m_model->getMaze(),
        m_model->getMouse(),
        m_view->getMazeGraphic(),
        m_view->getAllowableTileTextCharacters(),
        options
    );

    // Separate out the World options here
    m_world = new World(
        m_model->getMaze(), 
        m_model->getMouse(), m_view->getMazeGraphic(),
        {
            m_mouseAlgorithm->automaticallyClearFog(),
            STRING_TO_INTERFACE_TYPE.at(m_mouseAlgorithm->interfaceType())
        }
    );
}
		void Emitter::initParticle(Particle& p, float t)
		{
			init_physics_parameters(p.initial);
			init_physics_parameters(p.current);
			p.initial.position = current.position;
			p.initial.color = getColor();
			p.initial.time_to_live = time_to_live_->getValue(technique_->getParticleSystem()->getElapsedTime());
			p.initial.velocity = velocity_->getValue(technique_->getParticleSystem()->getElapsedTime());
			p.initial.mass = mass_->getValue(technique_->getParticleSystem()->getElapsedTime());
			p.initial.dimensions = technique_->getDefaultDimensions();
			if(orientation_range_) {
				p.initial.orientation = glm::slerp(orientation_range_->first, orientation_range_->second, get_random_float(0.0f,1.0f));
			} else {
				p.initial.orientation = current.orientation;
			}
			p.initial.direction = getInitialDirection();
			p.emitted_by = this;
		}