2012-09-23 18:11:08 +00:00
|
|
|
#ifndef OPENMW_ESM_LAND_H
|
|
|
|
#define OPENMW_ESM_LAND_H
|
2010-02-25 13:03:03 +00:00
|
|
|
|
2023-08-12 11:29:15 +00:00
|
|
|
#include <array>
|
2023-08-12 11:12:05 +00:00
|
|
|
#include <cstdint>
|
2023-08-12 11:26:04 +00:00
|
|
|
#include <memory>
|
2012-09-17 07:37:50 +00:00
|
|
|
|
2018-09-17 10:52:43 +00:00
|
|
|
#include <components/misc/constants.hpp>
|
|
|
|
|
2022-06-04 14:07:59 +00:00
|
|
|
#include "components/esm/defs.hpp"
|
2022-01-22 14:58:41 +00:00
|
|
|
#include "components/esm/esmcommon.hpp"
|
2010-02-25 13:03:03 +00:00
|
|
|
|
2023-08-12 13:45:44 +00:00
|
|
|
#include "landrecorddata.hpp"
|
|
|
|
|
2011-04-06 16:11:08 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2012-09-30 20:51:54 +00:00
|
|
|
|
|
|
|
class ESMReader;
|
|
|
|
class ESMWriter;
|
|
|
|
|
2010-02-25 13:03:03 +00:00
|
|
|
/*
|
|
|
|
* Landscape data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct Land
|
|
|
|
{
|
2022-06-04 14:34:23 +00:00
|
|
|
constexpr static RecNameInts sRecordId = REC_LAND;
|
2022-06-04 14:07:59 +00:00
|
|
|
|
2015-06-14 00:31:00 +00:00
|
|
|
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
|
2021-10-11 22:18:23 +00:00
|
|
|
static std::string_view getRecordType() { return "Land"; }
|
2013-09-24 11:17:28 +00:00
|
|
|
|
2023-08-12 11:16:58 +00:00
|
|
|
Land() = default;
|
2012-04-01 19:29:49 +00:00
|
|
|
|
2023-08-12 11:27:52 +00:00
|
|
|
Land(const Land& land);
|
|
|
|
|
|
|
|
Land(Land&& other) = default;
|
|
|
|
|
|
|
|
Land& operator=(const Land& land);
|
|
|
|
|
|
|
|
Land& operator=(Land&& land) = default;
|
|
|
|
|
2023-08-12 11:12:05 +00:00
|
|
|
// Only first four bits seem to be used, don't know what they mean.
|
2023-08-12 11:16:58 +00:00
|
|
|
std::uint32_t mFlags = 0;
|
2023-08-12 11:12:05 +00:00
|
|
|
// Map coordinates.
|
2023-08-12 11:16:58 +00:00
|
|
|
std::int32_t mX = 0;
|
|
|
|
std::int32_t mY = 0;
|
2010-02-25 13:03:03 +00:00
|
|
|
|
2017-09-08 04:51:46 +00:00
|
|
|
// Plugin index, used to reference the correct material palette.
|
2012-09-17 07:37:50 +00:00
|
|
|
int getPlugin() const { return mContext.index; }
|
|
|
|
void setPlugin(int index) { mContext.index = index; }
|
2010-02-25 13:03:03 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
// File context. This allows the ESM reader to be 'reset' to this
|
|
|
|
// location later when we are ready to load the full data set.
|
|
|
|
// In the editor, there may not be a file associated with the Land,
|
|
|
|
// in which case the filename will be empty.
|
|
|
|
ESM_Context mContext;
|
2010-02-25 13:03:03 +00:00
|
|
|
|
2023-08-12 11:16:58 +00:00
|
|
|
int mDataTypes = 0;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
enum
|
|
|
|
{
|
2012-06-11 18:02:03 +00:00
|
|
|
DATA_VNML = 1,
|
2016-02-28 15:49:18 +00:00
|
|
|
DATA_VHGT = 2,
|
2012-06-11 18:02:03 +00:00
|
|
|
DATA_WNAM = 4,
|
2021-07-01 17:00:05 +00:00
|
|
|
DATA_VCLR = 8,
|
|
|
|
DATA_VTEX = 16
|
|
|
|
};
|
2016-02-28 15:49:18 +00:00
|
|
|
|
2023-12-13 23:53:05 +00:00
|
|
|
enum Flags
|
2023-11-26 19:11:38 +00:00
|
|
|
{
|
2023-12-13 23:53:05 +00:00
|
|
|
Flag_HeightsNormals = 0x1,
|
|
|
|
Flag_Colors = 0x2,
|
|
|
|
Flag_Textures = 0x4
|
2023-11-26 19:11:38 +00:00
|
|
|
};
|
|
|
|
|
2012-01-21 16:59:08 +00:00
|
|
|
// default height to use in case there is no Land record
|
2021-07-01 17:00:05 +00:00
|
|
|
static constexpr int DEFAULT_HEIGHT = -2048;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
|
|
|
// number of vertices per side
|
2023-08-12 13:45:44 +00:00
|
|
|
static constexpr int LAND_SIZE = LandRecordData::sLandSize;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
|
|
|
// cell terrain size in world coords
|
2021-07-01 17:00:05 +00:00
|
|
|
static constexpr int REAL_SIZE = Constants::CellSizeInUnits;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2021-07-01 17:00:05 +00:00
|
|
|
// total number of vertices
|
2023-08-12 13:45:44 +00:00
|
|
|
static constexpr int LAND_NUM_VERTS = LandRecordData::sLandNumVerts;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2024-06-05 21:58:23 +00:00
|
|
|
static constexpr int sHeightScale = 8;
|
2012-01-21 17:59:12 +00:00
|
|
|
|
|
|
|
// number of textures per side of land
|
2023-08-12 13:45:44 +00:00
|
|
|
static constexpr int LAND_TEXTURE_SIZE = LandRecordData::sLandTextureSize;
|
2012-01-21 17:59:12 +00:00
|
|
|
|
2021-07-01 17:00:05 +00:00
|
|
|
// total number of textures per land
|
2023-08-12 13:45:44 +00:00
|
|
|
static constexpr int LAND_NUM_TEXTURES = LandRecordData::sLandNumTextures;
|
2017-09-04 00:00:19 +00:00
|
|
|
|
2024-06-05 21:58:23 +00:00
|
|
|
static constexpr std::size_t sGlobalMapLodSizeSqrt = 9;
|
2020-01-10 12:49:57 +00:00
|
|
|
|
2024-06-05 21:58:23 +00:00
|
|
|
static constexpr std::size_t sGlobalMapLodSize = sGlobalMapLodSizeSqrt * sGlobalMapLodSizeSqrt;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2023-08-12 13:45:44 +00:00
|
|
|
using LandData = ESM::LandRecordData;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2017-02-14 01:40:41 +00:00
|
|
|
// low-LOD heightmap (used for rendering the global map)
|
2024-06-05 21:58:23 +00:00
|
|
|
std::array<std::int8_t, sGlobalMapLodSize> mWnam;
|
|
|
|
|
|
|
|
mutable std::unique_ptr<LandData> mLandData;
|
2017-02-14 01:40:41 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
void load(ESMReader& esm, bool& isDeleted);
|
|
|
|
void save(ESMWriter& esm, bool isDeleted = false) const;
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2017-09-04 19:13:45 +00:00
|
|
|
void blank();
|
2014-10-08 15:17:31 +00:00
|
|
|
|
2024-06-05 21:58:23 +00:00
|
|
|
void loadData(int dataTypes) const;
|
2023-08-12 13:04:44 +00:00
|
|
|
|
2024-06-05 21:58:23 +00:00
|
|
|
void loadData(int dataTypes, LandData& data) const;
|
2012-04-04 19:05:19 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-06 23:25:04 +00:00
|
|
|
* Frees memory allocated for mLandData
|
2012-04-04 19:05:19 +00:00
|
|
|
*/
|
2023-08-12 13:04:44 +00:00
|
|
|
void unloadData();
|
2012-04-04 19:39:21 +00:00
|
|
|
|
2012-09-21 08:12:16 +00:00
|
|
|
/// Check if given data type is loaded
|
2015-01-29 02:30:07 +00:00
|
|
|
bool isDataLoaded(int flags) const;
|
2012-09-21 08:12:16 +00:00
|
|
|
|
2015-08-31 14:13:26 +00:00
|
|
|
/// Return land data with at least the data types specified in \a flags loaded (if they
|
|
|
|
/// are available). Will return a 0-pointer if there is no data for any of the
|
|
|
|
/// specified types.
|
|
|
|
const LandData* getLandData(int flags) const;
|
|
|
|
|
|
|
|
/// Return land data without loading first anything. Can return a 0-pointer.
|
2024-05-16 08:23:51 +00:00
|
|
|
const LandData* getLandData() const { return mLandData.get(); }
|
2015-08-31 14:13:26 +00:00
|
|
|
|
2015-09-03 14:15:00 +00:00
|
|
|
/// Return land data without loading first anything. Can return a 0-pointer.
|
2024-05-16 08:23:51 +00:00
|
|
|
LandData* getLandData() { return mLandData.get(); }
|
2015-09-03 14:15:00 +00:00
|
|
|
|
|
|
|
/// \attention Must not be called on objects that aren't fully loaded.
|
|
|
|
///
|
|
|
|
/// \note Added data fields will be uninitialised
|
|
|
|
void add(int flags);
|
2010-02-25 13:03:03 +00:00
|
|
|
};
|
2012-04-04 19:39:21 +00:00
|
|
|
|
2024-06-05 21:58:23 +00:00
|
|
|
void loadLandRecordData(int dataTypes, ESMReader& reader, LandRecordData& data);
|
|
|
|
|
|
|
|
void generateWnam(const std::array<float, LandRecordData::sLandNumVerts>& heights,
|
|
|
|
std::array<std::int8_t, Land::sGlobalMapLodSize>& wnam);
|
2010-02-25 13:03:03 +00:00
|
|
|
}
|
2024-06-05 21:58:23 +00:00
|
|
|
|
2010-02-25 13:03:03 +00:00
|
|
|
#endif
|