Просмотр исходного кода

Lua bindings now return pointer class members. Added an equality operator for Lua classes (you can just use == instead of same_c_class now). Updated examples to reflect new changes. UI scroll bars and tree containers will now set cursor to arrow.

Ivan Safrin 12 лет назад
Родитель
Сommit
ceaad6bee0

+ 6 - 0
Bindings/Contents/LUA/API/class.lua

@@ -13,10 +13,16 @@ function __is_class(c, T)
 	return (c.__classname == T.__classname)
 end
 
+function __are_tables_same_c_class(a,b)
+	return __are_same_c_class(a.__ptr,b.__ptr)
+end
+
 function class(name)
 	local cls = {}
 	cls.__classname = name
 	
+	cls.__eq = __are_tables_same_c_class
+
 	cls.__tostring = function(c)
 		return "Class of type "..c.__classname
 	end

+ 10 - 6
Bindings/Scripts/create_lua_library/create_lua_library.py

@@ -18,7 +18,7 @@ def mkdir_p(path): # Same effect as mkdir -p, create dir and all necessary paren
 def template_returnPtrLookupArray(prefix, className, ptr):
 	out = ""
 	out += "%sfor i=1,count(%s) do\n" % (prefix, ptr)
-	out += "%s\tlocal __c  = _G[%s](\"__skip_ptr__\")\n" % (prefix, className)
+	out += "%s\tlocal __c  = _G[%s](\"__skip_ptr__\")\n" % (prefix, className.replace("*", ""))
 	out += "%s\t__c.__ptr = %s[i]\n" % (prefix, ptr)
 	out += "%s\t%s[i] = __c\n" % (prefix, ptr)
 	out += "%send\n" % (prefix)
@@ -28,7 +28,7 @@ def template_returnPtrLookupArray(prefix, className, ptr):
 # Note we expect className to be a valid string
 def template_returnPtrLookup(prefix, className, ptr):
 	out = ""
-	out += "%slocal __c = _G[%s](\"__skip_ptr__\")\n" % (prefix, className)
+	out += "%slocal __c = _G[%s](\"__skip_ptr__\")\n" % (prefix, className.replace("*", ""))
 	out += "%s__c.__ptr = %s\n" % (prefix, ptr)
 	out += "%sreturn __c\n" % (prefix)
 	return out
@@ -40,7 +40,7 @@ def cleanDocs(docs):
 	return docs.replace("/*", "").replace("*/", "").replace("*", "").replace("\n", "").replace("\r", "").replace("::", ".").replace("\t", "")
 
 def toLuaType(t):
-	return t.replace("void", "nil").replace("int", "Integer").replace("bool", "Boolean")
+	return t.replace("void", "nil").replace("int", "Integer").replace("bool", "Boolean").replace("*", "")
 
 # FIXME: Some "unsigned int *" functions are still being generated on the polycode API?
 def typeFilter(ty):
@@ -236,7 +236,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 							luaDocOut += "\t\t\t</static_member>\n"
 					else: # FIXME: Nonstatic method ? variable ?? found.
 						#there are some bugs in the class parser that cause it to return junk
-						if pp["type"].find("*") == -1 and pp["type"].find("vector") == -1 and pp["name"] != "setScale" and pp["name"] != "setPosition" and pp["name"] != "BUFFER_CACHE_PRECISION" and not pp["name"].isdigit():
+						if pp["type"].find("vector") == -1 and pp["name"] != "setScale" and pp["name"] != "setPosition" and pp["name"] != "BUFFER_CACHE_PRECISION" and not pp["name"].isdigit():
 							classProperties.append(pp)
 
 				luaDocOut += "\t\t</static_members>\n"
@@ -312,8 +312,12 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 							if pp["type"] == "Number" or  pp["type"] == "String" or pp["type"] == "int" or pp["type"] == "bool" or pp["type"] == "PolyKEY":
 								wrappersHeaderOut += "\t%s(L, inst->%s%s);\n" % (outfunc, pp["name"], retFunc)
 							else:
-								wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
-								wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)&inst->%s%s;\n" % (pp["name"], retFunc)
+								if pp["type"].find("*") != -1:
+									wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
+									wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)inst->%s%s;\n" % (pp["name"], retFunc)
+								else:
+									wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
+									wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)&inst->%s%s;\n" % (pp["name"], retFunc)
 							wrappersHeaderOut += "\treturn 1;\n"
 							wrappersHeaderOut += "}\n\n"
 						

+ 1 - 1
Examples/Lua/2D_Physics/2DPhysics_CollisionOnly/Scripts/2DPhysics_CollisionOnly.lua

@@ -13,7 +13,7 @@ end
 
 function onNewCollision(t, event)
 	physicsEvent = safe_cast(event, PhysicsScreenEvent)
-	if same_c_class(physicsEvent:getFirstEntity(),checkShape) or same_c_class(physicsEvent:getSecondEntity(),checkShape) then
+	if physicsEvent.entity1 == checkShape then
 		physicsEvent:getFirstEntity():setColor(1.0, 0.0, 0.0, 1.0)
 		physicsEvent:getSecondEntity():setColor(1.0, 0.0, 0.0, 1.0)
 	end

+ 4 - 4
Examples/Lua/Game_Demos/Platformer/Scripts/Level.lua

@@ -90,10 +90,10 @@ end
 
 function Level:onNewCollision(event)
 	physicsEvent = safe_cast(event, PhysicsScreenEvent)
