Game Development Reference
In-Depth Information
, mid
, width, height);
}
}
// This function lives in vi_null.c
// byte* gfxbuf is the global graphics buffer
void VL_Startup()
{
// Original code
vwidth = 320;
vheight = 200;
if (MS_CheckParm("x2")) {
vwidth *= 2;
vheight *= 2;
} else if (MS_CheckParm("x3")) {
vwidth *= 3;
vheight *= 3;
}
if (gfxbuf == NULL)
gfxbuf = malloc(vwidth * vheight * 1);
// New code for Android
jni_printf("VL_Startup %dx%d. Calling init graphics.",vwidth, vheight);
jni_init_graphics(vwidth, vheight);
}
The function
VL_Startup
is the video startup function called by the Wolf native engine. Look closer,
and you can see that it initializes the size of the screen to a resolution of 320
200 pixels. It also checks
for the argument
x2
or
x3
(which tell the Wolf engine to double or triple the screen resolution). It also
allocates space for the video buffer. Finally, the last two lines display a debugging message and, most
importantly, tell the Java layer that the graphics have been initialized. These two lines are critical for the
game to work in Android.
×
Cascading Video Buffers
After the graphics are initialized, we can start sending video buffer updates to the main activity. To do so,
we use the C to Java callback
jni_send_pixels
in
jni_wolf.c
and
VW_UpdateScreen()
in
vi_null.c
.
jni_send_pixels
is almost identical to the callback in the previous section. The main difference
being that this callback will fire many times per second and must be as quick and nimble as possible.
•
To achieve maximum performance, the method ID for
wolf.jni.Natives.OnImageUpdate
is loaded by the native
WolfMain
implementation.
•
To speed thing up even more, the array buffer used to send the pixels to Java
(
jImage
) is created on
jni_init_graphics
using the width and height of the buffer.