Skip to content

Commit

Permalink
Refactor|libcommon|libdoom|libheretic|libhexen|libdoom64: Use de::Lum…
Browse files Browse the repository at this point in the history
…pIndex's C++ API
  • Loading branch information
danij-deng committed Jun 28, 2014
1 parent bbc9877 commit adcfd4d
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 216 deletions.
11 changes: 11 additions & 0 deletions doomsday/plugins/common/include/common.h
Expand Up @@ -46,6 +46,9 @@

#include "gamerules.h"
#include "pause.h"
#ifdef __cplusplus
# include <doomsday/filesys/lumpindex.h>
#endif

DENG_EXTERN_C dd_bool sc_FileScripts;
DENG_EXTERN_C char const *sc_ScriptsDir;
Expand All @@ -57,6 +60,14 @@ extern "C" {
int Common_GetInteger(int id);

#ifdef __cplusplus
/**
* Returns the primary LumpIndex from the engine. For use with old subsystems
* which still depend on this old fashioned mechanism for file access.
*
* @deprecated Implement file access without depending on this specialized behavior.
*/
inline de::LumpIndex const &CentralLumpIndex() { return *reinterpret_cast<de::LumpIndex *>(F_LumpIndex()); }

} // extern "C"
#endif

Expand Down
25 changes: 12 additions & 13 deletions doomsday/plugins/common/src/animdefs.cpp
Expand Up @@ -302,26 +302,25 @@ static void AnimDefsParser(ddstring_s const *path)
}
#endif // __JHEXEN__

