Exemplo n.º 1
0
sf::SoundBuffer const &RessourceManager::loadSound(std::string const &name)
{
    std::map<std::string, sf::SoundBuffer*>::const_iterator search;

    search = _sounds.find(name);
    if (search != _sounds.end())
        return *search->second;

    sf::SoundBuffer* buffer = new sf::SoundBuffer;
    std::string fullName = SOUNDS_PATH + name;
    if (!buffer->loadFromFile(fullName.c_str()))
        throw errFile("Failed to load: " + fullName);
    _sounds.insert(std::make_pair(name, buffer));
    return *buffer;
}
Exemplo n.º 2
0
sf::Font const &RessourceManager::loadFont(std::string const &name)
{
    std::map<std::string, sf::Font*>::const_iterator search;

    search = _fonts.find(name);
    if (search != _fonts.end())
        return *search->second;

    sf::Font* font = new sf::Font;
    std::string fullName = FONTS_PATH + name;

    font->loadFromFile(fullName.c_str());
    if (font == NULL)
        throw errFile("Failed to load: " + fullName);
    _fonts.insert(std::make_pair(name, font));
    return *font;
}
Exemplo n.º 3
0
sf::Texture const &RessourceManager::loadImage(std::string const &name)
{
    std::map<std::string, sf::Texture*>::const_iterator search;

    search = _textures.find(name);
    if (search != _textures.end())
        return *search->second;

    sf::Texture* texture = new sf::Texture;
    std::string fullName = IMAGES_PATH + name;

    texture->loadFromFile(fullName.c_str());
    if (texture == NULL)
        throw errFile("Failed to load: " + fullName);
    _textures.insert(std::make_pair(name, texture));
    return *texture;
}
Exemplo n.º 4
0
float sensor::GetDistance()
{
#if SENSOR
    QByteArray Bresponse;
    QString response;


    if (serial.isOpen() && serial.isWritable())
    {
        //Préparation de la trame
        QByteArray ba = QString("DIST").toLocal8Bit(); //conversion QString -> QByteArray
        ba.append("\r");
        //serial.clear();
        serial.write(ba);
        //serial.flush();
        serial.waitForBytesWritten(-1);
        //while(serial.flush());

        qDebug() << "Demande de distance" << endl;

        //Attente datas disponibles
        //while(!serial.waitForReadyRead(10));

        //Récupération de la distance (valeur  = 0 to 1023)
        while(serial.waitForReadyRead(500))
        {
            //serial.flush();
            //serial.waitForReadyRead(10);
            Bresponse = serial.readAll();
            response += QString(Bresponse);
            qDebug() << "response : " << response << endl;
            if(response.contains('\n'))
                break;
        }

        //Calcul de la distance en mm
        float dist = COEFA * response.toFloat() + COEFB;


        if(response.toFloat() < 10)//Si obstacle trop proche du capteur
            return 0;
        else if(response.toFloat() > 1020)//Si obstacle trop loin du capteur
            return 1000;
        else
            return dist;
    }
    else
    {
        qDebug() << "ERREUR de Port COM" << endl;

        QFile errFile(QCoreApplication::applicationDirPath() + ERROR);
        QTextStream stream_log(&errFile);
        errFile.open(QIODevice::WriteOnly | QIODevice::Text);

        stream_log << "Erreur de port COM (Arduino SENSOR)." << endl;
        errFile.close();
        exit(EXIT_PRB_PORT_COM_GRBL);
    }

    return 0;
#else
    return 45.45;
#endif
}