This commit is contained in:
Juan Linietsky 2017-01-02 19:12:25 -03:00
commit ce26eb74bc
1978 changed files with 188590 additions and 31400 deletions

1
.gitignore vendored
View file

@ -8,6 +8,7 @@ platform/osx/logo.h
platform/windows/logo.h
platform/x11/logo.h
drivers/gles2/shaders/*.h
drivers/gles3/shaders/*.h
modules/register_module_types.cpp
core/version.h
core/method_bind.inc

View file

@ -14,7 +14,7 @@ env:
- GODOT_TARGET=iphone
- GODOT_TARGET=osx
- GODOT_TARGET=x11
- GODOT_TARGET=android
#- GODOT_TARGET=android
- GODOT_TARGET=windows
matrix:
@ -69,8 +69,8 @@ addons:
before_script:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; brew install scons; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$GODOT_TARGET" = "android" ]; then
brew update; travis_wait 20 brew install -v android-sdk;
travis_wait 20 brew install -v android-ndk | grep -v "inflating:" | grep -v "creating:";
brew update; brew install -v android-sdk;
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;
fi

View file

@ -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
#### 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!
The Godot development team

View file

@ -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
a copy of this software and associated documentation files (the

View file

@ -1,30 +1,66 @@
![GODOT](/logo.png)
[![GODOT](/logo.png)](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.
The editor, language and APIs are feature rich, yet simple to learn, allowing you to become productive in a matter of hours.
#### 2D and 3D cross-platform game engine
### 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:
http://docs.godotengine.org/en/latest/reference/_compiling.html
[See the official docs](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.
[![Build Status](https://travis-ci.org/godotengine/godot.svg?branch=master)](https://travis-ci.org/godotengine/godot)
[![Code Triagers Badge](http://www.codetriage.com/godotengine/godot/badges/users.svg)](http://www.codetriage.com/godotengine/godot)

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
EnsureSConsVersion(0,14);
EnsureSConsVersion(0, 14)
import string
@ -14,85 +14,84 @@ methods.update_version()
# scan possible build platforms
platform_list = [] # list of platforms
platform_opts = {} # options for each platform
platform_flags = {} # flags for each platform
platform_list = [] # list of platforms
platform_opts = {} # options for each platform
platform_flags = {} # flags for each platform
active_platforms=[]
active_platform_ids=[]
platform_exporters=[]
global_defaults=[]
active_platforms = []
active_platform_ids = []
platform_exporters = []
global_defaults = []
for x in glob.glob("platform/*"):
if (not os.path.isdir(x) or not os.path.exists(x+"/detect.py")):
continue
tmppath="./"+x
if (not os.path.isdir(x) or not os.path.exists(x + "/detect.py")):
continue
tmppath = "./" + x
sys.path.append(tmppath)
import detect
sys.path.append(tmppath)
import detect
if (os.path.exists(x+"/export/export.cpp")):
platform_exporters.append(x[9:])
if (os.path.exists(x+"/globals/global_defaults.cpp")):
global_defaults.append(x[9:])
if (detect.is_active()):
active_platforms.append( detect.get_name() )
active_platform_ids.append(x);
if (detect.can_build()):
x=x.replace("platform/","") # rest of world
x=x.replace("platform\\","") # win32
platform_list+=[x]
platform_opts[x]=detect.get_opts()
platform_flags[x]=detect.get_flags()
sys.path.remove(tmppath)
sys.modules.pop('detect')
if (os.path.exists(x + "/export/export.cpp")):
platform_exporters.append(x[9:])
if (os.path.exists(x + "/globals/global_defaults.cpp")):
global_defaults.append(x[9:])
if (detect.is_active()):
active_platforms.append(detect.get_name())
active_platform_ids.append(x)
if (detect.can_build()):
x = x.replace("platform/", "") # rest of world
x = x.replace("platform\\", "") # win32
platform_list += [x]
platform_opts[x] = detect.get_opts()
platform_flags[x] = detect.get_flags()
sys.path.remove(tmppath)
sys.modules.pop('detect')
module_list=methods.detect_modules()
module_list = methods.detect_modules()
#print "Detected Platforms: "+str(platform_list)
# print "Detected Platforms: "+str(platform_list)
methods.save_active_platforms(active_platforms,active_platform_ids)
methods.save_active_platforms(active_platforms, active_platform_ids)
custom_tools=['default']
custom_tools = ['default']
platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))
if (os.name=="posix"):
pass
elif (os.name=="nt"):
if ( os.getenv("VCINSTALLDIR")==None or platform_arg=="android"):
custom_tools=['mingw']
if (os.name == "posix"):
pass
elif (os.name == "nt"):
if (os.getenv("VCINSTALLDIR") == None or platform_arg == "android"):
custom_tools = ['mingw']
env_base=Environment(tools=custom_tools);
env_base = Environment(tools=custom_tools)
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('PKG_CONFIG_PATH', os.getenv('PKG_CONFIG_PATH'))
env_base.global_defaults=global_defaults
env_base.android_maven_repos=[]
env_base.android_dependencies=[]
env_base.android_java_dirs=[]
env_base.android_res_dirs=[]
env_base.android_aidl_dirs=[]
env_base.android_jni_dirs=[]
env_base.android_default_config=[]
env_base.android_manifest_chunk=""
env_base.android_permission_chunk=""
env_base.android_appattributes_chunk=""
env_base.disabled_modules=[]
env_base.use_ptrcall=False
env_base.split_drivers=False
env_base.global_defaults = global_defaults
env_base.android_maven_repos = []
env_base.android_dependencies = []
env_base.android_java_dirs = []
env_base.android_res_dirs = []
env_base.android_aidl_dirs = []
env_base.android_jni_dirs = []
env_base.android_default_config = []
env_base.android_manifest_chunk = ""
env_base.android_permission_chunk = ""
env_base.android_appattributes_chunk = ""
env_base.disabled_modules = []
env_base.use_ptrcall = False
env_base.split_drivers = False
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_java_dir=methods.android_add_java_dir
env_base.__class__.android_add_res_dir=methods.android_add_res_dir
env_base.__class__.android_add_aidl_dir=methods.android_add_aidl_dir
env_base.__class__.android_add_jni_dir=methods.android_add_jni_dir
env_base.__class__.android_add_default_config=methods.android_add_default_config
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_java_dir = methods.android_add_java_dir
env_base.__class__.android_add_res_dir = methods.android_add_res_dir
env_base.__class__.android_add_aidl_dir = methods.android_add_aidl_dir
env_base.__class__.android_add_jni_dir = methods.android_add_jni_dir
env_base.__class__.android_add_default_config = methods.android_add_default_config
env_base.__class__.android_add_to_manifest = methods.android_add_to_manifest
env_base.__class__.android_add_to_permissions = methods.android_add_to_permissions
env_base.__class__.android_add_to_attributes = methods.android_add_to_attributes
@ -100,75 +99,91 @@ env_base.__class__.disable_module = methods.disable_module
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__.split_lib = methods.split_lib
env_base["x86_libtheora_opt_gcc"]=False
env_base["x86_libtheora_opt_vc"]=False
env_base["x86_libtheora_opt_gcc"] = False
env_base["x86_libtheora_opt_vc"] = False
# Build options
customs = ['custom.py']
profile = ARGUMENTS.get("profile", False)
if profile:
import os.path
if os.path.isfile(profile):
customs.append(profile)
elif os.path.isfile(profile+".py"):
customs.append(profile+".py")
import os.path
if os.path.isfile(profile):
customs.append(profile)
elif os.path.isfile(profile + ".py"):
customs.append(profile + ".py")
opts = Variables(customs, ARGUMENTS)
# Target build options
opts.Add('arch', "Platform-dependent architecture (arm/arm64/x86/x64/mips/etc)", '')
opts.Add('bits', "Target platform bits (default/32/64/fat)", 'default')
opts.Add('p', "Platform (alias for 'platform')", '')
opts.Add('platform', "Target platform: any in " + str(platform_list), '')
opts.Add('target', "Compilation target (debug/release_debug/release)", 'debug')
opts.Add('tools', "Build the tools a.k.a. the Godot editor (yes/no)", 'yes')
# Components
opts.Add('deprecated', "Enable deprecated features (yes/no)", 'yes')
opts.Add('gdscript', "Build GDSCript support (yes/no)", 'yes')
opts.Add('minizip', "Build minizip archive support (yes/no)", 'yes')
opts.Add('xaudio2', "XAudio2 audio driver (yes/no)", 'no')
opts.Add('xml', "XML format support for resources (yes/no)", 'yes')
# Advanced options
opts.Add('disable_3d', "Disable 3D nodes for smaller executable (yes/no)", 'no')
opts.Add('disable_advanced_gui', "Disable advance 3D gui nodes and behaviors (yes/no)", 'no')
opts.Add('extra_suffix', "Custom extra suffix added to the base filename of all generated binary files", '')
opts.Add('unix_global_settings_path', "UNIX-specific path to system-wide settings. Currently only used for templates", '')
opts.Add('verbose', "Enable verbose output for the compilation (yes/no)", 'yes')
opts.Add('vsproj', "Generate Visual Studio Project. (yes/no)", 'no')
# Thirdparty libraries
opts.Add('builtin_enet', "Use the builtin enet library (yes/no)", 'yes')
opts.Add('builtin_freetype', "Use the builtin freetype library (yes/no)", 'yes')
opts.Add('builtin_glew', "Use the builtin glew library (yes/no)", 'yes')
opts.Add('builtin_libmpcdec', "Use the builtin libmpcdec library (yes/no)", 'yes')
opts.Add('builtin_libogg', "Use the builtin libogg library (yes/no)", 'yes')
opts.Add('builtin_libpng', "Use the builtin libpng library (yes/no)", 'yes')
opts.Add('builtin_libtheora', "Use the builtin libtheora library (yes/no)", 'yes')
opts.Add('builtin_libvorbis', "Use the builtin libvorbis library (yes/no)", 'yes')
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")
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)', "")
opts.Add('bits', 'Compile Target Bits (default/32/64/fat).', "default")
opts.Add('platform','Platform: '+str(platform_list)+'.',"")
opts.Add('p','Platform (same as platform=).',"")
opts.Add('tools','Build Tools (Including Editor): (yes/no)','yes')
opts.Add('gdscript','Build GDSCript support: (yes/no)','yes')
opts.Add('libogg','Ogg library for ogg container support (system/builtin)','builtin')
opts.Add('libvorbis','Ogg Vorbis library for vorbis support (system/builtin)','builtin')
opts.Add('libtheora','Theora library for theora module (system/builtin)','builtin')
opts.Add('opus','Opus and opusfile library for Opus format support: (system/builtin)','builtin')
opts.Add('minizip','Build Minizip Archive Support: (yes/no)','yes')
opts.Add('squish','Squish library for BC Texture Compression in editor (system/builtin)','builtin')
opts.Add('freetype','Freetype library for TTF support via freetype module (system/builtin)','builtin')
opts.Add('xml','XML Save/Load support (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')
opts.Add('openssl','OpenSSL library for openssl module (system/builtin)','builtin')
opts.Add('libmpcdec','libmpcdec library for mpc module (system/builtin)','builtin')
opts.Add('enet','ENet library (system/builtin)','builtin')
opts.Add('glew','GLEW library for the gl_context (system/builtin)','builtin')
opts.Add('xaudio2','XAudio2 audio driver (yes/no)','no')
opts.Add("CXX", "C++ Compiler")
opts.Add("CC", "C Compiler")
opts.Add("CCFLAGS", "Custom flags for the C/C++ compiler");
opts.Add("CFLAGS", "Custom flags for the C compiler");
opts.Add("LINKFLAGS", "Custom flags for the linker");
opts.Add('unix_global_settings_path', 'unix-specific path to system-wide settings. Currently only used by templates.','')
opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no")
opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no")
opts.Add('verbose', 'Enable verbose output for the compilation (yes/no)', 'yes')
opts.Add('deprecated','Enable deprecated features (yes/no)','yes')
opts.Add('extra_suffix', 'Custom extra suffix added to the base filename of all generated binary files.', '')
opts.Add('vsproj', 'Generate Visual Studio Project. (yes/no)', 'no')
# add platform specific options
for k in platform_opts.keys():
opt_list = platform_opts[k]
for o in opt_list:
opts.Add(o[0],o[1],o[2])
opt_list = platform_opts[k]
for o in opt_list:
opts.Add(o[0], o[1], o[2])
for x in module_list:
opts.Add('module_'+x+'_enabled', "Enable module '"+x+"' (yes/no)", "yes")
opts.Add('module_' + x + '_enabled', "Enable module '" + x + "' (yes/no)", "yes")
opts.Update(env_base) # update environment
Help(opts.GenerateHelpText(env_base)) # generate help
opts.Update(env_base) # update environment
Help(opts.GenerateHelpText(env_base)) # generate help
# add default include paths
env_base.Append(CPPPATH=['#core','#core/math','#tools','#drivers','#'])
env_base.Append(CPPPATH=['#core', '#core/math', '#tools', '#drivers', '#'])
# configure ENV for platform
env_base.platform_exporters=platform_exporters
env_base.platform_exporters = platform_exporters
"""
sys.path.append("./platform/"+env_base["platform"])
@ -178,227 +193,226 @@ sys.path.remove("./platform/"+env_base["platform"])
sys.modules.pop('detect')
"""
if (env_base['target']=='debug'):
env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']);
env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE'])
if (env_base['target'] == 'debug'):
env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC'])
env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE'])
if (env_base['deprecated']!='no'):
env_base.Append(CPPFLAGS=['-DENABLE_DEPRECATED']);
if (env_base['deprecated'] != 'no'):
env_base.Append(CPPFLAGS=['-DENABLE_DEPRECATED'])
env_base.platforms = {}
selected_platform =""
selected_platform = ""
if env_base['platform'] != "":
selected_platform=env_base['platform']
selected_platform = env_base['platform']
elif env_base['p'] != "":
selected_platform=env_base['p']
env_base["platform"]=selected_platform
selected_platform = env_base['p']
env_base["platform"] = selected_platform
if selected_platform in platform_list:
sys.path.append("./platform/"+selected_platform)
import detect
if "create" in dir(detect):
env = detect.create(env_base)
else:
env = env_base.Clone()
sys.path.append("./platform/" + selected_platform)
import detect
if "create" in dir(detect):
env = detect.create(env_base)
else:
env = env_base.Clone()
if env['vsproj']=="yes":
env.vs_incs = []
env.vs_srcs = []
if env['vsproj'] == "yes":
env.vs_incs = []
env.vs_srcs = []
def AddToVSProject( sources ):
for x in sources:
if type(x) == type(""):
fname = env.File(x).path
else:
fname = env.File(x)[0].path
pieces = fname.split(".")
if len(pieces)>0:
basename = pieces[0]
basename = basename.replace('\\\\','/')
env.vs_srcs = env.vs_srcs + [basename + ".cpp"]
env.vs_incs = env.vs_incs + [basename + ".h"]
#print basename
env.AddToVSProject = AddToVSProject
def AddToVSProject(sources):
for x in sources:
if type(x) == type(""):
fname = env.File(x).path
else:
fname = env.File(x)[0].path
pieces = fname.split(".")
if len(pieces) > 0:
basename = pieces[0]
basename = basename.replace('\\\\', '/')
env.vs_srcs = env.vs_srcs + [basename + ".cpp"]
env.vs_incs = env.vs_incs + [basename + ".h"]
# print basename
env.AddToVSProject = AddToVSProject
env.extra_suffix=""
env.extra_suffix = ""
if env["extra_suffix"] != '' :
env.extra_suffix += '.'+env["extra_suffix"]
if env["extra_suffix"] != '':
env.extra_suffix += '.' + env["extra_suffix"]
CCFLAGS = env.get('CCFLAGS', '')
env['CCFLAGS'] = ''
CCFLAGS = env.get('CCFLAGS', '')
env['CCFLAGS'] = ''
env.Append(CCFLAGS=string.split(str(CCFLAGS)))
env.Append(CCFLAGS=string.split(str(CCFLAGS)))
CFLAGS = env.get('CFLAGS', '')
env['CFLAGS'] = ''
CFLAGS = env.get('CFLAGS', '')
env['CFLAGS'] = ''
env.Append(CFLAGS=string.split(str(CFLAGS)))
env.Append(CFLAGS=string.split(str(CFLAGS)))
LINKFLAGS = env.get('LINKFLAGS', '')
env['LINKFLAGS'] = ''
LINKFLAGS = env.get('LINKFLAGS', '')
env['LINKFLAGS'] = ''
env.Append(LINKFLAGS=string.split(str(LINKFLAGS)))
env.Append(LINKFLAGS=string.split(str(LINKFLAGS)))
flag_list = platform_flags[selected_platform]
for f in flag_list:
if not (f[0] in ARGUMENTS): # allow command line to override platform flags
env[f[0]] = f[1]
flag_list = platform_flags[selected_platform]
for f in flag_list:
if not (f[0] in ARGUMENTS): # allow command line to override platform flags
env[f[0]] = f[1]
#must happen after the flags, so when flags are used by configure, stuff happens (ie, ssl on x11)
detect.configure(env)
# must happen after the flags, so when flags are used by configure, stuff happens (ie, ssl on x11)
detect.configure(env)
#env['platform_libsuffix'] = env['LIBSUFFIX']
#env['platform_libsuffix'] = env['LIBSUFFIX']
suffix="."+selected_platform
suffix = "." + selected_platform
if (env["target"]=="release"):
if (env["tools"]=="yes"):
print("Tools can only be built with targets 'debug' and 'release_debug'.")
sys.exit(255)
suffix+=".opt"
if (env["target"] == "release"):
if (env["tools"] == "yes"):
print("Tools can only be built with targets 'debug' and 'release_debug'.")
sys.exit(255)
suffix += ".opt"
env.Append(CCFLAGS=['-DNDEBUG']);
env.Append(CCFLAGS=['-DNDEBUG'])
elif (env["target"]=="release_debug"):
if (env["tools"]=="yes"):
suffix+=".opt.tools"
else:
suffix+=".opt.debug"
else:
if (env["tools"]=="yes"):
suffix+=".tools"
else:
suffix+=".debug"
elif (env["target"] == "release_debug"):
if (env["tools"] == "yes"):
suffix += ".opt.tools"
else:
suffix += ".opt.debug"
else:
if (env["tools"] == "yes"):
suffix += ".tools"
else:
suffix += ".debug"
if env["arch"] != "":
suffix += "."+env["arch"]
elif (env["bits"]=="32"):
suffix+=".32"
elif (env["bits"]=="64"):
suffix+=".64"
elif (env["bits"]=="fat"):
suffix+=".fat"
if env["arch"] != "":
suffix += "." + env["arch"]
elif (env["bits"] == "32"):
suffix += ".32"
elif (env["bits"] == "64"):
suffix += ".64"
elif (env["bits"] == "fat"):
suffix += ".fat"
suffix+=env.extra_suffix
suffix += env.extra_suffix
env["PROGSUFFIX"]=suffix+env["PROGSUFFIX"]
env["OBJSUFFIX"]=suffix+env["OBJSUFFIX"]
env["LIBSUFFIX"]=suffix+env["LIBSUFFIX"]
env["SHLIBSUFFIX"]=suffix+env["SHLIBSUFFIX"]
env["PROGSUFFIX"] = suffix + env["PROGSUFFIX"]
env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]
env["LIBSUFFIX"] = suffix + env["LIBSUFFIX"]
env["SHLIBSUFFIX"] = suffix + env["SHLIBSUFFIX"]
sys.path.remove("./platform/"+selected_platform)
sys.modules.pop('detect')
sys.path.remove("./platform/" + selected_platform)
sys.modules.pop('detect')
env.module_list = []
env.module_list=[]
for x in module_list:
if env['module_' + x + '_enabled'] != "yes":
continue
tmppath = "./modules/" + x
sys.path.append(tmppath)
env.current_module = x
import config
if (config.can_build(selected_platform)):
config.configure(env)
env.module_list.append(x)
sys.path.remove(tmppath)
sys.modules.pop('config')
for x in module_list:
if env['module_'+x+'_enabled'] != "yes":
continue
tmppath="./modules/"+x
sys.path.append(tmppath)
env.current_module=x
import config
if (config.can_build(selected_platform)):
config.configure(env)
env.module_list.append(x)
sys.path.remove(tmppath)
sys.modules.pop('config')
if (env.use_ptrcall):
env.Append(CPPFLAGS=['-DPTRCALL_ENABLED'])
# to test 64 bits compiltion
# env.Append(CPPFLAGS=['-m64'])
if (env.use_ptrcall):
env.Append(CPPFLAGS=['-DPTRCALL_ENABLED']);
if (env['tools'] == 'yes'):
env.Append(CPPFLAGS=['-DTOOLS_ENABLED'])
if (env['disable_3d'] == 'yes'):
env.Append(CPPFLAGS=['-D_3D_DISABLED'])
if (env['gdscript'] == 'yes'):
env.Append(CPPFLAGS=['-DGDSCRIPT_ENABLED'])
if (env['disable_advanced_gui'] == 'yes'):
env.Append(CPPFLAGS=['-DADVANCED_GUI_DISABLED'])
# to test 64 bits compiltion
# env.Append(CPPFLAGS=['-m64'])
if (env['minizip'] == 'yes'):
env.Append(CPPFLAGS=['-DMINIZIP_ENABLED'])
if (env['tools']=='yes'):
env.Append(CPPFLAGS=['-DTOOLS_ENABLED'])
if (env['disable_3d']=='yes'):
env.Append(CPPFLAGS=['-D_3D_DISABLED'])
if (env['gdscript']=='yes'):
env.Append(CPPFLAGS=['-DGDSCRIPT_ENABLED'])
if (env['disable_advanced_gui']=='yes'):
env.Append(CPPFLAGS=['-DADVANCED_GUI_DISABLED'])
if (env['xml'] == 'yes'):
env.Append(CPPFLAGS=['-DXML_ENABLED'])
if (env['minizip'] == 'yes'):
env.Append(CPPFLAGS=['-DMINIZIP_ENABLED'])
if (env['verbose'] == 'no'):
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') } )
if (env['xml']=='yes'):
env.Append(CPPFLAGS=['-DXML_ENABLED'])
Export('env')
if (env['verbose']=='no'):
methods.no_verbose(sys,env)
# build subdirs, the build order is dependent on link order.
Export('env')
SConscript("core/SCsub")
SConscript("servers/SCsub")
SConscript("scene/SCsub")
SConscript("tools/SCsub")
SConscript("drivers/SCsub")
SConscript("bin/SCsub")
#build subdirs, the build order is dependent on link order.
SConscript("modules/SCsub")
SConscript("main/SCsub")
SConscript("core/SCsub")
SConscript("servers/SCsub")
SConscript("scene/SCsub")
SConscript("tools/SCsub")
SConscript("drivers/SCsub")
SConscript("bin/SCsub")
SConscript("platform/" + selected_platform + "/SCsub") # build selected platform
SConscript("modules/SCsub")
SConscript("main/SCsub")
# Microsoft Visual Studio Project Generation
if (env['vsproj']) == "yes":
SConscript("platform/"+selected_platform+"/SCsub"); # build selected platform
AddToVSProject(env.core_sources)
AddToVSProject(env.main_sources)
AddToVSProject(env.modules_sources)
AddToVSProject(env.scene_sources)
AddToVSProject(env.servers_sources)
AddToVSProject(env.tool_sources)
# Microsoft Visual Studio Project Generation
if (env['vsproj'])=="yes":
# this env flag won't work, it needs to be set in env_base=Environment(MSVC_VERSION='9.0')
# Even then, SCons still seems to ignore it and builds with the latest MSVC...
# That said, it's not needed to be set so far but I'm leaving it here so that this comment
# has a purpose.
# env['MSVS_VERSION']='9.0'
AddToVSProject(env.core_sources)
AddToVSProject(env.main_sources)
AddToVSProject(env.modules_sources)
AddToVSProject(env.scene_sources)
AddToVSProject(env.servers_sources)
AddToVSProject(env.tool_sources)
# 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
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['MSVSREBUILDCOM'] = '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! vsproj=yes -j2'
env['MSVSCLEANCOM'] = '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 --clean platform=windows target=$(Configuration) tools=!tools! -j2'
# this env flag won't work, it needs to be set in env_base=Environment(MSVC_VERSION='9.0')
# Even then, SCons still seems to ignore it and builds with the latest MSVC...
# That said, it's not needed to be set so far but I'm leaving it here so that this comment
# has a purpose.
#env['MSVS_VERSION']='9.0'
# 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
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['MSVSREBUILDCOM'] = '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! vsproj=yes -j2'
env['MSVSCLEANCOM'] = '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 --clean platform=windows target=$(Configuration) tools=!tools! -j2'
# This version information (Win32, x64, Debug, Release, Release_Debug seems to be
# required for Visual Studio to understand that it needs to generate an NMAKE
# project. Do not modify without knowing what you are doing.
debug_variants = ['debug|Win32']+['debug|x64']
release_variants = ['release|Win32']+['release|x64']
release_debug_variants = ['release_debug|Win32']+['release_debug|x64']
variants = debug_variants + release_variants + release_debug_variants
debug_targets = ['bin\\godot.windows.tools.32.exe']+['bin\\godot.windows.tools.64.exe']
release_targets = ['bin\\godot.windows.opt.32.exe']+['bin\\godot.windows.opt.64.exe']
release_debug_targets = ['bin\\godot.windows.opt.tools.32.exe']+['bin\\godot.windows.opt.tools.64.exe']
targets = debug_targets + release_targets + release_debug_targets
msvproj = env.MSVSProject(target = ['#godot' + env['MSVSPROJECTSUFFIX'] ],
incs = env.vs_incs,
srcs = env.vs_srcs,
runfile = targets,
buildtarget = targets,
auto_build_solution=1,
variant = variants)
# This version information (Win32, x64, Debug, Release, Release_Debug seems to be
# required for Visual Studio to understand that it needs to generate an NMAKE
# project. Do not modify without knowing what you are doing.
debug_variants = ['debug|Win32'] + ['debug|x64']
release_variants = ['release|Win32'] + ['release|x64']
release_debug_variants = ['release_debug|Win32'] + ['release_debug|x64']
variants = debug_variants + release_variants + release_debug_variants
debug_targets = ['bin\\godot.windows.tools.32.exe'] + ['bin\\godot.windows.tools.64.exe']
release_targets = ['bin\\godot.windows.opt.32.exe'] + ['bin\\godot.windows.opt.64.exe']
release_debug_targets = ['bin\\godot.windows.opt.tools.32.exe'] + ['bin\\godot.windows.opt.tools.64.exe']
targets = debug_targets + release_targets + release_debug_targets
msvproj = env.MSVSProject(target=['#godot' + env['MSVSPROJECTSUFFIX']],
incs=env.vs_incs,
srcs=env.vs_srcs,
runfile=targets,
buildtarget=targets,
auto_build_solution=1,
variant=variants)
else:
print("No valid target platform selected.")
print("The following were detected:")
for x in platform_list:
print("\t"+x)
print("\nPlease run scons again with argument: platform=<string>")
print("No valid target platform selected.")
print("The following were detected:")
for x in platform_list:
print("\t" + x)
print("\nPlease run scons again with argument: platform=<string>")

View file

@ -3,4 +3,4 @@
Import('env')
Export('env')
SConscript('tests/SCsub');
SConscript('tests/SCsub')

View file

@ -2,13 +2,13 @@
Import('env')
env.tests_sources=[]
env.add_source_files(env.tests_sources,"*.cpp")
env.tests_sources = []
env.add_source_files(env.tests_sources, "*.cpp")
Export('env')
#SConscript('math/SCsub');
# SConscript('math/SCsub');
lib = env.Library("tests",env.tests_sources)
lib = env.Library("tests", env.tests_sources)
env.Prepend(LIBS=[lib])

View file

@ -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);
}
}

View file

@ -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

View file

@ -370,7 +370,7 @@ public:
tabc->set_size( Point2( 180,250 ) );
Ref<ImageTexture> text = memnew( ImageTexture );
/*Ref<ImageTexture> text = memnew( ImageTexture );
text->load("test_data/concave.png");
Sprite* sprite = memnew(Sprite);
@ -383,7 +383,7 @@ public:
sprite->set_texture(text);
sprite->add_child(sprite2);
sprite2->set_pos(Point2(50, 50));
sprite2->show();
sprite2->show();*/
}

