Animated sprites

Every few weeks I hear this question: is it possible to have an animated sprite in a panel? Normally, I would answer "no" but this magazine proves me once again that I am wrong; we can create a sprite "entity" and place it anywhere on the screen.

First of all we create the panel:

panel energy_pan // background panel
{
bmap = panel_pcx;
layer = 20;
pos_x = 0;
pos_y = 0;
flags = d3d, overlay, refresh, visible;
}

Then we create the sprite entity, our animated sprite:

entity energy_sprite
{
type = <energy+10.pcx>;
layer = 25;
view = camera;
x = 350;
y = 134;
z = 124;
flags = visible, flare, bright;
}

It is important to choose the correct x y z values because they will help you place the sprite in the place and with the size you need. All we need to do now is to change the animation frames using a simple function:
function init_animsprite()
{
while (1)
{
energy_sprite.frame += 0.3 * time;
if (energy_sprite.frame > 10)
{
energy_sprite.frame %= 10; // loop
}
wait (1);
}
}
You can see that the sprite has 10 animation frames that will run in a loop; the animation speed can be changed if you modify 0.3.

New debug code

I'm pretty sure that you know the rows of numbers that appear when you press the "D" key while running a level. I have to admit that I was pretty scared when I saw all those values (I'm still scared, but please keep the secret) mostly because I couldn't tell what they were. This new debug code will show a panel with many important figures and text that explains what they are. I hope that you will be able to optimize your levels with this new tool.

Let's take a look at the interesting values offered by the engine:
- num_actions, number of currently running actions;
- num_visents, number of visible entities;
- num_visentpolys, visible model and sprite polys;
- num_vismappolys, visible map and wmb polys;
- d3d_texskins, memory used by models and sprites;
- d3d_texbmaps, memory used by panels and "entity" definitions;
- d3d_texsurfs, memory used by wmb entities;
- d3d_texsmaps, memory used by the shadow maps;
- d3d_texfree, available video memory.
All these values (and a few more) will be displayed on a panel that has this definition:

panel debug_panel
{
bmap = debug_pcx;
layer = 30;
pos_x = 0;
pos_y = 0;

digits = 40,20,5,arial10_font,1,num_actions;
digits = 40,60,5,arial10_font,1,num_visents;
digits = 40,100,5,arial10_font,1,num_visentpolys;
digits = 40,142,5,arial10_font,1,num_vismappolys;
digits = 40,186,5,arial10_font,1,temp_texskins;
digits = 40,230,5,arial10_font,1,temp_texbmaps;
digits = 40,274,5,arial10_font,1,temp_texsurfs;
digits = 40,321,5,arial10_font,1,temp_texsmaps;
digits = 40,364,5,arial10_font,1,temp_total;
digits = 40,410,5,arial10_font,1,temp_free;
digits = 40,455,5,arial10_font,16,temp_fps;

flags = overlay, refresh, d3d;
}

You can see that some of the values inside the panel definition appear without changes; the other values are calculated inside a while loop:

function toggle_debug()
{
on_d = null; // deactivate the standard debug panel
while (1)
{
temp_texskins = d3d_texskins / 1024;
temp_texbmaps = d3d_texbmaps / 1024;
temp_texsurfs = d3d_texsurfs / 1024;
temp_texsmaps = d3d_texsmaps / 1024;
temp_total = (d3d_texskins + d3d_texbmaps + d3d_texsurfs + d3d_texsmaps) / 1024;
temp_free = d3d_texfree / 1024;
temp_fps = 0.9 * temp_fps + 0.1 / time;
if (key_d == 1)
{
while (key_d == 1) {wait (1);}
debug_panel.visible = (debug_panel.visible == off);
}
wait (1);
}
}

The first line deactivated the standard debug panel that appear when we press "D". All the values related to the video memory are expressed in Kb, so we divide them by 1024 to get them in Mb. We add all these values to get the memory used in the level and we compute the frame rate (1 / time) fast in order to see any frame rate drop / increase. The panel will appear / disappear when we press "D".

Please note that d3d_texfree can show a value that is bigger than the memory installed on your video card, because many modern 3D cards use different compression algorithms. Some of your customers will use older cards so it is better to keep an eye on "Total memory used" instead of "Texture free".