mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 22:56:40 +00:00 
			
		
		
		
	added missing part of global variable implementation (storage and interpreter context)
This commit is contained in:
		
							parent
							
								
									c3c16facbf
								
							
						
					
					
						commit
						df8f8a315c
					
				
					 3 changed files with 41 additions and 6 deletions
				
			
		|  | @ -4,6 +4,8 @@ | |||
| #include <stdexcept> | ||||
| #include <iostream> | ||||
| 
 | ||||
| #include <components/interpreter/types.hpp> | ||||
| 
 | ||||
| #include "locals.hpp" | ||||
| #include "../mwworld/world.hpp" | ||||
| 
 | ||||
|  | @ -78,32 +80,44 @@ namespace MWScript | |||
|      | ||||
|     int InterpreterContext::getGlobalShort (const std::string& name) const | ||||
|     { | ||||
|         return 0; | ||||
|         Interpreter::Type_Data value = mEnvironment.mWorld->getGlobalVariable (name);        | ||||
|         return static_cast<Interpreter::Type_Short> ( | ||||
|             *reinterpret_cast<Interpreter::Type_Integer *> (&value)); | ||||
|     } | ||||
| 
 | ||||
|     int InterpreterContext::getGlobalLong (const std::string& name) const | ||||
|     { | ||||
|         return 0; | ||||
|         // a global long is internally a float.
 | ||||
|         Interpreter::Type_Data value = mEnvironment.mWorld->getGlobalVariable (name);        | ||||
|         return static_cast<Interpreter::Type_Integer> ( | ||||
|             *reinterpret_cast<Interpreter::Type_Float *> (&value)); | ||||
|     } | ||||
| 
 | ||||
|     float InterpreterContext::getGlobalFloat (const std::string& name) const | ||||
|     { | ||||
|         return 0; | ||||
|         Interpreter::Type_Data value = mEnvironment.mWorld->getGlobalVariable (name);        | ||||
|         return *reinterpret_cast<Interpreter::Type_Float *> (&value); | ||||
|     } | ||||
| 
 | ||||
|     void InterpreterContext::setGlobalShort (const std::string& name, int value) | ||||
|     { | ||||
|      | ||||
|          mEnvironment.mWorld->getGlobalVariable (name) = | ||||
|             *reinterpret_cast<Interpreter::Type_Data *> (&value); | ||||
|     } | ||||
| 
 | ||||
|     void InterpreterContext::setGlobalLong (const std::string& name, int value) | ||||
|     { | ||||
|      | ||||
|         // a global long is internally a float.
 | ||||
|         float value2 = value; | ||||
| 
 | ||||
|          mEnvironment.mWorld->getGlobalVariable (name) = | ||||
|             *reinterpret_cast<Interpreter::Type_Data *> (&value2);     | ||||
|     } | ||||
| 
 | ||||
|     void InterpreterContext::setGlobalFloat (const std::string& name, float value) | ||||
|     { | ||||
|      | ||||
|          mEnvironment.mWorld->getGlobalVariable (name) = | ||||
|             *reinterpret_cast<Interpreter::Type_Data *> (&value);     | ||||
|     } | ||||
|                  | ||||
|     MWWorld::World& InterpreterContext::getWorld() | ||||
|  |  | |||
|  | @ -72,6 +72,12 @@ namespace MWWorld | |||
|         mInteriors[startCell].loadInt (startCell, mStore, mEsm); | ||||
|          | ||||
|         insertInteriorScripts (mInteriors[startCell]); | ||||
| 
 | ||||
|         // global variables
 | ||||
|         for (ESMS::RecListT<ESM::Global>::MapType::const_iterator iter | ||||
|             (mStore.globals.list.begin());  | ||||
|             iter != mStore.globals.list.end(); ++iter) | ||||
|             mGlobalVariables.insert (std::make_pair (iter->first, iter->second.value)); | ||||
|          | ||||
|         std::cout << "\nSetting up cell rendering\n"; | ||||
| 
 | ||||
|  | @ -123,4 +129,14 @@ namespace MWWorld | |||
|         // Cell change not implemented yet.
 | ||||
|         return false; | ||||
|     } | ||||
|      | ||||
|     Interpreter::Type_Data& World::getGlobalVariable (const std::string& name) | ||||
|     { | ||||
|         std::map<std::string, Interpreter::Type_Data>::iterator iter = mGlobalVariables.find (name); | ||||
|          | ||||
|         if (iter==mGlobalVariables.end()) | ||||
|             throw std::runtime_error ("unknown global variable: " + name); | ||||
|              | ||||
|         return iter->second; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -8,6 +8,8 @@ | |||
| 
 | ||||
| #include <components/esm_store/cell_store.hpp> | ||||
| 
 | ||||
| #include <components/interpreter/types.hpp> | ||||
| 
 | ||||
| #include "../mwrender/playerpos.hpp" | ||||
| #include "../mwrender/mwscene.hpp" | ||||
| 
 | ||||
|  | @ -49,6 +51,7 @@ namespace MWWorld | |||
|             ESMS::ESMStore mStore; | ||||
|             std::map<std::string, CellStore> mInteriors; | ||||
|             ScriptList mLocalScripts; | ||||
|             std::map<std::string, Interpreter::Type_Data> mGlobalVariables; | ||||
|      | ||||
|             // not implemented
 | ||||
|             World (const World&); | ||||
|  | @ -72,6 +75,8 @@ namespace MWWorld | |||
|              | ||||
|             bool hasCellChanged() const; | ||||
|             ///< Has the player moved to a different cell, since the last frame?
 | ||||
|              | ||||
|             Interpreter::Type_Data& getGlobalVariable (const std::string& name); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue