2018-01-04 16:14:14 +11:00
|
|
|
#ifndef NATIVE_SCRIPT_MGR_H
|
|
|
|
#define NATIVE_SCRIPT_MGR_H
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
#include <unordered_map>
|
2017-12-12 17:29:31 +11:00
|
|
|
#include <set>
|
2017-12-14 22:30:06 +11:00
|
|
|
#include <queue>
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
2017-12-18 12:36:52 +01:00
|
|
|
#include <common/Crypt/md5.h>
|
2017-12-10 01:52:03 +11:00
|
|
|
|
2017-12-10 15:31:48 +11:00
|
|
|
#include "ScriptLoader.h"
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
namespace Core {
|
2017-12-12 14:57:13 +11:00
|
|
|
namespace Scripting {
|
|
|
|
|
2017-12-13 15:07:03 +11:00
|
|
|
class NativeScriptManager
|
2017-12-12 14:57:13 +11:00
|
|
|
{
|
|
|
|
protected:
|
2018-01-17 20:09:16 +11:00
|
|
|
std::unordered_map< std::size_t, std::unordered_map< uint32_t, ScriptObject* > > m_scripts;
|
2017-12-12 14:57:13 +11:00
|
|
|
|
|
|
|
ScriptLoader m_loader;
|
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
std::queue< std::string > m_scriptLoadQueue;
|
|
|
|
|
2017-12-14 13:23:59 +11:00
|
|
|
bool unloadScript( ScriptInfo* info );
|
|
|
|
|
2017-12-12 14:57:13 +11:00
|
|
|
public:
|
2018-01-04 16:14:14 +11:00
|
|
|
NativeScriptManager( ) = default;
|
2017-12-12 14:57:13 +11:00
|
|
|
|
|
|
|
bool loadScript( const std::string& path );
|
|
|
|
bool unloadScript( const std::string& name );
|
2017-12-14 23:05:53 +11:00
|
|
|
void queueScriptReload( const std::string& name );
|
2017-12-12 17:29:31 +11:00
|
|
|
void findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search );
|
2017-12-12 14:57:13 +11:00
|
|
|
|
2017-12-14 22:30:06 +11:00
|
|
|
void processLoadQueue();
|
|
|
|
|
2017-12-12 14:57:13 +11:00
|
|
|
const std::string getModuleExtension();
|
2017-12-14 22:30:06 +11:00
|
|
|
bool isModuleLoaded( const std::string& name );
|
2017-12-12 14:57:13 +11:00
|
|
|
|
2018-01-04 16:14:14 +11:00
|
|
|
// todo: use some template magic (type_traits is_same?) to avoid ScriptType param
|
|
|
|
// not sure if worthwhile given that it adds an extra place where script types need to be managed
|
|
|
|
template< typename T >
|
2018-01-17 20:09:16 +11:00
|
|
|
T* getScript( uint32_t scriptId )
|
2017-12-12 14:57:13 +11:00
|
|
|
{
|
2018-01-17 20:09:16 +11:00
|
|
|
auto type = typeid( T ).hash_code();
|
|
|
|
|
2018-01-04 22:40:48 +11:00
|
|
|
auto script = m_scripts[type].find( scriptId );
|
|
|
|
if( script == m_scripts[type].end() )
|
2018-01-04 16:14:14 +11:00
|
|
|
return nullptr;
|
|
|
|
|
2018-01-04 22:24:13 +11:00
|
|
|
return dynamic_cast< T* >( script->second );
|
2017-12-12 14:57:13 +11:00
|
|
|
}
|
|
|
|
};
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-13 15:07:03 +11:00
|
|
|
boost::shared_ptr< NativeScriptManager > createNativeScriptMgr();
|
2017-12-12 14:57:13 +11:00
|
|
|
} }
|
2017-12-10 01:52:03 +11:00
|
|
|
|
|
|
|
|
2017-12-18 12:36:52 +01:00
|
|
|
#endif
|