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

Author Topic: My little collection to short SFML Code  (Read 6598 times)

0 Members and 1 Guest are viewing this topic.

4B

  • Newbie
  • *
  • Posts: 20
    • View Profile
My little collection to short SFML Code
« on: April 09, 2014, 06:07:40 pm »
Hello.

I recently made a little collection of functions which make my life with SFML easier.

SFML is my favorite library for graphical purposes, but I always wondered why there has to be so much code just to create a colorful rectangle or whatever so I decided to create a little library that helps me being faster.

Here you can find the SFMLib: https://github.com/4B/FuncCollection/blob/master/SFMLib.hpp

Feel free to give any suggestions and please tell me if I did something wrong.



Edit:
I forgot to talk about the name. Of course it won't be named as "SFMLib" if there will be a release one day. It's just a codename.
« Last Edit: April 11, 2014, 08:17:36 pm by 4B »
If you're going to response to any of my comments, please avoid this smily: ";)"

I'd be grateful, thanks.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: My little collection to short SFML Code
« Reply #1 on: April 09, 2014, 06:23:02 pm »
Aside from a few variables needing more descriptive names it is a good start.  :)

For Mouse why not also return the full point as well depending on screen or world coordinates?

Could also add triangles to you different shapes.  Not sure how you'd pull them off though.

For collisions adding circular, line, point, and triangular collisions might help too.


Just a few things to work on if bored or lots of free time in case of the collisions. :)
I have many ideas but need the help of others to find way to make use of them.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: My little collection to short SFML Code
« Reply #2 on: April 09, 2014, 06:32:14 pm »
You are overusing the const keyword.

Declaring parameters const is meaningful for references and pointers, but on the top-level (like const sf::Vector param) it clutters the interface with irrelevant information. The caller doesn't care whether the function modifies a copy of the value. For return types, const is not only useless, but also harmful, as it prevents move semantics (which can be relevant for more complex types).

I suggest to use this keyword only in the places where it actually expresses semantics, and not everywhere it fits. That helps making code more readable and understandable. Ironically, you are not using const in these places (e.g. the functions in the Mouse or Collision namespaces).
« Last Edit: April 09, 2014, 06:34:39 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

4B

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: My little collection to short SFML Code
« Reply #3 on: April 09, 2014, 06:49:02 pm »
@StormWingDelta I'm not sure if it's necessary to return both coordinates in one function. Sometimes you just need one coordinate(For example in a space shooter[1D-movement]). If you convince me I'll add that.
And I'm not sure what a line collision is good for.

@Nexus Thanks for this hint. I didn't really understood when to use const until now.


-Added circle collision
-Added world/window-coordinates(also corrected the little mistake which I made in the first version)
If you're going to response to any of my comments, please avoid this smily: ";)"

I'd be grateful, thanks.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: My little collection to short SFML Code
« Reply #4 on: April 09, 2014, 06:51:31 pm »
Another suggest is to use source control like git and then put your code on either bitbucket or github.  ;)

Also attaching a license to your code would be helpful.  :)

const int x(sf::RenderWindow &window){ return sf::Mouse::getPosition().x; };

Why do you require a window parameter if you function doesn't even use it?
« Last Edit: April 09, 2014, 06:55:30 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

4B

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: My little collection to short SFML Code
« Reply #5 on: April 09, 2014, 07:19:44 pm »
I hope i used the "const" right and github as it is expected to be used.

https://github.com/4B/FuncCollection/blob/master/SFMLib.hpp

@zsbzsb like I said in my previous post "corrected the little mistake.." I noticed it, but thanks. =)

Everyone feel free to use it, I don't want to license anything.
If you're going to response to any of my comments, please avoid this smily: ";)"

I'd be grateful, thanks.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: My little collection to short SFML Code
« Reply #6 on: April 09, 2014, 07:26:29 pm »
Everyone feel free to use it, I don't want to license anything.
It's always a good idea to explicitly state the license that code is made available under. Otherwise defaults according to many local laws may be that people have no rights to it at all (as far as I know).
In the case where you just want to give it away with no strings attached, an explicit note that the code is placed in the public domain is probably the best option.
(Just my opinion; I'm not a lawyer)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: My little collection to short SFML Code
« Reply #7 on: April 09, 2014, 07:37:02 pm »
Everyone feel free to use it, I don't want to license anything.

You really need to read this then.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

4B

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: My little collection to short SFML Code
« Reply #8 on: April 11, 2014, 08:16:57 pm »
Is the license included the right way?

https://github.com/4B/FuncCollection/blob/master/SFMLib.hpp

-Added license
-Added buttons(still need to work on this)
-Added rectangle-point-collision
-Reworked descriptions

Well, I'm going to add GUI-stuff.
But if you have additional ideas, please tell me.



If you're going to response to any of my comments, please avoid this smily: ";)"

I'd be grateful, thanks.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: My little collection to short SFML Code
« Reply #9 on: April 11, 2014, 08:35:28 pm »
yep it looks good to me but don't trust my input for github since i couldn't get it working. XD
I have many ideas but need the help of others to find way to make use of them.