View file

@ -37,13 +37,10 @@
#include "test_gui.h"
#include "test_render.h"
#include "test_sound.h"
#include "test_misc.h"
#include "test_physics.h"
#include "test_physics_2d.h"
#include "test_python.h"
#include "test_io.h"
#include "test_particles.h"
#include "test_detailer.h"
#include "test_shader_lang.h"
#include "test_gdscript.h"
#include "test_image.h"
@ -56,7 +53,6 @@ const char ** tests_get_names() {
"containers",
"math",
"render",
"particles",
"multimesh",
"gui",
"io",
@ -96,11 +92,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
return TestPhysics2D::test();
}
if (p_test=="misc") {
return TestMisc::test();
}
if (p_test=="render") {
return TestRender::test();
@ -123,16 +114,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
return TestIO::test();
}
if (p_test=="particles") {
return TestParticles::test();
}
if (p_test=="multimesh") {
return TestMultiMesh::test();
}
if (p_test=="shaderlang") {
return TestShaderLang::test();
@ -163,19 +144,6 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
return TestImage::test();
}
if (p_test=="detailer") {
return TestMultiMesh::test();
}
#ifdef PYTHON_ENABLED
if (p_test=="python") {
return TestPython::test();
}
#endif
return NULL;
}

View file

@ -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 );
}
}

