Advertisement
Guest User

Untitled

a guest
Jun 7th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. //Please forgive some of the spacing.//
  2.  
  3. //These are all classes I plan to have in my application.//
  4.  
  5. //Application name = White - Storm: Lightning.//
  6. struct WSLObject {
  7.     //Stuff...//
  8. };
  9. //Part of the "solution".//
  10. struct BaseCastOperation {
  11.     virtual void DoCastOperation( WSLObject* operationRecipiant ) = 0;
  12.     //For arbitrary and possibly nessisary information.//
  13.     std::string info;
  14. };
  15.                
  16. struct ScriptingLanguage
  17. {
  18.     std::string fileType;
  19.     static std::string GetExtension( std::string scriptFileName ) = 0;
  20.     virtual void RunScript( std::string scriptFile ) = 0;
  21.     //Stuff...//
  22. };
  23.  
  24. class BaseEntity : public WSLObject
  25. {
  26.     protected:
  27.         /*Yes, yes I know this is suppose to be
  28.         implementation level.*/
  29.         std::vector<ScriptingLangauge*> scriptingLanguages;
  30.         std::vector<BaseCastOperation*> scriptTranslators; /*The purpose of these
  31.         objects
  32.         will be to take an Entity, cast it into its derived type, then "send it" (set
  33.         it as a global) to the script, why so many? So any scripting language that
  34.         can fit this functionality in-to one method can be used in the engine. Other
  35.         scripting classes will exist. This functionality will also allow for more
  36.         extensibility in the engine as in terms of what you can do with the
  37.         core-framework, and have all "senders" you need be applicable to all objects
  38.         anywhere in the hierarchy.*/
  39.                        
  40.         //All the scripts that will be run (file names/directories).//
  41.         std::string, init, ref, oth, des;
  42.         //Stuff...//
  43.     public:
  44.         virtual void Initialize() = 0;
  45.         virtual void Refresh() = 0;
  46.         virtual void Other() = 0;
  47.         virtual void Destroy() = 0;
  48.         //More stuff...//
  49. };
  50.  
  51. //Make sure it is consistent through the engine.//
  52. static const std::string globalObjectName = "object";
  53.  
  54. template< typename T >
  55. struct LuaSender : public BaseCastOperation
  56. {
  57.     LuaSender() {
  58.         info = ".lua";
  59.     }
  60.     void DoCastOperation( WSLObject* operationRecipiant )
  61.     {
  62.         /*Luabind stuff included luabind::global sets a global
  63.         in Lua, it is picky about type though (I cant send a pointer of type
  64.         BaseEntity that points to an entity, it will be sent as a BaseEntity.*/
  65.         //This is kinda yucky, but necessary... so bare with me...//
  66.         luabind::globals[ globalObjectName ] = dynamic_cast<T>( operationRecipiant );
  67.     }
  68. };
  69.  
  70.  
  71. //Others may include, Python, C#, or even Java-script.//
  72. struct Lua : public ScriptingLanguage
  73. {
  74.     Lua() {
  75.         fileType = ".lua";
  76.     }
  77.     void RunScript( std::string scriptFile ) {
  78.         //<IMPLEMENTATION NOT SHOWN>//
  79.     }
  80.     //Stuff...//
  81. };
  82.  
  83.  
  84. Class Entity : public BaseEntity
  85. {
  86.     //Stuff...//
  87.     public:
  88.         Entity()
  89.         {
  90.             //Stuff...//
  91.             //More "senders" can be added later.//
  92.             scriptTranslators.push_back( new LuaSender<Entity> );
  93.             //More "scripting languages" can be added later.//
  94.             scriptingLangauges.push_back( new Lua );
  95.         }
  96.         //Stuff...//
  97.         void Refresh()
  98.         {
  99.             //Stuff...//
  100.             //Sorry, I just have to put this optimization in there.//
  101.             unsigned int tsize = scriptTranslators.size();
  102.             unsigned int lSize = scriptingLangauages.size();
  103.             bool break_ = true;
  104.             for( unsigned int i = 0; i < tSize && break_; ++i )
  105.             {
  106.                 for( unsigned int j = 0; j < lSize; ++j )
  107.                 {
  108.                     if( ScriptingLanguage::GetExtension( ref ) ==
  109.                         scriptTranslators[i]->info &&
  110.                         ScriptingLanguage::GetExtension( ref ) ==
  111.                         scriptingLangauages[j]->fileType )
  112.                     {
  113.                         //=================================//
  114.                         //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
  115.                         //!!!!!!!!!The main point.!!!!!!!!!//
  116.                         //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
  117.                         //=================================//
  118.                         scriptTranslators[i]->DoCastOperation( this );
  119.                         scriptingLangauages[j]->RunScript( ref );
  120.                         break_ = false;
  121.                         break;
  122.                     }
  123.             }
  124.         }
  125.     }
  126. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement