Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 31 Mar 2000
Offline Last Active Jul 15 2016 12:47 AM

#4923938 Alternative to singleton

Posted by on 21 March 2012 - 08:40 AM

scene is a class that i create objects from, which are then the levels that one can play.

and yes, at load time, you put the filename (+relative path) as key into the map, and the actual loaded texture into the value, if it's not yet there. when ever you load a mesh, you check it's texture filenames against that map, add if not yet there, and replace the filename in the mesh with an iterator to the instance of the texture in the map (or a smart ptr, or what ever).

mostly one or twoliners, depends a bit on the language (i'm coding in c#, i guess you work in c++).

there will be a class game, which has a level currentlevel in it, on which update and draw will be called. a new level gets loaded by new Scene(filenameofscene); and that's it. it loads all it's textures into the map, all the meshes into their map, etc. and then processes the data in update, draws it in draw.

typically, scene can't even draw itself, but i just access all it's content to draw that in the drawing routine, but that's to each his own.

the biggest helper to stop creating global god-like variables: code what you use. not code something that might solve everything. code something that solves YOUR NEED. your level needs textures, so give it textures. it needs meshes, so give it meshes. done. that simplifies code massively. especially together with typical containers (vectors, maps). learn to use them instead of creating magical managers. much simpler in the end. much less of a mess.

btw, your 'fire' code example is perfect: if you have a global, only one player can shoot/trigger. multiplayer on the same machine? impossible.

but if you refactor it to have a class player, that stores it's own trigger variable, you suddenly can. a gun is then owned by that player, and shoots, if the player "is shooting".

the advantage: you can derive players: localxbox360controllerplayer, localkeyboardandmouseplayer, networkconnectedplayer, computeraiplayer, and they can all shoot individually, with the identical gun, the identical logic. they can even pick up your gun to use it, once they killed you.

singletons and globals always take away options you haven't even imagined. but believe me, at some point, you, or someone else will. then, rewriting everything will be the only solution.

#4923907 Alternative to singleton

Posted by on 21 March 2012 - 06:32 AM

in simple: it just shouldn't happen at that level. why can't a scene properly load it's textures (and all other data besides textures) without loading stuff multiple times? that's not part of a texture manager, it's just part of the scene to handle that.

scene {
std::<texturename, Texture> textures;


there is your texturemanager, your complex global have to be thing that just does not need to.

when a level gets loaded, it loads all the data it has to, into it's own object. when the level gets unloaded, it frees it all.

with the singleton, all you do is, when a level gets loaded, it loads all the stuff into a global object. when the level gets unloaded, it frees it all from the global object (maybe).

it's the same. just, in one case, you actually handle it where the stuff belongs, instead of outsourcing it to something that artifically acts like a god to your application.

and no, there are NO issues with that. it's clean. it's simple. it just works.

#4889864 Why is it that game designers should not have emotions for their ideas?

Posted by on 02 December 2011 - 01:06 PM

you should be passionate and everything. but you have to know, and always consider, that you can be wrong on something. you're not perfect, sometimes someone else is right. and you have to accept that not everything you invented is pure gold and pure genius.

if you can't let go of ideas that failed/will fail, you're not good at your passion. because your main goal and passion is and should be making a good product. not a product with a feature you've invented, even if that feature is completely bollocks.

so put your passion into a higher level: the actual product (be it a game, a webpage you're designing, what ever).

an idea getting dismissed doesn't mean the idea itself was bad. it means it doesn't fit right now, right here. focus on the project, not your idea.

#4823621 The GDNet Birthday thread

Posted by on 15 June 2011 - 08:51 AM

Happy birthday! It's great to have you around trough all those years.

#4784470 How many of you use C for game programming?

Posted by on 11 March 2011 - 11:59 AM

c# here. because i CAN MANAGE MY OWN MEMORY, because i CAN write my own containers, because i can write my own file handlers for stuff like xml, because i can write my own database like interface and stuff. but i don't WANT to. oh, and strings, too. i want to get my stuff going. and my stuff is an end product, not a library or tool for other programmers.

oh, and, because i know that i'm not perfect, i know i would do errors with all of the above listed stuff. and those might be hard to trace. memory leaks are one of the biggest issues in the computer industry since years, source of bugs, crashes, hacks, viruses, etc. knowing that i will not be able to 100% prevent it, i prefer to have a compiler/language setup that i know it will.

#4757652 What Does Everyone Think About The New Site Layout?

Posted by on 12 January 2011 - 04:19 AM

I'm not sure as to the origins of this sentiment that discussing problems with the new site is somehow equivalent to whining or attacking the developers, but it's patently ridiculous. When you support a software product, you don't consider users submitting feedback and bug reports as personal attacks, do you? I know for me, user feedback is ALWAYS appreciated, even if we don't always end up making the change the user wanted. So much so, in fact, that both at work as well as in my hobbyist projects I continually reach out to users to cajole them into giving feedback. Trying to put a damper on that here seems absolutely mind boggling.

it's a typical behaviour that when something changes, people start to cry omg it's all bad. seen it often enough. feedback is appreciated, of course. but overreaction is not.

As for the rating system, it's not hard to look at the new system and determine logically what the outcome of its effects will be. You don't always have to run an experiment to know the outcome of a process. Trying to dump off the role previously filled by the rating system onto the moderators, who already have enough work to do, doesn't sound like a brilliant move to me. It's not really their job to try to run posts through the constantly fluctuating filter of community standards, and even if it were I don't think they could do it with any degree of success.

well, as said, i know it works very well in .. well, about any other forum. so yes, looking at the outcome means one thing: it should work very well here, too.

Where would they draw the line? Profanity? How about if I just call you a stupid moron? What if I followed you around and after every single one of your posts, I also posted a followup "I think everything he just said is wrong."? I bet that would get me an even higher rating, since a few people might find it funny to rate those posts up, and anyone who finds it annoying won't have any recourse but to bug the moderators to censor me when the actual content of my posts isn't breaking any rules.

I think everything he just said is wrong.

sorry, had to :) but that's about exactly my point: always this negativity, always this "that could go wrong in so many ways!!" how about trying and see if it does? so far, in other fories, it did not go wrong. why should this be different? are we such a bad community?

#4756089 What Does Everyone Think About The New Site Layout?

Posted by on 09 January 2011 - 12:10 PM

rating system is there, but focused on posts now. bottom right of each post. should stop the downrating-orgies we had.

#4756040 What Does Everyone Think About The New Site Layout?

Posted by on 09 January 2011 - 10:50 AM

Just rate the posts now. Better than rating persons.

#4756037 What Does Everyone Think About The New Site Layout?

Posted by on 09 January 2011 - 10:46 AM

In my opinion I am very happy they got rid of the old rating system because even posting a thread like this in the lounge would make my rating drop. However, I think they should have had a rating system where users can only rate each other up. This way you would know if someone was a really helpful poster but you would not have people down rating each other over silly things like they used to.

they have. i have a reputation allready. yours is 0 :) no clue how to increase it, though.. how does it work?!

edit: ah, one can vote up posts. that's nice.

edit2: yes, voted your post, and you got a reputation of 1.

#4756020 New Site!1`~

Posted by on 09 January 2011 - 10:18 AM

Just seeing if I can make a new topic.

And a reply! horrayyhh!!

#4720835 Any use for ancient DOS code?

Posted by on 18 October 2010 - 02:43 AM

if you rewrite it, you have to release the old code, then, too! or even let it scroll trough in the credits, or something (and a song singing "still alive" would fit perfect).

#4313895 What IDE are YOU using?

Posted by on 14 September 2008 - 09:26 PM

since the first release, i used c# express edition and c++ express edition (and the web developer etc..)

now, that i got access to a quite cheap vs2008, i use visual studio 2008 (standard) + visual svn + xna 3.0 gamestudio (ctp).

i like the extensions-possibility of the full vs. svn integration is awesome :)