Ejemplo n.º 1
0
inline int basic_dbgstreambuf<elem_t, traits_t>::sync()
{
    if (ppos() == 0)  //avoid unnecessary carriage return in dbgview
        return 0;

    *pptr() = elem_t();
    OutputDebugStringX(pbase());

    ppos(0);

    return 0;
}
Ejemplo n.º 2
0
inline typename basic_dbgstreambuf<elem_t, traits_t>::int_type
basic_dbgstreambuf<elem_t, traits_t>::overflow(int_type c_)
{
    if (traits_t::eq_int_type(traits_t::eof(), c_))
        return traits_t::eof();

    const elem_t c = traits_t::to_char_type(c_);

    //sync();
    //NOTE: No, we can't do this here, since dbgview will
    //break the text across lines when the auto-scroll
    //option is enabled.

    const ptrdiff_t oldlen = epptr() - pbase();
    const ptrdiff_t newlen = oldlen ? 2 * oldlen : 1;

    if (elem_t* const newbuf = new (std::nothrow) elem_t[newlen + 1])
    {
        const std::streamsize pos = ppos();

#if _MSC_VER >= 1400
        const size_t size_in_bytes = newlen * sizeof(elem_t);
        traits_t::_Copy_s(newbuf, size_in_bytes, pbase(), pos);
#else
        traits_t::copy(newbuf, pbase(), pos);
#endif

        setp(newbuf, newbuf + pos, newbuf + newlen);

        delete[] m_buf;
        m_buf = newbuf;

        *pptr() = c;
        pbump(1);

        return traits_t::not_eof(c_);
    }

    if (oldlen)
    {
        sync();

        *pbase() = c;
        pbump(1);
    }
    else
    {
        const elem_t str[2] = { c, elem_t() };
        OutputDebugStringX(str);
    }

    return traits_t::not_eof(c_);
}
Ejemplo n.º 3
0
 bool within_shell(particle_shape_type const& sphere) const
 {
     for (typename spherical_shell_map::const_iterator
             i(shells_.begin()), e(shells_.end()); i != e; ++i)
     {
         spherical_shell_id_pair const& sp(*i);
         position_type ppos(main_.world()->cyclic_transpose(sphere.position(), (sp).second.position()));
         if (distance(ppos, (sp).second.shape().position()) < (sp).second.shape().radius() - sphere.radius())
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
inline typename basic_dbgstreambuf<elem_t, traits_t>::pos_type
basic_dbgstreambuf<elem_t, traits_t>::seekoff(
    off_type off,
    std::ios_base::seekdir way,
    std::ios_base::openmode which)
{
    off_type pos = -1;

    if (which & std::ios_base::out)
    {
       const ptrdiff_t buflen = epptr() - pbase();

        switch (way)
        {
            case std::ios_base::beg:
                pos = off;
                break;

            case std::ios_base::cur:
                pos = off_type(ppos()) + off;
                break;

            case std::ios_base::end:
                pos = off_type(buflen) + off;
                break;
        }

        if (pos < 0)
            pos = -1;
        else if (pos > off_type(buflen))
            pos = -1;
        else
            ppos(pos);
    }

    return pos;
}
Ejemplo n.º 5
0
static GameInst* get_weapon_autotarget(GameState* gs, PlayerInst* p,
                                       GameInst* targ, float dx, float dy) {
    WeaponEntry& wentry = p->weapon().weapon_entry();
    Pos ppos(p->x, p->y);
    GameInst* inst = NULL;
    bool ismelee = !(wentry.uses_projectile || p->equipment().has_projectile());
    int target_range = wentry.range + p->target_radius;

    if (targ) {
        int dist = distance_between(Pos(targ->x, targ->y), ppos)
                   - targ->target_radius;
        if (dist <= target_range) {
            return targ;
        }
    }

    if (ismelee) {
        /*normalize dx & dy*/
        float mag = sqrt(dx * dx + dy * dy);
        if (mag == 0.0f)
            mag = 1.0f;
        dx *= target_range / mag, dy *= target_range / mag;

        /*test in our walking direction first*/
        gs->object_radius_test(p, &inst, 1, enemy_colfilter, p->x + dx,
                               p->y + dy, p->radius);
    } else {
        target_range *= 1.25;
    }

    if (inst) {
        return inst;
    } else {
        std::vector<GameInst*> visible_monsters;
        get_visible_monsters(gs, visible_monsters, p);

        float dist;
        GameInst* inst = find_closest_from_list(gs, visible_monsters, ppos,
                                                &dist);
        if (inst && (!ismelee || dist <= target_range)) {
            return inst;
        }
    }
    return NULL;
}
Ejemplo n.º 6
0
void World::update(float delta) {
    sf::Vector2f vect(player->getSpeed());
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
        player->crouch(true);
    } else {
        player->crouch(false);
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
        if(vect.y == 0.f) vect.y = 300.f;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
        vect.x = -player->playerSpeed;
    } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
        vect.x = player->playerSpeed;
    } else {
        vect.x = 0;
    }

    player->move(vect);

    Level* curr = getLevel();
    if (curr != NULL) {
        std::vector<Tile*>* tiles = curr->getTileObjects();
        sf::Vector2i ppos(player->getPosition());

        for (auto const &ent : *tiles) {
            sf::Vector2i size(ent->getSize());
            sf::Vector2i epos(ent->getPosition());
        }
    }

    player->update(delta);
    camera->update(delta);

    if(player->getPosition().y <= 0)  {
      player->setPosition(sf::Vector2i(player->getPosition().x, 0));
      player->move(sf::Vector2f(player->getSpeed().x, 0));
    }
}
Ejemplo n.º 7
0
inline typename basic_dbgstreambuf<elem_t, traits_t>::pos_type
basic_dbgstreambuf<elem_t, traits_t>::seekpos(
    pos_type pos_,
    std::ios_base::openmode which)
{
    off_type pos = -1;

    if (which & std::ios_base::out)
    {
        pos = pos_;

        const ptrdiff_t buflen = epptr() - pbase();

        if (pos < 0)
            pos = -1;
        else if (pos > off_type(buflen))
            pos = -1;
        else
            ppos(pos);
    }

    return pos;
}
Ejemplo n.º 8
0
void DoSensePlayer( Mob* actor, Player* player )
{
	cml::vector3f playerpos = player->transform.position;
	cml::vector3f mob2player = actor->transform.position - playerpos;
	float angle_to_player = 0;
	actor->player_distance = cml::length( mob2player );
	bool player_visible = false;
	if( actor->player_distance < actor->vision.distance )
	{
		cml::vector2f mob_forward = GetForward( actor );
		angle_to_player = cml::deg(cml::signed_angle_2D( mob_forward, cml::vector2f(mob2player[0],mob2player[2]) ));

			if( abs(angle_to_player) < actor->vision.angle)
			{
				// comprobamos que no haya algun elemento del mapa interrumpiendo la visión
				b2Body* b = actor->GetPhysicBody();
				cml::vector3f actorpos = actor->transform.position;
				cml::vector3f playerpos = player->transform.position;
				if( actorpos != playerpos )
				{
					MyRayCB tehcb;
					tehcb.SetOrigin();
					b2Vec2 apos(-actorpos[0],-actorpos[2]);
					b2Vec2 ppos(-playerpos[0],-playerpos[2]);

					b->GetWorld()->RayCast( &tehcb, apos, ppos );

					// si el rayo NO ha colisionado con algun elemento del mapa, tenemos al player en el cono!
					player_visible = !tehcb.didcollide;
				}
			}
	}
	//if( !player_visible ) actor->angle_to_player = NO_PLAYER;
	actor->angle_to_player = angle_to_player;
	actor->player_visible = player_visible;
}
Ejemplo n.º 9
0
/*!

 */
