Bienvenue, Invité. Merci de vous connecter ou de vous inscrire. Avez-vous oublié d'activer ?

Voir les contributions

Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.


Sujets - nicooomg

Pages: [1]
1
Bonjour,

J'aimerais voir à l'avenir quelques ajouts dans les constructeurs de la classe Vector2;
Je ne sais pas pour vous, mais je tombe souvent sur des minis hacks à mettre en place autour de la construction car les choix sont quand meme assez legers !

    Vector2();
    Vector2(T X, T Y);
    template <typename U>
    explicit Vector2(const Vector2<U>& vector);
 

Est-ce que un jour on pourrait avoir quelque chose de ce style ?
    template<typename... Types>
    Vector2(const std::tuple<Types...>& types) : x(std::get<0>(types)), y(std::get<1>(types)) {}

Les mini-hacks ne sont pas très lourds, mais ils permettront au moins une plus grande lisibilité !

Merci,

nico

2
Général / [sfml 2] sf::Mouse events
« le: Février 27, 2013, 10:13:22 am »
Bonjour,

J'aimerais simplement savoir comment verifier un double click ? :o
Y aurait-il quelque chose du style:


        sf::Event event;
        while(App.pollEvent(event))
        {
           
            if(event.type == sf::Mouse::DoubleClick)
            {
               
            }
        }

Merci d'avance

nico

3
Fenêtrage / sf::Window::pollEvent bloquant !
« le: Janvier 16, 2013, 12:31:59 pm »
Bonjour,

Je suis tombé hier sur un problème que je n'arrive pas à résoudre, en effet, la fonction Window::pollEvent semble bloquer mon programme !

Ceci arrive quand j'appuie sur la touche LAlt du clavier.
-> Quand j'appuie une fois, la fonction bloque
-> Quand j'appuie en continue, la fonction ne bloque pas
-> Si je ré appuie sur une touche, ou autre, la fonction se débloque !

Comment résoudre le problème de la touche LAlt ?
Merci d'avance

nico

4
Système / sf::Rect contenant un Point
« le: Janvier 10, 2013, 08:10:28 pm »
Bonjour,

j'aimerais savoir comment faire pour verifier qu'un sf::Rect contient bien un point.
Le probleme, est que ce rectangle est en biais

exemple:


Comment faire ?

merci d'avance,

nico

5
Graphique / [Résolu] [SFML2] sf::View qui redimensionne un sf::Sprite
« le: Janvier 10, 2013, 12:57:13 am »
Bonjour :)

J'ai un problème en utilisant une view.

Voici le code, lorsque je charge ma texture de fond, je configure ma view:

        if(load_map_order>=0)
        {
            // chargement de la map

            m_game.getRenderer().mapView().setSize(800, 600-getToolboxHeight());
            m_game.getRenderer().mapView().setCenter(400, (600-getToolboxHeight())/2);
            load_map_order = -1;
        }

Et bien sur, l'affichage:
        if(m_game.getRenderer().hasMapTexture())
        {
           /// mise à jour de la vue, pour le scrolling, la fonction n'appelle que sf::View::move
            m_game.getRenderer().updateViews({0, 0, 0, getToolboxHeight()/2});
          /// on prend la vue pour le scrolling
            App.setView(m_game.getRenderer().mapView());
          /// dessine la map
            App.draw(m_game.getRenderer().mapSprite());
          /// vue normale !
            App.setView(App.getDefaultView());
        }


Le problème, c'est que.. voici un screenshot en fichier joint!

Quel est le problème ?

Merci d'avance,

nico


[attachment deleted by admin]

6
Graphique / Ecran blanc & loadFromMemory
« le: Octobre 18, 2012, 02:35:34 am »
Bonjour,

j'essaye de precharger des textures en memoire, pour un chargement plus dynamique.
Voici ma classe qui va garder tout en memoire...
class Memory
{
        public:
                Memory() {};
                ~Memory()
                {
                    std::cout << "Call ~Memory() " << std::endl;
                }

        /// Pas important.
                void preload(const std::string& pack)
                {
                    Reader* own_reader = new Reader();
                    Node* child = own_reader->Read(pack);

                    m_nodes.insert(std::make_pair(Filesystem::extractFilename(pack),
                                    std::make_pair(own_reader, child)));
                }

        /// Ceci, marche a merveille ! Aucune exception levée
                void loadGFX(const std::string& pack, const long id)
                {
                    try
                    {
                        Node& node(m_nodes[pack].second->find(id));
                        MemoryRessource<sf::Texture>* res = new MemoryRessource<sf::Texture>(node.get(m_nodes[pack].first->stream()));
                m_loaded_gfx.insert(std::make_pair(MemoryKey(node.getId(), node.getOffset()), res));
                    }
                    catch(...)
                    {
                        throw false;
                    }
                }


