summaryrefslogtreecommitdiff
path: root/platform/windows
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows')
-rw-r--r--platform/windows/SCsub9
-rw-r--r--platform/windows/context_gl_win.cpp2
-rw-r--r--platform/windows/context_gl_win.h2
-rw-r--r--platform/windows/ctxgl_procaddr.cpp2
-rw-r--r--platform/windows/ctxgl_procaddr.h2
-rw-r--r--platform/windows/detect.py41
-rw-r--r--platform/windows/export/export.cpp343
-rw-r--r--platform/windows/export/export.h34
-rw-r--r--platform/windows/godot.icobin0 -> 370070 bytes
-rw-r--r--platform/windows/godot_res.rc33
-rw-r--r--platform/windows/godot_win.cpp2
-rw-r--r--platform/windows/joystick.cpp536
-rw-r--r--platform/windows/joystick.h142
-rw-r--r--platform/windows/key_mapping_win.cpp2
-rw-r--r--platform/windows/key_mapping_win.h2
-rw-r--r--platform/windows/lang_table.h2
-rw-r--r--platform/windows/os_windows.cpp380
-rw-r--r--platform/windows/os_windows.h43
-rw-r--r--platform/windows/packet_peer_udp_winsock.cpp21
-rw-r--r--platform/windows/platform_config.h2
-rw-r--r--platform/windows/stream_peer_winsock.cpp10
-rw-r--r--platform/windows/stream_peer_winsock.h4
-rw-r--r--platform/windows/tcp_server_winsock.cpp2
-rw-r--r--platform/windows/tcp_server_winsock.h2
24 files changed, 1248 insertions, 370 deletions
diff --git a/platform/windows/SCsub b/platform/windows/SCsub
index 1ad32e7989..2db3d0f51e 100644
--- a/platform/windows/SCsub
+++ b/platform/windows/SCsub
@@ -9,11 +9,18 @@ common_win=[
"tcp_server_winsock.cpp",
"packet_peer_udp_winsock.cpp",
"stream_peer_winsock.cpp",
+ "joystick.cpp",
]
+restarget="godot_res"+env["OBJSUFFIX"]
+
+obj = env.RES(restarget,'godot_res.rc')
+
+common_win.append(obj)
+
env.Program('#bin/godot',['godot_win.cpp']+common_win,PROGSUFFIX=env["PROGSUFFIX"])
-# Microsoft Visual Studio Project Generation
+# Microsoft Visual Studio Project Generation
if (env['vsproj'])=="yes":
env.vs_srcs = env.vs_srcs + ["platform/windows/godot_win.cpp"]
for x in common_win:
diff --git a/platform/windows/context_gl_win.cpp b/platform/windows/context_gl_win.cpp
index 5a9c8edc63..e671101432 100644
--- a/platform/windows/context_gl_win.cpp
+++ b/platform/windows/context_gl_win.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/context_gl_win.h b/platform/windows/context_gl_win.h
index 5397676c8e..af15ad2659 100644
--- a/platform/windows/context_gl_win.h
+++ b/platform/windows/context_gl_win.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/ctxgl_procaddr.cpp b/platform/windows/ctxgl_procaddr.cpp
index 6e5f53eb96..1072197f89 100644
--- a/platform/windows/ctxgl_procaddr.cpp
+++ b/platform/windows/ctxgl_procaddr.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/ctxgl_procaddr.h b/platform/windows/ctxgl_procaddr.h
index 916b480639..2118e20e02 100644
--- a/platform/windows/ctxgl_procaddr.h
+++ b/platform/windows/ctxgl_procaddr.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index f0d2a7cc40..a1366e7630 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -88,7 +88,7 @@
import os
-import sys
+import sys
def is_active():
@@ -170,16 +170,32 @@ def get_flags():
return [
('freetype','builtin'), #use builtin freetype
('openssl','builtin'), #use builtin openssl
- ('theora','no'),
]
+def build_res_file( target, source, env ):
+ cmdbase = ""
+ if (env["bits"] == "32"):
+ cmdbase = env['mingw_prefix']
+ else:
+ cmdbase = env['mingw_prefix_64']
+ CPPPATH = env['CPPPATH']
+ cmdbase = cmdbase + 'windres --include-dir . '
+ import subprocess
+ for x in range(len(source)):
+ cmd = cmdbase + '-i ' + str(source[x]) + ' -o ' + str(target[x])
+ try:
+ out = subprocess.Popen(cmd,shell = True,stderr = subprocess.PIPE).communicate()
+ if len(out[1]):
+ return 1
+ except:
+ return 1
+ return 0
def configure(env):
env.Append(CPPPATH=['#platform/windows'])
-
-
+ env['is_mingw']=False
if (os.name=="nt" and os.getenv("VSINSTALLDIR")!=None):
#build using visual studio
env['ENV']['TMP'] = os.environ['TMP']
@@ -203,14 +219,14 @@ def configure(env):
env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
elif (env["target"]=="debug_release"):
- env.Append(CCFLAGS=['/Zi','/Od'])
+ env.Append(CCFLAGS=['/Z7','/Od'])
env.Append(LINKFLAGS=['/DEBUG'])
env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS'])
env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup'])
elif (env["target"]=="debug"):
- env.Append(CCFLAGS=['/Zi','/DDEBUG_ENABLED','/DDEBUG_MEMORY_ENABLED','/DD3D_DEBUG_INFO','/Od'])
+ env.Append(CCFLAGS=['/Z7','/DDEBUG_ENABLED','/DDEBUG_MEMORY_ENABLED','/DD3D_DEBUG_INFO','/Od'])
env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
env.Append(LINKFLAGS=['/DEBUG'])
@@ -227,7 +243,7 @@ def configure(env):
env.Append(CCFLAGS=['/DGLES2_ENABLED'])
env.Append(CCFLAGS=['/DGLEW_ENABLED'])
- LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI','Shlwapi', 'wsock32', 'shell32','advapi32']
+ LIBS=['winmm','opengl32','dsound','kernel32','ole32','oleaut32','user32','gdi32', 'IPHLPAPI','Shlwapi', 'wsock32', 'shell32','advapi32','dinput8','dxguid']
env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS])
env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"])
@@ -246,6 +262,7 @@ def configure(env):
env.Append(CCFLAGS=["/I"+DIRECTX_PATH+"/Include"])
env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"])
env['ENV'] = os.environ;
+ env["x86_opt_vc"]=True
else:
# Workaround for MinGW. See:
@@ -344,6 +361,7 @@ def configure(env):
env['AR'] = mingw_prefix+"ar"
env['RANLIB'] = mingw_prefix+"ranlib"
env['LD'] = mingw_prefix+"g++"
+ env["x86_opt_gcc"]=True
#env['CC'] = "winegcc"
#env['CXX'] = "wineg++"
@@ -351,10 +369,10 @@ def configure(env):
env.Append(CCFLAGS=['-DWINDOWS_ENABLED','-mwindows'])
env.Append(CPPFLAGS=['-DRTAUDIO_ENABLED'])
env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLEW_ENABLED'])
- env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','shlwapi','wsock32','kernel32'])
+ env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','shlwapi','wsock32','kernel32', 'oleaut32', 'dinput8', 'dxguid'])
# if (env["bits"]=="32"):
-# # env.Append(LIBS=['gcc_s'])
+ # env.Append(LIBS=['gcc_s'])
# #--with-arch=i686
# env.Append(CPPFLAGS=['-march=i686'])
# env.Append(LINKFLAGS=['-march=i686'])
@@ -366,6 +384,10 @@ def configure(env):
env.Append(CPPFLAGS=['-DMINGW_ENABLED'])
env.Append(LINKFLAGS=['-g'])
+ # resrc
+ env['is_mingw']=True
+ env.Append( BUILDERS = { 'RES' : env.Builder(action = build_res_file, suffix = '.o',src_suffix = '.rc') } )
+
import methods
env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
@@ -373,4 +395,3 @@ def configure(env):
env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
-
diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp
index 952f51fdd4..899edde087 100644
--- a/platform/windows/export/export.cpp
+++ b/platform/windows/export/export.cpp
@@ -1,6 +1,345 @@
+/*************************************************************************/
+/* export.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 "export.h"
#include "platform/windows/logo.h"
-#include "tools/editor/editor_import_export.h"
+#include "os/os.h"
+#include "globals.h"
+#include "tools/editor/editor_node.h"
+#include "tools/pe_bliss/pe_bliss_godot.h"
+
+/**
+ @author Masoud BaniHashemian <masoudbh3@gmail.com>
+*/
+
+
+void EditorExportPlatformWindows::store_16(DVector<uint8_t>& vector, uint16_t value) {
+ const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&value);
+ int size = vector.size();
+ vector.resize( size + 2 );
+ DVector<uint8_t>::Write w = vector.write();
+ w[size]=bytes[0];
+ w[size+1]=bytes[1];
+}
+void EditorExportPlatformWindows::store_32(DVector<uint8_t>& vector, uint32_t value) {
+ const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&value);
+ int size = vector.size();
+ vector.resize( size + 4 );
+ DVector<uint8_t>::Write w = vector.write();
+ w[size]=bytes[0];
+ w[size+1]=bytes[1];
+ w[size+2]=bytes[2];
+ w[size+3]=bytes[3];
+}
+
+bool EditorExportPlatformWindows::_set(const StringName& p_name, const Variant& p_value) {
+
+ String n = p_name;
+
+ if (n=="icon/icon_ico") {
+
+ icon_ico=p_value;
+ } else if (n=="icon/icon_png") {
+
+ icon_png=p_value;
+ } else if (n=="icon/icon_png16x16") {
+
+ icon16=p_value;
+ } else if (n=="icon/icon_png32x32") {
+
+ icon32=p_value;
+ } else if (n=="icon/icon_png48x48") {
+
+ icon48=p_value;
+ } else if (n=="icon/icon_png64x64") {
+
+ icon64=p_value;
+ } else if (n=="icon/icon_png128x128") {
+
+ icon128=p_value;
+ } else if (n=="icon/icon_png256x256") {
+
+ icon256=p_value;
+ } else if (n=="version_info/version_major") {
+
+ version_major=p_value;
+ } else if (n=="version_info/version_minor") {
+
+ version_minor=p_value;
+ } else if (n=="version_info/version_text") {
+
+ version_text=p_value;
+ } else if (n=="version_info/company_name") {
+
+ company_name=p_value;
+ } else if (n=="version_info/file_description") {
+
+ file_description=p_value;
+ } else if (n=="version_info/product_name") {
+
+ product_name=p_value;
+ } else if (n=="version_info/legal_copyright") {
+
+ legal_copyright=p_value;
+ } else if (n=="version_info/add_godot_version") {
+
+ set_godot_version=p_value;
+ } else
+ return false;
+
+ return true;
+
+}
+
+bool EditorExportPlatformWindows::_get(const StringName& p_name,Variant &r_ret) const {
+
+ String n = p_name;
+
+ if (n=="icon/icon_ico") {
+
+ r_ret=icon_ico;
+ } else if (n=="icon/icon_png") {
+
+ r_ret=icon_png;
+ } else if (n=="icon/icon_png16x16") {
+
+ r_ret=icon16;
+ } else if (n=="icon/icon_png32x32") {
+
+ r_ret=icon32;
+ } else if (n=="icon/icon_png48x48") {
+
+ r_ret=icon48;
+ } else if (n=="icon/icon_png64x64") {
+
+ r_ret=icon64;
+ } else if (n=="icon/icon_png128x128") {
+
+ r_ret=icon128;
+ } else if (n=="icon/icon_png256x256") {
+
+ r_ret=icon256;
+ } else if (n=="version_info/version_major") {
+
+ r_ret=version_major;
+ } else if (n=="version_info/version_minor") {
+
+ r_ret=version_minor;
+ } else if (n=="version_info/version_text") {
+
+ r_ret=version_text;
+ } else if (n=="version_info/company_name") {
+
+ r_ret=company_name;
+ } else if (n=="version_info/file_description") {
+
+ r_ret=file_description;
+ } else if (n=="version_info/product_name") {
+
+ r_ret=product_name;
+ } else if (n=="version_info/legal_copyright") {
+
+ r_ret=legal_copyright;
+ } else if (n=="version_info/add_godot_version") {
+
+ r_ret=set_godot_version;
+ } else
+ return false;
+
+ return true;
+
+}
+
+void EditorExportPlatformWindows::_get_property_list( List<PropertyInfo> *p_list) const {
+
+ p_list->push_back( PropertyInfo( Variant::STRING, "icon/icon_ico",PROPERTY_HINT_FILE,"ico") );
+ p_list->push_back( PropertyInfo( Variant::STRING, "icon/icon_png",PROPERTY_HINT_FILE,"png") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png16x16") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png32x32") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png48x48") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png64x64") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png128x128") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png256x256") );
+ p_list->push_back( PropertyInfo( Variant::INT, "version_info/version_major", PROPERTY_HINT_RANGE,"0,65535,1"));
+ p_list->push_back( PropertyInfo( Variant::INT, "version_info/version_minor", PROPERTY_HINT_RANGE,"0,65535,0"));
+ p_list->push_back( PropertyInfo( Variant::STRING, "version_info/version_text") );
+ p_list->push_back( PropertyInfo( Variant::STRING, "version_info/company_name") );
+ p_list->push_back( PropertyInfo( Variant::STRING, "version_info/file_description") );
+ p_list->push_back( PropertyInfo( Variant::STRING, "version_info/product_name") );
+ p_list->push_back( PropertyInfo( Variant::STRING, "version_info/legal_copyright") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "version_info/add_godot_version") );
+
+}
+
+Error EditorExportPlatformWindows::export_project(const String& p_path, bool p_debug, int p_flags) {
+
+ Error err = EditorExportPlatformPC::export_project(p_path, p_debug, p_flags);
+ if(err != OK)
+ {
+ return err;
+ }
+ EditorProgress ep("editexe","Edit EXE File",102);
+ ep.step("Create ico file..",0);
+
+ DVector<uint8_t> icon_content;
+ if (this->icon_ico!="" && this->icon_ico.ends_with(".ico")) {
+ FileAccess *f = FileAccess::open(this->icon_ico,FileAccess::READ);
+ if (f) {
+ icon_content.resize(f->get_len());
+ DVector<uint8_t>::Write write = icon_content.write();
+ f->get_buffer(write.ptr(),icon_content.size());
+ f->close();
+ memdelete(f);
+ }
+ } else if (this->icon_png!="" && this->icon_png.ends_with(".png") && (icon16 || icon32 || icon48 || icon64 || icon128 || icon256)) {
+ #ifdef PNG_ENABLED
+ Vector<Image> pngs;
+ Image png;
+ Error err_png = png.load(this->icon_png);
+ if (err_png==OK && !png.empty()) {
+ if(icon256) {
+ Image icon_256(png);
+ if(!(png.get_height()==256 && png.get_width()==256)) icon_256.resize(256,256);
+ pngs.push_back(icon_256);
+ }
+ if(icon128) {
+ Image icon_128(png);
+ if(!(png.get_height()==128 && png.get_width()==128)) icon_128.resize(128,128);
+ pngs.push_back(icon_128);
+ }
+ if(icon64) {
+ Image icon_64(png);
+ if(!(png.get_height()==64 && png.get_width()==64)) icon_64.resize(64,64);
+ pngs.push_back(icon_64);
+ }
+ if(icon48) {
+ Image icon_48(png);
+ if(!(png.get_height()==48 && png.get_width()==48)) icon_48.resize(48,48);
+ pngs.push_back(icon_48);
+ }
+ if(icon32) {
+ Image icon_32(png);
+ if(!(png.get_height()==32 && png.get_width()==32)) icon_32.resize(32,32);
+ pngs.push_back(icon_32);
+ }
+ if(icon16) {
+ Image icon_16(png);
+ if(!(png.get_height()==16 && png.get_width()==16)) icon_16.resize(16,16);
+ pngs.push_back(icon_16);
+ }
+ // create icon according to https://www.daubnet.com/en/file-format-ico
+ store_16(icon_content,0); //Reserved
+ store_16(icon_content,1); //Type
+ store_16(icon_content,pngs.size()); //Count
+ int offset = 6+pngs.size()*16;
+ //List of bitmaps
+ for(int i=0;i<pngs.size();i++) {
+ int w = pngs[i].get_width();
+ int h = pngs[i].get_height();
+ icon_content.push_back(w<256?w:0); //width
+ icon_content.push_back(h<256?h:0); //height
+ icon_content.push_back(0); //ColorCount = 0
+ icon_content.push_back(0); //Reserved
+ store_16(icon_content,1); //Planes
+ store_16(icon_content,32); //BitCount (bit per pixel)
+ int size = 40 + (w * h * 4) + (w * h / 8);
+ store_32(icon_content,size); //Size of (InfoHeader + ANDbitmap + XORbitmap)
+ store_32(icon_content,offset); //FileOffset
+ offset += size;
+ }
+ //Write bmp files.
+ for(int i=0;i<pngs.size();i++) {
+ int w = pngs[i].get_width();
+ int h = pngs[i].get_height();
+ store_32(icon_content,40); //Size of InfoHeader structure = 40
+ store_32(icon_content,w); //Width
+ store_32(icon_content,h*2); //Height
+ store_16(icon_content,1); //Planes
+ store_16(icon_content,32); //BitCount
+ store_32(icon_content,0); //Compression
+ store_32(icon_content,w*h*4); //ImageSize = Size of Image in Bytes
+ store_32(icon_content,0); //unused = 0
+ store_32(icon_content,0); //unused = 0
+ store_32(icon_content,0); //unused = 0
+ store_32(icon_content,0); //unused = 0
+ //XORBitmap
+ for(int y=h-1;y>=0;y--) {
+ for(int x=0;x<w;x++) {
+ store_32(icon_content,pngs[i].get_pixel(x,y).to_32());
+ }
+ }
+ //ANDBitmap
+ for(int m=0;m<(w * h / 8);m+=4) store_32(icon_content,0x00000000); // Add empty ANDBitmap , TODO create full ANDBitmap Structure if need.
+ }
+ }
+ #endif
+ }
+
+ ep.step("Add rsrc..",50);
+
+ String basename = Globals::get_singleton()->get("application/name");
+ product_name=product_name.replace("$genname",basename);
+ String godot_version;
+ if(set_godot_version) godot_version = String( VERSION_MKSTRING );
+ String ret = pe_bliss_add_resrc(p_path.utf8(), version_major, version_minor,
+ company_name, file_description, legal_copyright, version_text,
+ product_name, godot_version, icon_content);
+ if (ret.empty()) {
+ return OK;
+ } else {
+ EditorNode::add_io_error(ret);
+ return ERR_FILE_CANT_WRITE;
+ }
+}
+
+EditorExportPlatformWindows::EditorExportPlatformWindows() {
+
+ icon16=true;
+ icon32=true;
+ icon48=true;
+ icon64=true;
+ icon128=true;
+ icon256=true;
+ product_name="$genname";
+ company_name="Godot Engine";
+ file_description="Created With Godot Engine";
+ version_text="1.0";
+ OS::Date date = OS::get_singleton()->get_date();
+ legal_copyright="Copyright (c) 2007-";
+ legal_copyright+=String::num(date.year);
+ legal_copyright+=" Juan Linietsky, Ariel Manzur";
+ version_major=1;
+ version_minor=0;
+ set_godot_version=true;
+}
+
+
void register_windows_exporter() {
@@ -9,7 +348,7 @@ void register_windows_exporter() {
logo->create_from_image(img);
{
- Ref<EditorExportPlatformPC> exporter = Ref<EditorExportPlatformPC>( memnew(EditorExportPlatformPC) );
+ Ref<EditorExportPlatformWindows> exporter = Ref<EditorExportPlatformWindows>( memnew(EditorExportPlatformWindows) );
exporter->set_binary_extension("exe");
exporter->set_release_binary32("windows_32_release.exe");
exporter->set_debug_binary32("windows_32_debug.exe");
diff --git a/platform/windows/export/export.h b/platform/windows/export/export.h
index de3dc3fa50..2424efc861 100644
--- a/platform/windows/export/export.h
+++ b/platform/windows/export/export.h
@@ -1,3 +1,37 @@
+#include "tools/editor/editor_import_export.h"
+
+class EditorExportPlatformWindows : public EditorExportPlatformPC {
+ OBJ_TYPE( EditorExportPlatformWindows,EditorExportPlatformPC );
+
+private:
+ String icon_ico;
+ String icon_png;
+ bool icon16;
+ bool icon32;
+ bool icon48;
+ bool icon64;
+ bool icon128;
+ bool icon256;
+ String company_name;
+ String file_description;
+ String product_name;
+ String legal_copyright;
+ String version_text;
+ int version_major;
+ int version_minor;
+ bool set_godot_version;
+ void store_16(DVector<uint8_t>& vector, uint16_t value); ///< store 16 bits uint
+ void store_32(DVector<uint8_t>& vector, uint32_t value); ///< store 32 bits uint
+
+protected:
+ 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;
+
+public:
+ Error export_project(const String& p_path, bool p_debug,int p_flags=0);
+ EditorExportPlatformWindows();
+};
void register_windows_exporter();
diff --git a/platform/windows/godot.ico b/platform/windows/godot.ico
new file mode 100644
index 0000000000..e57ce36529
--- /dev/null
+++ b/platform/windows/godot.ico
Binary files differ
diff --git a/platform/windows/godot_res.rc b/platform/windows/godot_res.rc
new file mode 100644
index 0000000000..5f1e951e0f
--- /dev/null
+++ b/platform/windows/godot_res.rc
@@ -0,0 +1,33 @@
+#include "core/version.h"
+#ifndef _STR
+#define _STR(m_x) #m_x
+#define _MKSTR(m_x) _STR(m_x)
+#endif
+
+GODOT_ICON ICON platform/windows/godot.ico
+
+1 VERSIONINFO
+FILEVERSION VERSION_MAJOR,VERSION_MINOR,0,0
+PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,0,0
+FILEOS 4
+FILETYPE 1
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "Godot Engine"
+ VALUE "FileDescription", _MKSTR(VERSION_NAME) " Editor (" _MKSTR(VERSION_STATUS) ")"
+ VALUE "FileVersion", _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "."_MKSTR(VERSION_REVISION)
+ VALUE "ProductName", _MKSTR(VERSION_NAME)
+ VALUE "Licence", "MIT"
+ VALUE "LegalCopyright", "Copyright (c) 2007-" _MKSTR(VERSION_YEAR) " Juan Linietsky, Ariel Manzur"
+ VALUE "Info", "http://www.godotengine.org"
+ VALUE "ProductVersion", _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "."_MKSTR(VERSION_REVISION)
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp
index fe39051670..fa7989c726 100644
--- a/platform/windows/godot_win.cpp
+++ b/platform/windows/godot_win.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/joystick.cpp b/platform/windows/joystick.cpp
new file mode 100644
index 0000000000..f4fb09820f
--- /dev/null
+++ b/platform/windows/joystick.cpp
@@ -0,0 +1,536 @@
+/*************************************************************************/
+/* joystick.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. */
+/*************************************************************************/
+//author: Andreas Haas <hondres, liugam3@gmail.com>
+#include "joystick.h"
+#include <iostream>
+#include <wbemidl.h>
+#include <oleauto.h>
+
+#ifndef __GNUC__
+#define __builtin_bswap32 _byteswap_ulong
+#endif
+
+DWORD WINAPI _xinput_get_state(DWORD dwUserIndex, XINPUT_STATE* pState) { return ERROR_DEVICE_NOT_CONNECTED; }
+
+joystick_windows::joystick_windows() {
+
+}
+
+joystick_windows::joystick_windows(InputDefault* _input, HWND* hwnd) {
+
+ input = _input;
+ hWnd = hwnd;
+ joystick_count = 0;
+ dinput = NULL;
+ xinput_dll = NULL;
+ xinput_get_state = NULL;
+
+ load_xinput();
+
+ for (int i = 0; i < JOYSTICKS_MAX; i++)
+ attached_joysticks[i] = false;
+
+
+ HRESULT result;
+ result = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&dinput, NULL);
+ if (FAILED(result)) {
+ printf("failed init DINPUT: %ld\n", result);
+ }
+ probe_joysticks();
+}
+
+joystick_windows::~joystick_windows() {
+
+ close_joystick();
+ dinput->Release();
+ unload_xinput();
+}
+
+
+bool joystick_windows::have_device(const GUID &p_guid) {
+
+ for (int i = 0; i < JOYSTICKS_MAX; i++) {
+
+ if (d_joysticks[i].guid == p_guid) {
+
+ d_joysticks[i].confirmed = true;
+ return true;
+ }
+ }
+ return false;
+}
+
+int joystick_windows::check_free_joy_slot() const {
+
+ for (int i = 0; i < JOYSTICKS_MAX; i++) {
+
+ if (!attached_joysticks[i])
+ return i;
+ }
+ return -1;
+}
+
+
+// adapted from SDL2, works a lot better than the MSDN version
+bool joystick_windows::is_xinput_device(const GUID *p_guid) {
+
+ static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+
+ if (p_guid == &IID_ValveStreamingGamepad || p_guid == &IID_X360WiredGamepad || p_guid == &IID_X360WirelessGamepad)
+ return true;
+
+ PRAWINPUTDEVICELIST dev_list = NULL;
+ unsigned int dev_list_count = 0;
+
+ if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) {
+ return false;
+ }
+ dev_list = (PRAWINPUTDEVICELIST) malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count);
+ if (!dev_list) return false;
+
+ if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) {
+ free(dev_list);
+ return false;
+ }
+ for (int i = 0; i < dev_list_count; i++) {
+
+ RID_DEVICE_INFO rdi;
+ char dev_name[128];
+ UINT rdiSize = sizeof(rdi);
+ UINT nameSize = sizeof(dev_name);
+
+ rdi.cbSize = rdiSize;
+ if ( (dev_list[i].dwType == RIM_TYPEHID) &&
+ (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1) &&
+ (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)p_guid->Data1) &&
+ (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) &&
+ (strstr(dev_name, "IG_") != NULL)) {
+
+ free(dev_list);
+ return true;
+ }
+ }
+ free(dev_list);
+ return false;
+}
+
+bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE* instance) {
+
+ HRESULT hr;
+ int num = check_free_joy_slot();
+
+ if (have_device(instance->guidInstance) || num == -1)
+ return false;
+
+ d_joysticks[joystick_count] = dinput_gamepad();
+ dinput_gamepad* joy = &d_joysticks[joystick_count];
+
+ const DWORD devtype = (instance->dwDevType & 0xFF);
+
+ if ((devtype != DI8DEVTYPE_JOYSTICK) && (devtype != DI8DEVTYPE_GAMEPAD) && (devtype != DI8DEVTYPE_1STPERSON)) {
+ //printf("ignore device %s, type %x\n", instance->tszProductName, devtype);
+ return false;
+ }
+
+ hr = dinput->CreateDevice(instance->guidInstance, &joy->di_joy, NULL);
+
+ if (FAILED(hr)) {
+
+ //std::wcout << "failed to create device: " << instance->tszProductName << std::endl;
+ return false;
+ }
+
+ const GUID &guid = instance->guidProduct;
+ char uid[128];
+ sprintf(uid, "%08lx%04hx%04hx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
+ __builtin_bswap32(guid.Data1), guid.Data2, guid.Data3,
+ guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
+ guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
+
+ id_to_change = joystick_count;
+
+ joy->di_joy->SetDataFormat(&c_dfDIJoystick2);
+ joy->di_joy->SetCooperativeLevel(*hWnd, DISCL_FOREGROUND);
+ joy->di_joy->EnumObjects(objectsCallback, this, NULL);
+ joy->joy_axis.sort();
+
+ joy->guid = instance->guidInstance;
+ input->joy_connection_changed(num, true, instance->tszProductName, uid);
+ joy->attached = true;
+ joy->id = num;
+ attached_joysticks[num] = true;
+ joy->confirmed = true;
+ joystick_count++;
+ return true;
+}
+
+void joystick_windows::setup_joystick_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id) {
+
+ if (ob->dwType & DIDFT_AXIS) {
+
+ HRESULT res;
+ DIPROPRANGE prop_range;
+ DIPROPDWORD dilong;
+ DWORD ofs;
+ if (ob->guidType == GUID_XAxis)
+ ofs = DIJOFS_X;
+ else if (ob->guidType == GUID_YAxis)
+ ofs = DIJOFS_Y;
+ else if (ob->guidType == GUID_ZAxis)
+ ofs = DIJOFS_Z;
+ else if (ob->guidType == GUID_RxAxis)
+ ofs = DIJOFS_RX;
+ else if (ob->guidType == GUID_RyAxis)
+ ofs = DIJOFS_RY;
+ else if (ob->guidType == GUID_RzAxis)
+ ofs = DIJOFS_RZ;
+ else if (ob->guidType == GUID_Slider)
+ ofs = DIJOFS_SLIDER(0);
+ else
+ return;
+ prop_range.diph.dwSize = sizeof(DIPROPRANGE);
+ prop_range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ prop_range.diph.dwObj = ob->dwType;
+ prop_range.diph.dwHow = DIPH_BYID;
+ prop_range.lMin = -MAX_JOY_AXIS;
+ prop_range.lMax = +MAX_JOY_AXIS;
+
+ dinput_gamepad &joy = d_joysticks[p_joy_id];
+
+
+ res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_RANGE, &prop_range.diph);
+ if (FAILED(res))
+ return;
+
+ dilong.diph.dwSize = sizeof(dilong);
+ dilong.diph.dwHeaderSize = sizeof(dilong.diph);
+ dilong.diph.dwObj = ob->dwType;
+ dilong.diph.dwHow = DIPH_BYID;
+ dilong.dwData = 0;
+
+ res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_DEADZONE, &dilong.diph);
+ if (FAILED(res))
+ return;
+
+ joy.joy_axis.push_back(ofs);
+ }
+}
+
+BOOL CALLBACK joystick_windows::enumCallback(const DIDEVICEINSTANCE* instance, void* pContext) {
+
+
+ joystick_windows* self = (joystick_windows*)pContext;
+ if (self->is_xinput_device(&instance->guidProduct)) {;
+ return DIENUM_CONTINUE;
+ }
+ self->setup_dinput_joystick(instance);
+ return DIENUM_CONTINUE;
+}
+
+BOOL CALLBACK joystick_windows::objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context) {
+
+ joystick_windows* self = (joystick_windows*)context;
+ self->setup_joystick_object(instance, self->id_to_change);
+
+ return DIENUM_CONTINUE;
+}
+
+void joystick_windows::close_joystick(int id) {
+
+ if (id == -1) {
+
+ for (int i = 0; i < JOYSTICKS_MAX; i++) {
+
+ close_joystick(i);
+ }
+ return;
+ }
+
+ if (!d_joysticks[id].attached) return;
+
+ d_joysticks[id].di_joy->Unacquire();
+ d_joysticks[id].di_joy->Release();
+ d_joysticks[id].attached = false;
+ attached_joysticks[d_joysticks[id].id] = false;
+ d_joysticks[id].guid.Data1 = d_joysticks[id].guid.Data2 = d_joysticks[id].guid.Data3 = 0;
+ input->joy_connection_changed(id, false, "");
+ joystick_count--;
+}
+
+void joystick_windows::probe_joysticks() {
+
+ DWORD dwResult;
+ for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) {
+
+ ZeroMemory(&x_joysticks[i].state, sizeof(XINPUT_STATE));
+
+ dwResult = xinput_get_state(i, &x_joysticks[i].state);
+ if ( dwResult == ERROR_SUCCESS) {
+
+ int id = check_free_joy_slot();
+ if (id != -1 && !x_joysticks[i].attached) {
+
+ x_joysticks[i].attached = true;
+ x_joysticks[i].id = id;
+ attached_joysticks[id] = true;
+ input->joy_connection_changed(id, true, "XInput Gamepad","__XINPUT_DEVICE__");
+ }
+ }
+ else if (x_joysticks[i].attached) {
+
+ x_joysticks[i].attached = false;
+ attached_joysticks[x_joysticks[i].id] = false;
+ input->joy_connection_changed(x_joysticks[i].id, false, "");
+ }
+ }
+
+ for (int i = 0; i < joystick_count; i++) {
+
+ d_joysticks[i].confirmed = false;
+ }
+
+ dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, this, DIEDFL_ATTACHEDONLY);
+
+ for (int i = 0; i < joystick_count; i++) {
+
+ if (!d_joysticks[i].confirmed) {
+
+ close_joystick(i);
+ }
+ }
+}
+
+unsigned int joystick_windows::process_joysticks(unsigned int p_last_id) {
+
+ HRESULT hr;
+
+ for (int i = 0; i < XUSER_MAX_COUNT; i++) {
+
+ xinput_gamepad &joy = x_joysticks[i];
+ if (!joy.attached) {
+ continue;
+ }
+ ZeroMemory(&joy.state, sizeof(XINPUT_STATE));
+
+ xinput_get_state(i, &joy.state);
+ if (joy.state.dwPacketNumber != joy.last_packet) {
+
+ int button_mask = XINPUT_GAMEPAD_DPAD_UP;
+ for (int i = 0; i <= 16; i++) {
+
+ p_last_id = input->joy_button(p_last_id, joy.id, i, joy.state.Gamepad.wButtons & button_mask);
+ button_mask = button_mask * 2;
+ }
+
+ p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_0, axis_correct(joy.state.Gamepad.sThumbLX, true));
+ p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_1, axis_correct(joy.state.Gamepad.sThumbLY, true, false, true));
+ p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_2, axis_correct(joy.state.Gamepad.sThumbRX, true));
+ p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_3, axis_correct(joy.state.Gamepad.sThumbRY, true, false, true));
+ p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_4, axis_correct(joy.state.Gamepad.bLeftTrigger, true, true));
+ p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_5, axis_correct(joy.state.Gamepad.bRightTrigger, true, true));
+ joy.last_packet = joy.state.dwPacketNumber;
+ }
+ }
+
+ for (int i = 0; i < JOYSTICKS_MAX; i++) {
+
+ dinput_gamepad* joy = &d_joysticks[i];
+
+ if (!joy->attached)
+ continue;
+
+ DIJOYSTATE2 js;
+ hr = joy->di_joy->Poll();
+ if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) {
+ IDirectInputDevice8_Acquire(joy->di_joy);
+ joy->di_joy->Poll();
+ }
+ if (FAILED(hr = joy->di_joy->GetDeviceState(sizeof(DIJOYSTATE2), &js))) {
+
+ //printf("failed to read joy #%d\n", i);
+ continue;
+ }
+
+ p_last_id = post_hat(p_last_id, joy->id, js.rgdwPOV[0]);
+
+ for (int j = 0; j < 128; j++) {
+
+ if (js.rgbButtons[j] & 0x80) {
+
+ if (!joy->last_buttons[j]) {
+
+ p_last_id = input->joy_button(p_last_id, joy->id, j, true);
+ joy->last_buttons[j] = true;
+ }
+ }
+ else {
+
+ if (joy->last_buttons[j]) {
+
+ p_last_id = input->joy_button(p_last_id, joy->id, j, false);
+ joy->last_buttons[j] = false;
+ }
+ }
+ }
+
+ // on mingw, these constants are not constants
+ int count = 6;
+ int axes[] = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z, DIJOFS_RX, DIJOFS_RY, DIJOFS_RZ };
+ int values[] = { js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz };
+
+ for (int j = 0; j < joy->joy_axis.size(); j++) {
+
+ for (int k=0; k<count; k++) {
+ if (joy->joy_axis[j] == axes[k]) {
+ p_last_id = input->joy_axis(p_last_id, joy->id, j, axis_correct(values[k]));
+ break;
+ };
+ };
+ };
+ }
+ return p_last_id;
+}
+
+unsigned int joystick_windows::post_hat(unsigned int p_last_id, int p_device, DWORD p_dpad) {
+
+ int dpad_val = 0;
+
+ if (p_dpad == -1) {
+ dpad_val = InputDefault::HAT_MASK_CENTER;
+ }
+ if (p_dpad == 0) {
+
+ dpad_val = InputDefault::HAT_MASK_UP;
+
+ }
+ else if (p_dpad == 4500) {
+
+ dpad_val = (InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_RIGHT);
+
+ }
+ else if (p_dpad == 9000) {
+
+ dpad_val = InputDefault::HAT_MASK_RIGHT;
+
+ }
+ else if (p_dpad == 13500) {
+
+ dpad_val = (InputDefault::HAT_MASK_RIGHT | InputDefault::HAT_MASK_DOWN);
+
+ }
+ else if (p_dpad == 18000) {
+
+ dpad_val = InputDefault::HAT_MASK_DOWN;
+
+ }
+ else if (p_dpad == 22500) {
+
+ dpad_val = (InputDefault::HAT_MASK_DOWN | InputDefault::HAT_MASK_LEFT);
+
+ }
+ else if (p_dpad == 27000) {
+
+ dpad_val = InputDefault::HAT_MASK_LEFT;
+
+ }
+ else if (p_dpad == 31500) {
+
+ dpad_val = (InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_UP);
+ }
+ return input->joy_hat(p_last_id, p_device, dpad_val);
+};
+
+InputDefault::JoyAxis joystick_windows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const {
+
+ InputDefault::JoyAxis jx;
+ if (Math::abs(p_val) < MIN_JOY_AXIS) {
+ jx.min = -1;
+ jx.value = 0.0f;
+ return jx;
+ }
+ if (p_xinput) {
+
+ if (p_trigger) {
+ jx.min = 0;
+ jx.value = (float)p_val / MAX_TRIGGER;
+ return jx;
+ }
+ jx.min = -1;
+ if (p_val < 0) {
+ jx.value = (float)p_val / MAX_JOY_AXIS;
+ }
+ else {
+ jx.value = (float)p_val / (MAX_JOY_AXIS - 1);
+ }
+ if (p_negate) {
+ jx.value = -jx.value;
+ }
+ return jx;
+ }
+ jx.min = -1;
+ jx.value = (float)p_val / MAX_JOY_AXIS;
+ return jx;
+}
+
+void joystick_windows::load_xinput() {
+
+ xinput_get_state = &_xinput_get_state;
+ xinput_dll = LoadLibrary( "XInput1_4.dll" );
+ if (!xinput_dll) {
+ xinput_dll = LoadLibrary("XInput1_3.dll");
+ if (!xinput_dll) {
+ xinput_dll = LoadLibrary("XInput9_1_0.dll");
+ }
+ }
+
+ if (!xinput_dll) {
+ if (OS::get_singleton()->is_stdout_verbose()) {
+ print_line("Could not find XInput, using DirectInput only");
+ }
+ return;
+ }
+
+ XInputGetState_t func = (XInputGetState_t)GetProcAddress((HMODULE)xinput_dll, "XInputGetState");
+ if (!func) {
+ unload_xinput();
+ return;
+ }
+ xinput_get_state = func;
+ return;
+}
+
+void joystick_windows::unload_xinput() {
+
+ if (xinput_dll) {
+
+ FreeLibrary((HMODULE)xinput_dll);
+ }
+}
diff --git a/platform/windows/joystick.h b/platform/windows/joystick.h
new file mode 100644
index 0000000000..332e86fbb8
--- /dev/null
+++ b/platform/windows/joystick.h
@@ -0,0 +1,142 @@
+/*************************************************************************/
+/* joystick.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. */
+/*************************************************************************/
+//author: Andreas Haas <hondres, liugam3@gmail.com>
+#ifndef JOYSTICK_H
+#define JOYSTICK_H
+
+#include "os_windows.h"
+#define DIRECTINPUT_VERSION 0x0800
+#include <dinput.h>
+#include <xinput.h> // on unix the file is called "xinput.h", on windows I'm sure it won't mind
+
+#ifndef SAFE_RELEASE // when Windows Media Device M? is not present
+#define SAFE_RELEASE(x) \
+if(x != NULL) \
+{ \
+ x->Release(); \
+ x = NULL; \
+}
+#endif
+
+#ifndef XUSER_MAX_COUNT
+#define XUSER_MAX_COUNT 4
+#endif
+
+class joystick_windows
+{
+public:
+ joystick_windows();
+ joystick_windows(InputDefault* _input, HWND* hwnd);
+ ~joystick_windows();
+
+ void probe_joysticks();
+ unsigned int process_joysticks(unsigned int p_last_id);
+private:
+
+ enum {
+ JOYSTICKS_MAX = 16,
+ JOY_AXIS_COUNT = 6,
+ MIN_JOY_AXIS = 10,
+ MAX_JOY_AXIS = 32768,
+ MAX_JOY_BUTTONS = 128,
+ KEY_EVENT_BUFFER_SIZE = 512,
+ MAX_TRIGGER = 255
+ };
+
+ struct dinput_gamepad {
+
+ int id;
+ bool attached;
+ bool confirmed;
+ bool last_buttons[MAX_JOY_BUTTONS];
+ DWORD last_pad;
+
+ LPDIRECTINPUTDEVICE8 di_joy;
+ List<DWORD> joy_axis;
+ GUID guid;
+
+ dinput_gamepad() {
+ id = -1;
+ last_pad = -1;
+ attached = false;
+ confirmed = false;
+
+ for (int i = 0; i < MAX_JOY_BUTTONS; i++)
+ last_buttons[i] = false;
+ }
+ };
+
+ struct xinput_gamepad {
+
+ int id;
+ bool attached;
+ DWORD last_packet;
+ XINPUT_STATE state;
+
+ xinput_gamepad() {
+ attached = false;
+ last_packet = 0;
+ }
+ };
+
+ typedef DWORD (WINAPI *XInputGetState_t) (DWORD dwUserIndex, XINPUT_STATE* pState);
+
+ HWND* hWnd;
+ HANDLE xinput_dll;
+ LPDIRECTINPUT8 dinput;
+ InputDefault* input;
+
+ int id_to_change;
+ int joystick_count;
+ bool attached_joysticks[JOYSTICKS_MAX];
+ dinput_gamepad d_joysticks[JOYSTICKS_MAX];
+ xinput_gamepad x_joysticks[XUSER_MAX_COUNT];
+
+ static BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* p_instance, void* p_context);
+ static BOOL CALLBACK objectsCallback(const DIDEVICEOBJECTINSTANCE* instance, void* context);
+
+ void setup_joystick_object(const DIDEVICEOBJECTINSTANCE* ob, int p_joy_id);
+ void close_joystick(int id = -1);
+ void load_xinput();
+ void unload_xinput();
+
+ int check_free_joy_slot() const;
+ unsigned int post_hat(unsigned int p_last_id, int p_device, DWORD p_dpad);
+
+ bool have_device(const GUID &p_guid);
+ bool is_xinput_device(const GUID* p_guid);
+ bool setup_dinput_joystick(const DIDEVICEINSTANCE* instance);
+
+ InputDefault::JoyAxis axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const;
+ XInputGetState_t xinput_get_state;
+};
+
+#endif
+
+
diff --git a/platform/windows/key_mapping_win.cpp b/platform/windows/key_mapping_win.cpp
index f07b7c6eaa..07d5f32253 100644
--- a/platform/windows/key_mapping_win.cpp
+++ b/platform/windows/key_mapping_win.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/key_mapping_win.h b/platform/windows/key_mapping_win.h
index 288fcdd8de..da649d0115 100644
--- a/platform/windows/key_mapping_win.h
+++ b/platform/windows/key_mapping_win.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/lang_table.h b/platform/windows/lang_table.h
index bfdf2b6ebe..c9551b2d38 100644
--- a/platform/windows/lang_table.h
+++ b/platform/windows/lang_table.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 438a5a6903..95bfa2ea94 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* 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 */
@@ -52,6 +52,7 @@
#include "os/memory_pool_dynamic_prealloc.h"
#include "globals.h"
#include "io/marshalls.h"
+#include "joystick.h"
#include "shlobj.h"
#include <regstr.h>
@@ -148,7 +149,7 @@ const char * OS_Windows::get_video_driver_name(int p_driver) const {
OS::VideoMode OS_Windows::get_default_video_mode() const {
- return VideoMode(800,600,false);
+ return VideoMode(1280,720,false);
}
int OS_Windows::get_audio_driver_count() const {
@@ -682,6 +683,10 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) {
} break;
#endif
+ case WM_DEVICECHANGE: {
+
+ joystick->probe_joysticks();
+ } break;
default: {
@@ -706,108 +711,6 @@ LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) {
}
-
-String OS_Windows::get_joystick_name(int id, JOYCAPS jcaps)
-{
- char buffer [256];
- char OEM [256];
- HKEY hKey;
- DWORD sz;
- int res;
-
- _snprintf(buffer, sizeof(buffer), "%s\\%s\\%s",
- REGSTR_PATH_JOYCONFIG, jcaps.szRegKey,
- REGSTR_KEY_JOYCURR );
- res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey);
- if (res != ERROR_SUCCESS)
- {
- res = RegOpenKeyEx(HKEY_CURRENT_USER, buffer, 0, KEY_QUERY_VALUE, &hKey);
- if (res != ERROR_SUCCESS)
- return "";
- }
-
- sz = sizeof(OEM);
- _snprintf( buffer, sizeof(buffer), "Joystick%d%s", id + 1, REGSTR_VAL_JOYOEMNAME);
- res = RegQueryValueEx ( hKey, buffer, 0, 0, (LPBYTE) OEM, &sz);
- RegCloseKey ( hKey );
- if (res != ERROR_SUCCESS)
- return "";
-
- _snprintf( buffer, sizeof(buffer), "%s\\%s", REGSTR_PATH_JOYOEM, OEM);
- res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey);
- if (res != ERROR_SUCCESS)
- {
- res = RegOpenKeyEx(HKEY_CURRENT_USER, buffer, 0, KEY_QUERY_VALUE, &hKey);
- if (res != ERROR_SUCCESS)
- return "";
- }
-
-
- sz = sizeof(buffer);
- res = RegQueryValueEx(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, (LPBYTE) buffer,
- &sz);
- RegCloseKey(hKey);
- if (res != ERROR_SUCCESS)
- return "";
-
- return String(buffer);
-}
-
-void OS_Windows::probe_joysticks() {
-
- static uint32_t last_attached = 0;
-
- int device_count = joyGetNumDevs();
-
- JOYINFOEX jinfo;
- jinfo.dwSize = sizeof(JOYINFOEX);
- jinfo.dwFlags = JOY_RETURNALL;
-
- for (int i=0; i<JOYSTICKS_MAX; i++) {
-
- Joystick joy;
- joy.id = i;
- joy.attached = (device_count > 0) && (joyGetPosEx(JOYSTICKID1 + i, &jinfo) == JOYERR_NOERROR);
-
- if (joy.attached == (last_attached & (1 << i) != 0)) {
- continue;
- };
-
- // there's been a change since last call
-
- if (joy.attached)
- last_attached = last_attached | (1 << i);
- else
- last_attached &= ~(1 << i);
-
- if (joy.attached) {
-
- joy.last_buttons = jinfo.dwButtons;
-
- joy.last_axis[0] = jinfo.dwXpos;
- joy.last_axis[1] = jinfo.dwYpos;
- joy.last_axis[2] = jinfo.dwZpos;
- joy.last_axis[3] = jinfo.dwRpos;
- joy.last_axis[4] = jinfo.dwUpos;
- joy.last_axis[5] = jinfo.dwVpos;
-
- JOYCAPS jcaps;
- MMRESULT res = joyGetDevCaps(JOYSTICKID1 + i, &jcaps, sizeof(jcaps));
- if (res == JOYERR_NOERROR) {
- String name = get_joystick_name(JOYSTICKID1 + i, jcaps);
- if ( name == "")
- joy.name = jcaps.szPname;
- else
- joy.name = name;
-
-
- };
- };
-
- joystick_change_queue.push_back(joy);
- };
-};
-
void OS_Windows::process_key_events() {
for(int i=0;i<key_event_pos;i++) {
@@ -879,154 +782,6 @@ void OS_Windows::process_key_events() {
key_event_pos=0;
}
-void OS_Windows::_post_dpad(DWORD p_dpad, int p_device, bool p_pressed) {
-
- InputEvent ievent;
- ievent.device = p_device;
- ievent.type = InputEvent::JOYSTICK_BUTTON;
- ievent.joy_button.pressed = p_pressed;
- ievent.joy_button.pressure = p_pressed ? 1.0 : 0.0;
-
- if (p_dpad == 0) {
-
- ievent.joy_button.button_index = JOY_DPAD_UP;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- } else if (p_dpad == 4500) {
-
- ievent.joy_button.button_index = JOY_DPAD_UP;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- ievent.joy_button.button_index = JOY_DPAD_RIGHT;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- } else if (p_dpad == 9000) {
-
- ievent.joy_button.button_index = JOY_DPAD_RIGHT;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- } else if (p_dpad == 13500) {
-
- ievent.joy_button.button_index = JOY_DPAD_RIGHT;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- ievent.joy_button.button_index = JOY_DPAD_DOWN;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- } else if (p_dpad == 18000) {
-
- ievent.joy_button.button_index = JOY_DPAD_DOWN;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- } else if (p_dpad == 22500) {
-
- ievent.joy_button.button_index = JOY_DPAD_DOWN;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- ievent.joy_button.button_index = JOY_DPAD_LEFT;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- } else if (p_dpad == 27000) {
-
- ievent.joy_button.button_index = JOY_DPAD_LEFT;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- } else if (p_dpad == 31500) {
-
- ievent.joy_button.button_index = JOY_DPAD_LEFT;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
-
- ievent.joy_button.button_index = JOY_DPAD_UP;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
- };
-};
-
-void OS_Windows::process_joysticks() {
-
- if (!main_loop) {
- return;
- };
-
- InputEvent ievent;
-
- JOYINFOEX jinfo;
- jinfo.dwSize = sizeof(JOYINFOEX);
- jinfo.dwFlags = JOY_RETURNALL;
-
- for (int i=0; i<JOYSTICKS_MAX; i++) {
-
- if (!joysticks[i].attached) {
- continue;
- };
-
- if (joyGetPosEx(JOYSTICKID1 + i, &jinfo) != JOYERR_NOERROR) {
-
- continue;
- };
-
- ievent.device = i;
-
- #define CHECK_AXIS(n, var) \
- if (joysticks[i].last_axis[n] != var) {\
- ievent.type = InputEvent::JOYSTICK_MOTION;\
- ievent.ID = ++last_id;\
- ievent.joy_motion.axis = n;\
- ievent.joy_motion.axis_value = (float)((int)var - MAX_JOY_AXIS) / (float)MAX_JOY_AXIS;\
- joysticks[i].last_axis[n] = var;\
- input->parse_input_event(ievent);\
- };
-
- CHECK_AXIS(0, jinfo.dwXpos);
- CHECK_AXIS(1, jinfo.dwYpos);
- CHECK_AXIS(2, jinfo.dwZpos);
- CHECK_AXIS(3, jinfo.dwRpos);
- CHECK_AXIS(4, jinfo.dwUpos);
- CHECK_AXIS(5, jinfo.dwVpos);
-
- if (joysticks[i].last_pov != jinfo.dwPOV) {
-
- if (joysticks[i].last_pov != JOY_POVCENTERED)
- _post_dpad(joysticks[i].last_pov, i, false);
-
- if (jinfo.dwPOV != JOY_POVCENTERED)
- _post_dpad(jinfo.dwPOV, i, true);
-
- joysticks[i].last_pov = jinfo.dwPOV;
- };
-
- if (joysticks[i].last_buttons == jinfo.dwButtons) {
- continue;
- };
-
- ievent.type = InputEvent::JOYSTICK_BUTTON;
- for (int j=0; j<32; j++) {
-
- if ( (joysticks[i].last_buttons & (1<<j)) != (jinfo.dwButtons & (1<<j)) ) {
-
- ievent.joy_button.button_index = j; //_pc_joystick_get_native_button(j);
- ievent.joy_button.pressed = jinfo.dwButtons & 1<<j;
- ievent.ID = ++last_id;
- input->parse_input_event(ievent);
- };
- };
-
- joysticks[i].last_buttons = jinfo.dwButtons;
- };
-};
-
-
BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
OS_Windows *self=(OS_Windows*)OS::get_singleton();
MonitorInfo minfo;
@@ -1213,6 +968,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_
visual_server->init();
input = memnew( InputDefault );
+ joystick = memnew (joystick_windows(input, &hWnd));
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton();
@@ -1231,14 +987,6 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_
spatial_sound_2d_server = memnew( SpatialSound2DServerSW );
spatial_sound_2d_server->init();
- probe_joysticks(); // todo: move this to a thread
- while (joystick_change_queue.size() > 0) {
- Joystick joy = joystick_change_queue.front()->get();
- joystick_change_queue.pop_front();
- joysticks[joy.id] = joy;
- input->joy_connection_changed(joy.id, joy.attached, joy.name);
- };
-
TRACKMOUSEEVENT tme;
tme.cbSize=sizeof(TRACKMOUSEEVENT);
tme.dwFlags=TME_LEAVE;
@@ -1350,7 +1098,10 @@ void OS_Windows::finalize() {
memdelete(main_loop);
main_loop=NULL;
-
+
+ memdelete(joystick);
+ memdelete(input);
+
visual_server->finish();
memdelete(visual_server);
#ifdef OPENGL_ENABLED
@@ -1373,11 +1124,10 @@ void OS_Windows::finalize() {
// memdelete(debugger_connection_console);
//}
- audio_server->finish();
- memdelete(audio_server);
memdelete(sample_manager);
- memdelete(input);
+ audio_server->finish();
+ memdelete(audio_server);
physics_server->finish();
memdelete(physics_server);
@@ -1385,7 +1135,6 @@ void OS_Windows::finalize() {
physics_2d_server->finish();
memdelete(physics_2d_server);
- joystick_change_queue.clear();
monitor_info.clear();
}
@@ -1764,73 +1513,96 @@ bool OS_Windows::is_window_maximized() const{
}
-void OS_Windows::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) {
-
- HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
- if (!hCon || hCon==INVALID_HANDLE_VALUE) {
- if (p_rationale && p_rationale[0]) {
+void OS_Windows::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) {
- print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale);
- print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
+ HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (!hCon || hCon == INVALID_HANDLE_VALUE) {
- } else {
- print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code);
- print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
+ const char* err_details;
+ if (p_rationale && p_rationale[0])
+ err_details = p_rationale;
+ else
+ err_details = p_code;
+ switch(p_type) {
+ case ERR_ERROR:
+ print("ERROR: %s: %s\n", p_function, err_details);
+ print(" At: %s:%i\n", p_file, p_line);
+ break;
+ case ERR_WARNING:
+ print("WARNING: %s: %s\n", p_function, err_details);
+ print(" At: %s:%i\n", p_file, p_line);
+ break;
+ case ERR_SCRIPT:
+ print("SCRIPT ERROR: %s: %s\n", p_function, err_details);
+ print(" At: %s:%i\n", p_file, p_line);
+ break;
}
+
} else {
CONSOLE_SCREEN_BUFFER_INFO sbi; //original
- GetConsoleScreenBufferInfo(hCon,&sbi);
-
- SetConsoleTextAttribute(hCon,sbi.wAttributes);
+ GetConsoleScreenBufferInfo(hCon, &sbi);
+ WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
+ WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
-
- uint32_t basecol=0;
+ uint32_t basecol = 0;
switch(p_type) {
case ERR_ERROR: basecol = FOREGROUND_RED; break;
- case ERR_WARNING: basecol = FOREGROUND_RED|FOREGROUND_GREEN; break;
- case ERR_SCRIPT: basecol = FOREGROUND_GREEN; break;
+ case ERR_WARNING: basecol = FOREGROUND_RED | FOREGROUND_GREEN; break;
+ case ERR_SCRIPT: basecol = FOREGROUND_RED | FOREGROUND_BLUE; break;
}
- if (p_rationale && p_rationale[0]) {
-
- SetConsoleTextAttribute(hCon,basecol|FOREGROUND_INTENSITY);
+ basecol |= current_bg;
+ if (p_rationale && p_rationale[0]) {
+ SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
switch(p_type) {
case ERR_ERROR: print("ERROR: "); break;
case ERR_WARNING: print("WARNING: "); break;
case ERR_SCRIPT: print("SCRIPT ERROR: "); break;
}
- SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
- print(" %s\n",p_rationale);
- SetConsoleTextAttribute(hCon,basecol);
- print("At: ");
- SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
- print(" %s:%i\n",p_file,p_line);
+ SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
+ print("%s\n", p_rationale);
+
+ SetConsoleTextAttribute(hCon, basecol);
+ switch (p_type) {
+ case ERR_ERROR: print(" At: "); break;
+ case ERR_WARNING: print(" At: "); break;
+ case ERR_SCRIPT: print(" At: "); break;
+ }
+ SetConsoleTextAttribute(hCon, current_fg | current_bg);
+ print("%s:%i\n", p_file, p_line);
} else {
- SetConsoleTextAttribute(hCon,basecol|FOREGROUND_INTENSITY);
+
+ SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
switch(p_type) {
- case ERR_ERROR: print("ERROR: %s: ",p_function); break;
- case ERR_WARNING: print("WARNING: %s: ",p_function); break;
- case ERR_SCRIPT: print("SCRIPT ERROR: %s: ",p_function); break;
+ case ERR_ERROR: print("ERROR: %s: ", p_function); break;
+ case ERR_WARNING: print("WARNING: %s: ", p_function); break;
+ case ERR_SCRIPT: print("SCRIPT ERROR: %s: ", p_function); break;
}
- SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
- print(" %s\n",p_code);
- SetConsoleTextAttribute(hCon,basecol);
- print("At: ");
- SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
- print(" %s:%i\n",p_file,p_line);
+
+ SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
+ print("%s\n", p_code);
+
+ SetConsoleTextAttribute(hCon, basecol);
+ switch (p_type) {
+ case ERR_ERROR: print(" At: "); break;
+ case ERR_WARNING: print(" At: "); break;
+ case ERR_SCRIPT: print(" At: "); break;
+ }
+
+ SetConsoleTextAttribute(hCon, current_fg | current_bg);
+ print("%s:%i\n", p_file, p_line);
}
- SetConsoleTextAttribute(hCon,sbi.wAttributes);
+ SetConsoleTextAttribute(hCon, sbi.wAttributes);
}
-
}
@@ -1943,7 +1715,7 @@ void OS_Windows::process_events() {
MSG msg;
- process_joysticks();
+ last_id = joystick->process_joysticks(last_id);
while(PeekMessageW(&msg,NULL,0,0,PM_REMOVE)) {
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 026b50c33d..dfa2b40595 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
@@ -60,13 +60,11 @@
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+class joystick_windows;
class OS_Windows : public OS {
- enum {
- JOYSTICKS_MAX = 8,
- JOY_AXIS_COUNT = 6,
- MAX_JOY_AXIS = 32768, // I've no idea
- KEY_EVENT_BUFFER_SIZE=512
+ enum {
+ KEY_EVENT_BUFFER_SIZE=512
};
FILE *stdo;
@@ -106,32 +104,6 @@ class OS_Windows : public OS {
HINSTANCE hInstance; // Holds The Instance Of The Application
HWND hWnd;
- struct Joystick {
-
- int id;
- bool attached;
-
- DWORD last_axis[JOY_AXIS_COUNT];
- DWORD last_buttons;
- DWORD last_pov;
- String name;
-
- Joystick() {
- id = -1;
- attached = false;
- for (int i=0; i<JOY_AXIS_COUNT; i++) {
-
- last_axis[i] = 0;
- };
- last_buttons = 0;
- last_pov = 0;
- };
- };
-
- List<Joystick> joystick_change_queue;
- int joystick_count;
- Joystick joysticks[JOYSTICKS_MAX];
-
Size2 window_rect;
VideoMode video_mode;
@@ -156,13 +128,12 @@ class OS_Windows : public OS {
CursorShape cursor_shape;
InputDefault *input;
+ joystick_windows *joystick;
#ifdef RTAUDIO_ENABLED
AudioDriverRtAudio driver_rtaudio;
#endif
- void _post_dpad(DWORD p_dpad, int p_device, bool p_pressed);
-
void _drag_event(int p_x, int p_y, int idx);
void _touch_event(bool p_pressed, int p_x, int p_y, int idx);
@@ -186,11 +157,7 @@ protected:
virtual void finalize_core();
void process_events();
-
- void probe_joysticks();
- void process_joysticks();
void process_key_events();
- String get_joystick_name( int id, JOYCAPS jcaps);
struct ProcessInfo {
diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp
index aff92b8fc8..0ca2d358af 100644
--- a/platform/windows/packet_peer_udp_winsock.cpp
+++ b/platform/windows/packet_peer_udp_winsock.cpp
@@ -121,7 +121,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
struct sockaddr_in from = {0};
int len = sizeof(struct sockaddr_in);
int ret;
- while ( (ret = recvfrom(sockfd, (char*)recv_buffer, MIN(sizeof(recv_buffer),rb.data_left()-12), 0, (struct sockaddr*)&from, &len)) > 0) {
+ while ( (ret = recvfrom(sockfd, (char*)recv_buffer, MIN((int)sizeof(recv_buffer),MAX(rb.space_left()-12, 0)), 0, (struct sockaddr*)&from, &len)) > 0) {
rb.write((uint8_t*)&from.sin_addr, 4);
uint32_t port = ntohs(from.sin_port);
rb.write((uint8_t*)&port, 4);
@@ -132,8 +132,25 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
++queue_count;
};
+ if (ret == SOCKET_ERROR){
+ int error = WSAGetLastError();
+
+ if (error == WSAEWOULDBLOCK){
+ // Expected when doing non-blocking sockets, retry later.
+ }
+ else if (error == WSAECONNRESET){
+ // If the remote target does not accept messages, this error may occur, but is harmless.
+ // Once the remote target gets available, this message will disappear for new messages.
+ }
+ else
+ {
+ close();
+ return FAILED;
+ }
+ }
+
- if (ret == 0 || (ret == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) ) {
+ if (ret == 0) {
close();
return FAILED;
};
diff --git a/platform/windows/platform_config.h b/platform/windows/platform_config.h
index e6b561552e..55f6b5547e 100644
--- a/platform/windows/platform_config.h
+++ b/platform/windows/platform_config.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp
index e8245c92e5..fcf0cb1640 100644
--- a/platform/windows/stream_peer_winsock.cpp
+++ b/platform/windows/stream_peer_winsock.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
@@ -342,6 +342,14 @@ void StreamPeerWinsock::set_nodelay(bool p_enabled) {
setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));
}
+int StreamPeerWinsock::get_available_bytes() const {
+
+ unsigned long len;
+ int ret = ioctlsocket(sockfd,FIONREAD,&len);
+ ERR_FAIL_COND_V(ret==-1,0)
+ return len;
+
+}
IP_Address StreamPeerWinsock::get_connected_host() const {
diff --git a/platform/windows/stream_peer_winsock.h b/platform/windows/stream_peer_winsock.h
index 373b502d2c..bbff661490 100644
--- a/platform/windows/stream_peer_winsock.h
+++ b/platform/windows/stream_peer_winsock.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
@@ -66,6 +66,8 @@ public:
virtual Error get_data(uint8_t* p_buffer, int p_bytes);
virtual Error get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received);
+ virtual int get_available_bytes() const;
+
void set_socket(int p_sockfd, IP_Address p_host, int p_port);
virtual IP_Address get_connected_host() const;
diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp
index cc689d9dcf..dd1cf43f3b 100644
--- a/platform/windows/tcp_server_winsock.cpp
+++ b/platform/windows/tcp_server_winsock.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */
diff --git a/platform/windows/tcp_server_winsock.h b/platform/windows/tcp_server_winsock.h
index 2516123908..bd6a05c74d 100644
--- a/platform/windows/tcp_server_winsock.h
+++ b/platform/windows/tcp_server_winsock.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* 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 */