Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Skip cmd for release builds #5416

Merged
merged 1 commit into from
Apr 7, 2017

Conversation

adrido
Copy link
Contributor

@adrido adrido commented Mar 18, 2017

This skips the cmd window on startup for release builds. Startup time is much faster then.

The /INCREMENTAL:NO just solves a linker warning (Linking with /LTCG does not allow /INCREMENTAL)

@SmallJoker
Copy link
Member

👎 The console window is helpful to develop mods and finding bugs. Compared to the debug.txt file all new lines can be viewed in the console instantly.

@adrido
Copy link
Contributor Author

adrido commented Mar 18, 2017

Yes I understand that it might usefull, but here I have some points against it:

  • Most players just want to play, and there is the console window just annoying.
  • Some young players might get irritated by seeing the console. (they does not know what it is)
  • No other program uses such a console window.
  • The console on windows before windows 10 is really useless, it is not even resizeable.
  • If someone want instant notice about what happens in the code, he can simply replace print(...) with minetest.chat_send_all(...)
  • A real application window makes a more native and finished look
  • If I remember correctly there is no console window on Linux popping up
  • On debug builds the console is still available

EDIT:
As it seems, that you are a coredev now, I want you to think about whats better for the whole Minetest project, and not only think about whats better for you 😉

@Fixer-007
Copy link
Contributor

Fixer-007 commented Mar 18, 2017

Console is irritating and clutters my taskbar, If I really need it I will enable it in config. Players just want to play, console adds debug/notfinished feel to minetest and I need to damn select the right minetest window every time.
Also, there is debug.txt available, basically the same thing, with mtail it can be used as console anyway.
Can you make an option in config to enable/disable wincmd console somehow? With it disabled by default that will help a lot.

@nerzhul
Copy link
Member

nerzhul commented Mar 18, 2017

@SmallJoker cmd for debug build okay, but seems lgtm for release builds, it's not very proper and "profesionnal"

@adrido
Copy link
Contributor Author

adrido commented Mar 18, 2017

I added the cmake option ENABLE_CMD_WINDOW FALSE CACHE BOOL "Shows the cmd window in Release builds". If someone want it, its easy to enable.

@sofar
Copy link
Contributor

sofar commented Mar 18, 2017

👍 default disable, maybe this could actually be an option in minetest.conf, but, it seems @SmallJoker's concern for debug builds is entire covered this way.

Copy link
Member

@nerzhul nerzhul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice !

@nerzhul nerzhul added @ Build CMake, build scripts, official builds, compiler and linker errors One approval ✅ ◻️ labels Mar 19, 2017
@SmallJoker
Copy link
Member

SmallJoker commented Mar 19, 2017

@sofar This is a compiler parameter, thus it could be quite hacky to add a minetest.conf setting for the console window.

I want you to think about whats better for the whole Minetest project, and not only think about whats better for you 😉

@adrido Yes, that's true. My comment should only represent my own opinion - not meant as a downvote from a coredev. Blocking this PR if there are people who would like to have this window away would be nonsense. However, thanks for adding the CMake param in :)

@nerzhul
Copy link
Member

nerzhul commented Mar 19, 2017

@SmallJoker i think covering the whole usage are good, but for a end user point, console it crap, just permit to enable it for developers is good

@adrido
Copy link
Contributor Author

adrido commented Mar 19, 2017

@adrido Yes, that's true. My comment should only represent my own opinion - not meant as a downvote from a coredev. Blocking this PR if there are people who would like to have this window away would be nonsense. However, thanks for adding the CMake param in :)

Phew 😅 I thought this would end up in one of that "controversial" PR that does not have any future.

This PR changes the subsystem to Windows, this have to be done on link time. Its not possible to change the subsystem on run time. There exist (hacky) ways within the Windows API to allocate a new cmd window at runtime, but I does not know if this would have the wanted effect.

@tobyplowy
Copy link
Contributor

@adrido i made an issue about this a while ago I'm happy that someone took the time to fix this

@nerzhul
Copy link
Member

nerzhul commented Mar 19, 2017

@sfan5 @Zeno- what is your opinion on this PR ?

@sfan5
Copy link
Member

sfan5 commented Mar 19, 2017

agree that it's useful

however it's missing the code that does the same for MinGW

@adrido
Copy link
Contributor Author

adrido commented Mar 19, 2017