                Node& operator [] (const std::string& key) { return *(m_nodes[key].second); }
        Node& operator [] (const char* key) { return *(m_nodes[std::string(key)].second); }

                inline bool isLoaded(const MemoryKey& key) { return m_loaded_gfx.find(key) != m_loaded_gfx.end(); }

        template<class S>
                static inline S& getGFX(const long id) /// longer to perform ...!
                {
                    std::for_each(std::begin(m_loaded_gfx), std::end(m_loaded_gfx), [&](std::pair<MemoryKey, MemoryRessource<sf::Texture>*> res)
            {
                if(res.first.first == id) { return res.second->get(); }
            });
                }

        /// Retournera un sf::Texture
        template<class S>
                static inline S& getGFX(const MemoryKey& key)
                {
                    return m_loaded_gfx[key]->get();
                }

        private:

                static std::map<std::string, std::pair<Reader*, Node*>> m_nodes;

                static std::map<MemoryKey, MemoryRessource<sf::Texture>*> m_loaded_gfx;
};

En premier, je fais un void preload(), pas important, cela va remplir le membre m_nodes.
Ensuite, je vais faire loadGFX() avec un identifiant. Cela va charger une sf::Texture dans m_loaded_gfx.
Voici la classe MemoryRessource:

template<class S>
class MemoryRessource
{
public:
    MemoryRessource() {}
    MemoryRessource(const std::vector<char>& bytes) :
        m_buffer()
        {
            if(!m_buffer.loadFromMemory(&bytes[0], bytes.size()))
            {
                std::cout << "Failed to load from memory ! " << std::endl;
                throw false;
            }
            else
            {
                std::cout << "Loaded " << bytes.size() << std::endl;
            }
        }
    ~MemoryRessource()
    {
        std::cout << "Destroying !"<<std::endl;
    }

    inline const S& get() const { return m_buffer; }
private:
    S m_buffer;
};

On remarquera que si le loadFromMemory est mauvais, une exception est levée, et attrapée dans loadGFX.
Jusqu'ici , tout va bien.
Voici maintenant le main :

short SplashScreen::Run()
{


    /// Preloading archives
    std::for_each(std::begin(Config::ARCHIVES), std::end(Config::ARCHIVES), [&](const std::string& pack)
    {
        std::string full_name = pack;
        full_name += Config::EXT;
        m_game.getMemory().preload(full_name); // Tout va bien ...
    });

    Memory mem;

    Node& gfx(mem["Graphics"]);

    std::vector<long> ids_to_load = {2, 5};

    std::for_each(std::begin(ids_to_load), std::end(ids_to_load), [&](long id)
    {
        try
        {
            mem.loadGFX("Graphics", id);
        }
        catch(...)
        {
            std::cout << "Could not load: " << "Graphics:" << id << std::endl;
        }
    });
/// Aucune exception levée, nous avons donc nos sf::Texture chargés en mémoire

    std::cout << "loading texture into sprite ......."<<std::endl;
    sf::Sprite s_sprite(mem.getGFX<sf::Texture>(static_cast<long>(2)));
    std::cout << "OK loaded"<<std::endl;


    /// Rendering loop
    while(m_game.getRenderer().getApp().isOpen() && m_game.isRunning())
    {
        /// Clearing the window
        m_game.getRenderer().getApp().clear();
        sf::Event event;

        while(m_game.getRenderer().getApp().pollEvent(event))
        {
            /// Event handling

                /// SFML
            if(event.type == sf::Event::Closed)
            {
                /// This will automatically terminate the networker thread & nicely exit the game
                m_game.crash();
            }
        }

        /// Drawings (SFML)
            /// The sprite (background)
        m_game.getRenderer().getApp().draw(s_sprite);

        /// Displayings
        m_game.getRenderer().getApp().display();

    }

    return -1;
}

Bref, aucune erreur d'affichée malgrès les nombreuses conditions et try{}, pourtant: écran blanc :|

Une idée quelqu'un ?

Merci d'avance, nico

7
Graphique / Fade in & Fade out
« le: Août 27, 2012, 05:54:58 am »
Bonjour,

Mon jeu possede plusieurs ecrans differents deja en place, et j'aimerais faire un bel effet de transition avec Fade in & fade out.

L'appel de la transition se fait en dehors du thread de rendu graphique.

Voici la classe:

#ifndef FADE_H_INCLUDED
#define FADE_H_INCLUDED

/// Used for screen fading.
#include <SFML/Graphics.hpp>

class Fade
{
public:
    Fade() : m_fadein(false), m_fadeout(false), m_started(false), m_rect(sf::RectangleShape()), m_alpha(0), m_goal(0) {  };
    ~Fade() {  }

    /// Called by the secondary thread
    void FadeOut() {
        /// Setting the flag to true, so the rendering thread knows that he has to fade out the screen
        /// Regular screen to full black screen.
        m_fadeout = true; m_alpha = 0; m_goal = 255;
        m_rect.setFillColor(sf::Color(0,0,0,0));
    }
    /// Called by the secondary thread
    void FadeIn() {
        /// Setting the flag to true, so the rendering thread knows that he has to fade in the screen
        m_fadein = true; m_alpha = 255; m_goal = 0;
        //m_rect.setFillColor(sf::Color(0,0,0,255));
    }

    /// Simply returns the shape for displaying
    inline sf::RectangleShape& getShape() { return m_rect; }

    /// Used by the main loop, if this returns true, the thread will draw it
    inline bool doFade() {
        if(m_fadein && (m_alpha > m_goal)) // black > screen
        {
            m_alpha--;
            m_rect.setFillColor(sf::Color(0,0,0,m_alpha));
            return true;
        }
        else if(m_fadeout && (m_alpha < m_goal)) // screen > black
        {
            m_alpha++;
            m_rect.setFillColor(sf::Color(0,0,0,m_alpha));
            return true;
        }
        else { return false; }
    }
   
    /// Used by the secondary thread, if this is true, it means the main thread is fading. Some sort of mutex :P
    inline bool Fading() const { return (m_started); }
   
    /// Used by the main thread to know if he has to perform a fade
    inline bool requestFade() const { return (m_fadein | m_fadeout); }

    /// Both used by the main thread to change the flags, so the secondary thread will know that he is fading. (cf: Fading())
    void startFading() { m_started = true; }
    void doneFading() { m_started = false; m_fadein = false; m_fadeout = false; }
    inline static const unsigned int fadingTime() { return fading_time; }

private:

    /// Flag: Fade in action
    bool m_fadein;
    /// Flag: Fade out action
    bool m_fadeout;
    /// Flag: if theres a fade processing
    bool m_started;

    /// SFML's shape
    sf::RectangleShape m_rect;

    /// Current alpha.
    unsigned int m_alpha;
    /// Alpha to reach
    unsigned int m_goal;

    static const unsigned int fading_time = 10; // in ms

};



#endif // FADE_H_INCLUDED


Quand je veux faire un fade, de mon thread secondaire, je fais ceci:
    m_gameui.getRenderer().getFader().FadeOut(); // Appel a fade out : ecran > ecran noir
    nextScreen(); // Simple routine qui permet a l'ecran de se mettre a jour sous l'ecran noir
    while(m_gameui.getRenderer().getFader().Fading()) {} // On attend pendant que le fade se termine (donc ecran noir
    m_gameui.getRenderer().getFader().FadeIn(); // Et hop on retourne au nouvel ecran


Et mon thread principal:

short LoginScreen::Run()
{
    m_desktop.GetEngine().LoadThemeFromFile("Data/css/login.css");

    /// Add the UI to the window
    m_desktop.Add(getScreen());
    /// Rendering loop
    while(m_game.getRenderer().getApp().isOpen() && m_game.isRunning())
    {
        /// Clearing the window
        m_game.getRenderer().getApp().clear();


        sf::Event event;
        while(m_game.getRenderer().getApp().pollEvent(event))
        {
            /// Event handling
                /// SFGUI
            m_desktop.HandleEvent(event);
                /// SFML
            if(event.type == sf::Event::Closed)
            {
                /// This will automatically terminate the networker thread & nicely exit the game
                m_game.crash();
            }
        }
        m_game.getRenderer().getApp().resetGLStates();
        /// Drawings (SFGUI)
            /// UI
        if(changeScreen())
        {
            oldScreen()->Show(false);
            m_desktop.Remove(oldScreen());
            getScreen()->Show(true);
            m_desktop.Add(getScreen());
        }

        /// Fading out (screen to black)
        if(m_game.getRenderer().getFader().requestFade())
        {
            m_game.getRenderer().getFader().startFading();
        }
        if(m_game.getRenderer().getFader().Fading())
        {
            if(m_game.getRenderer().getFader().doFade())
            {
                m_game.getRenderer().getApp().draw(m_game.getRenderer().getFader().getShape());
            }
            else
            {
                m_game.getRenderer().getFader().doneFading();
            }
        }

        /// Displayings
        m_desktop.Update(0.f);
        m_game.getRenderer().display(m_game.getRenderer().getApp());
        m_game.getRenderer().getApp().display();

    }

    return -1;
}