void
PlayerPainter::drawKickAccelArea( QPainter & painter,
                                  const PlayerPainter::Param & param ) const
{
    //
    // draw kick accel area
    //

    if ( ! param.ball_.hasVelocity() )
    {
        return;
    }

    const Options & opt = Options::instance();
    const rcss::rcg::ServerParamT & SP = M_main_data.serverParam();

    Vector2D ppos( param.player_.x_,
                   param.player_.y_ );
    Vector2D bpos( param.ball_.x_,
                   param.ball_.y_ );

    Vector2D player_to_ball = bpos - ppos;
    player_to_ball.rotate( - param.player_.body_ );

    double ball_dist = player_to_ball.r();

    if ( ball_dist > ( param.player_type_.player_size_
                       + param.player_type_.kickable_margin_
                       + SP.ball_size_ ) )
    {
        return;
    }

    double max_kick_accel
        = SP.max_power_
        //* SP.kick_power_rate_
        * param.player_type_.kick_power_rate_
        * ( 1.0 - 0.25 * player_to_ball.th().abs() / 180.0
            - 0.25
            * ( ball_dist - param.player_type_.player_size_ - SP.ball_size_ )
            / param.player_type_.kickable_margin_ );

    if ( max_kick_accel > SP.ball_accel_max_ )
    {
        max_kick_accel = SP.ball_accel_max_;
    }

    Vector2D bnext( bpos.x + param.ball_.vx_,
                    bpos.y + param.ball_.vy_ );

    QPoint bpos_screen( opt.screenX( bpos.x ),
                        opt.screenY( bpos.y ) );
    QPoint bnext_screen( opt.screenX( bnext.x ),
                         opt.screenY( bnext.y ) );
    int max_speed_screen = opt.scale( SP.ball_speed_max_ );
    int max_kick_accel_screen = opt.scale( max_kick_accel );

    painter.setPen( M_kick_accel_pen );
    painter.setBrush( Qt::NoBrush );

    // draw no noise ball move line
    painter.drawLine( bpos_screen, bnext_screen );

    Circle2D max_speed_circle( bpos, SP.ball_speed_max_ );
    Circle2D max_accel_circle( bnext, max_kick_accel );
    Vector2D intersection_1, intersection_2;

    if ( max_speed_circle.intersection( max_accel_circle,
                                        &intersection_1,
                                        &intersection_2 ) != 2 )
    {
        // no intersection points

        // just draw a next ball reachable area by max accel
        painter.drawEllipse( bnext_screen.x() - max_kick_accel_screen,
                             bnext_screen.y() - max_kick_accel_screen,
                             max_kick_accel_screen * 2,
                             max_kick_accel_screen * 2 );
    }
    else
    {
        // exists 2 intersection points

        AngleDeg bpos_to_intersection_1 = ( intersection_1 - bpos ).th();
        AngleDeg bpos_to_intersection_2 = ( intersection_2 - bpos ).th();

        AngleDeg bpos_to_bnext_angle = ( bnext - bpos ).th();

        AngleDeg * bpos_start_angle = 0;
        double bpos_angle_span = 0.0;
        if ( bpos_to_intersection_1.isLeftOf( bpos_to_bnext_angle ) )
        {
            bpos_start_angle = &bpos_to_intersection_1;
            bpos_angle_span = ( bpos_to_intersection_2 - bpos_to_intersection_1 ).degree();
            if ( bpos_angle_span < 0.0 )
            {
                bpos_angle_span += 360.0;
            }
            bpos_angle_span *= -1.0;
        }
        else
        {
            bpos_start_angle = &bpos_to_intersection_2;
            bpos_angle_span = ( bpos_to_intersection_1 - bpos_to_intersection_2 ).degree();
            if ( bpos_angle_span < 0.0 )
            {
                bpos_angle_span += 360.0;
            }
            bpos_angle_span *= -1.0;
        }

        int bpos_start_angle_int
            = static_cast< int >( rint( - bpos_start_angle->degree() * 16 ) );
        int bpos_angle_span_int
            = static_cast< int >( rint( bpos_angle_span * 16 ) );
        painter.drawArc( bpos_screen.x() - max_speed_screen,
                         bpos_screen.y() - max_speed_screen,
                         max_speed_screen * 2,
                         max_speed_screen * 2,
                         bpos_start_angle_int,
                         bpos_angle_span_int  );

        AngleDeg bnext_to_intersection_1 = ( intersection_1 - bnext ).th();
        AngleDeg bnext_to_intersection_2 = ( intersection_2 - bnext ).th();

        AngleDeg bnext_to_bpos_angle = bpos_to_bnext_angle + 180.0;

        AngleDeg * bnext_start_angle = 0;
        double bnext_angle_span = 0.0;
        if ( bnext_to_intersection_1.isLeftOf( bnext_to_bpos_angle ) )
        {
            bnext_start_angle = &bnext_to_intersection_1;
            bnext_angle_span = ( bnext_to_intersection_2 - bnext_to_intersection_1 ).degree();
            if ( bnext_angle_span < 0.0 )
            {
                bnext_angle_span += 360.0;
            }
            bnext_angle_span *= -1.0;
        }
        else
        {
            bnext_start_angle = &bnext_to_intersection_2;
            bnext_angle_span = ( bnext_to_intersection_1 - bnext_to_intersection_2 ).degree();
            if ( bnext_angle_span < 0.0 )
            {
                bnext_angle_span += 360.0;
            }
            bnext_angle_span *= -1.0;
        }

        int bnext_start_angle_int
            = static_cast< int >( rint( - bnext_start_angle->degree() * 16 ) );
        int bnext_angle_span_int
            = static_cast< int >( rint( bnext_angle_span * 16 ) );
        painter.drawArc( bnext_screen.x() - max_kick_accel_screen,
                         bnext_screen.y() - max_kick_accel_screen,
                         max_kick_accel_screen * 2,
                         max_kick_accel_screen * 2,
                         bnext_start_angle_int,
                         bnext_angle_span_int );
    }

    // draw kick info text
    painter.setFont( M_player_font );
    painter.setPen( M_kick_accel_pen );

    char buf[32];
    snprintf( buf, 32, "MaxAccel=%.3f", max_kick_accel );
    painter.drawText( bnext_screen.x() + 10,
                      bnext_screen.y() + painter.fontMetrics().ascent(),
                      QString::fromAscii( buf ) );
}
Ejemplo n.º 10
0
/*!

 */
