Defining Awesome — Solving problems by using intelligence
  • Status Updates

  • Solving problems by using intelligence

    Written by . Posted at 1:02 pm on October 7th, 2009

    Programming is just arrangement of structures and data. If a problem/block arises it is either:
    – because you are constrained within the limits of the structures you are using (like using an external programming library) or
    – because you have not planned out how to cleverly arrange the structures you are using

    Example:
    I was using an external programming library called Box2D. It is a physics library. My game is not a physics game but it has elements of physics in it (like flying and colliding objects). Yet it is a game mainly defined by game logic and playability rules which are not “physical”. One of the biggest problems I had (it has been months, what you see in the test version is something working but buggy) was choosing between walking past and climbing stairs. This is a very hard problem if you are working with a physics library because physics are deterministic. There is no choice for a human, it is just math, so you must build tricky work-arounds. Which sometimes work sometimes not, anyway they are a pain in the ass. I got fed up with it and decided to write my own code for dealing with this from scratch.

    What I did:
    A physics library holds only collision data for a map that describes the position, size and structure of walls and floors. It is built only for the purpose of stuff bouncing off inside a map. I need more. That’s why I made my own collision data structures which keep more information. For example for each floor/wall/stairs I hold information where does it connect to and which direction I can walk on it. This is very useful for the stair climbing problem as well as very good data for AI bots.

    To end this a final note:

    The Greatest Optimization Method Ever – All algorithms can be bypassed by arranging data differently.

    Ponder on this for a moment. I managed to eliminate hundreds of checks of a Line-to-Line collision algorithm per second just because I did what I described above. Hell, I didn’t even need to write the damn algorithm at all! I don’t like programming algorithms – I like programming games – which is in fact – just arrangement of structures and data.

    Be Sociable, Share!

    8 comments.

    1. You still need an algorithm to pre-process or sort the data in a clever way, though.

      I’m not a big fan of calling this “clever data arrangement”, but pre-processing. Well, that may not be the correct term, but to put it in simple words: If some data will be iterated over very many times, and we can assume it won’t change often, then we can process it once and cache the result. Then just rebuilt the result as soon as the data changes. In case of level geometry, it doesn’t. Just arrange the data in rooms, sectors, collision groups, reachability graphs or whatever and… yeah.

      If you can exchange an if in a loop for creating an additional array, it may be worth it. If you can replace an if with a pointer to a function.. hey wait, can you actually do that in C++?

      Also, I’m very happy you’re posting more than a philosophical note that makes you sound smarter than you are. You’re a coder damnit, and you’re good at inventing code and game design, so keep it up with posts like these, soldier!


    2. dickpickle

      lol thx captain obvious, it’s unbelievable how clever you think you are.. verge of fail, pile of shit


    3. It’s better to be an asshole than to be a bore.


    4. Anonymous

      Greetings my sire.
      As you programed the time travel machine subperceptive continuum i am here to save you. You have to not to do THAT, and You have to stop the whole process emidietly!
      Regards,
      J.H.


    5. These libraries are often too much overloaded for gaming purposes. In case of link dead you only need some easy equations for gravity and force that you can find on many websites.
      Regarding the data structures i have to agree with archont, there are always two parts: the data and the logic.


    6. Let me know when you build an AI sans algorithms.


    7. You sound more like a terse and spell-checked version of Eskil Steenberg every day. 😉


    8. namuol: LOL


    Post a comment.

    Links