Skip to content

Commit

Permalink
Windows port
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisloge authored and sopyer committed Jul 9, 2021
1 parent 2888511 commit 3a8ff01
Show file tree
Hide file tree
Showing 27 changed files with 449 additions and 76 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Created by http://www.gitignore.io

### OSX ###
.vscode
.vs

### OSX ###
.DS_Store
.AppleDouble
Expand Down
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.15)

project(tangram)

Expand All @@ -18,11 +18,6 @@ option(TANGRAM_DEV_MODE "For developers only: Don't omit the frame pointer" OFF)

message(STATUS "Build type configuration: ${CMAKE_BUILD_TYPE}")

# Check that submodules are present.
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/core/deps/harfbuzz-icu-freetype/harfbuzz/README")
message(SEND_ERROR "Missing submodules - Please run:\n 'git submodule update --init'")
return()
endif()

if(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG)
Expand Down
3 changes: 2 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project(tangram-core)

# Build core library dependencies.
find_package(yaml-cpp CONFIG REQUIRED)
add_subdirectory(deps)

add_library(tangram-core
Expand Down Expand Up @@ -231,7 +232,6 @@ target_link_libraries(tangram-core
alfons
double-conversion
miniz
z
)

# Add JavaScript implementation.
Expand Down Expand Up @@ -260,6 +260,7 @@ if(UNIX AND NOT APPLE)
target_link_libraries(tangram-core PRIVATE dl)
endif()

target_compile_definitions(tangram-core PUBLIC _USE_MATH_DEFINES)
if(TANGRAM_WARN_ON_RULE_CONFLICT)
target_compile_definitions(tangram-core
PRIVATE
Expand Down
26 changes: 11 additions & 15 deletions core/deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ add_library(glm INTERFACE)
target_include_directories(glm INTERFACE glm)
target_compile_definitions(glm INTERFACE GLM_FORCE_CTOR_INIT)

## yaml-cpp ##
##############
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "")
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "")
set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "")
set(YAML_CPP_INSTALL OFF CACHE BOOL "")
add_subdirectory(yaml-cpp)
### yaml-cpp ##
###############
#set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "")
#set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "")
#set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "")
#set(YAML_CPP_INSTALL OFF CACHE BOOL "")
#add_subdirectory(yaml-cpp)

target_include_directories(yaml-cpp PUBLIC yaml-cpp/include)
#target_include_directories(yaml-cpp PUBLIC yaml-cpp/include)

## css-color-parser-cpp ##
##########################
Expand Down Expand Up @@ -48,14 +48,10 @@ target_include_directories(miniz
if(NOT TANGRAM_USE_SYSTEM_FONT_LIBS)
## Harfbuzz - ICU-Common - Freetype2 ##
#######################################
set(HARFBUZZ_BUILD_ICU ON CACHE BOOL "Enable building of ICU")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/harfbuzz-icu-freetype)

message(STATUS "harfbuzz" ${HARFBUZZ_LIBRARIES})

#find_package(ICU REQUIRED COMPONENTS common)
find_package(harfbuzz CONFIG REQUIRED)
set(ALFONS_DEPS_LIBRARIES
${ALFONS_DEPS_LIBRARIES}
harfbuzz ${HARFBUZZ_LIBRARIES}
harfbuzz::harfbuzz
CACHE INTERNAL "alfons-libs" FORCE)
endif()

Expand Down
6 changes: 5 additions & 1 deletion core/deps/pbf/pbf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
#endif