void
PlayerPainter::drawTackleArea( QPainter & painter,
                               const PlayerPainter::Param & param ) const
{
    //
    // draw tackle area & probability
    //

    const Options & opt = Options::instance();
    const rcss::rcg::ServerParamT & SP = M_main_data.serverParam();

    Vector2D ppos( param.player_.x_,
                   param.player_.y_ );
    Vector2D bpos( param.ball_.x_,
                   param.ball_.y_ );

    Vector2D player_to_ball = bpos - ppos;
    player_to_ball.rotate( - param.player_.body_ );

    double tackle_dist = ( player_to_ball.x > 0.0
                           ? SP.tackle_dist_
                           : SP.tackle_back_dist_ );
    if ( tackle_dist < 1.0e-5 )
    {
        return;
    }

    double tackle_fail_prob = ( std::pow( player_to_ball.absX() / tackle_dist,
                                          SP.tackle_exponent_ )
                                + std::pow( player_to_ball.absY() / SP.tackle_width_,
                                            SP.tackle_exponent_ ) );
    double foul_fail_prob = ( std::pow( player_to_ball.absX() / tackle_dist,
                                        SP.foul_exponent_ )
                              + std::pow( player_to_ball.absY() / SP.tackle_width_,
                                          SP.foul_exponent_ ) );

    if ( tackle_fail_prob < 1.0
         || foul_fail_prob < 1.0 )
    {
        painter.save();
        painter.translate( param.x_, param.y_ );
        painter.rotate( param.player_.body_ );

        painter.setPen( M_tackle_pen );
        painter.setBrush( Qt::NoBrush );

        painter.drawRect( opt.scale( - SP.tackle_back_dist_ ),
                          opt.scale( - SP.tackle_width_ ),
                          opt.scale( SP.tackle_dist_ + SP.tackle_back_dist_ ),
                          opt.scale( SP.tackle_width_ * 2.0 ) );
        painter.restore();

        int text_radius = std::min( 40, param.draw_radius_ );

        painter.setFont( M_player_font );
        painter.setPen( M_tackle_pen );

        if ( tackle_fail_prob < 1.0
             && foul_fail_prob < 1.0 )
        {
            painter.drawText( param.x_ + text_radius,
                              param.y_ + 2 + painter.fontMetrics().ascent(),
                              QString( "T=%1,F=%2" )
                              .arg( 1.0 - tackle_fail_prob, 0, 'g', 3 )
                              .arg( 1.0 - foul_fail_prob, 0, 'g', 3 ) );
        }
        else if ( tackle_fail_prob < 1.0 )
        {
            painter.drawText( param.x_ + text_radius,
                              param.y_ + 2 + painter.fontMetrics().ascent(),
                              QString( "Tackle=%1" )
                              .arg( 1.0 - tackle_fail_prob, 0, 'g', 3 ) );
        }
        else if ( foul_fail_prob < 1.0 )
        {
            painter.drawText( param.x_ + text_radius,
                              param.y_ + 2 + painter.fontMetrics().ascent(),
                              QString( "Foul=%1" )
                              .arg( 1.0 - foul_fail_prob, 0, 'g', 3 ) );
        }
    }
}
Ejemplo n.º 11
0
// Move the enemy
void ENEMY::move() {
	// Advance the animation
	if(!chase && !burning)
		anim += 0.10f;
	else
		anim += 0.20f;
	if((int)anim > 3 || kicked)
		anim = 0.0f;

	// Advance the dying animation if we're actually dying
	if(dying) {
		die_anim -= 0.03f;

		// Create the blue "burning down" effect
		float px = get_real_x();
		float py = get_real_y();
		for(int f=0; f < RAND(2,10); f++) {
			float rnd = RANDF(-0.3f, 0.3f);
			VECT pos(px, 2*size - 0.05f - (2.5f*size*(1-die_anim)), py);
			pos.x += rnd;
			pos.z -= rnd;
			if(pos.y < 0.0f)
				pos.y = 0.0f;
			if(turning)
				pos.y += (turning_raise * 0.85f);
			VECT dir = 0.0f;
			float c1[4] = { 0.1f, 0.7f, 1, 1 };
			float c2[4] = { 0.1f, 0.7f, 1, 0 };
			add_particle(pos, dir, RAND(20,35), 0.1f, 0.4f, c1, c2, part_star);
		}

		if(die_anim < 0.0f) {
			die_anim = 0.0f;
			alive = false;
		}

		return;
	}


	// Create some particle fire from the burning enemies
	if(burning) {
		VECT ppos(get_real_x(), 0.5f, get_real_y());
		create_fire(ppos);
	}

	// Advance the turning animation
	if(turning) {
		// Raise up
		if(turning == 1) {
			turning_raise += 0.035f;
			if(turning_raise >= 1.0f) {
				turning_raise = 1.0f;
				turning++;
			}
		}
		// Turn
		else if(turning == 2) {
			turning_counter++;
			if(turning_counter == 5) {
				dir = nextdir;
				nextdir = dir + 1;
				if(nextdir > DIR_W)
					nextdir = DIR_N;
			}
			else if(turning_counter == 10) {
				dir = nextdir;
				turning++;
			}
		}
		// Go down
		else if(turning == 3) {
			turning_raise -= 0.035f;
			if(turning_raise <= 0.0f) {
				turning_raise = 0.0f;
				turning = 0;
			}
		}

		// Check the collision between the player #1
		if(p1.alive && !p1.jumping) {
			float dx = get_real_x() - p1.get_real_x();
			float dy = get_real_y() - p1.get_real_y();
			if(dx*dx + dy*dy <= 0.9f) {
				// Collision happened!

				// Kill the player and die
				p1.die();
				die();
			}
		}

		// Check the collision between the player #2
		if(alive && two_players && p2.alive && !p2.jumping) {
			float dx = get_real_x() - p2.get_real_x();
			float dy = get_real_y() - p2.get_real_y();
			if(dx*dx + dy*dy <= 0.9f) {
				// Collision happened!

				// Kill the player and die
				p2.die();
				die();
			}
		}

		return;
	}


	// If there is the lightning special power in progress, don't move the enemies which are
	// suffering from the lightning strikes
	if(special_power_pause && which_special_power == BLUE_POWER_LIGHTNING) {
		// Check if we're a target
		for(int f=0; f<ENEMY_AMOUNT; f++) {
			if(sp_lightning.targets[f] == this) {
				anim += 0.30f;
				if((int)anim > 3)
					anim = 0.0f;
				return;
			}
		}
	}

	// Don't move if the level is finished
	if(level_pause)
		return;


	// Check the traps
	if(traplist.size() > 0) {
		list<TRAP>::iterator t;
		for(t = traplist.begin(); t != traplist.end(); ++t) {
			if(x == (*t).x && y == (*t).y) {
				die();
				return;
			}
		}
	}


	// Handle the burning, that is run around aimlessly
	if(burning) {
		if(!kicked) {
			// Reduce the burning time
			burn_time--;
			if(burn_time == 0) {
				die();
				return;
			}

			// Choose a random direction
			if(RAND(0,100) > 50 && offset == 0.0f) {
				if(RAND(0,100) > 50)
					dir++;
				else
					dir--;
				if(dir > DIR_W)
					dir = DIR_N;
				else if(dir < DIR_N)
					dir = DIR_W;
			}

			// Move one step
			if(tx == x && ty == y) {
				offset = 0.0f;

				// Don't stop until there's a wall.
				switch(dir) {
					default:
					case DIR_N: tx = x; ty = y - 1; break;
					case DIR_E: tx = x + 1; ty = y; break;
					case DIR_S: tx = x; ty = y + 1; break;
					case DIR_W: tx = x - 1; ty = y; break;
				}

				// Check if the target is passable?
				if(map_solid(tx, ty)) {
					// Stop and choose a new dir
					tx = x;
					ty = y;

					dir += RAND(-1,1);
					if(dir < DIR_N)
						dir = DIR_W;
					else if(dir > DIR_W)
						dir = DIR_N;
					return;
				}

			}

			// Move towards the target tile
			if(offset < 1.0f && (tx != x || ty != y)) {
				offset += speed;

				// Check the collision between the player #1
				if(p1.alive && !p1.jumping && !(using_special_power == 1 && which_special_power == BLUE_POWER_TELEPORT)) {
					float dx = get_real_x() - p1.get_real_x();
					float dy = get_real_y() - p1.get_real_y();
					if(dx*dx + dy*dy <= 0.9f) {
						// Collision happened!

						// Turn around and run
						tx = x;
						ty = y;
						offset = 0.0f;
						dir += 2;
						if(dir > DIR_W)
							dir -= 4;
					}
				}

				// Check the collision between the player #2
				if(two_players && p2.alive && !p2.jumping && !(using_special_power == 2 && which_special_power == BLUE_POWER_TELEPORT)) {
					float dx = get_real_x() - p2.get_real_x();
					float dy = get_real_y() - p2.get_real_y();
					if(dx*dx + dy*dy <= 0.9f) {
						// Collision happened!

						// Turn around and run
						tx = x;
						ty = y;
						offset = 0.0f;
						dir += 2;
						if(dir > DIR_W)
							dir -= 4;
					}
				}

				// Check the collision between the potato men
				if(potatoman.collide_with(this) && !kicked) {
					// Potatoman "kicked" us
					potatoman.kick(this);
				}


				// If we're reached the target tile, move again
				if(offset >= 1.0f) {
					x = tx;
					y = ty;
					offset = 0.0f;
				}
			}
		}

		// Check collisions with other enemies and spread the fire
		bool burnt_somebody = false;
		list<ENEMY>::iterator e;
		for(e = enemylist.begin(); e != enemylist.end(); ++e) {
			if(this != &(*e) && !(*e).burning) {
				// Check the distance
				float dx = get_real_x() - (*e).get_real_x();
				float dy = get_real_y() - (*e).get_real_y();
				if(dx*dx + dy*dy <= 0.9f) {
					// Burn the other enemy
					(*e).burning = true;
					(*e).burn_time = enemy_burn_time;
					(*e).speed += 0.06f;
					burnt_somebody = true;
				}
			}
		}

		// Play the burning sound
		if(burnt_somebody)
			play_sound(SND_WILDFIRE, false);

		if(!kicked)
			return;
	}


	// Not burning below here

	// Choose a random destination
	if(path_pos == -1) {
		// Choose a valid target
		int dx = RAND(0, MAP_W-1);
		int dy = RAND(0, MAP_H-1);
		while(map_solid(dx, dy) || dx == x || dy == y) {
			dx = RAND(0, MAP_W-1);
			dy = RAND(0, MAP_H-1);
		}

		// Calculate the path
		if(pf.find_path(x, y, dx, dy) == PATH_FAILED) {
			// Well, tough luck. We'll just wait and try again later.
			return;
		}

		// Now we've got a nice path for us!
		path_pos = 0;
		offset = 0.0f;
		tx = pf.path[0].x;
		ty = pf.path[0].y;
		dir = get_dir(tx - x, ty - y);
		look_player();
	}

	// Move one step
	if(tx == x && ty == y && path_pos > -1) {
		offset = 0.0f;

		// Follow the path if we're not chasing
		if(chase == 0 && !kicked) {
			path_pos++;
			tx = pf.path[path_pos].x;
			ty = pf.path[path_pos].y;
			dir = get_dir(tx - x, ty - y);
			look_player();
		}
		else if(chase && !kicked) {
			// We are chasing. Don't stop until there's a wall.
			switch(dir) {
				default:
				case DIR_N: tx = x; ty = y - 1; break;
				case DIR_E: tx = x + 1; ty = y; break;
				case DIR_S: tx = x; ty = y + 1; break;
				case DIR_W: tx = x - 1; ty = y; break;
			}

			// Check if the target is passable?
			if(map_solid(tx, ty)) {
				// Stop and choose a new path
				tx = x;
				ty = y;

				path_pos = -1;
				chase = 0;
				speed -= 0.03f;
			}
		}
		else if(kicked) {
			// Potatoman has kicked us. "Fly" straight until we hit a wall.
			switch(dir) {
				default:
				case DIR_N: tx = x; ty = y - 1; break;
				case DIR_E: tx = x + 1; ty = y; break;
				case DIR_S: tx = x; ty = y + 1; break;
				case DIR_W: tx = x - 1; ty = y; break;
			}

			// Check for the wall
			if(map_solid(tx, ty)) {
				die();
				return;
			}
		}
	}

	// Move towards the target tile
	if(offset < 1.0f && (tx != x || ty != y) && path_pos > -1) {
		offset += speed;

		// Check the collision between the player #1
		if(p1.alive && !p1.jumping && !(using_special_power == 1 && which_special_power == BLUE_POWER_TELEPORT)) {
			float dx = get_real_x() - p1.get_real_x();
			float dy = get_real_y() - p1.get_real_y();
			if(dx*dx + dy*dy <= 0.9f) {
				// Collision happened!

				// Kill the player and die
				p1.die();
				die();
			}
		}

		// Check the collision between the player #2
		if(alive && two_players && p2.alive && !p2.jumping && !(using_special_power == 2 && which_special_power == BLUE_POWER_TELEPORT)) {
			float dx = get_real_x() - p2.get_real_x();
			float dy = get_real_y() - p2.get_real_y();
			if(dx*dx + dy*dy <= 0.9f) {
				// Collision happened!

				// Kill the player and die
				p2.die();
				die();
			}
		}


		// Check the collision between the potato men
		if(potatoman.collide_with(this) && !kicked) {
			// Potatoman "kicked" us
			potatoman.kick(this);
		}


		// If we're reached the target tile, move again
		if(offset >= 1.0f) {
			x = tx;
			y = ty;
			offset = 0.0f;

			// If this is the final destination, stay put and choose a new path
			// on the next cycle
			if(x == pf.dx && y == pf.dy && !chase && !kicked)
				path_pos = -1;
		}
	}

}
Ejemplo n.º 12
0
void ParticleSystem::update(float dt)
{
	if (pMem == nullptr || dt == 0.0f)
		return;

	// Traverse all particles and update.
	Particle *p = pHead;

	while (p)
	{
		// Decrease lifespan.
		p->life -= dt;

		if (p->life <= 0)
			p = removeParticle(p);
		else
		{
			// Temp variables.
			love::Vector radial, tangential;
			love::Vector ppos(p->position[0], p->position[1]);

			// Get vector from particle center to particle.
			radial = ppos - p->origin;
			radial.normalize();
			tangential = radial;

			// Resize radial acceleration.
			radial *= p->radialAcceleration;

			// Calculate tangential acceleration.
			{
				float a = tangential.getX();
				tangential.setX(-tangential.getY());
				tangential.setY(a);
			}

			// Resize tangential.
			tangential *= p->tangentialAcceleration;

			// Update velocity.
			p->velocity += (radial + tangential + p->linearAcceleration) * dt;

			// Apply damping.
			p->velocity *= 1.0f / (1.0f + p->linearDamping * dt);

			// Modify position.
			ppos += p->velocity * dt;

			p->position[0] = ppos.getX();
			p->position[1] = ppos.getY();

			const float t = 1.0f - p->life / p->lifetime;

			// Rotate.
			p->rotation += (p->spinStart * (1.0f - t) + p->spinEnd * t) * dt;

			p->angle = p->rotation;

			if (relativeRotation)
				p->angle += atan2f(p->velocity.y, p->velocity.x);

			// Change size according to given intervals:
			// i = 0       1       2      3          n-1
			//     |-------|-------|------|--- ... ---|
			// t = 0    1/(n-1)        3/(n-1)        1
			//
			// `s' is the interpolation variable scaled to the current
			// interval width, e.g. if n = 5 and t = 0.3, then the current
			// indices are 1,2 and s = 0.3 - 0.25 = 0.05
			float s = p->sizeOffset + t * p->sizeIntervalSize; // size variation
			s *= (float)(sizes.size() - 1); // 0 <= s < sizes.size()
			size_t i = (size_t)s;
			size_t k = (i == sizes.size() - 1) ? i : i + 1; // boundary check (prevents failing on t = 1.0f)
			s -= (float)i; // transpose s to be in interval [0:1]: i <= s < i + 1 ~> 0 <= s < 1
			p->size = sizes[i] * (1.0f - s) + sizes[k] * s;

			// Update color according to given intervals (as above)
			s = t * (float)(colors.size() - 1);
			i = (size_t)s;
			k = (i == colors.size() - 1) ? i : i + 1;
			s -= (float)i;                            // 0 <= s <= 1
			p->color = colors[i] * (1.0f - s) + colors[k] * s;

			// Update the quad index.
			k = quads.size();
			if (k > 0)
			{
				s = t * (float) k; // [0:numquads-1] (clamped below)
				i = (s > 0.0f) ? (size_t) s : 0;
				p->quadIndex = (i < k) ? i : k - 1;
			}

			// Next particle.
			p = p->next;
		}
	}

	// Make some more particles.
	if (active)
	{
		float rate = 1.0f / emissionRate; // the amount of time between each particle emit
		emitCounter += dt;
		float total = emitCounter - rate;
		while (emitCounter > rate)
		{
			addParticle(1.0f - (emitCounter - rate) / total);
			emitCounter -= rate;
		}
		/*int particles = (int)(emissionRate * dt);
		 for (int i = 0; i != particles; i++)
		 add();*/

		life -= dt;
		if (lifetime != -1 && life < 0)
			stop();
	}

	prevPosition = position;
}
Ejemplo n.º 13
0
/**
 * Parse an ID into component pieces.  Take IDs of the form T,
 * T/V, S-T, S-T/V, or S/V-T.  If the source is missing, return a
 * source of ANY.
 * @param id the id string, in any of several forms
 * @param pos INPUT-OUTPUT parameter.  On input, pos is the
 * offset of the first character to parse in id.  On output,
 * pos is the offset after the last parsed character.  If the
 * parse failed, pos will be unchanged.
 * @param allowFilter2 if TRUE, a UnicodeSet pattern is allowed
 * at any location between specs or delimiters, and is returned
 * as the fifth string in the array.
 * @return a Specs object, or NULL if the parse failed.  If
 * neither source nor target was seen in the parsed id, then the
 * parse fails.  If allowFilter is TRUE, then the parsed filter
 * pattern is returned in the Specs object, otherwise the returned
 * filter reference is NULL.  If the parse fails for any reason
 * NULL is returned.
 */