Le probleme ?
L'ecran devient tout noir d'un coup, et j'ai acces a l'ecran caché derriere ce noir.
Comment faire pour avoir une belle transition ?

Merci d'avance,

nico

8
Graphique / Probleme de conception
« le: Août 23, 2012, 05:31:38 pm »
Bonjour,

Je cherche a faire ceci:
- Un sprite, avec un texte en dessous, et que le tout soit clickable, et meme double-clickable.

J'utilise SFML 2 ainsi que SFGUI. Et je me demande s'il n'est pas possible de combiner les deux.
Peut etre une classe qui à sf::Sprite plus un sfg::Button (invisible) en tant que membre, et de plus, qui hérite de sfg::Widget publiquement pour pouvoir l'ajouter au conteneurs de SFGUI !

Est-ce une bonne facon de faire?

Merci, nico

9
Graphique / Affichage d'une partie d'un sprite
« le: Juin 27, 2012, 06:19:40 pm »
Bonjour :)

Alors voici ma fonction:
void MapScroller::setViewport(const sf::IntRect& camera)
{
    mapsprite.setTextureRect(sf::IntRect(0, maptexture.getSize().y-winsz.y, winsz.x, winsz.y));
}
 

Le probleme: He bien, le rectangle d'affiche est toujours en haut a gauche ... !
Alors que normalement , je devrais avoir: sf::IntRect(0, 600, 800, 600);

Comment faire pour afficher simplement une partie ?

merci d'avance, nico

10
Général / [segfault] Appel de RenderWindow::create()
« le: Juin 25, 2012, 05:16:38 pm »
Bonjour,

Je viens de reinstaller Code::Blocks, avec pour compilateur: MinGW ayant GCC 4.7.0 !
J'utilise SFML 2 !
De: http://freefr.dl.sourceforge.net/project/mingw/Installer/mingw-get-inst/mingw-get-inst-20120426/mingw-get-inst-20120426.exe

Mon code compilait très bien avant cette mise à jour...
Maintenant...:

Citer
#0 6E182F29   sf::Window::Window(this=0x77af1bd1) (D:\developpement\sfml-master\src\SFML\Window\Window.cpp:47)
#1 00919519   sf::RenderWindow::RenderWindow(this=0x77af1bd1) (D:\developpement\sfml-master\src\SFML\Graphics\RenderWindow.cpp:35)
#2 00402BCC   ?? () (??:??)
#3 004010B9   ?? () (??:??)
#4 00401284   ?? () (??:??)
#5 7694339A   KERNEL32!BaseCleanupAppcompatCacheSupport() (C:\Windows\syswow64\kernel32.dll:??)
#6 7EFDE000   ?? () (??:??)
#7 77A59EF2   ntdll!RtlpNtSetValueKey() (C:\Windows\system32\ntdll.dll:??)
#8 7EFDE000   ?? () (??:??)
#9 77A59EC5   ntdll!RtlpNtSetValueKey() (C:\Windows\system32\ntdll.dll:??)
#10 0040126C   ?? () (??:??)
#11 ??   ?? () (??:??)

Dans mon projet (C::B) j'ai
Citer
link options:
-lsfml-graphics-d
-lsfml-window-d
-lsfml-system-d
-lsfgui
-lopengl32

compile define:
SFML_STATIC
SFGUI_STATIC

Que faut-il faire?

merci, nico

11
Graphique / Suppression de widget sfgui
« le: Juin 14, 2012, 05:55:09 pm »
Bonjour,

Pas sur que ce soit le bon endroit, je tente ma chance quand meme!
Apres avoir fait une petite boite alert (une window, un bouton et un label), j'essaye de la detruire pour liberer la memoire.

J'utilise SFML 2.0 & SFGUI.

Le constructeur, pour voir un peu la bete:
AlertBox::AlertBox(const std::string& errortitle, const std::string& errortext) :
    display(true)
{
    // The window
    dialog = sfg::Window::Create(sfg::Window::Style::TITLEBAR);
    dialog->SetTitle(errortitle);


    // The layouter
    sfg::Box::Ptr box( sfg::Box::Create( sfg::Box::VERTICAL, 5.0f ) );

    // The elements
    text = sfg::Label::Create(errortext);
    btn = sfg::Button::Create("Ok");
    btn->GetSignal(sfg::Widget::OnLeftClick).Connect(&AlertBox::Destroy, this);

    box->Pack(text);
    box->Pack(btn, false);
    dialog->Add(box);
}

