1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-29 14:34:29 +00:00

Fix most conversion warnings in components

This commit is contained in:
Evil Eye 2025-09-18 22:00:55 +02:00
parent 98291f1377
commit f7292680d6
46 changed files with 298 additions and 256 deletions

View file

@ -13,7 +13,7 @@
static osg::Vec3 sphereCoordToCartesian(float theta, float phi, float r) static osg::Vec3 sphereCoordToCartesian(float theta, float phi, float r)
{ {
osg::Vec3 returnVec = osg::Vec3(0.0, 0.0, 0.0); osg::Vec3 returnVec = osg::Vec3(0.0, 0.0, 0.0);
float phiToHorizontal = osg::PI_2 - phi; float phiToHorizontal = osg::PI_2f - phi;
returnVec.x() = std::cos(theta); returnVec.x() = std::cos(theta);
returnVec.y() = std::sin(theta); returnVec.y() = std::sin(theta);
returnVec.z() = std::sin(phiToHorizontal); returnVec.z() = std::sin(phiToHorizontal);
@ -36,9 +36,9 @@ static void generateWireCube(osg::Geometry& geom, float dim)
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
osg::Vec3 vert1 = osg::Vec3(indexPos[i].x() - 0.5, indexPos[i].y() - 0.5, 0.5); osg::Vec3 vert1 = osg::Vec3(indexPos[i].x() - 0.5f, indexPos[i].y() - 0.5f, 0.5f);
int next = (i + 1) % 4; int next = (i + 1) % 4;
osg::Vec3 vert2 = osg::Vec3(indexPos[next].x() - 0.5, indexPos[next].y() - 0.5, 0.5); osg::Vec3 vert2 = osg::Vec3(indexPos[next].x() - 0.5f, indexPos[next].y() - 0.5f, 0.5f);
vertices->push_back(vert1 * dim); vertices->push_back(vert1 * dim);
vertices->push_back(vert2 * dim); vertices->push_back(vert2 * dim);
@ -59,7 +59,7 @@ static void generateWireCube(osg::Geometry& geom, float dim)
geom.setVertexArray(vertices); geom.setVertexArray(vertices);
geom.setNormalArray(normals, osg::Array::BIND_PER_VERTEX); geom.setNormalArray(normals, osg::Array::BIND_PER_VERTEX);
geom.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); geom.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, static_cast<GLsizei>(vertices->size())));
} }
static void generateCube(osg::Geometry& geom, float dim) static void generateCube(osg::Geometry& geom, float dim)
@ -68,14 +68,13 @@ static void generateCube(osg::Geometry& geom, float dim)
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array; osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
osg::ref_ptr<osg::DrawElementsUShort> indices = new osg::DrawElementsUShort(osg::DrawElementsUShort::TRIANGLES, 0); osg::ref_ptr<osg::DrawElementsUShort> indices = new osg::DrawElementsUShort(osg::DrawElementsUShort::TRIANGLES, 0);
for (int iFace = 0; iFace < 6; iFace++) for (GLushort iFace = 0; iFace < 6; iFace++)
{ {
osg::Vec3f normale(0., 0., 0.); osg::Vec3f normale(0., 0., 0.);
osg::Vec3f u(0., 0., 0.); osg::Vec3f u(0., 0., 0.);
osg::Vec3f v(0., 0., 0.); osg::Vec3f v(0., 0., 0.);
int axis = iFace / 2; GLushort axis = iFace / 2;
int dir = iFace % 2 == 0 ? -1 : 1; float floatDir = iFace % 2 == 0 ? -1.f : 1.f;
float floatDir = dir;
normale[axis] = floatDir; normale[axis] = floatDir;
u[(axis + 1) % 3] = 1.0; u[(axis + 1) % 3] = 1.0;
v[(axis + 2) % 3] = 1.0; v[(axis + 2) % 3] = 1.0;
@ -85,20 +84,20 @@ static void generateCube(osg::Geometry& geom, float dim)
float iu = iPoint % 2 == 1 float iu = iPoint % 2 == 1
? floatDir ? floatDir
: -floatDir; // This is to get the right triangle orientation when the normal changes* : -floatDir; // This is to get the right triangle orientation when the normal changes*
float iv = iPoint / 2 == 1 ? 1.0 : -1.0; float iv = iPoint / 2 == 1 ? 1.f : -1.f;
osg::Vec3f point = (u * iu) + (v * iv); osg::Vec3f point = (u * iu) + (v * iv);
point = (point + normale); point = (point + normale);
point = point * (dim * 0.5f); point = point * (dim * 0.5f);
vertices->push_back(point); vertices->push_back(point);
normals->push_back(normale); normals->push_back(normale);
} }
int startVertex(iFace * 4); GLushort startVertex(iFace * 4);
int newFace1[] = { startVertex, startVertex + 1, startVertex + 2 }; GLushort newFace1[] = { startVertex, startVertex + 1u, startVertex + 2u };
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
indices->push_back(newFace1[i]); indices->push_back(newFace1[i]);
} }
int newFace2[] = { startVertex + 2, startVertex + 1, startVertex + 3 }; GLushort newFace2[] = { startVertex + 2u, startVertex + 1u, startVertex + 3u };
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
indices->push_back(newFace2[i]); indices->push_back(newFace2[i]);
@ -123,25 +122,25 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
// top disk // top disk
for (int i = 0; i < subdiv; i++) for (int i = 0; i < subdiv; i++)
{ {
float theta = (float(i) / float(subdiv)) * osg::PI * 2.; float theta = (float(i) / float(subdiv)) * osg::PIf * 2.f;
osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.); osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.f);
pos *= radius; pos *= radius;
pos.z() = height / 2.; pos.z() = height / 2.f;
vertices->push_back(pos); vertices->push_back(pos);
normals->push_back(topNormal); normals->push_back(topNormal);
iVertex += 1; iVertex += 1;
} }
auto centerTop = iVertex; auto centerTop = static_cast<GLushort>(iVertex);
// centerTop // centerTop
{ {
vertices->push_back(osg::Vec3(0., 0., height / 2.)); vertices->push_back(osg::Vec3(0.f, 0.f, height / 2.f));
normals->push_back(topNormal); normals->push_back(topNormal);
iVertex += 1; iVertex += 1;
} }
auto centerBot = iVertex; auto centerBot = static_cast<GLushort>(iVertex);
// centerBot // centerBot
{ {
vertices->push_back(osg::Vec3(0., 0., -height / 2)); vertices->push_back(osg::Vec3(0.f, 0.f, -height / 2));
normals->push_back(-topNormal); normals->push_back(-topNormal);
iVertex += 1; iVertex += 1;
} }
@ -149,10 +148,10 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
auto beginBot = iVertex; auto beginBot = iVertex;
for (int i = 0; i < subdiv; i++) for (int i = 0; i < subdiv; i++)
{ {
float theta = float(i) / float(subdiv) * osg::PI * 2.; float theta = float(i) / float(subdiv) * osg::PIf * 2.f;
osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.); osg::Vec3 pos = sphereCoordToCartesian(theta, osg::PI_2f, 1.f);
pos *= radius; pos *= radius;
pos.z() = -height / 2.; pos.z() = -height / 2.f;
vertices->push_back(pos); vertices->push_back(pos);
normals->push_back(-topNormal); normals->push_back(-topNormal);
iVertex += 1; iVertex += 1;
@ -161,13 +160,13 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
int beginSide = iVertex; int beginSide = iVertex;
for (int i = 0; i < subdiv; i++) for (int i = 0; i < subdiv; i++)
{ {
float theta = float(i) / float(subdiv) * osg::PI * 2.; float theta = float(i) / float(subdiv) * osg::PIf * 2.f;
osg::Vec3 normal = sphereCoordToCartesian(theta, osg::PI_2f, 1.); osg::Vec3 normal = sphereCoordToCartesian(theta, osg::PI_2f, 1.f);
auto posTop = normal; auto posTop = normal;
posTop *= radius; posTop *= radius;
auto posBot = posTop; auto posBot = posTop;
posTop.z() = height / 2.; posTop.z() = height / 2.f;
posBot.z() = -height / 2.; posBot.z() = -height / 2.f;
vertices->push_back(posTop); vertices->push_back(posTop);
normals->push_back(normal); normals->push_back(normal);
iVertex += 1; iVertex += 1;
@ -180,10 +179,10 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
for (int i = 0; i < subdiv; i++) for (int i = 0; i < subdiv; i++)
{ {
auto nextVert = (i + 1) % subdiv; auto nextVert = (i + 1) % subdiv;
auto v1 = (beginSide + 2 * i); auto v1 = static_cast<GLushort>(beginSide + 2 * i);
auto v2 = (beginSide + 2 * i + 1); auto v2 = static_cast<GLushort>(beginSide + 2 * i + 1);
auto v3 = (beginSide + 2 * nextVert); auto v3 = static_cast<GLushort>(beginSide + 2 * nextVert);
auto v4 = (beginSide + 2 * nextVert + 1); auto v4 = static_cast<GLushort>(beginSide + 2 * nextVert + 1);
indices->push_back(v1); indices->push_back(v1);
indices->push_back(v2); indices->push_back(v2);
indices->push_back(v4); indices->push_back(v4);
@ -195,11 +194,11 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
for (int i = 0; i < subdiv; i++) for (int i = 0; i < subdiv; i++)
{ {
auto nextVert = (i + 1) % subdiv; auto nextVert = (i + 1) % subdiv;
auto top1 = (beginTop + i); auto top1 = static_cast<GLushort>(beginTop + i);
auto top2 = (beginTop + nextVert); auto top2 = static_cast<GLushort>(beginTop + nextVert);
auto bot1 = (beginBot + i); auto bot1 = static_cast<GLushort>(beginBot + i);
auto bot2 = (beginBot + nextVert); auto bot2 = static_cast<GLushort>(beginBot + nextVert);
indices->push_back(top2); indices->push_back(top2);
indices->push_back(centerTop); indices->push_back(centerTop);
@ -239,7 +238,7 @@ namespace Debug
lines.setVertexArray(vertices); lines.setVertexArray(vertices);
lines.setNormalArray(color, osg::Array::BIND_PER_VERTEX); lines.setNormalArray(color, osg::Array::BIND_PER_VERTEX);
lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, static_cast<GLsizei>(vertices->size())));
} }
DebugCustomDraw::DebugCustomDraw() DebugCustomDraw::DebugCustomDraw()
@ -395,5 +394,5 @@ void Debug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, c
colors->push_back(color); colors->push_back(color);
colors->dirty(); colors->dirty();
primitive->setCount(vertices->size()); primitive->setCount(static_cast<GLsizei>(vertices->size()));
} }

View file

@ -273,7 +273,8 @@ namespace Debug
void DebugGroup::push(osg::State& state) const void DebugGroup::push(osg::State& state) const
{ {
if (isValid()) if (isValid())
PushDebugGroup::sInstance->glPushDebugGroup(mSource, mId, mMessage.size(), mMessage.c_str()); PushDebugGroup::sInstance->glPushDebugGroup(
mSource, mId, static_cast<GLsizei>(mMessage.size()), mMessage.c_str());
} }
void DebugGroup::pop(osg::State& state) const void DebugGroup::pop(osg::State& state) const

View file

@ -1039,7 +1039,7 @@ namespace DetourNavigator
if (const auto& cachedTileData = job->mCachedTileData) if (const auto& cachedTileData = job->mCachedTileData)
{ {
Log(Debug::Debug) << "Update db tile by job " << job->mId; Log(Debug::Debug) << "Update db tile by job " << job->mId;
job->mGeneratedNavMeshData->mUserId = cachedTileData->mTileId; job->mGeneratedNavMeshData->mUserId = static_cast<unsigned>(cachedTileData->mTileId);
mDb->updateTile(cachedTileData->mTileId, mVersion, serialize(*job->mGeneratedNavMeshData)); mDb->updateTile(cachedTileData->mTileId, mVersion, serialize(*job->mGeneratedNavMeshData));
return; return;
} }
@ -1051,7 +1051,7 @@ namespace DetourNavigator
return; return;
} }
job->mGeneratedNavMeshData->mUserId = mNextTileId; job->mGeneratedNavMeshData->mUserId = static_cast<unsigned>(mNextTileId);
Log(Debug::Debug) << "Insert db tile by job " << job->mId; Log(Debug::Debug) << "Insert db tile by job " << job->mId;
mDb->insertTile(mNextTileId, job->mWorldspace, job->mChangedTile, mVersion, job->mInput, mDb->insertTile(mNextTileId, job->mWorldspace, job->mChangedTile, mVersion, job->mInput,
serialize(*job->mGeneratedNavMeshData)); serialize(*job->mGeneratedNavMeshData));

View file

