示例#1
0
double Noise::FindNoise(int x, int y)
{
	x = WrapAround(x);
	y = WrapAround(y);
	int n = x * 331 + y * 337;
	n = (n << 13) ^ n;
	return (double)(1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
示例#2
0
double Noise::FindNoise(int x, int y, int z)
{
	x = WrapAround(x);
	y = WrapAround(y);
	z = WrapAround(z);
	//I'm guessing these are primes?
	int n = x * 331 + y * 337 + z * 339;
	n = (n << 13) ^ n;
	return (double)(1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
示例#3
0
int UpdatePlayer(SDL_Renderer *r, Player *p, double frameTime)//, Asteroid *ast)
{

  MovePlayer(r, p);

  p->prevBullet += frameTime;

  p->dest.x += sin(p->angle * PI / 180) * (p->speed * frameTime);

  p->dest.y -= cos(p->angle * PI / 180) * (p->speed * frameTime);

  WrapAround(p);

  for(int i = 0; i < p->bulletIndex; ++i) {
  
    if(UpdateBullet(r, p->b[i], frameTime)) {

      DestroyBullet(p->b[i]);
     
      ShiftBullets(p->b, i, p->bulletIndex);

      p->bulletIndex--;
 
    }

  }

  SDL_RenderCopyEx(r, p->t, NULL, &p->dest, p->angle, NULL, SDL_FLIP_NONE);

  return 0;

}
示例#4
0
 // Get the next num_data indices without advancing.
 std::vector<int32_t> GetBatchDataIdx(int32_t num_data) const {
   std::vector<int32_t> result(num_data);
   for (int i = 0; i < num_data; ++i) {
     result[i] = (num_data_this_epoch_ + data_idx_begin_ + i);
     // Wrap around to be within [data_idx_begin_, data_idx_end_)
     result[i] = WrapAround(result[i]);
   }
   return result;
 }
示例#5
0
//---------------------------------------------------------------------------
void TMyAgent::Move(TEnviroment enviroment, bool go_left, bool go_right, int steps_per_time){
    if(go_left)
        for(int x = 0; x < width; ++x)
            coordinates[x] -= steps_per_time;
    else if(go_right)
        for(int x = 0; x < width; ++x)
            coordinates[x] += steps_per_time;
    else if(!go_left && !go_right)
        return;

    WrapAround(enviroment);
}
示例#6
0
bool CVehicle::ReadSpecialData ( void )
{
    // Grab the "posX" data
    if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) )
    {
        CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the "posY" data
    if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) )
    {
        CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the "posZ" data
    if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) )
    {
        CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the "rotX", "rotY" and "rotZ" data
    GetCustomDataFloat ( "rotX", m_vecRotationDegrees.fX, true );
    GetCustomDataFloat ( "rotY", m_vecRotationDegrees.fY, true );
    GetCustomDataFloat ( "rotZ", m_vecRotationDegrees.fZ, true );

    // Wrap them around 360
    m_vecRotationDegrees.fX = WrapAround ( m_vecRotationDegrees.fX, 360.0f );
    m_vecRotationDegrees.fY = WrapAround ( m_vecRotationDegrees.fY, 360.0f );
    m_vecRotationDegrees.fZ = WrapAround ( m_vecRotationDegrees.fZ, 360.0f );

    // Set the respawn matrix
    SetRespawnPosition ( m_vecPosition );
    SetRespawnRotationDegrees ( m_vecRotationDegrees );

    // Grab the "model" data
    int iTemp;
    if ( GetCustomDataInt ( "model", iTemp, true ) )
    {
        // Is it valid?
        if ( CVehicleManager::IsValidModel ( iTemp ) )
        {
            // Remember it and generate a new random color
            m_usModel = static_cast < unsigned short > ( iTemp );
            m_Color = RandomizeColor ();
            GetInitialDoorStates ( m_ucDoorStates );

            m_usAdjustableProperty = 0;
        }
        else
        {
            CLogger::ErrorPrintf ( "Bad 'model'(%d) id specified in <vehicle> (line %u)\n", iTemp, m_uiLine );
            return false;
        }
    }
    else
    {
        CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the "turretX" data
    if ( GetCustomDataFloat ( "turretX", m_fTurretPositionX, true ) )
    {
        m_fTurretPositionX = ConvertDegreesToRadians ( m_fTurretPositionX );
    }

    // Grab the "turretY" data
    if ( GetCustomDataFloat ( "turretY", m_fTurretPositionY, true ) )
    {
        m_fTurretPositionY = ConvertDegreesToRadians ( m_fTurretPositionY );
    }

    // Grab the "health" data
    if ( GetCustomDataFloat ( "health", m_fHealth, true ) )
    {
        if ( m_fHealth < 0.0f )
            m_fHealth = 0.0f;
    }

    // Grab the "Sirens" data
    if ( !GetCustomDataBool ( "sirens", m_bSirenActive, true ) )
    {
        m_bSirenActive = false;
    }

    // Grab the "landingGearDown" data
    if ( !GetCustomDataBool ( "landingGearDown", m_bLandingGearDown, true ) )
    {
        m_bLandingGearDown = true;
    }

    if ( !GetCustomDataBool ( "locked", m_bLocked, true ) )
    {
        m_bLocked = false;
    }

    // Grab the "specialState" data
    if ( GetCustomDataInt ( "specialState", iTemp, true ) )
    {
        m_usAdjustableProperty = static_cast < unsigned short > ( iTemp );
    }
    else
    {
        m_usAdjustableProperty = 0;
    }

    // Grab the "color" data
    char szTemp [ 256 ];
    if ( GetCustomDataString ( "color", szTemp, 256, true ) )
    {
        char* sz1 = strtok ( szTemp, "," );
        char* sz2 = strtok ( NULL, "," );
        char* sz3 = strtok ( NULL, "," );
        char* sz4 = strtok ( NULL, "," );
        if ( sz1 )
            m_Color.SetColor1 ( atoi ( sz1 ) );
        if ( sz2 )
            m_Color.SetColor2 ( atoi ( sz2 ) );
        if ( sz3 )
            m_Color.SetColor3 ( atoi ( sz3 ) );
        if ( sz4 )
            m_Color.SetColor4 ( atoi ( sz4 ) );
    }            

    if ( GetCustomDataInt ( "paintjob", iTemp, true ) )
        m_ucPaintjob = static_cast < unsigned char > ( iTemp );

    if ( GetCustomDataString ( "upgrades", szTemp, 256, true ) )
    {
        if ( m_pUpgrades )
        {
            if ( strcmp ( szTemp, "all" ) == 0 )
            {
                m_pUpgrades->AddAllUpgrades ();
            }
            else
            {
                bool bTemp = true;
                while ( char* token = strtok ( ( bTemp ) ? szTemp : NULL, "," ) )
                {
                    bTemp = false;
                    unsigned short usUpgrade = static_cast < unsigned short > ( atoi ( token ) );
                    if ( CVehicleUpgrades::IsValidUpgrade ( usUpgrade ) )
                    {
                        m_pUpgrades->AddUpgrade ( usUpgrade );
                    }
                }
            }
        }
    }

    if ( GetCustomDataString ( "plate", szTemp, 9, true ) )
    {
        SetRegPlate ( szTemp );
    }

    if ( GetCustomDataInt ( "interior", iTemp, true ) )
        m_ucInterior = static_cast < unsigned char > ( iTemp );

    if ( GetCustomDataInt ( "dimension", iTemp, true ) )
        m_usDimension = static_cast < unsigned short > ( iTemp );

    return true;
}
示例#7
0
bool CVehicle::ReadSpecialData ( void )
{
    // Grab the "posX" data
    if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) )
    {
        CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the "posY" data
    if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) )
    {
        CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the "posZ" data
    if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) )
    {
        CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the "rotX", "rotY" and "rotZ" data
    GetCustomDataFloat ( "rotX", m_vecRotationDegrees.fX, true );
    GetCustomDataFloat ( "rotY", m_vecRotationDegrees.fY, true );
    GetCustomDataFloat ( "rotZ", m_vecRotationDegrees.fZ, true );

    // Wrap them around 360
    m_vecRotationDegrees.fX = WrapAround ( m_vecRotationDegrees.fX, 360.0f );
    m_vecRotationDegrees.fY = WrapAround ( m_vecRotationDegrees.fY, 360.0f );
    m_vecRotationDegrees.fZ = WrapAround ( m_vecRotationDegrees.fZ, 360.0f );

    // Set the respawn matrix
    SetRespawnPosition ( m_vecPosition );
    SetRespawnRotationDegrees ( m_vecRotationDegrees );

    // Grab the "model" data
    int iTemp;
    if ( GetCustomDataInt ( "model", iTemp, true ) )
    {
        // Is it valid?
        if ( CVehicleManager::IsValidModel ( iTemp ) )
        {
            // Remember it and generate a new random color
            SetModel ( static_cast < unsigned short > ( iTemp ) );

            m_usAdjustableProperty = 0;
        }
        else
        {
            CLogger::ErrorPrintf ( "Bad 'model'(%d) id specified in <vehicle> (line %u)\n", iTemp, m_uiLine );
            return false;
        }
    }
    else
    {
        CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <vehicle> (line %u)\n", m_uiLine );
        return false;
    }

    // Grab the variant data
    if ( GetCustomDataInt ( "variant1", iTemp, true ) )
    {
        m_ucVariant = static_cast < unsigned char > ( iTemp );
    }
    if ( GetCustomDataInt ( "variant2", iTemp, true ) )
    {
        m_ucVariant2 = static_cast < unsigned char > ( iTemp );
    }
    if ( m_ucVariant == 254 && m_ucVariant2 == 254 )
        CVehicleManager::GetRandomVariation ( m_usModel, m_ucVariant, m_ucVariant2 );

    // Grab the "turretX" data
    if ( GetCustomDataFloat ( "turretX", m_fTurretPositionX, true ) )
    {
        m_fTurretPositionX = ConvertDegreesToRadians ( m_fTurretPositionX );
    }

    // Grab the "turretY" data
    if ( GetCustomDataFloat ( "turretY", m_fTurretPositionY, true ) )
    {
        m_fTurretPositionY = ConvertDegreesToRadians ( m_fTurretPositionY );
    }

    // Grab the "health" data
    if ( GetCustomDataFloat ( "health", m_fHealth, true ) )
    {
        if ( m_fHealth < 0.0f )
            m_fHealth = 0.0f;
    }

    // Grab the "Sirens" data
    if ( !GetCustomDataBool ( "sirens", m_bSirenActive, true ) )
    {
        m_bSirenActive = false;
    }

    // Grab the "landingGearDown" data
    if ( !GetCustomDataBool ( "landingGearDown", m_bLandingGearDown, true ) )
    {
        m_bLandingGearDown = true;
    }

    if ( !GetCustomDataBool ( "locked", m_bLocked, true ) )
    {
        m_bLocked = false;
    }

    // Grab the "specialState" data
    if ( GetCustomDataInt ( "specialState", iTemp, true ) )
    {
        m_usAdjustableProperty = static_cast < unsigned short > ( iTemp );
    }
    else
    {
        m_usAdjustableProperty = 0;
    }

    // Grab the "color" data
    char szTemp [ 256 ];
    if ( GetCustomDataString ( "color", szTemp, 256, true ) )
    {
        uchar ucValues[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        char* sz1 = strtok ( szTemp, ", " );
        if ( sz1 )
            ucValues[0] = atoi ( sz1 );

        int i;
        for ( i = 1 ; i < 12 ; i++ )
        {
            char* szn =  strtok ( NULL, ", " );
            if ( !szn )
                break;
            ucValues[i] = atoi ( szn );
        }

        if ( i == 3 || i == 6 || i == 9 || i == 12 )
        {
            m_Color.SetRGBColors (  SColorRGBA ( ucValues[0], ucValues[1], ucValues[2], 0 ),
                                    SColorRGBA ( ucValues[3], ucValues[4], ucValues[5], 0 ),
                                    SColorRGBA ( ucValues[6], ucValues[7], ucValues[8], 0 ),
                                    SColorRGBA ( ucValues[9], ucValues[10], ucValues[11], 0 ) );
        }
        else
        {
            m_Color.SetPaletteColors ( ucValues[0], ucValues[1], ucValues[2], ucValues[3] );
        }
    }            

    if ( GetCustomDataInt ( "paintjob", iTemp, true ) )
        m_ucPaintjob = static_cast < unsigned char > ( iTemp );

    if ( GetCustomDataString ( "upgrades", szTemp, 256, true ) )
    {
        if ( m_pUpgrades )
        {
            if ( strcmp ( szTemp, "all" ) == 0 )
            {
                m_pUpgrades->AddAllUpgrades ();
            }
            else
            {
                bool bTemp = true;
                while ( char* token = strtok ( ( bTemp ) ? szTemp : NULL, ", " ) )
                {
                    bTemp = false;
                    unsigned short usUpgrade = static_cast < unsigned short > ( atoi ( token ) );
                    if ( CVehicleUpgrades::IsValidUpgrade ( usUpgrade ) )
                    {
                        m_pUpgrades->AddUpgrade ( usUpgrade );
                    }
                }
            }
        }
    }

    if ( GetCustomDataString ( "plate", szTemp, 9, true ) )
        SetRegPlate ( szTemp );

    if ( GetCustomDataInt ( "interior", iTemp, true ) )
        m_ucInterior = static_cast < unsigned char > ( iTemp );

    if ( GetCustomDataInt ( "dimension", iTemp, true ) )
        m_usDimension = static_cast < unsigned short > ( iTemp );

    if ( !GetCustomDataBool ( "collisions", m_bCollisionsEnabled, true ) )
        m_bCollisionsEnabled = true;

    if ( GetCustomDataInt ( "alpha", iTemp, true ) )
        m_ucAlpha = static_cast < unsigned char > ( iTemp );

    bool bFrozen;
    if ( GetCustomDataBool ( "frozen", bFrozen, true ) )
        m_bIsFrozen = bFrozen;

    return true;
}
示例#8
0
double Noise::FindNoise(int x)
{
	x = WrapAround(x);
	int n = (x << 13) ^ x;
	return (double)(1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
示例#9
0
 // Get a data index and advance.
 int32_t GetDataIdxAndAdvance() {
   CHECK(!IsEnd());
   int32_t ret_idx = num_data_this_epoch_++ + data_idx_begin_;
   return WrapAround(ret_idx);
 }