SFML community forums

General => SFML projects => Topic started by: kleinschrader on May 18, 2018, 07:19:18 pm

Title: A game engine i have been working on + Formatable Text
Post by: kleinschrader on May 18, 2018, 07:19:18 pm
Hi all,

i have been working on a small Project for some time now.
Its an Engine i plan to use in the Future for some games of mine.

https://github.com/kleinschrader/SFML-GameEngine-Test

It includes a somewhat inacceible Font and Texture loader im gonna rework.
An accecible Multithreading Renderer
and finaly a derivative of sf::Text that can have int's, float's and char arrays passed to it and have them Printet in the string and automaticly updated, similar to printf. (Its kind of an hack due to the way sfml works)
Title: Re: A game engine i have been working on + Formatable Text
Post by: Geheim on May 18, 2018, 08:49:06 pm
Hey,
I just took a quick look over your project...
You are using quite a lot of raw pointers, which most of them are never deleted (= memory leak).

One example would be your
sf::Font *FontArray;
this->FontArray = new sf::Font[Fonts::MAXSIZE];
// never deleted...

Many of them are not required in your project and if you really need pointers, use smart pointers.
Nowadays (since C++14) you don't even have to use the new keyword yourself.

There is also some inconsistency in your coding style, as if multiple people work on it, like:
float yScale                         // camelCase
sf::RectangleShape *Left_side        // Snake_case
sf::String OrgString                 // PascalCase
Or
#include "Textf.h"      // in Textf.cpp
#include <Textf.h>      // in main.cpp

I know that looks like not a big deal, but for some people it is, just don't make it a bad habbit  ::)

Anyways, keep it up!
Title: Re: A game engine i have been working on + Formatable Text
Post by: kleinschrader on May 18, 2018, 09:03:49 pm
Heyo,

i dont think that is a memory leak.
I allocated space for the fonts so i can access them later.
Of course i dont have a deconstructor but im to lazy to do them.

And yea. I know my code style is all over the place, ill have to clean up and comment more.

Thanks for the feedback. Ill better myself, i promise :)
Title: Re: A game engine i have been working on + Formatable Text
Post by: eXpl0it3r on May 18, 2018, 09:08:05 pm
If you don't delete your allocated memory, then yes, you do have a memory leak.

Are there some pictures to go with your project? :)
Title: Re: A game engine i have been working on + Formatable Text
Post by: kleinschrader on May 18, 2018, 09:34:52 pm
Hi,
i do not really need to Delete them, do i?

I mean the only time i do not use them is if the Programm is closing.

I have a simple picture, yes. To be honest it dosent show much, but im Proud of the fText.

(https://image.prntscr.com/image/EVhk2DEHQS_HGbVmmzFkFw.png)
Title: Re: A game engine i have been working on + Formatable Text
Post by: Phanoo on May 29, 2018, 04:11:03 pm
It depends, if it's a global object that is allocated only once at game startup then you don't need to delete it, although it's considered good practice to delete everything manually so everything is cleaned up properly in the right order