Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0!A.D. | * This file is part of 0!A.D. | ||||
* | * | ||||
* 0!A.D. is free software: you can redistribute it and/or modify | * 0!A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0!A.D. is distributed in the hope that it will be useful, | * 0!A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | static CVector3D GetUnitPos(const Position& pos, bool floating) | ||||
static CVector3D vec; | static CVector3D vec; | ||||
vec = pos.GetWorldSpace(vec, floating); // if msg->pos is 'Unchanged', use the previous pos | vec = pos.GetWorldSpace(vec, floating); // if msg->pos is 'Unchanged', use the previous pos | ||||
// Clamp the position to the edges of the world: | // Clamp the position to the edges of the world: | ||||
// Use 'Clamp' with a value slightly less than the width, so that converting | // Use 'Clamp' with a value slightly less than the width, so that converting | ||||
// to integer (rounding towards zero) will put it on the tile inside the edge | // to integer (rounding towards zero) will put it on the tile inside the edge | ||||
// instead of just outside | // instead of just outside | ||||
float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; | const float mapWidth = (g_Game->GetWorld()->GetTerrain().GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; | ||||
float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON | float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON | ||||
float xOnMap = Clamp(vec.X, 0.f, mapWidth * (1.f - delta)); | float xOnMap = Clamp(vec.X, 0.f, mapWidth * (1.f - delta)); | ||||
float zOnMap = Clamp(vec.Z, 0.f, mapWidth * (1.f - delta)); | float zOnMap = Clamp(vec.Z, 0.f, mapWidth * (1.f - delta)); | ||||
// Don't waste time with GetExactGroundLevel unless we've changed | // Don't waste time with GetExactGroundLevel unless we've changed | ||||
if (xOnMap != vec.X || zOnMap != vec.Z) | if (xOnMap != vec.X || zOnMap != vec.Z) | ||||
{ | { | ||||
vec.X = xOnMap; | vec.X = xOnMap; | ||||
vec.Z = zOnMap; | vec.Z = zOnMap; | ||||
vec.Y = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(xOnMap, zOnMap); | vec.Y = g_Game->GetWorld()->GetTerrain().GetExactGroundLevel(xOnMap, zOnMap); | ||||
} | } | ||||
return vec; | return vec; | ||||
} | } | ||||
QUERYHANDLER(GetCurrentSelection) | QUERYHANDLER(GetCurrentSelection) | ||||
{ | { | ||||
msg->ids = g_Selection; | msg->ids = g_Selection; | ||||
▲ Show 20 Lines • Show All 729 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator