Skip to content

Commit

Permalink
Refactor: Switched r_main.c to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 28, 2012
1 parent 6f51af9 commit 833cc1a
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 519 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/engine.pro
Expand Up @@ -553,7 +553,7 @@ SOURCES += \
src/render/lumobj.cpp \
src/render/r_draw.cpp \
src/render/r_fakeradio.c \
src/render/r_main.c \
src/render/r_main.cpp \
src/render/r_lgrid.c \
src/render/r_shadow.c \
src/render/r_things.cpp \
Expand Down
139 changes: 91 additions & 48 deletions doomsday/engine/include/render/r_main.h
@@ -1,36 +1,28 @@
/**\file r_main.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
/** @file r_main.h
*
*\author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2012 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2012 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.
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* 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
* <small>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</small>
*/

#ifndef LIBDENG_REFRESH_MAIN_H
#define LIBDENG_REFRESH_MAIN_H
#ifndef LIBDENG_RENDER_R_MAIN_H
#define LIBDENG_RENDER_R_MAIN_H

#include <de/rect.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct viewport_s {
int console;
RectRaw geometry;
Expand Down Expand Up @@ -68,49 +60,100 @@ typedef enum fontstyle_e {
FONTSTYLE_COUNT
} fontstyle_t;

extern float frameTimePos; // 0...1: fractional part for sharp game tics
extern int loadInStartupMode;
extern int validCount;
extern int frameCount;
extern int extraLight;
extern float extraLightDelta;
extern int rendInfoTris;
DENG_EXTERN_C float frameTimePos; // 0...1: fractional part for sharp game tics
DENG_EXTERN_C int loadInStartupMode;
DENG_EXTERN_C int validCount;
DENG_EXTERN_C int frameCount;
DENG_EXTERN_C int extraLight;
DENG_EXTERN_C float extraLightDelta;
DENG_EXTERN_C int rendInfoTris;

extern byte precacheMapMaterials, precacheSprites, precacheSkins;
DENG_EXTERN_C byte precacheMapMaterials, precacheSprites, precacheSkins;

extern fontid_t fontFixed, fontVariable[FONTSTYLE_COUNT];
DENG_EXTERN_C fontid_t fontFixed, fontVariable[FONTSTYLE_COUNT];

extern fixed_t fineTangent[FINEANGLES / 2];
DENG_EXTERN_C fixed_t fineTangent[FINEANGLES / 2];