View file

@ -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

View file

@ -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 );
}
}

View file

@ -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

View file

@ -138,10 +138,6 @@ protected:
/* SPHERE SHAPE */
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;
RID sphere_shape=ps->shape_create(PhysicsServer::SHAPE_SPHERE);
@ -151,12 +147,9 @@ protected:
/* BOX SHAPE */
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();
Geometry::MeshData box_data = Geometry::build_convex_mesh(box_planes);
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;
RID box_shape=ps->shape_create(PhysicsServer::SHAPE_BOX);
@ -167,13 +160,11 @@ protected:
/* CAPSULE SHAPE */
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();
Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes);
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;
RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE);
@ -186,14 +177,12 @@ protected:
/* CONVEX SHAPE */
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();
Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes);
QuickHull::build(convex_data.vertices,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;
RID convex_shape=ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON);
@ -223,11 +212,9 @@ protected:
d.resize(VS::ARRAY_MAX);
d[VS::ARRAY_VERTEX]=p_faces;
d[VS::ARRAY_NORMAL]=normals;
vs->mesh_add_surface(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->mesh_add_surface_from_arrays(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d );
//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);
@ -464,7 +451,7 @@ public:
}
virtual bool iteration(float p_time) {
if (mover) {
if (mover.is_valid()) {
static float joy_speed = 10;
PhysicsServer * ps = PhysicsServer::get_singleton();
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);
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();
Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes);
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;
RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE);