TransliteratorIDParser::Specs *
TransliteratorIDParser::parseFilterID(const UnicodeString & id, int32_t & pos,
                                      UBool allowFilter)
{
	UnicodeString first;
	UnicodeString source;
	UnicodeString target;
	UnicodeString variant;
	UnicodeString filter;
	UChar delimiter = 0;
	int32_t specCount = 0;
	int32_t start = pos;

	// This loop parses one of the following things with each
	// pass: a filter, a delimiter character (either '-' or '/'),
	// or a spec (source, target, or variant).
	for (;;)
	{
		ICU_Utility::skipWhitespace(id, pos, TRUE);
		if (pos == id.length())
		{
			break;
		}

		// Parse filters
		if (allowFilter && filter.length() == 0 &&
		    UnicodeSet::resemblesPattern(id, pos))
		{

			ParsePosition ppos(pos);
			UErrorCode ec = U_ZERO_ERROR;
			UnicodeSet set(id, ppos, USET_IGNORE_SPACE, NULL, ec);
			if (U_FAILURE(ec))
			{
				pos = start;
				return NULL;
			}
			id.extractBetween(pos, ppos.getIndex(), filter);
			pos = ppos.getIndex();
			continue;
		}

		if (delimiter == 0)
		{
			UChar c = id.charAt(pos);
			if ((c == TARGET_SEP && target.length() == 0) ||
			    (c == VARIANT_SEP && variant.length() == 0))
			{
				delimiter = c;
				++pos;
				continue;
			}
		}

		// We are about to try to parse a spec with no delimiter
		// when we can no longer do so (we can only do so at the
		// start); break.
		if (delimiter == 0 && specCount > 0)
		{
			break;
		}

		UnicodeString spec = ICU_Utility::parseUnicodeIdentifier(id, pos);
		if (spec.length() == 0)
		{
			// Note that if there was a trailing delimiter, we
			// consume it.  So Foo-, Foo/, Foo-Bar/, and Foo/Bar-
			// are legal.
			break;
		}

		switch (delimiter)
		{
		case 0:
			first = spec;
			break;
		case TARGET_SEP:
			target = spec;
			break;
		case VARIANT_SEP:
			variant = spec;
			break;
		}
		++specCount;
		delimiter = 0;
	}

	// A spec with no prior character is either source or target,
	// depending on whether an explicit "-target" was seen.
	if (first.length() != 0)
	{
		if (target.length() == 0)
		{
			target = first;
		}
		else
		{
			source = first;
		}
	}

	// Must have either source or target
	if (source.length() == 0 && target.length() == 0)
	{
		pos = start;
		return NULL;
	}

	// Empty source or target defaults to ANY
	UBool sawSource = TRUE;
	if (source.length() == 0)
	{
		source = ANY;
		sawSource = FALSE;
	}
	if (target.length() == 0)
	{
		target = ANY;
	}

	return new Specs(source, target, variant, sawSource, filter);
}
Ejemplo n.º 14
0
inline std::streamsize basic_dbgstreambuf<elem_t, traits_t>::xsputn(
    const elem_t* str,
    std::streamsize n)
{
    if (n <= plen())
    {
#if _MSC_VER >= 1400
        const size_t size_in_bytes = plen() * sizeof(elem_t);
        traits_t::_Copy_s(pptr(), size_in_bytes, str, n);
#else
        traits_t::copy(pptr(), str, n);
#endif

        const int off = static_cast<int>(n);
        pbump(off);

        return n;
    }

    const std::streamsize pos = ppos();
    const std::streamsize newlen = pos + n;

    if (elem_t* const newbuf = new (std::nothrow) elem_t[newlen + 1])
    {
#if _MSC_VER >= 1400
        size_t size_in_bytes = newlen * sizeof(elem_t);
        traits_t::_Copy_s(newbuf, size_in_bytes, pbase(), pos);
#else
        traits_t::copy(newbuf, pbase(), pos);
#endif

        setp(newbuf, newbuf + pos, newbuf + newlen);

        delete[] m_buf;
        m_buf = newbuf;

#if _MSC_VER >= 1400
        size_in_bytes = plen() * sizeof(elem_t);
        traits_t::_Copy_s(pptr(), size_in_bytes, str, n);
#else
        traits_t::copy(pptr(), str, n);
#endif

        const int off = static_cast<int>(n);
        pbump(off);

        return n;
    }

    const ptrdiff_t oldlen_ = epptr() - pbase();

    if (oldlen_ == 0)
    {
        elem_t buf[2];

        buf[1] = elem_t();

        for (std::streamsize i = 0; i < n; ++i)
        {
            buf[0] = *str++;
            OutputDebugStringX(buf);
        }

        return n;
    }

    std::streamsize nn = n;

    if (std::streamsize len = plen())
    {
#if _MSC_VER >= 1400
        const size_t size_in_bytes = len * sizeof(elem_t);
        traits_t::_Copy_s(pptr(), size_in_bytes, str, len);
#else
        traits_t::copy(pptr(), str, len);
#endif

        const int off = static_cast<int>(len);
        pbump(off);

        str += len;
        nn -= len;
    }

    const std::streamsize oldlen = static_cast<std::streamsize>(oldlen_);

#if _MSC_VER >= 1400
    const size_t size_in_bytes = oldlen * sizeof(elem_t);
#endif

    for (;;)
    {
        sync();

        if (nn <= oldlen)
        {
#if _MSC_VER >= 1400
            traits_t::_Copy_s(pbase(), size_in_bytes, str, nn);
#else
            traits_t::copy(pbase(), str, nn);
#endif

            const int off = static_cast<int>(nn);
            pbump(off);

            return n;
        }

#if _MSC_VER >= 1400
        traits_t::_Copy_s(pbase(), size_in_bytes, str, oldlen);
#else
        traits_t::copy(pbase(), str, oldlen);
#endif

        const int off = static_cast<int>(oldlen);
        pbump(off);

        str += oldlen;
        nn -= oldlen;
    }
}
Ejemplo n.º 15
0
	void ParticleSystem::update(float dt)
	{
		// Traverse all particles and update.
		particle * p = pStart;

		// Make some more particles.
		if(active)
		{
			float rate = 1.0f / emissionRate; // the amount of time between each particle emit
			emitCounter += dt;
			while(emitCounter > rate)
			{
				add();
				emitCounter -= rate;
			}
			/*int particles = (int)(emissionRate * dt);
			for(int i = 0; i != particles; i++)
				add();*/

			life -= dt;
			if(lifetime != -1 && life < 0)
				stop();
		}

		while(p != pLast)
		{
			// Decrease lifespan.
			p->life -= dt;

			if(p->life > 0)
			{

				// Temp variables.
				love::Vector radial, tangential, gravity(0, p->gravity);
				love::Vector ppos(p->position[0], p->position[1]);

				// Get vector from particle center to particle.
				radial = ppos - position;
				radial.normalize();
				tangential = radial;

				// Resize radial acceleration.
				radial *= p->radialAcceleration;

				// Calculate tangential acceleration.
				{
					float a = tangential.getX();
					tangential.setX(-tangential.getY());
					tangential.setY(a);
				}

				// Resize tangential.
				tangential *= p->tangentialAcceleration;

				// Update position.
				p->speed += (radial+tangential+gravity)*dt;

				// Modify position.
				ppos += p->speed * dt;

				p->position[0] = ppos.getX();
				p->position[1] = ppos.getY();

				const float t = p->life / p->lifetime;

				// Change size.
				p->size = p->sizeEnd - ((p->sizeEnd - p->sizeStart) * t);

				// Rotate.
				p->rotation += (p->spinStart*(1-t) + p->spinEnd*t)*dt;

				// Update color.
				p->color[0] = (float)(colorEnd.getRed()*(1.0f-t) + colorStart.getRed() * t)/255.0f;
				p->color[1] = (float)(colorEnd.getGreen()*(1.0f-t) + colorStart.getGreen() * t)/255.0f;
				p->color[2] = (float)(colorEnd.getBlue()*(1.0f-t) + colorStart.getBlue() * t)/255.0f;
				p->color[3] = (float)(colorEnd.getAlpha()*(1.0f-t) + colorStart.getAlpha() * t)/255.0f;
	
				// Next particle.
				p++;
			}
			else
			{
				remove(p);

				if(p >= pLast)
					return;
			} // else
		} // while
	}
