Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JSON++, initial Emscripten support

- ozCore
  * iter() member is not const any more
  * JSON
    + object iterators
    + load/save(const char* path)
    + ctors for files
    + toFormattedString()
- ports
  * Emscripten: most libraries build, OpenZone (mostly) compiles
- cmake
  * fixes in toolchain files
  • Loading branch information...
commit 75425c3303e3a6fb116c3debef6a11a65f835b77 1 parent f8f403e
@ducakar authored
Showing with 521 additions and 171 deletions.
  1. +4 −26 CMakeLists.txt
  2. +2 −2 README.md
  3. +9 −8 build.sh
  4. +5 −0 cmake/Android14-ARM.Toolchain.cmake
  5. +5 −0 cmake/Android14-ARMv7a.Toolchain.cmake
  6. +5 −0 cmake/Android14-MIPS.Toolchain.cmake
  7. +5 −0 cmake/Android14-i686.Toolchain.cmake
  8. +24 −0 cmake/Emscripten.Toolchain.cmake
  9. +5 −0 cmake/NaCl-ARM.Toolchain.cmake
  10. +6 −1 cmake/NaCl-i686.Toolchain.cmake
  11. +6 −1 cmake/NaCl-x86_64.Toolchain.cmake
  12. +14 −10 cmake/PNaCl.Toolchain.cmake
  13. +1 −0  etc/PKGBUILD
  14. +1 −0  etc/PKGBUILD.aur
  15. +1 −0  etc/openzone.spec
  16. +23 −0 etc/patches/freetype-2.4.11.patch
  17. +17 −6 etc/patches/libogg-1.3.0.patch
  18. +17 −6 etc/patches/libvorbis-1.3.3.patch
  19. +45 −3 ports.sh
  20. +1 −1  src/client/ui/Text.cc
  21. +0 −4 src/common/Lua.cc
  22. +1 −6 src/common/Lua.hh
  23. +4 −8 src/ozCore/BufferStream.hh
  24. +1 −1  src/ozCore/Chain.hh
  25. +1 −1  src/ozCore/DArray.hh
  26. +1 −1  src/ozCore/DChain.hh
  27. +3 −3 src/ozCore/HashMap.hh
  28. +3 −3 src/ozCore/HashSet.hh
  29. +2 −2 src/ozCore/InputStream.hh
  30. +109 −13 src/ozCore/JSON.cc
  31. +153 −30 src/ozCore/JSON.hh
  32. +1 −1  src/ozCore/List.hh
  33. +1 −1  src/ozCore/Map.hh
  34. +4 −8 src/ozCore/OutputStream.hh
  35. +1 −1  src/ozCore/Set.hh
  36. +37 −19 src/ozCore/System.cc
  37. +3 −5 src/tests/test.cc
