Compare commits
5 Commits
2.1-stable
...
1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| eb26ca7ae1 | |||
| c47810c33b | |||
| 8ee6e3848e | |||
| 7ae44a055b | |||
| a3a3cafbc8 |
@ -1,10 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = tab
|
||||
|
||||
[.travis.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
9
.gitattributes
vendored
9
.gitattributes
vendored
@ -1,9 +0,0 @@
|
||||
# Properly detect languages on Github
|
||||
*.h linguist-language=cpp
|
||||
*.inc linguist-language=cpp
|
||||
drivers/* linguist-vendored
|
||||
|
||||
*.cpp eol=lf
|
||||
*.h eol=lf
|
||||
*.py eol=lf
|
||||
*.hpp eol=lf
|
||||
52
.gitignore
vendored
52
.gitignore
vendored
@ -1,9 +1,10 @@
|
||||
# Godot auto generated files
|
||||
# GoDot auto generated files
|
||||
platform/server/logo.h
|
||||
platform/android/logo.h
|
||||
platform/bb10/logo.h
|
||||
platform/iphone/logo.h
|
||||
platform/javascript/logo.h
|
||||
platform/nacl/logo.h
|
||||
platform/osx/logo.h
|
||||
platform/windows/logo.h
|
||||
platform/x11/logo.h
|
||||
@ -14,33 +15,31 @@ core/method_bind.inc
|
||||
core/method_bind_ext.inc
|
||||
core/script_encryption_key.cpp
|
||||
core/global_defaults.cpp
|
||||
drivers/unix/os_unix_global_settings_path.cpp
|
||||
tools/editor/register_exporters.cpp
|
||||
tools/editor/doc_data_compressed.h
|
||||
tools/editor/certs_compressed.h
|
||||
tools/editor/editor_icons.cpp
|
||||
tools/editor/translations.h
|
||||
tools/editor/builtin_fonts.h
|
||||
-fpic
|
||||
.fscache
|
||||
make.bat
|
||||
log.txt
|
||||
|
||||
# Documentation generated by doxygen or from classes.xml
|
||||
doc/_build/
|
||||
|
||||
# Javascript specific
|
||||
*.bc
|
||||
|
||||
# Android specific
|
||||
platform/android/java/build.gradle
|
||||
platform/android/java/.gradle
|
||||
platform/android/java/.gradletasknamecache
|
||||
platform/android/java/local.properties
|
||||
platform/android/java/project.properties
|
||||
platform/android/java/build.gradle
|
||||
platform/android/java/AndroidManifest.xml
|
||||
platform/android/java/bin/*
|
||||
platform/android/java/libs/*
|
||||
platform/android/java/gen/*
|
||||
platform/android/java/assets
|
||||
platform/android/libs/apk_expansion/bin/*
|
||||
platform/android/libs/apk_expansion/gen/*
|
||||
platform/android/libs/google_play_services/bin/*
|
||||
platform/android/libs/google_play_services/gen/*
|
||||
platform/android/libs/play_licensing/bin/*
|
||||
platform/android/libs/play_licensing/gen/*
|
||||
|
||||
# General c++ generated files
|
||||
*.lib
|
||||
@ -51,16 +50,6 @@ platform/android/java/assets
|
||||
*.d
|
||||
*.so
|
||||
*.os
|
||||
*.Plo
|
||||
*.lo
|
||||
|
||||
# Libs generated files
|
||||
.deps/*
|
||||
.dirstamp
|
||||
|
||||
# Vim temp files
|
||||
*.swo
|
||||
*.swp
|
||||
|
||||
# QT project files
|
||||
*.config
|
||||
@ -84,8 +73,6 @@ platform/android/java/assets
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
*.sln
|
||||
*.vcxproj*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
@ -142,8 +129,6 @@ ipch/
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
@ -190,6 +175,9 @@ AutoTest.Net/
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# dumpdoc generated files
|
||||
doc/html/class_list
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
@ -240,9 +228,6 @@ node_modules/
|
||||
# KDE
|
||||
.directory
|
||||
|
||||
#Kdevelop project files
|
||||
*.kdev4
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
@ -295,11 +280,4 @@ cscope.files
|
||||
cscope.out
|
||||
cscope.in.out
|
||||
cscope.po.out
|
||||
godot.creator.*
|
||||
|
||||
projects/
|
||||
platform/windows/godot_res.res
|
||||
|
||||
# Visual Studio Code folder (and files) that are created
|
||||
# when the C/C++ extension (https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) is used
|
||||
/.vscode
|
||||
godot.creator.user.wd3476
|
||||
|
||||
86
.travis.yml
86
.travis.yml
@ -1,78 +1,14 @@
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
compiler:
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
before_install:
|
||||
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
env:
|
||||
- GODOT_TARGET=iphone
|
||||
- GODOT_TARGET=osx
|
||||
- GODOT_TARGET=x11
|
||||
- GODOT_TARGET=android
|
||||
- GODOT_TARGET=windows
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- os: linux
|
||||
env: GODOT_TARGET=iphone
|
||||
- os: linux
|
||||
env: GODOT_TARGET=osx
|
||||
- os: linux
|
||||
env: GODOT_TARGET=android
|
||||
- os: osx
|
||||
env: GODOT_TARGET=x11
|
||||
- os: osx
|
||||
env: GODOT_TARGET=windows
|
||||
- compiler: gcc
|
||||
env: GODOT_TARGET=iphone
|
||||
- compiler: gcc
|
||||
env: GODOT_TARGET=osx
|
||||
- compiler: clang
|
||||
env: GODOT_TARGET=android
|
||||
- compiler: clang
|
||||
env: GODOT_TARGET=windows
|
||||
- compiler: clang
|
||||
env: GODOT_TARGET=x11
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- build-essential
|
||||
- scons
|
||||
- pkg-config
|
||||
- libx11-dev
|
||||
- libxcursor-dev
|
||||
- libasound2-dev
|
||||
- libfreetype6-dev
|
||||
- libgl1-mesa-dev
|
||||
- libglu1-mesa-dev
|
||||
- libssl-dev
|
||||
- libxinerama-dev
|
||||
- libxrandr-dev
|
||||
|
||||
# For cross-compiling to Windows.
|
||||
- binutils-mingw-w64-i686
|
||||
- binutils-mingw-w64-x86-64
|
||||
- gcc-mingw-w64-i686
|
||||
- gcc-mingw-w64-x86-64
|
||||
- g++-mingw-w64-i686
|
||||
- g++-mingw-w64-x86-64
|
||||
- mingw-w64
|
||||
|
||||
|
||||
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; 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
|
||||
|
||||
script:
|
||||
- scons platform=$GODOT_TARGET CXX=$CXX openssl=builtin
|
||||
before_script:
|
||||
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq scons pkg-config libx11-dev libxcursor-dev build-essential libasound2-dev libfreetype6-dev libgl1-mesa-dev libglu-dev
|
||||
- if [ "$CXX" = "g++" ]; then sudo apt-get install -qq g++-4.8; fi
|
||||
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
|
||||
|
||||
script: scons platform=x11
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
# How to contribute efficiently
|
||||
|
||||
**Please read the first section before reporting a bug!**
|
||||
|
||||
## Reporting bugs or proposing features
|
||||
|
||||
The golden rule is to **always open *one* issue for *one* bug**. If you notice several bugs and want to report them, make sure to create one new issue for each of them.
|
||||
|
||||
Everything refered to hereafter as "bug" also applies for feature requests.
|
||||
|
||||
If you are reporting a new issue, you will make our life much simpler (and the fix come much sooner) by following those guidelines:
|
||||
|
||||
#### Search first in the existing database
|
||||
|
||||
Issues are often reported several times by various users. It's a good practice to **search first** in the issues database before reporting your issue. If you don't find a relevant match or if you are unsure, don't hesitate to **open a new issue**. The bugsquad will handle it from there if it's a duplicate.
|
||||
|
||||
#### Specify the platform
|
||||
|
||||
Godot runs on a large variety of platforms and operating systems and devices. If you believe your issue is device/platform dependent (for example if it is related to the rendering, crashes or compilation errors), please specify:
|
||||
* Operating system
|
||||
* Device (including architecture, e.g. x86, x86_64, arm, etc.)
|
||||
* GPU model (and driver in use if you know it)
|
||||
|
||||
#### Specify steps to reproduce
|
||||
|
||||
Many bugs can't be reproduced unless specific steps are taken. Please **specify the exact steps** that must be taken to reproduce the condition, and try to keep them as minimal as possible.
|
||||
|
||||
#### Provide a simple, example project
|
||||
|
||||
Sometimes an unexpected behavior happens in your project. In such case, understand that:
|
||||
|
||||
* What happens to you may not happen to other users.
|
||||
* We can't take the time to look at your project, understand how it is set up and then figure out why it's failing.
|
||||
|
||||
To speed up our work, please prepare for us **a simple project** that isolates and reproduces the issue. This is always the **the best way for us to fix it**. You can attach a zip file with the minimal project directly to the bug report, by drag and dropping the file in the GitHub edition field.
|
||||
|
||||
## Contributing pull requests
|
||||
|
||||
If you want to add new engine functionalities, please make sure that:
|
||||
|
||||
* This functionality is desired.
|
||||
* You talked to other developers on how to implement it best (on either communication channel, and maybe in a GitHub issue first before making your PR).
|
||||
* Even if it does not get merged, your PR is useful for future work by another developer.
|
||||
|
||||
Similar rules can be applied when contributing bug fixes - it's always best to discuss the implementation in the bug report first if you are not 100% about what would be the best fix.
|
||||
|
||||
#### Be nice to the git history
|
||||
|
||||
Try to make simple PRs with that handle one specific topic. Just like for reporting issues, it's better to open 3 different PRs that each address a different issue than one big PR with three commits.
|
||||
|
||||
When updating your fork with upstream changes, please use ``git pull --rebase`` to avoid creating "merge commits". Those commits unnecessarily pollute the git history when coming from PRs.
|
||||
|
||||
Also try to make commits that bring the engine from one stable state to another stable state, i.e. if your first commit has a bug that you fixed in the second commit, try to merge them together before making your pull request (see ``git rebase -i`` and relevant help about rebasing or ammending commits on the Internet).
|
||||
|
||||
This git style guide has some good practices to have in mind: https://github.com/agis-/git-style-guide
|
||||
|
||||
Thanks!
|
||||
|
||||
The Godot development team
|
||||
@ -51,14 +51,14 @@ PROJECT_BRIEF = "Game Engine MIT"
|
||||
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
|
||||
# the logo to the output directory.
|
||||
|
||||
PROJECT_LOGO = ../logo.png
|
||||
PROJECT_LOGO = E:/development/godot/logo_small.png
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
|
||||
# into which the generated documentation will be written. If a relative path is
|
||||
# entered, it will be relative to the location where doxygen was started. If
|
||||
# left blank the current directory will be used.
|
||||
|
||||
OUTPUT_DIRECTORY = ./_build/doxygen/
|
||||
OUTPUT_DIRECTORY = E:/development/godot/doxygen
|
||||
|
||||
# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
|
||||
# directories (in 2 levels) under the output directory of each output format and
|
||||
@ -768,7 +768,7 @@ WARN_LOGFILE =
|
||||
# spaces.
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = ../core/ ../main/ ../scene/
|
||||
INPUT = E:/development/godot
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||
@ -1,10 +0,0 @@
|
||||
**Operating system or device - Godot version:**
|
||||
|
||||
|
||||
**Issue description** (what happened, and what was expected):
|
||||
|
||||
|
||||
**Steps to reproduce:**
|
||||
|
||||
|
||||
**Link to minimal example project** (optional but very welcome):
|
||||
50
LICENSE.md
50
LICENSE.md
@ -1,27 +1,27 @@
|
||||
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
|
||||
GODOT ENGINE
|
||||
http://www.godotengine.org
|
||||
**********************************************************************
|
||||
Copyright (c) 2007-2014 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.
|
||||
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.
|
||||
|
||||
|
||||
**********************************************************************
|
||||
|
||||
************************************************************************
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
Godot Logo (c) Andrea Calabró, distributed under the terms of the CC By License:
|
||||
https://creativecommons.org/licenses/by/3.0/legalcode
|
||||
16
README.md
16
README.md
@ -1,7 +1,5 @@
|
||||

|
||||
|
||||
https://godotengine.org
|
||||
|
||||
### The Engine
|
||||
|
||||
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.
|
||||
@ -9,22 +7,20 @@ The editor, language and APIs are feature rich, yet simple to learn, allowing yo
|
||||
|
||||
### About
|
||||
|
||||
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)
|
||||
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.
|
||||
Development is sponsored by OKAM Studio (http://www.okamstudio.com).
|
||||
|
||||
### Documentation
|
||||
|
||||
Documentation is hosted on [ReadTheDocs](http://docs.godotengine.org).
|
||||
Documentation has been moved to the [GitHub Wiki](https://github.com/okamstudio/godot/wiki).
|
||||
|
||||
### Binary Downloads, Community, etc.
|
||||
|
||||
Binary downloads, community, etc. can be found in Godot homepage:
|
||||
|
||||
https://godotengine.org
|
||||
http://www.godotengine.org
|
||||
|
||||
### Compiling from Source
|
||||
|
||||
See docs for compilation instructions for every platform:
|
||||
http://docs.godotengine.org/en/latest/reference/_compiling.html
|
||||
|
||||
[](https://travis-ci.org/godotengine/godot)
|
||||
[](http://www.codetriage.com/godotengine/godot)
|
||||
Compilation instructions for every platform can be found in the Wiki:
|
||||
https://github.com/okamstudio/godot/wiki/advanced
|
||||
|
||||
176
SConstruct
176
SConstruct
@ -1,6 +1,5 @@
|
||||
EnsureSConsVersion(0,14);
|
||||
|
||||
|
||||
import string
|
||||
import os
|
||||
import os.path
|
||||
@ -23,7 +22,7 @@ platform_exporters=[]
|
||||
global_defaults=[]
|
||||
|
||||
for x in glob.glob("platform/*"):
|
||||
if (not os.path.isdir(x) or not os.path.exists(x+"/detect.py")):
|
||||
if (not os.path.isdir(x)):
|
||||
continue
|
||||
tmppath="./"+x
|
||||
|
||||
@ -55,52 +54,32 @@ methods.save_active_platforms(active_platforms,active_platform_ids)
|
||||
|
||||
custom_tools=['default']
|
||||
|
||||
platform_arg = ARGUMENTS.get("platform", False)
|
||||
|
||||
if (os.name=="posix"):
|
||||
pass
|
||||
elif (os.name=="nt"):
|
||||
if (os.getenv("VSINSTALLDIR")==None or platform_arg=="android"):
|
||||
custom_tools=['mingw']
|
||||
if (os.getenv("VSINSTALLDIR")==None):
|
||||
custom_tools=['mingw']
|
||||
|
||||
env_base=Environment(tools=custom_tools);
|
||||
env_base.AppendENVPath('PATH', os.getenv('PATH'))
|
||||
env_base.AppendENVPath('PKG_CONFIG_PATH', os.getenv('PKG_CONFIG_PATH'))
|
||||
env_base=Environment(tools=custom_tools,ENV = {'PATH' : os.environ['PATH']});
|
||||
#env_base=Environment(tools=custom_tools);
|
||||
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_source_modules=[]
|
||||
env_base.android_source_files=[]
|
||||
env_base.android_module_libraries=[]
|
||||
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_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
|
||||
env_base.__class__.android_module_source = methods.android_module_source
|
||||
env_base.__class__.android_module_library = methods.android_module_library
|
||||
env_base.__class__.android_module_file = methods.android_module_file
|
||||
env_base.__class__.android_module_manifest = methods.android_module_manifest
|
||||
env_base.__class__.android_module_permission = methods.android_module_permission
|
||||
env_base.__class__.android_module_attribute = methods.android_module_attribute
|
||||
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["x86_opt_gcc"]=False
|
||||
env_base["x86_opt_vc"]=False
|
||||
env_base["armv7_opt_gcc"]=False
|
||||
|
||||
customs = ['custom.py']
|
||||
|
||||
@ -114,19 +93,17 @@ if profile:
|
||||
|
||||
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('bits', 'Compile Target Bits (default/32/64).', "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('vorbis','Build Ogg Vorbis Support: (yes/no)','yes')
|
||||
opts.Add('opus','Build Opus Audio Format Support: (yes/no)','yes')
|
||||
opts.Add('minizip','Build Minizip Archive Support: (yes/no)','yes')
|
||||
opts.Add('squish','Squish BC Texture Compression in editor (yes/no)','yes')
|
||||
opts.Add('theora','Theora Video (yes/no)','yes')
|
||||
opts.Add('theoralib','Theora Video (yes/no)','no')
|
||||
opts.Add('freetype','Freetype support in editor','builtin')
|
||||
opts.Add('use_theoraplayer_binary', "Use precompiled binaries from libtheoraplayer for ogg/theora/vorbis (yes/no)", "no")
|
||||
opts.Add('freetype','Freetype support in editor','yes')
|
||||
opts.Add('speex','Speex Audio (yes/no)','yes')
|
||||
opts.Add('xml','XML Save/Load support (yes/no)','yes')
|
||||
opts.Add('png','PNG Image loader support (yes/no)','yes')
|
||||
@ -142,11 +119,9 @@ opts.Add("CXX", "Compiler");
|
||||
opts.Add("CCFLAGS", "Custom flags for the 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('colored', 'Enable colored output for the compilation (yes/no)', 'no')
|
||||
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')
|
||||
|
||||
@ -182,9 +157,6 @@ 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']);
|
||||
|
||||
env_base.platforms = {}
|
||||
|
||||
|
||||
@ -197,7 +169,6 @@ elif env_base['p'] != "":
|
||||
env_base["platform"]=selected_platform
|
||||
|
||||
|
||||
|
||||
if selected_platform in platform_list:
|
||||
|
||||
sys.path.append("./platform/"+selected_platform)
|
||||
@ -210,7 +181,7 @@ if selected_platform in platform_list:
|
||||
if env['vsproj']=="yes":
|
||||
env.vs_incs = []
|
||||
env.vs_srcs = []
|
||||
|
||||
|
||||
def AddToVSProject( sources ):
|
||||
for x in sources:
|
||||
if type(x) == type(""):
|
||||
@ -222,12 +193,12 @@ if selected_platform in platform_list:
|
||||
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.vs_incs = env.vs_incs + [basename + ".h"]
|
||||
#print basename
|
||||
env.AddToVSProject = AddToVSProject
|
||||
|
||||
env.extra_suffix=""
|
||||
|
||||
|
||||
if env["extra_suffix"] != '' :
|
||||
env.extra_suffix += '.'+env["extra_suffix"]
|
||||
|
||||
@ -246,23 +217,30 @@ if selected_platform in platform_list:
|
||||
|
||||
env.Append(LINKFLAGS=string.split(str(LINKFLAGS)))
|
||||
|
||||
detect.configure(env)
|
||||
|
||||
# Set our C and C++ standard requirements.
|
||||
# Prepending to make it possible to override.
|
||||
# This MSVC "detection" is an extreme hack.
|
||||
is_msvc = (os.name=="nt") and (os.getenv("VSINSTALLDIR")!=None or os.getenv("VCINSTALLDIR")!=None) and (selected_platform in ["windows", "winrt"])
|
||||
if (not is_msvc):
|
||||
# Specifying GNU extensions support explicitly, which are supported by both GCC and Clang.
|
||||
# We don't support C++17 so stick to earlier standards.
|
||||
# Godot 1.0 definitely started as a C++98 codebase.
|
||||
env.Prepend(CFLAGS=["-std=gnu11"])
|
||||
env.Prepend(CXXFLAGS=["-std=gnu++98"])
|
||||
# Disable these auto-enabled warnings which are treated as errors by modern compilers.
|
||||
env.Prepend(CCFLAGS=["-Wno-error=implicit-function-declaration", "-Wno-error=incompatible-pointer-types"])
|
||||
else:
|
||||
# MSVC doesn't support setting C++ to pre-C++14 standards, so do nothing and hope it works.
|
||||
pass
|
||||
|
||||
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)
|
||||
|
||||
|
||||
if (env["freetype"]!="no"):
|
||||
env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
|
||||
if (env["freetype"]=="builtin"):
|
||||
env.Append(CPPPATH=['#drivers/freetype'])
|
||||
env.Append(CPPPATH=['#drivers/freetype/freetype/include'])
|
||||
|
||||
|
||||
#env['platform_libsuffix'] = env['LIBSUFFIX']
|
||||
#env['platform_libsuffix'] = env['LIBSUFFIX']
|
||||
|
||||
suffix="."+selected_platform
|
||||
|
||||
@ -283,14 +261,10 @@ if selected_platform in platform_list:
|
||||
else:
|
||||
suffix+=".debug"
|
||||
|
||||
if env["arch"] != "":
|
||||
suffix += "."+env["arch"]
|
||||
elif (env["bits"]=="32"):
|
||||
if (env["bits"]=="32"):
|
||||
suffix+=".32"
|
||||
elif (env["bits"]=="64"):
|
||||
suffix+=".64"
|
||||
elif (env["bits"]=="fat"):
|
||||
suffix+=".fat"
|
||||
|
||||
suffix+=env.extra_suffix
|
||||
|
||||
@ -319,16 +293,12 @@ if selected_platform in platform_list:
|
||||
sys.modules.pop('config')
|
||||
|
||||
|
||||
if (env.use_ptrcall):
|
||||
env.Append(CPPFLAGS=['-DPTRCALL_ENABLED']);
|
||||
|
||||
if (env['musepack']=='yes'):
|
||||
env.Append(CPPFLAGS=['-DMUSEPACK_ENABLED']);
|
||||
|
||||
#if (env['openssl']!='no'):
|
||||
# env.Append(CPPFLAGS=['-DOPENSSL_ENABLED']);
|
||||
# if (env['openssl']=="builtin"):
|
||||
# env.Append(CPPPATH=['#drivers/builtin_openssl2'])
|
||||
if (env['openssl']!='no'):
|
||||
env.Append(CPPFLAGS=['-DOPENSSL_ENABLED']);
|
||||
if (env['openssl']=="builtin"):
|
||||
env.Append(CPPPATH=['#drivers/builtin_openssl2'])
|
||||
|
||||
if (env["builtin_zlib"]=='yes'):
|
||||
env.Append(CPPPATH=['#drivers/builtin_zlib/zlib'])
|
||||
@ -341,15 +311,9 @@ if selected_platform in platform_list:
|
||||
|
||||
if (env['vorbis']=='yes'):
|
||||
env.Append(CPPFLAGS=['-DVORBIS_ENABLED']);
|
||||
if (env['opus']=='yes'):
|
||||
env.Append(CPPFLAGS=['-DOPUS_ENABLED']);
|
||||
|
||||
|
||||
if (env['theora']=='yes'):
|
||||
env['theoralib']='yes'
|
||||
env.Append(CPPFLAGS=['-DTHEORA_ENABLED']);
|
||||
if (env['theoralib']=='yes'):
|
||||
env.Append(CPPFLAGS=['-DTHEORALIB_ENABLED']);
|
||||
|
||||
if (env['png']=='yes'):
|
||||
env.Append(CPPFLAGS=['-DPNG_ENABLED']);
|
||||
@ -382,7 +346,7 @@ if selected_platform in platform_list:
|
||||
|
||||
if (env['colored']=='yes'):
|
||||
methods.colored(sys,env)
|
||||
|
||||
|
||||
if (env['etc1']=='yes'):
|
||||
env.Append(CPPFLAGS=['-DETC1_ENABLED'])
|
||||
|
||||
@ -401,36 +365,20 @@ if selected_platform in platform_list:
|
||||
SConscript("main/SCsub")
|
||||
|
||||
SConscript("platform/"+selected_platform+"/SCsub"); # build selected platform
|
||||
|
||||
# Microsoft Visual Studio Project Generation
|
||||
if (env['vsproj'])=="yes":
|
||||
|
||||
|
||||
# Microsoft Visual Studio Project Generation
|
||||
if (env['vsproj'])=="yes":
|
||||
|
||||
AddToVSProject(env.core_sources)
|
||||
AddToVSProject(env.main_sources)
|
||||
AddToVSProject(env.modules_sources)
|
||||
AddToVSProject(env.modules_sources)
|
||||
AddToVSProject(env.scene_sources)
|
||||
AddToVSProject(env.servers_sources)
|
||||
AddToVSProject(env.tool_sources)
|
||||
|
||||
# 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']
|
||||
|
||||
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 = ['Debug']+['Debug']
|
||||
release_targets = ['Release']+['Release']
|
||||
@ -438,11 +386,11 @@ if selected_platform in platform_list:
|
||||
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)
|
||||
srcs = env.vs_srcs,
|
||||
runfile = targets,
|
||||
buildtarget = targets,
|
||||
auto_build_solution=1,
|
||||
variant = variants)
|
||||
|
||||
else:
|
||||
|
||||
|
||||
@ -10,3 +10,5 @@ Export('env')
|
||||
lib = env.Library("tests",env.tests_sources)
|
||||
|
||||
env.Prepend(LIBS=[lib])
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -44,9 +44,9 @@ MainLoop * test() {
|
||||
|
||||
/*
|
||||
HashMap<int,int> int_map;
|
||||
|
||||
|
||||
for (int i=0;i<68000;i++) {
|
||||
|
||||
|
||||
int num=(int)Math::random(0,1024);
|
||||
int_map[i]=num;
|
||||
}
|
||||
@ -70,21 +70,21 @@ MainLoop * test() {
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
#if 0
|
||||
Set<int> set;
|
||||
|
||||
|
||||
print_line("Begin Insert");
|
||||
for (int i=0;i<1100;i++) {
|
||||
|
||||
|
||||
int num=i;//(int)Math::random(0,1024);
|
||||
// print_line("inserting "+itos(num));
|
||||
// print_line("inserting "+itos(num));
|
||||
set.insert( num );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
for (int i=0;i<400;i++) {
|
||||
|
||||
|
||||
int num=(int)Math::random(0,1024);
|
||||
set.erase(num);
|
||||
}
|
||||
@ -92,11 +92,11 @@ MainLoop * test() {
|
||||
//set.print_tree();
|
||||
|
||||
for(Set<int>::Element *I=set.front();I;I=I->next()) {
|
||||
|
||||
|
||||
print_line("inserted "+itos(I->get())+" prev is "+itos(I->prev()?I->prev()->get():-100));
|
||||
|
||||
}
|
||||
|
||||
|
||||
print_line("depth is "+itos(set.calculate_depth()));
|
||||
print_line("Insert Success");
|
||||
#endif
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -44,7 +44,7 @@ class TestMainLoop : public MainLoop {
|
||||
RID light;
|
||||
RID mesh;
|
||||
RID scenario;
|
||||
|
||||
|
||||
#define MULTIMESH_COUNT 1500
|
||||
|
||||
float ofs_x,ofs_y;
|
||||
@ -122,9 +122,9 @@ public:
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -142,16 +142,16 @@ public:
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
virtual void request_quit() {
|
||||
|
||||
|
||||
quit=true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void init() {
|
||||
|
||||
|
||||
VisualServer *vs=VisualServer::get_singleton();
|
||||
|
||||
|
||||
@ -163,13 +163,13 @@ public:
|
||||
_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_camera( viewport, camera );
|
||||
vs->viewport_attach_to_screen(viewport);
|
||||
vs->viewport_set_scenario( viewport, scenario );
|
||||
|
||||
@ -179,7 +179,7 @@ public:
|
||||
//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;
|
||||
@ -190,20 +190,20 @@ public:
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -81,7 +81,7 @@ static String _parser_expr(const GDParser::Node *p_expr) {
|
||||
|
||||
case GDParser::Node::TYPE_IDENTIFIER: {
|
||||
|
||||
const GDParser::IdentifierNode *id_node = static_cast<const GDParser::IdentifierNode *>(p_expr);
|
||||
const GDParser::IdentifierNode *id_node = static_cast<const GDParser::IdentifierNode *>(p_expr);
|
||||
txt=id_node->name;
|
||||
} break;
|
||||
case GDParser::Node::TYPE_CONSTANT: {
|
||||
@ -487,12 +487,12 @@ static String _disassemble_addr(const Ref<GDScript>& p_script,const GDFunction&
|
||||
static void _disassemble_class(const Ref<GDScript>& p_class,const Vector<String>& p_code) {
|
||||
|
||||
|
||||
const Map<StringName,GDFunction*>& mf = p_class->debug_get_member_functions();
|
||||
const Map<StringName,GDFunction>& mf = p_class->debug_get_member_functions();
|
||||
|
||||
for(const Map<StringName,GDFunction*>::Element *E=mf.front();E;E=E->next()) {
|
||||
for(const Map<StringName,GDFunction>::Element *E=mf.front();E;E=E->next()) {
|
||||
|
||||
|
||||
const GDFunction &func=*E->get();
|
||||
const GDFunction &func=E->get();
|
||||
const int *code = func.get_code();
|
||||
int codelen=func.get_code_size();
|
||||
String defargs;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -62,16 +62,16 @@ class TestMainLoop : public SceneTree {
|
||||
|
||||
|
||||
Control *control;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
virtual void request_quit() {
|
||||
|
||||
|
||||
quit();
|
||||
|
||||
|
||||
}
|
||||
virtual void init() {
|
||||
|
||||
|
||||
SceneTree::init();
|
||||
|
||||
|
||||
@ -109,10 +109,7 @@ public:
|
||||
frame->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END );
|
||||
frame->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_END );
|
||||
frame->set_end( Point2(0,0) );
|
||||
|
||||
Ref<Theme> t = memnew( Theme );
|
||||
frame->set_theme(t);
|
||||
|
||||
|
||||
get_root()->add_child( frame );
|
||||
|
||||
Label *label = memnew( Label );
|
||||
@ -198,21 +195,21 @@ public:
|
||||
//root->add_child( control );
|
||||
|
||||
|
||||
|
||||
|
||||
LineEdit *line_edit = memnew( LineEdit );
|
||||
|
||||
|
||||
line_edit->set_pos( Point2( 30,190 ) );
|
||||
line_edit->set_size( Point2( 180,1 ) );
|
||||
|
||||
|
||||
frame->add_child(line_edit);
|
||||
|
||||
|
||||
HScrollBar *hscroll = memnew( HScrollBar );
|
||||
|
||||
|
||||
hscroll->set_pos( Point2( 30,290 ) );
|
||||
hscroll->set_size( Point2( 180,1 ) );
|
||||
hscroll->set_max(10);
|
||||
hscroll->set_page(4);
|
||||
|
||||
|
||||
frame->add_child(hscroll);
|
||||
|
||||
|
||||
@ -234,36 +231,36 @@ public:
|
||||
hscroll->share(progress);
|
||||
|
||||
MenuButton *menu_button = memnew( MenuButton );
|
||||
|
||||
|
||||
menu_button->set_text("I'm a menu!");
|
||||
menu_button->set_pos( Point2( 30,380 ) );
|
||||
menu_button->set_size( Point2( 1,1 ) );
|
||||
|
||||
frame->add_child(menu_button);
|
||||
|
||||
|
||||
frame->add_child(menu_button);
|
||||
|
||||
PopupMenu *popup = menu_button->get_popup();
|
||||
|
||||
|
||||
popup->add_item("Hello, testing");
|
||||
popup->add_item("My Dearest");
|
||||
popup->add_separator();
|
||||
popup->add_item("Popup");
|
||||
popup->add_check_item("Check Popup");
|
||||
popup->set_item_checked(4,true);
|
||||
|
||||
popup->set_item_checked(4,true);
|
||||
|
||||
OptionButton *options = memnew( OptionButton );
|
||||
|
||||
|
||||
options->add_item("Hello, testing");
|
||||
options->add_item("My Dearest");
|
||||
|
||||
|
||||
options->set_pos( Point2( 230,180 ) );
|
||||
options->set_size( Point2( 1,1 ) );
|
||||
|
||||
frame->add_child(options);
|
||||
|
||||
frame->add_child(options);
|
||||
|
||||
/*
|
||||
Tree * tree = memnew( Tree );
|
||||
tree->set_columns(2);
|
||||
|
||||
|
||||
tree->set_pos( Point2( 230,210 ) );
|
||||
tree->set_size( Point2( 150,250 ) );
|
||||
|
||||
@ -286,7 +283,7 @@ public:
|
||||
item->set_editable(0,true);
|
||||
item->set_text(0,"Have,Many,Several,Options!");
|
||||
item->set_range(0,2);
|
||||
|
||||
|
||||
frame->add_child(tree);
|
||||
*/
|
||||
|
||||
@ -365,11 +362,11 @@ public:
|
||||
tabc->add_child(ctl);
|
||||
|
||||
frame->add_child(tabc);
|
||||
|
||||
|
||||
tabc->set_pos( Point2( 400,210 ) );
|
||||
tabc->set_size( Point2( 180,250 ) );
|
||||
|
||||
|
||||
|
||||
Ref<ImageTexture> text = memnew( ImageTexture );
|
||||
text->load("test_data/concave.png");
|
||||
|
||||
@ -387,13 +384,13 @@ public:
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
MainLoop* test() {
|
||||
|
||||
|
||||
|
||||
return memnew( TestMainLoop );
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -47,37 +47,37 @@ namespace TestIO {
|
||||
|
||||
|
||||
class TestMainLoop : public MainLoop {
|
||||
|
||||
|
||||
|
||||
|
||||
bool quit;
|
||||
|
||||
|
||||
public:
|
||||
virtual void input_event(const InputEvent& p_event) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
virtual bool idle(float p_time) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void request_quit() {
|
||||
|
||||
|
||||
quit=true;
|
||||
|
||||
|
||||
}
|
||||
virtual void init() {
|
||||
|
||||
quit=true;
|
||||
}
|
||||
virtual bool iteration(float p_time) {
|
||||
|
||||
|
||||
return quit;
|
||||
}
|
||||
virtual void finish() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -61,10 +61,9 @@ const char ** tests_get_names() {
|
||||
"gui",
|
||||
"io",
|
||||
"shaderlang",
|
||||
"physics",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
return test_names;
|
||||
}
|
||||
|
||||
@ -72,22 +71,22 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
|
||||
|
||||
|
||||
if (p_test=="string") {
|
||||
|
||||
|
||||
return TestString::test();
|
||||
}
|
||||
|
||||
|
||||
if (p_test=="containers") {
|
||||
|
||||
|
||||
return TestContainers::test();
|
||||
}
|
||||
|
||||
|
||||
if (p_test=="math") {
|
||||
|
||||
|
||||
return TestMath::test();
|
||||
}
|
||||
|
||||
|
||||
if (p_test=="physics") {
|
||||
|
||||
|
||||
return TestPhysics::test();
|
||||
}
|
||||
|
||||
@ -97,15 +96,15 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
|
||||
}
|
||||
|
||||
if (p_test=="misc") {
|
||||
|
||||
|
||||
return TestMisc::test();
|
||||
}
|
||||
|
||||
if (p_test=="render") {
|
||||
|
||||
|
||||
return TestRender::test();
|
||||
}
|
||||
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
if (p_test=="gui") {
|
||||
|
||||
@ -119,17 +118,17 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
|
||||
}
|
||||
|
||||
if (p_test=="io") {
|
||||
|
||||
|
||||
return TestIO::test();
|
||||
}
|
||||
|
||||
|
||||
if (p_test=="particles") {
|
||||
|
||||
return TestParticles::test();
|
||||
}
|
||||
|
||||
|
||||
if (p_test=="multimesh") {
|
||||
|
||||
|
||||
return TestMultiMesh::test();
|
||||
}
|
||||
|
||||
@ -171,7 +170,7 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
|
||||
#ifdef PYTHON_ENABLED
|
||||
|
||||
if (p_test=="python") {
|
||||
|
||||
|
||||
return TestPython::test();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -40,9 +40,6 @@
|
||||
#include "scene/resources/texture.h"
|
||||
#include "vmap.h"
|
||||
#include "os/os.h"
|
||||
|
||||
#include "method_ptrcall.h"
|
||||
|
||||
namespace TestMath {
|
||||
|
||||
|
||||
@ -73,97 +70,14 @@ fix: 0, 0, 49.949951, 50
|
||||
v0: 0, 0, 100, 100
|
||||
v1: 0, 0, 100, 100
|
||||
fix: 0, 0, 100, 100
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint32_t ihash( uint32_t a)
|
||||
{
|
||||
a = (a+0x7ed55d16) + (a<<12);
|
||||
a = (a^0xc761c23c) ^ (a>>19);
|
||||
a = (a+0x165667b1) + (a<<5);
|
||||
a = (a+0xd3a2646c) ^ (a<<9);
|
||||
a = (a+0xfd7046c5) + (a<<3);
|
||||
a = (a^0xb55a4f09) ^ (a>>16);
|
||||
return a;
|
||||
}
|
||||
|
||||
uint32_t ihash2( uint32_t a) {
|
||||
a = (a ^ 61) ^ (a >> 16);
|
||||
a = a + (a << 3);
|
||||
a = a ^ (a >> 4);
|
||||
a = a * 0x27d4eb2d;
|
||||
a = a ^ (a >> 15);
|
||||
return a;
|
||||
}
|
||||
|
||||
uint32_t ihash3( uint32_t a)
|
||||
{
|
||||
a = (a+0x479ab41d) + (a<<8);
|
||||
a = (a^0xe4aa10ce) ^ (a>>5);
|
||||
a = (a+0x9942f0a6) - (a<<14);
|
||||
a = (a^0x5aedd67d) ^ (a>>3);
|
||||
a = (a+0x17bea992) + (a<<7);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MainLoop* test() {
|
||||
|
||||
print_line(itos(Math::step_decimals( 0.0001 )));
|
||||
return NULL;
|
||||
|
||||
{
|
||||
|
||||
Vector<int32_t> hashes;
|
||||
List<StringName> tl;
|
||||
ObjectTypeDB::get_type_list(&tl);
|
||||
|
||||
|
||||
for (List<StringName>::Element *E=tl.front();E;E=E->next()) {
|
||||
|
||||
Vector<uint8_t> m5b = E->get().operator String().md5_buffer();
|
||||
hashes.push_back(hashes.size());
|
||||
|
||||
}
|
||||
|
||||
//hashes.resize(50);
|
||||
|
||||
for(int i=nearest_shift(hashes.size());i<20;i++) {
|
||||
|
||||
bool success=true;
|
||||
for(int s=0;s<10000;s++) {
|
||||
Set<uint32_t> existing;
|
||||
success=true;
|
||||
|
||||
for(int j=0;j<hashes.size();j++) {
|
||||
|
||||
uint32_t eh = ihash2(ihash3(hashes[j]+ihash(s)+s))&((1<<i)-1);
|
||||
if (existing.has(eh)) {
|
||||
success=false;
|
||||
break;
|
||||
}
|
||||
existing.insert(eh);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
print_line("success at "+itos(i)+"/"+itos(nearest_shift(hashes.size()))+" shift "+itos(s));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (success)
|
||||
break;
|
||||
}
|
||||
|
||||
print_line("DONE");
|
||||
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
{
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -43,38 +43,38 @@ class TestMainLoop : public MainLoop {
|
||||
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 );
|
||||
@ -89,7 +89,7 @@ public:
|
||||
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;
|
||||
}
|
||||
@ -99,14 +99,14 @@ public:
|
||||
|
||||
|
||||
virtual bool iteration(float p_time) {
|
||||
|
||||
|
||||
// VisualServer *vs=VisualServer::get_singleton();
|
||||
|
||||
|
||||
ofs+=p_time;
|
||||
return quit;
|
||||
}
|
||||
virtual void finish() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -47,7 +47,7 @@ class TestPhysicsMainLoop : public MainLoop {
|
||||
};
|
||||
|
||||
RID test_cube;
|
||||
|
||||
|
||||
RID plane;
|
||||
RID sphere;
|
||||
RID light;
|
||||
@ -74,13 +74,13 @@ class TestPhysicsMainLoop : public MainLoop {
|
||||
//t.basis.scale( Vector3(1.0,0.5,0.2) );
|
||||
vs->instance_set_transform(p_visual_instance,t);
|
||||
}
|
||||
|
||||
|
||||
bool quit;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods() {
|
||||
|
||||
|
||||
ObjectTypeDB::bind_method("body_changed_transform",&TestPhysicsMainLoop::body_changed_transform);
|
||||
}
|
||||
|
||||
@ -90,11 +90,11 @@ protected:
|
||||
PhysicsServer * ps = PhysicsServer::get_singleton();
|
||||
|
||||
RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape],scenario);
|
||||
RID body = ps->body_create(p_body,!p_active_default);
|
||||
RID body = ps->body_create(p_body,!p_active_default);
|
||||
ps->body_set_space(body,space);
|
||||
ps->body_set_param(body,PhysicsServer::BODY_PARAM_BOUNCE,0.0);
|
||||
//todo set space
|
||||
ps->body_add_shape(body,type_shape_map[p_shape]);
|
||||
ps->body_add_shape(body,type_shape_map[p_shape]);
|
||||
ps->body_set_force_integration_callback(body,this,"body_changed_transform",mesh_instance);
|
||||
|
||||
ps->body_set_state( body, PhysicsServer::BODY_STATE_TRANSFORM,p_location);
|
||||
@ -289,7 +289,7 @@ protected:
|
||||
|
||||
public:
|
||||
virtual void input_event(const InputEvent& p_event) {
|
||||
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) {
|
||||
|
||||
ofs_y-=p_event.mouse_motion.relative_y/200.0;
|
||||
@ -329,7 +329,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void request_quit() {
|
||||
|
||||
|
||||
quit=true;
|
||||
}
|
||||
virtual void init() {
|
||||
@ -388,53 +388,53 @@ public:
|
||||
/* Make Trimesh */
|
||||
quit=false;
|
||||
return;
|
||||
|
||||
|
||||
#if 0
|
||||
#define GRID_SIZE 5
|
||||
|
||||
|
||||
float grid[GRID_SIZE][GRID_SIZE];
|
||||
|
||||
|
||||
for (int i=0;i<GRID_SIZE;i++) {
|
||||
|
||||
|
||||
for (int j=0;j<GRID_SIZE;j++) {
|
||||
|
||||
|
||||
grid[j][i]=Math::random(0.0, 1.0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector<Vector3> faces;
|
||||
|
||||
|
||||
for (int i=1;i<GRID_SIZE;i++) {
|
||||
|
||||
|
||||
for (int j=1;j<GRID_SIZE;j++) {
|
||||
|
||||
|
||||
|
||||
|
||||
#define MAKE_VERTEX(m_x,m_z)\
|
||||
faces.push_back( Vector3( m_x-GRID_SIZE/2.0, grid[m_x][m_z], m_z-GRID_SIZE/2.0 )*3.0 )
|
||||
|
||||
|
||||
MAKE_VERTEX(i,j-1);
|
||||
MAKE_VERTEX(i,j);
|
||||
MAKE_VERTEX(i-1,j);
|
||||
|
||||
|
||||
MAKE_VERTEX(i-1,j-1);
|
||||
MAKE_VERTEX(i,j-1);
|
||||
MAKE_VERTEX(i-1,j);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
faces.clear();
|
||||
faces.clear();
|
||||
faces.push_back( Vector3(0,0,-5) );
|
||||
faces.push_back( Vector3(1,0,-1) );
|
||||
faces.push_back( Vector3(-1,-0,-1) );
|
||||
*/
|
||||
|
||||
|
||||
RID trimesh_shape = ps->shape_create();
|
||||
ps->shape_set_data(trimesh_shape, PhysicsServer::SHAPE_CONCAVE_POLYGON,faces);
|
||||
faces=ps->shape_get_shape(trimesh_shape, 0);
|
||||
Vector<Vector3> normals; // for drawing
|
||||
for (int i=0;i<faces.size()/3;i++) {
|
||||
|
||||
|
||||
Plane p( faces[i*3+0],faces[i*3+1], faces[i*3+2] );
|
||||
normals.push_back(p.normal);
|
||||
normals.push_back(p.normal);
|
||||
@ -448,11 +448,11 @@ public:
|
||||
RID trimesh_mat = vs->fixed_material_create();
|
||||
vs->material_generate( trimesh_mat, Color(1.0,0.5,0.3) );
|
||||
vs->mesh_surface_set_material( trimesh_mesh, 0, trimesh_mat );
|
||||
|
||||
|
||||
RID triins = vs->instance_create2(trimesh_mesh);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RID tribody = ps->body_create( PhysicsServer::BODY_MODE_STATIC, trimesh_shape);
|
||||
Transform tritrans = Transform( Matrix3(), Vector3(0,0,-2) );
|
||||
ps->body_set_state( tribody, PhysicsServer::BODY_STATE_TRANSFORM, tritrans );
|
||||
@ -483,7 +483,7 @@ public:
|
||||
return quit;
|
||||
}
|
||||
virtual void finish() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void test_joint() {
|
||||
@ -599,7 +599,7 @@ public:
|
||||
PhysicsServer::ShapeType type=shape_idx[i%4];
|
||||
//type=PhysicsServer::SHAPE_CONVEX_POLYGON;
|
||||
|
||||
Transform t;
|
||||
Transform t;
|
||||
|
||||
t.origin=Vector3(0.0*i,3.5+1.1*i,0.7+0.0*i);
|
||||
//t.origin=Vector3(-0.7+0.0*i,0.5+4.1*i,0);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -47,10 +47,10 @@ void test() {
|
||||
PyRun_SimpleString("b=Moch();\n");
|
||||
PyRun_SimpleString("b.mooch();\n");
|
||||
PyRun_SimpleString("b.meis();\n");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,16 +49,16 @@ class TestMainLoop : public MainLoop {
|
||||
RID viewport;
|
||||
RID light;
|
||||
RID scenario;
|
||||
|
||||
|
||||
struct InstanceInfo {
|
||||
|
||||
|
||||
RID instance;
|
||||
Transform base;
|
||||
Vector3 rot_axis;
|
||||
};
|
||||
|
||||
|
||||
List<InstanceInfo> instances;
|
||||
|
||||
|
||||
float ofs;
|
||||
bool quit;
|
||||
protected:
|
||||
@ -66,13 +66,13 @@ protected:
|
||||
|
||||
public:
|
||||
virtual void input_event(const InputEvent& p_event) {
|
||||
|
||||
|
||||
if (p_event.type==InputEvent::KEY && p_event.key.pressed)
|
||||
quit=true;
|
||||
}
|
||||
|
||||
virtual void init() {
|
||||
|
||||
|
||||
|
||||
print_line("INITIALIZING TEST RENDER");
|
||||
VisualServer *vs=VisualServer::get_singleton();
|
||||
@ -150,26 +150,26 @@ public:
|
||||
};
|
||||
|
||||
for (int i=0;i<object_count;i++) {
|
||||
|
||||
|
||||
InstanceInfo ii;
|
||||
|
||||
|
||||
|
||||
|
||||
ii.instance = vs->instance_create2( test_cube, scenario );
|
||||
|
||||
|
||||
|
||||
|
||||
ii.base.translate( Math::random(-20,20), Math::random(-20,20),Math::random(-20,18) );
|
||||
ii.base.rotate( Vector3(0,1,0), Math::randf() * Math_PI );
|
||||
ii.base.rotate( Vector3(1,0,0), Math::randf() * Math_PI );
|
||||
vs->instance_set_transform( ii.instance, ii.base );
|
||||
|
||||
vs->instance_set_transform( ii.instance, ii.base );
|
||||
|
||||
ii.rot_axis = Vector3( Math::random(-1,1), Math::random(-1,1), Math::random(-1,1) ).normalized();
|
||||
|
||||
|
||||
instances.push_back(ii);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
camera = vs->camera_create();
|
||||
|
||||
|
||||
// vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
|
||||
|
||||
viewport = vs->viewport_create();
|
||||
@ -226,9 +226,9 @@ public:
|
||||
ofs+=p_time*0.05;
|
||||
|
||||
//return quit;
|
||||
|
||||
|
||||
for(List<InstanceInfo>::Element *E=instances.front();E;E=E->next()) {
|
||||
|
||||
|
||||
Transform pre( Matrix3(E->get().rot_axis, ofs), Vector3() );
|
||||
vs->instance_set_transform( E->get().instance, pre * E->get().base );
|
||||
/*
|
||||
@ -238,7 +238,7 @@ public:
|
||||
instances.erase(E );
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
return quit;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -290,7 +290,7 @@ MainLoop* test() {
|
||||
|
||||
FileAccess *fa = FileAccess::open(test,FileAccess::READ);
|
||||
|
||||
if (!fa) {
|
||||
if (!fa) {
|
||||
ERR_FAIL_V(NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,152 +31,152 @@
|
||||
//#include "math_funcs.h"
|
||||
#include <stdio.h>
|
||||
#include "os/os.h"
|
||||
#include "drivers/nrex/regex.h"
|
||||
#include "drivers/trex/regex.h"
|
||||
|
||||
#include "test_string.h"
|
||||
|
||||
namespace TestString {
|
||||
|
||||
bool test_1() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 1: Assign from cstr\n");
|
||||
|
||||
|
||||
String s = "Hello";
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Hello\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n",s.c_str());
|
||||
|
||||
|
||||
return (wcscmp(s.c_str(),L"Hello")==0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_2() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 2: Assign from string (operator=)\n");
|
||||
|
||||
|
||||
String s = "Dolly";
|
||||
String t = s;
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Dolly\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n",t.c_str());
|
||||
|
||||
|
||||
return (wcscmp(t.c_str(),L"Dolly")==0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_3() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 3: Assign from c-string (copycon)\n");
|
||||
|
||||
|
||||
String s("Sheep");
|
||||
String t(s);
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Sheep\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n",t.c_str());
|
||||
|
||||
|
||||
return (wcscmp(t.c_str(),L"Sheep")==0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_4() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 4: Assign from c-widechar (operator=)\n");
|
||||
|
||||
|
||||
String s(L"Give me");
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Give me\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n",s.c_str());
|
||||
|
||||
|
||||
return (wcscmp(s.c_str(),L"Give me")==0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_5() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 5: Assign from c-widechar (copycon)\n");
|
||||
|
||||
|
||||
String s(L"Wool");
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tExpected: Wool\n");
|
||||
OS::get_singleton()->print("\tResulted: %ls\n",s.c_str());
|
||||
|
||||
|
||||
return (wcscmp(s.c_str(),L"Wool")==0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_6() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 6: comparisons (equal)\n");
|
||||
|
||||
|
||||
|
||||
|
||||
String s="Test Compare";
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
|
||||
|
||||
|
||||
if (! ( s=="Test Compare" ) )
|
||||
return false;
|
||||
|
||||
|
||||
if (! ( s==L"Test Compare" ) )
|
||||
return false;
|
||||
|
||||
|
||||
if (! ( s==String("Test Compare") ) )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_7() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 7: comparisons (unequal)\n");
|
||||
|
||||
|
||||
|
||||
|
||||
String s="Test Compare";
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
|
||||
|
||||
|
||||
if (! ( s!="Peanut" ) )
|
||||
return false;
|
||||
|
||||
|
||||
if (! ( s!=L"Coconut" ) )
|
||||
return false;
|
||||
|
||||
|
||||
if (! ( s!=String("Butter") ) )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_8() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 8: comparisons (operator<)\n");
|
||||
|
||||
|
||||
|
||||
|
||||
String s="Bees";
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tComparing to \"Bees\"\n");
|
||||
|
||||
|
||||
if ( ! (s < "Elephant") )
|
||||
return false;
|
||||
|
||||
|
||||
if ( s < L"Amber" )
|
||||
return false;
|
||||
|
||||
|
||||
if ( s < String("Beatrix") )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_9() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 9: Concatenation\n");
|
||||
|
||||
|
||||
|
||||
|
||||
String s;
|
||||
|
||||
|
||||
s+="Have";
|
||||
s+=' ';
|
||||
s+='a';
|
||||
@ -184,295 +184,299 @@ bool test_9() {
|
||||
s = s + L"Nice";
|
||||
s = s + " ";
|
||||
s = s + String("Day");
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tComparing to \"Have a Nice Day\"\n");
|
||||
|
||||
|
||||
return (s == "Have a Nice Day");
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_10() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n");
|
||||
|
||||
|
||||
if (! String("").empty())
|
||||
return false;
|
||||
|
||||
|
||||
if (String("Mellon").size() != 7)
|
||||
return false;
|
||||
|
||||
if (String("Oranges").length() != 7)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool test_11() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 11: Operator[]\n");
|
||||
|
||||
|
||||
String a="Kugar Sane";
|
||||
|
||||
|
||||
a[0]='S';
|
||||
a[6]='C';
|
||||
|
||||
|
||||
if (a != "Sugar Cane")
|
||||
return false;
|
||||
|
||||
|
||||
if (a[1]!='u')
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_12() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 12: case functions\n");
|
||||
|
||||
|
||||
|
||||
|
||||
String a="MoMoNgA";
|
||||
|
||||
|
||||
if (a.to_upper() != "MOMONGA")
|
||||
return false;
|
||||
|
||||
|
||||
if (a.nocasecmp_to("momonga")!=0)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_13() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 13: UTF8\n");
|
||||
|
||||
|
||||
/* how can i embed UTF in here? */
|
||||
|
||||
|
||||
static const CharType ustr[] = { 0x304A , 0x360F, 0x3088, 0x3046, 0 };
|
||||
// static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 };
|
||||
String s=ustr;
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tUnicode: %ls\n",ustr);
|
||||
s.parse_utf8( s.utf8().get_data() );
|
||||
OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n",s.c_str());
|
||||
|
||||
|
||||
return (s==ustr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_14() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 14: ASCII\n");
|
||||
|
||||
|
||||
String s = L"Primero Leche";
|
||||
OS::get_singleton()->print("\tAscii: %s\n",s.ascii().get_data());
|
||||
|
||||
|
||||
String t=s.ascii().get_data();
|
||||
return (s==t);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_15() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 15: substr\n");
|
||||
|
||||
|
||||
String s="Killer Baby";
|
||||
OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n",s.c_str(),s.substr(3,4).c_str());
|
||||
|
||||
|
||||
return (s.substr(3,4)=="ler ");
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_16() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 16: find\n");
|
||||
|
||||
|
||||
String s="Pretty Woman";
|
||||
OS::get_singleton()->print("\tString: %ls\n",s.c_str());
|
||||
OS::get_singleton()->print("\t\"tty\" is at %i pos.\n",s.find("tty"));
|
||||
OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n",s.find("Revenge of the Monster Truck"));
|
||||
|
||||
|
||||
if (s.find("tty")!=3)
|
||||
return false;
|
||||
|
||||
|
||||
if (s.find("Revenge of the Monster Truck")!=-1)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_17() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 17: find no case\n");
|
||||
|
||||
|
||||
String s="Pretty Whale";
|
||||
OS::get_singleton()->print("\tString: %ls\n",s.c_str());
|
||||
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA"));
|
||||
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck"));
|
||||
|
||||
|
||||
if (s.findn("WHA")!=7)
|
||||
return false;
|
||||
|
||||
|
||||
if (s.findn("Revenge of the Monster SawFish")!=-1)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_18() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 18: find no case\n");
|
||||
|
||||
|
||||
String s="Pretty Whale";
|
||||
OS::get_singleton()->print("\tString: %ls\n",s.c_str());
|
||||
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA"));
|
||||
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck"));
|
||||
|
||||
|
||||
if (s.findn("WHA")!=7)
|
||||
return false;
|
||||
|
||||
|
||||
if (s.findn("Revenge of the Monster SawFish")!=-1)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_19() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 19: Search & replace\n");
|
||||
|
||||
|
||||
String s="Happy Birthday, Anna!";
|
||||
OS::get_singleton()->print("\tString: %ls\n",s.c_str());
|
||||
|
||||
|
||||
s=s.replace("Birthday","Halloween");
|
||||
OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n",s.c_str());
|
||||
|
||||
|
||||
return (s=="Happy Halloween, Anna!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_20() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 20: Insertion\n");
|
||||
|
||||
|
||||
String s="Who is Frederic?";
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tString: %ls\n",s.c_str());
|
||||
s=s.insert( s.find("?")," Chopin" );
|
||||
OS::get_singleton()->print("\tInserted Chopin: %ls.\n",s.c_str());
|
||||
|
||||
|
||||
return (s=="Who is Frederic Chopin?");
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_21() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 21: Number -> String\n");
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tPi is %f\n",33.141593);
|
||||
OS::get_singleton()->print("\tPi String is %ls\n",String::num(3.141593).c_str());
|
||||
|
||||
|
||||
return String::num(3.141593)=="3.141593";
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_22() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 22: String -> Int\n");
|
||||
|
||||
|
||||
static const char* nums[4]={ "1237461283", "- 22", "0", " - 1123412" };
|
||||
static const int num[4]={ 1237461283, -22, 0, -1123412 };
|
||||
|
||||
|
||||
for (int i=0;i<4;i++) {
|
||||
OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n",nums[i],String(nums[i]).to_int());
|
||||
|
||||
|
||||
if (String(nums[i]).to_int()!=num[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_23() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 23: String -> Float\n");
|
||||
|
||||
|
||||
static const char* nums[4]={ "-12348298412.2", "0.05", "2.0002", " -0.0001" };
|
||||
static const double num[4]={ -12348298412.2, 0.05, 2.0002, -0.0001 };
|
||||
|
||||
|
||||
for (int i=0;i<4;i++) {
|
||||
OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n",nums[i],String(nums[i]).to_double());
|
||||
|
||||
|
||||
if ( ABS(String(nums[i]).to_double()-num[i])>0.00001)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool test_24() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 24: Slicing\n");
|
||||
|
||||
|
||||
String s="Mars,Jupiter,Saturn,Uranus";
|
||||
|
||||
|
||||
const char*slices[4]={"Mars","Jupiter","Saturn","Uranus"};
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n",s.c_str(),",");
|
||||
|
||||
|
||||
for (int i=0;i<s.get_slice_count(",");i++) {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\t\t%i- %ls\n",i+1,s.get_slice(",",i).c_str());
|
||||
|
||||
|
||||
|
||||
|
||||
if (s.get_slice(",",i)!=slices[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_25() {
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 25: Erasing\n");
|
||||
|
||||
|
||||
String s="Josephine is such a cute girl!";
|
||||
|
||||
|
||||
OS::get_singleton()->print("\tString: %ls\n",s.c_str());
|
||||
OS::get_singleton()->print("\tRemoving \"cute\"\n");
|
||||
|
||||
|
||||
s.erase(s.find("cute "),String("cute ").length());
|
||||
OS::get_singleton()->print("\tResult: %ls\n",s.c_str());
|
||||
|
||||
|
||||
|
||||
|
||||
return (s=="Josephine is such a girl!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool test_26() {
|
||||
|
||||
OS::get_singleton()->print("\n\nTest 26: RegEx\n");
|
||||
RegEx regexp("(.*):(.*)");
|
||||
List<String> captures;
|
||||
|
||||
int res = regexp.find("name:password");
|
||||
printf("\tmatch: %s\n", (res>=0)?"true":"false");
|
||||
bool match = regexp.match("name:password", &captures);
|
||||
printf("\tmatch: %s\n", match?"true":"false");
|
||||
|
||||
printf("\t%i captures:\n", regexp.get_capture_count());
|
||||
for (int i = 0; i<regexp.get_capture_count(); i++)
|
||||
{
|
||||
printf("%ls\n", regexp.get_capture(i).c_str());
|
||||
}
|
||||
return (res>=0);
|
||||
printf("\t%i captures:\n", captures.size());
|
||||
List<String>::Element *I = captures.front();
|
||||
while (I) {
|
||||
|
||||
printf("%ls\n", I->get().c_str());
|
||||
|
||||
I = I->next();
|
||||
};
|
||||
return captures.size();
|
||||
};
|
||||
|
||||
struct test_27_data {
|
||||
@ -516,7 +520,7 @@ bool test_28() {
|
||||
String format, output;
|
||||
Array args;
|
||||
bool error;
|
||||
|
||||
|
||||
// %%
|
||||
format = "fish %% frog";
|
||||
args.clear();
|
||||
@ -846,7 +850,7 @@ bool test_28() {
|
||||
typedef bool (*TestFunc)(void);
|
||||
|
||||
TestFunc test_funcs[] = {
|
||||
|
||||
|
||||
test_1,
|
||||
test_2,
|
||||
test_3,
|
||||
@ -876,18 +880,18 @@ TestFunc test_funcs[] = {
|
||||
test_27,
|
||||
test_28,
|
||||
0
|
||||
|
||||
|
||||
};
|
||||
|
||||
MainLoop* test() {
|
||||
|
||||
|
||||
/** A character length != wchar_t may be forced, so the tests wont work */
|
||||
|
||||
|
||||
ERR_FAIL_COND_V( sizeof(CharType) != sizeof(wchar_t), NULL );
|
||||
|
||||
|
||||
int count=0;
|
||||
int passed=0;
|
||||
|
||||
|
||||
while(true) {
|
||||
if (!test_funcs[count])
|
||||
break;
|
||||
@ -895,17 +899,17 @@ MainLoop* test() {
|
||||
if (pass)
|
||||
passed++;
|
||||
OS::get_singleton()->print("\t%s\n",pass?"PASS":"FAILED");
|
||||
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
OS::get_singleton()->print("\n\n\n");
|
||||
OS::get_singleton()->print("*************\n");
|
||||
OS::get_singleton()->print("***TOTALS!***\n");
|
||||
OS::get_singleton()->print("*************\n");
|
||||
|
||||
OS::get_singleton()->print("Passed %i of %i tests\n", passed, count);
|
||||
|
||||
|
||||
OS::get_singleton()->print("Passed %i of %i tests\n",count,passed);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -63,3 +63,5 @@ SConscript('bind/SCsub');
|
||||
lib = env.Library("core",env.core_sources)
|
||||
|
||||
env.Prepend(LIBS=[lib])
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,58 +150,9 @@ void Array::erase(const Variant& p_value) {
|
||||
_p->array.erase(p_value);
|
||||
}
|
||||
|
||||
int Array::find(const Variant& p_value, int p_from) const {
|
||||
int Array::find(const Variant& p_value) const {
|
||||
|
||||
return _p->array.find(p_value, p_from);
|
||||
}
|
||||
|
||||
int Array::rfind(const Variant& p_value, int p_from) const {
|
||||
|
||||
if (_p->array.size() == 0)
|
||||
return -1;
|
||||
|
||||
if (p_from < 0) {
|
||||
// Relative offset from the end
|
||||
p_from = _p->array.size() + p_from;
|
||||
}
|
||||
if (p_from < 0 || p_from >= _p->array.size()) {
|
||||
// Limit to array boundaries
|
||||
p_from = _p->array.size() - 1;
|
||||
}
|
||||
|
||||
for (int i=p_from; i>=0; i--) {
|
||||
|
||||
if(_p->array[i] == p_value){
|
||||
return i;
|
||||
};
|
||||
};
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Array::find_last(const Variant& p_value) const {
|
||||
|
||||
return rfind(p_value);
|
||||
}
|
||||
|
||||
int Array::count(const Variant& p_value) const {
|
||||
|
||||
if(_p->array.size() == 0)
|
||||
return 0;
|
||||
|
||||
int amount=0;
|
||||
for (int i=0; i<_p->array.size(); i++) {
|
||||
|
||||
if(_p->array[i] == p_value){
|
||||
amount++;
|
||||
};
|
||||
};
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
bool Array::has(const Variant& p_value) const {
|
||||
return _p->array.find(p_value, 0) != -1;
|
||||
return _p->array.find(p_value);
|
||||
}
|
||||
|
||||
void Array::remove(int p_pos) {
|
||||
@ -271,24 +222,6 @@ void Array::invert(){
|
||||
}
|
||||
|
||||
|
||||
void Array::push_front(const Variant& p_value) {
|
||||
|
||||
_p->array.insert(0,p_value);
|
||||
}
|
||||
|
||||
void Array::pop_back(){
|
||||
|
||||
if (!_p->array.empty())
|
||||
_p->array.resize( _p->array.size() -1 );
|
||||
|
||||
}
|
||||
void Array::pop_front(){
|
||||
|
||||
if (!_p->array.empty())
|
||||
_p->array.remove(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Array::Array(const Array& p_from) {
|
||||
|
||||
|
||||
14
core/array.h
14
core/array.h
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -53,7 +53,7 @@ public:
|
||||
bool empty() const;
|
||||
void clear();
|
||||
|
||||
bool is_shared() const;
|
||||
bool is_shared() const;
|
||||
|
||||
bool operator==(const Array& p_array) const;
|
||||
|
||||
@ -71,18 +71,10 @@ public:
|
||||
void sort_custom(Object *p_obj,const StringName& p_function);
|
||||
void invert();
|
||||
|
||||
int find(const Variant& p_value, int p_from=0) const;
|
||||
int rfind(const Variant& p_value, int p_from=-1) const;
|
||||
int find_last(const Variant& p_value) const;
|
||||
int count(const Variant& p_value) const;
|
||||
bool has(const Variant& p_value) const;
|
||||
int find(const Variant& p_value) const;
|
||||
|
||||
void erase(const Variant& p_value);
|
||||
|
||||
void push_front(const Variant& p_value);
|
||||
void pop_back();
|
||||
void pop_front();
|
||||
|
||||
Array(const Array& p_from);
|
||||
Array(bool p_shared=false);
|
||||
~Array();
|
||||
|
||||
35
core/balloon_allocator.h
Normal file
35
core/balloon_allocator.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************/
|
||||
/* balloon_allocator.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2015 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 BALLOON_ALLOCATOR_H
|
||||
#define BALLOON_ALLOCATOR_H
|
||||
|
||||
#include "os/memory.h"
|
||||
|
||||
#include "allocators.h"
|
||||
#endif // BALLOON_ALLOCATOR_H
|
||||
@ -3,3 +3,5 @@ Import('env')
|
||||
env.add_source_files(env.core_sources,"*.cpp")
|
||||
|
||||
Export('env')
|
||||
|
||||
|
||||
|
||||
@ -1,31 +1,3 @@
|
||||
/*************************************************************************/
|
||||
/* core_bind.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 "core_bind.h"
|
||||
#include "os/os.h"
|
||||
#include "geometry.h"
|
||||
@ -34,29 +6,6 @@
|
||||
#include "core/globals.h"
|
||||
#include "io/file_access_encrypted.h"
|
||||
#include "os/keyboard.h"
|
||||
|
||||
/**
|
||||
* Time constants borrowed from loc_time.h
|
||||
*/
|
||||
#define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */
|
||||
#define SECS_DAY (24L * 60L * 60L)
|
||||
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
|
||||
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
|
||||
#define SECOND_KEY "second"
|
||||
#define MINUTE_KEY "minute"
|
||||
#define HOUR_KEY "hour"
|
||||
#define DAY_KEY "day"
|
||||
#define MONTH_KEY "month"
|
||||
#define YEAR_KEY "year"
|
||||
#define WEEKDAY_KEY "weekday"
|
||||
#define DST_KEY "dst"
|
||||
|
||||
/// Table of number of days in each month (for regular year and leap year)
|
||||
static const unsigned int MONTH_DAYS_TABLE[2][12] = {
|
||||
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
||||
};
|
||||
|
||||
_ResourceLoader *_ResourceLoader::singleton=NULL;
|
||||
|
||||
Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String& p_path,const String& p_type_hint) {
|
||||
@ -106,21 +55,15 @@ bool _ResourceLoader::has(const String &p_path) {
|
||||
return ResourceCache::has(local_path);
|
||||
};
|
||||
|
||||
Ref<ResourceImportMetadata> _ResourceLoader::load_import_metadata(const String& p_path) {
|
||||
|
||||
return ResourceLoader::load_import_metadata(p_path);
|
||||
}
|
||||
|
||||
void _ResourceLoader::_bind_methods() {
|
||||
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
|
||||
ObjectTypeDB::bind_method(_MD("load_import_metadata:ResourceImportMetadata","path"),&_ResourceLoader::load_import_metadata);
|
||||
ObjectTypeDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
|
||||
ObjectTypeDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
|
||||
ObjectTypeDB::bind_method(_MD("get_dependencies","path"),&_ResourceLoader::get_dependencies);
|
||||
ObjectTypeDB::bind_method(_MD("has","path"),&_ResourceLoader::has);
|
||||
ObjectTypeDB::bind_method(_MD("get_dependencies"),&_ResourceLoader::get_dependencies);
|
||||
ObjectTypeDB::bind_method(_MD("has"),&_ResourceLoader::has);
|
||||
}
|
||||
|
||||
_ResourceLoader::_ResourceLoader() {
|
||||
@ -153,7 +96,7 @@ _ResourceSaver *_ResourceSaver::singleton=NULL;
|
||||
|
||||
void _ResourceSaver::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("save","path","resource:Resource","flags"),&_ResourceSaver::save,DEFVAL(0));
|
||||
ObjectTypeDB::bind_method(_MD("save","path","resource:Resource"),&_ResourceSaver::save, DEFVAL(0));
|
||||
ObjectTypeDB::bind_method(_MD("get_recognized_extensions","type"),&_ResourceSaver::get_recognized_extensions);
|
||||
|
||||
BIND_CONSTANT(FLAG_RELATIVE_PATHS);
|
||||
@ -254,11 +197,6 @@ Size2 _OS::get_screen_size(int p_screen) const {
|
||||
return OS::get_singleton()->get_screen_size(p_screen);
|
||||
}
|
||||
|
||||
int _OS::get_screen_dpi(int p_screen) const {
|
||||
|
||||
return OS::get_singleton()->get_screen_dpi(p_screen);
|
||||
}
|
||||
|
||||
Point2 _OS::get_window_position() const {
|
||||
return OS::get_singleton()->get_window_position();
|
||||
}
|
||||
@ -307,13 +245,6 @@ bool _OS::is_window_maximized() const {
|
||||
return OS::get_singleton()->is_window_maximized();
|
||||
}
|
||||
|
||||
void _OS::set_borderless_window(bool p_borderless) {
|
||||
OS::get_singleton()->set_borderless_window(p_borderless);
|
||||
}
|
||||
|
||||
bool _OS::get_borderless_window() const {
|
||||
return OS::get_singleton()->get_borderless_window();
|
||||
}
|
||||
|
||||
void _OS::set_use_file_access_save_and_swap(bool p_enable) {
|
||||
|
||||
@ -435,18 +366,6 @@ String _OS::get_locale() const {
|
||||
return OS::get_singleton()->get_locale();
|
||||
}
|
||||
|
||||
String _OS::get_latin_keyboard_variant() const {
|
||||
switch( OS::get_singleton()->get_latin_keyboard_variant() ) {
|
||||
case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY";
|
||||
case OS::LATIN_KEYBOARD_QWERTZ: return "QWERTZ";
|
||||
case OS::LATIN_KEYBOARD_AZERTY: return "AZERTY";
|
||||
case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY";
|
||||
case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK";
|
||||
case OS::LATIN_KEYBOARD_NEO : return "NEO";
|
||||
default: return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
String _OS::get_model_name() const {
|
||||
|
||||
return OS::get_singleton()->get_model_name();
|
||||
@ -471,21 +390,6 @@ bool _OS::is_ok_left_and_cancel_right() const {
|
||||
return OS::get_singleton()->get_swap_ok_cancel();
|
||||
}
|
||||
|
||||
Error _OS::set_thread_name(const String& p_name) {
|
||||
|
||||
return Thread::set_name(p_name);
|
||||
};
|
||||
|
||||
void _OS::set_use_vsync(bool p_enable) {
|
||||
OS::get_singleton()->set_use_vsync(p_enable);
|
||||
}
|
||||
|
||||
bool _OS::is_vsnc_enabled() const {
|
||||
|
||||
return OS::get_singleton()->is_vsnc_enabled();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
enum Weekday {
|
||||
DAY_SUNDAY,
|
||||
@ -553,216 +457,33 @@ void _OS::set_icon(const Image& p_icon) {
|
||||
OS::get_singleton()->set_icon(p_icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current datetime with consideration for utc and
|
||||
* dst
|
||||
*/
|
||||
Dictionary _OS::get_datetime(bool utc) const {
|
||||
Dictionary _OS::get_date() const {
|
||||
|
||||
Dictionary dated = get_date(utc);
|
||||
Dictionary timed = get_time(utc);
|
||||
|
||||
List<Variant> keys;
|
||||
timed.get_key_list(&keys);
|
||||
|
||||
for(int i = 0; i < keys.size(); i++) {
|
||||
dated[keys[i]] = timed[keys[i]];
|
||||
}
|
||||
|
||||
return dated;
|
||||
}
|
||||
|
||||
Dictionary _OS::get_date(bool utc) const {
|
||||
|
||||
OS::Date date = OS::get_singleton()->get_date(utc);
|
||||
OS::Date date = OS::get_singleton()->get_date();
|
||||
Dictionary dated;
|
||||
dated[YEAR_KEY]=date.year;
|
||||
dated[MONTH_KEY]=date.month;
|
||||
dated[DAY_KEY]=date.day;
|
||||
dated[WEEKDAY_KEY]=date.weekday;
|
||||
dated[DST_KEY]=date.dst;
|
||||
dated["year"]=date.year;
|
||||
dated["month"]=date.month;
|
||||
dated["day"]=date.day;
|
||||
dated["weekday"]=date.weekday;
|
||||
dated["dst"]=date.dst;
|
||||
return dated;
|
||||
|
||||
|
||||
}
|
||||
Dictionary _OS::get_time() const {
|
||||
|
||||
Dictionary _OS::get_time(bool utc) const {
|
||||
|
||||
OS::Time time = OS::get_singleton()->get_time(utc);
|
||||
OS::Time time = OS::get_singleton()->get_time();
|
||||
Dictionary timed;
|
||||
timed[HOUR_KEY]=time.hour;
|
||||
timed[MINUTE_KEY]=time.min;
|
||||
timed[SECOND_KEY]=time.sec;
|
||||
timed["hour"]=time.hour;
|
||||
timed["minute"]=time.min;
|
||||
timed["second"]=time.sec;
|
||||
return timed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a epoch time value from a dictionary of time values
|
||||
* @p datetime must be populated with the following keys:
|
||||
* day, hour, minute, month, second, year. (dst is ignored).
|
||||
*
|
||||
* You can pass the output from
|
||||
* get_datetime_from_unix_time directly into this function
|
||||
*
|
||||
* @param datetime dictionary of date and time values to convert
|
||||
*
|
||||
* @return epoch calculated
|
||||
*/
|
||||
uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
|
||||
|
||||
// Bunch of conversion constants
|
||||
static const unsigned int SECONDS_PER_MINUTE = 60;
|
||||
static const unsigned int MINUTES_PER_HOUR = 60;
|
||||
static const unsigned int HOURS_PER_DAY = 24;
|
||||
static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR *
|
||||
SECONDS_PER_MINUTE;
|
||||
static const unsigned int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
|
||||
|
||||
// Get all time values from the dictionary, set to zero if it doesn't exist.
|
||||
// Risk incorrect calculation over throwing errors
|
||||
unsigned int second = ((datetime.has(SECOND_KEY))?
|
||||
static_cast<unsigned int>(datetime[SECOND_KEY]): 0);
|
||||
unsigned int minute = ((datetime.has(MINUTE_KEY))?
|
||||
static_cast<unsigned int>(datetime[MINUTE_KEY]): 0);
|
||||
unsigned int hour = ((datetime.has(HOUR_KEY))?
|
||||
static_cast<unsigned int>(datetime[HOUR_KEY]): 0);
|
||||
unsigned int day = ((datetime.has(DAY_KEY))?
|
||||
static_cast<unsigned int>(datetime[DAY_KEY]): 0);
|
||||
unsigned int month = ((datetime.has(MONTH_KEY))?
|
||||
static_cast<unsigned int>(datetime[MONTH_KEY]) -1: 0);
|
||||
unsigned int year = ((datetime.has(YEAR_KEY))?
|
||||
static_cast<unsigned int>(datetime[YEAR_KEY]):0);
|
||||
|
||||
/// How many days come before each month (0-12)
|
||||
static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] =
|
||||
{
|
||||
/* Normal years. */
|
||||
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
|
||||
/* Leap years. */
|
||||
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
|
||||
};
|
||||
|
||||
ERR_EXPLAIN("Invalid second value of: " + itos(second));
|
||||
ERR_FAIL_COND_V( second > 59, 0);
|
||||
|
||||
ERR_EXPLAIN("Invalid minute value of: " + itos(minute));
|
||||
ERR_FAIL_COND_V( minute > 59, 0);
|
||||
|
||||
ERR_EXPLAIN("Invalid hour value of: " + itos(hour));
|
||||
ERR_FAIL_COND_V( hour > 23, 0);
|
||||
|
||||
ERR_EXPLAIN("Invalid month value of: " + itos(month+1));
|
||||
ERR_FAIL_COND_V( month+1 > 12, 0);
|
||||
|
||||
// Do this check after month is tested as valid
|
||||
ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger "
|
||||
"than "+ itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month]));
|
||||
ERR_FAIL_COND_V( day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month], 0);
|
||||
|
||||
// Calculate all the seconds from months past in this year
|
||||
uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR =
|
||||
DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY;
|
||||
|
||||
uint64_t SECONDS_FROM_YEARS_PAST = 0;
|
||||
for(unsigned int iyear = EPOCH_YR; iyear < year; iyear++) {
|
||||
|
||||
SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) *
|
||||
SECONDS_PER_DAY;
|
||||
}
|
||||
|
||||
uint64_t epoch =
|
||||
second +
|
||||
minute * SECONDS_PER_MINUTE +
|
||||
hour * SECONDS_PER_HOUR +
|
||||
// Subtract 1 from day, since the current day isn't over yet
|
||||
// and we cannot count all 24 hours.
|
||||
(day-1) * SECONDS_PER_DAY +
|
||||
SECONDS_FROM_MONTHS_PAST_THIS_YEAR +
|
||||
SECONDS_FROM_YEARS_PAST;
|
||||
return epoch;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a dictionary of time values when given epoch time
|
||||
*
|
||||
* Dictionary Time values will be a union if values from #get_time
|
||||
* and #get_date dictionaries (with the exception of dst =
|
||||
* day light standard time, as it cannot be determined from epoch)
|
||||
*
|
||||
* @param unix_time_val epoch time to convert
|
||||
*
|
||||
* @return dictionary of date and time values
|
||||
*/
|
||||
Dictionary _OS::get_datetime_from_unix_time( uint64_t unix_time_val) const {
|
||||
|
||||
// Just fail if unix time is negative (when interpreted as an int).
|
||||
// This means the user passed in a negative value by accident
|
||||
ERR_EXPLAIN("unix_time_val was really huge!"+ itos(unix_time_val) +
|
||||
" You probably passed in a negative value!");
|
||||
ERR_FAIL_COND_V( (int64_t)unix_time_val < 0, Dictionary());
|
||||
|
||||
OS::Date date;
|
||||
OS::Time time;
|
||||
|
||||
unsigned long dayclock, dayno;
|
||||
int year = EPOCH_YR;
|
||||
|
||||
dayclock = (unsigned long)unix_time_val % SECS_DAY;
|
||||
dayno = (unsigned long)unix_time_val / SECS_DAY;
|
||||
|
||||
time.sec = dayclock % 60;
|
||||
time.min = (dayclock % 3600) / 60;
|
||||
time.hour = dayclock / 3600;
|
||||
|
||||
/* day 0 was a thursday */
|
||||
date.weekday = static_cast<OS::Weekday>((dayno + 4) % 7);
|
||||
|
||||
while (dayno >= YEARSIZE(year)) {
|
||||
dayno -= YEARSIZE(year);
|
||||
year++;
|
||||
}
|
||||
|
||||
date.year = year;
|
||||
|
||||
size_t imonth = 0;
|
||||
|
||||
while (dayno >= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth]) {
|
||||
dayno -= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth];
|
||||
imonth++;
|
||||
}
|
||||
|
||||
/// Add 1 to month to make sure months are indexed starting at 1
|
||||
date.month = static_cast<OS::Month>(imonth+1);
|
||||
|
||||
date.day = dayno + 1;
|
||||
|
||||
Dictionary timed;
|
||||
timed[HOUR_KEY]=time.hour;
|
||||
timed[MINUTE_KEY]=time.min;
|
||||
timed[SECOND_KEY]=time.sec;
|
||||
timed[YEAR_KEY]=date.year;
|
||||
timed[MONTH_KEY]=date.month;
|
||||
timed[DAY_KEY]=date.day;
|
||||
timed[WEEKDAY_KEY]=date.weekday;
|
||||
|
||||
return timed;
|
||||
}
|
||||
|
||||
Dictionary _OS::get_time_zone_info() const {
|
||||
OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
|
||||
Dictionary infod;
|
||||
infod["bias"] = info.bias;
|
||||
infod["name"] = info.name;
|
||||
return infod;
|
||||
}
|
||||
|
||||
uint64_t _OS::get_unix_time() const {
|
||||
|
||||
return OS::get_singleton()->get_unix_time();
|
||||
}
|
||||
|
||||
uint64_t _OS::get_system_time_secs() const {
|
||||
return OS::get_singleton()->get_system_time_secs();
|
||||
}
|
||||
};
|
||||
|
||||
void _OS::delay_usec(uint32_t p_usec) const {
|
||||
|
||||
@ -857,6 +578,7 @@ void _OS::print_all_textures_by_size() {
|
||||
|
||||
for(List<_OSCoreBindImg>::Element *E=imgs.front();E;E=E->next()) {
|
||||
|
||||
print_line(E->get().path+" - "+String::humanize_size(E->get().vram)+" ("+E->get().size+") - total:"+String::humanize_size(total) );
|
||||
total-=E->get().vram;
|
||||
}
|
||||
}
|
||||
@ -890,21 +612,23 @@ void _OS::print_resources_by_type(const Vector<String>& p_types) {
|
||||
|
||||
|
||||
type_count[r->get_type()]++;
|
||||
|
||||
print_line(r->get_type()+": "+r->get_path());
|
||||
|
||||
List<String> metas;
|
||||
r->get_meta_list(&metas);
|
||||
for (List<String>::Element* me = metas.front(); me; me = me->next()) {
|
||||
print_line(" "+String(me->get()) + ": " + r->get_meta(me->get()));
|
||||
};
|
||||
}
|
||||
|
||||
for(Map<String,int>::Element *E=type_count.front();E;E=E->next()) {
|
||||
|
||||
print_line(E->key()+" count: "+itos(E->get()));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
bool _OS::has_virtual_keyboard() const {
|
||||
return OS::get_singleton()->has_virtual_keyboard();
|
||||
}
|
||||
|
||||
void _OS::show_virtual_keyboard(const String& p_existing_text) {
|
||||
OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2());
|
||||
}
|
||||
|
||||
void _OS::hide_virtual_keyboard() {
|
||||
OS::get_singleton()->hide_virtual_keyboard();
|
||||
}
|
||||
|
||||
void _OS::print_all_resources(const String& p_to_file ) {
|
||||
|
||||
@ -946,20 +670,11 @@ void _OS::native_video_pause() {
|
||||
OS::get_singleton()->native_video_pause();
|
||||
};
|
||||
|
||||
void _OS::native_video_unpause() {
|
||||
OS::get_singleton()->native_video_unpause();
|
||||
};
|
||||
|
||||
void _OS::native_video_stop() {
|
||||
|
||||
OS::get_singleton()->native_video_stop();
|
||||
};
|
||||
|
||||
void _OS::request_attention() {
|
||||
|
||||
OS::get_singleton()->request_attention();
|
||||
}
|
||||
|
||||
bool _OS::is_debug_build() const {
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
@ -970,26 +685,6 @@ bool _OS::is_debug_build() const {
|
||||
|
||||
}
|
||||
|
||||
void _OS::set_screen_orientation(ScreenOrientation p_orientation) {
|
||||
|
||||
OS::get_singleton()->set_screen_orientation(OS::ScreenOrientation(p_orientation));
|
||||
}
|
||||
|
||||
_OS::ScreenOrientation _OS::get_screen_orientation() const {
|
||||
|
||||
return ScreenOrientation(OS::get_singleton()->get_screen_orientation());
|
||||
}
|
||||
|
||||
void _OS::set_keep_screen_on(bool p_enabled) {
|
||||
|
||||
OS::get_singleton()->set_keep_screen_on(p_enabled);
|
||||
}
|
||||
|
||||
bool _OS::is_keep_screen_on() const {
|
||||
|
||||
return OS::get_singleton()->is_keep_screen_on();
|
||||
}
|
||||
|
||||
String _OS::get_system_dir(SystemDir p_dir) const {
|
||||
|
||||
return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
|
||||
@ -1013,16 +708,6 @@ int _OS::find_scancode_from_string(const String& p_code) const {
|
||||
return find_keycode(p_code);
|
||||
}
|
||||
|
||||
void _OS::alert(const String& p_alert,const String& p_title) {
|
||||
|
||||
OS::get_singleton()->alert(p_alert,p_title);
|
||||
}
|
||||
|
||||
Dictionary _OS::get_engine_version() const {
|
||||
|
||||
return OS::get_singleton()->get_engine_version();
|
||||
}
|
||||
|
||||
_OS *_OS::singleton=NULL;
|
||||
|
||||
void _OS::_bind_methods() {
|
||||
@ -1045,7 +730,6 @@ void _OS::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("set_current_screen","screen"),&_OS::set_current_screen);
|
||||
ObjectTypeDB::bind_method(_MD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0));
|
||||
ObjectTypeDB::bind_method(_MD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0));
|
||||
ObjectTypeDB::bind_method(_MD("get_screen_dpi","screen"),&_OS::get_screen_dpi,DEFVAL(0));
|
||||
ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position);
|
||||
ObjectTypeDB::bind_method(_MD("set_window_position","position"),&_OS::set_window_position);
|
||||
ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size);
|
||||
@ -1058,16 +742,7 @@ void _OS::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("is_window_minimized"),&_OS::is_window_minimized);
|
||||
ObjectTypeDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized);
|
||||
ObjectTypeDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized);
|
||||
ObjectTypeDB::bind_method(_MD("request_attention"), &_OS::request_attention);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
|
||||
ObjectTypeDB::bind_method(_MD("get_borderless_window"), &_OS::get_borderless_window);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation);
|
||||
ObjectTypeDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on);
|
||||
ObjectTypeDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second);
|
||||
ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second);
|
||||
@ -1099,25 +774,17 @@ void _OS::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args);
|
||||
ObjectTypeDB::bind_method(_MD("get_main_loop"),&_OS::get_main_loop);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false));
|
||||
ObjectTypeDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false));
|
||||
ObjectTypeDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false));
|
||||
ObjectTypeDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info);
|
||||
ObjectTypeDB::bind_method(_MD("get_date"),&_OS::get_date);
|
||||
ObjectTypeDB::bind_method(_MD("get_time"),&_OS::get_time);
|
||||
ObjectTypeDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time);
|
||||
ObjectTypeDB::bind_method(_MD("get_datetime_from_unix_time", "unix_time_val"),
|
||||
&_OS::get_datetime_from_unix_time);
|
||||
ObjectTypeDB::bind_method(_MD("get_unix_time_from_datetime", "datetime"),
|
||||
&_OS::get_unix_time_from_datetime);
|
||||
ObjectTypeDB::bind_method(_MD("get_system_time_secs"), &_OS::get_system_time_secs);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_icon","icon"),&_OS::set_icon);
|
||||
ObjectTypeDB::bind_method(_MD("set_icon"),&_OS::set_icon);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("delay_usec","usec"),&_OS::delay_usec);
|
||||
ObjectTypeDB::bind_method(_MD("delay_msec","msec"),&_OS::delay_msec);
|
||||
ObjectTypeDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec);
|
||||
ObjectTypeDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec);
|
||||
ObjectTypeDB::bind_method(_MD("get_locale"),&_OS::get_locale);
|
||||
ObjectTypeDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant);
|
||||
ObjectTypeDB::bind_method(_MD("get_model_name"),&_OS::get_model_name);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_custom_level"),&_OS::get_custom_level);
|
||||
@ -1134,9 +801,6 @@ void _OS::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("dump_memory_to_file","file"),&_OS::dump_memory_to_file);
|
||||
ObjectTypeDB::bind_method(_MD("dump_resources_to_file","file"),&_OS::dump_resources_to_file);
|
||||
ObjectTypeDB::bind_method(_MD("has_virtual_keyboard"),&_OS::has_virtual_keyboard);
|
||||
ObjectTypeDB::bind_method(_MD("show_virtual_keyboard", "existing_text"),&_OS::show_virtual_keyboard,DEFVAL(""));
|
||||
ObjectTypeDB::bind_method(_MD("hide_virtual_keyboard"),&_OS::hide_virtual_keyboard);
|
||||
ObjectTypeDB::bind_method(_MD("print_resources_in_use","short"),&_OS::print_resources_in_use,DEFVAL(false));
|
||||
ObjectTypeDB::bind_method(_MD("print_all_resources","tofile"),&_OS::print_all_resources,DEFVAL(""));
|
||||
|
||||
@ -1153,13 +817,12 @@ void _OS::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("get_frames_per_second"),&_OS::get_frames_per_second);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
|
||||
ObjectTypeDB::bind_method(_MD("print_resources_by_type","types"),&_OS::print_resources_by_type);
|
||||
ObjectTypeDB::bind_method(_MD("print_resources_by_type"),&_OS::print_resources_by_type);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("native_video_play","path","volume","audio_track","subtitle_track"),&_OS::native_video_play);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_play"),&_OS::native_video_play);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_unpause"),&_OS::native_video_unpause);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string);
|
||||
ObjectTypeDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
|
||||
@ -1167,14 +830,7 @@ void _OS::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("alert","text","title"),&_OS::alert,DEFVAL("Alert!"));
|
||||
|
||||
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("get_engine_version"),&_OS::get_engine_version);
|
||||
|
||||
BIND_CONSTANT( DAY_SUNDAY );
|
||||
BIND_CONSTANT( DAY_MONDAY );
|
||||
@ -1197,14 +853,6 @@ void _OS::_bind_methods() {
|
||||
BIND_CONSTANT( MONTH_NOVEMBER );
|
||||
BIND_CONSTANT( MONTH_DECEMBER );
|
||||
|
||||
BIND_CONSTANT( SCREEN_ORIENTATION_LANDSCAPE );
|
||||
BIND_CONSTANT( SCREEN_ORIENTATION_PORTRAIT );
|
||||
BIND_CONSTANT( SCREEN_ORIENTATION_REVERSE_LANDSCAPE );
|
||||
BIND_CONSTANT( SCREEN_ORIENTATION_REVERSE_PORTRAIT );
|
||||
BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR_LANDSCAPE );
|
||||
BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR_PORTRAIT );
|
||||
BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR );
|
||||
|
||||
BIND_CONSTANT( SYSTEM_DIR_DESKTOP);
|
||||
BIND_CONSTANT( SYSTEM_DIR_DCIM );
|
||||
BIND_CONSTANT( SYSTEM_DIR_DOCUMENTS );
|
||||
@ -1592,12 +1240,7 @@ DVector<uint8_t> _File::get_buffer(int p_length) const{
|
||||
|
||||
String _File::get_as_text() const {
|
||||
|
||||
ERR_FAIL_COND_V(!f, String());
|
||||
|
||||
String text;
|
||||
size_t original_pos = f->get_pos();
|
||||
f->seek(0);
|
||||
|
||||
String l = get_line();
|
||||
while(!eof_reached()) {
|
||||
text+=l+"\n";
|
||||
@ -1605,27 +1248,10 @@ String _File::get_as_text() const {
|
||||
}
|
||||
text+=l;
|
||||
|
||||
f->seek(original_pos);
|
||||
|
||||
return text;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
String _File::get_md5(const String& p_path) const {
|
||||
|
||||
return FileAccess::get_md5(p_path);
|
||||
|
||||
}
|
||||
|
||||
String _File::get_sha256(const String& p_path) const {
|
||||
|
||||
return FileAccess::get_sha256(p_path);
|
||||
|
||||
}
|
||||
|
||||
|
||||
String _File::get_line() const{
|
||||
|
||||
ERR_FAIL_COND_V(!f,String());
|
||||
@ -1633,9 +1259,9 @@ String _File::get_line() const{
|
||||
|
||||
}
|
||||
|
||||
Vector<String> _File::get_csv_line(String delim) const {
|
||||
Vector<String> _File::get_csv_line() const {
|
||||
ERR_FAIL_COND_V(!f,Vector<String>());
|
||||
return f->get_csv_line(delim);
|
||||
return f->get_csv_line();
|
||||
}
|
||||
|
||||
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
|
||||
@ -1814,13 +1440,11 @@ void _File::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("get_buffer","len"),&_File::get_buffer);
|
||||
ObjectTypeDB::bind_method(_MD("get_line"),&_File::get_line);
|
||||
ObjectTypeDB::bind_method(_MD("get_as_text"),&_File::get_as_text);
|
||||
ObjectTypeDB::bind_method(_MD("get_md5","path"),&_File::get_md5);
|
||||
ObjectTypeDB::bind_method(_MD("get_sha256","path"),&_File::get_sha256);
|
||||
ObjectTypeDB::bind_method(_MD("get_endian_swap"),&_File::get_endian_swap);
|
||||
ObjectTypeDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap);
|
||||
ObjectTypeDB::bind_method(_MD("get_error:Error"),&_File::get_error);
|
||||
ObjectTypeDB::bind_method(_MD("get_var"),&_File::get_var);
|
||||
ObjectTypeDB::bind_method(_MD("get_csv_line","delim"),&_File::get_csv_line,DEFVAL(","));
|
||||
ObjectTypeDB::bind_method(_MD("get_csv_line"),&_File::get_csv_line);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("store_8","value"),&_File::store_8);
|
||||
ObjectTypeDB::bind_method(_MD("store_16","value"),&_File::store_16);
|
||||
@ -1842,7 +1466,6 @@ void _File::_bind_methods() {
|
||||
BIND_CONSTANT( READ );
|
||||
BIND_CONSTANT( WRITE );
|
||||
BIND_CONSTANT( READ_WRITE );
|
||||
BIND_CONSTANT( WRITE_READ );
|
||||
}
|
||||
|
||||
_File::_File(){
|
||||
@ -1924,57 +1547,29 @@ String _Directory::get_current_dir() {
|
||||
Error _Directory::make_dir(String p_dir){
|
||||
|
||||
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
||||
if (!p_dir.is_rel_path()) {
|
||||
DirAccess *d = DirAccess::create_for_path(p_dir);
|
||||
Error err = d->make_dir(p_dir);
|
||||
memdelete(d);
|
||||
return err;
|
||||
|
||||
}
|
||||
return d->make_dir(p_dir);
|
||||
}
|
||||
Error _Directory::make_dir_recursive(String p_dir){
|
||||
|
||||
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
||||
if (!p_dir.is_rel_path()) {
|
||||
DirAccess *d = DirAccess::create_for_path(p_dir);
|
||||
Error err = d->make_dir_recursive(p_dir);
|
||||
memdelete(d);
|
||||
return err;
|
||||
|
||||
}
|
||||
return d->make_dir_recursive(p_dir);
|
||||
}
|
||||
|
||||
bool _Directory::file_exists(String p_file){
|
||||
|
||||
ERR_FAIL_COND_V(!d,false);
|
||||
|
||||
if (!p_file.is_rel_path()) {
|
||||
return FileAccess::exists(p_file);
|
||||
}
|
||||
|
||||
return d->file_exists(p_file);
|
||||
}
|
||||
|
||||
bool _Directory::dir_exists(String p_dir) {
|
||||
ERR_FAIL_COND_V(!d,false);
|
||||
if (!p_dir.is_rel_path()) {
|
||||
|
||||
DirAccess *d = DirAccess::create_for_path(p_dir);
|
||||
bool exists = d->dir_exists(p_dir);
|
||||
memdelete(d);
|
||||
return exists;
|
||||
|
||||
} else {
|
||||
return d->dir_exists(p_dir);
|
||||
}
|
||||
return d->dir_exists(p_dir);
|
||||
}
|
||||
|
||||
int _Directory::get_space_left(){
|
||||
|
||||
ERR_FAIL_COND_V(!d,0);
|
||||
return d->get_space_left()/1024*1024; //return value in megabytes, given binding is int
|
||||
return d->get_space_left();
|
||||
}
|
||||
|
||||
Error _Directory::copy(String p_from,String p_to){
|
||||
@ -1985,26 +1580,12 @@ Error _Directory::copy(String p_from,String p_to){
|
||||
Error _Directory::rename(String p_from, String p_to){
|
||||
|
||||
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
||||
if (!p_from.is_rel_path()) {
|
||||
DirAccess *d = DirAccess::create_for_path(p_from);
|
||||
Error err = d->rename(p_from,p_to);
|
||||
memdelete(d);
|
||||
return err;
|
||||
}
|
||||
|
||||
return d->rename(p_from,p_to);
|
||||
|
||||
}
|
||||
Error _Directory::remove(String p_name){
|
||||
|
||||
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
||||
if (!p_name.is_rel_path()) {
|
||||
DirAccess *d = DirAccess::create_for_path(p_name);
|
||||
Error err = d->remove(p_name);
|
||||
memdelete(d);
|
||||
return err;
|
||||
}
|
||||
|
||||
return d->remove(p_name);
|
||||
}
|
||||
|
||||
@ -2020,15 +1601,15 @@ void _Directory::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("get_drive","idx"),&_Directory::get_drive);
|
||||
ObjectTypeDB::bind_method(_MD("change_dir:Error","todir"),&_Directory::change_dir);
|
||||
ObjectTypeDB::bind_method(_MD("get_current_dir"),&_Directory::get_current_dir);
|
||||
ObjectTypeDB::bind_method(_MD("make_dir:Error","path"),&_Directory::make_dir);
|
||||
ObjectTypeDB::bind_method(_MD("make_dir_recursive:Error","path"),&_Directory::make_dir_recursive);
|
||||
ObjectTypeDB::bind_method(_MD("file_exists","path"),&_Directory::file_exists);
|
||||
ObjectTypeDB::bind_method(_MD("dir_exists","path"),&_Directory::dir_exists);
|
||||
ObjectTypeDB::bind_method(_MD("make_dir:Error","name"),&_Directory::make_dir);
|
||||
ObjectTypeDB::bind_method(_MD("make_dir_recursive:Error","name"),&_Directory::make_dir_recursive);
|
||||
ObjectTypeDB::bind_method(_MD("file_exists","name"),&_Directory::file_exists);
|
||||
ObjectTypeDB::bind_method(_MD("dir_exists","name"),&_Directory::dir_exists);
|
||||
// ObjectTypeDB::bind_method(_MD("get_modified_time","file"),&_Directory::get_modified_time);
|
||||
ObjectTypeDB::bind_method(_MD("get_space_left"),&_Directory::get_space_left);
|
||||
ObjectTypeDB::bind_method(_MD("copy:Error","from","to"),&_Directory::copy);
|
||||
ObjectTypeDB::bind_method(_MD("rename:Error","from","to"),&_Directory::rename);
|
||||
ObjectTypeDB::bind_method(_MD("remove:Error","path"),&_Directory::remove);
|
||||
ObjectTypeDB::bind_method(_MD("remove:Error","file"),&_Directory::remove);
|
||||
|
||||
}
|
||||
|
||||
@ -2087,89 +1668,12 @@ Variant _Marshalls::base64_to_variant(const String& p_str) {
|
||||
return v;
|
||||
};
|
||||
|
||||
String _Marshalls::raw_to_base64(const DVector<uint8_t> &p_arr) {
|
||||
|
||||
int len = p_arr.size();
|
||||
DVector<uint8_t>::Read r = p_arr.read();
|
||||
|
||||
int b64len = len / 3 * 4 + 4 + 1;
|
||||
DVector<uint8_t> b64buff;
|
||||
b64buff.resize(b64len);
|
||||
DVector<uint8_t>::Write w64 = b64buff.write();
|
||||
|
||||
int strlen = base64_encode((char*)(&w64[0]), (char*)(&r[0]), len);
|
||||
w64[strlen] = 0;
|
||||
String ret = (char*)&w64[0];
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
DVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
|
||||
|
||||
int strlen = p_str.length();
|
||||
CharString cstr = p_str.ascii();
|
||||
|
||||
int arr_len;
|
||||
DVector<uint8_t> buf;
|
||||
{
|
||||
buf.resize(strlen / 4 * 3 + 1);
|
||||
DVector<uint8_t>::Write w = buf.write();
|
||||
|
||||
arr_len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
|
||||
};
|
||||
buf.resize(arr_len);
|
||||
|
||||
// conversion from DVector<uint8_t> to raw array?
|
||||
return buf;
|
||||
};
|
||||
|
||||
String _Marshalls::utf8_to_base64(const String& p_str) {
|
||||
|
||||
CharString cstr = p_str.utf8();
|
||||
int len = cstr.length();
|
||||
|
||||
int b64len = len / 3 * 4 + 4 + 1;
|
||||
DVector<uint8_t> b64buff;
|
||||
b64buff.resize(b64len);
|
||||
DVector<uint8_t>::Write w64 = b64buff.write();
|
||||
|
||||
int strlen = base64_encode((char*)(&w64[0]), (char*)cstr.get_data(), len);
|
||||
|
||||
w64[strlen] = 0;
|
||||
String ret = (char*)&w64[0];
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
String _Marshalls::base64_to_utf8(const String& p_str) {
|
||||
|
||||
int strlen = p_str.length();
|
||||
CharString cstr = p_str.ascii();
|
||||
|
||||
DVector<uint8_t> buf;
|
||||
buf.resize(strlen / 4 * 3 + 1 + 1);
|
||||
DVector<uint8_t>::Write w = buf.write();
|
||||
|
||||
int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
|
||||
|
||||
w[len] = 0;
|
||||
String ret = String::utf8((char*)&w[0]);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
void _Marshalls::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("variant_to_base64:String","variant"),&_Marshalls::variant_to_base64);
|
||||
ObjectTypeDB::bind_method(_MD("base64_to_variant:Variant","base64_str"),&_Marshalls::base64_to_variant);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("raw_to_base64:String","array"),&_Marshalls::raw_to_base64);
|
||||
ObjectTypeDB::bind_method(_MD("base64_to_raw:RawArray","base64_str"),&_Marshalls::base64_to_raw);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("utf8_to_base64:String","utf8_str"),&_Marshalls::utf8_to_base64);
|
||||
ObjectTypeDB::bind_method(_MD("base64_to_utf8:String","base64_str"),&_Marshalls::base64_to_utf8);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -2258,9 +1762,6 @@ void _Thread::_start_func(void *ud) {
|
||||
memdelete(tud);
|
||||
Variant::CallError ce;
|
||||
const Variant* arg[1]={&t->userdata};
|
||||
|
||||
Thread::set_name(t->target_method);
|
||||
|
||||
t->ret=t->target_instance->call(t->target_method,arg,1,ce);
|
||||
if (ce.error!=Variant::CallError::CALL_OK) {
|
||||
|
||||
@ -2285,7 +1786,6 @@ void _Thread::_start_func(void *ud) {
|
||||
default: {}
|
||||
}
|
||||
|
||||
|
||||
ERR_EXPLAIN("Could not call function '"+t->target_method.operator String()+"'' starting thread ID: "+t->get_id()+" Reason: "+reason);
|
||||
ERR_FAIL();
|
||||
}
|
||||
@ -2330,6 +1830,7 @@ String _Thread::get_id() const {
|
||||
return itos(thread->get_ID());
|
||||
}
|
||||
|
||||
|
||||
bool _Thread::is_active() const {
|
||||
|
||||
return active;
|
||||
@ -2354,7 +1855,7 @@ void _Thread::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("start:Error","instance","method","userdata","priority"),&_Thread::start,DEFVAL(Variant()),DEFVAL(PRIORITY_NORMAL));
|
||||
ObjectTypeDB::bind_method(_MD("get_id"),&_Thread::get_id);
|
||||
ObjectTypeDB::bind_method(_MD("is_active"),&_Thread::is_active);
|
||||
ObjectTypeDB::bind_method(_MD("wait_to_finish:Variant"),&_Thread::wait_to_finish);
|
||||
ObjectTypeDB::bind_method(_MD("wait_to_finish:var"),&_Thread::wait_to_finish);
|
||||
|
||||
BIND_CONSTANT( PRIORITY_LOW );
|
||||
BIND_CONSTANT( PRIORITY_NORMAL );
|
||||
|
||||
@ -1,31 +1,3 @@
|
||||
/*************************************************************************/
|
||||
/* core_bind.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 CORE_BIND_H
|
||||
#define CORE_BIND_H
|
||||
|
||||
@ -54,7 +26,6 @@ public:
|
||||
void set_abort_on_missing_resources(bool p_abort);
|
||||
StringArray get_dependencies(const String& p_path);
|
||||
bool has(const String& p_path);
|
||||
Ref<ResourceImportMetadata> load_import_metadata(const String& p_path);
|
||||
|
||||
_ResourceLoader();
|
||||
};
|
||||
@ -109,9 +80,7 @@ public:
|
||||
};
|
||||
|
||||
enum Month {
|
||||
/// Start at 1 to follow Windows SYSTEMTIME structure
|
||||
/// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
|
||||
MONTH_JANUARY = 1,
|
||||
MONTH_JANUARY,
|
||||
MONTH_FEBRUARY,
|
||||
MONTH_MARCH,
|
||||
MONTH_APRIL,
|
||||
@ -145,7 +114,6 @@ public:
|
||||
virtual void set_current_screen(int p_screen);
|
||||
virtual Point2 get_screen_position(int p_screen=0) const;
|
||||
virtual Size2 get_screen_size(int p_screen=0) const;
|
||||
virtual int get_screen_dpi(int p_screen=0) const;
|
||||
virtual Point2 get_window_position() const;
|
||||
virtual void set_window_position(const Point2& p_position);
|
||||
virtual Size2 get_window_size() const;
|
||||
@ -158,15 +126,11 @@ public:
|
||||
virtual bool is_window_minimized() const;
|
||||
virtual void set_window_maximized(bool p_enabled);
|
||||
virtual bool is_window_maximized() const;
|
||||
virtual void request_attention();
|
||||
|
||||
virtual void set_borderless_window(bool p_borderless);
|
||||
virtual bool get_borderless_window() const;
|
||||
|
||||
Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
|
||||
bool native_video_is_playing();
|
||||
void native_video_pause();
|
||||
void native_video_unpause();
|
||||
void native_video_stop();
|
||||
|
||||
void set_iterations_per_second(int p_ips);
|
||||
@ -193,8 +157,6 @@ public:
|
||||
Vector<String> get_cmdline_args();
|
||||
|
||||
String get_locale() const;
|
||||
String get_latin_keyboard_variant() const;
|
||||
|
||||
String get_model_name() const;
|
||||
MainLoop *get_main_loop() const;
|
||||
|
||||
@ -205,10 +167,6 @@ public:
|
||||
void dump_memory_to_file(const String& p_file);
|
||||
void dump_resources_to_file(const String& p_file);
|
||||
|
||||
bool has_virtual_keyboard() const;
|
||||
void show_virtual_keyboard(const String& p_existing_text="");
|
||||
void hide_virtual_keyboard();
|
||||
|
||||
void print_resources_in_use(bool p_short=false);
|
||||
void print_all_resources(const String& p_to_file);
|
||||
void print_all_textures_by_size();
|
||||
@ -246,14 +204,9 @@ public:
|
||||
void set_use_file_access_save_and_swap(bool p_enable);
|
||||
|
||||
void set_icon(const Image& p_icon);
|
||||
Dictionary get_date(bool utc) const;
|
||||
Dictionary get_time(bool utc) const;
|
||||
Dictionary get_datetime(bool utc) const;
|
||||
Dictionary get_datetime_from_unix_time(uint64_t unix_time_val) const;
|
||||
uint64_t get_unix_time_from_datetime(Dictionary datetime) const;
|
||||
Dictionary get_time_zone_info() const;
|
||||
Dictionary get_date() const;
|
||||
Dictionary get_time() const;
|
||||
uint64_t get_unix_time() const;
|
||||
uint64_t get_system_time_secs() const;
|
||||
|
||||
int get_static_memory_usage() const;
|
||||
int get_static_memory_peak_usage() const;
|
||||
@ -285,50 +238,22 @@ public:
|
||||
SYSTEM_DIR_RINGTONES,
|
||||
};
|
||||
|
||||
enum ScreenOrientation {
|
||||
|
||||
SCREEN_ORIENTATION_LANDSCAPE,
|
||||
SCREEN_ORIENTATION_PORTRAIT,
|
||||
SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
|
||||
SCREEN_ORIENTATION_REVERSE_PORTRAIT,
|
||||
SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
|
||||
SCREEN_ORIENTATION_SENSOR_PORTRAIT,
|
||||
SCREEN_ORIENTATION_SENSOR,
|
||||
};
|
||||
|
||||
String get_system_dir(SystemDir p_dir) const;
|
||||
|
||||
|
||||
String get_data_dir() const;
|
||||
|
||||
void alert(const String& p_alert,const String& p_title="ALERT!");
|
||||
|
||||
|
||||
void set_screen_orientation(ScreenOrientation p_orientation);
|
||||
ScreenOrientation get_screen_orientation() const;
|
||||
|
||||
void set_keep_screen_on(bool p_enabled);
|
||||
bool is_keep_screen_on() const;
|
||||
|
||||
void set_time_scale(float p_scale);
|
||||
float get_time_scale();
|
||||
|
||||
bool is_ok_left_and_cancel_right() const;
|
||||
|
||||
Error set_thread_name(const String& p_name);
|
||||
|
||||
void set_use_vsync(bool p_enable);
|
||||
bool is_vsnc_enabled() const;
|
||||
|
||||
Dictionary get_engine_version() const;
|
||||
|
||||
static _OS *get_singleton() { return singleton; }
|
||||
|
||||
_OS();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(_OS::SystemDir);
|
||||
VARIANT_ENUM_CAST(_OS::ScreenOrientation);
|
||||
|
||||
|
||||
class _Geometry : public Object {
|
||||
@ -384,7 +309,6 @@ public:
|
||||
READ=1,
|
||||
WRITE=2,
|
||||
READ_WRITE=3,
|
||||
WRITE_READ=7,
|
||||
};
|
||||
|
||||
Error open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key);
|
||||
@ -416,8 +340,6 @@ public:
|
||||
DVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
|
||||
String get_line() const;
|
||||
String get_as_text() const;
|
||||
String get_md5(const String& p_path) const;
|
||||
String get_sha256(const String& p_path) const;
|
||||
|
||||
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
|
||||
* It's not about the current CPU type but file formats.
|
||||
@ -444,7 +366,7 @@ public:
|
||||
virtual void store_pascal_string(const String& p_string);
|
||||
virtual String get_pascal_string();
|
||||
|
||||
Vector<String> get_csv_line(String delim=",") const;
|
||||
Vector<String> get_csv_line() const;
|
||||
|
||||
|
||||
void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes
|
||||
@ -513,12 +435,6 @@ public:
|
||||
String variant_to_base64(const Variant& p_var);
|
||||
Variant base64_to_variant(const String& p_str);
|
||||
|
||||
String raw_to_base64(const DVector<uint8_t>& p_arr);
|
||||
DVector<uint8_t> base64_to_raw(const String& p_str);
|
||||
|
||||
String utf8_to_base64(const String& p_str);
|
||||
String base64_to_utf8(const String& p_str);
|
||||
|
||||
_Marshalls() {};
|
||||
};
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -75,11 +75,11 @@ float Color::get_h() const {
|
||||
h = 2 + ( b - r ) / delta; // between cyan & yellow
|
||||
else
|
||||
h = 4 + ( r - g ) / delta; // between magenta & cyan
|
||||
|
||||
|
||||
h/=6.0;
|
||||
if (h<0)
|
||||
h+=1.0;
|
||||
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
@ -117,21 +117,19 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
|
||||
}
|
||||
|
||||
p_h *=6.0;
|
||||
p_h = Math::fmod(p_h,6);
|
||||
i = Math::floor( p_h );
|
||||
|
||||
f = p_h - i;
|
||||
p = p_v * ( 1 - p_s );
|
||||
q = p_v * ( 1 - p_s * f );
|
||||
t = p_v * ( 1 - p_s * ( 1 - f ) );
|
||||
|
||||
switch( i ) {
|
||||
case 0: // Red is the dominant color
|
||||
case 0:
|
||||
r = p_v;
|
||||
g = t;
|
||||
b = p;
|
||||
break;
|
||||
case 1: // Green is the dominant color
|
||||
case 1:
|
||||
r = q;
|
||||
g = p_v;
|
||||
b = p;
|
||||
@ -141,7 +139,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
|
||||
g = p_v;
|
||||
b = t;
|
||||
break;
|
||||
case 3: // Blue is the dominant color
|
||||
case 3:
|
||||
r = p;
|
||||
g = q;
|
||||
b = p_v;
|
||||
@ -151,7 +149,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
|
||||
g = p;
|
||||
b = p_v;
|
||||
break;
|
||||
default: // (5) Red is the dominant color
|
||||
default: // cap_se 5:
|
||||
r = p_v;
|
||||
g = p;
|
||||
b = q;
|
||||
@ -162,8 +160,8 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
|
||||
void Color::invert() {
|
||||
|
||||
r=1.0-r;
|
||||
g=1.0-g;
|
||||
b=1.0-b;
|
||||
g=1.0-g;
|
||||
g=1.0-b;
|
||||
}
|
||||
void Color::contrast() {
|
||||
|
||||
@ -368,7 +366,7 @@ String Color::to_html(bool p_alpha) const {
|
||||
|
||||
float Color::gray() const {
|
||||
|
||||
return (r+g+b)/3.0;
|
||||
return (r+g+b)/3.0;
|
||||
}
|
||||
|
||||
Color::operator String() const {
|
||||
|
||||
20
core/color.h
20
core/color.h
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -37,13 +37,13 @@
|
||||
struct Color {
|
||||
|
||||
union {
|
||||
|
||||
|
||||
struct {
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
};
|
||||
};
|
||||
float components[4];
|
||||
};
|
||||
|
||||
@ -58,28 +58,28 @@ struct Color {
|
||||
float get_v() const;
|
||||
void set_hsv(float p_h, float p_s, float p_v, float p_alpha=1.0);
|
||||
|
||||
_FORCE_INLINE_ float& operator[](int idx) {
|
||||
_FORCE_INLINE_ float& operator[](int idx) {
|
||||
return components[idx];
|
||||
}
|
||||
_FORCE_INLINE_ const float& operator[](int idx) const {
|
||||
_FORCE_INLINE_ const float& operator[](int idx) const {
|
||||
return components[idx];
|
||||
}
|
||||
|
||||
|
||||
void invert();
|
||||
void contrast();
|
||||
Color inverted() const;
|
||||
Color contrasted() const;
|
||||
|
||||
_FORCE_INLINE_ Color linear_interpolate(const Color& p_b, float p_t) const {
|
||||
|
||||
|
||||
Color res=*this;
|
||||
|
||||
|
||||
res.r+= (p_t * (p_b.r-r));
|
||||
res.g+= (p_t * (p_b.g-g));
|
||||
res.b+= (p_t * (p_b.b-b));
|
||||
res.a+= (p_t * (p_b.a-a));
|
||||
|
||||
return res;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Color blend(const Color& p_over) const {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -76,7 +76,7 @@ CommandQueueMT::SyncSemaphore* CommandQueueMT::_alloc_sync_sem() {
|
||||
CommandQueueMT::CommandQueueMT(bool p_sync){
|
||||
|
||||
read_ptr=0;
|
||||
write_ptr=0;
|
||||
write_ptr=0;
|
||||
mutex = Mutex::create();
|
||||
|
||||
for(int i=0;i<SYNC_SEMAPHORES;i++) {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -47,69 +47,69 @@ class CommandQueueMT {
|
||||
};
|
||||
|
||||
struct CommandBase {
|
||||
|
||||
|
||||
virtual void call()=0;
|
||||
virtual ~CommandBase() {};
|
||||
};
|
||||
|
||||
|
||||
template<class T,class M>
|
||||
struct Command0 : public CommandBase {
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(); }
|
||||
};
|
||||
|
||||
|
||||
template<class T,class M,class P1>
|
||||
struct Command1 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(p1); }
|
||||
};
|
||||
|
||||
|
||||
template<class T,class M,class P1,class P2>
|
||||
struct Command2 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
typename GetSimpleTypeT<P2>::type_t p2;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2); }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3>
|
||||
struct Command3 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
typename GetSimpleTypeT<P2>::type_t p2;
|
||||
typename GetSimpleTypeT<P3>::type_t p3;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3); }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4>
|
||||
struct Command4 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
typename GetSimpleTypeT<P2>::type_t p2;
|
||||
typename GetSimpleTypeT<P3>::type_t p3;
|
||||
typename GetSimpleTypeT<P4>::type_t p4;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4); }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5>
|
||||
struct Command5 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -117,13 +117,13 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P3>::type_t p3;
|
||||
typename GetSimpleTypeT<P4>::type_t p4;
|
||||
typename GetSimpleTypeT<P5>::type_t p5;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6>
|
||||
struct Command6 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -132,13 +132,13 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P4>::type_t p4;
|
||||
typename GetSimpleTypeT<P5>::type_t p5;
|
||||
typename GetSimpleTypeT<P6>::type_t p6;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); }
|
||||
};
|
||||
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7>
|
||||
struct Command7 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -148,29 +148,12 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P5>::type_t p5;
|
||||
typename GetSimpleTypeT<P6>::type_t p6;
|
||||
typename GetSimpleTypeT<P7>::type_t p7;
|
||||
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class P8>
|
||||
struct Command8 : public CommandBase {
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
typename GetSimpleTypeT<P2>::type_t p2;
|
||||
typename GetSimpleTypeT<P3>::type_t p3;
|
||||
typename GetSimpleTypeT<P4>::type_t p4;
|
||||
typename GetSimpleTypeT<P5>::type_t p5;
|
||||
typename GetSimpleTypeT<P6>::type_t p6;
|
||||
typename GetSimpleTypeT<P7>::type_t p7;
|
||||
typename GetSimpleTypeT<P8>::type_t p8;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); }
|
||||
};
|
||||
|
||||
|
||||
/* comands that return */
|
||||
|
||||
|
||||
template<class T,class M,class R>
|
||||
struct CommandRet0 : public CommandBase {
|
||||
|
||||
@ -178,38 +161,38 @@ class CommandQueueMT {
|
||||
M method;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
|
||||
template<class T,class M,class P1,class R>
|
||||
struct CommandRet1 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); sync->in_use=false; }
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
|
||||
template<class T,class M,class P1,class P2,class R>
|
||||
struct CommandRet2 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
typename GetSimpleTypeT<P2>::type_t p2;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class R>
|
||||
struct CommandRet3 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -217,13 +200,13 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P3>::type_t p3;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class R>
|
||||
struct CommandRet4 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -232,13 +215,13 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P4>::type_t p4;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class R>
|
||||
struct CommandRet5 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -248,13 +231,13 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P5>::type_t p5;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class R>
|
||||
struct CommandRet6 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -265,13 +248,13 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P6>::type_t p6;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class R>
|
||||
struct CommandRet7 : public CommandBase {
|
||||
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
@ -283,28 +266,9 @@ class CommandQueueMT {
|
||||
typename GetSimpleTypeT<P7>::type_t p7;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class P8,class R>
|
||||
struct CommandRet8 : public CommandBase {
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
typename GetSimpleTypeT<P2>::type_t p2;
|
||||
typename GetSimpleTypeT<P3>::type_t p3;
|
||||
typename GetSimpleTypeT<P4>::type_t p4;
|
||||
typename GetSimpleTypeT<P5>::type_t p5;
|
||||
typename GetSimpleTypeT<P6>::type_t p6;
|
||||
typename GetSimpleTypeT<P7>::type_t p7;
|
||||
typename GetSimpleTypeT<P8>::type_t p8;
|
||||
R* ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
};
|
||||
|
||||
/** commands that don't return but sync */
|
||||
|
||||
@ -426,28 +390,9 @@ class CommandQueueMT {
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class P8>
|
||||
struct CommandSync8 : public CommandBase {
|
||||
|
||||
T*instance;
|
||||
M method;
|
||||
typename GetSimpleTypeT<P1>::type_t p1;
|
||||
typename GetSimpleTypeT<P2>::type_t p2;
|
||||
typename GetSimpleTypeT<P3>::type_t p3;
|
||||
typename GetSimpleTypeT<P4>::type_t p4;
|
||||
typename GetSimpleTypeT<P5>::type_t p5;
|
||||
typename GetSimpleTypeT<P6>::type_t p6;
|
||||
typename GetSimpleTypeT<P7>::type_t p7;
|
||||
typename GetSimpleTypeT<P8>::type_t p8;
|
||||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; }
|
||||
};
|
||||
|
||||
/***** BASE *******/
|
||||
|
||||
enum {
|
||||
enum {
|
||||
COMMAND_MEM_SIZE_KB=256,
|
||||
COMMAND_MEM_SIZE=COMMAND_MEM_SIZE_KB*1024,
|
||||
SYNC_SEMAPHORES=8
|
||||
@ -460,30 +405,30 @@ class CommandQueueMT {
|
||||
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
|
||||
Mutex *mutex;
|
||||
Semaphore *sync;
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
T* allocate() {
|
||||
|
||||
|
||||
// alloc size is size+T+safeguard
|
||||
uint32_t alloc_size=sizeof(T)+sizeof(uint32_t);
|
||||
|
||||
|
||||
tryagain:
|
||||
|
||||
|
||||
if (write_ptr < read_ptr) {
|
||||
// behind read_ptr, check that there is room
|
||||
if ( (read_ptr-write_ptr) <= alloc_size )
|
||||
return NULL;
|
||||
} else if (write_ptr >= read_ptr) {
|
||||
// ahead of read_ptr, check that there is room
|
||||
|
||||
|
||||
|
||||
|
||||
if ( (COMMAND_MEM_SIZE-write_ptr) < alloc_size+4 ) {
|
||||
// no room at the end, wrap down;
|
||||
|
||||
|
||||
if (read_ptr==0) // dont want write_ptr to become read_ptr
|
||||
return NULL;
|
||||
|
||||
|
||||
// if this happens, it's a bug
|
||||
ERR_FAIL_COND_V( (COMMAND_MEM_SIZE-write_ptr) < sizeof(uint32_t), NULL );
|
||||
// zero means, wrap to begining
|
||||
@ -502,147 +447,147 @@ class CommandQueueMT {
|
||||
T* cmd = memnew_placement( &command_mem[write_ptr], T );
|
||||
write_ptr+=sizeof(T);
|
||||
return cmd;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
T* allocate_and_lock() {
|
||||
|
||||
|
||||
lock();
|
||||
T* ret;
|
||||
|
||||
|
||||
while ( (ret=allocate<T>())==NULL ) {
|
||||
|
||||
|
||||
unlock();
|
||||
// sleep a little until fetch happened and some room is made
|
||||
// sleep a little until fetch happened and some room is made
|
||||
wait_for_flush();
|
||||
lock();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool flush_one() {
|
||||
|
||||
|
||||
tryagain:
|
||||
|
||||
|
||||
// tried to read an empty queue
|
||||
if (read_ptr == write_ptr )
|
||||
return false;
|
||||
|
||||
|
||||
uint32_t size = *(uint32_t*)( &command_mem[read_ptr] );
|
||||
|
||||
|
||||
if (size==0) {
|
||||
//end of ringbuffer, wrap
|
||||
read_ptr=0;
|
||||
goto tryagain;
|
||||
}
|
||||
|
||||
|
||||
read_ptr+=sizeof(uint32_t);
|
||||
|
||||
|
||||
CommandBase *cmd = reinterpret_cast<CommandBase*>( &command_mem[read_ptr] );
|
||||
|
||||
|
||||
cmd->call();
|
||||
cmd->~CommandBase();
|
||||
|
||||
read_ptr+=size;
|
||||
|
||||
read_ptr+=size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
void wait_for_flush();
|
||||
SyncSemaphore* _alloc_sync_sem();
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/* NORMAL PUSH COMMANDS */
|
||||
|
||||
|
||||
template<class T, class M>
|
||||
void push( T * p_instance, M p_method ) {
|
||||
|
||||
|
||||
Command0<T,M> * cmd = allocate_and_lock< Command0<T,M> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1>
|
||||
void push( T * p_instance, M p_method, P1 p1 ) {
|
||||
|
||||
|
||||
Command1<T,M,P1> * cmd = allocate_and_lock< Command1<T,M,P1> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2>
|
||||
void push( T * p_instance, M p_method, P1 p1, P2 p2 ) {
|
||||
|
||||
|
||||
Command2<T,M,P1,P2> * cmd = allocate_and_lock< Command2<T,M,P1,P2> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
cmd->p2=p2;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3>
|
||||
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3 ) {
|
||||
|
||||
|
||||
Command3<T,M,P1,P2,P3> * cmd = allocate_and_lock< Command3<T,M,P1,P2,P3> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
cmd->p2=p2;
|
||||
cmd->p3=p3;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4>
|
||||
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4 ) {
|
||||
|
||||
|
||||
Command4<T,M,P1,P2,P3,P4> * cmd = allocate_and_lock< Command4<T,M,P1,P2,P3,P4> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
cmd->p2=p2;
|
||||
cmd->p3=p3;
|
||||
cmd->p4=p4;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5>
|
||||
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5 ) {
|
||||
|
||||
|
||||
Command5<T,M,P1,P2,P3,P4,P5> * cmd = allocate_and_lock< Command5<T,M,P1,P2,P3,P4,P5> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -650,17 +595,17 @@ public:
|
||||
cmd->p3=p3;
|
||||
cmd->p4=p4;
|
||||
cmd->p5=p5;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
|
||||
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6 ) {
|
||||
|
||||
|
||||
Command6<T,M,P1,P2,P3,P4,P5,P6> * cmd = allocate_and_lock< Command6<T,M,P1,P2,P3,P4,P5,P6> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -669,17 +614,17 @@ public:
|
||||
cmd->p4=p4;
|
||||
cmd->p5=p5;
|
||||
cmd->p6=p6;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
|
||||
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7 ) {
|
||||
|
||||
|
||||
Command7<T,M,P1,P2,P3,P4,P5,P6,P7> * cmd = allocate_and_lock< Command7<T,M,P1,P2,P3,P4,P5,P6,P7> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -689,40 +634,19 @@ public:
|
||||
cmd->p5=p5;
|
||||
cmd->p6=p6;
|
||||
cmd->p7=p7;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7,class P8>
|
||||
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8 ) {
|
||||
|
||||
Command8<T,M,P1,P2,P3,P4,P5,P6,P7,P8> * cmd = allocate_and_lock< Command8<T,M,P1,P2,P3,P4,P5,P6,P7,P8> >();
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
cmd->p2=p2;
|
||||
cmd->p3=p3;
|
||||
cmd->p4=p4;
|
||||
cmd->p5=p5;
|
||||
cmd->p6=p6;
|
||||
cmd->p7=p7;
|
||||
cmd->p8=p8;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
}
|
||||
/*** PUSH AND RET COMMANDS ***/
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T, class M,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, R* r_ret) {
|
||||
|
||||
|
||||
CommandRet0<T,M,R> * cmd = allocate_and_lock< CommandRet0<T,M,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->ret=r_ret;
|
||||
@ -730,34 +654,34 @@ public:
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, R* r_ret) {
|
||||
|
||||
|
||||
CommandRet1<T,M,P1,R> * cmd = allocate_and_lock< CommandRet1<T,M,P1,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
cmd->ret=r_ret;
|
||||
SyncSemaphore *ss=_alloc_sync_sem();
|
||||
cmd->sync=ss;
|
||||
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, R* r_ret) {
|
||||
|
||||
|
||||
CommandRet2<T,M,P1,P2,R> * cmd = allocate_and_lock< CommandRet2<T,M,P1,P2,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -767,16 +691,16 @@ public:
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, R* r_ret ) {
|
||||
|
||||
|
||||
CommandRet3<T,M,P1,P2,P3,R> * cmd = allocate_and_lock< CommandRet3<T,M,P1,P2,P3,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -787,16 +711,16 @@ public:
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R* r_ret ) {
|
||||
|
||||
|
||||
CommandRet4<T,M,P1,P2,P3,P4,R> * cmd = allocate_and_lock< CommandRet4<T,M,P1,P2,P3,P4,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -808,16 +732,16 @@ public:
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R* r_ret ) {
|
||||
|
||||
|
||||
CommandRet5<T,M,P1,P2,P3,P4,P5,R> * cmd = allocate_and_lock< CommandRet5<T,M,P1,P2,P3,P4,P5,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -830,16 +754,16 @@ public:
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, R* r_ret ) {
|
||||
|
||||
|
||||
CommandRet6<T,M,P1,P2,P3,P4,P5,P6,R> * cmd = allocate_and_lock< CommandRet6<T,M,P1,P2,P3,P4,P5,P6,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -853,16 +777,16 @@ public:
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class P7,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6,P7 p7, R* r_ret ) {
|
||||
|
||||
|
||||
CommandRet7<T,M,P1,P2,P3,P4,P5,P6,P7,R> * cmd = allocate_and_lock< CommandRet7<T,M,P1,P2,P3,P4,P5,P6,P7,R> >();
|
||||
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
@ -877,32 +801,7 @@ public:
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class P7,class P8,class R>
|
||||
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6,P7 p7,P8 p8, R* r_ret ) {
|
||||
|
||||
CommandRet8<T,M,P1,P2,P3,P4,P5,P6,P7,P8,R> * cmd = allocate_and_lock< CommandRet8<T,M,P1,P2,P3,P4,P5,P6,P7,P8,R> >();
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
cmd->p2=p2;
|
||||
cmd->p3=p3;
|
||||
cmd->p4=p4;
|
||||
cmd->p5=p5;
|
||||
cmd->p6=p6;
|
||||
cmd->p7=p7;
|
||||
cmd->p8=p8;
|
||||
cmd->ret=r_ret;
|
||||
SyncSemaphore *ss=_alloc_sync_sem();
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
@ -1072,42 +971,17 @@ public:
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class P7,class P8>
|
||||
void push_and_sync( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6,P7 p7,P8 p8) {
|
||||
|
||||
CommandSync8<T,M,P1,P2,P3,P4,P5,P6,P7,P8> * cmd = allocate_and_lock< CommandSync8<T,M,P1,P2,P3,P4,P5,P6,P7,P8> >();
|
||||
|
||||
cmd->instance=p_instance;
|
||||
cmd->method=p_method;
|
||||
cmd->p1=p1;
|
||||
cmd->p2=p2;
|
||||
cmd->p3=p3;
|
||||
cmd->p4=p4;
|
||||
cmd->p5=p5;
|
||||
cmd->p6=p6;
|
||||
cmd->p7=p7;
|
||||
cmd->p8=p8;
|
||||
|
||||
SyncSemaphore *ss=_alloc_sync_sem();
|
||||
cmd->sync=ss;
|
||||
|
||||
unlock();
|
||||
|
||||
if (sync) sync->post();
|
||||
ss->sem->wait();
|
||||
}
|
||||
|
||||
void wait_and_flush_one() {
|
||||
ERR_FAIL_COND(!sync);
|
||||
sync->wait();
|
||||
lock();
|
||||
flush_one();
|
||||
flush_one();
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
void flush_all() {
|
||||
|
||||
//ERR_FAIL_COND(sync);
|
||||
|
||||
ERR_FAIL_COND(sync);
|
||||
lock();
|
||||
while (true) {
|
||||
bool exit = !flush_one();
|
||||
@ -1116,10 +990,10 @@ public:
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
CommandQueueMT(bool p_sync);
|
||||
~CommandQueueMT();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -410,15 +410,15 @@ bool PHashTranslation::_set(const StringName& p_name, const Variant& p_value) {
|
||||
String name = p_name.operator String();
|
||||
if (name=="hash_table") {
|
||||
hash_table=p_value;
|
||||
//print_line("translation: loaded hash table of size: "+itos(hash_table.size()));
|
||||
print_line("translation: loaded hash table of size: "+itos(hash_table.size()));
|
||||
} else if (name=="bucket_table") {
|
||||
bucket_table=p_value;
|
||||
//print_line("translation: loaded bucket table of size: "+itos(bucket_table.size()));
|
||||
print_line("translation: loaded bucket table of size: "+itos(bucket_table.size()));
|
||||
} else if (name=="strings") {
|
||||
strings=p_value;
|
||||
//print_line("translation: loaded string table of size: "+itos(strings.size()));
|
||||
print_line("translation: loaded string table of size: "+itos(strings.size()));
|
||||
} else if (name=="load_from") {
|
||||
//print_line("generating");
|
||||
print_line("generating");
|
||||
generate(p_value);
|
||||
} else
|
||||
return false;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -110,16 +110,6 @@ bool Dictionary::has(const Variant& p_key) const {
|
||||
|
||||
return _p->variant_map.has(p_key);
|
||||
}
|
||||
|
||||
bool Dictionary::has_all(const Array& p_keys) const {
|
||||
for (int i=0;i<p_keys.size();i++) {
|
||||
if( !has(p_keys[i]) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Dictionary::erase(const Variant& p_key) {
|
||||
_copy_on_write();
|
||||
_p->variant_map.erase(p_key);
|
||||
@ -170,20 +160,7 @@ void Dictionary::_unref() const {
|
||||
}
|
||||
uint32_t Dictionary::hash() const {
|
||||
|
||||
uint32_t h=hash_djb2_one_32(Variant::DICTIONARY);
|
||||
|
||||
List<Variant> keys;
|
||||
get_key_list(&keys);
|
||||
|
||||
for (List<Variant>::Element *E=keys.front();E;E=E->next()) {
|
||||
|
||||
h = hash_djb2_one_32( E->get().hash(), h);
|
||||
h = hash_djb2_one_32( operator[](E->get()).hash(), h);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return h;
|
||||
return hash_djb2_one_64(make_uint64_t(_p));
|
||||
}
|
||||
|
||||
Array Dictionary::keys() const {
|
||||
@ -199,18 +176,6 @@ Array Dictionary::keys() const {
|
||||
|
||||
}
|
||||
|
||||
Array Dictionary::values() const {
|
||||
|
||||
Array varr;
|
||||
varr.resize(size());
|
||||
const Variant *key=NULL;
|
||||
int i=0;
|
||||
while((key=next(key))){
|
||||
varr[i++] = _p->variant_map[*key];
|
||||
}
|
||||
return varr;
|
||||
}
|
||||
|
||||
const Variant* Dictionary::next(const Variant* p_key) const {
|
||||
|
||||
return _p->variant_map.next(p_key);
|
||||
@ -262,3 +227,5 @@ Dictionary::~Dictionary() {
|
||||
|
||||
_unref();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -69,8 +69,6 @@ public:
|
||||
bool is_shared() const;
|
||||
|
||||
bool has(const Variant& p_key) const;
|
||||
bool has_all(const Array& p_keys) const;
|
||||
|
||||
void erase(const Variant& p_key);
|
||||
|
||||
bool operator==(const Dictionary& p_dictionary) const;
|
||||
@ -81,7 +79,6 @@ public:
|
||||
const Variant* next(const Variant* p_key=NULL) const;
|
||||
|
||||
Array keys() const;
|
||||
Array values() const;
|
||||
|
||||
Dictionary(const Dictionary& p_from);
|
||||
Dictionary(bool p_shared=false);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
213
core/dvector.h
213
core/dvector.h
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -43,18 +43,18 @@ template<class T>
|
||||
class DVector {
|
||||
|
||||
mutable MID mem;
|
||||
|
||||
|
||||
|
||||
|
||||
void copy_on_write() {
|
||||
|
||||
|
||||
if (!mem.is_valid())
|
||||
return;
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->lock();
|
||||
|
||||
|
||||
MID_Lock lock( mem );
|
||||
|
||||
|
||||
|
||||
if ( *(int*)lock.data() == 1 ) {
|
||||
// one reference, means no refcount changes
|
||||
@ -62,114 +62,114 @@ class DVector {
|
||||
dvector_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
MID new_mem= dynalloc( mem.get_size() );
|
||||
|
||||
|
||||
if (!new_mem.is_valid()) {
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->unlock();
|
||||
ERR_FAIL_COND( new_mem.is_valid() ); // out of memory
|
||||
ERR_FAIL_COND( new_mem.is_valid() ); // out of memory
|
||||
}
|
||||
|
||||
|
||||
MID_Lock dst_lock( new_mem );
|
||||
|
||||
|
||||
int *rc = (int*)dst_lock.data();
|
||||
|
||||
|
||||
*rc=1;
|
||||
|
||||
|
||||
T * dst = (T*)(rc + 1 );
|
||||
|
||||
|
||||
T * src =(T*) ((int*)lock.data() + 1 );
|
||||
|
||||
|
||||
int count = (mem.get_size() - sizeof(int)) / sizeof(T);
|
||||
|
||||
|
||||
for (int i=0;i<count;i++) {
|
||||
|
||||
|
||||
memnew_placement( &dst[i], T(src[i]) );
|
||||
}
|
||||
|
||||
|
||||
(*(int*)lock.data())--;
|
||||
|
||||
|
||||
// unlock all
|
||||
dst_lock=MID_Lock();
|
||||
lock=MID_Lock();
|
||||
|
||||
|
||||
mem=new_mem;
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->unlock();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void reference( const DVector& p_dvector ) {
|
||||
|
||||
|
||||
unreference();
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->lock();
|
||||
|
||||
|
||||
if (!p_dvector.mem.is_valid()) {
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->unlock();
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
MID_Lock lock(p_dvector.mem);
|
||||
|
||||
|
||||
int * rc = (int*)lock.data();
|
||||
(*rc)++;
|
||||
|
||||
|
||||
lock = MID_Lock();
|
||||
mem=p_dvector.mem;
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->unlock();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void unreference() {
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->lock();
|
||||
|
||||
|
||||
if (!mem.is_valid()) {
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->unlock();
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
MID_Lock lock(mem);
|
||||
|
||||
|
||||
int * rc = (int*)lock.data();
|
||||
(*rc)--;
|
||||
|
||||
|
||||
if (*rc==0) {
|
||||
// no one else using it, destruct
|
||||
|
||||
|
||||
T * t= (T*)(rc+1);
|
||||
int count = (mem.get_size() - sizeof(int)) / sizeof(T);
|
||||
|
||||
|
||||
for (int i=0;i<count;i++) {
|
||||
|
||||
|
||||
t[i].~T();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
lock = MID_Lock();
|
||||
|
||||
|
||||
mem = MID ();
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->unlock();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
class Read {
|
||||
@ -177,10 +177,10 @@ public:
|
||||
MID_Lock lock;
|
||||
const T * mem;
|
||||
public:
|
||||
|
||||
|
||||
_FORCE_INLINE_ const T& operator[](int p_index) const { return mem[p_index]; }
|
||||
_FORCE_INLINE_ const T *ptr() const { return mem; }
|
||||
|
||||
|
||||
Read() { mem=NULL; }
|
||||
};
|
||||
|
||||
@ -189,32 +189,32 @@ public:
|
||||
MID_Lock lock;
|
||||
T * mem;
|
||||
public:
|
||||
|
||||
|
||||
_FORCE_INLINE_ T& operator[](int p_index) { return mem[p_index]; }
|
||||
_FORCE_INLINE_ T *ptr() { return mem; }
|
||||
|
||||
|
||||
Write() { mem=NULL; }
|
||||
};
|
||||
|
||||
|
||||
Read read() const {
|
||||
|
||||
|
||||
Read r;
|
||||
if (mem.is_valid()) {
|
||||
if (mem.is_valid()) {
|
||||
r.lock = MID_Lock( mem );
|
||||
r.mem = (const T*)((int*)r.lock.data()+1);
|
||||
}
|
||||
return r;
|
||||
return r;
|
||||
}
|
||||
Write write() {
|
||||
|
||||
|
||||
Write w;
|
||||
if (mem.is_valid()) {
|
||||
copy_on_write();
|
||||
w.lock = MID_Lock( mem );
|
||||
w.mem = (T*)((int*)w.lock.data()+1);
|
||||
}
|
||||
return w;
|
||||
return w;
|
||||
}
|
||||
|
||||
template<class MC>
|
||||
@ -280,13 +280,12 @@ public:
|
||||
|
||||
|
||||
bool is_locked() const { return mem.is_locked(); }
|
||||
|
||||
|
||||
inline const T operator[](int p_index) const;
|
||||
|
||||
Error resize(int p_size);
|
||||
|
||||
void invert();
|
||||
|
||||
|
||||
|
||||
void operator=(const DVector& p_dvector) { reference(p_dvector); }
|
||||
DVector() {}
|
||||
DVector(const DVector& p_dvector) { reference(p_dvector); }
|
||||
@ -309,7 +308,7 @@ T DVector<T>::get(int p_index) const {
|
||||
template<class T>
|
||||
void DVector<T>::set(int p_index, const T& p_val) {
|
||||
|
||||
if (p_index<0 || p_index>=size()) {
|
||||
if (p_index<0 || p_index>=size()) {
|
||||
ERR_FAIL_COND(p_index<0 || p_index>=size());
|
||||
}
|
||||
|
||||
@ -333,7 +332,7 @@ const T DVector<T>::operator[](int p_index) const {
|
||||
}
|
||||
|
||||
Read r = read();
|
||||
|
||||
|
||||
return r[p_index];
|
||||
}
|
||||
|
||||
@ -345,98 +344,86 @@ Error DVector<T>::resize(int p_size) {
|
||||
dvector_lock->lock();
|
||||
|
||||
bool same = p_size==size();
|
||||
|
||||
|
||||
if (dvector_lock)
|
||||
dvector_lock->unlock();
|
||||
// no further locking is necesary because we are supposed to own the only copy of this (using copy on write)
|
||||
|
||||
// no further locking is necesary because we are supposed to own the only copy of this (using copy on write)
|
||||
|
||||
if (same)
|
||||
return OK;
|
||||
|
||||
if (p_size == 0 ) {
|
||||
|
||||
|
||||
unreference();
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
copy_on_write(); // make it unique
|
||||
|
||||
|
||||
ERR_FAIL_COND_V( mem.is_locked(), ERR_LOCKED ); // if after copy on write, memory is locked, fail.
|
||||
|
||||
|
||||
if (p_size > size() ) {
|
||||
|
||||
|
||||
int oldsize=size();
|
||||
|
||||
|
||||
MID_Lock lock;
|
||||
|
||||
|
||||
if (oldsize==0) {
|
||||
|
||||
mem = dynalloc( p_size * sizeof(T) + sizeof(int) );
|
||||
lock=MID_Lock(mem);
|
||||
int *rc = ((int*)lock.data());
|
||||
*rc=1;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) {
|
||||
|
||||
|
||||
ERR_FAIL_V(ERR_OUT_OF_MEMORY); // out of memory
|
||||
}
|
||||
|
||||
lock=MID_Lock(mem);
|
||||
|
||||
lock=MID_Lock(mem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
T *t = (T*)((int*)lock.data() + 1);
|
||||
|
||||
|
||||
for (int i=oldsize;i<p_size;i++) {
|
||||
|
||||
|
||||
memnew_placement(&t[i], T );
|
||||
}
|
||||
|
||||
|
||||
lock = MID_Lock(); // clear
|
||||
} else {
|
||||
|
||||
|
||||
int oldsize=size();
|
||||
|
||||
|
||||
MID_Lock lock(mem);
|
||||
|
||||
|
||||
|
||||
|
||||
T *t = (T*)((int*)lock.data() + 1);
|
||||
|
||||
|
||||
for (int i=p_size;i<oldsize;i++) {
|
||||
|
||||
|
||||
t[i].~T();
|
||||
}
|
||||
|
||||
|
||||
lock = MID_Lock(); // clear
|
||||
|
||||
|
||||
if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) {
|
||||
|
||||
ERR_FAIL_V(ERR_OUT_OF_MEMORY); // wtf error
|
||||
|
||||
ERR_FAIL_V(ERR_OUT_OF_MEMORY); // wtf error
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DVector<T>::invert() {
|
||||
T temp;
|
||||
Write w = write();
|
||||
int s = size();
|
||||
int half_s = s/2;
|
||||
|
||||
for(int i=0;i<half_s;i++) {
|
||||
temp = w[i];
|
||||
w[i] = w[s-i-1];
|
||||
w[s-i-1] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,6 @@ enum Error {
|
||||
ERR_FILE_CANT_READ,
|
||||
ERR_FILE_UNRECOGNIZED, // (15)
|
||||
ERR_FILE_CORRUPT,
|
||||
ERR_FILE_MISSING_DEPENDENCIES,
|
||||
ERR_FILE_EOF,
|
||||
ERR_CANT_OPEN, ///< Can't open a resource/socket/file
|
||||
ERR_CANT_CREATE,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,12 +33,12 @@
|
||||
/**
|
||||
* Error macros. Unlike exceptions and asserts, these macros try to mantain consistency and stability
|
||||
* inside the code. It is recommended to always return processable data, so in case of an error, the
|
||||
* engine can stay working well.
|
||||
* engine can stay working well.
|
||||
* In most cases, bugs and/or invalid data are not fatal and should never allow a perfectly running application
|
||||
* to fail or crash.
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Pointer to the error macro priting function. Reassign to any function to have errors printed
|
||||
*/
|
||||
|
||||
@ -104,7 +104,7 @@ extern bool _err_error_exists;
|
||||
|
||||
#define ERR_FAIL_INDEX(m_index,m_size) \
|
||||
do {if ((m_index)<0 || (m_index)>=(m_size)) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Index " _STR(m_index)" out of size (" _STR(m_size)")."); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Index "_STR(m_index)" out of size ("_STR(m_size)")."); \
|
||||
return; \
|
||||
} else _err_error_exists=false; } while(0); \
|
||||
|
||||
@ -115,7 +115,7 @@ extern bool _err_error_exists;
|
||||
|
||||
#define ERR_FAIL_INDEX_V(m_index,m_size,m_retval) \
|
||||
do {if ((m_index)<0 || (m_index)>=(m_size)) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Index " _STR(m_index)" out of size (" _STR(m_size)")."); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Index "_STR(m_index)" out of size ("_STR(m_size)")."); \
|
||||
return m_retval; \
|
||||
} else _err_error_exists=false;} while (0);
|
||||
|
||||
@ -125,28 +125,28 @@ extern bool _err_error_exists;
|
||||
|
||||
#define ERR_FAIL_NULL(m_param) \
|
||||
{ if ( !m_param ) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Parameter ' " _STR(m_param)" ' is null."); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Parameter ' "_STR(m_param)" ' is null."); \
|
||||
return; \
|
||||
}else _err_error_exists=false; } \
|
||||
|
||||
|
||||
#define ERR_FAIL_NULL_V(m_param,m_retval) \
|
||||
{ if ( !m_param ) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Parameter ' " _STR(m_param)" ' is null."); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Parameter ' "_STR(m_param)" ' is null."); \
|
||||
return m_retval; \
|
||||
}else _err_error_exists=false; } \
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the function will exit.
|
||||
*/
|
||||
|
||||
#define ERR_FAIL_COND(m_cond) \
|
||||
{ if ( m_cond ) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true."); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' "_STR(m_cond)" ' is true."); \
|
||||
return; \
|
||||
}else _err_error_exists=false; } \
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the function will exit.
|
||||
* This function returns an error value, if returning Error, please select the most
|
||||
* appropriate error condition from error_macros.h
|
||||
@ -154,27 +154,27 @@ extern bool _err_error_exists;
|
||||
|
||||
#define ERR_FAIL_COND_V(m_cond,m_retval) \
|
||||
{ if ( m_cond ) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true. returned: " _STR(m_retval)); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' "_STR(m_cond)" ' is true. returned: "_STR(m_retval)); \
|
||||
return m_retval; \
|
||||
}else _err_error_exists=false; } \
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the loop will skip to the next iteration.
|
||||
*/
|
||||
|
||||
#define ERR_CONTINUE(m_cond) \
|
||||
{ if ( m_cond ) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true. Continuing..:"); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' "_STR(m_cond)" ' is true. Continuing..:"); \
|
||||
continue;\
|
||||
} else _err_error_exists=false;} \
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the loop will break
|
||||
*/
|
||||
|
||||
#define ERR_BREAK(m_cond) \
|
||||
{ if ( m_cond ) { \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true. Breaking..:"); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' "_STR(m_cond)" ' is true. Breaking..:"); \
|
||||
break;\
|
||||
} else _err_error_exists=false;} \
|
||||
|
||||
@ -193,7 +193,7 @@ extern bool _err_error_exists;
|
||||
|
||||
#define ERR_FAIL_V(m_value) \
|
||||
{ \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Method/Function Failed, returning: " __STR(m_value)); \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Method/Function Failed, returning: "__STR(m_value)); \
|
||||
_err_error_exists=false; \
|
||||
return m_value;\
|
||||
} \
|
||||
@ -207,11 +207,6 @@ extern bool _err_error_exists;
|
||||
_err_error_exists=false;\
|
||||
} \
|
||||
|
||||
#define ERR_PRINTS(m_string) \
|
||||
{ \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,String(m_string).utf8().get_data()); \
|
||||
_err_error_exists=false;\
|
||||
} \
|
||||
|
||||
/** Print a warning string.
|
||||
*/
|
||||
@ -223,10 +218,5 @@ extern bool _err_error_exists;
|
||||
} \
|
||||
|
||||
|
||||
#define WARN_PRINTS(m_string) \
|
||||
{ \
|
||||
_err_print_error(FUNCTION_STR,__FILE__,__LINE__,String(m_string).utf8().get_data(),ERR_HANDLER_WARNING); \
|
||||
_err_error_exists=false;\
|
||||
} \
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -43,118 +43,118 @@ Error EventQueue::push_call(uint32_t p_instance_ID, const StringName& p_method,
|
||||
args=2;
|
||||
else if (p_arg1.get_type()!=Variant::NIL)
|
||||
args=1;
|
||||
else
|
||||
else
|
||||
args=0;
|
||||
|
||||
|
||||
room_needed+=sizeof(Variant)*args;
|
||||
|
||||
|
||||
ERR_FAIL_COND_V( (buffer_end+room_needed) >= buffer_size , ERR_OUT_OF_MEMORY );
|
||||
Event * ev = memnew_placement( &event_buffer[ buffer_end ], Event );
|
||||
ev->args=args;
|
||||
ev->instance_ID=p_instance_ID;
|
||||
ev->method=p_method;
|
||||
|
||||
|
||||
buffer_end+=sizeof(Event);
|
||||
|
||||
|
||||
if (args>=1) {
|
||||
|
||||
|
||||
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
|
||||
buffer_end+=sizeof(Variant);
|
||||
*v=p_arg1;
|
||||
}
|
||||
|
||||
if (args>=2) {
|
||||
|
||||
|
||||
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
|
||||
buffer_end+=sizeof(Variant);
|
||||
*v=p_arg2;
|
||||
}
|
||||
|
||||
if (args>=3) {
|
||||
|
||||
|
||||
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
|
||||
buffer_end+=sizeof(Variant);
|
||||
*v=p_arg3;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (args>=4) {
|
||||
|
||||
|
||||
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
|
||||
buffer_end+=sizeof(Variant);
|
||||
*v=p_arg4;
|
||||
}
|
||||
|
||||
if (args>=5) {
|
||||
|
||||
|
||||
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
|
||||
buffer_end+=sizeof(Variant);
|
||||
*v=p_arg5;
|
||||
}
|
||||
|
||||
if (buffer_end > buffer_max_used)
|
||||
|
||||
if (buffer_max_used>buffer_end);
|
||||
buffer_max_used=buffer_end;
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void EventQueue::flush_events() {
|
||||
|
||||
uint32_t read_pos=0;
|
||||
|
||||
|
||||
while (read_pos < buffer_end ) {
|
||||
|
||||
|
||||
Event *event = (Event*)&event_buffer[ read_pos ];
|
||||
Variant *args= (Variant*)(event+1);
|
||||
Object *obj = ObjectDB::get_instance(event->instance_ID);
|
||||
|
||||
if (obj) {
|
||||
|
||||
if (obj) {
|
||||
// events don't expect a return value
|
||||
obj->call( event->method,
|
||||
obj->call( event->method,
|
||||
(event->args>=1) ? args[0] : Variant(),
|
||||
(event->args>=2) ? args[1] : Variant(),
|
||||
(event->args>=3) ? args[2] : Variant(),
|
||||
(event->args>=4) ? args[3] : Variant(),
|
||||
(event->args>=5) ? args[4] : Variant() );
|
||||
}
|
||||
|
||||
|
||||
if (event->args>=1) args[0].~Variant();
|
||||
if (event->args>=2) args[1].~Variant();
|
||||
if (event->args>=3) args[2].~Variant();
|
||||
if (event->args>=4) args[3].~Variant();
|
||||
if (event->args>=5) args[4].~Variant();
|
||||
event->~Event();
|
||||
|
||||
|
||||
read_pos+=sizeof(Event)+sizeof(Variant)*event->args;
|
||||
}
|
||||
|
||||
|
||||
buffer_end=0; // reset buffer
|
||||
}
|
||||
|
||||
EventQueue::EventQueue(uint32_t p_buffer_size) {
|
||||
|
||||
|
||||
|
||||
buffer_end=0;
|
||||
buffer_max_used=0;
|
||||
buffer_size=p_buffer_size;
|
||||
event_buffer = memnew_arr( uint8_t, buffer_size );
|
||||
|
||||
|
||||
}
|
||||
EventQueue::~EventQueue() {
|
||||
|
||||
uint32_t read_pos=0;
|
||||
|
||||
|
||||
while (read_pos < buffer_end ) {
|
||||
|
||||
|
||||
Event *event = (Event*)&event_buffer[ read_pos ];
|
||||
Variant *args= (Variant*)(event+1);
|
||||
for (int i=0;i<event->args;i++)
|
||||
args[i].~Variant();
|
||||
event->~Event();
|
||||
|
||||
|
||||
read_pos+=sizeof(Event)+sizeof(Variant)*event->args;
|
||||
}
|
||||
|
||||
|
||||
memdelete_arr(event_buffer);
|
||||
event_buffer=NULL;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -36,18 +36,18 @@
|
||||
class EventQueue {
|
||||
|
||||
enum {
|
||||
|
||||
|
||||
DEFAULT_EVENT_QUEUE_SIZE_KB=256
|
||||
};
|
||||
|
||||
struct Event {
|
||||
|
||||
|
||||
uint32_t instance_ID;
|
||||
StringName method;
|
||||
int args;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t *event_buffer;
|
||||
uint32_t buffer_end;
|
||||
uint32_t buffer_max_used;
|
||||
@ -57,7 +57,7 @@ public:
|
||||
|
||||
Error push_call(uint32_t p_instance_ID, const StringName& p_method, VARIANT_ARG_LIST);
|
||||
void flush_events();
|
||||
|
||||
|
||||
EventQueue(uint32_t p_buffer_size=DEFAULT_EVENT_QUEUE_SIZE_KB*1024);
|
||||
~EventQueue();
|
||||
|
||||
|
||||
28
core/fpstr.cpp
Normal file
28
core/fpstr.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*************************************************************************/
|
||||
/* fpstr.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2015 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. */
|
||||
/*************************************************************************/
|
||||
28
core/fpstr.h
Normal file
28
core/fpstr.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*************************************************************************/
|
||||
/* fpstr.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2015 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. */
|
||||
/*************************************************************************/
|
||||
@ -1,31 +1,3 @@
|
||||
/*************************************************************************/
|
||||
/* func_ref.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 "func_ref.h"
|
||||
|
||||
Variant FuncRef::call_func(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
|
||||
@ -59,7 +31,8 @@ void FuncRef::_bind_methods() {
|
||||
|
||||
{
|
||||
MethodInfo mi;
|
||||
mi.name="call_func";
|
||||
mi.name="call";
|
||||
mi.arguments.push_back( PropertyInfo( Variant::STRING, "method"));
|
||||
Vector<Variant> defargs;
|
||||
for(int i=0;i<10;i++) {
|
||||
mi.arguments.push_back( PropertyInfo( Variant::NIL, "arg"+itos(i)));
|
||||
|
||||
@ -1,31 +1,3 @@
|
||||
/*************************************************************************/
|
||||
/* func_ref.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 FUNC_REF_H
|
||||
#define FUNC_REF_H
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 @@ static _GlobalConstant _global_constants[]={
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_ENTER ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_MULTIPLY ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_DIVIDE ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_SUBTRACT ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_SUBSTRACT ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_PERIOD ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_ADD ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_KP_0 ),
|
||||
@ -317,19 +317,16 @@ static _GlobalConstant _global_constants[]={
|
||||
BIND_GLOBAL_CONSTANT( KEY_MASK_KPAD ),
|
||||
BIND_GLOBAL_CONSTANT( KEY_MASK_GROUP_SWITCH ),
|
||||
|
||||
// mouse
|
||||
// joysticks
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_LEFT ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_RIGHT ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_MIDDLE ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_WHEEL_UP ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_WHEEL_DOWN ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_WHEEL_LEFT ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_WHEEL_RIGHT ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_MASK_LEFT ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_MASK_RIGHT ),
|
||||
BIND_GLOBAL_CONSTANT( BUTTON_MASK_MIDDLE ),
|
||||
|
||||
//joysticks
|
||||
BIND_GLOBAL_CONSTANT( JOY_BUTTON_0 ),
|
||||
BIND_GLOBAL_CONSTANT( JOY_BUTTON_1 ),
|
||||
BIND_GLOBAL_CONSTANT( JOY_BUTTON_2 ),
|
||||
@ -405,9 +402,6 @@ static _GlobalConstant _global_constants[]={
|
||||
BIND_GLOBAL_CONSTANT( JOY_ANALOG_2_X ),
|
||||
BIND_GLOBAL_CONSTANT( JOY_ANALOG_2_Y ),
|
||||
|
||||
BIND_GLOBAL_CONSTANT( JOY_ANALOG_L2 ),
|
||||
BIND_GLOBAL_CONSTANT( JOY_ANALOG_R2 ),
|
||||
|
||||
|
||||
// error list
|
||||
|
||||
@ -428,11 +422,9 @@ static _GlobalConstant _global_constants[]={
|
||||
BIND_GLOBAL_CONSTANT( ERR_FILE_CANT_READ ),
|
||||
BIND_GLOBAL_CONSTANT( ERR_FILE_UNRECOGNIZED ),
|
||||
BIND_GLOBAL_CONSTANT( ERR_FILE_CORRUPT ),
|
||||
BIND_GLOBAL_CONSTANT( ERR_FILE_MISSING_DEPENDENCIES),
|
||||
BIND_GLOBAL_CONSTANT( ERR_FILE_EOF ),
|
||||
BIND_GLOBAL_CONSTANT( ERR_CANT_OPEN ), ///< Can't open a resource/socket/file
|
||||
BIND_GLOBAL_CONSTANT( ERR_CANT_CREATE ),
|
||||
BIND_GLOBAL_CONSTANT( ERR_PARSE_ERROR ),
|
||||
BIND_GLOBAL_CONSTANT( ERROR_QUERY_FAILED ),
|
||||
BIND_GLOBAL_CONSTANT( ERR_ALREADY_IN_USE ),
|
||||
BIND_GLOBAL_CONSTANT( ERR_LOCKED ), ///< resource is locked
|
||||
@ -475,35 +467,11 @@ static _GlobalConstant _global_constants[]={
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS ),
|
||||
|
||||
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORAGE ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORAGE ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_EDITOR ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_NETWORK ),
|
||||
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_EDITOR_HELPER ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CHECKABLE ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CHECKED ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_INTERNATIONALIZED ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_BUNDLE ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CATEGORY ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORE_IF_NONZERO ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORE_IF_NONONE ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_NO_INSTANCE_STATE ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_RESTART_IF_CHANGED ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_SCRIPT_VARIABLE ),
|
||||
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_DEFAULT ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_DEFAULT_INTL ),
|
||||
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_NOEDITOR ),
|
||||
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAG_NORMAL ),
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAG_EDITOR ),
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAG_NOSCRIPT ),
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAG_CONST ),
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAG_REVERSE ),
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAG_VIRTUAL ),
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAG_FROM_SCRIPT ),
|
||||
BIND_GLOBAL_CONSTANT( METHOD_FLAGS_DEFAULT ),
|
||||
|
||||
{"TYPE_NIL",Variant::NIL},
|
||||
{"TYPE_BOOL",Variant::BOOL},
|
||||
{"TYPE_INT",Variant::INT},
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
121
core/globals.cpp
121
core/globals.cpp
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -40,7 +40,7 @@
|
||||
Globals *Globals::singleton=NULL;
|
||||
|
||||
Globals *Globals::get_singleton() {
|
||||
|
||||
|
||||
return singleton;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ 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://"))
|
||||
if (p_path.begins_with("res://"))
|
||||
return p_path.simplify_path();
|
||||
|
||||
|
||||
@ -82,8 +82,6 @@ String Globals::localize_path(const String& p_path) const {
|
||||
if (sep == -1) {
|
||||
return "res://"+path;
|
||||
};
|
||||
|
||||
|
||||
String parent = path.substr(0, sep);
|
||||
|
||||
String plocal = localize_path(parent);
|
||||
@ -110,7 +108,7 @@ bool Globals::is_persisting(const String& p_name) const {
|
||||
|
||||
|
||||
String Globals::globalize_path(const String& p_path) const {
|
||||
|
||||
|
||||
if (p_path.begins_with("res://")) {
|
||||
|
||||
if (resource_path != "") {
|
||||
@ -127,19 +125,15 @@ String Globals::globalize_path(const String& p_path) const {
|
||||
bool Globals::_set(const StringName& p_name, const Variant& p_value) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
|
||||
if (p_value.get_type()==Variant::NIL)
|
||||
props.erase(p_name);
|
||||
else {
|
||||
if (props.has(p_name)) {
|
||||
if (!props[p_name].overrided)
|
||||
props[p_name].variant=p_value;
|
||||
|
||||
if (props[p_name].order>=NO_ORDER_BASE && registering_order) {
|
||||
props[p_name].order=last_order++;
|
||||
}
|
||||
} else {
|
||||
props[p_name]=VariantContainer(p_value,last_order++ + (registering_order?0:NO_ORDER_BASE));
|
||||
props[p_name]=VariantContainer(p_value,last_order++);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +170,7 @@ bool Globals::_get(const StringName& p_name,Variant &r_ret) const {
|
||||
return false;
|
||||
r_ret=props[p_name].variant;
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct _VCSort {
|
||||
@ -190,13 +184,13 @@ struct _VCSort {
|
||||
};
|
||||
|
||||
void Globals::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
Set<_VCSort> vclist;
|
||||
|
||||
|
||||
for(Map<StringName,VariantContainer>::Element *E=props.front();E;E=E->next()) {
|
||||
|
||||
|
||||
const VariantContainer *v=&E->get();
|
||||
|
||||
if (v->hide_from_editor)
|
||||
@ -252,7 +246,7 @@ bool Globals::_load_resource_pack(const String& p_pack) {
|
||||
Error Globals::setup(const String& p_path,const String & p_main_pack) {
|
||||
|
||||
//an absolute mess of a function, must be cleaned up and reorganized somehow at some point
|
||||
|
||||
|
||||
//_load_settings(p_path+"/override.cfg");
|
||||
|
||||
if (p_main_pack!="") {
|
||||
@ -294,7 +288,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (FileAccessNetworkClient::get_singleton()) {
|
||||
|
||||
@ -306,7 +300,6 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (OS::get_singleton()->get_resource_dir()!="") {
|
||||
//OS will call Globals->get_resource_path which will be empty if not overriden!
|
||||
//if the OS would rather use somewhere else, then it will not be empty.
|
||||
@ -316,7 +309,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
|
||||
|
||||
print_line("has res dir: "+resource_path);
|
||||
if (!_load_resource_pack("res://data.pck"))
|
||||
_load_resource_pack("res://data.zip");
|
||||
_load_resource_pack("res://data.pcz");
|
||||
// make sure this is load from the resource path
|
||||
print_line("exists engine cfg? "+itos(FileAccess::exists("/engine.cfg")));
|
||||
if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
|
||||
@ -334,12 +327,11 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
|
||||
resource_path = p_path;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
d->change_dir(p_path);
|
||||
|
||||
String candidate = d->get_current_dir();
|
||||
String current_dir = d->get_current_dir();
|
||||
String exec_name = OS::get_singleton()->get_executable_path().get_file().basename();
|
||||
bool found = false;
|
||||
bool first_time=true;
|
||||
|
||||
@ -347,16 +339,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
|
||||
//try to load settings in ascending through dirs shape!
|
||||
|
||||
//tries to open pack, but only first time
|
||||
if (first_time && (_load_resource_pack(current_dir+"/"+exec_name+".pck") || _load_resource_pack(current_dir+"/"+exec_name+".zip") )) {
|
||||
if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
|
||||
|
||||
_load_settings("res://override.cfg");
|
||||
found=true;
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
} else if (first_time && (_load_resource_pack(current_dir+"/data.pck") || _load_resource_pack(current_dir+"/data.zip") )) {
|
||||
if (first_time && _load_resource_pack(current_dir+"/data.pck")) {
|
||||
if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
|
||||
|
||||
_load_settings("res://override.cfg");
|
||||
@ -397,7 +380,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
|
||||
}
|
||||
|
||||
bool Globals::has(String p_var) const {
|
||||
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
return props.has(p_var);
|
||||
@ -640,9 +623,7 @@ static Variant _decode_variant(const String& p_string) {
|
||||
InputEvent ie;
|
||||
ie.type=InputEvent::JOYSTICK_MOTION;
|
||||
ie.device=params[0].to_int();
|
||||
int axis = params[1].to_int();;
|
||||
ie.joy_motion.axis=axis>>1;
|
||||
ie.joy_motion.axis_value=axis&1?1:-1;
|
||||
ie.joy_motion.axis=params[1].to_int();
|
||||
|
||||
return ie;
|
||||
}
|
||||
@ -750,10 +731,6 @@ static Variant _decode_variant(const String& p_string) {
|
||||
return Variant();
|
||||
}
|
||||
|
||||
void Globals::set_registering_order(bool p_enable) {
|
||||
|
||||
registering_order=p_enable;
|
||||
}
|
||||
|
||||
Error Globals::_load_settings_binary(const String p_path) {
|
||||
|
||||
@ -773,8 +750,6 @@ Error Globals::_load_settings_binary(const String p_path) {
|
||||
ERR_FAIL_V(ERR_FILE_CORRUPT;)
|
||||
}
|
||||
|
||||
set_registering_order(false);
|
||||
|
||||
uint32_t count=f->get_32();
|
||||
|
||||
for(int i=0;i<count;i++) {
|
||||
@ -799,9 +774,6 @@ Error Globals::_load_settings_binary(const String p_path) {
|
||||
set_persisting(key,true);
|
||||
}
|
||||
|
||||
set_registering_order(true);
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
Error Globals::_load_settings(const String p_path) {
|
||||
@ -820,8 +792,6 @@ Error Globals::_load_settings(const String p_path) {
|
||||
String section;
|
||||
String subpath;
|
||||
|
||||
set_registering_order(false);
|
||||
|
||||
int line_count = 0;
|
||||
|
||||
while(!f->eof_reached()) {
|
||||
@ -897,7 +867,6 @@ Error Globals::_load_settings(const String p_path) {
|
||||
|
||||
memdelete(f);
|
||||
|
||||
set_registering_order(true);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -918,14 +887,6 @@ static String _encode_variant(const Variant& p_variant) {
|
||||
float val = p_variant;
|
||||
return rtos(val)+(val==int(val)?".0":"");
|
||||
} break;
|
||||
case Variant::VECTOR2: {
|
||||
Vector2 val = p_variant;
|
||||
return String("Vector2(")+rtos(val.x)+String(", ")+rtos(val.y)+String(")");
|
||||
} break;
|
||||
case Variant::VECTOR3: {
|
||||
Vector3 val = p_variant;
|
||||
return String("Vector3(")+rtos(val.x)+ String(", ") +rtos(val.y)+ String(", ") +rtos(val.z)+String(")");
|
||||
} break;
|
||||
case Variant::STRING: {
|
||||
String val = p_variant;
|
||||
return "\""+val.xml_escape()+"\"";
|
||||
@ -1041,7 +1002,7 @@ static String _encode_variant(const Variant& p_variant) {
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_MOTION: {
|
||||
|
||||
return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis * 2 + (ev.joy_motion.axis_value<0?0:1))+")";
|
||||
return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis)+")";
|
||||
} break;
|
||||
default: {
|
||||
|
||||
@ -1188,12 +1149,6 @@ Error Globals::_save_settings_text(const String& p_file,const Map<String,List<St
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error Globals::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
|
||||
|
||||
return save_custom(p_file);
|
||||
};
|
||||
|
||||
Error Globals::save_custom(const String& p_path,const CustomMap& p_custom,const Set<String>& p_ignore_masks) {
|
||||
|
||||
ERR_FAIL_COND_V(p_path=="",ERR_INVALID_PARAMETER);
|
||||
@ -1366,7 +1321,7 @@ Vector<String> Globals::get_optimizer_presets() const {
|
||||
|
||||
if (!E->get().name.begins_with("optimizer_presets/"))
|
||||
continue;
|
||||
names.push_back(E->get().name.get_slicec('/',1));
|
||||
names.push_back(E->get().name.get_slice("/",1));
|
||||
}
|
||||
|
||||
names.sort();
|
||||
@ -1403,21 +1358,18 @@ void Globals::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("localize_path","path"),&Globals::localize_path);
|
||||
ObjectTypeDB::bind_method(_MD("globalize_path","path"),&Globals::globalize_path);
|
||||
ObjectTypeDB::bind_method(_MD("save"),&Globals::save);
|
||||
ObjectTypeDB::bind_method(_MD("has_singleton","name"),&Globals::has_singleton);
|
||||
ObjectTypeDB::bind_method(_MD("get_singleton","name"),&Globals::get_singleton_object);
|
||||
ObjectTypeDB::bind_method(_MD("load_resource_pack","pack"),&Globals::_load_resource_pack);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("save_custom","file"),&Globals::_save_custom_bnd);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("has_singleton"),&Globals::has_singleton);
|
||||
ObjectTypeDB::bind_method(_MD("get_singleton"),&Globals::get_singleton_object);
|
||||
ObjectTypeDB::bind_method(_MD("load_resource_pack"),&Globals::_load_resource_pack);
|
||||
}
|
||||
|
||||
Globals::Globals() {
|
||||
|
||||
|
||||
|
||||
singleton=this;
|
||||
last_order=0;
|
||||
disable_platform_override=false;
|
||||
registering_order=true;
|
||||
|
||||
|
||||
|
||||
Array va;
|
||||
@ -1429,7 +1381,7 @@ Globals::Globals() {
|
||||
|
||||
set("application/name","" );
|
||||
set("application/main_scene","");
|
||||
custom_prop_info["application/main_scene"]=PropertyInfo(Variant::STRING,"application/main_scene",PROPERTY_HINT_FILE,"tscn,scn,xscn,xml,res");
|
||||
custom_prop_info["application/main_scene"]=PropertyInfo(Variant::STRING,"application/main_scene",PROPERTY_HINT_FILE,"scn,res,xscn,xml");
|
||||
set("application/disable_stdout",false);
|
||||
set("application/use_shared_user_dir",true);
|
||||
|
||||
@ -1443,15 +1395,6 @@ Globals::Globals() {
|
||||
joyb.joy_button.button_index=JOY_BUTTON_0;
|
||||
va.push_back(joyb);
|
||||
set("input/ui_accept",va);
|
||||
input_presets.push_back("input/ui_accept");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_SPACE;
|
||||
va.push_back(key);
|
||||
joyb.joy_button.button_index=JOY_BUTTON_3;
|
||||
va.push_back(joyb);
|
||||
set("input/ui_select",va);
|
||||
input_presets.push_back("input/ui_select");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_ESCAPE;
|
||||
@ -1459,20 +1402,17 @@ Globals::Globals() {
|
||||
joyb.joy_button.button_index=JOY_BUTTON_1;
|
||||
va.push_back(joyb);
|
||||
set("input/ui_cancel",va);
|
||||
input_presets.push_back("input/ui_cancel");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_TAB;
|
||||
va.push_back(key);
|
||||
set("input/ui_focus_next",va);
|
||||
input_presets.push_back("input/ui_focus_next");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_TAB;
|
||||
key.key.mod.shift=true;
|
||||
va.push_back(key);
|
||||
set("input/ui_focus_prev",va);
|
||||
input_presets.push_back("input/ui_focus_prev");
|
||||
key.key.mod.shift=false;
|
||||
|
||||
va=Array();
|
||||
@ -1481,7 +1421,6 @@ Globals::Globals() {
|
||||
joyb.joy_button.button_index=JOY_DPAD_LEFT;
|
||||
va.push_back(joyb);
|
||||
set("input/ui_left",va);
|
||||
input_presets.push_back("input/ui_left");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_RIGHT;
|
||||
@ -1489,7 +1428,6 @@ Globals::Globals() {
|
||||
joyb.joy_button.button_index=JOY_DPAD_RIGHT;
|
||||
va.push_back(joyb);
|
||||
set("input/ui_right",va);
|
||||
input_presets.push_back("input/ui_right");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_UP;
|
||||
@ -1497,7 +1435,6 @@ Globals::Globals() {
|
||||
joyb.joy_button.button_index=JOY_DPAD_UP;
|
||||
va.push_back(joyb);
|
||||
set("input/ui_up",va);
|
||||
input_presets.push_back("input/ui_up");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_DOWN;
|
||||
@ -1505,20 +1442,17 @@ Globals::Globals() {
|
||||
joyb.joy_button.button_index=JOY_DPAD_DOWN;
|
||||
va.push_back(joyb);
|
||||
set("input/ui_down",va);
|
||||
input_presets.push_back("input/ui_down");
|
||||
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_PAGEUP;
|
||||
va.push_back(key);
|
||||
set("input/ui_page_up",va);
|
||||
input_presets.push_back("input/ui_page_up");
|
||||
|
||||
va=Array();
|
||||
key.key.scancode=KEY_PAGEDOWN;
|
||||
va.push_back(key);
|
||||
set("input/ui_page_down",va);
|
||||
input_presets.push_back("input/ui_page_down");
|
||||
|
||||
// set("display/orientation", "landscape");
|
||||
|
||||
@ -1526,15 +1460,14 @@ Globals::Globals() {
|
||||
custom_prop_info["display/orientation"]=PropertyInfo(Variant::STRING,"display/orientation",PROPERTY_HINT_ENUM,"landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
|
||||
custom_prop_info["render/mipmap_policy"]=PropertyInfo(Variant::INT,"render/mipmap_policy",PROPERTY_HINT_ENUM,"Allow,Allow For Po2,Disallow");
|
||||
custom_prop_info["render/thread_model"]=PropertyInfo(Variant::INT,"render/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
|
||||
custom_prop_info["physics_2d/thread_model"]=PropertyInfo(Variant::INT,"physics_2d/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
|
||||
set("display/emulate_touchscreen",false);
|
||||
|
||||
set("debug/profiler_max_functions",16384);
|
||||
using_datapack=false;
|
||||
}
|
||||
|
||||
|
||||
Globals::~Globals() {
|
||||
|
||||
|
||||
singleton=NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,7 +38,7 @@
|
||||
|
||||
|
||||
class Globals : public Object {
|
||||
|
||||
|
||||
OBJ_TYPE( Globals, Object );
|
||||
_THREAD_SAFE_CLASS_
|
||||
|
||||
@ -54,10 +54,6 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
enum {
|
||||
NO_ORDER_BASE=1<<18
|
||||
};
|
||||
|
||||
struct VariantContainer {
|
||||
int order;
|
||||
bool persist;
|
||||
@ -68,22 +64,20 @@ protected:
|
||||
VariantContainer(const Variant& p_variant, int p_order, bool p_persist=false) { variant=p_variant; order=p_order; hide_from_editor=false; persist=p_persist; overrided=false; }
|
||||
};
|
||||
|
||||
bool registering_order;
|
||||
int last_order;
|
||||
Map<StringName,VariantContainer> props;
|
||||
String resource_path;
|
||||
Map<StringName,PropertyInfo> custom_prop_info;
|
||||
bool disable_platform_override;
|
||||
bool using_datapack;
|
||||
List<String> input_presets;
|
||||
|
||||
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
|
||||
static Globals *singleton;
|
||||
|
||||
|
||||
Error _load_settings(const String p_path);
|
||||
Error _load_settings_binary(const String p_path);
|
||||
|
||||
@ -92,7 +86,6 @@ protected:
|
||||
|
||||
List<Singleton> singletons;
|
||||
|
||||
Error _save_custom_bnd(const String& p_file);
|
||||
|
||||
bool _load_resource_pack(const String& p_pack);
|
||||
|
||||
@ -101,7 +94,7 @@ protected:
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
|
||||
|
||||
bool has(String p_var) const;
|
||||
String localize_path(const String& p_path) const;
|
||||
String globalize_path(const String& p_path) const;
|
||||
@ -110,13 +103,13 @@ public:
|
||||
bool is_persisting(const String& p_name) const;
|
||||
|
||||
String get_resource_path() const;
|
||||
|
||||
|
||||
static Globals *get_singleton();
|
||||
|
||||
void clear(const String& p_name);
|
||||
int get_order(const String& p_name) const;
|
||||
void set_order(const String& p_name, int p_order);
|
||||
|
||||
|
||||
Error setup(const String& p_path, const String &p_main_pack);
|
||||
|
||||
Error save_custom(const String& p_path="",const CustomMap& p_custom=CustomMap(),const Set<String>& p_ignore_masks=Set<String>());
|
||||
@ -130,8 +123,6 @@ public:
|
||||
|
||||
Vector<String> get_optimizer_presets() const;
|
||||
|
||||
List<String> get_input_presets() const { return input_presets; }
|
||||
|
||||
void set_disable_platform_override(bool p_disable);
|
||||
Object* get_singleton_object(const String& p_name) const;
|
||||
|
||||
@ -139,9 +130,7 @@ public:
|
||||
|
||||
bool is_using_datapack() const;
|
||||
|
||||
void set_registering_order(bool p_registering);
|
||||
|
||||
Globals();
|
||||
Globals();
|
||||
~Globals();
|
||||
|
||||
};
|
||||
|
||||
332
core/hash_map.h
332
core/hash_map.h
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,7 +38,7 @@
|
||||
|
||||
class HashMapHahserDefault {
|
||||
public:
|
||||
|
||||
|
||||
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
|
||||
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
|
||||
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) {
|
||||
@ -66,8 +66,8 @@ public:
|
||||
|
||||
/**
|
||||
* @class HashMap
|
||||
* @author Juan Linietsky <reduzio@gmail.com>
|
||||
*
|
||||
* @author Juan Linietsky <reduzio@gmail.com>
|
||||
*
|
||||
* Implementation of a standard Hashing HashMap, for quick lookups of Data associated with a Key.
|
||||
* The implementation provides hashers for the default types, if you need a special kind of hasher, provide
|
||||
* your own.
|
||||
@ -77,213 +77,213 @@ public:
|
||||
* @param MIN_HASH_TABLE_POWER Miminum size of the hash table, as a power of two. You rarely need to change this parameter.
|
||||
* @param RELATIONSHIP Relationship at which the hash table is resized. if amount of elements is RELATIONSHIP
|
||||
* times bigger than the hash table, table is resized to solve this condition. if RELATIONSHIP is zero, table is always MIN_HASH_TABLE_POWER.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
template<class TKey, class TData, class Hasher=HashMapHahserDefault,uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8>
|
||||
class HashMap {
|
||||
public:
|
||||
|
||||
public:
|
||||
|
||||
struct Pair {
|
||||
|
||||
|
||||
TKey key;
|
||||
TData data;
|
||||
|
||||
|
||||
Pair() {}
|
||||
Pair(const TKey& p_key, const TData& p_data) { key=p_key; data=p_data; }
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
|
||||
|
||||
uint32_t hash;
|
||||
Entry *next;
|
||||
Pair pair;
|
||||
|
||||
|
||||
Entry() { next=0; }
|
||||
};
|
||||
|
||||
|
||||
Entry **hash_table;
|
||||
uint8_t hash_table_power;
|
||||
uint32_t elements;
|
||||
|
||||
|
||||
void make_hash_table() {
|
||||
|
||||
|
||||
ERR_FAIL_COND( hash_table );
|
||||
|
||||
|
||||
|
||||
|
||||
hash_table = memnew_arr( Entry*, (1<<MIN_HASH_TABLE_POWER) );
|
||||
|
||||
|
||||
hash_table_power = MIN_HASH_TABLE_POWER;
|
||||
elements=0;
|
||||
for (int i=0;i<(1<<MIN_HASH_TABLE_POWER);i++)
|
||||
hash_table[i]=0;
|
||||
}
|
||||
|
||||
|
||||
void erase_hash_table() {
|
||||
|
||||
|
||||
ERR_FAIL_COND(elements);
|
||||
|
||||
|
||||
memdelete_arr( hash_table );
|
||||
hash_table=0;
|
||||
hash_table_power=0;
|
||||
elements=0;
|
||||
}
|
||||
|
||||
hash_table_power=0;
|
||||
elements=0;
|
||||
}
|
||||
|
||||
void check_hash_table() {
|
||||
|
||||
int new_hash_table_power=-1;
|
||||
|
||||
|
||||
if ((int)elements > ( (1<<hash_table_power) * RELATIONSHIP ) ) {
|
||||
/* rehash up */
|
||||
new_hash_table_power=hash_table_power+1;
|
||||
|
||||
|
||||
while( (int)elements > ( (1<<new_hash_table_power) * RELATIONSHIP ) ) {
|
||||
|
||||
|
||||
new_hash_table_power++;
|
||||
}
|
||||
|
||||
|
||||
} else if ( (hash_table_power>(int)MIN_HASH_TABLE_POWER) && ((int)elements < ( (1<<(hash_table_power-1)) * RELATIONSHIP ) ) ) {
|
||||
|
||||
|
||||
/* rehash down */
|
||||
new_hash_table_power=hash_table_power-1;
|
||||
|
||||
|
||||
while( (int)elements < ( (1<<(new_hash_table_power-1)) * RELATIONSHIP ) ) {
|
||||
|
||||
|
||||
new_hash_table_power--;
|
||||
}
|
||||
|
||||
|
||||
if (new_hash_table_power<(int)MIN_HASH_TABLE_POWER)
|
||||
new_hash_table_power=MIN_HASH_TABLE_POWER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (new_hash_table_power==-1)
|
||||
return;
|
||||
|
||||
|
||||
Entry ** new_hash_table = memnew_arr( Entry*, (1<<new_hash_table_power) );
|
||||
if (!new_hash_table) {
|
||||
|
||||
|
||||
ERR_PRINT("Out of Memory");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<(1<<new_hash_table_power);i++) {
|
||||
|
||||
|
||||
new_hash_table[i]=0;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<(1<<hash_table_power);i++) {
|
||||
|
||||
|
||||
while( hash_table[i] ) {
|
||||
|
||||
|
||||
Entry *se=hash_table[i];
|
||||
hash_table[i]=se->next;
|
||||
int new_pos = se->hash & ((1<<new_hash_table_power)-1);
|
||||
se->next=new_hash_table[new_pos];
|
||||
new_hash_table[new_pos]=se;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (hash_table)
|
||||
memdelete_arr( hash_table );
|
||||
hash_table=new_hash_table;
|
||||
hash_table_power=new_hash_table_power;
|
||||
hash_table_power=new_hash_table_power;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* I want to have only one function.. */
|
||||
_FORCE_INLINE_ const Entry * get_entry( const TKey& p_key ) const {
|
||||
|
||||
|
||||
uint32_t hash = Hasher::hash( p_key );
|
||||
uint32_t index = hash&((1<<hash_table_power)-1);
|
||||
|
||||
|
||||
Entry *e = hash_table[index];
|
||||
|
||||
|
||||
while (e) {
|
||||
|
||||
|
||||
/* checking hash first avoids comparing key, which may take longer */
|
||||
if (e->hash == hash && e->pair.key == p_key ) {
|
||||
|
||||
|
||||
/* the pair exists in this hashtable, so just update data */
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
e=e->next;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Entry * create_entry(const TKey& p_key) {
|
||||
|
||||
|
||||
/* if entry doesn't exist, create it */
|
||||
Entry *e = memnew( Entry );
|
||||
ERR_FAIL_COND_V(!e,NULL); /* out of memory */
|
||||
uint32_t hash = Hasher::hash( p_key );
|
||||
uint32_t index = hash&((1<<hash_table_power)-1);
|
||||
e->next = hash_table[index];
|
||||
e->next = hash_table[index];
|
||||
e->hash = hash;
|
||||
e->pair.key=p_key;
|
||||
|
||||
|
||||
hash_table[index]=e;
|
||||
elements++;
|
||||
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void copy_from(const HashMap& p_t) {
|
||||
|
||||
|
||||
if (&p_t==this)
|
||||
return; /* much less bother with that */
|
||||
|
||||
|
||||
clear();
|
||||
|
||||
|
||||
if (!p_t.hash_table || p_t.hash_table_power==0)
|
||||
return; /* not copying from empty table */
|
||||
|
||||
|
||||
hash_table = memnew_arr(Entry*,1<<p_t.hash_table_power);
|
||||
hash_table_power=p_t.hash_table_power;
|
||||
elements=p_t.elements;
|
||||
|
||||
|
||||
for (int i=0;i<( 1<<p_t.hash_table_power );i++) {
|
||||
|
||||
|
||||
hash_table[i]=NULL;
|
||||
/* elements will be in the reverse order, but it doesn't matter */
|
||||
|
||||
|
||||
const Entry *e = p_t.hash_table[i];
|
||||
|
||||
|
||||
while(e) {
|
||||
|
||||
|
||||
Entry *le = memnew( Entry ); /* local entry */
|
||||
|
||||
|
||||
*le=*e; /* copy data */
|
||||
|
||||
|
||||
/* add to list and reassign pointers */
|
||||
le->next=hash_table[i];
|
||||
hash_table[i]=le;
|
||||
|
||||
|
||||
e=e->next;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
void set( const TKey& p_key, const TData& p_data ) {
|
||||
|
||||
|
||||
set( Pair( p_key, p_data ) );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void set( const Pair& p_pair ) {
|
||||
|
||||
Entry *e=NULL;
|
||||
@ -291,63 +291,63 @@ public:
|
||||
make_hash_table(); // if no table, make one
|
||||
else
|
||||
e = const_cast<Entry*>( get_entry(p_pair.key) );
|
||||
|
||||
|
||||
/* if we made it up to here, the pair doesn't exist, create and assign */
|
||||
|
||||
|
||||
if (!e) {
|
||||
|
||||
|
||||
e=create_entry(p_pair.key);
|
||||
if (!e)
|
||||
return;
|
||||
check_hash_table(); // perform mantenience routine
|
||||
}
|
||||
|
||||
|
||||
e->pair.data = p_pair.data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool has( const TKey& p_key ) const {
|
||||
|
||||
|
||||
return getptr(p_key)!=NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a key from data, return a const reference.
|
||||
* Get a key from data, return a const reference.
|
||||
* WARNING: this doesn't check errors, use either getptr and check NULL, or check
|
||||
* first with has(key)
|
||||
*/
|
||||
|
||||
|
||||
const TData& get( const TKey& p_key ) const {
|
||||
|
||||
|
||||
const TData* res = getptr(p_key);
|
||||
ERR_FAIL_COND_V(!res,*res);
|
||||
return *res;
|
||||
}
|
||||
|
||||
|
||||
TData& get( const TKey& p_key ) {
|
||||
|
||||
|
||||
TData* res = getptr(p_key);
|
||||
ERR_FAIL_COND_V(!res,*res);
|
||||
return *res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as get, except it can return NULL when item was not found.
|
||||
* This is mainly used for speed purposes.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
_FORCE_INLINE_ TData* getptr( const TKey& p_key ) {
|
||||
|
||||
|
||||
if (!hash_table)
|
||||
return NULL;
|
||||
|
||||
|
||||
Entry *e=const_cast<Entry*>(get_entry(p_key ));
|
||||
|
||||
|
||||
if (e)
|
||||
return &e->pair.data;
|
||||
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
@ -427,108 +427,108 @@ public:
|
||||
/**
|
||||
* Erase an item, return true if erasing was succesful
|
||||
*/
|
||||
|
||||
|
||||
bool erase( const TKey& p_key ) {
|
||||
|
||||
|
||||
if (!hash_table)
|
||||
return false;
|
||||
|
||||
|
||||
uint32_t hash = Hasher::hash( p_key );
|
||||
uint32_t index = hash&((1<<hash_table_power)-1);
|
||||
|
||||
|
||||
|
||||
|
||||
Entry *e = hash_table[index];
|
||||
Entry *p=NULL;
|
||||
while (e) {
|
||||
|
||||
|
||||
/* checking hash first avoids comparing key, which may take longer */
|
||||
if (e->hash == hash && e->pair.key == p_key ) {
|
||||
|
||||
|
||||
if (p) {
|
||||
|
||||
|
||||
p->next=e->next;
|
||||
} else {
|
||||
} else {
|
||||
//begin of list
|
||||
hash_table[index]=e->next;
|
||||
}
|
||||
|
||||
|
||||
memdelete(e);
|
||||
elements--;
|
||||
|
||||
|
||||
if (elements==0)
|
||||
erase_hash_table();
|
||||
else
|
||||
check_hash_table();
|
||||
check_hash_table();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
p=e;
|
||||
e=e->next;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline const TData& operator[](const TKey& p_key) const { //constref
|
||||
|
||||
|
||||
return get(p_key);
|
||||
}
|
||||
inline TData& operator[](const TKey& p_key ) { //assignment
|
||||
|
||||
|
||||
Entry *e=NULL;
|
||||
if (!hash_table)
|
||||
make_hash_table(); // if no table, make one
|
||||
else
|
||||
e = const_cast<Entry*>( get_entry(p_key) );
|
||||
|
||||
|
||||
/* if we made it up to here, the pair doesn't exist, create */
|
||||
if (!e) {
|
||||
|
||||
|
||||
e=create_entry(p_key);
|
||||
if (!e)
|
||||
return *(TData*)NULL; /* panic! */
|
||||
check_hash_table(); // perform mantenience routine
|
||||
}
|
||||
|
||||
|
||||
return e->pair.data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next key to p_key, and the first key if p_key is null.
|
||||
|
||||
/**
|
||||
* Get the next key to p_key, and the first key if p_key is null.
|
||||
* Returns a pointer to the next key if found, NULL otherwise.
|
||||
* Adding/Removing elements while iterating will, of course, have unexpected results, don't do it.
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
*
|
||||
* const TKey *k=NULL;
|
||||
*
|
||||
*
|
||||
* while( (k=table.next(k)) ) {
|
||||
*
|
||||
*
|
||||
* print( *k );
|
||||
* }
|
||||
*
|
||||
*
|
||||
*/
|
||||
const TKey* next(const TKey* p_key) const {
|
||||
|
||||
|
||||
if (!hash_table) return NULL;
|
||||
|
||||
|
||||
if (!p_key) { /* get the first key */
|
||||
|
||||
|
||||
for (int i=0;i<(1<<hash_table_power);i++) {
|
||||
|
||||
|
||||
if (hash_table[i]) {
|
||||
return &hash_table[i]->pair.key;
|
||||
}
|
||||
}
|
||||
|
||||
} else { /* get the next key */
|
||||
|
||||
|
||||
const Entry *e = get_entry( *p_key );
|
||||
ERR_FAIL_COND_V( !e, NULL ); /* invalid key supplied */
|
||||
|
||||
|
||||
if (e->next) {
|
||||
/* if there is a "next" in the list, return that */
|
||||
return &e->next->pair.key;
|
||||
@ -537,60 +537,60 @@ public:
|
||||
uint32_t index = e->hash&((1<<hash_table_power)-1);
|
||||
index++;
|
||||
for (int i=index;i<(1<<hash_table_power);i++) {
|
||||
|
||||
|
||||
if (hash_table[i]) {
|
||||
return &hash_table[i]->pair.key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* nothing found, was at end */
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return NULL; /* nothing found */
|
||||
}
|
||||
|
||||
|
||||
inline unsigned int size() const {
|
||||
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
|
||||
inline bool empty() const {
|
||||
|
||||
|
||||
return elements==0;
|
||||
}
|
||||
|
||||
|
||||
void clear() {
|
||||
|
||||
|
||||
/* clean up */
|
||||
if (hash_table) {
|
||||
for (int i=0;i<(1<<hash_table_power);i++) {
|
||||
|
||||
|
||||
while (hash_table[i]) {
|
||||
|
||||
|
||||
Entry *e=hash_table[i];
|
||||
hash_table[i]=e->next;
|
||||
memdelete( e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
memdelete_arr( hash_table );
|
||||
}
|
||||
|
||||
|
||||
hash_table=0;
|
||||
hash_table_power=0;
|
||||
elements=0;
|
||||
elements=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void operator=(const HashMap& p_table) {
|
||||
|
||||
|
||||
copy_from(p_table);
|
||||
}
|
||||
|
||||
HashMap() {
|
||||
|
||||
HashMap() {
|
||||
hash_table=NULL;
|
||||
elements=0;
|
||||
hash_table_power=0;
|
||||
@ -609,18 +609,18 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
HashMap(const HashMap& p_table) {
|
||||
|
||||
HashMap(const HashMap& p_table) {
|
||||
|
||||
hash_table=NULL;
|
||||
elements=0;
|
||||
hash_table_power=0;
|
||||
|
||||
|
||||
copy_from(p_table);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
~HashMap() {
|
||||
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -47,10 +47,10 @@ static inline uint32_t hash_djb2(const char *p_cstr) {
|
||||
const unsigned char* chr=(const unsigned char*)p_cstr;
|
||||
uint32_t hash = 5381;
|
||||
uint32_t c;
|
||||
|
||||
|
||||
while ((c = *chr++))
|
||||
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
||||
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ static inline uint32_t make_uint32_t(T p_in) {
|
||||
T t;
|
||||
uint32_t _u32;
|
||||
} _u;
|
||||
_u._u32=0;
|
||||
_u._u32=0;
|
||||
_u.t=p_in;
|
||||
return _u._u32;
|
||||
}
|
||||
@ -106,7 +106,7 @@ static inline uint64_t make_uint64_t(T p_in) {
|
||||
uint64_t _u64;
|
||||
} _u;
|
||||
_u._u64=0; // in case p_in is smaller
|
||||
|
||||
|
||||
_u.t=p_in;
|
||||
return _u._u64;
|
||||
}
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* value_evaluator.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 VALUE_EVALUATOR_H
|
||||
#define VALUE_EVALUATOR_H
|
||||
|
||||
#include "core/object.h"
|
||||
|
||||
class ValueEvaluator : public Object {
|
||||
|
||||
OBJ_TYPE(ValueEvaluator, Object);
|
||||
public:
|
||||
virtual double eval(const String& p_text) {
|
||||
return p_text.to_double();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // VALUE_EVALUATOR_H
|
||||
2636
core/hq2x.cpp
2636
core/hq2x.cpp
File diff suppressed because it is too large
Load Diff
19
core/hq2x.h
19
core/hq2x.h
@ -1,19 +0,0 @@
|
||||
#ifndef HQ2X_H
|
||||
#define HQ2X_H
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
|
||||
uint32_t *hq2x_resize(
|
||||
const uint32_t *image,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t *output,
|
||||
uint32_t trY = 0x30,
|
||||
uint32_t trU = 0x07,
|
||||
uint32_t trV = 0x06,
|
||||
uint32_t trA = 0x50,
|
||||
bool wrapX = false,
|
||||
bool wrapY = false );
|
||||
|
||||
#endif // HQ2X_H
|
||||
485
core/image.cpp
485
core/image.cpp
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,37 +30,10 @@
|
||||
#include "hash_map.h"
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/os/copymem.h"
|
||||
#include "hq2x.h"
|
||||
|
||||
#include "print_string.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
const char* Image::format_names[Image::FORMAT_MAX]={
|
||||
"Grayscale",
|
||||
"Intensity",
|
||||
"GrayscaleAlpha",
|
||||
"RGB",
|
||||
"RGBA",
|
||||
"Indexed",
|
||||
"IndexedAlpha",
|
||||
"YUV422",
|
||||
"YUV444",
|
||||
"BC1",
|
||||
"BC2",
|
||||
"BC3",
|
||||
"BC4",
|
||||
"BC5",
|
||||
"PVRTC2",
|
||||
"PVRTC2Alpha",
|
||||
"PVRTC4",
|
||||
"PVRTC4Alpha",
|
||||
"ETC",
|
||||
"ATC",
|
||||
"ATCAlphaExp",
|
||||
"ATCAlphaInterp",
|
||||
|
||||
};
|
||||
|
||||
SavePNGFunc Image::save_png_func = NULL;
|
||||
|
||||
void Image::_put_pixel(int p_x,int p_y, const BColor& p_color, unsigned char *p_data) {
|
||||
@ -322,7 +295,7 @@ void Image::set_pallete(const DVector<uint8_t>& p_data) {
|
||||
DVector<uint8_t>::Write wp = data.write();
|
||||
unsigned char *dst=wp.ptr() + pal_ofs;
|
||||
|
||||
DVector<uint8_t>::Read r = p_data.read();
|
||||
DVector<uint8_t>::Read r = data.read();
|
||||
const unsigned char *src=r.ptr();
|
||||
|
||||
copymem(dst, src, len);
|
||||
@ -382,7 +355,7 @@ void Image::convert( Format p_new_format ){
|
||||
|
||||
|
||||
Image new_img(width,height,0,p_new_format);
|
||||
|
||||
|
||||
int len=data.size();
|
||||
|
||||
DVector<uint8_t>::Read r = data.read();
|
||||
@ -413,7 +386,7 @@ void Image::convert( Format p_new_format ){
|
||||
w = DVector<uint8_t>::Write();
|
||||
|
||||
bool gen_mipmaps=mipmaps>0;
|
||||
|
||||
|
||||
*this=new_img;
|
||||
|
||||
if (gen_mipmaps)
|
||||
@ -427,102 +400,6 @@ Image::Format Image::get_format() const{
|
||||
return format;
|
||||
}
|
||||
|
||||
static double _bicubic_interp_kernel( double x ) {
|
||||
|
||||
x = ABS(x);
|
||||
|
||||
double bc = 0;
|
||||
|
||||
if ( x <= 1 )
|
||||
bc = ( 1.5 * x - 2.5 ) * x * x + 1;
|
||||
else if ( x < 2 )
|
||||
bc = ( ( -0.5 * x + 2.5 ) * x - 4 ) * x + 2;
|
||||
|
||||
|
||||
return bc;
|
||||
}
|
||||
|
||||
template<int CC>
|
||||
static void _scale_cubic(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
|
||||
|
||||
|
||||
// get source image size
|
||||
int width = p_src_width;
|
||||
int height = p_src_height;
|
||||
double xfac = (double) width / p_dst_width;
|
||||
double yfac = (double) height / p_dst_height;
|
||||
// coordinates of source points and cooefficiens
|
||||
double ox, oy, dx, dy, k1, k2;
|
||||
int ox1, oy1, ox2, oy2;
|
||||
// destination pixel values
|
||||
// width and height decreased by 1
|
||||
int ymax = height - 1;
|
||||
int xmax = width - 1;
|
||||
// temporary pointer
|
||||
|
||||
for ( int y = 0; y < p_dst_height; y++ ) {
|
||||
// Y coordinates
|
||||
oy = (double) y * yfac - 0.5f;
|
||||
oy1 = (int) oy;
|
||||
dy = oy - (double) oy1;
|
||||
|
||||
for ( int x = 0; x < p_dst_width; x++ ) {
|
||||
// X coordinates
|
||||
ox = (double) x * xfac - 0.5f;
|
||||
ox1 = (int) ox;
|
||||
dx = ox - (double) ox1;
|
||||
|
||||
// initial pixel value
|
||||
|
||||
uint8_t *dst=p_dst + (y*p_dst_width+x)*CC;
|
||||
|
||||
double color[CC];
|
||||
for(int i=0;i<CC;i++) {
|
||||
color[i]=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for ( int n = -1; n < 3; n++ ) {
|
||||
// get Y cooefficient
|
||||
k1 = _bicubic_interp_kernel( dy - (double) n );
|
||||
|
||||
oy2 = oy1 + n;
|
||||
if ( oy2 < 0 )
|
||||
oy2 = 0;
|
||||
if ( oy2 > ymax )
|
||||
oy2 = ymax;
|
||||
|
||||
for ( int m = -1; m < 3; m++ ) {
|
||||
// get X cooefficient
|
||||
k2 = k1 * _bicubic_interp_kernel( (double) m - dx );
|
||||
|
||||
ox2 = ox1 + m;
|
||||
if ( ox2 < 0 )
|
||||
ox2 = 0;
|
||||
if ( ox2 > xmax )
|
||||
ox2 = xmax;
|
||||
|
||||
// get pixel of original image
|
||||
const uint8_t *p = p_src + (oy2 * p_src_width + ox2)*CC;
|
||||
|
||||
for(int i=0;i<CC;i++) {
|
||||
|
||||
color[i]+=p[i]*k2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<CC;i++) {
|
||||
dst[i]=CLAMP(Math::fast_ftoi(color[i]),0,255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<int CC>
|
||||
static void _scale_bilinear(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
|
||||
|
||||
@ -643,13 +520,13 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
|
||||
ERR_FAIL_COND(p_height<=0);
|
||||
ERR_FAIL_COND(p_width>MAX_WIDTH);
|
||||
ERR_FAIL_COND(p_height>MAX_HEIGHT);
|
||||
|
||||
|
||||
|
||||
if (p_width==width && p_height==height)
|
||||
return;
|
||||
|
||||
|
||||
Image dst( p_width, p_height, 0, format );
|
||||
|
||||
|
||||
if (format==FORMAT_INDEXED)
|
||||
p_interpolation=INTERPOLATE_NEAREST;
|
||||
|
||||
@ -682,17 +559,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
|
||||
}
|
||||
|
||||
} break;
|
||||
case INTERPOLATE_CUBIC: {
|
||||
|
||||
switch(get_format_pixel_size(format)) {
|
||||
case 1: _scale_cubic<1>(r_ptr,w_ptr,width,height,p_width,p_height); break;
|
||||
case 2: _scale_cubic<2>(r_ptr,w_ptr,width,height,p_width,p_height); break;
|
||||
case 3: _scale_cubic<3>(r_ptr,w_ptr,width,height,p_width,p_height); break;
|
||||
case 4: _scale_cubic<4>(r_ptr,w_ptr,width,height,p_width,p_height); break;
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -714,34 +580,34 @@ void Image::crop( int p_width, int p_height ) {
|
||||
ERR_FAIL_COND(p_height<=0);
|
||||
ERR_FAIL_COND(p_width>MAX_WIDTH);
|
||||
ERR_FAIL_COND(p_height>MAX_HEIGHT);
|
||||
|
||||
|
||||
/* to save memory, cropping should be done in-place, however, since this function
|
||||
will most likely either not be used much, or in critical areas, for now it wont, because
|
||||
it's a waste of time. */
|
||||
|
||||
if (p_width==width && p_height==height)
|
||||
return;
|
||||
|
||||
|
||||
Image dst( p_width, p_height,0, format );
|
||||
|
||||
|
||||
|
||||
for (int y=0;y<p_height;y++) {
|
||||
|
||||
|
||||
for (int x=0;x<p_width;x++) {
|
||||
|
||||
Color col = (x>=width || y>=height)? Color() : get_pixel(x,y);
|
||||
dst.put_pixel(x,y,col);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mipmaps>0)
|
||||
dst.generate_mipmaps();
|
||||
*this=dst;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Image::flip_y() {
|
||||
|
||||
|
||||
if (!_can_modify(format)) {
|
||||
ERR_EXPLAIN("Cannot flip_y in indexed, compressed or custom image formats.");
|
||||
ERR_FAIL();
|
||||
@ -756,12 +622,12 @@ void Image::flip_y() {
|
||||
|
||||
|
||||
for (int y=0;y<(height/2);y++) {
|
||||
|
||||
|
||||
for (int x=0;x<width;x++) {
|
||||
|
||||
Color up = get_pixel(x,y);
|
||||
Color down = get_pixel(x,height-y-1);
|
||||
|
||||
|
||||
put_pixel(x,y,down);
|
||||
put_pixel(x,height-y-1,up);
|
||||
}
|
||||
@ -783,12 +649,12 @@ void Image::flip_x() {
|
||||
clear_mipmaps();;
|
||||
|
||||
for (int y=0;y<(height/2);y++) {
|
||||
|
||||
|
||||
for (int x=0;x<width;x++) {
|
||||
|
||||
|
||||
Color up = get_pixel(x,y);
|
||||
Color down = get_pixel(width-x-1,y);
|
||||
|
||||
|
||||
put_pixel(x,y,down);
|
||||
put_pixel(width-x-1,y,up);
|
||||
}
|
||||
@ -901,104 +767,6 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
|
||||
}
|
||||
|
||||
|
||||
void Image::expand_x2_hq2x() {
|
||||
|
||||
ERR_FAIL_COND(format>=FORMAT_INDEXED);
|
||||
|
||||
Format current = format;
|
||||
bool mipmaps=get_mipmaps();
|
||||
if (mipmaps) {
|
||||
clear_mipmaps();
|
||||
}
|
||||
|
||||
if (current!=FORMAT_RGBA)
|
||||
convert(FORMAT_RGBA);
|
||||
|
||||
DVector<uint8_t> dest;
|
||||
dest.resize(width*2*height*2*4);
|
||||
|
||||
{
|
||||
DVector<uint8_t>::Read r = data.read();
|
||||
DVector<uint8_t>::Write w = dest.write();
|
||||
|
||||
hq2x_resize((const uint32_t*)r.ptr(),width,height,(uint32_t*)w.ptr());
|
||||
|
||||
}
|
||||
|
||||
width*=2;
|
||||
height*=2;
|
||||
data=dest;
|
||||
|
||||
|
||||
if (current!=FORMAT_RGBA)
|
||||
convert(current);
|
||||
|
||||
if (mipmaps) {
|
||||
generate_mipmaps();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Image::shrink_x2() {
|
||||
|
||||
ERR_FAIL_COND(format==FORMAT_INDEXED || format==FORMAT_INDEXED_ALPHA);
|
||||
ERR_FAIL_COND( data.size()==0 );
|
||||
|
||||
|
||||
|
||||
if (mipmaps) {
|
||||
|
||||
//just use the lower mipmap as base and copy all
|
||||
DVector<uint8_t> new_img;
|
||||
|
||||
int ofs = get_mipmap_offset(1);
|
||||
|
||||
int new_size = data.size()-ofs;
|
||||
new_img.resize(new_size);
|
||||
|
||||
|
||||
{
|
||||
DVector<uint8_t>::Write w=new_img.write();
|
||||
DVector<uint8_t>::Read r=data.read();
|
||||
|
||||
copymem(w.ptr(),&r[ofs],new_size);
|
||||
}
|
||||
|
||||
mipmaps--;
|
||||
width/=2;
|
||||
height/=2;
|
||||
data=new_img;
|
||||
|
||||
} else {
|
||||
|
||||
DVector<uint8_t> new_img;
|
||||
|
||||
ERR_FAIL_COND( format>=FORMAT_INDEXED );
|
||||
int ps = get_format_pixel_size(format);
|
||||
new_img.resize((width/2)*(height/2)*ps);
|
||||
|
||||
{
|
||||
DVector<uint8_t>::Write w=new_img.write();
|
||||
DVector<uint8_t>::Read r=data.read();
|
||||
|
||||
switch(format) {
|
||||
|
||||
case FORMAT_GRAYSCALE:
|
||||
case FORMAT_INTENSITY: _generate_po2_mipmap<1>(r.ptr(), w.ptr(), width,height); break;
|
||||
case FORMAT_GRAYSCALE_ALPHA: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
|
||||
case FORMAT_RGB: _generate_po2_mipmap<3>(r.ptr(), w.ptr(), width,height); break;
|
||||
case FORMAT_RGBA: _generate_po2_mipmap<4>(r.ptr(), w.ptr(), width,height); break;
|
||||
default: {}
|
||||
}
|
||||
}
|
||||
|
||||
width/=2;
|
||||
height/=2;
|
||||
data=new_img;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
|
||||
|
||||
if (!_can_modify(format)) {
|
||||
@ -1138,26 +906,26 @@ void Image::make_normalmap(float p_height_scale) {
|
||||
}
|
||||
|
||||
ERR_FAIL_COND( empty() );
|
||||
|
||||
|
||||
Image normalmap(width,height,0, FORMAT_RGB);
|
||||
/*
|
||||
for (int y=0;y<height;y++) {
|
||||
for (int x=0;x<width;x++) {
|
||||
|
||||
|
||||
float center=get_pixel(x,y).gray()/255.0;
|
||||
float up=(y>0)?get_pixel(x,y-1).gray()/255.0:center;
|
||||
float down=(y<(height-1))?get_pixel(x,y+1).gray()/255.0:center;
|
||||
float left=(x>0)?get_pixel(x-1,y).gray()/255.0:center;
|
||||
float right=(x<(width-1))?get_pixel(x+1,y).gray()/255.0:center;
|
||||
|
||||
|
||||
|
||||
|
||||
// uhm, how do i do this? ....
|
||||
|
||||
|
||||
Color result( (uint8_t)((normal.x+1.0)*127.0), (uint8_t)((normal.y+1.0)*127.0), (uint8_t)((normal.z+1.0)*127.0) );
|
||||
|
||||
|
||||
normalmap.put_pixel( x, y, result );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
*this=normalmap;
|
||||
@ -1169,14 +937,14 @@ bool Image::empty() const {
|
||||
}
|
||||
|
||||
DVector<uint8_t> Image::get_data() const {
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format) {
|
||||
|
||||
|
||||
int mm=0;
|
||||
int mm=0;
|
||||
int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0);
|
||||
data.resize( size );
|
||||
{
|
||||
@ -1193,7 +961,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format
|
||||
}
|
||||
|
||||
void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
|
||||
|
||||
|
||||
ERR_FAIL_INDEX(p_width-1,MAX_WIDTH);
|
||||
ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT);
|
||||
|
||||
@ -1206,52 +974,52 @@ void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, co
|
||||
ERR_FAIL_COND(p_data.size()!=size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
height=p_height;
|
||||
width=p_width;
|
||||
format=p_format;
|
||||
data=p_data;
|
||||
data=p_data;
|
||||
mipmaps=p_mipmaps;
|
||||
}
|
||||
|
||||
|
||||
void Image::create( const char ** p_xpm ) {
|
||||
|
||||
|
||||
|
||||
int size_width,size_height;
|
||||
int pixelchars=0;
|
||||
mipmaps=0;
|
||||
bool has_alpha=false;
|
||||
|
||||
|
||||
enum Status {
|
||||
READING_HEADER,
|
||||
READING_COLORS,
|
||||
READING_PIXELS,
|
||||
DONE
|
||||
};
|
||||
|
||||
|
||||
Status status = READING_HEADER;
|
||||
int line=0;
|
||||
|
||||
|
||||
HashMap<String,Color> colormap;
|
||||
int colormap_size;
|
||||
|
||||
|
||||
while (status!=DONE) {
|
||||
|
||||
|
||||
const char * line_ptr = p_xpm[line];
|
||||
|
||||
|
||||
|
||||
|
||||
switch (status) {
|
||||
|
||||
|
||||
case READING_HEADER: {
|
||||
|
||||
|
||||
String line_str=line_ptr;
|
||||
line_str.replace("\t"," ");
|
||||
|
||||
size_width=line_str.get_slicec(' ',0).to_int();
|
||||
size_height=line_str.get_slicec(' ',1).to_int();
|
||||
colormap_size=line_str.get_slicec(' ',2).to_int();
|
||||
pixelchars=line_str.get_slicec(' ',3).to_int();
|
||||
|
||||
size_width=line_str.get_slice(" ",0).to_int();
|
||||
size_height=line_str.get_slice(" ",1).to_int();
|
||||
colormap_size=line_str.get_slice(" ",2).to_int();
|
||||
pixelchars=line_str.get_slice(" ",3).to_int();
|
||||
ERR_FAIL_COND(colormap_size > 32766);
|
||||
ERR_FAIL_COND(pixelchars > 5);
|
||||
ERR_FAIL_COND(size_width > 32767);
|
||||
@ -1259,10 +1027,10 @@ void Image::create( const char ** p_xpm ) {
|
||||
status=READING_COLORS;
|
||||
} break;
|
||||
case READING_COLORS: {
|
||||
|
||||
|
||||
String colorstring;
|
||||
for (int i=0;i<pixelchars;i++) {
|
||||
|
||||
|
||||
colorstring+=*line_ptr;
|
||||
line_ptr++;
|
||||
}
|
||||
@ -1273,25 +1041,25 @@ void Image::create( const char ** p_xpm ) {
|
||||
line_ptr++;
|
||||
}
|
||||
if (*line_ptr=='c') {
|
||||
|
||||
|
||||
line_ptr++;
|
||||
while (*line_ptr==' ' || *line_ptr=='\t' || *line_ptr==0) {
|
||||
if (*line_ptr==0)
|
||||
break;
|
||||
line_ptr++;
|
||||
}
|
||||
|
||||
|
||||
if (*line_ptr=='#') {
|
||||
line_ptr++;
|
||||
uint8_t col_r;
|
||||
uint8_t col_g;
|
||||
uint8_t col_b;
|
||||
// uint8_t col_a=255;
|
||||
|
||||
|
||||
for (int i=0;i<6;i++) {
|
||||
|
||||
|
||||
char v = line_ptr[i];
|
||||
|
||||
|
||||
if (v>='0' && v<='9')
|
||||
v-='0';
|
||||
else if (v>='A' && v<='F')
|
||||
@ -1300,7 +1068,7 @@ void Image::create( const char ** p_xpm ) {
|
||||
v=(v-'a')+10;
|
||||
else
|
||||
break;
|
||||
|
||||
|
||||
switch(i) {
|
||||
case 0: col_r=v<<4; break;
|
||||
case 1: col_r|=v; break;
|
||||
@ -1309,54 +1077,53 @@ void Image::create( const char ** p_xpm ) {
|
||||
case 4: col_b=v<<4; break;
|
||||
case 5: col_b|=v; break;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// magenta mask
|
||||
if (col_r==255 && col_g==0 && col_b==255) {
|
||||
|
||||
|
||||
colormap[colorstring]=Color(0,0,0,0);
|
||||
has_alpha=true;
|
||||
} else {
|
||||
|
||||
colormap[colorstring]=Color(col_r/255.0,col_g/255.0,col_b/255.0,1.0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (line==colormap_size) {
|
||||
|
||||
|
||||
status=READING_PIXELS;
|
||||
create(size_width,size_height,0,has_alpha?FORMAT_RGBA:FORMAT_RGB);
|
||||
}
|
||||
} break;
|
||||
case READING_PIXELS: {
|
||||
|
||||
|
||||
int y=line-colormap_size-1;
|
||||
for (int x=0;x<size_width;x++) {
|
||||
|
||||
|
||||
char pixelstr[6]={0,0,0,0,0,0};
|
||||
for (int i=0;i<pixelchars;i++)
|
||||
pixelstr[i]=line_ptr[x*pixelchars+i];
|
||||
|
||||
|
||||
Color *colorptr = colormap.getptr(pixelstr);
|
||||
ERR_FAIL_COND(!colorptr);
|
||||
put_pixel(x,y,*colorptr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (y==(size_height-1))
|
||||
status=DONE;
|
||||
} break;
|
||||
default:{}
|
||||
}
|
||||
|
||||
|
||||
line++;
|
||||
}
|
||||
}
|
||||
#define DETECT_ALPHA_MAX_TRESHOLD 254
|
||||
#define DETECT_ALPHA_MIN_TRESHOLD 2
|
||||
|
||||
#define DETECT_ALPHA( m_value )\
|
||||
{ \
|
||||
uint8_t value=m_value;\
|
||||
@ -1369,82 +1136,6 @@ void Image::create( const char ** p_xpm ) {
|
||||
}\
|
||||
}
|
||||
|
||||
#define DETECT_NON_ALPHA( m_value )\
|
||||
{ \
|
||||
uint8_t value=m_value;\
|
||||
if (value>0) {\
|
||||
\
|
||||
detected=true;\
|
||||
break;\
|
||||
}\
|
||||
}
|
||||
|
||||
|
||||
bool Image::is_invisible() const {
|
||||
|
||||
if (format==FORMAT_GRAYSCALE ||
|
||||
format==FORMAT_RGB ||
|
||||
format==FORMAT_INDEXED)
|
||||
return false;
|
||||
|
||||
int len = data.size();
|
||||
|
||||
if (len==0)
|
||||
return true;
|
||||
|
||||
if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444)
|
||||
return false;
|
||||
|
||||
int w,h;
|
||||
_get_mipmap_offset_and_size(1,len,w,h);
|
||||
|
||||
DVector<uint8_t>::Read r = data.read();
|
||||
const unsigned char *data_ptr=r.ptr();
|
||||
|
||||
bool detected=false;
|
||||
|
||||
switch(format) {
|
||||
case FORMAT_INTENSITY: {
|
||||
|
||||
for(int i=0;i<len;i++) {
|
||||
DETECT_NON_ALPHA(data_ptr[i]);
|
||||
}
|
||||
} break;
|
||||
case FORMAT_GRAYSCALE_ALPHA: {
|
||||
|
||||
|
||||
for(int i=0;i<(len>>1);i++) {
|
||||
DETECT_NON_ALPHA(data_ptr[(i<<1)+1]);
|
||||
}
|
||||
|
||||
} break;
|
||||
case FORMAT_RGBA: {
|
||||
|
||||
for(int i=0;i<(len>>2);i++) {
|
||||
DETECT_NON_ALPHA(data_ptr[(i<<2)+3])
|
||||
}
|
||||
|
||||
} break;
|
||||
case FORMAT_INDEXED: {
|
||||
|
||||
return false;
|
||||
} break;
|
||||
case FORMAT_INDEXED_ALPHA: {
|
||||
|
||||
return false;
|
||||
} break;
|
||||
case FORMAT_PVRTC2_ALPHA:
|
||||
case FORMAT_PVRTC4_ALPHA:
|
||||
case FORMAT_BC2:
|
||||
case FORMAT_BC3: {
|
||||
detected=true;
|
||||
} break;
|
||||
default: {}
|
||||
}
|
||||
|
||||
return !detected;
|
||||
}
|
||||
|
||||
Image::AlphaMode Image::detect_alpha() const {
|
||||
|
||||
if (format==FORMAT_GRAYSCALE ||
|
||||
@ -1735,17 +1426,8 @@ Error Image::_decompress_bc() {
|
||||
|
||||
print_line("decompressing bc");
|
||||
|
||||
int wd=width,ht=height;
|
||||
if (wd%4!=0) {
|
||||
wd+=4-(wd%4);
|
||||
}
|
||||
if (ht%4!=0) {
|
||||
ht+=4-(ht%4);
|
||||
}
|
||||
|
||||
|
||||
int mm;
|
||||
int size = _get_dst_image_size(wd,ht,FORMAT_RGBA,mm,mipmaps);
|
||||
int size = _get_dst_image_size(width,height,FORMAT_RGBA,mm,mipmaps);
|
||||
|
||||
DVector<uint8_t> newdata;
|
||||
newdata.resize(size);
|
||||
@ -1755,8 +1437,7 @@ Error Image::_decompress_bc() {
|
||||
|
||||
int rofs=0;
|
||||
int wofs=0;
|
||||
|
||||
//print_line("width: "+itos(wd)+" height: "+itos(ht));
|
||||
int wd=width,ht=height;
|
||||
|
||||
for(int i=0;i<=mm;i++) {
|
||||
|
||||
@ -2061,19 +1742,10 @@ Error Image::_decompress_bc() {
|
||||
|
||||
data=newdata;
|
||||
format=FORMAT_RGBA;
|
||||
if (wd!=width || ht!=height) {
|
||||
//todo, crop
|
||||
width=wd;
|
||||
height=ht;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool Image::is_compressed() const {
|
||||
return format>=FORMAT_BC1;
|
||||
}
|
||||
|
||||
|
||||
Image Image::decompressed() const {
|
||||
|
||||
@ -2135,7 +1807,7 @@ Image Image::compressed(int p_mode) {
|
||||
};
|
||||
|
||||
Image::Image(const char **p_xpm) {
|
||||
|
||||
|
||||
width=0;
|
||||
height=0;
|
||||
mipmaps=0;
|
||||
@ -2326,9 +1998,7 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
|
||||
}
|
||||
|
||||
|
||||
Image (*Image::_png_mem_loader_func)(const uint8_t*,int)=NULL;
|
||||
Image (*Image::_jpg_mem_loader_func)(const uint8_t*,int)=NULL;
|
||||
|
||||
Image (*Image::_png_mem_loader_func)(const uint8_t*)=NULL;
|
||||
void (*Image::_image_compress_bc_func)(Image *)=NULL;
|
||||
void (*Image::_image_compress_pvrtc2_func)(Image *)=NULL;
|
||||
void (*Image::_image_compress_pvrtc4_func)(Image *)=NULL;
|
||||
@ -2497,13 +2167,7 @@ void Image::fix_alpha_edges() {
|
||||
|
||||
}
|
||||
|
||||
String Image::get_format_name(Format p_format) {
|
||||
|
||||
ERR_FAIL_INDEX_V(p_format,FORMAT_MAX,String());
|
||||
return format_names[p_format];
|
||||
}
|
||||
|
||||
Image::Image(const uint8_t* p_mem_png_jpg, int p_len) {
|
||||
Image::Image(const uint8_t* p_png) {
|
||||
|
||||
width=0;
|
||||
height=0;
|
||||
@ -2511,13 +2175,8 @@ Image::Image(const uint8_t* p_mem_png_jpg, int p_len) {
|
||||
format=FORMAT_GRAYSCALE;
|
||||
|
||||
if (_png_mem_loader_func) {
|
||||
*this = _png_mem_loader_func(p_mem_png_jpg,p_len);
|
||||
*this = _png_mem_loader_func(p_png);
|
||||
}
|
||||
|
||||
if (empty() && _jpg_mem_loader_func) {
|
||||
*this = _jpg_mem_loader_func(p_mem_png_jpg,p_len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Image::Image() {
|
||||
|
||||
67
core/image.h
67
core/image.h
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 @@ typedef Error (*SavePNGFunc)(const String &p_path, Image& p_img);
|
||||
|
||||
class Image {
|
||||
|
||||
enum {
|
||||
enum {
|
||||
MAX_WIDTH=16384, // force a limit somehow
|
||||
MAX_HEIGHT=16384// force a limit somehow
|
||||
};
|
||||
@ -55,12 +55,12 @@ 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_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,
|
||||
@ -87,17 +87,14 @@ public:
|
||||
FORMAT_MAX
|
||||
};
|
||||
|
||||
static const char* format_names[FORMAT_MAX];
|
||||
enum Interpolation {
|
||||
|
||||
|
||||
INTERPOLATE_NEAREST,
|
||||
INTERPOLATE_BILINEAR,
|
||||
INTERPOLATE_CUBIC,
|
||||
/* INTERPOLATE GAUSS */
|
||||
};
|
||||
|
||||
static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size);
|
||||
static Image (*_jpg_mem_loader_func)(const uint8_t* p_png,int p_size);
|
||||
static Image (*_png_mem_loader_func)(const uint8_t* p_png);
|
||||
static void (*_image_compress_bc_func)(Image *);
|
||||
static void (*_image_compress_pvrtc2_func)(Image *);
|
||||
static void (*_image_compress_pvrtc4_func)(Image *);
|
||||
@ -187,7 +184,7 @@ private:
|
||||
DVector<uint8_t> data;
|
||||
int width,height,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;
|
||||
@ -208,7 +205,7 @@ public:
|
||||
int get_width() const; ///< Get image width
|
||||
int get_height() const; ///< Get image height
|
||||
int get_mipmaps() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual
|
||||
* value.
|
||||
@ -218,7 +215,7 @@ public:
|
||||
* 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.
|
||||
*/
|
||||
@ -231,7 +228,7 @@ public:
|
||||
ret.convert((Format)p_new_format);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the current image format.
|
||||
*/
|
||||
@ -244,33 +241,31 @@ public:
|
||||
/**
|
||||
* Resize the image, using the prefered interpolation method.
|
||||
* Indexed-Color images always use INTERPOLATE_NEAREST.
|
||||
*/
|
||||
*/
|
||||
|
||||
void resize_to_po2(bool p_square=false);
|
||||
void resize( int p_width, int p_height, Interpolation p_interpolation=INTERPOLATE_BILINEAR );
|
||||
Image resized( int p_width, int p_height, int p_interpolation=INTERPOLATE_BILINEAR );
|
||||
void shrink_x2();
|
||||
void expand_x2_hq2x();
|
||||
/**
|
||||
* Crop the image to a specific size, if larger, then the image is filled by black
|
||||
*/
|
||||
void crop( int p_width, int p_height );
|
||||
|
||||
|
||||
|
||||
|
||||
void flip_x();
|
||||
void flip_y();
|
||||
/**
|
||||
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
|
||||
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
|
||||
*/
|
||||
Error generate_mipmaps(int p_amount=-1,bool p_keep_existing=false);
|
||||
|
||||
void clear_mipmaps();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate a normal map from a grayscale image
|
||||
*/
|
||||
|
||||
|
||||
void make_normalmap(float p_height_scale=1.0);
|
||||
|
||||
/**
|
||||
@ -279,26 +274,26 @@ public:
|
||||
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( const char ** p_xpm );
|
||||
void create( const char ** p_xpm );
|
||||
/**
|
||||
* returns true when the image is empty (0,0) in size
|
||||
*/
|
||||
bool empty() const;
|
||||
|
||||
|
||||
DVector<uint8_t> get_data() const;
|
||||
|
||||
|
||||
Error load(const String& p_path);
|
||||
Error save_png(const String& p_path);
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* create an empty image
|
||||
*/
|
||||
Image();
|
||||
/**
|
||||
/**
|
||||
* create an empty image of a specific size and format
|
||||
*/
|
||||
Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
|
||||
/**
|
||||
/**
|
||||
* 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);
|
||||
@ -310,13 +305,12 @@ 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);
|
||||
@ -341,7 +335,6 @@ public:
|
||||
Image compressed(int p_mode); /* from the Image::CompressMode enum */
|
||||
Error decompress();
|
||||
Image decompressed() const;
|
||||
bool is_compressed() const;
|
||||
|
||||
void fix_alpha_edges();
|
||||
void premultiply_alpha();
|
||||
@ -356,9 +349,7 @@ public:
|
||||
Image get_rect(const Rect2& p_area) const;
|
||||
|
||||
static void set_compress_bc_func(void (*p_compress_func)(Image *));
|
||||
static String get_format_name(Format p_format);
|
||||
|
||||
Image(const uint8_t* p_mem_png_jpg, int p_len=-1);
|
||||
Image(const uint8_t* p_mem_png);
|
||||
Image(const char **p_xpm);
|
||||
~Image();
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -59,6 +59,7 @@ int Image::MCBlock::get_longest_axis_index() const {
|
||||
for(int i=0;i<4;i++) {
|
||||
|
||||
int d = max_color.color.col[i]-min_color.color.col[i];
|
||||
//printf(" ai:%i - %i\n",i,d);
|
||||
if (d>max_dist) {
|
||||
max_index=i;
|
||||
max_dist=d;
|
||||
@ -70,11 +71,13 @@ int Image::MCBlock::get_longest_axis_index() const {
|
||||
int Image::MCBlock::get_longest_axis_length() 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;
|
||||
}
|
||||
}
|
||||
@ -114,6 +117,8 @@ void Image::MCBlock::shrink() {
|
||||
|
||||
void Image::quantize() {
|
||||
|
||||
Image::Format orig_format=format;
|
||||
|
||||
bool has_alpha = detect_alpha()!=ALPHA_NONE;
|
||||
|
||||
bool quantize_fast=OS::get_singleton()->has_environment("QUANTIZE_FAST");
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -28,7 +28,6 @@
|
||||
/*************************************************************************/
|
||||
#include "input_map.h"
|
||||
#include "globals.h"
|
||||
#include "os/keyboard.h"
|
||||
|
||||
InputMap *InputMap::singleton=NULL;
|
||||
|
||||
@ -37,10 +36,9 @@ void InputMap::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("has_action","action"),&InputMap::has_action);
|
||||
ObjectTypeDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id);
|
||||
ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id);
|
||||
ObjectTypeDB::bind_method(_MD("get_actions"),&InputMap::_get_actions);
|
||||
ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action);
|
||||
ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action);
|
||||
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event);
|
||||
ObjectTypeDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event);
|
||||
ObjectTypeDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event);
|
||||
@ -77,35 +75,6 @@ StringName InputMap::get_action_from_id(int p_id) const {
|
||||
return input_id_map[p_id];
|
||||
}
|
||||
|
||||
Array InputMap::_get_actions() {
|
||||
|
||||
Array ret;
|
||||
List<StringName> actions = get_actions();
|
||||
if(actions.empty())
|
||||
return ret;
|
||||
|
||||
for(const List<StringName>::Element *E=actions.front();E;E=E->next()) {
|
||||
|
||||
ret.push_back(E->get());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
List<StringName> InputMap::get_actions() const {
|
||||
|
||||
List<StringName> actions = List<StringName>();
|
||||
if(input_map.empty()){
|
||||
return actions;
|
||||
}
|
||||
|
||||
for (Map<StringName, Action>::Element *E=input_map.front();E;E=E->next()) {
|
||||
actions.push_back(E->key());
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const {
|
||||
|
||||
for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) {
|
||||
@ -137,7 +106,7 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_MOTION: {
|
||||
|
||||
same=(e.joy_motion.axis==p_event.joy_motion.axis && (e.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
|
||||
same=(e.joy_motion.axis==p_event.joy_motion.axis);
|
||||
|
||||
} break;
|
||||
}
|
||||
@ -187,7 +156,10 @@ void InputMap::action_erase_event(const StringName& p_action,const InputEvent& p
|
||||
|
||||
List<InputEvent>::Element *E=_find_event(input_map[p_action].inputs,p_event);
|
||||
if (E)
|
||||
input_map[p_action].inputs.erase(E);
|
||||
return; //already gots
|
||||
|
||||
input_map[p_action].inputs.erase(E);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -232,64 +204,6 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac
|
||||
return _find_event(E->get().inputs,p_event)!=NULL;
|
||||
}
|
||||
|
||||
bool InputMap::event_is_joy_motion_action_pressed(const InputEvent& p_event) const {
|
||||
|
||||
ERR_FAIL_COND_V(p_event.type!=InputEvent::JOYSTICK_MOTION,false);
|
||||
bool pressed=false;
|
||||
|
||||
//this could be optimized by having a separate list of joymotions?
|
||||
|
||||
for (Map<StringName, Action>::Element *A=input_map.front();A;A=A->next()) {
|
||||
|
||||
for (List<InputEvent>::Element *E=A->get().inputs.front();E;E=E->next()) {
|
||||
|
||||
const InputEvent& e=E->get();
|
||||
if(e.type!=p_event.type)
|
||||
continue;
|
||||
if (e.type!=InputEvent::KEY && e.device!=p_event.device)
|
||||
continue;
|
||||
|
||||
switch(p_event.type) {
|
||||
|
||||
case InputEvent::KEY: {
|
||||
|
||||
if (e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod)
|
||||
return e.key.pressed;
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_BUTTON: {
|
||||
|
||||
if (e.joy_button.button_index==p_event.joy_button.button_index) {
|
||||
return e.joy_button.pressed;
|
||||
}
|
||||
|
||||
} break;
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
if (e.mouse_button.button_index==p_event.mouse_button.button_index) {
|
||||
return e.mouse_button.pressed;
|
||||
}
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_MOTION: {
|
||||
|
||||
if (e.joy_motion.axis==p_event.joy_motion.axis) {
|
||||
if (
|
||||
(e.joy_motion.axis_value * p_event.joy_motion.axis_value >0) && //same axis
|
||||
ABS(e.joy_motion.axis_value)>0.5 && ABS(p_event.joy_motion.axis_value)>0.5 )
|
||||
pressed=true;
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return pressed;
|
||||
|
||||
}
|
||||
|
||||
void InputMap::load_from_globals() {
|
||||
|
||||
input_map.clear();;
|
||||
@ -320,67 +234,6 @@ void InputMap::load_from_globals() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InputMap::load_default() {
|
||||
|
||||
InputEvent key;
|
||||
key.type=InputEvent::KEY;
|
||||
|
||||
add_action("ui_accept");
|
||||
key.key.scancode=KEY_RETURN;
|
||||
action_add_event("ui_accept",key);
|
||||
key.key.scancode=KEY_ENTER;
|
||||
action_add_event("ui_accept",key);
|
||||
key.key.scancode=KEY_SPACE;
|
||||
action_add_event("ui_accept",key);
|
||||
|
||||
add_action("ui_select");
|
||||
key.key.scancode=KEY_SPACE;
|
||||
action_add_event("ui_select",key);
|
||||
|
||||
add_action("ui_cancel");
|
||||
key.key.scancode=KEY_ESCAPE;
|
||||
action_add_event("ui_cancel",key);
|
||||
|
||||
add_action("ui_focus_next");
|
||||
key.key.scancode=KEY_TAB;
|
||||
action_add_event("ui_focus_next",key);
|
||||
|
||||
add_action("ui_focus_prev");
|
||||
key.key.scancode=KEY_TAB;
|
||||
key.key.mod.shift=true;
|
||||
action_add_event("ui_focus_prev",key);
|
||||
key.key.mod.shift=false;
|
||||
|
||||
add_action("ui_left");
|
||||
key.key.scancode=KEY_LEFT;
|
||||
action_add_event("ui_left",key);
|
||||
|
||||
add_action("ui_right");
|
||||
key.key.scancode=KEY_RIGHT;
|
||||
action_add_event("ui_right",key);
|
||||
|
||||
add_action("ui_up");
|
||||
key.key.scancode=KEY_UP;
|
||||
action_add_event("ui_up",key);
|
||||
|
||||
add_action("ui_down");
|
||||
key.key.scancode=KEY_DOWN;
|
||||
action_add_event("ui_down",key);
|
||||
|
||||
|
||||
add_action("ui_page_up");
|
||||
key.key.scancode=KEY_PAGEUP;
|
||||
action_add_event("ui_page_up",key);
|
||||
|
||||
add_action("ui_page_down");
|
||||
key.key.scancode=KEY_PAGEDOWN;
|
||||
action_add_event("ui_page_down",key);
|
||||
|
||||
// set("display/orientation", "landscape");
|
||||
|
||||
|
||||
}
|
||||
|
||||
InputMap::InputMap() {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -47,7 +47,6 @@ class InputMap : public Object {
|
||||
List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const;
|
||||
|
||||
Array _get_action_list(const StringName& p_action);
|
||||
Array _get_actions();
|
||||
|
||||
protected:
|
||||
|
||||
@ -60,7 +59,6 @@ public:
|
||||
bool has_action(const StringName& p_action) const;
|
||||
int get_action_id(const StringName& p_action) const;
|
||||
StringName get_action_from_id(int p_id) const;
|
||||
List<StringName> get_actions() const;
|
||||
void add_action(const StringName& p_action);
|
||||
void erase_action(const StringName& p_action);
|
||||
|
||||
@ -70,11 +68,9 @@ public:
|
||||
|
||||
const List<InputEvent> *get_action_list(const StringName& p_action);
|
||||
bool event_is_action(const InputEvent& p_event, const StringName& p_action) const;
|
||||
bool event_is_joy_motion_action_pressed(const InputEvent& p_event) const;
|
||||
|
||||
|
||||
void load_from_globals();
|
||||
void load_default();
|
||||
|
||||
InputMap();
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
This is version 2007-Mar-4 of the Info-ZIP license.
|
||||
The definitive version of this document should be available at
|
||||
ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely and
|
||||
a copy at http://www.info-zip.org/pub/infozip/license.html.
|
||||
|
||||
|
||||
Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
|
||||
|
||||
For the purposes of this copyright and license, "Info-ZIP" is defined as
|
||||
the following set of individuals:
|
||||
|
||||
Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
|
||||
Jean-loup Gailly, Hunter Goatley, Ed Gordon, Ian Gorman, Chris Herborth,
|
||||
Dirk Haase, Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz,
|
||||
David Kirschbaum, Johnny Lee, Onno van der Linden, Igor Mandrichenko,
|
||||
Steve P. Miller, Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs,
|
||||
Kai Uwe Rommel, Steve Salisbury, Dave Smith, Steven M. Schweda,
|
||||
Christian Spieler, Cosmin Truta, Antoine Verheijen, Paul von Behren,
|
||||
Rich Wales, Mike White.
|
||||
|
||||
This software is provided "as is," without warranty of any kind, express
|
||||
or implied. In no event shall Info-ZIP or its contributors be held liable
|
||||
for any direct, indirect, incidental, special or consequential damages
|
||||
arising out of the use of or inability to use this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the above disclaimer and the following restrictions:
|
||||
|
||||
1. Redistributions of source code (in whole or in part) must retain
|
||||
the above copyright notice, definition, disclaimer, and this list
|
||||
of conditions.
|
||||
|
||||
2. Redistributions in binary form (compiled executables and libraries)
|
||||
must reproduce the above copyright notice, definition, disclaimer,
|
||||
and this list of conditions in documentation and/or other materials
|
||||
provided with the distribution. The sole exception to this condition
|
||||
is redistribution of a standard UnZipSFX binary (including SFXWiz) as
|
||||
part of a self-extracting archive; that is permitted without inclusion
|
||||
of this license, as long as the normal SFX banner has not been removed
|
||||
from the binary or disabled.
|
||||
|
||||
3. Altered versions--including, but not limited to, ports to new operating
|
||||
systems, existing ports with new graphical interfaces, versions with
|
||||
modified or added functionality, and dynamic, shared, or static library
|
||||
versions not from Info-ZIP--must be plainly marked as such and must not
|
||||
be misrepresented as being the original source or, if binaries,
|
||||
compiled from the original source. Such altered versions also must not
|
||||
be misrepresented as being Info-ZIP releases--including, but not
|
||||
limited to, labeling of the altered versions with the names "Info-ZIP"
|
||||
(or any variation thereof, including, but not limited to, different
|
||||
capitalizations), "Pocket UnZip," "WiZ" or "MacZip" without the
|
||||
explicit permission of Info-ZIP. Such altered versions are further
|
||||
prohibited from misrepresentative use of the Zip-Bugs or Info-ZIP
|
||||
e-mail addresses or the Info-ZIP URL(s), such as to imply Info-ZIP
|
||||
will provide support for the altered versions.
|
||||
|
||||
4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip,"
|
||||
"UnZipSFX," "WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its
|
||||
own source and binary releases.
|
||||
@ -1,32 +0,0 @@
|
||||
Credits
|
||||
|
||||
Gilles Vollant - Original MiniZip author
|
||||
Even Rouault - ZIP64 unzip Support
|
||||
Daniel Borca - BZip Compression method support in unzip
|
||||
Mathias Svensson - ZIP64 zip support
|
||||
Mathias Svensson - BZip Compression method support in zip
|
||||
|
||||
This version has been modified for Godot Engine
|
||||
|
||||
|
||||
License
|
||||
----------------------------------------------------------------------------
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
@ -5,3 +5,5 @@ env.add_source_files(env.core_sources,"*.c")
|
||||
#env.core_sources.append("io/fastlz.c")
|
||||
|
||||
Export('env')
|
||||
|
||||
|
||||
|
||||
@ -1,399 +1,359 @@
|
||||
/*
|
||||
* Byte-oriented AES-256 implementation.
|
||||
* All lookup tables replaced with 'on the fly' calculations.
|
||||
*
|
||||
* Copyright (c) 2007-2011 Ilya O. Levin, http://www.literatecode.com
|
||||
* Other contributors: Hal Finney
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#include "aes256.h"
|
||||
|
||||
#define FD(x) (((x) >> 1) ^ (((x) & 1) ? 0x8d : 0))
|
||||
|
||||
#define BACK_TO_TABLES
|
||||
|
||||
static uint8_t rj_xtime(uint8_t);
|
||||
static void aes_subBytes(uint8_t *);
|
||||
static void aes_subBytes_inv(uint8_t *);
|
||||
static void aes_addRoundKey(uint8_t *, uint8_t *);
|
||||
static void aes_addRoundKey_cpy(uint8_t *, uint8_t *, uint8_t *);
|
||||
static void aes_shiftRows(uint8_t *);
|
||||
static void aes_shiftRows_inv(uint8_t *);
|
||||
static void aes_mixColumns(uint8_t *);
|
||||
static void aes_mixColumns_inv(uint8_t *);
|
||||
static void aes_expandEncKey(uint8_t *, uint8_t *);
|
||||
static void aes_expandDecKey(uint8_t *, uint8_t *);
|
||||
#ifndef BACK_TO_TABLES
|
||||
static uint8_t gf_alog(uint8_t);
|
||||
static uint8_t gf_log(uint8_t);
|
||||
static uint8_t gf_mulinv(uint8_t);
|
||||
static uint8_t rj_sbox(uint8_t);
|
||||
static uint8_t rj_sbox_inv(uint8_t);
|
||||
#endif
|
||||
|
||||
#ifdef BACK_TO_TABLES
|
||||
|
||||
static const uint8_t sbox[256] =
|
||||
{
|
||||
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
|
||||
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
|
||||
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
|
||||
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
|
||||
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
|
||||
0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
||||
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
|
||||
0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
|
||||
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
|
||||
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
|
||||
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
|
||||
0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
||||
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
|
||||
0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
|
||||
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
|
||||
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
|
||||
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
|
||||
0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
||||
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
|
||||
0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
|
||||
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
|
||||
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
|
||||
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
|
||||
0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
||||
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
|
||||
0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
|
||||
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
|
||||
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
|
||||
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
|
||||
0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
||||
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
|
||||
0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
|
||||
};
|
||||
static const uint8_t sboxinv[256] =
|
||||
{
|
||||
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38,
|
||||
0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
|
||||
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
|
||||
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
|
||||
0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d,
|
||||
0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
||||
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2,
|
||||
0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
|
||||
0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
|
||||
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
|
||||
0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda,
|
||||
0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
||||
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a,
|
||||
0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
|
||||
0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
|
||||
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
|
||||
0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea,
|
||||
0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
||||
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85,
|
||||
0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
|
||||
0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
|
||||
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
|
||||
0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20,
|
||||
0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
||||
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31,
|
||||
0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
|
||||
0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
|
||||
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
|
||||
0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0,
|
||||
0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
||||
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26,
|
||||
0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
|
||||
};
|
||||
|
||||
#define rj_sbox(x) sbox[(x)]
|
||||
#define rj_sbox_inv(x) sboxinv[(x)]
|
||||
|
||||
#else /* tableless subroutines */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static uint8_t gf_alog(uint8_t x) // calculate anti-logarithm gen 3
|
||||
{
|
||||
uint8_t y = 1, i;
|
||||
|
||||
for (i = 0; i < x; i++) y ^= rj_xtime(y);
|
||||
|
||||
return y;
|
||||
} /* gf_alog */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static uint8_t gf_log(uint8_t x) // calculate logarithm gen 3
|
||||
{
|
||||
uint8_t y, i = 0;
|
||||
|
||||
if (x)
|
||||
for (i = 1, y = 1; i > 0; i++ )
|
||||
{
|
||||
y ^= rj_xtime(y);
|
||||
if (y == x) break;
|
||||
}
|
||||
|
||||
return i;
|
||||
} /* gf_log */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static uint8_t gf_mulinv(uint8_t x) // calculate multiplicative inverse
|
||||
{
|
||||
return (x) ? gf_alog(255 - gf_log(x)) : 0;
|
||||
} /* gf_mulinv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static uint8_t rj_sbox(uint8_t x)
|
||||
{
|
||||
uint8_t y, sb;
|
||||
|
||||
sb = y = gf_mulinv(x);
|
||||
y = (uint8_t)(y << 1) | (y >> 7), sb ^= y;
|
||||
y = (uint8_t)(y << 1) | (y >> 7), sb ^= y;
|
||||
y = (uint8_t)(y << 1) | (y >> 7), sb ^= y;
|
||||
y = (uint8_t)(y << 1) | (y >> 7), sb ^= y;
|
||||
|
||||
return (sb ^ 0x63);
|
||||
} /* rj_sbox */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static uint8_t rj_sbox_inv(uint8_t x)
|
||||
{
|
||||
uint8_t y, sb;
|
||||
|
||||
y = x ^ 0x63;
|
||||
sb = y = (uint8_t)(y << 1) | (y >> 7);
|
||||
y = (uint8_t)(y << 2) | (y >> 6);
|
||||
sb ^= y;
|
||||
y = (uint8_t)(y << 3) | (y >> 5);
|
||||
sb ^= y;
|
||||
|
||||
return gf_mulinv(sb);
|
||||
} /* rj_sbox_inv */
|
||||
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static uint8_t rj_xtime(uint8_t x)
|
||||
{
|
||||
uint8_t y = (uint8_t)(x << 1);
|
||||
return (x & 0x80) ? (y ^ 0x1b) : y;
|
||||
} /* rj_xtime */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_subBytes(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] = rj_sbox(buf[i]);
|
||||
} /* aes_subBytes */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_subBytes_inv(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] = rj_sbox_inv(buf[i]);
|
||||
} /* aes_subBytes_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_addRoundKey(uint8_t *buf, uint8_t *key)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] ^= key[i];
|
||||
} /* aes_addRoundKey */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_addRoundKey_cpy(uint8_t *buf, uint8_t *key, uint8_t *cpk)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] ^= (cpk[i] = key[i]), cpk[16 + i] = key[16 + i];
|
||||
} /* aes_addRoundKey_cpy */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_shiftRows(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, j; /* to make it potentially parallelable :) */
|
||||
|
||||
i = buf[1], buf[1] = buf[5], buf[5] = buf[9], buf[9] = buf[13], buf[13] = i;
|
||||
i = buf[10], buf[10] = buf[2], buf[2] = i;
|
||||
j = buf[3], buf[3] = buf[15], buf[15] = buf[11], buf[11] = buf[7], buf[7] = j;
|
||||
j = buf[14], buf[14] = buf[6], buf[6] = j;
|
||||
|
||||
} /* aes_shiftRows */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_shiftRows_inv(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, j; /* same as above :) */
|
||||
|
||||
i = buf[1], buf[1] = buf[13], buf[13] = buf[9], buf[9] = buf[5], buf[5] = i;
|
||||
i = buf[2], buf[2] = buf[10], buf[10] = i;
|
||||
j = buf[3], buf[3] = buf[7], buf[7] = buf[11], buf[11] = buf[15], buf[15] = j;
|
||||
j = buf[6], buf[6] = buf[14], buf[14] = j;
|
||||
|
||||
} /* aes_shiftRows_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_mixColumns(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, a, b, c, d, e;
|
||||
|
||||
for (i = 0; i < 16; i += 4)
|
||||
{
|
||||
a = buf[i];
|
||||
b = buf[i + 1];
|
||||
c = buf[i + 2];
|
||||
d = buf[i + 3];
|
||||
e = a ^ b ^ c ^ d;
|
||||
buf[i] ^= e ^ rj_xtime(a ^ b);
|
||||
buf[i + 1] ^= e ^ rj_xtime(b ^ c);
|
||||
buf[i + 2] ^= e ^ rj_xtime(c ^ d);
|
||||
buf[i + 3] ^= e ^ rj_xtime(d ^ a);
|
||||
}
|
||||
} /* aes_mixColumns */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_mixColumns_inv(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, a, b, c, d, e, x, y, z;
|
||||
|
||||
for (i = 0; i < 16; i += 4)
|
||||
{
|
||||
a = buf[i];
|
||||
b = buf[i + 1];
|
||||
c = buf[i + 2];
|
||||
d = buf[i + 3];
|
||||
e = a ^ b ^ c ^ d;
|
||||
z = rj_xtime(e);
|
||||
x = e ^ rj_xtime(rj_xtime(z ^ a ^ c));
|
||||
y = e ^ rj_xtime(rj_xtime(z ^ b ^ d));
|
||||
buf[i] ^= x ^ rj_xtime(a ^ b);
|
||||
buf[i + 1] ^= y ^ rj_xtime(b ^ c);
|
||||
buf[i + 2] ^= x ^ rj_xtime(c ^ d);
|
||||
buf[i + 3] ^= y ^ rj_xtime(d ^ a);
|
||||
}
|
||||
} /* aes_mixColumns_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void aes_expandEncKey(uint8_t *k, uint8_t *rc)
|
||||
{
|
||||
register uint8_t i;
|
||||
|
||||
k[0] ^= rj_sbox(k[29]) ^ (*rc);
|
||||
k[1] ^= rj_sbox(k[30]);
|
||||
k[2] ^= rj_sbox(k[31]);
|
||||
k[3] ^= rj_sbox(k[28]);
|
||||
*rc = rj_xtime( *rc);
|
||||
|
||||
for(i = 4; i < 16; i += 4) k[i] ^= k[i - 4], k[i + 1] ^= k[i - 3],
|
||||
k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1];
|
||||
k[16] ^= rj_sbox(k[12]);
|
||||
k[17] ^= rj_sbox(k[13]);
|
||||
k[18] ^= rj_sbox(k[14]);
|
||||
k[19] ^= rj_sbox(k[15]);
|
||||
|
||||
for(i = 20; i < 32; i += 4) k[i] ^= k[i - 4], k[i + 1] ^= k[i - 3],
|
||||
k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1];
|
||||
|
||||
} /* aes_expandEncKey */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_expandDecKey(uint8_t *k, uint8_t *rc)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 28; i > 16; i -= 4) k[i + 0] ^= k[i - 4], k[i + 1] ^= k[i - 3],
|
||||
k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1];
|
||||
|
||||
k[16] ^= rj_sbox(k[12]);
|
||||
k[17] ^= rj_sbox(k[13]);
|
||||
k[18] ^= rj_sbox(k[14]);
|
||||
k[19] ^= rj_sbox(k[15]);
|
||||
|
||||
for(i = 12; i > 0; i -= 4) k[i + 0] ^= k[i - 4], k[i + 1] ^= k[i - 3],
|
||||
k[i + 2] ^= k[i - 2], k[i + 3] ^= k[i - 1];
|
||||
|
||||
*rc = FD(*rc);
|
||||
k[0] ^= rj_sbox(k[29]) ^ (*rc);
|
||||
k[1] ^= rj_sbox(k[30]);
|
||||
k[2] ^= rj_sbox(k[31]);
|
||||
k[3] ^= rj_sbox(k[28]);
|
||||
} /* aes_expandDecKey */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_init(aes256_context *ctx, uint8_t *k)
|
||||
{
|
||||
uint8_t rcon = 1;
|
||||
register uint8_t i;
|
||||
|
||||
for (i = 0; i < sizeof(ctx->key); i++) ctx->enckey[i] = ctx->deckey[i] = k[i];
|
||||
for (i = 8; --i;) aes_expandEncKey(ctx->deckey, &rcon);
|
||||
} /* aes256_init */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_done(aes256_context *ctx)
|
||||
{
|
||||
register uint8_t i;
|
||||
|
||||
for (i = 0; i < sizeof(ctx->key); i++)
|
||||
ctx->key[i] = ctx->enckey[i] = ctx->deckey[i] = 0;
|
||||
} /* aes256_done */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_encrypt_ecb(aes256_context *ctx, uint8_t *buf)
|
||||
{
|
||||
uint8_t i, rcon;
|
||||
|
||||
aes_addRoundKey_cpy(buf, ctx->enckey, ctx->key);
|
||||
for(i = 1, rcon = 1; i < 14; ++i)
|
||||
{
|
||||
aes_subBytes(buf);
|
||||
aes_shiftRows(buf);
|
||||
aes_mixColumns(buf);
|
||||
if( i & 1 ) aes_addRoundKey( buf, &ctx->key[16]);
|
||||
else aes_expandEncKey(ctx->key, &rcon), aes_addRoundKey(buf, ctx->key);
|
||||
}
|
||||
aes_subBytes(buf);
|
||||
aes_shiftRows(buf);
|
||||
aes_expandEncKey(ctx->key, &rcon);
|
||||
aes_addRoundKey(buf, ctx->key);
|
||||
} /* aes256_encrypt */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_decrypt_ecb(aes256_context *ctx, uint8_t *buf)
|
||||
{
|
||||
uint8_t i, rcon;
|
||||
|
||||
aes_addRoundKey_cpy(buf, ctx->deckey, ctx->key);
|
||||
aes_shiftRows_inv(buf);
|
||||
aes_subBytes_inv(buf);
|
||||
|
||||
for (i = 14, rcon = 0x80; --i;)
|
||||
{
|
||||
if( ( i & 1 ) )
|
||||
{
|
||||
aes_expandDecKey(ctx->key, &rcon);
|
||||
aes_addRoundKey(buf, &ctx->key[16]);
|
||||
}
|
||||
else aes_addRoundKey(buf, ctx->key);
|
||||
aes_mixColumns_inv(buf);
|
||||
aes_shiftRows_inv(buf);
|
||||
aes_subBytes_inv(buf);
|
||||
}
|
||||
aes_addRoundKey( buf, ctx->key);
|
||||
} /* aes256_decrypt */
|
||||
/*
|
||||
* Byte-oriented AES-256 implementation.
|
||||
* All lookup tables replaced with 'on the fly' calculations.
|
||||
*
|
||||
* Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com
|
||||
* Other contributors: Hal Finney
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#include "aes256.h"
|
||||
|
||||
#define F(x) (((x)<<1) ^ ((((x)>>7) & 1) * 0x1b))
|
||||
#define FD(x) (((x) >> 1) ^ (((x) & 1) ? 0x8d : 0))
|
||||
|
||||
// #define BACK_TO_TABLES
|
||||
#ifdef BACK_TO_TABLES
|
||||
|
||||
const uint8_t sbox[256] = {
|
||||
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
|
||||
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
|
||||
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
|
||||
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
|
||||
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
|
||||
0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
||||
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
|
||||
0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
|
||||
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
|
||||
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
|
||||
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
|
||||
0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
||||
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
|
||||
0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
|
||||
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
|
||||
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
|
||||
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
|
||||
0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
||||
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
|
||||
0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
|
||||
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
|
||||
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
|
||||
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
|
||||
0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
||||
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
|
||||
0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
|
||||
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
|
||||
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
|
||||
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
|
||||
0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
||||
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
|
||||
0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
|
||||
};
|
||||
const uint8_t sboxinv[256] = {
|
||||
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38,
|
||||
0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
|
||||
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
|
||||
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
|
||||
0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d,
|
||||
0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
||||
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2,
|
||||
0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
|
||||
0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
|
||||
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
|
||||
0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda,
|
||||
0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
||||
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a,
|
||||
0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
|
||||
0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
|
||||
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
|
||||
0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea,
|
||||
0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
||||
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85,
|
||||
0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
|
||||
0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
|
||||
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
|
||||
0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20,
|
||||
0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
||||
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31,
|
||||
0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
|
||||
0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
|
||||
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
|
||||
0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0,
|
||||
0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
||||
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26,
|
||||
0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
|
||||
};
|
||||
|
||||
#define rj_sbox(x) sbox[(x)]
|
||||
#define rj_sbox_inv(x) sboxinv[(x)]
|
||||
|
||||
#else /* tableless subroutines */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t gf_alog(uint8_t x) // calculate anti-logarithm gen 3
|
||||
{
|
||||
uint8_t atb = 1, z;
|
||||
|
||||
while (x--) {z = atb; atb <<= 1; if (z & 0x80) atb^= 0x1b; atb ^= z;}
|
||||
|
||||
return atb;
|
||||
} /* gf_alog */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t gf_log(uint8_t x) // calculate logarithm gen 3
|
||||
{
|
||||
uint8_t atb = 1, i = 0, z;
|
||||
|
||||
do {
|
||||
if (atb == x) break;
|
||||
z = atb; atb <<= 1; if (z & 0x80) atb^= 0x1b; atb ^= z;
|
||||
} while (++i > 0);
|
||||
|
||||
return i;
|
||||
} /* gf_log */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t gf_mulinv(uint8_t x) // calculate multiplicative inverse
|
||||
{
|
||||
return (x) ? gf_alog(255 - gf_log(x)) : 0;
|
||||
} /* gf_mulinv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t rj_sbox(uint8_t x)
|
||||
{
|
||||
uint8_t y, sb;
|
||||
|
||||
sb = y = gf_mulinv(x);
|
||||
y = (y<<1)|(y>>7); sb ^= y; y = (y<<1)|(y>>7); sb ^= y;
|
||||
y = (y<<1)|(y>>7); sb ^= y; y = (y<<1)|(y>>7); sb ^= y;
|
||||
|
||||
return (sb ^ 0x63);
|
||||
} /* rj_sbox */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t rj_sbox_inv(uint8_t x)
|
||||
{
|
||||
uint8_t y, sb;
|
||||
|
||||
y = x ^ 0x63;
|
||||
sb = y = (y<<1)|(y>>7);
|
||||
y = (y<<2)|(y>>6); sb ^= y; y = (y<<3)|(y>>5); sb ^= y;
|
||||
|
||||
return gf_mulinv(sb);
|
||||
} /* rj_sbox_inv */
|
||||
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
uint8_t rj_xtime(uint8_t x)
|
||||
{
|
||||
return (x & 0x80) ? ((x << 1) ^ 0x1b) : (x << 1);
|
||||
} /* rj_xtime */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_subBytes(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] = rj_sbox(buf[i]);
|
||||
} /* aes_subBytes */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_subBytes_inv(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] = rj_sbox_inv(buf[i]);
|
||||
} /* aes_subBytes_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_addRoundKey(uint8_t *buf, uint8_t *key)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] ^= key[i];
|
||||
} /* aes_addRoundKey */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_addRoundKey_cpy(uint8_t *buf, uint8_t *key, uint8_t *cpk)
|
||||
{
|
||||
register uint8_t i = 16;
|
||||
|
||||
while (i--) buf[i] ^= (cpk[i] = key[i]), cpk[16+i] = key[16 + i];
|
||||
} /* aes_addRoundKey_cpy */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_shiftRows(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, j; /* to make it potentially parallelable :) */
|
||||
|
||||
i = buf[1]; buf[1] = buf[5]; buf[5] = buf[9]; buf[9] = buf[13]; buf[13] = i;
|
||||
i = buf[10]; buf[10] = buf[2]; buf[2] = i;
|
||||
j = buf[3]; buf[3] = buf[15]; buf[15] = buf[11]; buf[11] = buf[7]; buf[7] = j;
|
||||
j = buf[14]; buf[14] = buf[6]; buf[6] = j;
|
||||
|
||||
} /* aes_shiftRows */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_shiftRows_inv(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, j; /* same as above :) */
|
||||
|
||||
i = buf[1]; buf[1] = buf[13]; buf[13] = buf[9]; buf[9] = buf[5]; buf[5] = i;
|
||||
i = buf[2]; buf[2] = buf[10]; buf[10] = i;
|
||||
j = buf[3]; buf[3] = buf[7]; buf[7] = buf[11]; buf[11] = buf[15]; buf[15] = j;
|
||||
j = buf[6]; buf[6] = buf[14]; buf[14] = j;
|
||||
|
||||
} /* aes_shiftRows_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_mixColumns(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, a, b, c, d, e;
|
||||
|
||||
for (i = 0; i < 16; i += 4)
|
||||
{
|
||||
a = buf[i]; b = buf[i + 1]; c = buf[i + 2]; d = buf[i + 3];
|
||||
e = a ^ b ^ c ^ d;
|
||||
buf[i] ^= e ^ rj_xtime(a^b); buf[i+1] ^= e ^ rj_xtime(b^c);
|
||||
buf[i+2] ^= e ^ rj_xtime(c^d); buf[i+3] ^= e ^ rj_xtime(d^a);
|
||||
}
|
||||
} /* aes_mixColumns */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_mixColumns_inv(uint8_t *buf)
|
||||
{
|
||||
register uint8_t i, a, b, c, d, e, x, y, z;
|
||||
|
||||
for (i = 0; i < 16; i += 4)
|
||||
{
|
||||
a = buf[i]; b = buf[i + 1]; c = buf[i + 2]; d = buf[i + 3];
|
||||
e = a ^ b ^ c ^ d;
|
||||
z = rj_xtime(e);
|
||||
x = e ^ rj_xtime(rj_xtime(z^a^c)); y = e ^ rj_xtime(rj_xtime(z^b^d));
|
||||
buf[i] ^= x ^ rj_xtime(a^b); buf[i+1] ^= y ^ rj_xtime(b^c);
|
||||
buf[i+2] ^= x ^ rj_xtime(c^d); buf[i+3] ^= y ^ rj_xtime(d^a);
|
||||
}
|
||||
} /* aes_mixColumns_inv */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_expandEncKey(uint8_t *k, uint8_t *rc)
|
||||
{
|
||||
register uint8_t i;
|
||||
|
||||
k[0] ^= rj_sbox(k[29]) ^ (*rc);
|
||||
k[1] ^= rj_sbox(k[30]);
|
||||
k[2] ^= rj_sbox(k[31]);
|
||||
k[3] ^= rj_sbox(k[28]);
|
||||
*rc = F( *rc);
|
||||
|
||||
for(i = 4; i < 16; i += 4) k[i] ^= k[i-4], k[i+1] ^= k[i-3],
|
||||
k[i+2] ^= k[i-2], k[i+3] ^= k[i-1];
|
||||
k[16] ^= rj_sbox(k[12]);
|
||||
k[17] ^= rj_sbox(k[13]);
|
||||
k[18] ^= rj_sbox(k[14]);
|
||||
k[19] ^= rj_sbox(k[15]);
|
||||
|
||||
for(i = 20; i < 32; i += 4) k[i] ^= k[i-4], k[i+1] ^= k[i-3],
|
||||
k[i+2] ^= k[i-2], k[i+3] ^= k[i-1];
|
||||
|
||||
} /* aes_expandEncKey */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes_expandDecKey(uint8_t *k, uint8_t *rc)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 28; i > 16; i -= 4) k[i+0] ^= k[i-4], k[i+1] ^= k[i-3],
|
||||
k[i+2] ^= k[i-2], k[i+3] ^= k[i-1];
|
||||
|
||||
k[16] ^= rj_sbox(k[12]);
|
||||
k[17] ^= rj_sbox(k[13]);
|
||||
k[18] ^= rj_sbox(k[14]);
|
||||
k[19] ^= rj_sbox(k[15]);
|
||||
|
||||
for(i = 12; i > 0; i -= 4) k[i+0] ^= k[i-4], k[i+1] ^= k[i-3],
|
||||
k[i+2] ^= k[i-2], k[i+3] ^= k[i-1];
|
||||
|
||||
*rc = FD(*rc);
|
||||
k[0] ^= rj_sbox(k[29]) ^ (*rc);
|
||||
k[1] ^= rj_sbox(k[30]);
|
||||
k[2] ^= rj_sbox(k[31]);
|
||||
k[3] ^= rj_sbox(k[28]);
|
||||
} /* aes_expandDecKey */
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_init(aes256_context *ctx, uint8_t *k)
|
||||
{
|
||||
uint8_t rcon = 1;
|
||||
register uint8_t i;
|
||||
|
||||
for (i = 0; i < sizeof(ctx->key); i++) ctx->enckey[i] = ctx->deckey[i] = k[i];
|
||||
for (i = 8;--i;) aes_expandEncKey(ctx->deckey, &rcon);
|
||||
} /* aes256_init */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_done(aes256_context *ctx)
|
||||
{
|
||||
register uint8_t i;
|
||||
|
||||
for (i = 0; i < sizeof(ctx->key); i++)
|
||||
ctx->key[i] = ctx->enckey[i] = ctx->deckey[i] = 0;
|
||||
} /* aes256_done */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_encrypt_ecb(aes256_context *ctx, uint8_t *buf)
|
||||
{
|
||||
uint8_t i, rcon;
|
||||
|
||||
aes_addRoundKey_cpy(buf, ctx->enckey, ctx->key);
|
||||
for(i = 1, rcon = 1; i < 14; ++i)
|
||||
{
|
||||
aes_subBytes(buf);
|
||||
aes_shiftRows(buf);
|
||||
aes_mixColumns(buf);
|
||||
if( i & 1 ) aes_addRoundKey( buf, &ctx->key[16]);
|
||||
else aes_expandEncKey(ctx->key, &rcon), aes_addRoundKey(buf, ctx->key);
|
||||
}
|
||||
aes_subBytes(buf);
|
||||
aes_shiftRows(buf);
|
||||
aes_expandEncKey(ctx->key, &rcon);
|
||||
aes_addRoundKey(buf, ctx->key);
|
||||
} /* aes256_encrypt */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void aes256_decrypt_ecb(aes256_context *ctx, uint8_t *buf)
|
||||
{
|
||||
uint8_t i, rcon;
|
||||
|
||||
aes_addRoundKey_cpy(buf, ctx->deckey, ctx->key);
|
||||
aes_shiftRows_inv(buf);
|
||||
aes_subBytes_inv(buf);
|
||||
|
||||
for (i = 14, rcon = 0x80; --i;)
|
||||
{
|
||||
if( ( i & 1 ) )
|
||||
{
|
||||
aes_expandDecKey(ctx->key, &rcon);
|
||||
aes_addRoundKey(buf, &ctx->key[16]);
|
||||
}
|
||||
else aes_addRoundKey(buf, ctx->key);
|
||||
aes_mixColumns_inv(buf);
|
||||
aes_shiftRows_inv(buf);
|
||||
aes_subBytes_inv(buf);
|
||||
}
|
||||
aes_addRoundKey( buf, ctx->key);
|
||||
} /* aes256_decrypt */
|
||||
|
||||
@ -1,46 +1,46 @@
|
||||
/*
|
||||
* Byte-oriented AES-256 implementation.
|
||||
* All lookup tables replaced with 'on the fly' calculations.
|
||||
*
|
||||
* Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com
|
||||
* Other contributors: Hal Finney
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef AES_256_H
|
||||
#define AES_256_H
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t key[32];
|
||||
uint8_t enckey[32];
|
||||
uint8_t deckey[32];
|
||||
} aes256_context;
|
||||
|
||||
|
||||
void aes256_init(aes256_context *, uint8_t * /* key */);
|
||||
void aes256_done(aes256_context *);
|
||||
void aes256_encrypt_ecb(aes256_context *, uint8_t * /* plaintext */);
|
||||
void aes256_decrypt_ecb(aes256_context *, uint8_t * /* cipertext */);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Byte-oriented AES-256 implementation.
|
||||
* All lookup tables replaced with 'on the fly' calculations.
|
||||
*
|
||||
* Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com
|
||||
* Other contributors: Hal Finney
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef AES_256_H
|
||||
#define AES_256_H
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t key[32];
|
||||
uint8_t enckey[32];
|
||||
uint8_t deckey[32];
|
||||
} aes256_context;
|
||||
|
||||
|
||||
void aes256_init(aes256_context *, uint8_t * /* key */);
|
||||
void aes256_done(aes256_context *);
|
||||
void aes256_encrypt_ecb(aes256_context *, uint8_t * /* plaintext */);
|
||||
void aes256_decrypt_ecb(aes256_context *, uint8_t * /* cipertext */);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
@ -26,12 +26,12 @@
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "zlib.h"
|
||||
#include "os/copymem.h"
|
||||
#include "compression.h"
|
||||
|
||||
#include "fastlz.h"
|
||||
#include "zlib.h"
|
||||
#include "zip_io.h"
|
||||
#include "os/copymem.h"
|
||||
|
||||
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode) {
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 */
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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,7 +29,6 @@
|
||||
#include "config_file.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "os/file_access.h"
|
||||
#include "variant_parser.h"
|
||||
|
||||
StringArray ConfigFile::_get_sections() const {
|
||||
|
||||
@ -84,10 +83,10 @@ void ConfigFile::set_value(const String& p_section, const String& p_key, const V
|
||||
}
|
||||
|
||||
}
|
||||
Variant ConfigFile::get_value(const String& p_section, const String& p_key, Variant p_default) const {
|
||||
Variant ConfigFile::get_value(const String& p_section, const String& p_key) const{
|
||||
|
||||
ERR_FAIL_COND_V(!values.has(p_section),p_default);
|
||||
ERR_FAIL_COND_V(!values[p_section].has(p_key),p_default);
|
||||
ERR_FAIL_COND_V(!values.has(p_section),Variant());
|
||||
ERR_FAIL_COND_V(!values[p_section].has(p_key),Variant());
|
||||
return values[p_section][p_key];
|
||||
|
||||
}
|
||||
@ -119,6 +118,151 @@ void ConfigFile::get_section_keys(const String& p_section,List<String> *r_keys)
|
||||
|
||||
}
|
||||
|
||||
static String _encode_variant(const Variant& p_variant) {
|
||||
|
||||
switch(p_variant.get_type()) {
|
||||
|
||||
case Variant::BOOL: {
|
||||
bool val = p_variant;
|
||||
return (val?"true":"false");
|
||||
} break;
|
||||
case Variant::INT: {
|
||||
int val = p_variant;
|
||||
return itos(val);
|
||||
} break;
|
||||
case Variant::REAL: {
|
||||
float val = p_variant;
|
||||
return rtos(val)+(val==int(val)?".0":"");
|
||||
} break;
|
||||
case Variant::STRING: {
|
||||
String val = p_variant;
|
||||
return "\""+val.xml_escape()+"\"";
|
||||
} break;
|
||||
case Variant::COLOR: {
|
||||
|
||||
Color val = p_variant;
|
||||
return "#"+val.to_html();
|
||||
} break;
|
||||
case Variant::STRING_ARRAY:
|
||||
case Variant::INT_ARRAY:
|
||||
case Variant::REAL_ARRAY:
|
||||
case Variant::ARRAY: {
|
||||
Array arr = p_variant;
|
||||
String str="[";
|
||||
for(int i=0;i<arr.size();i++) {
|
||||
|
||||
if (i>0)
|
||||
str+=", ";
|
||||
str+=_encode_variant(arr[i]);
|
||||
}
|
||||
str+="]";
|
||||
return str;
|
||||
} break;
|
||||
case Variant::DICTIONARY: {
|
||||
Dictionary d = p_variant;
|
||||
String str="{";
|
||||
List<Variant> keys;
|
||||
d.get_key_list(&keys);
|
||||
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
|
||||
|
||||
if (E!=keys.front())
|
||||
str+=", ";
|
||||
str+=_encode_variant(E->get());
|
||||
str+=":";
|
||||
str+=_encode_variant(d[E->get()]);
|
||||
|
||||
}
|
||||
str+="}";
|
||||
return str;
|
||||
} break;
|
||||
case Variant::IMAGE: {
|
||||
String str="img(";
|
||||
|
||||
Image img=p_variant;
|
||||
if (!img.empty()) {
|
||||
|
||||
String format;
|
||||
switch(img.get_format()) {
|
||||
|
||||
case Image::FORMAT_GRAYSCALE: 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_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_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break;
|
||||
default: {}
|
||||
}
|
||||
|
||||
str+=format+", ";
|
||||
str+=itos(img.get_mipmaps())+", ";
|
||||
str+=itos(img.get_width())+", ";
|
||||
str+=itos(img.get_height())+", ";
|
||||
DVector<uint8_t> data = img.get_data();
|
||||
int ds=data.size();
|
||||
DVector<uint8_t>::Read r = data.read();
|
||||
for(int i=0;i<ds;i++) {
|
||||
uint8_t byte = r[i];
|
||||
const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
char bstr[3]={ hex[byte>>4], hex[byte&0xF], 0};
|
||||
str+=bstr;
|
||||
}
|
||||
}
|
||||
str+=")";
|
||||
return str;
|
||||
} break;
|
||||
case Variant::INPUT_EVENT: {
|
||||
|
||||
InputEvent ev = p_variant;
|
||||
|
||||
switch(ev.type) {
|
||||
|
||||
case InputEvent::KEY: {
|
||||
|
||||
String mods;
|
||||
if (ev.key.mod.control)
|
||||
mods+="C";
|
||||
if (ev.key.mod.shift)
|
||||
mods+="S";
|
||||
if (ev.key.mod.alt)
|
||||
mods+="A";
|
||||
if (ev.key.mod.meta)
|
||||
mods+="M";
|
||||
if (mods!="")
|
||||
mods=", "+mods;
|
||||
|
||||
return "key("+keycode_get_string(ev.key.scancode)+mods+")";
|
||||
} break;
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
return "mbutton("+itos(ev.device)+", "+itos(ev.mouse_button.button_index)+")";
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_BUTTON: {
|
||||
|
||||
return "jbutton("+itos(ev.device)+", "+itos(ev.joy_button.button_index)+")";
|
||||
} break;
|
||||
case InputEvent::JOYSTICK_MOTION: {
|
||||
|
||||
return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis)+")";
|
||||
} break;
|
||||
default: {
|
||||
|
||||
return "nil";
|
||||
} break;
|
||||
|
||||
}
|
||||
} break;
|
||||
default: {}
|
||||
}
|
||||
|
||||
return "nil"; //don't know wha to do with this
|
||||
}
|
||||
|
||||
|
||||
Error ConfigFile::save(const String& p_path){
|
||||
@ -127,8 +271,6 @@ Error ConfigFile::save(const String& p_path){
|
||||
FileAccess *file = FileAccess::open(p_path,FileAccess::WRITE,&err);
|
||||
|
||||
if (err) {
|
||||
if (file)
|
||||
memdelete(file);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -141,9 +283,7 @@ Error ConfigFile::save(const String& p_path){
|
||||
|
||||
for(Map<String, Variant>::Element *F=E->get().front();F;F=F->next()) {
|
||||
|
||||
String vstr;
|
||||
VariantWriter::write_to_string(F->get(),vstr);
|
||||
file->store_string(F->key()+"="+vstr+"\n");
|
||||
file->store_string(F->key()+"="+_encode_variant(F->get())+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,49 +292,432 @@ Error ConfigFile::save(const String& p_path){
|
||||
return OK;
|
||||
}
|
||||
|
||||
static Vector<String> _decode_params(const String& p_string) {
|
||||
|
||||
int begin=p_string.find("(");
|
||||
ERR_FAIL_COND_V(begin==-1,Vector<String>());
|
||||
begin++;
|
||||
int end=p_string.find(")");
|
||||
ERR_FAIL_COND_V(end<begin,Vector<String>());
|
||||
return p_string.substr(begin,end-begin).split(",");
|
||||
}
|
||||
|
||||
static String _get_chunk(const String& str,int &pos, int close_pos) {
|
||||
|
||||
|
||||
enum {
|
||||
MIN_COMMA,
|
||||
MIN_COLON,
|
||||
MIN_CLOSE,
|
||||
MIN_QUOTE,
|
||||
MIN_PARENTHESIS,
|
||||
MIN_CURLY_OPEN,
|
||||
MIN_OPEN
|
||||
};
|
||||
|
||||
int min_pos=close_pos;
|
||||
int min_what=MIN_CLOSE;
|
||||
|
||||
#define TEST_MIN(m_how,m_what) \
|
||||
{\
|
||||
int res = str.find(m_how,pos);\
|
||||
if (res!=-1 && res < min_pos) {\
|
||||
min_pos=res;\
|
||||
min_what=m_what;\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
TEST_MIN(",",MIN_COMMA);
|
||||
TEST_MIN("[",MIN_OPEN);
|
||||
TEST_MIN("{",MIN_CURLY_OPEN);
|
||||
TEST_MIN("(",MIN_PARENTHESIS);
|
||||
TEST_MIN("\"",MIN_QUOTE);
|
||||
|
||||
int end=min_pos;
|
||||
|
||||
|
||||
switch(min_what) {
|
||||
|
||||
case MIN_COMMA: {
|
||||
} break;
|
||||
case MIN_CLOSE: {
|
||||
//end because it's done
|
||||
} break;
|
||||
case MIN_QUOTE: {
|
||||
end=str.find("\"",min_pos+1)+1;
|
||||
ERR_FAIL_COND_V(end==-1,Variant());
|
||||
|
||||
} break;
|
||||
case MIN_PARENTHESIS: {
|
||||
|
||||
end=str.find(")",min_pos+1)+1;
|
||||
ERR_FAIL_COND_V(end==-1,Variant());
|
||||
|
||||
} break;
|
||||
case MIN_OPEN: {
|
||||
int level=1;
|
||||
end++;
|
||||
while(end<close_pos) {
|
||||
|
||||
if (str[end]=='[')
|
||||
level++;
|
||||
if (str[end]==']') {
|
||||
level--;
|
||||
if (level==0)
|
||||
break;
|
||||
}
|
||||
end++;
|
||||
}
|
||||
ERR_FAIL_COND_V(level!=0,Variant());
|
||||
end++;
|
||||
} break;
|
||||
case MIN_CURLY_OPEN: {
|
||||
int level=1;
|
||||
end++;
|
||||
while(end<close_pos) {
|
||||
|
||||
if (str[end]=='{')
|
||||
level++;
|
||||
if (str[end]=='}') {
|
||||
level--;
|
||||
if (level==0)
|
||||
break;
|
||||
}
|
||||
end++;
|
||||
}
|
||||
ERR_FAIL_COND_V(level!=0,Variant());
|
||||
end++;
|
||||
} break;
|
||||
|
||||
}
|
||||
|
||||
String ret = str.substr(pos,end-pos);
|
||||
|
||||
pos=end;
|
||||
while(pos<close_pos) {
|
||||
if (str[pos]!=',' && str[pos]!=' ' && str[pos]!=':')
|
||||
break;
|
||||
pos++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static Variant _decode_variant(const String& p_string) {
|
||||
|
||||
|
||||
String str = p_string.strip_edges();
|
||||
|
||||
if (str.nocasecmp_to("true")==0)
|
||||
return Variant(true);
|
||||
if (str.nocasecmp_to("false")==0)
|
||||
return Variant(false);
|
||||
if (str.nocasecmp_to("nil")==0)
|
||||
return Variant();
|
||||
if (str.is_valid_float()) {
|
||||
if (str.find(".")==-1)
|
||||
return str.to_int();
|
||||
else
|
||||
return str.to_double();
|
||||
|
||||
}
|
||||
if (str.begins_with("#")) { //string
|
||||
return Color::html(str);
|
||||
}
|
||||
if (str.begins_with("\"")) { //string
|
||||
int end = str.find_last("\"");
|
||||
ERR_FAIL_COND_V(end==0,Variant());
|
||||
return str.substr(1,end-1).xml_unescape();
|
||||
|
||||
}
|
||||
|
||||
if (str.begins_with("[")) { //array
|
||||
|
||||
int close_pos = str.find_last("]");
|
||||
ERR_FAIL_COND_V(close_pos==-1,Variant());
|
||||
Array array;
|
||||
|
||||
int pos=1;
|
||||
|
||||
while(pos<close_pos) {
|
||||
|
||||
String s = _get_chunk(str,pos,close_pos);
|
||||
array.push_back(_decode_variant(s));
|
||||
}
|
||||
return array;
|
||||
|
||||
}
|
||||
|
||||
if (str.begins_with("{")) { //array
|
||||
|
||||
int close_pos = str.find_last("}");
|
||||
ERR_FAIL_COND_V(close_pos==-1,Variant());
|
||||
Dictionary d;
|
||||
|
||||
int pos=1;
|
||||
|
||||
while(pos<close_pos) {
|
||||
|
||||
String key = _get_chunk(str,pos,close_pos);
|
||||
String data = _get_chunk(str,pos,close_pos);
|
||||
d[_decode_variant(key)]=_decode_variant(data);
|
||||
}
|
||||
return d;
|
||||
|
||||
}
|
||||
if (str.begins_with("key")) {
|
||||
Vector<String> params = _decode_params(p_string);
|
||||
ERR_FAIL_COND_V(params.size()!=1 && params.size()!=2,Variant());
|
||||
int scode=0;
|
||||
|
||||
if (params[0].is_numeric()) {
|
||||
scode=params[0].to_int();
|
||||
if (scode < 10) {
|
||||
scode=KEY_0+scode;
|
||||
}
|
||||
} else
|
||||
scode=find_keycode(params[0]);
|
||||
|
||||
InputEvent ie;
|
||||
ie.type=InputEvent::KEY;
|
||||
ie.key.scancode=scode;
|
||||
|
||||
if (params.size()==2) {
|
||||
String mods=params[1];
|
||||
if (mods.findn("C")!=-1)
|
||||
ie.key.mod.control=true;
|
||||
if (mods.findn("A")!=-1)
|
||||
ie.key.mod.alt=true;
|
||||
if (mods.findn("S")!=-1)
|
||||
ie.key.mod.shift=true;
|
||||
if (mods.findn("M")!=-1)
|
||||
ie.key.mod.meta=true;
|
||||
}
|
||||
return ie;
|
||||
|
||||
}
|
||||
|
||||
if (str.begins_with("mbutton")) {
|
||||
Vector<String> params = _decode_params(p_string);
|
||||
ERR_FAIL_COND_V(params.size()!=2,Variant());
|
||||
|
||||
InputEvent ie;
|
||||
ie.type=InputEvent::MOUSE_BUTTON;
|
||||
ie.device=params[0].to_int();
|
||||
ie.mouse_button.button_index=params[1].to_int();
|
||||
|
||||
return ie;
|
||||
}
|
||||
|
||||
if (str.begins_with("jbutton")) {
|
||||
Vector<String> params = _decode_params(p_string);
|
||||
ERR_FAIL_COND_V(params.size()!=2,Variant());
|
||||
|
||||
InputEvent ie;
|
||||
ie.type=InputEvent::JOYSTICK_BUTTON;
|
||||
ie.device=params[0].to_int();
|
||||
ie.joy_button.button_index=params[1].to_int();
|
||||
|
||||
return ie;
|
||||
}
|
||||
|
||||
if (str.begins_with("jaxis")) {
|
||||
Vector<String> params = _decode_params(p_string);
|
||||
ERR_FAIL_COND_V(params.size()!=2,Variant());
|
||||
|
||||
InputEvent ie;
|
||||
ie.type=InputEvent::JOYSTICK_MOTION;
|
||||
ie.device=params[0].to_int();
|
||||
ie.joy_motion.axis=params[1].to_int();
|
||||
|
||||
return ie;
|
||||
}
|
||||
if (str.begins_with("img")) {
|
||||
Vector<String> params = _decode_params(p_string);
|
||||
if (params.size()==0) {
|
||||
return Image();
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(params.size()!=5,Image());
|
||||
|
||||
String format=params[0].strip_edges();
|
||||
|
||||
Image::Format imgformat;
|
||||
|
||||
if (format=="grayscale") {
|
||||
imgformat=Image::FORMAT_GRAYSCALE;
|
||||
} else if (format=="intensity") {
|
||||
imgformat=Image::FORMAT_INTENSITY;
|
||||
} else if (format=="grayscale_alpha") {
|
||||
imgformat=Image::FORMAT_GRAYSCALE_ALPHA;
|
||||
} else if (format=="rgb") {
|
||||
imgformat=Image::FORMAT_RGB;
|
||||
} else if (format=="rgba") {
|
||||
imgformat=Image::FORMAT_RGBA;
|
||||
} 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;
|
||||
} else if (format=="bc2") {
|
||||
imgformat=Image::FORMAT_BC2;
|
||||
} else if (format=="bc3") {
|
||||
imgformat=Image::FORMAT_BC3;
|
||||
} else if (format=="bc4") {
|
||||
imgformat=Image::FORMAT_BC4;
|
||||
} else if (format=="bc5") {
|
||||
imgformat=Image::FORMAT_BC5;
|
||||
} 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();
|
||||
int h=params[3].to_int();
|
||||
|
||||
if (w == 0 && h == 0) {
|
||||
//r_v = Image(w, h, imgformat);
|
||||
return Image();
|
||||
};
|
||||
|
||||
|
||||
String data=params[4];
|
||||
int datasize=data.length()/2;
|
||||
DVector<uint8_t> pixels;
|
||||
pixels.resize(datasize);
|
||||
DVector<uint8_t>::Write wb = pixels.write();
|
||||
const CharType *cptr=data.c_str();
|
||||
|
||||
int idx=0;
|
||||
uint8_t byte;
|
||||
while( idx<datasize*2) {
|
||||
|
||||
CharType c=*(cptr++);
|
||||
|
||||
ERR_FAIL_COND_V(c=='<',ERR_FILE_CORRUPT);
|
||||
|
||||
if ( (c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f') ) {
|
||||
|
||||
if (idx&1) {
|
||||
|
||||
byte|=HEX2CHR(c);
|
||||
wb[idx>>1]=byte;
|
||||
} else {
|
||||
|
||||
byte=HEX2CHR(c)<<4;
|
||||
}
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wb = DVector<uint8_t>::Write();
|
||||
|
||||
return Image(w,h,mipmaps,imgformat,pixels);
|
||||
}
|
||||
|
||||
if (str.find(",")!=-1) { //vector2 or vector3
|
||||
Vector<float> farr = str.split_floats(",",true);
|
||||
if (farr.size()==2) {
|
||||
return Point2(farr[0],farr[1]);
|
||||
}
|
||||
if (farr.size()==3) {
|
||||
return Vector3(farr[0],farr[1],farr[2]);
|
||||
}
|
||||
ERR_FAIL_V(Variant());
|
||||
}
|
||||
|
||||
|
||||
return Variant();
|
||||
}
|
||||
|
||||
Error ConfigFile::load(const String& p_path) {
|
||||
|
||||
Error err;
|
||||
FileAccess *f= FileAccess::open(p_path,FileAccess::READ,&err);
|
||||
|
||||
if (!f)
|
||||
return ERR_CANT_OPEN;
|
||||
if (err!=OK) {
|
||||
|
||||
VariantParser::StreamFile stream;
|
||||
stream.f=f;
|
||||
return err;
|
||||
}
|
||||
|
||||
String assign;
|
||||
Variant value;
|
||||
VariantParser::Tag next_tag;
|
||||
|
||||
int lines=0;
|
||||
String error_text;
|
||||
|
||||
String line;
|
||||
String section;
|
||||
String subpath;
|
||||
|
||||
while(true) {
|
||||
int line_count = 0;
|
||||
|
||||
assign=Variant();
|
||||
next_tag.fields.clear();
|
||||
next_tag.name=String();
|
||||
while(!f->eof_reached()) {
|
||||
|
||||
err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true);
|
||||
if (err==ERR_FILE_EOF) {
|
||||
memdelete(f);
|
||||
return OK;
|
||||
}
|
||||
else if (err!=OK) {
|
||||
ERR_PRINTS("ConfgFile::load - "+p_path+":"+itos(lines)+" error: "+error_text);
|
||||
memdelete(f);
|
||||
return err;
|
||||
String line = f->get_line().strip_edges();
|
||||
line_count++;
|
||||
|
||||
if (line=="")
|
||||
continue;
|
||||
|
||||
// find comments
|
||||
|
||||
{
|
||||
|
||||
int pos=0;
|
||||
while (true) {
|
||||
int ret = line.find(";",pos);
|
||||
if (ret==-1)
|
||||
break;
|
||||
|
||||
int qc=0;
|
||||
for(int i=0;i<ret;i++) {
|
||||
|
||||
if (line[i]=='"')
|
||||
qc++;
|
||||
}
|
||||
|
||||
if ( !(qc&1) ) {
|
||||
//not inside string, real comment
|
||||
line=line.substr(0,ret);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
pos=ret+1;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (assign!=String()) {
|
||||
set_value(section,assign,value);
|
||||
} else if (next_tag.name!=String()) {
|
||||
section=next_tag.name;
|
||||
}
|
||||
if (line.begins_with("[")) {
|
||||
|
||||
int end = line.find_last("]");
|
||||
ERR_CONTINUE(end!=line.length()-1);
|
||||
|
||||
section=line.substr(1,line.length()-2);
|
||||
|
||||
} else if (line.find("=")!=-1) {
|
||||
|
||||
|
||||
int eqpos = line.find("=");
|
||||
String var=line.substr(0,eqpos).strip_edges();
|
||||
String value=line.substr(eqpos+1,line.length()).strip_edges();
|
||||
|
||||
Variant val = _decode_variant(value);
|
||||
|
||||
set_value(section,var,val);
|
||||
|
||||
} else {
|
||||
|
||||
if (line.length() > 0) {
|
||||
ERR_PRINT(String("Syntax error on line "+itos(line_count)+" of file "+p_path).ascii().get_data());
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
memdelete(f);
|
||||
@ -207,13 +730,13 @@ Error ConfigFile::load(const String& p_path) {
|
||||
void ConfigFile::_bind_methods(){
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_value","section","key","value"),&ConfigFile::set_value);
|
||||
ObjectTypeDB::bind_method(_MD("get_value:Variant","section","key","default"),&ConfigFile::get_value,DEFVAL(Variant()));
|
||||
ObjectTypeDB::bind_method(_MD("get_value","section","key"),&ConfigFile::get_value);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("has_section","section"),&ConfigFile::has_section);
|
||||
ObjectTypeDB::bind_method(_MD("has_section_key","section","key"),&ConfigFile::has_section_key);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_sections"),&ConfigFile::_get_sections);
|
||||
ObjectTypeDB::bind_method(_MD("get_section_keys","section"),&ConfigFile::_get_section_keys);
|
||||
ObjectTypeDB::bind_method(_MD("get_section_keys"),&ConfigFile::_get_section_keys);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("load:Error","path"),&ConfigFile::load);
|
||||
ObjectTypeDB::bind_method(_MD("save:Error","path"),&ConfigFile::save);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2007-2015 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 @@ protected:
|
||||
public:
|
||||
|
||||
void set_value(const String& p_section, const String& p_key, const Variant& p_value);
|
||||
Variant get_value(const String& p_section, const String& p_key, Variant p_default=Variant()) const;
|
||||
Variant get_value(const String& p_section, const String& p_key) const;
|
||||
|
||||
bool has_section(const String& p_section) const;
|
||||
bool has_section_key(const String& p_section,const String& p_key) const;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
FastLZ - lightning-fast lossless compression library
|
||||
|
||||
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
|
||||
@ -40,11 +40,11 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
minimum input buffer size is 16.
|
||||
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
and can not be smaller than 66 bytes.
|
||||
|
||||
If the input is not compressible, the return value might be larger than
|
||||
@ -56,9 +56,9 @@ extern "C" {
|
||||
int fastlz_compress(const void* input, int length, void* output);
|
||||
|
||||
/**
|
||||
Decompress a block of compressed data and returns the size of the
|
||||
decompressed block. If error occurs, e.g. the compressed data is
|
||||
corrupted or the output buffer is not large enough, then 0 (zero)
|
||||
Decompress a block of compressed data and returns the size of the
|
||||
decompressed block. If error occurs, e.g. the compressed data is
|
||||
corrupted or the output buffer is not large enough, then 0 (zero)
|
||||
will be returned instead.
|
||||
|
||||
The input buffer and the output buffer can not overlap.
|
||||
@ -67,14 +67,14 @@ int fastlz_compress(const void* input, int length, void* output);
|
||||
more than what is specified in maxout.
|
||||
*/
|
||||
|
||||
int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
||||
int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
||||
|
||||
/**
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
minimum input buffer size is 16.
|
||||
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
and can not be smaller than 66 bytes.
|
||||
|
||||
If the input is not compressible, the return value might be larger than
|
||||
@ -82,14 +82,14 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
||||
|
||||
The input buffer and the output buffer can not overlap.
|
||||
|
||||
Compression level can be specified in parameter level. At the moment,
|
||||
Compression level can be specified in parameter level. At the moment,
|
||||
only level 1 and level 2 are supported.
|
||||
Level 1 is the fastest compression and generally useful for short data.
|
||||
Level 2 is slightly slower but it gives better compression ratio.
|
||||
|
||||
Note that the compressed data, regardless of the level, can always be
|
||||
decompressed using the function fastlz_decompress above.
|
||||
*/
|
||||
*/
|
||||
|
||||
int fastlz_compress_level(int level, const void* input, int length, void* output);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user