Defining Awesome — Good code looking good
  • Status Updates

  • Good code looking good

    Written by . Posted at 2:00 pm on May 27th, 2009

    Tile Engine for Link-Dead is complete. It was one of the hardest things to accomplish code-wise. There are a couple things I did differently for this and I want to write it down. Also I want to share what I’ve learnt from making it.

    This is not a typical tile engine like in most sprite games. This is a tile engine with the tiles being prerendered and transformed into Box2D physics data for handling collisions. I’ve been programming this for a couple days for more than 6 hours each day (it’s amazing how much you can accomplish if you just sit and code).

    The tile engine is not yet implemented in the game itself. Just in the TestBox program that I made to test out ideas. The programming style for it is different than the Link-Dead engine itself. Before I started I got partially inspired by the article Making Wrong Code Look  Wrong. I have no idea what the authors suggestions were in this article, its hard for me to understand his writing style (maybe cause he’s a programmer). Nevertheless the title of the article got me thinking.

    First of all I decided to make the code quick and dirty. I am best in writing this sort of code. Prototyping is my favourite activity. I didn’t use any c++ stuff like private,/public methods and variables, polymorphism and all that crap. I used mostly structs and it looks like c code. I like it very much. After a couple years of programming in c++ and making the Link-Dead engine with it using all sorts of c++ object-oriented tricks I think it’s shit.

    I believe it is good for everyone else, so don’t argue here with me. It is just my experience, I write far more efficiently in dirty c-style. The code might not be nice and usable for something else but it doesn’t matter. What matters is the delivery of the product. Soldat was written in this style and people are out there playing it, that is all.

    Some other things I did differently was making all variables have only small letters. Don’t know why but this just works for me. Before I used all sorts of variations mixing it with Hungarian coding.

    Also I decided to chop down functions if they were too long ( like longer than 2 screens). I was always too lazy to do that but this time I sort of wanted to. It just looks better with the small letter variables I guess.

    The last thing I learned is that I’m awesome.

    Now for some facts:

    I managed to do the physics data optimization (I asked for ideas in a previous post). Joining edges was easy, some of you managed to write it down, but the problem was making it fast. The trick was to store the data in an efficient way to make searching for nearby edges fast. It happens to be a tile engine so the data was already stored in tiles, so it was easy from there. My algorithm came out to be super fast.

    Unfortunately Box2D is a bottleneck. You can’t create a very very large world with it and Box2D loading into memory is the slowest thing in the entire map loading process. I could separate the map into many Box2D worlds or I’m thinking of simply implementing tile collisions into Box2D.  I might think about it in the future if there is a need for a larger map than now.The good news about Box2D is that it is very fast with a large map.

    The largest map I can create now 4096 * 3072  (4 * 4 screens).
    It is 50MB in RAM and 9MB in video memory. So I guess everyone even with old video cards will be able to play this.

    This is a lot smaller than when the physics data was streamed from a file in real-time as I showed a couple posts below. I’m cheering myself up with the fact that the caves I generate have very complicated collision data. The maps in Link-Dead will be much much simpler consisting of corridors and paths. To really have infinite maps I will have to think how the game server could work with streamed physics, but I’ll leave that for the future. If I invent a way to make that work it would be a milestone in physics-based multiplayer gaming.

    Be Sociable, Share!


    1. First! ;D

    2. guyguy001

      YEAAAAAAAAAAAAAH!! im telling everyone that Link-Dead is coming!

    3. danyukhin

      We love you, Michal. Keep it up!

    4. still working on the idea to have a 1000 vs 1000 match : P ????

    5. niko šveikovsky

      applause coming from this end.

      take a few days off in the real world, give yourself some fresh air.

    6. jettlarue

      Congrats mate. No more porn until its out, I want it to be extra exciting.

    7. Good Job. Soon it will be time for artwork. I’m ready for the call with my giant chest of digital tools. >:D

      _ _
      – | | | | –
      | | | | | | | |
      | |_ _| | | |_ _| |
      | | ,—‘\ /`—, | |
      | | |–, | | ,–| | |
      | \_|_/ / \ \_|_/ |
      \ / \ /

    8. “it’s amazing how much you can accomplish if you just sit and code”

      Fucking genius 😀

      7 years.. It took you fucking 7 years! <3

    9. Aww, the textbox screwed up my ascii. Oh well anyway.

    10. Underline

      nice :)
      what is left to be done?

    11. Tribes 2’s game engine (Torque – check has *infinite* terrain generation (you can walk in the same direction for days and never reach the end).

      That may be a source of help?

    12. dingdongtralala

      Isn’t Box2D open source? You could optimize it.

      Maybe you could make a custom version of Box2D for Link-Dead?

    13. I’m glad you guys are excited. but the game isn’t finished yet:). I still got to fix the netcode and then make some actual gameplay stuff.

      Andrew: hmm but does this infinite map work in multiplayer?

    14. If you’re not using C++ style tactics and techniques, why not just write in straight C altogether?

    15. finnally wen exactly isit coming

    16. Its good to hear you are making progress. I share your opininion about quick and dirty code, you dont write a public library that othe pople have to understand easy or extend it, you have to write a game by yourself in the most efficient way. But object orientiend design can also be very efficient in that case (you dont need to write/change the same shit over and over again after changing/creating something and the usability is more abstract).
      With your blog you gave me some motivation to start writing a game (i wrote some games before, but they are more code snippets than real games). I decided to make the best looking, most funny and most addictive ASCII-Game ever made :) It will be a top-perspective action shooter with roleplay elements and realicstic enemy-AI and sounds (A mix of the amiga game “Dogs Of War” and the PC game Stalker). I want to make the user aim with the mouse like in Soldat, in future i plan to enable multiplayer playing. Ive spent some hours with coding the map editor in C++ (i have some yoears of coding expierience in industry), i make good progress, i managed to draw with mouse in a virtual buffer, display the buffer on screen smoothly and quickly, implemented some simple drawing functions like lines, boxes, windows etc.

      I wanted to ask you something: Would it make you angry if i would record some sounds from soldat into my game for the first official release candidate? Maybe you have some links for me where i can get some game sounds?

      Yasan v3

    17. Can you give any information about the weaponry? Will it consist of lots of automatic basically just plain ballistic firearms like in Soldat or do you think that an arsenal like the TF2 arsenal would make the game more exciting?

    18. yv3, check this out:

    19. A*|Demoniac

      Elo michal. Dobrze ze jest cos na co bede czekal dopuki bugi w 1.5 sie naprawia xD
      Kiedy wezmiesz odpoczynek od tego czlowieku? Nie ludski jestes? 😀

    20. mm youll need to make place on your blog for yv3 entries 😀

      Good work to both of ya in your projects


      So Michal stop lieing to yourself , you need to put your money where your mouth is and finish the damn fucking game , it’s about time .
      Btw , where do you get funding to slack your ass off in the meantime ( drink beer and totally slack off ) ?

    22. DARK AVENGER: I take money from the governemnt. Pretend I can’t work, drink beer all day and make babies to get even more money.


      lol Michal , you’ve cracked me up

    24. “Andrew: hmm but does this infinite map work in multiplayer?”

      Yes. Tribes 2 is all about multiplayer (its a 3D game though, not 2D – but the principle should be the same I guess!).

      The game is several years old now, but GarageGames (then Dynamix) built the Torque game engine for Tribes 2, so its much more advanced now.

      I’m not that familiar with what GarageGames have on offer (I think you can buy an indie license for $100 US?) or what you’d need to buy/look at to see how it works, you’d probably need to ask them yourself.

      And to clarify, yes it really was limitless terrain – they talked about it (this is even longer ago, in an interview some time), and from playing Tribes 2 myself, I never (nor anyone else for that matter) encountered an end to the terrain (if you’re that inclined to fly a plane in the same direction for ages).

      I’ll also point out that Tribes 2 has awesome networking code (these guys are smart heh), but that’s another discussion :)

    25. The torque terrain is “limitless” because it simply repeats itself…

      > “Before I started I got partially inspired by the article Making Wrong Code Look Wrong. I have no idea what the authors suggestions were in this article, its hard for me to understand his writing style (maybe cause he’s a programmer). Nevertheless the title of the article got me thinking.”

      I Lol’d.

      I also completely agree about C++ and a lot of its methodologies being moot. As for the “Oh, it’s great for libraries” argument: take a look at SDL or Allegro or OpenGL; these are all great and are pure C. Hell, Carmack was still coding straight C all the way up to and including Quake 3.

      There’s a lot of tricks and shortcuts one can use in “dirty c” that are non-existent or difficult to implement in purely object oriented C++.

    26. teh_ham

      So, you don’t use classes/inheritance at all MM?

    27. gnat: I think its procedurally generated, not repeating (I could be wrong!), but the same still applies to MM’s case, how to stream collision/map data over time instead of loading everything at once (which is impossible if the terrain never ends).

    28. So, you don’t use classes/inheritance at all MM? In the LD engine and game I use classes heavily, so I know what I’m talking about.
      When I look at Quake 3 source code ( C ) and compare it with Half-Life 2 ( C++ ) its obvious for me that C code is much more clearer. It looks nice, ordered and well written. HL2 code is a mess. Much like LD code at this point (maybe not as much as HL2 though).

      I also think Tribes 2 had repeating terrain, something in my head tells me that, I may have read about it. Still it would be interesting to see how they solved the multiplayer part.

    29. dingdongtralala

      Since when is Half-Life 2 open source? You got HL2 source code? GIMME THAT!!!!

    30. It was leaked onto the internet while the game was in development. :) Ah the memories.

    31. dingdongtralala

      Damn! I missed that. Can’t find any active torrents for the source code.

    32. The repayment term ranges from 1 to 30 days. They may print out long documents, when they really only need one of the pages.

    Post a comment.