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

Author Topic: SFML Game Development Book - C# Port  (Read 7917 times)

0 Members and 2 Guests are viewing this topic.

Dejan Geci

  • Newbie
  • *
  • Posts: 19
    • View Profile
SFML Game Development Book - C# Port
« on: August 05, 2014, 03:06:19 pm »
Recently I decided to port the "SFML Game Development" book to C# in order to learn more about SFML. The code almost maps 1:1 with the C++ until the 7th chapter, which is where I decided to stop. It still might prove useful for someone, so here it is:

https://github.com/dejangeci/WarfareUnleashed

You will need Visual Studio 2010 Express to compile.

Cheers
« Last Edit: April 04, 2015, 09:15:11 am by dejan.geci »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML Game Development C# Port
« Reply #1 on: August 05, 2014, 03:45:33 pm »
FYI

Quote
sf::Clock -> System.Diagnostics.Stopwatch
sf::Time -> System.TimeSpan
sf::Time.asSeconds() -> TimeSpan.Milliseconds / 1000f

https://github.com/SFML/SFML.Net/commit/f7aeeb196d64b3924391f513f31b03c3336a9d27
http://en.sfml-dev.org/forums/index.php?topic=15003.msg110059#msg110059

Quote
std::size_t -> int

This isn't a missing feature, if you really want 1:1 mapping the C# equivalent would be IntPtr. However assuming you are using the type for indexing containers then an int fits the bill just fine.
« Last Edit: August 05, 2014, 03:47:05 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Dejan Geci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: SFML Game Development C# Port
« Reply #2 on: August 05, 2014, 05:20:37 pm »
I decided to use 2.1, and Clock and Time classes were added after that. As for the std::size_t, wasn't really sure what it is, so I used int.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML Game Development C# Port
« Reply #3 on: August 06, 2014, 12:43:12 am »
Nice to see somebody port the code to C#, thanks! :)

Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eyeliner

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: SFML Game Development C# Port
« Reply #4 on: August 07, 2014, 03:13:24 pm »
Cool stuff! Thanks for the hard work! I, personally, appreciate it.  :)

Dejan Geci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: SFML Game Development C# Port
« Reply #5 on: March 18, 2015, 01:08:51 pm »
Codebase updated to SFML 2.2.
- Using Clock and Time instead of Stopwatch and TimeSpan
- Indentation converted to 2-space

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: SFML Game Development C# Port
« Reply #6 on: March 18, 2015, 02:21:31 pm »
Only nitpicking but,I would say that uint maps better to size_t because size_t is unsigned by definition.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML Game Development C# Port
« Reply #7 on: March 18, 2015, 02:44:06 pm »
Only nitpicking but,I would say that uint maps better to size_t because size_t is unsigned by definition.

Yes, that would map better... but in the CLI all index types use a signed int as the type. In C++ the STD uses size_t for container indexing and such.

Also using an unsigned int would require casts. You can't implicitly cast an uint to an int.

https://msdn.microsoft.com/en-us/library/0ebtbkkc%28v=vs.110%29.aspx
« Last Edit: March 18, 2015, 02:46:52 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

headkase

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: SFML Game Development Book - C# Port
« Reply #8 on: May 24, 2015, 08:50:19 pm »
Thank you for taking the time to do this.  I'm new to SFML and with the book your source code will no doubt save me a lot of hair pulling.  :)
We all make choices, but in the end, our choices make us.