SFML community forums

General => SFML projects => Topic started by: mvl on January 19, 2014, 03:16:15 pm

Title: mage engine
Post by: mvl on January 19, 2014, 03:16:15 pm
hey this is a little beta engine I am making on top of sfml it currently only has 2 modules entity system and input module
it is called mage engine after the first name i have given it (mge which stands for mvl's  game engine)

the git repository can be found here:
https://github.com/unerize/mage-engine

any help is appreciated and if you add something i do not quite understand (i am not that good at c++ yet)
I would like to have a explanation.

also what do you think it is my first biblically released bit of code so any commentary is also appreciated
Title: Re: mage engine
Post by: Nexus on January 19, 2014, 03:47:20 pm
It seems to be a real trend to call every collection of some C++ files an "engine" :P

You should rather show us what your engine is actually capable of. Some code snippets that demonstrate how it can simplify things that are not possible with SFML directly.

Some things I noticed when quickly looking at the code:
I don't know what your exact plans are, but the GPL license will effectively prevent most people here from using your code.
Title: Re: mage engine
Post by: mvl on January 19, 2014, 04:24:01 pm
Ok the explanation I wanted to do that but not really had the time to at the and of this post I will post a short explanation of the modules.

How do you mean the GPL is not good I thought it was a open source licence that made you free to do with it want you want
is the LGPL better then?

I know it is not really a game engine yet but I am planing to make it one it is just not yet complete.

I did the things you said except the second and the two latest: the second because i don't really understand it,
the fifth for the same reason and the last because I don't really want to depend too much an c++11 and i am not really used to it
so i don't know a lot yet

explanation: entity system
a system for managing entities
you create a entity by creating a class that inherits entity
then you create a entity manager object add entities to it update and render it like this:

a ball entity example
ball.cpp
#include "entity_system/Entity.h"

class ball : public mge::Entity
{
        public:
                ball();

                void update(double delta);
                void render(sf::RenderWindow& window);
        protected:
        private:
};
 

and the main code
#include <SFML/Graphics.hpp>
#include "entity_system/entityManager.h"

int main()
{
    sf::VideoMode VMode(800, 600, 32);
    sf::RenderWindow Window(VMode, "SFMLCoder Tutorial - Empty Window");
    mge::entityManager manager();
    manager.add(new ball());

    while (Window.IsOpened())
    {
        sf::Event Event;
        while (Window.PollEvent(Event))
        {
            switch (Event.Type)
            {
            case sf::Event::Closed:
                Window.Close();
                break;
            default:
                break;
            }
        }
        manager.update(delta);
 
        Window.Clear(sf::Color(0, 255, 255));
        manager.draw(window);
        Window.Display();
    }
 
    return 0;
}
 

this code is written quickly and will most probably not work
Title: Re: mage engine
Post by: zsbzsb on January 19, 2014, 05:15:34 pm
How do you mean the GPL is not good I thought it was a open source licence that made you free to do with it want you want

Maybe you should read up on licenses  ;) Not all licenses are equal, not even open source licenses. The biggest problem with GPL is that it is a virus, it requires any code that uses a library that has a GPL to use also use a GPL license (because of derived works).

Quote
is the LGPL better then?

Not by much, the only difference is that if you link dynamically you don't need to use GPL/LGPL license.
Title: Re: mage engine
Post by: AlexAUT on January 19, 2014, 05:24:33 pm
this code is written quickly and will most probably not work

Why do you post it then? Where do you define delta? Where do you include you ball.hpp? Where is your ball.hpp? How should mge::entityManager manager(); work?

I skimmed over the code of your "engine" and saw some manual memory management (new Square()) but no deletes, so your entityManager is leaking because you do not delete the memory you allocated on the freespace. (erase will only delete the pointer but not the memory he points at). Two options to solve the problem.



AlexAUT

Title: Re: mage engine
Post by: mvl on January 19, 2014, 09:47:00 pm
this code is written quickly and will most probably not work

Why do you post it then? Where do you define delta? Where do you include you ball.hpp? Where is your ball.hpp? How should mge::entityManager manager(); work?

I skimmed over the code of your "engine" and saw some manual memory management (new Square()) but no deletes, so your entityManager is leaking because you do not delete the memory you allocated on the freespace. (erase will only delete the pointer but not the memory he points at). Two options to solve the problem.

  • Use the C++11 smartpointers std::unique_ptr / std::shared_ptr. So you don't have to call delete manually. (I highly recommend this way)
  • Delete the objects manually


AlexAUT



I didn't really have time yet to write a full explanation of everything and stuff I will certainly but Nexus asked for it so I quickly made this without even testing so...

and ball.cpp needed to be .h

also I am not really used to c++11 yet and smart pointers I might do a little research though

How do you mean the GPL is not good I thought it was a open source licence that made you free to do with it want you want

Maybe you should read up on licenses  ;) Not all licenses are equal, not even open source licenses. The biggest problem with GPL is that it is a virus, it requires any code that uses a library that has a GPL to use also use a GPL license (because of derived works).

Quote
is the LGPL better then?

Not by much, the only difference is that if you link dynamically you don't need to use GPL/LGPL license.

ok then
which licence do you recommend?

Title: Re: mage engine
Post by: zsbzsb on January 19, 2014, 10:07:01 pm
which licence do you recommend?

I personally like ZLIB/PNG license (same as SFML), but another good one is the MPL (http://www.mozilla.org/MPL/). A neat tool I found is TLDRLegal (http://www.tldrlegal.com/) which you may also find useful.  ;)
Title: Re: mage engine
Post by: FRex on January 19, 2014, 10:21:53 pm
Boost and MIT/X11 ones are good too.
OSI has a few lists of certified licenses too: http://opensource.org/licenses
Title: Re: mage engine
Post by: mvl on January 21, 2014, 04:45:47 pm
can I ask another quistion regarding the code

  • I wouldn't return internal details like a map's iterator. Try to encapsulate data and functionality.
how do you mean and how would you do it then [/list]
Title: Re: mage engine
Post by: Nexus on January 21, 2014, 06:11:36 pm
Encapsulate your data, that's one of the core principles of OOP. Do not make member variables public, and do not hand out implementation details (like a map iterator).

I would hide the map as a private member in the class, and only provide the necessary accessor functions (such as lookup or insertion).