mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 05:31:01 +00:00 
			
		
		
		
	Merge branch 'master' of https://github.com/godotengine/godot
This commit is contained in:
		
						commit
						ce26eb74bc
					
				
					 1978 changed files with 188590 additions and 31400 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -8,6 +8,7 @@ platform/osx/logo.h | ||||||
| platform/windows/logo.h | platform/windows/logo.h | ||||||
| platform/x11/logo.h | platform/x11/logo.h | ||||||
| drivers/gles2/shaders/*.h | drivers/gles2/shaders/*.h | ||||||
|  | drivers/gles3/shaders/*.h | ||||||
| modules/register_module_types.cpp | modules/register_module_types.cpp | ||||||
| core/version.h | core/version.h | ||||||
| core/method_bind.inc | core/method_bind.inc | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ env: | ||||||
|   - GODOT_TARGET=iphone |   - GODOT_TARGET=iphone | ||||||
|   - GODOT_TARGET=osx |   - GODOT_TARGET=osx | ||||||
|   - GODOT_TARGET=x11 |   - GODOT_TARGET=x11 | ||||||
|   - GODOT_TARGET=android |   #- GODOT_TARGET=android | ||||||
|   - GODOT_TARGET=windows |   - GODOT_TARGET=windows | ||||||
| 
 | 
 | ||||||
| matrix: | matrix: | ||||||
|  | @ -69,8 +69,8 @@ addons: | ||||||
| before_script: | before_script: | ||||||
|   - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; brew install scons; fi |   - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; brew install scons; fi | ||||||
|   - if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$GODOT_TARGET" = "android" ]; then |   - if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$GODOT_TARGET" = "android" ]; then | ||||||
|       brew update; travis_wait 20 brew install -v android-sdk; |       brew update; brew install -v android-sdk; | ||||||
|       travis_wait 20 brew install -v android-ndk | grep -v "inflating:" | grep -v "creating:"; |       brew install -v android-ndk | grep -v "inflating:" | grep -v "creating:"; | ||||||
|       export ANDROID_HOME=/usr/local/opt/android-sdk; export ANDROID_NDK_ROOT=/usr/local/opt/android-ndk; |       export ANDROID_HOME=/usr/local/opt/android-sdk; export ANDROID_NDK_ROOT=/usr/local/opt/android-ndk; | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -54,6 +54,30 @@ Also try to make commits that bring the engine from one stable state to another | ||||||
| 
 | 
 | ||||||
| This git style guide has some good practices to have in mind: https://github.com/agis-/git-style-guide | This git style guide has some good practices to have in mind: https://github.com/agis-/git-style-guide | ||||||
| 
 | 
 | ||||||
|  | #### Format your commit logs with readability in mind | ||||||
|  | 
 | ||||||
|  | The way you format your commit logs is quite important to ensure that the commit history and changelog will be easy to read and understand. A git commit log is formatted as a short title (first line) and an extended description (everything after the first line and an empty separation line). | ||||||
|  | 
 | ||||||
|  | The short title is the most important part, as it is what will appear in the `shortlog` changelog (one line per commit, so no description shown) or in the GitHub interface unless you click the "expand" button. As the name tells it, try to keep that first line relatively short (ideally <= 50 chars, though it's rare to be able to tell enough in so few characters, so you can go a bit higher) - it should describe what the commit does globally, while details would go in the description. Typically, if you can't keep the title short because you have too much stuff to mention, it means that you should probably split your changes in several commits :) | ||||||
|  | 
 | ||||||
|  | Here's an example of a well-formatted commit log (note how the extended description is also manually wrapped at 80 chars for readability): | ||||||
|  | 
 | ||||||
|  | ``` | ||||||
|  | Prevent French fries carbonization by fixing heat regulation | ||||||
|  | 
 | ||||||
|  | When using the French fries frying module, Godot would not regulate the heat | ||||||
|  | and thus bring the oil bath to supercritical liquid conditions, thus causing | ||||||
|  | unwanted side effects in the physics engine. | ||||||
|  | 
 | ||||||
|  | By fixing the regulation system via an added binding to the internal feature, | ||||||
|  | this commit now ensures that Godot will not go past the ebullition temperature | ||||||
|  | of cooking oil under normal atmosheric conditions. | ||||||
|  | 
 | ||||||
|  | Fixes #1789, long live the Realm! | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | *Note:* When using the GitHub online editor (or worse, the drag and drop feature), *please* edit the commit title to something meaningful. Commits named "Update my_file.cpp" will not be accepted. | ||||||
|  | 
 | ||||||
| Thanks! | Thanks! | ||||||
| 
 | 
 | ||||||
| The Godot development team | The Godot development team | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| ************************************************************************ | ************************************************************************ | ||||||
| 
 | 
 | ||||||
|  Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. |  Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. | ||||||
| 
 | 
 | ||||||
|  Permission is hereby granted, free of charge, to any person obtaining |  Permission is hereby granted, free of charge, to any person obtaining | ||||||
|  a copy of this software and associated documentation files (the |  a copy of this software and associated documentation files (the | ||||||
|  |  | ||||||
							
								
								
									
										66
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										66
									
								
								README.md
									
										
									
									
									
								
							|  | @ -1,30 +1,66 @@ | ||||||
|  | [](https://godotengine.org) | ||||||
| 
 | 
 | ||||||
| https://godotengine.org | ## Godot Engine | ||||||
| 
 | 
 | ||||||
| ### The Engine | Homepage: https://godotengine.org | ||||||
| 
 | 
 | ||||||
| Godot is a fully featured, open source, MIT licensed, game engine. It focuses on having great tools, and a visual oriented workflow that can export to PC, Mobile and Web platforms with no hassle. | #### 2D and 3D cross-platform game engine | ||||||
| The editor, language and APIs are feature rich, yet simple to learn, allowing you to become productive in a matter of hours. |  | ||||||
| 
 | 
 | ||||||
| ### About | Godot Engine is a feature-packed, cross-platform game engine to create 2D and | ||||||
|  | 3D games from a unified interface. It provides a comprehensive set of common | ||||||
|  | tools, so that users can focus on making games without having to reinvent the | ||||||
|  | wheel. Games can be exported in one click to a number of platforms, including | ||||||
|  | the major desktop platforms (Linux, Mac OSX, Windows) as well as mobile | ||||||
|  | (Android, iOS) and web-based (HTML5) platforms. | ||||||
| 
 | 
 | ||||||
| Godot has been developed by Juan Linietsky and Ariel Manzur for several years, and was born as an in-house engine, used to publish several work-for-hire titles. Godot is a member project of the [Software Freedom Conservancy](https://sfconservancy.org) | #### Free, open source and community-driven | ||||||
| 
 | 
 | ||||||
| ### Documentation | Godot is completely free and open source under the very permissive MIT license. | ||||||
|  | No strings attached, no royalties, nothing. The users' games are theirs, down | ||||||
|  | to the last line of engine code. Godot's development is fully independent and | ||||||
|  | community-driven, empowering users to help shape their engine to match their | ||||||
|  | expectations. It is supported by the Software Freedom Conservancy | ||||||
|  | not-for-profit. | ||||||
| 
 | 
 | ||||||
| Documentation is hosted on [ReadTheDocs](http://docs.godotengine.org). | Before being open sourced in February 2014, Godot had been developed by Juan | ||||||
|  | Linietsky and Ariel Manzur (both still maintaining the project) for several | ||||||
|  | years as an in-house engine, used to publish several work-for-hire titles. | ||||||
| 
 | 
 | ||||||
| ### Binary Downloads, Community, etc. | ### Getting the engine | ||||||
| 
 | 
 | ||||||
| Binary downloads, community, etc. can be found in Godot homepage: | #### Binary downloads | ||||||
| 
 | 
 | ||||||
| https://godotengine.org | Official binaries for the Godot editor and the export templates can be found | ||||||
|  | [on the homepage](https://godotengine.org/download). | ||||||
| 
 | 
 | ||||||
| ### Compiling from Source | #### Compiling from source | ||||||
| 
 | 
 | ||||||
| See docs for compilation instructions for every platform: | [See the official docs](http://docs.godotengine.org/en/latest/reference/_compiling.html) | ||||||
| http://docs.godotengine.org/en/latest/reference/_compiling.html | for compilation instructions for every supported platform. | ||||||
|  | 
 | ||||||
|  | ### Community | ||||||
|  | 
 | ||||||
|  | Godot is not only an engine but an ever-growing community of users and engine | ||||||
|  | developers. The main community channels are listed [on the homepage](https://godotengine.org/community). | ||||||
|  | 
 | ||||||
|  | To get in touch with the developers, the best way is to join the | ||||||
|  | [#godotengine IRC channel](https://webchat.freenode.net/?channels=godotengine) | ||||||
|  | on Freenode. | ||||||
|  | 
 | ||||||
|  | ### Documentation and demos | ||||||
|  | 
 | ||||||
|  | The official documentation is hosted on [ReadTheDocs](http://docs.godotengine.org). | ||||||
|  | It is maintained by the Godot community in its own [GitHub repository](https://github.com/godotengine/godot-docs). | ||||||
|  | 
 | ||||||
|  | The [class reference](http://docs.godotengine.org/en/latest/classes/_classes.html) | ||||||
|  | is also accessible from within the engine. | ||||||
|  | 
 | ||||||
|  | The official demos are maintained in their own [GitHub repository](https://github.com/godotengine/godot-demo-projects) | ||||||
|  | as well. | ||||||
|  | 
 | ||||||
|  | There are also a number of other learning resources provided by the community, | ||||||
|  | such as text and video tutorials, demos, etc. Consult the [community channels](https://godotengine.org/community) | ||||||
|  | for more info. | ||||||
| 
 | 
 | ||||||
| [](https://travis-ci.org/godotengine/godot) | [](https://travis-ci.org/godotengine/godot) | ||||||
| [](http://www.codetriage.com/godotengine/godot) | [](http://www.codetriage.com/godotengine/godot) | ||||||
|  |  | ||||||
							
								
								
									
										108
									
								
								SConstruct
									
										
									
									
									
								
							
							
						
						
									
										108
									
								
								SConstruct
									
										
									
									
									
								
							|  | @ -1,6 +1,6 @@ | ||||||
| #!/usr/bin/env python | #!/usr/bin/env python | ||||||
| 
 | 
 | ||||||
| EnsureSConsVersion(0,14); | EnsureSConsVersion(0, 14) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| import string | import string | ||||||
|  | @ -37,7 +37,7 @@ for x in glob.glob("platform/*"): | ||||||
|         global_defaults.append(x[9:]) |         global_defaults.append(x[9:]) | ||||||
|     if (detect.is_active()): |     if (detect.is_active()): | ||||||
|         active_platforms.append(detect.get_name()) |         active_platforms.append(detect.get_name()) | ||||||
| 		active_platform_ids.append(x); |         active_platform_ids.append(x) | ||||||
|     if (detect.can_build()): |     if (detect.can_build()): | ||||||
|         x = x.replace("platform/", "")  # rest of world |         x = x.replace("platform/", "")  # rest of world | ||||||
|         x = x.replace("platform\\", "")  # win32 |         x = x.replace("platform\\", "")  # win32 | ||||||
|  | @ -64,7 +64,7 @@ elif (os.name=="nt"): | ||||||
|     if (os.getenv("VCINSTALLDIR") == None or platform_arg == "android"): |     if (os.getenv("VCINSTALLDIR") == None or platform_arg == "android"): | ||||||
|         custom_tools = ['mingw'] |         custom_tools = ['mingw'] | ||||||
| 
 | 
 | ||||||
| env_base=Environment(tools=custom_tools); | env_base = Environment(tools=custom_tools) | ||||||
| if 'TERM' in os.environ: | if 'TERM' in os.environ: | ||||||
|     env_base['ENV']['TERM'] = os.environ['TERM'] |     env_base['ENV']['TERM'] = os.environ['TERM'] | ||||||
| env_base.AppendENVPath('PATH', os.getenv('PATH')) | env_base.AppendENVPath('PATH', os.getenv('PATH')) | ||||||
|  | @ -85,7 +85,6 @@ env_base.use_ptrcall=False | ||||||
| env_base.split_drivers = False | env_base.split_drivers = False | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| env_base.__class__.android_add_maven_repository = methods.android_add_maven_repository | env_base.__class__.android_add_maven_repository = methods.android_add_maven_repository | ||||||
| env_base.__class__.android_add_dependency = methods.android_add_dependency | env_base.__class__.android_add_dependency = methods.android_add_dependency | ||||||
| env_base.__class__.android_add_java_dir = methods.android_add_java_dir | env_base.__class__.android_add_java_dir = methods.android_add_java_dir | ||||||
|  | @ -100,10 +99,13 @@ env_base.__class__.disable_module = methods.disable_module | ||||||
| 
 | 
 | ||||||
| env_base.__class__.add_source_files = methods.add_source_files | env_base.__class__.add_source_files = methods.add_source_files | ||||||
| env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix | env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix | ||||||
|  | env_base.__class__.split_lib = methods.split_lib | ||||||
| 
 | 
 | ||||||
| env_base["x86_libtheora_opt_gcc"] = False | env_base["x86_libtheora_opt_gcc"] = False | ||||||
| env_base["x86_libtheora_opt_vc"] = False | env_base["x86_libtheora_opt_vc"] = False | ||||||
| 
 | 
 | ||||||
|  | # Build options | ||||||
|  | 
 | ||||||
| customs = ['custom.py'] | customs = ['custom.py'] | ||||||
| 
 | 
 | ||||||
| profile = ARGUMENTS.get("profile", False) | profile = ARGUMENTS.get("profile", False) | ||||||
|  | @ -115,40 +117,53 @@ if profile: | ||||||
|         customs.append(profile + ".py") |         customs.append(profile + ".py") | ||||||
| 
 | 
 | ||||||
| opts = Variables(customs, ARGUMENTS) | opts = Variables(customs, ARGUMENTS) | ||||||
| opts.Add('target', 'Compile Target (debug/release_debug/release).', "debug") | 
 | ||||||
| opts.Add('arch', 'Platform dependent architecture (arm/arm64/x86/x64/mips/etc)', "") | # Target build options | ||||||
| opts.Add('bits', 'Compile Target Bits (default/32/64/fat).', "default") | opts.Add('arch', "Platform-dependent architecture (arm/arm64/x86/x64/mips/etc)", '') | ||||||
| opts.Add('platform','Platform: '+str(platform_list)+'.',"") | opts.Add('bits', "Target platform bits (default/32/64/fat)", 'default') | ||||||
| opts.Add('p','Platform (same as platform=).',"") | opts.Add('p', "Platform (alias for 'platform')", '') | ||||||
| opts.Add('tools','Build Tools (Including Editor): (yes/no)','yes') | opts.Add('platform', "Target platform: any in " + str(platform_list), '') | ||||||
| opts.Add('gdscript','Build GDSCript support: (yes/no)','yes') | opts.Add('target', "Compilation target (debug/release_debug/release)", 'debug') | ||||||
| opts.Add('libogg','Ogg library for ogg container support (system/builtin)','builtin') | opts.Add('tools', "Build the tools a.k.a. the Godot editor (yes/no)", 'yes') | ||||||
| opts.Add('libvorbis','Ogg Vorbis library for vorbis support (system/builtin)','builtin') | 
 | ||||||
| opts.Add('libtheora','Theora library for theora module (system/builtin)','builtin') | # Components | ||||||
| opts.Add('opus','Opus and opusfile library for Opus format support: (system/builtin)','builtin') | opts.Add('deprecated', "Enable deprecated features (yes/no)", 'yes') | ||||||
| opts.Add('minizip','Build Minizip Archive Support: (yes/no)','yes') | opts.Add('gdscript', "Build GDSCript support (yes/no)", 'yes') | ||||||
| opts.Add('squish','Squish library for BC Texture Compression in editor (system/builtin)','builtin') | opts.Add('minizip', "Build minizip archive support (yes/no)", 'yes') | ||||||
| opts.Add('freetype','Freetype library for TTF support via freetype module (system/builtin)','builtin') | opts.Add('xaudio2', "XAudio2 audio driver (yes/no)", 'no') | ||||||
| opts.Add('xml','XML Save/Load support (yes/no)','yes') | opts.Add('xml', "XML format support for resources (yes/no)", 'yes') | ||||||
| opts.Add('libpng','libpng library for image loader support (system/builtin)','builtin') | 
 | ||||||
| opts.Add('libwebp','libwebp library for webp module (system/builtin)','builtin') | # Advanced options | ||||||
| opts.Add('openssl','OpenSSL library for openssl module (system/builtin)','builtin') | opts.Add('disable_3d', "Disable 3D nodes for smaller executable (yes/no)", 'no') | ||||||
| opts.Add('libmpcdec','libmpcdec library for mpc module (system/builtin)','builtin') | opts.Add('disable_advanced_gui', "Disable advance 3D gui nodes and behaviors (yes/no)", 'no') | ||||||
| opts.Add('enet','ENet library (system/builtin)','builtin') | opts.Add('extra_suffix', "Custom extra suffix added to the base filename of all generated binary files", '') | ||||||
| opts.Add('glew','GLEW library for the gl_context (system/builtin)','builtin') | opts.Add('unix_global_settings_path', "UNIX-specific path to system-wide settings. Currently only used for templates", '') | ||||||
| opts.Add('xaudio2','XAudio2 audio driver (yes/no)','no') | opts.Add('verbose', "Enable verbose output for the compilation (yes/no)", 'yes') | ||||||
| opts.Add("CXX", "C++ Compiler") | opts.Add('vsproj', "Generate Visual Studio Project. (yes/no)", 'no') | ||||||
| opts.Add("CC", "C Compiler") | 
 | ||||||
| opts.Add("CCFLAGS", "Custom flags for the C/C++ compiler"); | # Thirdparty libraries | ||||||
| opts.Add("CFLAGS", "Custom flags for the C compiler"); | opts.Add('builtin_enet', "Use the builtin enet library (yes/no)", 'yes') | ||||||
| opts.Add("LINKFLAGS", "Custom flags for the linker"); | opts.Add('builtin_freetype', "Use the builtin freetype library (yes/no)", 'yes') | ||||||
| opts.Add('unix_global_settings_path', 'unix-specific path to system-wide settings. Currently only used by templates.','') | opts.Add('builtin_glew', "Use the builtin glew library (yes/no)", 'yes') | ||||||
| opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no") | opts.Add('builtin_libmpcdec', "Use the builtin libmpcdec library (yes/no)", 'yes') | ||||||
| opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no") | opts.Add('builtin_libogg', "Use the builtin libogg library (yes/no)", 'yes') | ||||||
| opts.Add('verbose', 'Enable verbose output for the compilation (yes/no)', 'yes') | opts.Add('builtin_libpng', "Use the builtin libpng library (yes/no)", 'yes') | ||||||
| opts.Add('deprecated','Enable deprecated features (yes/no)','yes') | opts.Add('builtin_libtheora', "Use the builtin libtheora library (yes/no)", 'yes') | ||||||
| opts.Add('extra_suffix', 'Custom extra suffix added to the base filename of all generated binary files.', '') | opts.Add('builtin_libvorbis', "Use the builtin libvorbis library (yes/no)", 'yes') | ||||||
| opts.Add('vsproj', 'Generate Visual Studio Project. (yes/no)', 'no') | opts.Add('builtin_libvpx', "Use the builtin libvpx library (yes/no)", 'yes') | ||||||
|  | opts.Add('builtin_libwebp', "Use the builtin libwebp library (yes/no)", 'yes') | ||||||
|  | opts.Add('builtin_openssl', "Use the builtin openssl library (yes/no)", 'yes') | ||||||
|  | opts.Add('builtin_opus', "Use the builtin opus library (yes/no)", 'yes') | ||||||
|  | opts.Add('builtin_squish', "Use the builtin squish library (yes/no)", 'yes') | ||||||
|  | opts.Add('builtin_zlib', "Use the builtin zlib library (yes/no)", 'yes') | ||||||
|  | 
 | ||||||
|  | # Environment setup | ||||||
|  | opts.Add("CXX", "C++ compiler") | ||||||
|  | opts.Add("CC", "C compiler") | ||||||
|  | opts.Add("CCFLAGS", "Custom flags for the C and C++ compilers") | ||||||
|  | opts.Add("CFLAGS", "Custom flags for the C compiler") | ||||||
|  | opts.Add("LINKFLAGS", "Custom flags for the linker") | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| # add platform specific options | # add platform specific options | ||||||
| 
 | 
 | ||||||
|  | @ -179,11 +194,11 @@ sys.modules.pop('detect') | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| if (env_base['target'] == 'debug'): | if (env_base['target'] == 'debug'): | ||||||
| 	env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']); |     env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']) | ||||||
|     env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE']) |     env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE']) | ||||||
| 
 | 
 | ||||||
| if (env_base['deprecated'] != 'no'): | if (env_base['deprecated'] != 'no'): | ||||||
| 	env_base.Append(CPPFLAGS=['-DENABLE_DEPRECATED']); |     env_base.Append(CPPFLAGS=['-DENABLE_DEPRECATED']) | ||||||
| 
 | 
 | ||||||
| env_base.platforms = {} | env_base.platforms = {} | ||||||
| 
 | 
 | ||||||
|  | @ -197,7 +212,6 @@ elif env_base['p'] != "": | ||||||
|     env_base["platform"] = selected_platform |     env_base["platform"] = selected_platform | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| if selected_platform in platform_list: | if selected_platform in platform_list: | ||||||
| 
 | 
 | ||||||
|     sys.path.append("./platform/" + selected_platform) |     sys.path.append("./platform/" + selected_platform) | ||||||
|  | @ -264,7 +278,7 @@ if selected_platform in platform_list: | ||||||
|             sys.exit(255) |             sys.exit(255) | ||||||
|         suffix += ".opt" |         suffix += ".opt" | ||||||
| 
 | 
 | ||||||
| 		env.Append(CCFLAGS=['-DNDEBUG']); |         env.Append(CCFLAGS=['-DNDEBUG']) | ||||||
| 
 | 
 | ||||||
|     elif (env["target"] == "release_debug"): |     elif (env["target"] == "release_debug"): | ||||||
|         if (env["tools"] == "yes"): |         if (env["tools"] == "yes"): | ||||||
|  | @ -296,7 +310,6 @@ if selected_platform in platform_list: | ||||||
|     sys.path.remove("./platform/" + selected_platform) |     sys.path.remove("./platform/" + selected_platform) | ||||||
|     sys.modules.pop('detect') |     sys.modules.pop('detect') | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     env.module_list = [] |     env.module_list = [] | ||||||
| 
 | 
 | ||||||
|     for x in module_list: |     for x in module_list: | ||||||
|  | @ -312,9 +325,8 @@ if selected_platform in platform_list: | ||||||
|         sys.path.remove(tmppath) |         sys.path.remove(tmppath) | ||||||
|         sys.modules.pop('config') |         sys.modules.pop('config') | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     if (env.use_ptrcall): |     if (env.use_ptrcall): | ||||||
| 		env.Append(CPPFLAGS=['-DPTRCALL_ENABLED']); |         env.Append(CPPFLAGS=['-DPTRCALL_ENABLED']) | ||||||
| 
 | 
 | ||||||
|     # to test 64 bits compiltion |     # to test 64 bits compiltion | ||||||
|     # env.Append(CPPFLAGS=['-m64']) |     # env.Append(CPPFLAGS=['-m64']) | ||||||
|  | @ -337,6 +349,9 @@ if selected_platform in platform_list: | ||||||
|     if (env['verbose'] == 'no'): |     if (env['verbose'] == 'no'): | ||||||
|         methods.no_verbose(sys, env) |         methods.no_verbose(sys, env) | ||||||
|          |          | ||||||
|  |     if (True): # FIXME: detect GLES3 | ||||||
|  |         env.Append( BUILDERS = { 'GLES3_GLSL' : env.Builder(action = methods.build_gles3_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) | ||||||
|  | 
 | ||||||
|     Export('env') |     Export('env') | ||||||
| 
 | 
 | ||||||
|     # build subdirs, the build order is dependent on link order. |     # build subdirs, the build order is dependent on link order. | ||||||
|  | @ -351,7 +366,7 @@ if selected_platform in platform_list: | ||||||
|     SConscript("modules/SCsub") |     SConscript("modules/SCsub") | ||||||
|     SConscript("main/SCsub") |     SConscript("main/SCsub") | ||||||
| 
 | 
 | ||||||
| 	SConscript("platform/"+selected_platform+"/SCsub"); # build selected platform |     SConscript("platform/" + selected_platform + "/SCsub")  # build selected platform | ||||||
| 
 | 
 | ||||||
|     # Microsoft Visual Studio Project Generation |     # Microsoft Visual Studio Project Generation | ||||||
|     if (env['vsproj']) == "yes": |     if (env['vsproj']) == "yes": | ||||||
|  | @ -369,7 +384,6 @@ if selected_platform in platform_list: | ||||||
|         # has a purpose. |         # has a purpose. | ||||||
|         # env['MSVS_VERSION']='9.0' |         # env['MSVS_VERSION']='9.0' | ||||||
| 
 | 
 | ||||||
| 		 |  | ||||||
|         # Calls a CMD with /C(lose) and /V(delayed environment variable expansion) options. |         # Calls a CMD with /C(lose) and /V(delayed environment variable expansion) options. | ||||||
|         # And runs vcvarsall bat for the propper arhitecture and scons for propper configuration |         # And runs vcvarsall bat for the propper arhitecture and scons for propper configuration | ||||||
|         env['MSVSBUILDCOM'] = 'cmd /V /C set "plat=$(PlatformTarget)" ^& (if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64")) ^& set "tools=yes" ^& (if "$(Configuration)"=="release" (set "tools=no")) ^& call "$(VCInstallDir)vcvarsall.bat" !plat! ^& scons platform=windows target=$(Configuration) tools=!tools! -j2' |         env['MSVSBUILDCOM'] = 'cmd /V /C set "plat=$(PlatformTarget)" ^& (if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64")) ^& set "tools=yes" ^& (if "$(Configuration)"=="release" (set "tools=no")) ^& call "$(VCInstallDir)vcvarsall.bat" !plat! ^& scons platform=windows target=$(Configuration) tools=!tools! -j2' | ||||||
|  |  | ||||||
|  | @ -3,4 +3,4 @@ | ||||||
| Import('env') | Import('env') | ||||||
| Export('env') | Export('env') | ||||||
| 
 | 
 | ||||||
| SConscript('tests/SCsub'); | SConscript('tests/SCsub') | ||||||
|  |  | ||||||
|  | @ -1,217 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_detailer.cpp                                                    */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #include "test_detailer.h" |  | ||||||
| #include "servers/visual_server.h" |  | ||||||
| #include "os/main_loop.h" |  | ||||||
| #include "math_funcs.h" |  | ||||||
| #include "print_string.h" |  | ||||||
| #include "geometry.h" |  | ||||||
| #include "quick_hull.h" |  | ||||||
| namespace TestMultiMesh { |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class TestMainLoop : public MainLoop { |  | ||||||
| 
 |  | ||||||
| 	RID instance; |  | ||||||
| 	RID camera; |  | ||||||
| 	RID viewport; |  | ||||||
| 	RID light; |  | ||||||
| 	RID mesh; |  | ||||||
| 	RID scenario; |  | ||||||
| 
 |  | ||||||
| #define MULTIMESH_COUNT 1500 |  | ||||||
| 
 |  | ||||||
| 	float ofs_x,ofs_y; |  | ||||||
| 	bool quit; |  | ||||||
| public: |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	virtual void _update_qh() { |  | ||||||
| 
 |  | ||||||
| 		VisualServer *vs=VisualServer::get_singleton(); |  | ||||||
| 		Vector<Vector3> vts; |  | ||||||
| /*
 |  | ||||||
| 
 |  | ||||||
| 		static const int s = 20; |  | ||||||
| 		for(int i=0;i<s;i++) { |  | ||||||
| 			Matrix3 rot(Vector3(0,1,0),i*Math_PI/s); |  | ||||||
| 
 |  | ||||||
| 			for(int j=0;j<s;j++) { |  | ||||||
| 				Vector3 v; |  | ||||||
| 				v.x=Math::sin(j*Math_PI*2/s); |  | ||||||
| 				v.y=Math::cos(j*Math_PI*2/s); |  | ||||||
| 
 |  | ||||||
| 				vts.push_back( rot.xform(v*2 ) ); |  | ||||||
| 			} |  | ||||||
| 		}*/ |  | ||||||
| 		/*
 |  | ||||||
| 		Math::seed(0); |  | ||||||
| 		for(int i=0;i<50;i++) { |  | ||||||
| 
 |  | ||||||
| 			vts.push_back( Vector3(Math::randf()*2-1.0,Math::randf()*2-1.0,Math::randf()*2-1.0).normalized()*2); |  | ||||||
| 		}*/ |  | ||||||
| 		/*
 |  | ||||||
| 		vts.push_back(Vector3(0,0,1)); |  | ||||||
| 		vts.push_back(Vector3(0,0,-1)); |  | ||||||
| 		vts.push_back(Vector3(0,1,0)); |  | ||||||
| 		vts.push_back(Vector3(0,-1,0)); |  | ||||||
| 		vts.push_back(Vector3(1,0,0)); |  | ||||||
| 		vts.push_back(Vector3(-1,0,0));*/ |  | ||||||
| /*
 |  | ||||||
| 		vts.push_back(Vector3(1,1,1)); |  | ||||||
| 		vts.push_back(Vector3(1,-1,1)); |  | ||||||
| 		vts.push_back(Vector3(-1,1,1)); |  | ||||||
| 		vts.push_back(Vector3(-1,-1,1)); |  | ||||||
| 		vts.push_back(Vector3(1,1,-1)); |  | ||||||
| 		vts.push_back(Vector3(1,-1,-1)); |  | ||||||
| 		vts.push_back(Vector3(-1,1,-1)); |  | ||||||
| 		vts.push_back(Vector3(-1,-1,-1)); |  | ||||||
| */ |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,4,Vector3::AXIS_Z); |  | ||||||
| 		Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes); |  | ||||||
| 		vts=convex_data.vertices; |  | ||||||
| 
 |  | ||||||
| 		Geometry::MeshData md; |  | ||||||
| 		Error err = QuickHull::build(vts,md); |  | ||||||
| 		print_line("ERR: "+itos(err)); |  | ||||||
| 
 |  | ||||||
| 		vs->mesh_remove_surface(mesh,0); |  | ||||||
| 		vs->mesh_add_surface_from_mesh_data(mesh,md); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		//vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME);
 |  | ||||||
| 
 |  | ||||||
| 		/*
 |  | ||||||
| 		RID sm = vs->shader_create(); |  | ||||||
| 		//vs->shader_set_fragment_code(sm,"OUT_ALPHA=mod(TIME,1);");
 |  | ||||||
| 		//vs->shader_set_vertex_code(sm,"OUT_VERTEX=IN_VERTEX*mod(TIME,1);");
 |  | ||||||
| 		vs->shader_set_fragment_code(sm,"OUT_DIFFUSE=vec3(1,0,1);OUT_GLOW=abs(sin(TIME));"); |  | ||||||
| 		RID tcmat = vs->mesh_surface_get_material(test_cube,0); |  | ||||||
| 		vs->material_set_shader(tcmat,sm); |  | ||||||
| 		*/ |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	virtual void input_event(const InputEvent& p_event) { |  | ||||||
| 
 |  | ||||||
| 		if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) { |  | ||||||
| 
 |  | ||||||
| 			ofs_x+=p_event.mouse_motion.relative_y/200.0; |  | ||||||
| 			ofs_y+=p_event.mouse_motion.relative_x/200.0; |  | ||||||
| 		} |  | ||||||
| 		if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==1) { |  | ||||||
| 
 |  | ||||||
| 			QuickHull::debug_stop_after++; |  | ||||||
| 			_update_qh(); |  | ||||||
| 		} |  | ||||||
| 		if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==2) { |  | ||||||
| 
 |  | ||||||
| 			if (QuickHull::debug_stop_after>0) |  | ||||||
| 				QuickHull::debug_stop_after--; |  | ||||||
| 			_update_qh(); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	virtual void request_quit() { |  | ||||||
| 
 |  | ||||||
| 		quit=true; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	virtual void init() { |  | ||||||
| 
 |  | ||||||
| 		VisualServer *vs=VisualServer::get_singleton(); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		mesh = vs->mesh_create(); |  | ||||||
| 
 |  | ||||||
| 		scenario = vs->scenario_create(); |  | ||||||
| 
 |  | ||||||
| 		QuickHull::debug_stop_after=0; |  | ||||||
| 		_update_qh(); |  | ||||||
| 
 |  | ||||||
| 		instance = vs->instance_create2(mesh,scenario); |  | ||||||
| 
 |  | ||||||
| 		camera = vs->camera_create(); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		vs->camera_set_perspective( camera, 60.0,0.1, 100.0 ); |  | ||||||
| 		viewport = vs->viewport_create(); |  | ||||||
| 		vs->viewport_attach_camera( viewport, camera ); |  | ||||||
| 		vs->viewport_attach_to_screen(viewport); |  | ||||||
| 		vs->viewport_set_scenario( viewport, scenario ); |  | ||||||
| 
 |  | ||||||
| 		vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,2 ) ) ); |  | ||||||
| 
 |  | ||||||