#ifdef __cplusplus
extern "C" {
#endif

/**
* Register console variables.
*/
void R_Register(void);

/**
* One-time initialization of the refresh daemon. Called by DD_Main.
*/
void R_Init(void);

/**
* Re-initialize almost everything.
*/
void R_Update(void);

/**
* Shutdown the refresh daemon.
*/
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.
*/
void R_RenderViewPorts(void);

/**
* Render a blank view for the specified player.
*/
void R_RenderBlankView(void);

/**
* Draw the view of the player inside the view window.
*/
void R_RenderPlayerView(int num);

/**
* Draw the border around the view window.
*/
void R_RenderPlayerViewBorder(void);

/// @return Current viewport else @c NULL.
const viewport_t* R_CurrentViewPort(void);
/// @return Current viewport; otherwise @c NULL.
viewport_t const *R_CurrentViewPort(void);

void R_UseViewPort(viewport_t* vp);
/**
* Set the current GL viewport.
*/
void R_UseViewPort(viewport_t *vp);

const viewdata_t* R_ViewData(int consoleNum);
viewdata_t const *R_ViewData(int consoleNum);

void R_UpdateViewer(int consoleNum);

void R_ResetViewer(void);

/**
* Update the sharp world data by rotating the stored values of plane
* heights and sharp camera positions.
*/
void R_NewSharpWorld(void);

/**
* Attempt to set up a view grid and calculate the viewports. Set 'numCols' and
* 'numRows' to zero to just update the viewport coordinates.
*/
boolean R_SetViewGrid(int numCols, int numRows);

void R_SetupDefaultViewWindow(int consoleNum);
Expand Down Expand Up @@ -142,27 +185,27 @@ void R_SetViewAngle(int consoleNum, angle_t angle);
*/
void R_SetViewPitch(int consoleNum, float pitch);

int R_ViewWindowGeometry(int consoleNum, RectRaw* geometry);
int R_ViewWindowOrigin(int consoleNum, Point2Raw* origin);
int R_ViewWindowSize(int consoleNum, Size2Raw* size);
int R_ViewWindowGeometry(int consoleNum, RectRaw *geometry);
int R_ViewWindowOrigin(int consoleNum, Point2Raw *origin);
int R_ViewWindowSize(int consoleNum, Size2Raw *size);

void R_SetViewWindowGeometry(int consoleNum, const RectRaw* geometry, boolean interpolate);
void R_SetViewWindowGeometry(int consoleNum, RectRaw const *geometry, boolean interpolate);

/**
* Animates the view window towards the target values.
*/
void R_ViewWindowTicker(int consoleNum, timespan_t ticLength);

int R_ViewPortGeometry(int consoleNum, RectRaw* geometry);
int R_ViewPortOrigin(int consoleNum, Point2Raw* origin);
int R_ViewPortSize(int consoleNum, Size2Raw* size);
int R_ViewPortGeometry(int consoleNum, RectRaw *geometry);
int R_ViewPortOrigin(int consoleNum, Point2Raw *origin);
int R_ViewPortSize(int consoleNum, Size2Raw *size);

void R_SetViewPortPlayer(int consoleNum, int viewPlayer);

void R_LoadSystemFonts(void);

const char* R_ChooseFixedFont(void);
const char* R_ChooseVariableFont(fontstyle_t style, int resX, int resY);
char const *R_ChooseFixedFont(void);
char const *R_ChooseVariableFont(fontstyle_t style, int resX, int resY);

/**
* Prepare resources for the current Map.
Expand Down
22 changes: 11 additions & 11 deletions doomsday/engine/include/resource/materials.h
Expand Up @@ -25,12 +25,8 @@

#include "def_data.h"
#include "material.h"

#ifdef __cplusplus

#include "resource/materialvariant.h"

extern "C" {
# include "resource/materialvariant.h"
#endif

struct texturevariantspecification_s;
Expand Down Expand Up @@ -63,6 +59,10 @@ typedef struct materialvariantspecification_s {
struct texturevariantspecification_s *primarySpec;
} materialvariantspecification_t;

#ifdef __cplusplus
extern "C" {
#endif

/// To be called during init to register the cvars and ccmds for this module.
void Materials_Register(void);

Expand Down Expand Up @@ -201,6 +201,8 @@ struct materialvariantspecification_s const *Materials_VariantSpecificationForCo
int tMap, int wrapS, int wrapT, int minFilter, int magFilter, int anisoFilter,
boolean mipmapped, boolean gammaCorrection, boolean noStretch, boolean toAlpha);

#ifdef __cplusplus

/**
* Add a variant of @a material to the cache queue for deferred preparation.
*
Expand All @@ -210,10 +212,8 @@ struct materialvariantspecification_s const *Materials_VariantSpecificationForCo
* @param cacheGroups @c true= variants for all Materials in any applicable
* animation groups are desired, else just this specific Material.
*/
void Materials_Precache2(material_t *material, struct materialvariantspecification_s const *spec, boolean smooth, boolean cacheGroups);
void Materials_Precache(material_t *material, struct materialvariantspecification_s const *spec, boolean smooth/*, cacheGroups = true*/);

#ifdef __cplusplus
void Materials_Precache2(material_t &material, struct materialvariantspecification_s const &spec, bool smooth, bool cacheGroups);
void Materials_Precache(material_t &material, struct materialvariantspecification_s const &spec, bool smooth/*, cacheGroups = true*/);

/**
* Choose/create a variant of @a material which fulfills @a spec and then
Expand Down Expand Up @@ -261,8 +261,6 @@ struct materialsnapshot_s const *Materials_PrepareVariant(de::MaterialVariant &m
de::MaterialVariant *Materials_ChooseVariant(material_t &material,
struct materialvariantspecification_s const &spec, bool smoothed, bool canCreate);

#endif

/**
* Create a new animation group.
* @return Logical (unique) identifier reference associated with the new group.
Expand All @@ -279,6 +277,8 @@ int Materials_CreateAnimGroup(int flags);
*/
void Materials_AddAnimGroupFrame(int animGroupNum, material_t *material, int tics, int randomTics);

#endif // __cplusplus

/// @todo Refactor; does not fit the current design.
boolean Materials_IsPrecacheAnimGroup(int animGroupNum);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/resource/materialvariant.h
@@ -1,6 +1,6 @@
/** @file materialvariant.h Logical Material Variant.
*
* @authors Copyright &copy; 2011-2012 Daniel Swanson <danij@dengine.net>
* @author Copyright &copy; 2011-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down
23 changes: 13 additions & 10 deletions doomsday/engine/src/map/p_particle.c
Expand Up @@ -1380,11 +1380,13 @@ void P_SpawnDamageParticleGen(mobj_t* mo, mobj_t* inflictor, int amount)
}
}

static int findDefForGenerator(ptcgen_t* gen, void* parameters)
static int findDefForGenerator(ptcgen_t *gen, void *parameters)
{
ded_ptcgen_t* def;
ded_ptcgen_t *def;
int i;

DENG_UNUSED(parameters);

// Search for a suitable definition.
def = defs.ptcGens;
for(i = 0; i < defs.count.ptcGens.num; ++i, def++)
Expand All @@ -1409,8 +1411,8 @@ static int findDefForGenerator(ptcgen_t* gen, void* parameters)
// A flat generator?
if(gen->plane && def->material)
{
material_t* mat = gen->plane->PS_material;
material_t* defMat = Materials_ToMaterial(Materials_ResolveUri2(def->material, true/*quiet please*/));
material_t *mat = gen->plane->PS_material;
material_t *defMat = Materials_ToMaterial(Materials_ResolveUri2(def->material, true/*quiet please*/));

