1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-22 04:37:13 +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 // Attempt to load and compile the script file
try try
{ {
s.second.CompileFile(s.first); s.mExec.CompileFile(s.mPath);
} }
catch (const Sqrat::Exception & e) 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 // Failed to executed properly
return false; return false;
} }
// Attempt to execute the compiled script code // Attempt to execute the compiled script code
try try
{ {
s.second.Run(); s.mExec.Run();
} }
catch (const Sqrat::Exception & e) 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 // Failed to executed properly
return false; return false;
} }
// At this point the script should be completely loaded // 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 // Import already existing entities
@ -357,7 +357,6 @@ void Core::Terminate()
m_Objects.clear(); m_Objects.clear();
m_Pickups.clear(); m_Pickups.clear();
m_Checkpoints.clear(); m_Checkpoints.clear();
m_Scripts.clear();
// Release all resources from routines // Release all resources from routines
TerminateRoutines(); TerminateRoutines();
// Release all resources from command manager // Release all resources from command manager
@ -442,7 +441,9 @@ bool Core::LoadScript(CSStr filepath)
// 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 (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()); LogWrn("Script was specified before: %s", path.c_str());
} }
@ -450,7 +451,7 @@ bool Core::LoadScript(CSStr filepath)
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_back(m_VM, path, false);
} }
// At this point the script exists in the pool // At this point the script exists in the pool
return true; return true;

View File

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