however it's missing the code that does the same for MinGW

If this document is a trusted source, the command line arguments might be
--subsystem "windows" --entry=mainCRTStartup, but I does neither know if this is the official documentation, nor I can verify that it works. Feel free to test it and create a PR to this branch, or a separate PR later.

@Fixer-007
Copy link
Contributor

Fixer-007 commented Mar 19, 2017

From http:https://www.mingw.org/wiki/FAQ:

  • How do I remove DOS command windows?
  • In the link step add a "-mwindows" switch to the command line.

Also from https://gcc.gnu.org/onlinedocs/gcc/x86-Windows-Options.html:

-mwindows

This option is available for Cygwin and MinGW targets. It specifies that a GUI application is to be generated by instructing the linker to set the PE header subsystem type appropriately.

@Fixer-007
Copy link
Contributor

@adrido

@adrido
Copy link
Contributor Author

adrido commented Mar 27, 2017

Maybe the MinGW stuff should be added by someone who have more experience with MinGW than me. I does not like to blindly write code, that I cannot test.
I hope this can be considered to merge in current state, and someone else creates a separate PR for doing the same with MinGW later.

@Fixer-007
Copy link
Contributor

Fixer-007 commented Mar 27, 2017

I can test it right now, I already pasted info above. It does not look like complicated stuff, also main builds are made with mingw.

@sfan5
Copy link
Member

sfan5 commented Mar 28, 2017

I have used -mwindows before and can confirm that it has the intended effect (not tested it on MT tho).

@Fixer-007
Copy link
Contributor

Fixer-007 commented Mar 28, 2017

I've tried it with -mwindows on MINGW64 cross-compilation on debian and had a success - no cmd window, starts up and runs fine, icon is visible in taskbar (but not in alt+tab taskbar switcher, but I'm ok with that). Debug.txt is working.
Here is what I did:
in src/CmakeLists.txt I found line https://github.com/adrido/minetest/blob/e85637b4e3d44112ba04fdf0cc456482805692ab/src/CMakeLists.txt#L771
and made it like this:

	if(MINGW)
		set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
		if(NOT ENABLE_CMD_WINDOW)
			set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions -mwindows")
		endif()
	endif()

By default minetest is compiled without cmd window, if needed -DENABLE_CMD_WINDOW=1 enables it, I checked.
Demo:
default

Cmake setup used:

cmake .. \
	-DCMAKE_TOOLCHAIN_FILE=$toolchain_file \
	-DCMAKE_INSTALL_PREFIX=/tmp \
	-DVERSION_EXTRA=$git_hash \
	-DBUILD_CLIENT=1 -DBUILD_SERVER=0 \
	\
	-DENABLE_SOUND=1 \
	-DENABLE_CURL=1 \
	-DENABLE_GETTEXT=1 \
	-DENABLE_FREETYPE=1 \
	-DENABLE_LEVELDB=1 \
	\
	-DIRRLICHT_INCLUDE_DIR=$libdir/irrlicht/include \
	-DIRRLICHT_LIBRARY=$libdir/irrlicht/lib/Win64-gcc/libIrrlicht.dll.a \
	-DIRRLICHT_DLL=$libdir/irrlicht/bin/Win64-gcc/Irrlicht.dll \
	\
	-DZLIB_INCLUDE_DIR=$libdir/zlib/include \
	-DZLIB_LIBRARIES=$libdir/zlib/lib/libz.dll.a \
	-DZLIB_DLL=$libdir/zlib/bin/zlib1.dll \
	\
	-DLUA_INCLUDE_DIR=$libdir/luajit/include \
	-DLUA_LIBRARY=$libdir/luajit/libluajit.a \
	\
	-DOGG_INCLUDE_DIR=$libdir/libogg/include \
	-DOGG_LIBRARY=$libdir/libogg/lib/libogg.dll.a \
	-DOGG_DLL=$libdir/libogg/bin/libogg-0.dll \
	\
	-DVORBIS_INCLUDE_DIR=$libdir/libvorbis/include \
	-DVORBIS_LIBRARY=$libdir/libvorbis/lib/libvorbis.dll.a \
	-DVORBIS_DLL=$libdir/libvorbis/bin/libvorbis-0.dll \
	-DVORBISFILE_LIBRARY=$libdir/libvorbis/lib/libvorbisfile.dll.a \
	-DVORBISFILE_DLL=$libdir/libvorbis/bin/libvorbisfile-3.dll \
	\
	-DOPENAL_INCLUDE_DIR=$libdir/openal_stripped/include/AL \
	-DOPENAL_LIBRARY=$libdir/openal_stripped/lib/libOpenAL32.dll.a \
	-DOPENAL_DLL=$libdir/openal_stripped/bin/OpenAL32.dll \
	\
	-DCURL_DLL=$libdir/libcurl/bin/libcurl-4.dll \
	-DCURL_INCLUDE_DIR=$libdir/libcurl/include \
	-DCURL_LIBRARY=$libdir/libcurl/lib/libcurl.dll.a \
	\
	-DGETTEXT_MSGFMT=`which msgfmt` \
	-DGETTEXT_DLL=$libdir/gettext/bin/libintl-8.dll \
	-DGETTEXT_ICONV_DLL=$libdir/gettext/bin/libiconv-2.dll \
	-DGETTEXT_INCLUDE_DIR=$libdir/gettext/include \
	-DGETTEXT_LIBRARY=$libdir/gettext/lib/libintl.dll.a \
	\
	-DFREETYPE_INCLUDE_DIR_freetype2=$libdir/freetype/include/freetype2 \
	-DFREETYPE_INCLUDE_DIR_ft2build=$libdir/freetype/include/freetype2 \
	-DFREETYPE_LIBRARY=$libdir/freetype/lib/libfreetype.dll.a \
	-DFREETYPE_DLL=$libdir/freetype/bin/libfreetype-6.dll \
	\
	-DSQLITE3_INCLUDE_DIR=$libdir/sqlite3/include \
	-DSQLITE3_LIBRARY=$libdir/sqlite3/lib/libsqlite3.dll.a \
	-DSQLITE3_DLL=$libdir/sqlite3/bin/libsqlite3-0.dll \
	\
	-DLEVELDB_INCLUDE_DIR=$libdir/leveldb/include \
	-DLEVELDB_LIBRARY=$libdir/leveldb/lib/libleveldb.dll.a \
	-DLEVELDB_DLL=$libdir/leveldb/bin/libleveldb.dll 

@adrido
Copy link
Contributor Author

adrido commented Mar 29, 2017

Thanks for testing, but if it does not show up inside the ALT-TAB task switcher, something seems wrong to me. Or could that be because of your Windows version? It looks a bit older.

@Fixer-007
Copy link
Contributor

Fixer-007 commented Mar 29, 2017

Icon in alt-tab mode is visible in console window, if you disable console, the behaviour for main window is the same as before. That can be improved later. I'm interested in getting this PR in for both msvc and mingw.

@adrido
Copy link
Contributor Author

adrido commented Mar 29, 2017

Ahh Sorry, did not understand you correctly. I understand that the whole Minetest application is not displayed in Task switcher 😆 . The Icon that is displayed in the Taskbar is the "Application Icon" that icon that's displayed in the "Classic" Task switcher is the "Window Icon". Since Windows 7 (Vista maybe too) the Window is displayed as a thumbnail. As long as Minetest does not have a proper Window Icon set there is nothing to display. If I remember correctly, the Window icon is hard coded by the Irrlicht engine to "irrlicht.ico"
Dont know if there exist other ways to set it, but just copy the "minetest-icon.ico" from misc\ to the "bin\" folder and rename it to "irrlicht.ico". Then it should display the proper Window Icon 😉.

Could you please check, if it also work if you do:

	if(MINGW)
		set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
		if(NOT ENABLE_CMD_WINDOW)
			set(OTHER_FLAGS "${OTHER_FLAGS} -mwindows")
		endif()
	endif()

@Fixer-007
Copy link
Contributor

Dont know if there exist other ways to set it, but just copy the "minetest-icon.ico" from misc\ to the "bin" folder and rename it to "irrlicht.ico". Then it should display the proper Window Icon 😉.

Indeed! I did this and now I see proper icon for minetest everywhere (Windows 7 sp1)

Could you please check, if it also work if you do

Yes it does work.

@rubenwardy
Copy link
Member

Is it possible to create a batch file to start with the console?

@adrido
Copy link
Contributor Author

adrido commented Apr 1, 2017

No, thats not possible. This is changing the subsystem where the application is running on. This have to be made at compile/ link time, and cannot be done on run time.

@Fixer-007
Copy link
Contributor

