Jump to content

  • Log In with Google      Sign In   
  • Create Account


Xai

Member Since 14 Oct 1999
Offline Last Active Mar 14 2014 11:22 PM
-----

#5139154 No Low Level Programming is better ?, Please explain this then ?

Posted by Xai on 14 March 2014 - 11:22 PM

No professional programmer, let alone game developer, would say that all low level programming / optimizations are bad.

 

But experienced professionals will tell you that things similar to the saying "premature optimization is the root of all evil" ...

 

The gist of most professionals opinions is that you should not focus on specific target or performance concerns too early in the life cycle.  Partially because there is no point in optimizing a program or feature that may not make the cut into a final product anyway.  Partially because by the time the product comes out, the exact appropriate optimization might change.  Partially because clean logical code is easier to understand and modify, and you want to be able to change and improve as much as possible while learning what is fun and what isn't.  And Finally because it is often true that developer time is more important than efficiency in many cases and they'd rather make 3 games that are fun and for sale, then 2 highly optimized games that are just as fun and just as for sale.

 

Also, don't confuse "premature optimization" with "building for a platform".  An example of the type of optimization that would be discouraged is "oh man I have a great idea for how to make this highly detailed crafting system for this fantasy MMORPG i'm working on ... but I don't know which data structure or algorithm is the most efficient implementation".  An example of the type of platform utilization that is NOT bad would be "oh man, since this game is for phones and tablets I have a great idea for how we can leverage the gyroscope to control the crafting system in a unique and cool way".  See the difference is, in the first case, someone has a great idea and is letting the low level aspects reduce their ability to deliver a functional feature.  In the second case, the developer is being inspired to create a more enjoyable or fresh experience in harmony with the target platform characteristics.




#5131432 From C to ?

Posted by Xai on 14 February 2014 - 06:12 PM

I also love how people complain about C++, C# or Java version issues, and then don't comlain about Perl, Python or Ruby versions issues ... which are absolutely the worst, except most of the history of Perl 5 has been about as stable as C++,C# and Java ... hell, you can just now BARELY get a linux distro that ships with Python 3 (which is at 3.3) because they have a dependency on incompatible Python 2 code.  And ruby, a langauge I actually like, got stuck at 1.8 for more than 2 years after 1.9 was released, and now that 2.0 is released, only 1 major distro ships it.

 

The fact is in my entire C++ history, I had exactly 1 type of code I actually used that wasn't compatible with C++ 11 - related to how it disambiguates names in some cases.  I spent 3 hours fixing my code base, problem gone.

 

Also, in C#, none of my working code has ever failed to work on newer versions, except for 1 change they made with 1.1 as a security fix.




#5104254 GUI aspect ratio independence

Posted by Xai on 24 October 2013 - 10:51 PM

Depends on what you mean.  Do you mean you want letter boxing, so the actual controls are in correct aspect ratio as your base version ... or do you mean if the screen is 20% wider, you want your controls to be 20% wider?  Either way, you can see that if you just thing about it from those 2 choice, the answer is almost obvious.




#5098201 How to cut out duplicate code

Posted by Xai on 01 October 2013 - 11:20 PM

Or better yet, do not combine 2 completely separate concepts into single classes.  The responsibility to have manage a list of event handlers is a single purpose.  Aka a class.  This is a basic common pattern known by many names include Broadcaster / Listener, Publish / Subscribe or Observer pattern.  The responsibility to define a callback signature is another responsibility - usually using a function pointer typedef, a delegate, or other technique.  And the responsibility to define an actual specific slot, for a specific purpose within your program is a 3rd one.  So to put in some possible specifics.

 

Alvaro's EventHandler is a good class here - although for the way I plan to decompose responsibility in this example, I would rename something else, perhaps "EventManager" or something.

 

I would then use EventHandler or EventCallback as the base class for various event signatures, perhaps ClosedEventHandler, ResizedEventHandler, etc.  So a "ClosedEventHandler" would be a function signature for a callback that accepts the "closed event argument type" as its event argument.

 

