Sfoglia il codice sorgente

Fix LocalShaderParam access from LUA: Add typed getters and setters for void * field, incidentally re-triggering the 'at least two methods' rule for create_lua_library

mcc 13 anni fa
parent
commit
238a8c5e60
1 ha cambiato i file con 12 aggiunte e 0 eliminazioni
  1. 12 0
      Core/Contents/Include/PolyShader.h

+ 12 - 0
Core/Contents/Include/PolyShader.h

@@ -23,6 +23,8 @@ THE SOFTWARE.
 #pragma once
 #include "PolyString.h"
 #include "PolyGlobals.h"
+#include "PolyColor.h"
+#include "PolyVector2.h"
 #include "PolyVector3.h"
 #include "PolyResource.h"
 #include <string.h>
@@ -102,6 +104,16 @@ namespace Polycode {
 		public:	
 			String name;
 			void *data;
+		
+		// Convenience getters/setters for Lua users
+		Number getNumber()         { return *((Number *)data); }
+		Vector2 getVector2()       { return *((Vector2 *)data); }
+		Vector3 getVector3()       { return *((Vector3 *)data); }
+		Color getColor()           { return *((Color *)data); }
+		void setNumber(Number x)   { memcpy(data, &x, sizeof(x)); }
+		void setVector2(Vector2 x) { memcpy(data, &x, sizeof(x)); }
+		void setVector3(Vector3 x) { memcpy(data, &x, sizeof(x)); }
+		void setColor(Color x)     { memcpy(data, &x, sizeof(x)); }
 	};	
 	
 	class RenderTargetBinding {