Esempio n. 1
0
int Checkpoint::estimatedMovingTimeToTargetCheckpoint( const Checkpoint *targetCheckpoint ) const
{
    LOG_INFO( "Start %s", __FUNCTION__ );

    int distance = sqrt( pow( posX() - targetCheckpoint->posX(), 2) + pow( posY() - targetCheckpoint->posY(), 2) );
    int time = 10 * distance;

    LOG_INFO( "Distance between: (%f,%f) and (%f,%f) = %i", posX(), posY(), targetCheckpoint->posX(), targetCheckpoint->posY(), distance );
    LOG_INFO( "Estimated moving time: %i", time );

    return time;
}
Esempio n. 2
0
 int manhattan()                 // sum of Manhattan distances between blocks and goal
 {
     int result = 0;
     for (int i = 0; i < N * N; i++)
     {
         if (position[i] == 0) continue;
         int finalPos = finalPosition(position[i]);
         int currentPos = i;
         result = result + abs(posX(finalPos) - posX(currentPos));
         result = result + abs(posY(finalPos) - posY(currentPos));
     }
     return result;
 }
Esempio n. 3
0
 std::vector<Board *> neighbors()
 {
     std::vector<Board *> result;
     int zeroX = posX(zeroPosition);
     int zeroY = posY(zeroPosition);
     
     if (zeroX == 0)
         result.push_back(changed(zeroPosition+1));
     else if (zeroX == N-1)
         result.push_back(changed(zeroPosition-1));
     else
     {
         result.push_back(changed(zeroPosition-1));
         result.push_back(changed(zeroPosition+1));
     }
     
     if (zeroY == 0)
         result.push_back(changed(zeroPosition+N));
     else if (zeroY == N - 1)
         result.push_back(changed(zeroPosition-N));
     else
     {
         result.push_back(changed(zeroPosition+N));
         result.push_back(changed(zeroPosition-N));
     }
     
     return result;
     
 }
/**
 * @brief Write the neutral mob data back to a file.
 */
