Skip to main content
GameDev.net gamedev.net
🔒 Locked

c++ code

Started by tomsh Dec 9, 2011 at 12:39 PM 2 replies 1.1k views
ryan20fun
ryan20fun
it looks good and readable.

but i would change the formating slightly like:

for bracketed statements i like to add a space to either side like so

if( foo > bar )
{
fooed();
}

and.

if( foo[ 0 ] > foo[ 1 ] )
{
fooed( foo[ 0 ] );
}


one change i would do to your code is in "rectangle.cpp".
you have

if(xSpeed < 0 && xSpeed+sAce/sSlip < 0)
xSpeed += sAce/sSlip;
else if(xSpeed > 0 && xSpeed-sAce/sSlip > 0)
xSpeed -= sAce/sSlip;
else
xSpeed = 0.f;


and i would add extra brackets for readability.

if( ( xSpeed < 0 ) && ( xSpeed + sAce/sSlip < 0 ) )
xSpeed += sAce/sSlip;
...
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.
rip-off
rip-off
An incomplete set of comments on your program:


  • Your header files lack include guards. This will become a problem as your project becomes more complex.

  • You depend heavily on public members. Public members should be the exception, not the rule. They generally make most sense for types with no intrinsic invariants, such as your "vector" class.

  • Your naming convention is confusing and inconsistent.

  • It is generally preferable to use a constainer such as std::vector or std::list rather than implement an instrusive linked list.

  • It is spelled "Camera", not "cemra".

  • Your SfWin::rect member should be a local variable in each function it is used.

  • You could use your vector class in more places, rather than passing x,y pairs and having them as members.

  • There is no need to pass the texture to the rectangle, as it doesn't use it.

  • I see no code to cleanup the rectangles you allocate.
tomsh
tomsh
Thank you a lot!
From your comment I learned a lot of things.
Actually, the reason I didn't use include guards, it because I didn't know it. So you learned me something new

I will try to do the things you said.

ryan20fun what you said, is it something personally to you, or something known?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.