commit x64 compilation from lulu cause the other branch dont seems to compile properly at home
This commit is contained in:
23
include/engine/automation/automated_property_provider.cpp
Normal file
23
include/engine/automation/automated_property_provider.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "automation/automated_property_provider.h"
|
||||
#include "math/quaternion.h"
|
||||
|
||||
using namespace GS::Automation;
|
||||
using GS::Core::MotionChannel;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool IPropertyProvider::GetProperty(MotionChannel::Type, float &)
|
||||
{ return false; }
|
||||
bool IPropertyProvider::SetProperty(MotionChannel::Type, float)
|
||||
{ return false; }
|
||||
GS::Quaternion IPropertyProvider::GetRotation() const
|
||||
{ return Quaternion(); }
|
||||
bool IPropertyProvider::SetRotation(const GS::Quaternion &)
|
||||
{ return false; }
|
||||
//------------------------------------------------------------------------------
|
||||
152
include/engine/automation/automation_player.cpp
Normal file
152
include/engine/automation/automation_player.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __PLATFORM_IOS__
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#include "automation/automation_player.h"
|
||||
#include "automation/automation_source.h"
|
||||
#include "platform_config.h"
|
||||
|
||||
using namespace GS::Automation;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Motion *Player::GetMotion(const char *id) const
|
||||
{
|
||||
ListForeachPtr(Motion *, i, motions)
|
||||
if (!String::Compare(i->name, id))
|
||||
return i;
|
||||
return NULL;
|
||||
}
|
||||
Motion *Player::GetMotionFromIndex(uint index) const
|
||||
{ return motions.ObjectAt(index); }
|
||||
bool Player::AddMotion(Motion *motion)
|
||||
{ return asbool(motions.Add(motion)); }
|
||||
void Player::RemoveMotion(Motion *motion)
|
||||
{ motions.Remove(motion); }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Source *Player::StartAutomation(Source *source, float _blend, AddSourceMode mode, float _weight)
|
||||
{
|
||||
if (!source)
|
||||
return NULL;
|
||||
|
||||
// Source blend.
|
||||
switch (mode)
|
||||
{
|
||||
case SourceSet: // Dispose of all current sources.
|
||||
ListForeachPtr(Source *, s, sources)
|
||||
s->Dispose(_blend);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Blend in source.
|
||||
source->SetWeight(_weight, _blend);
|
||||
sources.Add(source);
|
||||
|
||||
switch (source->GetType())
|
||||
{
|
||||
case Source::TypeMotion:
|
||||
source->relative = flags.IsSet(FlagRelativeMotion);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
void Player::Evaluate(const GS::Time &dt_time)
|
||||
{
|
||||
if (!sources.GetCount() || property_provider.IsNull())
|
||||
return;
|
||||
|
||||
// Allocate weight table from stack.
|
||||
weight_table = (float *)alloca(sizeof(float) * MotionChannel::Last);
|
||||
for (int n = 0; n < MotionChannel::Last; ++n)
|
||||
weight_table[n] = 0;
|
||||
|
||||
// Update sources.
|
||||
ListForeachPtr(Source *, s, sources)
|
||||
{
|
||||
s->Update(dt_time);
|
||||
if (s->CanDispose())
|
||||
sources.Remove(s);
|
||||
}
|
||||
|
||||
// Mix rotation.
|
||||
float w = 0;
|
||||
Quaternion q, source_q = property_provider->GetRotation();
|
||||
|
||||
ListForeachPtr(Source *, s, sources)
|
||||
if (s->GetWeight() > 0.01)
|
||||
if (s->EvaluateRotation(source_q))
|
||||
{
|
||||
if (w > 0.01)
|
||||
q = Quaternion::Slerp(w / (w + s->GetWeight()), source_q, q);
|
||||
else q = source_q;
|
||||
|
||||
w += s->GetWeight();
|
||||
}
|
||||
|
||||
if (w > 0)
|
||||
property_provider->SetRotation(q);
|
||||
|
||||
// Mix sources.
|
||||
ListForeachPtr(Source *, s, sources)
|
||||
if (s->GetWeight())
|
||||
s->Evaluate(*this);
|
||||
|
||||
// Drop weight table.
|
||||
weight_table = NULL;
|
||||
}
|
||||
void Player::BlendAutomatedProperty(MotionChannel::Type type, float _v, float _w)
|
||||
{
|
||||
if (!_w || !weight_table)
|
||||
return;
|
||||
|
||||
float v, *w = &weight_table[(uint)type];
|
||||
|
||||
if (property_provider->GetProperty(type, v))
|
||||
{
|
||||
v = (v * *w + _v * _w) / (*w + _w);
|
||||
*w += _w;
|
||||
property_provider->SetProperty(type, v);
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Player::IsAutomated() const
|
||||
{ return asbool(sources.GetCount()); }
|
||||
bool Player::IsAutomationDone() const
|
||||
{
|
||||
ListForeachPtr(Source *, s, GetSourceList())
|
||||
if (!s->IsDone())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool Player::GetAutomationActive() const
|
||||
{ return active; }
|
||||
void Player::SetAutomationActive(bool _active)
|
||||
{ active = _active; }
|
||||
void Player::DisposeAutomationSources()
|
||||
{ sources.Clear(); }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Player::Player()
|
||||
{
|
||||
active = true;
|
||||
weight_table = NULL;
|
||||
}
|
||||
Player::~Player()
|
||||
{
|
||||
DisposeAutomationSources();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
60
include/engine/automation/automation_player_nml.cpp
Normal file
60
include/engine/automation/automation_player_nml.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "automation/automation_player.h"
|
||||
#include "motion/motion.h"
|
||||
#include "memory/memory.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::Automation;
|
||||
using namespace GS::NML;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Player::FromMetaTag(Tag &tag)
|
||||
{
|
||||
if (tag.name != "MotionPlayer")
|
||||
__ERR__(__LOG_E__ << "Could not parse motion player, incorrect root tag (" << tag.name << ").\n", false)
|
||||
|
||||
NMLTagForeach(pt, tag)
|
||||
{
|
||||
if (pt->name == "Motions")
|
||||
{
|
||||
NMLTagForeach(pm, *pt)
|
||||
if (pm->name == "Motion")
|
||||
{
|
||||
if (Motion *m = new Motion)
|
||||
{
|
||||
m->FromMetaTag(*pm);
|
||||
motions.Add(m);
|
||||
}
|
||||
}
|
||||
else __LOG_W__ << "Unknown tag '" << pm->name << "' in <Motions>.\n";
|
||||
}
|
||||
#if 1
|
||||
else if (pt->name == "Flag")
|
||||
;
|
||||
#endif
|
||||
else __LOG_W__ << "Unknown tag '" << pt->name << "' in <MotionPlayer>.\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Tag *Player::AsMetaTag()
|
||||
{
|
||||
Tag *root = new Tag("MotionPlayer");
|
||||
if (!root)
|
||||
__ERR__(__LOG_E__ << "Could not create root tag to serialize.\n", NULL)
|
||||
|
||||
// Dump all motions.
|
||||
if (Tag *mtag = root->AddChild("Motions"))
|
||||
ListForeachPtr(Motion *, m, motions)
|
||||
mtag->AddChild(m->AsMetaTag());
|
||||
|
||||
if (!root->GetChildCount())
|
||||
_safe_delete(root);
|
||||
return root;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
81
include/engine/automation/automation_source.cpp
Normal file
81
include/engine/automation/automation_source.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "automation/automation_source.h"
|
||||
|
||||
using namespace GS::Automation;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Source::Dispose(float blend)
|
||||
{
|
||||
if (!dispose)
|
||||
{
|
||||
SetWeight(0, blend);
|
||||
dispose = true;
|
||||
}
|
||||
}
|
||||
bool Source::CanDispose() const
|
||||
{ return asbool(dispose && (weight == 0)); }
|
||||
void Source::Update(const GS::Time &dt_time)
|
||||
{
|
||||
const Time scaled_dt(dt_time * time_scale);
|
||||
|
||||
// Update weight.
|
||||
if (weight_step)
|
||||
{
|
||||
weight += weight_step * dt_time.toSec();
|
||||
|
||||
if (weight_step > 0)
|
||||
{
|
||||
if (weight > weight_target)
|
||||
{
|
||||
weight = weight_target;
|
||||
weight_step = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weight < weight_target)
|
||||
{
|
||||
weight = weight_target;
|
||||
weight_step = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
time += scaled_dt;
|
||||
}
|
||||
void Source::SetWeight(float _weight, float _blend)
|
||||
{
|
||||
if (_weight < 0)
|
||||
_weight = 0;
|
||||
if (_blend < 0)
|
||||
_blend = 0;
|
||||
|
||||
if (_blend)
|
||||
{
|
||||
weight_target = _weight;
|
||||
weight_step = (_weight - weight) / _blend;
|
||||
}
|
||||
else
|
||||
{
|
||||
weight = _weight;
|
||||
weight_target = _weight;
|
||||
weight_step = 0;
|
||||
}
|
||||
}
|
||||
Source::Source()
|
||||
{
|
||||
weight = 0;
|
||||
weight_target = 1;
|
||||
weight_step = 0;
|
||||
|
||||
time_scale = 1;
|
||||
|
||||
dispose = false;
|
||||
}
|
||||
Source::~Source() {}
|
||||
//------------------------------------------------------------------------------
|
||||
41
include/engine/automation/automation_source_group.cpp
Normal file
41
include/engine/automation/automation_source_group.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "automation/automation_source_group.h"
|
||||
|
||||
using namespace GS::Automation;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SourceGroup::Dispose(float blend)
|
||||
{ ListForeachPtr(Source *, s, source_list)
|
||||
s->Dispose(blend); }
|
||||
void SourceGroup::SetTime(const GS::Time &t)
|
||||
{ ListForeachPtr(Source *, s, source_list)
|
||||
s->time = t; }
|
||||
void SourceGroup::SetTimeScale(float scale)
|
||||
{ ListForeachPtr(Source *, s, source_list)
|
||||
s->time_scale = scale; }
|
||||
void SourceGroup::SetWeight(float weight, float blend)
|
||||
{ ListForeachPtr(Source *, s, source_list)
|
||||
s->SetWeight(weight, blend); }
|
||||
void SourceGroup::SetRelative(bool relative)
|
||||
{ ListForeachPtr(Source *, s, source_list)
|
||||
s->relative = relative; }
|
||||
void SourceGroup::SetLoop(const GS::Time &start, const GS::Time &end)
|
||||
{ ListForeachPtr(Source *, s, source_list)
|
||||
s->SetLoop(start, end); }
|
||||
void SourceGroup::SetLoopMode(GS::Curve::LoopMode mode)
|
||||
{ ListForeachPtr(Source *, s, source_list)
|
||||
s->SetLoopMode(mode); }
|
||||
bool SourceGroup::IsDone() const
|
||||
{
|
||||
ListForeachPtr(Source *, s, source_list)
|
||||
if (!s->IsDone())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user