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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
/**\file r_common.c
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* Common routines for refresh.
*/
#include <assert.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#if __JDOOM__
# include "jdoom.h"
#elif __JDOOM64__
# include "jdoom64.h"
#elif __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#endif
#include "am_map.h"
#include "p_actor.h"
#include "player.h"
#include "g_common.h"
#include "g_controls.h"
#include "x_hair.h"
#include "r_common.h"
Size2Rawf viewScale = { 1, 1 };
float aspectScale = 1;
static int gammaLevel;
#ifndef __JHEXEN__
char gammamsg[5][81];
#endif
void R_PrecachePSprites(void)
{
int i, k;
int pclass = players[CONSOLEPLAYER].class_;
if(IS_DEDICATED)
return;
for(i = 0; i < NUM_WEAPON_TYPES; ++i)
{
for(k = 0; k < NUMWEAPLEVELS; ++k)
{
pclass = players[CONSOLEPLAYER].class_;
Models_CacheForState(weaponInfo[i][pclass].mode[k].states[WSN_UP]);
Models_CacheForState(weaponInfo[i][pclass].mode[k].states[WSN_DOWN]);
Models_CacheForState(weaponInfo[i][pclass].mode[k].states[WSN_READY]);
Models_CacheForState(weaponInfo[i][pclass].mode[k].states[WSN_ATTACK]);
Models_CacheForState(weaponInfo[i][pclass].mode[k].states[WSN_FLASH]);
#if __JHERETIC__ || __JHEXEN__
Models_CacheForState(weaponInfo[i][pclass].mode[k].states[WSN_ATTACK_HOLD]);
#endif
}
}
}
/// @return @c true= maximized view window is in effect.
static dd_bool maximizedViewWindow(int player)
{
player_t* plr = players + player;
if(player < 0 || player >= MAXPLAYERS)
{
Con_Error("maximizedViewWindow: Invalid player #%i.", player);
abort();
}
return (!(G_GameState() == GS_MAP && cfg.common.screenBlocks <= 10 &&
!(P_MobjIsCamera(plr->plr->mo) && Get(DD_PLAYBACK)))); // $democam: can be set on every game tic.
}
static void calcStatusBarSize(Size2Raw* size, Size2Rawf* viewScale, int maxWidth)
{
#if __JDOOM__ || __JHERETIC__ || __JHEXEN__
float aspectScale = cfg.common.statusbarScale;
size->width = ST_WIDTH * viewScale->height;
if(size->width > maxWidth)
aspectScale *= (float)maxWidth/size->width;
size->width *= cfg.common.statusbarScale;
size->height = floor(ST_HEIGHT * 1.2f/*aspect correct*/ * aspectScale);
#else
size->width = size->height = 0;
#endif
}
void R_StatusBarSize(int player, Size2Raw *statusBarSize)
{
Size2Raw viewSize;
R_ViewWindowSize(player, &viewSize);
calcStatusBarSize(statusBarSize, &viewScale, viewSize.width);
}
static void resizeViewWindow(int player, const RectRaw* newGeometry,
const RectRaw* oldGeometry, dd_bool interpolate)
{
RectRaw window;
assert(newGeometry);
if(player < 0 || player >= MAXPLAYERS)
{
Con_Error("resizeViewWindow: Invalid player #%i.", player);
abort(); // Unreachable.
}
// Calculate fixed 320x200 scale factors.
viewScale.width = (float)newGeometry->size.width / SCREENWIDTH;
viewScale.height = (float)newGeometry->size.height / SCREENHEIGHT;
aspectScale = newGeometry->size.width >= newGeometry->size.height? viewScale.width : viewScale.height;
// Determine view window geometry.
memcpy(&window, newGeometry, sizeof(window));
window.origin.x = window.origin.y = 0;
// Override @c cfg.common.screenBlocks and force a maximized window?
if(!maximizedViewWindow(player) && cfg.common.screenBlocks <= 10)
{
Size2Raw statusBarSize;
calcStatusBarSize(&statusBarSize, &viewScale, newGeometry->size.width);
if(cfg.common.screenBlocks != 10)
{
window.size.width = cfg.common.screenBlocks * SCREENWIDTH/10;
window.size.height = cfg.common.screenBlocks * (SCREENHEIGHT - statusBarSize.height) / 10;
window.origin.x = (SCREENWIDTH - window.size.width) / 2;
window.origin.y = (SCREENHEIGHT - statusBarSize.height - window.size.height) / 2;
}
else
{
window.origin.x = 0;
window.origin.y = 0;
window.size.width = SCREENWIDTH;
window.size.height = SCREENHEIGHT - statusBarSize.height;
}
// Scale from fixed to viewport coordinates.
window.origin.x = ROUND(window.origin.x * viewScale.width);
window.origin.y = ROUND(window.origin.y * viewScale.height);
window.size.width = ROUND(window.size.width * viewScale.width);
window.size.height = ROUND(window.size.height * viewScale.height);
}
R_SetViewWindowGeometry(player, &window, interpolate);
}
void R_ResizeViewWindow(int flags)
{
static dd_bool oldMaximized;
int i, delta, destBlocks = MINMAX_OF(3, cfg.common.setBlocks, 13);
dd_bool maximized;
RectRaw port;
if(IS_DEDICATED) return;
// Override @c cfg.common.screenBlocks and force a maximized window?
maximized = maximizedViewWindow(DISPLAYPLAYER);
if(maximized != oldMaximized)
{
oldMaximized = maximized;
flags |= RWF_FORCE|RWF_NO_LERP;
}
if(!(flags & RWF_FORCE))
{
if(cfg.common.screenBlocks == destBlocks)
return;
}
delta = MINMAX_OF(-1, destBlocks - cfg.common.screenBlocks, 1);
if(delta != 0)
{
if(cfg.common.screenBlocks >= 10 && destBlocks != 13)
{
// When going fullscreen, force a hud show event (to reset the timer).
for(i = 0; i < MAXPLAYERS; ++i)
ST_HUDUnHide(i, HUE_FORCE);
}
if((cfg.common.screenBlocks == 11 && destBlocks == 10) ||
(cfg.common.screenBlocks == 10 && destBlocks == 11))
{
// When going to/from statusbar span, do an instant change.
flags |= RWF_NO_LERP;
}
cfg.common.screenBlocks += delta;
flags |= RWF_FORCE;
}
// No update necessary?
if(!(flags & RWF_FORCE)) return;
for(i = 0; i < MAXPLAYERS; ++i)
{
if(!R_ViewPortGeometry(i, &port))
{
// Player is not local or does not have a viewport.
continue;
}
resizeViewWindow(i, &port, &port, (flags & RWF_NO_LERP)==0);
}
}
int R_UpdateViewport(int hookType, int param, void* data)
{
const ddhook_viewport_reshape_t* p = (ddhook_viewport_reshape_t*)data;
resizeViewWindow(param, &p->geometry, &p->oldGeometry, false);
return true;
}
#ifndef __JHEXEN__
void R_GetGammaMessageStrings(void)
{
int i;
for(i = 0; i < 5; ++i)
{
strcpy(gammamsg[i], GET_TXT(TXT_GAMMALVL0 + i));
}
}
#endif
void R_CycleGammaLevel(void)
{
char buf[50];
if(G_QuitInProgress()) return;
gammaLevel++;
if(gammaLevel > 4)
gammaLevel = 0;
#if __JDOOM__ || __JDOOM64__
P_SetMessage(players + CONSOLEPLAYER, LMF_NO_HIDE, gammamsg[gammaLevel]);
#endif
sprintf(buf, "rend-tex-gamma %f", ((float) gammaLevel / 8.0f) * 1.5f);
DD_Execute(false, buf);
}
/**
* Tells the engine where the camera is located. This has to be called before
* the end of G_Ticker() (after thinkers have been run), so that the up-to-date
* sharp camera position and angles are available when the new sharp world is
* saved.
*
* @param player Player # to update.
*/
void R_UpdateConsoleView(int player)
{
coord_t viewOrigin[3];
player_t* plr;
mobj_t* mo;
if(IS_DEDICATED || player < 0 || player >= MAXPLAYERS) return;
plr = &players[player];
mo = plr->plr->mo;
if(!mo || !plr->plr->inGame) return; // Not present?
viewOrigin[VX] = mo->origin[VX] + plr->viewOffset[VX];
viewOrigin[VY] = mo->origin[VY] + plr->viewOffset[VY];
viewOrigin[VZ] = plr->viewZ + plr->viewOffset[VZ];
R_SetViewOrigin(player, viewOrigin);
R_SetViewAngle(player, Player_ViewYawAngle(player));
R_SetViewPitch(player, plr->plr->lookDir);
}
static void rendHUD(int player, const RectRaw* portGeometry)
{
if(player < 0 || player >= MAXPLAYERS) return;
if(G_GameState() != GS_MAP) return;
if(IS_CLIENT && (!Get(DD_GAME_READY) || !Get(DD_GOTFRAME))) return;
if(!DD_GetInteger(DD_GAME_DRAW_HUD_HINT)) return; // The engine advises not to draw any HUD displays.
ST_Drawer(player);
HU_DrawScoreBoard(player);
Hu_MapTitleDrawer(portGeometry);
}
void G_DrawViewPort(int port, RectRaw const *portGeometry,
RectRaw const *windowGeometry, int player, int layer)
{
switch(G_GameState())
{
case GS_MAP: {
player_t* plr = players + player;
dd_bool isAutomapObscuring = ST_AutomapObscures2(player, windowGeometry);
if(IS_CLIENT && (!Get(DD_GAME_READY) || !Get(DD_GOTFRAME)))
return;
if(Con_GetInteger("rend-vr-mode") == 9) // Oculus Rift mode
{
// Automap will not cover the full view.
isAutomapObscuring = false;
}
switch(layer)
{
case 0: // Primary layer (3D view).
if(!isAutomapObscuring)
{
G_RendPlayerView(player);
#if !defined(__JDOOM__) && !defined(__JHEXEN__)
G_RendSpecialFilter(player, windowGeometry);
#endif
}
break;
default: // HUD layer.
// Crosshair.
if(!isAutomapObscuring && !(P_MobjIsCamera(plr->plr->mo) && Get(DD_PLAYBACK))) // $democam
{
X_Drawer(player);
}
// Other HUD elements.
rendHUD(player, portGeometry);
break;
}
break; }
case GS_STARTUP:
if(layer == 0)
{
DGL_DrawRectf2Color(0, 0, portGeometry->size.width, portGeometry->size.height,
0, 0, 0, 1);
}
break;
default:
break;
}
}
void G_ResetViewEffects()
{
GL_ResetViewEffects();
#if __JDOOM__
G_InitSpecialFilter();
#endif
}
|