La fonction Destroy ne change que la variable membre "display" à false.

Dans ma boucle graphique, j'ai ceci:
        // Boucle sur les boites alert
        for(auto itr = m_window->GetPerennials()->List().begin(); itr != m_window->GetPerennials()->List().end(); ++itr)
        {
                // Si l'objet n'a jamais été dessiné, on l'ajoute au sfg::Desktop
            if(itr->second->Display() && !itr->second->Drawn())
            {
                // La fonction AlertBox::GetDrawable retourne un sfg::Window::Ptr
                desktop.Add(itr->second->GetDrawable());
            }
            else if(!itr->second->Display())
            { // Ceci est quand on vient d'appuyer sur le bouton, et que la fonction Destroy a ete appellee
                        // On supprime le sfg::Window de sfg::Desktop
                desktop.Remove(itr->second->GetDrawable());
            }
        }
        m_window->Clear(); // sf::RenderWindow::Clear();
        desktop.Update( clock.restart().asSeconds() );
        m_window->RenderGUI(sfgui); // sfg::Display(m_window);
        m_window->Render(); // sf::RenderWindow::Display();
 

Et Quand j'appuie sur le bouton, he bien le sfg::Window ne disparait pas. Il reste sur l'ecran ! Neanmoins je ne peux plus interagir.
Il doit y avoir un probleme au niveau de Clear, ou Update.

Quelqu'un saurais me gider? :)
merci, nico

12
Graphique / Affichage d'écrans differents, flash d'un sprite
« le: Juin 10, 2012, 12:30:29 am »
Bonjour,
Je me suis mis pour de bon à la sfml apres avoir vu la comparaison sfml vs sdl du createur...

Je fais un jeu en 2D, et je vais avoir besoin de trois ecrans, un splash screen, le menu de connexion et le jeu lui meme, donc pour separer proprement ces ecrans, voici mon main:

int main()
{
    Window* w = new Window();

    std::vector<Screen*> Screens;
    Screens.push_back(new SplashScreen());
    //Screens.push_back(new LoginScreen());
    Screens.push_back(new Ingame());

    int iscreen = 0, temp;
    while(iscreen >= 0)
    {
        // On lance l'affichage
        temp = Screens[iscreen]->Run(w);
        // On vient de sortir de la boucle de Screen::Run()
        // Si temp est different, on met a jour les variables
        if(temp != iscreen)
        {
            delete Screens[iscreen];
            w->Clear();
            iscreen = temp;
        }
    }
    return EXIT_SUCCESS;
}

L'affichage du Splash se fait tres bien, mais apres quelques secondes (le temps que le splash passe, j'ai du mettre 2secondes) mon ecran commence a flasher l'image qu'il y avait dans le splash.

Voici le code du splash:
class SplashScreen: public Screen
{
    public:
        SplashScreen() {}
        ~SplashScreen() {}
        int Run (Window* App);

    private:
};

int SplashScreen::Run(Window* App)
{

    sf::Texture splash;
    splash.loadFromFile("Data/gui/splash/splashscreen.jpg");

    sf::Sprite spr(splash);

    sf::Clock clock;
    sf::Event event;

    clock.restart();


    while(App->Running()) {
        // Event processing.
        while(App->GetEvent(event) ) {
            //desktop.HandleEvent( event );

            // If window is about to be closed, leave program.
            if(Window::Closing(event)) {
                exit(0);
            }
        }
        std::cout << "splash screen"<<std::endl;
        if(clock.getElapsedTime() > sf::seconds(2)) // On reste sur cet ecran 2secs
        {
            return 1;
        }
        App->Draw(spr);
        App->Render();
    }
    return -1;
}

Infos:
App->Draw(spr) est un simple template pour faire appel à RenderWindow::draw();
App->Render() est un simple alias pour faire appel à RenderWindow::display();

Donc a la sortie du splash, comme on le voit dans le main, je fais un w->Clear(); (alias pour RenderWindow::clear()) et de plus, l'objet SplashScreen est détruit, donc le sprite & texture devraient logiquement disparaitres....
Mais a ce moment la, mon ecran flash, et si je le regarde plus de 30sec, je fais une crise d'épilepsie !

Quelqu'un a une idée?

nico.

Pages: [1]