Skip to content

Commit

Permalink
Added separate view variables for each local player
Browse files Browse the repository at this point in the history
Separate values for view origin, angle and pitch are now stored in
viewdata_t for each local player.
  • Loading branch information
danij-deng committed Dec 11, 2011
1 parent 5aa321e commit 0f3d0a7
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 162 deletions.
5 changes: 0 additions & 5 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -284,11 +284,6 @@ enum {
DD_OPENTOP,
DD_OPENBOTTOM,
DD_LOWFLOOR,
DD_VIEW_X,
DD_VIEW_Y,
DD_VIEW_Z,
DD_VIEW_ANGLE,
DD_VIEW_PITCH,
DD_CPLAYER_THRUST_MUL_OBSOLETE, // obsolete
DD_GRAVITY,
DD_PSPRITE_OFFSET_X, // 10x
Expand Down
9 changes: 5 additions & 4 deletions doomsday/engine/api/doomsday.def
Expand Up @@ -5,9 +5,6 @@ NAME "DOOMSDAY"
; Free ordinals:
; 45 formerly B_BindingsForCommand
; 65 formerly P_GetBlockRootIdx
; 68 formerly P_BlockLinesIterator
; 69 formerly P_BlockMobjsIterator
; 70 formerly P_BlockPolyobjsIterator
; 77 formerly P_LoadBlockMap
; 78 formerly P_LoadReject
; 95 formerly R_FlatNumForName
Expand Down Expand Up @@ -342,6 +339,10 @@ EXPORTS
R_SetViewWindow @92 NONAME
R_GetViewPort @430 NONAME
R_SetViewPortPlayer @450 NONAME
R_SetViewOrigin @68 NONAME
R_SetViewAngle @69 NONAME
R_SetViewPitch @70 NONAME

R_SetBorderGfx @93 NONAME
R_GetSpriteInfo @94 NONAME
R_GetPatchInfo @237 NONAME
Expand All @@ -350,7 +351,7 @@ EXPORTS
R_CreateAnimGroup @241 NONAME
R_AddToAnimGroup @242 NONAME
R_HSVToRGB @439 NONAME
R_CreateColorPalette @444 NONAME
R_CreateColorPalette @444 NONAME
R_GetColorPaletteNumForName @446 NONAME
R_GetColorPaletteNameForNum @445 NONAME
R_GetColorPaletteRGBf @423 NONAME
Expand Down
5 changes: 5 additions & 0 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -334,6 +334,11 @@ extern "C" {
void R_SetViewWindow(int x, int y, int w, int h);
int R_GetViewPort(int player, int* x, int* y, int* w, int* h);
void R_SetViewPortPlayer(int consoleNum, int viewPlayer);

void R_SetViewOrigin(int player, float const origin[3]);
void R_SetViewAngle(int player, angle_t angle);
void R_SetViewPitch(int player, float pitch);

void R_SetBorderGfx(char* lumps[9]);
boolean R_GetSpriteInfo(int sprite, int frame,
spriteinfo_t* sprinfo);
Expand Down
9 changes: 6 additions & 3 deletions doomsday/engine/portable/include/r_main.h
Expand Up @@ -43,6 +43,8 @@ typedef struct viewer_s {
typedef struct viewdata_s {
viewer_t current; // Current view paramaters.
viewer_t lastSharp[2]; // For smoothing.
viewer_t latest; // Sharp values taken from here.

float frontVec[3], upVec[3], sideVec[3];
float viewCos, viewSin;

Expand All @@ -51,9 +53,6 @@ typedef struct viewdata_s {
float frozenPitch;
} viewdata_t;

extern float viewX, viewY, viewZ, viewPitch;
extern int viewAngle;

extern float frameTimePos; // 0...1: fractional part for sharp game tics
extern int loadInStartupMode;
extern int validCount;
Expand Down Expand Up @@ -85,4 +84,8 @@ void R_SetViewGrid(int numCols, int numRows);
void R_SetViewWindow(int x, int y, int w, int h);
void R_SetViewPortPlayer(int consoleNum, int viewPlayer);

void R_SetViewOrigin(int consoleNum, float const origin[3]);
void R_SetViewAngle(int consoleNum, angle_t angle);
void R_SetViewPitch(int consoleNum, float pitch);

#endif
35 changes: 0 additions & 35 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -973,21 +973,6 @@ void* DD_GetVariable(int ddvalue)
case DD_GAME_EXPORTS:
return &gx;

case DD_VIEW_X:
return &viewX;

case DD_VIEW_Y:
return &viewY;

case DD_VIEW_Z:
return &viewZ;

case DD_VIEW_ANGLE:
return &viewAngle;

case DD_VIEW_PITCH:
return &viewPitch;

case DD_SECTOR_COUNT:
return &numSectors;

Expand Down Expand Up @@ -1150,26 +1135,6 @@ void DD_SetVariable(int ddvalue, void *parm)
{
switch(ddvalue)
{
case DD_VIEW_X:
viewX = *(float*) parm;
return;

case DD_VIEW_Y:
viewY = *(float*) parm;
return;

case DD_VIEW_Z:
viewZ = *(float*) parm;
return;

case DD_VIEW_ANGLE:
viewAngle = *(angle_t*) parm;
return;

case DD_VIEW_PITCH:
viewPitch = *(float*) parm;
return;

/*case DD_CPLAYER_THRUST_MUL:
cplrThrustMul = *(float*) parm;
return;*/
Expand Down
49 changes: 36 additions & 13 deletions doomsday/engine/portable/src/r_main.c
Expand Up @@ -74,8 +74,6 @@ int validCount = 1; // Increment every time a check is made.
int frameCount; // Just for profiling purposes.
int rendInfoTris = 0;
int useVSync = 0;
float viewX = 0, viewY = 0, viewZ = 0, viewPitch = 0;
int viewAngle = 0;
boolean setSizeNeeded;

// Precalculated math tables.
Expand Down Expand Up @@ -153,6 +151,39 @@ void R_SetViewWindow(int x, int y, int w, int h)
viewheight = h;
}

/// \note Part of the Doomsday public API.
void R_SetViewOrigin(int consoleNum, float const origin[3])
{
int p = P_ConsoleToLocal(consoleNum);
if(p != -1)
{
viewdata_t* vd = &viewData[p];
V3_Copy(vd->latest.pos, origin);
}
}

/// \note Part of the Doomsday public API.
void R_SetViewAngle(int consoleNum, angle_t angle)
{
int p = P_ConsoleToLocal(consoleNum);
if(p != -1)
{
viewdata_t* vd = &viewData[p];
vd->latest.angle = angle;
}
}

/// \note Part of the Doomsday public API.
void R_SetViewPitch(int consoleNum, float pitch)
{
int p = P_ConsoleToLocal(consoleNum);
if(p != -1)
{
viewdata_t* vd = &viewData[p];
vd->latest.pitch = pitch;
}
}

/**
* Retrieve the dimensions of the specified viewport by console player num.
*/
Expand Down Expand Up @@ -419,21 +450,13 @@ void R_CheckViewerLimits(viewer_t* src, viewer_t* dst)
*/
void R_GetSharpView(viewer_t* view, player_t* player)
{
viewdata_t* vd = &viewData[player - ddPlayers];
ddplayer_t* ddpl;

if(!player || !player->shared.mo)
{
return;
}

if(!player || !player->shared.mo) return;
ddpl = &player->shared;

view->pos[VX] = viewX;
view->pos[VY] = viewY;
view->pos[VZ] = viewZ;
/* $unifiedangles */
view->angle = viewAngle;
view->pitch = viewPitch;
R_CopyViewer(view, &vd->latest);

if((ddpl->flags & DDPF_CHASECAM) && !(ddpl->flags & DDPF_CAMERA))
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/r_util.c
Expand Up @@ -213,7 +213,7 @@ static angle_t pointToAngle(float x, float y)
* @param x X coordinate to test.
* @param y Y coordinate to test.
*
* @return angle_t Angle between the test point and viewX,y.
* @return angle_t Angle between the test point and view x,y.
*/
angle_t R_PointToAngle(float x, float y)
{
Expand Down
10 changes: 3 additions & 7 deletions doomsday/plugins/common/src/p_start.c
Expand Up @@ -537,13 +537,9 @@ void P_SpawnPlayer(int plrNum, playerclass_t pClass, float x, float y,
NetSv_SendPlayerInfo(plrNum, DDSP_ALL_PLAYERS);
#endif

if(plrNum == DISPLAYPLAYER)
{
// The display player has been spawned, so tell the engine where
// the camera is initially located. After this it will be updated
// after every game tick.
R_UpdateConsoleView(plrNum);
}
// Player has been spawned, so tell the engine where the camera is
// initially located. After this it will be updated after every game tick.
R_UpdateConsoleView(plrNum);
}

static void spawnPlayer(int plrNum, playerclass_t pClass, float x, float y,
Expand Down
12 changes: 8 additions & 4 deletions doomsday/plugins/common/src/p_tick.c
Expand Up @@ -100,9 +100,10 @@ void P_RunPlayers(timespan_t ticLength)
*/
void P_DoTick(void)
{
int i;

// If the game is paused, nothing will happen.
if(paused)
return;
if(paused) return;

actualMapTime++;

Expand Down Expand Up @@ -135,8 +136,11 @@ void P_DoTick(void)
P_AnimateSurfaces();
#endif

// Let the engine know where the viewplayer is now.
R_UpdateConsoleView(DISPLAYPLAYER);
// Let the engine know where the local players are now.
for(i = 0; i < MAXPLAYERS; ++i)
{
R_UpdateConsoleView(i);
}

// For par times, among other things.
mapTime++;
Expand Down
37 changes: 15 additions & 22 deletions doomsday/plugins/common/src/r_common.c
Expand Up @@ -279,30 +279,23 @@ void R_CycleGammaLevel(void)
* sharp camera position and angles are available when the new sharp world is
* saved.
*
* @note Currently this assumes that there is only a single local player and
* a single viewport visible at a time. For multiple local players
* there should be a separate DD_VIEW_* variables.
*
* @param player Player # to update.
*/
void R_UpdateConsoleView(int player)
{
float viewPos[3], viewPitch;
angle_t viewAngle;
player_t* plr = &players[player];

if(IS_DEDICATED || player < 0 || player >= MAXPLAYERS)
return;

viewPos[VX] = plr->plr->mo->pos[VX] + plr->viewOffset[VX];
viewPos[VY] = plr->plr->mo->pos[VY] + plr->viewOffset[VY];
viewPos[VZ] = plr->viewZ + plr->viewOffset[VZ];
viewAngle = plr->plr->mo->angle + (int) (ANGLE_MAX * -G_GetLookOffset(player));
viewPitch = plr->plr->lookDir;

DD_SetVariable(DD_VIEW_X, &viewPos[VX]);
DD_SetVariable(DD_VIEW_Y, &viewPos[VY]);
DD_SetVariable(DD_VIEW_Z, &viewPos[VZ]);
DD_SetVariable(DD_VIEW_ANGLE, &viewAngle);
DD_SetVariable(DD_VIEW_PITCH, &viewPitch);
float 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) return; // Not present?

viewOrigin[VX] = mo->pos[VX] + plr->viewOffset[VX];
viewOrigin[VY] = mo->pos[VY] + plr->viewOffset[VY];
viewOrigin[VZ] = plr->viewZ + plr->viewOffset[VZ];
R_SetViewOrigin(player, viewOrigin);
R_SetViewAngle(player, mo->angle + (int) (ANGLE_MAX * -G_GetLookOffset(player)));
R_SetViewPitch(player, plr->plr->lookDir);
}
19 changes: 2 additions & 17 deletions doomsday/plugins/jdoom/src/d_refresh.c
Expand Up @@ -224,8 +224,6 @@ static void rendPlayerView(int player)
{
player_t* plr = &players[player];
float pspriteOffsetY;
int viewAngle;
float viewPitch;
int isFullBright = ((plr->powers[PT_INFRARED] > 4 * 32) ||
(plr->powers[PT_INFRARED] & 8) ||
plr->powers[PT_INVULNERABILITY] > 30);
Expand All @@ -236,22 +234,9 @@ static void rendPlayerView(int player)
R_SetAllDoomsdayFlags();
}

/// @todo Each player needs their own view variables.
/// @see R_UpdateConsoleView()
/*
viewPos[VX] = plr->plr->mo->pos[VX] + plr->viewOffset[VX];
viewPos[VY] = plr->plr->mo->pos[VY] + plr->viewOffset[VY];
viewPos[VZ] = plr->viewZ + plr->viewOffset[VZ];
DD_SetVariable(DD_VIEW_X, &viewPos[VX]);
DD_SetVariable(DD_VIEW_Y, &viewPos[VY]);
DD_SetVariable(DD_VIEW_Z, &viewPos[VZ]);
*/
// View angles are updated with fractional ticks, so we can just use the current values.
viewAngle = plr->plr->mo->angle + (int) (ANGLE_MAX * -G_GetLookOffset(player));
viewPitch = plr->plr->lookDir;
DD_SetVariable(DD_VIEW_ANGLE, &viewAngle);
DD_SetVariable(DD_VIEW_PITCH, &viewPitch);
R_SetViewAngle(player, plr->plr->mo->angle + (int) (ANGLE_MAX * -G_GetLookOffset(player)));
R_SetViewPitch(player, plr->plr->lookDir);

pspriteOffsetY = HU_PSpriteYOffset(plr);
DD_SetVariable(DD_PSPRITE_OFFSET_Y, &pspriteOffsetY);
Expand Down
19 changes: 2 additions & 17 deletions doomsday/plugins/jdoom64/src/d_refresh.c
Expand Up @@ -225,8 +225,6 @@ static void rendPlayerView(int player)
{
player_t* plr = &players[player];
float pspriteOffsetY;
int viewAngle;
float viewPitch;
int isFullBright = ((plr->powers[PT_INFRARED] > 4 * 32) ||
(plr->powers[PT_INFRARED] & 8) ||
plr->powers[PT_INVULNERABILITY] > 30);
Expand All @@ -237,22 +235,9 @@ static void rendPlayerView(int player)
R_SetAllDoomsdayFlags();
}

/// @todo Each player needs their own view variables.
/// @see R_UpdateConsoleView()
/*
viewPos[VX] = plr->plr->mo->pos[VX] + plr->viewOffset[VX];
viewPos[VY] = plr->plr->mo->pos[VY] + plr->viewOffset[VY];
viewPos[VZ] = plr->viewZ + plr->viewOffset[VZ];
DD_SetVariable(DD_VIEW_X, &viewPos[VX]);
DD_SetVariable(DD_VIEW_Y, &viewPos[VY]);
DD_SetVariable(DD_VIEW_Z, &viewPos[VZ]);
*/
// View angles are updated with fractional ticks, so we can just use the current values.
viewAngle = plr->plr->mo->angle + (int) (ANGLE_MAX * -G_GetLookOffset(player));
viewPitch = plr->plr->lookDir;
DD_SetVariable(DD_VIEW_ANGLE, &viewAngle);
DD_SetVariable(DD_VIEW_PITCH, &viewPitch);
R_SetViewAngle(player, plr->plr->mo->angle + (int) (ANGLE_MAX * -G_GetLookOffset(player)));
R_SetViewPitch(player, plr->plr->lookDir);

pspriteOffsetY = HU_PSpriteYOffset(plr);
DD_SetVariable(DD_PSPRITE_OFFSET_Y, &pspriteOffsetY);
Expand Down

0 comments on commit 0f3d0a7

Please sign in to comment.