@ -22,7 +22,7 @@ namespace DetourNavigator
std::array<dtPolyRef, 16> path; std::array<dtPolyRef, 16> path;
dtRaycastHit hit; dtRaycastHit hit;
hit.path = path.data(); hit.path = path.data();
hit.maxPath = path.size(); hit.maxPath = static_cast<int>(path.size());
if (dtStatus status = navMeshQuery.raycast(ref, start.ptr(), end.ptr(), &queryFilter, options, &hit); if (dtStatus status = navMeshQuery.raycast(ref, start.ptr(), end.ptr(), &queryFilter, options, &hit);
dtStatusFailed(status) || hit.pathCount == 0) dtStatusFailed(status) || hit.pathCount == 0)
return {}; return {};

View file

@ -122,10 +122,10 @@ namespace DetourNavigator
triangles.emplace_back(makeRecastMeshTriangle(vertices, AreaType_ground)); triangles.emplace_back(makeRecastMeshTriangle(vertices, AreaType_ground));
}); });
shape.processAllTriangles(&callback, aabbMin, aabbMax); shape.processAllTriangles(&callback, aabbMin, aabbMax);
const osg::Vec2f aabbShift const btVector3 aabbShift = (aabbMax - aabbMin) * 0.5;
= (osg::Vec2f(aabbMax.x(), aabbMax.y()) - osg::Vec2f(aabbMin.x(), aabbMin.y())) * 0.5;
const osg::Vec2f tileShift = osg::Vec2f(heightfield.mMinX, heightfield.mMinY) * scale; const osg::Vec2f tileShift = osg::Vec2f(heightfield.mMinX, heightfield.mMinY) * scale;
const osg::Vec2f localShift = aabbShift + tileShift; const osg::Vec2f localShift
= osg::Vec2f(static_cast<float>(aabbShift.x()), static_cast<float>(aabbShift.y())) + tileShift;
const float cellSize = static_cast<float>(heightfield.mCellSize); const float cellSize = static_cast<float>(heightfield.mCellSize);
const osg::Vec3f cellShift(heightfield.mCellPosition.x() * cellSize, heightfield.mCellPosition.y() * cellSize, const osg::Vec3f cellShift(heightfield.mCellPosition.x() * cellSize, heightfield.mCellPosition.y() * cellSize,
(heightfield.mMinHeight + heightfield.mMaxHeight) * 0.5f); (heightfield.mMinHeight + heightfield.mMaxHeight) * 0.5f);
@ -238,7 +238,8 @@ namespace DetourNavigator
const float stepSize = getHeightfieldScale(cellSize, size); const float stepSize = getHeightfieldScale(cellSize, size);
const int halfCellSize = cellSize / 2; const int halfCellSize = cellSize / 2;
const auto local = [&](float v, float offset) { return (v - offset + halfCellSize) / stepSize; }; const auto local = [&](float v, float offset) { return (v - offset + halfCellSize) / stepSize; };
const auto index = [&](float v, int add) { return std::clamp<int>(static_cast<int>(v) + add, 0, size); }; const auto index
= [&](float v, int add) { return std::clamp<int>(static_cast<int>(v) + add, 0, static_cast<int>(size)); };
const std::size_t minX = index(std::round(local(intersection->mMin.x(), shift.x())), -1); const std::size_t minX = index(std::round(local(intersection->mMin.x(), shift.x())), -1);
const std::size_t minY = index(std::round(local(intersection->mMin.y(), shift.y())), -1); const std::size_t minY = index(std::round(local(intersection->mMin.y(), shift.y())), -1);
const std::size_t maxX = index(std::round(local(intersection->mMax.x(), shift.x())), 1); const std::size_t maxX = index(std::round(local(intersection->mMax.x(), shift.x())), 1);

View file

@ -79,8 +79,10 @@ namespace DetourNavigator
inline TileBounds makeTileBounds(const RecastSettings& settings, const TilePosition& tilePosition) inline TileBounds makeTileBounds(const RecastSettings& settings, const TilePosition& tilePosition)
{ {
return TileBounds{ return TileBounds{
osg::Vec2f(tilePosition.x(), tilePosition.y()) * getTileSize(settings), osg::Vec2f(static_cast<float>(tilePosition.x()), static_cast<float>(tilePosition.y()))
osg::Vec2f(tilePosition.x() + 1, tilePosition.y() + 1) * getTileSize(settings), * getTileSize(settings),
osg::Vec2f(static_cast<float>(tilePosition.x() + 1), static_cast<float>(tilePosition.y() + 1))
* getTileSize(settings),
}; };
} }
@ -97,7 +99,7 @@ namespace DetourNavigator
inline float getMaxNavmeshAreaRadius(const Settings& settings) inline float getMaxNavmeshAreaRadius(const Settings& settings)
{ {
return std::floor(std::sqrt(settings.mMaxTilesNumber / osg::PI)) - 1; return std::floor(std::sqrt(settings.mMaxTilesNumber / osg::PIf)) - 1;
} }
// Returns tile bounds in real coordinates // Returns tile bounds in real coordinates

View file

@ -56,8 +56,10 @@ namespace DetourNavigator
inline TileBounds maxCellTileBounds(const osg::Vec2i& position, int size) inline TileBounds maxCellTileBounds(const osg::Vec2i& position, int size)
{ {
return TileBounds{ osg::Vec2f(static_cast<float>(position.x()), static_cast<float>(position.y())) * static_cast<float>(size), return TileBounds{ osg::Vec2f(static_cast<float>(position.x()), static_cast<float>(position.y()))
osg::Vec2f(static_cast<float>(position.x() + 1), static_cast<float>(position.y() + 1)) * static_cast<float>(size) }; * static_cast<float>(size),
osg::Vec2f(static_cast<float>(position.x() + 1), static_cast<float>(position.y() + 1))
* static_cast<float>(size) };
} }
inline TileBounds makeObjectTileBounds(const btCollisionShape& shape, const btTransform& transform) inline TileBounds makeObjectTileBounds(const btCollisionShape& shape, const btTransform& transform)

View file

@ -84,7 +84,7 @@ namespace ESM
// The exact value of mDuration only matters for repeating packages. // The exact value of mDuration only matters for repeating packages.
// Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should // Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should
// fix old saves. // fix old saves.
mData.mDuration = std::max<float>(mRemainingDuration > 0, mRemainingDuration); mData.mDuration = static_cast<int16_t>(std::max<float>(mRemainingDuration > 0, mRemainingDuration));
} }
} }
@ -121,7 +121,7 @@ namespace ESM
// The exact value of mDuration only matters for repeating packages. // The exact value of mDuration only matters for repeating packages.
// Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should // Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should
// fix old saves. // fix old saves.
mData.mDuration = std::max<float>(mRemainingDuration > 0, mRemainingDuration); mData.mDuration = static_cast<int16_t>(std::max<float>(mRemainingDuration > 0, mRemainingDuration));
} }
} }

View file

@ -145,7 +145,8 @@ namespace ESM
effects[i] = MagicEffect::Effects::ResistMagicka; effects[i] = MagicEffect::Effects::ResistMagicka;
for (short i = MagicEffect::Effects::AbsorbAttribute; i <= MagicEffect::Effects::AbsorbSkill; ++i) for (short i = MagicEffect::Effects::AbsorbAttribute; i <= MagicEffect::Effects::AbsorbSkill; ++i)
effects[i] = MagicEffect::Effects::ResistMagicka; effects[i] = MagicEffect::Effects::ResistMagicka;
for (short i = MagicEffect::Effects::WeaknessToFire; i <= MagicEffect::Effects::WeaknessToNormalWeapons; ++i) for (short i = MagicEffect::Effects::WeaknessToFire; i <= MagicEffect::Effects::WeaknessToNormalWeapons;
++i)
effects[i] = MagicEffect::Effects::ResistMagicka; effects[i] = MagicEffect::Effects::ResistMagicka;
effects[MagicEffect::Effects::Burden] = MagicEffect::Effects::ResistMagicka; effects[MagicEffect::Effects::Burden] = MagicEffect::Effects::ResistMagicka;
@ -541,7 +542,7 @@ namespace ESM
{ {
std::map<std::string_view, int, Misc::StringUtils::CiComp> map; std::map<std::string_view, int, Misc::StringUtils::CiComp> map;
for (size_t i = 0; i < strings.size(); i++) for (size_t i = 0; i < strings.size(); i++)
map[strings[i]] = i; map[strings[i]] = static_cast<int>(i);
return map; return map;
} }

View file

