Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: mage engine  (Read 6302 times)

0 Members and 1 Guest are viewing this topic.

mvl

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
mage engine
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: mage engine
« Reply #1 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:
  • You should pass class objects like std::string by const-reference, not value.
  • I wouldn't return internal details like a map's iterator. Try to encapsulate data and functionality.
  • Getter functions that don't change the object should be const-qualified.
  • There's no need to declare a virtual destructor if the object isn't used polymorphically. You don't need destructors at all if the compiler-generated ones work well.
  • Instead of handcrafted loops, you could use STL algorithms such as std::find() or std::fill().
  • When your compiler supports C++11, you can simplify a lot: std::array instead of arrays, range-based for loops, type inference.
I don't know what your exact plans are, but the GPL license will effectively prevent most people here from using your code.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

mvl

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: mage engine
« Reply #2 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
« Last Edit: January 19, 2014, 04:28:43 pm by mvl »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: mage engine
« Reply #3 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: mage engine
« Reply #4 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.

  • 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

« Last Edit: January 19, 2014, 05:26:04 pm by AlexAUT »

mvl

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: mage engine
« Reply #5 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?


zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: mage engine
« Reply #6 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. A neat tool I found is TLDRLegal which you may also find useful.  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: mage engine
« Reply #7 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
Back to C++ gamedev with SFML in May 2023

mvl

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: mage engine
« Reply #8 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]

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: mage engine
« Reply #9 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).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything