
Untitled
By: a guest on Feb 7th, 2011 | syntax:
C++ | size: 1.35 KB | hits: 209 | expires: Never
class ScriptManager
{
GameResource m_gameResource;
List<Script> m_runningScripts = new List<Script>();
List<Script> m_toAdd = new List<Script>();
public void run(float dt)
{
List<Script> toRemove = new List<Script>();
foreach (Script s in m_toAdd)
{
m_runningScripts.Add(s);
}
m_toAdd.Clear();
foreach (Script s in m_runningScripts)
{
if (s.shouldDelete())
{
toRemove.Add(s);
}
else if (!s.run(dt))
{
toRemove.Add(s);
}
}
foreach (Script s in m_toAdd)
{
m_runningScripts.Add(s);
}
m_toAdd.Clear();
foreach (Script s in toRemove)
{
m_runningScripts.Remove(s);
}
}
public Script queueScript(String scriptName, String caller)
{
Script s = new Script(scriptName, m_gameResource, caller);
m_toAdd.Add(s);
return s;
}
public void clear()
{
m_toAdd.Clear();
m_runningScripts.Clear();
}
}