I would then using INSTANCES of the EventHandler class, for each slot I had.  So perhaps:

 

EventManager<ClosedEventHandler> Closed;

EventManager<ResizedEventHandler> Resized;

 

And the OnClosed() method would iterate over the Closed EventManager calling all of the managed handlers (ie, "Raise" the event).

 

If you just look into how C#/.Net events and delegates work, you'll find a great example of a design like this.  But back in my C++ days I had written something quite similar to what I am posting here - although I haven't looked up all the details, and the names and such were different.




#5098199 about keyword and include

Posted by Xai on 01 October 2013 - 11:03 PM

You may wonder why / how the language designers decide what goes in the language as a "keyword" and / or "part of the core language", and what goes in the language as part of the "standard library" / aka requiring "#includes".

 

The normal short answer is - the language core is usually the smallest part reasonable, that can be used to write / reference the rest - they put nearly everything they can into the "standard library" instead of the language core ... but obviously if nothing is in the language itself, you couldn't do anything at all - so a certain subset of features needs to exist at a basic level, to even support the concept of writing basic code, and referencing and using already written code.

 

And as in Cosmic's answer ... it also includes whatever set of "rules" are needed so that the compiler / parser can just divide and understand the program's structure and content.




#5098198 Help debug multidimensional array loop?

Posted by Xai on 01 October 2013 - 10:56 PM

Here is an expanded version of Brother Bob's idea, in case you prefer to see more abstraction.  Note that all the named variables do not have to be decomposed the way I have shown them ... this is just to show all of the named concepts / values / partial values present in the domain you are working with.  In a real solution you would probably use about 1/3 to 1/2 of these actual values ... but which set depends on what is coming from your environment / configuration.  The main thing I want to encourage is - STOP USING MAGIC NUMBERS - put them in constants or #defines or something ... so that you can change them ONE PLACE and have your code still work.  So when you want to go from say 1280x800 to 1680x1050, or to a mobile devices 480x800 ... you can change you constants / config file, but not your debugged formulas / functions.

// Assuming these constant or configured values
int invMaxCols = 4;
int invMaxRows = 7;
int invCellWidth = 65;
int invCellHeight = 65;
int invGridOffsetX = ?;
int invGridOffsetY = ?;
 
// And these input values
int xClicked = ?;
int yClicked = ?;
 
// These can be easily computed - if needed
int invGridWidth = invMaxCols * invCellWidth;
int invGridHeight = invMaxRows * invCellHeight;
int invGridBoundsX = invGridOffsetX + invGridWidth;
int invGridBoundsY = invGridOffsetY + invGridHeight;
 
// AND THEN - version 1
bool isInGrid_v1 = 
  (xClicked >= invGridOffsetX && xClicked < invGridBoundsX
  && yClicked >= invGridOffsetY && yClicked < invGridBoundsY);
 
if(isInGrid_v1)
{
  int cellX = (xClicked - invGridOffsetX) / invCellWidth;
  int cellY = (yClicked - invGridOffsetY) / invCellHeight;
  T selectedItem = inventoryList[cellX][cellY];
  if(selectedItem != null)
    selectedItem.use();
}
 
// OR - version 2 = almost same as Brother Bob's great and succint suggestion.
int gridX = xClicked - invGridOffsetX;
int gridY = yClicked - invGridOffsetY;
int cellX = gridX / invCellWidth;
int cellY = gridY / invCellHeight;
 
bool isInGrid_v2 = 
  (cellX >= 0 && cellX < invMaxCols
  && cellY >= 0 && cellY < invMaxRows)
 
if(isInGrid_v2)
{
  T selectedItem = inventoryList[cellX][cellY];
  if(selectedItem != null)
    selectedItem.use();
}



#5096339 Implementing game objects with builder?

Posted by Xai on 23 September 2013 - 11:18 PM

I love the example Julien (not being sarcastic) ... but just so you know, Scalation is not related to the "scale" of an object.  In english it is:  Position, Rotation and Scale, not scalation.  Scalation is a visual things about the scale patterns on reptiles - similar to Coloration.




