merge commit by Wuzzy that allows drop down lists in team edit screen to display more items at a time, if possible
authorsheepluva
Sat, 23 Apr 2016 12:02:39 +0200
changeset 11678 86cacfde14c4
parent 11676 51c4ea6d7f91 (diff)
parent 11677 98545abbedb3 (current diff)
child 11680 8efe91eae41e
merge commit by Wuzzy that allows drop down lists in team edit screen to display more items at a time, if possible
--- a/.travis.yml	Mon Apr 18 18:15:20 2016 +0200
+++ b/.travis.yml	Sat Apr 23 12:02:39 2016 +0200
@@ -44,7 +44,7 @@
     sudo apt-get install debhelper cmake dpkg-dev libqt4-dev qt4-qmake libphysfs-dev libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev libsdl2-net-dev bzip2 ghc libghc-mtl-dev libghc-parsec3-dev libghc-bytestring-show-dev libghc-vector-dev libghc-zlib-dev libghc-random-dev libghc-stm-dev libghc-network-dev libghc-dataenc-dev libghc-hslogger-dev libghc-utf8-string-dev libghc-sha-dev libghc-entropy-dev liblua5.1-0-dev imagemagick fpc fp-compiler fp-units-misc libpng-dev fp-units-gfx libavcodec-dev libavformat-dev libglew1.6-dev
   elif [ "$TRAVIS_OS_NAME" == "osx" ]; then
     brew install fpc glew qt physfs lua51 sdl2 sdl2_image sdl2_net sdl2_ttf ffmpeg ghc cabal-install
-    brew install sdl2_mixer --with-vorbis
+    brew install sdl2_mixer --with-libvorbis
     # use cabal install haskell deps, pas2c ones are covered by server
     if [[ "$BUILD_ARGS" != *"NOSERVER"* ]]; then
       cabal update
--- a/CMakeLists.txt	Mon Apr 18 18:15:20 2016 +0200
+++ b/CMakeLists.txt	Sat Apr 23 12:02:39 2016 +0200
@@ -41,6 +41,7 @@
 option(SKIPBUNDLE "Do not create relocate bundle (off)" OFF)
 
 option(BUILD_ENGINE_C "Compile hwengine as native C (off)" OFF)
+option(BUILD_ENGINE_JS "Compile hwengine as javascript (off)" OFF)
 option(GL2 "Enable OpenGL 2 rendering !!!EXPERIMENTAL - DO NOT USE!!! [default: off)" OFF)
 
 set(GHFLAGS "" CACHE STRING "Additional Haskell flags")
@@ -50,6 +51,22 @@
 
 option(NOVERSIONINFOUPDATE "Disable update of version_info.txt. To be used if source is in a git/repo that is NOT the hedgewars repo" OFF)
 
