sábado, 26 de abril de 2008

Current experiments

Currently I'm prototyping a few ideas for carcode features, I have to plan very well what I'm gonna do as everything should be flexible in order to facilitate future development, here are a few things I have been doing:

Tracer lines

One of the features needed was to implement tracer lines, my initial idea was to use an additional surface and just draw them there, this worked well and was very easy to implement, however, this restricts the level size to the screen size, in the future we want to be able to work with maps bigger than the screen.

To alleviate this problem I just recorded the lines coordinates as they where being draw, each new line is checked against the last one in order to see if they have the same angle, if they do we only extend the last line, this helps a lot with memory consumption. In a test I did I generated around 680 lines by just moving forward and doing a half curve, this was reduced to just 15 lines with the checks in place.

OpenGL Rendering

I have a branch with OpenGL rendering as an experiment, which could potentially help with many features, it makes easy to implement big levels and corrects visual problems (skewing) introduced by rotozoom function used to rotate the car surface. Additionally OpenGL rendering is very fast in my machine (with a puny old intel graphics card, mind you), faster than plain pygame.

This could be a good enhancement has it will facilitate future development, we could substitute pixel graphics for 3D models.

jueves, 24 de abril de 2008

Carcode gsoc08 branch, rev49

Originally from http://cdrv.centralnogales.com/?p=76, from 21 April.

This revision makes some deep changes to the carcode structure, which includes rendering and event handling, this in order to accommodate later features such as scripting.

Current state, sound works, the car moves as with original code, there is now a working tracer line.

Rendering

Initialization, mainloop and event dispatching are now handled by the CarcodeApp class, this creates the main window surface and an instance of Arena which handles rendering.

I rewrote the arena code, we now use two surfaces, one for the background (unused still) and other for the tracer, the rendering loop goes more or less like this:

  • Clean the background
  • Draw all entities of the arena, not including the car
  • Draw the tracer surface
  • Draw the car

The arena code handles the tracer too, it first gets the current position of the car, then tells the car to self update and draw, then we get the new position, we do a few checks in order to not draw lines across the screen when the car passes from side to side, and the just draw a line from original position to new one.

Event Handling

The new CarcodeApp class handles all initialization and event handling work, we use a dictionary of Key Codes and Functions to handle keyboard input, just like old Arena code, but we use the function add_key to hook new functions.