Ver código fonte

More work on script binding generation

BearishSun 8 anos atrás
pai
commit
479e9cb3b2

+ 9 - 1
Documentation/GitHub/dependencies.md

@@ -207,4 +207,12 @@ If the library structure still isn't clear, download one of the pre-compiled dep
 - Required by BansheeSL
 - Outputs:
   - Windows (tool):
-    - flex/flex.exe (Including all other installation files)
+    - flex/flex.exe (Including all other installation files)
+	
+**BansheeSBGen**
+ - Banshee Script Binding Generator 1.0
+ - https://github.com/BearishSun/BansheeSBGen
+ - Required for generation of C# script binding files. Not required if not using the scripting sub-system.
+ - Outputs:
+  - Windows (tool):
+   - BansheeSBGen/BansheeSBGen_v1.0.0.exe

+ 4 - 0
Source/BansheeUtility/Include/BsPrerequisitesUtil.h

@@ -239,6 +239,10 @@
  *		  parameter and return no values. Usable on methods only.
  *	- ed - Specify that a type should be exported for use in the editor only. Supported values are "true" or "false".
  *		   Usable on types only.
+ *  - ex - Excludes an enum member from being generated in script code. Supported values are "true" or "false".
+ *  - in - When enabled ensures only the interop C# method is generated, but not a public one. It is instead expected
+ *		   the user will manually implement the public method. Supported values are "true" or "false". Default is "false".
+ *		   Only supported on methods.
  */
 
 #if BS_COMPILER == BS_COMPILER_CLANG

+ 50 - 29
Source/CMake/GenerateScriptBindings.cmake