+
+if(BUILD_ENGINE_JS)
+    if(NOT CMAKE_TOOLCHAIN_FILE)
+        message(FATAL_ERROR "Missing emscripten toolchain file\nRerun cmake with -DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/cmake_modules/Platform/Emscripten.cmake")
+    endif()
+
+    set(BUILD_ENGINE_C ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(NOAUTOUPDATE ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(PHYSFS_SYSTEM OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(LUA_SYSTEM OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(NOVIDEOREC ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(NOSERVER ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(GL2 ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+    set(BUILD_SHARED_LIBS OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE)
+endif()
+
 #system paths for finding required fonts (see share/hedgewars/Data/fonts)
 #subdirectories will NOT be searched.
 #all fonts that can't be found will be bundled with hedgewars
@@ -90,7 +107,10 @@
 
 
 #perform safe check that enable/disable compilation features
-include(${CMAKE_MODULE_PATH}/compilerchecks.cmake)
+#skip when crosscompiling to javascript
+if(NOT BUILD_ENGINE_JS)
+    include(${CMAKE_MODULE_PATH}/compilerchecks.cmake)
+endif()
 
 #set default compiler flags
 add_flag_append(CMAKE_C_FLAGS "-Wall -pipe")
@@ -135,7 +155,7 @@
 
 
 #build engine without freepascal
-if(BUILD_ENGINE_C)
+if(BUILD_ENGINE_C AND NOT BUILD_ENGINE_JS)
     find_package(Clang REQUIRED)
 
     if(${CLANG_VERSION} VERSION_LESS "3.0")
@@ -232,9 +252,13 @@
 if(ANDROID)
     add_subdirectory(project_files/Android-build)
 else(ANDROID)
+    #skip frontend for javascript
+    if(NOT BUILD_ENGINE_JS)
+        add_subdirectory(QTfrontend)
+        add_subdirectory(share)
+    endif()
+
     add_subdirectory(bin)
-    add_subdirectory(QTfrontend)
-    add_subdirectory(share)
     add_subdirectory(tools)
 endif(ANDROID)
 
--- a/QTfrontend/ui/widget/feedbackdialog.cpp	Mon Apr 18 18:15:20 2016 +0200
+++ b/QTfrontend/ui/widget/feedbackdialog.cpp	Sat Apr 23 12:02:39 2016 +0200
@@ -61,7 +61,6 @@
     setWindowFlags(Qt::Sheet);
     setWindowModality(Qt::WindowModal);
     setWindowTitle(tr("Feedback"));
-    setMinimumSize(700, 460);
     resize(700, 460);
     setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
 
@@ -71,11 +70,9 @@
     /* Top layout */
 
     QVBoxLayout * pageLayout = new QVBoxLayout();
-    QHBoxLayout * summaryLayout = new QHBoxLayout();
-    QHBoxLayout * emailLayout = new QHBoxLayout();
-    QHBoxLayout * descriptionLayout = new QHBoxLayout();
-    QHBoxLayout * combinedTopLayout = new QHBoxLayout();
-    QHBoxLayout * systemLayout = new QHBoxLayout();
+    QGridLayout * feedbackLayout = new QGridLayout();
+
+    setStyleSheet("QPushButton { padding: 5px }");
 
     info = new QLabel();
     info->setText(QString(
@@ -96,65 +93,45 @@
     info->setOpenExternalLinks(true);
     pageLayout->addWidget(info);
 
-    QVBoxLayout * summaryEmailLayout = new QVBoxLayout();
-
-    const int labelWidth = 90;
-
     label_email = new QLabel();
     label_email->setText(QLabel::tr("Your Email"));
-    label_email->setFixedWidth(labelWidth);
-    emailLayout->addWidget(label_email);
     email = new QLineEdit();
-    emailLayout->addWidget(email);
-    summaryEmailLayout->addLayout(emailLayout);
+    feedbackLayout->addWidget(label_email, 0, 0);
+    feedbackLayout->addWidget(email, 0, 1);
 
     label_summary = new QLabel();
     label_summary->setText(QLabel::tr("Summary"));
-    label_summary->setFixedWidth(labelWidth);
-    summaryLayout->addWidget(label_summary);
     summary = new QLineEdit();
-    summaryLayout->addWidget(summary);
-    summaryEmailLayout->addLayout(summaryLayout);
-
-    combinedTopLayout->addLayout(summaryEmailLayout);
+    feedbackLayout->addWidget(label_summary, 1, 0);
+    feedbackLayout->addWidget(summary, 1, 1);
 
     CheckSendSpecs = new QCheckBox();
     CheckSendSpecs->setText(QLabel::tr("Send system information"));
     CheckSendSpecs->setChecked(true);
-    systemLayout->addWidget(CheckSendSpecs);
     BtnViewInfo = new QPushButton(tr("View"));
-    systemLayout->addWidget(BtnViewInfo, 1);
-    BtnViewInfo->setFixedSize(60, 30);
+    BtnViewInfo->setFixedHeight(40);
+    feedbackLayout->addWidget(CheckSendSpecs, 0, 2, 2, 1);
+    feedbackLayout->addWidget(BtnViewInfo, 0, 3, 2, 1);
     connect(BtnViewInfo, SIGNAL(clicked()), this, SLOT(ShowSpecs()));
-    combinedTopLayout->addLayout(systemLayout);
 
-    combinedTopLayout->setStretch(0, 1);
-    combinedTopLayout->insertSpacing(1, 20);
-
-    pageLayout->addLayout(combinedTopLayout);
 
     label_description = new QLabel();
     label_description->setText(QLabel::tr("Description"));
-    label_description->setFixedWidth(labelWidth);
-    descriptionLayout->addWidget(label_description, 0, Qt::AlignTop);
     description = new QTextBrowser();
     description->setReadOnly(false);
-    descriptionLayout->addWidget(description);
-    pageLayout->addLayout(descriptionLayout);
+    feedbackLayout->addWidget(label_description, 2, 0);
+    feedbackLayout->addWidget(description, 2, 1, 1, 3);
 
     /* Bottom layout */
 
-    QHBoxLayout * bottomLayout = new QHBoxLayout();
     QHBoxLayout * captchaLayout = new QHBoxLayout();
     QVBoxLayout * captchaInputLayout = new QVBoxLayout();
 
     QPushButton * BtnCancel = new QPushButton(tr("Cancel"));
-    bottomLayout->addWidget(BtnCancel, 0);
-    BtnCancel->setFixedSize(100, 40);
+    feedbackLayout->addWidget(BtnCancel, 3, 0);
+    BtnCancel->setFixedHeight(40);
     connect(BtnCancel, SIGNAL(clicked()), this, SLOT(reject()));
 
-    bottomLayout->insertStretch(1);
-
     label_captcha = new QLabel();
     label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px");
     label_captcha->setText("loading<br>captcha");
@@ -166,27 +143,27 @@
     captchaInputLayout->addWidget(label_captcha_input);
     captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom);
     captcha_code = new QLineEdit();
-    captcha_code->setFixedSize(165, 30);
+    captcha_code->setFixedHeight(30);
     captchaInputLayout->addWidget(captcha_code);
     captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop);
     captchaLayout->addLayout(captchaInputLayout);
     captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft);
 
-    bottomLayout->addLayout(captchaLayout);
-    bottomLayout->addSpacing(40);
+    QWidget * captchaLayoutWidget = new QWidget();
+    captchaLayoutWidget->setContentsMargins(0, 0, 0, 0);
+    captchaLayoutWidget->setLayout(captchaLayout);
+    feedbackLayout->addWidget(captchaLayoutWidget, 3, 1, 1, 2);
 
     // TODO: Set green arrow icon for send button (:/res/Start.png)
     BtnSend = new QPushButton(tr("Send Feedback"));
-    bottomLayout->addWidget(BtnSend, 0);
-    BtnSend->setFixedSize(120, 40);
+    feedbackLayout->addWidget(BtnSend, 3, 3);
+    BtnSend->setFixedHeight(40);
     connect(BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
 
-    bottomLayout->setStretchFactor(captchaLayout, 0);
-    bottomLayout->setStretchFactor(BtnSend, 1);
+    pageLayout->addLayout(feedbackLayout);
 
     QVBoxLayout * dialogLayout = new QVBoxLayout(this);
     dialogLayout->addLayout(pageLayout, 1);
-    dialogLayout->addLayout(bottomLayout);
 
     LoadCaptchaImage();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/CMakeSystemSpecificInformation.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -0,0 +1,123 @@
+# XXX Emscripten:
+# This file is copied as-is from the CMake source tree. Due to how CMake
+# platform toolchain files work, we must have a copy of this file located
+# relative to Emscripten platform toolchain file, or file inclusion order
+# in cmGlobalGenerator::EnableLanguage will not find Emscripten.cmake
+# toolchain file, and as a result, it is not possible to set the default
+# compilation output suffix to .js, and as a consequence the script
+# check_function_exists() will not function properly (it will try to
+# build to wrong file suffix)
+
+# CMake - Cross Platform Makefile Generator
+# Copyright 2000-2014 Kitware, Inc.
+# Copyright 2000-2011 Insight Software Consortium
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+
+# * Neither the names of Kitware, Inc., the Insight Software Consortium,
+#   nor the names of their contributors may be used to endorse or promote
+#   products derived from this software without specific prior written
+#   permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# ------------------------------------------------------------------------------
+
+# The above copyright and license notice applies to distributions of
+# CMake in source and binary form.  Some source files contain additional
+# notices of original copyright by their contributors; see each source
+# for details.  Third-party software packages supplied with CMake under
+# compatible licenses provide their own copyright notices documented in
+# corresponding subdirectories.
+
+# ------------------------------------------------------------------------------
+
+# CMake was initially developed by Kitware with the following sponsorship:
+
+#  * National Library of Medicine at the National Institutes of Health
+#    as part of the Insight Segmentation and Registration Toolkit (ITK).
+
+#  * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
+#    Visualization Initiative.
+
+#  * National Alliance for Medical Image Computing (NAMIC) is funded by the
+#    National Institutes of Health through the NIH Roadmap for Medical Research,
+#    Grant U54 EB005149.
+
+#  * Kitware, Inc.
+
+# This file is included by cmGlobalGenerator::EnableLanguage.
+# It is included after the compiler has been determined, so
+# we know things like the compiler name and if the compiler is gnu.
+
+# before cmake 2.6 these variables were set in cmMakefile.cxx. This is still
+# done to keep scripts and custom language and compiler modules working.
+# But they are reset here and set again in the platform files for the target
+# platform, so they can be used for testing the target platform instead
+# of testing the host platform.
+set(APPLE  )
+set(UNIX   )
+set(CYGWIN )
+set(WIN32  )
+
+
+# include Generic system information
+include(CMakeGenericSystem)
+
+# 2. now include SystemName.cmake file to set the system specific information
+set(CMAKE_SYSTEM_INFO_FILE Platform/${CMAKE_SYSTEM_NAME})
+
+include(${CMAKE_SYSTEM_INFO_FILE} OPTIONAL RESULT_VARIABLE _INCLUDED_SYSTEM_INFO_FILE)
+
+if(NOT _INCLUDED_SYSTEM_INFO_FILE)
+  message("System is unknown to cmake, create:\n${CMAKE_SYSTEM_INFO_FILE}"
+          " to use this system, please send your config file to "
+          "cmake@www.cmake.org so it can be added to cmake")
+  if(EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
+    configure_file(${CMAKE_BINARY_DIR}/CMakeCache.txt
+                   ${CMAKE_BINARY_DIR}/CopyOfCMakeCache.txt COPYONLY)
+    message("Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. "
+            "Please send that file to cmake@www.cmake.org.")
+   endif()
+endif()
+
+
+# optionally include a file which can do extra-generator specific things, e.g.
+# CMakeFindEclipseCDT4.cmake asks gcc for the system include dirs for the Eclipse CDT4 generator
+if(CMAKE_EXTRA_GENERATOR)
+  string(REPLACE " " "" _CMAKE_EXTRA_GENERATOR_NO_SPACES ${CMAKE_EXTRA_GENERATOR} )
+  include("CMakeFind${_CMAKE_EXTRA_GENERATOR_NO_SPACES}" OPTIONAL)
+endif()
+
+
+# for most systems a module is the same as a shared library
+# so unless the variable CMAKE_MODULE_EXISTS is set just
+# copy the values from the LIBRARY variables
+# this has to be done after the system information has been loaded
+if(NOT CMAKE_MODULE_EXISTS)
+  set(CMAKE_SHARED_MODULE_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}")
+  set(CMAKE_SHARED_MODULE_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
+endif()
+
+
+set(CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED 1)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/CheckTypeSize.c.in	Sat Apr 23 12:02:39 2016 +0200
@@ -0,0 +1,37 @@
+@headers@
+
+#undef KEY
+#if defined(__i386)
+# define KEY '_','_','i','3','8','6'
+#elif defined(__x86_64)
+# define KEY '_','_','x','8','6','_','6','4'
+#elif defined(__ppc__)
+# define KEY '_','_','p','p','c','_','_'
+#elif defined(__ppc64__)
+# define KEY '_','_','p','p','c','6','4','_','_'
+#endif
+
+#define SIZE (sizeof(@type@))
+char info_size[] =  {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
+  ('0' + ((SIZE / 10000)%10)),
+  ('0' + ((SIZE / 1000)%10)),
+  ('0' + ((SIZE / 100)%10)),
+  ('0' + ((SIZE / 10)%10)),
+  ('0' +  (SIZE    % 10)),
+  ']',
+#ifdef KEY
+  ' ','k','e','y','[', KEY, ']',
+#endif
+  '\0'};
+
+#ifdef __CLASSIC_C__
+int main(argc, argv) int argc; char *argv[];
+#else
+int main(int argc, char *argv[])
+#endif
+{
+  int require = 0;
+  require += info_size[argc];
+  (void)argv;
+  return SIZE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/CheckTypeSize.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -0,0 +1,231 @@
+#.rst:
+# CheckTypeSize
+# -------------
+#
+# Check sizeof a type
+#
+# ::
+#
+#   CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY]
+#                                 [LANGUAGE <language>])
+#
+# Check if the type exists and determine its size.  On return,
+# "HAVE_${VARIABLE}" holds the existence of the type, and "${VARIABLE}"
+# holds one of the following:
+#
+# ::
+#
+#    <size> = type has non-zero size <size>
+#    "0"    = type has arch-dependent size (see below)
+#    ""     = type does not exist
+#
+# Both ``HAVE_${VARIABLE}`` and ``${VARIABLE}`` will be created as internal
+# cache variables.
+#
+# Furthermore, the variable "${VARIABLE}_CODE" holds C preprocessor code
+# to define the macro "${VARIABLE}" to the size of the type, or leave
+# the macro undefined if the type does not exist.
+#
+# The variable "${VARIABLE}" may be "0" when CMAKE_OSX_ARCHITECTURES has
+# multiple architectures for building OS X universal binaries.  This
+# indicates that the type size varies across architectures.  In this
+# case "${VARIABLE}_CODE" contains C preprocessor tests mapping from
+# each architecture macro to the corresponding type size.  The list of
+# architecture macros is stored in "${VARIABLE}_KEYS", and the value for
+# each key is stored in "${VARIABLE}-${KEY}".
+#
+# If the BUILTIN_TYPES_ONLY option is not given, the macro checks for
+# headers <sys/types.h>, <stdint.h>, and <stddef.h>, and saves results
+# in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H.  The type size
+# check automatically includes the available headers, thus supporting
+# checks of types defined in the headers.
+#
+# If LANGUAGE is set, the specified compiler will be used to perform the
+# check. Acceptable values are C and CXX
+#
+# Despite the name of the macro you may use it to check the size of more
+# complex expressions, too.  To check e.g.  for the size of a struct
+# member you can do something like this:
+#
+# ::
+#
+#   check_type_size("((struct something*)0)->member" SIZEOF_MEMBER)
+#
+#
+#
+# The following variables may be set before calling this macro to modify
+# the way the check is run:
+#
+# ::
+#
+#   CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#   CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#   CMAKE_REQUIRED_INCLUDES = list of include directories
+#   CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+#   CMAKE_REQUIRED_QUIET = execute quietly without messages
+#   CMAKE_EXTRA_INCLUDE_FILES = list of extra headers to include
+
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+include(CheckIncludeFile)
+include(CheckIncludeFileCXX)
+
+cmake_policy(PUSH)
+cmake_policy(VERSION 3.0)
+
+get_filename_component(__check_type_size_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+#-----------------------------------------------------------------------------
+# Helper function.  DO NOT CALL DIRECTLY.
+function(__check_type_size_impl type var map builtin language)
+  if(NOT CMAKE_REQUIRED_QUIET)
+    message(STATUS "Check size of ${type}")
+  endif()
+
+  # Include header files.
+  set(headers)
+  if(builtin)
+    if(HAVE_SYS_TYPES_H)
+      set(headers "${headers}#include <sys/types.h>\n")
+    endif()
+    if(HAVE_STDINT_H)
+      set(headers "${headers}#include <stdint.h>\n")
+    endif()
+    if(HAVE_STDDEF_H)
+      set(headers "${headers}#include <stddef.h>\n")
+    endif()
+  endif()
+  foreach(h ${CMAKE_EXTRA_INCLUDE_FILES})
+    set(headers "${headers}#include \"${h}\"\n")
+  endforeach()
+
+  # Perform the check.
+
+  if("${language}" STREQUAL "C")
+    set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c)
+  elseif("${language}" STREQUAL "CXX")
+    set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp)
+  else()
+    message(FATAL_ERROR "Unknown language:\n  ${language}\nSupported languages: C, CXX.\n")
+  endif()
+  set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin)
+  configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY)
+  try_run(${var}_run_result HAVE_${var} ${CMAKE_BINARY_DIR} ${src}
+    COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+    LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
+    CMAKE_FLAGS
+      "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}"
+      "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
+    RUN_OUTPUT_VARIABLE ${var}_run_output
+    COMPILE_OUTPUT_VARIABLE output
+    )
+
+  if(${HAVE_${var}} AND NOT "${${var}_run_result}" STREQUAL "FAILED_TO_RUN")
+    set(${var} ${${var}_run_result})
+    if(NOT CMAKE_REQUIRED_QUIET)
+      message(STATUS "Check size of ${type} - done")
+    endif()
+    file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+      "Determining size of ${type} passed with the following output:\n${output}\n\n")
+    set(${var} "${${var}}" CACHE INTERNAL "CHECK_TYPE_SIZE: sizeof(${type})")
+  else()
+    # The check failed to compile.
+    if(NOT CMAKE_REQUIRED_QUIET)
+      message(STATUS "Check size of ${type} - failed")
+    endif()
+    file(READ ${src} content)
+    file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+      "Determining size of ${type} failed with the following output:\n${output}\n${src}:\n${content}\n\n")
+    set(${var} "" CACHE INTERNAL "CHECK_TYPE_SIZE: ${type} unknown")
+    file(REMOVE ${map})
+  endif()
+endfunction()
+
+#-----------------------------------------------------------------------------
+macro(CHECK_TYPE_SIZE TYPE VARIABLE)
+  # parse arguments
+  unset(doing)
+  foreach(arg ${ARGN})
+    if("x${arg}" STREQUAL "xBUILTIN_TYPES_ONLY")
+      set(_CHECK_TYPE_SIZE_${arg} 1)
+      unset(doing)
+    elseif("x${arg}" STREQUAL "xLANGUAGE") # change to MATCHES for more keys
+      set(doing "${arg}")
+      set(_CHECK_TYPE_SIZE_${doing} "")
+    elseif("x${doing}" STREQUAL "xLANGUAGE")
+      set(_CHECK_TYPE_SIZE_${doing} "${arg}")
+      unset(doing)
+    else()
+      message(FATAL_ERROR "Unknown argument:\n  ${arg}\n")
+    endif()
+  endforeach()
+  if("x${doing}" MATCHES "^x(LANGUAGE)$")
+    message(FATAL_ERROR "Missing argument:\n  ${doing} arguments requires a value\n")
+  endif()
+  if(DEFINED _CHECK_TYPE_SIZE_LANGUAGE)
+    if(NOT "x${_CHECK_TYPE_SIZE_LANGUAGE}" MATCHES "^x(C|CXX)$")
+      message(FATAL_ERROR "Unknown language:\n  ${_CHECK_TYPE_SIZE_LANGUAGE}.\nSupported languages: C, CXX.\n")
+    endif()
+    set(_language ${_CHECK_TYPE_SIZE_LANGUAGE})
+  else()
+    set(_language C)
+  endif()
+
+  # Optionally check for standard headers.
+  if(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
+    set(_builtin 0)
+  else()
+    set(_builtin 1)
+    if("${_language}" STREQUAL "C")
+      check_include_file(sys/types.h HAVE_SYS_TYPES_H)
+      check_include_file(stdint.h HAVE_STDINT_H)
+      check_include_file(stddef.h HAVE_STDDEF_H)
+    elseif("${_language}" STREQUAL "CXX")
+      check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
+      check_include_file_cxx(stdint.h HAVE_STDINT_H)
+      check_include_file_cxx(stddef.h HAVE_STDDEF_H)
+    endif()
+  endif()
+  unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
+  unset(_CHECK_TYPE_SIZE_LANGUAGE)
+
+  # Compute or load the size or size map.
+  set(${VARIABLE}_KEYS)
+  set(_map_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${VARIABLE}.cmake)
+  if(NOT DEFINED HAVE_${VARIABLE})
+    __check_type_size_impl(${TYPE} ${VARIABLE} ${_map_file} ${_builtin} ${_language})
+  endif()
+  include(${_map_file} OPTIONAL)
+  set(_map_file)
+  set(_builtin)
+
+  # Create preprocessor code.
+  if(${VARIABLE}_KEYS)
+    set(${VARIABLE}_CODE)
+    set(_if if)
+    foreach(key ${${VARIABLE}_KEYS})
+      set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#${_if} defined(${key})\n# define ${VARIABLE} ${${VARIABLE}-${key}}\n")
+      set(_if elif)
+    endforeach()
+    set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#else\n# error ${VARIABLE} unknown\n#endif")
+    set(_if)
+  elseif(${VARIABLE})
+    set(${VARIABLE}_CODE "#define ${VARIABLE} ${${VARIABLE}}")
+  else()
+    set(${VARIABLE}_CODE "/* #undef ${VARIABLE} */")
+  endif()
+endmacro()
+
+#-----------------------------------------------------------------------------
+cmake_policy(POP)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/FindEmscripten.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -0,0 +1,36 @@
+# - Try to find the Clang/LLVM executable
+# Once done this will define
+#
+#  EMSCRIPTEN_FOUND       - system has Clang
+#  EMSCRIPTEN_VERSION     - Clang version
+#  EMSCRIPTEN_EXECUTABLE  - Clang executable
+#
+# Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+find_program(EMSCRIPTEN_EXECUTABLE
+        NAMES emcc
+        PATHS /opt/local/bin /usr/local/bin /usr/bin)
+
+if (EMSCRIPTEN_EXECUTABLE)
+    execute_process(COMMAND ${EMSCRIPTEN_EXECUTABLE} -v
+                    OUTPUT_VARIABLE EMSCRIPTEN_VERSION_OUTPUT
+                    ERROR_VARIABLE EMSCRIPTEN_VERSION_ERROR
+                    RESULT_VARIABLE EMSCRIPTEN_VERSION_RESULT
+                    OUTPUT_STRIP_TRAILING_WHITESPACE
+                    )
+
+    if(${EMSCRIPTEN_VERSION_RESULT} EQUAL 0)
+        string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" EMSCRIPTEN_VERSION "${EMSCRIPTEN_VERSION_OUTPUT}")
+        string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" EMSCRIPTEN_VERSION "${EMSCRIPTEN_VERSION}")
+    else()
+        message(SEND_ERROR "Command \"${EMSCRIPTEN_EXECUTABLE} --version\" failed with output: ${EMSCRIPTEN_VERSION_ERROR}")
+    endif()
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Emscripten DEFAULT_MSG EMSCRIPTEN_EXECUTABLE EMSCRIPTEN_VERSION)
+mark_as_advanced(EMSCRIPTEN_VERSION)
+
--- a/cmake_modules/FindGLEW.cmake	Mon Apr 18 18:15:20 2016 +0200
+++ b/cmake_modules/FindGLEW.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -34,6 +34,11 @@
             $ENV{PROGRAMFILES}/GLEW/lib
             DOC "The GLEW library")
 
+if(BUILD_ENGINE_JS)
+    set(GLEW_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include")
+    SET(GLEW_LIBRARY "glew_emscripten_internal")
+endif()
+
 find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_DIR)
 mark_as_advanced(GLEW_LIBRARY GLEW_INCLUDE_DIR)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/FindOpenGL.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -0,0 +1,209 @@
+#.rst:
+# FindOpenGL
+# ----------
+#
+# FindModule for OpenGL and GLU.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module sets the following variables:
+#
+# ``OPENGL_FOUND``
+#  True, if the system has OpenGL.
+# ``OPENGL_XMESA_FOUND``
+#  True, if the system has XMESA.
+# ``OPENGL_GLU_FOUND``
+#  True, if the system has GLU.
+# ``OPENGL_INCLUDE_DIR``
+#  Path to the OpenGL include directory.
+# ``OPENGL_LIBRARIES``
+#  Paths to the OpenGL and GLU libraries.
+#
+# If you want to use just GL you can use these values:
+#
+# ``OPENGL_gl_LIBRARY``
+#  Path to the OpenGL library.
+# ``OPENGL_glu_LIBRARY``
+#  Path to the GLU library.
+#
+# OSX Specific
+# ^^^^^^^^^^^^
+#
+# On OSX default to using the framework version of OpenGL. People will
+# have to change the cache values of OPENGL_glu_LIBRARY and
+# OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX.
+
+
+#=============================================================================
+# Copyright 2001-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
+
+if (CYGWIN)
+
+  find_path(OPENGL_INCLUDE_DIR GL/gl.h )
+  list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
+
+  find_library(OPENGL_gl_LIBRARY opengl32 )
+
+  find_library(OPENGL_glu_LIBRARY glu32 )
+
+elseif (WIN32)
+
+  if(BORLAND)
+    set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
+    set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
+  else()
+    set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
+    set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
+  endif()
+
+elseif (APPLE)
+
+  # The OpenGL.framework provides both gl and glu
+  find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X")
+  find_library(OPENGL_glu_LIBRARY OpenGL DOC
+    "GLU library for OS X (usually same as OpenGL library)")
+  find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OS X")
+  list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
+
+else()
+  if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
+    # Handle HP-UX cases where we only want to find OpenGL in either hpux64
+    # or hpux32 depending on if we're doing a 64 bit build.
+    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+      set(_OPENGL_LIB_PATH
+        /opt/graphics/OpenGL/lib/hpux32/)
+    else()
+      set(_OPENGL_LIB_PATH
+        /opt/graphics/OpenGL/lib/hpux64/
+        /opt/graphics/OpenGL/lib/pa20_64)
+    endif()
+  elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku)
+    set(_OPENGL_LIB_PATH
+      /boot/develop/lib/x86)
+    set(_OPENGL_INCLUDE_PATH
+      /boot/develop/headers/os/opengl)
+  endif()
+
+  # The first line below is to make sure that the proper headers
+  # are used on a Linux machine with the NVidia drivers installed.
+  # They replace Mesa with NVidia's own library but normally do not
+  # install headers and that causes the linking to
+  # fail since the compiler finds the Mesa headers but NVidia's library.
+  # Make sure the NVIDIA directory comes BEFORE the others.
+  #  - Atanas Georgiev <atanas@cs.columbia.edu>
+
+  find_path(OPENGL_INCLUDE_DIR GL/gl.h
+    /usr/share/doc/NVIDIA_GLX-1.0/include
+    /usr/openwin/share/include
+    /opt/graphics/OpenGL/include /usr/X11R6/include
+    ${_OPENGL_INCLUDE_PATH}
+  )
+  list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
+
+  find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
+    /usr/share/doc/NVIDIA_GLX-1.0/include
+    /usr/openwin/share/include
+    /opt/graphics/OpenGL/include /usr/X11R6/include
+  )
+
+  find_library(OPENGL_gl_LIBRARY
+    NAMES GL MesaGL
+    PATHS /opt/graphics/OpenGL/lib
+          /usr/openwin/lib
+          /usr/shlib /usr/X11R6/lib
+          ${_OPENGL_LIB_PATH}
+  )
+
+  unset(_OPENGL_INCLUDE_PATH)
+  unset(_OPENGL_LIB_PATH)
+
+  find_library(OPENGL_glu_LIBRARY
+    NAMES GLU MesaGLU
+    PATHS ${OPENGL_gl_LIBRARY}
+          /opt/graphics/OpenGL/lib
+          /usr/openwin/lib
+          /usr/shlib /usr/X11R6/lib
+  )
+
+endif ()
+
+if(OPENGL_gl_LIBRARY)
+
+    if(OPENGL_xmesa_INCLUDE_DIR)
+      set( OPENGL_XMESA_FOUND "YES" )
+    else()
+      set( OPENGL_XMESA_FOUND "NO" )
+    endif()
+
+    set( OPENGL_LIBRARIES  ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
+    if(OPENGL_glu_LIBRARY)
+      set( OPENGL_GLU_FOUND "YES" )
+      if(NOT "${OPENGL_glu_LIBRARY}" STREQUAL "${OPENGL_gl_LIBRARY}")
+        set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
+      endif()
+    else()
+      set( OPENGL_GLU_FOUND "NO" )
+    endif()
+
+    # This deprecated setting is for backward compatibility with CMake1.4
+    set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
+
+endif()
+
+# This deprecated setting is for backward compatibility with CMake1.4
+set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
+
+if(BUILD_ENGINE_JS)
+    # The implementation is based on the standard FindOpenGL.cmake provided
+    # with CMake, but customized for targeting Emscripten only.
+
+    # These libraries are provided with Emscripten
+    SET(OPENGL_FOUND TRUE)
+    SET(OPENGL_GLU_FOUND TRUE)
+
+    # Doesn't look like this one is part of Emscripten
+    SET(OPENGL_XMESA_FOUND FALSE)
+
+    # This is the path where <GL/gl.h> is found
+    SET(OPENGL_INCLUDE_DIR "${EMSCRIPTEN_ROOT_PATH}/system/include")
+
+    # No library to link against for OpenGL, since Emscripten picks it up
+    # automatically from library_gl.js, but need to report something, or
+    # CMake thinks we failed in the search.
+    SET(OPENGL_LIBRARIES "opengl_emscripten_internal")
+    SET(OPENGL_gl_LIBRARY "gl_emscripten_internal")
+    SET(OPENGL_glu_LIBRARY "glu_emscripten_internal")
+
+    mark_as_advanced(
+      OPENGL_INCLUDE_DIR
+      OPENGL_glu_LIBRARY
+      OPENGL_gl_LIBRARY
+    )
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS})
+unset(_OpenGL_REQUIRED_VARS)
+
+mark_as_advanced(
+  OPENGL_INCLUDE_DIR
+  OPENGL_xmesa_INCLUDE_DIR
+  OPENGL_glu_LIBRARY
+  OPENGL_gl_LIBRARY
+)
--- a/cmake_modules/FindSDL2.cmake	Mon Apr 18 18:15:20 2016 +0200
+++ b/cmake_modules/FindSDL2.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -158,6 +158,11 @@
     SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
 ENDIF(SDL2_LIBRARY_TEMP)
 