void NeutralMob::writeToFile( QFile &unitFile )
{
    QTextStream unitStream(&unitFile);

    if ( (dirty() > 0) || (rawData() == Q_NULLPTR) ) { // dirty = 0 means not dirty, dirty < 0 means uneditable, dirty > 0 means we can probably edit this entry without issue
        unitStream << type() << "/"
                   << posX() << "/"
                   << posY() << "/"
                   << posZ() << "/"
                   << rotation() << "/";

        // Write all the unknown floats
        for (int i=0; i<4; i++)
        {
            unitStream << unknown_float(i) << "/";
        }

        // Write all the options
        for (int i=0; i<3; i++)
        {
            unitStream << QString(option(i)?"True":"False") << "/";
        }

    } else {
        unitStream << rawData();
    }

    unitStream << endl;
    unitStream.flush();
}
Esempio n. 5
0
Cube::Cube(const position_type &where, std::shared_ptr<Texture> texture )
		: Object3D(where) {
	// 8 points, 6 surfaces

	position_type
			    blf(-1.0, -1.0, 1.0)    // front rectangle
	,       brf(1.0, -1.0, 1.0)
	,       trf(1.0, 1.0, 1.0)
	,       tlf(-1.0, 1.0, 1.0)
	,       blr(-1.0, -1.0, -1.0)    // rear rectangle
	,       brr(1.0, -1.0, -1.0)
	,       trr(1.0, 1.0, -1.0)
	,       tlr(-1.0, 1.0, -1.0);

  position_type
    negZ(0.0, 0.0, -1.0)
    , posZ(0.0, 0.0, 1.0)
    , negY(0.0, -1.0, 0.0)
    , posY(0.0, 1.0, 0.0)
    , negX(-1.0, 0.0, 0.0)
    , posX(1.0, 0.0, 0.0);

	// if changing the order, make sure to change accessors so they grab the correct object
  this->add_child(new Rectangle(POSITION_INHERIT, { blf, blr, brr, brf }, { negY, negY, negY, negY }, texture));    // bottom negY
  this->add_child(new Rectangle(POSITION_INHERIT, { trr, brr, blr, tlr }, { negZ, negZ, negZ, negZ }, texture));    // rear   negZ
  this->add_child(new Rectangle(POSITION_INHERIT, { trf, brf, brr, trr }, { posX, posX, posX, posX }, texture));    // right  posX
  this->add_child(new Rectangle(POSITION_INHERIT, { tlr, blr, blf, tlf }, { negX, negX, negX, negX }, texture));    // left   negX
  this->add_child(new Rectangle(POSITION_INHERIT, { tlf, blf, brf, trf }, { posZ, posZ, posZ, posZ }, texture));    // front  posZ
  this->add_child(new Rectangle(POSITION_INHERIT, { tlr, tlf, trf, trr }, { posY, posY, posY, posY }, texture));    // top    posY

}    // Cube
void NeutralMob::print()
{
    qDebug() << type()
             << "x" << posX()
             << "y" << posY()
             << "z" << posZ()
             << "rotation" << rotation();
}
Esempio n. 7
0
void Point2D::draw() {
	glTranslatef(posX(), posY(), posZ());
	glColor3fv(color);
	glBegin(GL_POINTS);
		glVertex2f(0.5f, 0.5f);
	glEnd();
	glLoadIdentity();
}
Esempio n. 8
0
std::vector<Point> WorldGenerator::getAllPoints(World* world)
{
    std::vector<Point> v;
    auto dim = world->getDimensions();
    for(unsigned x = 0; x < (unsigned)dim.posX(); x++)
        for(unsigned y = 0; y < (unsigned)dim.posY(); y++)
            v.emplace_back(Point(x, y));
    return v;
}
Esempio n. 9
0
void Square::draw() {
	glTranslatef(posX(), posY(), 0);
	glColor3fv(color);
	glBegin(GL_QUADS);
		glVertex3f(0, 0, 0);
		glVertex3f(dim, 0, 0);
		glVertex3f(dim, dim, 0);
		glVertex3f(0, dim, 0);
	glEnd();
	//glLoadIdentity();
}
Esempio n. 10
0
void LVL_Block::render(double camX, double camY)
{
    //Don't draw hidden block before it will be hitten
    if(isHidden) return;
    if(destroyed) return;

    PGE_RectF blockG;
    blockG.setRect(posX()-camX+offset_x,
                         posY()-camY+offset_y,
                         _width,
                         _height);


    AniPos x(0,1);

    if(animated) //Get current animated frame
        x = ConfigManager::Animator_Blocks[animator_ID].image();

    glEnable(GL_TEXTURE_2D);
    glColor4f( 1.f, 1.f, 1.f, 1.f);

    glBindTexture( GL_TEXTURE_2D, texId );
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    if(sizable)
    {
        int w = _width;
        int h = _height;

        int x,y, x2, y2, i, j;
        int hc, wc;

        x = qRound(qreal(texture.w)/3);  // Width of one piece
        y = qRound(qreal(texture.h)/3); // Height of one piece

        //Double size
        x2 = x<<1;
        y2 = y<<1;

        int pWidth = texture.w-x2;//Width of center piece
        int pHeight = texture.h-y2;//Height of center piece

        int fLnt = 0; // Free Lenght
        int fWdt = 0; // Free Width

        int dX=0; //Draw Offset. This need for crop junk on small sizes
        int dY=0;

        if(w < x2) dX = (x2-w)>>1; else dX=0;
        if(h < y2) dY = (y2-h)>>1; else dY=0;
Esempio n. 11
0
LVL_Npc *LVL_Player::lua_spawnNPC(unsigned long npcID, int sp_type, int sp_dir, bool reSpawnable)
{
    LevelNPC def = FileFormats::CreateLvlNpc();
    def.id = npcID;
    def.x = static_cast<long>(round(posX()));
    def.y = static_cast<long>(round(posY()));
    def.direct = m_direction;
    def.generator = false;
    def.layer = "Spawned NPCs";
    def.attach_layer = "";
    def.event_activate = "";
    def.event_die = "";
    def.event_talk = "";
    def.event_emptylayer = "";
    return m_scene->spawnNPC(def,
                             static_cast<LevelScene::NpcSpawnType>(sp_type),
                             static_cast<LevelScene::NpcSpawnDirection>(sp_dir), reSpawnable);
}
Esempio n. 12
0
LVL_Npc *LVL_Npc::lua_spawnNPC(int npcID, int sp_type, int sp_dir, bool reSpawnable)
{
    LevelNPC def = data;
    def.id = static_cast<unsigned long>(npcID);
    def.x = Maths::lRound(posX());
    def.y = Maths::lRound(posY());
    def.direct = _direction;
    def.generator = false;
    def.layer = "Spawned NPCs";
    def.attach_layer = "";
    def.event_activate = "";
    def.event_die = "";
    def.event_talk = "";
    def.event_emptylayer = "";
    return m_scene->spawnNPC(def,
                            (LevelScene::NpcSpawnType)sp_type,
                            (LevelScene::NpcSpawnDirection)sp_dir, reSpawnable);
}
Esempio n. 13
0
void LVL_Block::transformTo(unsigned long id, int type)
{
    if(id == 0) return;

    if(type == 2) //Other block
    {
        transformTask_block t;
        t.block = this;
        t.id = id;
        t.type = type;
        m_scene->block_transforms.push_back(t);
    }

    if(type == 1) //Other NPC
    {
        LevelNPC def = FileFormats::CreateLvlNpc();
        def.id = id;
        def.x = long(round(posX()));
        def.y = long(round(posY()));
        def.direct = 0;
        def.generator = false;
        def.layer = data.layer;
        def.attach_layer = "";
        def.event_activate = "";
        def.event_die = "";
        def.event_talk = "";
        def.event_emptylayer = "";
        LVL_Npc *npc = m_scene->spawnNPC(def,
                                        LevelScene::GENERATOR_APPEAR,
                                        LevelScene::SPAWN_UP, true);

        if(npc)
        {
            npc->transformedFromBlock = this;
            npc->transformedFromBlockID = data.id;
            npc->setCenterPos(m_momentum.centerX(), m_momentum.centerY());
            npc->m_momentum.saveOld();
            npc->data.x = long(round(npc->m_momentum.x));
            npc->data.y = long(round(npc->m_momentum.y));
        }

        destroy(false);
    }
}
Esempio n. 14
0
void LVL_Block::render(double camX, double camY)
{
    //Don't draw hidden block before it will be hitten
    if(m_isHidden) return;

    if(m_destroyed) return;

    PGE_RectF blockG;
    blockG.setRect(posX() - camX + offset_x,
                   posY() - camY + offset_y,
                   m_width_registered,
                   m_height_registered);
    AniPos x(0, 1);

    if(animated) //Get current animated frame
        x = ConfigManager::Animator_Blocks[int(animator_ID)].image();

    GlRenderer::BindTexture(&texture);
    GlRenderer::setTextureColor(1.0f, 1.0f, 1.0f, 1.0f);

    if(sizable)
    {
        int w = int(round(m_width_registered));
        int h = int(round(m_height_registered));
        int x, y, x2, y2, i, j;
        int hc, wc;
        x = qRound(qreal(texture.w) / 3); // Width of one piece
        y = qRound(qreal(texture.h) / 3); // Height of one piece
        //Double size
        x2 = x << 1;
        y2 = y << 1;
        int pWidth = texture.w - x2; //Width of center piece
        int pHeight = texture.h - y2; //Height of center piece
        int fLnt = 0; // Free Lenght
        int fWdt = 0; // Free Width
        int dX = 0; //Draw Offset. This need for crop junk on small sizes
        int dY = 0;

        if(w < x2) dX = (x2 - w) >> 1;
        else dX = 0;

        if(h < y2) dY = (y2 - h) >> 1;
        else dY = 0;
void Renderer::renderParticlesToCanvas(const MarkerParticleSet& particle_set)
{
	MyFloat scale_x = _canvas.width() / (_x_max - _x_min);
	MyFloat scale_y = _canvas.height() / (_y_max - _y_min);

	MyFloat translate_x = 0.5 * (_x_min * _canvas.width());
	MyFloat translate_y = 0.5 * (_y_min * _canvas.height());

	_canvas.setLineColor(Color(0,0.5,0.8));
	_canvas.setFillColor(Color(0,0.5,0.8));

	for (auto it = particle_set.begin(); it != particle_set.end(); it++)
	{
		// Position in pixel coordinates
		int pos_x = - translate_x + scale_x * it->posX();
		int pos_y = - translate_y + scale_y * it->posY();
		
		_canvas.drawPoint(pos_x, pos_y, 3);
	}
}
Esempio n. 16
0
void Afficher(SDL_Surface* screen, SDL_Surface* tileset, s_map *map)
{
  int i;
  SDL_Rect Rect_dest;
  SDL_Rect Rect_source;

  i = 0;
  Rect_source.w = LARGEUR_TILE;
  Rect_source.h = HAUTEUR_TILE;
  while (map->map[i])
    {
      Rect_dest.x = posX(map, i) * LARGEUR_TILE;
      Rect_dest.y = posY(map, i) * HAUTEUR_TILE;
      Rect_source.x = (map->map[i] - '0') * LARGEUR_TILE;
      Rect_source.y = 0;
      SDL_BlitSurface(tileset, &Rect_source, screen, &Rect_dest);
      i++;
    }
  SDL_Flip(screen);
}
Esempio n. 17
0
void LVL_Npc::updateGenerator(float tickTime)
{
    if(!isGenerator) return;
    generatorTimeLeft-=tickTime;
    if(generatorTimeLeft<=0)
    {
        generatorTimeLeft += data.generator_period*100;
        if(!contacted_npc.isEmpty()) return;
        if(!contacted_players.isEmpty()) return;

        LevelNPC def = data;
        def.x=round(posX());
        def.y=round(posY());
        def.generator=false;
        def.layer="Spawned NPCs";
        LvlSceneP::s->spawnNPC(def,
                               (LevelScene::NpcSpawnType)generatorType,
                               (LevelScene::NpcSpawnDirection)generatorDirection, false);
    }

}
Esempio n. 18
0
Cube::Cube( const position_type &where, Texture::pointer_type texture )
	: Object( where, texture )
{
	glm::vec3
		blf( -1.0, -1.0, 1.0 )    // front rectangle
		, brf( 1.0, -1.0, 1.0 )
		, trf( 1.0, 1.0, 1.0 )
		, tlf( -1.0, 1.0, 1.0 )
		, blr( -1.0, -1.0, -1.0 )    // rear rectangle
		, brr( 1.0, -1.0, -1.0 )
		, trr( 1.0, 1.0, -1.0 )
		, tlr( -1.0, 1.0, -1.0 )
		;

	glm::vec3
		negZ( 0.0, 0.0, -1.0 )
		, posZ( 0.0, 0.0, 1.0 )
		, negY( 0.0, -1.0, 0.0 )
		, posY( 0.0, 1.0, 0.0 )
		, negX( -1.0, 0.0, 0.0 )
		, posX( 1.0, 0.0, 0.0 )
		;

	// gl_triangle strip
	// for ccw winding:  top left, bottom left, top right, bottom right

	auto add_components = [ &]( const std::vector<Component::pointer_type>& vec )
	{
		for ( auto& v : vec )
			this->components.emplace_back( v );
	};

	add_components( Triangle::from_quad( std::vector<glm::vec3>( { blf, blr, brf, brr } ), negY, texture ) );	// bottom
	add_components( Triangle::from_quad( std::vector<glm::vec3>( { trr, brr, tlr, blr } ), negZ, texture ) );	// rear
	add_components( Triangle::from_quad( std::vector<glm::vec3>( { trf, brf, trr, brr } ), posX, texture ) );    // right  posX
	add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlr, blr, tlf, blf } ), negX, texture ) );    // left   negX
	add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlf, blf, trf, brf } ), posZ, texture ) );    // front  posZ
	add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlr, tlf, trr, trf } ), posY, texture ) );    // top    posY
}
QVariant NeutralMob::data(int role) const
{
    switch(role) {
    case IdRole:
        return (unsigned int)id();
    case FilterStringRole:
        return filterString();

    case TypeRole:
        return type();
    case PosXRole:
        return posX();
    case PosYRole:
        return posY();
    case PosZRole:
        return posZ();
    case RotationRole:
        return rotation();
    default:
        return QVariant();
    }
}
Esempio n. 20
0
void LVL_Npc::updateGenerator(double tickTime)
{
    if(!m_isGenerator) return;

    generatorTimeLeft -= tickTime;

    if(generatorTimeLeft <= 0)
    {
        generatorTimeLeft += data.generator_period * 100;
        if(!contacted_npc.empty())
            return;
        if(!contacted_players.empty())
            return;
        LevelNPC def = data;
        def.x = Maths::lRound(posX());
        def.y = Maths::lRound(posY());
        def.generator = false;
        def.layer = "Spawned NPCs";
        m_scene->spawnNPC(def,
                         static_cast<LevelScene::NpcSpawnType>(generatorType),
                         static_cast<LevelScene::NpcSpawnDirection>(generatorDirection), false);
    }
}
Esempio n. 21
0
void LVL_Player::update(float ticks)
{
    if(isLocked) return;
    if(!_isInited) return;
    if(!camera) return;
    LVL_Section* section = sct();
    if(!section) return;

    event_queue.processEvents(ticks);

    if((isWarping) || (!isAlive))
    {
        animator.tickAnimation(ticks);
        updateCamera();
        return;
    }

    _onGround = !foot_contacts_map.isEmpty();
    on_slippery_surface = !foot_sl_contacts_map.isEmpty();
    bool climbableUp  = !climbable_map.isEmpty();
    bool climbableDown= climbableUp && !_onGround;
    climbing = (climbableUp && climbing && !_onGround && (posRect.center().y()>=(climbableHeight-physics_cur.velocity_climb_y_up)) );
    if(_onGround)
    {
        phys_setup.decelerate_x =
                (fabs(speedX())<=physics_cur.MaxSpeed_walk)?
                (on_slippery_surface?physics_cur.decelerate_stop/physics_cur.slippery_c : physics_cur.decelerate_stop):
                (on_slippery_surface?physics_cur.decelerate_run/physics_cur.slippery_c : physics_cur.decelerate_run);

        if(physics_cur.strict_max_speed_on_ground)
        {
            if((speedX()>0)&&(speedX()>phys_setup.max_vel_x))
                setSpeedX(phys_setup.max_vel_x);
            else
            if((speedX()<0)&&(speedX()<phys_setup.min_vel_x))
                setSpeedX(phys_setup.min_vel_x);
        }
    }
    else
        phys_setup.decelerate_x = physics_cur.decelerate_air;

    if(doKill)
    {
        doKill=false;
        isAlive = false;
        setPaused(true);
        LvlSceneP::s->checkPlayers();
        return;
    }

    if(climbing)
    {
        PGE_Phys_Object* climbableItem = static_cast<PGE_Phys_Object*>((void*)(intptr_t)climbable_map[climbable_map.keys().first()]);
        if(climbableItem)
        {
            _velocityX_add=climbableItem->speedX();
            _velocityY_add=climbableItem->speedY();
        } else
        {
            _velocityX_add=0.0f;
            _velocityY_add=0.0f;
        }

        if(gscale_Backup != 1)
        {
            setGravityScale(0);
            gscale_Backup = 1;
        }
    }
    else
    {
        if(gscale_Backup != 0.f)
        {
            setGravityScale(physics_cur.gravity_scale);
            gscale_Backup = 0.f;
        }
    }

    if(climbing)
    {
        setSpeed(0,0);
    }

    if(environments_map.isEmpty())
    {
        if(last_environment!=section->getPhysicalEnvironment() )
        {
            environment = section->getPhysicalEnvironment();
        }
    }
    else
    {
        int newEnv = section->getPhysicalEnvironment();

        foreach(int x, environments_map)
        {
            newEnv = x;
        }

        if(last_environment != newEnv)
        {
            qDebug()<<"Enter to environment" << newEnv;
            environment = newEnv;
        }
    }

    refreshEnvironmentState();

    if(_onGround)
    {
        if(!floating_isworks)
        {
            floating_timer=floating_maxtime;
        }
    }

    //Running key
    if(keys.run)
    {
        if(!_isRunning)
        {
            phys_setup.max_vel_x = physics_cur.MaxSpeed_run;
            phys_setup.min_vel_x = -physics_cur.MaxSpeed_run;
            _isRunning=true;
        }
    }
    else
    {
        if(_isRunning)
        {
            phys_setup.max_vel_x = physics_cur.MaxSpeed_walk;
            phys_setup.min_vel_x = -physics_cur.MaxSpeed_walk;
            _isRunning=false;
        }
    }
    if((physics_cur.ground_c_max!=1.0f))
    {
        phys_setup.max_vel_x = fabs(_isRunning ?
                    physics_cur.MaxSpeed_run :
                    physics_cur.MaxSpeed_walk) *(_onGround?physics_cur.ground_c_max:1.0f);
        phys_setup.min_vel_x = -fabs(_isRunning ?
                    physics_cur.MaxSpeed_run :
                    physics_cur.MaxSpeed_walk) *(_onGround?physics_cur.ground_c_max:1.0f);
    }


    if(keys.alt_run)
    {
        if(attack_enabled && !attack_pressed && !climbing)
        {
            attack_pressed=true;

            if(keys.up)
                attack(Attack_Up);
            else
            if(keys.down)
                attack(Attack_Down);
            else
            {
                attack(Attack_Forward);
                PGE_Audio::playSoundByRole(obj_sound_role::PlayerTail);
                animator.playOnce(MatrixAnimator::RacoonTail, _direction, 75, true, true, 1);
            }
        }
    }
    else
    {
        if(attack_pressed) attack_pressed=false;
    }



    //if
    if(!keys.up && !keys.down && !keys.left && !keys.right)
    {
        if(wasEntered)
        {
            wasEntered = false;
            wasEnteredTimeout=0;
        }
    }

    //Reset state
    if(wasEntered)
    {
        wasEnteredTimeout-=ticks;
        if(wasEnteredTimeout<0)
        {
            wasEnteredTimeout=0;
            wasEntered=false;
        }
    }

    if(keys.up)
    {
        if(climbableUp&&(jumpTime<=0))
        {
            setDuck(false);
            climbing=true;
            floating_isworks=false;//!< Reset floating on climbing start
        }

        if(climbing)
        {
            if(posRect.center().y() >= climbableHeight)
                setSpeedY(-physics_cur.velocity_climb_y_up);
        }
    }

    if(keys.down)
    {
        if( climbableDown && (jumpTime<=0) )
        {
            setDuck(false);
            climbing=true;
            floating_isworks=false;//!< Reset floating on climbing start
        }
        else
        {
            if((duck_allow & !ducking)&&( (animator.curAnimation()!=MatrixAnimator::RacoonTail) ) )
            {
                setDuck(true);
            }
        }

        if(climbing)
        {
            setSpeedY(physics_cur.velocity_climb_y_down);
        }
    }
    else
    {
        if(ducking)
            setDuck(false);
    }

    if( (!keys.left) || (!keys.right) )
    {
        bool turning=(((speedX()>0)&&(_direction<0))||((speedX()<0)&&(_direction>0)));

        float force = turning?
                    physics_cur.decelerate_turn :
                    (fabs(speedX())>physics_cur.MaxSpeed_walk)?physics_cur.run_force : physics_cur.walk_force;

        if(on_slippery_surface) force=force/physics_cur.slippery_c;
        else if((_onGround)&&(physics_cur.ground_c!=1.0f)) force=force*physics_cur.ground_c;

        if(keys.left) _direction=-1;
        if(keys.right) _direction=1;

        if(!ducking || !_onGround)
        {
            //If left key is pressed
            if(keys.right && collided_right.isEmpty())
            {
                if(climbing)
                    setSpeedX(physics_cur.velocity_climb_x);
                else
                    applyAccel(force, 0);
            }
            //If right key is pressed
            if(keys.left && collided_left.isEmpty())
            {
                if(climbing)
                    setSpeedX(-physics_cur.velocity_climb_x);
                else
                    applyAccel(-force, 0);
            }
        }
    }

    if( keys.alt_jump )
    {
        //Temporary it is ability to fly up!
        if(!bumpDown && !bumpUp) {
            setSpeedY(-physics_cur.velocity_jump);
        }
    }

    if( keys.jump )
    {
        if(!JumpPressed)
        {
            if(environment!=LVL_PhysEnv::Env_Water)
                { if(climbing || _onGround || (environment==LVL_PhysEnv::Env_Quicksand))
                    PGE_Audio::playSoundByRole(obj_sound_role::PlayerJump); }
            else
                PGE_Audio::playSoundByRole(obj_sound_role::PlayerWaterSwim);
        }

        if((environment==LVL_PhysEnv::Env_Water)||(environment==LVL_PhysEnv::Env_Quicksand))
        {
            if(!JumpPressed)
            {
                if(environment==LVL_PhysEnv::Env_Water)
                {
                    if(!ducking) animator.playOnce(MatrixAnimator::SwimUp, _direction, 75);
                }
                else
                if(environment==LVL_PhysEnv::Env_Quicksand)
                {
                    if(!ducking) animator.playOnce(MatrixAnimator::JumpFloat, _direction, 64);
                }

                JumpPressed=true;
                jumpTime = physics_cur.jump_time;
                jumpVelocity=physics_cur.velocity_jump;
                floating_timer = floating_maxtime;
                setSpeedY(speedY()-jumpVelocity);
            }
        }
        else
        if(!JumpPressed)
        {
            JumpPressed=true;
            if(_onGround || climbing)
            {
                climbing=false;
                jumpTime=physics_cur.jump_time;
                jumpVelocity=physics_cur.velocity_jump;
                floating_timer = floating_maxtime;
                setSpeedY(-jumpVelocity-fabs(speedX()/physics_cur.velocity_jump_c));
            }
            else
            if((floating_allow)&&(floating_timer>0))
            {
                floating_isworks=true;

                //if true - do floating with sin, if false - do with cos.
                floating_start_type=(speedY()<0);

                setSpeedY(0);
                setGravityScale(0);
            }
        }
        else
        {
            if(jumpTime>0)
            {
                jumpTime -= ticks;
                setSpeedY(-jumpVelocity-fabs(speedX()/physics_cur.velocity_jump_c));
            }

            if(floating_isworks)
            {
                floating_timer -= ticks;
                if(floating_start_type)
                    setSpeedY( state_cur.floating_amplitude*(-cos(floating_timer/80.0)) );
                else
                    setSpeedY( state_cur.floating_amplitude*(cos(floating_timer/80.0)) );
                if(floating_timer<=0)
                {
                    floating_timer=0;
                    floating_isworks=false;
                    setGravityScale(climbing?0:physics_cur.gravity_scale);
                }
            }
        }
    }
    else
    {
        jumpTime=0;
        if(JumpPressed)
        {
            JumpPressed=false;
            if(floating_allow)
            {
                if(floating_isworks)
                {
                    floating_timer=0;
                    floating_isworks=false;
                    setGravityScale(climbing?0:physics_cur.gravity_scale);
                }
            }
        }
    }

    refreshAnimation();
    animator.tickAnimation(ticks);

    PGE_RectF sBox = section->sectionLimitBox();

    //Return player to start position on fall down
    if( posY() > sBox.bottom()+_height )
    {
        kill(DEAD_fall);
    }

    if(bumpDown)
    {
        bumpDown=false;
        jumpTime=0;
        setSpeedY(bumpVelocity);
    }
    else
    if(bumpUp)
    {
        bumpUp=false;
        if(keys.jump)
        {
            jumpTime=bumpJumpTime;
            jumpVelocity=bumpJumpVelocity;
        }
        setSpeedY( (keys.jump ?
                        (-fabs(bumpJumpVelocity)-fabs(speedX()/physics_cur.velocity_jump_c)):
                         -fabs(bumpJumpVelocity)) );
    }


    //Connection of section opposite sides
    if(isExiting) // Allow walk offscreen if exiting
    {
        if((posX() < sBox.left()-_width-1 )||(posX() > sBox.right() + 1 ))
        {
            setGravityScale(0.0);//Prevent falling [we anyway exited from this level, isn't it?]
            setSpeedY(0.0);
        }
        if(keys.left||keys.right)
        {
            if((environment==LVL_PhysEnv::Env_Water)||(environment==LVL_PhysEnv::Env_Quicksand))
            {
                keys.run=true;
                if(_exiting_swimTimer<0 && !keys.jump)
                    keys.jump=true;
                else
                if(_exiting_swimTimer<0 && keys.jump)
                {
                    keys.jump=false; _exiting_swimTimer=(environment==LVL_PhysEnv::Env_Quicksand)? 1 : 500;
                }
                _exiting_swimTimer-= ticks;
            } else keys.run=false;
        }
    }
    else
    if(section->isWarp())
    {
        if(posX() < sBox.left()-_width-1 )
            setPosX( sBox.right()+1 );
        else
        if(posX() > sBox.right() + 1 )
            setPosX( sBox.left()-_width-1 );
    }
    else
    {

        if(section->ExitOffscreen())
        {
            if(section->RightOnly())
            {
                if( posX() < sBox.left())
                {
                    setPosX( sBox.left() );
                    setSpeedX(0.0);
                }
            }

            if((posX() < sBox.left()-_width-1 ) || (posX() > sBox.right() + 1 ))
            {
                setLocked(true);
                _no_render=true;
                LvlSceneP::s->setExiting(1000, LvlExit::EXIT_OffScreen);
                return;
            }
        }
        else
        {
            //Prevent moving of player away from screen
            if( posX() < sBox.left())
            {
                setPosX(sBox.left());
                setSpeedX(0.0);
            }
            else
            if( posX()+_width > sBox.right())
            {
                setPosX(sBox.right()-_width);
                setSpeedX(0.0);
            }
        }
    }

    if(_stucked)
    {
        posRect.setX(posRect.x()-_direction*2);
        applyAccel(0, 0);
    }

    processWarpChecking();

    if(_doSafeSwitchCharacter) setCharacter(characterID, stateID);

    try {
        lua_onLoop();
    } catch (luabind::error& e) {
        LvlSceneP::s->getLuaEngine()->postLateShutdownError(e);
    }
    updateCamera();
}
Esempio n. 22
0
/**
 * @brief Write the Human data back to a file.
 */
