Fix yield_ms().
This fixes https://code.google.com/p/singularity-viewer/issues/detail?id=714 The problem was a typo in AIStateMachine::sleep, >= should have been <= which caused a state machine that uses yield_ms() to never run anymore when next run it already should have run again. AIFilePicker is the only state machine that currently uses yield_ms and I hadn't spotted this because I don't have plugin messages on by default which made my viewer just that much faster that it the yield never expired the first run already (causing it to expire immediately). The rest of the changes in this commit are just minor improvements / conformation to the EXAMPLE_CODE in aistatemachine.cpp.
This commit is contained in:
@@ -296,7 +296,7 @@ class AIStateMachine : public LLThreadSafeRefCount
|
||||
return false;
|
||||
else if (mSleep < 0)
|
||||
++mSleep;
|
||||
else if ((U64)mSleep >= current_time)
|
||||
else if ((U64)mSleep <= current_time)
|
||||
mSleep = 0;
|
||||
return mSleep != 0;
|
||||
}
|
||||
|
||||
@@ -46,14 +46,6 @@
|
||||
#include "llwindowsdl.h"
|
||||
#endif
|
||||
|
||||
|
||||
enum filepicker_state_type {
|
||||
AIFilePicker_initialize_plugin = AIStateMachine::max_state,
|
||||
AIFilePicker_plugin_running,
|
||||
AIFilePicker_canceled,
|
||||
AIFilePicker_done
|
||||
};
|
||||
|
||||
char const* AIFilePicker::state_str_impl(state_type run_state) const
|
||||
{
|
||||
switch(run_state)
|
||||
@@ -63,6 +55,7 @@ char const* AIFilePicker::state_str_impl(state_type run_state) const
|
||||
AI_CASE_RETURN(AIFilePicker_canceled);
|
||||
AI_CASE_RETURN(AIFilePicker_done);
|
||||
}
|
||||
llassert(false);
|
||||
return "UNKNOWN STATE";
|
||||
}
|
||||
|
||||
@@ -361,6 +354,7 @@ void AIFilePicker::multiplex_impl(state_type run_state)
|
||||
{
|
||||
if (!plugin->isPluginRunning())
|
||||
{
|
||||
yield();
|
||||
break; // Still initializing.
|
||||
}
|
||||
|
||||
@@ -457,7 +451,7 @@ void AIFilePicker::receivePluginMessage(const LLPluginMessage &message)
|
||||
if (message_name == "canceled")
|
||||
{
|
||||
LL_DEBUGS("Plugin") << "received message \"canceled\"" << LL_ENDL;
|
||||
advance_state(AIFilePicker_canceled);
|
||||
set_state(AIFilePicker_canceled);
|
||||
}
|
||||
else if (message_name == "done")
|
||||
{
|
||||
@@ -468,7 +462,7 @@ void AIFilePicker::receivePluginMessage(const LLPluginMessage &message)
|
||||
{
|
||||
mFilenames.push_back(*filename);
|
||||
}
|
||||
advance_state(AIFilePicker_done);
|
||||
set_state(AIFilePicker_done);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -151,7 +151,21 @@ new AIFilePicker
|
||||
// Objects of this type can be reused multiple times, see
|
||||
// also the documentation of AIStateMachine.
|
||||
class AIFilePicker : public AIStateMachine {
|
||||
protected:
|
||||
// The base class of this state machine.
|
||||
typedef AIStateMachine direct_base_type;
|
||||
|
||||
enum filepicker_state_type {
|
||||
AIFilePicker_initialize_plugin = direct_base_type::max_state,
|
||||
AIFilePicker_plugin_running,
|
||||
AIFilePicker_canceled,
|
||||
AIFilePicker_done
|
||||
};
|
||||
public:
|
||||
static state_type const max_state = AIFilePicker_done + 1; // One beyond the largest state.
|
||||
|
||||
public:
|
||||
// The derived class must have a default constructor.
|
||||
AIFilePicker(void);
|
||||
|
||||
// Create a dynamically created AIFilePicker object.
|
||||
|
||||
Reference in New Issue
Block a user