+if(BUILD_ENGINE_JS)
+    set(SDL2_LIBRARY "sdl2_emscripten_internal" CACHE STRING "emscripten override" FORCE)
+    set(SDL2_INCLUDE_DIR "${CMAKE_SYSTEM_INCLUDE_PATH}/SDL" CACHE STRING "emscripten override" FORCE)
+endif()
+
 INCLUDE(FindPackageHandleStandardArgs)
 
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
--- a/cmake_modules/FindSDL2_image.cmake	Mon Apr 18 18:15:20 2016 +0200
+++ b/cmake_modules/FindSDL2_image.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -74,6 +74,12 @@
 set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY})
 set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
 
+if(BUILD_ENGINE_JS)
+    set(SDL2_IMAGE_LIBRARY "sdl2_image_emscripten_internal")
+    set(SDL2_IMAGE_LIBRARIES "sdl2_image_emscripten_internal")
+    set(SDL2_IMAGE_INCLUDE_DIRS "${CMAKE_SYSTEM_INCLUDE_PATH}/SDL")
+endif()
+
 include(FindPackageHandleStandardArgs)
 
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image
--- a/cmake_modules/FindSDL2_mixer.cmake	Mon Apr 18 18:15:20 2016 +0200
+++ b/cmake_modules/FindSDL2_mixer.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -74,6 +74,12 @@
 set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY})
 set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR})
 
