1
0
forked from 0ad/0ad
0ad/source/simulation2/components/ICmpUnitRenderer.h
Yves 8e30410109 Improve PickEntitiesAtPoint
First, do a ray intersection test with the bounding-sphere for all
entities on the map and then check the more detailed selection shape for
the remaining candidates. Do checks that require component lookups after
the ray intersection tests because these are relatively expensive.
The old method for figuring out which entities are below the mouse
cursor was incorrect because it does a 2D check to filter out the first
candidates which can lead to incorrect results with lower camera angles
and high buildings or buildings with a large footprint. Such problems
were avoided with quite a large radius for this 2D test and resulted in
a large number of candiate entities after this first test (200-500).
Also rename PickEntitiesAtPoint to PickEntityAtPoint and make it return
only one (the closest) match.

I've tested performance with the tracelogger by starting a map and then
moving the mouse in circles for one minute. The results were relatively
stable. I've compared the total time percentage of input.js:836, which
spends nearly all of the time in PickEntityAtPoint.
Ardennes Forest - Normal size:       Original: 41.46%    Patched: 31.6%
Ardennes Forest - Giant size:        Original: 40.59%    Patched: 51.55%

As we see, it's faster on normal map sizes but slower on giant maps with
a lot of entities.
This approach can be further improved with some kind of spatial
subdivision for the culling (like an octree), which would help the unit
renderer too. This way it should be possible to make it faster (and
still correct) on all map sizes and with a large total numbers of
entities.

This was SVN commit r16098.
2015-01-01 23:05:26 +00:00

84 lines
2.4 KiB
C++

/* Copyright (C) 2014 Wildfire Games.
* This file is part of 0 A.D.
*
* 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
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_ICMPMODELRENDERER
#define INCLUDED_ICMPMODELRENDERER
#include "simulation2/system/Interface.h"
class CUnit;
class CBoundingSphere;
class CVector3D;
class ICmpUnitRenderer : public IComponent
{
public:
/**
* External identifiers for models.
* (This is a struct rather than a raw u32 for type-safety.)
*/
struct tag_t
{
tag_t() : n(0) {}
explicit tag_t(u32 n) : n(n) {}
bool valid() { return n != 0; }
u32 n;
};
enum
{
ACTOR_ONLY = 1 << 0,
VISIBLE_IN_ATLAS_ONLY = 1 << 1,
};
virtual tag_t AddUnit(CEntityHandle entity, CUnit* unit, const CBoundingSphere& boundsApprox, int flags) = 0;
virtual void RemoveUnit(tag_t tag) = 0;
virtual void UpdateUnit(tag_t tag, CUnit* unit, const CBoundingSphere& boundsApprox) = 0;
virtual void UpdateUnitPos(tag_t tag, bool inWorld, const CVector3D& pos0, const CVector3D& pos1) = 0;
/**
* Return a list of visual entities along with their center point.
* Visual means they have an associated actor and a visual component,
* but they could still be hiden in the fog of war for a specific player,
* for example.
* NOTE: It's generally faster to do a lot of ray intersection tests than
* querying a lot of entities for component interfaces and doing these types
* of tests first.
*/
virtual void PickAllEntitiesAtPoint(std::vector<std::pair<CEntityHandle, CVector3D> >& outEntities,
const CVector3D& origin, const CVector3D& dir,
bool allowEditorSelectables) = 0;
/**
* Returns the frame offset from the last Interpolate message.
*/
virtual float GetFrameOffset() = 0;
/**
* Toggle the rendering of debug info.
*/
virtual void SetDebugOverlay(bool enabled) = 0;
DECLARE_INTERFACE_TYPE(UnitRenderer)
};
#endif // INCLUDED_ICMPMODELRENDERER