@ -591,7 +591,7 @@ namespace Gui
// Underscore, use for NotDefined marker (used for glyphs not existing in the font) // Underscore, use for NotDefined marker (used for glyphs not existing in the font)
additional.emplace(95, MyGUI::FontCodeType::NotDefined); additional.emplace(95, MyGUI::FontCodeType::NotDefined);
for (int i = 0; i < 256; i++) for (unsigned char i = 0; i < 256; i++)
{ {
float x1 = data[i].top_left.x * width; float x1 = data[i].top_left.x * width;
float y1 = data[i].top_left.y * height; float y1 = data[i].top_left.y * height;

View file

@ -29,12 +29,12 @@ namespace Fx
int scaledHeight = height; int scaledHeight = height;
if (mWidthRatio) if (mWidthRatio)
scaledWidth = width * mWidthRatio.value(); scaledWidth = static_cast<int>(width * mWidthRatio.value());
else if (mWidth) else if (mWidth)
scaledWidth = mWidth.value(); scaledWidth = mWidth.value();
if (mHeightRatio > 0.f) if (mHeightRatio > 0.f)
scaledHeight = height * mHeightRatio.value(); scaledHeight = static_cast<int>(height * mHeightRatio.value());
else if (mHeight) else if (mHeight)
scaledHeight = mHeight.value(); scaledHeight = mHeight.value();
@ -190,7 +190,7 @@ namespace Fx
if (arg.isArray()) if (arg.isArray())
{ {
for (size_t i = 0; i < arg.getArray().size(); ++i) for (size_t i = 0; i < arg.getArray().size(); ++i)
uniform->setElement(i, arg.getArray()[i]); uniform->setElement(static_cast<unsigned int>(i), arg.getArray()[i]);
uniform->dirty(); uniform->dirty();
} }
else else

View file

@ -334,8 +334,8 @@ namespace LuaUtil
void ScriptsContainer::insertHandler(std::vector<Handler>& list, int scriptId, sol::function fn) void ScriptsContainer::insertHandler(std::vector<Handler>& list, int scriptId, sol::function fn)
{ {
size_t pos = list.size();
list.emplace_back(); list.emplace_back();
int pos = list.size() - 1;
while (pos > 0 && list[pos - 1].mScriptId > scriptId) while (pos > 0 && list[pos - 1].mScriptId > scriptId)
{ {
list[pos] = std::move(list[pos - 1]); list[pos] = std::move(list[pos - 1]);
@ -370,9 +370,9 @@ namespace LuaUtil
return; return;
} }
EventHandlerList& list = it->second; EventHandlerList& list = it->second;
for (int i = list.size() - 1; i >= 0; --i) for (size_t i = list.size(); i > 0; --i)
{ {
const Handler& h = list[i]; const Handler& h = list[i - 1];
try try
{ {
sol::object res = LuaUtil::call({ this, h.mScriptId }, h.mFn, object); sol::object res = LuaUtil::call({ this, h.mScriptId }, h.mFn, object);

View file

@ -20,9 +20,9 @@ namespace LuaUi
// mCoord could be zero, prevent division by 0 // mCoord could be zero, prevent division by 0
// use arbitrary large numbers to prevent performance issues // use arbitrary large numbers to prevent performance issues
if (mTileSize.width <= 0) if (mTileSize.width <= 0)
mTileSize.width = 1e7; mTileSize.width = 10000000;
if (mTileSize.height <= 0) if (mTileSize.height <= 0)
mTileSize.height = 1e7; mTileSize.height = 10000000;
MyGUI::TileRect::_updateView(); MyGUI::TileRect::_updateView();
} }

View file

@ -26,7 +26,7 @@ namespace LuaUi
{ {
MyGUI::ILayer* p = refresh(); MyGUI::ILayer* p = refresh();
MyGUI::IntSize size = p->getSize(); MyGUI::IntSize size = p->getSize();
return osg::Vec2f(size.width, size.height); return osg::Vec2f(static_cast<float>(size.width), static_cast<float>(size.height));
} }
struct Options struct Options

View file

@ -11,11 +11,16 @@
namespace LuaUi namespace LuaUi
{ {
template <typename T>
constexpr bool isMyGuiIntVector()
{
return std::is_same<T, MyGUI::IntPoint>() || std::is_same<T, MyGUI::IntSize>();
}
template <typename T> template <typename T>
constexpr bool isMyGuiVector() constexpr bool isMyGuiVector()
{ {
return std::is_same<T, MyGUI::IntPoint>() || std::is_same<T, MyGUI::IntSize>() return isMyGuiIntVector<T>() || std::is_same<T, MyGUI::FloatPoint>() || std::is_same<T, MyGUI::FloatSize>();
|| std::is_same<T, MyGUI::FloatPoint>() || std::is_same<T, MyGUI::FloatSize>();
} }
template <typename T> template <typename T>
@ -42,7 +47,9 @@ namespace LuaUi
return sol::nullopt; return sol::nullopt;
LuaT luaT = opt.as<LuaT>(); LuaT luaT = opt.as<LuaT>();
if constexpr (isMyGuiVector<T>()) if constexpr (isMyGuiIntVector<T>())
return T(static_cast<int>(luaT.x()), static_cast<int>(luaT.y()));
else if constexpr (isMyGuiVector<T>())
return T(luaT.x(), luaT.y()); return T(luaT.x(), luaT.y());
else if constexpr (isMyGuiColor<T>()) else if constexpr (isMyGuiColor<T>())
return T(luaT.r(), luaT.g(), luaT.b(), luaT.a()); return T(luaT.r(), luaT.g(), luaT.b(), luaT.a());

View file

@ -179,16 +179,17 @@ namespace LuaUi
auto keySym = SDL_Keysym(); auto keySym = SDL_Keysym();
keySym.sym = SDLUtil::myGuiKeyToSdl(code); keySym.sym = SDLUtil::myGuiKeyToSdl(code);
keySym.scancode = SDL_GetScancodeFromKey(keySym.sym); keySym.scancode = SDL_GetScancodeFromKey(keySym.sym);
keySym.mod = SDL_GetModState(); keySym.mod = static_cast<Uint16>(SDL_GetModState());
return sol::make_object(lua(), keySym); return sol::make_object(lua(), keySym);
} }
sol::object WidgetExtension::mouseEvent( sol::object WidgetExtension::mouseEvent(
int left, int top, MyGUI::MouseButton button = MyGUI::MouseButton::None) const int left, int top, MyGUI::MouseButton button = MyGUI::MouseButton::None) const
{ {
osg::Vec2f position(left, top); osg::Vec2f position(static_cast<float>(left), static_cast<float>(top));
MyGUI::IntPoint absolutePosition = mWidget->getAbsolutePosition(); MyGUI::IntPoint absolutePosition = mWidget->getAbsolutePosition();
osg::Vec2f offset = position - osg::Vec2f(absolutePosition.left, absolutePosition.top); osg::Vec2f offset = position
- osg::Vec2f(static_cast<float>(absolutePosition.left), static_cast<float>(absolutePosition.top));
sol::table table = makeTable(); sol::table table = makeTable();
int sdlButton = SDLUtil::myGuiMouseButtonToSdl(button); int sdlButton = SDLUtil::myGuiMouseButtonToSdl(button);
table["position"] = position; table["position"] = position;
@ -328,8 +329,8 @@ namespace LuaUi
MyGUI::IntSize pSize = parentSize(); MyGUI::IntSize pSize = parentSize();
MyGUI::IntSize newSize; MyGUI::IntSize newSize;
newSize = mAbsoluteCoord.size(); newSize = mAbsoluteCoord.size();
newSize.width += mRelativeCoord.width * pSize.width; newSize.width += static_cast<int>(mRelativeCoord.width * pSize.width);
newSize.height += mRelativeCoord.height * pSize.height; newSize.height += static_cast<int>(mRelativeCoord.height * pSize.height);
return newSize; return newSize;
} }
@ -340,8 +341,8 @@ namespace LuaUi
MyGUI::IntSize pSize = parentSize(); MyGUI::IntSize pSize = parentSize();
MyGUI::IntPoint newPosition; MyGUI::IntPoint newPosition;
newPosition = mAbsoluteCoord.point(); newPosition = mAbsoluteCoord.point();
newPosition.left += mRelativeCoord.left * pSize.width - mAnchor.width * size.width; newPosition.left += static_cast<int>(mRelativeCoord.left * pSize.width - mAnchor.width * size.width);
newPosition.top += mRelativeCoord.top * pSize.height - mAnchor.height * size.height; newPosition.top += static_cast<int>(mRelativeCoord.top * pSize.height - mAnchor.height * size.height);
return newPosition; return newPosition;
} }

View file

@ -79,8 +79,8 @@ namespace LuaUi
mPreviousMouse.top = top; mPreviousMouse.top = top;
sol::table table = makeTable(); sol::table table = makeTable();
table["position"] = osg::Vec2f(mCoord.left, mCoord.top); table["position"] = osg::Vec2f(static_cast<float>(mCoord.left), static_cast<float>(mCoord.top));
table["size"] = osg::Vec2f(mCoord.width, mCoord.height); table["size"] = osg::Vec2f(static_cast<float>(mCoord.width), static_cast<float>(mCoord.height));
triggerEvent("windowDrag", table); triggerEvent("windowDrag", table);
} }
} }

View file

@ -141,7 +141,7 @@ namespace MyGUIPlatform
reinterpret_cast<const char*>(vbo->getArray(0)->getDataPointer()) + 16); reinterpret_cast<const char*>(vbo->getArray(0)->getDataPointer()) + 16);
} }
glDrawArrays(GL_TRIANGLES, 0, batch.mVertexCount); glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(batch.mVertexCount));
if (batch.mStateSet) if (batch.mStateSet)
{ {
@ -328,7 +328,8 @@ namespace MyGUIPlatform
osg::UByteArray* OSGVertexBuffer::create() osg::UByteArray* OSGVertexBuffer::create()
{ {
mVertexArray[mCurrentBuffer] = new osg::UByteArray(mNeedVertexCount * sizeof(MyGUI::Vertex)); mVertexArray[mCurrentBuffer]
= new osg::UByteArray(static_cast<unsigned int>(mNeedVertexCount * sizeof(MyGUI::Vertex)));
mBuffer[mCurrentBuffer] = new osg::VertexBufferObject; mBuffer[mCurrentBuffer] = new osg::VertexBufferObject;
mBuffer[mCurrentBuffer]->setDataVariance(osg::Object::DYNAMIC); mBuffer[mCurrentBuffer]->setDataVariance(osg::Object::DYNAMIC);
@ -404,7 +405,7 @@ namespace MyGUIPlatform
mSceneRoot->addChild(mGuiRoot.get()); mSceneRoot->addChild(mGuiRoot.get());
osg::ref_ptr<osg::Viewport> vp = mViewer->getCamera()->getViewport(); osg::ref_ptr<osg::Viewport> vp = mViewer->getCamera()->getViewport();
setViewSize(vp->width(), vp->height()); setViewSize(static_cast<int>(vp->width()), static_cast<int>(vp->height()));
MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized"); MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true; mIsInitialise = true;
@ -500,7 +501,7 @@ namespace MyGUIPlatform
mGuiRoot->setViewport(0, 0, width, height); mGuiRoot->setViewport(0, 0, width, height);
mViewSize.set(width * mInvScalingFactor, height * mInvScalingFactor); mViewSize.set(static_cast<int>(width * mInvScalingFactor), static_cast<int>(height * mInvScalingFactor));
mInfo.maximumDepth = 1; mInfo.maximumDepth = 1;
mInfo.hOffset = 0; mInfo.hOffset = 0;

View file

@ -699,7 +699,7 @@ namespace Nif
assert(r != nullptr); assert(r != nullptr);
assert(r->recType != RC_MISSING); assert(r->recType != RC_MISSING);
r->recName = std::move(rec); r->recName = std::move(rec);
r->recIndex = i; r->recIndex = static_cast<unsigned>(i);
r->read(&nif); r->read(&nif);
mRecords[i] = std::move(r); mRecords[i] = std::move(r);
} }

View file

@ -664,13 +664,13 @@ namespace Nif
mDynamicVertexSize = (data & 0xF0) >> 0x04; mDynamicVertexSize = (data & 0xF0) >> 0x04;
mUV1Offset = (data & 0xF00) >> 0x08; mUV1Offset = (data & 0xF00) >> 0x08;
mUV2Offset = (data & 0xF000) >> 0x0C; mUV2Offset = (data & 0xF000) >> 0x0C;
mNormalOffset = (data & 0xF0000) >> 0x10; mNormalOffset = static_cast<uint8_t>((data & 0xF0000) >> 0x10);
mTangentOffset = (data & 0xF00000) >> 0x14; mTangentOffset = static_cast<uint8_t>((data & 0xF00000) >> 0x14);
mColorOffset = (data & 0xF000000) >> 0x18; mColorOffset = (data & 0xF000000) >> 0x18;
mSkinningDataOffset = (data & 0xF0000000) >> 0x1C; mSkinningDataOffset = (data & 0xF0000000) >> 0x1C;
mLandscapeDataOffset = (data & 0xF00000000) >> 0x20; mLandscapeDataOffset = static_cast<uint8_t>((data & 0xF00000000) >> 0x20);
mEyeDataOffset = (data & 0xF000000000) >> 0x24; mEyeDataOffset = static_cast<uint8_t>((data & 0xF000000000) >> 0x24);
mFlags = (data & 0xFFF00000000000) >> 0x2C; mFlags = static_cast<uint16_t>((data & 0xFFF00000000000) >> 0x2C);
if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_SSE) if (nif->getBethVersion() == NIFFile::BethVersion::BETHVER_SSE)
mFlags |= BSVertexDesc::VertexAttribute::Full_Precision; mFlags |= BSVertexDesc::VertexAttribute::Full_Precision;
} }

View file