-	local collidedEntity =  physicsEvent:getSecondEntity()
-	local firstEntity = physicsEvent:getFirstEntity()
+	local collidedEntity =  physicsEvent.entity2
+	local firstEntity = physicsEvent.entity1
 
-	if same_c_class(firstEntity, self.player.groundSensor) then
+	if firstEntity == self.player.groundSensor then
 		if collidedEntity:hasTag("button") then
 			local buttonUp = collidedEntity:getEntityById("button_up", true)
 			local buttonDown = collidedEntity:getEntityById("button_down", true)
@@ -109,7 +109,7 @@ function Level:onNewCollision(event)
 		end
 	end
 
-	if same_c_class(firstEntity, self.player.playerEntity) then
+	if firstEntity == self.player.playerEntity then
 		if collidedEntity:hasTag("coin") and collidedEntity.visible == true then
 			collidedEntity.visible = false
 			self.player.numCoins = self.player.numCoins + 1

BIN
Examples/Lua/Game_Demos/Pong/Resources/polycode_logo.png


+ 2 - 3
Examples/Lua/Game_Demos/Pong/Scripts/Main.lua

@@ -45,10 +45,10 @@ function onCollision(t, event)
 	physicsEvent = cast(event, PhysicsScreenEvent)
 
 	-- check if the colliding entity is the ball
-	if same_c_class(physicsEvent:getFirstEntity(), ball) then
+	if physicsEvent.entity1 == ball then
 
 		-- if colliding with player 1 or player 2 paddle
-		if same_c_class(physicsEvent:getSecondEntity(), p1) or  same_c_class(physicsEvent:getSecondEntity(), p2) then
+		if physicsEvent.entity2 == p1 or physicsEvent.entity2 == p2 then
 
 			-- reverse the horizontal direction
 			ballDirection.x = ballDirection.x * -1 
@@ -120,5 +120,4 @@ function Update(elapsed)
 		p1Score = p1Score + 1
 		p1scoreLabel:setText(""..p1Score)
 	end
-
 end

+ 1 - 1
Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h

@@ -89,7 +89,7 @@ class _PolyExport PhysicsScreenEvent : public Event {
          * Raw Box2d Contact
          */
     
-        b2Contact *contact;
+        b2Contact POLYIGNORE *contact;
 	
         /**
 		* Strength of the collision impact.

+ 3 - 0
Modules/Contents/UI/Source/PolyUITreeContainer.cpp

@@ -68,6 +68,7 @@ UITreeContainer::UITreeContainer(String icon, String text, Number treeWidth, Num
 
 	CoreServices::getInstance()->getCore()->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
 	this->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+	this->addEventListener(this, InputEvent::EVENT_MOUSEOVER);
 	focusable = true;
 	keyNavigable = true;
 }
@@ -94,6 +95,8 @@ void UITreeContainer::handleEvent(Event *event) {
 		if (event->getEventCode() == InputEvent::EVENT_MOUSEDOWN) {
 			if (parentEntity && isFocusable())
 				((ScreenEntity*)parentEntity)->focusChild(this);
+		} else if (event->getEventCode() == InputEvent::EVENT_MOUSEOVER) {
+			CoreServices::getInstance()->getCore()->setCursor(Core::CURSOR_ARROW);
 		}
 	}
 

+ 10 - 1
Modules/Contents/UI/Source/PolyUIVScrollBar.cpp

@@ -26,6 +26,7 @@
 #include "PolyInputEvent.h"
 #include "PolyLabel.h"
 #include "PolyCoreServices.h"
+#include "PolyCore.h"
 
 using namespace Polycode;
 
@@ -48,7 +49,8 @@ UIVScrollBar::UIVScrollBar(Number width, Number height, Number initialRatio) : S
 					  width, height);
 	
 	bgBox->processInputEvents = true;
-	bgBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);		
+	bgBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
+	bgBox->addEventListener(this, InputEvent::EVENT_MOUSEOVER);
 	addChild(bgBox);
 	
 	st = conf->getNumericValue("Polycode", "uiScrollHandleSkinT");
@@ -73,6 +75,7 @@ UIVScrollBar::UIVScrollBar(Number width, Number height, Number initialRatio) : S
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEUP_OUTSIDE);	
 	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);	
+	handleBox->addEventListener(this, InputEvent::EVENT_MOUSEOVER);
 	handleBox->processInputEvents = true;
 	handleBox->blockMouseInput = true;
 	
@@ -173,6 +176,9 @@ void UIVScrollBar::handleEvent(Event *event) {
 	if(event->getDispatcher() == bgBox) {
 		InputEvent *inputEvent = (InputEvent*)event;
 		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEOVER:
+				CoreServices::getInstance()->getCore()->setCursor(Core::CURSOR_ARROW);
+			break;
 			case InputEvent::EVENT_MOUSEDOWN:
 				if(inputEvent->mousePosition.y < handleBox->getPosition().y)  {
 					Number newPos = handleBox->getPosition().y - scrollHandleHeight/2;
@@ -192,6 +198,9 @@ void UIVScrollBar::handleEvent(Event *event) {
 	if(event->getDispatcher() == handleBox) {
 		InputEvent *inputEvent = (InputEvent*)event;
 		switch(event->getEventCode()) {
+			case InputEvent::EVENT_MOUSEOVER:
+				CoreServices::getInstance()->getCore()->setCursor(Core::CURSOR_ARROW);
+			break;		
 			case InputEvent::EVENT_MOUSEUP:
 			case InputEvent::EVENT_MOUSEUP_OUTSIDE:				
 				handleBox->stopDrag();