/*!

*/
void
PlayerControlPainter::draw( QPainter & painter )
{
    const Options & opt = Options::instance();

    if ( ! opt.showKickAccelArea() )
    {
        return;
    }

    int number = opt.selectedNumber();
    if ( number == 0 )
    {
        return;
    }

    MonitorViewConstPtr view = M_main_data.getCurrentViewData();

    if ( ! view )
    {
        return;
    }

    const Ball & ball = view->ball();

    if ( ! ball.hasDelta() )
    {
        return;
    }

    const rcsc::ServerParam & SP = rcsc::ServerParam::i();
    const DrawConfig & dconf = DrawConfig::instance();

    const Player & player = view->players()[ ( number > 0
                                               ? number - 1
                                               : -number - 1 + 11 ) ];
    const rcsc::PlayerType & ptype = M_main_data.viewHolder().playerType( player.type() );

    rcsc::Vector2D ppos( player.x(), player.y() );
    rcsc::Vector2D bpos( ball.x(), ball.y() );
    rcsc::Vector2D player_to_ball = bpos - ppos;
    player_to_ball.rotate( - player.body() );

    rcsc::Vector2D bnext( bpos.x + ball.deltaX(),
                          bpos.y + ball.deltaY() );
    double ball_dist = player_to_ball.r();

    if ( ball_dist < ptype.kickableArea() )
    {
        double max_kick_accel
            = SP.maxPower()
            //* SP.kickPowerRate()
            * ptype.kickPowerRate()
            * ( 1.0 - 0.25 * player_to_ball.th().abs() / 180.0
                - 0.25
                * ( ball_dist - ptype.playerSize() - SP.ballSize() )
                / ptype.kickableMargin() );

        if ( max_kick_accel > SP.ballAccelMax() )
        {
            max_kick_accel = SP.ballAccelMax();
        }

        QPointF bpos_screen( opt.screenXF( bpos.x ),
                             opt.screenYF( bpos.y ) );
        QPointF bnext_screen( opt.screenXF( bnext.x ),
                              opt.screenYF( bnext.y ) );
        double max_speed_screen = opt.scaleF( SP.ballSpeedMax() );
        double max_kick_accel_screen = opt.scaleF( max_kick_accel );

        painter.setPen( dconf.kickAccelPen() );
        painter.setBrush( dconf.transparentBrush() );

        // draw no noise next ball move only by inertia
        painter.drawLine( QLineF( bpos_screen, bnext_screen ) );

        rcsc::Circle2D max_speed_circle( bpos, SP.ballSpeedMax() );
        rcsc::Circle2D max_accel_circle( bnext, max_kick_accel );
        rcsc::Vector2D intersection_1, intersection_2;

        if ( max_speed_circle.intersection( max_accel_circle,
                                            &intersection_1,
                                            &intersection_2 ) != 2 )

        {
            // no intersection points

            // just draw a next ball reachable area by max accel
            painter.drawEllipse( QRectF( bnext_screen.x() - max_kick_accel_screen,
                                         bnext_screen.y() - max_kick_accel_screen,
                                         max_kick_accel_screen * 2,
                                         max_kick_accel_screen * 2 ) );
        }
        else
        {
            // exists 2 intersection points

            rcsc::AngleDeg bpos_to_intersection_1 = ( intersection_1 - bpos ).th();
            rcsc::AngleDeg bpos_to_intersection_2 = ( intersection_2 - bpos ).th();

            rcsc::AngleDeg bpos_to_bnext_angle = ( bnext - bpos ).th();

            rcsc::AngleDeg * bpos_start_angle = 0;
            double bpos_angle_span = 0.0;
            if ( bpos_to_intersection_1.isLeftOf( bpos_to_bnext_angle ) )
            {
                bpos_start_angle = &bpos_to_intersection_1;
                bpos_angle_span = ( bpos_to_intersection_2 - bpos_to_intersection_1 ).degree();
                if ( bpos_angle_span < 0.0 )
                {
                    bpos_angle_span += 360.0;
                }
                bpos_angle_span *= -1.0;
            }
            else
            {
                bpos_start_angle = &bpos_to_intersection_2;
                bpos_angle_span = ( bpos_to_intersection_1 - bpos_to_intersection_2 ).degree();
                if ( bpos_angle_span < 0.0 )
                {
                    bpos_angle_span += 360.0;
                }
                bpos_angle_span *= -1.0;
            }

            if ( opt.reverseSide() )
            {
                *bpos_start_angle += 180.0;
            }

            int bpos_start_angle_int
                = static_cast< int >( rint( - bpos_start_angle->degree() * 16 ) );
            int bpos_angle_span_int
                = static_cast< int >( rint( bpos_angle_span * 16 ) );
            painter.drawArc( QRectF( bpos_screen.x() - max_speed_screen,
                                     bpos_screen.y() - max_speed_screen,
                                     max_speed_screen * 2,
                                     max_speed_screen * 2 ),
                             bpos_start_angle_int,
                             bpos_angle_span_int  );

            rcsc::AngleDeg bnext_to_intersection_1 = ( intersection_1 - bnext ).th();
            rcsc::AngleDeg bnext_to_intersection_2 = ( intersection_2 - bnext ).th();

            rcsc::AngleDeg bnext_to_bpos_angle = bpos_to_bnext_angle + 180.0;

            rcsc::AngleDeg * bnext_start_angle = 0;
            double bnext_angle_span = 0.0;
            if ( bnext_to_intersection_1.isLeftOf( bnext_to_bpos_angle ) )
            {
                bnext_start_angle = &bnext_to_intersection_1;
                bnext_angle_span = ( bnext_to_intersection_2 - bnext_to_intersection_1 ).degree();
                if ( bnext_angle_span < 0.0 )
                {
                    bnext_angle_span += 360.0;
                }
                bnext_angle_span *= -1.0;
            }
            else
            {
                bnext_start_angle = &bnext_to_intersection_2;
                bnext_angle_span = ( bnext_to_intersection_1 - bnext_to_intersection_2 ).degree();
                if ( bnext_angle_span < 0.0 )
                {
                    bnext_angle_span += 360.0;
                }
                bnext_angle_span *= -1.0;
            }

            if ( opt.reverseSide() )
            {
                *bnext_start_angle += 180.0;
            }

            int bnext_start_angle_int
                = static_cast< int >( rint( - bnext_start_angle->degree() * 16 ) );
            int bnext_angle_span_int
                = static_cast< int >( rint( bnext_angle_span * 16 ) );
            painter.drawArc( QRectF( bnext_screen.x() - max_kick_accel_screen,
                                     bnext_screen.y() - max_kick_accel_screen,
                                     max_kick_accel_screen * 2,
                                     max_kick_accel_screen * 2 ),
                             bnext_start_angle_int,
                             bnext_angle_span_int );
        }

        // draw kick info text
        painter.setFont( dconf.playerFont() );
        painter.setPen( dconf.kickAccelPen() );

        //snprintf( buf, 32, "MaxAccel=%.3f", max_kick_accel );
        painter.drawText( QPointF( bnext_screen.x() + 10,
                                   bnext_screen.y() + painter.fontMetrics().ascent() ),
                          QString( "MaxAccel=%1" ).arg( max_kick_accel, 0, 'g', 4 ) );
    }
}
Ejemplo n.º 17
0
/**
 * Parse a global filter of the form "[f]" or "([f])", depending
 * on 'withParens'.
 * @param id the pattern the parse
 * @param pos INPUT-OUTPUT parameter.  On input, the position of
 * the first character to parse.  On output, the position after
 * the last character parsed.
 * @param dir the direction.
 * @param withParens INPUT-OUTPUT parameter.  On entry, if
 * withParens is 0, then parens are disallowed.  If it is 1,
 * then parens are requires.  If it is -1, then parens are
 * optional, and the return result will be set to 0 or 1.
 * @param canonID OUTPUT parameter.  The pattern for the filter
 * added to the canonID, either at the end, if dir is FORWARD, or
 * at the start, if dir is REVERSE.  The pattern will be enclosed
 * in parentheses if appropriate, and will be suffixed with an
 * ID_DELIM character.  May be NULL.
 * @return a UnicodeSet object or NULL.  A non-NULL results
 * indicates a successful parse, regardless of whether the filter
 * applies to the given direction.  The caller should discard it
 * if withParens != (dir == REVERSE).
 */