| 		RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); |  | ||||||
| 		//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.3,0.3,0.3) );
 |  | ||||||
| 		light = vs->instance_create2( lightaux,scenario ); |  | ||||||
| 		vs->instance_set_transform(light,Transform(Matrix3(Vector3(0.1,0.4,0.7).normalized(),0.9))); |  | ||||||
| 
 |  | ||||||
| 		ofs_x=0; |  | ||||||
| 		ofs_y=0; |  | ||||||
| 		quit=false; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	virtual bool idle(float p_time) { |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	virtual bool iteration(float p_time) { |  | ||||||
| 
 |  | ||||||
| 		VisualServer *vs=VisualServer::get_singleton(); |  | ||||||
| 
 |  | ||||||
| 		Transform tr_camera; |  | ||||||
| 		tr_camera.rotate( Vector3(0,1,0), ofs_y ); |  | ||||||
| 		tr_camera.rotate( Vector3(1,0,0),ofs_x ); |  | ||||||
| 		tr_camera.translate(0,0,10); |  | ||||||
| 
 |  | ||||||
| 		vs->camera_set_transform( camera, tr_camera ); |  | ||||||
| 
 |  | ||||||
| 		return quit; |  | ||||||
| 	} |  | ||||||
| 	virtual void finish() { |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| MainLoop* test() { |  | ||||||
| 
 |  | ||||||
| 	return memnew(TestMainLoop); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
|  | @ -1,44 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_detailer.h                                                      */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #ifndef TEST_MULTIMESH_H |  | ||||||
| #define TEST_MULTIMESH_H |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
| 	@author Juan Linietsky <reduzio@gmail.com> |  | ||||||
| */ |  | ||||||
| #include "os/main_loop.h" |  | ||||||
| 
 |  | ||||||
| namespace TestMultiMesh { |  | ||||||
| 
 |  | ||||||
| MainLoop* test(); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
|  | @ -370,7 +370,7 @@ public: | ||||||
| 		tabc->set_size( Point2( 180,250 ) ); | 		tabc->set_size( Point2( 180,250 ) ); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 		Ref<ImageTexture> text = memnew( ImageTexture ); | 		/*Ref<ImageTexture> text = memnew( ImageTexture );
 | ||||||
| 		text->load("test_data/concave.png"); | 		text->load("test_data/concave.png"); | ||||||
| 
 | 
 | ||||||
| 		Sprite* sprite = memnew(Sprite); | 		Sprite* sprite = memnew(Sprite); | ||||||
|  | @ -383,7 +383,7 @@ public: | ||||||
| 		sprite->set_texture(text); | 		sprite->set_texture(text); | ||||||
| 		sprite->add_child(sprite2); | 		sprite->add_child(sprite2); | ||||||
| 		sprite2->set_pos(Point2(50, 50)); | 		sprite2->set_pos(Point2(50, 50)); | ||||||
| 		sprite2->show(); | 		sprite2->show();*/ | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -37,13 +37,10 @@ | ||||||
| #include "test_gui.h" | #include "test_gui.h" | ||||||
| #include "test_render.h" | #include "test_render.h" | ||||||
| #include "test_sound.h" | #include "test_sound.h" | ||||||
| #include "test_misc.h" |  | ||||||
| #include "test_physics.h" | #include "test_physics.h" | ||||||
| #include "test_physics_2d.h" | #include "test_physics_2d.h" | ||||||
| #include "test_python.h" | 
 | ||||||
| #include "test_io.h" | #include "test_io.h" | ||||||
| #include "test_particles.h" |  | ||||||
| #include "test_detailer.h" |  | ||||||
| #include "test_shader_lang.h" | #include "test_shader_lang.h" | ||||||
| #include "test_gdscript.h" | #include "test_gdscript.h" | ||||||
| #include "test_image.h" | #include "test_image.h" | ||||||
|  | @ -56,7 +53,6 @@ const char ** tests_get_names()  { | ||||||
| 		"containers", | 		"containers", | ||||||
| 		"math", | 		"math", | ||||||
| 		"render", | 		"render", | ||||||
| 		"particles", |  | ||||||
| 		"multimesh", | 		"multimesh", | ||||||
| 		"gui", | 		"gui", | ||||||
| 		"io", | 		"io", | ||||||
|  | @ -96,11 +92,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { | ||||||
| 		return TestPhysics2D::test(); | 		return TestPhysics2D::test(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|   	if (p_test=="misc") { |  | ||||||
| 
 |  | ||||||
| 		return TestMisc::test(); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (p_test=="render") { | 	if (p_test=="render") { | ||||||
| 
 | 
 | ||||||
| 		return TestRender::test(); | 		return TestRender::test(); | ||||||
|  | @ -123,16 +114,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { | ||||||
| 		return TestIO::test(); | 		return TestIO::test(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (p_test=="particles") { |  | ||||||
| 
 |  | ||||||
| 		return TestParticles::test(); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (p_test=="multimesh") { |  | ||||||
| 
 |  | ||||||
| 		return TestMultiMesh::test(); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (p_test=="shaderlang") { | 	if (p_test=="shaderlang") { | ||||||
| 
 | 
 | ||||||
| 		return TestShaderLang::test(); | 		return TestShaderLang::test(); | ||||||
|  | @ -163,19 +144,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { | ||||||
| 		return TestImage::test(); | 		return TestImage::test(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (p_test=="detailer") { |  | ||||||
| 
 |  | ||||||
| 		return TestMultiMesh::test(); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| #ifdef PYTHON_ENABLED |  | ||||||
| 
 |  | ||||||
| 	if (p_test=="python") { |  | ||||||
| 
 |  | ||||||
| 		return TestPython::test(); |  | ||||||
| 	} |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,499 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_misc.cpp                                                        */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #include "test_misc.h" |  | ||||||
| #include "servers/visual_server.h" |  | ||||||
| #include "os/main_loop.h" |  | ||||||
| #include "math_funcs.h" |  | ||||||
| #include "print_string.h" |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| namespace TestMisc { |  | ||||||
| 
 |  | ||||||
| struct ConvexTestResult |  | ||||||
| { |  | ||||||
| 
 |  | ||||||
| 	Vector3 edgeA[2]; |  | ||||||
| 	Vector3 edgeB[2]; |  | ||||||
| 	bool valid; |  | ||||||
| 	Vector3 contactA; |  | ||||||
| 	Vector3 contactB; |  | ||||||
| 	Vector3 contactNormal; |  | ||||||
| 	float depth; |  | ||||||
| 
 |  | ||||||
| 	/*
 |  | ||||||
| 	Vector3 contactA; |  | ||||||
| 	Vector3 contactB; |  | ||||||
| 	Vector3 contactNormal; |  | ||||||
| 	Vector3 contactX; |  | ||||||
| 	Vector3 contactY; |  | ||||||
| 	Vector3 edgeA[2]; |  | ||||||
| 	Vector3 edgeB[2]; |  | ||||||
| 	float depth; |  | ||||||
| 	bool valid; |  | ||||||
| 	bool isEdgeEdge; |  | ||||||
| 	bool needTransform; |  | ||||||
| 	neBool ComputerEdgeContactPoint(ConvexTestResult & res); |  | ||||||
| 	neBool ComputerEdgeContactPoint2(float & au, float & bu); |  | ||||||
| 	void Reverse() |  | ||||||
| 	{ |  | ||||||
| 		neSwap(contactA, contactB); |  | ||||||
| 		contactNormal *= -1.0f; |  | ||||||
| 	}*/ |  | ||||||
| 	bool ComputerEdgeContactPoint2(float & au, float & bu); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| bool ConvexTestResult::ComputerEdgeContactPoint2(float & au, float & bu) |  | ||||||
| { |  | ||||||
| 	float d1343, d4321, d1321, d4343, d2121; |  | ||||||
| 	float numer, denom; |  | ||||||
| 
 |  | ||||||
| 	Vector3 p13; |  | ||||||
| 	Vector3 p43; |  | ||||||
| 	Vector3 p21; |  | ||||||
| 	Vector3 diff; |  | ||||||
| 
 |  | ||||||
| 	p13 = (edgeA[0]) - (edgeB[0]); |  | ||||||
| 	p43 = (edgeB[1]) - (edgeB[0]); |  | ||||||
| 
 |  | ||||||
| 	if ( p43.length_squared() < CMP_EPSILON2 ) |  | ||||||
| 	{ |  | ||||||
| 		valid = false; |  | ||||||
| 		goto ComputerEdgeContactPoint2_Exit; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	p21 = (edgeA[1]) - (edgeA[0]); |  | ||||||
| 
 |  | ||||||
| 	if ( p21.length_squared()<CMP_EPSILON2 ) |  | ||||||
| 	{ |  | ||||||
| 		valid = false; |  | ||||||
| 		goto ComputerEdgeContactPoint2_Exit; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	d1343 = p13.dot(p43); |  | ||||||
| 	d4321 = p43.dot(p21); |  | ||||||
| 	d1321 = p13.dot(p21); |  | ||||||
| 	d4343 = p43.dot(p43); |  | ||||||
| 	d2121 = p21.dot(p21); |  | ||||||
| 
 |  | ||||||
| 	denom = d2121 * d4343 - d4321 * d4321; |  | ||||||
| 
 |  | ||||||
| 	if (ABS(denom) < CMP_EPSILON) |  | ||||||
| 	{ |  | ||||||
| 		valid = false; |  | ||||||
| 
 |  | ||||||
| 		goto ComputerEdgeContactPoint2_Exit; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	numer = d1343 * d4321 - d1321 * d4343; |  | ||||||
| 	au = numer / denom; |  | ||||||
| 	bu = (d1343 + d4321 * (au)) / d4343; |  | ||||||
| 
 |  | ||||||
| 	if (au < 0.0f || au >= 1.0f) |  | ||||||
| 	{ |  | ||||||
| 		valid = false; |  | ||||||
| 	} |  | ||||||
| 	else if (bu < 0.0f || bu >= 1.0f) |  | ||||||
| 	{ |  | ||||||
| 		valid = false; |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		valid = true; |  | ||||||
| 	} |  | ||||||
| 	{ |  | ||||||
| 		Vector3 tmpv; |  | ||||||
| 
 |  | ||||||
| 		tmpv = p21 * au; |  | ||||||
| 		contactA = (edgeA[0]) + tmpv; |  | ||||||
| 
 |  | ||||||
| 		tmpv = p43 * bu; |  | ||||||
| 		contactB = (edgeB[0]) + tmpv; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	diff = contactA - contactB; |  | ||||||
| 
 |  | ||||||
| 	depth = Math::sqrt(diff.dot(diff)); |  | ||||||
| 
 |  | ||||||
| 	return true; |  | ||||||
| 
 |  | ||||||
| ComputerEdgeContactPoint2_Exit: |  | ||||||
| 
 |  | ||||||
| 	return false; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| struct neCollisionResult { |  | ||||||
| 
 |  | ||||||
| 	float depth; |  | ||||||
| 	bool penetrate; |  | ||||||
| 	Matrix3 collisionFrame; |  | ||||||
| 	Vector3 contactA; |  | ||||||
| 	Vector3 contactB; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| struct TConvex { |  | ||||||
| 
 |  | ||||||
| 	float radius; |  | ||||||
| 	float half_height; |  | ||||||
| 	float CylinderRadius() const { return radius; } |  | ||||||
| 	float CylinderHalfHeight() const { return half_height; } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| float GetDistanceFromLine2(Vector3 v, Vector3 & project, const Vector3 & pointA, const Vector3 & pointB) |  | ||||||
| { |  | ||||||
| 	Vector3 ba = pointB - pointA; |  | ||||||
| 
 |  | ||||||
| 	float len = ba.length(); |  | ||||||
| 
 |  | ||||||
| 	if (len<CMP_EPSILON) |  | ||||||
| 		ba=Vector3(); |  | ||||||
| 	else |  | ||||||
| 		ba *= 1.0f / len; |  | ||||||
| 
 |  | ||||||
| 	Vector3 pa = v - pointA; |  | ||||||
| 
 |  | ||||||
| 	float k = pa.dot(ba); |  | ||||||
| 
 |  | ||||||
| 	project = pointA + ba * k; |  | ||||||
| 
 |  | ||||||
| 	Vector3 diff = v - project; |  | ||||||
| 
 |  | ||||||
| 	return diff.length(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void TestCylinderVertEdge(neCollisionResult & result, Vector3 & edgeA1, Vector3 & edgeA2, Vector3 & vertB, |  | ||||||
| 						  TConvex & cA, TConvex & cB, Transform & transA, Transform & transB, bool flip) |  | ||||||
| { |  | ||||||
| 	Vector3 project; |  | ||||||
| 
 |  | ||||||
| 	float dist = GetDistanceFromLine2(vertB,project, edgeA1, edgeA2); |  | ||||||
| 
 |  | ||||||
| 	float depth = cA.CylinderRadius() + cB.CylinderRadius() - dist; |  | ||||||
| 
 |  | ||||||
| 	if (depth <= 0.0f) |  | ||||||
| 		return; |  | ||||||
| 
 |  | ||||||
| 	if (depth <= result.depth) |  | ||||||
| 		return; |  | ||||||
| 
 |  | ||||||
| 	result.penetrate = true; |  | ||||||
| 
 |  | ||||||
| 	result.depth = depth; |  | ||||||
| 
 |  | ||||||
| 	if (!flip) |  | ||||||
| 	{ |  | ||||||
| 		result.collisionFrame.set_axis(2,(project - vertB).normalized()); |  | ||||||
| 
 |  | ||||||
| 		result.contactA = project - result.collisionFrame.get_axis(2) * cA.CylinderRadius(); |  | ||||||
| 
 |  | ||||||
| 		result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius(); |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 
 |  | ||||||
| 		result.collisionFrame.set_axis(2,(vertB - project).normalized()); |  | ||||||
| 
 |  | ||||||
| 		result.contactA = vertB - result.collisionFrame.get_axis(2) * cB.CylinderRadius(); |  | ||||||
| 
 |  | ||||||
| 		result.contactB = project + result.collisionFrame.get_axis(2) * cA.CylinderRadius(); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void TestCylinderVertVert(neCollisionResult & result, Vector3 & vertA, Vector3 & vertB, |  | ||||||
| 						  TConvex & cA, TConvex & cB, Transform & transA, Transform & transB) |  | ||||||
| { |  | ||||||
| 	Vector3 diff = vertA - vertB; |  | ||||||
| 
 |  | ||||||
| 	float dist = diff.length(); |  | ||||||
| 
 |  | ||||||
| 	float depth = cA.CylinderRadius() + cB.CylinderRadius() - dist; |  | ||||||
| 
 |  | ||||||
| 	if (depth <= 0.0f) |  | ||||||
| 		return; |  | ||||||
| 
 |  | ||||||
| 	if (depth <= result.depth) |  | ||||||
| 		return; |  | ||||||
| 
 |  | ||||||
| 	result.penetrate = true; |  | ||||||
| 
 |  | ||||||
| 	result.depth = depth; |  | ||||||
| 
 |  | ||||||
| 	result.collisionFrame.set_axis(2, diff * (1.0f / dist)); |  | ||||||
| 
 |  | ||||||
| 	result.contactA = vertA - result.collisionFrame.get_axis(2) * cA.CylinderRadius(); |  | ||||||
| 
 |  | ||||||
| 	result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void Cylinder2CylinderTest(neCollisionResult & result, TConvex & cA, Transform & transA, TConvex & cB, Transform & transB) |  | ||||||
| { |  | ||||||
| 	result.penetrate = false; |  | ||||||
| 
 |  | ||||||
| 	Vector3 dir = transA.basis.get_axis(1).cross(transB.basis.get_axis(1)); |  | ||||||
| 
 |  | ||||||
| 	float len = dir.length(); |  | ||||||
| 
 |  | ||||||
| //	bool isParallel = len<CMP_EPSILON;
 |  | ||||||
| 
 |  | ||||||
| //	int doVertCheck = 0;
 |  | ||||||
| 
 |  | ||||||
| 	ConvexTestResult cr; |  | ||||||
| 
 |  | ||||||
| 	cr.edgeA[0] = transA.origin + transA.basis.get_axis(1) * cA.CylinderHalfHeight(); |  | ||||||
| 	cr.edgeA[1] = transA.origin - transA.basis.get_axis(1) * cA.CylinderHalfHeight(); |  | ||||||
| 	cr.edgeB[0] = transB.origin + transB.basis.get_axis(1) * cB.CylinderHalfHeight(); |  | ||||||
| 	cr.edgeB[1] = transB.origin - transB.basis.get_axis(1) * cB.CylinderHalfHeight(); |  | ||||||
| 
 |  | ||||||
| //	float dot = transA.basis.get_axis(1).dot(transB.basis.get_axis(1));
 |  | ||||||
| 
 |  | ||||||
| 	if (len>CMP_EPSILON) |  | ||||||
| 	{ |  | ||||||
| 		float au, bu; |  | ||||||
| 
 |  | ||||||
| 		cr.ComputerEdgeContactPoint2(au, bu); |  | ||||||
| 
 |  | ||||||
| 		if (cr.valid) |  | ||||||
| 		{ |  | ||||||
| 			float depth = cA.CylinderRadius() + cB.CylinderRadius() - cr.depth; |  | ||||||
| 
 |  | ||||||
| 			if (depth <= 0.0f) |  | ||||||
| 				return; |  | ||||||
| 
 |  | ||||||
| 			result.depth = depth; |  | ||||||
| 
 |  | ||||||
| 			result.penetrate = true; |  | ||||||
| 
 |  | ||||||
| 			result.collisionFrame.set_axis(2, (cr.contactA - cr.contactB)*(1.0f / cr.depth)); |  | ||||||
| 
 |  | ||||||
| 			result.contactA = cr.contactA - result.collisionFrame.get_axis(2) * cA.CylinderRadius(); |  | ||||||
| 
 |  | ||||||
| 			result.contactB = cr.contactB + result.collisionFrame.get_axis(2) * cB.CylinderRadius(); |  | ||||||
| 
 |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	result.depth = -1.0e6f; |  | ||||||
| 
 |  | ||||||
| 	int i; |  | ||||||
| 
 |  | ||||||
| 	for (i = 0; i < 2; i++) |  | ||||||
| 	{ |  | ||||||
| 		//project onto edge b
 |  | ||||||
| 
 |  | ||||||
| 		Vector3 diff = cr.edgeA[i] - cr.edgeB[1]; |  | ||||||
| 
 |  | ||||||
| 		float dot = diff.dot(transB.basis.get_axis(1)); |  | ||||||
| 
 |  | ||||||
| 		if (dot < 0.0f) |  | ||||||
| 		{ |  | ||||||
| 			TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[1], cA, cB, transA, transB); |  | ||||||
| 		} |  | ||||||
| 		else if (dot > (2.0f * cB.CylinderHalfHeight())) |  | ||||||
| 		{ |  | ||||||
| 			TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[0], cA, cB, transA, transB); |  | ||||||
| 		} |  | ||||||
| 		else |  | ||||||
| 		{ |  | ||||||
| 			TestCylinderVertEdge(result, cr.edgeB[0], cr.edgeB[1], cr.edgeA[i], cB, cA, transB, transA, true); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	for (i = 0; i < 2; i++) |  | ||||||
| 	{ |  | ||||||
| 		//project onto edge b
 |  | ||||||
| 
 |  | ||||||
| 		Vector3 diff = cr.edgeB[i] - cr.edgeA[1]; |  | ||||||
| 
 |  | ||||||
| 		float dot = diff.dot(transA.basis.get_axis(1)); |  | ||||||
| 
 |  | ||||||
| 		if (dot < 0.0f) |  | ||||||
| 		{ |  | ||||||
| 			TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[1], cA, cB, transA, transB); |  | ||||||
| 		} |  | ||||||
| 		else if (dot > (2.0f * cB.CylinderHalfHeight())) |  | ||||||
| 		{ |  | ||||||
| 			TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[0], cA, cB, transA, transB); |  | ||||||
| 		} |  | ||||||
| 		else |  | ||||||
| 		{ |  | ||||||
| 			TestCylinderVertEdge(result, cr.edgeA[0], cr.edgeA[1], cr.edgeB[i], cA, cB, transA, transB, false); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class TestMainLoop : public MainLoop { |  | ||||||
| 
 |  | ||||||
| 	RID meshA; |  | ||||||
| 	RID meshB; |  | ||||||
| 	RID poly; |  | ||||||
| 	RID instance; |  | ||||||
| 	RID camera; |  | ||||||
| 	RID viewport; |  | ||||||
| 	RID boxA; |  | ||||||
| 	RID boxB; |  | ||||||
| 	RID scenario; |  | ||||||
| 
 |  | ||||||
| 	Transform rot_a; |  | ||||||
| 	Transform rot_b; |  | ||||||
| 
 |  | ||||||
| 	bool quit; |  | ||||||
| public: |  | ||||||
| 	virtual void input_event(const InputEvent& p_event) { |  | ||||||
| 
 |  | ||||||
| 		if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { |  | ||||||
| 
 |  | ||||||
| 			rot_b.origin.y+=-p_event.mouse_motion.relative_y/100.0; |  | ||||||
| 			rot_b.origin.x+=p_event.mouse_motion.relative_x/100.0; |  | ||||||
| 		} |  | ||||||
| 		if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_MIDDLE) { |  | ||||||
| 
 |  | ||||||
| 			//rot_b.origin.x+=-p_event.mouse_motion.relative_y/100.0;
 |  | ||||||
| 			rot_b.origin.z+=p_event.mouse_motion.relative_x/100.0; |  | ||||||
| 		} |  | ||||||
| 		if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_RIGHT) { |  | ||||||
| 
 |  | ||||||
| 			float rot_x=-p_event.mouse_motion.relative_y/100.0; |  | ||||||
| 			float rot_y=p_event.mouse_motion.relative_x/100.0; |  | ||||||
| 			rot_b.basis = rot_b.basis * Matrix3(Vector3(1,0,0),rot_x) * Matrix3(Vector3(0,1,0),rot_y); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 	virtual void request_quit() { |  | ||||||
| 
 |  | ||||||
| 		quit=true; |  | ||||||
| 	} |  | ||||||
| 	virtual void init() { |  | ||||||
| 
 |  | ||||||
| 		VisualServer *vs=VisualServer::get_singleton(); |  | ||||||
| 
 |  | ||||||
| 		camera = vs->camera_create(); |  | ||||||
| 
 |  | ||||||
| 		viewport = vs->viewport_create(); |  | ||||||
| 		vs->viewport_attach_to_screen(viewport); |  | ||||||
| 		vs->viewport_attach_camera( viewport, camera ); |  | ||||||
| 		vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,3 ) ) ); |  | ||||||
| 
 |  | ||||||
| 		/* CONVEX SHAPE */ |  | ||||||
| 
 |  | ||||||
| 		DVector<Plane> cylinder_planes = Geometry::build_cylinder_planes(0.5,2,9,Vector3::AXIS_Y); |  | ||||||
| 		RID cylinder_material = vs->fixed_material_create(); |  | ||||||
| 		vs->fixed_material_set_param( cylinder_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8,0.2,0.9)); |  | ||||||
| 		vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_ONTOP,true); |  | ||||||
| 		//vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_WIREFRAME,true);
 |  | ||||||
| 		vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_DOUBLE_SIDED,true); |  | ||||||
| 		vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_UNSHADED,true); |  | ||||||
| 
 |  | ||||||
| 		RID cylinder_mesh = vs->mesh_create(); |  | ||||||
| 		Geometry::MeshData cylinder_data = Geometry::build_convex_mesh(cylinder_planes); |  | ||||||
| 		vs->mesh_add_surface_from_mesh_data(cylinder_mesh,cylinder_data); |  | ||||||
| 		vs->mesh_surface_set_material( cylinder_mesh, 0, cylinder_material ); |  | ||||||
| 
 |  | ||||||
| 		meshA=vs->instance_create2(cylinder_mesh,scenario); |  | ||||||
| 		meshB=vs->instance_create2(cylinder_mesh,scenario); |  | ||||||
| 		boxA=vs->instance_create2(vs->get_test_cube(),scenario); |  | ||||||
| 		boxB=vs->instance_create2(vs->get_test_cube(),scenario); |  | ||||||
| 
 |  | ||||||
| 		/*
 |  | ||||||
| 		RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI ); |  | ||||||
| 		vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_RADIUS, 80 ); |  | ||||||
| 		vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ATTENUATION, 1 ); |  | ||||||
| 		vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 ); |  | ||||||
| 		light = vs->instance_create2( lightaux ); |  | ||||||
| 		*/ |  | ||||||
| 		RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); |  | ||||||
| 		//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
 |  | ||||||
| 		//vs->light_set_shadow( lightaux, true );
 |  | ||||||
| 		vs->instance_create2( lightaux,scenario ); |  | ||||||
| 
 |  | ||||||
| 		//rot_a=Transform(Matrix3(Vector3(1,0,0),Math_PI/2.0),Vector3());
 |  | ||||||
| 		rot_b=Transform(Matrix3(),Vector3(2,0,0)); |  | ||||||
| 
 |  | ||||||
| 		//rot_x=0;
 |  | ||||||
| 		//rot_y=0;
 |  | ||||||
| 		quit=false; |  | ||||||
| 	} |  | ||||||
| 	virtual bool idle(float p_time) { |  | ||||||
| 
 |  | ||||||
| 		VisualServer *vs=VisualServer::get_singleton(); |  | ||||||
| 
 |  | ||||||
| 		vs->instance_set_transform(meshA,rot_a); |  | ||||||
| 		vs->instance_set_transform(meshB,rot_b); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		neCollisionResult res; |  | ||||||
| 		TConvex a; |  | ||||||
| 		a.radius=0.5; |  | ||||||
| 		a.half_height=1; |  | ||||||
| 		Cylinder2CylinderTest(res,a,rot_a,a,rot_b); |  | ||||||
| 		if (res.penetrate) { |  | ||||||
| 
 |  | ||||||
| 			Matrix3 scale; |  | ||||||
| 			scale.scale(Vector3(0.1,0.1,0.1)); |  | ||||||
| 			vs->instance_set_transform(boxA,Transform(scale,res.contactA)); |  | ||||||
| 			vs->instance_set_transform(boxB,Transform(scale,res.contactB)); |  | ||||||
| 			print_line("depth: "+rtos(res.depth)); |  | ||||||
| 		} else  { |  | ||||||
| 
 |  | ||||||
| 			Matrix3 scale; |  | ||||||
| 			scale.scale(Vector3()); |  | ||||||
| 			vs->instance_set_transform(boxA,Transform(scale,res.contactA)); |  | ||||||
| 			vs->instance_set_transform(boxB,Transform(scale,res.contactB)); |  | ||||||
| 
 |  | ||||||
| 		} |  | ||||||
| 		print_line("collided: "+itos(res.penetrate)); |  | ||||||
| 
 |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	virtual bool iteration(float p_time) { |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		return quit; |  | ||||||
| 	} |  | ||||||
| 	virtual void finish() { |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| MainLoop* test() { |  | ||||||
| 
 |  | ||||||
| 	return memnew( TestMainLoop ); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  | @ -1,40 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_misc.h                                                          */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #ifndef TEST_MISC_H |  | ||||||
| #define TEST_MISC_H |  | ||||||
| 
 |  | ||||||
| #include "os/main_loop.h" |  | ||||||
| 
 |  | ||||||
| namespace TestMisc { |  | ||||||
| 
 |  | ||||||
| MainLoop* test(); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
|  | @ -1,121 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_particles.cpp                                                   */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #include "test_particles.h" |  | ||||||
| #include "servers/visual_server.h" |  | ||||||
| #include "os/main_loop.h" |  | ||||||
| #include "math_funcs.h" |  | ||||||
| #include "print_string.h" |  | ||||||
| 
 |  | ||||||
| namespace TestParticles { |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class TestMainLoop : public MainLoop { |  | ||||||
| 
 |  | ||||||
| 	RID particles; |  | ||||||
| 	RID instance; |  | ||||||
| 	RID camera; |  | ||||||
| 	RID viewport; |  | ||||||
| 	RID light; |  | ||||||
| 	RID scenario; |  | ||||||
| 
 |  | ||||||
| 	struct InstanceInfo { |  | ||||||
| 
 |  | ||||||
| 		RID instance; |  | ||||||
| 		Transform base; |  | ||||||
| 		Vector3 rot_axis; |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	List<InstanceInfo> instances; |  | ||||||
| 
 |  | ||||||
| 	float ofs; |  | ||||||
| 	bool quit; |  | ||||||
| public: |  | ||||||
| 	virtual void input_event(const InputEvent& p_event) { |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 	virtual void request_quit() { |  | ||||||
| 
 |  | ||||||
| 		quit=true; |  | ||||||
| 	} |  | ||||||
| 	virtual void init() { |  | ||||||
| 
 |  | ||||||
| 		VisualServer *vs=VisualServer::get_singleton(); |  | ||||||
| 		particles = vs->particles_create(); |  | ||||||
| 		vs->particles_set_amount(particles,1000); |  | ||||||
| 
 |  | ||||||
| 		instance = vs->instance_create2(particles,scenario); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		camera = vs->camera_create(); |  | ||||||
| 
 |  | ||||||
| // 		vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
 |  | ||||||
| 		viewport = vs->viewport_create(); |  | ||||||
| 		vs->viewport_attach_camera( viewport, camera ); |  | ||||||
| 		vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,20 ) ) ); |  | ||||||
| 		/*
 |  | ||||||
| 		RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI ); |  | ||||||
| 		vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_RADIUS, 80 ); |  | ||||||
| 		vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ATTENUATION, 1 ); |  | ||||||
| 		vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 ); |  | ||||||
| 		light = vs->instance_create2( lightaux ); |  | ||||||
| 		*/ |  | ||||||
| 		RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); |  | ||||||
| 	//	vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
 |  | ||||||
| 		light = vs->instance_create2( lightaux, scenario ); |  | ||||||
| 
 |  | ||||||
| 		ofs=0; |  | ||||||
| 		quit=false; |  | ||||||
| 	} |  | ||||||
| 	virtual bool idle(float p_time) { |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	virtual bool iteration(float p_time) { |  | ||||||
| 
 |  | ||||||
| //		VisualServer *vs=VisualServer::get_singleton();
 |  | ||||||
| 
 |  | ||||||
| 		ofs+=p_time; |  | ||||||
| 		return quit; |  | ||||||
| 	} |  | ||||||
| 	virtual void finish() { |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| MainLoop* test() { |  | ||||||
| 
 |  | ||||||
| 	return memnew( TestMainLoop ); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
|  | @ -1,43 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_particles.h                                                     */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #ifndef TEST_PARTICLES_H |  | ||||||
| #define TEST_PARTICLES_H |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
| 	@author Juan Linietsky <reduzio@gmail.com> |  | ||||||
| */ |  | ||||||
| #include "os/main_loop.h" |  | ||||||
| 
 |  | ||||||
| namespace TestParticles { |  | ||||||
| 
 |  | ||||||
| MainLoop* test(); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
|  | @ -138,10 +138,6 @@ protected: | ||||||
| 
 | 
 | ||||||
| 		/* SPHERE SHAPE */ | 		/* SPHERE SHAPE */ | ||||||
| 		RID sphere_mesh = vs->make_sphere_mesh(10,20,0.5); | 		RID sphere_mesh = vs->make_sphere_mesh(10,20,0.5); | ||||||
| 		RID sphere_material = vs->fixed_material_create(); |  | ||||||
| 		//vs->material_set_flag( sphere_material, VisualServer::MATERIAL_FLAG_WIREFRAME, true );
 |  | ||||||
| 		vs->fixed_material_set_param( sphere_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.7,0.8,3.0) ); |  | ||||||
| 		vs->mesh_surface_set_material( sphere_mesh, 0, sphere_material ); |  | ||||||
| 		type_mesh_map[PhysicsServer::SHAPE_SPHERE]=sphere_mesh; | 		type_mesh_map[PhysicsServer::SHAPE_SPHERE]=sphere_mesh; | ||||||
| 
 | 
 | ||||||
| 		RID sphere_shape=ps->shape_create(PhysicsServer::SHAPE_SPHERE); | 		RID sphere_shape=ps->shape_create(PhysicsServer::SHAPE_SPHERE); | ||||||
|  | @ -151,12 +147,9 @@ protected: | ||||||
| 		/* BOX SHAPE */ | 		/* BOX SHAPE */ | ||||||
| 
 | 
 | ||||||
| 		DVector<Plane> box_planes = Geometry::build_box_planes(Vector3(0.5,0.5,0.5)); | 		DVector<Plane> box_planes = Geometry::build_box_planes(Vector3(0.5,0.5,0.5)); | ||||||
| 		RID box_material = vs->fixed_material_create(); |  | ||||||
| 		vs->fixed_material_set_param( box_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0,0.2,0.2) ); |  | ||||||
| 		RID box_mesh = vs->mesh_create(); | 		RID box_mesh = vs->mesh_create(); | ||||||
| 		Geometry::MeshData box_data = Geometry::build_convex_mesh(box_planes); | 		Geometry::MeshData box_data = Geometry::build_convex_mesh(box_planes); | ||||||
| 		vs->mesh_add_surface_from_mesh_data(box_mesh,box_data); | 		vs->mesh_add_surface_from_mesh_data(box_mesh,box_data); | ||||||
| 		vs->mesh_surface_set_material( box_mesh, 0, box_material ); |  | ||||||
| 		type_mesh_map[PhysicsServer::SHAPE_BOX]=box_mesh; | 		type_mesh_map[PhysicsServer::SHAPE_BOX]=box_mesh; | ||||||
| 
 | 
 | ||||||
| 		RID box_shape=ps->shape_create(PhysicsServer::SHAPE_BOX); | 		RID box_shape=ps->shape_create(PhysicsServer::SHAPE_BOX); | ||||||
|  | @ -167,13 +160,11 @@ protected: | ||||||
| 		/* CAPSULE SHAPE */ | 		/* CAPSULE SHAPE */ | ||||||
| 
 | 
 | ||||||
| 		DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,0.7,12,Vector3::AXIS_Z); | 		DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,0.7,12,Vector3::AXIS_Z); | ||||||
| 		RID capsule_material = vs->fixed_material_create(); |  | ||||||
| 		vs->fixed_material_set_param( capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.3,0.4,1.0) ); |  | ||||||
| 
 | 
 | ||||||
| 		RID capsule_mesh = vs->mesh_create(); | 		RID capsule_mesh = vs->mesh_create(); | ||||||
| 		Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes); | 		Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes); | ||||||
| 		vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data); | 		vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data); | ||||||
| 		vs->mesh_surface_set_material( capsule_mesh, 0, capsule_material ); | 
 | ||||||
| 		type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh; | 		type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh; | ||||||
| 
 | 
 | ||||||
| 		RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE); | 		RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE); | ||||||
|  | @ -186,14 +177,12 @@ protected: | ||||||
| 		/* CONVEX SHAPE */ | 		/* CONVEX SHAPE */ | ||||||
| 
 | 
 | ||||||
| 		DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,5,Vector3::AXIS_Z); | 		DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,5,Vector3::AXIS_Z); | ||||||
| 		RID convex_material = vs->fixed_material_create(); |  | ||||||
| 		vs->fixed_material_set_param( convex_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8,0.2,0.9)); |  | ||||||
| 
 | 
 | ||||||
| 		RID convex_mesh = vs->mesh_create(); | 		RID convex_mesh = vs->mesh_create(); | ||||||
| 		Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes); | 		Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes); | ||||||
| 		QuickHull::build(convex_data.vertices,convex_data); | 		QuickHull::build(convex_data.vertices,convex_data); | ||||||
| 		vs->mesh_add_surface_from_mesh_data(convex_mesh,convex_data); | 		vs->mesh_add_surface_from_mesh_data(convex_mesh,convex_data); | ||||||
| 		vs->mesh_surface_set_material( convex_mesh, 0, convex_material ); | 
 | ||||||
| 		type_mesh_map[PhysicsServer::SHAPE_CONVEX_POLYGON]=convex_mesh; | 		type_mesh_map[PhysicsServer::SHAPE_CONVEX_POLYGON]=convex_mesh; | ||||||
| 
 | 
 | ||||||
| 		RID convex_shape=ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON); | 		RID convex_shape=ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON); | ||||||
|  | @ -223,11 +212,9 @@ protected: | ||||||
| 		d.resize(VS::ARRAY_MAX); | 		d.resize(VS::ARRAY_MAX); | ||||||
| 		d[VS::ARRAY_VERTEX]=p_faces; | 		d[VS::ARRAY_VERTEX]=p_faces; | ||||||
| 		d[VS::ARRAY_NORMAL]=normals; | 		d[VS::ARRAY_NORMAL]=normals; | ||||||
| 		vs->mesh_add_surface(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d ); | 		vs->mesh_add_surface_from_arrays(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d ); | ||||||
| 		RID trimesh_mat = vs->fixed_material_create(); |  | ||||||
| 		vs->fixed_material_set_param( trimesh_mat, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0,0.5,0.8)); |  | ||||||
| 		//vs->material_set_flag( trimesh_mat, VisualServer::MATERIAL_FLAG_UNSHADED,true);
 | 		//vs->material_set_flag( trimesh_mat, VisualServer::MATERIAL_FLAG_UNSHADED,true);
 | ||||||
| 		vs->mesh_surface_set_material( trimesh_mesh, 0, trimesh_mat ); | 
 | ||||||
| 
 | 
 | ||||||
| 		RID triins = vs->instance_create2(trimesh_mesh,scenario); | 		RID triins = vs->instance_create2(trimesh_mesh,scenario); | ||||||
| 
 | 
 | ||||||
|  | @ -464,7 +451,7 @@ public: | ||||||
| 	} | 	} | ||||||
| 	virtual bool iteration(float p_time) { | 	virtual bool iteration(float p_time) { | ||||||
| 
 | 
 | ||||||
| 		if (mover) { | 		if (mover.is_valid()) { | ||||||
| 			static float joy_speed = 10; | 			static float joy_speed = 10; | ||||||
| 			PhysicsServer * ps = PhysicsServer::get_singleton(); | 			PhysicsServer * ps = PhysicsServer::get_singleton(); | ||||||
| 			Transform t = ps->body_get_state(mover,PhysicsServer::BODY_STATE_TRANSFORM); | 			Transform t = ps->body_get_state(mover,PhysicsServer::BODY_STATE_TRANSFORM); | ||||||
|  | @ -548,15 +535,10 @@ public: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 		DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,1,12,5,Vector3::AXIS_Y); | 		DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,1,12,5,Vector3::AXIS_Y); | ||||||
| 		RID capsule_material = vs->fixed_material_create(); |  | ||||||
| 
 |  | ||||||
| 		vs->fixed_material_set_param( capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1,1,1) ); |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| 		RID capsule_mesh = vs->mesh_create(); | 		RID capsule_mesh = vs->mesh_create(); | ||||||
| 		Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes); | 		Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes); | ||||||
| 		vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data); | 		vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data); | ||||||
| 		vs->mesh_surface_set_material( capsule_mesh, 0, capsule_material ); |  | ||||||
| 		type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh; | 		type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh; | ||||||
| 
 | 
 | ||||||
| 		RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE); | 		RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE); | ||||||
|  |  | ||||||
|  | @ -85,7 +85,7 @@ class TestPhysics2DMainLoop : public MainLoop { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			Image image(32,2,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels); | 			Image image(32,2,0,Image::FORMAT_LA8,pixels); | ||||||
| 
 | 
 | ||||||
| 			body_shape_data[Physics2DServer::SHAPE_SEGMENT].image=vs->texture_create_from_image(image); | 			body_shape_data[Physics2DServer::SHAPE_SEGMENT].image=vs->texture_create_from_image(image); | ||||||
| 
 | 
 | ||||||
|  | @ -113,7 +113,7 @@ class TestPhysics2DMainLoop : public MainLoop { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			Image image(32,32,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels); | 			Image image(32,32,0,Image::FORMAT_LA8,pixels); | ||||||
| 
 | 
 | ||||||
| 			body_shape_data[Physics2DServer::SHAPE_CIRCLE].image=vs->texture_create_from_image(image); | 			body_shape_data[Physics2DServer::SHAPE_CIRCLE].image=vs->texture_create_from_image(image); | ||||||
| 
 | 
 | ||||||
|  | @ -141,7 +141,7 @@ class TestPhysics2DMainLoop : public MainLoop { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			Image image(32,32,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels); | 			Image image(32,32,0,Image::FORMAT_LA8,pixels); | ||||||
| 
 | 
 | ||||||
| 			body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image=vs->texture_create_from_image(image); | 			body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image=vs->texture_create_from_image(image); | ||||||
| 
 | 
 | ||||||
|  | @ -173,7 +173,7 @@ class TestPhysics2DMainLoop : public MainLoop { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			Image image(32,64,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels); | 			Image image(32,64,0,Image::FORMAT_LA8,pixels); | ||||||
| 
 | 
 | ||||||
| 			body_shape_data[Physics2DServer::SHAPE_CAPSULE].image=vs->texture_create_from_image(image); | 			body_shape_data[Physics2DServer::SHAPE_CAPSULE].image=vs->texture_create_from_image(image); | ||||||
| 
 | 
 | ||||||
|  | @ -381,7 +381,7 @@ public: | ||||||
| 			RID vp = vs->viewport_create(); | 			RID vp = vs->viewport_create(); | ||||||
| 			canvas = vs->canvas_create(); | 			canvas = vs->canvas_create(); | ||||||
| 			vs->viewport_attach_canvas(vp,canvas); | 			vs->viewport_attach_canvas(vp,canvas); | ||||||
| 			vs->viewport_attach_to_screen(vp); | 			vs->viewport_attach_to_screen(vp,Rect2(Vector2(),OS::get_singleton()->get_window_size())); | ||||||
| 			Matrix32 smaller; | 			Matrix32 smaller; | ||||||
| 			//smaller.scale(Vector2(0.6,0.6));
 | 			//smaller.scale(Vector2(0.6,0.6));
 | ||||||
| 			//smaller.elements[2]=Vector2(100,0);
 | 			//smaller.elements[2]=Vector2(100,0);
 | ||||||
|  |  | ||||||
|  | @ -1,56 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_python.cpp                                                      */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #include "test_python.h" |  | ||||||
| 
 |  | ||||||
| #ifdef PYTHON_ENABLED |  | ||||||
| 
 |  | ||||||
| #include "Python.h" |  | ||||||
| #include "print_string.h" |  | ||||||
| 
 |  | ||||||
| namespace TestPython { |  | ||||||
| 
 |  | ||||||
| void test() { |  | ||||||
| 
 |  | ||||||
| 	print_line("testing python"); |  | ||||||
| 	PyRun_SimpleString("import engine\n"); |  | ||||||
| 	PyRun_SimpleString("def test(self):\n\tprint(\"noway\")\n"); |  | ||||||
| 	PyRun_SimpleString("a=engine.ObjectPtr()\n"); |  | ||||||
| 	PyRun_SimpleString("a.noway(22,'hello')\n"); |  | ||||||
| 	PyRun_SimpleString("a.normalize()\n"); |  | ||||||
| 	PyRun_SimpleString("class Moch(engine.ObjectPtr):\n\tdef mooch(self):\n\t\tprint('muchi')\n"); |  | ||||||
| 	PyRun_SimpleString("b=Moch();\n"); |  | ||||||
| 	PyRun_SimpleString("b.mooch();\n"); |  | ||||||
| 	PyRun_SimpleString("b.meis();\n"); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
|  | @ -1,43 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  test_python.h                                                        */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #ifndef TEST_PYTHON_H |  | ||||||
| #define TEST_PYTHON_H |  | ||||||
| 
 |  | ||||||
| #ifdef PYTHON_ENABLED |  | ||||||
| /**
 |  | ||||||
| 	@author Juan Linietsky <reduzio@gmail.com> |  | ||||||
| */ |  | ||||||
| namespace TestPython { |  | ||||||
| 
 |  | ||||||
| void test(); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| #endif |  | ||||||
|  | @ -173,7 +173,10 @@ public: | ||||||
| // 		vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
 | // 		vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
 | ||||||
| 
 | 
 | ||||||
| 		viewport = vs->viewport_create(); | 		viewport = vs->viewport_create(); | ||||||
| 		vs->viewport_attach_to_screen(viewport); | 		Size2i screen_size = OS::get_singleton()->get_window_size(); | ||||||
|  | 		vs->viewport_set_size(viewport,screen_size.x,screen_size.y); | ||||||
|  | 		vs->viewport_attach_to_screen(viewport,Rect2(Vector2(),screen_size)); | ||||||
|  | 		vs->viewport_set_active(viewport,true); | ||||||
| 		vs->viewport_attach_camera( viewport, camera ); | 		vs->viewport_attach_camera( viewport, camera ); | ||||||
| 		vs->viewport_set_scenario( viewport, scenario ); | 		vs->viewport_set_scenario( viewport, scenario ); | ||||||
| 		vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,3,30 ) ) ); | 		vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,3,30 ) ) ); | ||||||
|  | @ -192,7 +195,7 @@ public: | ||||||
| 		//*
 | 		//*
 | ||||||
| 		lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); | 		lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); | ||||||
| 		//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
 | 		//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
 | ||||||
| 		vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0,1.0,1.0) ); | 		vs->light_set_color( lightaux,  Color(1.0,1.0,1.0) ); | ||||||
| 		//vs->light_set_shadow( lightaux, true );
 | 		//vs->light_set_shadow( lightaux, true );
 | ||||||
| 		light = vs->instance_create2( lightaux, scenario ); | 		light = vs->instance_create2( lightaux, scenario ); | ||||||
| 		Transform lla; | 		Transform lla; | ||||||
|  | @ -205,8 +208,8 @@ public: | ||||||
| 		//*
 | 		//*
 | ||||||
| 		lightaux = vs->light_create( VisualServer::LIGHT_OMNI ); | 		lightaux = vs->light_create( VisualServer::LIGHT_OMNI ); | ||||||
| //		vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) );
 | //		vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) );
 | ||||||
| 		vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0,1.0,0.0) ); | 		vs->light_set_color( lightaux,  Color(1.0,1.0,0.0) ); | ||||||
| 		vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RADIUS, 4 ); | 		vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RANGE, 4 ); | ||||||
| 		vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8 ); | 		vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8 ); | ||||||
| 		//vs->light_set_shadow( lightaux, true );
 | 		//vs->light_set_shadow( lightaux, true );
 | ||||||
| 		//light = vs->instance_create( lightaux );
 | 		//light = vs->instance_create( lightaux );
 | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ | ||||||
| #include "scene/gui/text_edit.h" | #include "scene/gui/text_edit.h" | ||||||
| #include "print_string.h" | #include "print_string.h" | ||||||
| #include "servers/visual/shader_language.h" | #include "servers/visual/shader_language.h" | ||||||
| #include "drivers/gles2/shader_compiler_gles2.h" | //#include "drivers/gles2/shader_compiler_gles2.h"
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| typedef ShaderLanguage SL; | typedef ShaderLanguage SL; | ||||||
|  | @ -57,50 +57,54 @@ static String _mktab(int p_level) { | ||||||
| 
 | 
 | ||||||
| static String _typestr(SL::DataType p_type) { | static String _typestr(SL::DataType p_type) { | ||||||
| 
 | 
 | ||||||
| 	switch(p_type) { | 	return ShaderLanguage::get_datatype_name(p_type); | ||||||
| 
 |  | ||||||
| 		case SL::TYPE_VOID: return "void"; |  | ||||||
| 		case SL::TYPE_BOOL: return "bool"; |  | ||||||
| 		case SL::TYPE_FLOAT: return "float"; |  | ||||||
| 		case SL::TYPE_VEC2: return "vec2"; |  | ||||||
| 		case SL::TYPE_VEC3: return "vec3"; |  | ||||||
| 		case SL::TYPE_VEC4: return "vec4"; |  | ||||||
| 		case SL::TYPE_MAT3: return "mat3"; |  | ||||||
| 		case SL::TYPE_MAT4: return "mat4"; |  | ||||||
| 		case SL::TYPE_TEXTURE: return "texture"; |  | ||||||
| 		case SL::TYPE_CUBEMAP: return "cubemap"; |  | ||||||
| 		default: {} |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	return ""; | 	return ""; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | static String _prestr(SL::DataPrecision p_pres) { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	switch(p_pres) { | ||||||
|  | 		case SL::PRECISION_LOWP: return "lowp "; | ||||||
|  | 		case SL::PRECISION_MEDIUMP: return "mediump "; | ||||||
|  | 		case SL::PRECISION_HIGHP: return "highp "; | ||||||
|  | 		case SL::PRECISION_DEFAULT: return ""; | ||||||
|  | 	} | ||||||
|  | 	return ""; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| static String _opstr(SL::Operator p_op) { | static String _opstr(SL::Operator p_op) { | ||||||
| 
 | 
 | ||||||
| 	switch(p_op) { | 	return ShaderLanguage::get_operator_text(p_op); | ||||||
| 		case SL::OP_ASSIGN: return "="; | 
 | ||||||
| 		case SL::OP_ADD: return "+"; | 
 | ||||||
| 		case SL::OP_SUB: return "-"; |  | ||||||
| 		case SL::OP_MUL: return "*"; |  | ||||||
| 		case SL::OP_DIV: return "/"; |  | ||||||
| 		case SL::OP_ASSIGN_ADD: return "+="; |  | ||||||
| 		case SL::OP_ASSIGN_SUB: return "-="; |  | ||||||
| 		case SL::OP_ASSIGN_MUL: return "*="; |  | ||||||
| 		case SL::OP_ASSIGN_DIV: return "/="; |  | ||||||
| 		case SL::OP_NEG: return "-"; |  | ||||||
| 		case SL::OP_NOT: return "!"; |  | ||||||
| 		case SL::OP_CMP_EQ: return "=="; |  | ||||||
| 		case SL::OP_CMP_NEQ: return "!="; |  | ||||||
| 		case SL::OP_CMP_LEQ: return "<="; |  | ||||||
| 		case SL::OP_CMP_GEQ: return ">="; |  | ||||||
| 		case SL::OP_CMP_LESS: return "<"; |  | ||||||
| 		case SL::OP_CMP_GREATER: return ">"; |  | ||||||
| 		case SL::OP_CMP_OR: return "||"; |  | ||||||
| 		case SL::OP_CMP_AND: return "&&"; |  | ||||||
| 		default: return ""; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 	return ""; | 
 | ||||||
|  | static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value>& p_values) { | ||||||
|  | 
 | ||||||
|  | 	switch(p_type) { | ||||||
|  | 		case SL::TYPE_BOOL:  return p_values[0].boolean?"true":"false"; | ||||||
|  | 		case SL::TYPE_BVEC2:  return String()+"bvec2("+(p_values[0].boolean?"true":"false")+(p_values[1].boolean?"true":"false")+")"; | ||||||
|  | 		case SL::TYPE_BVEC3:  return String()+"bvec3("+(p_values[0].boolean?"true":"false")+","+(p_values[1].boolean?"true":"false")+","+(p_values[2].boolean?"true":"false")+")"; | ||||||
|  | 		case SL::TYPE_BVEC4:  return String()+"bvec4("+(p_values[0].boolean?"true":"false")+","+(p_values[1].boolean?"true":"false")+","+(p_values[2].boolean?"true":"false")+","+(p_values[3].boolean?"true":"false")+")"; | ||||||
|  | 		case SL::TYPE_INT:  return rtos(p_values[0].sint); | ||||||
|  | 		case SL::TYPE_IVEC2:  return String()+"ivec2("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+")"; | ||||||
|  | 		case SL::TYPE_IVEC3:  return String()+"ivec3("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+","+rtos(p_values[2].sint)+")"; | ||||||
|  | 		case SL::TYPE_IVEC4:  return String()+"ivec4("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+","+rtos(p_values[2].sint)+","+rtos(p_values[3].sint)+")"; | ||||||
|  | 		case SL::TYPE_UINT:  return rtos(p_values[0].real); | ||||||
|  | 		case SL::TYPE_UVEC2:  return String()+"uvec2("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+")"; | ||||||
|  | 		case SL::TYPE_UVEC3:  return String()+"uvec3("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+")"; | ||||||
|  | 		case SL::TYPE_UVEC4:  return String()+"uvec4("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+","+rtos(p_values[3].real)+")"; | ||||||
|  | 		case SL::TYPE_FLOAT:  return rtos(p_values[0].real); | ||||||
|  | 		case SL::TYPE_VEC2:  return String()+"vec2("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+")"; | ||||||
|  | 		case SL::TYPE_VEC3:  return String()+"vec3("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+")"; | ||||||
|  | 		case SL::TYPE_VEC4:  return String()+"vec4("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+","+rtos(p_values[3].real)+")"; | ||||||
|  | 		default: ERR_FAIL_V(String()); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static String dump_node_code(SL::Node *p_node,int p_level) { | static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
|  | @ -109,18 +113,48 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 
 | 
 | ||||||
| 	switch(p_node->type) { | 	switch(p_node->type) { | ||||||
| 
 | 
 | ||||||
| 		case SL::Node::TYPE_PROGRAM: { | 		case SL::Node::TYPE_SHADER: { | ||||||
| 
 | 
 | ||||||
| 			SL::ProgramNode *pnode=(SL::ProgramNode*)p_node; | 			SL::ShaderNode *pnode=(SL::ShaderNode*)p_node; | ||||||
| 
 | 
 | ||||||
| 			for(Map<StringName,SL::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) { | 			for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) { | ||||||
| 
 | 
 | ||||||
| 				String ucode="uniform "; | 				String ucode="uniform "; | ||||||
| 				ucode+=_typestr(E->get().type)+"="+String(E->get().default_value)+"\n"; | 				ucode+=_prestr(E->get().precission); | ||||||
| 				code+=ucode; | 				ucode+=_typestr(E->get().type); | ||||||
|  | 				ucode+=" "+String(E->key()); | ||||||
|  | 
 | ||||||
|  | 				if (E->get().default_value.size()) { | ||||||
|  | 					ucode+=" = "+get_constant_text(E->get().type,E->get().default_value); | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				static const char*hint_name[SL::ShaderNode::Uniform::HINT_MAX]={ | ||||||
|  | 					"", | ||||||
|  | 					"color", | ||||||
|  | 					"range", | ||||||
|  | 					"albedo", | ||||||
|  | 					"normal", | ||||||
|  | 					"black", | ||||||
|  | 					"white" | ||||||
|  | 				}; | ||||||
|  | 
 | ||||||
|  | 				if (E->get().hint) | ||||||
|  | 					ucode+=" : "+String(hint_name[E->get().hint]); | ||||||
|  | 
 | ||||||
|  | 				code+=ucode+"\n"; | ||||||
| 
 | 
 | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | 			for(Map<StringName,SL::ShaderNode::Varying>::Element *E=pnode->varyings.front();E;E=E->next()) { | ||||||
|  | 
 | ||||||
|  | 				String vcode="varying "; | ||||||
|  | 				vcode+=_prestr(E->get().precission); | ||||||
|  | 				vcode+=_typestr(E->get().type); | ||||||
|  | 				vcode+=" "+String(E->key()); | ||||||
|  | 
 | ||||||
|  | 				code+=vcode+"\n"; | ||||||
|  | 
 | ||||||
|  | 			} | ||||||
| 			for(int i=0;i<pnode->functions.size();i++) { | 			for(int i=0;i<pnode->functions.size();i++) { | ||||||
| 
 | 
 | ||||||
| 				SL::FunctionNode *fnode=pnode->functions[i].function; | 				SL::FunctionNode *fnode=pnode->functions[i].function; | ||||||
|  | @ -131,16 +165,15 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 
 | 
 | ||||||
| 					if (i>0) | 					if (i>0) | ||||||
| 						header+=", "; | 						header+=", "; | ||||||
| 					header+=_typestr(fnode->arguments[i].type)+" "+fnode->arguments[i].name; | 					header+=_prestr(fnode->arguments[i].precision)+_typestr(fnode->arguments[i].type)+" "+fnode->arguments[i].name; | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				header+=") {\n"; | 				header+=")\n"; | ||||||
| 				code+=header; | 				code+=header; | ||||||
| 				code+=dump_node_code(fnode->body,p_level+1); | 				code+=dump_node_code(fnode->body,p_level+1); | ||||||
| 				code+="}\n"; |  | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			code+=dump_node_code(pnode->body,p_level); | 			//code+=dump_node_code(pnode->body,p_level);
 | ||||||
| 		} break; | 		} break; | ||||||
| 		case SL::Node::TYPE_FUNCTION: { | 		case SL::Node::TYPE_FUNCTION: { | ||||||
| 
 | 
 | ||||||
|  | @ -149,15 +182,23 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 			SL::BlockNode *bnode=(SL::BlockNode*)p_node; | 			SL::BlockNode *bnode=(SL::BlockNode*)p_node; | ||||||
| 
 | 
 | ||||||
| 			//variables
 | 			//variables
 | ||||||
| 			for(Map<StringName,SL::DataType>::Element *E=bnode->variables.front();E;E=E->next()) { | 			code+=_mktab(p_level-1)+"{\n"; | ||||||
|  | 			for(Map<StringName,SL::BlockNode::Variable>::Element *E=bnode->variables.front();E;E=E->next()) { | ||||||
| 
 | 
 | ||||||
| 				code+=_mktab(p_level)+_typestr(E->value())+" "+E->key()+";\n"; | 				code+=_mktab(p_level)+_prestr(E->get().precision)+_typestr(E->get().type)+" "+E->key()+";\n"; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			for(int i=0;i<bnode->statements.size();i++) { | 			for(int i=0;i<bnode->statements.size();i++) { | ||||||
| 
 | 
 | ||||||
| 				code+=_mktab(p_level)+dump_node_code(bnode->statements[i],p_level)+";\n"; | 				String scode = dump_node_code(bnode->statements[i],p_level); | ||||||
|  | 
 | ||||||
|  | 				if (bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW) { | ||||||
|  | 					code+=scode; //use directly
 | ||||||
|  | 				} else { | ||||||
|  | 					code+=_mktab(p_level)+scode+";\n"; | ||||||
| 				} | 				} | ||||||
|  | 			} | ||||||
|  | 			code+=_mktab(p_level-1)+"}\n"; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 		} break; | 		} break; | ||||||
|  | @ -168,18 +209,7 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 		} break; | 		} break; | ||||||
| 		case SL::Node::TYPE_CONSTANT: { | 		case SL::Node::TYPE_CONSTANT: { | ||||||
| 			SL::ConstantNode *cnode=(SL::ConstantNode*)p_node; | 			SL::ConstantNode *cnode=(SL::ConstantNode*)p_node; | ||||||
| 			switch(cnode->datatype) { | 			return get_constant_text(cnode->datatype,cnode->values); | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 				case SL::TYPE_BOOL: code=cnode->value.operator bool()?"true":"false"; break; |  | ||||||
| 				case SL::TYPE_FLOAT: code=cnode->value; break; |  | ||||||
| 				case SL::TYPE_VEC2: { Vector2 v = cnode->value; code="vec2("+rtos(v.x)+", "+rtos(v.y)+")"; } break; |  | ||||||
| 				case SL::TYPE_VEC3: { Vector3 v = cnode->value; code="vec3("+rtos(v.x)+", "+rtos(v.y)+", "+rtos(v.z)+")"; } break; |  | ||||||
| 				case SL::TYPE_VEC4: { Plane v = cnode->value; code="vec4("+rtos(v.normal.x)+", "+rtos(v.normal.y)+", "+rtos(v.normal.z)+", "+rtos(v.d)+")"; } break; |  | ||||||
| 				case SL::TYPE_MAT3: { Matrix3 x = cnode->value; code="mat3( vec3("+rtos(x.get_axis(0).x)+", "+rtos(x.get_axis(0).y)+", "+rtos(x.get_axis(0).z)+"), vec3("+rtos(x.get_axis(1).x)+", "+rtos(x.get_axis(1).y)+", "+rtos(x.get_axis(1).z)+"), vec3("+rtos(x.get_axis(2).x)+", "+rtos(x.get_axis(2).y)+", "+rtos(x.get_axis(2).z)+"))"; } break; |  | ||||||
| 				case SL::TYPE_MAT4: { Transform x = cnode->value; code="mat4( vec3("+rtos(x.basis.get_axis(0).x)+", "+rtos(x.basis.get_axis(0).y)+", "+rtos(x.basis.get_axis(0).z)+"), vec3("+rtos(x.basis.get_axis(1).x)+", "+rtos(x.basis.get_axis(1).y)+", "+rtos(x.basis.get_axis(1).z)+"), vec3("+rtos(x.basis.get_axis(2).x)+", "+rtos(x.basis.get_axis(2).y)+", "+rtos(x.basis.get_axis(2).z)+"), vec3("+rtos(x.origin.x)+", "+rtos(x.origin.y)+", "+rtos(x.origin.z)+"))"; } break; |  | ||||||
| 				default: code="<error: "+Variant::get_type_name(cnode->value.get_type())+" ("+itos(cnode->datatype)+">"; |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 		} break; | 		} break; | ||||||
| 		case SL::Node::TYPE_OPERATOR: { | 		case SL::Node::TYPE_OPERATOR: { | ||||||
|  | @ -193,28 +223,25 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 				case SL::OP_ASSIGN_SUB: | 				case SL::OP_ASSIGN_SUB: | ||||||
| 				case SL::OP_ASSIGN_MUL: | 				case SL::OP_ASSIGN_MUL: | ||||||
| 				case SL::OP_ASSIGN_DIV: | 				case SL::OP_ASSIGN_DIV: | ||||||
|  | 				case SL::OP_ASSIGN_SHIFT_LEFT: | ||||||
|  | 				case SL::OP_ASSIGN_SHIFT_RIGHT: | ||||||
|  | 				case SL::OP_ASSIGN_MOD: | ||||||
|  | 				case SL::OP_ASSIGN_BIT_AND: | ||||||
|  | 				case SL::OP_ASSIGN_BIT_OR: | ||||||
|  | 				case SL::OP_ASSIGN_BIT_XOR: | ||||||
| 					code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level); | 					code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level); | ||||||
| 					break; | 					break; | ||||||
| 
 | 				case SL::OP_BIT_INVERT: | ||||||
| 				case SL::OP_ADD: | 				case SL::OP_NEGATE: | ||||||
| 				case SL::OP_SUB: |  | ||||||
| 				case SL::OP_MUL: |  | ||||||
| 				case SL::OP_DIV: |  | ||||||
| 				case SL::OP_CMP_EQ: |  | ||||||
| 				case SL::OP_CMP_NEQ: |  | ||||||
| 				case SL::OP_CMP_LEQ: |  | ||||||
| 				case SL::OP_CMP_GEQ: |  | ||||||
| 				case SL::OP_CMP_LESS: |  | ||||||
| 				case SL::OP_CMP_GREATER: |  | ||||||
| 				case SL::OP_CMP_OR: |  | ||||||
| 				case SL::OP_CMP_AND: |  | ||||||
| 
 |  | ||||||
| 					code="("+dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")"; |  | ||||||
| 					break; |  | ||||||
| 				case SL::OP_NEG: |  | ||||||
| 				case SL::OP_NOT: | 				case SL::OP_NOT: | ||||||
|  | 				case SL::OP_DECREMENT: | ||||||
|  | 				case SL::OP_INCREMENT: | ||||||
| 					code=_opstr(onode->op)+dump_node_code(onode->arguments[0],p_level); | 					code=_opstr(onode->op)+dump_node_code(onode->arguments[0],p_level); | ||||||
| 					break; | 					break; | ||||||
|  | 				case SL::OP_POST_DECREMENT: | ||||||
|  | 				case SL::OP_POST_INCREMENT: | ||||||
|  | 					code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op); | ||||||
|  | 					break; | ||||||
| 				case SL::OP_CALL: | 				case SL::OP_CALL: | ||||||
| 				case SL::OP_CONSTRUCT: | 				case SL::OP_CONSTRUCT: | ||||||
| 					code=dump_node_code(onode->arguments[0],p_level)+"("; | 					code=dump_node_code(onode->arguments[0],p_level)+"("; | ||||||
|  | @ -225,7 +252,12 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 					} | 					} | ||||||
| 					code+=")"; | 					code+=")"; | ||||||
| 					break; | 					break; | ||||||
| 				default: {} | 				default: { | ||||||
|  | 
 | ||||||
|  | 					code="("+dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")"; | ||||||
|  | 					break; | ||||||
|  | 
 | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 		} break; | 		} break; | ||||||
|  | @ -233,20 +265,19 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 			SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node; | 			SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node; | ||||||
| 			if (cfnode->flow_op==SL::FLOW_OP_IF) { | 			if (cfnode->flow_op==SL::FLOW_OP_IF) { | ||||||
| 
 | 
 | ||||||
| 				code+="if ("+dump_node_code(cfnode->statements[0],p_level)+") {\n"; | 				code+=_mktab(p_level)+"if ("+dump_node_code(cfnode->expressions[0],p_level)+")\n"; | ||||||
| 				code+=dump_node_code(cfnode->statements[1],p_level+1); | 				code+=dump_node_code(cfnode->blocks[0],p_level+1); | ||||||
| 				if (cfnode->statements.size()==3) { | 				if (cfnode->blocks.size()==2) { | ||||||
| 
 | 
 | ||||||
| 					code+="} else {\n"; | 					code+=_mktab(p_level)+"else\n"; | ||||||
| 					code+=dump_node_code(cfnode->statements[2],p_level+1); | 					code+=dump_node_code(cfnode->blocks[1],p_level+1); | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				code+="}\n"; |  | ||||||
| 
 | 
 | ||||||
| 			} else if (cfnode->flow_op==SL::FLOW_OP_RETURN) { | 			} else if (cfnode->flow_op==SL::FLOW_OP_RETURN) { | ||||||
| 
 | 
 | ||||||
| 				if (cfnode->statements.size()) { | 				if (cfnode->blocks.size()) { | ||||||
| 					code="return "+dump_node_code(cfnode->statements[0],p_level); | 					code="return "+dump_node_code(cfnode->blocks[0],p_level); | ||||||
| 				} else { | 				} else { | ||||||
| 					code="return"; | 					code="return"; | ||||||
| 				} | 				} | ||||||
|  | @ -264,16 +295,14 @@ static String dump_node_code(SL::Node *p_node,int p_level) { | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static Error recreate_code(void *p_str,SL::ProgramNode *p_program) { | static Error recreate_code(void *p_str,SL::ShaderNode *p_program) { | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| 	print_line("recr"); |  | ||||||
| 	String *str=(String*)p_str; | 	String *str=(String*)p_str; | ||||||
| 
 | 
 | ||||||
| 	*str=dump_node_code(p_program,0); | 	*str=dump_node_code(p_program,0); | ||||||
| 
 | 
 | ||||||
| 	return OK; | 	return OK; | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -283,6 +312,7 @@ MainLoop* test() { | ||||||
| 
 | 
 | ||||||
| 	if (cmdlargs.empty()) { | 	if (cmdlargs.empty()) { | ||||||
| 		//try editor!
 | 		//try editor!
 | ||||||
|  | 		print_line("usage: godot -test shader_lang <shader>"); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -303,38 +333,29 @@ MainLoop* test() { | ||||||
| 		code+=c; | 		code+=c; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	int errline; | 	SL sl; | ||||||
| 	int errcol; | 	print_line("tokens:\n\n"+sl.token_debug(code)); | ||||||
| 	String error; | 
 | ||||||
| 	print_line(SL::lex_debug(code)); | 	Map<StringName,Map<StringName,SL::DataType> > dt; | ||||||
| 	Error err = SL::compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,NULL,NULL,&error,&errline,&errcol); | 	dt["fragment"]["ALBEDO"]=SL::TYPE_VEC3; | ||||||
|  | 
 | ||||||
|  | 	Set<String> rm; | ||||||
|  | 	rm.insert("popo"); | ||||||
|  | 
 | ||||||
|  | 	Error err = sl.compile(code,dt,rm); | ||||||
| 
 | 
 | ||||||
| 	if (err) { | 	if (err) { | ||||||
| 
 | 
 | ||||||
| 		print_line("Error: "+itos(errline)+":"+itos(errcol)+" "+error); | 		print_line("Error at line: "+rtos(sl.get_error_line())+": "+sl.get_error_text()); | ||||||
| 		return NULL; | 		return NULL; | ||||||
|  | 	} else { | ||||||
|  | 		String code; | ||||||
|  | 		recreate_code(&code,sl.get_shader()); | ||||||
|  | 		print_line("code:\n\n"+code); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	print_line("Compile OK! - pretty printing"); |  | ||||||
| 
 |  | ||||||
| 	String rcode; |  | ||||||
| 	err = SL::compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,recreate_code,&rcode,&error,&errline,&errcol); |  | ||||||
| 
 |  | ||||||
| 	if (!err) { |  | ||||||
| 		print_line(rcode); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	ShaderCompilerGLES2 comp; |  | ||||||
| 	String codeline,globalsline; |  | ||||||
| 	SL::VarInfo vi; |  | ||||||
| 	vi.name="mongs"; |  | ||||||
| 	vi.type=SL::TYPE_VEC3; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	ShaderCompilerGLES2::Flags fl; |  | ||||||
| 	comp.compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,codeline,globalsline,fl); |  | ||||||
| 
 |  | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -842,7 +842,7 @@ bool test_29() { | ||||||
| 	IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); | 	IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); | ||||||
| 	OS::get_singleton()->print("ip0 is %ls\n", String(ip0).c_str()); | 	OS::get_singleton()->print("ip0 is %ls\n", String(ip0).c_str()); | ||||||
| 
 | 
 | ||||||
| 	IP_Address ip(0x0123, 0x4567, 0x89ab, 0xcdef, IP_Address::TYPE_IPV6); | 	IP_Address ip(0x0123, 0x4567, 0x89ab, 0xcdef, true); | ||||||
| 	OS::get_singleton()->print("ip6 is %ls\n", String(ip).c_str()); | 	OS::get_singleton()->print("ip6 is %ls\n", String(ip).c_str()); | ||||||
| 
 | 
 | ||||||
| 	IP_Address ip2("fe80::52e5:49ff:fe93:1baf"); | 	IP_Address ip2("fe80::52e5:49ff:fe93:1baf"); | ||||||
|  |  | ||||||
|  | @ -57,10 +57,10 @@ Export('env') | ||||||
| import make_binders | import make_binders | ||||||
| env.Command(['method_bind.inc', 'method_bind_ext.inc'], 'make_binders.py', make_binders.run) | env.Command(['method_bind.inc', 'method_bind_ext.inc'], 'make_binders.py', make_binders.run) | ||||||
| 
 | 
 | ||||||
| SConscript('os/SCsub'); | SConscript('os/SCsub') | ||||||
| SConscript('math/SCsub'); | SConscript('math/SCsub') | ||||||
| SConscript('io/SCsub'); | SConscript('io/SCsub') | ||||||
| SConscript('bind/SCsub'); | SConscript('bind/SCsub') | ||||||
| 
 | 
 | ||||||
| lib = env.Library("core", env.core_sources) | lib = env.Library("core", env.core_sources) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -150,6 +150,16 @@ void Array::erase(const Variant& p_value) { | ||||||
| 	_p->array.erase(p_value); | 	_p->array.erase(p_value); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | Variant Array::front() const { | ||||||
|  | 	ERR_FAIL_COND_V(_p->array.size() == 0, Variant()); | ||||||
|  | 	return operator[](0); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Variant Array::back() const { | ||||||
|  | 	ERR_FAIL_COND_V(_p->array.size() == 0, Variant()); | ||||||
|  | 	return operator[](_p->array.size() - 1); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int Array::find(const Variant& p_value, int p_from) const { | int Array::find(const Variant& p_value, int p_from) const { | ||||||
| 
 | 
 | ||||||
| 	return _p->array.find(p_value, p_from); | 	return _p->array.find(p_value, p_from); | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -67,6 +67,9 @@ public: | ||||||
| 	void insert(int p_pos, const Variant& p_value); | 	void insert(int p_pos, const Variant& p_value); | ||||||
| 	void remove(int p_pos); | 	void remove(int p_pos); | ||||||
| 
 | 
 | ||||||
|  | 	Variant front() const; | ||||||
|  | 	Variant back() const; | ||||||
|  | 
 | ||||||
| 	void sort(); | 	void sort(); | ||||||
| 	void sort_custom(Object *p_obj,const StringName& p_function); | 	void sort_custom(Object *p_obj,const StringName& p_function); | ||||||
| 	void invert(); | 	void invert(); | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -480,9 +480,9 @@ void _OS::set_use_vsync(bool p_enable) { | ||||||
| 	OS::get_singleton()->set_use_vsync(p_enable); | 	OS::get_singleton()->set_use_vsync(p_enable); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool _OS::is_vsnc_enabled() const { | bool _OS::is_vsync_enabled() const { | ||||||
| 
 | 
 | ||||||
| 	return OS::get_singleton()->is_vsnc_enabled(); | 	return OS::get_singleton()->is_vsync_enabled(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -1172,7 +1172,7 @@ void _OS::_bind_methods() { | ||||||
| 	ObjectTypeDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name); | 	ObjectTypeDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name); | ||||||
| 
 | 
 | ||||||
| 	ObjectTypeDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync); | 	ObjectTypeDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync); | ||||||
| 	ObjectTypeDB::bind_method(_MD("is_vsnc_enabled"),&_OS::is_vsnc_enabled); | 	ObjectTypeDB::bind_method(_MD("is_vsync_enabled"),&_OS::is_vsync_enabled); | ||||||
| 
 | 
 | ||||||
| 	ObjectTypeDB::bind_method(_MD("get_engine_version"),&_OS::get_engine_version); | 	ObjectTypeDB::bind_method(_MD("get_engine_version"),&_OS::get_engine_version); | ||||||
| 
 | 
 | ||||||
|  | @ -2043,6 +2043,13 @@ _Directory::~_Directory() { | ||||||
| 		memdelete(d); | 		memdelete(d); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | _Marshalls* _Marshalls::singleton=NULL; | ||||||
|  | 
 | ||||||
|  | _Marshalls *_Marshalls::get_singleton() | ||||||
|  | { | ||||||
|  | 	return singleton; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| String _Marshalls::variant_to_base64(const Variant& p_var) { | String _Marshalls::variant_to_base64(const Variant& p_var) { | ||||||
| 
 | 
 | ||||||
| 	int len; | 	int len; | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -318,7 +318,7 @@ public: | ||||||
| 	Error set_thread_name(const String& p_name); | 	Error set_thread_name(const String& p_name); | ||||||
| 
 | 
 | ||||||
| 	void set_use_vsync(bool p_enable); | 	void set_use_vsync(bool p_enable); | ||||||
| 	bool is_vsnc_enabled() const; | 	bool is_vsync_enabled() const; | ||||||
| 
 | 
 | ||||||
| 	Dictionary get_engine_version() const; | 	Dictionary get_engine_version() const; | ||||||
| 
 | 
 | ||||||
|  | @ -503,6 +503,8 @@ class _Marshalls : public Reference { | ||||||
| 
 | 
 | ||||||
| 	OBJ_TYPE(_Marshalls,Reference); | 	OBJ_TYPE(_Marshalls,Reference); | ||||||
| 
 | 
 | ||||||
|  | 	static _Marshalls* singleton; | ||||||
|  | 
 | ||||||
| protected: | protected: | ||||||
| 
 | 
 | ||||||
| 	static void _bind_methods(); | 	static void _bind_methods(); | ||||||
|  | @ -510,6 +512,8 @@ protected: | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 
 | 
 | ||||||
|  | 	static _Marshalls* get_singleton(); | ||||||
|  | 
 | ||||||
| 	String variant_to_base64(const Variant& p_var); | 	String variant_to_base64(const Variant& p_var); | ||||||
| 	Variant base64_to_variant(const String& p_str); | 	Variant base64_to_variant(const String& p_str); | ||||||
| 
 | 
 | ||||||
|  | @ -519,7 +523,8 @@ public: | ||||||
| 	String utf8_to_base64(const String& p_str); | 	String utf8_to_base64(const String& p_str); | ||||||
| 	String base64_to_utf8(const String& p_str); | 	String base64_to_utf8(const String& p_str); | ||||||
| 
 | 
 | ||||||
| 	_Marshalls() {}; | 	_Marshalls() { singleton = this; } | ||||||
|  | 	~_Marshalls() { singleton = NULL; } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -57,33 +57,33 @@ enum Error { | ||||||
| 	ERR_FILE_MISSING_DEPENDENCIES, | 	ERR_FILE_MISSING_DEPENDENCIES, | ||||||
| 	ERR_FILE_EOF, | 	ERR_FILE_EOF, | ||||||
| 	ERR_CANT_OPEN, ///< Can't open a resource/socket/file
 | 	ERR_CANT_OPEN, ///< Can't open a resource/socket/file
 | ||||||
| 	ERR_CANT_CREATE, | 	ERR_CANT_CREATE,		// (20)
 | ||||||
| 	ERROR_QUERY_FAILED,		// (20)
 | 	ERROR_QUERY_FAILED, | ||||||
| 	ERR_ALREADY_IN_USE, | 	ERR_ALREADY_IN_USE, | ||||||
|  	ERR_LOCKED, ///< resource is locked
 |  	ERR_LOCKED, ///< resource is locked
 | ||||||
|  	ERR_TIMEOUT, |  	ERR_TIMEOUT, | ||||||
| 	ERR_CANT_CONNECT, | 	ERR_CANT_CONNECT,		// (25)
 | ||||||
| 	ERR_CANT_RESOLVE,		// (25)
 | 	ERR_CANT_RESOLVE, | ||||||
| 	ERR_CONNECTION_ERROR, | 	ERR_CONNECTION_ERROR, | ||||||
|  	ERR_CANT_AQUIRE_RESOURCE, |  	ERR_CANT_AQUIRE_RESOURCE, | ||||||
| 	ERR_CANT_FORK, | 	ERR_CANT_FORK, | ||||||
| 	ERR_INVALID_DATA, ///< Data passed is invalid
 | 	ERR_INVALID_DATA, ///< Data passed is invalid	(30)
 | ||||||
| 	ERR_INVALID_PARAMETER, ///< Parameter passed is invalid  (30)
 | 	ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
 | ||||||
| 	ERR_ALREADY_EXISTS, ///< When adding, item already exists
 | 	ERR_ALREADY_EXISTS, ///< When adding, item already exists
 | ||||||
| 	ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
 | 	ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
 | ||||||
| 	ERR_DATABASE_CANT_READ, ///< database is full
 | 	ERR_DATABASE_CANT_READ, ///< database is full
 | ||||||
| 	ERR_DATABASE_CANT_WRITE, ///< database is full
 | 	ERR_DATABASE_CANT_WRITE, ///< database is full	(35)
 | ||||||
| 	ERR_COMPILATION_FAILED,	// (35)
 | 	ERR_COMPILATION_FAILED, | ||||||
|  	ERR_METHOD_NOT_FOUND, |  	ERR_METHOD_NOT_FOUND, | ||||||
|   	ERR_LINK_FAILED, |   	ERR_LINK_FAILED, | ||||||
| 	ERR_SCRIPT_FAILED, | 	ERR_SCRIPT_FAILED, | ||||||
|   	ERR_CYCLIC_LINK, | 	ERR_CYCLIC_LINK,		// (40)
 | ||||||
| 	ERR_INVALID_DECLARATION,	// (40)
 | 	ERR_INVALID_DECLARATION, | ||||||
| 	ERR_DUPLICATE_SYMBOL, | 	ERR_DUPLICATE_SYMBOL, | ||||||
| 	ERR_PARSE_ERROR, | 	ERR_PARSE_ERROR, | ||||||
| 	ERR_BUSY, | 	ERR_BUSY, | ||||||
| 	ERR_SKIP, | 	ERR_SKIP,			// (45)
 | ||||||
| 	ERR_HELP, ///< user requested help!! (45)
 | 	ERR_HELP, ///< user requested help!!
 | ||||||
| 	ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
 | 	ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
 | ||||||
| 	ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
 | 	ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
 | ||||||
| 	ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
 | 	ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -49,7 +49,8 @@ | ||||||
| enum ErrorHandlerType { | enum ErrorHandlerType { | ||||||
| 	ERR_HANDLER_ERROR, | 	ERR_HANDLER_ERROR, | ||||||
| 	ERR_HANDLER_WARNING, | 	ERR_HANDLER_WARNING, | ||||||
| 	ERR_HANDLER_SCRIPT | 	ERR_HANDLER_SCRIPT, | ||||||
|  | 	ERR_HANDLER_SHADER, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| typedef void (*ErrorHandlerFunc)(void*,const char*,const char*,int p_line,const char *, const char *,ErrorHandlerType p_type); | typedef void (*ErrorHandlerFunc)(void*,const char*,const char*,int p_line,const char *, const char *,ErrorHandlerType p_type); | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -54,7 +54,8 @@ String Globals::localize_path(const String& p_path) const { | ||||||
| 	if (resource_path=="") | 	if (resource_path=="") | ||||||
| 		return p_path; //not initialied yet
 | 		return p_path; //not initialied yet
 | ||||||
| 
 | 
 | ||||||
| 	if (p_path.begins_with("res://") || p_path.begins_with("user://") || p_path.is_abs_path()) | 	if (p_path.begins_with("res://") || p_path.begins_with("user://") || | ||||||
|  | 		(p_path.is_abs_path() && !p_path.begins_with(resource_path))) | ||||||
| 		return p_path.simplify_path(); | 		return p_path.simplify_path(); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -657,37 +658,37 @@ static Variant _decode_variant(const String& p_string) { | ||||||
| 		String format=params[0].strip_edges(); | 		String format=params[0].strip_edges(); | ||||||
| 
 | 
 | ||||||
| 		Image::Format imgformat; | 		Image::Format imgformat; | ||||||
| 
 | /*
 | ||||||
| 		if (format=="grayscale") { | 		if (format=="grayscale") { | ||||||
| 			imgformat=Image::FORMAT_GRAYSCALE; | 			imgformat=Image::FORMAT_L8; | ||||||
| 		} else if (format=="intensity") { | 		} else if (format=="intensity") { | ||||||
| 			imgformat=Image::FORMAT_INTENSITY; | 			imgformat=Image::FORMAT_INTENSITY; | ||||||
| 		} else if (format=="grayscale_alpha") { | 		} else if (format=="grayscale_alpha") { | ||||||
| 			imgformat=Image::FORMAT_GRAYSCALE_ALPHA; | 			imgformat=Image::FORMAT_LA8; | ||||||
| 		} else if (format=="rgb") { | 		} else if (format=="rgb") { | ||||||
| 			imgformat=Image::FORMAT_RGB; | 			imgformat=Image::FORMAT_RGB8; | ||||||
| 		} else if (format=="rgba") { | 		} else if (format=="rgba") { | ||||||
| 			imgformat=Image::FORMAT_RGBA; | 			imgformat=Image::FORMAT_RGBA8; | ||||||
| 		} else if (format=="indexed") { | 		} else if (format=="indexed") { | ||||||
| 			imgformat=Image::FORMAT_INDEXED; | 			imgformat=Image::FORMAT_INDEXED; | ||||||
| 		} else if (format=="indexed_alpha") { | 		} else if (format=="indexed_alpha") { | ||||||
| 			imgformat=Image::FORMAT_INDEXED_ALPHA; | 			imgformat=Image::FORMAT_INDEXED_ALPHA; | ||||||
| 		} else if (format=="bc1") { | 		} else if (format=="bc1") { | ||||||
| 			imgformat=Image::FORMAT_BC1; | 			imgformat=Image::FORMAT_DXT1; | ||||||
| 		} else if (format=="bc2") { | 		} else if (format=="bc2") { | ||||||
| 			imgformat=Image::FORMAT_BC2; | 			imgformat=Image::FORMAT_DXT3; | ||||||
| 		} else if (format=="bc3") { | 		} else if (format=="bc3") { | ||||||
| 			imgformat=Image::FORMAT_BC3; | 			imgformat=Image::FORMAT_DXT5; | ||||||
| 		} else if (format=="bc4") { | 		} else if (format=="bc4") { | ||||||
| 			imgformat=Image::FORMAT_BC4; | 			imgformat=Image::FORMAT_ATI1; | ||||||
| 		} else if (format=="bc5") { | 		} else if (format=="bc5") { | ||||||
| 			imgformat=Image::FORMAT_BC5; | 			imgformat=Image::FORMAT_ATI2; | ||||||
| 		} else if (format=="custom") { | 		} else if (format=="custom") { | ||||||
| 			imgformat=Image::FORMAT_CUSTOM; | 			imgformat=Image::FORMAT_CUSTOM; | ||||||
| 		} else { | 		} else { | ||||||
| 
 | 
 | ||||||
| 			ERR_FAIL_V( Image() ); | 			ERR_FAIL_V( Image() ); | ||||||
| 		} | 		}*/ | ||||||
| 
 | 
 | ||||||
| 		int mipmaps=params[1].to_int(); | 		int mipmaps=params[1].to_int(); | ||||||
| 		int w=params[2].to_int(); | 		int w=params[2].to_int(); | ||||||
|  | @ -974,26 +975,30 @@ static String _encode_variant(const Variant& p_variant) { | ||||||
| 			if (!img.empty()) { | 			if (!img.empty()) { | ||||||
| 
 | 
 | ||||||
| 				String format; | 				String format; | ||||||
|  | 
 | ||||||
|  | 				/*
 | ||||||
| 				switch(img.get_format()) { | 				switch(img.get_format()) { | ||||||
| 
 | 
 | ||||||
| 					case Image::FORMAT_GRAYSCALE: format="grayscale"; break; | 					case Image::FORMAT_L8: format="grayscale"; break; | ||||||
| 					case Image::FORMAT_INTENSITY: format="intensity"; break; | 					case Image::FORMAT_INTENSITY: format="intensity"; break; | ||||||
| 					case Image::FORMAT_GRAYSCALE_ALPHA: format="grayscale_alpha"; break; | 					case Image::FORMAT_LA8: format="grayscale_alpha"; break; | ||||||
| 					case Image::FORMAT_RGB: format="rgb"; break; | 					case Image::FORMAT_RGB8: format="rgb"; break; | ||||||
| 					case Image::FORMAT_RGBA: format="rgba"; break; | 					case Image::FORMAT_RGBA8: format="rgba"; break; | ||||||
| 					case Image::FORMAT_INDEXED : format="indexed"; break; | 					case Image::FORMAT_INDEXED : format="indexed"; break; | ||||||
| 					case Image::FORMAT_INDEXED_ALPHA: format="indexed_alpha"; break; | 					case Image::FORMAT_INDEXED_ALPHA: format="indexed_alpha"; break; | ||||||
| 					case Image::FORMAT_BC1: format="bc1"; break; | 					case Image::FORMAT_DXT1: format="bc1"; break; | ||||||
| 					case Image::FORMAT_BC2: format="bc2"; break; | 					case Image::FORMAT_DXT3: format="bc2"; break; | ||||||
| 					case Image::FORMAT_BC3: format="bc3"; break; | 					case Image::FORMAT_DXT5: format="bc3"; break; | ||||||
| 					case Image::FORMAT_BC4: format="bc4"; break; | 					case Image::FORMAT_ATI1: format="bc4"; break; | ||||||
| 					case Image::FORMAT_BC5: format="bc5"; break; | 					case Image::FORMAT_ATI2: format="bc5"; break; | ||||||
| 					case Image::FORMAT_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break; | 					case Image::FORMAT_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break; | ||||||
| 					default: {} | 					default: {} | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
|  | 				*/ | ||||||
|  | 
 | ||||||
| 				str+=format+", "; | 				str+=format+", "; | ||||||
| 				str+=itos(img.get_mipmaps())+", "; | 				str+=itos(img.has_mipmaps())+", "; | ||||||
| 				str+=itos(img.get_width())+", "; | 				str+=itos(img.get_width())+", "; | ||||||
| 				str+=itos(img.get_height())+", "; | 				str+=itos(img.get_height())+", "; | ||||||
| 				DVector<uint8_t> data = img.get_data(); | 				DVector<uint8_t> data = img.get_data(); | ||||||
|  | @ -1399,6 +1404,7 @@ void Globals::set_custom_property_info(const String& p_prop,const PropertyInfo& | ||||||
| 
 | 
 | ||||||
| 	ERR_FAIL_COND(!props.has(p_prop)); | 	ERR_FAIL_COND(!props.has(p_prop)); | ||||||
| 	custom_prop_info[p_prop]=p_info; | 	custom_prop_info[p_prop]=p_info; | ||||||
|  | 	custom_prop_info[p_prop].name=p_prop; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
							
								
								
									
										1233
									
								
								core/image.cpp
									
										
									
									
									
								
							
							
						
						
									
										1233
									
								
								core/image.cpp
									
										
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										202
									
								
								core/image.h
									
										
									
									
									
								
							
							
						
						
									
										202
									
								
								core/image.h
									
										
									
									
									
								
							|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -55,35 +55,44 @@ public: | ||||||
| 	static SavePNGFunc save_png_func; | 	static SavePNGFunc save_png_func; | ||||||
| 
 | 
 | ||||||
| 	enum Format { | 	enum Format { | ||||||
| 		FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255
 |  | ||||||
| 		FORMAT_INTENSITY, ///< one byte per pixel, 0-255
 |  | ||||||
| 		FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255
 |  | ||||||
| 		FORMAT_RGB, ///< one byte R, one byte G, one byte B
 |  | ||||||
| 		FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A
 |  | ||||||
| 		FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette
 |  | ||||||
| 		FORMAT_INDEXED_ALPHA, ///< index byte 0-256, and after image end, 256*4 bytes of palette (alpha)
 |  | ||||||
| 		FORMAT_YUV_422, |  | ||||||
| 		FORMAT_YUV_444, |  | ||||||
| 		FORMAT_BC1, // DXT1
 |  | ||||||
| 		FORMAT_BC2, // DXT3
 |  | ||||||
| 		FORMAT_BC3, // DXT5
 |  | ||||||
| 		FORMAT_BC4, // ATI1
 |  | ||||||
| 		FORMAT_BC5, // ATI2
 |  | ||||||
| 		FORMAT_PVRTC2, |  | ||||||
| 		FORMAT_PVRTC2_ALPHA, |  | ||||||
| 		FORMAT_PVRTC4, |  | ||||||
| 		FORMAT_PVRTC4_ALPHA, |  | ||||||
| 		FORMAT_ETC, // regular ETC, no transparency
 |  | ||||||
| 		FORMAT_ATC, |  | ||||||
| 		FORMAT_ATC_ALPHA_EXPLICIT, |  | ||||||
| 		FORMAT_ATC_ALPHA_INTERPOLATED, |  | ||||||
| 		/*FORMAT_ETC2_R, for the future..
 |  | ||||||
| 		FORMAT_ETC2_RG, |  | ||||||
| 		FORMAT_ETC2_RGB, |  | ||||||
| 		FORMAT_ETC2_RGBA1, |  | ||||||
| 		FORMAT_ETC2_RGBA,*/ |  | ||||||
| 		FORMAT_CUSTOM, |  | ||||||
| 
 | 
 | ||||||
|  | 		FORMAT_L8, //luminance
 | ||||||
|  | 		FORMAT_LA8, //luminance-alpha
 | ||||||
|  | 		FORMAT_R8, | ||||||
|  | 		FORMAT_RG8, | ||||||
|  | 		FORMAT_RGB8, | ||||||
|  | 		FORMAT_RGBA8, | ||||||
|  | 		FORMAT_RGB565, //16 bit
 | ||||||
|  | 		FORMAT_RGBA4444, | ||||||
|  | 		FORMAT_RGBA5551, | ||||||
|  | 		FORMAT_RF, //float
 | ||||||
|  | 		FORMAT_RGF, | ||||||
|  | 		FORMAT_RGBF, | ||||||
|  | 		FORMAT_RGBAF, | ||||||
|  | 		FORMAT_RH, //half float
 | ||||||
|  | 		FORMAT_RGH, | ||||||
|  | 		FORMAT_RGBH, | ||||||
|  | 		FORMAT_RGBAH, | ||||||
|  | 		FORMAT_DXT1, //s3tc bc1
 | ||||||
|  | 		FORMAT_DXT3, //bc2
 | ||||||
|  | 		FORMAT_DXT5, //bc3
 | ||||||
|  | 		FORMAT_ATI1, //bc4
 | ||||||
|  | 		FORMAT_ATI2, //bc5
 | ||||||
|  | 		FORMAT_BPTC_RGBA, //btpc bc6h
 | ||||||
|  | 		FORMAT_BPTC_RGBF, //float /
 | ||||||
|  | 		FORMAT_BPTC_RGBFU, //unsigned float
 | ||||||
|  | 		FORMAT_PVRTC2, //pvrtc
 | ||||||
|  | 		FORMAT_PVRTC2A, | ||||||
|  | 		FORMAT_PVRTC4, | ||||||
|  | 		FORMAT_PVRTC4A, | ||||||
|  | 		FORMAT_ETC, //etc1
 | ||||||
|  | 		FORMAT_ETC2_R11, //etc2
 | ||||||
|  | 		FORMAT_ETC2_R11S, //signed, NOT srgb.
 | ||||||
|  | 		FORMAT_ETC2_RG11, | ||||||
|  | 		FORMAT_ETC2_RG11S, | ||||||
|  | 		FORMAT_ETC2_RGB8, | ||||||
|  | 		FORMAT_ETC2_RGBA8, | ||||||
|  | 		FORMAT_ETC2_RGB8A1, | ||||||
| 		FORMAT_MAX | 		FORMAT_MAX | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
|  | @ -96,15 +105,21 @@ public: | ||||||
| 		/* INTERPOLATE GAUSS */ | 		/* INTERPOLATE GAUSS */ | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
|  | 	//some functions provided by something else
 | ||||||
|  | 
 | ||||||
| 	static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size); | 	static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size); | ||||||
| 	static Image (*_jpg_mem_loader_func)(const uint8_t* p_png,int p_size); | 	static Image (*_jpg_mem_loader_func)(const uint8_t* p_png,int p_size); | ||||||
|  | 
 | ||||||
| 	static void (*_image_compress_bc_func)(Image *); | 	static void (*_image_compress_bc_func)(Image *); | ||||||
| 	static void (*_image_compress_pvrtc2_func)(Image *); | 	static void (*_image_compress_pvrtc2_func)(Image *); | ||||||
| 	static void (*_image_compress_pvrtc4_func)(Image *); | 	static void (*_image_compress_pvrtc4_func)(Image *); | ||||||
| 	static void (*_image_compress_etc_func)(Image *); | 	static void (*_image_compress_etc_func)(Image *); | ||||||
|  | 	static void (*_image_compress_etc2_func)(Image *); | ||||||
|  | 
 | ||||||
| 	static void (*_image_decompress_pvrtc)(Image *); | 	static void (*_image_decompress_pvrtc)(Image *); | ||||||
| 	static void (*_image_decompress_bc)(Image *); | 	static void (*_image_decompress_bc)(Image *); | ||||||
| 	static void (*_image_decompress_etc)(Image *); | 	static void (*_image_decompress_etc)(Image *); | ||||||
|  | 	static void (*_image_decompress_etc2)(Image *); | ||||||
| 
 | 
 | ||||||
| 	Error _decompress_bc(); | 	Error _decompress_bc(); | ||||||
| 
 | 
 | ||||||
|  | @ -114,92 +129,19 @@ public: | ||||||
| 	static Image (*lossless_unpacker)(const DVector<uint8_t>& p_buffer); | 	static Image (*lossless_unpacker)(const DVector<uint8_t>& p_buffer); | ||||||
| private: | private: | ||||||
| 
 | 
 | ||||||
| 	//internal byte based color
 |  | ||||||
| 	struct BColor { |  | ||||||
| 		union { |  | ||||||
| 			uint8_t col[4]; |  | ||||||
| 			struct { |  | ||||||
| 				uint8_t r,g,b,a; |  | ||||||
| 			}; |  | ||||||
| 		}; |  | ||||||
| 
 |  | ||||||
| 		bool operator==(const BColor& p_color) const { for(int i=0;i<4;i++) {if (col[i]!=p_color.col[i]) return false; } return true; } |  | ||||||
| 		_FORCE_INLINE_ uint8_t gray() const { return (uint16_t(col[0])+uint16_t(col[1])+uint16_t(col[2]))/3; } |  | ||||||
| 		_FORCE_INLINE_ BColor() {} |  | ||||||
| 		BColor(uint8_t p_r,uint8_t p_g,uint8_t p_b,uint8_t p_a=255) { col[0]=p_r; col[1]=p_g; col[2]=p_b; col[3]=p_a; } |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	//median cut classes
 |  | ||||||
| 
 |  | ||||||
| 	struct BColorPos { |  | ||||||
| 
 |  | ||||||
| 		uint32_t index; |  | ||||||
| 		BColor color; |  | ||||||
| 		struct SortR { |  | ||||||
| 
 |  | ||||||
| 			bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.r < cb.color.r; } |  | ||||||
| 		}; |  | ||||||
| 
 |  | ||||||
| 		struct SortG { |  | ||||||
| 
 |  | ||||||
| 			bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.g < cb.color.g; } |  | ||||||
| 		}; |  | ||||||
| 
 |  | ||||||
| 		struct SortB { |  | ||||||
| 
 |  | ||||||
| 			bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.b < cb.color.b; } |  | ||||||
| 		}; |  | ||||||
| 
 |  | ||||||
| 		struct SortA { |  | ||||||
| 
 |  | ||||||
| 			bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.a < cb.color.a; } |  | ||||||
| 		}; |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	struct SPTree { |  | ||||||
| 
 |  | ||||||
| 		bool leaf; |  | ||||||
| 		uint8_t split_plane; |  | ||||||
| 		uint8_t split_value; |  | ||||||
| 		union { |  | ||||||
| 			int left; |  | ||||||
| 			int color; |  | ||||||
| 		}; |  | ||||||
| 		int right; |  | ||||||
| 		SPTree() { leaf=true; left=-1; right=-1;} |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	struct MCBlock { |  | ||||||
| 
 |  | ||||||
| 		BColorPos min_color,max_color; |  | ||||||
| 		BColorPos *colors; |  | ||||||
| 		int sp_idx; |  | ||||||
| 		int color_count; |  | ||||||
| 		int get_longest_axis_index() const; |  | ||||||
| 		int get_longest_axis_length() const; |  | ||||||
| 		bool operator<(const MCBlock& p_block) const; |  | ||||||
| 		void shrink(); |  | ||||||
| 		MCBlock(); |  | ||||||
| 		MCBlock(BColorPos *p_colors,int p_color_count); |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	Format format; | 	Format format; | ||||||
| 	DVector<uint8_t> data; | 	DVector<uint8_t> data; | ||||||
| 	int width,height,mipmaps; | 	int width,height; | ||||||
|  | 	bool mipmaps; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	_FORCE_INLINE_ BColor _get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const; |  | ||||||
| 	_FORCE_INLINE_ BColor _get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const; |  | ||||||
| 	_FORCE_INLINE_ void _put_pixelw(int p_x,int p_y, int p_width, const BColor& p_color, unsigned char *p_data); |  | ||||||
| 	_FORCE_INLINE_ void _put_pixel(int p_x,int p_y, const BColor& p_color, unsigned char *p_data); |  | ||||||
| 	_FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
 | 	_FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
 | ||||||
| 	_FORCE_INLINE_ static void _get_format_min_data_size(Format p_format,int &r_w, int &r_h); |  | ||||||
| 
 | 
 | ||||||
| 	static int _get_dst_image_size(int p_width, int p_height, Format p_format,int &r_mipmaps,int p_mipmaps=-1); | 	static int _get_dst_image_size(int p_width, int p_height, Format p_format,int &r_mipmaps,int p_mipmaps=-1); | ||||||
| 	bool _can_modify(Format p_format) const; | 	bool _can_modify(Format p_format) const; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 	_FORCE_INLINE_ void _put_pixelb(int p_x,int p_y, uint32_t p_pixelsize,uint8_t *p_dst,const uint8_t *p_src); | ||||||
|  | 	_FORCE_INLINE_ void _get_pixelb(int p_x,int p_y,  uint32_t p_pixelsize,const uint8_t *p_src,uint8_t *p_dst); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 
 | 
 | ||||||
|  | @ -207,20 +149,11 @@ public: | ||||||
| 
 | 
 | ||||||
| 	int get_width() const; ///< Get image width
 | 	int get_width() const; ///< Get image width
 | ||||||
| 	int get_height() const; ///< Get image height
 | 	int get_height() const; ///< Get image height
 | ||||||
| 	int get_mipmaps() const; | 	bool has_mipmaps() const; | ||||||
|  | 	int get_mipmap_count() const; | ||||||
| 
 | 
 | ||||||
| 	/**
 | 	/**
 | ||||||
| 	 * Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual | 	 * Convert the image to another format, conversion only to raw byte format | ||||||
| 	 * value. |  | ||||||
| 	 */ |  | ||||||
| 	Color get_pixel(int p_x,int p_y,int p_mipmap=0) const; |  | ||||||
| 	/**
 |  | ||||||
| 	 * Set a pixel into the image. for grayscale or indexed formats, a suitable Color constructor. |  | ||||||
| 	 */ |  | ||||||
| 	void put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap=0); /* alpha and index are averaged */ |  | ||||||
| 
 |  | ||||||
| 	/**
 |  | ||||||
| 	 * Convert the image to another format, as close as it can be done. |  | ||||||
| 	 */ | 	 */ | ||||||
| 	void convert( Format p_new_format ); | 	void convert( Format p_new_format ); | ||||||
| 
 | 
 | ||||||
|  | @ -259,25 +192,21 @@ public: | ||||||
| 
 | 
 | ||||||
| 	void flip_x(); | 	void flip_x(); | ||||||
| 	void flip_y(); | 	void flip_y(); | ||||||
|  | 
 | ||||||
| 	/**
 | 	/**
 | ||||||
| 	 * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1) | 	 * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1) | ||||||
| 	 */ | 	 */ | ||||||
| 	Error generate_mipmaps(int p_amount=-1,bool p_keep_existing=false); | 	Error generate_mipmaps(bool p_keep_existing=false); | ||||||
| 
 | 
 | ||||||
| 	void clear_mipmaps(); | 	void clear_mipmaps(); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	/**
 |  | ||||||
| 	 * Generate a normal map from a grayscale image |  | ||||||
| 	 */ |  | ||||||
| 
 |  | ||||||
| 	void make_normalmap(float p_height_scale=1.0); |  | ||||||
| 
 | 
 | ||||||
| 	/**
 | 	/**
 | ||||||
| 	 * Create a new image of a given size and format. Current image will be lost | 	 * Create a new image of a given size and format. Current image will be lost | ||||||
| 	 */ | 	 */ | ||||||
| 	void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format); | 	void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format); | ||||||
| 	void create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data); | 	void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const DVector<uint8_t>& p_data); | ||||||
| 
 | 
 | ||||||
| 	void create( const char ** p_xpm ); | 	void create( const char ** p_xpm ); | ||||||
| 	/**
 | 	/**
 | ||||||
|  | @ -301,7 +230,7 @@ public: | ||||||
| 	/**
 | 	/**
 | ||||||
| 	 * import an image of a specific size and format from a pointer | 	 * import an image of a specific size and format from a pointer | ||||||
| 	 */ | 	 */ | ||||||
| 	Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data); | 	Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const DVector<uint8_t>& p_data); | ||||||
| 
 | 
 | ||||||
| 	enum AlphaMode { | 	enum AlphaMode { | ||||||
| 		ALPHA_NONE, | 		ALPHA_NONE, | ||||||
|  | @ -312,32 +241,27 @@ public: | ||||||
| 	AlphaMode detect_alpha() const; | 	AlphaMode detect_alpha() const; | ||||||
| 	bool is_invisible() const; | 	bool is_invisible() const; | ||||||
| 
 | 
 | ||||||
| 	void put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap=0); |  | ||||||
| 	uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const; |  | ||||||
| 	void set_pallete(const DVector<uint8_t>& p_data); |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| 	static int get_format_pixel_size(Format p_format); | 	static int get_format_pixel_size(Format p_format); | ||||||
| 	static int get_format_pixel_rshift(Format p_format); | 	static int get_format_pixel_rshift(Format p_format); | ||||||
| 	static int get_format_pallete_size(Format p_format); | 	static void get_format_min_pixel_size(Format p_format,int &r_w, int &r_h); | ||||||
|  | 
 | ||||||
| 	static int get_image_data_size(int p_width, int p_height, Format p_format,int p_mipmaps=0); | 	static int get_image_data_size(int p_width, int p_height, Format p_format,int p_mipmaps=0); | ||||||
| 	static int get_image_required_mipmaps(int p_width, int p_height, Format p_format); | 	static int get_image_required_mipmaps(int p_width, int p_height, Format p_format); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	bool operator==(const Image& p_image) const; | 	bool operator==(const Image& p_image) const; | ||||||
| 
 | 
 | ||||||
| 	void quantize(); |  | ||||||
| 
 |  | ||||||
| 	enum CompressMode { | 	enum CompressMode { | ||||||
| 		COMPRESS_BC, | 		COMPRESS_16BIT, | ||||||
|  | 		COMPRESS_S3TC, | ||||||
| 		COMPRESS_PVRTC2, | 		COMPRESS_PVRTC2, | ||||||
| 		COMPRESS_PVRTC4, | 		COMPRESS_PVRTC4, | ||||||
| 		COMPRESS_ETC | 		COMPRESS_ETC, | ||||||
|  | 		COMPRESS_ETC2 | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	Error compress(CompressMode p_mode=COMPRESS_BC); | 	Error compress(CompressMode p_mode=COMPRESS_S3TC); | ||||||
| 	Image compressed(int p_mode); /* from the Image::CompressMode enum */ | 	Image compressed(int p_mode); /* from the Image::CompressMode enum */ | ||||||
| 	Error decompress(); | 	Error decompress(); | ||||||
| 	Image decompressed() const; | 	Image decompressed() const; | ||||||
|  | @ -349,8 +273,6 @@ public: | ||||||
| 	void normalmap_to_xy(); | 	void normalmap_to_xy(); | ||||||
| 
 | 
 | ||||||
| 	void blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest); | 	void blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest); | ||||||
| 	void brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest); |  | ||||||
| 	Image brushed(const Image& p_src, const Image& p_brush, const Point2& p_dest) const; |  | ||||||
| 
 | 
 | ||||||
| 	Rect2 get_used_rect() const; | 	Rect2 get_used_rect() const; | ||||||
| 	Image get_rect(const Rect2& p_area) const; | 	Image get_rect(const Rect2& p_area) const; | ||||||
|  |  | ||||||
|  | @ -1,365 +0,0 @@ | ||||||
| /*************************************************************************/ |  | ||||||
| /*  image_quantize.cpp                                                   */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /*                       This file is part of:                           */ |  | ||||||
| /*                           GODOT ENGINE                                */ |  | ||||||
| /*                    http://www.godotengine.org                         */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ |  | ||||||
| /* a copy of this software and associated documentation files (the       */ |  | ||||||
| /* "Software"), to deal in the Software without restriction, including   */ |  | ||||||
| /* without limitation the rights to use, copy, modify, merge, publish,   */ |  | ||||||
| /* distribute, sublicense, and/or sell copies of the Software, and to    */ |  | ||||||
| /* permit persons to whom the Software is furnished to do so, subject to */ |  | ||||||
| /* the following conditions:                                             */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* The above copyright notice and this permission notice shall be        */ |  | ||||||
| /* included in all copies or substantial portions of the Software.       */ |  | ||||||
| /*                                                                       */ |  | ||||||
| /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ |  | ||||||
| /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ |  | ||||||
| /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ |  | ||||||
| /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ |  | ||||||
| /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ |  | ||||||
| /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ |  | ||||||
| /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ |  | ||||||
| /*************************************************************************/ |  | ||||||
| #include "image.h" |  | ||||||
| #include <stdio.h> |  | ||||||
| #include "print_string.h" |  | ||||||
| #ifdef TOOLS_ENABLED |  | ||||||
| #include "set.h" |  | ||||||
| #include "sort.h" |  | ||||||
| #include "os/os.h" |  | ||||||
| 
 |  | ||||||
| //#define QUANTIZE_SPEED_OVER_QUALITY
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| Image::MCBlock::MCBlock() { |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| Image::MCBlock::MCBlock(BColorPos *p_colors,int p_color_count) { |  | ||||||
| 
 |  | ||||||
| 	colors=p_colors; |  | ||||||
| 	color_count=p_color_count; |  | ||||||
| 	min_color.color=BColor(255,255,255,255); |  | ||||||
| 	max_color.color=BColor(0,0,0,0); |  | ||||||
| 	shrink(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| int Image::MCBlock::get_longest_axis_index() const { |  | ||||||
| 
 |  | ||||||
| 	int max_dist=-1; |  | ||||||
| 	int max_index=0; |  | ||||||
| 
 |  | ||||||
| 	for(int i=0;i<4;i++) { |  | ||||||
| 
 |  | ||||||
| 		int d = max_color.color.col[i]-min_color.color.col[i]; |  | ||||||
| 		if (d>max_dist) { |  | ||||||
| 			max_index=i; |  | ||||||
| 			max_dist=d; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return max_index; |  | ||||||
| } |  | ||||||
| int Image::MCBlock::get_longest_axis_length() const { |  | ||||||
| 
 |  | ||||||
| 	int max_dist=-1; |  | ||||||
| 
 |  | ||||||
| 	for(int i=0;i<4;i++) { |  | ||||||
| 
 |  | ||||||
| 		int d = max_color.color.col[i]-min_color.color.col[i]; |  | ||||||
| 		if (d>max_dist) { |  | ||||||
| 			max_dist=d; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return max_dist; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| bool Image::MCBlock::operator<(const MCBlock& p_block) const { |  | ||||||
| 
 |  | ||||||
| 	int alen = get_longest_axis_length(); |  | ||||||
| 	int blen = p_block.get_longest_axis_length(); |  | ||||||
| 	if (alen==blen) { |  | ||||||
| 
 |  | ||||||
| 		return colors < p_block.colors; |  | ||||||
| 	} else |  | ||||||
| 		return alen < blen; |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void Image::MCBlock::shrink() { |  | ||||||
| 
 |  | ||||||
| 	min_color=colors[0]; |  | ||||||
| 	max_color=colors[0]; |  | ||||||
| 
 |  | ||||||
| 	for(int i=1;i<color_count;i++) { |  | ||||||
| 
 |  | ||||||
| 		for(int j=0;j<4;j++) { |  | ||||||
| 
 |  | ||||||
| 			min_color.color.col[j]=MIN(min_color.color.col[j],colors[i].color.col[j]); |  | ||||||
| 			max_color.color.col[j]=MAX(max_color.color.col[j],colors[i].color.col[j]); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| void Image::quantize() { |  | ||||||
| 
 |  | ||||||
| 	bool has_alpha = detect_alpha()!=ALPHA_NONE; |  | ||||||
| 
 |  | ||||||
| 	bool quantize_fast=OS::get_singleton()->has_environment("QUANTIZE_FAST"); |  | ||||||
| 
 |  | ||||||
| 	convert(FORMAT_RGBA); |  | ||||||
| 
 |  | ||||||
| 	ERR_FAIL_COND( format!=FORMAT_RGBA ); |  | ||||||
| 
 |  | ||||||
| 	DVector<uint8_t> indexed_data; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	{ |  | ||||||
| 		int color_count = data.size()/4; |  | ||||||
| 
 |  | ||||||
| 		ERR_FAIL_COND(color_count==0); |  | ||||||
| 
 |  | ||||||
| 		Set<MCBlock> block_queue; |  | ||||||
| 
 |  | ||||||
| 		DVector<BColorPos> data_colors; |  | ||||||
| 		data_colors.resize(color_count); |  | ||||||
| 
 |  | ||||||
| 		DVector<BColorPos>::Write dcw=data_colors.write(); |  | ||||||
| 
 |  | ||||||
| 		DVector<uint8_t>::Read dr = data.read(); |  | ||||||
| 		const BColor * drptr=(const BColor*)&dr[0]; |  | ||||||
| 		BColorPos *bcptr=&dcw[0]; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		{ |  | ||||||
| 			for(int i=0;i<color_count;i++) { |  | ||||||
| 
 |  | ||||||
| 				//uint32_t data_ofs=i<<2;
 |  | ||||||
| 				bcptr[i].color=drptr[i];//BColor(drptr[data_ofs+0],drptr[data_ofs+1],drptr[data_ofs+2],drptr[data_ofs+3]);
 |  | ||||||
| 				bcptr[i].index=i; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		//printf("color count: %i\n",color_count);
 |  | ||||||
| 		/*
 |  | ||||||
| 		for(int i=0;i<color_count;i++) { |  | ||||||
| 
 |  | ||||||
| 			BColor bc = ((BColor*)&wb[0])[i]; |  | ||||||
| 			printf("%i - %i,%i,%i,%i\n",i,bc.r,bc.g,bc.b,bc.a); |  | ||||||
| 		}*/ |  | ||||||
| 
 |  | ||||||
| 		MCBlock initial_block((BColorPos*)&dcw[0],color_count); |  | ||||||
| 
 |  | ||||||
| 		block_queue.insert(initial_block); |  | ||||||
| 
 |  | ||||||
| 		while( block_queue.size() < 256 && block_queue.back()->get().color_count > 1 ) { |  | ||||||
| 
 |  | ||||||
| 			MCBlock longest = block_queue.back()->get(); |  | ||||||
| 			//printf("longest: %i (%i)\n",longest.get_longest_axis_index(),longest.get_longest_axis_length());
 |  | ||||||
| 
 |  | ||||||
| 			block_queue.erase(block_queue.back()); |  | ||||||
| 
 |  | ||||||
| 			BColorPos *first = longest.colors; |  | ||||||
| 			BColorPos *median = longest.colors + (longest.color_count+1)/2; |  | ||||||
| 			BColorPos *end = longest.colors + longest.color_count; |  | ||||||
| 
 |  | ||||||
| #if 0 |  | ||||||
| 			int lai =longest.get_longest_axis_index(); |  | ||||||
| 			switch(lai) { |  | ||||||
| #if 0 |  | ||||||
| 				case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.sort(first,end-first); } break; |  | ||||||
| 				case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.sort(first,end-first); } break; |  | ||||||
| 				case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.sort(first,end-first); } break; |  | ||||||
| 				case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.sort(first,end-first); } break; |  | ||||||
| #else |  | ||||||
| 				case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| 				case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| 				case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| 				case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			//avoid same color from being split in 2
 |  | ||||||
| 			//search forward and flip
 |  | ||||||
| 			BColorPos *median_end=median; |  | ||||||
| 			BColorPos *p=median_end+1; |  | ||||||
| 
 |  | ||||||
| 			while(p!=end) { |  | ||||||
| 				if (median_end->color==p->color) { |  | ||||||
| 					SWAP(*(median_end+1),*p); |  | ||||||
| 					median_end++; |  | ||||||
| 				} |  | ||||||
| 				p++; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			//search backward and flip
 |  | ||||||
| 			BColorPos *median_begin=median; |  | ||||||
| 			p=median_begin-1; |  | ||||||
| 
 |  | ||||||
| 			while(p!=(first-1)) { |  | ||||||
| 				if (median_begin->color==p->color) { |  | ||||||
| 					SWAP(*(median_begin-1),*p); |  | ||||||
| 					median_begin--; |  | ||||||
| 				} |  | ||||||
| 				p--; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 			if (first < median_begin) { |  | ||||||
| 				median=median_begin; |  | ||||||
| 			} else if (median_end < end-1) { |  | ||||||
| 				median=median_end+1; |  | ||||||
| 			} else { |  | ||||||
| 				break; //shouldn't have arrived here, since it means all pixels are equal, but wathever
 |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			MCBlock left(first,median-first); |  | ||||||
| 			MCBlock right(median,end-median); |  | ||||||
| 
 |  | ||||||
| 			block_queue.insert(left); |  | ||||||
| 			block_queue.insert(right); |  | ||||||
| 
 |  | ||||||
| #else |  | ||||||
| 			switch(longest.get_longest_axis_index()) { |  | ||||||
| 				case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| 				case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| 				case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| 				case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.nth_element(0,end-first,median-first,first); } break; |  | ||||||
| 
 |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			MCBlock left(first,median-first); |  | ||||||
| 			MCBlock right(median,end-median); |  | ||||||
| 
 |  | ||||||
| 			block_queue.insert(left); |  | ||||||
| 			block_queue.insert(right); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		while(block_queue.size() > 256) { |  | ||||||
| 
 |  | ||||||
| 			block_queue.erase(block_queue.front());// erase least significant
 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		int res_colors=0; |  | ||||||
| 
 |  | ||||||
| 		int comp_size = (has_alpha?4:3); |  | ||||||
| 		indexed_data.resize(color_count + 256*comp_size); |  | ||||||
| 
 |  | ||||||
| 		DVector<uint8_t>::Write iw = indexed_data.write(); |  | ||||||
| 		uint8_t *iwptr=&iw[0]; |  | ||||||
| 		BColor pallete[256]; |  | ||||||
| 
 |  | ||||||
| 	//	print_line("applying quantization - res colors "+itos(block_queue.size()));
 |  | ||||||
| 
 |  | ||||||
| 		while(block_queue.size()) { |  | ||||||
| 
 |  | ||||||
| 			const MCBlock &b = block_queue.back()->get(); |  | ||||||
| 
 |  | ||||||
| 			uint64_t sum[4]={0,0,0,0}; |  | ||||||
| 
 |  | ||||||
| 			for(int i=0;i<b.color_count;i++) { |  | ||||||
| 
 |  | ||||||
| 				sum[0]+=b.colors[i].color.col[0]; |  | ||||||
| 				sum[1]+=b.colors[i].color.col[1]; |  | ||||||
| 				sum[2]+=b.colors[i].color.col[2]; |  | ||||||
| 				sum[3]+=b.colors[i].color.col[3]; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			BColor c( sum[0]/b.color_count, sum[1]/b.color_count, sum[2]/b.color_count, sum[3]/b.color_count ); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 			//printf(" %i: %i,%i,%i,%i out of %i\n",res_colors,c.r,c.g,c.b,c.a,b.color_count);
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 			for(int i=0;i<comp_size;i++) { |  | ||||||
| 				iwptr[ color_count + res_colors * comp_size + i ] = c.col[i]; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			if (quantize_fast) { |  | ||||||
| 				for(int i=0;i<b.color_count;i++) { |  | ||||||
| 					iwptr[b.colors[i].index]=res_colors; |  | ||||||
| 				} |  | ||||||
| 			} else { |  | ||||||
| 
 |  | ||||||
| 				pallete[res_colors]=c; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 			res_colors++; |  | ||||||
| 
 |  | ||||||
| 			block_queue.erase(block_queue.back()); |  | ||||||
| 
 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		if (!quantize_fast) { |  | ||||||
| 
 |  | ||||||
| 			for(int i=0;i<color_count;i++) { |  | ||||||
| 
 |  | ||||||
| 				const BColor &c=drptr[i]; |  | ||||||
| 				uint8_t best_dist_idx=0; |  | ||||||
| 				uint32_t dist=0xFFFFFFFF; |  | ||||||
| 
 |  | ||||||
| 				for(int j=0;j<res_colors;j++) { |  | ||||||
| 
 |  | ||||||
| 					const BColor &pc=pallete[j]; |  | ||||||
| 					uint32_t d = 0; |  | ||||||
| 					{ int16_t v = (int16_t)c.r-(int16_t)pc.r; d+=v*v; } |  | ||||||
| 					{ int16_t v = (int16_t)c.g-(int16_t)pc.g; d+=v*v; } |  | ||||||
| 					{ int16_t v = (int16_t)c.b-(int16_t)pc.b; d+=v*v; } |  | ||||||
| 					{ int16_t v = (int16_t)c.a-(int16_t)pc.a; d+=v*v; } |  | ||||||
| 
 |  | ||||||
| 					if (d<=dist) { |  | ||||||
| 						best_dist_idx=j; |  | ||||||
| 						dist=d; |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 				iwptr[ i ] = best_dist_idx; |  | ||||||
| 
 |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		//iw = DVector<uint8_t>::Write();
 |  | ||||||
| 		//dr = DVector<uint8_t>::Read();
 |  | ||||||
| 		//wb = DVector<uint8_t>::Write();
 |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	print_line(itos(indexed_data.size())); |  | ||||||
| 	data=indexed_data; |  | ||||||
| 	format=has_alpha?FORMAT_INDEXED_ALPHA:FORMAT_INDEXED; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| } //do none
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| #else |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| void Image::quantize() {} //do none
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -106,7 +106,7 @@ List<StringName> InputMap::get_actions() const { | ||||||
| 	return actions; | 	return actions; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const { | List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore=false) const { | ||||||
| 
 | 
 | ||||||
| 	for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) { | 	for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) { | ||||||
| 
 | 
 | ||||||
|  | @ -122,7 +122,7 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const | ||||||
| 
 | 
 | ||||||
| 			case InputEvent::KEY: { | 			case InputEvent::KEY: { | ||||||
| 
 | 
 | ||||||
| 				same=(e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod); | 				same=(e.key.scancode==p_event.key.scancode && (p_mod_ignore || e.key.mod == p_event.key.mod)); | ||||||
| 
 | 
 | ||||||
| 			} break; | 			} break; | ||||||
| 			case InputEvent::JOYSTICK_BUTTON: { | 			case InputEvent::JOYSTICK_BUTTON: { | ||||||
|  | @ -229,7 +229,7 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac | ||||||
| 		return p_event.action.action==E->get().id; | 		return p_event.action.action==E->get().id; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return _find_event(E->get().inputs,p_event)!=NULL; | 	return _find_event(E->get().inputs,p_event,!p_event.is_pressed())!=NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const Map<StringName, InputMap::Action>& InputMap::get_action_map() const { | const Map<StringName, InputMap::Action>& InputMap::get_action_map() const { | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -46,7 +46,7 @@ private: | ||||||
| 	mutable Map<StringName, Action> input_map; | 	mutable Map<StringName, Action> input_map; | ||||||
| 	mutable Map<int,StringName> input_id_map; | 	mutable Map<int,StringName> input_id_map; | ||||||
| 
 | 
 | ||||||
| 	List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const; | 	List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore) const; | ||||||
| 
 | 
 | ||||||
| 	Array _get_action_list(const StringName& p_action); | 	Array _get_action_list(const StringName& p_action); | ||||||
| 	Array _get_actions(); | 	Array _get_actions(); | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -29,11 +29,14 @@ | ||||||
| #include "http_client.h" | #include "http_client.h" | ||||||
| #include "io/stream_peer_ssl.h" | #include "io/stream_peer_ssl.h" | ||||||
| 
 | 
 | ||||||
| VARIANT_ENUM_CAST(IP_Address::AddrType); | void HTTPClient::set_ip_type(IP::Type p_type) { | ||||||
|  | 	ip_type = p_type; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host, IP_Address::AddrType p_addr_type){ | Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host){ | ||||||
| 
 | 
 | ||||||
| 	close(); | 	close(); | ||||||
|  | 	tcp_connection->set_ip_type(ip_type); | ||||||
| 	conn_port=p_port; | 	conn_port=p_port; | ||||||
| 	conn_host=p_host; | 	conn_host=p_host; | ||||||
| 
 | 
 | ||||||
|  | @ -63,7 +66,7 @@ Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_ve | ||||||
| 		status=STATUS_CONNECTING; | 		status=STATUS_CONNECTING; | ||||||
| 	} else { | 	} else { | ||||||
| 		//is hostname
 | 		//is hostname
 | ||||||
| 		resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host, p_addr_type); | 		resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host, ip_type); | ||||||
| 		status=STATUS_RESOLVING; | 		status=STATUS_RESOLVING; | ||||||
| 
 | 
 | ||||||
| 	} | 	} | ||||||
|  | @ -636,7 +639,8 @@ Error HTTPClient::_get_http_data(uint8_t* p_buffer, int p_bytes,int &r_received) | ||||||
| 
 | 
 | ||||||
| void HTTPClient::_bind_methods() { | void HTTPClient::_bind_methods() { | ||||||
| 
 | 
 | ||||||
| 	ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true),DEFVAL(IP_Address::TYPE_ANY)); | 	ObjectTypeDB::bind_method(_MD("set_ip_type","ip_type"),&HTTPClient::set_ip_type); | ||||||
|  | 	ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true)); | ||||||
| 	ObjectTypeDB::bind_method(_MD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection); | 	ObjectTypeDB::bind_method(_MD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection); | ||||||
| 	ObjectTypeDB::bind_method(_MD("get_connection:StreamPeer"),&HTTPClient::get_connection); | 	ObjectTypeDB::bind_method(_MD("get_connection:StreamPeer"),&HTTPClient::get_connection); | ||||||
| 	ObjectTypeDB::bind_method(_MD("request_raw","method","url","headers","body"),&HTTPClient::request_raw); | 	ObjectTypeDB::bind_method(_MD("request_raw","method","url","headers","body"),&HTTPClient::request_raw); | ||||||
|  | @ -762,6 +766,7 @@ String HTTPClient::query_string_from_dict(const Dictionary& p_dict) { | ||||||
| 
 | 
 | ||||||
| HTTPClient::HTTPClient(){ | HTTPClient::HTTPClient(){ | ||||||
| 
 | 
 | ||||||
|  | 	ip_type = IP::TYPE_ANY; | ||||||
| 	tcp_connection = StreamPeerTCP::create_ref(); | 	tcp_connection = StreamPeerTCP::create_ref(); | ||||||
| 	resolving = IP::RESOLVER_INVALID_ID; | 	resolving = IP::RESOLVER_INVALID_ID; | ||||||
| 	status=STATUS_DISCONNECTED; | 	status=STATUS_DISCONNECTED; | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -132,6 +132,7 @@ public: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| 
 | 
 | ||||||
|  | 	IP::Type ip_type; | ||||||
| 	Status status; | 	Status status; | ||||||
| 	IP::ResolverID resolving; | 	IP::ResolverID resolving; | ||||||
| 	int conn_port; | 	int conn_port; | ||||||
|  | @ -164,8 +165,9 @@ private: | ||||||
| public: | public: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 	void set_ip_type(IP::Type p_type); | ||||||
| 	//Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request
 | 	//Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request
 | ||||||
| 	Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true, IP_Address::AddrType p_addr_type = IP_Address::TYPE_ANY); | 	Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true); | ||||||
| 
 | 
 | ||||||
| 	void set_connection(const Ref<StreamPeer>& p_connection); | 	void set_connection(const Ref<StreamPeer>& p_connection); | ||||||
| 	Ref<StreamPeer> get_connection() const; | 	Ref<StreamPeer> get_connection() const; | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -32,7 +32,6 @@ | ||||||
| #include "hash_map.h" | #include "hash_map.h" | ||||||
| 
 | 
 | ||||||
| VARIANT_ENUM_CAST(IP::ResolverStatus); | VARIANT_ENUM_CAST(IP::ResolverStatus); | ||||||
| VARIANT_ENUM_CAST(IP_Address::AddrType); |  | ||||||
| 
 | 
 | ||||||
| /************* RESOLVER ******************/ | /************* RESOLVER ******************/ | ||||||
| 
 | 
 | ||||||
|  | @ -44,12 +43,12 @@ struct _IP_ResolverPrivate { | ||||||
| 		volatile IP::ResolverStatus status; | 		volatile IP::ResolverStatus status; | ||||||
| 		IP_Address response; | 		IP_Address response; | ||||||
| 		String hostname; | 		String hostname; | ||||||
| 		IP_Address::AddrType type; | 		IP::Type type; | ||||||
| 
 | 
 | ||||||
| 		void clear() { | 		void clear() { | ||||||
| 			status = IP::RESOLVER_STATUS_NONE; | 			status = IP::RESOLVER_STATUS_NONE; | ||||||
| 			response = IP_Address(); | 			response = IP_Address(); | ||||||
| 			type = IP_Address::TYPE_NONE; | 			type = IP::TYPE_NONE; | ||||||
| 			hostname=""; | 			hostname=""; | ||||||
| 		}; | 		}; | ||||||
| 
 | 
 | ||||||
|  | @ -83,7 +82,7 @@ struct _IP_ResolverPrivate { | ||||||
| 				continue; | 				continue; | ||||||
| 			queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); | 			queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); | ||||||
| 
 | 
 | ||||||
| 			if (queue[i].response.type==IP_Address::TYPE_NONE) | 			if (queue[i].response==IP_Address()) | ||||||
| 				queue[i].status=IP::RESOLVER_STATUS_ERROR; | 				queue[i].status=IP::RESOLVER_STATUS_ERROR; | ||||||
| 			else | 			else | ||||||
| 				queue[i].status=IP::RESOLVER_STATUS_DONE; | 				queue[i].status=IP::RESOLVER_STATUS_DONE; | ||||||
|  | @ -108,25 +107,28 @@ struct _IP_ResolverPrivate { | ||||||
| 
 | 
 | ||||||
| 	HashMap<String, IP_Address> cache; | 	HashMap<String, IP_Address> cache; | ||||||
| 
 | 
 | ||||||
|  | 	static String get_cache_key(String p_hostname, IP::Type p_type) { | ||||||
|  | 		return itos(p_type) + p_hostname; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| IP_Address IP::resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type) { | IP_Address IP::resolve_hostname(const String& p_hostname, IP::Type p_type) { | ||||||
| 
 | 
 | ||||||
| 	GLOBAL_LOCK_FUNCTION; | 	GLOBAL_LOCK_FUNCTION; | ||||||
| 
 | 
 | ||||||
| 	if (resolver->cache.has(p_hostname)) | 	String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); | ||||||
| 		if (resolver->cache[p_hostname].type & p_type != 0) | 	if (resolver->cache.has(key)) | ||||||
| 			return resolver->cache[p_hostname]; | 		return resolver->cache[key]; | ||||||
| 		// requested type is different from type in cache. continue resolution, if successful it'll overwrite cache
 |  | ||||||
| 
 | 
 | ||||||
| 	IP_Address res = _resolve_hostname(p_hostname, p_type); | 	IP_Address res = _resolve_hostname(p_hostname, p_type); | ||||||
| 	resolver->cache[p_hostname]=res; | 	resolver->cache[key]=res; | ||||||
| 	return res; | 	return res; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP_Address::AddrType p_type) { | IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP::Type p_type) { | ||||||
| 
 | 
 | ||||||
| 	GLOBAL_LOCK_FUNCTION; | 	GLOBAL_LOCK_FUNCTION; | ||||||
| 
 | 
 | ||||||
|  | @ -137,10 +139,11 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP_Addr | ||||||
| 		return id; | 		return id; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); | ||||||
| 	resolver->queue[id].hostname=p_hostname; | 	resolver->queue[id].hostname=p_hostname; | ||||||
| 	resolver->queue[id].type = p_type; | 	resolver->queue[id].type = p_type; | ||||||
| 	if (resolver->cache.has(p_hostname) && (resolver->cache[p_hostname].type & p_type) != 0) { | 	if (resolver->cache.has(key)) { | ||||||
| 		resolver->queue[id].response=resolver->cache[p_hostname]; | 		resolver->queue[id].response=resolver->cache[key]; | ||||||
| 		resolver->queue[id].status=IP::RESOLVER_STATUS_DONE; | 		resolver->queue[id].status=IP::RESOLVER_STATUS_DONE; | ||||||
| 	} else { | 	} else { | ||||||
| 		resolver->queue[id].response=IP_Address(); | 		resolver->queue[id].response=IP_Address(); | ||||||
|  | @ -194,7 +197,10 @@ void IP::clear_cache(const String &p_hostname) { | ||||||
| 	if (p_hostname.empty()) { | 	if (p_hostname.empty()) { | ||||||
| 		resolver->cache.clear(); | 		resolver->cache.clear(); | ||||||
| 	} else { | 	} else { | ||||||
| 		resolver->cache.erase(p_hostname); | 		resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_NONE)); | ||||||
|  | 		resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_IPV4)); | ||||||
|  | 		resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_IPV6)); | ||||||
|  | 		resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_ANY)); | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -212,8 +218,8 @@ Array IP::_get_local_addresses() const { | ||||||
| 
 | 
 | ||||||
| void IP::_bind_methods() { | void IP::_bind_methods() { | ||||||
| 
 | 
 | ||||||
| 	ObjectTypeDB::bind_method(_MD("resolve_hostname","host"),&IP::resolve_hostname); | 	ObjectTypeDB::bind_method(_MD("resolve_hostname","host","ip_type"),&IP::resolve_hostname,DEFVAL(IP::TYPE_ANY)); | ||||||
| 	ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host"),&IP::resolve_hostname_queue_item); | 	ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host","ip_type"),&IP::resolve_hostname_queue_item,DEFVAL(IP::TYPE_ANY)); | ||||||
| 	ObjectTypeDB::bind_method(_MD("get_resolve_item_status","id"),&IP::get_resolve_item_status); | 	ObjectTypeDB::bind_method(_MD("get_resolve_item_status","id"),&IP::get_resolve_item_status); | ||||||
| 	ObjectTypeDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address); | 	ObjectTypeDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address); | ||||||
| 	ObjectTypeDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item); | 	ObjectTypeDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item); | ||||||
|  | @ -228,6 +234,10 @@ void IP::_bind_methods() { | ||||||
| 	BIND_CONSTANT( RESOLVER_MAX_QUERIES ); | 	BIND_CONSTANT( RESOLVER_MAX_QUERIES ); | ||||||
| 	BIND_CONSTANT( RESOLVER_INVALID_ID ); | 	BIND_CONSTANT( RESOLVER_INVALID_ID ); | ||||||
| 
 | 
 | ||||||
|  | 	BIND_CONSTANT( TYPE_NONE ); | ||||||
|  | 	BIND_CONSTANT( TYPE_IPV4 ); | ||||||
|  | 	BIND_CONSTANT( TYPE_IPV6 ); | ||||||
|  | 	BIND_CONSTANT( TYPE_ANY ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										20
									
								
								core/io/ip.h
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								core/io/ip.h
									
										
									
									
									
								
							|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -48,12 +48,12 @@ public: | ||||||
| 		RESOLVER_STATUS_ERROR, | 		RESOLVER_STATUS_ERROR, | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	enum AddressType { | 	enum Type { | ||||||
| 
 | 
 | ||||||
| 		ADDRESS_IPV4 = 1, | 		TYPE_NONE = 0, | ||||||
| 		ADDRESS_IPV6 = 2, | 		TYPE_IPV4 = 1, | ||||||
| 
 | 		TYPE_IPV6 = 2, | ||||||
| 		ADDRESS_ANY = 3, | 		TYPE_ANY = 3, | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	enum { | 	enum { | ||||||
|  | @ -73,7 +73,7 @@ protected: | ||||||
| 	static IP*singleton; | 	static IP*singleton; | ||||||
| 	static void _bind_methods(); | 	static void _bind_methods(); | ||||||
| 
 | 
 | ||||||
| 	virtual IP_Address _resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY)=0; | 	virtual IP_Address _resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY)=0; | ||||||
| 	Array _get_local_addresses() const; | 	Array _get_local_addresses() const; | ||||||
| 
 | 
 | ||||||
| 	static IP* (*_create)(); | 	static IP* (*_create)(); | ||||||
|  | @ -81,9 +81,9 @@ public: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	IP_Address resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); | 	IP_Address resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY); | ||||||
| 	// async resolver hostname
 | 	// async resolver hostname
 | ||||||
| 	ResolverID resolve_hostname_queue_item(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); | 	ResolverID resolve_hostname_queue_item(const String& p_hostname, Type p_type = TYPE_ANY); | ||||||
| 	ResolverStatus get_resolve_item_status(ResolverID p_id) const; | 	ResolverStatus get_resolve_item_status(ResolverID p_id) const; | ||||||
| 	IP_Address get_resolve_item_address(ResolverID p_id) const; | 	IP_Address get_resolve_item_address(ResolverID p_id) const; | ||||||
| 	virtual void get_local_addresses(List<IP_Address> *r_addresses) const=0; | 	virtual void get_local_addresses(List<IP_Address> *r_addresses) const=0; | ||||||
|  | @ -101,4 +101,6 @@ public: | ||||||
| 
 | 
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | VARIANT_ENUM_CAST(IP::Type); | ||||||
|  | 
 | ||||||
| #endif // IP_H
 | #endif // IP_H
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -38,11 +38,9 @@ IP_Address::operator Variant() const { | ||||||
| 
 | 
 | ||||||
| IP_Address::operator String() const { | IP_Address::operator String() const { | ||||||
| 
 | 
 | ||||||
| 	if (type == TYPE_NONE) | 	if(is_ipv4()) | ||||||
| 		return "0.0.0.0"; | 		// IPv4 address mapped to IPv6
 | ||||||
| 	if (type == TYPE_IPV4) | 		return itos(field8[12])+"."+itos(field8[13])+"."+itos(field8[14])+"."+itos(field8[15]); | ||||||
| 		return itos(field8[0])+"."+itos(field8[1])+"."+itos(field8[2])+"."+itos(field8[3]); |  | ||||||
| 	else { |  | ||||||
| 	String ret; | 	String ret; | ||||||
| 	for (int i=0; i<8; i++) { | 	for (int i=0; i<8; i++) { | ||||||
| 		if (i > 0) | 		if (i > 0) | ||||||
|  | @ -52,7 +50,6 @@ IP_Address::operator String() const { | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	return ret; | 	return ret; | ||||||
| 	}; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void _parse_hex(const String& p_string, int p_start, uint8_t* p_dst) { | static void _parse_hex(const String& p_string, int p_start, uint8_t* p_dst) { | ||||||
|  | @ -176,17 +173,41 @@ void IP_Address::clear() { | ||||||
| 	memset(&field8[0], 0, sizeof(field8)); | 	memset(&field8[0], 0, sizeof(field8)); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | bool IP_Address::is_ipv4() const{ | ||||||
|  | 	return (field32[0]==0 && field32[1]==0 && field16[4]==0 && field16[5]==0xffff); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const uint8_t *IP_Address::get_ipv4() const{ | ||||||
|  | 	ERR_FAIL_COND_V(!is_ipv4(),0); | ||||||
|  | 	return &(field8[12]); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void IP_Address::set_ipv4(const uint8_t *p_ip) { | ||||||
|  | 	clear(); | ||||||
|  | 	field16[5]=0xffff; | ||||||
|  | 	field32[3]=*((const uint32_t *)p_ip); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const uint8_t *IP_Address::get_ipv6() const{ | ||||||
|  | 	return field8; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void IP_Address::set_ipv6(const uint8_t *p_buf) { | ||||||
|  | 	clear(); | ||||||
|  | 	for (int i=0; i<16; i++) | ||||||
|  | 		field8[i] = p_buf[i]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| IP_Address::IP_Address(const String& p_string) { | IP_Address::IP_Address(const String& p_string) { | ||||||
| 
 | 
 | ||||||
| 	clear(); | 	clear(); | ||||||
| 	if (p_string.find(":") >= 0) { | 	if (p_string.find(":") >= 0) { | ||||||
| 
 | 
 | ||||||
| 		_parse_ipv6(p_string); | 		_parse_ipv6(p_string); | ||||||
| 		type = TYPE_IPV6; |  | ||||||
| 	} else { | 	} else { | ||||||
| 
 | 		// Mapped to IPv6
 | ||||||
| 		_parse_ipv4(p_string, 0, &field8[0]); | 		field16[5] = 0xffff; | ||||||
| 		type = TYPE_IPV4; | 		_parse_ipv4(p_string, 0, &field8[12]); | ||||||
| 	}; | 	}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -198,25 +219,22 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t* p_dst, uint32_t p_n) { | ||||||
| 	p_dst[3] = (p_n >> 0) & 0xff; | 	p_dst[3] = (p_n >> 0) & 0xff; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, IP_Address::AddrType p_type) { | IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool is_v6) { | ||||||
| 
 | 
 | ||||||
| 	type = p_type; | 	clear(); | ||||||
| 	memset(&field8[0], 0, sizeof(field8)); | 	if (!is_v6) { | ||||||
| 	if (p_type == TYPE_IPV4) { | 		// Mapped to IPv6
 | ||||||
| 		field8[0]=p_a; | 		field16[5]=0xffff; | ||||||
| 		field8[1]=p_b; | 		field8[12]=p_a; | ||||||
| 		field8[2]=p_c; | 		field8[13]=p_b; | ||||||
| 		field8[3]=p_d; | 		field8[14]=p_c; | ||||||
| 	} else if (type == TYPE_IPV6) { | 		field8[15]=p_d; | ||||||
|  | 	} else { | ||||||
| 
 | 
 | ||||||
| 		_32_to_buf(&field8[0], p_a); | 		_32_to_buf(&field8[0], p_a); | ||||||
| 		_32_to_buf(&field8[4], p_b); | 		_32_to_buf(&field8[4], p_b); | ||||||
| 		_32_to_buf(&field8[8], p_c); | 		_32_to_buf(&field8[8], p_c); | ||||||
| 		_32_to_buf(&field8[12], p_d); | 		_32_to_buf(&field8[12], p_d); | ||||||
| 	} else { | 	} | ||||||
| 		type = TYPE_NONE; |  | ||||||
| 		ERR_EXPLAIN("Invalid type specified for IP_Address (use TYPE_IPV4 or TYPE_IPV6"); |  | ||||||
| 		ERR_FAIL(); |  | ||||||
| 	}; |  | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -33,16 +33,7 @@ | ||||||
| 
 | 
 | ||||||
| struct IP_Address { | struct IP_Address { | ||||||
| 
 | 
 | ||||||
| public: | private: | ||||||
| 	enum AddrType { |  | ||||||
| 		TYPE_NONE = 0, |  | ||||||
| 		TYPE_IPV4 = 1, |  | ||||||
| 		TYPE_IPV6 = 2, |  | ||||||
| 
 |  | ||||||
| 		TYPE_ANY = 3, |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	AddrType type; |  | ||||||
| 
 | 
 | ||||||
| 	union { | 	union { | ||||||
| 		uint8_t field8[16]; | 		uint8_t field8[16]; | ||||||
|  | @ -70,11 +61,17 @@ public: | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	void clear(); | 	void clear(); | ||||||
|  | 	bool is_ipv4() const; | ||||||
|  | 	const uint8_t *get_ipv4() const; | ||||||
|  | 	void set_ipv4(const uint8_t *p_ip); | ||||||
|  | 
 | ||||||
|  | 	const uint8_t *get_ipv6() const; | ||||||
|  | 	void set_ipv6(const uint8_t *buf); | ||||||
| 
 | 
 | ||||||
| 	operator String() const; | 	operator String() const; | ||||||
| 	IP_Address(const String& p_string); | 	IP_Address(const String& p_string); | ||||||
| 	IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, AddrType p_type=TYPE_IPV4); | 	IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool is_v6=false); | ||||||
| 	IP_Address() { clear(); type=TYPE_NONE; } | 	IP_Address() { clear(); } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -1060,7 +1060,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { | ||||||
| 			if (buf) { | 			if (buf) { | ||||||
| 
 | 
 | ||||||
| 				encode_uint32(image.get_format(),&buf[0]); | 				encode_uint32(image.get_format(),&buf[0]); | ||||||
| 				encode_uint32(image.get_mipmaps(),&buf[4]); | 				encode_uint32(image.has_mipmaps(),&buf[4]); | ||||||
| 				encode_uint32(image.get_width(),&buf[8]); | 				encode_uint32(image.get_width(),&buf[8]); | ||||||
| 				encode_uint32(image.get_height(),&buf[12]); | 				encode_uint32(image.get_height(),&buf[12]); | ||||||
| 				int ds=data.size(); | 				int ds=data.size(); | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -31,8 +31,6 @@ | ||||||
| 
 | 
 | ||||||
| PacketPeerUDP* (*PacketPeerUDP::_create)()=NULL; | PacketPeerUDP* (*PacketPeerUDP::_create)()=NULL; | ||||||
| 
 | 
 | ||||||
| VARIANT_ENUM_CAST(IP_Address::AddrType); |  | ||||||
| 
 |  | ||||||
| String PacketPeerUDP::_get_packet_ip() const { | String PacketPeerUDP::_get_packet_ip() const { | ||||||
| 
 | 
 | ||||||
| 	return get_packet_address(); | 	return get_packet_address(); | ||||||
|  | @ -44,7 +42,7 @@ Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) { | ||||||
| 	if (p_address.is_valid_ip_address()) { | 	if (p_address.is_valid_ip_address()) { | ||||||
| 		ip=p_address; | 		ip=p_address; | ||||||
| 	} else { | 	} else { | ||||||
| 		ip=IP::get_singleton()->resolve_hostname(p_address); | 		ip=IP::get_singleton()->resolve_hostname(p_address, ip_type); | ||||||
| 		if (ip==IP_Address()) | 		if (ip==IP_Address()) | ||||||
| 			return ERR_CANT_RESOLVE; | 			return ERR_CANT_RESOLVE; | ||||||
| 	} | 	} | ||||||
|  | @ -53,8 +51,14 @@ Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) { | ||||||
| 	return OK; | 	return OK; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void PacketPeerUDP::set_ip_type(IP::Type p_type) { | ||||||
|  | 	close(); | ||||||
|  | 	ip_type = p_type; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void PacketPeerUDP::_bind_methods() { | void PacketPeerUDP::_bind_methods() { | ||||||
| 
 | 
 | ||||||
|  | 	ObjectTypeDB::bind_method(_MD("set_ip_type","ip_type"),&PacketPeerUDP::set_ip_type); | ||||||
| 	ObjectTypeDB::bind_method(_MD("listen:Error","port", "recv_buf_size"),&PacketPeerUDP::listen,DEFVAL(65536)); | 	ObjectTypeDB::bind_method(_MD("listen:Error","port", "recv_buf_size"),&PacketPeerUDP::listen,DEFVAL(65536)); | ||||||
| 	ObjectTypeDB::bind_method(_MD("close"),&PacketPeerUDP::close); | 	ObjectTypeDB::bind_method(_MD("close"),&PacketPeerUDP::close); | ||||||
| 	ObjectTypeDB::bind_method(_MD("wait:Error"),&PacketPeerUDP::wait); | 	ObjectTypeDB::bind_method(_MD("wait:Error"),&PacketPeerUDP::wait); | ||||||
|  | @ -83,4 +87,5 @@ PacketPeerUDP* PacketPeerUDP::create() { | ||||||
| 
 | 
 | ||||||
| PacketPeerUDP::PacketPeerUDP() | PacketPeerUDP::PacketPeerUDP() | ||||||
| { | { | ||||||
|  | 	ip_type = IP::TYPE_ANY; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -30,6 +30,7 @@ | ||||||
| #define PACKET_PEER_UDP_H | #define PACKET_PEER_UDP_H | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | #include "io/ip.h" | ||||||
| #include "io/packet_peer.h" | #include "io/packet_peer.h" | ||||||
| 
 | 
 | ||||||
| class PacketPeerUDP : public PacketPeer { | class PacketPeerUDP : public PacketPeer { | ||||||
|  | @ -37,6 +38,8 @@ class PacketPeerUDP : public PacketPeer { | ||||||
| 
 | 
 | ||||||
| protected: | protected: | ||||||
| 
 | 
 | ||||||
|  | 	IP::Type ip_type; | ||||||
|  | 
 | ||||||
| 	static PacketPeerUDP* (*_create)(); | 	static PacketPeerUDP* (*_create)(); | ||||||
| 	static void _bind_methods(); | 	static void _bind_methods(); | ||||||
| 
 | 
 | ||||||
|  | @ -46,7 +49,8 @@ protected: | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 
 | 
 | ||||||
| 	virtual Error listen(int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_IPV4, int p_recv_buffer_size=65536)=0; | 	virtual void set_ip_type(IP::Type p_type); | ||||||
|  | 	virtual Error listen(int p_port, int p_recv_buffer_size=65536)=0; | ||||||
| 	virtual void close()=0; | 	virtual void close()=0; | ||||||
| 	virtual Error wait()=0; | 	virtual Error wait()=0; | ||||||
| 	virtual bool is_listening() const=0; | 	virtual bool is_listening() const=0; | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -74,29 +74,6 @@ enum { | ||||||
| 	IMAGE_ENCODING_LOSSLESS=2, | 	IMAGE_ENCODING_LOSSLESS=2, | ||||||
| 	IMAGE_ENCODING_LOSSY=3, | 	IMAGE_ENCODING_LOSSY=3, | ||||||
| 
 | 
 | ||||||
| 	IMAGE_FORMAT_GRAYSCALE=0, |  | ||||||
| 	IMAGE_FORMAT_INTENSITY=1, |  | ||||||
| 	IMAGE_FORMAT_GRAYSCALE_ALPHA=2, |  | ||||||
| 	IMAGE_FORMAT_RGB=3, |  | ||||||
| 	IMAGE_FORMAT_RGBA=4, |  | ||||||
| 	IMAGE_FORMAT_INDEXED=5, |  | ||||||
| 	IMAGE_FORMAT_INDEXED_ALPHA=6, |  | ||||||
| 	IMAGE_FORMAT_BC1=7, |  | ||||||
| 	IMAGE_FORMAT_BC2=8, |  | ||||||
| 	IMAGE_FORMAT_BC3=9, |  | ||||||
| 	IMAGE_FORMAT_BC4=10, |  | ||||||
| 	IMAGE_FORMAT_BC5=11, |  | ||||||
| 	IMAGE_FORMAT_PVRTC2=12, |  | ||||||
| 	IMAGE_FORMAT_PVRTC2_ALPHA=13, |  | ||||||
| 	IMAGE_FORMAT_PVRTC4=14, |  | ||||||
| 	IMAGE_FORMAT_PVRTC4_ALPHA=15, |  | ||||||
| 	IMAGE_FORMAT_ETC=16, |  | ||||||
| 	IMAGE_FORMAT_ATC=17, |  | ||||||
| 	IMAGE_FORMAT_ATC_ALPHA_EXPLICIT=18, |  | ||||||
| 	IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED=19, |  | ||||||
| 	IMAGE_FORMAT_CUSTOM=30, |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	OBJECT_EMPTY=0, | 	OBJECT_EMPTY=0, | ||||||
| 	OBJECT_EXTERNAL_RESOURCE=1, | 	OBJECT_EXTERNAL_RESOURCE=1, | ||||||
| 	OBJECT_INTERNAL_RESOURCE=2, | 	OBJECT_INTERNAL_RESOURCE=2, | ||||||
|  | @ -269,36 +246,20 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v)  { | ||||||
| 				uint32_t height = f->get_32(); | 				uint32_t height = f->get_32(); | ||||||
| 				uint32_t mipmaps = f->get_32(); | 				uint32_t mipmaps = f->get_32(); | ||||||
| 				uint32_t format = f->get_32(); | 				uint32_t format = f->get_32(); | ||||||
| 				Image::Format fmt; | 				const uint32_t format_version_shift=24; | ||||||
| 				switch(format) { | 				const uint32_t format_version_mask=format_version_shift-1; | ||||||
| 
 | 
 | ||||||
| 					case IMAGE_FORMAT_GRAYSCALE: { fmt=Image::FORMAT_GRAYSCALE; } break; | 				uint32_t format_version = format>>format_version_shift; | ||||||
| 					case IMAGE_FORMAT_INTENSITY: { fmt=Image::FORMAT_INTENSITY; } break; |  | ||||||
| 					case IMAGE_FORMAT_GRAYSCALE_ALPHA: { fmt=Image::FORMAT_GRAYSCALE_ALPHA; } break; |  | ||||||
| 					case IMAGE_FORMAT_RGB: { fmt=Image::FORMAT_RGB; } break; |  | ||||||
| 					case IMAGE_FORMAT_RGBA: { fmt=Image::FORMAT_RGBA; } break; |  | ||||||
| 					case IMAGE_FORMAT_INDEXED: { fmt=Image::FORMAT_INDEXED; } break; |  | ||||||
| 					case IMAGE_FORMAT_INDEXED_ALPHA: { fmt=Image::FORMAT_INDEXED_ALPHA; } break; |  | ||||||
| 					case IMAGE_FORMAT_BC1: { fmt=Image::FORMAT_BC1; } break; |  | ||||||
| 					case IMAGE_FORMAT_BC2: { fmt=Image::FORMAT_BC2; } break; |  | ||||||
| 					case IMAGE_FORMAT_BC3: { fmt=Image::FORMAT_BC3; } break; |  | ||||||
| 					case IMAGE_FORMAT_BC4: { fmt=Image::FORMAT_BC4; } break; |  | ||||||
| 					case IMAGE_FORMAT_BC5: { fmt=Image::FORMAT_BC5; } break; |  | ||||||
| 					case IMAGE_FORMAT_PVRTC2: { fmt=Image::FORMAT_PVRTC2; } break; |  | ||||||
| 					case IMAGE_FORMAT_PVRTC2_ALPHA: { fmt=Image::FORMAT_PVRTC2_ALPHA; } break; |  | ||||||
| 					case IMAGE_FORMAT_PVRTC4: { fmt=Image::FORMAT_PVRTC4; } break; |  | ||||||
| 					case IMAGE_FORMAT_PVRTC4_ALPHA: { fmt=Image::FORMAT_PVRTC4_ALPHA; } break; |  | ||||||
| 					case IMAGE_FORMAT_ETC: { fmt=Image::FORMAT_ETC; } break; |  | ||||||
| 					case IMAGE_FORMAT_ATC: { fmt=Image::FORMAT_ATC; } break; |  | ||||||
| 					case IMAGE_FORMAT_ATC_ALPHA_EXPLICIT: { fmt=Image::FORMAT_ATC_ALPHA_EXPLICIT; } break; |  | ||||||
| 					case IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED: { fmt=Image::FORMAT_ATC_ALPHA_INTERPOLATED; } break; |  | ||||||
| 					case IMAGE_FORMAT_CUSTOM: { fmt=Image::FORMAT_CUSTOM; } break; |  | ||||||
| 					default: { |  | ||||||
| 
 | 
 | ||||||
| 						ERR_FAIL_V(ERR_FILE_CORRUPT); | 				const uint32_t current_version = 0; | ||||||
|  | 				if (format_version>current_version) { | ||||||
|  | 
 | ||||||
|  | 					ERR_PRINT("Format version for encoded binary image is too new"); | ||||||
|  | 					return ERR_PARSE_ERROR; | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				} | 
 | ||||||
|  | 				Image::Format fmt=Image::Format(format&format_version_mask); //if format changes, we can add a compatibility bit on top
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 				uint32_t datalen = f->get_32(); | 				uint32_t datalen = f->get_32(); | ||||||
|  | @ -1599,7 +1560,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property, | ||||||
| 			int encoding=IMAGE_ENCODING_RAW; | 			int encoding=IMAGE_ENCODING_RAW; | ||||||
| 			float quality=0.7; | 			float quality=0.7; | ||||||
| 
 | 
 | ||||||
| 			if (val.get_format() <= Image::FORMAT_INDEXED_ALPHA) { | 			if (!val.is_compressed()) { | ||||||
| 				//can only compress uncompressed stuff
 | 				//can only compress uncompressed stuff
 | ||||||
| 
 | 
 | ||||||
| 				if (p_hint.hint==PROPERTY_HINT_IMAGE_COMPRESS_LOSSY && Image::lossy_packer) { | 				if (p_hint.hint==PROPERTY_HINT_IMAGE_COMPRESS_LOSSY && Image::lossy_packer) { | ||||||
|  | @ -1621,33 +1582,8 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property, | ||||||
| 
 | 
 | ||||||
| 				f->store_32(val.get_width()); | 				f->store_32(val.get_width()); | ||||||
| 				f->store_32(val.get_height()); | 				f->store_32(val.get_height()); | ||||||
| 				f->store_32(val.get_mipmaps()); | 				f->store_32(val.has_mipmaps()); | ||||||
| 				switch(val.get_format()) { | 				f->store_32(val.get_format()); //if format changes we can add a compatibility version bit
 | ||||||
| 
 |  | ||||||
| 					case Image::FORMAT_GRAYSCALE: f->store_32(IMAGE_FORMAT_GRAYSCALE ); break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
 |  | ||||||
| 					case Image::FORMAT_INTENSITY: f->store_32(IMAGE_FORMAT_INTENSITY ); break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
 |  | ||||||
| 					case Image::FORMAT_GRAYSCALE_ALPHA: f->store_32(IMAGE_FORMAT_GRAYSCALE_ALPHA ); break; ///< two bytes per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255. alpha 0-255
 |  | ||||||
| 					case Image::FORMAT_RGB: f->store_32(IMAGE_FORMAT_RGB ); break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B
 |  | ||||||
| 					case Image::FORMAT_RGBA: f->store_32(IMAGE_FORMAT_RGBA ); break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B: f->store_32(IMAGE_FORMAT_ ); break; one byte A
 |  | ||||||
| 					case Image::FORMAT_INDEXED: f->store_32(IMAGE_FORMAT_INDEXED ); break; ///< index byte 0-256: f->store_32(IMAGE_FORMAT_ ); break; and after image end: f->store_32(IMAGE_FORMAT_ ); break; 256*3 bytes of palette
 |  | ||||||
| 					case Image::FORMAT_INDEXED_ALPHA: f->store_32(IMAGE_FORMAT_INDEXED_ALPHA ); break; ///< index byte 0-256: f->store_32(IMAGE_FORMAT_ ); break; and after image end: f->store_32(IMAGE_FORMAT_ ); break; 256*4 bytes of palette (alpha)
 |  | ||||||
| 					case Image::FORMAT_BC1: f->store_32(IMAGE_FORMAT_BC1 ); break; // DXT1
 |  | ||||||
| 					case Image::FORMAT_BC2: f->store_32(IMAGE_FORMAT_BC2 ); break; // DXT3
 |  | ||||||
| 					case Image::FORMAT_BC3: f->store_32(IMAGE_FORMAT_BC3 ); break; // DXT5
 |  | ||||||
| 					case Image::FORMAT_BC4: f->store_32(IMAGE_FORMAT_BC4 ); break; // ATI1
 |  | ||||||
| 					case Image::FORMAT_BC5: f->store_32(IMAGE_FORMAT_BC5 ); break; // ATI2
 |  | ||||||
| 					case Image::FORMAT_PVRTC2: f->store_32(IMAGE_FORMAT_PVRTC2 ); break; |  | ||||||
| 					case Image::FORMAT_PVRTC2_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC2_ALPHA ); break; |  | ||||||
| 					case Image::FORMAT_PVRTC4: f->store_32(IMAGE_FORMAT_PVRTC4 ); break; |  | ||||||
| 					case Image::FORMAT_PVRTC4_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC4_ALPHA ); break; |  | ||||||
| 					case Image::FORMAT_ETC: f->store_32(IMAGE_FORMAT_ETC); break; |  | ||||||
| 					case Image::FORMAT_ATC: f->store_32(IMAGE_FORMAT_ATC); break; |  | ||||||
| 					case Image::FORMAT_ATC_ALPHA_EXPLICIT: f->store_32(IMAGE_FORMAT_ATC_ALPHA_EXPLICIT); break; |  | ||||||
| 					case Image::FORMAT_ATC_ALPHA_INTERPOLATED: f->store_32(IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED); break; |  | ||||||
| 					case Image::FORMAT_CUSTOM: f->store_32(IMAGE_FORMAT_CUSTOM ); break; |  | ||||||
| 					default: {} |  | ||||||
| 
 |  | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
| 				int dlen = val.get_data().size(); | 				int dlen = val.get_data().size(); | ||||||
| 				f->store_32(dlen); | 				f->store_32(dlen); | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| /*                           GODOT ENGINE                                */ | /*                           GODOT ENGINE                                */ | ||||||
| /*                    http://www.godotengine.org                         */ | /*                    http://www.godotengine.org                         */ | ||||||
| /*************************************************************************/ | /*************************************************************************/ | ||||||
| /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */ | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | ||||||
| /*                                                                       */ | /*                                                                       */ | ||||||
| /* Permission is hereby granted, free of charge, to any person obtaining */ | /* Permission is hereby granted, free of charge, to any person obtaining */ | ||||||
| /* a copy of this software and associated documentation files (the       */ | /* a copy of this software and associated documentation files (the       */ | ||||||
|  | @ -553,39 +553,39 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) | ||||||
| 
 | 
 | ||||||
| 			Image::Format imgformat; | 			Image::Format imgformat; | ||||||
| 
 | 
 | ||||||
| 
 | /*
 | ||||||
| 			if (format=="grayscale") { | 			if (format=="grayscale") { | ||||||
| 				imgformat=Image::FORMAT_GRAYSCALE; | 				imgformat=Image::FORMAT_L8; | ||||||
| 			} else if (format=="intensity") { | 			} else if (format=="intensity") { | ||||||
| 				imgformat=Image::FORMAT_INTENSITY; | 				imgformat=Image::FORMAT_INTENSITY; | ||||||
| 			} else if (format=="grayscale_alpha") { | 			} else if (format=="grayscale_alpha") { | ||||||
| 				imgformat=Image::FORMAT_GRAYSCALE_ALPHA; | 				imgformat=Image::FORMAT_LA8; | ||||||
| 			} else if (format=="rgb") { | 			} else if (format=="rgb") { | ||||||
| 				imgformat=Image::FORMAT_RGB; | 				imgformat=Image::FORMAT_RGB8; | ||||||
| 			} else if (format=="rgba") { | 			} else if (format=="rgba") { | ||||||
| 				imgformat=Image::FORMAT_RGBA; | 				imgformat=Image::FORMAT_RGBA8; | ||||||
| 			} else if (format=="indexed") { | 			} else if (format=="indexed") { | ||||||
| 				imgformat=Image::FORMAT_INDEXED; | 				imgformat=Image::FORMAT_INDEXED; | ||||||
| 			} else if (format=="indexed_alpha") { | 			} else if (format=="indexed_alpha") { | ||||||
| 				imgformat=Image::FORMAT_INDEXED_ALPHA; | 				imgformat=Image::FORMAT_INDEXED_ALPHA; | ||||||
| 			} else if (format=="bc1") { | 			} else if (format=="bc1") { | ||||||
| 				imgformat=Image::FORMAT_BC1; | 				imgformat=Image::FORMAT_DXT1; | ||||||
| 			} else if (format=="bc2") { | 			} else if (format=="bc2") { | ||||||
| 				imgformat=Image::FORMAT_BC2; | 				imgformat=Image::FORMAT_DXT3; | ||||||
| 			} else if (format=="bc3") { | 			} else if (format=="bc3") { | ||||||
| 				imgformat=Image::FORMAT_BC3; | 				imgformat=Image::FORMAT_DXT5; | ||||||
| 			} else if (format=="bc4") { | 			} else if (format=="bc4") { | ||||||
| 				imgformat=Image::FORMAT_BC4; | 				imgformat=Image::FORMAT_ATI1; | ||||||
| 			} else if (format=="bc5") { | 			} else if (format=="bc5") { | ||||||
| 				imgformat=Image::FORMAT_BC5; | 				imgformat=Image::FORMAT_ATI2; | ||||||
| 			} else if (format=="pvrtc2") { | 			} else if (format=="pvrtc2") { | ||||||
| 				imgformat=Image::FORMAT_PVRTC2; | 				imgformat=Image::FORMAT_PVRTC2; | ||||||
| 			} else if (format=="pvrtc2a") { | 			} else if (format=="pvrtc2a") { | ||||||
| 				imgformat=Image::FORMAT_PVRTC2_ALPHA; | 				imgformat=Image::FORMAT_PVRTC2A; | ||||||
| 			} else if (format=="pvrtc4") { | 			} else if (format=="pvrtc4") { | ||||||
| 				imgformat=Image::FORMAT_PVRTC4; | 				imgformat=Image::FORMAT_PVRTC4; | ||||||
| 			} else if (format=="pvrtc4a") { | 			} else if (format=="pvrtc4a") { | ||||||
| 				imgformat=Image::FORMAT_PVRTC4_ALPHA; | 				imgformat=Image::FORMAT_PVRTC4A; | ||||||
| 			} else if (format=="etc") { | 			} else if (format=="etc") { | ||||||
| 				imgformat=Image::FORMAT_ETC; | 				imgformat=Image::FORMAT_ETC; | ||||||
| 			} else if (format=="atc") { | 			} else if (format=="atc") { | ||||||
|  | @ -599,7 +599,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) | ||||||
| 			} else { | 			} else { | ||||||
| 
 | 
 | ||||||
| 				ERR_FAIL_V( ERR_FILE_CORRUPT ); | 				ERR_FAIL_V( ERR_FILE_CORRUPT ); | ||||||
| 			} | 			}*/ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 			int datasize; | 			int datasize; | ||||||
|  | @ -614,13 +614,6 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) | ||||||
| 				return OK; | 				return OK; | ||||||
| 			}; | 			}; | ||||||
| 
 | 
 | ||||||
| 			if (imgformat==Image::FORMAT_CUSTOM) { |  | ||||||
| 
 |  | ||||||
| 				datasize=custom_size; |  | ||||||
| 			} else { |  | ||||||
| 
 |  | ||||||
| 				datasize = Image::get_image_data_size(h,w,imgformat,mipmaps); |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			if (datasize==0) { | 			if (datasize==0) { | ||||||
| 				//r_v = Image(w, h, imgformat);
 | 				//r_v = Image(w, h, imgformat);
 | ||||||
|  | @ -2186,33 +2179,33 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V | ||||||
| 			params+="encoding=\"raw\""; | 			params+="encoding=\"raw\""; | ||||||
| 			params+=" width=\""+itos(img.get_width())+"\""; | 			params+=" width=\""+itos(img.get_width())+"\""; | ||||||
| 			params+=" height=\""+itos(img.get_height())+"\""; | 			params+=" height=\""+itos(img.get_height())+"\""; | ||||||
| 			params+=" mipmaps=\""+itos(img.get_mipmaps())+"\""; | 			params+=" mipmaps=\""+itos(img.has_mipmaps())+"\""; | ||||||
| 
 | /*
 | ||||||
| 			switch(img.get_format()) { | 			switch(img.get_format()) { | ||||||
| 
 | 
 | ||||||
| 				case Image::FORMAT_GRAYSCALE: params+=" format=\"grayscale\""; break; | 				case Image::FORMAT_L8: params+=" format=\"grayscale\""; break; | ||||||
| 				case Image::FORMAT_INTENSITY: params+=" format=\"intensity\""; break; | 				case Image::FORMAT_INTENSITY: params+=" format=\"intensity\""; break; | ||||||
| 				case Image::FORMAT_GRAYSCALE_ALPHA: params+=" format=\"grayscale_alpha\""; break; | 				case Image::FORMAT_LA8: params+=" format=\"grayscale_alpha\""; break; | ||||||
| 				case Image::FORMAT_RGB: params+=" format=\"rgb\""; break; | 				case Image::FORMAT_RGB8: params+=" format=\"rgb\""; break; | ||||||
| 				case Image::FORMAT_RGBA: params+=" format=\"rgba\""; break; | 				case Image::FORMAT_RGBA8: params+=" format=\"rgba\""; break; | ||||||
| 				case Image::FORMAT_INDEXED : params+=" format=\"indexed\""; break; | 				case Image::FORMAT_INDEXED : params+=" format=\"indexed\""; break; | ||||||
| 				case Image::FORMAT_INDEXED_ALPHA: params+=" format=\"indexed_alpha\""; break; | 				case Image::FORMAT_INDEXED_ALPHA: params+=" format=\"indexed_alpha\""; break; | ||||||
| 				case Image::FORMAT_BC1: params+=" format=\"bc1\""; break; | 				case Image::FORMAT_DXT1: params+=" format=\"bc1\""; break; | ||||||
| 				case Image::FORMAT_BC2: params+=" format=\"bc2\""; break; | 				case Image::FORMAT_DXT3: params+=" format=\"bc2\""; break; | ||||||
| 				case Image::FORMAT_BC3: params+=" format=\"bc3\""; break; | 				case Image::FORMAT_DXT5: params+=" format=\"bc3\""; break; | ||||||
| 				case Image::FORMAT_BC4: params+=" format=\"bc4\""; break; | 				case Image::FORMAT_ATI1: params+=" format=\"bc4\""; break; | ||||||
| 				case Image::FORMAT_BC5: params+=" format=\"bc5\""; break; | 				case Image::FORMAT_ATI2: params+=" format=\"bc5\""; break; | ||||||
| 				case Image::FORMAT_PVRTC2: params+=" format=\"pvrtc2\""; break; | 				case Image::FORMAT_PVRTC2: params+=" format=\"pvrtc2\""; break; | ||||||
| 				case Image::FORMAT_PVRTC2_ALPHA: params+=" format=\"pvrtc2a\""; break; | 				case Image::FORMAT_PVRTC2A: params+=" format=\"pvrtc2a\""; break; | ||||||
| 				case Image::FORMAT_PVRTC4: params+=" format=\"pvrtc4\""; break; | 				case Image::FORMAT_PVRTC4: params+=" format=\"pvrtc4\""; break; | ||||||
| 				case Image::FORMAT_PVRTC4_ALPHA: params+=" format=\"pvrtc4a\""; break; | 				case Image::FORMAT_PVRTC4A: params+=" format=\"pvrtc4a\""; break; | ||||||
| 				case Image::FORMAT_ETC: params+=" format=\"etc\""; break; | 				case Image::FORMAT_ETC: params+=" format=\"etc\""; break; | ||||||
| 				case Image::FORMAT_ATC: params+=" format=\"atc\""; break; | 				case Image::FORMAT_ATC: params+=" format=\"atc\""; break; | ||||||
| 				case Image::FORMAT_ATC_ALPHA_EXPLICIT: params+=" format=\"atcae\""; break; | 				case Image::FORMAT_ATC_ALPHA_EXPLICIT: params+=" format=\"atcae\""; break; | ||||||
| 				case Image::FORMAT_ATC_ALPHA_INTERPOLATED: params+=" format=\"atcai\""; break; | 				case Image::FORMAT_ATC_ALPHA_INTERPOLATED: params+=" format=\"atcai\""; break; | ||||||
| 				case Image::FORMAT_CUSTOM: params+=" format=\"custom\" custom_size=\""+itos(img.get_data().size())+"\""; break; | 				case Image::FORMAT_CUSTOM: params+=" format=\"custom\" custom_size=\""+itos(img.get_data().size())+"\""; break; | ||||||
| 				default: {} | 				default: {} | ||||||
| 			} | 			}*/ | ||||||
| 		} break; | 		} break; | ||||||
| 		case Variant::NODE_PATH:		type="node_path"; break; | 		case Variant::NODE_PATH:		type="node_path"; break; | ||||||
| 		case Variant::OBJECT:	{ | 		case Variant::OBJECT:	{ | ||||||
|  |  | ||||||
Some files were not shown because too many files have changed in this diff Show more
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Juan Linietsky
						Juan Linietsky