void P_InitPicAnims(void)
void P_InitPicAnims()
{
#if __JHEXEN__
AnimDefsParser(AutoStr_FromText("Lumps:ANIMDEFS"));
#else
lumpnum_t animsLump;
if((animsLump = W_CheckLumpNumForName("ANIMATED")) > 0)
if(CentralLumpIndex().contains("ANIMATED.lmp"))
{
/**
* We'll support this BOOM extension by reading the data and then registering
* the new animations into Doomsday using the animation groups feature.
*
* Support for this extension should be considered deprecated.
* All new features should be added, accessed via DED.
*/
File1 &lump = CentralLumpIndex()[CentralLumpIndex().findLast("ANIMATED.lmp")];

// Support this BOOM extension by reading the data and then registering
// the new animations into Doomsday using the animation groups feature.
//
// Support for this extension should be considered deprecated.
// All new features should be added, accessed via DED.
LOG_RES_VERBOSE("Processing lump %s::ANIMATED")
<< NativePath(Str_Text(W_LumpSourceFile(animsLump))).pretty();
<< NativePath(lump.container().composePath()).pretty();

loadAnimDefs((TextureAnimDef *)W_CacheLump(animsLump), true);
W_UnlockLump(animsLump);
loadAnimDefs((TextureAnimDef *)lump.cache(), true);
lump.unlock();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/d_netsv.cpp
Expand Up @@ -374,7 +374,7 @@ int NetSv_ScanCycle(int index, maprule_t *rules)

sprintf(lump, "MAP%02u", m);
#endif
if(W_CheckLumpNumForName(lump) >= 0)
if(CentralLumpIndex().findLast(de::String(lump) + ".lmp") >= 0)
{
tmp[0] = episode + '0';
tmp[1] = map + '0';
Expand Down
168 changes: 82 additions & 86 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -69,6 +69,7 @@
#include <de/NativePath>
#include <doomsday/uri.h>

using namespace de;
using namespace common;

static GameSession session;
Expand Down Expand Up @@ -661,101 +662,91 @@ void R_LoadColorPalettes()
#define PALENTRIES (256)
#define PALID (0)

lumpnum_t lumpNum = W_GetLumpNumForName(PALLUMPNAME);
uint8_t colors[PALENTRIES*3];
colorpaletteid_t palId;
Str xlatId;
Str_InitStd(&xlatId);
File1 &playpal = CentralLumpIndex()[CentralLumpIndex().findLast(String(PALLUMPNAME) + ".lmp")];

// Record whether we are using a custom palette.
customPal = W_LumpIsCustom(lumpNum);
customPal = playpal.hasCustom(); // Remember whether we are using a custom palette.

W_ReadLumpSection(lumpNum, colors, 0 + PALID * (PALENTRIES * 3), PALENTRIES * 3);
palId = R_CreateColorPalette("R8G8B8", PALLUMPNAME, colors, PALENTRIES);
uint8_t colors[PALENTRIES * 3];
playpal.read(colors, 0 + PALID * (PALENTRIES * 3), PALENTRIES * 3);
colorpaletteid_t palId = R_CreateColorPalette("R8G8B8", PALLUMPNAME, colors, PALENTRIES);

ddstring_s xlatId; Str_InitStd(&xlatId);

#if __JHEXEN__
// Load the translation tables.
{
int const numPerClass = (gameMode == hexen_v10? 3 : 7);

int i, cl;
int xlatNum;
lumpnum_t lumpNum;
Str lumpName;
Str_Reserve(Str_InitStd(&lumpName), 8);

// In v1.0, the color translations are a bit different. There are only
// three translation maps per class, whereas Doomsday assumes seven maps
// per class. Thus we'll need to account for the difference.
int const numPerClass = (gameMode == hexen_v10? 3 : 7);

xlatNum = 0;
for(cl = 0; cl < 3; ++cl)
for(i = 0; i < 7; ++i)
{
if(i == numPerClass) break; // Not present.
// In v1.0, the color translations are a bit different. There are only
// three translation maps per class, whereas Doomsday assumes seven maps
// per class. Thus we'll need to account for the difference.

Str_Clear(&lumpName);
if(xlatNum < 10)
int xlatNum = 0;
for(int cl = 0; cl < 3; ++cl)
for(int i = 0; i < 7; ++i)
{
Str_Appendf(&lumpName, "TRANTBL%i", xlatNum);
}
else
{
Str_Appendf(&lumpName, "TRANTBL%c", 'A' + (xlatNum - 10));
}
xlatNum++;
if(i == numPerClass) break; // Not present.

String lumpName;
if(xlatNum < 10)
{
lumpName = String("TRANTBL%1").arg(xlatNum);
}
else
{
lumpName = String("TRANTBL%1").arg('A' + (xlatNum - 10));
}
xlatNum++;

App_Log(DE2_DEV_RES_MSG, "Reading translation table '%s' as tclass=%i tmap=%i",
Str_Text(&lumpName), cl, i);
App_Log(DE2_DEV_RES_MSG, "Reading translation table '%s' as tclass=%i tmap=%i",
lumpName.toUtf8().constData(), cl, i);

if(-1 != (lumpNum = W_CheckLumpNumForName(Str_Text(&lumpName))))
{
uint8_t const *mappings = W_CacheLump(lumpNum);
Str_Appendf(Str_Clear(&xlatId), "%i", 7 * cl + i);
R_CreateColorPaletteTranslation(palId, &xlatId, mappings);
W_UnlockLump(lumpNum);
lumpName += ".lmp";
if(CentralLumpIndex().contains(lumpName))
{
File1 &lump = CentralLumpIndex()[CentralLumpIndex().findLast(lumpName)];
uint8_t const *mappings = lump.cache();
Str_Appendf(Str_Clear(&xlatId), "%i", 7 * cl + i);
R_CreateColorPaletteTranslation(palId, &xlatId, mappings);
lump.unlock();
}
}
}

Str_Free(&lumpName);
}
#else
// Create the translation tables to map the green color ramp to gray,
// brown, red. Could be read from a lump instead?
{
uint8_t xlat[PALENTRIES];
int xlatNum, palIdx;

for(xlatNum = 0; xlatNum < 3; ++xlatNum)
{
// Translate just the 16 green colors.
for(palIdx = 0; palIdx < 256; ++palIdx)
uint8_t xlat[PALENTRIES];
for(int xlatNum = 0; xlatNum < 3; ++xlatNum)
{
# if __JHERETIC__
if(palIdx >= 225 && palIdx <= 240)
// Translate just the 16 green colors.
for(int palIdx = 0; palIdx < 256; ++palIdx)
{
xlat[palIdx] = xlatNum == 0? 114 + (palIdx - 225) /*yellow*/ :
xlatNum == 1? 145 + (palIdx - 225) /*red*/ :
190 + (palIdx - 225) /*blue*/;
}
# if __JHERETIC__
if(palIdx >= 225 && palIdx <= 240)
{
xlat[palIdx] = xlatNum == 0? 114 + (palIdx - 225) /*yellow*/ :
xlatNum == 1? 145 + (palIdx - 225) /*red*/ :
190 + (palIdx - 225) /*blue*/;
}
# else
if(palIdx >= 0x70 && palIdx <= 0x7f)
{
// Map green ramp to gray, brown, red.
xlat[palIdx] = xlatNum == 0? 0x60 + (palIdx & 0xf) :
xlatNum == 1? 0x40 + (palIdx & 0xf) :
0x20 + (palIdx & 0xf);
}
if(palIdx >= 0x70 && palIdx <= 0x7f)
{
// Map green ramp to gray, brown, red.
xlat[palIdx] = xlatNum == 0? 0x60 + (palIdx & 0xf) :
xlatNum == 1? 0x40 + (palIdx & 0xf) :
0x20 + (palIdx & 0xf);
}
# endif
else
{
// Keep all other colors as is.
xlat[palIdx] = palIdx;
else
{
// Keep all other colors as is.
xlat[palIdx] = palIdx;
}
}
Str_Appendf(Str_Clear(&xlatId), "%i", xlatNum);
R_CreateColorPaletteTranslation(palId, &xlatId, xlat);
}
Str_Appendf(Str_Clear(&xlatId), "%i", xlatNum);
R_CreateColorPaletteTranslation(palId, &xlatId, xlat);
}
}
#endif

Expand Down Expand Up @@ -927,9 +918,9 @@ void R_LoadVectorGraphics()
* @param name Name of the font to lookup.
* @return Unique id of the found font.
*/
fontid_t R_MustFindFontForName(const char* name)
fontid_t R_MustFindFontForName(char const *name)
{
Uri* uri = Uri_NewWithPath2(name, RC_NULL);
uri_s *uri = Uri_NewWithPath2(name, RC_NULL);
fontid_t fontId = Fonts_ResolveUri(uri);
Uri_Delete(uri);
if(fontId) return fontId;
Expand All @@ -945,14 +936,20 @@ void R_InitRefresh()

// Setup the view border.
cfg.screenBlocks = cfg.setBlocks;
{ Uri* paths[9];
uint i;
for(i = 0; i < 9; ++i)
paths[i] = ((borderGraphics[i] && borderGraphics[i][0])? Uri_NewWithPath2(borderGraphics[i], RC_NULL) : 0);
R_SetBorderGfx((const Uri**)paths);
for(i = 0; i < 9; ++i)
if(paths[i])
Uri_Delete(paths[i]);
{
uri_s *paths[9];
for(int i = 0; i < 9; ++i)
{
paths[i] = ((borderGraphics[i] && borderGraphics[i][0])? Uri_NewWithPath2(borderGraphics[i], RC_NULL) : 0);
}
R_SetBorderGfx((uri_s const **)paths);
for(int i = 0; i < 9; ++i)
{
if(paths[i])
{
Uri_Delete(paths[i]);
}
}
}
R_ResizeViewWindow(RWF_FORCE|RWF_NO_LERP);

Expand All @@ -971,9 +968,8 @@ void R_InitRefresh()
#endif
fonts[GF_MAPPOINT] = R_MustFindFontForName("mappoint");

{ float mul = 1.4f;
float mul = 1.4f;
DD_SetVariable(DD_PSPRITE_LIGHTLEVEL_MULTIPLIER, &mul);
}
}

void R_InitHud()
Expand Down Expand Up @@ -1646,8 +1642,8 @@ static void rebornPlayers()
if(COMMON_GAMESESSION->progressRestoredOnReload() && cfg.confirmRebornLoad)
{
S_LocalSound(SFX_REBORNLOAD_CONFIRM, NULL);
Str msg; Str_Appendf(Str_Init(&msg), REBORNLOAD_CONFIRM, COMMON_GAMESESSION->userDescription().toUtf8().constData());
Hu_MsgStart(MSG_YESNO, Str_Text(&msg), rebornLoadConfirmed, 0, 0);
AutoStr *msg = Str_Appendf(AutoStr_NewStd(), REBORNLOAD_CONFIRM, COMMON_GAMESESSION->userDescription().toUtf8().constData());
Hu_MsgStart(MSG_YESNO, Str_Text(msg), rebornLoadConfirmed, 0, 0);
return;
}

Expand Down
21 changes: 13 additions & 8 deletions doomsday/plugins/common/src/hu_automap.cpp
Expand Up @@ -38,6 +38,8 @@
#include <cstdio>
#include <cstring>

using namespace de;

#define LERP(start, end, pos) (end * pos + start * (1 - pos))

// Translate between frame and map distances:
Expand Down Expand Up @@ -182,23 +184,26 @@ void UIAutomap_ClearLists(uiwidget_t* obj)
}
}

void UIAutomap_LoadResources(void)
void UIAutomap_LoadResources()
{
LumpIndex const &lumps = CentralLumpIndex();

if(autopageLumpNum >= 0)
autopageLumpNum = W_CheckLumpNumForName("autopage");
autopageLumpNum = lumps.findLast("autopage.lmp");

if(!amMaskTexture)
{
lumpnum_t lumpNum = W_GetLumpNumForName("mapmask");
lumpnum_t lumpNum = lumps.findLast("mapmask.lmp");
if(lumpNum >= 0)
{
const uint8_t* pixels = (const uint8_t*) W_CacheLump(lumpNum);
File1 &lump = lumps[lumpNum];
uint8_t const *pixels = (uint8_t const *) lump.cache();
int width = 256, height = 256;

amMaskTexture = DGL_NewTextureWithParams(DGL_LUMINANCE, width, height, pixels,
0x8, DGL_NEAREST, DGL_LINEAR, 0 /*no anisotropy*/, DGL_REPEAT, DGL_REPEAT);

W_UnlockLump(lumpNum);
lump.unlock();
}
}
}
Expand Down Expand Up @@ -1153,6 +1158,8 @@ static void drawMarkedPoints(uiwidget_t* obj, float scale)
*/
static void setupGLStateForMap(uiwidget_t *obj)
{
DENG2_ASSERT(obj != 0 && obj->type == GUI_AUTOMAP);

//guidata_automap_t *am = (guidata_automap_t *)obj->typedata;
float const alpha = uiRendState->pageAlpha;
#if __JDOOM64__
Expand All @@ -1162,8 +1169,6 @@ static void setupGLStateForMap(uiwidget_t *obj)
coord_t plx, ply;
RectRaw geometry;

assert(obj->type == GUI_AUTOMAP);

UIAutomap_ParallaxLayerOrigin(obj, &plx, &ply);
angle = UIAutomap_CameraAngle(obj);

Expand All @@ -1176,7 +1181,7 @@ static void setupGLStateForMap(uiwidget_t *obj)
DGL_PushMatrix();

#if __JHERETIC__ || __JHEXEN__
if(W_CheckLumpNumForName("AUTOPAGE") == -1)
if(!CentralLumpIndex().contains("AUTOPAGE.lmp"))
{
bgColor[CR] = .55f; bgColor[CG] = .45f; bgColor[CB] = .35f;
}
Expand Down

0 comments on commit adcfd4d

Please sign in to comment.