UnicodeSet * TransliteratorIDParser::parseGlobalFilter(const UnicodeString & id, int32_t & pos,
        int32_t dir,
        int32_t & withParens,
        UnicodeString * canonID)
{
	UnicodeSet * filter = NULL;
	int32_t start = pos;

	if (withParens == -1)
	{
		withParens = ICU_Utility::parseChar(id, pos, OPEN_REV) ? 1 : 0;
	}
	else if (withParens == 1)
	{
		if (!ICU_Utility::parseChar(id, pos, OPEN_REV))
		{
			pos = start;
			return NULL;
		}
	}

	ICU_Utility::skipWhitespace(id, pos, TRUE);

	if (UnicodeSet::resemblesPattern(id, pos))
	{
		ParsePosition ppos(pos);
		UErrorCode ec = U_ZERO_ERROR;
		filter = new UnicodeSet(id, ppos, USET_IGNORE_SPACE, NULL, ec);
		/* test for NULL */
		if (filter == 0)
		{
			pos = start;
			return 0;
		}
		if (U_FAILURE(ec))
		{
			delete filter;
			pos = start;
			return NULL;
		}

		UnicodeString pattern;
		id.extractBetween(pos, ppos.getIndex(), pattern);
		pos = ppos.getIndex();

		if (withParens == 1 && !ICU_Utility::parseChar(id, pos, CLOSE_REV))
		{
			pos = start;
			return NULL;
		}

		// In the forward direction, append the pattern to the
		// canonID.  In the reverse, insert it at zero, and invert
		// the presence of parens ("A" <-> "(A)").
		if (canonID != NULL)
		{
			if (dir == FORWARD)
			{
				if (withParens == 1)
				{
					pattern.insert(0, OPEN_REV);
					pattern.append(CLOSE_REV);
				}
				canonID->append(pattern).append(ID_DELIM);
			}
			else
			{
				if (withParens == 0)
				{
					pattern.insert(0, OPEN_REV);
					pattern.append(CLOSE_REV);
				}
				canonID->insert(0, pattern);
				canonID->insert(pattern.length(), ID_DELIM);
			}
		}
	}

	return filter;
}
Ejemplo n.º 18
0
inline void basic_dbgstreambuf<elem_t, traits_t>::ppos(std::streamsize pos)
{
    pbump(int(pos) - int(ppos()));
}
Ejemplo n.º 19
0
void Tie::layout()
      {
      qreal _spatium = spatium();

      //
      //    show short bow
      //
      if (startNote() == 0 || endNote() == 0) {
            if (startNote() == 0) {
                  qDebug("Tie::layout(): no start note");
                  return;
                  }
            Chord* c1 = startNote()->chord();
            if (_slurDirection == MScore::Direction::AUTO) {
                  if (c1->measure()->mstaff(c1->staffIdx())->hasVoices) {
                        // in polyphonic passage, ties go on the stem side
                        _up = c1->up();
                        }
                  else
                        _up = !c1->up();
                  }
            else
                  _up = _slurDirection == MScore::Direction::UP ? true : false;
            fixupSegments(1);
            SlurSegment* segment = segmentAt(0);
            segment->setSpannerSegmentType(SpannerSegmentType::SINGLE);
            segment->setSystem(startNote()->chord()->segment()->measure()->system());
            SlurPos sPos;
            slurPos(&sPos);
            segment->layout(sPos.p1, sPos.p2);
            return;
            }

      calculateDirection();

      qreal w   = startNote()->headWidth();
      qreal xo1 = w * 1.12;
      qreal h   = w * 0.3;
      qreal yo  = _up ? -h : h;

      QPointF off1(xo1, yo);
      QPointF off2(0.0, yo);

#if 0 // yet(?) unused
      QPointF ppos(pagePos());
#endif

      // TODO: cleanup

      SlurPos sPos;
      slurPos(&sPos);

      // p1, p2, s1, s2

      QList<System*>* systems = score()->systems();
      setPos(0, 0);

      //---------------------------------------------------------
      //   count number of segments, if no change, all
      //    user offsets (drags) are retained
      //---------------------------------------------------------

      int sysIdx1 = systems->indexOf(sPos.system1);
      if (sysIdx1 == -1) {
            qDebug("system not found");
            foreach(System* s, *systems)
                  qDebug("   search %p in %p", sPos.system1, s);
            return;
            }

      int sysIdx2     = systems->indexOf(sPos.system2);
      if (sysIdx2 < 0)
            sysIdx2 = sysIdx1;
      unsigned nsegs  = sysIdx2 - sysIdx1 + 1;
      fixupSegments(nsegs);

      int i = 0;
      for (uint ii = 0; ii < nsegs; ++ii) {
            System* system = (*systems)[sysIdx1++];
            if (system->isVbox())
                  continue;
            SlurSegment* segment = segmentAt(i);
            segment->setSystem(system);

            // case 1: one segment
            if (sPos.system1 == sPos.system2) {
                  segment->layout(sPos.p1, sPos.p2);
                  segment->setSpannerSegmentType(SpannerSegmentType::SINGLE);
                  }
            // case 2: start segment
            else if (i == 0) {
                  qreal x = system->bbox().width();
                  segment->layout(sPos.p1, QPointF(x, sPos.p1.y()));
                  segment->setSpannerSegmentType(SpannerSegmentType::BEGIN);
                  }
            // case 4: end segment
            else {
                  qreal x = firstNoteRestSegmentX(system) - 2 * _spatium;

                  segment->layout(QPointF(x, sPos.p2.y()), sPos.p2);
                  segment->setSpannerSegmentType(SpannerSegmentType::END);
                  }
            ++i;
            }
      }