View file

@ -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);
@ -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);
@ -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);
@ -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);
@ -381,7 +381,7 @@ public:
RID vp = vs->viewport_create();
canvas = vs->canvas_create();
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;
//smaller.scale(Vector2(0.6,0.6));
//smaller.elements[2]=Vector2(100,0);

View file

@ -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

View file

@ -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

View file

@ -173,7 +173,10 @@ public:
// vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
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_set_scenario( viewport, scenario );
vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,3,30 ) ) );
@ -192,7 +195,7 @@ public:
//*
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_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 );
light = vs->instance_create2( lightaux, scenario );
Transform lla;
@ -205,8 +208,8 @@ public:
//*
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_DIFFUSE, Color(1.0,1.0,0.0) );
vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RADIUS, 4 );
vs->light_set_color( lightaux, Color(1.0,1.0,0.0) );
vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RANGE, 4 );
vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8 );
//vs->light_set_shadow( lightaux, true );
//light = vs->instance_create( lightaux );

View file

@ -37,7 +37,7 @@
#include "scene/gui/text_edit.h"
#include "print_string.h"
#include "servers/visual/shader_language.h"
#include "drivers/gles2/shader_compiler_gles2.h"
//#include "drivers/gles2/shader_compiler_gles2.h"
typedef ShaderLanguage SL;
@ -57,50 +57,54 @@ static String _mktab(int p_level) {
static String _typestr(SL::DataType p_type) {
switch(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 ShaderLanguage::get_datatype_name(p_type);
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) {
switch(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 ShaderLanguage::get_operator_text(p_op);
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) {
@ -109,18 +113,48 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
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 ";
ucode+=_typestr(E->get().type)+"="+String(E->get().default_value)+"\n";
code+=ucode;
ucode+=_prestr(E->get().precission);
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++) {
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)
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+=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;
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;
//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++) {
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;
@ -168,18 +209,7 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
} break;
case SL::Node::TYPE_CONSTANT: {
SL::ConstantNode *cnode=(SL::ConstantNode*)p_node;
switch(cnode->datatype) {
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)+">";
}
return get_constant_text(cnode->datatype,cnode->values);
} break;
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_MUL:
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);
break;
case SL::OP_ADD:
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_BIT_INVERT:
case SL::OP_NEGATE:
case SL::OP_NOT:
case SL::OP_DECREMENT:
case SL::OP_INCREMENT:
code=_opstr(onode->op)+dump_node_code(onode->arguments[0],p_level);
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_CONSTRUCT:
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+=")";
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;
@ -233,20 +265,19 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node;
if (cfnode->flow_op==SL::FLOW_OP_IF) {
code+="if ("+dump_node_code(cfnode->statements[0],p_level)+") {\n";
code+=dump_node_code(cfnode->statements[1],p_level+1);
if (cfnode->statements.size()==3) {
code+=_mktab(p_level)+"if ("+dump_node_code(cfnode->expressions[0],p_level)+")\n";
code+=dump_node_code(cfnode->blocks[0],p_level+1);
if (cfnode->blocks.size()==2) {
code+="} else {\n";
code+=dump_node_code(cfnode->statements[2],p_level+1);
code+=_mktab(p_level)+"else\n";
code+=dump_node_code(cfnode->blocks[1],p_level+1);
}
code+="}\n";
} else if (cfnode->flow_op==SL::FLOW_OP_RETURN) {
if (cfnode->statements.size()) {
code="return "+dump_node_code(cfnode->statements[0],p_level);
if (cfnode->blocks.size()) {
code="return "+dump_node_code(cfnode->blocks[0],p_level);
} else {
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;
*str=dump_node_code(p_program,0);
return OK;
}
@ -283,6 +312,7 @@ MainLoop* test() {
if (cmdlargs.empty()) {
//try editor!
print_line("usage: godot -test shader_lang <shader>");
return NULL;
}
@ -303,38 +333,29 @@ MainLoop* test() {
code+=c;
}
int errline;
int errcol;
String error;
print_line(SL::lex_debug(code));
Error err = SL::compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,NULL,NULL,&error,&errline,&errcol);
SL sl;
print_line("tokens:\n\n"+sl.token_debug(code));
Map<StringName,Map<StringName,SL::DataType> > dt;
dt["fragment"]["ALBEDO"]=SL::TYPE_VEC3;
Set<String> rm;
rm.insert("popo");
Error err = sl.compile(code,dt,rm);
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;
} 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;
}
}

