mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-31 09:57:14 +01:00
Use unordered maps for storing script instances and options.
Also update some of the code to use braces even for single statements.
This commit is contained in:
parent
886e525119
commit
216ac8bbc0
@ -113,7 +113,9 @@ Core::~Core()
|
|||||||
bool Core::Init()
|
bool Core::Init()
|
||||||
{
|
{
|
||||||
if (cLogWrn(m_VM, "Already initialized"))
|
if (cLogWrn(m_VM, "Already initialized"))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
LogDbg("Resizing the entity containers");
|
LogDbg("Resizing the entity containers");
|
||||||
// Make sure the entity containers have the proper size
|
// Make sure the entity containers have the proper size
|
||||||
@ -172,9 +174,13 @@ bool Core::Init()
|
|||||||
Ulong num = conf.GetLongValue("Config", "StackSize", SQMOD_STACK_SIZE);
|
Ulong num = conf.GetLongValue("Config", "StackSize", SQMOD_STACK_SIZE);
|
||||||
// Make sure that the retrieved number is within range
|
// Make sure that the retrieved number is within range
|
||||||
if (!num)
|
if (!num)
|
||||||
|
{
|
||||||
throw std::out_of_range("stack size too small");
|
throw std::out_of_range("stack size too small");
|
||||||
|
}
|
||||||
else if (num >= std::numeric_limits< Uint16 >::max())
|
else if (num >= std::numeric_limits< Uint16 >::max())
|
||||||
|
{
|
||||||
throw std::out_of_range("stack size too big");
|
throw std::out_of_range("stack size too big");
|
||||||
|
}
|
||||||
// Save the port number
|
// Save the port number
|
||||||
stack_size = static_cast< Uint16 >(num);
|
stack_size = static_cast< Uint16 >(num);
|
||||||
}
|
}
|
||||||
@ -226,7 +232,9 @@ bool Core::Init()
|
|||||||
LogDbg("Registering the plug-in API");
|
LogDbg("Registering the plug-in API");
|
||||||
// Attempt to register the plugin API
|
// Attempt to register the plugin API
|
||||||
if (cLogFtl(!RegisterAPI(m_VM), "Unable to register the plug-in API"))
|
if (cLogFtl(!RegisterAPI(m_VM), "Unable to register the plug-in API"))
|
||||||
|
{
|
||||||
return false; // Can't execute scripts without a valid API!
|
return false; // Can't execute scripts without a valid API!
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to retrieve the list of strings specified in the config
|
// Attempt to retrieve the list of strings specified in the config
|
||||||
CSimpleIniA::TNamesDepend scripts;
|
CSimpleIniA::TNamesDepend scripts;
|
||||||
@ -244,9 +252,11 @@ bool Core::Init()
|
|||||||
scripts.sort(CSimpleIniA::Entry::LoadOrder());
|
scripts.sort(CSimpleIniA::Entry::LoadOrder());
|
||||||
// Process each specified script paths
|
// Process each specified script paths
|
||||||
for (const auto & script : scripts)
|
for (const auto & script : scripts)
|
||||||
|
{
|
||||||
// Attempt to queue the specified script path for loading
|
// Attempt to queue the specified script path for loading
|
||||||
LoadScript(script.pItem);
|
LoadScript(script.pItem);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// See if any script could be queued for loading
|
// See if any script could be queued for loading
|
||||||
if (m_Scripts.empty() && !conf.GetBoolValue("Config", "EmptyInit", false))
|
if (m_Scripts.empty() && !conf.GetBoolValue("Config", "EmptyInit", false))
|
||||||
{
|
{
|
||||||
@ -266,33 +276,53 @@ bool Core::Init()
|
|||||||
CSimpleIniA::TNamesDepend values;
|
CSimpleIniA::TNamesDepend values;
|
||||||
// Get the values of all keys with the same name
|
// Get the values of all keys with the same name
|
||||||
if (!conf.GetAllValues("Options", option.pItem, values))
|
if (!conf.GetAllValues("Options", option.pItem, values))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
// Sort the keys in their original order
|
// Sort the keys in their original order
|
||||||
values.sort(CSimpleIniA::Entry::LoadOrder());
|
values.sort(CSimpleIniA::Entry::LoadOrder());
|
||||||
// Save each option option and overwrite existing value
|
// Save each option option and overwrite existing value
|
||||||
for (const auto & value : values)
|
for (const auto & value : values)
|
||||||
|
{
|
||||||
m_Options[option.pItem] = value.pItem;
|
m_Options[option.pItem] = value.pItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
LogInf("No options specified in the configuration file");
|
LogInf("No options specified in the configuration file");
|
||||||
|
}
|
||||||
|
|
||||||
LogDbg("Applying the specified logging filters");
|
LogDbg("Applying the specified logging filters");
|
||||||
// Apply the specified logging filters only after initialization was completed
|
// Apply the specified logging filters only after initialization was completed
|
||||||
if (!conf.GetBoolValue("Log", "Debug", true))
|
if (!conf.GetBoolValue("Log", "Debug", true))
|
||||||
|
{
|
||||||
_Log->DisableLevel(LL_DBG);
|
_Log->DisableLevel(LL_DBG);
|
||||||
|
}
|
||||||
if (!conf.GetBoolValue("Log", "User", true))
|
if (!conf.GetBoolValue("Log", "User", true))
|
||||||
|
{
|
||||||
_Log->DisableLevel(LL_USR);
|
_Log->DisableLevel(LL_USR);
|
||||||
|
}
|
||||||
if (!conf.GetBoolValue("Log", "Success", true))
|
if (!conf.GetBoolValue("Log", "Success", true))
|
||||||
|
{
|
||||||
_Log->DisableLevel(LL_SCS);
|
_Log->DisableLevel(LL_SCS);
|
||||||
|
}
|
||||||
if (!conf.GetBoolValue("Log", "Info", true))
|
if (!conf.GetBoolValue("Log", "Info", true))
|
||||||
|
{
|
||||||
_Log->DisableLevel(LL_INF);
|
_Log->DisableLevel(LL_INF);
|
||||||
|
}
|
||||||
if (!conf.GetBoolValue("Log", "Warning", true))
|
if (!conf.GetBoolValue("Log", "Warning", true))
|
||||||
|
{
|
||||||
_Log->DisableLevel(LL_WRN);
|
_Log->DisableLevel(LL_WRN);
|
||||||
|
}
|
||||||
if (!conf.GetBoolValue("Log", "Error", true))
|
if (!conf.GetBoolValue("Log", "Error", true))
|
||||||
|
{
|
||||||
_Log->DisableLevel(LL_ERR);
|
_Log->DisableLevel(LL_ERR);
|
||||||
|
}
|
||||||
if (!conf.GetBoolValue("Log", "Fatal", true))
|
if (!conf.GetBoolValue("Log", "Fatal", true))
|
||||||
|
{
|
||||||
_Log->DisableLevel(LL_FTL);
|
_Log->DisableLevel(LL_FTL);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialization successful
|
// Initialization successful
|
||||||
return true;
|
return true;
|
||||||
@ -422,16 +452,22 @@ bool Core::LoadScript(CSStr filepath)
|
|||||||
{
|
{
|
||||||
// Is the specified path empty?
|
// Is the specified path empty?
|
||||||
if (!filepath || *filepath == 0)
|
if (!filepath || *filepath == 0)
|
||||||
|
{
|
||||||
return false; // Simply ignore it
|
return false; // Simply ignore it
|
||||||
|
}
|
||||||
// Get the file path as a string
|
// Get the file path as a string
|
||||||
String path(filepath);
|
String path(filepath);
|
||||||
// See if it wasn't already loaded
|
// See if it wasn't already loaded
|
||||||
if (m_Scripts.find(path) != m_Scripts.end())
|
if (m_Scripts.find(path) != m_Scripts.end())
|
||||||
|
{
|
||||||
LogWrn("Script was specified before: %s", path.c_str());
|
LogWrn("Script was specified before: %s", path.c_str());
|
||||||
|
}
|
||||||
// We don't compile the scripts yet. We just store their path and prepare the objects.
|
// We don't compile the scripts yet. We just store their path and prepare the objects.
|
||||||
else
|
else
|
||||||
|
{
|
||||||
// Create a new script container and insert it into the script pool
|
// Create a new script container and insert it into the script pool
|
||||||
m_Scripts.emplace(std::move(path), Script(m_VM));
|
m_Scripts.emplace(std::move(path), Script(m_VM));
|
||||||
|
}
|
||||||
// At this point the script exists in the pool
|
// At this point the script exists in the pool
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <unordered_map>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
@ -20,7 +20,7 @@ namespace SqMod {
|
|||||||
extern SQMOD_MANAGEDPTR_TYPE(Core) _Core;
|
extern SQMOD_MANAGEDPTR_TYPE(Core) _Core;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* ...
|
* Core module class responsible for managing resources.
|
||||||
*/
|
*/
|
||||||
class Core
|
class Core
|
||||||
{
|
{
|
||||||
@ -413,8 +413,8 @@ public:
|
|||||||
typedef VehicleTrack VehicleInstTrack[SQMOD_VEHICLE_POOL];
|
typedef VehicleTrack VehicleInstTrack[SQMOD_VEHICLE_POOL];
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
typedef std::map< String, Script > Scripts;
|
typedef std::unordered_map< String, Script > Scripts;
|
||||||
typedef std::map< String, String > Options;
|
typedef std::unordered_map< String, String > Options;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user