void IslandGame::redraw( )
{
	//static bool gfxInit = false;
	//if (!gfxInit)
	//{
	//	initGraphics();
	//	gfxInit = true;
	//}

	glClearColor( 0.3, 1.0, 1.0, 1.0 );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	// 3d stuff
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_TEXTURE_2D );
	glEnable( GL_TEXTURE );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();	

	int useOrtho = _TV(1);
	if (!useOrtho)
	{
		gluPerspective( _TV(2.0f), 800.0/600.0, 0.1, 1000.0 );
	}
	else
	{
		float aspect = 800.0 / 600.0;
		float hite = _TV(4.0f);
		glOrtho( -aspect * hite, aspect * hite, -hite, hite, 0.1, 1000.0 );
	}

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();	
	
	glDisable( GL_LIGHTING );

	// player
	MapSquare &mp = m_map[m_px][m_py];
	vec3f ppos( m_px + 0.5f, 
				(mp.m_elevation+1.0) * 0.3f, 
				m_py + 0.5f );
	
	//gluLookAt( ppos.x, ppos.y + 1, ppos.z + 1,
	//		   ppos.x, ppos.y, ppos.z,
	//		   0.0, 1.0, 0.0 );	
	glRotatef( _TV(29.7f), 1.0, 0.0, 0.0 );
	glTranslatef( _TV(0), _TV(-6), _TV(-8) );
	glRotatef( _TV(45.0f), 0.0, 1.0, 0.0 );

	glTranslatef( m_camPos.x * _TV(-1.0f), 
				  m_camPos.y * _TV( 0.0f), 
				  m_camPos.z  * _TV(-1.0f));
	

	//static float ang = 0;
	//glRotatef( ang, 0.0, 1.0, 0.0 );
	//ang += 1;	

	glDisable( GL_TEXTURE_2D );
