Sign in to follow this  
Richy2k

Beginning XNA - Some C++ - C# translation questions

Recommended Posts

Decided it's time I properly get acquainted with C#. Plan on finding another job outside of games, and C# seems to be a popular choice to program with. Thus, I've decided to have a go at making a small game with XNA to get my C# up to scratch. For my framework, I'm mostly gonna copy my C++ engine's ideas - cutting out the lower level parts due to XNA being higher level. My main problem is access to core systems in my C++ engine looks like this:
CsArchive* pArchive = CsCore::pImpl()->requestArchive( "whatever.arc" );

OsInputDevice* pKeybord = OsCore::pImpl()->getInputDevice( osID_KEYBOARD, 0 );
Basically, CsCore, RsCore, SsCore, OsCore, and GsCore are all similar to singletons - but could have a different version of them dropped in even at run time. I am happy to drop that part of them for my XNA framework, but what would you guys recommend I use? Static class? Singleton? Have 1 place to get access to all of these subsystems? Something different? Cheers ahead of time!

Share this post


Link to post
Share on other sites
Quote:

but what would you guys recommend I use? Static class? Singleton? Something different?

The last option: pass the dependency interfaces to the interfaces depending on them.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
The last option: pass the dependency interfaces to the interfaces depending on them.


That's what sort of thing I had in mind when I was thinking "1 place to get access to the subsystems". It's been suggested I just use singletons, I can't really argue as to whether it's bad practice or not due to it being a language I can "cut code" in, but not really familiar with. You think singletons would be ok? I.e. I just use them, and get on with actually writing a framework and a game?

Share this post


Link to post
Share on other sites
No, I think singletons are terrible and unnecessary, and make your code worse -- and harder to maintain and develop with -- for their existence.

The problems with singletons are language-agnostic, for the most part. You can search these forums and find plenty of discussions about the issue.

Share this post


Link to post
Share on other sites
Ok, I shall avoid singletons. I do hate them - but if it were a "best practice" in a language I would be happy to put my hatred of them aside. Access to the engine can wait, but I'll go with having a single interface class - use that to access core elements.

Not that I'm new to programming or have no idea how to do thing - I just want to take some other people's opinions, views, and not have a messy start with C# - as I refuse to rewrite another framework in the coming months.

[Edited by - Richy2k on February 19, 2010 4:38:20 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this