Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/ci-build.yml # .github/workflows/release-linux.yml # .github/workflows/release-macos.yml # .github/workflows/release-source.yml # .github/workflows/release.yml # CMakeLists.txt # COMPILING.md # src/ai/ai_core.cpp # src/ai/ai_gui.cpp # src/bridge_gui.cpp # src/company_gui.cpp # src/console_cmds.cpp # src/core/CMakeLists.txt # src/core/smallmap_type.hpp # src/disaster_vehicle.h # src/effectvehicle_base.h # src/fontcache.cpp # src/game/game_core.cpp # src/game/game_gui.cpp # src/gamelog.cpp # src/gamelog_internal.h # src/group_gui.cpp # src/linkgraph/linkgraph.h # src/misc.cpp # src/network/core/config.h # src/network/core/udp.cpp # src/network/network_chat_gui.cpp # src/network/network_content_gui.cpp # src/network/network_gui.cpp # src/newgrf.cpp # src/newgrf_gui.cpp # src/newgrf_profiling.cpp # src/newgrf_profiling.h # src/object_gui.cpp # src/openttd.cpp # src/openttd.h # src/order_gui.cpp # src/os/windows/font_win32.cpp # src/rail_gui.cpp # src/road.cpp # src/road_gui.cpp # src/saveload/afterload.cpp # src/saveload/saveload.h # src/script/api/script_controller.cpp # src/script/api/script_roadtypelist.cpp # src/script/script_config.cpp # src/script/script_config.hpp # src/script/script_instance.cpp # src/script/script_scanner.cpp # src/script/squirrel.cpp # src/script/squirrel_helper.hpp # src/settings_gui.cpp # src/settings_internal.h # src/settings_type.h # src/table/settings/network_private_settings.ini # src/timetable_gui.cpp # src/vehicle.cpp # src/vehicle_base.h # src/window_gui.hpull/562/head
commit
d09b504bc5
@ -0,0 +1,20 @@
|
|||||||
|
# nlohmann-json is a custom addition to the emscripten SDK, so it is possible
|
||||||
|
# someone patched their SDK. Test out if the SDK supports nlohmann-json.
|
||||||
|
include(CheckCXXSourceCompiles)
|
||||||
|
set(CMAKE_REQUIRED_FLAGS "-sUSE_NLOHMANN_JSON=1")
|
||||||
|
|
||||||
|
check_cxx_source_compiles("
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
int main() { return 0; }"
|
||||||
|
NLOHMANN_JSON_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NLOHMANN_JSON_FOUND)
|
||||||
|
add_library(nlohmann_json INTERFACE IMPORTED)
|
||||||
|
set_target_properties(nlohmann_json PROPERTIES
|
||||||
|
INTERFACE_COMPILE_OPTIONS "-sUSE_NLOHMANN_JSON=1"
|
||||||
|
INTERFACE_LINK_LIBRARIES "-sUSE_NLOHMANN_JSON=1"
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(WARNING "You are using an emscripten SDK without nlohmann-json support. Please apply 'emsdk-nlohmann_json.patch' to your local emsdk installation.")
|
||||||
|
endif()
|
@ -0,0 +1,93 @@
|
|||||||
|
From 0edcedbea375e59f41df10acaee0c483d245751f Mon Sep 17 00:00:00 2001
|
||||||
|
From: Patric Stout <truebrain@openttd.org>
|
||||||
|
Date: Tue, 2 May 2023 21:48:08 +0200
|
||||||
|
Subject: [PATCH] Add nlohmmann-json port
|
||||||
|
|
||||||
|
---
|
||||||
|
src/settings.js | 4 ++++
|
||||||
|
tools/ports/nlohmann_json.py | 46 ++++++++++++++++++++++++++++++++++++
|
||||||
|
tools/settings.py | 1 +
|
||||||
|
3 files changed, 51 insertions(+)
|
||||||
|
create mode 100644 tools/ports/nlohmann_json.py
|
||||||
|
|
||||||
|
diff --git a/src/settings.js b/src/settings.js
|
||||||
|
index f93140d..39f4366 100644
|
||||||
|
--- a/src/settings.js
|
||||||
|
+++ b/src/settings.js
|
||||||
|
@@ -1483,6 +1483,10 @@ var USE_MPG123 = false;
|
||||||
|
// [compile+link]
|
||||||
|
var USE_FREETYPE = false;
|
||||||
|
|
||||||
|
+// 1 = use nlohmann-json from emscripten-ports
|
||||||
|
+// [compile+link]
|
||||||
|
+var USE_NLOHMANN_JSON = false;
|
||||||
|
+
|
||||||
|
// Specify the SDL_mixer version that is being linked against.
|
||||||
|
// Doesn't *have* to match USE_SDL, but a good idea.
|
||||||
|
// [compile+link]
|
||||||
|
diff --git a/tools/ports/nlohmann_json.py b/tools/ports/nlohmann_json.py
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..9e44297
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/tools/ports/nlohmann_json.py
|
||||||
|
@@ -0,0 +1,46 @@
|
||||||
|
+# Copyright 2023 The Emscripten Authors. All rights reserved.
|
||||||
|
+# Emscripten is available under two separate licenses, the MIT license and the
|
||||||
|
+# University of Illinois/NCSA Open Source License. Both these licenses can be
|
||||||
|
+# found in the LICENSE file.
|
||||||
|
+
|
||||||
|
+import os
|
||||||
|
+
|
||||||
|
+TAG = '3.11.2'
|
||||||
|
+HASH = '99d9e6d588cabe8913a37437f86acb5d4b8b98bce12423e633c11c13b61e6c7f92ef8f9a4e991baa590329ee2b5c09ca9db9894bee1e54bdd68e8d09d83cc245'
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+def needed(settings):
|
||||||
|
+ return settings.USE_NLOHMANN_JSON
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+def get(ports, settings, shared):
|
||||||
|
+ ports.fetch_project('nlohmann_json',
|
||||||
|
+ f'https://github.com/nlohmann/json/releases/download/v{TAG}/include.zip',
|
||||||
|
+ sha512hash=HASH)
|
||||||
|
+
|
||||||
|
+ def create(final):
|
||||||
|
+ source_path = os.path.join(ports.get_dir(), 'nlohmann_json')
|
||||||
|
+ source_path_include = os.path.join(source_path, 'include', 'nlohmann')
|
||||||
|
+ ports.install_header_dir(source_path_include, 'nlohmann')
|
||||||
|
+
|
||||||
|
+ # write out a dummy cpp file, to create an empty library
|
||||||
|
+ # this is needed as emscripten ports expect this, even if it is not used
|
||||||
|
+ dummy_file = os.path.join(source_path, 'dummy.cpp')
|
||||||
|
+ shared.safe_ensure_dirs(os.path.dirname(dummy_file))
|
||||||
|
+ ports.write_file(dummy_file, 'static void dummy() {}')
|
||||||
|
+
|
||||||
|
+ ports.build_port(source_path, final, 'nlohmann_json', srcs=['dummy.cpp'])
|
||||||
|
+
|
||||||
|
+ return [shared.cache.get_lib('libnlohmann_json.a', create, what='port')]
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+def clear(ports, settings, shared):
|
||||||
|
+ shared.cache.erase_lib('libnlohmann_json.a')
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+def process_args(ports):
|
||||||
|
+ return []
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+def show():
|
||||||
|
+ return 'nlohmann-json'
|
||||||
|
diff --git a/tools/settings.py b/tools/settings.py
|
||||||
|
index 10d6ca0..8536092 100644
|
||||||
|
--- a/tools/settings.py
|
||||||
|
+++ b/tools/settings.py
|
||||||
|
@@ -47,6 +47,7 @@ PORTS_SETTINGS = {
|
||||||
|
'USE_MPG123',
|
||||||
|
'USE_GIFLIB',
|
||||||
|
'USE_FREETYPE',
|
||||||
|
+ 'USE_NLOHMANN_JSON',
|
||||||
|
'SDL2_MIXER_FORMATS',
|
||||||
|
'SDL2_IMAGE_FORMATS',
|
||||||
|
'USE_SQLITE3',
|
||||||
|
--
|
||||||
|
2.34.1
|
@ -1,147 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of OpenTTD.
|
|
||||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
||||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @file smallmap_type.hpp Simple mapping class targeted for small sets of data. Stored data shall be POD ("Plain Old Data")! */
|
|
||||||
|
|
||||||
#ifndef SMALLMAP_TYPE_HPP
|
|
||||||
#define SMALLMAP_TYPE_HPP
|
|
||||||
|
|
||||||
#include "smallvec_type.hpp"
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of simple mapping class.
|
|
||||||
* It has inherited accessors from std::vector().
|
|
||||||
* @tparam T Key type.
|
|
||||||
* @tparam U Value type.
|
|
||||||
* @tparam S Unit of allocation.
|
|
||||||
*
|
|
||||||
* @see std::vector
|
|
||||||
*/
|
|
||||||
template <typename T, typename U>
|
|
||||||
struct SmallMap : std::vector<std::pair<T, U> > {
|
|
||||||
typedef std::pair<T, U> Pair;
|
|
||||||
typedef Pair *iterator;
|
|
||||||
typedef const Pair *const_iterator;
|
|
||||||
|
|
||||||
/** Creates new SmallMap. Data are initialized in std::vector constructor */
|
|
||||||
inline SmallMap() { }
|
|
||||||
/** Data are freed in std::vector destructor */
|
|
||||||
inline ~SmallMap() { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds given key in this map
|
|
||||||
* @param key key to find
|
|
||||||
* @return &Pair(key, data) if found, this->End() if not
|
|
||||||
*/
|
|
||||||
inline typename std::vector<Pair>::const_iterator Find(const T &key) const
|
|
||||||
{
|
|
||||||
return std::find_if(std::vector<Pair>::begin(), std::vector<Pair>::end(), [&key](const Pair &pair) { return key == pair.first; });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds given key in this map
|
|
||||||
* @param key key to find
|
|
||||||
* @return &Pair(key, data) if found, this->End() if not
|
|
||||||
*/
|
|
||||||
inline Pair *Find(const T &key)
|
|
||||||
{
|
|
||||||
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
|
|
||||||
if (key == std::vector<Pair>::operator[](i).first) return &std::vector<Pair>::operator[](i);
|
|
||||||
}
|
|
||||||
return this->End();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Pair *End() const
|
|
||||||
{
|
|
||||||
return std::vector<Pair>::data() + std::vector<Pair>::size();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Pair *End()
|
|
||||||
{
|
|
||||||
return std::vector<Pair>::data() + std::vector<Pair>::size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether a key is assigned in this map.
|
|
||||||
* @param key key to test
|
|
||||||
* @return true iff the item is present
|
|
||||||
*/
|
|
||||||
inline bool Contains(const T &key) const
|
|
||||||
{
|
|
||||||
return this->Find(key) != std::vector<Pair>::end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether a key is assigned in this map.
|
|
||||||
* @param key key to test
|
|
||||||
* @return true iff the item is present
|
|
||||||
*/
|
|
||||||
inline bool Contains(const T &key)
|
|
||||||
{
|
|
||||||
return this->Find(key) != this->End();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes given pair from this map
|
|
||||||
* @param pair pair to remove
|
|
||||||
* @note it has to be pointer to pair in this map. It is overwritten by the last item.
|
|
||||||
*/
|
|
||||||
inline void Erase(Pair *pair)
|
|
||||||
{
|
|
||||||
assert(pair >= std::vector<Pair>::data() && pair < this->End());
|
|
||||||
auto distance = pair - std::vector<Pair>::data();
|
|
||||||
std::vector<Pair>::erase(std::vector<Pair>::begin() + distance);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes given key from this map
|
|
||||||
* @param key key to remove
|
|
||||||
* @return true iff the key was found
|
|
||||||
* @note last item is moved to its place, so don't increase your iterator if true is returned!
|
|
||||||
*/
|
|
||||||
inline bool Erase(const T &key)
|
|
||||||
{
|
|
||||||
Pair *pair = this->Find(key);
|
|
||||||
if (pair == this->End()) return false;
|
|
||||||
|
|
||||||
this->Erase(pair);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds new item to this map.
|
|
||||||
* @param key key
|
|
||||||
* @param data data
|
|
||||||
* @return true iff the key wasn't already present
|
|
||||||
*/
|
|
||||||
inline bool Insert(const T &key, const U &data)
|
|
||||||
{
|
|
||||||
if (this->Contains(key)) return false;
|
|
||||||
std::vector<Pair>::emplace_back(key, data);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns data belonging to this key
|
|
||||||
* @param key key
|
|
||||||
* @return data belonging to this key
|
|
||||||
* @note if this key wasn't present, new entry is created
|
|
||||||
*/
|
|
||||||
inline U &operator[](const T &key)
|
|
||||||
{
|
|
||||||
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
|
|
||||||
if (key == std::vector<Pair>::operator[](i).first) return std::vector<Pair>::operator[](i).second;
|
|
||||||
}
|
|
||||||
Pair &n = std::vector<Pair>::emplace_back();
|
|
||||||
n.first = key;
|
|
||||||
return n.second;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SMALLMAP_TYPE_HPP */
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue