1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Use the new script loading system to be able to hold script information for future debugging implementations.

Fixes issue with scripts being sorted rather then being executed in the load order.
This commit is contained in:
Sandu Liviu Catalin 2016-06-17 03:28:37 +03:00
parent 2242ac9394
commit c76acc07dc
2 changed files with 13 additions and 9 deletions

View File

@ -301,27 +301,27 @@ bool Core::Execute()
// Attempt to load and compile the script file
try
{
s.second.CompileFile(s.first);
s.mExec.CompileFile(s.mPath);
}
catch (const Sqrat::Exception & e)
{
LogFtl("Unable to compile: %s", s.first.c_str());
LogFtl("Unable to compile: %s", s.mPath.c_str());
// Failed to executed properly
return false;
}
// Attempt to execute the compiled script code
try
{
s.second.Run();
s.mExec.Run();
}
catch (const Sqrat::Exception & e)
{
LogFtl("Unable to execute: %s", s.first.c_str());
LogFtl("Unable to execute: %s", s.mPath.c_str());
// Failed to executed properly
return false;
}
// At this point the script should be completely loaded
LogScs("Successfully executed script: %s", s.first.c_str());
LogScs("Successfully executed script: %s", s.mPath.c_str());
}
// Import already existing entities
@ -357,7 +357,6 @@ void Core::Terminate()
m_Objects.clear();
m_Pickups.clear();
m_Checkpoints.clear();
m_Scripts.clear();
// Release all resources from routines
TerminateRoutines();
// Release all resources from command manager
@ -442,7 +441,9 @@ bool Core::LoadScript(CSStr filepath)
// Get the file path as a string
String path(filepath);
// See if it wasn't already loaded
if (m_Scripts.find(path) != m_Scripts.end())
if (std::find_if(m_Scripts.cbegin(), m_Scripts.cend(), [&path](Scripts::const_reference s) {
return (s.mPath == path);
}) != m_Scripts.end())
{
LogWrn("Script was specified before: %s", path.c_str());
}
@ -450,7 +451,7 @@ bool Core::LoadScript(CSStr filepath)
else
{
// Create a new script container and insert it into the script pool
m_Scripts.emplace(std::move(path), Script(m_VM));
m_Scripts.emplace_back(m_VM, path, false);
}
// At this point the script exists in the pool
return true;

View File

@ -6,6 +6,7 @@
#include "Base/Vector3.hpp"
#include "Base/Quaternion.hpp"
#include "Base/Color4.hpp"
#include "Base/ScriptSrc.hpp"
// ------------------------------------------------------------------------------------------------
#include <vector>
@ -356,7 +357,9 @@ public:
typedef std::vector< VehicleInst > Vehicles;
// --------------------------------------------------------------------------------------------
typedef std::unordered_map< String, Script > Scripts;
typedef std::vector< ScriptSrc > Scripts;
// --------------------------------------------------------------------------------------------
typedef std::unordered_map< String, String > Options;
private: