Skip to content

Commit

Permalink
World: Integrated Hand and added FrameBegin, FrameEnd audiences
Browse files Browse the repository at this point in the history
Plus some minor rename refactorings.
  • Loading branch information
danij-deng committed Jun 25, 2013
1 parent c80d795 commit 89a5612
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 107 deletions.
12 changes: 2 additions & 10 deletions doomsday/client/include/render/r_main.h
Expand Up @@ -105,16 +105,6 @@ void R_Shutdown(void);

void R_Ticker(timespan_t time);

/**
* Prepare for rendering view(s) of the world.
*/
void R_BeginWorldFrame(void);

/**
* Wrap up after drawing view(s) of the world.
*/
void R_EndWorldFrame(void);

/**
* Render all view ports in the viewport grid.
*/
Expand Down Expand Up @@ -144,6 +134,8 @@ void R_UpdateViewer(int consoleNum);

void R_ResetViewer(void);

int R_NextViewer(void);

/**
* Update the sharp world data by rotating the stored values of plane
* heights and sharp camera positions.
Expand Down
25 changes: 18 additions & 7 deletions doomsday/client/include/world/map.h
Expand Up @@ -30,6 +30,10 @@
#include "p_particle.h"
#include "Polyobj"

#ifdef __CLIENT__
# include "world/world.h"
#endif

class BspLeaf;
class BspNode;
class Line;
Expand Down Expand Up @@ -85,6 +89,9 @@ class Thinkers;
* @ingroup world
*/
class Map
#ifdef __CLIENT__
: DENG2_OBSERVES(World, FrameBegin)
#endif
{
DENG2_NO_COPY (Map)
DENG2_NO_ASSIGN(Map)
Expand All @@ -108,13 +115,18 @@ class Map
#endif

/*
* Observers to be notified when a one-way window construct is first found.
* Notified when the map is about to be deleted.
*/
DENG2_DEFINE_AUDIENCE(Deletion, void mapBeingDeleted(Map const &map))

/*
* Notified when a one-way window construct is first found.
*/
DENG2_DEFINE_AUDIENCE(OneWayWindowFound,
void oneWayWindowFound(Line &line, Sector &backFacingSector))

/*
* Observers to be notified when an unclosed sector is first found.
* Notified when an unclosed sector is first found.
*/
DENG2_DEFINE_AUDIENCE(UnclosedSectorFound,
void unclosedSectorFound(Sector &sector, Vector2d const &nearPoint))
Expand Down Expand Up @@ -677,12 +689,11 @@ class Map
*/
void initLightGrid();

#endif // __CLIENT__
protected:
/// Observes World FrameBegin
void worldFrameBegins(World &world, bool resetNextViewer);

/**
* To be called following an engine reset to update the map state.
*/
void update();
#endif // __CLIENT__

public: /// @todo Make private:

Expand Down
60 changes: 50 additions & 10 deletions doomsday/client/include/world/world.h
Expand Up @@ -37,10 +37,14 @@

#include "uri.hh"

#include "world/map.h"
#ifdef __CLIENT__
class Hand;
#endif

namespace de {

class Map;

/**
* @ingroup world
*/
Expand All @@ -54,9 +58,21 @@ class World
DENG2_ERROR(MapError);

/**
* Audience that will be notified when the "current" map changes.
* Notified when the "current" map changes.
*/
DENG2_DEFINE_AUDIENCE(MapChange, void worldMapChanged(World &world))

#ifdef __CLIENT__
/**
* Notified when the "current" frame begins.
*/
DENG2_DEFINE_AUDIENCE(MapChange, void currentMapChanged())
DENG2_DEFINE_AUDIENCE(FrameBegin, void worldFrameBegins(World &world, bool resetNextViewer))

/**
* Notified when the "current" frame ends.
*/
DENG2_DEFINE_AUDIENCE(FrameEnd, void worldFrameEnds(World &world))
#endif

public:
/**
Expand All @@ -69,6 +85,19 @@ class World
*/
static void consoleRegister();

/**
* To be called to reset the world back to the initial state. Any currently
* loaded map will be unloaded and player states are re-initialized.
*
* @todo World should observe GameChange.
*/
void reset();

/**
* To be called following an engine reset to update the world state.
*/
void update();

/**
* Returns @c true iff a map is currently loaded.
*/
Expand Down Expand Up @@ -96,18 +125,29 @@ class World
*/
inline void unloadMap() { changeMap(Uri()); }

#ifdef __CLIENT__
/**
* To be called to reset the world back to the initial state. Any currently
* loaded map will be unloaded and player states are re-initialized.
*
* @todo World should observe GameChange.
* To be called at the beginning of a render frame, so that we can prepare for
* drawing view(s) of the current map.
*/
void reset();
void beginFrame(bool resetNextViewer = false);

/**
* To be called following an engine reset to update the world state.
* To be called at the end of a render frame, so that we can finish up any tasks
* that must be completed after view(s) have been drawn.
*/
void update();
void endFrame();

/**
* Returns the hand of the "user" in the world. Used for manipulating elements
* for the purposes of runtime map editing.
*
* @param distance The current distance of the hand from the viewer will be
* written here if not @c 0.
*/
Hand &hand(coord_t *distance = 0) const;

#endif // __CLIENT__

private:
DENG2_PRIVATE(d)
Expand Down
69 changes: 6 additions & 63 deletions doomsday/client/src/render/r_main.cpp
Expand Up @@ -49,10 +49,6 @@ float devCameraMovementStartTime = 0; // sysTime
float devCameraMovementStartTimeRealSecs = 0;
#endif

BEGIN_PROF_TIMERS()
PROF_MOBJ_INIT_ADD
END_PROF_TIMERS()

D_CMD(ViewGrid);

int validCount = 1; // Increment every time a check is made.
Expand All @@ -75,7 +71,7 @@ byte texGammaLut[256];

fontid_t fontFixed, fontVariable[FONTSTYLE_COUNT];

static boolean resetNextViewer = true;
static int resetNextViewer = true;

static viewdata_t viewDataOfConsole[DDMAXPLAYERS]; // Indexed by console number.

Expand Down Expand Up @@ -565,6 +561,11 @@ void R_ResetViewer()
resetNextViewer = 1;
}

int R_NextViewer()
{
return resetNextViewer;
}

void R_InterpolateViewer(viewer_t *start, viewer_t *end, float pos, viewer_t *out)
{
float inv = 1 - pos;
Expand Down Expand Up @@ -733,64 +734,6 @@ END_PROF( PROF_MOBJ_INIT_ADD );
#endif
}

void R_BeginWorldFrame()
{
#ifdef __CLIENT__

// Clear all flags that can be cleared before each frame.
foreach(Sector *sector, App_World().map().sectors())
{
sector->_frameFlags &= ~SIF_FRAME_CLEAR;
}

App_World().map().lerpTrackedPlanes(resetNextViewer);
App_World().map().lerpScrollingSurfaces(resetNextViewer);

if(!freezeRLs)
{
// Initialize and/or update the LightGrid.
App_World().map().initLightGrid();

SB_BeginFrame();
LO_BeginWorldFrame();
R_ClearObjlinksForFrame(); // Zeroes the links.

// Clear the objlinks.
R_InitForNewFrame();

// Generate surface decorations for the frame.
Rend_DecorBeginFrame();

// Spawn omnilights for decorations.
Rend_DecorAddLuminous();

// Spawn omnilights for mobjs.
LO_AddLuminousMobjs();

// Create objlinks for mobjs.
R_CreateMobjLinks();

// Link all active particle generators into the world.
P_CreatePtcGenLinks();

// Link objs to all contacted surfaces.
R_LinkObjs();
}

#endif
}

void R_EndWorldFrame()
{
#ifdef __CLIENT__
if(!freezeRLs)
{
// Wrap up with Source, Bias lights.
SB_EndFrame();
}
#endif
}

void R_UpdateViewer(int consoleNum)
{
DENG_ASSERT(consoleNum >= 0 && consoleNum < DDMAXPLAYERS);
Expand Down
20 changes: 10 additions & 10 deletions doomsday/client/src/ui/widgets/legacywidget.cpp
Expand Up @@ -29,7 +29,9 @@
#include "dd_main.h"
#include "dd_loop.h"
#include "sys_system.h"
#include "edit_bias.h"
#ifdef __CLIENT__
# include "edit_bias.h"
#endif
#include "world/map.h"
#include "network/net_main.h"
#include "render/r_main.h"
Expand Down Expand Up @@ -75,11 +77,9 @@ DENG2_PIMPL(LegacyWidget)
{
if(App_GameLoaded())
{
// Interpolate the world ready for drawing view(s) of it.
if(App_World().hasMap())
{
R_BeginWorldFrame();
}
// Notify the world that a new render frame has begun.
App_World().beginFrame(CPP_BOOL(R_NextViewer()));

R_RenderViewPorts();
}
else if(titleFinale == 0)
Expand Down Expand Up @@ -114,8 +114,8 @@ DENG2_PIMPL(LegacyWidget)

if(drawGame)
{
// Shadow Bias Editor HUD (if it is active).
SBE_DrawHUD();
// Draw the widgets of the Shadow Bias Editor (if active).
SBE_DrawGui();

/*
* Draw debug information.
Expand All @@ -127,8 +127,8 @@ DENG2_PIMPL(LegacyWidget)
Net_Drawer();
S_Drawer();

// Finish up any tasks that must be completed after view(s) have been drawn.
R_EndWorldFrame();
// Notify the world that we've finished rendering the frame.
App_World().endFrame();
}

if(UI_IsActive())
Expand Down

0 comments on commit 89a5612

Please sign in to comment.