void Human::writeToFile( QFile &unitFile )
{
    QTextStream unitStream(&unitFile);

    unitStream << profession() << "/"
               << QString("%1").arg(posX(),0,'g',8) << "/"
               << QString("%1").arg(posY(),0,'g',8) << "/"
               << QString("%1").arg(posZ(),0,'g',8) << "/"
               << name() << "/";
    unitStream.flush();

    unitFile.write(Utils::toBinary(archerLevel()));
    unitFile.write(Utils::toBinary(blacksmithLevel()));
    unitFile.write(Utils::toBinary(builderLevel()));
    unitFile.write(Utils::toBinary(carpenterLevel()).constData());
    unitFile.write(Utils::toBinary(engineerLevel()).constData());
    unitFile.write(Utils::toBinary(farmerLevel()).constData());
    unitFile.write(Utils::toBinary(fishermanLevel()).constData());
    unitFile.write(Utils::toBinary(foragerLevel()).constData());
    unitFile.write(Utils::toBinary(infantryLevel()).constData());
    unitFile.write(Utils::toBinary(minerLevel()).constData());
    unitFile.write(Utils::toBinary(stoneMasonLevel()).constData());
    unitFile.write(Utils::toBinary(woodChopperLevel()).constData());
    unitFile.write(Utils::toBinary(tailorLevel()).constData());
    unitFile.write(Utils::toBinary(traderLevel()).constData());
    unitFile.write(Utils::toBinary(herderLevel()).constData());
    unitFile.write(Utils::toBinary(adventurerLevel()).constData());
    unitFile.write(Utils::toBinary(unknown1Level()).constData());
    unitFile.write(Utils::toBinary(unknown2Level()).constData());
    unitFile.write(Utils::toBinary(unknown3Level()).constData());
    unitFile.write(Utils::toBinary(unknown4Level()).constData());
    unitStream << "/"; unitStream.flush();

    unitFile.write(Utils::toBinary(experience()).constData());
    unitStream << "/"; unitStream.flush();

    unitStream << QString(autoChop()?"True":"False") << "/"
               << QString(gatherBerries()?"True":"False") << "/"
               << QString(huntChicken()?"True":"False") << "/"
               << QString(huntBoar()?"True":"False") << "/"
               << QString(showBowRange()?"True":"False") << "/";

    unitStream << QString(trainNearTarget()?"True":"False") << "/";

    unitStream << QString("%1").arg(rotation(),0,'g',8) << "/";
    unitStream.flush();

    unitFile.write(Utils::toBinary(equipHand()).constData());
    unitStream << "/"; unitStream.flush();
    unitFile.write(Utils::toBinary(equipOffhand()).constData());
    unitStream << "/"; unitStream.flush();
    unitFile.write(Utils::toBinary(equipHead()).constData());
    unitStream << "/"; unitStream.flush();
    unitFile.write(Utils::toBinary(equipBody()).constData());
    unitStream << "/"; unitStream.flush();
    unitFile.write(Utils::toBinary(equipFeet()).constData());
    unitStream << "/"; unitStream.flush();
    unitFile.write(Utils::toBinary(health()).constData());
    unitStream << "/"; unitStream.flush();

    // Dump some of the options in the file.
    for (unsigned int i = 0; i<52; i++) {
        unitStream << QString(option(i)?"True":"False") << "/";
    }
    unitStream << timeToEat() << "/"
               << morale() << "/"
               << fatigue() << "/"
               << hunger() << "/";

    // Dump more options in the file.
    for (unsigned int i = 52; i<52+12; i++) {
        unitStream << QString(option(i)?"True":"False") << "/";
    }

    // Inventory Preferences
    for (int i = 0; i<inventoryPreferences()->length(); i++) {
        unitStream << inventoryPreferences()->at(i) << "/";
    }

    // Inventory Items
    unitStream << inventoryItems()->length() << "/";
    for (int i = 0; i<inventoryItems()->length(); i++) {
        unitStream << inventoryItems()->at(i) << "/";
    }

    // Spare Inventory
    unitStream << spareInventory()->length() << "/";
    for (int i = 0; i<spareInventory()->length(); i++) {
        unitStream << spareInventory()->at(i) << "/";
    }

    // Patrol
    unitStream << patrolSetpoints()->length() << "/";
    for (int i = 0; i<patrolSetpoints()->length(); i++) {
        unitStream << patrolSetpoints()->at(i) << "/";
    }
    unitStream << patrolIndex() << "/";

    unitStream << guardedUnit() << "/";

    // Profession Experience
    for (int i = 0; i<professionEXP()->length(); i++) {
        unitStream << professionEXP()->at(i) << "/";
    }

    unitStream << maxWeight() << "/";

    unitStream << endl;
    unitStream.flush();

}
int main(int argc, char *argv[])
{

#   include "setRootCase.H"
#   include "createTime.H"

    instantList Times = runTime.times();
#   include "checkTimeOptions.H"
    runTime.setTime(Times[startTime],startTime);
#   include "createMesh.H"

    typedef VectorSpace<Vector<scalar>,scalar,4> quad;
    typedef VectorSpace<Vector<scalar>,scalar,6> hex;
    
    //read setDiscreteFieldsDictionary

    IOdictionary setDiscreteFieldsDict
      (
       IOobject
       (
	"setDiscreteFieldsDict",
	runTime.system(),
	mesh,
	IOobject::MUST_READ,
	IOobject::NO_WRITE
	)
       );
    // read pointer lists of each "Fields"
    PtrList<entry> parts=setDiscreteFieldsDict.lookup("Fields");

    forAll(parts,partI) {
      const dictionary &part=parts[partI].dict();
      Info <<part <<endl;

      // "field" ,"type", and "profile" are required in setDiscreteFieldsDict
      word field=part["field"];

      word type=part["type"];

      // "direction", "internal", and "patchNames" are option
      string direction="x";
      if (part.found("direction")) {
	direction=part["direction"];
      }

      bool internal=true;
      if (part.found("internal")) {
	internal=readBool(part["internal"]);
      }
      
      wordList patchNames;      
      if (part.found("patchNames")){
	patchNames=wordList(part.lookup("patchNames"));
      }

      const string &time = runTime.timeName();
      Info <<"time " <<time <<"\n";

      // for scalar field
      if(type=="scalar"){
        Info << "set " <<field <<endl;

        // read profile
	List<quad> profile(part.lookup("profile"));
	scalarField posX(profile.size());
	scalarField posY(profile.size());
	scalarField posZ(profile.size());
	scalarField fX(profile.size());
	forAll(profile,i)
	  {
	    posX[i]=profile[i][0];
	    posY[i]=profile[i][1];
	    posZ[i]=profile[i][2];
	    fX[i]=profile[i][3];
	  }
        // read target field (scalar)
	volScalarField tmpField
	  (
	   IOobject
	   (
	    field,
	    time,
	    mesh,
	    IOobject::MUST_READ,
	    IOobject::AUTO_WRITE
	    ),
	   mesh
	   );
	
	//read cellCenter of targetMesh
	volVectorField center=tmpField.mesh().C();

	//internalField
	if(internal){
          scalarField &Ifield = tmpField.internalField();
          scalarField Icenter(Ifield.size());
          scalarField newIField(Ifield.size());
          if(direction=="x"){
            Icenter = center.internalField().component(vector::X);
            newIField = interpolateXY(Icenter,posX,fX);
          }	
          else if(direction=="y"){
            Icenter = center.internalField().component(vector::Y);
            newIField = interpolateXY(Icenter,posY,fX);
          }	
          else if(direction=="z"){
            Icenter = center.internalField().component(vector::Z);
            newIField  = interpolateXY(Icenter,posZ,fX);
          }	
          Ifield = newIField;
        }
	//patch
	forAll(patchNames,patchNameI)
	  {
	    label patchID=mesh.boundaryMesh().findPatchID(patchNames[patchNameI]);
	    scalarField &Pfield = tmpField.boundaryField()[patchID];
	    scalarField newPField(Pfield.size());
	    scalarField Pcenter(Pfield.size());
	    if(direction=="x"){
	      Pcenter = center.boundaryField()[patchID].component(vector::X);
	      newPField = interpolateXY(Pcenter,posX,fX);
	    }	
	    else if(direction=="y"){
	      Pcenter = center.boundaryField()[patchID].component(vector::Y);
	      newPField = interpolateXY(Pcenter,posY,fX);
	    }	
	    else if(direction=="z"){
	      Pcenter = center.boundaryField()[patchID].component(vector::Z);
	      newPField = interpolateXY(Pcenter,posZ,fX);
	    }	
	    Pfield = newPField;
	  }
void LVL_Npc::render(double camX, double camY)
{
    if(killed) return;
    if(m_isGenerator) return;
    if((!isActivated)&&(!warpSpawing)) return;

    bool doDraw=true;
    AniPos x(0,1);
    if(animated)
    {
        if(is_shared_animation)
            x=ConfigManager::Animator_NPC[int(animator_ID)].image(_direction);
        else
            x=animator.image(_direction);
    }
    double offsetX = offset.x()+lua_offset.x();
    double offsetY = offset.y()+lua_offset.y();

    PGE_RectF tPos; tPos.setLeft(0.0); tPos.setRight(1.0);
    tPos.setTop(x.first); tPos.setBottom(x.second);

    PGE_RectF npc;
    npc.setRect(round(posX()-offsetX)-camX,
                   round(posY()-offsetY)-camY,
                   frameSize.w(),
                   frameSize.h()
                   );
    if(isWarping)
    {
        if(warpSpriteOffset >= 1.0)
            return;
        PGE_RectF  bodyPos = m_momentum.rectF();
                   bodyPos.setPos(round(bodyPos.x()-camX), round(bodyPos.y()-camY));
        PGE_RectF &textPos = npc;
        //     Exit direction: [1] down  [3] up  [4] left  [2] right
        // Entrance direction: [3] down, [1] up, [2] left, [4] right
        switch( warpDirectO )
        {
            case WARP_LEFT://Left entrance, right Exit
                {
                    //Offset at right side, crop left side
                    double cropLeft = 0.0;
                    double offset = (warpResizedBody?double(setup->setup.width) : bodyPos.width())*double(warpSpriteOffset);
                    bodyPos.setRight( bodyPos.right()-offset );
                    textPos.setPos(textPos.x()-offset, textPos.y());
                    if(textPos.left() < bodyPos.left())
                    {
                        cropLeft = fabs(bodyPos.left()-textPos.left());
                        textPos.setLeft(bodyPos.left());
                    }
                    double wOfs = cropLeft/double(warpFrameW);//Relative X offset
                    tPos.setLeft( tPos.left()+wOfs );
                    if( textPos.right() <= bodyPos.left() )
                        doDraw = false;
                }
                break;
            case WARP_TOP://Up entrance, down exit
                {
                    //Offset at bottom side, crop top side
                    double cropTop = 0.0;
                    double offset = (warpResizedBody?double(setup->setup.height) : bodyPos.height())*double(warpSpriteOffset);
                    bodyPos.setBottom( bodyPos.bottom()-offset );
                    textPos.setPos(textPos.x(), textPos.y()-offset);
                    if(textPos.top() < bodyPos.top())
                    {
                        cropTop = fabs(bodyPos.top()-textPos.top());
                        textPos.setTop(bodyPos.top());
                    }
                    double wOfs = ( cropTop/double(warpFrameH) ) * (double(texture.frame_h)/double(texture.h));//Relative X offset
                    tPos.setTop( tPos.top()+wOfs );
                    if( textPos.bottom() <= bodyPos.top() )
                        doDraw = false;
                }
                break;
            case WARP_RIGHT://right emtramce. left exit
                {
                    //Offset at left side, crop right side
                    double cropRight = 0.0;
                    double offset = (warpResizedBody?double(setup->setup.width) : bodyPos.width())*double(warpSpriteOffset);
                    bodyPos.setLeft( bodyPos.left()+offset );
                    textPos.setPos(textPos.x()+(warpResizedBody ? 0.0 : offset), textPos.y());
                    if(textPos.right() > bodyPos.right())
                    {
                        cropRight = fabs(textPos.right()-bodyPos.right());
                        textPos.setRight(bodyPos.right());
                    }
                    double wOfs = cropRight/double(warpFrameW);//Relative X offset
                    tPos.setRight( tPos.right()-wOfs );
                    if( textPos.left() >= bodyPos.right() )
                        doDraw = false;
                }
                break;
            case WARP_BOTTOM://down entrance, up exit
                {
                    //Offset at top side, crop bottop side
                    double cropBottom = 0.0;
                    double offset = (warpResizedBody?double(setup->setup.height) : bodyPos.height())*double(warpSpriteOffset);
                    bodyPos.setTop( bodyPos.top()+offset );
                    textPos.setPos(textPos.x(), textPos.y()+(warpResizedBody ? 0.0 : offset));
                    if(textPos.bottom() > bodyPos.bottom())
                    {
                        cropBottom  = fabs(textPos.bottom()-bodyPos.bottom());
                        textPos.setBottom(bodyPos.bottom());
                    }
                    double wOfs = ( cropBottom/double(warpFrameH) ) * (double(texture.frame_h)/double(texture.h));//Relative X offset
                    tPos.setBottom( tPos.bottom()-wOfs );
                    if( textPos.top() >= bodyPos.bottom() )
                        doDraw = false;
                }
                break;
            default:
                break;
        }
    }

    if(doDraw)
    {
        GlRenderer::renderTexture(&texture,
                                  float(npc.x()),
                                  float(npc.y()),
                                  float(npc.width()),
                                  float(npc.height()),
                                  float(tPos.top()),
                                  float(tPos.bottom()),
                                  float(tPos.left()),
                                  float(tPos.right()));
    }

    if(PGE_Window::showDebugInfo)
    {
        std::string warpingInfo;
        if(isWarping)
        {
            switch(warpDirectO)
            {
            case WARP_LEFT:     warpingInfo="LEFT"; break;
            case WARP_RIGHT:    warpingInfo="RIGHT"; break;
            case WARP_TOP:      warpingInfo="TOP"; break;
            case WARP_BOTTOM:   warpingInfo="BOTTOM"; break;
            }
        }
        FontManager::printText(fmt::format_ne(  " {0} \n"
                                           "{1}{2}{3}\n"
                                             " {4}  {5} {6}",
                                        l_contactT.size(),
                                        l_contactL.size(),
                                        l_contactAny.size(),
                                        l_contactR.size(),
                                        l_contactB.size(),
                               //.arg(collision_speed_add.size())
                                        warpingInfo,
                                    std::string(m_cliff ? "CLIFF" : "")+
                                    std::string(m_blockedAtLeft?"|<" : "")+
                                    std::string(m_blockedAtRight?">|" : "")
                                    )
                               //.arg(LEGACY_m_speedAddingTopElements.size())
                               //.arg(LEGACY_m_speedAddingBottomElements.size())
                               , int(round(20+posX()-camX)), -50+int(round(posY()-camY)), FontManager::DefaultRaster);
    }
}
Esempio n. 25
0
void Bullet::update(int gameTime)
{
    (void)gameTime;
    setPosition(posX() + _direction.x, posY() + _direction.y);
}
Esempio n. 26
0
QVariant Human::data(int role) const
{
    switch(role) {
    case IdRole:
        return (unsigned int)id();
    case FilterStringRole:
        return filterString();

    case ProfessionRole:
        return profession();
    case PosXRole:
        return posX();
    case PosYRole:
        return posY();
    case PosZRole:
        return posZ();
    case NameRole:
        return name();

    case ArcherLevelRole:
        return archerLevel();
    case BlacksmithLevelRole:
        return blacksmithLevel();
    case BuilderLevelRole:
        return builderLevel();
    case CarpenterLevelRole:
        return carpenterLevel();
    case EngineerLeveRole:
        return engineerLevel();
    case FarmerLevelRole:
        return farmerLevel();
    case FishermanLevelRole:
        return fishermanLevel();
    case ForagerLevelRole:
        return foragerLevel();
    case InfantryLevelRole:
        return infantryLevel();
    case MinerLevelRole:
        return minerLevel();
    case StoneMasonLevelRole:
        return stoneMasonLevel();
    case WoodChopperLevelRole:
        return woodChopperLevel();
    case TailorLevelRole:
        return tailorLevel();
    case TraderLevelRole:
        return traderLevel();
    case HerderLevelRole:
        return herderLevel();
    case AdventurerLevelRole:
        return adventurerLevel();
    case Unknown1Role:
        return unknown1Level();
    case Unknown2Role:
        return unknown2Level();
    case Unknown3Role:
        return unknown3Level();
    case Unknown4Role:
        return unknown4Level();

    case ExperienceRole:
        return experience();

    case AutoChopTreesRole:
        return autoChop();
    case GatherBerriesRole:
        return gatherBerries();
    case HuntChickenRole:
        return huntChicken();
    case HuntBoarRole:
        return huntBoar();
    case ShowBowRangeRole:
        return showBowRange();
    case TrainNearTargetRole:
        return trainNearTarget();

    case RotationRole:
        return rotation();

    case EquipHandRole:
        return equipHand();
    case EquipOffhandRole:
        return equipOffhand();
    case EquipHeadRole:
        return equipHead();
    case EquipBodyRole:
        return equipBody();
    case EquipFeetRole:
        return equipFeet();

    case HealthRole:
        return health();

    case MoraleRole:
        return morale();
    case FatigueRole:
        return fatigue();
    case HungerRole:
        return hunger();

    default:
        return QVariant();
    }
}
Esempio n. 27
0
void Settings::writeSettings()
{
    setValue(KEY_LANGUAGE, language());

    setValue(KEY_SESSION_AUTOPLAY, sessionAutoplay());
    setValue(KEY_SESSION_CHANNEL, sessionChannel());
    setValue(KEY_SESSION_REMEMBER_VOLUME, sessionRememberVolume());
    setValue(KEY_SESSION_VOLUME, sessionVolume());

    if (globalConfig && globalConfig->disableSettings("channels")) {
        remove("channels");
    } else {
        setValue(KEY_PLAYLIST, playlist());
        setValue(KEY_PLAYLIST_UPDATE, playlistUpdate());
        setValue(KEY_PLAYLIST_UPDATE_URL, playlistUpdateUrl());
        setValue(KEY_RADIO_CATEGORY, radioCategory());
        setValue(KEY_HD_CATEGORY, hdCategory());
        setValue(KEY_UDPXY, udpxy());
        setValue(KEY_UDPXY_URL, udpxyUrl());
        setValue(KEY_UDPXY_PORT, udpxyPort());
    }

    if (globalConfig && globalConfig->disableSettings("gui")) {
        remove("gui");
    } else {
        setValue(KEY_WIDTH, width());
        setValue(KEY_HEIGHT, height());
        setValue(KEY_POS_X, posX());
        setValue(KEY_POS_Y, posY());

        setValue(KEY_OSD, osd());
        setValue(KEY_TRAY_ENABLED, trayEnabled());
        setValue(KEY_HIDE_TO_TRAY, hideToTray());
        setValue(KEY_MOUSE_WHEEL, mouseWheel());
        setValue(KEY_REMEMBER_GUI_SESSION, rememberGuiSession());
        setValue(KEY_ICONS, icons());
    }

    if (globalConfig && globalConfig->disableSettings("backend")) {
        remove("backend");
    } else {
        setValue(KEY_VOUT, vout());
        setValue(KEY_AOUT, aout());
        setValue(KEY_YUV_TO_RGB, yuvToRgb());
        setValue(KEY_SPDIF, spdif());

        setValue(KEY_REMEMBER_VIDEO_SETTINGS, rememberVideoSettings());
        setValue(KEY_REMEMBER_VIDEO_PER_CHANNEL, rememberVideoPerChannel());
        setValue(KEY_ASPECT_RATIO, aspectRatio());
        setValue(KEY_CROP_RATIO, cropRatio());
        setValue(KEY_DEINTERLACING, deinterlacing());
        setValue(KEY_AUDIO_LANGUAGE, audioLanguage());
        setValue(KEY_SUBTITLE_LANGUAGE, subtitleLanguage());

        setValue(KEY_MUTE_ON_MINIMIZE, muteOnMinimize());
        setValue(KEY_TELETEXT, teletext());
    }

    if (globalConfig && globalConfig->disableSettings("recorder")) {
        remove("recorder");
    } else {
        setValue(KEY_RECORDER_DIRECTORY, recorderDirectory());
        setValue(KEY_SNAPSHOTS_DIRECTORY, snapshotsDirectory());
    }

    if (globalConfig && globalConfig->disableSettings("xmltv")) {
        remove("xmltv");
    } else {
        setValue(KEY_XMLTV_UPDATE, xmltvUpdate());
        setValue(KEY_XMLTV_UPDATE_LOCATION, xmltvUpdateLocation());
        setValue(KEY_XMLTV_UPDATE_REMOTE, xmltvUpdateRemote());
    }

    sync();
}
Esempio n. 28
0
void testCannonball()
{
    const double feilmargin = 0.0001;
    
    //AcclX
    assert(avvik(0.0, 
                 acclX()) < feilmargin);
    
    //AcclY
    assert(avvik(-9.81, 
                 acclY()) < feilmargin);
    
    //velX
    assert(avvik(50.0, 
                 velX(50.0, 0)) < feilmargin);
    assert(avvik(50.0, 
                 velX(50.0, 2.5)) < feilmargin);
    assert(avvik(50.0, 
                 velX(50.0, 5.0)) < feilmargin);
    
    //velY
    assert(avvik(25.0, 
                 velY(25.0, 0)) < feilmargin);
    assert(avvik(0.475, 
                 velY(25.0, 2.5)) < feilmargin);
    assert(avvik(-24.05, 
                 velY(25.0, 5.0)) < feilmargin);
    
    //velIntY
    assert(avvik(25.0, 
                 velIntY(25.0, 0)) < feilmargin);
    assert(avvik(0.475, 
                 velIntY(25.0, 2.5)) < feilmargin);
    assert(avvik(-24.05, 
                 velIntY(25.0, 5.0)) < feilmargin);
    
    //posX
    assert(avvik(0.0, 
                 posX(50.0, 0)) < feilmargin);
    assert(avvik(125.0, 
                 posX(50.0, 2.5)) < feilmargin);
    assert(avvik(250.0, 
                 posX(50.0, 5.0)) < feilmargin);
    
    //posIntX
    assert(avvik(0.0, 
                 posIntX(50.0, 0)) < feilmargin);
    assert(avvik(125.0, 
                 posIntX(50.0, 2.5)) < feilmargin);
    assert(avvik(250.0, 
                 posIntX(50.0, 5.0)) < feilmargin);
    
    //posY
    assert(avvik(0.0, 
                 posY(25.0, 0)) < feilmargin);
    assert(avvik(31.84, 
                 posY(25.0, 2.5)) < feilmargin);
    assert(avvik(2.375, 
                 posY(25.0, 5.0)) < feilmargin);
    
    //posIntY
    assert(avvik(0.0, 
                 posIntY(25.0, 0)) < feilmargin);
    assert(avvik(31.84, 
                 posIntY(25.0, 2.5)) < feilmargin);
    assert(avvik(2.375, 
                 posIntY(25.0, 5.0)) < feilmargin);
    
    //flightTime
    assert(avvik(2.03874, 
                 flightTime(10.0)) < feilmargin);
    
    //getVelocityX
    assert(avvik(7.071067812, getVelocityX(
        asin(1) / 2, 10.0
    )) < feilmargin);
    
    //getVelocityY
    assert(avvik(7.071067812, getVelocityY(
        asin(1) / 2, 10.0
    )) < feilmargin);
    
    //getDistanceTraveled
    assert(avvik(20.3874, getDistanceTraveled(
        10.0, 10.0
    )) < feilmargin);
    
    //optimalAngleForMaxDistance
    assert(avvik(0.7853981634, optimalAngleForMaxDistance(
        10.0
    )) < feilmargin);
    
    //getDistanceTraveled
    assert(avvik(-0.3874, targetPractice(
        20.0, 10.0, 10.0
    )) < feilmargin);
}