Game Development Reference
In-Depth Information
where width and height are references that will store the size of the screen, and mode
is the
gl_mode
argument sent in the command line. Note that
ri.Vid_GetModeInfo
is
nothing more than a function pointer that references the real
Vid_GetModeInfo
function
declared in
vid_so.c
.
ri.Vid_GetModeInfo = Vid_GetModeInfo
This is done because, as mentioned at the beginning of the chapter, Quake II has been
greatly modularized. In the default configuration (where the client, game, and renderer
are compiled in separate libraries) functions can be called across libraries. This makes
the code very complex, but the benefits are well worth it: it's very easy to maintain and
enhance.
Vid_GetModeInfo
simply uses the value of mode to look up the video modes
table (
vid_modes
) and obtain the size of the screen.
*width = vid_modes[mode].width;
*height = vid_modes[mode].height;
Once the screen size is received,
GLimp_SetMode
sends the information back to the parent
and tells the other subsystems that a new window has been created.
*pwidth = width;
*pheight = height;
// let the sound and input subsystems know about the new window
ri.Vid_NewWindow (width, height);
In Android,
VID_NewWindow
updates the video definition with the screen values and calls the
C-to-Java callback
jni_init_video
.
viddef.width = width;
viddef.height = height;
//tell Java about it
jni_init_video (width, height);
jni_init_video
invokes the Java static method
OnInitVideo
declared in
quake.jni.Natives.
java
with the width and height of the screen.
// jni_quake.c
jmethodID mid = (*env)->GetStaticMethodID(env, jNativesCls
, "OnInitVideo"
, "(II)V");
if (mid) {
(*env)->CallStaticVoidMethod(env, jNativesCls, mid, width, height);
}
Note that the
jni_init_video
implementation is the same as Quake I in Chapter 6.