Skip to content

Commit

Permalink
Gloom: Testing texture loading during map import
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent ad5d14e commit 1b0330e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 47 deletions.
75 changes: 28 additions & 47 deletions doomsday/apps/gloom/gloom/world/mapimport.cpp
Expand Up @@ -18,7 +18,9 @@

#include "gloom/world/mapimport.h"
#include "gloom/world/sectorpolygonizer.h"
#include <doomsday/resource/idtech1texturelib.h>
#include <de/ByteOrder>
#include <de/DataArray>

#include <QDebug>

Expand All @@ -28,20 +30,12 @@ namespace gloom {

static inline int16_t le16(int16_t leValue)
{
#ifdef __BIG_ENDIAN__
return int16_t(swap16(leValue));
#else
return leValue;
#endif
return fromLittleEndian(leValue);
}

static inline uint16_t le16u(int16_t leValue)
static inline uint16_t le16u(uint16_t leValue)
{
#ifdef __BIG_ENDIAN__
return swap16(uint16_t(leValue));
#else
return uint16_t(leValue);
#endif
return fromLittleEndian(leValue);
}

#if !defined (_MSC_VER)
Expand All @@ -60,6 +54,7 @@ static String fixedString(const char *name, dsize maxLen = 8)
DENG2_PIMPL_NOREF(MapImport)
{
const res::LumpCatalog &lumps;
res::IdTech1TextureLib textureLib;
Map map;
QSet<String> textures;

Expand Down Expand Up @@ -121,36 +116,7 @@ DENG2_PIMPL_NOREF(MapImport)
# pragma pack(pop)
#endif

template <typename T>
struct DataArray
{
explicit DataArray(Block data)
: _data(std::move(data))
, _entries(reinterpret_cast<const T *>(_data.constData()))
, _size(int(_data.size() / sizeof(T)))
{}
int size() const
{
return _size;
}
const T &at(int pos) const
{
DENG2_ASSERT(pos >= 0);
DENG2_ASSERT(pos < _size);
return _entries[pos];
}
const T &operator[](int pos) const
{
return at(pos);
}

private:
Block _data;
const T *_entries;
int _size;
};

Impl(const res::LumpCatalog &lc) : lumps(lc)
Impl(const res::LumpCatalog &lc) : lumps(lc), textureLib(lc)
{}

bool isSky(const char *texture) const
Expand Down Expand Up @@ -204,7 +170,6 @@ DENG2_PIMPL_NOREF(MapImport)
QVector<MappedSector> mappedSectors(idSectors.size());

QVector<ID> mappedLines(linedefsCount);
QSet<String> textures;

// -------- Create planes for all sectors: each gets a separate floor and ceiling --------

Expand All @@ -213,8 +178,8 @@ DENG2_PIMPL_NOREF(MapImport)
const auto &sec = idSectors[i];

// Plane materials.
String floorTexture = scope + ".flat." + fixedString(sec.floorTexture).toLower();
String ceilingTexture = scope + ".flat." + fixedString(sec.ceilingTexture).toLower();
String floorTexture = scope + ".flat." + fixedString(sec.floorTexture);
String ceilingTexture = scope + ".flat." + fixedString(sec.ceilingTexture);

if (isSky(sec.floorTexture))
{
Expand Down Expand Up @@ -305,15 +270,15 @@ DENG2_PIMPL_NOREF(MapImport)

if (midTex != "-")
{
middleTexture[p] = scope + ".texture." + midTex.toLower();
middleTexture[p] = scope + ".texture." + midTex;
}
if (upTex != "-")
{
upperTexture[p] = scope + ".texture." + upTex.toLower();
upperTexture[p] = scope + ".texture." + upTex;
}
if (lowTex != "-")
{
lowerTexture[p] = scope + ".texture." + lowTex.toLower();
lowerTexture[p] = scope + ".texture." + lowTex;
}

textures.insert(middleTexture[p]);
Expand Down Expand Up @@ -406,4 +371,20 @@ StringList MapImport::textures() const
return compose<StringList>(d->textures.constBegin(), d->textures.constEnd());
}

Image MapImport::textureImage(const String &name) const
{
if (!name) return {};

const DotPath path(name);
if (path.segmentCount() < 3) return {};

if (path.segment(1) == QStringLiteral("texture"))
{
const auto img = d->textureLib.textureImage(path.segment(2));
return Image::fromRgbaData(img.pixelSize(), img.pixels());
}

return {};
}

} // namespace gloom
3 changes: 3 additions & 0 deletions doomsday/apps/gloom/gloom/world/mapimport.h
Expand Up @@ -21,6 +21,7 @@

#include "gloom/world/map.h"

#include <de/Image>
#include <de/String>
#include <doomsday/LumpCatalog>

Expand All @@ -41,6 +42,8 @@ class MapImport
Map & map();
StringList textures() const;

Image textureImage(const String &name) const;

private:
DENG2_PRIVATE(d)
};
Expand Down
10 changes: 10 additions & 0 deletions doomsday/apps/gloom/src/editor.cpp
Expand Up @@ -1106,6 +1106,16 @@ DENG2_PIMPL(Editor)
MapImport importer(catalog);
if (importer.importMap(mapId))
{
// Build a texture atlas.
{
foreach (String n, importer.textures())
{
Image img = importer.textureImage(n);
qDebug() << "Texture:" << n << img.size().asText();
img.toQImage().save(n + ".png");
}
}

// Update the editor's map.
map = importer.map();
filePath.clear();
Expand Down

0 comments on commit 1b0330e

Please sign in to comment.