diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-07-26 20:14:16 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-07-26 20:14:16 +0000 |
| commit | e260085a116271e49c3d1d835eac1df70424f4c6 (patch) | |
| tree | f08772ebbed902c7e482e8fc58122bebe984dec0 /pokebattle/ATBTimer.cpp | |
| parent | 96058e330b9a535ec3aecc40cfbd2fa74b791cd8 (diff) | |
[FIX] Fraction won't reduce whenever possible
[FIX] ScriptWidget updates cleaner now
[FIX] Player is now a Containment (Team is for storing the data; Player is an interface for battling)
[FIX] QtConcurrent framework used to parallelize ATB timer and requesting actions
[FIX] ActionQueue now uses a QMutexLocker (slimmer code)
[FIX] Various fixes with arenas
[ADD] pokebattle/Player.cpp
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@229 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokebattle/ATBTimer.cpp')
| -rw-r--r-- | pokebattle/ATBTimer.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/pokebattle/ATBTimer.cpp b/pokebattle/ATBTimer.cpp index a72b9819..d2f42ce2 100644 --- a/pokebattle/ATBTimer.cpp +++ b/pokebattle/ATBTimer.cpp @@ -22,11 +22,15 @@ #include "ATBArena.h" // Qt includes -#include <QtCore/QtConcurrentMap> #include <QtCore/QtConcurrentFilter> +#include <QtCore/QtConcurrentMap> #include <QtCore/QFuture> +#include <QtCore/QMultiMap> #include <QtCore/QTimer> +// STL includes +#include <functional> + Pokebattle::ATBTimer::ATBTimer(ATBArena* arena, ActionQueue& actions) : QThread(arena), m_arena(arena), @@ -38,14 +42,31 @@ Pokebattle::ATBTimer::ATBTimer(ATBArena* arena, ActionQueue& actions) : void Pokebattle::ATBTimer::update() { - // TODO: update times with mapping + const QList<TeamMember*> active = m_timeStates.keys(); + QtConcurrent::blockingMap(active, std::bind1st(std::mem_fun(&Pokebattle::ATBTimer::increaseMeter), this)); // TODO: adjust max time if needed - // TODO: filter out those not above the threshold and push into the queue if needed and reset its timer + QList<TeamMember*> overflow = QtConcurrent::blockingFiltered(active, std::bind1st(std::mem_fun(&Pokebattle::ATBTimer::isOverflowed), this)); + QMultiMap<double, TeamMember*> sorter; + foreach (TeamMember* teamMember, overflow) + sorter.insert(m_timeStates[teamMember], teamMember); + overflow = sorter.values(); + foreach(TeamMember* teamMember, overflow) + m_actions.enqueue(requestDecision(teamMember)); } void Pokebattle::ATBTimer::run() { m_timer->start(50); - // TODO: Anything else to do here? exec(); } + +void Pokebattle::ATBTimer::increaseMeter(const TeamMember* teamMember) +{ + // TODO: tweak this(?) + m_timeStates[const_cast<TeamMember*>(teamMember)] += teamMember->statValue(Pokemod::ST_Speed) / 10; +} + +bool Pokebattle::ATBTimer::isOverflowed(const TeamMember* teamMember) const +{ + return m_threshold < m_timeStates[const_cast<TeamMember*>(teamMember)]; +} |