if(def->flags & PGF_FLOOR_SPAWN)
mat = gen->plane->sector->SP_plane(PLN_FLOOR)->PS_material;
Expand All @@ -1420,12 +1422,13 @@ static int findDefForGenerator(ptcgen_t* gen, void* parameters)
// Is this suitable?
if(mat == defMat)
{
return i+1;
return i + 1; // 1-based index.
}

if(def->flags & PGF_GROUP)
{
// Generator triggered by all materials in the (animation) group.

/**
* A search is necessary only if we know both the used material and
* the specified material in this definition are in *a* group.
Expand All @@ -1435,14 +1438,14 @@ static int findDefForGenerator(ptcgen_t* gen, void* parameters)
int g, numGroups = Materials_AnimGroupCount();
for(g = 0; g < numGroups; ++g)
{
if(Materials_IsPrecacheAnimGroup(g))
continue; // Precache groups don't apply.
// Precache groups don't apply.
if(Materials_IsPrecacheAnimGroup(g)) continue;

if(Materials_IsMaterialInAnimGroup(defMat, g) &&
Materials_IsMaterialInAnimGroup(mat, g))
{
// Both are in this group! This def will do.
return i+1;
return i + 1; // 1-based index.
}
}
}
Expand All @@ -1453,14 +1456,14 @@ static int findDefForGenerator(ptcgen_t* gen, void* parameters)
if(gen->source && def->state[0] &&
gen->source->state - states == Def_GetStateNum(def->state))
{
return i+1;
return i + 1; // 1-based index.
}
}

return 0; // Not found.
}

static int updateGenerator(ptcgen_t* gen, void* parameters)
static int updateGenerator(ptcgen_t *gen, void *parameters)
{
int defIndex;

Expand Down

0 comments on commit 833cc1a

Please sign in to comment.