namespace protobuf {

#if defined(__GNUC__)
#define FORCEINLINE inline __attribute__((always_inline))
#define NOINLINE __attribute__((noinline))
#else
#define FORCEINLINE inline
#define NOINLINE
#endif
#define PBF_INLINE FORCEINLINE

class message {
Expand Down
4 changes: 4 additions & 0 deletions core/include/tangram/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ static constexpr const char * past_last_slash(const char * const str) {
return past_last_slash(str, str);
}

#ifdef TANGRAM_WINDOWS
#define __FILENAME__ __FILE__
#else
#define __FILENAME__ ({constexpr const char * const sf__ {past_last_slash(__FILE__)}; sf__;})
#endif

#define TANGRAM_MAX_BUFFER_LOG_SIZE 99999

Expand Down
1 change: 1 addition & 0 deletions core/include/tangram/tile/tileID.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cassert>
#include <cstdint>
#include <string>
#include <algorithm>

/* An immutable identifier for a map tile
*
Expand Down
10 changes: 9 additions & 1 deletion core/include/tangram/util/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ using Value = variant<none_type, double, std::string>;

class Value : public detail::Value {
using Base = detail::Value;
using Base::Base;

public:
Value(): Base() {}

template<typename T>
Value(const T& val): Base(val) {}

template<typename T>
Value(T&& val): Base(val) {}
};

const static Value NOT_A_VALUE(none_type{});
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/rasterSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ std::shared_ptr<Texture> RasterSource::cacheTexture(const TileID& _tileId, std::
}

texture = std::shared_ptr<Texture>(_texture.release(),
[c = std::weak_ptr<Cache>(m_textures), id](auto t) {
[c = std::weak_ptr<Cache>(m_textures), id](auto* t) {
if (auto cache = c.lock()) {
cache->erase(id);
LOGD("%d - remove %s", cache->size(), id.toString().c_str());
Expand Down
2 changes: 1 addition & 1 deletion core/src/debug/textDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void TextDisplay::draw(RenderState& rs, const std::string& _text, int _posx, int
std::vector<glm::vec2> vertices;
int nquads;

nquads = stb_easy_font_print(_posx, _posy, _text.c_str(), NULL, m_vertexBuffer, VERTEX_BUFFER_SIZE);
nquads = stb_easy_font_print(_posx, _posy, const_cast<char*>(_text.c_str()), NULL, m_vertexBuffer, VERTEX_BUFFER_SIZE);

float* data = reinterpret_cast<float*>(m_vertexBuffer);

Expand Down
2 changes: 1 addition & 1 deletion core/src/gl/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void FrameBuffer::init(RenderState& _rs) {
}

GLenum status = GL::checkFramebufferStatus(GL_FRAMEBUFFER);
GL_CHECK();
GL_CHECK("");

if (status != GL_FRAMEBUFFER_COMPLETE) {
LOGE("Framebuffer status is incomplete:");
Expand Down
4 changes: 4 additions & 0 deletions core/src/scene/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ void Importer::addSceneYaml(const Url& sceneUrl, const char* sceneYaml, size_t l
auto& sceneNode = m_sceneNodes[sceneUrl];

try {
#ifdef TANGRAM_WINDOWS
sceneNode.yaml = YAML::Load(sceneYaml);
#else
sceneNode.yaml = YAML::Load(sceneYaml, length);
#endif
} catch (const YAML::ParserException& e) {
LOGE("Parsing scene config '%s'", e.what());
return;
Expand Down
30 changes: 15 additions & 15 deletions core/src/scene/sceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void SceneLoader::applyScene(const Node& _node, Color& backgroundColor,
Stops& backgroundStops, Scene::animate& animated) {
if (!_node) { return; }
if (!_node.IsMap()) {
LOGNode("Invalid 'scene' section", _node);
LOGNode("Invalid 'scene' section", _node, "");
return;
}

Expand Down Expand Up @@ -302,7 +302,7 @@ Scene::Lights SceneLoader::applyLights(const Node& _node) {
}
}
} else if (_node) {
LOGNode("Invalid 'lights'", _node);
LOGNode("Invalid 'lights'", _node, "");
}

if (lights.empty()) {
Expand Down Expand Up @@ -436,14 +436,14 @@ void SceneLoader::parseLightPosition(const Node& _positionNode, PointLight& _lig
}
_light.setPosition(positionResult);
} else {
LOGNode("Invalid light position parameter:", _positionNode);
LOGNode("Invalid light position parameter:", _positionNode, "");
}
}

void SceneLoader::applyTextures(const Node& _node, SceneTextures& _textures) {
if (!_node) { return; }
if (!_node.IsMap()) {
LOGNode("Invalid 'textures' section", _node);
LOGNode("Invalid 'textures' section", _node, "");
return;
}

Expand Down Expand Up @@ -543,7 +543,7 @@ bool SceneLoader::parseTexFiltering(const Node& _filteringNode, TextureOptions&
void SceneLoader::applyFonts(const Node& _node, SceneFonts& _fonts) {
if (!_node) { return; }
if (!_node.IsMap()) {
LOGNode("Invalid 'fonts' section", _node);
LOGNode("Invalid 'fonts' section", _node, "");
return;
}

Expand All @@ -570,7 +570,7 @@ void SceneLoader::applyFonts(const Node& _node, SceneFonts& _fonts) {
void SceneLoader::loadFontDescription(const Node& _node, const std::string& _family, SceneFonts& _fonts) {
if (!_node) { return; }
if (!_node.IsMap()) {
LOGNode("Invalid 'font' section", _node);
LOGNode("Invalid 'font' section", _node, "");
return;
}

Expand Down Expand Up @@ -634,18 +634,18 @@ Scene::TileSources SceneLoader::applySources(const Node& _config, const SceneOpt

if (const Node& rasters = source.second["rasters"]) {
if (!rasters.IsSequence()) {
LOGNode("Invalid 'rasters'", rasters);
LOGNode("Invalid 'rasters'", rasters, "");
continue;
}
for (const auto& raster : rasters) {
if (!raster.IsScalar()) {
LOGNode("Invalid 'raster'", raster);
LOGNode("Invalid 'raster'", raster, "");
continue;
}
if (auto rasterSource = getTileSource(raster.Scalar())) {
tileSource->addRasterSource(rasterSource);
} else {
LOGNode("Missing raster source", raster);
LOGNode("Missing raster source", raster, "");
}
}
}
Expand Down Expand Up @@ -676,7 +676,7 @@ Scene::TileSources SceneLoader::applySources(const Node& _config, const SceneOpt
if (!data_source) { continue;}

if (!data_source.IsScalar()) {
LOGNode("Invalid 'source", data);
LOGNode("Invalid 'source", data, "");
continue;
}
auto source = data_source.Scalar();
Expand Down Expand Up @@ -875,7 +875,7 @@ Scene::Styles SceneLoader::applyStyles(const Node& _node, SceneTextures& _textur

if (!_node) { return styles; }
if (!_node.IsMap()) {
LOGNode("Invalid 'styles' section", _node);
LOGNode("Invalid 'styles' section", _node, "");
return styles;
}

Expand Down Expand Up @@ -1256,7 +1256,7 @@ void SceneLoader::loadShaderConfig(const Node& _shaders, Style& _style, SceneTex

_style.styleUniforms().emplace_back(name, styleUniform.value);
} else {
LOGNode("Style uniform parsing failure", uniform.second);
LOGNode("Style uniform parsing failure", uniform.second, "");
}
}
}
Expand Down Expand Up @@ -1387,7 +1387,7 @@ void SceneLoader::loadMaterial(const Node& _matNode, Material& _material, Style&
// Handled as texture
break;
default:
LOGNode("Invalid 'material'", prop);
LOGNode("Invalid 'material'", prop, "");
break;
}
return glm::vec4(0.0);
Expand Down Expand Up @@ -1441,7 +1441,7 @@ MaterialTexture SceneLoader::loadMaterialTexture(const Node& _matCompNode, Style

Node textureNode = _matCompNode["texture"];
if (!textureNode) {
LOGNode("Expected a 'texture' parameter", _matCompNode);
LOGNode("Expected a 'texture' parameter", _matCompNode, "");

return MaterialTexture{};
}
Expand Down Expand Up @@ -1501,7 +1501,7 @@ std::vector<DataLayer> SceneLoader::applyLayers(const Node& _node, SceneFunctio
SceneStops& _stops, DrawRuleNames& _ruleNames) {
if (!_node) { return {}; }
if (!_node.IsMap()) {
LOGNode("Invalid 'layers' section", _node);
LOGNode("Invalid 'layers' section", _node, "");
return {};
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/text/textUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int TextWrapper::draw(alfons::TextBatch& _batch, float _maxWidth, const alfons::
TextLabelProperty::Align _alignment, float _lineSpacing,
alfons::LineMetrics& _layoutMetrics) {
size_t shapeStart = 0;
glm::vec2 position;
glm::vec2 position{};

for (auto wrap : m_lineWraps) {
alfons::LineMetrics lineMetrics;
Expand Down
4 changes: 2 additions & 2 deletions core/src/util/floatFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ struct ff {

static double stod(const std::string& _string) {
int end = 0;
return stod(_string.data(), _string.size(), &end);
return stod(_string.data(), static_cast<int>(_string.size()), &end);
}

static float stof(const char* _string, int _length, int* _end);

static float stof(const std::string& _string) {
int end = 0;
return stof(_string.data(), _string.size(), &end);
return stof(_string.data(), static_cast<int>(_string.size()), &end);
}

};
Expand Down
6 changes: 3 additions & 3 deletions core/src/util/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ float signedArea(InputIt begin, InputIt end) {
float area = 0;
auto prev = end - 1;
for (auto curr = begin; curr != end; ++curr) {
area += curr->x * prev->y - curr->y * prev->x;
area += static_cast<float>(curr->x * prev->y - curr->y * prev->x);
prev = curr;
}
return 0.5f * area;
Expand All @@ -82,14 +82,14 @@ float signedArea(InputIt begin, InputIt end) {
/// If the polygon has no area, the coordinates returned are NaN.
template<class InputIt, class Vector = typename InputIt::value_type>
Vector centroid(InputIt begin, InputIt end) {
Vector centroid;
Vector centroid{};
float area = 0.f;
const Vector offset(begin->x, begin->y);

for (auto curr = begin, prev = end - 1; curr != end; prev = curr, ++curr) {
const Vector prevPoint(prev->x - offset.x, prev->y - offset.y);
const Vector currPoint(curr->x - offset.x, curr->y - offset.y);
float a = (prevPoint.x * currPoint.y - currPoint.x * prevPoint.y);
float a = static_cast<float>(prevPoint.x * currPoint.y - currPoint.x * prevPoint.y);
centroid.x += (prevPoint.x + currPoint.x) * a;
centroid.y += (prevPoint.y + currPoint.y) * a;
area += a;
Expand Down
1 change: 1 addition & 0 deletions core/src/util/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdlib>
#include <cassert>
#include <algorithm>

namespace Tangram {

Expand Down
Loading

0 comments on commit 3a8ff01

Please sign in to comment.