Fixer-007 commented Apr 1, 2017

Tested. Thanks 👍

@tenplus1
Copy link
Contributor

tenplus1 commented Apr 1, 2017

Removing console would be a pain for mod makers when it comes to errors, having to refer to debug.txt all the time instead of simply looking at the cmd window... Also, if cmd was removed and minetest was made a windows program only a console would have to be added for just such checking so we would need someone to add that beforehand, which in itself comes with separate problems like when Mt crashes and closes the console window with it.

@Fixer-007
Copy link
Contributor

@Fixer-007
Copy link
Contributor

Fixer-007 commented Apr 1, 2017

@adrido
Copy link
Contributor Author

adrido commented Apr 1, 2017

I found a simple way to dynamically allocate a console window within pidgin source code. [sarcasm] And it also leads all that useless crap to that console too (like it did before). hope that spam makes people happy again 😛 [/sarcasm]
screenshot 3

@Fixer-007 you answered while i was compiling and taking that screenshot. Its similar to the last answer of your link. 😆

That solution does require some more programming to do it right, so I may need some more days.
Just a question to coredevs, how should the commandline argument be called to make the console visible?

@celeron55
Copy link
Member

What happens if Minetest is started from a console? Does it create a new console or use the existing one?

@celeron55
Copy link
Member

For that option, I'd suggest simply "--console".

@Ezhh
Copy link
Contributor

Ezhh commented Apr 1, 2017

I use console a lot from Windows version of MT. If it can be an option to enable, and then I run the game as usual and the console is there, it's great, otherwise this will be a huge annoyance. (And if it's not there by default, having to enable an option each time I test a client (and, I assume, then restart the game?) would also be a (slightly) lesser annoyance by itself.

@adrido
Copy link
Contributor Author

adrido commented Apr 1, 2017

My idea is to check if AttachConsole(ATTACH_PARENT_PROCESS) is successfull, then its called from a parrent console. If not, allocate a new console. So this is better then the console window before, because it does not open a new console if there is already one.I Just did some tests, and it works as expected. :-)
I does currently not know what happens if the parent process is not a cmd window. I assume it does not open a cmd window

@celeron55
Copy link
Member

It looks like we need to also add the option to pop up the console window like it currently does, and also make that behavior configurable in minetest.conf. We can't just decide people shouldn't like the current behavior.

@rubenwardy
Copy link
Member

--console is enough if you also add a batch file
Whichever is cleaner

@adrido adrido force-pushed the no-cmd-on-release branch 2 times, most recently from 4000365 to 36f22f3 Compare April 1, 2017 19:36
@adrido
Copy link
Contributor Author

adrido commented Apr 1, 2017

should work now except for reading the setting. I does not find the point when the settings-file got parsed, and g_settings is available.

@Fixer-007
Copy link
Contributor

Status?

@nerzhul nerzhul added this to the 0.4.16 milestone Apr 6, 2017
@nerzhul
Copy link
Member

nerzhul commented Apr 6, 2017

i don't like windows but it's inacceptable for end users to have an opened cmd, minetest is not a Dos game on Windows 95

@sofar
Copy link
Contributor

sofar commented Apr 7, 2017

Looking at this patch it adds all the options needed for the console to be easily reachable:

  • --console option
  • minetest.conf option
  • console is started when relevant (e.g. server is started)

So, 👍 (But I can't test).

@nerzhul nerzhul merged commit 676951d into minetest:master Apr 7, 2017
@Fixer-007
Copy link
Contributor

Fixer-007 commented Apr 7, 2017

Got very nice results for now on mingw64 cross-compile from lin to win (updating):

  • starts without console by default
  • command line options work
  • minetest --console via link or cmd opens the console
  • minetest with "enable_console = true" in minetest.conf also opens console
  • debug.txt and console output seems good, nothing suspicious
  • enable_console is missing from settingtypes and minetest.conf (will be added in trivial PR)
  • console is enabled and opened by default on "Debug" builds

Finally that CMD window is gone, Console can be enabled easily via many ways, everyone is satisfied.
Big thanks to @adrido 👍

@nerzhul nerzhul added this to Done in Minetest 0.4.16 Apr 29, 2017
@adrido adrido deleted the no-cmd-on-release branch August 19, 2017 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Build CMake, build scripts, official builds, compiler and linker errors >= Two approvals ✅ ✅
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet