Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
/* Copyright (C) 2021 Wildfire Games.
2009-04-18 19:00:33 +02:00
* 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/>.
*/
2004-06-03 20:38:14 +02:00
# include "precompiled.h"
2004-05-30 02:46:58 +02:00
# include "ObjectEntry.h"
2011-03-13 20:22:05 +01:00
# include "graphics/Decal.h"
2012-08-07 20:21:16 +02:00
# include "graphics/Material.h"
2011-03-13 20:22:05 +01:00
# include "graphics/MaterialManager.h"
# include "graphics/MeshManager.h"
# include "graphics/Model.h"
# include "graphics/ModelDef.h"
2021-04-09 17:45:31 +02:00
# include "graphics/ModelDummy.h"
2011-03-13 20:22:05 +01:00
# include "graphics/ObjectBase.h"
# include "graphics/ObjectManager.h"
2011-04-03 21:15:15 +02:00
# include "graphics/ParticleManager.h"
2011-03-13 20:22:05 +01:00
# include "graphics/SkeletonAnim.h"
# include "graphics/TextureManager.h"
2007-05-18 02:14:26 +02:00
# include "lib/rand.h"
2011-03-13 20:22:05 +01:00
# include "ps/CLogger.h"
# include "ps/Game.h"
# include "ps/World.h"
# include "renderer/Renderer.h"
2013-07-12 00:53:31 +02:00
# include "simulation2/Simulation2.h"
2004-12-31 00:01:09 +01:00
2005-05-18 07:32:09 +02:00
# include <sstream>
2004-08-15 22:57:31 +02:00
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
CObjectEntry : : CObjectEntry ( const std : : shared_ptr < CObjectBase > & base , CSimulation2 & simulation ) :
2013-07-12 00:53:31 +02:00
m_Base ( base ) , m_Color ( 1.0f , 1.0f , 1.0f , 1.0f ) , m_Model ( NULL ) , m_Outdated ( false ) , m_Simulation ( simulation )
2004-05-30 02:46:58 +02:00
{
}
CObjectEntry : : ~ CObjectEntry ( )
{
2020-12-31 15:27:02 +01:00
for ( const std : : pair < const CStr , CSkeletonAnim * > & anim : m_Animations )
2015-07-29 03:07:23 +02:00
delete anim . second ;
2004-05-30 02:46:58 +02:00
delete m_Model ;
}
2005-07-03 03:37:49 +02:00
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
bool CObjectEntry : : BuildVariation ( const std : : vector < const std : : set < CStr > * > & completeSelections ,
2007-01-08 02:56:46 +01:00
const std : : vector < u8 > & variationKey ,
CObjectManager & objectManager )
2006-03-17 04:59:49 +01:00
{
2006-04-14 05:14:43 +02:00
CObjectBase : : Variation variation = m_Base - > BuildVariation ( variationKey ) ;
2004-05-30 02:46:58 +02:00
2005-04-03 07:02:00 +02:00
// Copy the chosen data onto this model:
2012-07-24 00:49:46 +02:00
for ( std : : multimap < CStr , CObjectBase : : Samp > : : iterator it = variation . samplers . begin ( ) ; it ! = variation . samplers . end ( ) ; + + it )
m_Samplers . push_back ( it - > second ) ;
2016-11-23 15:09:58 +01:00
2006-04-14 05:14:43 +02:00
m_ModelName = variation . model ;
2005-04-03 07:02:00 +02:00
2007-02-01 15:46:14 +01:00
if ( ! variation . color . empty ( ) )
2005-04-07 06:29:07 +02:00
{
std : : stringstream str ;
2006-04-14 05:14:43 +02:00
str < < variation . color ;
2005-04-07 06:29:07 +02:00
int r , g , b ;
if ( ! ( str > > r > > g > > b ) ) // Any trailing data is ignored
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
LOGERROR ( " Actor '%s' has invalid RGB color '%s' " , m_Base - > GetIdentifier ( ) , variation . color ) ;
2005-04-07 06:29:07 +02:00
else
m_Color = CColor ( r / 255.0f , g / 255.0f , b / 255.0f , 1.0f ) ;
}
2021-04-09 17:45:31 +02:00
if ( variation . model . empty ( ) )
{
m_Model = new CModelDummy ( ) ;
return true ;
}
2011-03-13 20:22:05 +01:00
if ( variation . decal . m_SizeX & & variation . decal . m_SizeZ )
{
2012-08-07 20:21:16 +02:00
CMaterial material = g_Renderer . GetMaterialManager ( ) . LoadMaterial ( m_Base - > m_Material ) ;
2016-11-23 15:09:58 +01:00
2016-01-13 01:42:55 +01:00
for ( const CObjectBase : : Samp & samp : m_Samplers )
2012-07-24 00:49:46 +02:00
{
2016-01-13 01:42:55 +01:00
CTextureProperties textureProps ( samp . m_SamplerFile ) ;
2012-08-07 20:21:16 +02:00
textureProps . SetWrap ( GL_CLAMP_TO_BORDER ) ;
CTexturePtr texture = g_Renderer . GetTextureManager ( ) . CreateTexture ( textureProps ) ;
// TODO: Should check which renderpath is selected and only preload the necessary textures.
2016-11-23 14:02:58 +01:00
texture - > Prefetch ( ) ;
2016-01-13 01:42:55 +01:00
material . AddSampler ( CMaterial : : TextureSampler ( samp . m_SamplerName , texture ) ) ;
2012-07-24 00:49:46 +02:00
}
2012-08-07 20:21:16 +02:00
SDecal decal ( material ,
2011-03-13 20:22:05 +01:00
variation . decal . m_SizeX , variation . decal . m_SizeZ ,
variation . decal . m_Angle , variation . decal . m_OffsetX , variation . decal . m_OffsetZ ,
m_Base - > m_Properties . m_FloatOnWater ) ;
2011-04-05 22:32:03 +02:00
m_Model = new CModelDecal ( objectManager . GetTerrain ( ) , decal ) ;
2011-03-13 20:22:05 +01:00
return true ;
}
2011-04-03 21:15:15 +02:00
if ( ! variation . particles . empty ( ) )
{
m_Model = new CModelParticleEmitter ( g_Renderer . GetParticleManager ( ) . LoadEmitterType ( variation . particles ) ) ;
return true ;
}
2005-05-21 03:40:32 +02:00
std : : vector < CObjectBase : : Prop > props ;
2005-04-03 07:02:00 +02:00
2009-02-18 11:36:27 +01:00
for ( std : : multimap < CStr , CObjectBase : : Prop > : : iterator it = variation . props . begin ( ) ; it ! = variation . props . end ( ) ; + + it )
2005-05-21 03:40:32 +02:00
props . push_back ( it - > second ) ;
2005-04-03 07:02:00 +02:00
// Build the model:
2004-12-12 19:40:00 +01:00
// try and create a model
2007-01-08 02:56:46 +01:00
CModelDefPtr modeldef ( objectManager . GetMeshManager ( ) . GetMesh ( m_ModelName ) ) ;
2004-12-12 19:40:00 +01:00
if ( ! modeldef )
{
2015-01-22 21:36:24 +01:00
LOGERROR ( " CObjectEntry::BuildVariation(): Model %s failed to load " , m_ModelName . string8 ( ) ) ;
2004-05-30 02:46:58 +02:00
return false ;
}
2004-06-07 22:03:10 +02:00
2016-11-23 14:02:58 +01:00
// delete old model, create new
2013-07-12 00:53:31 +02:00
CModel * model = new CModel ( objectManager . GetSkeletonAnimManager ( ) , m_Simulation ) ;
2004-10-06 20:46:33 +02:00
delete m_Model ;
2011-03-13 20:22:05 +01:00
m_Model = model ;
2012-04-03 20:44:46 +02:00
model - > SetMaterial ( g_Renderer . GetMaterialManager ( ) . LoadMaterial ( m_Base - > m_Material ) ) ;
2012-04-08 17:55:06 +02:00
model - > GetMaterial ( ) . AddStaticUniform ( " objectColor " , CVector4D ( m_Color . r , m_Color . g , m_Color . b , m_Color . a ) ) ;
2011-03-13 20:22:05 +01:00
model - > InitModel ( modeldef ) ;
2016-11-23 15:09:58 +01:00
2015-07-27 03:08:29 +02:00
if ( m_Samplers . empty ( ) )
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
LOGERROR ( " Actor '%s' has no textures. " , m_Base - > GetIdentifier ( ) ) ;
2016-11-23 15:09:58 +01:00
2016-01-13 01:42:55 +01:00
for ( const CObjectBase : : Samp & samp : m_Samplers )
2012-07-24 00:49:46 +02:00
{
2015-03-15 12:37:26 +01:00
CTextureProperties textureProps ( samp . m_SamplerFile ) ;
2012-07-24 00:49:46 +02:00
textureProps . SetWrap ( GL_CLAMP_TO_EDGE ) ;
CTexturePtr texture = g_Renderer . GetTextureManager ( ) . CreateTexture ( textureProps ) ;
2016-11-23 14:02:58 +01:00
// if we've loaded this model we're probably going to render it soon, so prefetch its texture.
2012-07-24 00:49:46 +02:00
// All textures are prefetched even in the fixed pipeline, including the normal maps etc.
// TODO: Should check which renderpath is selected and only preload the necessary textures.
2016-11-23 14:02:58 +01:00
texture - > Prefetch ( ) ;
2015-03-15 12:37:26 +01:00
model - > GetMaterial ( ) . AddSampler ( CMaterial : : TextureSampler ( samp . m_SamplerName , texture ) ) ;
2012-07-24 00:49:46 +02:00
}
2010-09-10 23:02:10 +02:00
2016-01-13 01:42:55 +01:00
for ( const CStrIntern & requSampName : model - > GetMaterial ( ) . GetRequiredSampler ( ) )
2015-03-15 12:37:26 +01:00
{
if ( std : : find_if ( m_Samplers . begin ( ) , m_Samplers . end ( ) ,
2016-01-13 01:42:55 +01:00
[ & ] ( const CObjectBase : : Samp & sampler ) { return sampler . m_SamplerName = = requSampName ; } ) = = m_Samplers . end ( ) )
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
LOGERROR ( " Actor %s: required texture sampler %s not found (material %s) " , m_Base - > GetIdentifier ( ) , requSampName . string ( ) . c_str ( ) , m_Base - > m_Material . string8 ( ) . c_str ( ) ) ;
2015-03-15 12:37:26 +01:00
}
2016-11-23 15:09:58 +01:00
2004-05-30 02:46:58 +02:00
// calculate initial object space bounds, based on vertex positions
2011-11-25 07:36:13 +01:00
model - > CalcStaticObjectBounds ( ) ;
2004-06-07 22:03:10 +02:00
2005-05-21 03:40:32 +02:00
// load the animations
2006-04-14 05:14:43 +02:00
for ( std : : multimap < CStr , CObjectBase : : Anim > : : iterator it = variation . anims . begin ( ) ; it ! = variation . anims . end ( ) ; + + it )
2004-05-30 02:46:58 +02:00
{
2005-05-21 03:40:32 +02:00
CStr name = it - > first . LowerCase ( ) ;
2004-05-30 02:46:58 +02:00
2016-06-01 09:21:50 +02:00
if ( it - > second . m_FileName . empty ( ) )
continue ;
CSkeletonAnim * anim = model - > BuildAnimation (
it - > second . m_FileName ,
name ,
2016-12-09 00:16:54 +01:00
it - > second . m_ID ,
2016-06-01 09:21:50 +02:00
it - > second . m_Frequency ,
it - > second . m_Speed ,
it - > second . m_ActionPos ,
it - > second . m_ActionPos2 ,
it - > second . m_SoundPos ) ;
if ( anim )
m_Animations . insert ( std : : make_pair ( name , anim ) ) ;
2004-05-30 02:46:58 +02:00
}
2005-05-21 03:40:32 +02:00
2006-03-17 04:59:49 +01:00
// ensure there's always an idle animation
if ( m_Animations . find ( " idle " ) = = m_Animations . end ( ) )
{
CSkeletonAnim * anim = new CSkeletonAnim ( ) ;
anim - > m_Name = " idle " ;
2016-12-09 00:16:54 +01:00
anim - > m_ID = " " ;
2006-03-17 04:59:49 +01:00
anim - > m_AnimDef = NULL ;
2016-06-01 09:21:50 +02:00
anim - > m_Frequency = 0 ;
2006-03-17 04:59:49 +01:00
anim - > m_Speed = 0.f ;
anim - > m_ActionPos = 0.f ;
anim - > m_ActionPos2 = 0.f ;
2013-07-02 13:44:46 +02:00
anim - > m_SoundPos = 0.f ;
2006-03-17 04:59:49 +01:00
m_Animations . insert ( std : : make_pair ( " idle " , anim ) ) ;
// Ignore errors, since they're probably saying this is a non-animated model
2011-03-13 20:22:05 +01:00
model - > SetAnimation ( anim ) ;
2006-03-17 04:59:49 +01:00
}
else
{
// start up idling
2011-03-13 20:22:05 +01:00
if ( ! model - > SetAnimation ( GetRandomAnimation ( " idle " ) ) )
2015-01-22 21:36:24 +01:00
LOGERROR ( " Failed to set idle animation in model \" %s \" " , m_ModelName . string8 ( ) ) ;
2006-03-17 04:59:49 +01:00
}
2004-06-07 22:03:10 +02:00
2004-05-30 02:46:58 +02:00
// build props - TODO, RC - need to fix up bounds here
2005-04-03 07:02:00 +02:00
// TODO: Make sure random variations get handled correctly when a prop fails
2016-01-13 01:42:55 +01:00
for ( const CObjectBase : : Prop & prop : props )
2005-04-03 07:02:00 +02:00
{
2010-04-17 13:34:40 +02:00
// Pluck out the special attachpoint 'projectile'
if ( prop . m_PropPointName = = " projectile " )
{
2011-03-21 18:53:13 +01:00
m_ProjectileModelName = prop . m_ModelName ;
2010-04-17 13:34:40 +02:00
continue ;
}
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
CObjectEntry * oe = nullptr ;
if ( CActorDef * actorDef = objectManager . FindActorDef ( prop . m_ModelName . c_str ( ) ) ; actorDef )
oe = objectManager . FindObjectVariation ( actorDef - > GetBase ( m_Base - > m_QualityLevel ) , completeSelections ) ;
2005-05-10 09:13:25 +02:00
if ( ! oe )
2005-04-03 07:02:00 +02:00
{
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
LOGERROR ( " Failed to build prop model \" %s \" on actor \" %s \" " , utf8_from_wstring ( prop . m_ModelName ) , m_Base - > GetIdentifier ( ) ) ;
2005-05-10 09:13:25 +02:00
continue ;
}
2010-06-05 02:49:14 +02:00
// If we don't have a projectile but this prop does (e.g. it's our rider), then
// use that as our projectile too
if ( m_ProjectileModelName . empty ( ) & & ! oe - > m_ProjectileModelName . empty ( ) )
m_ProjectileModelName = oe - > m_ProjectileModelName ;
CStr ppn = prop . m_PropPointName ;
bool isAmmo = false ;
// Handle the special attachpoint 'loaded-<proppoint>'
if ( ppn . Find ( " loaded- " ) = = 0 )
2005-05-10 09:13:25 +02:00
{
2010-06-05 02:49:14 +02:00
ppn = prop . m_PropPointName . substr ( 7 ) ;
isAmmo = true ;
2005-05-10 09:13:25 +02:00
}
2010-06-05 02:49:14 +02:00
2010-11-20 21:16:06 +01:00
const SPropPoint * proppoint = modeldef - > FindPropPoint ( ppn . c_str ( ) ) ;
2010-06-05 02:49:14 +02:00
if ( proppoint )
2005-05-10 09:13:25 +02:00
{
2011-03-13 20:22:05 +01:00
CModelAbstract * propmodel = oe - > m_Model - > Clone ( ) ;
2010-06-05 02:49:14 +02:00
if ( isAmmo )
2011-03-13 20:22:05 +01:00
model - > AddAmmoProp ( proppoint , propmodel , oe ) ;
2005-04-03 07:02:00 +02:00
else
2014-01-04 11:41:32 +01:00
model - > AddProp ( proppoint , propmodel , oe , prop . m_minHeight , prop . m_maxHeight , prop . m_selectable ) ;
2011-03-13 20:22:05 +01:00
if ( propmodel - > ToCModel ( ) )
propmodel - > ToCModel ( ) - > SetAnimation ( oe - > GetRandomAnimation ( " idle " ) ) ;
2004-05-30 02:46:58 +02:00
}
2010-06-05 02:49:14 +02:00
else
Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.
Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
- such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
- such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).
Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.
Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.
Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 09:22:24 +02:00
LOGERROR ( " Failed to find matching prop point called \" %s \" in model \" %s \" for actor \" %s \" " , ppn , m_ModelName . string8 ( ) , m_Base - > GetIdentifier ( ) ) ;
2004-05-30 02:46:58 +02:00
}
2020-12-31 17:17:58 +01:00
// Setup flags.
2005-04-03 07:02:00 +02:00
if ( m_Base - > m_Properties . m_CastShadows )
{
2020-12-31 17:17:58 +01:00
model - > SetFlags ( model - > GetFlags ( ) | MODELFLAG_CASTSHADOWS ) ;
}
if ( m_Base - > m_Properties . m_FloatOnWater )
{
model - > SetFlags ( model - > GetFlags ( ) | MODELFLAG_FLOATONWATER ) ;
2004-10-06 20:46:33 +02:00
}
2004-05-30 02:46:58 +02:00
return true ;
}
2016-12-09 00:16:54 +01:00
CSkeletonAnim * CObjectEntry : : GetRandomAnimation ( const CStr & animationName , const CStr & ID ) const
2005-03-22 18:09:36 +01:00
{
2016-12-09 00:16:54 +01:00
std : : vector < CSkeletonAnim * > anims = GetAnimations ( animationName , ID ) ;
2016-05-30 13:53:19 +02:00
int totalFreq = 0 ;
for ( CSkeletonAnim * anim : anims )
totalFreq + = anim - > m_Frequency ;
2010-06-05 02:49:14 +02:00
2016-05-30 13:53:19 +02:00
if ( totalFreq = = 0 )
return anims [ rand ( 0 , anims . size ( ) ) ] ;
int r = rand ( 0 , totalFreq ) ;
for ( CSkeletonAnim * anim : anims )
{
r - = anim - > m_Frequency ;
if ( r < 0 )
return anim ;
}
return NULL ;
2010-06-05 02:49:14 +02:00
}
2016-12-09 00:16:54 +01:00
std : : vector < CSkeletonAnim * > CObjectEntry : : GetAnimations ( const CStr & animationName , const CStr & ID ) const
2010-06-05 02:49:14 +02:00
{
std : : vector < CSkeletonAnim * > anims ;
SkeletonAnimMap : : const_iterator lower = m_Animations . lower_bound ( animationName ) ;
SkeletonAnimMap : : const_iterator upper = m_Animations . upper_bound ( animationName ) ;
2016-05-30 13:53:19 +02:00
2010-06-05 02:49:14 +02:00
for ( SkeletonAnimMap : : const_iterator it = lower ; it ! = upper ; + + it )
2016-12-09 00:16:54 +01:00
{
if ( ID . empty ( ) | | it - > second - > m_ID = = ID )
anims . push_back ( it - > second ) ;
}
2016-05-30 13:53:19 +02:00
2016-05-30 19:05:39 +02:00
if ( anims . empty ( ) )
2016-05-30 13:53:19 +02:00
{
2016-05-30 19:05:39 +02:00
lower = m_Animations . lower_bound ( " idle " ) ;
upper = m_Animations . upper_bound ( " idle " ) ;
2016-05-30 13:53:19 +02:00
for ( SkeletonAnimMap : : const_iterator it = lower ; it ! = upper ; + + it )
anims . push_back ( it - > second ) ;
}
2016-05-30 19:05:39 +02:00
ENSURE ( ! anims . empty ( ) ) ;
2010-06-05 02:49:14 +02:00
return anims ;
2004-10-06 20:46:33 +02:00
}