@ -165,7 +165,7 @@ namespace
osg::Matrix modelView = *cv->getModelViewMatrix(); osg::Matrix modelView = *cv->getModelViewMatrix();
// attempt to preserve scale // attempt to preserve scale
float mag[3]; double mag[3];
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
{ {
mag[i] = std::sqrt(modelView(0, i) * modelView(0, i) + modelView(1, i) * modelView(1, i) mag[i] = std::sqrt(modelView(0, i) * modelView(0, i) + modelView(1, i) * modelView(1, i)
@ -1083,7 +1083,7 @@ namespace NifOsg
texture2d->setTextureSize(image->s(), image->t()); texture2d->setTextureSize(image->s(), image->t());
texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); texture2d->setWrap(osg::Texture::WRAP_S, wrapS ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE); texture2d->setWrap(osg::Texture::WRAP_T, wrapT ? osg::Texture::REPEAT : osg::Texture::CLAMP_TO_EDGE);
unsigned int texUnit = boundTextures.size(); auto texUnit = static_cast<unsigned int>(boundTextures.size());
if (stateset) if (stateset)
{ {
stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON);
@ -1244,12 +1244,12 @@ namespace NifOsg
auto particleNode = static_cast<const Nif::NiParticles*>(nifNode); auto particleNode = static_cast<const Nif::NiParticles*>(nifNode);
if (particleNode->mData.empty()) if (particleNode->mData.empty())
{ {
partsys->setQuota(partctrl->mParticles.size()); partsys->setQuota(static_cast<int>(partctrl->mParticles.size()));
return; return;
} }
auto particledata = static_cast<const Nif::NiParticlesData*>(particleNode->mData.getPtr()); auto particledata = static_cast<const Nif::NiParticlesData*>(particleNode->mData.getPtr());
partsys->setQuota(particledata->mNumParticles); partsys->setQuota(static_cast<int>(particledata->mNumParticles));
osg::BoundingBox box; osg::BoundingBox box;
@ -1342,7 +1342,7 @@ namespace NifOsg
{ {
for (const auto& emitterPair : mEmitterQueue) for (const auto& emitterPair : mEmitterQueue)
{ {
size_t recIndex = emitterPair.first; auto recIndex = static_cast<unsigned>(emitterPair.first);
FindGroupByRecIndex findEmitterNode(recIndex); FindGroupByRecIndex findEmitterNode(recIndex);
rootNode->accept(findEmitterNode); rootNode->accept(findEmitterNode);
osg::Group* emitterNode = findEmitterNode.mFound; osg::Group* emitterNode = findEmitterNode.mFound;
@ -1488,15 +1488,15 @@ namespace NifOsg
const std::vector<unsigned short>& trueTriangles = partition.mTrueTriangles; const std::vector<unsigned short>& trueTriangles = partition.mTrueTriangles;
if (!trueTriangles.empty()) if (!trueTriangles.empty())
{ {
geometry->addPrimitiveSet(new osg::DrawElementsUShort( geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES,
osg::PrimitiveSet::TRIANGLES, trueTriangles.size(), trueTriangles.data())); static_cast<unsigned>(trueTriangles.size()), trueTriangles.data()));
} }
for (const auto& strip : partition.mTrueStrips) for (const auto& strip : partition.mTrueStrips)
{ {
if (strip.size() < 3) if (strip.size() < 3)
continue; continue;
geometry->addPrimitiveSet(new osg::DrawElementsUShort( geometry->addPrimitiveSet(new osg::DrawElementsUShort(
osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(), strip.data())); osg::PrimitiveSet::TRIANGLE_STRIP, static_cast<unsigned>(strip.size()), strip.data()));
} }
} }
} }
@ -1511,8 +1511,8 @@ namespace NifOsg
const std::vector<unsigned short>& triangles = data->mTriangles; const std::vector<unsigned short>& triangles = data->mTriangles;
if (triangles.empty()) if (triangles.empty())
return; return;
geometry->addPrimitiveSet( geometry->addPrimitiveSet(new osg::DrawElementsUShort(
new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, triangles.size(), triangles.data())); osg::PrimitiveSet::TRIANGLES, static_cast<unsigned>(triangles.size()), triangles.data()));
} }
else if (niGeometry->recType == Nif::RC_NiTriStrips) else if (niGeometry->recType == Nif::RC_NiTriStrips)
{ {
@ -1522,8 +1522,8 @@ namespace NifOsg
{ {
if (strip.size() < 3) if (strip.size() < 3)
continue; continue;
geometry->addPrimitiveSet( geometry->addPrimitiveSet(new osg::DrawElementsUShort(
new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(), strip.data())); osg::PrimitiveSet::TRIANGLE_STRIP, static_cast<unsigned>(strip.size()), strip.data()));
hasGeometry = true; hasGeometry = true;
} }
if (!hasGeometry) if (!hasGeometry)
@ -1535,8 +1535,8 @@ namespace NifOsg
const auto& line = data->mLines; const auto& line = data->mLines;
if (line.empty()) if (line.empty())
return; return;
geometry->addPrimitiveSet( geometry->addPrimitiveSet(new osg::DrawElementsUShort(
new osg::DrawElementsUShort(osg::PrimitiveSet::LINES, line.size(), line.data())); osg::PrimitiveSet::LINES, static_cast<unsigned>(line.size()), line.data()));
} }
} }
@ -1544,17 +1544,18 @@ namespace NifOsg
const auto& normals = niGeometryData->mNormals; const auto& normals = niGeometryData->mNormals;
const auto& colors = niGeometryData->mColors; const auto& colors = niGeometryData->mColors;
if (!vertices.empty()) if (!vertices.empty())
geometry->setVertexArray(new osg::Vec3Array(vertices.size(), vertices.data())); geometry->setVertexArray(new osg::Vec3Array(static_cast<unsigned>(vertices.size()), vertices.data()));
if (!normals.empty()) if (!normals.empty())
geometry->setNormalArray( geometry->setNormalArray(new osg::Vec3Array(static_cast<unsigned>(normals.size()), normals.data()),
new osg::Vec3Array(normals.size(), normals.data()), osg::Array::BIND_PER_VERTEX); osg::Array::BIND_PER_VERTEX);
if (!colors.empty()) if (!colors.empty())
geometry->setColorArray(new osg::Vec4Array(colors.size(), colors.data()), osg::Array::BIND_PER_VERTEX); geometry->setColorArray(new osg::Vec4Array(static_cast<unsigned>(colors.size()), colors.data()),
osg::Array::BIND_PER_VERTEX);
const auto& uvlist = niGeometryData->mUVList; const auto& uvlist = niGeometryData->mUVList;
int textureStage = 0; int textureStage = 0;
for (std::vector<unsigned int>::const_iterator it = boundTextures.begin(); it != boundTextures.end(); for (std::vector<unsigned int>::const_iterator it = boundTextures.begin(); it != boundTextures.end();
++it, ++textureStage) ++it, ++textureStage)
{ {
unsigned int uvSet = *it; unsigned int uvSet = *it;
if (uvSet >= uvlist.size()) if (uvSet >= uvlist.size())
@ -1566,7 +1567,8 @@ namespace NifOsg
uvSet = 0; uvSet = 0;
} }
geometry->setTexCoordArray(textureStage, new osg::Vec2Array(uvlist[uvSet].size(), uvlist[uvSet].data()), geometry->setTexCoordArray(textureStage,
new osg::Vec2Array(static_cast<unsigned>(uvlist[uvSet].size()), uvlist[uvSet].data()),
osg::Array::BIND_PER_VERTEX); osg::Array::BIND_PER_VERTEX);
} }
@ -1650,8 +1652,9 @@ namespace NifOsg
osg::ref_ptr<SceneUtil::MorphGeometry> morphGeom = new SceneUtil::MorphGeometry; osg::ref_ptr<SceneUtil::MorphGeometry> morphGeom = new SceneUtil::MorphGeometry;
morphGeom->setSourceGeometry(geom); morphGeom->setSourceGeometry(geom);
for (unsigned int i = 0; i < morphs.size(); ++i) for (unsigned int i = 0; i < morphs.size(); ++i)
morphGeom->addMorphTarget( morphGeom->addMorphTarget(new osg::Vec3Array(static_cast<unsigned>(morphs[i].mVertices.size()),
new osg::Vec3Array(morphs[i].mVertices.size(), morphs[i].mVertices.data()), 0.f); morphs[i].mVertices.data()),
0.f);
osg::ref_ptr<GeomMorpherController> morphctrl = new GeomMorpherController(nimorphctrl); osg::ref_ptr<GeomMorpherController> morphctrl = new GeomMorpherController(nimorphctrl);
setupController(ctrl.getPtr(), morphctrl, animflags); setupController(ctrl.getPtr(), morphctrl, animflags);
@ -1678,8 +1681,8 @@ namespace NifOsg
return; return;
osg::ref_ptr<osg::Geometry> geometry(new osg::Geometry); osg::ref_ptr<osg::Geometry> geometry(new osg::Geometry);
geometry->addPrimitiveSet( geometry->addPrimitiveSet(new osg::DrawElementsUShort(
new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, triangles.size(), triangles.data())); osg::PrimitiveSet::TRIANGLES, static_cast<unsigned>(triangles.size()), triangles.data()));
osg::ref_ptr<osg::Drawable> drawable = geometry; osg::ref_ptr<osg::Drawable> drawable = geometry;
@ -1743,16 +1746,16 @@ namespace NifOsg
} }
if (!vertices.empty()) if (!vertices.empty())
geometry->setVertexArray(new osg::Vec3Array(vertices.size(), vertices.data())); geometry->setVertexArray(new osg::Vec3Array(static_cast<unsigned>(vertices.size()), vertices.data()));
if (!normals.empty()) if (!normals.empty())
geometry->setNormalArray( geometry->setNormalArray(new osg::Vec3Array(static_cast<unsigned>(normals.size()), normals.data()),
new osg::Vec3Array(normals.size(), normals.data()), osg::Array::BIND_PER_VERTEX); osg::Array::BIND_PER_VERTEX);
if (!colors.empty()) if (!colors.empty())
geometry->setColorArray( geometry->setColorArray(new osg::Vec4ubArray(static_cast<unsigned>(colors.size()), colors.data()),
new osg::Vec4ubArray(colors.size(), colors.data()), osg::Array::BIND_PER_VERTEX); osg::Array::BIND_PER_VERTEX);
if (!uvlist.empty()) if (!uvlist.empty())
geometry->setTexCoordArray( geometry->setTexCoordArray(0, new osg::Vec2Array(static_cast<unsigned>(uvlist.size()), uvlist.data()),
0, new osg::Vec2Array(uvlist.size(), uvlist.data()), osg::Array::BIND_PER_VERTEX); osg::Array::BIND_PER_VERTEX);
// This is the skinning data Fallout 4 provides // This is the skinning data Fallout 4 provides
// TODO: support Skyrim SE skinning data // TODO: support Skyrim SE skinning data
@ -2124,7 +2127,7 @@ namespace NifOsg
} }
} }
const unsigned int texUnit = boundTextures.size(); const auto texUnit = static_cast<unsigned>(boundTextures.size());
if (tex.mEnabled) if (tex.mEnabled)
{ {
if (tex.mSourceTexture.empty() && texprop->mController.empty()) if (tex.mSourceTexture.empty() && texprop->mController.empty())
@ -2632,7 +2635,7 @@ namespace NifOsg
if (!texprop->mSourceTexture.empty()) if (!texprop->mSourceTexture.empty())
{ {
const unsigned int uvSet = 0; const unsigned int uvSet = 0;
unsigned int texUnit = boundTextures.size(); unsigned int texUnit = static_cast<unsigned>(boundTextures.size());
attachExternalTexture("diffuseMap", texprop->mSourceTexture, texprop->wrapS(), texprop->wrapT(), attachExternalTexture("diffuseMap", texprop->mSourceTexture, texprop->wrapS(), texprop->wrapT(),
uvSet, stateset, boundTextures); uvSet, stateset, boundTextures);
{ {

View file

@ -487,7 +487,8 @@ namespace NifOsg
} }
else else
{ {
int randomIndex = static_cast<int>(std::floor(Misc::Rng::rollClosedProbability() * (mTargets.size() - 1))); int randomIndex
= static_cast<int>(std::floor(Misc::Rng::rollClosedProbability() * (mTargets.size() - 1)));
recIndex = mTargets[randomIndex]; recIndex = mTargets[randomIndex];
} }

View file

@ -86,8 +86,8 @@ namespace Resource
shape->mCollisionBox.mExtents[0] = static_cast<float>(aabbMax[0] - aabbMin[0]) / 2.0f; shape->mCollisionBox.mExtents[0] = static_cast<float>(aabbMax[0] - aabbMin[0]) / 2.0f;
shape->mCollisionBox.mExtents[1] = static_cast<float>(aabbMax[1] - aabbMin[1]) / 2.0f; shape->mCollisionBox.mExtents[1] = static_cast<float>(aabbMax[1] - aabbMin[1]) / 2.0f;
shape->mCollisionBox.mExtents[2] = static_cast<float>(aabbMax[2] - aabbMin[2]) / 2.0f; shape->mCollisionBox.mExtents[2] = static_cast<float>(aabbMax[2] - aabbMin[2]) / 2.0f;
shape->mCollisionBox.mCenter = osg::Vec3f( shape->mCollisionBox.mCenter = osg::Vec3f(static_cast<float>(aabbMax[0] + aabbMin[0]) / 2.0f,
static_cast<float>(aabbMax[0] + aabbMin[0]) / 2.0f, static_cast<float>(aabbMax[1] + aabbMin[1]) / 2.0f, static_cast<float>(aabbMax[2] + aabbMin[2]) / 2.0f); static_cast<float>(aabbMax[1] + aabbMin[1]) / 2.0f, static_cast<float>(aabbMax[2] + aabbMin[2]) / 2.0f);
shape->mCollisionShape.reset(triangleMeshShape.release()); shape->mCollisionShape.reset(triangleMeshShape.release());
return shape; return shape;

View file

@ -141,9 +141,9 @@ namespace Resource
class SharedStateManager : public osgDB::SharedStateManager class SharedStateManager : public osgDB::SharedStateManager
{ {
public: public:
unsigned int getNumSharedTextures() const { return _sharedTextureList.size(); } size_t getNumSharedTextures() const { return _sharedTextureList.size(); }
unsigned int getNumSharedStateSets() const { return _sharedStateSetList.size(); } size_t getNumSharedStateSets() const { return _sharedStateSetList.size(); }
void clearCache() void clearCache()
{ {
@ -158,7 +158,7 @@ namespace Resource
{ {
public: public:
SetFilterSettingsControllerVisitor( SetFilterSettingsControllerVisitor(
osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, int maxAnisotropy) osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, float maxAnisotropy)
: mMinFilter(minFilter) : mMinFilter(minFilter)
, mMagFilter(magFilter) , mMagFilter(magFilter)
, mMaxAnisotropy(maxAnisotropy) , mMaxAnisotropy(maxAnisotropy)
@ -170,7 +170,7 @@ namespace Resource
if (NifOsg::FlipController* flipctrl = dynamic_cast<NifOsg::FlipController*>(&ctrl)) if (NifOsg::FlipController* flipctrl = dynamic_cast<NifOsg::FlipController*>(&ctrl))
{ {
for (std::vector<osg::ref_ptr<osg::Texture2D>>::iterator it = flipctrl->getTextures().begin(); for (std::vector<osg::ref_ptr<osg::Texture2D>>::iterator it = flipctrl->getTextures().begin();
it != flipctrl->getTextures().end(); ++it) it != flipctrl->getTextures().end(); ++it)
{ {
osg::Texture* tex = *it; osg::Texture* tex = *it;
tex->setFilter(osg::Texture::MIN_FILTER, mMinFilter); tex->setFilter(osg::Texture::MIN_FILTER, mMinFilter);
@ -183,7 +183,7 @@ namespace Resource
private: private:
osg::Texture::FilterMode mMinFilter; osg::Texture::FilterMode mMinFilter;
osg::Texture::FilterMode mMagFilter; osg::Texture::FilterMode mMagFilter;
int mMaxAnisotropy; float mMaxAnisotropy;
}; };
/// Set texture filtering settings on textures contained in StateSets. /// Set texture filtering settings on textures contained in StateSets.
@ -191,7 +191,7 @@ namespace Resource
{ {
public: public:
SetFilterSettingsVisitor( SetFilterSettingsVisitor(
osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, int maxAnisotropy) osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, float maxAnisotropy)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
, mMinFilter(minFilter) , mMinFilter(minFilter)
, mMagFilter(magFilter) , mMagFilter(magFilter)
@ -233,7 +233,7 @@ namespace Resource
private: private:
osg::Texture::FilterMode mMinFilter; osg::Texture::FilterMode mMinFilter;
osg::Texture::FilterMode mMagFilter; osg::Texture::FilterMode mMagFilter;
int mMaxAnisotropy; float mMaxAnisotropy;
}; };
// Check Collada extra descriptions // Check Collada extra descriptions
@ -461,7 +461,7 @@ namespace Resource
, mBgsmFileManager(bgsmFileManager) , mBgsmFileManager(bgsmFileManager)
, mMinFilter(osg::Texture::LINEAR_MIPMAP_LINEAR) , mMinFilter(osg::Texture::LINEAR_MIPMAP_LINEAR)
, mMagFilter(osg::Texture::LINEAR) , mMagFilter(osg::Texture::LINEAR)
, mMaxAnisotropy(1) , mMaxAnisotropy(1.f)
, mUnRefImageDataAfterApply(false) , mUnRefImageDataAfterApply(false)
, mParticleSystemMask(~0u) , mParticleSystemMask(~0u)
{ {
@ -1129,7 +1129,7 @@ namespace Resource
} }
void SceneManager::setFilterSettings( void SceneManager::setFilterSettings(
const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, int maxAnisotropy) const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, float maxAnisotropy)
{ {
osg::Texture::FilterMode min = osg::Texture::LINEAR; osg::Texture::FilterMode min = osg::Texture::LINEAR;
osg::Texture::FilterMode mag = osg::Texture::LINEAR; osg::Texture::FilterMode mag = osg::Texture::LINEAR;
@ -1163,7 +1163,7 @@ namespace Resource
mMinFilter = min; mMinFilter = min;
mMagFilter = mag; mMagFilter = mag;
mMaxAnisotropy = std::max(1, maxAnisotropy); mMaxAnisotropy = std::max(1.f, maxAnisotropy);
SetFilterSettingsControllerVisitor setFilterSettingsControllerVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); SetFilterSettingsControllerVisitor setFilterSettingsControllerVisitor(mMinFilter, mMagFilter, mMaxAnisotropy);
SetFilterSettingsVisitor setFilterSettingsVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); SetFilterSettingsVisitor setFilterSettingsVisitor(mMinFilter, mMagFilter, mMaxAnisotropy);
@ -1225,13 +1225,16 @@ namespace Resource
if (mIncrementalCompileOperation) if (mIncrementalCompileOperation)
{ {
std::lock_guard<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex()); std::lock_guard<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex());
stats->setAttribute(frameNumber, "Compiling", mIncrementalCompileOperation->getToCompile().size()); stats->setAttribute(
frameNumber, "Compiling", static_cast<double>(mIncrementalCompileOperation->getToCompile().size()));
} }
{ {
std::lock_guard<std::mutex> lock(mSharedStateMutex); std::lock_guard<std::mutex> lock(mSharedStateMutex);
stats->setAttribute(frameNumber, "Texture", mSharedStateManager->getNumSharedTextures()); stats->setAttribute(
stats->setAttribute(frameNumber, "StateSet", mSharedStateManager->getNumSharedStateSets()); frameNumber, "Texture", static_cast<double>(mSharedStateManager->getNumSharedTextures()));
stats->setAttribute(
frameNumber, "StateSet", static_cast<double>(mSharedStateManager->getNumSharedStateSets()));
} }
Resource::reportStats("Node", frameNumber, mCache->getStats(), *stats); Resource::reportStats("Node", frameNumber, mCache->getStats(), *stats);

View file

@ -207,7 +207,7 @@ namespace Resource
/// @warning It is unsafe to call this method while the draw thread is using textures! call /// @warning It is unsafe to call this method while the draw thread is using textures! call
/// Viewer::stopThreading first. /// Viewer::stopThreading first.
void setFilterSettings( void setFilterSettings(
const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, int maxAnisotropy); const std::string& magfilter, const std::string& minfilter, const std::string& mipmap, float maxAnisotropy);
/// Apply filter settings to the given texture. Note, when loading an object through this scene manager (i.e. /// Apply filter settings to the given texture. Note, when loading an object through this scene manager (i.e.
/// calling getTemplate or createInstance) the filter settings are applied automatically. This method is /// calling getTemplate or createInstance) the filter settings are applied automatically. This method is
@ -263,7 +263,7 @@ namespace Resource
osg::Texture::FilterMode mMinFilter; osg::Texture::FilterMode mMinFilter;
osg::Texture::FilterMode mMagFilter; osg::Texture::FilterMode mMagFilter;
int mMaxAnisotropy; float mMaxAnisotropy;
bool mUnRefImageDataAfterApply; bool mUnRefImageDataAfterApply;
osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation; osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;

View file

@ -314,7 +314,7 @@ namespace SceneUtil
bool getModeUsage(ModeUsage& usage) const override bool getModeUsage(ModeUsage& usage) const override
{ {
usage.usesMode(GL_LIGHT0 + mIndex); usage.usesMode(static_cast<GLMode>(GL_LIGHT0 + mIndex));
return true; return true;
} }
@ -325,7 +325,7 @@ namespace SceneUtil
void apply(osg::State& state) const override void apply(osg::State& state) const override
{ {
int lightNum = GL_LIGHT0 + mIndex; GLenum lightNum = static_cast<GLenum>(GL_LIGHT0 + mIndex);
glLightfv(lightNum, GL_AMBIENT, mNullptr.ptr()); glLightfv(lightNum, GL_AMBIENT, mNullptr.ptr());
glLightfv(lightNum, GL_DIFFUSE, mNullptr.ptr()); glLightfv(lightNum, GL_DIFFUSE, mNullptr.ptr());
glLightfv(lightNum, GL_SPECULAR, mNullptr.ptr()); glLightfv(lightNum, GL_SPECULAR, mNullptr.ptr());
@ -365,7 +365,7 @@ namespace SceneUtil
bool getModeUsage(ModeUsage& usage) const override bool getModeUsage(ModeUsage& usage) const override
{ {
for (size_t i = 0; i < mLights.size(); ++i) for (size_t i = 0; i < mLights.size(); ++i)
usage.usesMode(GL_LIGHT0 + static_cast<int>(mIndex) + i); usage.usesMode(static_cast<GLMode>(GL_LIGHT0 + mIndex + i));
return true; return true;
} }
@ -424,7 +424,7 @@ namespace SceneUtil
{ {
LightManager* mLightManager; LightManager* mLightManager;
virtual ~StateSetGenerator() {} virtual ~StateSetGenerator() = default;
virtual osg::ref_ptr<osg::StateSet> generate(const LightManager::LightList& lightList, size_t frameNum) = 0; virtual osg::ref_ptr<osg::StateSet> generate(const LightManager::LightList& lightList, size_t frameNum) = 0;
@ -451,7 +451,8 @@ namespace SceneUtil
new FFPLightStateAttribute(mLightManager->getStartLight(), std::move(lights)), osg::StateAttribute::ON); new FFPLightStateAttribute(mLightManager->getStartLight(), std::move(lights)), osg::StateAttribute::ON);
for (size_t i = 0; i < lightList.size(); ++i) for (size_t i = 0; i < lightList.size(); ++i)
stateset->setMode(GL_LIGHT0 + mLightManager->getStartLight() + static_cast<int>(i), osg::StateAttribute::ON); stateset->setMode(
GL_LIGHT0 + mLightManager->getStartLight() + static_cast<int>(i), osg::StateAttribute::ON);
// need to push some dummy attributes to ensure proper state tracking // need to push some dummy attributes to ensure proper state tracking
// lights need to reset to their default when the StateSet is popped // lights need to reset to their default when the StateSet is popped
@ -774,7 +775,8 @@ namespace SceneUtil
int stride = -1; int stride = -1;
ext->glGetActiveUniformBlockiv(handle, 0, GL_UNIFORM_BLOCK_DATA_SIZE, &totalBlockSize); ext->glGetActiveUniformBlockiv(handle, 0, GL_UNIFORM_BLOCK_DATA_SIZE, &totalBlockSize);
ext->glGetActiveUniformsiv(handle, static_cast<GLsizei>(index.size()), index.data(), GL_UNIFORM_ARRAY_STRIDE, &stride); ext->glGetActiveUniformsiv(
handle, static_cast<GLsizei>(index.size()), index.data(), GL_UNIFORM_ARRAY_STRIDE, &stride);
std::array<const char*, 3> names = { std::array<const char*, 3> names = {
"LightBuffer[0].packedColors", "LightBuffer[0].packedColors",
@ -785,7 +787,8 @@ namespace SceneUtil
std::vector<int> offsets(names.size()); std::vector<int> offsets(names.size());
ext->glGetUniformIndices(handle, static_cast<GLsizei>(names.size()), names.data(), indices.data()); ext->glGetUniformIndices(handle, static_cast<GLsizei>(names.size()), names.data(), indices.data());
ext->glGetActiveUniformsiv(handle, static_cast<GLsizei>(indices.size()), indices.data(), GL_UNIFORM_OFFSET, offsets.data()); ext->glGetActiveUniformsiv(
handle, static_cast<GLsizei>(indices.size()), indices.data(), GL_UNIFORM_OFFSET, offsets.data());
mTemplate->configureLayout(offsets[0], offsets[1], offsets[2], totalBlockSize, stride); mTemplate->configureLayout(offsets[0], offsets[1], offsets[2], totalBlockSize, stride);
} }
@ -1291,7 +1294,7 @@ namespace SceneUtil
const osg::Transform* transform = node->asTransform(); const osg::Transform* transform = node->asTransform();
if (transform) if (transform)
{ {
for (size_t i = 0; i < transform->getNumChildren(); ++i) for (unsigned int i = 0; i < transform->getNumChildren(); ++i)
nodeBound.expandBy(transform->getChild(i)->getBound()); nodeBound.expandBy(transform->getChild(i)->getBound());
} }
else else

View file

@ -3344,7 +3344,7 @@ void SceneUtil::MWShadowTechnique::DebugHUD::addAnotherShadowMap()
size_t shadowMapNumber = mDebugCameras.size(); size_t shadowMapNumber = mDebugCameras.size();
mDebugCameras.push_back(new osg::Camera); mDebugCameras.push_back(new osg::Camera);
mDebugCameras[shadowMapNumber]->setViewport(200 * shadowMapNumber, 0, 200, 200); mDebugCameras[shadowMapNumber]->setViewport(static_cast<int>(200 * shadowMapNumber), 0, 200, 200);
mDebugCameras[shadowMapNumber]->setRenderOrder(osg::Camera::POST_RENDER); mDebugCameras[shadowMapNumber]->setRenderOrder(osg::Camera::POST_RENDER);
mDebugCameras[shadowMapNumber]->setClearColor(osg::Vec4(1.0, 1.0, 0.0, 1.0)); mDebugCameras[shadowMapNumber]->setClearColor(osg::Vec4(1.0, 1.0, 0.0, 1.0));
mDebugCameras[shadowMapNumber]->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); mDebugCameras[shadowMapNumber]->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

View file

@ -52,14 +52,17 @@ namespace SceneUtil
assert(edgeIndexCount < std::numeric_limits<unsigned int>::max()); assert(edgeIndexCount < std::numeric_limits<unsigned int>::max());
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(static_cast<unsigned int>(vertexCount)); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(static_cast<unsigned int>(vertexCount));
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(static_cast<unsigned int>(vertexCount)); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(static_cast<unsigned int>(vertexCount));
osg::ref_ptr<PType> pointIndices = new PType(osg::PrimitiveSet::TRIANGLES, static_cast<unsigned int>(pointIndexCount)); osg::ref_ptr<PType> pointIndices
osg::ref_ptr<LType> lineIndices = new LType(osg::PrimitiveSet::LINES, static_cast<unsigned int>(edgeIndexCount)); = new PType(osg::PrimitiveSet::TRIANGLES, static_cast<unsigned int>(pointIndexCount));
osg::ref_ptr<LType> lineIndices
= new LType(osg::PrimitiveSet::LINES, static_cast<unsigned int>(edgeIndexCount));
// Add each point/node // Add each point/node
for (size_t pointIndex = 0; pointIndex < pathgrid.mPoints.size(); ++pointIndex) for (size_t pointIndex = 0; pointIndex < pathgrid.mPoints.size(); ++pointIndex)
{ {
const ESM::Pathgrid::Point& point = pathgrid.mPoints[pointIndex]; const ESM::Pathgrid::Point& point = pathgrid.mPoints[pointIndex];
osg::Vec3f position = osg::Vec3f(static_cast<float>(point.mX), static_cast<float>(point.mY), static_cast<float>(point.mZ)); osg::Vec3f position = osg::Vec3f(
static_cast<float>(point.mX), static_cast<float>(point.mY), static_cast<float>(point.mZ));
size_t vertexOffset = pointIndex * DiamondTotalVertexCount; size_t vertexOffset = pointIndex * DiamondTotalVertexCount;
size_t indexOffset = pointIndex * DiamondIndexCount; size_t indexOffset = pointIndex * DiamondIndexCount;
@ -73,7 +76,8 @@ namespace SceneUtil
for (unsigned short i = 0; i < DiamondIndexCount; ++i) for (unsigned short i = 0; i < DiamondIndexCount; ++i)
{ {
pointIndices->setElement(static_cast<unsigned int>(indexOffset + i), static_cast<unsigned int>(vertexOffset + DiamondIndices[i])); pointIndices->setElement(static_cast<unsigned int>(indexOffset + i),
static_cast<unsigned int>(vertexOffset + DiamondIndices[i]));
} }
// Connectors // Connectors
@ -96,8 +100,10 @@ namespace SceneUtil
const ESM::Pathgrid::Point& from = pathgrid.mPoints[edge.mV0]; const ESM::Pathgrid::Point& from = pathgrid.mPoints[edge.mV0];
const ESM::Pathgrid::Point& to = pathgrid.mPoints[edge.mV1]; const ESM::Pathgrid::Point& to = pathgrid.mPoints[edge.mV1];
osg::Vec3f fromPos = osg::Vec3f(static_cast<float>(from.mX), static_cast<float>(from.mY), static_cast<float>(from.mZ)); osg::Vec3f fromPos
osg::Vec3f toPos = osg::Vec3f(static_cast<float>(to.mX), static_cast<float>(to.mY), static_cast<float>(to.mZ)); = osg::Vec3f(static_cast<float>(from.mX), static_cast<float>(from.mY), static_cast<float>(from.mZ));
osg::Vec3f toPos
= osg::Vec3f(static_cast<float>(to.mX), static_cast<float>(to.mY), static_cast<float>(to.mZ));
osg::Vec3f dir = toPos - fromPos; osg::Vec3f dir = toPos - fromPos;
dir.normalize(); dir.normalize();
@ -153,7 +159,9 @@ namespace SceneUtil
for (size_t it = 0; it < selected.size(); ++it) for (size_t it = 0; it < selected.size(); ++it)
{ {
const ESM::Pathgrid::Point& point = pathgrid.mPoints[selected[it]]; const ESM::Pathgrid::Point& point = pathgrid.mPoints[selected[it]];
osg::Vec3f position = osg::Vec3f(static_cast<float>(point.mX), static_cast<float>(point.mY), static_cast<float>(point.mZ)) + wireOffset; osg::Vec3f position = osg::Vec3f(static_cast<float>(point.mX), static_cast<float>(point.mY),
static_cast<float>(point.mZ))
+ wireOffset;
size_t vertexOffset = it * DiamondVertexCount; size_t vertexOffset = it * DiamondVertexCount;
size_t indexOffset = it * DiamondWireframeIndexCount; size_t indexOffset = it * DiamondWireframeIndexCount;
@ -171,7 +179,8 @@ namespace SceneUtil
for (unsigned short i = 0; i < DiamondWireframeIndexCount; ++i) for (unsigned short i = 0; i < DiamondWireframeIndexCount; ++i)
{ {
indices->setElement(static_cast<unsigned int>(indexOffset + i), static_cast<unsigned int>(vertexOffset + DiamondWireframeIndices[i])); indices->setElement(static_cast<unsigned int>(indexOffset + i),
static_cast<unsigned int>(vertexOffset + DiamondWireframeIndices[i]));
} }
} }

View file

@ -58,7 +58,8 @@ namespace SceneUtil
normal->push_back(osg::Vec3f(0, 0, 1)); normal->push_back(osg::Vec3f(0, 0, 1));
waterGeom->setNormalArray(normal, osg::Array::BIND_OVERALL); waterGeom->setNormalArray(normal, osg::Array::BIND_OVERALL);
waterGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, static_cast<GLsizei>(verts->size()))); waterGeom->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, static_cast<GLsizei>(verts->size())));
waterGeom->setComputeBoundingBoxCallback(new WaterBoundCallback); waterGeom->setComputeBoundingBoxCallback(new WaterBoundCallback);
waterGeom->setCullingActive(false); waterGeom->setCullingActive(false);
return waterGeom; return waterGeom;

View file

@ -39,7 +39,7 @@ namespace SDLUtil
_setWindowScale(); _setWindowScale();
} }
InputWrapper::~InputWrapper() {} InputWrapper::~InputWrapper() = default;
void InputWrapper::_setWindowScale() void InputWrapper::_setWindowScale()
{ {
@ -47,8 +47,8 @@ namespace SDLUtil
SDL_GetWindowSize(mSDLWindow, &w, &h); SDL_GetWindowSize(mSDLWindow, &w, &h);
int dw, dh; int dw, dh;
SDL_GL_GetDrawableSize(mSDLWindow, &dw, &dh); SDL_GL_GetDrawableSize(mSDLWindow, &dw, &dh);
mScaleX = dw / w; mScaleX = static_cast<Uint16>(dw / w);
mScaleY = dh / h; mScaleY = static_cast<Uint16>(dh / h);
} }
void InputWrapper::capture(bool windowEventsOnly) void InputWrapper::capture(bool windowEventsOnly)
@ -320,8 +320,8 @@ namespace SDLUtil
{ {
SDL_WarpMouseInWindow(mSDLWindow, x, y); SDL_WarpMouseInWindow(mSDLWindow, x, y);
mWarpCompensate = true; mWarpCompensate = true;
mWarpX = x; mWarpX = static_cast<Uint16>(x);
mWarpY = y; mWarpY = static_cast<Uint16>(y);
} }
/// \brief Locks the pointer to the window /// \brief Locks the pointer to the window

View file

@ -69,7 +69,8 @@ namespace
{ {
lineDirectivePosition = 0; lineDirectivePosition = 0;
} }
lineNumber += std::count(source.begin() + lineDirectivePosition, source.begin() + foundPos, '\n'); lineNumber
+= static_cast<int>(std::count(source.begin() + lineDirectivePosition, source.begin() + foundPos, '\n'));
return lineNumber; return lineNumber;
} }
} }

View file

@ -52,7 +52,7 @@ namespace Stereo
bool getTextureViewSupportedImpl(unsigned int contextID) bool getTextureViewSupportedImpl(unsigned int contextID)
{ {
if (!osg::isGLExtensionOrVersionSupported(contextID, "ARB_texture_view", 4.3)) if (!osg::isGLExtensionOrVersionSupported(contextID, "ARB_texture_view", 4.3f))
{ {
Log(Debug::Verbose) << "Disabling texture views (opengl extension \"ARB_texture_view\" not supported)"; Log(Debug::Verbose) << "Disabling texture views (opengl extension \"ARB_texture_view\" not supported)";
return false; return false;

View file

@ -114,7 +114,7 @@ namespace Stereo
return *sInstance; return *sInstance;
} }
Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo, double near, double far) Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo, float near, float far)
: mViewer(viewer) : mViewer(viewer)
, mMainCamera(mViewer->getCamera()) , mMainCamera(mViewer->getCamera())
, mUpdateCallback(new StereoUpdateCallback(this)) , mUpdateCallback(new StereoUpdateCallback(this))
@ -182,8 +182,8 @@ namespace Stereo
{ {
if (mEyeResolutionOverriden) if (mEyeResolutionOverriden)
return mEyeResolutionOverride; return mEyeResolutionOverride;
auto width = mMainCamera->getViewport()->width() / 2; auto width = static_cast<int>(mMainCamera->getViewport()->width() / 2);
auto height = mMainCamera->getViewport()->height(); auto height = static_cast<int>(mMainCamera->getViewport()->height());
return osg::Vec2i(width, height); return osg::Vec2i(width, height);
} }

View file

@ -78,13 +78,13 @@ namespace Stereo
//! @Param enableMultiview whether or not to make use of the GL_OVR_Multiview extension, if supported. //! @Param enableMultiview whether or not to make use of the GL_OVR_Multiview extension, if supported.
//! @Param near defines distance to near camera clipping plane from view point. //! @Param near defines distance to near camera clipping plane from view point.
//! @Param far defines distance to far camera clipping plane from view point. //! @Param far defines distance to far camera clipping plane from view point.
explicit Manager(osgViewer::Viewer* viewer, bool enableStereo, double near, double far); explicit Manager(osgViewer::Viewer* viewer, bool enableStereo, float near, float far);
~Manager(); ~Manager();
//! Called during update traversal //! Called during update traversal
void update(); void update();
void updateSettings(double near, double far) void updateSettings(float near, float far)
{ {
mNear = near; mNear = near;
mFar = far; mFar = far;
@ -146,8 +146,8 @@ namespace Stereo
std::shared_ptr<MultiviewFramebuffer> mMultiviewFramebuffer; std::shared_ptr<MultiviewFramebuffer> mMultiviewFramebuffer;
bool mEyeResolutionOverriden; bool mEyeResolutionOverriden;
osg::Vec2i mEyeResolutionOverride; osg::Vec2i mEyeResolutionOverride;
double mNear; float mNear;
double mFar; float mFar;
std::array<View, 2> mView; std::array<View, 2> mView;
std::array<osg::Matrixd, 2> mViewOffsetMatrix; std::array<osg::Matrixd, 2> mViewOffsetMatrix;

View file

@ -60,15 +60,18 @@ namespace Stereo
// that view matrix will already convert points to a camera space // that view matrix will already convert points to a camera space
// with opengl conventions. So we need to convert offsets to opengl // with opengl conventions. So we need to convert offsets to opengl
// conventions. // conventions.
float y = position.y(); {
float z = position.z(); float y = position.y();
position.y() = z; float z = position.z();
position.z() = -y; position.y() = z;
position.z() = -y;
y = orientation.y(); }
z = orientation.z(); {
orientation.y() = z; double y = orientation.y();
orientation.z() = -y; double z = orientation.z();
orientation.y() = z;
orientation.z() = -y;
}
osg::Matrix viewMatrix; osg::Matrix viewMatrix;
viewMatrix.setTrans(-position); viewMatrix.setTrans(-position);

View file

@ -12,6 +12,7 @@ namespace
template <typename IndexArrayType> template <typename IndexArrayType>
osg::ref_ptr<IndexArrayType> createIndexBuffer(unsigned int flags, unsigned int verts) osg::ref_ptr<IndexArrayType> createIndexBuffer(unsigned int flags, unsigned int verts)
{ {
using IndexType = IndexArrayType::value_type;
// LOD level n means every 2^n-th vertex is kept, but we currently handle LOD elsewhere. // LOD level n means every 2^n-th vertex is kept, but we currently handle LOD elsewhere.
size_t lodLevel = 0; //(flags >> (4*4)); size_t lodLevel = 0; //(flags >> (4*4));
@ -45,23 +46,23 @@ namespace
// diamond pattern // diamond pattern
if ((row + col % 2) % 2 == 1) if ((row + col % 2) % 2 == 1)
{ {
indices->push_back(verts * (col + increment) + row); indices->push_back(static_cast<IndexType>(verts * (col + increment) + row));
indices->push_back(verts * (col + increment) + row + increment); indices->push_back(static_cast<IndexType>(verts * (col + increment) + row + increment));
indices->push_back(verts * col + row + increment); indices->push_back(static_cast<IndexType>(verts * col + row + increment));
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
indices->push_back(verts * (col + increment) + row); indices->push_back(static_cast<IndexType>(verts * (col + increment) + row));
indices->push_back(verts * (col) + row + increment); indices->push_back(static_cast<IndexType>(verts * (col) + row + increment));
} }
else else
{ {
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
indices->push_back(verts * (col + increment) + row + increment); indices->push_back(static_cast<IndexType>(verts * (col + increment) + row + increment));
indices->push_back(verts * col + row + increment); indices->push_back(static_cast<IndexType>(verts * col + row + increment));
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
indices->push_back(verts * (col + increment) + row); indices->push_back(static_cast<IndexType>(verts * (col + increment) + row));
indices->push_back(verts * (col + increment) + row + increment); indices->push_back(static_cast<IndexType>(verts * (col + increment) + row + increment));
} }
} }
} }
@ -77,22 +78,22 @@ namespace
size_t outerStep = static_cast<size_t>(1) << (lodDeltas[Terrain::South] + lodLevel); size_t outerStep = static_cast<size_t>(1) << (lodDeltas[Terrain::South] + lodLevel);
for (size_t col = 0; col < verts - 1; col += outerStep) for (size_t col = 0; col < verts - 1; col += outerStep)
{ {
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
indices->push_back(verts * (col + outerStep) + row); indices->push_back(static_cast<IndexType>(verts * (col + outerStep) + row));
// Make sure not to touch the right edge // Make sure not to touch the right edge
if (col + outerStep == verts - 1) if (col + outerStep == verts - 1)
indices->push_back(verts * (col + outerStep - innerStep) + row + innerStep); indices->push_back(static_cast<IndexType>(verts * (col + outerStep - innerStep) + row + innerStep));
else else
indices->push_back(verts * (col + outerStep) + row + innerStep); indices->push_back(static_cast<IndexType>(verts * (col + outerStep) + row + innerStep));
for (size_t i = 0; i < outerStep; i += innerStep) for (size_t i = 0; i < outerStep; i += innerStep)
{ {
// Make sure not to touch the left or right edges // Make sure not to touch the left or right edges
if (col + i == 0 || col + i == verts - 1 - innerStep) if (col + i == 0 || col + i == verts - 1 - innerStep)
continue; continue;
indices->push_back(verts * (col) + row); indices->push_back(static_cast<IndexType>(verts * (col) + row));
indices->push_back(verts * (col + i + innerStep) + row + innerStep); indices->push_back(static_cast<IndexType>(verts * (col + i + innerStep) + row + innerStep));
indices->push_back(verts * (col + i) + row + innerStep); indices->push_back(static_cast<IndexType>(verts * (col + i) + row + innerStep));
} }
} }
@ -101,22 +102,22 @@ namespace
outerStep = size_t(1) << (lodDeltas[Terrain::North] + lodLevel); outerStep = size_t(1) << (lodDeltas[Terrain::North] + lodLevel);
for (size_t col = 0; col < verts - 1; col += outerStep) for (size_t col = 0; col < verts - 1; col += outerStep)
{ {
indices->push_back(verts * (col + outerStep) + row); indices->push_back(static_cast<IndexType>(verts * (col + outerStep) + row));
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
// Make sure not to touch the left edge // Make sure not to touch the left edge
if (col == 0) if (col == 0)
indices->push_back(verts * (col + innerStep) + row - innerStep); indices->push_back(static_cast<IndexType>(verts * (col + innerStep) + row - innerStep));
else else
indices->push_back(verts * col + row - innerStep); indices->push_back(static_cast<IndexType>(verts * col + row - innerStep));
for (size_t i = 0; i < outerStep; i += innerStep) for (size_t i = 0; i < outerStep; i += innerStep)
{ {
// Make sure not to touch the left or right edges // Make sure not to touch the left or right edges
if (col + i == 0 || col + i == verts - 1 - innerStep) if (col + i == 0 || col + i == verts - 1 - innerStep)
continue; continue;
indices->push_back(verts * (col + i) + row - innerStep); indices->push_back(static_cast<IndexType>(verts * (col + i) + row - innerStep));
indices->push_back(verts * (col + i + innerStep) + row - innerStep); indices->push_back(static_cast<IndexType>(verts * (col + i + innerStep) + row - innerStep));
indices->push_back(verts * (col + outerStep) + row); indices->push_back(static_cast<IndexType>(verts * (col + outerStep) + row));
} }
} }
@ -125,22 +126,22 @@ namespace
outerStep = size_t(1) << (lodDeltas[Terrain::West] + lodLevel); outerStep = size_t(1) << (lodDeltas[Terrain::West] + lodLevel);
for (row = 0; row < verts - 1; row += outerStep) for (row = 0; row < verts - 1; row += outerStep)
{ {
indices->push_back(verts * col + row + outerStep); indices->push_back(static_cast<IndexType>(verts * col + row + outerStep));
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
// Make sure not to touch the top edge // Make sure not to touch the top edge
if (row + outerStep == verts - 1) if (row + outerStep == verts - 1)
indices->push_back(verts * (col + innerStep) + row + outerStep - innerStep); indices->push_back(static_cast<IndexType>(verts * (col + innerStep) + row + outerStep - innerStep));
else else
indices->push_back(verts * (col + innerStep) + row + outerStep); indices->push_back(static_cast<IndexType>(verts * (col + innerStep) + row + outerStep));
for (size_t i = 0; i < outerStep; i += innerStep) for (size_t i = 0; i < outerStep; i += innerStep)
{ {
// Make sure not to touch the top or bottom edges // Make sure not to touch the top or bottom edges
if (row + i == 0 || row + i == verts - 1 - innerStep) if (row + i == 0 || row + i == verts - 1 - innerStep)
continue; continue;
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
indices->push_back(verts * (col + innerStep) + row + i); indices->push_back(static_cast<IndexType>(verts * (col + innerStep) + row + i));
indices->push_back(verts * (col + innerStep) + row + i + innerStep); indices->push_back(static_cast<IndexType>(verts * (col + innerStep) + row + i + innerStep));
} }
} }
@ -149,22 +150,22 @@ namespace
outerStep = size_t(1) << (lodDeltas[Terrain::East] + lodLevel); outerStep = size_t(1) << (lodDeltas[Terrain::East] + lodLevel);
for (row = 0; row < verts - 1; row += outerStep) for (row = 0; row < verts - 1; row += outerStep)
{ {
indices->push_back(verts * col + row); indices->push_back(static_cast<IndexType>(verts * col + row));
indices->push_back(verts * col + row + outerStep); indices->push_back(static_cast<IndexType>(verts * col + row + outerStep));
// Make sure not to touch the bottom edge // Make sure not to touch the bottom edge
if (row == 0) if (row == 0)
indices->push_back(verts * (col - innerStep) + row + innerStep); indices->push_back(static_cast<IndexType>(verts * (col - innerStep) + row + innerStep));
else else
indices->push_back(verts * (col - innerStep) + row); indices->push_back(static_cast<IndexType>(verts * (col - innerStep) + row));
for (size_t i = 0; i < outerStep; i += innerStep) for (size_t i = 0; i < outerStep; i += innerStep)
{ {
// Make sure not to touch the top or bottom edges // Make sure not to touch the top or bottom edges
if (row + i == 0 || row + i == verts - 1 - innerStep) if (row + i == 0 || row + i == verts - 1 - innerStep)
continue; continue;
indices->push_back(verts * col + row + outerStep); indices->push_back(static_cast<IndexType>(verts * col + row + outerStep));
indices->push_back(verts * (col - innerStep) + row + i + innerStep); indices->push_back(static_cast<IndexType>(verts * (col - innerStep) + row + i + innerStep));
indices->push_back(verts * (col - innerStep) + row + i); indices->push_back(static_cast<IndexType>(verts * (col - innerStep) + row + i));
} }
} }
} }

View file

@ -62,7 +62,7 @@ namespace Terrain
border->setColorArray(colors.get()); border->setColorArray(colors.get());
border->setColorBinding(osg::Geometry::BIND_PER_VERTEX); border->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, vertices->size())); border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(vertices->size())));
osg::ref_ptr<osg::Group> borderGroup = new osg::Group; osg::ref_ptr<osg::Group> borderGroup = new osg::Group;
borderGroup->addChild(border.get()); borderGroup->addChild(border.get());
@ -84,8 +84,8 @@ namespace Terrain
void CellBorder::createCellBorderGeometry(int x, int y) void CellBorder::createCellBorderGeometry(int x, int y)
{ {
auto borderGroup = createBorderGeometry( auto borderGroup = createBorderGeometry(static_cast<float>(x), static_cast<float>(y), 1.f, mWorld->getStorage(),
x, y, 1.f, mWorld->getStorage(), mSceneManager, mBorderMask, mWorld->getWorldspace()); mSceneManager, mBorderMask, mWorld->getWorldspace());
mRoot->addChild(borderGroup); mRoot->addChild(borderGroup);
mCellBorderNodes[std::make_pair(x, y)] = borderGroup; mCellBorderNodes[std::make_pair(x, y)] = borderGroup;

View file

@ -206,10 +206,10 @@ namespace Terrain
blendmapTextures.push_back(texture); blendmapTextures.push_back(texture);
} }
float tileCount = mStorage->getTextureTileCount(chunkSize, mWorldspace); int tileCount = mStorage->getTextureTileCount(chunkSize, mWorldspace);
return ::Terrain::createPasses( return ::Terrain::createPasses(useShaders, mSceneManager, layers, blendmapTextures, tileCount,
useShaders, mSceneManager, layers, blendmapTextures, tileCount, tileCount, ESM::isEsm4Ext(mWorldspace)); static_cast<float>(tileCount), ESM::isEsm4Ext(mWorldspace));
} }
osg::ref_ptr<osg::Node> ChunkManager::createChunk(float chunkSize, const osg::Vec2f& chunkCenter, unsigned char lod, osg::ref_ptr<osg::Node> ChunkManager::createChunk(float chunkSize, const osg::Vec2f& chunkCenter, unsigned char lod,
@ -261,7 +261,8 @@ namespace Terrain
if (chunkSize <= 1.f) if (chunkSize <= 1.f)
geometry->setLightListCallback(new SceneUtil::LightListCallback); geometry->setLightListCallback(new SceneUtil::LightListCallback);
unsigned int numVerts = (mStorage->getCellVertices(mWorldspace) - 1) * chunkSize / (1 << lod) + 1; unsigned int numVerts
= static_cast<unsigned>((mStorage->getCellVertices(mWorldspace) - 1) * chunkSize / (1 << lod) + 1);
geometry->addPrimitiveSet(mBufferCache.getIndexBuffer(numVerts, lodFlags)); geometry->addPrimitiveSet(mBufferCache.getIndexBuffer(numVerts, lodFlags));
@ -303,7 +304,7 @@ namespace Terrain
layer.mSpecular = false; layer.mSpecular = false;
geometry->setPasses(::Terrain::createPasses( geometry->setPasses(::Terrain::createPasses(
mSceneManager->getForceShaders() || !mSceneManager->getClampLighting(), mSceneManager, mSceneManager->getForceShaders() || !mSceneManager->getClampLighting(), mSceneManager,
std::vector<TextureLayer>(1, layer), std::vector<osg::ref_ptr<osg::Texture2D>>(), 1.f, 1.f)); std::vector<TextureLayer>(1, layer), std::vector<osg::ref_ptr<osg::Texture2D>>(), 1, 1.f));
} }
else else
{ {

View file

@ -21,7 +21,7 @@ namespace Terrain
getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
} }
CompositeMapRenderer::~CompositeMapRenderer() {} CompositeMapRenderer::~CompositeMapRenderer() = default;
void CompositeMapRenderer::drawImplementation(osg::RenderInfo& renderInfo) const void CompositeMapRenderer::drawImplementation(osg::RenderInfo& renderInfo) const
{ {
@ -104,7 +104,7 @@ namespace Terrain
// should OSG be doing this on its own? // should OSG be doing this on its own?
state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), osg::StateAttribute::TEXTURE); state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), osg::StateAttribute::TEXTURE);
for (unsigned int i = compositeMap.mCompiled; i < compositeMap.mDrawables.size(); ++i) for (size_t i = compositeMap.mCompiled; i < compositeMap.mDrawables.size(); ++i)
{ {
osg::Drawable* drw = compositeMap.mDrawables[i]; osg::Drawable* drw = compositeMap.mDrawables[i];
osg::StateSet* stateset = drw->getStateSet(); osg::StateSet* stateset = drw->getStateSet();
@ -165,7 +165,7 @@ namespace Terrain
} }
} }
unsigned int CompositeMapRenderer::getCompileSetSize() const size_t CompositeMapRenderer::getCompileSetSize() const
{ {
std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
return mCompileSet.size(); return mCompileSet.size();

View file

@ -23,7 +23,7 @@ namespace Terrain
~CompositeMap(); ~CompositeMap();
std::vector<osg::ref_ptr<osg::Drawable>> mDrawables; std::vector<osg::ref_ptr<osg::Drawable>> mDrawables;
osg::ref_ptr<osg::Texture2D> mTexture; osg::ref_ptr<osg::Texture2D> mTexture;
unsigned int mCompiled; size_t mCompiled;
}; };
/** /**
@ -52,7 +52,7 @@ namespace Terrain
/// Mark this composite map to be required for the current frame /// Mark this composite map to be required for the current frame
void setImmediate(CompositeMap* map); void setImmediate(CompositeMap* map);
unsigned int getCompileSetSize() const; size_t getCompileSetSize() const;
private: private:
float mTargetFrameRate; float mTargetFrameRate;

View file

@ -24,17 +24,17 @@ namespace
static const osg::ref_ptr<osg::TexMat>& value(const int blendmapScale) static const osg::ref_ptr<osg::TexMat>& value(const int blendmapScale)
{ {
static BlendmapTexMat instance; static BlendmapTexMat instance;
return instance.get(blendmapScale); return instance.get(static_cast<float>(blendmapScale));
} }
const osg::ref_ptr<osg::TexMat>& get(const int blendmapScale) const osg::ref_ptr<osg::TexMat>& get(const float blendmapScale)
{ {
const std::lock_guard<std::mutex> lock(mMutex); const std::lock_guard<std::mutex> lock(mMutex);
auto texMat = mTexMatMap.find(blendmapScale); auto texMat = mTexMatMap.find(blendmapScale);
if (texMat == mTexMatMap.end()) if (texMat == mTexMatMap.end())
{ {
osg::Matrixf matrix; osg::Matrixf matrix;
float scale = (blendmapScale / (static_cast<float>(blendmapScale) + 1.f)); float scale = (blendmapScale / (blendmapScale + 1.f));
matrix.preMultTranslate(osg::Vec3f(0.5f, 0.5f, 0.f)); matrix.preMultTranslate(osg::Vec3f(0.5f, 0.5f, 0.f));
matrix.preMultScale(osg::Vec3f(scale, scale, 1.f)); matrix.preMultScale(osg::Vec3f(scale, scale, 1.f));
matrix.preMultTranslate(osg::Vec3f(-0.5f, -0.5f, 0.f)); matrix.preMultTranslate(osg::Vec3f(-0.5f, -0.5f, 0.f));
@ -43,8 +43,7 @@ namespace
// blendmap, apparently. // blendmap, apparently.
matrix.preMultTranslate(osg::Vec3f(1.0f / blendmapScale / 4.0f, 1.0f / blendmapScale / 4.0f, 0.f)); matrix.preMultTranslate(osg::Vec3f(1.0f / blendmapScale / 4.0f, 1.0f / blendmapScale / 4.0f, 0.f));
texMat = mTexMatMap.insert(std::make_pair(static_cast<float>(blendmapScale), new osg::TexMat(matrix))) texMat = mTexMatMap.emplace(blendmapScale, new osg::TexMat(matrix)).first;
.first;
} }
return texMat->second; return texMat->second;
} }

View file

@ -44,7 +44,7 @@ namespace Terrain
inline QuadTreeNode* getParent() { return mParent; } inline QuadTreeNode* getParent() { return mParent; }
inline QuadTreeNode* getChild(unsigned int i) { return static_cast<QuadTreeNode*>(Group::getChild(i)); } inline QuadTreeNode* getChild(unsigned int i) { return static_cast<QuadTreeNode*>(Group::getChild(i)); }
inline unsigned int getNumChildren() const override { return _children.size(); } inline unsigned int getNumChildren() const override { return static_cast<unsigned int>(_children.size()); }
// osg::Group::addChild() does a lot of unrelated stuff, but we just really want to add a child node. // osg::Group::addChild() does a lot of unrelated stuff, but we just really want to add a child node.
void addChildNode(QuadTreeNode* child) void addChildNode(QuadTreeNode* child)

View file

@ -145,7 +145,7 @@ namespace Terrain
float centerX = (mMinX + mMaxX) / 2.f + (size - origSizeX) / 2.f; float centerX = (mMinX + mMaxX) / 2.f + (size - origSizeX) / 2.f;
float centerY = (mMinY + mMaxY) / 2.f + (size - origSizeY) / 2.f; float centerY = (mMinY + mMaxY) / 2.f + (size - origSizeY) / 2.f;
mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY)); mRootNode = new RootNode(static_cast<float>(size), osg::Vec2f(centerX, centerY));
addChildren(mRootNode); addChildren(mRootNode);
mRootNode->initNeighbours(); mRootNode->initNeighbours();
@ -212,7 +212,8 @@ namespace Terrain
// Do not add child nodes for default cells without data. // Do not add child nodes for default cells without data.
// size = 1 means that the single shape covers the whole cell. // size = 1 means that the single shape covers the whole cell.
if (node->getSize() == 1 if (node->getSize() == 1
&& !mStorage->hasData(ESM::ExteriorCellLocation(center.x() - 0.5, center.y() - 0.5, mWorldspace))) && !mStorage->hasData(ESM::ExteriorCellLocation(
static_cast<int>(center.x() - 0.5f), static_cast<int>(center.y() - 0.5f), mWorldspace)))
return node; return node;
if (node->getSize() <= mMinSize) if (node->getSize() <= mMinSize)
@ -259,14 +260,14 @@ namespace Terrain
, mNodeMask(nodeMask) , mNodeMask(nodeMask)
{ {
} }
osg::ref_ptr<osg::Node> getChunk(float size, const osg::Vec2f& chunkCenter, unsigned char lod, osg::ref_ptr<osg::Node> getChunk(float size, const osg::Vec2f& chunkCenter, unsigned char /*lod*/,
unsigned int lodFlags, bool activeGrid, const osg::Vec3f& viewPoint, bool compile) unsigned int lodFlags, bool activeGrid, const osg::Vec3f& viewPoint, bool compile)
{ {
osg::Vec3f center = { chunkCenter.x(), chunkCenter.y(), 0 }; osg::Vec3f center = { chunkCenter.x(), chunkCenter.y(), 0 };
auto chunkBorder = CellBorder::createBorderGeometry(center.x() - size / 2.f, center.y() - size / 2.f, size, auto chunkBorder = CellBorder::createBorderGeometry(center.x() - size / 2.f, center.y() - size / 2.f, size,
mStorage, mSceneManager, mNodeMask, mWorldspace, 5.f, { 1, 0, 0, 0 }); mStorage, mSceneManager, mNodeMask, mWorldspace, 5.f, { 1, 0, 0, 0 });
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> pat = new SceneUtil::PositionAttitudeTransform; osg::ref_ptr<SceneUtil::PositionAttitudeTransform> pat = new SceneUtil::PositionAttitudeTransform;
pat->setPosition(-center * ESM::getCellSize(mWorldspace)); pat->setPosition(-center * static_cast<float>(ESM::getCellSize(mWorldspace)));
pat->addChild(chunkBorder); pat->addChild(chunkBorder);
return pat; return pat;
} }
@ -282,8 +283,8 @@ namespace Terrain
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask, Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask,
int compMapResolution, float compMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize, int compMapResolution, float compMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize,
bool debugChunks, ESM::RefId worldspace, double expiryDelay) bool debugChunks, ESM::RefId worldspace, double expiryDelay)
: TerrainGrid( : TerrainGrid(parent, compileRoot, resourceSystem, storage, nodeMask, worldspace, expiryDelay, preCompileMask,
parent, compileRoot, resourceSystem, storage, nodeMask, worldspace, expiryDelay, preCompileMask, borderMask) borderMask)
, mViewDataMap(new ViewDataMap) , mViewDataMap(new ViewDataMap)
, mQuadTreeBuilt(false) , mQuadTreeBuilt(false)
, mLodFactor(lodFactor) , mLodFactor(lodFactor)
@ -396,8 +397,8 @@ namespace Terrain
for (QuadTreeWorld::ChunkManager* m : mChunkManagers) for (QuadTreeWorld::ChunkManager* m : mChunkManagers)
{ {
osg::ref_ptr<osg::Node> n = m->getChunk(entry.mNode->getSize(), entry.mNode->getCenter(), osg::ref_ptr<osg::Node> n = m->getChunk(entry.mNode->getSize(), entry.mNode->getCenter(),
DefaultLodCallback::getNativeLodLevel(entry.mNode, mMinSize), entry.mLodFlags, activeGrid, static_cast<unsigned char>(DefaultLodCallback::getNativeLodLevel(entry.mNode, mMinSize)),
vd->getViewPoint(), compile); entry.mLodFlags, activeGrid, vd->getViewPoint(), compile);
if (n) if (n)
pat->addChild(n); pat->addChild(n);
} }
@ -487,7 +488,7 @@ namespace Terrain
mRootNode->traverseNodes(vd, viewPoint, &lodCallback); mRootNode->traverseNodes(vd, viewPoint, &lodCallback);
} }
const float cellWorldSize = ESM::getCellSize(mWorldspace); const float cellWorldSize = static_cast<float>(ESM::getCellSize(mWorldspace));
for (unsigned int i = 0; i < vd->getNumEntries(); ++i) for (unsigned int i = 0; i < vd->getNumEntries(); ++i)
{ {
@ -552,7 +553,7 @@ namespace Terrain
vd->setViewPoint(viewPoint); vd->setViewPoint(viewPoint);
vd->setActiveGrid(grid); vd->setActiveGrid(grid);
DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, cellWorldSize); DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, static_cast<int>(cellWorldSize));
mRootNode->traverseNodes(vd, viewPoint, &lodCallback); mRootNode->traverseNodes(vd, viewPoint, &lodCallback);
reporter.addTotal(vd->getNumEntries()); reporter.addTotal(vd->getNumEntries());
@ -568,14 +569,15 @@ namespace Terrain
void QuadTreeWorld::reportStats(unsigned int frameNumber, osg::Stats* stats) void QuadTreeWorld::reportStats(unsigned int frameNumber, osg::Stats* stats)
{ {
if (mCompositeMapRenderer) if (mCompositeMapRenderer)
stats->setAttribute(frameNumber, "Composite", mCompositeMapRenderer->getCompileSetSize()); stats->setAttribute(
frameNumber, "Composite", static_cast<double>(mCompositeMapRenderer->getCompileSetSize()));
} }
void QuadTreeWorld::loadCell(int x, int y) void QuadTreeWorld::loadCell(int x, int y)
{ {
// fallback behavior only for undefined cells (every other is already handled in quadtree) // fallback behavior only for undefined cells (every other is already handled in quadtree)
float dummy; float dummy;
if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5, y + 0.5), mWorldspace, dummy, dummy)) if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5f, y + 0.5f), mWorldspace, dummy, dummy))
TerrainGrid::loadCell(x, y); TerrainGrid::loadCell(x, y);
else else
World::loadCell(x, y); World::loadCell(x, y);
@ -585,7 +587,7 @@ namespace Terrain
{ {
// fallback behavior only for undefined cells (every other is already handled in quadtree) // fallback behavior only for undefined cells (every other is already handled in quadtree)
float dummy; float dummy;
if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5, y + 0.5), mWorldspace, dummy, dummy)) if (mChunkManager && !mStorage->getMinMaxHeights(1, osg::Vec2f(x + 0.5f, y + 0.5f), mWorldspace, dummy, dummy))
TerrainGrid::unloadCell(x, y); TerrainGrid::unloadCell(x, y);
else else
World::unloadCell(x, y); World::unloadCell(x, y);

View file

@ -59,7 +59,7 @@ namespace Terrain
class ChunkManager class ChunkManager
{ {
public: public:
virtual ~ChunkManager() {} virtual ~ChunkManager() = default;
ChunkManager() = default; ChunkManager() = default;
ChunkManager(ESM::RefId worldspace) ChunkManager(ESM::RefId worldspace)
: ChunkManager() : ChunkManager()

View file

@ -25,7 +25,7 @@ namespace Terrain
class Storage class Storage
{ {
public: public:
virtual ~Storage() {} virtual ~Storage() = default;
public: public:
/// Get bounds of the whole terrain in cell units /// Get bounds of the whole terrain in cell units
@ -36,8 +36,8 @@ namespace Terrain
virtual bool hasData(ESM::ExteriorCellLocation cellLocation) virtual bool hasData(ESM::ExteriorCellLocation cellLocation)
{ {
float dummy; float dummy;
return getMinMaxHeights( return getMinMaxHeights(1.f, osg::Vec2f(cellLocation.mX + 0.5f, cellLocation.mY + 0.5f),
1, osg::Vec2f(cellLocation.mX + 0.5, cellLocation.mY + 0.5), cellLocation.mWorldspace, dummy, dummy); cellLocation.mWorldspace, dummy, dummy);
} }
/// Get the minimum and maximum heights of a terrain region. /// Get the minimum and maximum heights of a terrain region.

View file

@ -12,7 +12,7 @@ namespace Terrain
TerrainDrawable::TerrainDrawable() {} TerrainDrawable::TerrainDrawable() {}
TerrainDrawable::~TerrainDrawable() {} TerrainDrawable::~TerrainDrawable() = default;
TerrainDrawable::TerrainDrawable(const TerrainDrawable& copy, const osg::CopyOp& copyop) TerrainDrawable::TerrainDrawable(const TerrainDrawable& copy, const osg::CopyOp& copyop)
: osg::Geometry(copy, copyop) : osg::Geometry(copy, copyop)
@ -37,8 +37,8 @@ namespace Terrain
inline float distance(const osg::Vec3& coord, const osg::Matrix& matrix) inline float distance(const osg::Vec3& coord, const osg::Matrix& matrix)
{ {
return -((float)coord[0] * (float)matrix(0, 2) + (float)coord[1] * (float)matrix(1, 2) return -(coord[0] * static_cast<float>(matrix(0, 2)) + coord[1] * static_cast<float>(matrix(1, 2))
+ (float)coord[2] * (float)matrix(2, 2) + matrix(3, 2)); + coord[2] * static_cast<float>(matrix(2, 2)) + static_cast<float>(matrix(3, 2)));
} }
// canot use ClusterCullingCallback::cull: viewpoint != eyepoint // canot use ClusterCullingCallback::cull: viewpoint != eyepoint