1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
#include "video/video.h"
#include "game/game.h"
#include "filesystem/path.h"
#include "Nebu_video.h"
#include "Nebu_input.h"
#include "Nebu_scripting.h"
void displayGame(void) {
drawGame();
SystemSwapBuffers();
}
int initWindow(void) {
int win_id;
int flags;
char fullscreen = 0;
/* char buf[20]; */
SystemInitWindow(0, 0, getSettingi("width"), getSettingi("height"));
if(getSettingi("windowMode") == 0) {
fullscreen = SYSTEM_FULLSCREEN;
}
flags = SYSTEM_RGBA | SYSTEM_DOUBLE | SYSTEM_DEPTH;
if(getSettingi("bitdepth_32"))
flags |= SYSTEM_32_BIT;
if(getSettingi("use_stencil"))
flags |= SYSTEM_STENCIL;
SystemInitDisplayMode(flags, fullscreen);
win_id = SystemCreateWindow("gltron");
if (win_id < 0) {
if( getSettingi("use_stencil") ) {
flags &= ~SYSTEM_STENCIL;
SystemInitDisplayMode(flags, fullscreen);
win_id = SystemCreateWindow("gltron");
if(win_id >= 0) {
setSettingi("use_stencil", 0);
goto SKIP;
}
}
printf("[fatal] could not create window...exiting\n");
exit(1); /* OK: critical, no visual */
}
SKIP:
if(getSettingi("windowMode") == 0 || getSettingi("mouse_warp") == 1) {
SystemGrabInput();
} else {
SystemUngrabInput();
}
return win_id;
}
void reshape(int x, int y) {
if(x < getSettingi("height") || x < getSettingi("width"))
initGameScreen();
if(x > getSettingi("width") )
gScreen->vp_x = (x - getSettingi("width")) / 2;
if(y > getSettingi("height") )
gScreen->vp_y = (y - getSettingi("height")) / 2;
changeDisplay(-1);
}
void shutdownDisplay(Visual *d) {
deleteTextures(d);
deleteFonts();
SystemDestroyWindow(d->win_id);
// printf("[video] window destroyed\n");
}
void setupDisplay(Visual *d) {
// fprintf(stderr, "[video] trying to create window\n");
d->win_id = initWindow();
// fprintf(stderr, "[video] window created\n");
// initRenderer();
// printRendererInfo();
// printf("win_id is %d\n", d->win_id);
// fprintf(stderr, "[status] loading art\n");
loadArt();
SystemReshapeFunc(reshape);
}
static void loadModels(void) {
char *path;
int i;
/* load recognizer model */
path = getPath(PATH_DATA, "recognizer.obj");
if(path != NULL) {
recognizer = readMeshFromFile(path, TRI_MESH);
/* old code did normalize & invert normals & rescale to size = 60 */
} else {
fprintf(stderr, "fatal: could not load %s - exiting...\n", path);
exit(1); /* OK: critical, installation corrupt */
}
free(path);
/* load recognizer quad model (for recognizer outlines) */
path = getPath(PATH_DATA, "recognizer_quad.obj");
if(path != NULL) {
recognizer_quad = readMeshFromFile(path, QUAD_MESH);
/* old code did normalize & invert normals & rescale to size = 60 */
} else {
fprintf(stderr, "fatal: could not load %s - exiting...\n", path);
exit(1); /* OK: critical, installation corrupt */
}
free(path);
/* load lightcycle models */
for(i = 0; i < LC_LOD; i++) {
path = getPath(PATH_DATA, lc_lod_names[i]);
if(path != NULL) {
lightcycle[i] = readMeshFromFile(path, TRI_MESH);
} else {
fprintf(stderr, "fatal: could not load model %s - exiting...\n", lc_lod_names[i]);
exit(1); /* OK: critical, installation corrupt */
}
}
free(path);
}
void initVideoData(void) {
gScreen = (Visual*) malloc(sizeof(Visual));
gViewportType = getSettingi("display_type");
{
Visual *d = gScreen;
d->w = getSettingi("width");
d->h = getSettingi("height");
d->vp_x = 0; d->vp_y = 0;
d->vp_w = d->w; d->vp_h = d->h;
d->onScreen = -1;
d->textures = (unsigned int*) malloc(game_textures * sizeof(unsigned int));
}
gPlayerVisuals = (PlayerVisual*) malloc(MAX_PLAYERS * sizeof(PlayerVisual));
loadModels();
changeDisplay(-1);
}
void initGameScreen(void) {
Visual *d;
d = gScreen;
d->w = getSettingi("width");
d->h = getSettingi("height");
d->vp_x = 0; d->vp_y = 0;
d->vp_w = d->w; d->vp_h = d->h;
}
void resetVideoData(void) {
/* for each player */
int i;
for(i = 0; i < game->players; i++) {
PlayerVisual *pV = gPlayerVisuals + i;
{
char name[32];
sprintf(name, "model_diffuse_%d", i);
scripting_GetGlobal(name, NULL);
scripting_GetFloatArrayResult(pV->pColorDiffuse, 4);
sprintf(name, "model_specular_%d", i);
scripting_GetGlobal(name, NULL);
scripting_GetFloatArrayResult(pV->pColorSpecular, 4);
sprintf(name, "trail_diffuse_%d", i);
scripting_GetGlobal(name, NULL);
scripting_GetFloatArrayResult(pV->pColorAlpha, 4);
}
if(game->player[i].ai->active != AI_NONE) {
pV->impact_radius = 0.0;
pV->exp_radius = 0;
} else {
pV->exp_radius = EXP_RADIUS_MAX;
}
}
}
void initDisplay(Visual *d, int type, int p, int onScreen) {
int field;
field = gScreen->vp_w / 32;
d->h = gScreen->h;
d->w = gScreen->w;
d->vp_x = gScreen->vp_x + vp_x[type][p] * field;
d->vp_y = gScreen->vp_y + vp_y[type][p] * field;
d->vp_w = vp_w[type][p] * field;
d->vp_h = vp_h[type][p] * field;
d->onScreen = onScreen;
}
static void defaultViewportPositions(void) {
viewport_content[0] = 0;
viewport_content[1] = 1;
viewport_content[2] = 2;
viewport_content[3] = 3;
}
/*
autoConfigureDisplay - configure viewports so every human player has one
*/
static void autoConfigureDisplay(void) {
int n_humans = 0;
int i;
int vp;
defaultViewportPositions();
/* loop thru players and find the humans */
for (i=0; i < game->players; i++) {
if (game->player[i].ai->active == AI_HUMAN) {
viewport_content[n_humans] = i;
n_humans++;
}
}
switch(n_humans) {
case 0 :
/*
Not sure what the default should be for
a game without human players. For now
just show a single viewport.
*/
/* fall thru */
case 1 :
vp = VP_SINGLE;
break;
case 2 :
vp = VP_SPLIT;
break;
default :
defaultViewportPositions();
vp = VP_FOURWAY;
}
updateDisplay(vp);
}
void changeDisplay(int view) {
/* passing -1 to changeDisplay tells it to use the view from settings */
if (view == -1) {
view = getSettingi("display_type");
}
if (view == 3) {
autoConfigureDisplay();
} else {
defaultViewportPositions();
updateDisplay(view);
}
// displayMessage(TO_STDOUT, "set display to %d", view);
setSettingi("display_type", view);
}
void updateDisplay(int vpType) {
int i;
gViewportType = vpType;
for (i = 0; i < game->players; i++) {
gPlayerVisuals[i].display.onScreen = 0;
}
for (i = 0; i < vp_max[vpType]; i++) {
initDisplay(& gPlayerVisuals[ viewport_content[i] ].display,
vpType, i, 1);
}
}
void Video_Idle(void) { }
|