Hello Everyone,
I started to watch the Videos of Casey a while ago and I'm currently at Day 16 - Compiler Switches, but I took a look at Day 26+27.
I got two little questions:
- 1st: I'm still not completly sure about the code philosophy "write the usage code first". And I want to give an example:
- Let's say I did some foundational work for an game engine.
- Now I want to add an vectorgraphic renderer to this engine, but never did this.
So the first thing I doo is to google what vectorgraphics are about, to learn the basic foundation and the different techniques. In this case I would try to learn about the mathematical concept of vectors and which rendering techniques for vectorgraphics are common.
- After I did this I will some code that will endup being neither performance-optimized nor structural-optimized. "usage code".
- When I got the thinks I want to work and therefore I know what my renderer need to be able to and now I could write some little diagramms and try to think about the structure of this subsystem of the engine. And this structure fits in to the rest of the engine. If I'm going to encapsulate it or not and so on.
- Now I rewrite the code to fit this structure and after this, this topic is done for now (may be changed later if some other subsystems needs more stuff from this vectorrenderer etc etc.)
So does this example fit in the "write usage code first" philosophy?
- 2nd: In the "Day 26" video, Casey talks about that he wants to have the update and render functionality in one function to avoid that one object is loaded twice into the CPU cache, once for updating and once for rendering. So the whole process is brought done to an per object basis. I update an object I do some other stuff with it and render it. Then I'm going to repeat this process for the next object. But the order I update objects and the order I render objects matters for some operations. But both of these operations are dependent on other factors which determin the sequence in which these operations are executed.
What I mean is that you could create a bug if you update the wrong object first you might get a glitch (Casey used an example of a buggy collision detection of a bullet if the player moved first). But if you just depend the sequence of the update part and just render an object directly after it's updated, some rendering techniques won't work correclty. I know that 3D Alpha blending requires that you order Alpha-Rendered Objects with the distance to the camera. The Alpha-Blendet-Object that is behind the other need to be rendered first, or your blending will have a glitch, afaik. There are maybe some 2D Render techniques that require, that you render something in a specific order (layer?). So some rendering techniques require, that you render in a specific order and some updates require that you update in a specific order.
So at the moment I don't know how to avoid this problem (maybe Casey talks about this in a later Episode). So is this a problem?
Thanks in advance B)