+if(BUILD_ENGINE_JS)
+    set(SDL2_MIXER_LIBRARY "sdl2_mixer_emscripten_internal")
+    set(SDL2_MIXER_LIBRARIES "sdl2_mixer_emscripten_internal")
+    set(SDL2_MIXER_INCLUDE_DIRS "${CMAKE_SYSTEM_INCLUDE_PATH}/SDL")
+endif()
+
 include(FindPackageHandleStandardArgs)
 
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer
--- a/cmake_modules/FindSDL2_net.cmake	Mon Apr 18 18:15:20 2016 +0200
+++ b/cmake_modules/FindSDL2_net.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -74,6 +74,12 @@
 set(SDL2_NET_LIBRARIES ${SDL2_NET_LIBRARY})
 set(SDL2_NET_INCLUDE_DIRS ${SDL2_NET_INCLUDE_DIR})
 
+if(BUILD_ENGINE_JS)
+    set(SDL2_NET_LIBRARY "sdl2_net_emscripten_internal")
+    set(SDL2_NET_LIBRARIES "sdl2_net_emscripten_internal")
+    set(SDL2_NET_INCLUDE_DIRS "${CMAKE_SYSTEM_INCLUDE_PATH}/SDL")
+endif()
+
 include(FindPackageHandleStandardArgs)
 
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_net
--- a/cmake_modules/FindSDL2_ttf.cmake	Mon Apr 18 18:15:20 2016 +0200
+++ b/cmake_modules/FindSDL2_ttf.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -74,6 +74,12 @@
 set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY})
 set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR})
 
