mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-29 03:26:38 +00:00 
			
		
		
		
	Merge branch 'getsquareroot' into 'master'
Remove duplicate GetSquareRoot implementation See merge request OpenMW/openmw!1231
This commit is contained in:
		
						commit
						15bcbb5844
					
				
					 10 changed files with 19 additions and 65 deletions
				
			
		|  | @ -864,6 +864,9 @@ namespace MWScript | |||
|                     float param = runtime[0].mFloat; | ||||
|                     runtime.pop(); | ||||
| 
 | ||||
|                     if (param < 0) | ||||
|                         throw std::runtime_error("square root of negative number (we aren't that imaginary)"); | ||||
| 
 | ||||
|                     runtime.push(std::sqrt (param)); | ||||
|                 } | ||||
|         }; | ||||
|  |  | |||
|  | @ -420,21 +420,6 @@ namespace Compiler | |||
|         } | ||||
| 
 | ||||
|         if (mNextOperand) | ||||
|         { | ||||
|             if (keyword==Scanner::K_getsquareroot) | ||||
|             { | ||||
|                 start(); | ||||
| 
 | ||||
|                 mTokenLoc = loc; | ||||
|                 parseArguments ("f", scanner); | ||||
| 
 | ||||
|                 Generator::squareRoot (mCode); | ||||
|                 mOperands.push_back ('f'); | ||||
| 
 | ||||
|                 mNextOperand = false; | ||||
|                 return true; | ||||
|             } | ||||
|             else | ||||
|         { | ||||
|             // check for custom extensions
 | ||||
|             if (const Extensions *extensions = getContext().getExtensions()) | ||||
|  | @ -459,7 +444,6 @@ namespace Compiler | |||
|                 } | ||||
|             } | ||||
|         } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             // no comma was used between arguments
 | ||||
|  |  | |||
|  | @ -104,11 +104,6 @@ namespace | |||
|         code.push_back (Compiler::Generator::segment5 (17)); | ||||
|     } | ||||
| 
 | ||||
|     void opSquareRoot (Compiler::Generator::CodeContainer& code) | ||||
|     { | ||||
|         code.push_back (Compiler::Generator::segment5 (19)); | ||||
|     } | ||||
| 
 | ||||
|     void opReturn (Compiler::Generator::CodeContainer& code) | ||||
|     { | ||||
|         code.push_back (Compiler::Generator::segment5 (20)); | ||||
|  | @ -452,11 +447,6 @@ namespace Compiler::Generator | |||
|             } | ||||
|         } | ||||
| 
 | ||||
|         void squareRoot (CodeContainer& code) | ||||
|         { | ||||
|             opSquareRoot (code); | ||||
|         } | ||||
| 
 | ||||
|         void exit (CodeContainer& code) | ||||
|         { | ||||
|             opReturn (code); | ||||
|  |  | |||
|  | @ -74,8 +74,6 @@ namespace Compiler | |||
| 
 | ||||
|         void convert (CodeContainer& code, char fromType, char toType); | ||||
| 
 | ||||
|         void squareRoot (CodeContainer& code); | ||||
| 
 | ||||
|         void exit (CodeContainer& code); | ||||
| 
 | ||||
|         void message (CodeContainer& code, Literals& literals, const std::string& message, | ||||
|  |  | |||
|  | @ -265,7 +265,6 @@ namespace Compiler | |||
|         "return", | ||||
|         "messagebox", | ||||
|         "set", "to", | ||||
|         "getsquareroot", | ||||
|         nullptr | ||||
|     }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -205,8 +205,7 @@ namespace Compiler | |||
|                 K_while, K_endwhile, | ||||
|                 K_return, | ||||
|                 K_messagebox, | ||||
|                 K_set, K_to, | ||||
|                 K_getsquareroot | ||||
|                 K_set, K_to | ||||
|             }; | ||||
| 
 | ||||
|             enum special | ||||
|  |  | |||
|  | @ -63,7 +63,7 @@ namespace Compiler | |||
|             keyword==Scanner::K_elseif || keyword==Scanner::K_while || | ||||
|             keyword==Scanner::K_endwhile || keyword==Scanner::K_return || | ||||
|             keyword==Scanner::K_messagebox || keyword==Scanner::K_set || | ||||
|             keyword==Scanner::K_to || keyword==Scanner::K_getsquareroot) | ||||
|             keyword==Scanner::K_to) | ||||
|         { | ||||
|             // pretend this is not a keyword
 | ||||
|             std::string name = loc.mLiteral; | ||||
|  |  | |||
|  | @ -77,7 +77,7 @@ op  15: div (integer) stack[1] by stack[0], pop twice, push result | |||
| op  16: div (float) stack[1] by stack[0], pop twice, push result | ||||
| op  17: convert stack[1] from integer to float | ||||
| op  18: convert stack[1] from float to integer | ||||
| op  19: take square root of stack[0] (float) | ||||
| opcode 19 unused | ||||
| op  20: return | ||||
| op  21: replace stack[0] with local short stack[0] | ||||
| op  22: replace stack[0] with local long stack[0] | ||||
|  |  | |||
|  | @ -59,7 +59,6 @@ namespace Interpreter | |||
|         interpreter.installSegment5 (14, new OpMulInt<Type_Float>); | ||||
|         interpreter.installSegment5 (15, new OpDivInt<Type_Integer>); | ||||
|         interpreter.installSegment5 (16, new OpDivInt<Type_Float>); | ||||
|         interpreter.installSegment5 (19, new OpSquareRoot); | ||||
|         interpreter.installSegment5 (26, | ||||
|             new OpCompare<Type_Integer, std::equal_to<Type_Integer> >); | ||||
|         interpreter.installSegment5 (27, | ||||
|  |  | |||
|  | @ -74,24 +74,6 @@ namespace Interpreter | |||
|             }            | ||||
|     }; | ||||
|      | ||||
|     class OpSquareRoot : public Opcode0 | ||||
|     { | ||||
|         public: | ||||
|          | ||||
|             void execute (Runtime& runtime) override | ||||
|             { | ||||
|                 Type_Float value = runtime[0].mFloat; | ||||
|                  | ||||
|                 if (value<0) | ||||
|                     throw std::runtime_error ( | ||||
|                         "square root of negative number (we aren't that imaginary)"); | ||||
|                  | ||||
|                 value = std::sqrt (value); | ||||
|                  | ||||
|                 runtime[0].mFloat = value; | ||||
|             }            | ||||
|     };     | ||||
|      | ||||
|     template<typename T, typename C> | ||||
|     class OpCompare : public Opcode0 | ||||
|     { | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue