Skip to content

Commit

Permalink
Faster compile times (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy authored Aug 22, 2020
1 parent 5c22ebe commit 515ad9d
Show file tree
Hide file tree
Showing 28 changed files with 189 additions and 134 deletions.
3 changes: 2 additions & 1 deletion apps/ysceneitrace/ysceneitrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ T1* get_element(
for (auto pos = 0; pos < ioelements.size(); pos++) {
if (ioelements[pos] == ioelement) return elements[pos];
}
throw std::runtime_error{"element not found"};
print_fatal("element not found");
return nullptr;
}

void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
Expand Down
3 changes: 3 additions & 0 deletions apps/ysceneproc/yshapedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <yocto/yocto_math.h>
using namespace yocto;

#include <vector>
using std::vector;

extern vector<vec3f> bunny_positions;
extern vector<vec3f> bunny_normals;
extern vector<vec2f> bunny_texcoords;
Expand Down
3 changes: 2 additions & 1 deletion apps/ysceneview/ysceneview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ T1* get_element(
for (auto pos = 0; pos < ioelements.size(); pos++) {
if (ioelements[pos] == ioelement) return elements[pos];
}
throw std::runtime_error{"element not found"};
print_fatal("element not found");
return nullptr;
}

// draw with shading
Expand Down
1 change: 1 addition & 0 deletions docs/yocto/yocto_commonio.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yocto/CommonIO is a collection of utilities used in writing command-line
applications, including parsing command line arguments, simple path
manipulation, file lading and saving, printing values, timers and
progress bars.
Yocto/CommonIO is implemented in `yocto_commonio.h` and `yocto_commonio.cpp`.

## Printing values

Expand Down
10 changes: 5 additions & 5 deletions libs/yocto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
add_library(yocto
yocto_common.h
yocto_common.h
yocto_math.h yocto_color.h yocto_geometry.h
yocto_noise.h yocto_sampling.h yocto_shading.h
yocto_modelio.h yocto_modelio.cpp
yocto_bvh.h yocto_bvh.cpp
yocto_shape.h yocto_shape.cpp
yocto_bvh.h yocto_bvh.cpp
yocto_shape.h yocto_shape.cpp
yocto_mesh.h yocto_mesh.cpp
yocto_image.h yocto_image.cpp
yocto_trace.h yocto_trace.cpp
yocto_sceneio.h yocto_sceneio.cpp
yocto_commonio.h
yocto_commonio.h yocto_commonio.cpp
ext/stb_image.h ext/stb_image_resize.h ext/stb_image_write.h ext/stb_image.cpp
ext/cgltf.h ext/cgltf_write.h ext/cgltf.cpp
ext/json.hpp
Expand Down Expand Up @@ -41,7 +41,7 @@ endif(YOCTO_EMBREE)

# warning flags
if(APPLE)
target_compile_options(yocto PUBLIC -Wall -Wconversion -Wno-sign-conversion -Wno-implicit-float-conversion)
target_compile_options(yocto PUBLIC -Wall -Wconversion -Wno-sign-conversion -Wno-implicit-float-conversion -ftime-trace)
endif(APPLE)
if(MSVC)
target_compile_options(yocto PUBLIC /D_CRT_SECURE_NO_WARNINGS /wd4018 /wd4244 /wd4305 /wd4800 /wd4267)
Expand Down
4 changes: 3 additions & 1 deletion libs/yocto/yocto_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cstring>
#include <deque>
#include <memory>
#include <stdexcept>
#include <string>

#include "yocto_geometry.h"
Expand All @@ -29,6 +30,7 @@ namespace yocto {
using std::atomic;
using std::deque;
using std::pair;
using std::string;
using namespace std::string_literals;

} // namespace yocto
Expand Down Expand Up @@ -320,7 +322,7 @@ static pair<int, int> split_sah(vector<int>& primitives,
if (mid == start || mid == end) {
split_axis = 0;
mid = (start + end) / 2;
throw std::runtime_error("bad bvh split");
throw std::runtime_error{"bad bvh split"};
}

return {mid, split_axis};
Expand Down
7 changes: 1 addition & 6 deletions libs/yocto/yocto_bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@
// INCLUDES
// -----------------------------------------------------------------------------

#include <array>
#include <cstdint>
#include <memory>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

#include "yocto_math.h"
Expand All @@ -58,8 +55,6 @@ namespace yocto {

// using directives
using std::array;
using std::string;
using std::unordered_map;
using std::vector;

} // namespace yocto
Expand Down
6 changes: 2 additions & 4 deletions libs/yocto/yocto_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
// INCLUDES
// -----------------------------------------------------------------------------

#include <algorithm>
#include <utility>

#include "yocto_math.h"
Expand Down Expand Up @@ -381,11 +380,11 @@ inline vec3f rgb_to_hsv(const vec3f& rgb) {
auto r = rgb.x, g = rgb.y, b = rgb.z;
auto K = 0.f;
if (g < b) {
swap(g, b);
std::swap(g, b);
K = -1;
}
if (r < g) {
swap(r, g);
std::swap(r, g);
K = -2 / 6.0f - K;
}

Expand Down Expand Up @@ -542,7 +541,6 @@ inline vec3f colormap(float t, colormap_type type) {
case colormap_type::magma: return colormap_magma(t);
case colormap_type::inferno: return colormap_inferno(t);
case colormap_type::plasma: return colormap_plasma(t);
default: throw std::runtime_error{"unknown color map type"};
}
}

Expand Down
128 changes: 128 additions & 0 deletions libs/yocto/yocto_commonio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// Implementation for Yocto/CommonIO
//

//
// LICENSE:
//
// Copyright (c) 2016 -- 2020 Fabio Pellacini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//

#include "yocto_commonio.h"

#include <algorithm>
#include <chrono>
#include <cstdio>
#include <filesystem>
#include <functional>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <vector>

// -----------------------------------------------------------------------------
// PATH UTILITIES
// -----------------------------------------------------------------------------
namespace yocto {

// Make a path from a utf8 string
static std::filesystem::path make_path(const string& filename) {
return std::filesystem::u8path(filename);
}

// Normalize path
string normalize_path(const string& filename) {
return make_path(filename).generic_u8string();
}

// Get directory name (not including /)
string path_dirname(const string& filename) {
return make_path(filename).parent_path().generic_u8string();
}

// Get extension (including .)
string path_extension(const string& filename) {
return make_path(filename).extension().u8string();
}

// Get filename without directory.
string path_filename(const string& filename) {
return make_path(filename).filename().u8string();
}

// Get filename without directory and extension.
string path_basename(const string& filename) {
return make_path(filename).stem().u8string();
}

// Joins paths
string path_join(const string& patha, const string& pathb) {
return (make_path(patha) / make_path(pathb)).generic_u8string();
}
string path_join(
const string& patha, const string& pathb, const string& pathc) {
return (make_path(patha) / make_path(pathb) / make_path(pathc))
.generic_u8string();
}

// Replaces extensions
string replace_extension(const string& filename, const string& ext) {
return make_path(filename).replace_extension(ext).u8string();
}

// Check if a file can be opened for reading.
bool path_exists(const string& filename) { return exists(make_path(filename)); }

// Check if a file is a directory
bool path_isdir(const string& filename) {
return is_directory(make_path(filename));
}

// Check if a file is a file
bool path_isfile(const string& filename) {
return is_regular_file(make_path(filename));
}

// List the contents of a directory
vector<string> list_directory(const string& filename) {
auto entries = vector<string>{};
for (auto entry : std::filesystem::directory_iterator(make_path(filename))) {
entries.push_back(entry.path().generic_u8string());
}
return entries;
}

// Create a directory and all missing parent directories if needed
bool make_directory(const string& dirname, string& error) {
if (path_exists(dirname)) return true;
try {
create_directories(make_path(dirname));
return true;
} catch (...) {
error = dirname + ": cannot create directory";
return false;
}
}

} // namespace yocto
Loading

0 comments on commit 515ad9d

Please sign in to comment.