Browse Source

Various fixes to sync Lua scripting with recent updates

David Wimsey 11 years ago
parent
commit
579dce51f3

+ 8 - 0
Build/CMakeLists.txt

@@ -221,6 +221,14 @@ if(BUILD_LUA_BINDINGS)
                            SOVERSION ${LIBROCKET_VERSION_MAJOR}
                            SOVERSION ${LIBROCKET_VERSION_MAJOR}
         )
         )
         
         
+    if(APPLE)
+	if(NOT IOS)
+    		set_target_properties(${NAME} PROPERTIES
+    						OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_64_BIT)"
+    		)
+	endif(NOT IOS)
+    endif(APPLE)
+
         install(TARGETS ${NAME}
         install(TARGETS ${NAME}
             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

+ 11 - 8
Include/Rocket/Core/Lua/Interpreter.h

@@ -92,17 +92,20 @@ public:
     static lua_State* GetLuaState();
     static lua_State* GetLuaState();
 
 
     /** Creates the plugin. 
     /** Creates the plugin. 
-    @remark Call this function only once. Only call it more than once if you call Interpreter::Shutdown() and need to have this
-    exist again. Internally, it calls Interpreter::Startup() and registers the "body" tag to generate a LuaDocument
-    rather than a Rocket::Core::ElementDocument    */
+	@remark This is equivilent to calling Initialise(NULL).
+      */
     static void Initialise();
     static void Initialise();
-    /** Creates the plugin and adds Rocket to an existing Lua context
+    /** Creates the plugin and adds Rocket to an existing Lua context if one is provided.
 	 @remark Call this function only once, and special care must be taken when destroying the lua_State passed to this method.
 	 @remark Call this function only once, and special care must be taken when destroying the lua_State passed to this method.
 	 Interpreter::Shutdown() calles lua_close on the lua_State pointer provided here, do not call Interpreter::Shutdown if you
 	 Interpreter::Shutdown() calles lua_close on the lua_State pointer provided here, do not call Interpreter::Shutdown if you
-	 must call lua_close yourself or if you need to continue to use the lua_State pointer provided here.  Internally, this
-	 method works as Initialise() except an existing lua_State pointer is used instead of creating a new lua_State context. */
-    static void Initialise(lua_State *_L = NULL);
-    /** Stops the plugin by calling lua_close        */
+	 must call lua_close yourself or if you need to continue to use the lua_State pointer provided here.  Internally, it calls
+	 Interpreter::Startup() and registers the "body" tag to generate a LuaDocument rather than a Rocket::Core::ElementDocument.
+	 If the argument provided is NULL, a Lua context is created automatically instead. */
+    static void Initialise(lua_State *_L);
+
+    /** Stops the plugin by calling lua_close
+	 @remark Shutdown calls lua_Close on the lua_State associated with the Interpreter.  If a lua_State was provided in the
+	 original call to Initialise, Shutdown should not be called OR you must not call lua_Close from within your code. */
 	static void Shutdown();
 	static void Shutdown();
     
     
     /** @sa Rocket::Core::Plugin::GetEventClasses */
     /** @sa Rocket::Core::Plugin::GetEventClasses */

+ 10 - 5
Samples/luainvaders/src/DecoratorDefender.cpp

@@ -47,26 +47,31 @@ bool DecoratorDefender::Initialise(const Rocket::Core::String& image_source, con
 }
 }
 
 
 /// Called on a decorator to generate any required per-element data for a newly decorated element.
 /// Called on a decorator to generate any required per-element data for a newly decorated element.
-Rocket::Core::DecoratorDataHandle DecoratorDefender::GenerateElementData(Rocket::Core::Element* ROCKET_UNUSED(element))
+Rocket::Core::DecoratorDataHandle DecoratorDefender::GenerateElementData(Rocket::Core::Element* ROCKET_UNUSED_PARAMETER(element))
 {
 {
-	return NULL;
+	ROCKET_UNUSED(element);
+
+	return Rocket::Core::Decorator::INVALID_DECORATORDATAHANDLE;
 }
 }
 
 
 // Called to release element data generated by this decorator.
 // Called to release element data generated by this decorator.
-void DecoratorDefender::ReleaseElementData(Rocket::Core::DecoratorDataHandle ROCKET_UNUSED(element_data))
+void DecoratorDefender::ReleaseElementData(Rocket::Core::DecoratorDataHandle ROCKET_UNUSED_PARAMETER(element_data))
 {
 {
+	ROCKET_UNUSED(element_data);
 }
 }
 
 
 // Called to render the decorator on an element.
 // Called to render the decorator on an element.
-void DecoratorDefender::RenderElement(Rocket::Core::Element* element, Rocket::Core::DecoratorDataHandle ROCKET_UNUSED(element_data))
+void DecoratorDefender::RenderElement(Rocket::Core::Element* element, Rocket::Core::DecoratorDataHandle ROCKET_UNUSED_PARAMETER(element_data))
 {
 {
+	ROCKET_UNUSED(element_data);
+
 	Rocket::Core::Vector2f position = element->GetAbsoluteOffset(Rocket::Core::Box::PADDING);
 	Rocket::Core::Vector2f position = element->GetAbsoluteOffset(Rocket::Core::Box::PADDING);
 	Rocket::Core::Vector2f size = element->GetBox().GetSize(Rocket::Core::Box::PADDING);
 	Rocket::Core::Vector2f size = element->GetBox().GetSize(Rocket::Core::Box::PADDING);
 
 
 	glEnable(GL_TEXTURE_2D);
 	glEnable(GL_TEXTURE_2D);
 	glBindTexture(GL_TEXTURE_2D, (GLuint) GetTexture(image_index)->GetHandle(element->GetRenderInterface()));
 	glBindTexture(GL_TEXTURE_2D, (GLuint) GetTexture(image_index)->GetHandle(element->GetRenderInterface()));
 	Rocket::Core::Colourb colour = element->GetProperty< Rocket::Core::Colourb >("color");
 	Rocket::Core::Colourb colour = element->GetProperty< Rocket::Core::Colourb >("color");
-	glColor4ubv(element->GetProperty< Rocket::Core::Colourb >("color"));
+	glColor4ubv(colour);
 	glBegin(GL_QUADS);
 	glBegin(GL_QUADS);
 
 
 		glVertex2f(position.x, position.y);
 		glVertex2f(position.x, position.y);

+ 3 - 1
Samples/luainvaders/src/DecoratorInstancerDefender.cpp

@@ -40,8 +40,10 @@ DecoratorInstancerDefender::~DecoratorInstancerDefender()
 }
 }
 
 
 // Instances a decorator given the property tag and attributes from the RCSS file.
 // Instances a decorator given the property tag and attributes from the RCSS file.
-Rocket::Core::Decorator* DecoratorInstancerDefender::InstanceDecorator(const Rocket::Core::String& ROCKET_UNUSED(name), const Rocket::Core::PropertyDictionary& properties)
+Rocket::Core::Decorator* DecoratorInstancerDefender::InstanceDecorator(const Rocket::Core::String& ROCKET_UNUSED_PARAMETER(name), const Rocket::Core::PropertyDictionary& properties)
 {
 {
+	ROCKET_UNUSED(name);
+
 	const Rocket::Core::Property* image_source_property = properties.GetProperty("image-src");
 	const Rocket::Core::Property* image_source_property = properties.GetProperty("image-src");
 	Rocket::Core::String image_source = image_source_property->Get< Rocket::Core::String >();
 	Rocket::Core::String image_source = image_source_property->Get< Rocket::Core::String >();
 
 

+ 3 - 1
Samples/luainvaders/src/DecoratorInstancerStarfield.cpp

@@ -46,8 +46,10 @@ DecoratorInstancerStarfield::~DecoratorInstancerStarfield()
 }
 }
 
 
 // Instances a decorator given the property tag and attributes from the RCSS file.
 // Instances a decorator given the property tag and attributes from the RCSS file.
-Rocket::Core::Decorator* DecoratorInstancerStarfield::InstanceDecorator(const Rocket::Core::String& ROCKET_UNUSED(name), const Rocket::Core::PropertyDictionary& properties)
+Rocket::Core::Decorator* DecoratorInstancerStarfield::InstanceDecorator(const Rocket::Core::String& ROCKET_UNUSED_PARAMETER(name), const Rocket::Core::PropertyDictionary& properties)
 {
 {
+	ROCKET_UNUSED(name);
+
 	int num_layers = Rocket::Core::Math::RealToInteger(properties.GetProperty("num-layers")->Get< float >());
 	int num_layers = Rocket::Core::Math::RealToInteger(properties.GetProperty("num-layers")->Get< float >());
 	Rocket::Core::Colourb top_colour = properties.GetProperty("top-colour")->Get< Rocket::Core::Colourb >();
 	Rocket::Core::Colourb top_colour = properties.GetProperty("top-colour")->Get< Rocket::Core::Colourb >();
 	Rocket::Core::Colourb bottom_colour = properties.GetProperty("bottom-colour")->Get< Rocket::Core::Colourb >();
 	Rocket::Core::Colourb bottom_colour = properties.GetProperty("bottom-colour")->Get< Rocket::Core::Colourb >();

+ 3 - 1
Samples/luainvaders/src/DecoratorStarfield.cpp

@@ -95,8 +95,10 @@ void DecoratorStarfield::ReleaseElementData(Rocket::Core::DecoratorDataHandle el
 }
 }
 
 
 // Called to render the decorator on an element.
 // Called to render the decorator on an element.
-void DecoratorStarfield::RenderElement(Rocket::Core::Element* ROCKET_UNUSED(element), Rocket::Core::DecoratorDataHandle element_data)
+void DecoratorStarfield::RenderElement(Rocket::Core::Element* ROCKET_UNUSED_PARAMETER(element), Rocket::Core::DecoratorDataHandle element_data)
 {
 {
+	ROCKET_UNUSED(element);
+
 	StarField* star_field = (StarField*)element_data;
 	StarField* star_field = (StarField*)element_data;
 	star_field->Update();
 	star_field->Update();
 
 

+ 0 - 1
Samples/luainvaders/src/Game.cpp

@@ -49,7 +49,6 @@ const int INVADER_SPACING_Y = 48;
 const int INVADER_START_Y = 96;
 const int INVADER_START_Y = 96;
 
 
 const float INVADER_MOVEMENT = 10;
 const float INVADER_MOVEMENT = 10;
-const float INVADER_START_MOVE_FREQ = 0.5f;
 const float INVADER_UPDATE_MODIFIER = 0.7f;
 const float INVADER_UPDATE_MODIFIER = 0.7f;
 
 
 const int MOTHERSHIP = NUM_INVADERS;
 const int MOTHERSHIP = NUM_INVADERS;

+ 3 - 0
Samples/luainvaders/src/Invader.cpp

@@ -228,6 +228,7 @@ bool Invader::CheckHit(const Rocket::Core::Vector2f& check_position)
 		int score = 0;
 		int score = 0;
 		switch (type)
 		switch (type)
 		{
 		{
+			ROCKET_UNUSED_SWITCH_ENUM(UNKNOWN);
 			case MOTHERSHIP: score = (Rocket::Core::Math::RandomInteger(6) + 1) * 50; break;	// 50 -> 300
 			case MOTHERSHIP: score = (Rocket::Core::Math::RandomInteger(6) + 1) * 50; break;	// 50 -> 300
 			case RANK3: score = 40; break;
 			case RANK3: score = 40; break;
 			case RANK2: score = 20; break;
 			case RANK2: score = 20; break;
@@ -253,6 +254,8 @@ int Invader::GetSpriteIndex() const
 	int index = animation_frame;
 	int index = animation_frame;
 	switch (type)
 	switch (type)
 	{
 	{
+		ROCKET_UNUSED_SWITCH_ENUM(UNKNOWN);
+		case RANK1:                 break;      // animation_frame is the right index already
 		case RANK2:	index += 2; break;
 		case RANK2:	index += 2; break;
 		case RANK3:	index += 4; break;
 		case RANK3:	index += 4; break;
 		case MOTHERSHIP: index = 6; break;
 		case MOTHERSHIP: index = 6; break;

+ 0 - 1
Samples/luainvaders/src/Mothership.cpp

@@ -32,7 +32,6 @@
 #include "Sprite.h"
 #include "Sprite.h"
 
 
 const int SPRITE_WIDTH = 64;
 const int SPRITE_WIDTH = 64;
-const int SPRITE_HEIGHT = 28;
 
 
 const float APPEARANCE_PROBABILITY = 0.001f;
 const float APPEARANCE_PROBABILITY = 0.001f;
 const float UPDATE_FREQ = 0.025f;
 const float UPDATE_FREQ = 0.025f;

+ 2 - 2
Samples/luainvaders/src/main.cpp

@@ -93,8 +93,8 @@ int main(int, char**)
 	Rocket::Controls::Initialise();
 	Rocket::Controls::Initialise();
 
 
 	// Initialise the Lua interface
 	// Initialise the Lua interface
-    Rocket::Core::Lua::Interpreter::Initialise();
-    Rocket::Controls::Lua::RegisterTypes(Rocket::Core::Lua::Interpreter::GetLuaState());
+	Rocket::Core::Lua::Interpreter::Initialise();
+	Rocket::Controls::Lua::RegisterTypes(Rocket::Core::Lua::Interpreter::GetLuaState());
 
 
 	// Create the main Rocket context and set it on the shell's input layer.
 	// Create the main Rocket context and set it on the shell's input layer.
 	context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
 	context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));

+ 1 - 1
Source/Core/Lua/Interpreter.cpp

@@ -222,7 +222,7 @@ void Interpreter::OnShutdown()
 
 
 void Interpreter::Initialise()
 void Interpreter::Initialise()
 {
 {
-    Rocket::Core::RegisterPlugin(new Interpreter());
+    Rocket::Core::Lua::Interpreter::Initialise(NULL);
 }
 }
 
 
 void Interpreter::Initialise(lua_State *luaStatePointer)
 void Interpreter::Initialise(lua_State *luaStatePointer)