Jump to content

  • Log In with Google      Sign In   
  • Create Account

Game Engine using SDL 2


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 kovacsmarcell99   Members   -  Reputation: 134

Like
0Likes
Like

Posted 22 April 2014 - 10:42 AM

I just made my game engine MEngine SDL public!
Please look at the source code and give some tips because I would like to use it in the Ludum Dare compo this weekend!

https://bitbucket.org/kovacsmarcell99/mengine-sdl

 

Feel free to make a Pull request


Edited by kovacsmarcell99, 26 April 2014 - 10:44 AM.


Sponsor:

#2 Alundra   Members   -  Reputation: 926

Like
1Likes
Like

Posted 22 April 2014 - 11:14 AM

Your math.h should have precomputed value :

const float DEG2RAD = 0.01745329251994329576923690768f;
const float RAD2DEG = 57.2957795130823208767981548141f;

inline float ToRadian( const float Degree )
{
  return ( Degree * DEG2RAD );
}

inline float ToDegree( const float Radian )
{
  return ( Radian * RAD2DEG );
}

You can clean your main.cpp, but it's personal comment, if you release, you have to clean, it's not a big code source so it's not a big effort.

You can optimize your vector2.h and vector3.h a lot using *= versus /= and avoiding return in CreateVector using reference as output.

I saw the same thing on different files who can be changed, output who has to be reference output and not returned.

This kind of optimization is important if the function is called each frame or often.

Now what I have to say about the all stuff is it's not a game engine for me but a framework actually.

But it can't be really used by other because you don't have any doc and it needs to be clean on different places.


Edited by Alundra, 22 April 2014 - 11:20 AM.


#3 BeerNutts   Crossbones+   -  Reputation: 3007

Like
2Likes
Like

Posted 22 April 2014 - 12:21 PM

Please, move the code out of the headers.  Every file that includes a header will include all the code as well.  That means you'll have multiple instances of the same code included over and over.

Just declare the classes and API's in the include files, and have the source code be available via a library, or at least separate .cpp source files.


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 Alundra   Members   -  Reputation: 926

Like
1Likes
Like

Posted 22 April 2014 - 12:50 PM

It's true, I didn't noticed that the first view. It's very bad coding style.

When you will move all the code, if you have function who is just "get" or "set", let them inline.

It's a hint for the compiler but you know these function will be inlined so it's ok to let them in .h inlined.



#5 Irlan   Members   -  Reputation: 1806

Like
-5Likes
Like

Posted 23 April 2014 - 06:43 AM

If you use C++ go with SFML instead.


"Information is not knowledge. The only source of knowledge is experience." - Albert Einstein

Irlan Engine: http://robsrc.wordpress.com/


#6 Hodgman   Moderators   -  Reputation: 31851

Like
2Likes
Like

Posted 23 April 2014 - 06:55 AM

You can remove a lot of new/delete usage from your classes, e.g.

class Global
{
public:
	Global(SDL_Window& window, SDL_Renderer& renderer, Logger& logger)
		: input()
		, screen(window, renderer)
		, logger(logger)
		, audio(logger)
		, gfx(window, renderer, logger)
	{
	}

	Input input;
	Screen screen;
	Logger& logger;
	AudioManager audio;
	GraphicsManager gfx;
};

This is exactly equivalent to your original code, but removes the need for you to remember to write a destructor that deletes everything (and the chance that you'll forget to add a matching delete for every new)... The member variables will be constructed automatically when a Global object is constructed, and will be destructed automatically when that object is destructed.

 

You're also not following the rule of three -- if your class has a destructor, then it must also have a copy constructor and an assignment operator (the above re-write avoids all this hassle by just not having an explicit destructor cool.png).


Edited by Hodgman, 23 April 2014 - 07:00 AM.


#7 Alundra   Members   -  Reputation: 926

Like
1Likes
Like

Posted 23 April 2014 - 09:46 AM

If you use C++ go with SFML instead.

If he used SFML, the result would have been the same because it's a question of coding style more than API used.

Another point is SFML is more a game framework for OpenGL, SDL can be just used for windowing on D3D/OGL.

But after that, it's just a comment because SDL or SFML can be used for Unix version only if needed.

 

You're also not following the rule of three

I always like when Hodgman speaks about rule of three, because it's not always knew and should be.


Edited by Alundra, 23 April 2014 - 09:46 AM.


#8 kovacsmarcell99   Members   -  Reputation: 134

Like
0Likes
Like

Posted 26 April 2014 - 10:47 AM

Thanks everyone I almost finished all of them! I'm currently working on seperaing the code into .h and .cpp files, it's the last thing. I would like to hear further tips!


Edited by kovacsmarcell99, 26 April 2014 - 10:55 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS