Skip to content

Commit

Permalink
Added 'sequence' option for plugins, to control sequencing
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Feb 24, 2013
1 parent 0ff3058 commit df9c170
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ProcessPreviousLine.cpp
Expand Up @@ -584,6 +584,7 @@ assemble the full text of the original line.
// timer t ("Process all triggers");

m_CurrentPlugin = NULL;
// allow trigger evaluation for the moment
m_iStopTriggerEvaluation = eKeepEvaluatingTriggers;

// do main triggers
Expand All @@ -599,13 +600,14 @@ assemble the full text of the original line.
mapDeferredScripts,
mapOneShotItems);

// do plugins
// do plugins (stop if one stops trigger evaluation, or if it was stopped by the main world triggers)
for (PluginListIterator pit = m_PluginList.begin ();
pit != m_PluginList.end () &&
m_iStopTriggerEvaluation != eStopEvaluatingTriggersInAllPlugins;
++pit)
{
m_CurrentPlugin = *pit;
// allow trigger evaluation for the moment (ie. the next plugin)
m_iStopTriggerEvaluation = eKeepEvaluatingTriggers;
if (m_CurrentPlugin->m_bEnabled)
ProcessOneTriggerSequence (strCurrentLine,
Expand Down
2 changes: 1 addition & 1 deletion install/readme.txt
@@ -1,7 +1,7 @@
MUSHclient version 4.89
=======================

Monday, 11th February 2013
Sunday, 24th February 2013

Author: Nick Gammon
Web support: http://www.gammon.com.au/forum/
Expand Down
1 change: 1 addition & 0 deletions plugins.cpp
Expand Up @@ -166,6 +166,7 @@ CPlugin::CPlugin (CMUSHclientDoc * pDoc)
m_iLoadOrder = 0;
m_iScriptTimeTaken = 0;
m_bSavingStateNow = false;
m_iSequence = DEFAULT_PLUGIN_SEQUENCE;

} // end of constructor

Expand Down
3 changes: 3 additions & 0 deletions plugins.h
@@ -1,6 +1,8 @@
/////////////////////////////////////////////////////////////////////////////
// CPlugin - these are world plugins

#define DEFAULT_PLUGIN_SEQUENCE 5000

// for storing dispatch IDs, and how many times each one is called
// we need a copy constructor and operator =, so it can be moved
// around in the STL map it is stored in
Expand Down Expand Up @@ -82,6 +84,7 @@ class CPlugin :public CObject
double m_dRequiredVersion; // minimum MUSHclient version required
CTime m_tDateInstalled; // date installed
CString m_strCallingPluginID; // during a CallPlugin - the ID of the calling plugin
unsigned short m_iSequence; // evaluation order, lower is sooner

CScriptEngine * m_ScriptEngine; // script engine for script, if any

Expand Down
1 change: 1 addition & 0 deletions world_debug.cpp
Expand Up @@ -825,6 +825,7 @@ VARIANT CMUSHclientDoc::Debug(LPCTSTR Command)
Note (TFormat ("Disk file: %s", (LPCTSTR) p->m_strSource));
Note (TFormat ("Language: %s", (LPCTSTR) p->m_strLanguage));
Note (TFormat ("Enabled: %s", SHOW_TRUE (p->m_bEnabled)));
Note (TFormat ("Sequence: %d", p->m_iSequence));

if (!p->m_strScript.IsEmpty ())
{
Expand Down
14 changes: 12 additions & 2 deletions xml/xml_load_world.cpp
Expand Up @@ -548,8 +548,17 @@ LONGLONG iCounterFrequency = large_int_frequency.QuadPart;

} // end of having a script

// add to world plugins
m_PluginList.push_back (m_CurrentPlugin);
PluginListIterator pit;

// find where to insert it
for (pit = m_PluginList.begin ();
pit != m_PluginList.end () &&
m_CurrentPlugin->m_iSequence >= (*pit)->m_iSequence;
++pit)
{ }

// add to world plugins (in sequence order)
m_PluginList.insert (pit, m_CurrentPlugin);

// now call the OnInstall routine (once it is in the list)

Expand Down Expand Up @@ -2396,6 +2405,7 @@ void CMUSHclientDoc::Load_Plugin_XML (CXMLelement & parent)
Get_XML_string (*node, "purpose", m_CurrentPlugin->m_strPurpose, false, true);
Get_XML_date (*node, "date_written", m_CurrentPlugin->m_tDateWritten, false);
Get_XML_date (*node, "date_modified", m_CurrentPlugin->m_tDateModified, false);
Get_XML_ushort (*node, "sequence", m_CurrentPlugin->m_iSequence, true, 0, 10000);
Get_XML_boolean (*node, "save_state", m_CurrentPlugin->m_bSaveState, false);
Get_XML_double (*node, "requires", m_CurrentPlugin->m_dRequiredVersion, false, 0.0, 1000.0);
Get_XML_double (*node, "version", m_CurrentPlugin->m_dVersion, false, 0.0);
Expand Down

0 comments on commit df9c170

Please sign in to comment.