Gosmore/Hacking

From OpenStreetMap Wiki
Jump to navigation Jump to search

Prerequisites

  • Know C/C++ very well. Operator precedence, pointer reference/deference. Conditionals (?:) and macros (#define). for(;;) is a while loop.
  • Know dot products / the Cosine rule, De Morgan's law.
  • Use a debugger.
  • Use an editor with syntax highlighting to hide everything that is commented out.

What are OPTIONS ?

Through the magic of macros they are global variables, enum members, parts of the translations array and code (e.g. serialization).

Where's the documentation ?

My excuse is that I really didn't have time to write any. And many OSM users are quite poor at English. But the real reason is that I'm too scared the code will change and then the documentation will become misleading.

Search, don't scroll

Instead of passing some variables from procedure to procedure without being changed, the are made global. But their names are unique in the project, so a search will tell you when they are changed and what depends on them.

The code doesn't form these nice patterns I'm used to

If the code repeats it's more difficult to maintain, test etc. So I wrapped many things up in for loops and functions. In fact, if you see a function you can be pretty sure it is either being used more than once, or it's a callback. I learned a lot making these abstractions.

The code is so simple!

Yes, it's much simpler than most 3D game engines published 20 years ago.

But I still don't like it

Then rewrite the parts you are working on. It won't take that long and others may benefit.