+if(BUILD_ENGINE_JS)
+    set(SDL2_TTF_LIBRARY "sdl2_ttf_emscripten_internal")
+    set(SDL2_TTF_LIBRARIES "sdl2_ttf_emscripten_internal")
+    set(SDL2_TTF_INCLUDE_DIRS "${CMAKE_SYSTEM_INCLUDE_PATH}/SDL")
+endif()
+
 include(FindPackageHandleStandardArgs)
 
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/Platform/Emscripten.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -0,0 +1,275 @@
+# This file is a 'toolchain description file' for CMake.
+# It teaches CMake about the Emscripten compiler, so that CMake can generate makefiles
+# from CMakeLists.txt that invoke emcc.
+
+# To use this toolchain file with CMake, invoke CMake with the following command line parameters
+# cmake -DCMAKE_TOOLCHAIN_FILE=<EmscriptenRoot>/cmake/Modules/Platform/Emscripten.cmake
+#       -DCMAKE_BUILD_TYPE=<Debug|RelWithDebInfo|Release|MinSizeRel>
+#       -G "Unix Makefiles" (Linux and OSX)
+#       -G "MinGW Makefiles" (Windows)
+#       <path/to/CMakeLists.txt> # Note, pass in here ONLY the path to the file, not the filename 'CMakeLists.txt' itself.
+
+# After that, build the generated Makefile with the command 'make'. On Windows, you may download and use 'mingw32-make' instead.
+
+# The following variable describes the target OS we are building to.
+set(CMAKE_SYSTEM_NAME Emscripten)
+set(CMAKE_SYSTEM_VERSION 1)
+
+set(CMAKE_CROSSCOMPILING TRUE)
+
+# Advertise Emscripten as a 32-bit platform (as opposed to CMAKE_SYSTEM_PROCESSOR=x86_64 for 64-bit platform),
+# since some projects (e.g. OpenCV) use this to detect bitness.
+set(CMAKE_SYSTEM_PROCESSOR x86)
+
+# Tell CMake how it should instruct the compiler to generate multiple versions of an outputted .so library: e.g. "libfoo.so, libfoo.so.1, libfoo.so.1.4" etc.
+# This feature is activated if a shared library project has the property SOVERSION defined.
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+
+# In CMake, CMAKE_HOST_WIN32 is set when we are cross-compiling from Win32 to Emscripten: http://www.cmake.org/cmake/help/v2.8.12/cmake.html#variable:CMAKE_HOST_WIN32
+# The variable WIN32 is set only when the target arch that will run the code will be WIN32, so unset WIN32 when cross-compiling.
+set(WIN32)
+
+# The same logic as above applies for APPLE and CMAKE_HOST_APPLE, so unset APPLE.
+set(APPLE)
+
+# And for UNIX and CMAKE_HOST_UNIX. However, Emscripten is often able to mimic being a Linux/Unix system, in which case a lot of existing CMakeLists.txt files can be configured for Emscripten while assuming UNIX build, so this is left enabled.
+set(UNIX 1)
+
+# Do a no-op access on the CMAKE_TOOLCHAIN_FILE variable so that CMake will not issue a warning on it being unused.
+if(CMAKE_TOOLCHAIN_FILE)
+endif()
+
+# In order for check_function_exists() detection to work, we must signal it to pass an additional flag, which causes the compilation
+# to abort if linking results in any undefined symbols. The CMake detection mechanism depends on the undefined symbol error to be raised.
+set(CMAKE_REQUIRED_FLAGS "-s ERROR_ON_UNDEFINED_SYMBOLS=1")
+
+# Locate where the Emscripten compiler resides in relative to this toolchain file.
+if("${EMSCRIPTEN_ROOT_PATH}" STREQUAL "")
+    get_filename_component(GUESS_EMSCRIPTEN_ROOT_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
+    if(EXISTS "${GUESS_EMSCRIPTEN_ROOT_PATH}/emranlib")
+        set(EMSCRIPTEN_ROOT_PATH "${GUESS_EMSCRIPTEN_ROOT_PATH}")
+    endif()
+endif()
+
+# If not found by above search, locate using the EMSCRIPTEN environment variable.
+if("${EMSCRIPTEN_ROOT_PATH}" STREQUAL "")
+    set(EMSCRIPTEN_ROOT_PATH "$ENV{EMSCRIPTEN}")
+endif()
+
+# Abort if not found.
+if("${EMSCRIPTEN_ROOT_PATH}" STREQUAL "")
+    message(FATAL_ERROR "Could not locate the Emscripten compiler toolchain directory! Either set the EMSCRIPTEN environment variable, or pass -DEMSCRIPTEN_ROOT_PATH=xxx to CMake to explicitly specify the location of the compiler! This usually matches EMSCRIPTEN_ROOT from your ~/.emscripten file.")
+endif()
+
+# Normalize, convert Windows backslashes to forward slashes or CMake will crash.
+get_filename_component(EMSCRIPTEN_ROOT_PATH "${EMSCRIPTEN_ROOT_PATH}" ABSOLUTE)
+
+if(NOT CMAKE_MODULE_PATH)
+    set(CMAKE_MODULE_PATH "")
+endif()
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${EMSCRIPTEN_ROOT_PATH}/cmake/Modules")
+
+set(CMAKE_FIND_ROOT_PATH "${EMSCRIPTEN_ROOT_PATH}/system")
+
+if(CMAKE_HOST_WIN32)
+    set(EMCC_SUFFIX ".bat")
+else()
+    set(EMCC_SUFFIX "")
+endif()
+
+# Specify the compilers to use for C and C++
+if("${CMAKE_C_COMPILER}" STREQUAL "")
+    set(CMAKE_C_COMPILER "${EMSCRIPTEN_ROOT_PATH}/emcc${EMCC_SUFFIX}")
+endif()
+if("${CMAKE_CXX_COMPILER}" STREQUAL "")
+    set(CMAKE_CXX_COMPILER "${EMSCRIPTEN_ROOT_PATH}/em++${EMCC_SUFFIX}")
+endif()
+
+if("${CMAKE_AR}" STREQUAL "")
+    set(CMAKE_AR "${EMSCRIPTEN_ROOT_PATH}/emar${EMCC_SUFFIX}" CACHE FILEPATH "Emscripten ar")
+endif()
+
+if("${CMAKE_RANLIB}" STREQUAL "")
+    set(CMAKE_RANLIB "${EMSCRIPTEN_ROOT_PATH}/emranlib${EMCC_SUFFIX}" CACHE FILEPATH "Emscripten ranlib")
+endif()
+
+# Don't do compiler autodetection, since we are cross-compiling.
+include(CMakeForceCompiler)
+CMAKE_FORCE_C_COMPILER("${CMAKE_C_COMPILER}" Clang)
+CMAKE_FORCE_CXX_COMPILER("${CMAKE_CXX_COMPILER}" Clang)
+
+# To find programs to execute during CMake run time with find_program(), e.g. 'git' or so, we allow looking
+# into system paths.
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+# Since Emscripten is a cross-compiler, we should never look at the system-provided directories like /usr/include and so on.
+# Therefore only CMAKE_FIND_ROOT_PATH should be used as a find directory. See http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_FIND_ROOT_PATH_MODE_INCLUDE.html
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
+set(CMAKE_SYSTEM_INCLUDE_PATH "${EMSCRIPTEN_ROOT_PATH}/system/include")
+
+# We would prefer to specify a standard set of Clang+Emscripten-friendly common convention for suffix files, especially for CMake executable files,
+# but if these are adjusted, ${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake will fail, since it depends on being able to compile output files with predefined names.
+#SET(CMAKE_LINK_LIBRARY_SUFFIX "")
+#SET(CMAKE_STATIC_LIBRARY_PREFIX "")
+#SET(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")
+#SET(CMAKE_SHARED_LIBRARY_PREFIX "")
+#SET(CMAKE_SHARED_LIBRARY_SUFFIX ".bc")
+SET(CMAKE_EXECUTABLE_SUFFIX ".js")
+#SET(CMAKE_FIND_LIBRARY_PREFIXES "")
+#SET(CMAKE_FIND_LIBRARY_SUFFIXES ".bc")
+
+SET(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
+SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
+SET(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)
+SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
+SET(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1)
+SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1)
+
+set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@")
+set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@")
+
+# Specify the program to use when building static libraries. Force Emscripten-related command line options to clang.
+set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")
+set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")
+
+# Set a global EMSCRIPTEN variable that can be used in client CMakeLists.txt to detect when building using Emscripten.
+set(EMSCRIPTEN 1 CACHE BOOL "If true, we are targeting Emscripten output.")
+
+# Hardwire support for cmake-2.8/Modules/CMakeBackwardsCompatibilityC.cmake without having CMake to try complex things
+# to autodetect these:
+set(CMAKE_SKIP_COMPATIBILITY_TESTS 1)
+set(CMAKE_SIZEOF_CHAR 1)
+set(CMAKE_SIZEOF_UNSIGNED_SHORT 2)
+set(CMAKE_SIZEOF_SHORT 2)
+set(CMAKE_SIZEOF_INT 4)
+set(CMAKE_SIZEOF_UNSIGNED_LONG 4)
+set(CMAKE_SIZEOF_UNSIGNED_INT 4)
+set(CMAKE_SIZEOF_LONG 4)
+set(CMAKE_SIZEOF_VOID_P 4)
+set(CMAKE_SIZEOF_FLOAT 4)
+set(CMAKE_SIZEOF_DOUBLE 8)
+set(CMAKE_C_SIZEOF_DATA_PTR 4)
+set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
+set(CMAKE_HAVE_LIMITS_H 1)
+set(CMAKE_HAVE_UNISTD_H 1)
+set(CMAKE_HAVE_PTHREAD_H 1)
+set(CMAKE_HAVE_SYS_PRCTL_H 1)
+set(CMAKE_WORDS_BIGENDIAN 0)
+set(CMAKE_DL_LIBS)
+
+set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2" CACHE STRING "Emscripten-overridden CMAKE_C_FLAGS_RELEASE")
+set(CMAKE_C_FLAGS_MINSIZEREL "-DNDEBUG -Os" CACHE STRING "Emscripten-overridden CMAKE_C_FLAGS_MINSIZEREL")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2" CACHE STRING "Emscripten-overridden CMAKE_C_FLAGS_RELWITHDEBINFO")
+set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O2" CACHE STRING "Emscripten-overridden CMAKE_CXX_FLAGS_RELEASE")
+set(CMAKE_CXX_FLAGS_MINSIZEREL "-DNDEBUG -Os" CACHE STRING "Emscripten-overridden CMAKE_CXX_FLAGS_MINSIZEREL")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2" CACHE STRING "Emscripten-overridden CMAKE_CXX_FLAGS_RELWITHDEBINFO")
+
+set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-O2" CACHE STRING "Emscripten-overridden CMAKE_EXE_LINKER_FLAGS_RELEASE")
+set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "-Os" CACHE STRING "Emscripten-overridden CMAKE_EXE_LINKER_FLAGS_MINSIZEREL")
+set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "-O2 -g" CACHE STRING "Emscripten-overridden CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO")
+set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "-O2" CACHE STRING "Emscripten-overridden CMAKE_SHARED_LINKER_FLAGS_RELEASE")
+set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "-Os" CACHE STRING "Emscripten-overridden CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL")
+set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "-O2 -g" CACHE STRING "Emscripten-overridden CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO")
+set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "-O2" CACHE STRING "Emscripten-overridden CMAKE_MODULE_LINKER_FLAGS_RELEASE")
+set(CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL "-Os" CACHE STRING "Emscripten-overridden CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL")
+set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "-O2 -g" CACHE STRING "Emscripten-overridden CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO")
+
+function(em_validate_asmjs_after_build target)
+    add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo Validating build output for asm.js... COMMAND "python" ARGS "${EMSCRIPTEN_ROOT_PATH}/tools/validate_asmjs.py" "$<TARGET_FILE:${target}>")
+endfunction()
+
+# A global counter to guarantee unique names for js library files.
+set(link_js_counter 1)
+
+# Internal function: Do not call from user CMakeLists.txt files. Use one of em_link_js_library()/em_link_pre_js()/em_link_post_js() instead.
+function(em_add_tracked_link_flag target flagname)
+
+    # User can input list of JS files either as a single list, or as variable arguments to this function, so iterate over varargs, and treat each
+    # item in varargs as a list itself, to support both syntax forms.
+    foreach(jsFileList ${ARGN})
+        foreach(jsfile ${jsFileList})
+            # If the user edits the JS file, we want to relink the emscripten application, but unfortunately it is not possible to make a link step
+            # depend directly on a source file. Instead, we must make a dummy no-op build target on that source file, and make the project depend on
+            # that target.
+
+            # Sanitate the source .js filename to a good symbol name to use as a dummy filename.
+            get_filename_component(jsname "${jsfile}" NAME)
+            string(REGEX REPLACE "[/:\\\\.\ ]" "_" dummy_js_target ${jsname})
+            set(dummy_lib_name ${target}_${link_js_counter}_${dummy_js_target})
+            set(dummy_c_name "${CMAKE_BINARY_DIR}/${dummy_js_target}_tracker.c")
+
+            # Create a new static library target that with a single dummy .c file.
+            add_library(${dummy_lib_name} STATIC ${dummy_c_name})
+            # Make the dummy .c file depend on the .js file we are linking, so that if the .js file is edited, the dummy .c file, and hence the static library will be rebuild (no-op). This causes the main application to be relinked, which is what we want.
+            # This approach was recommended by http://www.cmake.org/pipermail/cmake/2010-May/037206.html
+            add_custom_command(OUTPUT ${dummy_c_name} COMMAND ${CMAKE_COMMAND} -E touch ${dummy_c_name} DEPENDS ${jsfile})
+            target_link_libraries(${target} ${dummy_lib_name})
+
+            # Link the js-library to the target
+            # When a linked library starts with a "-" cmake will just add it to the linker command line as it is.
+            # The advantage of doing it this way is that the js-library will also be automatically linked to targets
+            # that depend on this target.
+            get_filename_component(js_file_absolute_path "${jsfile}" ABSOLUTE )
+            target_link_libraries(${target} "${flagname} \"${js_file_absolute_path}\"")
+
+            math(EXPR link_js_counter "${link_js_counter} + 1")
+        endforeach()
+    endforeach()
+endfunction()
+
+# This function links a (list of ) .js library file(s) to the given CMake project.
+# Example: em_link_js_library(my_executable "lib1.js" "lib2.js")
+#    will result in emcc passing --js-library lib1.js --js-library lib2.js to the emscripten linker, as well as
+#    tracking the modification timestamp between the linked .js files and the main project, so that editing the .js file
+#    will cause the target project to be relinked.
+function(em_link_js_library target)
+    em_add_tracked_link_flag(${target} "--js-library" ${ARGN})
+endfunction()
+
+# This function is identical to em_link_js_library(), except the .js files will be added with '--pre-js file.js' command line flag,
+# which is generally used to add some preamble .js code to a generated output file.
+function(em_link_pre_js target)
+    em_add_tracked_link_flag(${target} "--pre-js" ${ARGN})
+endfunction()
+
+# This function is identical to em_link_js_library(), except the .js files will be added with '--post-js file.js' command line flag,
+# which is generally used to add some postamble .js code to a generated output file.
+function(em_link_post_js target)
+    em_add_tracked_link_flag(${target} "--post-js" ${ARGN})
+endfunction()
+
+# Experimental support for targeting generation of Visual Studio project files (vs-tool) of Emscripten projects for Windows.
+# To use this, pass the combination -G "Visual Studio 10" -DCMAKE_TOOLCHAIN_FILE=Emscripten.cmake
+if ("${CMAKE_GENERATOR}" MATCHES "^Visual Studio.*")
+    # By default, CMake generates VS project files with a <GenerateManifest>true</GenerateManifest> directive.
+    # This causes VS to attempt to invoke rc.exe during the build, which will fail since app manifests are meaningless for Emscripten.
+    # To disable this, add the following linker flag. This flag will not go to emcc, since the Visual Studio CMake generator will swallow it.
+    set(EMSCRIPTEN_VS_LINKER_FLAGS "/MANIFEST:NO")
+    # CMake is hardcoded to write a ClCompile directive <ObjectFileName>$(IntDir)</ObjectFileName> in all VS project files it generates.
+    # This makes VS pass emcc a -o param that points to a directory instead of a file, which causes emcc autogenerate the output filename.
+    # CMake is hardcoded to assume all object files have the suffix .obj, so adjust the emcc-autogenerated default suffix name to match.
+    set(EMSCRIPTEN_VS_LINKER_FLAGS "${EMSCRIPTEN_VS_LINKER_FLAGS} --default-obj-ext .obj")
+    # Also hint CMake that it should not hardcode <ObjectFileName> generation. Requires a custom CMake build for this to work (ignored on others)
+    # See http://www.cmake.org/Bug/view.php?id=14673 and https://github.com/juj/CMake
+    set(CMAKE_VS_NO_DEFAULT_OBJECTFILENAME 1)
+
+    # Apply and cache Emscripten Visual Studio IDE-specific linker flags.
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EMSCRIPTEN_VS_LINKER_FLAGS}" CACHE STRING "")
+    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${EMSCRIPTEN_VS_LINKER_FLAGS}" CACHE STRING "")
+    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${EMSCRIPTEN_VS_LINKER_FLAGS}" CACHE STRING "")
+endif()
+
+if(NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR)
+  find_program(NODE_JS_EXECUTABLE NAMES nodejs node)
+  if(NODE_JS_EXECUTABLE)
+    set(CMAKE_CROSSCOMPILING_EMULATOR "${NODE_JS_EXECUTABLE}" CACHE FILEPATH "Path to the emulator for the target system.")
+  endif()
+endif()
+
+# No-op on CMAKE_CROSSCOMPILING_EMULATOR so older versions of cmake do not
+# complain about unused CMake variable.
+if(CMAKE_CROSSCOMPILING_EMULATOR)
+endif()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/TestBigEndian.cmake	Sat Apr 23 12:02:39 2016 +0200
@@ -0,0 +1,30 @@
+#.rst:
+# TestBigEndian
+# -------------
+#
+# The TestBigEndian.cmake module that ships with CMake, which
+# checks if the system is big endian or little endian, assumes
+# that a binary is produced that will have bytes that correspond to the
+# endianness on the target system. Since emscripten produces Javascript, we
+# override the default behavior and always return little endian.
+#
+# ::
+#
+#   TEST_BIG_ENDIAN(VARIABLE)
+#   VARIABLE - variable to store the result to
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+function(TEST_BIG_ENDIAN VARIABLE)
+  set(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
+endfunction()
--- a/hedgewars/options.inc	Mon Apr 18 18:15:20 2016 +0200
+++ b/hedgewars/options.inc	Sat Apr 23 12:02:39 2016 +0200
@@ -46,7 +46,9 @@
     {$DEFINE USE_TOUCH_INTERFACE}
 {$ELSE}
     {$DEFINE USE_AM_NUMCOLUMN}
-    {$DEFINE USE_S3D_RENDERING}
+    {$IFNDEF WEBGL}
+        {$DEFINE USE_S3D_RENDERING}
+    {$ENDIF}
 {$ENDIF}
 
 
--- a/hedgewars/uInputHandler.pas	Mon Apr 18 18:15:20 2016 +0200
+++ b/hedgewars/uInputHandler.pas	Sat Apr 23 12:02:39 2016 +0200
@@ -318,7 +318,7 @@
     DefaultBinds[KeyNameToCode('j0a0d')]:= '+right';
     DefaultBinds[KeyNameToCode('j0a1u')]:= '+up';
     DefaultBinds[KeyNameToCode('j0a1d')]:= '+down';
-    for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
+    for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+char(48+i);
     for i:= 1 to 5  do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i);
 
     loadBinds('dbind', cPathz[ptData] + '/settings.ini');
