diff options
Diffstat (limited to 'platform/windows')
22 files changed, 1763 insertions, 757 deletions
diff --git a/platform/windows/SCsub b/platform/windows/SCsub index a77428e954..1fa793e2de 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -11,4 +11,16 @@ common_win=[ "stream_peer_winsock.cpp", ] +env.RES('godot_res.rc') +if env["is_mingw"]: + common_win.append("godot_res.o") +else: + common_win.append("godot_res.res") + env.Program('#bin/godot',['godot_win.cpp']+common_win,PROGSUFFIX=env["PROGSUFFIX"]) + +# 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: + env.vs_srcs = env.vs_srcs + ["platform/windows/" + x] diff --git a/platform/windows/context_gl_win.cpp b/platform/windows/context_gl_win.cpp index a8f74fde2c..5a9c8edc63 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-2014 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 */ diff --git a/platform/windows/context_gl_win.h b/platform/windows/context_gl_win.h index 6e8d99a5f0..5397676c8e 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-2014 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 */ diff --git a/platform/windows/ctxgl_procaddr.cpp b/platform/windows/ctxgl_procaddr.cpp index 9715784c32..6e5f53eb96 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-2014 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,161 +26,161 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef OPENGL_ENABLED
-#include "ctxgl_procaddr.h"
-#include <GL/gl.h>
-#include <stdio.h>
-
-static PROC _gl_procs[]={
- (PROC)glCullFace,
- (PROC)glFrontFace,
- (PROC)glHint,
- (PROC)glLineWidth,
- (PROC)glPointSize,
- (PROC)glPolygonMode,
- (PROC)glScissor,
- (PROC)glTexParameterf,
- (PROC)glTexParameterfv,
- (PROC)glTexParameteri,
- (PROC)glTexParameteriv,
- (PROC)glTexImage1D,
- (PROC)glTexImage2D,
- (PROC)glDrawBuffer,
- (PROC)glClear,
- (PROC)glClearColor,
- (PROC)glClearStencil,
- (PROC)glClearDepth,
- (PROC)glStencilMask,
- (PROC)glColorMask,
- (PROC)glDepthMask,
- (PROC)glDisable,
- (PROC)glEnable,
- (PROC)glFinish,
- (PROC)glFlush,
- (PROC)glBlendFunc,
- (PROC)glLogicOp,
- (PROC)glStencilFunc,
- (PROC)glStencilOp,
- (PROC)glDepthFunc,
- (PROC)glPixelStoref,
- (PROC)glPixelStorei,
- (PROC)glReadBuffer,
- (PROC)glReadPixels,
- (PROC)glGetBooleanv,
- (PROC)glGetDoublev,
- (PROC)glGetError,
- (PROC)glGetFloatv,
- (PROC)glGetIntegerv,
- (PROC)glGetString,
- (PROC)glGetTexImage,
- (PROC)glGetTexParameterfv,
- (PROC)glGetTexParameteriv,
- (PROC)glGetTexLevelParameterfv,
- (PROC)glGetTexLevelParameteriv,
- (PROC)glIsEnabled,
- (PROC)glDepthRange,
- (PROC)glViewport,
- /* not detected in ATI */
- (PROC)glDrawArrays,
- (PROC)glDrawElements,
- (PROC)glGetPointerv,
- (PROC)glPolygonOffset,
- (PROC)glCopyTexImage1D,
- (PROC)glCopyTexImage2D,
- (PROC)glCopyTexSubImage1D,
- (PROC)glCopyTexSubImage2D,
- (PROC)glTexSubImage1D,
- (PROC)glTexSubImage2D,
- (PROC)glBindTexture,
- (PROC)glDeleteTextures,
- (PROC)glGenTextures,
- (PROC)glIsTexture,
-
- 0
-};
-
-static const char* _gl_proc_names[]={
- "glCullFace",
- "glFrontFace",
- "glHint",
- "glLineWidth",
- "glPointSize",
- "glPolygonMode",
- "glScissor",
- "glTexParameterf",
- "glTexParameterfv",
- "glTexParameteri",
- "glTexParameteriv",
- "glTexImage1D",
- "glTexImage2D",
- "glDrawBuffer",
- "glClear",
- "glClearColor",
- "glClearStencil",
- "glClearDepth",
- "glStencilMask",
- "glColorMask",
- "glDepthMask",
- "glDisable",
- "glEnable",
- "glFinish",
- "glFlush",
- "glBlendFunc",
- "glLogicOp",
- "glStencilFunc",
- "glStencilOp",
- "glDepthFunc",
- "glPixelStoref",
- "glPixelStorei",
- "glReadBuffer",
- "glReadPixels",
- "glGetBooleanv",
- "glGetDoublev",
- "glGetError",
- "glGetFloatv",
- "glGetIntegerv",
- "glGetString",
- "glGetTexImage",
- "glGetTexParameterfv",
- "glGetTexParameteriv",
- "glGetTexLevelParameterfv",
- "glGetTexLevelParameteriv",
- "glIsEnabled",
- "glDepthRange",
- "glViewport",
- /* not detected in ati */
- "glDrawArrays",
- "glDrawElements",
- "glGetPointerv",
- "glPolygonOffset",
- "glCopyTexImage1D",
- "glCopyTexImage2D",
- "glCopyTexSubImage1D",
- "glCopyTexSubImage2D",
- "glTexSubImage1D",
- "glTexSubImage2D",
- "glBindTexture",
- "glDeleteTextures",
- "glGenTextures",
- "glIsTexture",
-
- 0
-};
-
-PROC get_gl_proc_address(const char* p_address) {
-
- PROC proc = wglGetProcAddress((const CHAR*)p_address);
- if (!proc) {
-
- int i=0;
- while(_gl_procs[i]) {
-
- if (strcmp(p_address,_gl_proc_names[i])==0) {
- return _gl_procs[i];
- }
- i++;
- }
- }
- return proc;
-}
-#endif
+#ifdef OPENGL_ENABLED +#include "ctxgl_procaddr.h" +#include <GL/gl.h> +#include <stdio.h> + +static PROC _gl_procs[]={ + (PROC)glCullFace, + (PROC)glFrontFace, + (PROC)glHint, + (PROC)glLineWidth, + (PROC)glPointSize, + (PROC)glPolygonMode, + (PROC)glScissor, + (PROC)glTexParameterf, + (PROC)glTexParameterfv, + (PROC)glTexParameteri, + (PROC)glTexParameteriv, + (PROC)glTexImage1D, + (PROC)glTexImage2D, + (PROC)glDrawBuffer, + (PROC)glClear, + (PROC)glClearColor, + (PROC)glClearStencil, + (PROC)glClearDepth, + (PROC)glStencilMask, + (PROC)glColorMask, + (PROC)glDepthMask, + (PROC)glDisable, + (PROC)glEnable, + (PROC)glFinish, + (PROC)glFlush, + (PROC)glBlendFunc, + (PROC)glLogicOp, + (PROC)glStencilFunc, + (PROC)glStencilOp, + (PROC)glDepthFunc, + (PROC)glPixelStoref, + (PROC)glPixelStorei, + (PROC)glReadBuffer, + (PROC)glReadPixels, + (PROC)glGetBooleanv, + (PROC)glGetDoublev, + (PROC)glGetError, + (PROC)glGetFloatv, + (PROC)glGetIntegerv, + (PROC)glGetString, + (PROC)glGetTexImage, + (PROC)glGetTexParameterfv, + (PROC)glGetTexParameteriv, + (PROC)glGetTexLevelParameterfv, + (PROC)glGetTexLevelParameteriv, + (PROC)glIsEnabled, + (PROC)glDepthRange, + (PROC)glViewport, + /* not detected in ATI */ + (PROC)glDrawArrays, + (PROC)glDrawElements, + (PROC)glGetPointerv, + (PROC)glPolygonOffset, + (PROC)glCopyTexImage1D, + (PROC)glCopyTexImage2D, + (PROC)glCopyTexSubImage1D, + (PROC)glCopyTexSubImage2D, + (PROC)glTexSubImage1D, + (PROC)glTexSubImage2D, + (PROC)glBindTexture, + (PROC)glDeleteTextures, + (PROC)glGenTextures, + (PROC)glIsTexture, + + 0 +}; + +static const char* _gl_proc_names[]={ + "glCullFace", + "glFrontFace", + "glHint", + "glLineWidth", + "glPointSize", + "glPolygonMode", + "glScissor", + "glTexParameterf", + "glTexParameterfv", + "glTexParameteri", + "glTexParameteriv", + "glTexImage1D", + "glTexImage2D", + "glDrawBuffer", + "glClear", + "glClearColor", + "glClearStencil", + "glClearDepth", + "glStencilMask", + "glColorMask", + "glDepthMask", + "glDisable", + "glEnable", + "glFinish", + "glFlush", + "glBlendFunc", + "glLogicOp", + "glStencilFunc", + "glStencilOp", + "glDepthFunc", + "glPixelStoref", + "glPixelStorei", + "glReadBuffer", + "glReadPixels", + "glGetBooleanv", + "glGetDoublev", + "glGetError", + "glGetFloatv", + "glGetIntegerv", + "glGetString", + "glGetTexImage", + "glGetTexParameterfv", + "glGetTexParameteriv", + "glGetTexLevelParameterfv", + "glGetTexLevelParameteriv", + "glIsEnabled", + "glDepthRange", + "glViewport", + /* not detected in ati */ + "glDrawArrays", + "glDrawElements", + "glGetPointerv", + "glPolygonOffset", + "glCopyTexImage1D", + "glCopyTexImage2D", + "glCopyTexSubImage1D", + "glCopyTexSubImage2D", + "glTexSubImage1D", + "glTexSubImage2D", + "glBindTexture", + "glDeleteTextures", + "glGenTextures", + "glIsTexture", + + 0 +}; + +PROC get_gl_proc_address(const char* p_address) { + + PROC proc = wglGetProcAddress((const CHAR*)p_address); + if (!proc) { + + int i=0; + while(_gl_procs[i]) { + + if (strcmp(p_address,_gl_proc_names[i])==0) { + return _gl_procs[i]; + } + i++; + } + } + return proc; +} +#endif diff --git a/platform/windows/ctxgl_procaddr.h b/platform/windows/ctxgl_procaddr.h index d3ab20e82d..916b480639 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-2014 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,13 +26,13 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef CTXGL_PROCADDR_H
-#define CTXGL_PROCADDR_H
-
-#ifdef OPENGL_ENABLED
-#include <windows.h>
-
-
-PROC get_gl_proc_address(const char* p_address);
-#endif
-#endif // CTXGL_PROCADDR_H
+#ifndef CTXGL_PROCADDR_H +#define CTXGL_PROCADDR_H + +#ifdef OPENGL_ENABLED +#include <windows.h> + + +PROC get_gl_proc_address(const char* p_address); +#endif +#endif // CTXGL_PROCADDR_H diff --git a/platform/windows/detect.py b/platform/windows/detect.py index be92ee8f6d..fcde14030f 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -1,233 +1,396 @@ -
-
-import os
-
-import sys
-
-
-def is_active():
- return True
-
-def get_name():
- return "Windows"
-
-def can_build():
-
-
- if (os.name=="nt"):
- #building natively on windows!
- if (os.getenv("VSINSTALLDIR")):
- return True
- else:
- print("MSVC Not detected, attempting mingw.")
- return True
-
-
-
- if (os.name=="posix"):
-
- mingw = "i586-mingw32msvc-"
- mingw64 = "i686-w64-mingw32-"
- if (os.getenv("MINGW32_PREFIX")):
- mingw=os.getenv("MINGW32_PREFIX")
- if (os.getenv("MINGW64_PREFIX")):
- mingw64=os.getenv("MINGW64_PREFIX")
-
- if os.system(mingw+"gcc --version >/dev/null") == 0 or os.system(mingw64+"gcc --version >/dev/null") ==0:
- return True
-
-
-
- return False
-
-def get_opts():
-
- mingw=""
- mingw64=""
- if (os.name!="nt"):
- mingw = "i586-mingw32msvc-"
- mingw64 = "i686-w64-mingw32-"
- if (os.getenv("MINGW32_PREFIX")):
- mingw=os.getenv("MINGW32_PREFIX")
- if (os.getenv("MINGW64_PREFIX")):
- mingw64=os.getenv("MINGW64_PREFIX")
-
-
- return [
- ('mingw_prefix','Mingw Prefix',mingw),
- ('mingw_prefix_64','Mingw Prefix 64 bits',mingw64),
- ('mingw64_for_32','Use Mingw 64 for 32 Bits Build',"no"),
- ]
-
-def get_flags():
-
- return [
- ('freetype','builtin'), #use builtin freetype
- ('openssl','builtin'), #use builtin openssl
- ('theora','no'),
- ]
-
-
-
-def configure(env):
-
- env.Append(CPPPATH=['#platform/windows'])
-
-
- if (os.name=="nt" and os.getenv("VSINSTALLDIR")!=None):
- #build using visual studio
- env['ENV']['TMP'] = os.environ['TMP']
- env.Append(CPPPATH=['#platform/windows/include'])
- env.Append(LIBPATH=['#platform/windows/lib'])
-
- if (env["freetype"]!="no"):
- env.Append(CCFLAGS=['/DFREETYPE_ENABLED'])
- env.Append(CPPPATH=['#tools/freetype'])
- env.Append(CPPPATH=['#tools/freetype/freetype/include'])
-
- if (env["target"]=="release"):
-
- env.Append(CCFLAGS=['/O2'])
- env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS'])
- env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup'])
-
- elif (env["target"]=="release_debug"):
-
- env.Append(CCFLAGS=['/O2','/DDEBUG_ENABLED'])
- env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
-
- elif (env["target"]=="debug"):
-
- env.Append(CCFLAGS=['/Zi','/DDEBUG_ENABLED','/DDEBUG_MEMORY_ENABLED','/DD3D_DEBUG_INFO','/O1'])
- env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
- env.Append(LINKFLAGS=['/DEBUG'])
-
-
- env.Append(CCFLAGS=['/MT','/Gd','/GR','/nologo'])
- env.Append(CXXFLAGS=['/TP'])
- env.Append(CPPFLAGS=['/DMSVC', '/GR', ])
- env.Append(CCFLAGS=['/I'+os.getenv("WindowsSdkDir")+"/Include"])
- env.Append(CCFLAGS=['/DWINDOWS_ENABLED'])
- env.Append(CCFLAGS=['/DRTAUDIO_ENABLED'])
- env.Append(CCFLAGS=['/DWIN32'])
- env.Append(CCFLAGS=['/DTYPED_METHOD_BIND'])
-
- env.Append(CCFLAGS=['/DGLES2_ENABLED'])
- env.Append(CCFLAGS=['/DGLES1_ENABLED'])
- env.Append(CCFLAGS=['/DGLEW_ENABLED'])
- LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI', 'wsock32', 'shell32','advapi32']
- env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS])
-
- env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"])
- if (os.getenv("DXSDK_DIR")):
- DIRECTX_PATH=os.getenv("DXSDK_DIR")
- else:
- DIRECTX_PATH="C:/Program Files/Microsoft DirectX SDK (March 2009)"
-
- if (os.getenv("VCINSTALLDIR")):
- VC_PATH=os.getenv("VCINSTALLDIR")
- else:
- VC_PATH=""
-
- env.Append(CCFLAGS=["/I" + p for p in os.getenv("INCLUDE").split(";")])
- env.Append(LIBPATH=[p for p in os.getenv("LIB").split(";")])
- env.Append(CCFLAGS=["/I"+DIRECTX_PATH+"/Include"])
- env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"])
- env['ENV'] = os.environ;
- else:
- #build using mingw
- if (os.name=="nt"):
- env['ENV']['TMP'] = os.environ['TMP'] #way to go scons, you can be so stupid sometimes
- else:
- env["PROGSUFFIX"]=env["PROGSUFFIX"]+".exe"
-
- mingw_prefix=""
-
- if (env["bits"]=="default"):
- env["bits"]="32"
-
- use64=False
- if (env["bits"]=="32"):
-
- if (env["mingw64_for_32"]=="yes"):
- env.Append(CCFLAGS=['-m32'])
- env.Append(LINKFLAGS=['-m32'])
- env.Append(LINKFLAGS=['-static-libgcc'])
- env.Append(LINKFLAGS=['-static-libstdc++'])
- mingw_prefix=env["mingw_prefix_64"];
- else:
- mingw_prefix=env["mingw_prefix"];
-
-
- else:
- mingw_prefix=env["mingw_prefix_64"];
- env.Append(LINKFLAGS=['-static'])
-
- nulstr=""
-
- if (os.name=="posix"):
- nulstr=">/dev/null"
- else:
- nulstr=">nul"
-
-
-
- if os.system(mingw_prefix+"gcc --version"+nulstr)!=0:
- #not really super consistent but..
- print("Can't find Windows compiler: "+mingw_prefix)
- sys.exit(255)
-
- if (env["target"]=="release"):
-
- env.Append(CCFLAGS=['-O3','-ffast-math','-fomit-frame-pointer','-msse2'])
- env.Append(LINKFLAGS=['-Wl,--subsystem,windows'])
-
- elif (env["target"]=="release_debug"):
-
- env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED'])
-
- elif (env["target"]=="debug"):
-
- env.Append(CCFLAGS=['-g', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED'])
-
- if (env["freetype"]!="no"):
- env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
- env.Append(CPPPATH=['#tools/freetype'])
- env.Append(CPPPATH=['#tools/freetype/freetype/include'])
-
- env["CC"]=mingw_prefix+"gcc"
- env['AS']=mingw_prefix+"as"
- env['CXX'] = mingw_prefix+"g++"
- env['AR'] = mingw_prefix+"ar"
- env['RANLIB'] = mingw_prefix+"ranlib"
- env['LD'] = mingw_prefix+"g++"
-
- #env['CC'] = "winegcc"
- #env['CXX'] = "wineg++"
-
- env.Append(CCFLAGS=['-DWINDOWS_ENABLED','-mwindows'])
- env.Append(CPPFLAGS=['-DRTAUDIO_ENABLED'])
- env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLEW_ENABLED'])
- env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','wsock32','kernel32'])
-
- if (env["bits"]=="32" and env["mingw64_for_32"]!="yes"):
-# env.Append(LIBS=['gcc_s'])
- #--with-arch=i686
- env.Append(CPPFLAGS=['-march=i686'])
- env.Append(LINKFLAGS=['-march=i686'])
-
-
-
-
- #'d3dx9d'
- env.Append(CPPFLAGS=['-DMINGW_ENABLED'])
- env.Append(LINKFLAGS=['-g'])
-
- 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') } )
- env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } )
- env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
-
-
-
+# +# tested on | Windows native | Linux cross-compilation +# ------------------------+-------------------+--------------------------- +# MSVS C++ 2010 Express | WORKS | n/a +# Mingw-w64 | WORKS | WORKS +# Mingw-w32 | WORKS | WORKS +# MinGW | WORKS | untested +# +##### +# Notes about MSVS C++ : +# +# - MSVC2010-Express compiles to 32bits only. +# +##### +# Notes about Mingw-w64 and Mingw-w32 under Windows : +# +# - both can be installed using the official installer : +# http://mingw-w64.sourceforge.net/download.php#mingw-builds +# +# - if you want to compile both 32bits and 64bits, don't forget to +# run the installer twice to install them both. +# +# - install them into a path that does not contain spaces +# ( example : "C:/Mingw-w32", "C:/Mingw-w64" ) +# +# - if you want to compile faster using the "-j" option, don't forget +# to install the appropriate version of the Pywin32 python extension +# available from : http://sourceforge.net/projects/pywin32/files/ +# +# - before running scons, you must add into the environment path +# the path to the "/bin" directory of the Mingw version you want +# to use : +# +# set PATH=C:/Mingw-w32/bin;%PATH% +# +# - then, scons should be able to detect gcc. +# - Mingw-w32 only compiles 32bits. +# - Mingw-w64 only compiles 64bits. +# +# - it is possible to add them both at the same time into the PATH env, +# if you also define the MINGW32_PREFIX and MINGW64_PREFIX environment +# variables. +# For instance, you could store that set of commands into a .bat script +# that you would run just before scons : +# +# set PATH=C:\mingw-w32\bin;%PATH% +# set PATH=C:\mingw-w64\bin;%PATH% +# set MINGW32_PREFIX=C:\mingw-w32\bin\ +# set MINGW64_PREFIX=C:\mingw-w64\bin\ +# +##### +# Notes about Mingw, Mingw-w64 and Mingw-w32 under Linux : +# +# - default toolchain prefixes are : +# "i586-mingw32msvc-" for MinGW +# "i686-w64-mingw32-" for Mingw-w32 +# "x86_64-w64-mingw32-" for Mingw-w64 +# +# - if both MinGW and Mingw-w32 are installed on your system +# Mingw-w32 should take the priority over MinGW. +# +# - it is possible to manually override prefixes by defining +# the MINGW32_PREFIX and MINGW64_PREFIX environment variables. +# +##### +# Notes about Mingw under Windows : +# +# - this is the MinGW version from http://mingw.org/ +# - install it into a path that does not contain spaces +# ( example : "C:/MinGW" ) +# - several DirectX headers might be missing. You can copy them into +# the C:/MinGW/include" directory from this page : +# https://code.google.com/p/mingw-lib/source/browse/trunk/working/avcodec_to_widget_5/directx_include/ +# - before running scons, add the path to the "/bin" directory : +# set PATH=C:/MinGW/bin;%PATH% +# - scons should be able to detect gcc. +# + +##### +# TODO : +# +# - finish to cleanup this script to remove all the remains of previous hacks and workarounds +# - make it work with the Windows7 SDK that is supposed to enable 64bits compilation for MSVC2010-Express +# - confirm it works well with other Visual Studio versions. +# - update the wiki about the pywin32 extension required for the "-j" option under Windows. +# - update the wiki to document MINGW32_PREFIX and MINGW64_PREFIX +# + +import os + +import sys + + +def is_active(): + return True + +def get_name(): + return "Windows" + +def can_build(): + + if (os.name=="nt"): + #building natively on windows! + if (os.getenv("VSINSTALLDIR")): + return True + else: + print("\nMSVC not detected, attempting Mingw.") + mingw32 = "" + mingw64 = "" + if ( os.getenv("MINGW32_PREFIX") ) : + mingw32 = os.getenv("MINGW32_PREFIX") + if ( os.getenv("MINGW64_PREFIX") ) : + mingw64 = os.getenv("MINGW64_PREFIX") + + test = "gcc --version > NUL 2>&1" + if os.system(test)!= 0 and os.system(mingw32+test)!=0 and os.system(mingw64+test)!=0 : + print("- could not detect gcc.") + print("Please, make sure a path to a Mingw /bin directory is accessible into the environment PATH.\n") + return False + else: + print("- gcc detected.") + + return True + + if (os.name=="posix"): + + mingw = "i586-mingw32msvc-" + mingw64 = "x86_64-w64-mingw32-" + mingw32 = "i686-w64-mingw32-" + + if (os.getenv("MINGW32_PREFIX")): + mingw32=os.getenv("MINGW32_PREFIX") + mingw = mingw32 + if (os.getenv("MINGW64_PREFIX")): + mingw64=os.getenv("MINGW64_PREFIX") + + test = "gcc --version &>/dev/null" + if (os.system(mingw+test) == 0 or os.system(mingw64+test) == 0 or os.system(mingw32+test) == 0): + return True + + return False + +def get_opts(): + + mingw="" + mingw32="" + mingw64="" + if ( os.name == "posix" ): + mingw = "i586-mingw32msvc-" + mingw32 = "i686-w64-mingw32-" + mingw64 = "x86_64-w64-mingw32-" + + if os.system(mingw32+"gcc --version &>/dev/null") != 0 : + mingw32 = mingw + + if (os.getenv("MINGW32_PREFIX")): + mingw32=os.getenv("MINGW32_PREFIX") + mingw = mingw32 + if (os.getenv("MINGW64_PREFIX")): + mingw64=os.getenv("MINGW64_PREFIX") + + + return [ + ('mingw_prefix','Mingw Prefix',mingw32), + ('mingw_prefix_64','Mingw Prefix 64 bits',mingw64), + ] + +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'] + env.Append(CPPPATH=['#platform/windows/include']) + env.Append(LIBPATH=['#platform/windows/lib']) + + if (env["freetype"]!="no"): + env.Append(CCFLAGS=['/DFREETYPE_ENABLED']) + env.Append(CPPPATH=['#tools/freetype']) + env.Append(CPPPATH=['#tools/freetype/freetype/include']) + + if (env["target"]=="release"): + + env.Append(CCFLAGS=['/O2']) + env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS']) + env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup']) + + elif (env["target"]=="release_debug"): + + env.Append(CCFLAGS=['/O2','/DDEBUG_ENABLED']) + env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) + elif (env["target"]=="debug_release"): + + 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=['/Z7','/DDEBUG_ENABLED','/DDEBUG_MEMORY_ENABLED','/DD3D_DEBUG_INFO','/Od']) + env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) + env.Append(LINKFLAGS=['/DEBUG']) + + + env.Append(CCFLAGS=['/MT','/Gd','/GR','/nologo']) + env.Append(CXXFLAGS=['/TP']) + env.Append(CPPFLAGS=['/DMSVC', '/GR', ]) + env.Append(CCFLAGS=['/I'+os.getenv("WindowsSdkDir")+"/Include"]) + env.Append(CCFLAGS=['/DWINDOWS_ENABLED']) + env.Append(CCFLAGS=['/DRTAUDIO_ENABLED']) + env.Append(CCFLAGS=['/DWIN32']) + env.Append(CCFLAGS=['/DTYPED_METHOD_BIND']) + + env.Append(CCFLAGS=['/DGLES2_ENABLED']) + + env.Append(CCFLAGS=['/DGLEW_ENABLED']) + LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI','Shlwapi', 'wsock32', 'shell32','advapi32'] + env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS]) + + env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"]) + if (os.getenv("DXSDK_DIR")): + DIRECTX_PATH=os.getenv("DXSDK_DIR") + else: + DIRECTX_PATH="C:/Program Files/Microsoft DirectX SDK (March 2009)" + + if (os.getenv("VCINSTALLDIR")): + VC_PATH=os.getenv("VCINSTALLDIR") + else: + VC_PATH="" + + env.Append(CCFLAGS=["/I" + p for p in os.getenv("INCLUDE").split(";")]) + env.Append(LIBPATH=[p for p in os.getenv("LIB").split(";")]) + env.Append(CCFLAGS=["/I"+DIRECTX_PATH+"/Include"]) + env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"]) + env['ENV'] = os.environ; + else: + + # Workaround for MinGW. See: + # http://www.scons.org/wiki/LongCmdLinesOnWin32 + if (os.name=="nt"): + import subprocess + + def mySubProcess(cmdline,env): + #print "SPAWNED : " + cmdline + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env) + data, err = proc.communicate() + rv = proc.wait() + if rv: + print "=====" + print err + print "=====" + return rv + + def mySpawn(sh, escape, cmd, args, env): + + newargs = ' '.join(args[1:]) + cmdline = cmd + " " + newargs + + rv=0 + if len(cmdline) > 32000 and cmd.endswith("ar") : + cmdline = cmd + " " + args[1] + " " + args[2] + " " + for i in range(3,len(args)) : + rv = mySubProcess( cmdline + args[i], env ) + if rv : + break + else: + rv = mySubProcess( cmdline, env ) + + return rv + + env['SPAWN'] = mySpawn + + #build using mingw + if (os.name=="nt"): + env['ENV']['TMP'] = os.environ['TMP'] #way to go scons, you can be so stupid sometimes + else: + env["PROGSUFFIX"]=env["PROGSUFFIX"]+".exe" # for linux cross-compilation + + mingw_prefix="" + + if (env["bits"]=="default"): + env["bits"]="32" + + if (env["bits"]=="32"): + env.Append(LINKFLAGS=['-static']) + env.Append(LINKFLAGS=['-static-libgcc']) + env.Append(LINKFLAGS=['-static-libstdc++']) + mingw_prefix=env["mingw_prefix"]; + else: + env.Append(LINKFLAGS=['-static']) + mingw_prefix=env["mingw_prefix_64"]; + + nulstr="" + + if (os.name=="posix"): + nulstr=">/dev/null" + else: + nulstr=">nul" + + + + # if os.system(mingw_prefix+"gcc --version"+nulstr)!=0: + # #not really super consistent but.. + # print("Can't find Windows compiler: "+mingw_prefix) + # sys.exit(255) + + if (env["target"]=="release"): + + env.Append(CCFLAGS=['-O3','-ffast-math','-fomit-frame-pointer','-msse2']) + env.Append(LINKFLAGS=['-Wl,--subsystem,windows']) + + elif (env["target"]=="release_debug"): + + env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED']) + + elif (env["target"]=="debug"): + + env.Append(CCFLAGS=['-g', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) + + if (env["freetype"]!="no"): + env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) + env.Append(CPPPATH=['#tools/freetype']) + env.Append(CPPPATH=['#tools/freetype/freetype/include']) + + env["CC"]=mingw_prefix+"gcc" + env['AS']=mingw_prefix+"as" + env['CXX'] = mingw_prefix+"g++" + env['AR'] = mingw_prefix+"ar" + env['RANLIB'] = mingw_prefix+"ranlib" + env['LD'] = mingw_prefix+"g++" + + #env['CC'] = "winegcc" + #env['CXX'] = "wineg++" + + 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']) + + # if (env["bits"]=="32"): + # env.Append(LIBS=['gcc_s']) + # #--with-arch=i686 + # env.Append(CPPFLAGS=['-march=i686']) + # env.Append(LINKFLAGS=['-march=i686']) + + + + + #'d3dx9d' + 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') } ) + env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) + 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..29f21bf227 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-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. */ +/*************************************************************************/ + #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="Okam Studio"; + 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 Binary files differnew file mode 100644 index 0000000000..e57ce36529 --- /dev/null +++ b/platform/windows/godot.ico diff --git a/platform/windows/godot_res.rc b/platform/windows/godot_res.rc new file mode 100644 index 0000000000..73f36e5e59 --- /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 +PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,0 +FILEOS 4 +FILETYPE 1 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Okam Studio" + 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
\ No newline at end of file diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index fa573b9421..fe39051670 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-2014 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 */ @@ -115,32 +115,32 @@ PCHAR* return argv; } -char* mb_to_utf8(const char* mbs) { - - int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0); // returns 0 if failed - wchar_t *wbuf = new wchar_t[wlen + 1]; - MultiByteToWideChar(CP_ACP,0,mbs,-1,wbuf,wlen); - wbuf[wlen]=0; - - int ulen = WideCharToMultiByte(CP_UTF8,0,wbuf,-1,NULL,0,NULL,NULL); +char* wc_to_utf8(const wchar_t* wc) { + int ulen = WideCharToMultiByte(CP_UTF8,0,wc,-1,NULL,0,NULL,NULL); char * ubuf = new char[ulen + 1]; - WideCharToMultiByte(CP_UTF8,0,wbuf,-1,ubuf,ulen,NULL,NULL); + WideCharToMultiByte(CP_UTF8,0,wc,-1,ubuf,ulen,NULL,NULL); ubuf[ulen] = 0; return ubuf; } -int main(int argc, char** argv) { +int widechar_main(int argc, wchar_t** argv) { OS_Windows os(NULL); setlocale(LC_CTYPE, ""); char ** argv_utf8 = new char*[argc]; + for(int i=0; i<argc; ++i) { - argv_utf8[i] = mb_to_utf8(argv[i]); + argv_utf8[i] = wc_to_utf8(argv[i]); } - Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]); + Error err = Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]); + + if (err!=OK) + return 255; + + if (Main::start()) os.run(); Main::cleanup(); @@ -154,82 +154,30 @@ int main(int argc, char** argv) { return os.get_exit_code(); }; -HINSTANCE godot_hinstance = NULL; - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - - int argc; - char** argv; - - char* arg; - int index; - int result; +int main(int _argc, char** _argv) { + // _argc and _argv are ignored + // we are going to use the WideChar version of them instead - // count the arguments + LPWSTR *wc_argv; + int argc; + int result; - argc = 1; - arg = lpCmdLine; - - while (arg[0] != 0) { - - while (arg[0] != 0 && arg[0] == ' ') { - arg++; - } - - if (arg[0] != 0) { - - argc++; - - while (arg[0] != 0 && arg[0] != ' ') { - arg++; - } - - } - - } + wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc); - // tokenize the arguments - - argv = (char**)malloc(argc * sizeof(char*)); - - arg = lpCmdLine; - index = 1; - - while (arg[0] != 0) { - - while (arg[0] != 0 && arg[0] == ' ') { - arg++; - } - - if (arg[0] != 0) { - - argv[index] = arg; - index++; - - while (arg[0] != 0 && arg[0] != ' ') { - arg++; - } - - if (arg[0] != 0) { - arg[0] = 0; - arg++; - } - - } - - } - - // put the program name into argv[0] - - char filename[_MAX_PATH]; + if( NULL == wc_argv ) { + wprintf(L"CommandLineToArgvW failed\n"); + return 0; + } - GetModuleFileName(NULL, filename, _MAX_PATH); - argv[0] = filename; + result = widechar_main(argc, wc_argv); - // call the user specified main function + LocalFree(wc_argv); + return result; +} - result = main(argc, argv); +HINSTANCE godot_hinstance = NULL; - free(argv); - return result; +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + godot_hinstance = hInstance; + return main(0,NULL); } diff --git a/platform/windows/key_mapping_win.cpp b/platform/windows/key_mapping_win.cpp index bdf3b2a92f..f07b7c6eaa 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-2014 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 */ diff --git a/platform/windows/key_mapping_win.h b/platform/windows/key_mapping_win.h index 3e351675b0..288fcdd8de 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-2014 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,26 +26,26 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef KEY_MAPPING_WINDOWS_H
-#define KEY_MAPPING_WINDOWS_H
-
-
-#include "os/keyboard.h"
-
-#include <windows.h>
-
-#include <winuser.h>
-
-
-class KeyMappingWindows {
-
- KeyMappingWindows() {};
-public:
-
- static unsigned int get_keysym(unsigned int p_code);
-
-};
-
-
-
-#endif
+#ifndef KEY_MAPPING_WINDOWS_H +#define KEY_MAPPING_WINDOWS_H + + +#include "os/keyboard.h" + +#include <windows.h> + +#include <winuser.h> + + +class KeyMappingWindows { + + KeyMappingWindows() {}; +public: + + static unsigned int get_keysym(unsigned int p_code); + +}; + + + +#endif diff --git a/platform/windows/lang_table.h b/platform/windows/lang_table.h index 83f3fb52fd..bfdf2b6ebe 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-2014 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 */ diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index a10152a025..1fb8e6dbd0 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "drivers/gles2/rasterizer_gles2.h" -#include "drivers/gles1/rasterizer_gles1.h" + #include "os_windows.h" #include "drivers/nedmalloc/memory_pool_static_nedmalloc.h" #include "drivers/unix/memory_pool_static_malloc.h" @@ -54,8 +54,17 @@ #include "io/marshalls.h" #include "shlobj.h" +#include <regstr.h> + static const WORD MAX_CONSOLE_LINES = 1500; +extern "C" { +#ifdef _MSC_VER + _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; +#else + __attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001; +#endif +} //#define STDOUT_FILE @@ -130,11 +139,11 @@ void RedirectIOToConsole() { int OS_Windows::get_video_driver_count() const { - return 2; + return 1; } const char * OS_Windows::get_video_driver_name(int p_driver) const { - return p_driver==0?"GLES2":"GLES1"; + return "GLES2"; } OS::VideoMode OS_Windows::get_default_video_mode() const { @@ -162,6 +171,8 @@ void OS_Windows::initialize_core() { last_button_state=0; //RedirectIOToConsole(); + maximized=false; + minimized=false; ThreadWindows::make_default(); SemaphoreWindows::make_default(); @@ -312,11 +323,21 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { old_invalid=true; outside=true; + if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT); + if (input) + input->set_mouse_in_window(false); } break; case WM_MOUSEMOVE: { if (outside) { + //mouse enter + + if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER); + if (input) + input->set_mouse_in_window(true); CursorShape c=cursor_shape; cursor_shape=CURSOR_MAX; @@ -412,6 +433,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_RBUTTONUP: case WM_MOUSEWHEEL: case WM_LBUTTONDBLCLK: + case WM_RBUTTONDBLCLK: /*case WM_XBUTTONDOWN: case WM_XBUTTONUP: */{ @@ -465,6 +487,12 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { mb.button_index=1; mb.doubleclick = true; } break; + case WM_RBUTTONDBLCLK: { + + mb.pressed=true; + mb.button_index=2; + mb.doubleclick = true; + } break; case WM_MOUSEWHEEL: { mb.pressed=true; @@ -586,10 +614,11 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { ERR_BREAK(key_event_pos >= KEY_EVENT_BUFFER_SIZE); + // Make sure we don't include modifiers for the modifier key itself. KeyEvent ke; - ke.mod_state.shift=shift_mem; - ke.mod_state.alt=alt_mem; - ke.mod_state.control=control_mem; + ke.mod_state.shift= (wParam != VK_SHIFT) ? shift_mem : false; + ke.mod_state.alt= (! (wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false; + ke.mod_state.control= (wParam != VK_CONTROL) ? control_mem : false; ke.mod_state.meta=meta_mem; ke.uMsg=uMsg; @@ -677,6 +706,53 @@ 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; @@ -718,7 +794,13 @@ void OS_Windows::probe_joysticks() { JOYCAPS jcaps; MMRESULT res = joyGetDevCaps(JOYSTICKID1 + i, &jcaps, sizeof(jcaps)); if (res == JOYERR_NOERROR) { - joy.name = jcaps.szPname; + String name = get_joystick_name(JOYSTICKID1 + i, jcaps); + if ( name == "") + joy.name = jcaps.szPname; + else + joy.name = name; + + }; }; @@ -944,6 +1026,23 @@ void OS_Windows::process_joysticks() { }; }; + +BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + OS_Windows *self=(OS_Windows*)OS::get_singleton(); + MonitorInfo minfo; + minfo.hMonitor=hMonitor; + minfo.hdcMonitor=hdcMonitor; + minfo.rect.pos.x=lprcMonitor->left; + minfo.rect.pos.y=lprcMonitor->top; + minfo.rect.size.x=lprcMonitor->right - lprcMonitor->left; + minfo.rect.size.y=lprcMonitor->bottom - lprcMonitor->top; + + self->monitor_info.push_back(minfo); + + return TRUE; +} + + void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { @@ -982,6 +1081,10 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ } + EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,0); + + print_line("DETECTED MONITORS: "+itos(monitor_info.size())); + pre_fs_valid=true; if (video_mode.fullscreen) { DEVMODE current; @@ -1004,6 +1107,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ video_mode.fullscreen=false; }*/ + pre_fs_valid=false; } DWORD dwExStyle; @@ -1083,7 +1187,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ physics_server = memnew( PhysicsServerSW ); physics_server->init(); - physics_2d_server = memnew( Physics2DServerSW ); + physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); if (!is_no_window_mode_enabled()) { @@ -1246,7 +1350,9 @@ void OS_Windows::finalize() { memdelete(main_loop); main_loop=NULL; - + + memdelete(input); + visual_server->finish(); memdelete(visual_server); #ifdef OPENGL_ENABLED @@ -1269,11 +1375,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); @@ -1281,6 +1386,9 @@ void OS_Windows::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); + joystick_change_queue.clear(); + monitor_info.clear(); + } void OS_Windows::finalize_core() { @@ -1374,9 +1482,13 @@ void OS_Windows::warp_mouse_pos(const Point2& p_to) { old_y=p_to.y; } else { - SetCursorPos(p_to.x, p_to.y); - } + POINT p; + p.x=p_to.x; + p.y=p_to.y; + ClientToScreen(hWnd,&p); + SetCursorPos(p.x,p.y); + } } Point2 OS_Windows::get_mouse_pos() const { @@ -1408,73 +1520,341 @@ void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) } -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) { +int OS_Windows::get_screen_count() const { + + return monitor_info.size(); +} +int OS_Windows::get_current_screen() const{ + + HMONITOR monitor = MonitorFromWindow(hWnd,MONITOR_DEFAULTTONEAREST); + for(int i=0;i<monitor_info.size();i++) { + if (monitor_info[i].hMonitor==monitor) + return i; + } + + return 0; +} +void OS_Windows::set_current_screen(int p_screen){ + + ERR_FAIL_INDEX(p_screen,monitor_info.size()); + + Vector2 ofs = get_window_position() - get_screen_position(get_current_screen()); + set_window_position(ofs+get_screen_position(p_screen)); + +} + +Point2 OS_Windows::get_screen_position(int p_screen) const{ + + ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),Point2()); + return Vector2( monitor_info[p_screen].rect.pos ); + +} +Size2 OS_Windows::get_screen_size(int p_screen) const{ + + ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),Point2()); + return Vector2( monitor_info[p_screen].rect.size ); + +} +Point2 OS_Windows::get_window_position() const{ + + RECT r; + GetWindowRect(hWnd,&r); + return Point2(r.left,r.top); +} +void OS_Windows::set_window_position(const Point2& p_position){ + + RECT r; + GetWindowRect(hWnd,&r); + MoveWindow(hWnd,p_position.x,p_position.y,r.right-r.left,r.bottom-r.top,TRUE); + +} +Size2 OS_Windows::get_window_size() const{ + + RECT r; + GetClientRect(hWnd,&r); + return Vector2(r.right-r.left,r.bottom-r.top); + +} +void OS_Windows::set_window_size(const Size2 p_size){ + + video_mode.width=p_size.width; + video_mode.height=p_size.height; + + if (video_mode.fullscreen) { + return; + } + + + RECT crect; + GetClientRect(hWnd,&crect); + + RECT rect; + GetWindowRect(hWnd,&rect); + int dx = (rect.right-rect.left)-(crect.right-crect.left); + int dy = (rect.bottom-rect.top)-(crect.bottom-crect.top); + + rect.right=rect.left+p_size.width+dx; + rect.bottom=rect.top+p_size.height+dy; + + + //print_line("PRE: "+itos(rect.left)+","+itos(rect.top)+","+itos(rect.right-rect.left)+","+itos(rect.bottom-rect.top)); + + /*if (video_mode.resizable) { + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); + } else { + AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW, FALSE); + }*/ + + //print_line("POST: "+itos(rect.left)+","+itos(rect.top)+","+itos(rect.right-rect.left)+","+itos(rect.bottom-rect.top)); + + MoveWindow(hWnd,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE); + +} +void OS_Windows::set_window_fullscreen(bool p_enabled){ + + if (video_mode.fullscreen==p_enabled) + return; + + + + if (p_enabled) { + + + if (pre_fs_valid) { + GetWindowRect(hWnd,&pre_fs_rect); + //print_line("A: "+itos(pre_fs_rect.left)+","+itos(pre_fs_rect.top)+","+itos(pre_fs_rect.right-pre_fs_rect.left)+","+itos(pre_fs_rect.bottom-pre_fs_rect.top)); + //MapWindowPoints(hWnd, GetParent(hWnd), (LPPOINT) &pre_fs_rect, 2); + //print_line("B: "+itos(pre_fs_rect.left)+","+itos(pre_fs_rect.top)+","+itos(pre_fs_rect.right-pre_fs_rect.left)+","+itos(pre_fs_rect.bottom-pre_fs_rect.top)); + } - HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE); - if (!hCon || hCon==INVALID_HANDLE_VALUE) { - if (p_rationale && p_rationale[0]) { - 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); + int cs = get_current_screen(); + Point2 pos = get_screen_position(cs); + Size2 size = get_screen_size(cs); + /* r.left = pos.x; + r.top = pos.y; + r.bottom = pos.y+size.y; + r.right = pos.x+size.x; +*/ + SetWindowLongPtr(hWnd, GWL_STYLE, + WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); + MoveWindow(hWnd, pos.x, pos.y, size.width, size.height, TRUE); + + video_mode.fullscreen=true; + + + } else { + + RECT rect; + + if (pre_fs_valid) { + rect=pre_fs_rect; + } else { + rect.left=0; + rect.right=video_mode.width; + rect.top=0; + rect.bottom=video_mode.height; + } + + + + if (video_mode.resizable) { + + SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); + //AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); + MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); } 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); + SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); + //AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW, FALSE); + MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + } + + video_mode.fullscreen=false; + pre_fs_valid=true; +/* + DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + DWORD dwStyle=WS_OVERLAPPEDWINDOW; + if (!video_mode.resizable) { + dwStyle &= ~WS_THICKFRAME; + dwStyle &= ~WS_MAXIMIZEBOX; } + AdjustWindowRectEx(&pre_fs_rect, dwStyle, FALSE, dwExStyle); + video_mode.fullscreen=false; + video_mode.width=pre_fs_rect.right-pre_fs_rect.left; + video_mode.height=pre_fs_rect.bottom-pre_fs_rect.top; +*/ + } + +// MoveWindow(hWnd,r.left,r.top,p_size.x,p_size.y,TRUE); + + +} +bool OS_Windows::is_window_fullscreen() const{ + + return video_mode.fullscreen; +} +void OS_Windows::set_window_resizable(bool p_enabled){ + + if (video_mode.resizable==p_enabled) + return; +/* + GetWindowRect(hWnd,&pre_fs_rect); + DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + DWORD dwStyle=WS_OVERLAPPEDWINDOW; + if (!p_enabled) { + dwStyle &= ~WS_THICKFRAME; + dwStyle &= ~WS_MAXIMIZEBOX; + } + AdjustWindowRectEx(&pre_fs_rect, dwStyle, FALSE, dwExStyle); + */ + + if (!video_mode.fullscreen) { + if (p_enabled) { + SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); + } else { + SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); + + } + + RECT rect; + GetWindowRect(hWnd,&rect); + MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + } + + video_mode.resizable=p_enabled; + +} +bool OS_Windows::is_window_resizable() const{ + + return video_mode.resizable; +} +void OS_Windows::set_window_minimized(bool p_enabled){ + + if (p_enabled) { + maximized=false; + minimized=true; + ShowWindow(hWnd,SW_MINIMIZE); } else { + ShowWindow(hWnd,SW_RESTORE); + maximized=false; + minimized=false; + } +} +bool OS_Windows::is_window_minimized() const{ - CONSOLE_SCREEN_BUFFER_INFO sbi; //original - GetConsoleScreenBufferInfo(hCon,&sbi); + return minimized; - SetConsoleTextAttribute(hCon,sbi.wAttributes); +} +void OS_Windows::set_window_maximized(bool p_enabled){ + + if (p_enabled) { + maximized=true; + minimized=false; + ShowWindow(hWnd,SW_MAXIMIZE); + } else { + ShowWindow(hWnd,SW_RESTORE); + maximized=false; + minimized=false; + } +} +bool OS_Windows::is_window_maximized() const{ + + return maximized; +} +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) { + + const char* err_details; + if (p_rationale && p_rationale[0]) + err_details = p_rationale; + else + err_details = p_code; - 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_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; } - if (p_rationale && p_rationale[0]) { + } else { - SetConsoleTextAttribute(hCon,basecol|FOREGROUND_INTENSITY); + CONSOLE_SCREEN_BUFFER_INFO sbi; //original + 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; + switch(p_type) { + case ERR_ERROR: basecol = FOREGROUND_RED; break; + case ERR_WARNING: basecol = FOREGROUND_RED | FOREGROUND_GREEN; break; + case ERR_SCRIPT: basecol = FOREGROUND_RED | FOREGROUND_BLUE; break; + } + 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); } - } @@ -1483,10 +1863,14 @@ String OS_Windows::get_name() { return "Windows"; } -OS::Date OS_Windows::get_date() const { +OS::Date OS_Windows::get_date(bool utc) const { SYSTEMTIME systemtime; - GetSystemTime(&systemtime); + if (utc) + GetSystemTime(&systemtime); + else + GetLocalTime(&systemtime); + Date date; date.day=systemtime.wDay; date.month=Month(systemtime.wMonth); @@ -1495,10 +1879,13 @@ OS::Date OS_Windows::get_date() const { date.dst=false; return date; } -OS::Time OS_Windows::get_time() const { +OS::Time OS_Windows::get_time(bool utc) const { SYSTEMTIME systemtime; - GetLocalTime(&systemtime); + if (utc) + GetSystemTime(&systemtime); + else + GetLocalTime(&systemtime); Time time; time.hour=systemtime.wHour; @@ -1507,6 +1894,23 @@ OS::Time OS_Windows::get_time() const { return time; } +OS::TimeZoneInfo OS_Windows::get_time_zone_info() const { + TIME_ZONE_INFORMATION info; + bool daylight = false; + if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) + daylight = true; + + TimeZoneInfo ret; + if (daylight) { + ret.name = info.DaylightName; + } else { + ret.name = info.StandardName; + } + + ret.bias = info.Bias; + return ret; +} + uint64_t OS_Windows::get_unix_time() const { FILETIME ft; @@ -1529,6 +1933,12 @@ uint64_t OS_Windows::get_unix_time() const { return (*(uint64_t*)&ft - *(uint64_t*)&fep) / 10000000; }; +uint64_t OS_Windows::get_system_time_msec() const { + SYSTEMTIME st; + GetSystemTime(&st); + return st.wMilliseconds; +} + void OS_Windows::delay_usec(uint32_t p_usec) const { if (p_usec < 1000) @@ -1709,7 +2119,7 @@ String OS_Windows::get_executable_path() const { wchar_t bufname[4096]; GetModuleFileNameW(NULL,bufname,4096); String s= bufname; - print_line("EXEC PATHPó: "+s); + print_line("EXEC PATHP??: "+s); return s; } @@ -1774,12 +2184,13 @@ bool OS_Windows::has_environment(const String& p_var) const { String OS_Windows::get_environment(const String& p_var) const { - char* val = getenv(p_var.utf8().get_data()); - if (val) - return val; - + wchar_t wval[0x7Fff]; // MSDN says 32767 char is the maximum + int wlen = GetEnvironmentVariableW(p_var.c_str(),wval,0x7Fff); + if ( wlen > 0 ) { + return wval; + } return ""; -}; +} String OS_Windows::get_stdin_string(bool p_block) { @@ -1795,6 +2206,7 @@ String OS_Windows::get_stdin_string(bool p_block) { void OS_Windows::move_window_to_foreground() { SetForegroundWindow(hWnd); + BringWindowToTop(hWnd); } diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 20993c6419..026b50c33d 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-2014 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 */ @@ -45,7 +45,9 @@ #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" #include "drivers/unix/ip_unix.h" #include "servers/physics_2d/physics_2d_server_sw.h" +#include "servers/physics_2d/physics_2d_server_wrap_mt.h" +#include "main/input_default.h" #include <windows.h> @@ -86,7 +88,7 @@ class OS_Windows : public OS { uint64_t ticks_start; uint64_t ticks_per_second; - bool minimized; + bool old_invalid; bool outside; int old_x,old_y; @@ -130,6 +132,7 @@ class OS_Windows : public OS { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; + Size2 window_rect; VideoMode video_mode; MainLoop *main_loop; @@ -187,6 +190,7 @@ protected: void probe_joysticks(); void process_joysticks(); void process_key_events(); + String get_joystick_name( int id, JOYCAPS jcaps); struct ProcessInfo { @@ -195,6 +199,23 @@ protected: }; Map<ProcessID, ProcessInfo>* process_map; + struct MonitorInfo { + HMONITOR hMonitor; + HDC hdcMonitor; + Rect2 rect; + + + }; + + bool pre_fs_valid; + RECT pre_fs_rect; + Vector<MonitorInfo> monitor_info; + bool maximized; + bool minimized; + + static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); + + public: LRESULT WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -217,13 +238,33 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; + virtual int get_screen_count() const; + virtual int get_current_screen() const; + 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 Point2 get_window_position() const; + virtual void set_window_position(const Point2& p_position); + virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2 p_size); + virtual void set_window_fullscreen(bool p_enabled); + virtual bool is_window_fullscreen() const; + virtual void set_window_resizable(bool p_enabled); + virtual bool is_window_resizable() const; + virtual void set_window_minimized(bool p_enabled); + virtual bool is_window_minimized() const; + virtual void set_window_maximized(bool p_enabled); + virtual bool is_window_maximized() const; + virtual MainLoop *get_main_loop() const; virtual String get_name(); - virtual Date get_date() const; - virtual Time get_time() const; + virtual Date get_date(bool utc) const; + virtual Time get_time(bool utc) const; + virtual TimeZoneInfo get_time_zone_info() const; virtual uint64_t get_unix_time() const; + virtual uint64_t get_system_time_msec() const; virtual bool can_draw() const; virtual Error set_cwd(const String& p_cwd); @@ -233,7 +274,7 @@ public: virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL); virtual Error kill(const ProcessID& p_pid); - + virtual bool has_environment(const String& p_var) const; virtual String get_environment(const String& p_var) const; 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 7bc3e42833..e6b561552e 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-2014 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,5 +31,5 @@ //#include <alloca.h> //#endif #define GLES2_INCLUDE_H "gl_context/glew.h" -#define GLES1_INCLUDE_H "gl_context/glew.h" + diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp index eabfb30599..e8245c92e5 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-2014 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 */ diff --git a/platform/windows/stream_peer_winsock.h b/platform/windows/stream_peer_winsock.h index 14dd5f0bb1..373b502d2c 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-2014 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 */ diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp index e77ca6feaa..cc689d9dcf 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-2014 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,144 +26,151 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "tcp_server_winsock.h"
-
-#include "stream_peer_winsock.h"
-
-#include <winsock2.h>
-
-extern int winsock_refcount;
-
-TCP_Server* TCPServerWinsock::_create() {
-
- return memnew(TCPServerWinsock);
-};
-
-void TCPServerWinsock::make_default() {
-
- TCP_Server::_create = TCPServerWinsock::_create;
-
- if (winsock_refcount == 0) {
- WSADATA data;
- WSAStartup(MAKEWORD(2,2), &data);
- };
- ++winsock_refcount;
-};
-
-void TCPServerWinsock::cleanup() {
-
- --winsock_refcount;
- if (winsock_refcount == 0) {
-
- WSACleanup();
- };
-};
-
-
-Error TCPServerWinsock::listen(uint16_t p_port,const List<String> *p_accepted_hosts) {
-
- int sockfd;
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, FAILED);
-
- unsigned long par = 1;
- if (ioctlsocket(sockfd, FIONBIO, &par)) {
- perror("setting non-block mode");
- stop();
- return FAILED;
- };
-
- struct sockaddr_in my_addr;
- my_addr.sin_family = AF_INET; // host byte order
- my_addr.sin_port = htons(p_port); // short, network byte order
- my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP TODO: use p_accepted_hosts
- memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero);
-
- if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr) != SOCKET_ERROR) {
-
- if (::listen(sockfd, SOMAXCONN) == SOCKET_ERROR) {
-
- closesocket(sockfd);
- ERR_FAIL_V(FAILED);
- };
- }
- else {
- return ERR_ALREADY_IN_USE;
- };
-
- if (listen_sockfd != INVALID_SOCKET) {
-
- stop();
- };
-
- listen_sockfd = sockfd;
-
- return OK;
-};
-
-bool TCPServerWinsock::is_connection_available() const {
-
- if (listen_sockfd == -1) {
- return false;
- };
-
- timeval timeout;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
-
- fd_set pfd;
- FD_ZERO(&pfd);
- FD_SET(listen_sockfd, &pfd);
-
- int ret = select(listen_sockfd + 1, &pfd, NULL, NULL, &timeout);
- ERR_FAIL_COND_V(ret < 0, 0);
-
- if (ret && (FD_ISSET(listen_sockfd, &pfd))) {
-
- return true;
- };
-
- return false;
-};
-
-
-Ref<StreamPeerTCP> TCPServerWinsock::take_connection() {
-
- if (!is_connection_available()) {
- return NULL;
- };
-
- struct sockaddr_in their_addr;
- int sin_size = sizeof(their_addr);
- int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &sin_size);
- ERR_FAIL_COND_V(fd == INVALID_SOCKET, NULL);
-
- Ref<StreamPeerWinsock> conn = memnew(StreamPeerWinsock);
- IP_Address ip;
- ip.host = (uint32_t)their_addr.sin_addr.s_addr;
-
- conn->set_socket(fd, ip, ntohs(their_addr.sin_port));
-
- return conn;
-};
-
-void TCPServerWinsock::stop() {
-
- if (listen_sockfd != INVALID_SOCKET) {
- closesocket(listen_sockfd);
- };
-
- listen_sockfd = -1;
-};
-
-
-TCPServerWinsock::TCPServerWinsock() {
-
- listen_sockfd = INVALID_SOCKET;
-};
-
-TCPServerWinsock::~TCPServerWinsock() {
-
- stop();
-};
-
+#include "tcp_server_winsock.h" + +#include "stream_peer_winsock.h" + +#include <winsock2.h> + +extern int winsock_refcount; + +TCP_Server* TCPServerWinsock::_create() { + + return memnew(TCPServerWinsock); +}; + +void TCPServerWinsock::make_default() { + + TCP_Server::_create = TCPServerWinsock::_create; + + if (winsock_refcount == 0) { + WSADATA data; + WSAStartup(MAKEWORD(2,2), &data); + }; + ++winsock_refcount; +}; + +void TCPServerWinsock::cleanup() { + + --winsock_refcount; + if (winsock_refcount == 0) { + + WSACleanup(); + }; +}; + + +Error TCPServerWinsock::listen(uint16_t p_port,const List<String> *p_accepted_hosts) { + + int sockfd; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, FAILED); + + unsigned long par = 1; + if (ioctlsocket(sockfd, FIONBIO, &par)) { + perror("setting non-block mode"); + stop(); + return FAILED; + }; + + struct sockaddr_in my_addr; + my_addr.sin_family = AF_INET; // host byte order + my_addr.sin_port = htons(p_port); // short, network byte order + my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP TODO: use p_accepted_hosts + memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); + + int reuse=1; + if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) { + + printf("REUSEADDR failed!"); + } + + + if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr) != SOCKET_ERROR) { + + if (::listen(sockfd, SOMAXCONN) == SOCKET_ERROR) { + + closesocket(sockfd); + ERR_FAIL_V(FAILED); + }; + } + else { + return ERR_ALREADY_IN_USE; + }; + + if (listen_sockfd != INVALID_SOCKET) { + + stop(); + }; + + listen_sockfd = sockfd; + + return OK; +}; + +bool TCPServerWinsock::is_connection_available() const { + + if (listen_sockfd == -1) { + return false; + }; + + timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + fd_set pfd; + FD_ZERO(&pfd); + FD_SET(listen_sockfd, &pfd); + + int ret = select(listen_sockfd + 1, &pfd, NULL, NULL, &timeout); + ERR_FAIL_COND_V(ret < 0, 0); + + if (ret && (FD_ISSET(listen_sockfd, &pfd))) { + + return true; + }; + + return false; +}; + + +Ref<StreamPeerTCP> TCPServerWinsock::take_connection() { + + if (!is_connection_available()) { + return NULL; + }; + + struct sockaddr_in their_addr; + int sin_size = sizeof(their_addr); + int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &sin_size); + ERR_FAIL_COND_V(fd == INVALID_SOCKET, NULL); + + Ref<StreamPeerWinsock> conn = memnew(StreamPeerWinsock); + IP_Address ip; + ip.host = (uint32_t)their_addr.sin_addr.s_addr; + + conn->set_socket(fd, ip, ntohs(their_addr.sin_port)); + + return conn; +}; + +void TCPServerWinsock::stop() { + + if (listen_sockfd != INVALID_SOCKET) { + closesocket(listen_sockfd); + }; + + listen_sockfd = -1; +}; + + +TCPServerWinsock::TCPServerWinsock() { + + listen_sockfd = INVALID_SOCKET; +}; + +TCPServerWinsock::~TCPServerWinsock() { + + stop(); +}; + diff --git a/platform/windows/tcp_server_winsock.h b/platform/windows/tcp_server_winsock.h index 2d54b6ce40..2516123908 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-2014 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,30 +26,30 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef TCP_SERVER_WINSOCK_H
-#define TCP_SERVER_WINSOCK_H
-
-#include "core/io/tcp_server.h"
-
-class TCPServerWinsock : public TCP_Server {
-
- int listen_sockfd;
-
- static TCP_Server* _create();
-
-public:
-
- virtual Error listen(uint16_t p_port,const List<String> *p_accepted_hosts=NULL);
- virtual bool is_connection_available() const;
- virtual Ref<StreamPeerTCP> take_connection();
-
- virtual void stop(); //stop listening
-
- static void make_default();
- static void cleanup();
-
- TCPServerWinsock();
- ~TCPServerWinsock();
-};
-
-#endif
+#ifndef TCP_SERVER_WINSOCK_H +#define TCP_SERVER_WINSOCK_H + +#include "core/io/tcp_server.h" + +class TCPServerWinsock : public TCP_Server { + + int listen_sockfd; + + static TCP_Server* _create(); + +public: + + virtual Error listen(uint16_t p_port,const List<String> *p_accepted_hosts=NULL); + virtual bool is_connection_available() const; + virtual Ref<StreamPeerTCP> take_connection(); + + virtual void stop(); //stop listening + + static void make_default(); + static void cleanup(); + + TCPServerWinsock(); + ~TCPServerWinsock(); +}; + +#endif |