1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-19 16:47:14 +02:00

Implemented the IRC library.

Fixed a bug in the Routine system that caused crashes when constructed with only the first three arguments because it wasn't attached.
Implemented a gentle release of functions to not release them if the reference count is 1.
Adjusted the Routine and Command system to not be necessary to include them in the module core.
Moved the INI and XML libraries into their own namespace.
Various other modifications and fixes.
This commit is contained in:
Sandu Liviu Catalin
2016-02-23 05:23:56 +02:00
parent b6e72e93a2
commit bedf03c9cd
32 changed files with 10554 additions and 297 deletions

View File

@ -60,16 +60,16 @@ void CmdManager::Terminate()
{
if (itr->second)
{
itr->second->m_OnExec.Release2();
itr->second->m_OnAuth.Release2();
itr->second->m_OnPost.Release2();
itr->second->m_OnFail.Release2();
itr->second->m_OnExec.ReleaseGently();
itr->second->m_OnAuth.ReleaseGently();
itr->second->m_OnPost.ReleaseGently();
itr->second->m_OnFail.ReleaseGently();
}
}
// Release the script resources from this class
m_Argv.clear();
m_OnError.Release2();
m_OnAuth.Release2();
m_OnError.ReleaseGently();
m_OnAuth.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -648,10 +648,10 @@ CmdListener::~CmdListener()
if (!m_Name.empty())
_Cmd->Detach(m_Name);
// Release callbacks
m_OnExec.Release2();
m_OnAuth.Release2();
m_OnPost.Release2();
m_OnFail.Release2();
m_OnExec.ReleaseGently();
m_OnAuth.ReleaseGently();
m_OnPost.ReleaseGently();
m_OnFail.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
@ -1226,6 +1226,22 @@ bool CmdListener::ProcSpec(CSStr str)
return good;
}
/* ------------------------------------------------------------------------------------------------
* Forward the call to run a command.
*/
Int32 RunCommand(Int32 invoker, CSStr command)
{
return _Cmd->Run(invoker, command);
}
/* ------------------------------------------------------------------------------------------------
* Forward the call to terminate the command system.
*/
void TerminateCommand()
{
_Cmd->Terminate();
}
// ------------------------------------------------------------------------------------------------
static Function & Cmd_GetOnError()
{

View File

@ -1,8 +1,6 @@
// ------------------------------------------------------------------------------------------------
#include "Core.hpp"
#include "Logger.hpp"
#include "Command.hpp"
#include "Routine.hpp"
// ------------------------------------------------------------------------------------------------
#include "Entity/Blip.hpp"
@ -39,6 +37,18 @@ namespace SqMod {
// ------------------------------------------------------------------------------------------------
extern bool RegisterAPI(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
extern void ProcessIrc();
extern void TerminateIrc();
// ------------------------------------------------------------------------------------------------
extern void ProcessRoutine();
extern void TerminateRoutine();
// ------------------------------------------------------------------------------------------------
extern Int32 RunCommand(Int32 invoker, CSStr command);
extern void TerminateCommand();
// ------------------------------------------------------------------------------------------------
Core * _Core = NULL;
@ -332,10 +342,12 @@ void Core::Terminate()
m_Textdraws.clear();
m_Vehicles.clear();
m_Scripts.clear();
// Release all resources from command manager
_Cmd->Terminate();
// Release all resources from routines
Routine::Cleanup();
TerminateRoutine();
// Release all resources from command manager
TerminateCommand();
// Release all resources from irc sessions
TerminateIrc();
// Is there a VM to close?
if (m_VM)
{
@ -1251,7 +1263,7 @@ void Core::EmitPlayerCommand(Int32 player, CCStr command)
Emit(_player.mOnCommand, command);
Emit(mOnPlayerCommand, _player.mObj, command);
// Send it to the command manager
_Cmd->Run(player, command);
RunCommand(player, command);
}
void Core::EmitPlayerMessage(Int32 player, Int32 receiver, CCStr message)
@ -1664,7 +1676,10 @@ void Core::EmitForcefieldExited(Int32 player, Int32 forcefield)
void Core::EmitServerFrame(Float32 delta)
{
Emit(mOnServerFrame, delta);
Routine::Process();
// Update routines
ProcessRoutine();
// Update IRC sessions
ProcessIrc();
}
void Core::EmitServerStartup()

View File

@ -6,9 +6,10 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace INI {
// ------------------------------------------------------------------------------------------------
Int32 IniEntries::Cmp(const IniEntries & o) const
Int32 Entries::Cmp(const Entries & o) const
{
if (m_Elem == o.m_Elem)
return 0;
@ -19,13 +20,13 @@ Int32 IniEntries::Cmp(const IniEntries & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr IniEntries::ToString() const
CSStr Entries::ToString() const
{
return GetItem();
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Next()
void Entries::Next()
{
// Are there any other elements ahead?
if (!m_List.empty() && m_Elem != m_List.end())
@ -33,7 +34,7 @@ void IniEntries::Next()
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Prev()
void Entries::Prev()
{
// Are there any other elements behind?
if (!m_List.empty() && m_Elem != m_List.begin())
@ -41,7 +42,7 @@ void IniEntries::Prev()
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Advance(Int32 n)
void Entries::Advance(Int32 n)
{
// Are there any other elements ahead?
if (m_List.empty() || m_Elem == m_List.end())
@ -51,7 +52,7 @@ void IniEntries::Advance(Int32 n)
}
// ------------------------------------------------------------------------------------------------
void IniEntries::Retreat(Int32 n)
void Entries::Retreat(Int32 n)
{
// Are there any other elements behind?
if (m_List.empty() || m_Elem == m_List.begin())
@ -61,7 +62,7 @@ void IniEntries::Retreat(Int32 n)
}
// ------------------------------------------------------------------------------------------------
CSStr IniEntries::GetItem() const
CSStr Entries::GetItem() const
{
if (m_List.empty() || m_Elem == m_List.end())
SqThrow("Invalid INI entry [item]");
@ -71,7 +72,7 @@ CSStr IniEntries::GetItem() const
}
// ------------------------------------------------------------------------------------------------
CSStr IniEntries::GetComment() const
CSStr Entries::GetComment() const
{
if (m_List.empty() || m_Elem == m_List.end())
SqThrow("Invalid INI entry [comment]");
@ -81,7 +82,7 @@ CSStr IniEntries::GetComment() const
}
// ------------------------------------------------------------------------------------------------
Int32 IniEntries::GetOrder() const
Int32 Entries::GetOrder() const
{
if (m_List.empty() || m_Elem == m_List.end())
SqThrow("Invalid INI entry [order]");
@ -91,27 +92,27 @@ Int32 IniEntries::GetOrder() const
}
// ------------------------------------------------------------------------------------------------
IniDocument::IniDocument()
Document::Document()
: m_Doc(false, false, true)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
IniDocument::IniDocument(bool utf8, bool multikey, bool multiline)
Document::Document(bool utf8, bool multikey, bool multiline)
: m_Doc(utf8, multikey, multiline)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
IniDocument::~IniDocument()
Document::~Document()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Int32 IniDocument::Cmp(const IniDocument & o) const
Int32 Document::Cmp(const Document & o) const
{
if (m_Doc == o.m_Doc)
return 0;
@ -122,91 +123,91 @@ Int32 IniDocument::Cmp(const IniDocument & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr IniDocument::ToString() const
CSStr Document::ToString() const
{
return _SC("");
}
// ------------------------------------------------------------------------------------------------
void IniDocument::LoadFile(CSStr filepath)
void Document::LoadFile(CSStr filepath)
{
if (!Validate())
return; /* Unable to proceed */
// Attempt to load the file from disk
const SI_Error ini_ret = m_Doc->LoadFile(filepath);
const SI_Error ret = m_Doc->LoadFile(filepath);
// See if the file could be loaded
if (ini_ret < 0)
if (ret < 0)
{
// Identify the error type
switch (ini_ret)
switch (ret)
{
case SI_FAIL:
SqThrow("Failed to load the ini file. Probably invalid");
SqThrow("Failed to load the INI file. Probably invalid");
break;
case SI_NOMEM:
SqThrow("Ran out of memory while loading the ini file");
SqThrow("Ran out of memory while loading the INI file");
break;
case SI_FILE:
SqThrow("Failed to load the ini file. %s", strerror(errno));
SqThrow("Failed to load the INI file. %s", strerror(errno));
break;
default:
SqThrow("Failed to load the ini file for some unforeseen reason");
SqThrow("Failed to load the INI file for some unforeseen reason");
}
}
}
// ------------------------------------------------------------------------------------------------
void IniDocument::LoadData(CSStr source, Int32 size)
void Document::LoadData(CSStr source, Int32 size)
{
if (!Validate())
return; /* Unable to proceed */
// Attempt to load the source from memory
const SI_Error ini_ret = m_Doc->LoadData(source, size < 0 ? strlen(source) : size);
const SI_Error ret = m_Doc->LoadData(source, size < 0 ? strlen(source) : size);
// See if the source could be loaded
if (ini_ret < 0)
if (ret < 0)
{
// Identify the error type
switch (ini_ret)
switch (ret)
{
case SI_FAIL:
SqThrow("Failed to load the ini data. Probably invalid");
SqThrow("Failed to load the INI data. Probably invalid");
break;
case SI_NOMEM:
SqThrow("Ran out of memory while loading the ini data");
SqThrow("Ran out of memory while loading the INI data");
break;
default:
SqThrow("Failed to load the ini data for some unforeseen reason");
SqThrow("Failed to load the INI data for some unforeseen reason");
}
}
}
// ------------------------------------------------------------------------------------------------
void IniDocument::SaveFile(CSStr filepath, bool signature)
void Document::SaveFile(CSStr filepath, bool signature)
{
if (!Validate())
return; /* Unable to proceed */
// Attempt to save the file to disk
const SI_Error ini_ret = m_Doc->SaveFile(filepath, signature);
const SI_Error ret = m_Doc->SaveFile(filepath, signature);
// See if the file could be saved
if (ini_ret == SI_FAIL)
if (ret == SI_FAIL)
{
SqThrow("Failed to save the ini file. Probably invalid");
SqThrow("Failed to save the INI file. Probably invalid");
}
}
// ------------------------------------------------------------------------------------------------
Object IniDocument::SaveData(bool signature)
Object Document::SaveData(bool signature)
{
if (!Validate())
return NullObject(); /* Unable to proceed */
// The string where the content will be saved
String source;
// Attempt to save the data to string
const SI_Error ini_ret = m_Doc->Save(source, signature);
const SI_Error ret = m_Doc->Save(source, signature);
// See if the data could be saved
if (ini_ret == SI_FAIL)
if (ret == SI_FAIL)
{
SqThrow("Failed to save the ini data. Probably invalid");
SqThrow("Failed to save the INI data. Probably invalid");
return NullObject(); /* Unable to proceed */
}
// Transform it into a script object
@ -223,46 +224,46 @@ Object IniDocument::SaveData(bool signature)
}
// ------------------------------------------------------------------------------------------------
IniEntries IniDocument::GetAllSections() const
Entries Document::GetAllSections() const
{
if (!Validate())
return IniEntries(); /* Unable to proceed */
return Entries(); /* Unable to proceed */
// Prepare a container to receive the entries
static Container entries;
// Obtain all sections from the ini document
// Obtain all sections from the INI document
m_Doc->GetAllSections(entries);
// Return the entries and take over content
return IniEntries(m_Doc, entries);
return Entries(m_Doc, entries);
}
// ------------------------------------------------------------------------------------------------
IniEntries IniDocument::GetAllKeys(CSStr section) const
Entries Document::GetAllKeys(CSStr section) const
{
if (!Validate())
return IniEntries(); /* Unable to proceed */
return Entries(); /* Unable to proceed */
// Prepare a container to receive the entries
static Container entries;
// Obtain all sections from the ini document
// Obtain all sections from the INI document
m_Doc->GetAllKeys(section, entries);
// Return the entries and take over content
return IniEntries(m_Doc, entries);
return Entries(m_Doc, entries);
}
// ------------------------------------------------------------------------------------------------
IniEntries IniDocument::GetAllValues(CSStr section, CSStr key) const
Entries Document::GetAllValues(CSStr section, CSStr key) const
{
if (!Validate())
return IniEntries(); /* Unable to proceed */
return Entries(); /* Unable to proceed */
// Prepare a container to receive the entries
static Container entries;
// Obtain all sections from the ini document
// Obtain all sections from the INI document
m_Doc->GetAllValues(section, key, entries);
// Return the entries and take over content
return IniEntries(m_Doc, entries);
return Entries(m_Doc, entries);
}
// ------------------------------------------------------------------------------------------------
Int32 IniDocument::GetSectionSize(CSStr section) const
Int32 Document::GetSectionSize(CSStr section) const
{
if (Validate())
// Return the requested information
@ -272,7 +273,7 @@ Int32 IniDocument::GetSectionSize(CSStr section) const
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::HasMultipleKeys(CSStr section, CSStr key) const
bool Document::HasMultipleKeys(CSStr section, CSStr key) const
{
if (!Validate())
return false; /* Unable to proceed */
@ -285,7 +286,7 @@ bool IniDocument::HasMultipleKeys(CSStr section, CSStr key) const
}
// ------------------------------------------------------------------------------------------------
CCStr IniDocument::GetValue(CSStr section, CSStr key, CSStr def) const
CCStr Document::GetValue(CSStr section, CSStr key, CSStr def) const
{
if (!Validate())
return _SC(""); /* Unable to proceed */
@ -294,7 +295,7 @@ CCStr IniDocument::GetValue(CSStr section, CSStr key, CSStr def) const
}
// ------------------------------------------------------------------------------------------------
SQInteger IniDocument::GetInteger(CSStr section, CSStr key, SQInteger def) const
SQInteger Document::GetInteger(CSStr section, CSStr key, SQInteger def) const
{
if (!Validate())
return 0; /* Unable to proceed */
@ -303,7 +304,7 @@ SQInteger IniDocument::GetInteger(CSStr section, CSStr key, SQInteger def) const
}
// ------------------------------------------------------------------------------------------------
SQFloat IniDocument::GetFloat(CSStr section, CSStr key, SQFloat def) const
SQFloat Document::GetFloat(CSStr section, CSStr key, SQFloat def) const
{
if (!Validate())
return 0.0; /* Unable to proceed */
@ -312,7 +313,7 @@ SQFloat IniDocument::GetFloat(CSStr section, CSStr key, SQFloat def) const
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::GetBoolean(CSStr section, CSStr key, bool def) const
bool Document::GetBoolean(CSStr section, CSStr key, bool def) const
{
if (!Validate())
return false; /* Unable to proceed */
@ -321,205 +322,209 @@ bool IniDocument::GetBoolean(CSStr section, CSStr key, bool def) const
}
// ------------------------------------------------------------------------------------------------
void IniDocument::SetValue(CSStr section, CSStr key, CSStr value, bool force, CSStr comment)
void Document::SetValue(CSStr section, CSStr key, CSStr value, bool force, CSStr comment)
{
if (!Validate())
return; /* Unable to proceed */
// Attempt to apply the specified information
const SI_Error ini_ret = m_Doc->SetValue(section, key, value, comment, force);
const SI_Error ret = m_Doc->SetValue(section, key, value, comment, force);
// See if the information could be applied
if (ini_ret < 0)
if (ret < 0)
{
// Identify the error type
switch (ini_ret)
switch (ret)
{
case SI_FAIL:
SqThrow("Failed to set the ini value. Probably invalid");
SqThrow("Failed to set the INI value. Probably invalid");
break;
case SI_NOMEM:
SqThrow("Ran out of memory while setting ini value");
SqThrow("Ran out of memory while setting INI value");
break;
default:
SqThrow("Failed to set the ini value for some unforeseen reason");
SqThrow("Failed to set the INI value for some unforeseen reason");
}
}
}
// ------------------------------------------------------------------------------------------------
void IniDocument::SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force, CSStr comment)
void Document::SetInteger(CSStr section, CSStr key, SQInteger value, bool hex, bool force, CSStr comment)
{
if (!Validate())
return; /* Unable to proceed */
// Attempt to apply the specified information
const SI_Error ini_ret = m_Doc->SetLongValue(section, key, value, comment, hex, force);
const SI_Error ret = m_Doc->SetLongValue(section, key, value, comment, hex, force);
// See if the information could be applied
if (ini_ret < 0)
if (ret < 0)
{
// Identify the error type
switch (ini_ret)
switch (ret)
{
case SI_FAIL:
SqThrow("Failed to set the ini integer. Probably invalid");
SqThrow("Failed to set the INI integer. Probably invalid");
break;
case SI_NOMEM:
SqThrow("Ran out of memory while setting ini integer");
SqThrow("Ran out of memory while setting INI integer");
break;
default:
SqThrow("Failed to set the ini integer for some unforeseen reason");
SqThrow("Failed to set the INI integer for some unforeseen reason");
}
}
}
// ------------------------------------------------------------------------------------------------
void IniDocument::SetFloat(CSStr section, CSStr key, SQFloat value, bool force, CSStr comment)
void Document::SetFloat(CSStr section, CSStr key, SQFloat value, bool force, CSStr comment)
{
if (!Validate())
return; /* Unable to proceed */
// Attempt to apply the specified information
const SI_Error ini_ret = m_Doc->SetDoubleValue(section, key, value, comment, force);
const SI_Error ret = m_Doc->SetDoubleValue(section, key, value, comment, force);
// See if the information could be applied
if (ini_ret < 0)
if (ret < 0)
{
// Identify the error type
switch (ini_ret)
switch (ret)
{
case SI_FAIL:
SqThrow("Failed to set the ini float. Probably invalid");
SqThrow("Failed to set the INI float. Probably invalid");
break;
case SI_NOMEM:
SqThrow("Ran out of memory while setting ini float");
SqThrow("Ran out of memory while setting INI float");
break;
default:
SqThrow("Failed to set the ini float for some unforeseen reason");
SqThrow("Failed to set the INI float for some unforeseen reason");
}
}
}
// ------------------------------------------------------------------------------------------------
void IniDocument::SetBoolean(CSStr section, CSStr key, bool value, bool force, CSStr comment)
void Document::SetBoolean(CSStr section, CSStr key, bool value, bool force, CSStr comment)
{
if (!Validate())
return; /* Unable to proceed */
// Attempt to apply the specified information
const SI_Error ini_ret = m_Doc->SetBoolValue(section, key, value, comment, force);
const SI_Error ret = m_Doc->SetBoolValue(section, key, value, comment, force);
// See if the information could be applied
if (ini_ret < 0)
if (ret < 0)
{
// Identify the error type
switch (ini_ret)
switch (ret)
{
case SI_FAIL:
SqThrow("Failed to set the ini boolean. Probably invalid");
SqThrow("Failed to set the INI boolean. Probably invalid");
break;
case SI_NOMEM:
SqThrow("Ran out of memory while setting ini boolean");
SqThrow("Ran out of memory while setting INI boolean");
break;
default:
SqThrow("Failed to set the ini boolean for some unforeseen reason");
SqThrow("Failed to set the INI boolean for some unforeseen reason");
}
}
}
// ------------------------------------------------------------------------------------------------
bool IniDocument::DeleteValue(CSStr section, CSStr key, CSStr value, bool empty)
bool Document::DeleteValue(CSStr section, CSStr key, CSStr value, bool empty)
{
if (!Validate())
return false; /* Unable to proceed */
else if (!section)
{
SqThrow("Invalid ini section");
SqThrow("Invalid INI section");
return false; /* Unable to proceed */
}
else if (!key)
{
SqThrow("Invalid ini key");
SqThrow("Invalid INI key");
return false; /* Unable to proceed */
}
// Attempt to remove the specified value
return m_Doc->DeleteValue(section, key, value, empty);
}
} // Namespace:: INI
// ================================================================================================
void Register_INI(HSQUIRRELVM vm)
{
using namespace INI;
Table inins(vm);
inins.Bind(_SC("Entries"), Class< IniEntries >(vm, _SC("SqIniEntries"))
inins.Bind(_SC("Entries"), Class< Entries >(vm, _SC("SqIniEntries"))
/* Constructors */
.Ctor()
.Ctor< const IniEntries & >()
.Ctor< const Entries & >()
/* Core Metamethods */
.Func(_SC("_tostring"), &IniEntries::ToString)
.Func(_SC("_cmp"), &IniEntries::Cmp)
.Func(_SC("_tostring"), &Entries::ToString)
.Func(_SC("_cmp"), &Entries::Cmp)
/* Properties */
.Prop(_SC("Valid"), &IniEntries::IsValid)
.Prop(_SC("Empty"), &IniEntries::IsEmpty)
.Prop(_SC("References"), &IniEntries::GetRefCount)
.Prop(_SC("Size"), &IniEntries::GetSize)
.Prop(_SC("Item"), &IniEntries::GetItem)
.Prop(_SC("Comment"), &IniEntries::GetComment)
.Prop(_SC("Order"), &IniEntries::GetOrder)
.Prop(_SC("Valid"), &Entries::IsValid)
.Prop(_SC("Empty"), &Entries::IsEmpty)
.Prop(_SC("References"), &Entries::GetRefCount)
.Prop(_SC("Size"), &Entries::GetSize)
.Prop(_SC("Item"), &Entries::GetItem)
.Prop(_SC("Comment"), &Entries::GetComment)
.Prop(_SC("Order"), &Entries::GetOrder)
/* Functions */
.Func(_SC("Reset"), &IniEntries::Reset)
.Func(_SC("Next"), &IniEntries::Next)
.Func(_SC("Prev"), &IniEntries::Prev)
.Func(_SC("Advance"), &IniEntries::Advance)
.Func(_SC("Retreat"), &IniEntries::Retreat)
.Func(_SC("Sort"), &IniEntries::Sort)
.Func(_SC("SortByKeyOrder"), &IniEntries::SortByKeyOrder)
.Func(_SC("SortByLoadOrder"), &IniEntries::SortByLoadOrder)
.Func(_SC("SortByLoadOrderEmptyFirst"), &IniEntries::SortByLoadOrderEmptyFirst)
.Func(_SC("Reset"), &Entries::Reset)
.Func(_SC("Next"), &Entries::Next)
.Func(_SC("Prev"), &Entries::Prev)
.Func(_SC("Advance"), &Entries::Advance)
.Func(_SC("Retreat"), &Entries::Retreat)
.Func(_SC("Sort"), &Entries::Sort)
.Func(_SC("SortByKeyOrder"), &Entries::SortByKeyOrder)
.Func(_SC("SortByLoadOrder"), &Entries::SortByLoadOrder)
.Func(_SC("SortByLoadOrderEmptyFirst"), &Entries::SortByLoadOrderEmptyFirst)
);
inins.Bind(_SC("Document"), Class< IniDocument, NoCopy< IniDocument > >(vm, _SC("SqIniDocument"))
inins.Bind(_SC("Document"), Class< Document, NoCopy< Document > >(vm, _SC("SqIniDocument"))
/* Constructors */
.Ctor()
.Ctor< bool, bool, bool >()
/* Core Metamethods */
.Func(_SC("_tostring"), &IniDocument::ToString)
.Func(_SC("_cmp"), &IniDocument::Cmp)
.Func(_SC("_tostring"), &Document::ToString)
.Func(_SC("_cmp"), &Document::Cmp)
/* Properties */
.Prop(_SC("Valid"), &IniDocument::IsValid)
.Prop(_SC("Empty"), &IniDocument::IsEmpty)
.Prop(_SC("References"), &IniDocument::GetRefCount)
.Prop(_SC("Unicode"), &IniDocument::GetUnicode, &IniDocument::SetUnicode)
.Prop(_SC("MultiKey"), &IniDocument::GetMultiKey, &IniDocument::SetMultiKey)
.Prop(_SC("MultiLine"), &IniDocument::GetMultiLine, &IniDocument::SetMultiLine)
.Prop(_SC("Spaces"), &IniDocument::GetSpaces, &IniDocument::SetSpaces)
.Prop(_SC("Valid"), &Document::IsValid)
.Prop(_SC("Empty"), &Document::IsEmpty)
.Prop(_SC("References"), &Document::GetRefCount)
.Prop(_SC("Unicode"), &Document::GetUnicode, &Document::SetUnicode)
.Prop(_SC("MultiKey"), &Document::GetMultiKey, &Document::SetMultiKey)
.Prop(_SC("MultiLine"), &Document::GetMultiLine, &Document::SetMultiLine)
.Prop(_SC("Spaces"), &Document::GetSpaces, &Document::SetSpaces)
/* Functions */
.Func(_SC("Reset"), &IniDocument::Reset)
.Func(_SC("LoadFile"), &IniDocument::LoadFile)
.Overload< void (IniDocument::*)(CSStr) >(_SC("LoadData"), &IniDocument::LoadData)
.Overload< void (IniDocument::*)(CSStr, Int32) >(_SC("LoadData"), &IniDocument::LoadData)
.Overload< void (IniDocument::*)(CSStr) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Overload< void (IniDocument::*)(CSStr, bool) >(_SC("SaveFile"), &IniDocument::SaveFile)
.Func(_SC("SaveData"), &IniDocument::SaveData)
.Func(_SC("GetSections"), &IniDocument::GetAllSections)
.Func(_SC("GetKeys"), &IniDocument::GetAllKeys)
.Func(_SC("GetValues"), &IniDocument::GetAllValues)
.Func(_SC("GetSectionSize"), &IniDocument::GetSectionSize)
.Func(_SC("HasMultipleKeys"), &IniDocument::HasMultipleKeys)
.Func(_SC("GetValue"), &IniDocument::GetValue)
.Func(_SC("GetInteger"), &IniDocument::GetInteger)
.Func(_SC("GetFloat"), &IniDocument::GetFloat)
.Func(_SC("GetBoolean"), &IniDocument::GetBoolean)
.Overload< void (IniDocument::*)(CSStr, CSStr, CSStr) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< void (IniDocument::*)(CSStr, CSStr, CSStr, bool) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< void (IniDocument::*)(CSStr, CSStr, CSStr, bool, CSStr) >(_SC("SetValue"), &IniDocument::SetValue)
.Overload< void (IniDocument::*)(CSStr, CSStr, SQInteger) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< void (IniDocument::*)(CSStr, CSStr, SQInteger, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< void (IniDocument::*)(CSStr, CSStr, SQInteger, bool, bool) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< void (IniDocument::*)(CSStr, CSStr, SQInteger, bool, bool, CSStr) >(_SC("SetInteger"), &IniDocument::SetInteger)
.Overload< void (IniDocument::*)(CSStr, CSStr, SQFloat) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< void (IniDocument::*)(CSStr, CSStr, SQFloat, bool) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< void (IniDocument::*)(CSStr, CSStr, SQFloat, bool, CSStr) >(_SC("SetFloat"), &IniDocument::SetFloat)
.Overload< void (IniDocument::*)(CSStr, CSStr, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< void (IniDocument::*)(CSStr, CSStr, bool, bool) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< void (IniDocument::*)(CSStr, CSStr, bool, bool, CSStr) >(_SC("SetBoolean"), &IniDocument::SetBoolean)
.Overload< bool (IniDocument::*)(CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr, CSStr) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Overload< bool (IniDocument::*)(CSStr, CSStr, CSStr, bool) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
.Func(_SC("Reset"), &Document::Reset)
.Func(_SC("LoadFile"), &Document::LoadFile)
.Overload< void (Document::*)(CSStr) >(_SC("LoadData"), &Document::LoadData)
.Overload< void (Document::*)(CSStr, Int32) >(_SC("LoadData"), &Document::LoadData)
.Overload< void (Document::*)(CSStr) >(_SC("SaveFile"), &Document::SaveFile)
.Overload< void (Document::*)(CSStr, bool) >(_SC("SaveFile"), &Document::SaveFile)
.Func(_SC("SaveData"), &Document::SaveData)
.Func(_SC("GetSections"), &Document::GetAllSections)
.Func(_SC("GetKeys"), &Document::GetAllKeys)
.Func(_SC("GetValues"), &Document::GetAllValues)
.Func(_SC("GetSectionSize"), &Document::GetSectionSize)
.Func(_SC("HasMultipleKeys"), &Document::HasMultipleKeys)
.Func(_SC("GetValue"), &Document::GetValue)
.Func(_SC("GetInteger"), &Document::GetInteger)
.Func(_SC("GetFloat"), &Document::GetFloat)
.Func(_SC("GetBoolean"), &Document::GetBoolean)
.Overload< void (Document::*)(CSStr, CSStr, CSStr) >(_SC("SetValue"), &Document::SetValue)
.Overload< void (Document::*)(CSStr, CSStr, CSStr, bool) >(_SC("SetValue"), &Document::SetValue)
.Overload< void (Document::*)(CSStr, CSStr, CSStr, bool, CSStr) >(_SC("SetValue"), &Document::SetValue)
.Overload< void (Document::*)(CSStr, CSStr, SQInteger) >(_SC("SetInteger"), &Document::SetInteger)
.Overload< void (Document::*)(CSStr, CSStr, SQInteger, bool) >(_SC("SetInteger"), &Document::SetInteger)
.Overload< void (Document::*)(CSStr, CSStr, SQInteger, bool, bool) >(_SC("SetInteger"), &Document::SetInteger)
.Overload< void (Document::*)(CSStr, CSStr, SQInteger, bool, bool, CSStr) >(_SC("SetInteger"), &Document::SetInteger)
.Overload< void (Document::*)(CSStr, CSStr, SQFloat) >(_SC("SetFloat"), &Document::SetFloat)
.Overload< void (Document::*)(CSStr, CSStr, SQFloat, bool) >(_SC("SetFloat"), &Document::SetFloat)
.Overload< void (Document::*)(CSStr, CSStr, SQFloat, bool, CSStr) >(_SC("SetFloat"), &Document::SetFloat)
.Overload< void (Document::*)(CSStr, CSStr, bool) >(_SC("SetBoolean"), &Document::SetBoolean)
.Overload< void (Document::*)(CSStr, CSStr, bool, bool) >(_SC("SetBoolean"), &Document::SetBoolean)
.Overload< void (Document::*)(CSStr, CSStr, bool, bool, CSStr) >(_SC("SetBoolean"), &Document::SetBoolean)
.Overload< bool (Document::*)(CSStr) >(_SC("DeleteValue"), &Document::DeleteValue)
.Overload< bool (Document::*)(CSStr, CSStr) >(_SC("DeleteValue"), &Document::DeleteValue)
.Overload< bool (Document::*)(CSStr, CSStr, CSStr) >(_SC("DeleteValue"), &Document::DeleteValue)
.Overload< bool (Document::*)(CSStr, CSStr, CSStr, bool) >(_SC("DeleteValue"), &Document::DeleteValue)
);
RootTable(vm).Bind(_SC("SqIni"), inins);

View File

@ -9,30 +9,31 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace INI {
// ------------------------------------------------------------------------------------------------
class IniEntries;
class IniDocument;
class Entries;
class Document;
/* ------------------------------------------------------------------------------------------------
* Manages a reference counted ini document instance.
* Manages a reference counted INI document instance.
*/
class IniDocumentRef
class DocumentRef
{
// --------------------------------------------------------------------------------------------
friend class IniDocument;
friend class Document;
private:
// --------------------------------------------------------------------------------------------
typedef CSimpleIniA Document;
typedef CSimpleIniA IrcDocument;
// --------------------------------------------------------------------------------------------
typedef unsigned int Counter;
// --------------------------------------------------------------------------------------------
Document* m_Ptr; /* The document reader, writer and manager instance. */
Counter* m_Ref; /* Reference count to the managed instance. */
IrcDocument* m_Ptr; /* The document reader, writer and manager instance. */
Counter* m_Ref; /* Reference count to the managed instance. */
/* --------------------------------------------------------------------------------------------
* Grab a strong reference to a document instance.
@ -62,8 +63,8 @@ private:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
IniDocumentRef(bool utf8, bool multikey, bool multiline)
: m_Ptr(new Document(utf8, multikey, multiline)), m_Ref(new Counter(1))
DocumentRef(bool utf8, bool multikey, bool multiline)
: m_Ptr(new IrcDocument(utf8, multikey, multiline)), m_Ref(new Counter(1))
{
/* ... */
}
@ -73,7 +74,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Default constructor (null).
*/
IniDocumentRef()
DocumentRef()
: m_Ptr(NULL), m_Ref(NULL)
{
/* ... */
@ -82,7 +83,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
IniDocumentRef(const IniDocumentRef & o)
DocumentRef(const DocumentRef & o)
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
{
@ -92,7 +93,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniDocumentRef()
~DocumentRef()
{
Drop();
}
@ -100,7 +101,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
IniDocumentRef & operator = (const IniDocumentRef & o)
DocumentRef & operator = (const DocumentRef & o)
{
if (m_Ptr != o.m_Ptr)
{
@ -115,7 +116,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Perform an equality comparison between two document instances.
*/
bool operator == (const IniDocumentRef & o) const
bool operator == (const DocumentRef & o) const
{
return (m_Ptr == o.m_Ptr);
}
@ -123,7 +124,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Perform an inequality comparison between two document instances.
*/
bool operator != (const IniDocumentRef & o) const
bool operator != (const DocumentRef & o) const
{
return (m_Ptr != o.m_Ptr);
}
@ -139,7 +140,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Member operator for dereferencing the managed pointer.
*/
Document * operator -> () const
IrcDocument * operator -> () const
{
assert(m_Ptr != NULL);
return m_Ptr;
@ -148,7 +149,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Indirection operator for obtaining a reference of the managed pointer.
*/
Document & operator * () const
IrcDocument & operator * () const
{
assert(m_Ptr != NULL);
return *m_Ptr;
@ -165,20 +166,20 @@ public:
};
/* ------------------------------------------------------------------------------------------------
* Class that can access and iterate a series of entries in the ini document.
* Class that can access and iterate a series of entries in the INI document.
*/
class IniEntries
class Entries
{
// --------------------------------------------------------------------------------------------
friend class IniDocument;
friend class Document;
protected:
// --------------------------------------------------------------------------------------------
typedef CSimpleIniA Document;
typedef CSimpleIniA IrcDocument;
// --------------------------------------------------------------------------------------------
typedef Document::TNamesDepend Container;
typedef IrcDocument::TNamesDepend Container;
// --------------------------------------------------------------------------------------------
typedef Container::iterator Iterator;
@ -186,7 +187,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
IniEntries(const IniDocumentRef & ini, Container & list)
Entries(const DocumentRef & ini, Container & list)
: m_Doc(ini), m_List(), m_Elem()
{
m_List.swap(list);
@ -196,7 +197,7 @@ protected:
private:
// ---------------------------------------------------------------------------------------------
IniDocumentRef m_Doc; /* The document that contains the elements. */
DocumentRef m_Doc; /* The document that contains the elements. */
Container m_List; /* The list of elements to iterate. */
Iterator m_Elem; /* The currently processed element. */
@ -205,7 +206,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Default constructor. (null)
*/
IniEntries()
Entries()
: m_Doc(), m_List(), m_Elem(m_List.end())
{
/* ... */
@ -214,7 +215,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
IniEntries(const IniEntries & o)
Entries(const Entries & o)
: m_Doc(o.m_Doc), m_List(o.m_List), m_Elem()
{
Reset();
@ -223,7 +224,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniEntries()
~Entries()
{
/* ... */
}
@ -231,7 +232,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
IniEntries & operator = (const IniEntries & o)
Entries & operator = (const Entries & o)
{
m_Doc = o.m_Doc;
m_List = o.m_List;
@ -242,7 +243,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniEntries & o) const;
Int32 Cmp(const Entries & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
@ -318,7 +319,7 @@ public:
void Sort()
{
if (!m_List.empty())
m_List.sort(Document::Entry::KeyOrder());
m_List.sort(IrcDocument::Entry::KeyOrder());
}
/* --------------------------------------------------------------------------------------------
@ -327,7 +328,7 @@ public:
void SortByKeyOrder()
{
if (!m_List.empty())
m_List.sort(Document::Entry::KeyOrder());
m_List.sort(IrcDocument::Entry::KeyOrder());
}
/* --------------------------------------------------------------------------------------------
@ -336,7 +337,7 @@ public:
void SortByLoadOrder()
{
if (!m_List.empty())
m_List.sort(Document::Entry::LoadOrder());
m_List.sort(IrcDocument::Entry::LoadOrder());
}
/* --------------------------------------------------------------------------------------------
@ -345,7 +346,7 @@ public:
void SortByLoadOrderEmptyFirst()
{
if (!m_List.empty())
m_List.sort(Document::Entry::LoadOrderEmptyFirst());
m_List.sort(IrcDocument::Entry::LoadOrderEmptyFirst());
}
/* --------------------------------------------------------------------------------------------
@ -365,27 +366,27 @@ public:
};
/* ------------------------------------------------------------------------------------------------
* Class that can read/write and alter the contents of ini files.
* Class that can read/write and alter the contents of INI files.
*/
class IniDocument
class Document
{
protected:
// --------------------------------------------------------------------------------------------
typedef CSimpleIniA Document;
typedef CSimpleIniA IrcDocument;
// --------------------------------------------------------------------------------------------
typedef Document::TNamesDepend Container;
typedef IrcDocument::TNamesDepend Container;
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
IniDocument(const IniDocument & o);
Document(const Document & o);
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
IniDocument & operator = (const IniDocument & o);
Document & operator = (const Document & o);
/* --------------------------------------------------------------------------------------------
* Validate the document reference.
@ -394,36 +395,36 @@ protected:
{
if (m_Doc)
return true;
SqThrow("Invalid ini document reference");
SqThrow("Invalid INI document reference");
return false;
}
private:
// ---------------------------------------------------------------------------------------------
IniDocumentRef m_Doc; /* The main ini document instance. */
DocumentRef m_Doc; /* The main INI document instance. */
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
IniDocument();
Document();
/* --------------------------------------------------------------------------------------------
* Explicit constructor.
*/
IniDocument(bool utf8, bool multikey, bool multiline);
Document(bool utf8, bool multikey, bool multiline);
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~IniDocument();
~Document();
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const IniDocument & o) const;
Int32 Cmp(const Document & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
@ -431,7 +432,7 @@ public:
CSStr ToString() const;
/* --------------------------------------------------------------------------------------------
* See whether this instance references a valid ini document.
* See whether this instance references a valid INI document.
*/
bool IsValid() const
{
@ -463,7 +464,7 @@ public:
}
/* --------------------------------------------------------------------------------------------
* See whether the ini data is treated as unicode.
* See whether the INI data is treated as unicode.
*/
bool GetUnicode() const
{
@ -471,7 +472,7 @@ public:
}
/* --------------------------------------------------------------------------------------------
* Set whether the ini data should be treated as unicode.
* Set whether the INI data should be treated as unicode.
*/
void SetUnicode(bool toggle)
{
@ -565,17 +566,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve all section names.
*/
IniEntries GetAllSections() const;
Entries GetAllSections() const;
/* --------------------------------------------------------------------------------------------
* Retrieve all unique key names in a section.
*/
IniEntries GetAllKeys(CSStr section) const;
Entries GetAllKeys(CSStr section) const;
/* --------------------------------------------------------------------------------------------
* Retrieve all values for a specific key.
*/
IniEntries GetAllValues(CSStr section, CSStr key) const;
Entries GetAllValues(CSStr section, CSStr key) const;
/* --------------------------------------------------------------------------------------------
* Query the number of keys in a specific section.
@ -729,6 +730,7 @@ public:
bool DeleteValue(CSStr section, CSStr key, CSStr value, bool empty);
};
} // Namespace:: INI
} // Namespace:: SqMod
#endif // _LIBRARY_INI_HPP_

1045
source/Library/IRC.cpp Normal file

File diff suppressed because it is too large Load Diff

1434
source/Library/IRC.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace XML {
// ------------------------------------------------------------------------------------------------
void XmlParseResult::Check() const
@ -25,9 +26,13 @@ XmlNode XmlDocument::GetNode() const
return XmlNode();
}
} // Namespace:: XML
// ================================================================================================
void Register_XML(HSQUIRRELVM vm)
{
using namespace XML;
Table xmlns(vm);
xmlns.Bind(_SC("ParseResult"), Class< XmlParseResult >(vm, _SC("SqXmlParseResult"))

View File

@ -10,6 +10,7 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace XML {
// ------------------------------------------------------------------------------------------------
using namespace pugi;
@ -2030,6 +2031,7 @@ public:
};
} // Namespace:: XML
} // Namespace:: SqMod
#endif // _LIBRARY_XML_HPP_

View File

@ -117,7 +117,7 @@ template < Uint8 L, bool S > static SQInteger LogBasicMessage(HSQUIRRELVM vm)
void Register_Log(HSQUIRRELVM vm)
{
RootTable(vm)
.Bind(_SC("Log"), Table(vm)
.Bind(_SC("SqLog"), Table(vm)
.SquirrelFunc(_SC("Dbg"), &LogBasicMessage< LL_DBG, false >)
.SquirrelFunc(_SC("Usr"), &LogBasicMessage< LL_USR, false >)
.SquirrelFunc(_SC("Scs"), &LogBasicMessage< LL_SCS, false >)

View File

@ -36,6 +36,7 @@ extern void Register_Entity(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
extern void Register_Hash(HSQUIRRELVM vm);
extern void Register_INI(HSQUIRRELVM vm);
extern void Register_IRC(HSQUIRRELVM vm);
extern void Register_Numeric(HSQUIRRELVM vm);
extern void Register_Random(HSQUIRRELVM vm);
extern void Register_SQLite(HSQUIRRELVM vm);
@ -81,6 +82,7 @@ bool RegisterAPI(HSQUIRRELVM vm)
Register_Hash(vm);
Register_INI(vm);
Register_IRC(vm);
Register_Random(vm);
Register_Numeric(vm);
//Register_SQLite(vm);

View File

@ -15,6 +15,62 @@ Routine::Time Routine::s_Prev = 0;
Routine::Queue Routine::s_Queue;
Routine::Buckets Routine::s_Buckets;
// ------------------------------------------------------------------------------------------------
void Routine::Process()
{
s_Lock = false; /* In case an exception prevented the unlock last time */
if (!s_Queue.empty())
{
for (Queue::iterator itr = s_Queue.begin(); itr != s_Queue.end(); ++itr)
{
if (itr->first && itr->second)
itr->second->Attach();
else if (itr->second)
itr->second->Terminate();
}
s_Queue.clear();
}
// Is this the first call?
if (s_Last == 0)
{
s_Last = GetCurrentSysTime();
return;
}
s_Lock = true;
s_Prev = s_Last;
s_Last = GetCurrentSysTime();
Int32 delta = Int32((s_Last - s_Prev) / 1000L);
for (Buckets::iterator bucket = s_Buckets.begin(); bucket != s_Buckets.end(); ++bucket)
{
bucket->mElapsed += delta;
if (bucket->mElapsed < bucket->mInterval)
continue;
Routines::iterator itr = bucket->mRoutines.begin();
Routines::iterator end = bucket->mRoutines.end();
for (; itr != end; ++itr)
(*itr)->Execute();
bucket->mElapsed = 0;
}
s_Lock = false;
}
// ------------------------------------------------------------------------------------------------
void Routine::TerminateAll()
{
for (Buckets::iterator bucket = s_Buckets.begin(); bucket != s_Buckets.end(); ++bucket)
{
Routines::iterator itr = bucket->mRoutines.begin();
Routines::iterator end = bucket->mRoutines.end();
for (; itr != end; ++itr)
{
(*itr)->Release();
(*itr)->m_Terminated = true;
}
}
// Clear all references
s_Buckets.clear();
}
// ------------------------------------------------------------------------------------------------
Routine::Routine(Object & env, Function & func, Interval interval)
: m_Iterations(0)
@ -24,7 +80,7 @@ Routine::Routine(Object & env, Function & func, Interval interval)
, m_Terminated(false)
, m_Callback(env.GetVM(), env, func.GetFunc())
{
/* ... */
Create();
}
Routine::Routine(Object & env, Function & func, Interval interval, Iterate iterations)
@ -142,6 +198,7 @@ void Routine::Terminate()
{
Detach();
Release();
m_Terminated = true;
}
}
@ -298,7 +355,7 @@ void Routine::Release()
if (m_Terminated)
return;
m_Terminated = true;
m_Callback.Release2();
m_Callback.ReleaseGently();
m_Arg1.Release();
m_Arg2.Release();
m_Arg3.Release();
@ -426,55 +483,20 @@ void Routine::Execute()
}
// ------------------------------------------------------------------------------------------------
void Routine::Process()
/* ------------------------------------------------------------------------------------------------
* Forward the call to process routines.
*/
void ProcessRoutine()
{
s_Lock = false; /* In case an exception prevented the unlock last time */
if (!s_Queue.empty())
{
for (Queue::iterator itr = s_Queue.begin(); itr != s_Queue.end(); ++itr)
{
if (itr->first && itr->second)
itr->second->Attach();
else if (itr->second)
itr->second->Terminate();
}
s_Queue.clear();
}
// Is this the first call?
if (s_Last == 0)
{
s_Last = GetCurrentSysTime();
return;
}
s_Lock = true;
s_Prev = s_Last;
s_Last = GetCurrentSysTime();
Int32 delta = Int32((s_Last - s_Prev) / 1000L);
for (Buckets::iterator bucket = s_Buckets.begin(); bucket != s_Buckets.end(); ++bucket)
{
bucket->mElapsed += delta;
if (bucket->mElapsed < bucket->mInterval)
continue;
Routines::iterator itr = bucket->mRoutines.begin();
Routines::iterator end = bucket->mRoutines.end();
for (; itr != end; ++itr)
(*itr)->Execute();
bucket->mElapsed = 0;
}
s_Lock = false;
Routine::Process();
}
// ------------------------------------------------------------------------------------------------
void Routine::Cleanup()
/* ------------------------------------------------------------------------------------------------
* Forward the call to terminate routines.
*/
void TerminateRoutine()
{
for (Buckets::iterator bucket = s_Buckets.begin(); bucket != s_Buckets.end(); ++bucket)
{
Routines::iterator itr = bucket->mRoutines.begin();
Routines::iterator end = bucket->mRoutines.end();
for (; itr != end; ++itr)
(*itr)->Release();
}
Routine::TerminateAll();
}
// ================================================================================================

View File

@ -25,6 +25,16 @@ public:
typedef Uint32 Iterate;
typedef std::vector< Routine * > Routines;
/* --------------------------------------------------------------------------------------------
* Process all active routines and update elapsed time.
*/
static void Process();
/* --------------------------------------------------------------------------------------------
* Release all resources and prepare for shutdown.
*/
static void TerminateAll();
protected:
/* --------------------------------------------------------------------------------------------
@ -117,6 +127,8 @@ protected:
static Queue s_Queue; /* Actions to be performed when the buckets aren't locked */
static Buckets s_Buckets; /* Buckets of routines grouped by similar intervals. */
private:
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
@ -127,6 +139,24 @@ protected:
*/
Routine & operator = (const Routine &);
private:
// --------------------------------------------------------------------------------------------
Iterate m_Iterations; /* Number of iterations before self destruct. */
Interval m_Interval; /* Interval between calls. */
Uint8 m_Arguments; /* Number of arguments to forward. */
bool m_Suspended; /* Whether calls should be ignored. */
bool m_Terminated; /* Whether the routine was terminated. */
// --------------------------------------------------------------------------------------------
Function m_Callback; /* The callback to be executed when triggered. */
/* --------------------------------------------------------------------------------------------
* Arguments to be forwarded to the callback.
*/
Object m_Arg1, m_Arg2, m_Arg3, m_Arg4, m_Arg5, m_Arg6, m_Arg7,
m_Arg8, m_Arg9, m_Arg10, m_Arg11, m_Arg12, m_Arg13, m_Arg14;
public:
/* --------------------------------------------------------------------------------------------
@ -280,36 +310,6 @@ protected:
* Execute the binded callback.
*/
void Execute();
private:
// --------------------------------------------------------------------------------------------
Iterate m_Iterations; /* Number of iterations before self destruct. */
Interval m_Interval; /* Interval between calls. */
Uint8 m_Arguments; /* Number of arguments to forward. */
bool m_Suspended; /* Whether calls should be ignored. */
bool m_Terminated; /* Whether the routine was terminated. */
// --------------------------------------------------------------------------------------------
Function m_Callback; /* The callback to be executed when triggered. */
/* --------------------------------------------------------------------------------------------
* Arguments to be forwarded to the callback.
*/
Object m_Arg1, m_Arg2, m_Arg3, m_Arg4, m_Arg5, m_Arg6, m_Arg7,
m_Arg8, m_Arg9, m_Arg10, m_Arg11, m_Arg12, m_Arg13, m_Arg14;
public:
/* --------------------------------------------------------------------------------------------
* Process all active routines and update elapsed time.
*/
static void Process();
/* --------------------------------------------------------------------------------------------
* Release all resources and prepare for shutdown.
*/
static void Cleanup();
};
} // Namespace:: SqMod