--- a/hedgewars/uSound.pas	Mon Apr 18 18:15:20 2016 +0200
+++ b/hedgewars/uSound.pas	Sat Apr 23 12:02:39 2016 +0200
@@ -425,7 +425,7 @@
             s:= cPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
             WriteToConsole(msgLoading + s + ' ');
             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
-            if not SDLCheck(defVoicepack^.chunks[snd] <> nil, 'Mix_LoadWAV_RW', true) then exit;
+            if SDLCheck(defVoicepack^.chunks[snd] <> nil, 'Mix_LoadWAV_RW', true) then exit;
             WriteLnToConsole(msgOK);
             end;
         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
--- a/misc/liblua/CMakeLists.txt	Mon Apr 18 18:15:20 2016 +0200
+++ b/misc/liblua/CMakeLists.txt	Sat Apr 23 12:02:39 2016 +0200
@@ -23,4 +23,8 @@
 set(LUA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Lua include dir" FORCE)
 set(LUA_LIBRARY ${lua_fullpath} CACHE STRING "Lua library" FORCE)
 
+#emscripten does not expose headers but has an internal binary copy
+if(BUILD_ENGINE_JS)
+    set(LUA_LIBRARY "lua_emscripten_internal" CACHE STRING "Lua library" FORCE)
+endif()
 
--- a/misc/libphyslayer/CMakeLists.txt	Mon Apr 18 18:15:20 2016 +0200
+++ b/misc/libphyslayer/CMakeLists.txt	Sat Apr 23 12:02:39 2016 +0200
@@ -26,3 +26,7 @@
 set(PHYSLAYER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Physlayer include dir" FORCE)
 set(PHYSLAYER_LIBRARY ${physlayer_fullpath} CACHE STRING "Physlayer library" FORCE)
 
+if(BUILD_ENGINE_JS)
+    set_target_properties(physlayer PROPERTIES SUFFIX ".bc")
+endif()
+
--- a/misc/libphyslayer/physfsrwops.c	Mon Apr 18 18:15:20 2016 +0200
+++ b/misc/libphyslayer/physfsrwops.c	Sat Apr 23 12:02:39 2016 +0200
@@ -180,7 +180,7 @@
         retval = SDL_AllocRW();
         if (retval != NULL)
         {
-#if TARGET_SDL13
+#if TARGET_SDL13 && !defined(EMSCRIPTEN)
             retval->size  = physfsrwops_size;
 #endif
             retval->seek  = physfsrwops_seek;
--- a/project_files/hwc/CMakeLists.txt	Mon Apr 18 18:15:20 2016 +0200
+++ b/project_files/hwc/CMakeLists.txt	Sat Apr 23 12:02:39 2016 +0200
@@ -57,15 +57,20 @@
 list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas)
 
 
+set(pas2c_args -n hwengine
+               -i ${CMAKE_SOURCE_DIR}/hedgewars
+               -o ${CMAKE_CURRENT_BINARY_DIR}
+               -a ${CMAKE_CURRENT_BINARY_DIR}
+               -d ENDIAN_LITTLE
+               -d DEBUGFILE)
+if(BUILD_ENGINE_JS)
+    set(pas2c_args ${pas2c_args} -d WEBGL)
+endif()
+
 #invoke pas2c on main module, it will call all the others
 add_custom_command(OUTPUT ${engine_sources}
                    COMMAND "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}"
-                   ARGS -n "hwengine"
-                        -i "${CMAKE_SOURCE_DIR}/hedgewars"
-                        -o "${CMAKE_CURRENT_BINARY_DIR}"
-                        -a "${CMAKE_CURRENT_BINARY_DIR}"
-                        -d "ENDIAN_LITTLE"
-                        -d "DEBUGFILE"
+                   ARGS ${pas2c_args}
                    DEPENDS pas2c                     #converter tool
                            ${engine_sources_pas}     #original pascal file
                   )
@@ -80,6 +85,10 @@
 
 add_executable(hwengine WIN32 ${engine_sources})
 
+if(BUILD_ENGINE_JS)
+    set_target_properties(hwengine PROPERTIES SUFFIX ".html")
+endif()
+
 target_link_libraries(hwengine  fpcrtl
                                 ${LUA_LIBRARY}
                                 ${OPENGL_LIBRARY}
--- a/project_files/hwc/rtl/CMakeLists.txt	Mon Apr 18 18:15:20 2016 +0200
+++ b/project_files/hwc/rtl/CMakeLists.txt	Sat Apr 23 12:02:39 2016 +0200
@@ -5,12 +5,3 @@
 
 add_library(fpcrtl STATIC ${fpcrtl_src})
 
-#if(WEBGL)
-#    set_target_properties(fpcrtl PROPERTIES PREFIX "em")
-#    set_target_properties(fpcrtl PROPERTIES SUFFIX ".bc")
-#endif(WEBGL)
-
-
-
-
-
--- a/project_files/hwc/rtl/misc.c	Mon Apr 18 18:15:20 2016 +0200
+++ b/project_files/hwc/rtl/misc.c	Sat Apr 23 12:02:39 2016 +0200
@@ -78,8 +78,8 @@
 {
     if(s.len < MAX_ANSISTRING_LENGTH)
     {
+        ++s.len;
         s.s[s.len] = c;
-        ++s.len;
     }
 
     return s;
--- a/project_files/hwc/rtl/pmath.h	Mon Apr 18 18:15:20 2016 +0200
+++ b/project_files/hwc/rtl/pmath.h	Sat Apr 23 12:02:39 2016 +0200
@@ -21,4 +21,17 @@
 int         __attribute__((overloadable))   fpcrtl_abs(int x);
 int64_t     __attribute__((overloadable))   fpcrtl_abs(int64_t x);
 
+/* emscripten cannot find math.h through our cmake */
+#ifdef EMSCRIPTEN
+double      exp(double);
+double      log(double);
+double      sin(double);
+double      cos(double);
+double      fabs(double);
+double      ceil(double);
+double      sqrt(double);
+double      atan(double);
+double      atan2(double, double);
+#endif
+
 #endif /* PMATH_H_ */
--- a/project_files/hwc/rtl/system.c	Mon Apr 18 18:15:20 2016 +0200
+++ b/project_files/hwc/rtl/system.c	Sat Apr 23 12:02:39 2016 +0200
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <wchar.h>
+#include "pmath.h"
 
 #ifndef M_PI
 // some math.h do not have M_PI macros
--- a/share/hedgewars/Data/Missions/Training/portal.lua	Mon Apr 18 18:15:20 2016 +0200
+++ b/share/hedgewars/Data/Missions/Training/portal.lua	Sat Apr 23 12:02:39 2016 +0200
@@ -16,32 +16,32 @@
 	Delay = 10 -- The delay between each round
 	Map = "portal" -- The map to be played
 	Theme = "Hell" -- The theme to be used
-	Goals = loc("Use the portal to move fast and far, use it to kill, use it with caution!")  --the goal ...
-	
+	-- Disable Sudden Death
+	HealthDecrease = 0
+	WaterRise = 0
 	
-----AddTeam(teamname, color, grave, fort, voicepack, flag)--
-	AddTeam(loc("Subject"), 14483406, "Simple", "Island", "Default", "cm_star")
-	player = AddHog(loc("player"), 0, 10, "Terminator_Glasses")
+	AddTeam(loc("Subjects"), 0xFFFF01, "Simple", "Island", "Default", "cm_test")
+	player = AddHog(loc("Subject 1"), 0, 10, "Terminator_Glasses")
 
-	AddTeam(loc("Hell Army"), 1170801, "Simple", "Island", "Default", "cm_galaxy")
-	enemy1 = AddHog(loc("Lucifer"), 1, 200, "thinkingcap")
-	enemy2 = AddHog(loc("voldemort"), 1, 150, "WizardHat")
-	enemy3 = AddHog(loc("zombi"), 1, 100, "zombi")
-	enemy4 = AddHog(loc("Predator"), 1, 14, "predator")
-	enemy5 = AddHog(loc("oneye"), 1, 50, "cyclops")
-	enemy6 = AddHog(loc("razac"), 1, 50, "plaguemask")
+	AddTeam(loc("Hell Army"), 0xFF0402, "skull", "Island", "Default", "cm_hellish")
+	enemy1 = AddHog(loc("Lucifer"), 1, 200, "InfernalHorns")
+	enemy2 = AddHog(loc("Voldemort"), 1, 150, "WizardHat")
+	enemy3 = AddHog(loc("Zombi"), 1, 100, "Zombi")
+	enemy4 = AddHog(loc("Predator"), 1, 14, "anzac")
+	enemy5 = AddHog(loc("Oneye"), 1, 50, "cyclops")
+	enemy6 = AddHog(loc("Razac"), 1, 50, "Evil")
 	enemy7 = AddHog(loc("C-2"), 1, 50, "cyborg1")
 	enemy8 = AddHog(loc("Rider"), 1, 50, "scif_SparkssHelmet")
 
-	AddTeam(loc("badmad"), 1170801, "Simple", "Island", "Default", "cm_jupiter")
+	AddTeam(loc("Badmad"), 0xFF0402, "skull", "Island", "Default", "cm_pentagram")
 	enemy9 = AddHog(loc("C-1"), 1, 50, "cyborg2")
-	enemy10 = AddHog(loc("hiden"), 1, 40, "daftpunkguymanuel")
-	enemy11 = AddHog(loc("ronald"), 1, 70, "clown")
-	enemy12 = AddHog(loc("phosphatoglucidique"), 1, 50, "chef")
-	enemy13 = AddHog(loc("Lestat"), 1, 30, "draculakz")
+	enemy10 = AddHog(loc("Hidden"), 1, 40, "bushhider")
+	enemy11 = AddHog(loc("Ronald"), 1, 70, "clown")
+	enemy12 = AddHog(loc("Phosphat"), 1, 50, "chef")
+	enemy13 = AddHog(loc("Lestat"), 1, 30, "vampirichog")
 
 	SetGearPosition(player, 350, 1820)
-    SetGearPosition(enemy1, 2037, 1313)
+	SetGearPosition(enemy1, 2037, 1313)
 	SetGearPosition(enemy2, 1369, 1605)
 	SetGearPosition(enemy3, 1750, 1937)
 	SetGearPosition(enemy4, 3125, 89)
@@ -55,8 +55,6 @@
 	SetGearPosition(enemy12, 2666, 950)
 	SetGearPosition(enemy13, 3306, 1205)
 
-
-
 end
 
 function onAmmoStoreInit()
@@ -80,11 +78,7 @@
 
 function onGameStart()
 
-	SetWind(100)-- SetWind(windSpeed) Sets the current wind in the range of -100 to 100. Use together with gfDisableWind for full control.
-                -- -100to0 is to the left, and 0to100 is to the right  (of course more its far from 0, more the speed is high
-				--  -100.............................0..................................+100
-				-- <<<<<<<<--<<--<<<<<<<<<<<<<--<<<<<|||-->>>>>>>>-->>>>>>>>>>>>>>>-->>>>>>          =  wind direction
-
+	SetWind(100)
 
 	MineArray[0] = AddGear(840, 1847, gtMine, 0, 0, 0, 0)
 	MineArray[1] = AddGear(900, 1847, gtMine, 0, 0, 0, 0)
@@ -124,16 +118,14 @@
 	MineArray[34] = AddGear(1311, 1785, gtMine, 0, 0, 0, 0)
 
 	MineArray[35] = AddGear(4029, 89, gtMine, 0, 0, 0, 120)
-	--MineArray[36] = AddGear(3376, 1947, gtMine, 0, 0, 0, 10)
 
-		for i = 0,#MineArray do
-			SetTimer(MineArray[i],050)
-			SetState(MineArray[i],544)
-		end
-				--needed this MineArray cause timer didn't work, its was always 3sec, i wanna instant mines
+	for i = 0,#MineArray do
+		SetTimer(MineArray[i],050)
+		SetState(MineArray[i],544)
+	end
+	--needed this MineArray cause timer didn't work, its was always 3sec, i wanna instant mines
 
-
-				--UTILITY CRATE--
+	--UTILITY CRATE--
 	parachute = SpawnUtilityCrate(1670, 1165, amParachute)
 	girder = SpawnUtilityCrate(2101, 1297, amGirder)
 	SpawnUtilityCrate(3965, 625, amBlowTorch)
@@ -146,7 +138,7 @@
 	SpawnUtilityCrate(4070,1840, amLaserSight)
 	
 	
-				--AMMO CRATE--
+	--AMMO CRATE--
 	portalgun = SpawnAmmoCrate(505, 1943, amPortalGun, 1000)
 	extratime = SpawnAmmoCrate(4020, 785, amExtraTime, 2)
 	SpawnAmmoCrate(425, 613, amSnowball)
@@ -159,77 +151,55 @@
 	SpawnAmmoCrate(2900, 1400, amRope)
 	SpawnAmmoCrate(4025, 1117, amFirePunch)
 
-	
-				--HEALTH CRATE--
+	--HEALTH CRATE--
 	SpawnHealthCrate(2000, 780)
 	
-				--GIRDER--
+	--GIRDER--
 	PlaceGirder(3363, 1323, 4)
 
-
-	ShowMission (loc("Portal mission"), loc("training"), "", -amPortalGun, 5000)
-	HogSay(player, loc("I should get myself a portal gun, maybe this crate has one"), SAY_THINK)
+	ShowMission (loc("Portal Mind Challenge"), loc("Mission"), 
+		loc("Defeat all enemies!") .. "|" .. loc("In this mission you have infinite time."),
+		-amPortalGun, 5000)
+	HogSay(player, loc("I should get myself a portal device, maybe this crate has one."), SAY_THINK)
 	
-
-
-
 end
 
 function onGameTick()
 
-    if (player ~= nil)  then
+	if (player ~= nil)  then
 		if (gearIsInBox(player, 1650, 1907, 200, 60) and (adviceGiven == false)) then
 			adviceGiven = true
-				HogSay(player, loc("Hmmm, I'll have to find some way of moving him off this anti-portal surface..."), SAY_THINK)
+			HogSay(player, loc("Hmmm, I’ll have to find some way of moving him off this anti-portal surface."), SAY_THINK)
 		elseif (gearIsInBox(player, 2960, 790, 200, 60) and (adviceGiven2 == false)) then
 			adviceGiven2 = true
-				HogSay(player, loc("The anti-portal zone is all over the floor, and I have nothing to kill him...Droping something could hurt him enough to kill him..."), SAY_THINK)
- end
- end
-	
+			HogSay(player, loc("The anti-portal surface is all over the floor, and I have nothing to kill him. Dropping something could hurt him enough to kill him."), SAY_THINK)
+		end
 	end
 	
-
-
-
+end
+	
+function onGearDelete(gear)
+	-- Check gear collection
+	if CurrentHedgehog == player and (band(GetGearMessage(gear), gmDestroy) ~= 0) then
+		if gear == portalgun then
+			HogSay(player, loc("Great! Let’s kill all these enemies, using portals."), SAY_THINK)
+		end
 
-function onNewturn()
-end
+		if gear == girder then 
+			HogSay(player, loc("This will be useful when I need a new platform or if I want to rise."), SAY_THINK)
+		end
+	
+		if gear == parachute then
+			HogSay(player, loc("You can’t open a portal on the blue surface."), SAY_THINK)
+		end
 
+		if gear == extratime then
+			HogSay(player, loc("What?! For all this struggle I just win some ... time? Oh dear!"), SAY_SHOUT)
+		end
+	end
 
-function onGearAdd(gear)
+	if gear == player then
+		player = nil
+	end
 end
 
-function onGearDelete(gear)
-
-	if gear == portalgun then
-		--AddAmmo(player, amPortalGun, 10000)
-		HogSay(player, loc("GREAT ! Let's kill all this enemies, using portals"), SAY_THINK)
-	end
-
-	if gear == girder then 
-		HogSay(player, loc("Will be useful if I need a new plateform or if I want to rise...."), SAY_THINK)
-	end
-	
-	if gear == parachute then
-		HogSay(player, loc("You can't fire a portal on the blue surface"), SAY_THINK)
-	end
---if you wanted to check for collection only
---you could probably say
---if (gear == myParachuteGear) and (band(GetGearMessage(gear), gmDestroy) ~= 0) then
-
-	if gear == extratime then
-		HogSay(player, loc(" What !! For all of this struggle i just win some ... TIME o0"), SAY_SHOUT)
-	end
-
-	
-	if gear == player then
-        player = nil
-    end
-end
-
-
-
-
-
-