File: esmterrain.cpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (77 lines) | stat: -rw-r--r-- 2,413 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "esmterrain.hpp"

#include <components/esm3/loadland.hpp>
#include <components/esm4/loadland.hpp>
#include <components/misc/constants.hpp>

namespace
{
    constexpr std::uint16_t textures[ESM::LandRecordData::sLandNumTextures]{ 0 };

    std::unique_ptr<const ESM::LandRecordData> loadData(const ESM::Land& land, int loadFlags)
    {
        std::unique_ptr<ESM::LandRecordData> result = std::make_unique<ESM::LandRecordData>();
        land.loadData(loadFlags, *result);
        return result;
    }
}

namespace ESM
{
    LandData::LandData() = default;
}

ESM::LandData::LandData(const ESM::Land& land, int loadFlags)
    : mData(loadData(land, loadFlags))
    , mLoadFlags(mData->mDataLoaded)
    , mMinHeight(mData->mMinHeight)
    , mMaxHeight(mData->mMaxHeight)
    , mSize(Constants::CellSizeInUnits)
    , mLandSize(ESM::Land::LAND_SIZE)
    , mPlugin(land.getPlugin())
    , mHeights(mData->mHeights)
    , mNormals(mData->mNormals)
    , mColors(mData->mColours)
    , mTextures(mData->mTextures)
{
}

ESM::LandData::LandData(const ESM4::Land& land, int /*loadFlags*/)
    : mLoadFlags(land.mDataTypes) // ESM4::Land is always fully loaded. TODO: implement lazy loading
    , mHeightsData(ESM4::Land::sLandNumVerts)
    , mMinHeight(std::numeric_limits<float>::max())
    , mMaxHeight(std::numeric_limits<float>::lowest())
    , mSize(Constants::ESM4CellSizeInUnits)
    , mLandSize(ESM4::Land::sVertsPerSide)
    , mNormals(land.mVertNorm)
    , mColors(land.mVertColr)
    , mTextures(textures)
{
    float rowOffset = land.mHeightMap.heightOffset;
    for (int y = 0; y < mLandSize; y++)
    {
        rowOffset += land.mHeightMap.gradientData[y * mLandSize];

        const float heightY = rowOffset * ESM4::Land::sHeightScale;
        mHeightsData[y * mLandSize] = heightY;
        mMinHeight = std::min(mMinHeight, heightY);
        mMaxHeight = std::max(mMaxHeight, heightY);

        float colOffset = rowOffset;
        for (int x = 1; x < mLandSize; x++)
        {
            colOffset += land.mHeightMap.gradientData[y * mLandSize + x];
            const float heightX = colOffset * ESM4::Land::sHeightScale;
            mMinHeight = std::min(mMinHeight, heightX);
            mMaxHeight = std::max(mMaxHeight, heightX);
            mHeightsData[x + y * mLandSize] = heightX;
        }
    }

    mHeights = mHeightsData;
}

namespace ESM
{
    LandData::~LandData() = default;
}