View
30 CMakeLists.txt
@@ -29,14 +29,12 @@ include( CheckCXXSourceCompiles )
include( CheckCXXCompilerFlag )
include( FindPkgConfig )
+set( OZ_PLATFORM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" )
+
if( PLATFORM_EMBEDDED )
set( OZ_PLATFORM_NAME "${PLATFORM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" )
- set( BUILD_SHARED_LIBS OFF )
set( OZ_GL_ES ON )
set( OZ_STANDALONE OFF )
-else()
- set( OZ_PLATFORM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" )
- set( BUILD_SHARED_LIBS ON )
endif()
if( ANDROID )
@@ -55,29 +53,12 @@ else()
set( OZ_BINARY_SUBDIR "" )
endif()
-if( ${CMAKE_CXX_COMPILER_ID} STREQUAL GNU )
- if( ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.4 )
- message( FATAL_ERROR "GCC >= 4.4 and LLVM/Clang >= 3.0 are the only supported compilers." )
- endif()
-elseif( ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang )
- if( ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.0 )
- message( FATAL_ERROR "GCC >= 4.4 and LLVM/Clang >= 3.0 are the only supported compilers." )
- endif()
-else()
- message( FATAL_ERROR "GCC >= 4.4 and LLVM/Clang >= 3.0 are the only supported compilers." )
-endif()
-
#
# Libraries
#
# Set-up include and library directories for different toolchains.
-if( ANDROID )
- include_directories( SYSTEM ${PLATFORM_PORTS_PREFIX}/usr/include )
- link_directories( ${PLATFORM_PORTS_PREFIX}/usr/lib )
-
- set( ENV{PKG_CONFIG_PATH} ${PLATFORM_PORTS_PREFIX}/usr/lib/pkgconfig )
-elseif( NACL )
+if( PLATFORM_EMBEDDED )
include_directories( SYSTEM ${PLATFORM_PORTS_PREFIX}/usr/include )
link_directories( ${PLATFORM_PORTS_PREFIX}/usr/lib )
@@ -85,9 +66,6 @@ elseif( NACL )
elseif( WIN32 )
set( ENV{PKG_CONFIG_PATH} ${PLATFORM_PREFIX}/lib/pkgconfig )
else()
- if( CMAKE_SYSTEM_NAME STREQUAL Linux )
- find_package( ALSA REQUIRED )
- endif()
pkg_check_modules( PULSE_SIMPLE REQUIRED libpulse-simple )
endif()
@@ -195,7 +173,7 @@ else()
set( flags "-std=c++0x -pedantic -fstrict-enums" )
endif()
-set( flags "${flags} -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -ffast-math" )
+set( flags "${flags} -fno-exceptions -fno-rtti -ffast-math -fvisibility-inlines-hidden" )
# Additional warnings.
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang )
View
4 README.md
@@ -60,8 +60,8 @@ You may also want to set several options when configuring CMake build system:
`OFF` by default.
- `OZ_SIMD_MATH`: Enable SIMD-specific implementation of linear algebra classes (Vec3, Vec4, Point,
- Plane, Quat, Mat44). Currently it yields ~15% worse performance than generic implementations since
- Vec3 and Point classes are a bit larger (4 floats v. 3 floats) and there are lots of accesses to
+ Plane, Quat, Mat44). Currently it yields ~15% worse performance than generic implementation since
+ Vec3 and Point classes are a bit larger (4 floats v. 3 floats) and there are plenty of accesses to
vector components in OpenZone code.
`OFF` by default.
View
17 build.sh
@@ -15,23 +15,24 @@
buildType=Debug
platforms=(
- Linux-x86_64-Clang
- Linux-x86_64-GCC
- Linux-i686-Clang
- Linux-i686-GCC
+# Linux-x86_64-Clang
+# Linux-x86_64-GCC
+# Linux-i686-Clang
+# Linux-i686-GCC
# FreeBSD-x86_64-Clang
# FreeBSD-x86_64-GCC
# FreeBSD-i686-Clang
# FreeBSD-i686-GCC
- Windows-i686
- NaCl-x86_64
- NaCl-i686
+# Windows-i686
+# NaCl-x86_64
+# NaCl-i686
# NaCl-ARM
# PNaCl
- Android14-i686
+# Android14-i686
# Android14-ARM
# Android14-ARMv7a
# Android14-MIPS
+# Emscripten
)
pnaclPrefix="$NACL_SDK_ROOT/toolchain/linux_x86_pnacl/newlib"
View
5 cmake/Android14-ARM.Toolchain.cmake
@@ -20,3 +20,8 @@ set( CMAKE_C_COMPILER "${PLATFORM_TOOL_PREFIX}/bin/${PLATFORM_TRIPLET}
set( CMAKE_CXX_COMPILER "${PLATFORM_TOOL_PREFIX}/bin/${PLATFORM_TRIPLET}-g++" )
set( CMAKE_C_FLAGS "${PLATFORM_FLAGS}" CACHE STRING "" )
set( CMAKE_CXX_FLAGS "${PLATFORM_FLAGS}" CACHE STRING "" )
+
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
5 cmake/Android14-ARMv7a.Toolchain.cmake
@@ -21,3 +21,8 @@ set( CMAKE_CXX_COMPILER "${PLATFORM_TOOL_PREFIX}/bin/${PLATFORM_TRIPLET}
set( CMAKE_C_FLAGS "${PLATFORM_FLAGS} -march=armv7-a -mfloat-abi=softfp -mfpu=neon" CACHE STRING "" )
set( CMAKE_CXX_FLAGS "${PLATFORM_FLAGS} -march=armv7-a -mfloat-abi=softfp -mfpu=neon" CACHE STRING "" )
set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--fix-cortex-a8" CACHE STRING "" )
+
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
5 cmake/Android14-MIPS.Toolchain.cmake
@@ -20,3 +20,8 @@ set( CMAKE_C_COMPILER "${PLATFORM_TOOL_PREFIX}/bin/${PLATFORM_TRIPLET}
set( CMAKE_CXX_COMPILER "${PLATFORM_TOOL_PREFIX}/bin/${PLATFORM_TRIPLET}-g++" )
set( CMAKE_C_FLAGS "${PLATFORM_FLAGS}" CACHE STRING "" )
set( CMAKE_CXX_FLAGS "${PLATFORM_FLAGS}" CACHE STRING "" )
+
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
5 cmake/Android14-i686.Toolchain.cmake
@@ -20,3 +20,8 @@ set( CMAKE_C_COMPILER "${PLATFORM_TOOL_PREFIX}/bin/${PLATFORM_TRIPLET}
set( CMAKE_CXX_COMPILER "${PLATFORM_TOOL_PREFIX}/bin/${PLATFORM_TRIPLET}-g++" )
set( CMAKE_C_FLAGS "${PLATFORM_FLAGS} -msse3 -mfpmath=sse" CACHE STRING "" )
set( CMAKE_CXX_FLAGS "${PLATFORM_FLAGS} -msse3 -mfpmath=sse" CACHE STRING "" )
+
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
24 cmake/Emscripten.Toolchain.cmake
@@ -0,0 +1,24 @@
+include( CMakeForceCompiler )
+
+set( EMSCRIPTEN ON )
+set( PCH_DISABLE ON )
+
+set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "Emscripten" )
+set( PLATFORM_TRIPLET "emscripten" )
+set( PLATFORM_PREFIX "$ENV{EMSCRIPTEN}" )
+set( PLATFORM_PORTS_PREFIX "${CMAKE_SOURCE_DIR}/ports/Emscripten" )
+set( PLATFORM_EXE_SUFFIX ".js" )
+
+set( CMAKE_SYSTEM_NAME "Generic" CACHE STRING "Target system." )
+set( CMAKE_SYSTEM_PROCESSOR "JavaScript" CACHE STRING "Target processor." )
+set( CMAKE_FIND_ROOT_PATH "${PLATFORM_PORTS_PREFIX}/usr;${PLATFORM_PREFIX}/system" )
+set( CMAKE_AR "${PLATFORM_PREFIX}/emar")
+set( CMAKE_RANLIB "${PLATFORM_PREFIX}/emranlib")
+set( CMAKE_C_COMPILER "${PLATFORM_PREFIX}/emcc")
+set( CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/em++")
+set( CMAKE_C_ARCHIVE_CREATE "${CMAKE_C_COMPILER} -o <TARGET> -emit-llvm <LINK_FLAGS> <OBJECTS>" )
+set( CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_CXX_COMPILER} -o <TARGET> -emit-llvm <LINK_FLAGS> <OBJECTS>" )
+
+cmake_force_c_compiler( ${CMAKE_C_COMPILER} Clang )
+cmake_force_cxx_compiler( ${CMAKE_CXX_COMPILER} Clang )
View
5 cmake/NaCl-ARM.Toolchain.cmake
@@ -14,3 +14,8 @@ set( CMAKE_C_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-gcc"
set( CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-g++" )
set( CMAKE_C_FLAGS "-U__STRICT_ANSI__" CACHE STRING "" )
set( CMAKE_CXX_FLAGS "-U__STRICT_ANSI__" CACHE STRING "" )
+
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
7 cmake/NaCl-i686.Toolchain.cmake
@@ -1,7 +1,7 @@
set( NACL ON )
-set( PLATFORM_NAME "NaCl" )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "NaCl" )
set( PLATFORM_TRIPLET "i686-nacl" )
set( PLATFORM_PREFIX "$ENV{NACL_SDK_ROOT}/toolchain/linux_x86_newlib" )
set( PLATFORM_PORTS_PREFIX "${CMAKE_SOURCE_DIR}/ports/NaCl-i686" )
@@ -14,3 +14,8 @@ set( CMAKE_C_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-gcc"
set( CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-g++" )
set( CMAKE_C_FLAGS "-msse3 -mfpmath=sse" CACHE STRING "" )
set( CMAKE_CXX_FLAGS "-msse3 -mfpmath=sse" CACHE STRING "" )
+
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
7 cmake/NaCl-x86_64.Toolchain.cmake
@@ -1,7 +1,7 @@
set( NACL ON )
-set( PLATFORM_NAME "NaCl" )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "NaCl" )
set( PLATFORM_TRIPLET "x86_64-nacl" )
set( PLATFORM_PREFIX "$ENV{NACL_SDK_ROOT}/toolchain/linux_x86_newlib" )
set( PLATFORM_PORTS_PREFIX "${CMAKE_SOURCE_DIR}/ports/NaCl-x86_64" )
@@ -14,3 +14,8 @@ set( CMAKE_C_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-gcc"
set( CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-g++" )
set( CMAKE_C_FLAGS "-msse3" CACHE STRING "" )
set( CMAKE_CXX_FLAGS "-msse3" CACHE STRING "" )
+
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
24 cmake/PNaCl.Toolchain.cmake
@@ -1,7 +1,10 @@
+include( CMakeForceCompiler )
+
set( NACL ON )
+set( PCH_DISABLE ON )
-set( PLATFORM_NAME "PNaCl" )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "PNaCl" )
set( PLATFORM_TRIPLET "pnacl" )
set( PLATFORM_PREFIX "$ENV{NACL_SDK_ROOT}/toolchain/linux_x86_pnacl/newlib" )
set( PLATFORM_PORTS_PREFIX "${CMAKE_SOURCE_DIR}/ports/PNaCl" )
@@ -11,16 +14,17 @@ set( CMAKE_SYSTEM_NAME "Linux" CACHE STRING "Target system." )
set( CMAKE_SYSTEM_PROCESSOR "LLVM-IR" CACHE STRING "Target processor." )
set( CMAKE_FIND_ROOT_PATH "${PLATFORM_PORTS_PREFIX};${PLATFORM_PREFIX}/usr" )
set( CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH};${PLATFORM_PREFIX}/sdk" )
-set( CMAKE_C_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-clang" )
-set( CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-clang++" )
set( CMAKE_AR "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-ar" CACHE STRING "")
set( CMAKE_RANLIB "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-ranlib" CACHE STRING "")
+set( CMAKE_C_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-clang" )
+set( CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-clang++" )
+set( CMAKE_C_FLAGS "-U__STRICT_ANSI__" CACHE STRING "" )
+set( CMAKE_CXX_FLAGS "-U__STRICT_ANSI__" CACHE STRING "" )
-set( PCH_DISABLE ON )
-
-include( CMakeForceCompiler )
-cmake_force_c_compiler( ${CMAKE_C_COMPILER} Clang )
-cmake_force_cxx_compiler( ${CMAKE_CXX_COMPILER} Clang )
+cmake_force_c_compiler( ${CMAKE_C_COMPILER} Clang )
+cmake_force_cxx_compiler( ${CMAKE_CXX_COMPILER} Clang )
-set( CMAKE_C_COMPILER_VERSION 3.2 )
-set( CMAKE_CXX_COMPILER_VERSION 3.2 )
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
View
1  etc/PKGBUILD
@@ -21,6 +21,7 @@ function build()
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_FLAGS="${CXXFLAGS/-O2} -msse3 -mfpmath=sse" \
-D CMAKE_CXX_FLAGS_RELEASE="-Ofast -flto" \
+ -D BUILD_SHARED_LIBS=1 \
-D OZ_LUAJIT=1 \
-D OZ_NONFREE=1 \
..
View
1  etc/PKGBUILD.aur
@@ -26,6 +26,7 @@ function build()
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr \
-D CMAKE_CXX_FLAGS="$CXXFLAGS -msse3 -mfpmath=sse" \
+ -D BUILD_SHARED_LIBS=0 \
-D OZ_LUAJIT=1 \
-D OZ_NONFREE=1 \
..
View
1  etc/openzone.spec
@@ -76,6 +76,7 @@ cmake \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_FLAGS="-msse3 -mfpmath=sse" \
-D CMAKE_CXX_FLAGS_RELEASE="-Ofast -flto" \
+ -D BUILD_SHARED_LIBS=1 \
..
make %{?_smp_mflags}
View
23 etc/patches/freetype-2.4.11.patch
@@ -0,0 +1,23 @@
+diff -Naur freetype-2.4.11.orig/builds/unix/config.sub freetype-2.4.11/builds/unix/config.sub
+--- freetype-2.4.11.orig/builds/unix/config.sub 2012-12-20 08:35:22.000000000 +0100
++++ freetype-2.4.11/builds/unix/config.sub 2013-01-11 16:41:42.002166917 +0100
+@@ -639,6 +639,10 @@
+ basic_machine=elxsi-elxsi
+ os=-bsd
+ ;;
++ emscripten)
++ basic_machine=le32-unknown
++ os=-emscripten
++ ;;
+ encore | umax | mmax)
+ basic_machine=ns32k-encore
+ ;;
+@@ -1510,6 +1514,8 @@
+ ;;
+ -nacl*)
+ ;;
++ -emscripten*)
++ ;;
+ -none)
+ ;;
+ *)
View
23 etc/patches/libogg-1.3.0.patch
@@ -1,6 +1,6 @@
-diff -Naur libogg-1.3.0/config.sub libogg-1.3.0-nacl/config.sub
---- libogg-1.3.0/config.sub 2010-03-29 13:21:24.000000000 +0200
-+++ libogg-1.3.0-nacl/config.sub 2012-10-14 15:29:14.782198877 +0200
+diff -Naur libogg-1.3.0.orig/config.sub libogg-1.3.0/config.sub
+--- libogg-1.3.0.orig/config.sub 2010-03-29 13:21:24.000000000 +0200
++++ libogg-1.3.0/config.sub 2013-01-11 16:32:31.108348588 +0100
@@ -448,6 +448,10 @@
basic_machine=m68k-unknown
os=-sysv4
@@ -12,7 +12,18 @@ diff -Naur libogg-1.3.0/config.sub libogg-1.3.0-nacl/config.sub
apollo68)
basic_machine=m68k-apollo
os=-sysv
-@@ -775,6 +779,10 @@
+@@ -579,6 +583,10 @@
+ basic_machine=elxsi-elxsi
+ os=-bsd
+ ;;
++ emscripten)
++ basic_machine=i686-pc
++ os=-emscripten
++ ;;
+ encore | umax | mmax)
+ basic_machine=ns32k-encore
+ ;;
+@@ -775,6 +783,10 @@
basic_machine=i370-ibm
os=-mvs
;;
@@ -23,13 +34,13 @@ diff -Naur libogg-1.3.0/config.sub libogg-1.3.0-nacl/config.sub
ncr3000)
basic_machine=i486-ncr
os=-sysv4
-@@ -1302,7 +1310,8 @@
+@@ -1302,7 +1314,8 @@
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
- | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
+ | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
-+ | -nacl* | -android*)
++ | -nacl* | -android* | -emscripten*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
View
23 etc/patches/libvorbis-1.3.3.patch
@@ -1,6 +1,6 @@
-diff -Naur libvorbis-1.3.3/config.sub libvorbis-1.3.3-nacl/config.sub
---- libvorbis-1.3.3/config.sub 2006-08-10 17:17:12.000000000 +0200
-+++ libvorbis-1.3.3-nacl/config.sub 2012-10-14 15:36:09.150078136 +0200
+diff -Naur libvorbis-1.3.3.orig/config.sub libvorbis-1.3.3/config.sub
+--- libvorbis-1.3.3.orig/config.sub 2006-08-10 17:17:12.000000000 +0200
++++ libvorbis-1.3.3/config.sub 2013-01-11 16:34:19.955900267 +0100
@@ -426,6 +426,10 @@
basic_machine=m68k-unknown
os=-sysv4
@@ -12,7 +12,18 @@ diff -Naur libvorbis-1.3.3/config.sub libvorbis-1.3.3-nacl/config.sub
apollo68)
basic_machine=m68k-apollo
os=-sysv
-@@ -714,6 +718,10 @@
+@@ -533,6 +537,10 @@
+ basic_machine=elxsi-elxsi
+ os=-bsd
+ ;;
++ emscripten)
++ basic_machine=i686-pc
++ os=-emscripten
++ ;;
+ encore | umax | mmax)
+ basic_machine=ns32k-encore
+ ;;
+@@ -714,6 +722,10 @@
basic_machine=i370-ibm
os=-mvs
;;
@@ -23,12 +34,12 @@ diff -Naur libvorbis-1.3.3/config.sub libvorbis-1.3.3-nacl/config.sub
ncr3000)
basic_machine=i486-ncr
os=-sysv4
-@@ -1214,7 +1222,7 @@
+@@ -1214,7 +1226,7 @@
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
- | -skyos* | -haiku* | -rdos* | -toppers*)
-+ | -skyos* | -haiku* | -rdos* | -toppers* | -nacl* | -android*)
++ | -skyos* | -haiku* | -rdos* | -toppers* | -nacl* | -android* | -emscripten*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
View
48 ports.sh
@@ -16,14 +16,15 @@
#
platforms=(
- NaCl-x86_64
- NaCl-i686
+# NaCl-x86_64
+# NaCl-i686
# NaCl-ARM
# PNaCl
- Android14-i686
+# Android14-i686
# Android14-ARM
# Android14-ARMv7a
# Android14-MIPS
+ Emscripten
)
projectDir=`pwd`
@@ -42,6 +43,8 @@ ndkARMPlatform="$ANDROID_NDK/platforms/android-14/arch-arm"
ndkMIPSTools="$ANDROID_NDK/toolchains/mipsel-linux-android-4.6/prebuilt/linux-x86"
ndkMIPSPlatform="$ANDROID_NDK/platforms/android-14/arch-mips"
+emscriptenPrefix="$EMSCRIPTEN"
+
function msg()
{
echo -ne "\e[1;32m"
@@ -294,6 +297,37 @@ function setup_ndk_MIPS()
(( $enabled )) || return 1
}
+function setup_emscripten()
+{
+ platform="Emscripten" # Platform name.
+ buildDir="$topDir/$platform" # Build and install directory.
+ triplet="emscripten" # Platform triplet (tools prefix).
+ hostTriplet="emscripten" # Host triplet for autotools configure.
+ sysroot="$emscriptenPrefix/system" # SDK sysroot.
+ toolsroot="$emscriptenPrefix" # SDK tool root.
+ toolchain="$projectDir/cmake/$platform.Toolchain.cmake" # CMake toolchain.
+
+ #export CPP="$toolsroot/bin/$triplet-cpp"
+ export -n CPP
+ export CC="$toolsroot/emcc"
+ export AR="$toolsroot/emar"
+ export RANLIB="$toolsroot/emranlib"
+ export STRIP="/bin/true"
+ export PKG_CONFIG_PATH="$buildDir/usr/lib/pkgconfig"
+ export PKG_CONFIG_LIBDIR="$buildDir/usr/lib"
+ export PATH="$toolsroot/bin:$PATH"
+
+ export CPPFLAGS="-I$buildDir/usr/include"
+ export CFLAGS="-O2 -U__STRICT_ANSI__"
+ export LDFLAGS="-L$buildDir/usr/lib"
+
+ enabled=0
+ for p in ${platforms[@]}; do
+ [[ $p == $platform ]] && enabled=1
+ done
+ (( $enabled )) || return 1
+}
+
function clean()
{
for platform in ${platforms[@]}; do
@@ -503,6 +537,7 @@ function build_sdl2()
function build_freetype()
{
prepare freetype-2.4.11 freetype-2.4.11.tar.bz2 || return
+ applyPatches freetype-2.4.11.patch
autotoolsBuild --disable-shared --without-bzip2
@@ -572,6 +607,7 @@ function build()
setup_nacl_i686 && build_zlib
setup_nacl_ARM && build_zlib
setup_pnacl && build_zlib
+ setup_emscripten && build_zlib
# PhysicsFS
setup_nacl_x86_64 && build_physfs
@@ -582,6 +618,7 @@ function build()
setup_ndk_ARM && build_physfs
setup_ndk_ARMv7a && build_physfs
setup_ndk_MIPS && build_physfs
+ setup_emscripten && build_physfs
# Lua
setup_nacl_x86_64 && build_lua
@@ -592,6 +629,7 @@ function build()
setup_ndk_ARM && build_lua
setup_ndk_ARMv7a && build_lua
setup_ndk_MIPS && build_lua
+ setup_emscripten && build_lua
# LuaJIT
# setup_nacl_x86_64 && build_luajit
@@ -622,6 +660,7 @@ function build()
setup_ndk_ARM && build_freetype
setup_ndk_ARMv7a && build_freetype
setup_ndk_MIPS && build_freetype
+ setup_emscripten && build_freetype
# SDL_ttf
setup_nacl_x86_64 && build_sdl_ttf
@@ -642,6 +681,7 @@ function build()
setup_ndk_ARM && build_openal
setup_ndk_ARMv7a && build_openal
setup_ndk_MIPS && build_openal
+ setup_emscripten && build_openal
# libogg
setup_nacl_x86_64 && build_libogg
@@ -652,6 +692,7 @@ function build()
setup_ndk_ARM && build_libogg
setup_ndk_ARMv7a && build_libogg
setup_ndk_MIPS && build_libogg
+ setup_emscripten && build_libogg
# libvorbis
setup_nacl_x86_64 && build_libvorbis
@@ -662,6 +703,7 @@ function build()
setup_ndk_ARM && build_libvorbis
setup_ndk_ARMv7a && build_libvorbis
setup_ndk_MIPS && build_libvorbis
+ setup_emscripten && build_libvorbis
}
case $1 in
View
2  src/client/ui/Text.cc
@@ -31,7 +31,7 @@
#include <client/ui/Style.hh>
#include <client/ui/Area.hh>
-#if defined( __ANDROID__ ) || defined( _WIN32 )
+#if defined( EMSCRIPTEN ) || defined( __ANDROID__ ) || defined( _WIN32 )
static char* strchrnul( const char* s, int c )
{
while( *s != c && *s != '\0' ) {
View
4 src/common/Lua.cc
@@ -34,10 +34,6 @@ namespace common
int Lua::randomSeed = 0;
bool Lua::isRandomSeedTime = true;
-Lua::Lua() :
- l( nullptr )
-{}
-
bool Lua::readVariable( InputStream* istream )
{
char ch = istream->readChar();
View
7 src/common/Lua.hh
@@ -25,7 +25,7 @@
#include <common/common.hh>
-// Forward declaration needed for Lua API declarations, to prevent pollution from Lua headers.
+// Forward declaration to prevent pollution from Lua headers.
struct lua_State;
namespace oz
@@ -57,11 +57,6 @@ class Lua
protected:
/**
- * Default constructor, clears `l` to `nullptr`.
- */
- explicit Lua();
-
- /**
* Read serialised %Lua variable and push it on global stack (recursively for tables).
*/
bool readVariable( InputStream* istream );
View
12 src/ozCore/BufferStream.hh
@@ -1359,9 +1359,9 @@ class BufferStream
}
/**
- * Read line from a text file.
+ * Read a line.
*
- * Line delimiting character is not part of the returned string.
+ * Line delimiter is read but not included in the returned string.
*/
String readLine()
{
@@ -1379,9 +1379,7 @@ class BufferStream
}
/**
- * Write line in a text file.
- *
- * This writes the given string but replaces terminating null character with a UNIX newline.
+ * Write a line replacing terminating null byte with UNIX newline.
*/
OZ_ALWAYS_INLINE
void writeLine( const String& s )
@@ -1394,9 +1392,7 @@ class BufferStream
}
/**
- * Write line in a text file.
- *
- * This writes the given string but replaces terminating null character with a UNIX newline.
+ * Write a line replacing terminating null byte with UNIX newline.
*/
OZ_ALWAYS_INLINE
void writeLine( const char* s )
View
2  src/ozCore/Chain.hh
@@ -222,7 +222,7 @@ class Chain
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( firstElem );
}
View
2  src/ozCore/DArray.hh
@@ -178,7 +178,7 @@ class DArray
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( data, data + count );
}
View
2  src/ozCore/DChain.hh
@@ -230,7 +230,7 @@ class DChain
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( firstElem );
}
View
6 src/ozCore/HashMap.hh
@@ -254,7 +254,7 @@ class HashMap
* Move constructor, moves storage.
*/
HashMap( HashMap&& hm ) :
- pool( static_cast< Pool<Elem, SIZE>&& >( hm.pool ) )
+ pool( static_cast<Pool<Elem, SIZE>&&>( hm.pool ) )
{
aCopy<Elem*>( data, hm.data, SIZE );
aFill<Elem*, Elem*>( hm.data, nullptr, SIZE );
@@ -289,7 +289,7 @@ class HashMap
aCopy<Elem*>( data, hm.data, SIZE );
aFill<Elem*, Elem*>( hm.data, nullptr, SIZE );
- pool = static_cast< Pool<Elem, SIZE>&& >( hm.pool );
+ pool = static_cast<Pool<Elem, SIZE>&&>( hm.pool );
return *this;
}
@@ -341,7 +341,7 @@ class HashMap
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( data );
}
View
6 src/ozCore/HashSet.hh
@@ -252,7 +252,7 @@ class HashSet
* Move constructor, moves storage.
*/
HashSet( HashSet&& hs ) :
- pool( static_cast< Pool<Elem, SIZE>&& >( hs.pool ) )
+ pool( static_cast<Pool<Elem, SIZE>&&>( hs.pool ) )
{
aCopy<Elem*>( data, hs.data, SIZE );
aFill<Elem*, Elem*>( hs.data, nullptr, SIZE );
@@ -287,7 +287,7 @@ class HashSet
aCopy<Elem*>( data, hs.data, SIZE );
aFill<Elem*, Elem*>( hs.data, nullptr, SIZE );
- pool = static_cast< Pool<Elem, SIZE>&& >( hs.pool );
+ pool = static_cast<Pool<Elem, SIZE>&&>( hs.pool );
return *this;
}
@@ -339,7 +339,7 @@ class HashSet
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( data );
}
View
4 src/ozCore/InputStream.hh
@@ -628,9 +628,9 @@ class InputStream
}
/**
- * Read line from a text file.
+ * Read a line.
*
- * Line delimiting character is not part of the returned string.
+ * Line delimiter is read but not included in the returned string.
*/
String readLine()
{
View
122 src/ozCore/JSON.cc
@@ -105,6 +105,32 @@ struct JSON::ObjectData : JSON::Data
HashMap<String, JSON> table;
};
+JSON::CIterator::CIterator( const ObjectData* data ) :
+ IteratorBase<const HashMap<String, JSON>::Elem>( nullptr ), objectIter( data->table.citer() )
+{
+ elem = objectIter;
+}
+
+JSON::CIterator& JSON::CIterator::operator ++ ()
+{
+ ++objectIter;
+ elem = objectIter;
+ return *this;
+}
+
+JSON::Iterator::Iterator( ObjectData* data ) :
+ IteratorBase<HashMap<String, JSON>::Elem>( nullptr ), objectIter( data->table.iter() )
+{
+ elem = objectIter;
+}
+
+JSON::Iterator& JSON::Iterator::operator ++ ()
+{
+ ++objectIter;
+ elem = objectIter;
+ return *this;
+}
+
struct JSON::Parser
{
struct Position
@@ -178,7 +204,7 @@ void JSON::Parser::setAccessed( JSON* value )
break;
}
case ARRAY: {
- const List<JSON>& list = static_cast<const ArrayData*>( value->data )->list;
+ List<JSON>& list = static_cast<ArrayData*>( value->data )->list;
foreach( i, list.iter() ) {
setAccessed( i );
@@ -186,7 +212,7 @@ void JSON::Parser::setAccessed( JSON* value )
break;
}
case OBJECT: {
- const HashMap<String, JSON>& table = static_cast<const ObjectData*>( value->data )->table;
+ HashMap<String, JSON>& table = static_cast<ObjectData*>( value->data )->table;
foreach( i, table.iter() ) {
setAccessed( &i->value );
@@ -669,6 +695,24 @@ JSON::JSON() :
data( nullptr ), valueType( NIL ), wasAccessed( true )
{}
+JSON::JSON( const char* path ) :
+ data( nullptr ), valueType( NIL ), wasAccessed( true )
+{
+ load( path );
+}
+
+JSON::JSON( File* file ) :
+ data( nullptr ), valueType( NIL ), wasAccessed( true )
+{
+ load( file );
+}
+
+JSON::JSON( PFile* file ) :
+ data( nullptr ), valueType( NIL ), wasAccessed( true )
+{
+ load( file );
+}
+
JSON::~JSON()
{
clear();
@@ -792,6 +836,30 @@ const JSON& JSON::operator [] ( const char* key ) const
return *value;
}
+JSON::CIterator JSON::objectCIter() const
+{
+ if( valueType == OBJECT ) {
+ const ObjectData* objectData = static_cast<const ObjectData*>( data );
+
+ return CIterator( objectData );
+ }
+ else {
+ return CIterator();
+ }
+}
+
+JSON::Iterator JSON::objectIter()
+{
+ if( valueType == OBJECT ) {
+ ObjectData* objectData = static_cast<ObjectData*>( data );
+
+ return Iterator( objectData );
+ }
+ else {
+ return Iterator();
+ }
+}
+
bool JSON::asBool() const
{
wasAccessed = true;
@@ -2468,12 +2536,20 @@ String JSON::toString() const
}
}
+String JSON::toFormattedString( const char* lineEnd ) const
+{
+ BufferStream os;
+ write( &os, lineEnd );
+
+ return String( os.begin(), os.length() );
+}
+
void JSON::read( InputStream* istream, const char* path )
{
*this = Parser::parse( istream, path );
}
-void JSON::write( BufferStream* ostream, const char* lineEnd )
+void JSON::write( BufferStream* ostream, const char* lineEnd ) const
{
Formatter formatter = { ostream, lineEnd, String::length( lineEnd ), 0 };
@@ -2481,6 +2557,20 @@ void JSON::write( BufferStream* ostream, const char* lineEnd )
ostream->writeChars( lineEnd, formatter.lineEndLength );
}
+bool JSON::load( const char* path )
+{
+ File file( path );
+ if( !file.map() ) {
+ return false;
+ }
+
+ InputStream is = file.inputStream();
+ read( &is, file.path() );
+
+ file.unmap();
+ return true;
+}
+
bool JSON::load( File* file )
{
if( !file->map() ) {
@@ -2488,7 +2578,6 @@ bool JSON::load( File* file )
}
InputStream is = file->inputStream();
-
read( &is, file->path() );
file->unmap();
@@ -2502,29 +2591,36 @@ bool JSON::load( PFile* file )
}
InputStream is = file->inputStream();
-
read( &is, file->path() );
file->unmap();
return true;
}
-bool JSON::save( File* file, const char* lineEnd )
+bool JSON::save( const char* path, const char* lineEnd ) const
{
- BufferStream ostream;
+ File file( path );
- write( &ostream, lineEnd );
+ BufferStream os;
+ write( &os, lineEnd );
- return file->write( ostream.begin(), ostream.length() );
+ return file.write( os.begin(), os.length() );
}
-bool JSON::save( PFile* file, const char* lineEnd )
+bool JSON::save( File* file, const char* lineEnd ) const
{
- BufferStream ostream;
+ BufferStream os;
+ write( &os, lineEnd );
- write( &ostream, lineEnd );
+ return file->write( os.begin(), os.length() );
+}
+
+bool JSON::save( PFile* file, const char* lineEnd ) const
+{
+ BufferStream os;
+ write( &os, lineEnd );
- return file->write( ostream.begin(), ostream.length() );
+ return file->write( os.begin(), os.length() );
}
}
View
183 src/ozCore/JSON.hh
@@ -28,6 +28,7 @@
#pragma once
+#include "HashMap.hh"
#include "BufferStream.hh"
#include "PFile.hh"
@@ -69,10 +70,82 @@ class JSON
struct Parser;
struct Formatter;
+ public:
+
+ /**
+ * %Iterator for %JSON objects with constant access.
+ */
+ class CIterator : public IteratorBase<const HashMap<String, JSON>::Elem>
+ {
+ private:
+
+ /**
+ * HashMap iterator used internally.
+ */
+ HashMap<String, JSON>::CIterator objectIter;
+
+ public:
+
+ /**
+ * Default constructor, creates an invalid iterator.
+ */
+ OZ_ALWAYS_INLINE
+ explicit CIterator() :
+ IteratorBase<const HashMap<String, JSON>::Elem>( nullptr )
+ {}
+
+ /**
+ * Create iterator for the given %JSON object's data.
+ */
+ explicit CIterator( const ObjectData* data );
+
+ /**
+ * Advance to the next element.
+ */
+ CIterator& operator ++ ();
+
+ };
+
+ /**
+ * %Iterator for %JSON objects with non-constant access.
+ */
+ class Iterator : public IteratorBase<HashMap<String, JSON>::Elem>
+ {
+ private:
+
+ /**
+ * HashMap iterator used internally.
+ */
+ HashMap<String, JSON>::Iterator objectIter;
+
+ public:
+
+ /**
+ * Default constructor, creates an invalid iterator.
+ */
+ OZ_ALWAYS_INLINE
+ explicit Iterator() :
+ IteratorBase<HashMap<String, JSON>::Elem>( nullptr )
+ {}
+
+ /**
+ * Create iterator for the given %JSON object's data.
+ */
+ explicit Iterator( ObjectData* data );
+
+ /**
+ * Advance to the next element.
+ */
+ Iterator& operator ++ ();
+
+ };
+
+ private:
+
/// A null value instance, required by `operator []`.
static const JSON NIL_VALUE;
- Data* data; ///< Pointer to internal data struct.
+ Data* data; ///< Pointer to internal data structure.
Type valueType; ///< Value type, `JSON::Type`.
mutable bool wasAccessed; ///< For warnings about unused variables.
@@ -89,6 +162,21 @@ class JSON
explicit JSON();
/**
+ * Create from a file contents.
+ */
+ explicit JSON( const char* path );
+
+ /**
+ * Create from a file contents.
+ */
+ explicit JSON( File* file );
+
+ /**
+ * Create from a file contents.
+ */
+ explicit JSON( PFile* file );
+
+ /**
* Destructor.
*/
~JSON();
@@ -120,7 +208,7 @@ class JSON
}
/**
- * Number of entries if value is an object or array, -1 otherwise.
+ * Number of entries if value is an array or an object, -1 otherwise.
*/
int length() const;
@@ -153,6 +241,20 @@ class JSON
const JSON& operator [] ( const char* key ) const;
/**
+ * %JSON object iterator with constant access.
+ *
+ * An invalid iterator is returned if the %JSON element is not an object.
+ */
+ CIterator objectCIter() const;
+
+ /**
+ * %JSON object iterator with non-constant access.
+ *
+ * An invalid iterator is returned if the %JSON element is not an object.
+ */
+ Iterator objectIter();
+
+ /**
* Get boolean value.
*
* If value is not a boolean, `System::error()` is invoked.
@@ -402,112 +504,112 @@ class JSON
Mat44 get( const Mat44& defaultValue ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with boolean elements,
* `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( bool* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with number elements,
* `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( int* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with number elements,
* `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( float* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with string elements,
* `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( String* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with arrays of 3 numbers as
* elements, `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( Vec3* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with arrays of 4 numbers as
* elements, `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( Vec4* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with arrays of 3 numbers as
* elements, `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( Point* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with arrays of 4 numbers as
* elements, `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( Plane* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with arrays of 4 numbers as
* elements, `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( Quat* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with arrays of 9 numbers as
* elements, `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( Mat33* array, int count ) const;
/**
- * Write array values into the given array (it is left unchanged if %JSON value is null).
+ * Write array values into the given array (it is left unchanged if %JSON element is null).
*
* If value is not either null or an array of the specified length with arrays of 16 numbers as
* elements, `System::error()` is invoked.
*
- * @return true if destination array has been filled, false if %JSON array is null.
+ * @return true if destination array has been filled, false if %JSON element is null.
*/
bool get( Mat44* array, int count ) const;
@@ -959,6 +1061,13 @@ class JSON
String toString() const;
/**
+ * Formatted String representation of a value.
+ *
+ * This function returns string written by `write()` method.
+ */
+ String toFormattedString(const char* lineEnd = "\n" ) const;
+
+ /**
* Clear existing value and read new contents from a stream.
*
* @param istream input stream.
@@ -967,12 +1076,21 @@ class JSON
void read( InputStream* istream, const char* path = "InputStream" );
/**
- * Write formatted JSON to a stream.
+ * Write formatted %JSON to a stream.
+ */
+ void write( BufferStream* ostream, const char* lineEnd = "\n" ) const;
+
+ /**
+ * Clear existing value and read new contents from a %JSON file (via `File` class).
+ *
+ * If file open fails, existing value is kept intact.
+ *
+ * @return true iff file is successfully read and parsed.
*/
- void write( BufferStream* ostream, const char* lineEnd = "\n" );
+ bool load( const char* path );
/**
- * Clear existing value and read new contents from a JSON file.
+ * Clear existing value and read new contents from a %JSON file.
*
* If file open fails, existing value is kept intact.
*
@@ -981,7 +1099,7 @@ class JSON
bool load( File* file );
/**
- * Clear existing value and read new contents from a JSON file.
+ * Clear existing value and read new contents from a %JSON file.
*
* If file open fails, existing value is kept intact.
*
@@ -990,14 +1108,19 @@ class JSON
bool load( PFile* file );
/**
+ * Write to a file (via `File` class).
+ */
+ bool save( const char* path, const char* lineEnd = "\n" ) const;
+
+ /**
* Write to a file.
*/
- bool save( File* file, const char* lineEnd = "\n" );
+ bool save( File* file, const char* lineEnd = "\n" ) const;
/**
* Write to a file.
*/
- bool save( PFile* file, const char* lineEnd = "\n" );
+ bool save( PFile* file, const char* lineEnd = "\n" ) const;
};
View
2  src/ozCore/List.hh
@@ -197,7 +197,7 @@ class List
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( data, data + count );
}
View
2  src/ozCore/Map.hh
@@ -223,7 +223,7 @@ class Map
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( data, data + count );
}
View
12 src/ozCore/OutputStream.hh
@@ -1245,9 +1245,9 @@ class OutputStream
}
/**
- * Read line from a text file.
+ * Read a line.
*
- * Line delimiting character is not part of the returned string.
+ * Line delimiter is read but not included in the returned string.
*/
String readLine()
{
@@ -1265,9 +1265,7 @@ class OutputStream
}
/**
- * Write line in a text file.
- *
- * This writes the given string but replaces terminating null character with a UNIX newline.
+ * Write a line replacing terminating null byte with UNIX newline.
*/
OZ_ALWAYS_INLINE
void writeLine( const String& s )
@@ -1280,9 +1278,7 @@ class OutputStream
}
/**
- * Write line in a text file.
- *
- * This writes the given string but replaces terminating null character with a UNIX newline.
+ * Write a line replacing terminating null byte with UNIX newline.
*/
OZ_ALWAYS_INLINE
void writeLine( const char* s )
View
2  src/ozCore/Set.hh
@@ -200,7 +200,7 @@ class Set
* %Iterator with non-constant access, initially points to the first element.
*/
OZ_ALWAYS_INLINE
- Iterator iter() const
+ Iterator iter()
{
return Iterator( data, data + count );
}
View
56 src/ozCore/System.cc
@@ -36,7 +36,10 @@
#include <cstdlib>
#include <exception>
-#if defined( __ANDROID__ )
+#if defined( EMSCRIPTEN )
+# include <ctime>
+# include <pthread.h>
+#elif defined( __ANDROID__ )
# include <android/log.h>
# include <ctime>
# include <pthread.h>
@@ -97,7 +100,11 @@ static const float BELL_TIME = 0.30f;
static const float BELL_FREQUENCY = 1000.0f;
static const int BELL_PREFERRED_RATE = 44100;
-#if defined( __ANDROID__ )
+#if defined( EMSCRIPTEN )
+
+static const timespec TIMESPEC_10MS = { 0, 10 * 1000000 };
+
+#elif defined( __ANDROID__ )
static const timespec TIMESPEC_10MS = { 0, 10 * 1000000 };
@@ -251,9 +258,27 @@ static void genBellSamples( short* samples, int nSamples_, int rate, int begin,
}
}
-#if defined( __ANDROID__ )
+#if defined( EMSCRIPTEN )
-// TODO: Implement bell for OpenSL ES.
+static void* bellMain( void* )
+{
+ static_cast<void>( genBellSamples );
+
+ // TODO: Implement bell for Emscripten.
+ fprintf( stderr, "*** BELL ***\n" );
+ return nullptr;
+}
+
+#elif defined( __ANDROID__ )
+
+static void* bellMain( void* )
+{
+ static_cast<void>( genBellSamples );
+
+ // TODO: Implement bell for OpenSL ES.
+ __android_log_write( ANDROID_LOG_DEFAULT, "oz", "*** BELL ***\n" );
+ return nullptr;
+}
#elif defined( __native_client__ )
@@ -567,13 +592,7 @@ bool System::isInstrumented()
void System::bell()
{
-#if defined( __ANDROID__ )
-
- static_cast<void>( genBellSamples );
-
- __android_log_write( ANDROID_LOG_DEFAULT, "oz", "*** BELL ***\n" );
-
-#elif defined( __native_client__ )
+#if defined( __native_client__ )
if( instance != nullptr && !__sync_lock_test_and_set( &isBellPlaying, true ) ) {
core = pp::Module::Get()->core();
@@ -678,24 +697,23 @@ void System::init( int flags, CrashHandler* crashHandler_ )
initFlags = flags;
crashHandler = crashHandler_;
-#if defined( __unix__ ) && !defined( __ANDROID__ ) && !defined( __native_client__ )
+#if !defined( EMSCRIPTEN ) && !defined( __ANDROID__ ) && !defined( __native_client__ ) && \
+ !defined( _WIN32 )
int fd = open( "/proc", O_RDONLY );
isDebuggerAttached = fd >= 5;
close( fd );
+
+ if( initFlags & LOCALE_BIT ) {
+ setlocale( LC_ALL, "" );
+ }
#endif
if( initFlags & HANDLERS_BIT ) {
- catchSignals();
-
std::set_terminate( terminate );
std::set_unexpected( unexpected );
}
-#if !defined( __ANDROID__ ) && !defined( __native_client__ )
- if( initFlags & LOCALE_BIT ) {
- setlocale( LC_ALL, "" );
- }
-#endif
+ threadInit();
}
}
View
8 src/tests/test.cc
@@ -118,10 +118,8 @@ class Foo
int main()
{
System::init();
- const char* s = " 1 2 3 ";
- DArray<String> tokens = String::split( s, ' ' );
- for( const String& s : tokens ) {
- Log() << s << ": " << s.parseFloat() << "\n";
- }
+
+ JSON json( "/home/davorin/.config/chromium/Default/Bookmarks" );
+ Log() << json.toFormattedString();
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.