#5093829 Need architecture advice

Posted by Xai on 13 September 2013 - 12:38 PM

I think you are approching this development effort slightly backwards.  You are trying to solve the abstract development "problems" before creating your program, instead of creating your progam ... and trying to improve on problems you actual run into while doing so.  That's not how good design, architecture, patterns and experience is built.  There are general "goals" and "strategies" in programming (goals include:  don't repeat yourself, keep it simple stupid, clean readable code, consistency) (strategies include:  single responsibility principle, liskov substitution principle, tiered design, factories, polymorphism, interfaces, etc). 

 

Understand that the main goal is that for any given program there are a certain set of lines of code that MUST be written and executed by the machine to make the program work (such as the reading of files, bliting to screen, computing of damage, starting and stopping of sound, processing of input etc).  But these usually make up only a fraction of the actual code in a program.  The rest of the code is organizational overhead.  While there may only be a few ways to draw a texture on a triangle in a video card, there are HUNDREDS of ways to organize and layer code that eventually does so. 

 

These organizational structures, patterns, abstractions ... they have NO INTRINSIC VALUE.  They have value only to the extent that the humans who use them find them helpful for getting to the desired goal.  Accept that your program will not be able to be 100% perfect.  Accept that there will be "some" repitition of code, some ugliness of design, and some inconsistency and difficulty in maintenace.  When trying to get a progam working, the first question should not be how to make it fit a principle or ideal.  It should be how to make it work, to do what the computer needs to do.  And then, the second (or third or fifth) question should be "Is this code as clean, well designed, performant and or pleasing to me as it should be?". 

 

You don't learn to make high quality guitars by asking the luthier to explain to you the "right" ways of making them.  First you learn how to do a specific detail - staining or polishing wood perhaps, or attaching fretboards.  Then once you have done that thing, you ask as to how you might improve at that thing.  Then you move on to another.  And after years, you hopefully are good at all of the skills required to make quality quitars (or computer games).

 

So what I am sugesting (in a long winded and not so obovious way) - is that you bring an ACTUAL EXACT and REAL example of something you are actually doing, and ask for how to make THAT THING better.

 

For instance, if you have a "Sword" or "Weapon" interface or class, and perhaps have made it data driven, and perhaps are now looking at your code, unhappy because you feel like it is too much duplication, you then would be asking, "How might I generate this set of artifacts (or their equivelent) from a single source to reduce this duplication?".  By posting your existing code, and your question that way, people can help you factor out commonality in your design, or push you toward a more appropriate abstraction that would not create as much redundancy.

 

People cannot tell you how to generate code in general, or recommend or judge abstractions in general ... but only in specifics.

 

I will give you my example.  I started on some simple 2D game stuff about 15 years ago.  Early on I produced some results but had really ugly code and bad abstractions.  How do I know they were bad ... only because I had a hard time keeping strait what code was responsible for what feature and where to change things as I made my game better, without creating bugs.  So over time, my code moved toward certain shapes.  And many of these shapes eventually settled and haven't moved much in many years ... because they are now good expressions for what I need them to do (in a relative sense).  I can't remember my "bad" designs from 15 years ago.  But my current concepts are fairly simple.  These are NOT necessarily designs OTHERS should use, they just work for MY code basae.  I have "game resources" which represents things which need to be managed by resources managers (such as images and sounds), this general concept is not a class but a term, I have actual classes for the different resource domains including "ScreenResource", managed by a ScreenManager, and SoundResource by a SoundManager, etc.  There is some repitiion here, which I have factored into ResourceUtils, but mostly they are different.  I have GameObject which represents everything which interacts with the "game world" and affects the management of "game state".  I have a Game base class which represents an instance of the logical game, which is subclassed for each logical game such as ColorInvasionGame, which is different than my Application class which represents a client progam that the user uses to play or serve a game, which has derived classes such as ColorInvasionWin32App and PokerServerApp, etc.  When it comes to my simple 2D game sutff, I have IPhysicalObject which is anything with a position in the "physical" game world, and IMovableObject which is a physcial object that may change position, and IActorObject which is a movable object which may cause changes, usually via user input, AI action, or timers or other event triggers.  Of instance an asteroid is a movable object, but a pirate ship is an actor object.  Each of these adds an API to interact with the additional features it provides, while letting the common simple physics/collision engine work on physical objects.

 