#if 0	
	glLineWidth( 4.0 );
	glBegin( GL_LINES );

	glColor3f( 1.0, 0.0, 0.0 );
	glVertex3f( ppos.x-1.0, ppos.y + 0.01, ppos.z );
	glVertex3f( ppos.x+1.0, ppos.y + 0.01, ppos.z );

	glColor3f( 0.0, 1.0, 0.0 );
	glVertex3f( ppos.x, ppos.y -1.0, ppos.z );
	glVertex3f( ppos.x, ppos.y +1.0, ppos.z );

	glColor3f( 0.0, 0.0, 1.0 );
	glVertex3f( ppos.x, ppos.y + 0.01, ppos.z - 1.0 );
	glVertex3f( ppos.x, ppos.y + 0.01, ppos.z + 1.0 );

	glEnd();
#endif

	glColor3f( 1.0, 1.0, 1.0 );
	glEnable( GL_TEXTURE_2D );	

	// draw some stuff the easy way
	glBindTexture( GL_TEXTURE_2D, m_waterTexId );	
	glBegin( GL_QUADS );
	
	glTexCoord2f( 0.0, 0.0 );
	glVertex3f( -2000, 0, -2000 );

	glTexCoord2f( 0.0, 1000.0 );
	glVertex3f( -2000, 0, 2000 );

	glTexCoord2f( 1000.0, 1000.0 );
	glVertex3f( 2000, 0, 2000 );

	glTexCoord2f( 1000.0, 0.0 );
	glVertex3f( 2000, 0, -2000 );

	glEnd();

	glEnable( GL_TEXTURE_2D );	
	//glColor3f( 1.0, 0.0, 1.0 );	

	// draw player
	glPushMatrix();	
	glTranslatef( ppos.x, ppos.y, ppos.z );
	glScalef( 0.4f, 0.4f, 0.4f );
	glRotatef( getRotForDir(m_pdir), 0.0, 1.0, 0.0 );
	glBindTexture( GL_TEXTURE_2D, m_playerTex );
	glCallList( m_personMesh );
	glPopMatrix();

	// draw critters
	for (std::vector<Critter*>::iterator ci = m_critters.begin(); 
		 ci != m_critters.end(); ci++)
	{
		Critter *c = (*ci);
		float elev = (m_map[c->m_x][c->m_y].m_elevation + 1.0) * 0.3;
		glPushMatrix();	
		glTranslatef( c->m_x + 0.5f, elev, c->m_y + 0.5f );
		glScalef( 0.4f, 0.4f, 0.4f );

		if (c->m_behavior == BEHAVIOR_STATIC)
		{
			glRotatef( getRotLookAt( c->m_x, c->m_y ), 0.0, 1.0, 0.0 );
		}
		else
		{
			glRotatef( getRotForDir( c->m_dir ), 0.0, 1.0, 0.0 );
		}

		glBindTexture( GL_TEXTURE_2D, c->m_critterTex );
		glCallList( m_critterMesh );
		glPopMatrix();
	}

	// draw npcs
	for (std::vector<Npc*>::iterator ci = m_npcs.begin(); 
		 ci != m_npcs.end(); ci++)
	{
		Npc *npc = (*ci);
		float elev = (m_map[npc->m_x][npc->m_y].m_elevation + 1.0) * 0.3;
		glPushMatrix();	
		glTranslatef( npc->m_x + 0.5f, elev, npc->m_y + 0.5f );
		glScalef( 0.4f, 0.4f, 0.4f );
		glRotatef( getRotLookAt( npc->m_x, npc->m_y ), 0.0, 1.0, 0.0 );
		glBindTexture( GL_TEXTURE_2D, npc->m_personTex );
		glCallList( m_personMesh );
		glPopMatrix();
	}

	glEnable( GL_LIGHTING );
	glEnable( GL_LIGHT0 );
	glEnable( GL_LIGHT1 );	

	glBindTexture( GL_TEXTURE_2D, m_terrainTilesTexId );

	// Bind the island VBO
	glBindBuffer(GL_ARRAY_BUFFER, m_islandVBO);

	//glEnableVertexAttribArray( MapVert::ATTRIB_VERTEX);
	//glEnableVertexAttribArray( MapVert::ATTRIB_TEXCOORD );
	//glEnableVertexAttribArray( ATTRIB_NORMAL );
	
	//glVertexAttribPointer( MapVert::ATTRIB_VERTEX,   4, GL_FLOAT, GL_FALSE, sizeof(MapVert), 0);
	//glVertexAttribPointer( MapVert::ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof(MapVert), (void*)(3*sizeof(GLfloat)) );
	//glVertexAttribPointer( ATTRIB_NORMAL,   3, GL_FLOAT, GL_FALSE, sizeof(MapVert), (void*)(6*sizeof(GLfloat)) );
	
	//glBufferData( GL_ARRAY_BUFFER, sizeof(MapVert) * m_quadSize, 0, GL_STATIC_DRAW );
	//glVertexPointer( 4, GL_FLOAT, sizeof(MapVert), NULL );
	//

	glEnableClientState( GL_VERTEX_ARRAY );
	glVertexPointer( 3, GL_FLOAT, sizeof(MapVert), 0 );
	
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );	
	glTexCoordPointer( 2, GL_FLOAT, sizeof(MapVert), (void*)(4*sizeof(GLfloat)) );

	glEnableClientState( GL_NORMAL_ARRAY );
	glNormalPointer( GL_FLOAT, sizeof(MapVert), (void*)(6*sizeof(GLfloat)) );
	
	glDrawArrays( GL_QUADS, 0, m_quadSize );

	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
	glDisableClientState( GL_NORMAL_ARRAY );
	glDisableClientState( GL_VERTEX_ARRAY );

	// 2D text and GUI stuff
	glDisable( GL_DEPTH_TEST );	
	
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glDisable( GL_LIGHTING );		
	

	glColor3f( 1.0, 1.0, 1.0 );
		
	if (m_showHudText)
	{
		gfEnableFont( m_fntFontId, 32 );
		gfBeginText();		

		// draw background box
		glDisable( GL_TEXTURE_2D );
		glColor4f( 0.0, 0.0, 0.0, 0.6 );
		glBegin( GL_QUADS );
		glVertex2f( 0, 0 ); glVertex2f( 0, 210 );
		glVertex2f( 800, 210 ); glVertex2f( 800, 0 );
		glEnd();
		glColor4f( 1.0, 1.0, 0.0, 1.0 );

		glEnable( GL_TEXTURE_2D );

		glTranslated( 20, 170, 0 );		
		gfDrawString( m_hudTitle.c_str() );
		gfEndText();

		glColor4f( 1.0, 1.0, 1.0, 1.0 );
		gfEnableFont( m_fntFontId, 20 );
		gfBeginText();		
		glTranslated( 20, 130, 0 );		
		gfDrawString( m_hudText.c_str() );
		gfEndText();
	}

}