View file

@ -842,7 +842,7 @@ bool test_29() {
IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
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());
IP_Address ip2("fe80::52e5:49ff:fe93:1baf");

View file

@ -2,66 +2,66 @@
Import('env')
env.core_sources=[]
env.core_sources = []
gd_call=""
gd_inc=""
gd_call = ""
gd_inc = ""
for x in env.global_defaults:
env.core_sources.append("#platform/"+x+"/globals/global_defaults.cpp")
gd_inc+='#include "platform/'+x+'/globals/global_defaults.h"\n'
gd_call+="\tregister_"+x+"_global_defaults();\n"
env.core_sources.append("#platform/" + x + "/globals/global_defaults.cpp")
gd_inc += '#include "platform/' + x + '/globals/global_defaults.h"\n'
gd_call += "\tregister_" + x + "_global_defaults();\n"
gd_cpp='#include "globals.h"\n'
gd_cpp+=gd_inc
gd_cpp+="void Globals::register_global_defaults() {\n"+gd_call+"\n}\n"
gd_cpp = '#include "globals.h"\n'
gd_cpp += gd_inc
gd_cpp += "void Globals::register_global_defaults() {\n" + gd_call + "\n}\n"
f = open("global_defaults.cpp","wb")
f = open("global_defaults.cpp", "wb")
f.write(gd_cpp)
f.close()
import os
txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
e=os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
txt = ""
ec_valid=True
if (len(e)!=64):
ec_valid=False
else:
e = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
txt = ""
ec_valid = True
if (len(e) != 64):
ec_valid = False
else:
for i in range(len(e)>>1):
if (i>0):
txt+=","
txts="0x"+e[i*2:i*2+2]
try:
int(txts,16)
except:
ec_valid=False
txt+=txts
if (not ec_valid):
txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
print("Invalid AES256 encryption key, not 64 bits hex: "+e)
for i in range(len(e) >> 1):
if (i > 0):
txt += ","
txts = "0x" + e[i * 2:i * 2 + 2]
try:
int(txts, 16)
except:
ec_valid = False
txt += txts
if (not ec_valid):
txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
print("Invalid AES256 encryption key, not 64 bits hex: " + e)
f = open("script_encryption_key.cpp", "wb")
f.write("#include \"globals.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
f.close()
env.add_source_files(env.core_sources,"*.cpp")
env.add_source_files(env.core_sources, "*.cpp")
Export('env')
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('math/SCsub');
SConscript('io/SCsub');
SConscript('bind/SCsub');
SConscript('os/SCsub')
SConscript('math/SCsub')
SConscript('io/SCsub')
SConscript('bind/SCsub')
lib = env.Library("core",env.core_sources)
lib = env.Library("core", env.core_sources)
env.Prepend(LIBS=[lib])

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* 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);
}
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 {
return _p->array.find(p_value, p_from);

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* 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 remove(int p_pos);
Variant front() const;
Variant back() const;
void sort();
void sort_custom(Object *p_obj,const StringName& p_function);
void invert();

View file

@ -2,6 +2,6 @@
Import('env')
env.add_source_files(env.core_sources,"*.cpp")
env.add_source_files(env.core_sources, "*.cpp")
Export('env')

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* 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);
}
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_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);
@ -2043,6 +2043,13 @@ _Directory::~_Directory() {
memdelete(d);
}
_Marshalls* _Marshalls::singleton=NULL;
_Marshalls *_Marshalls::get_singleton()
{
return singleton;
}
String _Marshalls::variant_to_base64(const Variant& p_var) {
int len;

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -318,7 +318,7 @@ public:
Error set_thread_name(const String& p_name);
void set_use_vsync(bool p_enable);
bool is_vsnc_enabled() const;
bool is_vsync_enabled() const;
Dictionary get_engine_version() const;
@ -503,6 +503,8 @@ class _Marshalls : public Reference {
OBJ_TYPE(_Marshalls,Reference);
static _Marshalls* singleton;
protected:
static void _bind_methods();
@ -510,6 +512,8 @@ protected:
public:
static _Marshalls* get_singleton();
String variant_to_base64(const Variant& p_var);
Variant base64_to_variant(const String& p_str);
@ -519,7 +523,8 @@ public:
String utf8_to_base64(const String& p_str);
String base64_to_utf8(const String& p_str);
_Marshalls() {};
_Marshalls() { singleton = this; }
~_Marshalls() { singleton = NULL; }
};

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -57,33 +57,33 @@ enum Error {
ERR_FILE_MISSING_DEPENDENCIES,
ERR_FILE_EOF,
ERR_CANT_OPEN, ///< Can't open a resource/socket/file
ERR_CANT_CREATE,
ERROR_QUERY_FAILED, // (20)
ERR_CANT_CREATE, // (20)
ERROR_QUERY_FAILED,
ERR_ALREADY_IN_USE,
ERR_LOCKED, ///< resource is locked
ERR_TIMEOUT,
ERR_CANT_CONNECT,
ERR_CANT_RESOLVE, // (25)
ERR_CANT_CONNECT, // (25)
ERR_CANT_RESOLVE,
ERR_CONNECTION_ERROR,
ERR_CANT_AQUIRE_RESOURCE,
ERR_CANT_FORK,
ERR_INVALID_DATA, ///< Data passed is invalid
ERR_INVALID_PARAMETER, ///< Parameter passed is invalid (30)
ERR_INVALID_DATA, ///< Data passed is invalid (30)
ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
ERR_ALREADY_EXISTS, ///< When adding, item already exists
ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
ERR_DATABASE_CANT_READ, ///< database is full
ERR_DATABASE_CANT_WRITE, ///< database is full
ERR_COMPILATION_FAILED, // (35)
ERR_DATABASE_CANT_WRITE, ///< database is full (35)
ERR_COMPILATION_FAILED,
ERR_METHOD_NOT_FOUND,
ERR_LINK_FAILED,
ERR_SCRIPT_FAILED,
ERR_CYCLIC_LINK,
ERR_INVALID_DECLARATION, // (40)
ERR_CYCLIC_LINK, // (40)
ERR_INVALID_DECLARATION,
ERR_DUPLICATE_SYMBOL,
ERR_PARSE_ERROR,
ERR_BUSY,
ERR_SKIP,
ERR_HELP, ///< user requested help!! (45)
ERR_SKIP, // (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_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

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -49,7 +49,8 @@
enum ErrorHandlerType {
ERR_HANDLER_ERROR,
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);

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* 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=="")
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();
@ -657,37 +658,37 @@ static Variant _decode_variant(const String& p_string) {
String format=params[0].strip_edges();
Image::Format imgformat;
/*
if (format=="grayscale") {
imgformat=Image::FORMAT_GRAYSCALE;
imgformat=Image::FORMAT_L8;
} else if (format=="intensity") {
imgformat=Image::FORMAT_INTENSITY;
} else if (format=="grayscale_alpha") {
imgformat=Image::FORMAT_GRAYSCALE_ALPHA;
imgformat=Image::FORMAT_LA8;
} else if (format=="rgb") {
imgformat=Image::FORMAT_RGB;
imgformat=Image::FORMAT_RGB8;
} else if (format=="rgba") {
imgformat=Image::FORMAT_RGBA;
imgformat=Image::FORMAT_RGBA8;
} else if (format=="indexed") {
imgformat=Image::FORMAT_INDEXED;
} else if (format=="indexed_alpha") {
imgformat=Image::FORMAT_INDEXED_ALPHA;
} else if (format=="bc1") {
imgformat=Image::FORMAT_BC1;
imgformat=Image::FORMAT_DXT1;
} else if (format=="bc2") {
imgformat=Image::FORMAT_BC2;
imgformat=Image::FORMAT_DXT3;
} else if (format=="bc3") {
imgformat=Image::FORMAT_BC3;
imgformat=Image::FORMAT_DXT5;
} else if (format=="bc4") {
imgformat=Image::FORMAT_BC4;
imgformat=Image::FORMAT_ATI1;
} else if (format=="bc5") {
imgformat=Image::FORMAT_BC5;
imgformat=Image::FORMAT_ATI2;
} else if (format=="custom") {
imgformat=Image::FORMAT_CUSTOM;
} else {
ERR_FAIL_V( Image() );
}
}*/
int mipmaps=params[1].to_int();
int w=params[2].to_int();
@ -974,26 +975,30 @@ static String _encode_variant(const Variant& p_variant) {
if (!img.empty()) {
String 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_GRAYSCALE_ALPHA: format="grayscale_alpha"; break;
case Image::FORMAT_RGB: format="rgb"; break;
case Image::FORMAT_RGBA: format="rgba"; break;
case Image::FORMAT_LA8: format="grayscale_alpha"; break;
case Image::FORMAT_RGB8: format="rgb"; break;
case Image::FORMAT_RGBA8: format="rgba"; break;
case Image::FORMAT_INDEXED : format="indexed"; break;
case Image::FORMAT_INDEXED_ALPHA: format="indexed_alpha"; break;
case Image::FORMAT_BC1: format="bc1"; break;
case Image::FORMAT_BC2: format="bc2"; break;
case Image::FORMAT_BC3: format="bc3"; break;
case Image::FORMAT_BC4: format="bc4"; break;
case Image::FORMAT_BC5: format="bc5"; break;
case Image::FORMAT_DXT1: format="bc1"; break;
case Image::FORMAT_DXT3: format="bc2"; break;
case Image::FORMAT_DXT5: format="bc3"; break;
case Image::FORMAT_ATI1: format="bc4"; break;
case Image::FORMAT_ATI2: format="bc5"; break;
case Image::FORMAT_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break;
default: {}
}
*/
str+=format+", ";
str+=itos(img.get_mipmaps())+", ";
str+=itos(img.has_mipmaps())+", ";
str+=itos(img.get_width())+", ";
str+=itos(img.get_height())+", ";
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));
custom_prop_info[p_prop]=p_info;
custom_prop_info[p_prop].name=p_prop;
}

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -55,35 +55,44 @@ public:
static SavePNGFunc save_png_func;
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
};
@ -96,15 +105,21 @@ public:
/* INTERPOLATE GAUSS */
};
//some functions provided by something else
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 void (*_image_compress_bc_func)(Image *);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_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_bc)(Image *);
static void (*_image_decompress_etc)(Image *);
static void (*_image_decompress_etc2)(Image *);
Error _decompress_bc();
@ -114,92 +129,19 @@ public:
static Image (*lossless_unpacker)(const DVector<uint8_t>& p_buffer);
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;
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_ 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);
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:
@ -207,20 +149,11 @@ public:
int get_width() const; ///< Get image width
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
* 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.
* Convert the image to another format, conversion only to raw byte format
*/
void convert( Format p_new_format );
@ -259,25 +192,21 @@ public:
void flip_x();
void flip_y();
/**
* 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();
/**
* 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
*/
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 );
/**
@ -301,7 +230,7 @@ public:
/**
* 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 {
ALPHA_NONE,
@ -312,32 +241,27 @@ public:
AlphaMode detect_alpha() 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_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_required_mipmaps(int p_width, int p_height, Format p_format);
bool operator==(const Image& p_image) const;
void quantize();
enum CompressMode {
COMPRESS_BC,
COMPRESS_16BIT,
COMPRESS_S3TC,
COMPRESS_PVRTC2,
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 */
Error decompress();
Image decompressed() const;
@ -349,8 +273,6 @@ public:
void normalmap_to_xy();
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;
Image get_rect(const Rect2& p_area) const;

