[WIP] Kairy - A 2D Game Framework

Discussion in '3DS - Homebrew Development and Emulators' started by _Nanni, Oct 22, 2015.

  1. _Nanni
    OP

    _Nanni Newbie

    Newcomer
    5
    23
    Sep 4, 2015
    Italy
    Kairy - A 2D Game Framework

    Hi, I'm Nanni one of the creators of the original Lua Player Plus.
    Currently I'm working on a C++11 2D game framework for the 3DS named Kairy.

    Right now the project is a WIP, many things don't work as expected and there are many bugs, but the library is still usable to make games. It's also pretty fast.

    The library is heavily inspired to Cocos2D and SFML, so many things are similar.

    This is a list of some supported features:

    • Kairy can be compiled for Windows, Linux and Mac making your life super easy when you want only to test the appearance of your game. It depends on GLEW, OpenGL and OpenAL. You should build it by yourself (for instance on Windows by adding all the source to a Visual Studio solution) but i'm planning to write a CMake file.
    • Tmx maps loading and rendering (with support for animated tiles)
    • A complete input engine
    • Loading of Bitmap Fonts and TTF (using stb_truetype) fonts
    • A resource manager to avoid loading of textures twice
    • Rich 2D math library (Vectors and Rectangles)
    • A decent scene graph
    • A class for images manipulation
    • Actions
    • Basic UI
    • A working Sound class
    • Some third party libraries are included in Kairy itself (like Box2D, tinyxml2 ... )
    Here is an example to show how powerful Kairy is:

    Code:
    #include <Kairy/Kairy.h>
    
    USING_NS_KAIRY;
    
    class TestScene : public Scene
    {
    public:
        bool onCreate() override
        {
            auto sprite = Sprite::create("assets/sprite.png");
       
            sprite->setPosition((getScreenSize(Screen::Top) -
                sprite->getSize()) / 2.0f);
       
            sprite->runAction(RepeatForever::create(RotateBy::create(1.0f, 120.0f)));
       
            addChild(sprite);
       
            auto triangle = TriangleShape::create(Vec2(-30, 30), Vec2(0, 0), Vec2(30, 30));
            triangle->setPosition((getScreenSize(Screen::Bottom) - triangle->getSize()) / 2.0f);
            triangle->setColor(Color::Red);
            addChildBot(triangle);
       
            return true;
        }
    private:
    };
    
    int main(int argc, char* argv[])
    {
        auto device = RenderDevice::getInstance();
        auto audio = AudioDevice::getInstance();
        auto sceneManager = SceneManager::getInstance();
    
        device->init();
        audio->init();
    
        device->setQuitOnStart(true);
    
        sceneManager->changeScene(std::make_shared<TestScene>());
    
        while (device->isRunning())
        {
            sceneManager->update(device->getDeltaTime());
            sceneManager->draw();
    
            device->swapBuffers();
        }
    
        audio->destroy();
        device->destroy();
    
        return EXIT_SUCCESS;
    }
    
    And here is the result running on Citra:
    Warning: Spoilers inside!
    And here is the result running on Kairy compiled for Windows:
    Warning: Spoilers inside!

    If you like Kairy and you want to contribute, please help the project on GitHub.
    Currently I don't have a enough time to put on it so i will greatly appreciate your help.

    I've made Kairy to allow easily games creation for any interested C++ developer (or maybe because i wanted to play someting new on my 3DS...).

    I can't wait to see what you can do with it =)

    KNOWN BUGS:
    • Music streaming doesn't work (currently only wav mono files works)
    • Incomplete and shitty particle engine
    • PCM8 stereo playback is broken
    • RenderTexture doesn't work
    • CircleShape is broken
    • Threads creation inside classes could randomly crash
    • Converting some types of floats to strings (with Kairy utility functions or even with sprintf) will crash the 3DS
    • Incomplete UI
    • Incomplete Actions
    • Loading a Tmx map with a tsx tileset doesn't always work
    • Loading resources from zip files on the 3DS dont' work right now
    • Screenshots on Windows, Linux and Mac are upside down (I know the reason but i'm too lazy to fix it xD)
    • Directory class is super incomplete
    • Error handler isn't flawless

    LINKS:
    GitHub repository: https://github.com/CurryGuy/Kairy

    Current version compiled with lastest libctru: https://mega.nz/#!CMNDgJTS!o3fVM2efQ2dfLeVCTMhAddPH1FwI4yfspR_2RQEDFwk

    3DS compiled examples: https://mega.nz/#!Od80SK7Q!lDmSe2qP-cXJHZ-e0xpf-OUgJNS92GOlnUqfDPZuDVc
     
    Last edited by _Nanni, Oct 26, 2015
    730, cynosura, the assaf and 17 others like this.
  2. VegaRoXas

    VegaRoXas GBAtemp Regular

    Member
    290
    158
    Mar 29, 2015
    Gambia, The
    Nice! Keep it up :3
     
    Margen67 likes this.
  3. SLiV3R

    SLiV3R 3DS Friend Code: 0473-9069-2206

    Member
    2,202
    1,044
    Jan 9, 2006
    Cool! Looking great :)
     
    Margen67 likes this.
  4. Pacheko17

    Pacheko17 かっこい男の子

    Member
    1,211
    1,145
    Jan 31, 2015
    Brazil
    Southern Confederation
    This looks cool, I'll mess around with it ^^
     
    Margen67 likes this.
  5. neobrain

    neobrain -

    Member
    306
    472
    Apr 25, 2014
    Did you happen to forget committing some shader related files? In particular, source/Kairy/Graphics/RenderDevice.cpp includes base_vsh_shbin.h, which I suppose is supposed to be generated from a compiled shader. Couldn't find any of that in the git tree, though.

    EDIT: Also, the downloads for the binaries demand some decryption key..
     
    Last edited by neobrain, Oct 22, 2015
  6. ringo1206

    ringo1206 Banned

    Banned
    173
    110
    Oct 14, 2015
    United States
    Cool! Just wondering my 2D game do you mean like "not 3D by perspective or stereoscopic 3D?

    I think a 2D game with 3D stereo. layers would be cool. Just a suggestion.
     
  7. _Nanni
    OP

    _Nanni Newbie

    Newcomer
    5
    23
    Sep 4, 2015
    Italy
    You're right, I've uploaded the shader to GitHub.
    Also I fixed the links =)
    That was my bad sorry
     
    neobrain likes this.
  8. machinamentum

    machinamentum GBAtemp Regular

    Member
    163
    450
    Jul 5, 2015
    United States
    Any reason why there's a kernel exploit embedded into this project? Games should be entirely userland applications, so I don't understand why it goes through the trouble of privilege escalation at start up.
     
    VegaRoXas likes this.
  9. _Nanni
    OP

    _Nanni Newbie

    Newcomer
    5
    23
    Sep 4, 2015
    Italy
    I was using it for testing purpose.
    I've removed it, now the project on GitHub should be clean
     
  10. BurningDesire

    BurningDesire GBAtemp Psycho!

    Member
    4,964
    5,814
    Jan 27, 2015
    United States
    Behind a screen reading news
    This is awesome! One question though... Why the name Kairy?
    Edit: one more question.. How do i set it up
     
    Last edited by BurningDesire, Oct 22, 2015
  11. Garcia98

    Garcia98 Hey! Listen!

    Member
    361
    188
    Sep 8, 2015
    Salamanca
    Like any other library?
     
  12. Gocario

    Gocario GBAFail'd

    Member
    640
    560
    Sep 5, 2015
    France
    Bourg Palette
    You should use the .hpp extension file for c++ header files.
     
  13. TheCruel

    TheCruel Developer

    Banned
    1,351
    2,884
    Dec 6, 2013
    United States
    Last edited by TheCruel, Oct 23, 2015
  14. cpasjuste

    cpasjuste GBAtemp Fan

    Member
    440
    641
    Aug 27, 2015
    France
    Hum this is interesting. I'm developing my own c++ gui/windows library since a few weeks now (with the very little time I have). Your project seems to be a lot more advanced than mine (holy crap :P). I will probably take a look/port my current project to your lib and see how it goes. I mean I'll probably work with you on this and trash my own lib (which work fine tought, snif...).

    I'll report in a few days ! By the way, nice work.

    Edit: just a little question, it seems it currently only allow to create textures from rgba8 pixels buffer isn't it ?
     
    Last edited by cpasjuste, Oct 23, 2015
  15. _Nanni
    OP

    _Nanni Newbie

    Newcomer
    5
    23
    Sep 4, 2015
    Italy
    First of all, sorry for the late reply:

    It's not 3D by perspective. Kairy supports stereoscopic 3D

    I don't know why Kairy... I always wanted to call something 'Kairy' lol
    However, you can setup Kairy copying the compiled files in the libctru folder (you should copy the Kairy lib and include directories to libctru)
    Or if you want you can compile Kairy yourself. Just grab the source from GitHub and do a "make install". That will compile and install the library.
    Then you can start a new project by using the example 0 (00-Template) as template from GitHub.

    You're right, I should. But I personally like the 'h' extensione more. I don't think it's a problem...

    GJ for porting SFML and OpenGL, didn't know of that Project. However I don't like SFML much that's why I made Kairy xD
    Feel free to take inspiration from my examples if you want =)

    I'm glad to hear that. Since the UI part of Kairy is very poor I will be happy to include your library in Kairy if you want =)
    Yeah it supports only the loading of RGBA8 pixel buffers. But I can easily add other formats too if it's a problem.
    (If you need to pass a RGB8 buffer just create a vector of Color and pass its data pointer to it. If you need something like RGB565 I can add it)


    I'm so happy of your feedbacks and comments. If you want to ask something or point out a problem, feel free to do it. I'm open to everything =)
     
    Margen67 and BurningDesire like this.
  16. ringo1206

    ringo1206 Banned

    Banned
    173
    110
    Oct 14, 2015
    United States

    Ok, cool!
     
  17. cpasjuste

    cpasjuste GBAtemp Fan

    Member
    440
    641
    Aug 27, 2015
    France
    Hi _Nanni,

    So I did find the time to play with it and to me its one of the best stuff we have on the 3ds. Your library is a lot more advanced than mine so .. my work is now useless :) People who know a little of c++ (which is my case, I mainly know c) should really take a look at it for games/gui. I ported my actual project (a 3ds menu) in a few minutes/hours.

    So here is my report/requests/questions :

    - I think that rectangleShape::create is broken on latest commit (undefined reference)
    - How would you reuse the same texture (image?) for multiple sprite ?
    - I would love to see the possibility to create textures from rgb8 (rgb24?) buffers (I was using this format for loading smdh icons as smea does :
    https://github.com/smealum/3ds_hb_menu/blob/master/source/smdh.c#L27)
    - I did loose some time trying to override the "onTouch" nodes functions before I understand it only work on "top level" nodes (ie. not a child). Its maybe for perfs reasons ?
    - I'm new to c++ sorry for the "common question" but are shared_ptr free(ed) automatically when allocated/created for a second time or do we need to free them manually ? If I understand correctly the answer is yes.
    - I think Box2D could be built only if needed for size saving (ifdef box2d?)
    - Do you have a preferred IDE ? I actually use code::blocks, its crap.

    I had a lot more (little/positive) reports yesterday but unfortunately my little brain forgot them, I'll comeback when they do comeback to me :)

    So once again, awesome work/lib, I do really, really like it. I'll try to help when possible but my time is very limited :x

    Thanks !
     
    Last edited by cpasjuste, Oct 27, 2015
  18. _Nanni
    OP

    _Nanni Newbie

    Newcomer
    5
    23
    Sep 4, 2015
    Italy
    Hi, I'm so happy you appreciate my work =)

    Now, about your questions:
    Yes the create function with no arguments was missing. I've added it.
    If the texture you should reuse is loaded from a file, just load every sprite from the same texture file. The ResourceManager will use the same data for all textures.
    If your texture is loaded from a buffer for instance, just set it to every sprite. (In the old version that was possibile with: sprite.getTexture() = texture. I've added the setTexture function now that's more intuitive). So if you have a texture and 2 sprites just do something like this:
    Code:
    Texture t(......);
    sprite1->setTexture(t);
    sprite2->setTexture(t);
    
    I've tweaked a bit the Sprite and Texture class. Now you can load textures from RGB8 pixel buffers.
    I'm sorry you have lost some time. It's just bad design, I will fix that
    Yeah, it gets deleted automatically.
    If you don't use Box2D the size of your executable shouldn't increase. If you meant remove it from the library itself I don't think it would matter.
    I like Visual Studio with Visual Assist X. I think is even better than CLion.
     
    Last edited by _Nanni, Oct 27, 2015
  19. cpasjuste

    cpasjuste GBAtemp Fan

    Member
    440
    641
    Aug 27, 2015
    France
    Hehe thanks for the fast additions/fixes and reply, your so nice. I've just setup CLion before your post, its already awsome to me in combination with kairy (I'll probably test VS in the future but I'm not a fan of windows/devkitpro mysys stuff).

    This is seriously a game changer, people really need to try/play with Kairy..

    Count on me for further reports and maybe some help on github (not sure of that when I see how nice kairy is already :).
     
    _Nanni likes this.