@@ -47,11 +47,9 @@ set(BS_SCRIPT_PARSER_INCLUDE_DIRS ${BS_SCRIPT_PARSER_INCLUDE_DIRS} "BansheeMono/
 list(REMOVE_DUPLICATES BS_SCRIPT_PARSER_INCLUDE_DIRS)
 list(REMOVE_DUPLICATES BS_SCRIPT_PARSER_H_FILES)
 
-# Overriding previous code and using a fixed set of files in order to speed up parsing
-#set(BS_SCRIPT_PARSER_SOURCE_FILES "")
-#list(APPEND BS_SCRIPT_PARSER_SOURCE_FILES "BansheeUtility/Include/PixelVolume.h");
-
-set(BS_GENERATED_FILES_OUTPUT_DIR ${PROJECT_BINARY_DIR}/Generated)
+set(BS_GENERATED_CPP_OUTPUT_DIR ${PROJECT_BINARY_DIR}/Generated)
+set(BS_GENERATED_CS_ENGINE_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/MBansheeEngine/Generated)
+set(BS_GENERATED_CS_EDITOR_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/MBansheeEditor/Generated)
 prepend(BS_INCLUDE_DIRS "-I${PROJECT_SOURCE_DIR}" ${BS_SCRIPT_PARSER_INCLUDE_DIRS})
 
 # Generate a single .cpp file including all headers
@@ -60,27 +58,50 @@ FOREACH(f ${BS_SCRIPT_PARSER_H_FILES})
 	LIST(APPEND BS_GLOBAL_FILE_CONTENTS "#include \"${f}\"\n")
 ENDFOREACH(f)
 
-file(WRITE ${BS_GENERATED_FILES_OUTPUT_DIR}/toParse.cpp ${BS_GLOBAL_FILE_CONTENTS})
-
-#execute_process(
-#    COMMAND ${PROJECT_SOURCE_DIR}/../Dependencies/tools/SBGen 
-#		${BS_GENERATED_FILES_OUTPUT_DIR}/toParse.cpp
-#		-output ${BS_GENERATED_FILES_OUTPUT_DIR}
-#		-- ${BS_INCLUDE_DIRS}
-#		-DBS_STATIC_LIB
-#	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
-#    RESULT_VARIABLE SBGEN_RETURN_VALUE
-#)
-
-#if (NOT SBGEN_RETURN_VALUE EQUAL 0)
-#    message(FATAL_ERROR "Failed to generate script bindings.")
-#endif()
-
-file(GLOB BS_GENERATED_ENGINE_H_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Engine/Include/*)
-file(GLOB BS_GENERATED_ENGINE_CPP_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Engine/Source/*)
-
-file(GLOB BS_GENERATED_EDITOR_H_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Editor/Include/*)
-file(GLOB BS_GENERATED_EDITOR_CPP_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cpp/Editor/Source/*)
-
-file(GLOB BS_GENERATED_ENGINE_CS_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cs/Engine/*)
-file(GLOB BS_GENERATED_EDITOR_CS_FILES ${BS_GENERATED_FILES_OUTPUT_DIR}/Cs/Editor/*)
+file(WRITE ${BS_GENERATED_CPP_OUTPUT_DIR}/toParse.cpp ${BS_GLOBAL_FILE_CONTENTS})
+
+find_package(BansheeSBGen)
+if(BansheeSBGen_FOUND)
+	set(BS_GSB_COMMAND ${BansheeSBGen_EXECUTABLE_PATH}
+		${BS_GENERATED_CPP_OUTPUT_DIR}/toParse.cpp
+		-output-cpp ${BS_GENERATED_CPP_OUTPUT_DIR}
+		-output-cs-engine ${BS_GENERATED_CS_ENGINE_OUTPUT_DIR}
+		-output-cs-editor ${BS_GENERATED_CS_EDITOR_OUTPUT_DIR}
+		-- ${BS_INCLUDE_DIRS}
+		-DBS_STATIC_LIB
+		-w)
+
+	message(STATUS "Generating script bindings, please wait...")
+	execute_process(
+		COMMAND ${BS_GSB_COMMAND}
+		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+		RESULT_VARIABLE SBGEN_RETURN_VALUE
+	)
+
+	if (NOT SBGEN_RETURN_VALUE EQUAL 0)
+		message(FATAL_ERROR "Failed to generate script bindings.")
+	else()
+		message(STATUS "...scripting binding generation OK.")
+	endif()	
+		
+	add_custom_target(GenerateScriptBindings
+		COMMAND ${BS_GSB_COMMAND}
+		WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+		COMMENT "Generating script bindings, please wait...")	
+		
+	#add_custom_command(
+	#	OUTPUT ${BS_GENERATED_CPP_OUTPUT_DIR}/scriptBindings2.timestamp
+	#	COMMAND echo "Test"
+	#	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/input.cpp
+	#	COMMENT "Generating script bindings, please wait...")	
+		
+	#add_custom_target(GenerateScriptBindings 
+	#	DEPENDS ${BS_GENERATED_CPP_OUTPUT_DIR}/scriptBindings2.timestamp
+	#	COMMENT "Running custom target")	
+		
+	file(GLOB BS_GENERATED_ENGINE_H_FILES ${BS_GENERATED_CPP_OUTPUT_DIR}/Engine/Include/*)
+	file(GLOB BS_GENERATED_ENGINE_CPP_FILES ${BS_GENERATED_CPP_OUTPUT_DIR}/Engine/Source/*)
+
+	file(GLOB BS_GENERATED_EDITOR_H_FILES ${BS_GENERATED_CPP_OUTPUT_DIR}/Editor/Include/*)
+	file(GLOB BS_GENERATED_EDITOR_CPP_FILES ${BS_GENERATED_CPP_OUTPUT_DIR}/Editor/Source/*)
+endif()

+ 30 - 0
Source/CMake/Modules/FindBansheeSBGen.cmake

@@ -0,0 +1,30 @@
+# Find BansheeSBGen tool dependency
+#
+# This module defines
+#  BansheeSBGen_EXECUTABLE_PATH
+#  BansheeSBGen_FOUND
+
+set(BansheeSBGen_INSTALL_DIRS ${PROJECT_SOURCE_DIR}/../Dependencies/tools/BansheeSBGen CACHE PATH "")
+
+message(STATUS "Looking for BansheeSBGen installation...")
+find_program(BansheeSBGen_EXECUTABLE NAMES BansheeSBGen_v1.0.0 PATHS ${BansheeSBGen_INSTALL_DIRS})
+
+if(BansheeSBGen_EXECUTABLE)
+	set(BansheeSBGen_FOUND TRUE)
+endif()
+
+if(NOT BansheeSBGen_FOUND)
+	if(BansheeSBGen_FIND_REQUIRED)
+		message(FATAL_ERROR "Cannot find BansheeSBGen installation. Try modifying the BansheeSBGen_INSTALL_DIRS path.")
+	else()
+		message(WARNING "Cannot find BansheeSBGen installation. Try modifying the BansheeSBGen_INSTALL_DIRS path.")
+	endif()
+else()
+	message(STATUS "...BansheeSBGen OK.")
+endif()
+
+mark_as_advanced(
+	BansheeSBGen_INSTALL_DIRS 
+	BansheeSBGen_EXECUTABLE)
+
+set(BansheeSBGen_EXECUTABLE_PATH ${BansheeSBGen_EXECUTABLE})

+ 1 - 0
Source/MBansheeEditor/MBansheeEditor.csproj

@@ -224,6 +224,7 @@
     <Compile Include="Tests\UnitTests.cs" />
     <Compile Include="Tests\UnitTestTypes.cs" />
     <Compile Include="Window\UndoRedoLocal.cs" />
+	<Compile Include="Generated\*.cs"/>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\MBansheeEngine\MBansheeEngine.csproj">

+ 1 - 0
Source/MBansheeEngine/MBansheeEngine.csproj

@@ -213,6 +213,7 @@
     <Compile Include="Rendering\TextureCube.cs" />
     <Compile Include="Utility\Time.cs" />
     <Compile Include="Input\VirtualInput.cs" />
+	<Compile Include="Generated\*.cs"/>
   </ItemGroup>
   <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 4 - 1
Source/SBansheeEditor/CMakeLists.txt

@@ -1,6 +1,9 @@
 # Source files and their filters
 include(CMakeSources.cmake)
 
+source_group("Header Files\\Generated" FILES ${BS_GENERATED_EDITOR_H_FILES})
+source_group("Source Files\\Generated" FILES ${BS_GENERATED_EDITOR_CPP_FILES})
+
 # Includes
 set(SBansheeEditor_INC 
 	"Include"
@@ -10,7 +13,7 @@ set(SBansheeEditor_INC
 	"../BansheeEditor/Include"
 	"../BansheeMono/Include"
 	"../SBansheeEngine/Include"
-	"${PROJECT_BINARY_DIR}/Generated/Cpp/Editor/Include")
+	"${PROJECT_BINARY_DIR}/Generated/Editor/Include")
 
 include_directories(${SBansheeEditor_INC})	
 

+ 4 - 1
Source/SBansheeEngine/CMakeLists.txt

@@ -1,6 +1,9 @@
 # Source files and their filters
 include(CMakeSources.cmake)
 
+source_group("Header Files\\Generated" FILES ${BS_GENERATED_ENGINE_H_FILES})
+source_group("Source Files\\Generated" FILES ${BS_GENERATED_ENGINE_CPP_FILES})
+
 # Includes
 set(SBansheeEngine_INC 
 	"Include"
@@ -9,7 +12,7 @@ set(SBansheeEngine_INC
 	"../BansheeEngine/Include"
 	"../BansheeEditor/Include"
 	"../BansheeMono/Include"
-	"${PROJECT_BINARY_DIR}/Generated/Cpp/Engine/Include")
+	"${PROJECT_BINARY_DIR}/Generated/Engine/Include")
 
 include_directories(${SBansheeEngine_INC})	
 

+ 4 - 4
Source/SBansheeEngine/Include/BsScriptComponent.h

@@ -37,8 +37,8 @@ namespace bs
 	};
 
 	/**	Base class for a specific builtin component's interop object. */
-	template<class ScriptClass, class CompType>
-	class BS_SCR_BE_EXPORT TScriptComponent : public ScriptObject <ScriptClass, ScriptComponentBase>
+	template<class ScriptClass, class CompType, class BaseType = ScriptComponentBase>
+	class BS_SCR_BE_EXPORT TScriptComponent : public ScriptObject <ScriptClass, BaseType>
 	{
 	public:
 		/**	Returns a generic handle to the internal wrapped component. */
@@ -54,7 +54,7 @@ namespace bs
 		friend class ScriptGameObjectManager;
 
 		TScriptComponent(MonoObject* instance, const GameObjectHandle<CompType>& component)
-			:ScriptObject<ScriptClass, ScriptComponentBase>(instance), mComponent(component)
+			:ScriptObject<ScriptClass, BaseType>(instance), mComponent(component)
 		{
 			mManagedHandle = MonoUtil::newGCHandle(instance);
 
@@ -72,7 +72,7 @@ namespace bs
 			BS_ASSERT(!mHandleValid);
 			mManagedHandle = MonoUtil::newGCHandle(this->mManagedInstance);
 
-			ScriptObject<ScriptClass, ScriptComponentBase>::endRefresh(backupData);
+			ScriptObject<ScriptClass, BaseType>::endRefresh(backupData);
 		}
 
 		/**

+ 4 - 4
Source/SBansheeEngine/Include/BsScriptResource.h

@@ -53,8 +53,8 @@ namespace bs
 	};
 
 	/**	Base class for a specific resource's interop object. */
-	template<class ScriptClass, class ResType>
-	class BS_SCR_BE_EXPORT TScriptResource : public ScriptObject <ScriptClass, ScriptResourceBase>
+	template<class ScriptClass, class ResType, class BaseType = ScriptResourceBase>
+	class BS_SCR_BE_EXPORT TScriptResource : public ScriptObject <ScriptClass, BaseType>
 	{
 	public:
 		/**	Returns a generic handle to the internal wrapped resource. */
@@ -70,7 +70,7 @@ namespace bs
 		friend class ScriptResourceManager;
 
 		TScriptResource(MonoObject* instance, const ResourceHandle<ResType>& resource)
-			:ScriptObject<ScriptClass, ScriptResourceBase>(instance), mResource(resource)
+			:ScriptObject<ScriptClass, BaseType>(instance), mResource(resource)
 		{
 			mManagedHandle = MonoUtil::newGCHandle(instance);
 
@@ -88,7 +88,7 @@ namespace bs
 			BS_ASSERT(!mHandleValid);
 			mManagedHandle = MonoUtil::newGCHandle(this->mManagedInstance);
 
-			ScriptObject<ScriptClass, ScriptResourceBase>::endRefresh(backupData);
+			ScriptObject<ScriptClass, BaseType>::endRefresh(backupData);
 		}
 
 		/**