Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Jan 2013
Offline Last Active Apr 22 2013 12:40 PM

Topics I've Started

c++11 and VS2010 options

18 March 2013 - 02:31 PM

I'm looking for an option (easy option) to use c++11 range-for loops in VS2010.


On my primary machine I have Windows 7 and VS2012 (which I upgraded to specifically to get more of the C++11 features).    But my "real job" has me traveling quite a bit lately and at the momment I'm in a hotel in London (I live in the states).    While my work laptop has 7 on it, I can't really install VS on it to do a non-work project.    I had an old laptop I brought along thinking I could keep working on my project, but unfortunatly it has WinXP and can't get VS2012 installed on it.


So I'm back to VS2010, but it doesn't support everything thats already in my code.    Google has sadly failed me in looking for a way to get range-for support into 2010, so I hoping someone has a suggestion.    I'd really like to be able to keep working on my project while I'm in the hotel, but I certainly don't want to go through all my existing code to replace all my loops...(espcially since when I get home I'd want to switch them back...)





Is my design "bad"?

05 March 2013 - 05:15 PM


I think I have a bad design.  


I’d appreciate some pointers or directions on how to evolve this design.


This game is a port of a hex-based board-game.   It’s a pretty complicated board game (400 pages of rules) with 1000’s of different units, many with LOTs of special case rules.    My code is in C++ and using Allegro as well (although that is pretty hidden in my design, I could swap that out if I wanted too)


At a high level I have a class for the game itself which includes the core variables about game state, maps of all the core game elements and pointers to the major core steps.


There are classes for each of the core game elements (players, units, fleets, planets, etc.).    As previously mentioned the actual instances of these elements are in their own std::maps in the core game class.


For each major phase of the game (economics step, production step, etc…) there is a class which contains all relevant information for that
step (screen initializations, game logic for that step, listeners for input, etc.).    There is a pointer to the instance of each of these in the core game class.


From a GUI standpoint, anything that needs to put something on the screen (or for that matter interact with the human player) calls a GUIFactory class, which in turn calls classes for the various screen elements (button,image, dropdown, etc.).   I’ve further broken it out that those classes call a separate library of classes for actually rendering.


My class hierarchy is pretty flat for the core elements, although there is quite a bit of inheritance going on the GUI side (some layers are from the library though).


Anyway it does work…it’s just I’m barely scratching the surface on the rules/game content that I need to create and its feeling fragile/difficult to maintain already.   And I haven’t even looked at some of things I know I need to tackle like network play or if I wanted to make an AI player.  Maybe I have done it “right” and it’s just a complicated game…but before I get too much further I thought I’d ask the experts.

Clearly this isn’t enough information for you to redesign it for me…because I don’t want you too…I want to do it [learn better that way]…but
some pointers on how I should be thinking about this would be appreciated.    


Happy to post code if you need a better explanation.


using shared_ptr

16 January 2013 - 03:49 PM

ok please bear with me on this one smile.png


For my game I've been building my own GUI library (mostly because I wanted to learn how and partly because the ones available for Allegro 5 were either overkill or not good enough)


I was lazy when I started this and used regular old raw pointers, but as my game itself has become more complex I started noticing memory leaks so I just went through the (painful) experiance of changing all my pointers to std::shared_ptrs


[Side-Note to self and to others do it right the first time, that was a pain]


Anyway the memory leak is gone now which is great, but my frame-rate dropped from the 60 FPS I was throttling too down to 10 FPS (sometimes dipping to 2 FPS)


Now I expected sharted pointers to be a bit slower, but thats crazy.    I have to assume that it is me using them wrong.


As an example here is how I use this...


GUIElement is my superclass that all the widgets base themselves on and then I have a vector to hold them all...


std::vector<std::shared_ptr<GUIElement>> UIelements;
std::vector<std::shared_ptr<GUIElement>>::iterator UIiter;


When I want to put something on the screen I do something like this...


    std::shared_ptr<GUIButton> button1(new GUIButton(g_width/2-125,g_height/2-125,0,250,100,"(L)oad Default Scenario",updatestate));

Now I may do that 2000 times on a single screen for all the various elements on the map (which worked fine as "raw" pointers)


In my main game loop I have this...


///in the game logic update part of the loop....


//in the render part of the game loop




Anyway anything obvious that I"m doing wrong here, or some thoughts on what to look into?



Entity System

03 January 2013 - 03:08 PM

So for those of you building Entity Systems out there...I have a question about design.    I think for the game I'm working on it would be a great system to use given all the "exceptions" my rules for units seem to have so being able to have componets that I can swap out would be a big benefit to me.


Question is though do you try to treat everything as an entity or keep the "basic stuff" (i.e. title screens, main menus, dialogs, etc) as more traditional classes.    I guess what I'm asking is do I need to make like a MenuSystem which acts on MenuComponets and be able to have a DialogComponet (which may be the only thing a given entity had).    Or not worry about that and just save the entity system for actual gameplay elements.


I ask because when I look at the various example out there they are all focused on the actual gameplay objects and so I wasn't sure what the "right" way to go about it might be.


I'm sure there is no hard and fast rule here, just trying to get an idea for best practice before I redo everything


Thanks all