Skip to content

Commit

Permalink
Refactor|Model: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 3, 2013
1 parent 7375ae7 commit c985395
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/render/sky.h
@@ -1,4 +1,4 @@
/** @file sky.h Sky Sphere and 3D Models
/** @file sky.h Sky Sphere and 3D Models
*
* This version supports only two sky layers. (More would be a waste of resources?)
*
Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/include/resource/model.h
Expand Up @@ -37,7 +37,10 @@ typedef uint modelid_t;

/**
* 3D model resource.
*
* @ingroup resource
*
* @todo Implement an API for building models programmatically.
*/
class Model
{
Expand Down
59 changes: 28 additions & 31 deletions doomsday/client/src/resource/model.cpp
Expand Up @@ -137,6 +137,9 @@ static float avertexnormals[NUMVERTEXNORMALS][3] = {
#include "tab_anorms.h"
};

/**
* @todo reimplement file loading using de::Reader.
*/
DENG2_PIMPL(Model)
{
Flags flags;
Expand Down Expand Up @@ -520,26 +523,6 @@ DENG2_PIMPL(Model)
return mdl;
}

static Model *interpretDmd(de::FileHandle &hndl, float aspectScale)
{
if(Model *mdl = loadDmd(hndl, aspectScale))
{
LOG_VERBOSE("Interpreted \"" + NativePath(hndl.file().composePath()).pretty() + "\" as a DMD model.");
return mdl;
}
return 0;
}

static Model *interpretMd2(de::FileHandle &hndl, float aspectScale)
{
if(Model *mdl = loadMd2(hndl, aspectScale))
{
LOG_VERBOSE("Interpreted \"" + NativePath(hndl.file().composePath()).pretty() + "\" as a MD2 model.");
return mdl;
}
return 0;
}

#if 0
/**
* Calculate vertex normals. Only with -renorm.
Expand Down Expand Up @@ -646,6 +629,8 @@ static bool recogniseMd2(de::FileHandle &file)

bool Model::recognise(de::FileHandle &hndl) //static
{
LOG_AS("Model");

if(recogniseDmd(hndl)) return true;
if(recogniseMd2(hndl)) return true;
return false;
Expand All @@ -656,15 +641,17 @@ struct ModelFileType
String name; ///< Symbolic name of the resource type.
String ext; ///< Known file extension.

Model *(*interpretFunc)(de::FileHandle &hndl, float aspectScale);
Model *(*loadFunc)(de::FileHandle &hndl, float aspectScale);
};

Model *Model::loadFromFile(de::FileHandle &hndl, float aspectScale) //static
{
// Recognised file types.
LOG_AS("Model");

// Recognized file types.
static ModelFileType modelTypes[] = {
{ "DMD", ".dmd", Instance::interpretDmd },
{ "MD2", ".md2", Instance::interpretMd2 },
{ "DMD", ".dmd", Instance::loadDmd },
{ "MD2", ".md2", Instance::loadMd2 },
{ "", "", 0 } // Terminate.
};

Expand All @@ -676,12 +663,13 @@ Model *Model::loadFromFile(de::FileHandle &hndl, float aspectScale) //static
{
for(int i = 0; !modelTypes[i].name.isEmpty(); ++i)
{
ModelFileType &type = modelTypes[i];
if(!type.ext.compareWithoutCase(ext))
ModelFileType &rtype = modelTypes[i];
if(!rtype.ext.compareWithoutCase(ext))
{
rtypeGuess = &type;
if(Model *mdl = type.interpretFunc(hndl, aspectScale))
rtypeGuess = &rtype;
if(Model *mdl = rtype.loadFunc(hndl, aspectScale))
{
LOG_VERBOSE("Interpreted \"" + NativePath(filePath).pretty() + "\" as a " + rtype.name + " model.");
return mdl;
}
break;
Expand All @@ -692,13 +680,14 @@ Model *Model::loadFromFile(de::FileHandle &hndl, float aspectScale) //static
// Not yet interpreted - try each known format in order.
for(int i = 0; !modelTypes[i].name.isEmpty(); ++i)
{
ModelFileType const &modelType = modelTypes[i];
ModelFileType const &rtype = modelTypes[i];

// Already tried this?
if(&modelType == rtypeGuess) continue;
if(&rtype == rtypeGuess) continue;

if(Model *mdl = modelType.interpretFunc(hndl, aspectScale))
if(Model *mdl = rtype.loadFunc(hndl, aspectScale))
{
LOG_VERBOSE("Interpreted \"" + NativePath(filePath).pretty() + "\" as a " + rtype.name + " model.");
return mdl;
}
}
Expand All @@ -723,6 +712,7 @@ Model::Flags Model::flags() const

void Model::setFlags(Model::Flags flagsToChange, FlagOp operation)
{
LOG_AS("Model");
applyFlagOperation(d->flags, flagsToChange, operation);
}

Expand All @@ -742,6 +732,7 @@ int Model::frameNumber(String name) const

Model::Frame &Model::frame(int number) const
{
LOG_AS("Model");
if(hasFrame(number))
{
return *d->frames.at(number);
Expand All @@ -756,6 +747,7 @@ Model::Frames const &Model::frames() const

void Model::clearAllFrames()
{
LOG_AS("Model");
qDeleteAll(d->frames);
d->frames.clear();
}
Expand All @@ -776,6 +768,7 @@ int Model::skinNumber(String name) const

Model::Skin &Model::skin(int number) const
{
LOG_AS("Model");
if(hasSkin(number))
{
return const_cast<Skin &>(d->skins.at(number));
Expand All @@ -785,6 +778,7 @@ Model::Skin &Model::skin(int number) const

Model::Skin &Model::newSkin(String name)
{
LOG_AS("Model");
if(int index = skinNumber(name) > 0)
{
return skin(index);
Expand All @@ -800,11 +794,13 @@ Model::Skins const &Model::skins() const

void Model::clearAllSkins()
{
LOG_AS("Model");
d->skins.clear();
}

Model::DetailLevel &Model::lod(int level) const
{
LOG_AS("Model");
if(hasLod(level))
{
return *d->lods.at(level);
Expand All @@ -819,6 +815,7 @@ Model::DetailLevels const &Model::lods() const

Model::Primitives const &Model::primitives() const
{
LOG_AS("Model");
return lod(0).primitives;
}

Expand Down

0 comments on commit c985395

Please sign in to comment.