View file

@ -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

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -106,7 +106,7 @@ List<StringName> InputMap::get_actions() const {
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()) {
@ -122,7 +122,7 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
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;
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 _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 {

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -46,7 +46,7 @@ private:
mutable Map<StringName, Action> input_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_actions();

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -2,8 +2,8 @@
Import('env')
env.add_source_files(env.core_sources,"*.cpp")
env.add_source_files(env.core_sources,"*.c")
#env.core_sources.append("io/fastlz.c")
env.add_source_files(env.core_sources, "*.cpp")
env.add_source_files(env.core_sources, "*.c")
# env.core_sources.append("io/fastlz.c")
Export('env')

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -29,11 +29,14 @@
#include "http_client.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();
tcp_connection->set_ip_type(ip_type);
conn_port=p_port;
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;
} else {
//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;
}
@ -636,7 +639,8 @@ Error HTTPClient::_get_http_data(uint8_t* p_buffer, int p_bytes,int &r_received)
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("get_connection:StreamPeer"),&HTTPClient::get_connection);
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(){
ip_type = IP::TYPE_ANY;
tcp_connection = StreamPeerTCP::create_ref();
resolving = IP::RESOLVER_INVALID_ID;
status=STATUS_DISCONNECTED;

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -132,6 +132,7 @@ public:
private:
IP::Type ip_type;
Status status;
IP::ResolverID resolving;
int conn_port;
@ -164,8 +165,9 @@ private:
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(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);
Ref<StreamPeer> get_connection() const;

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -32,7 +32,6 @@
#include "hash_map.h"
VARIANT_ENUM_CAST(IP::ResolverStatus);
VARIANT_ENUM_CAST(IP_Address::AddrType);
/************* RESOLVER ******************/
@ -44,12 +43,12 @@ struct _IP_ResolverPrivate {
volatile IP::ResolverStatus status;
IP_Address response;
String hostname;
IP_Address::AddrType type;
IP::Type type;
void clear() {
status = IP::RESOLVER_STATUS_NONE;
response = IP_Address();
type = IP_Address::TYPE_NONE;
type = IP::TYPE_NONE;
hostname="";
};
@ -83,7 +82,7 @@ struct _IP_ResolverPrivate {
continue;
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;
else
queue[i].status=IP::RESOLVER_STATUS_DONE;
@ -108,25 +107,28 @@ struct _IP_ResolverPrivate {
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;
if (resolver->cache.has(p_hostname))
if (resolver->cache[p_hostname].type & p_type != 0)
return resolver->cache[p_hostname];
// requested type is different from type in cache. continue resolution, if successful it'll overwrite cache
String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
if (resolver->cache.has(key))
return resolver->cache[key];
IP_Address res = _resolve_hostname(p_hostname, p_type);
resolver->cache[p_hostname]=res;
resolver->cache[key]=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;
@ -137,10 +139,11 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP_Addr
return id;
}
String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
resolver->queue[id].hostname=p_hostname;
resolver->queue[id].type = p_type;
if (resolver->cache.has(p_hostname) && (resolver->cache[p_hostname].type & p_type) != 0) {
resolver->queue[id].response=resolver->cache[p_hostname];
if (resolver->cache.has(key)) {
resolver->queue[id].response=resolver->cache[key];
resolver->queue[id].status=IP::RESOLVER_STATUS_DONE;
} else {
resolver->queue[id].response=IP_Address();
@ -194,7 +197,10 @@ void IP::clear_cache(const String &p_hostname) {
if (p_hostname.empty()) {
resolver->cache.clear();
} 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() {
ObjectTypeDB::bind_method(_MD("resolve_hostname","host"),&IP::resolve_hostname);
ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host"),&IP::resolve_hostname_queue_item);
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_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_address","id"),&IP::get_resolve_item_address);
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_INVALID_ID );
BIND_CONSTANT( TYPE_NONE );
BIND_CONSTANT( TYPE_IPV4 );
BIND_CONSTANT( TYPE_IPV6 );
BIND_CONSTANT( TYPE_ANY );
}

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -48,12 +48,12 @@ public:
RESOLVER_STATUS_ERROR,
};
enum AddressType {
enum Type {
ADDRESS_IPV4 = 1,
ADDRESS_IPV6 = 2,
ADDRESS_ANY = 3,
TYPE_NONE = 0,
TYPE_IPV4 = 1,
TYPE_IPV6 = 2,
TYPE_ANY = 3,
};
enum {
@ -73,7 +73,7 @@ protected:
static IP*singleton;
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;
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
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;
IP_Address get_resolve_item_address(ResolverID p_id) const;
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

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -38,21 +38,18 @@ IP_Address::operator Variant() const {
IP_Address::operator String() const {
if (type == TYPE_NONE)
return "0.0.0.0";
if (type == TYPE_IPV4)
return itos(field8[0])+"."+itos(field8[1])+"."+itos(field8[2])+"."+itos(field8[3]);
else {
String ret;
for (int i=0; i<8; i++) {
if (i > 0)
ret = ret + ":";
uint16_t num = (field8[i*2] << 8) + field8[i*2+1];
ret = ret + String::num_int64(num, 16);
};
return ret;
if(is_ipv4())
// IPv4 address mapped to IPv6
return itos(field8[12])+"."+itos(field8[13])+"."+itos(field8[14])+"."+itos(field8[15]);
String ret;
for (int i=0; i<8; i++) {
if (i > 0)
ret = ret + ":";
uint16_t num = (field8[i*2] << 8) + field8[i*2+1];
ret = ret + String::num_int64(num, 16);
};
return ret;
}
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));
};
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) {
clear();
if (p_string.find(":") >= 0) {
_parse_ipv6(p_string);
type = TYPE_IPV6;
} else {
_parse_ipv4(p_string, 0, &field8[0]);
type = TYPE_IPV4;
// Mapped to IPv6
field16[5] = 0xffff;
_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;
};
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;
memset(&field8[0], 0, sizeof(field8));
if (p_type == TYPE_IPV4) {
field8[0]=p_a;
field8[1]=p_b;
field8[2]=p_c;
field8[3]=p_d;
} else if (type == TYPE_IPV6) {
clear();
if (!is_v6) {
// Mapped to IPv6
field16[5]=0xffff;
field8[12]=p_a;
field8[13]=p_b;
field8[14]=p_c;
field8[15]=p_d;
} else {
_32_to_buf(&field8[0], p_a);
_32_to_buf(&field8[4], p_b);
_32_to_buf(&field8[8], p_c);
_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();
};
}
}

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -33,16 +33,7 @@
struct IP_Address {
public:
enum AddrType {
TYPE_NONE = 0,
TYPE_IPV4 = 1,
TYPE_IPV6 = 2,
TYPE_ANY = 3,
};
AddrType type;
private:
union {
uint8_t field8[16];
@ -70,11 +61,17 @@ public:
}
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;
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() { clear(); type=TYPE_NONE; }
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(); }
};

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* 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) {
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_height(),&buf[12]);
int ds=data.size();

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -31,20 +31,18 @@
PacketPeerUDP* (*PacketPeerUDP::_create)()=NULL;
VARIANT_ENUM_CAST(IP_Address::AddrType);
String PacketPeerUDP::_get_packet_ip() const {
return get_packet_address();
}
Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) {
Error PacketPeerUDP::_set_send_address(const String& p_address, int p_port) {
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip=p_address;
} else {
ip=IP::get_singleton()->resolve_hostname(p_address);
ip=IP::get_singleton()->resolve_hostname(p_address, ip_type);
if (ip==IP_Address())
return ERR_CANT_RESOLVE;
}
@ -53,9 +51,15 @@ Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) {
return OK;
}
void PacketPeerUDP::set_ip_type(IP::Type p_type) {
close();
ip_type = p_type;
}
void PacketPeerUDP::_bind_methods() {
ObjectTypeDB::bind_method(_MD("listen:Error","port","recv_buf_size"),&PacketPeerUDP::listen,DEFVAL(65536));
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("close"),&PacketPeerUDP::close);
ObjectTypeDB::bind_method(_MD("wait:Error"),&PacketPeerUDP::wait);
ObjectTypeDB::bind_method(_MD("is_listening"),&PacketPeerUDP::is_listening);
@ -83,4 +87,5 @@ PacketPeerUDP* PacketPeerUDP::create() {
PacketPeerUDP::PacketPeerUDP()
{
ip_type = IP::TYPE_ANY;
}

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */
@ -30,6 +30,7 @@
#define PACKET_PEER_UDP_H
#include "io/ip.h"
#include "io/packet_peer.h"
class PacketPeerUDP : public PacketPeer {
@ -37,6 +38,8 @@ class PacketPeerUDP : public PacketPeer {
protected:
IP::Type ip_type;
static PacketPeerUDP* (*_create)();
static void _bind_methods();
@ -46,7 +49,8 @@ protected:
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 Error wait()=0;
virtual bool is_listening() const=0;

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

View file

@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* 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 */
/* a copy of this software and associated documentation files (the */

Some files were not shown because too many files have changed in this diff Show more