Software design

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
danieLs0xFF
Posts: 14
Joined: Wed Aug 16, 2006 6:58 pm

Software design

Post by danieLs0xFF »

hi
i have a noob question :P, but i hope to get an answer

i'm trying to make a simple 2d application using irrlicht that will access a lyrics database and show them verse by verse like a powerpoint presentation

so basically my app will be :

Code: Select all

             splashscreen
               |
            menu (with list of songs)
         /     |                    \
  show          \                     quit
selected         \about screen
  song               (go back to menu)
  lyrics
(go back to menu
after all verses showed)

i will only use draw2DImage, and some Gui controls for buttons and song list


what is a good way to do this?
i searched a lot for open source games that have someting like i need but no luck,
the ones that i've found are not open source

i tried doing something like this:

while(device->run())
switch(APP_STATUS)
case STATUSMENU:
drawmenu();
...
etc...

but it's kind of a pain to manage everything in a single loop


this is more a software design question, not a "how to code one"

so if anybody feels like giving me some tips, or pseudo code something to start from?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Have you looked at the Demo example/tutorial? That has multiple stages to it but i think it probably handles it in the same way as you've been doing it.
Image Image Image
MarcoTMP
Posts: 37
Joined: Mon Aug 29, 2005 8:14 pm
Location: Dominican Republic
Contact:

Post by MarcoTMP »

I think your design is good. I should recomend you the use of states class instead of case for a cleaner code.

for example:

note: this is just to give you an idea, not the code itself. :wink:


The state class

Code: Select all

class state
{
...
    virtual void enter();
    virtual void run();
    virtual void exit();
...
}

then declare each of your screens in a diferent class

Code: Select all

class splash: public state
{
...
    void enter() {... draw splash screen}
    void run() {... wait for timer > 3 sec}
    void exit() {...}
...
}

class menu: public state
{
    ...
    void enter() {... draw menu screen}
    void run() {... 
        //transitions
        if (about_event) statemachine->changestate(statemachine->aboutscreen);
        if (show_liric) statemachine->changestate(statemachine->showliric);
        ...
    }
    void exit() {...}
    ...
}



your state machine

Code: Select all

class statemachine
{
    state* splashscreen;
    state* menu;
    ...

    void init()
    {
        splashscreen = new splash(this);
        menuscreen = new menu(this);
        ...
        currentstate = splashscreen;
    }

    void changestate(state* newstate)
    { 
        currentstate->exit();
        currentstate = newstate;
        currentstate->enter();
    }

    void run()
    {
        currentstate->run();
    }

    ...
}
then in your main code:

Code: Select all

class app
{
   ...
    void init()
    {
        statemachine.init(this);
    }

    void run()
    {
        while(device->run()) 
        {
            statemachine.run();
        }
    }
    ...
}


void main()
{
    app app1;
    app1.run();
}



hope this can help you.


Marco
danieLs0xFF
Posts: 14
Joined: Wed Aug 16, 2006 6:58 pm

Post by danieLs0xFF »

this is exactly what i was looking for :D
thank you
Post Reply