The above has nothing to do with your original question, because I still need more details about the code you "have" that isn't as good as you'd like to have, to give you better advice.  The above is like 10% of the primary classes of my game design, which is broken into over 100 classes, about 30% of which are heaviliy data driven (and would be approprite as DB tables or configuration files) ... there is no 1 size fits all design.  My engine doesn't support 3D, doesn't do real physics, can do either turn based or real-time, and is only made to handle the small indie hobbiest stuff I like to play with in my spare time.  It is underwhelming and poorly designed in some areas, and overengineered in others ...

 

Just make code work, do something you like, and make it better piece by piece.




#5093715 Need architecture advice

Posted by Xai on 12 September 2013 - 10:06 PM

Your question hasn't gotten a good response because:

1.  It is very very far reaching, broad / open ended and vague.  It doesn't give any clear question you actually want answers to, but instead opens the door for the content of some people entire blogs.

2.  It is not specifying the actual REAL problems you are trying to solve.  The architecure of a flash game, an MMORPG, a peer-to-peer card game, an RTS, an arcade game .. there are all actually somewhat different ... and have different "correct" designs.

3.  You include a lot of partial specifiers of what you want the shape to be, but they are both incomplete and also not in line with how 95% of the people on this forum work.  You sound like a guy with either 4+ years of CS schooling, or multiple years of professional business programming experience ... and your bullet points sound like terms from that domain. 

4.  Some of this isn't game dev related, but is mixed in.  For example, what do "build systems" have to do with anything about game development?  All of the standard general purpose software development build concerns are identical in game development as in normal development (Inversion of Control configuration as well).  So for those topics, you would just use whatever tools are common for your toolchain (things like CruiseControl and Jenkins for CI, things like VisualStudio, XCode, or make/cmake/jam etc for compiling or executing unit tests).

 

And your "lets assume ..." seems a little too much to assume.  you need to define a little more to have common language for this.  what do you mean by "same instance in various contexts".  Do you mean that there are different pieces of code/programs running on different machines to make the 1 thing we call a "game" actually run?  Or do you mean you have a common OO class, instanciated to be each of these things.  The former is of course true for all multi-player games ... but the details vary a lot amoung types.  It is very UNCOMMON to have the same game class running server side as that which knows how to load images and sounds and interact with a user client-side.  These are almost always separate programs, running separate code (but sharing mutliple libraries).

 

Also, your idea of having raw data without validations and a layer with validations is very common in traditional non-game designs, but very uncommon in games.  Games don't usually have any "validations" that they don't need to operate, and if they need them to operate, they usually run in all appropriate contexts.

 

And the idea of running a "simulation" client-side that mirrors what the server does, and then syncing up these states when they don't agree is a full topic all to itself with many articles published.

 

You have simply opened too many topics in 1 tiny partially written thread.  Break your problem down and repost as specific questions for specific areas of guidance.




#5093585 Simple C++ Design Question for Numerology App

Posted by Xai on 12 September 2013 - 10:09 AM

Also, I want to say I was wrong, Alvaro's post is correct, there is a constant time solution and that is it - and it works for all numbers >= 1 (make sure and trap 0 as the only special case that adds to 0). 

 

I was erroneously thinking that an inheirantly loop-base operation cannot be condensed to constant time, but the fact is, the divide and modulous operators and not "constant time" in the simple sense.  They have circuitry added for each digit of support, so the "loop-based" aspect is being played out in parallel in the modulus operator - very neat indead.

 

I was also erroneously thinking that that range 1-9 couldn't be correct, because there is no 0 ... but I forgot to account for the fact that it is supposed to be that way for any number >0.  9 = 9, 10 = 1, 11 = 2 ... I don't know why I lost sight of that in my argument.

 

