Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespace and file header: refactoring #4

Closed
6 tasks done
Gumichan01 opened this issue May 26, 2018 · 3 comments
Closed
6 tasks done

namespace and file header: refactoring #4

Gumichan01 opened this issue May 26, 2018 · 3 comments
Assignees
Projects
Milestone

Comments

@Gumichan01
Copy link
Owner

Gumichan01 commented May 26, 2018

  • AStyle formatting - astyle --pad-oper --pad-paren-in --pad-header --indent=spaces=4 -A1 --align-pointer=middle --align-reference=type
  • File name without LX
  • LunatiX → Lunatix
  • lx namespace
  • LX_<Module> replaced by <Module>
  • LX_<Class> replaced by <Class>

On 0.13.0

  • Structure
#include <LunatiX/LX_[Name].hpp>
namespace LX_<module>
{

class LX_<Class_name>
{
    ...
}

}

v0.14.0

#include <Lunatix/[Name].hpp>

namespace lx
{

namespace <ModuleName>
{
class <ClassName>
{
    ...
}

}

}

Why

Using the old syntax (LX_<module_name>::LX_<class_name>) could be very painful in a project that use a lot of class from the library. So it could be very difficult to read and understand the code without taking a look into the documentation. This new syntax, inspired by SFML, should clarify the code and make the use of namespaces and classes in LunatiX more convenient.

Be careful, this new syntax will break backward compatibility with the previous version.

Preview (on the example code in main.cpp)

  • In the current version
#include <LunatiX/Lunatix.hpp>

using namespace LX_Event;

int main( int argc, char** argv )
{
    if (!LX_Init())
    {
        LX_Log::log("Cannot load the library: %s", LX_getError());
	return -1;
    }

    // Information about how to build the window
    LX_Win::LX_WindowInfo info;
    LX_Win::LX_loadWindowConfig(info);
    info.w = 256;
    info.h = 256;

    LX_Win::LX_Window w(info);
    const std::string s = "data/bullet.png";
    LX_Graphics::LX_Sprite sprite(s, w);
    const LX_Graphics::LX_ImgRect position = { { 0, 0 }, 256, 256};
    LX_EventHandler ev;
    bool go = true;

    while (go)
    {
        while (ev.pollEvent())
        {
            switch (ev.getEventType())
            {
            case LX_EventType::QUIT:
                go = false;
                break;
            default:
                break;
            }
        }

        w.clearWindow();
        sprite.draw(position);
        w.update();
        LX_Timer::delay(33);
    }

    LX_Quit();
    return 0;
}
  • In the next version
#include <Lunatix/Lunatix.hpp>

int main( int argc, char** argv )
{
    if ( !lx::init() )
    {
        lx::Log::info( "Cannot load the library: %s", LX::getError() );
        return -1;
    }

    // Information about how to build the window
    lx::Win::WindowInfo info;
    lx::Win::loadWindowConfig( info );
    info.w = 256;
    info.h = 256;

    lx::Win::Window w( info );
    const std::string s = "data/bullet.png";
    lx::Graphics::Sprite sprite( s, w );
    const lx::Graphics::ImgRect position = { { 0, 0 }, 256, 256 };
    lx::Event::EventHandler ev;
    bool go = true;

    while ( go )
    {
        while ( ev.pollEvent() )
        {
            switch ( ev.getEventType() )
            {
            case lx::Event::EventType::QUIT:
                go = false;
                break;
            default:
                break;
            }
        }

        w.clearWindow();
        sprite.draw( position );
        w.update();
        lx::Time::delay( 33 );
    }

    lx::quit();
    return 0;
}
@Gumichan01 Gumichan01 added this to the 0.14.0 milestone May 26, 2018
@Gumichan01 Gumichan01 self-assigned this May 26, 2018
This was referenced May 26, 2018
@Gumichan01 Gumichan01 added this to To do in LX v0.14.0 May 28, 2018
@Gumichan01 Gumichan01 moved this from To do to In progress in LX v0.14.0 Jun 23, 2018
@Gumichan01
Copy link
Owner Author

⚠️ Those commits breaks compatibility with the previous version

@Gumichan01
Copy link
Owner Author

Gumichan01 commented Jun 29, 2018

  1. lx::<Module>
  2. LX_Module replaced by Module

Commits:

@Gumichan01
Copy link
Owner Author

LX_ prefix removed — a33a767

LX v0.14.0 automation moved this from In progress to Done Jun 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
LX v0.14.0
  
Done
Development

No branches or pull requests

1 participant