Sorry for the confusion.




#5093460 virtual destructor

Posted by Xai on 11 September 2013 - 07:58 PM

Paradigm Shifter's No is also a yes.  As he said, you don't need to DECLARE a destructor as virtual in derived classes, because once it is defined as virtual in a base, it is virtual from their on down.  So YES, it would be (and need to be) virutal in all derived classes, you just don't have to add the declaration to make it so.




#5093079 Custom C++ Classes in Visual Studio Express 2012

Posted by Xai on 10 September 2013 - 02:16 PM

Yes, there are 2 different choices on "reusing" class in C++, and you are accidentally trying a hybrid between them.

1.  The CODE sharing route.  Include the code itself into your project directly ... and #include it using relative paths with quotes.

2.  The LIBRARY sharing route.  Put the code into a separate project, compile that into a library.  Add the path to the HEADER files to your include configuration, and #include it using traditional style includes (angle-brackets instead of quotes).  Then ALSO add a reference to the library to your project.




#5093074 Simple C++ Design Question for Numerology App

Posted by Xai on 10 September 2013 - 02:11 PM

Finding if a number is divisible by nine has NOTHING to do with the OPs purposes.

 

In numerology - one of the most important "values" of a number is the sum of its digits (although there are special cases for certain numbers like 11 and 22, which are NOT usually reduced.

 

There is NO SUCH THING as a way to compute this without a loop or recursion.  Frob's post is almost exactly what the OP needs for a primary function.  But anyway, here's some code.

 

int SumOfDigits_SinglePass(int input)
{
  if(input > 10)
    return SumOfDigits_SinglePass(input / 10) + (input % 10);
  else
    return input;
}
 
int SumOfDigits_MultiPass(int input)
{
  int newValue = input;
  while(newValue > 10)
  {
    newValue = SumOfDigits_SinlgePass(newValue);
  }
  return newValue;
}

 

Obviously adding tests to stop reducing 11 and 22 if desired would be fairly easy.  Another function you would want to write would be one that accepts a list (or vector) of integers and sums them into 1 integer ... this would be used to take things like 3, 13, 1998 and sum them into 1 integer, which you would them feed into the above functions.  I'll leave that as an exercise to the OP so you get some fun yourself.




#5092824 Stick with C++ or venture into C#?

Posted by Xai on 09 September 2013 - 04:00 PM

Use both.  I had 7 years professional C++ before my currnet 8 years of C# (not in the game industry).  C# is easier to create simple clean code when you don't care about every low-level detail or aren't needing to interact with someone else's low level, non .NET, library.  But sometimes you do.  So use C++ for that.  The last time I hit that situation I created 2 C++ libraries (1 for interacting with windows USB devices and 1 for doing low level audio block management), but then I created a .NET wrapper for each of those using C++/CLI (this took less than half a day to wrap both lirbaries), and then I used those lirbaries in a C# application (where all the other libraries were also written in C#).

 

C++/CLI is your friend for interating C# and C++ ... but if you like C# and it isn't hurting you, put as much of your logic in C# ... is truly is easier to maintain, primarily because it is more "normalized" and less powerful.  So C# libraries tend to follow more common patterns and require less "what the hell was I thinking" moments when you come back to them 3 years later.




#5092215 I need a C++ Mentor.

Posted by Xai on 06 September 2013 - 09:57 PM

I recommend 1 thing in addition to a mentor ... a cohort.  If I had time I'd mentor you, but I just had a daughter and I just can't spare enough time to pull you up as much as you'll need to invest.  However, in addition to trying to find someone to help you understand the occasional concept from a book or tutorial that's just flying over your head ... find someone who wants to learn as well.  Someone you can have long conversations with trying to figure stuff out, debates, or just someone you can work with trying to make the damn code do what it "should".  Working with someone is so rewarding for both parties, even if 1 of you ends up being way better than the other (which almost always happens, but ... so what).

 

Good Luck.






PARTNERS