Skip to content

Commit 9da5ed2

Browse files
committed
Refactoring some codes.
- Add NOEXCEPT specifier. - Reduce boost dependency. - Fix incorrect logging.
1 parent 47ed468 commit 9da5ed2

File tree

8 files changed

+51
-37
lines changed

8 files changed

+51
-37
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ target_link_libraries(${PROJECT_NAME}
7676
PUBLIC Boost::boost panda3d::panda3d
7777

7878
PRIVATE $<$<NOT:$<BOOL:${Boost_USE_STATIC_LIBS}>>:Boost::dynamic_linking>
79-
Boost::filesystem Boost::system
79+
Boost::filesystem
8080
${FREETYPE_LIBRARIES} yaml-cpp spdlog::spdlog
8181
)
8282

@@ -97,7 +97,7 @@ include(CMakePackageConfigHelpers)
9797
write_basic_package_version_file(${PACKAGE_VERSION_CONFIG_FILE}
9898
VERSION ${PROJECT_VERSION}
9999
COMPATIBILITY SameMajorVersion)
100-
configure_package_config_file("${PROJECT_SOURCE_DIR}/CMake/${PROJECT_NAME}-config.cmake.in"
100+
configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
101101
${PACKAGE_CONFIG_FILE}
102102
INSTALL_DESTINATION ${PACKAGE_CMAKE_INSTALL_DIR})
103103
export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_BINARY_DIR}/${TARGET_EXPORT_NAME}.cmake)

render_pipeline/rpcore/render_target.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ class RPCPP_DECL RenderTarget: public RPObject
4747
* You can also pass a string containing a percentage, e.g. '25%', '50%'
4848
* or '100%' (the default).
4949
*/
50-
void set_size(const std::string& width, const std::string& height);
51-
void set_size(const std::string& size);
50+
void set_size(const std::string& width, const std::string& height) NOEXCEPT;
51+
void set_size(const std::string& size) NOEXCEPT;
5252

5353
/**
5454
* Set size_constraint.
5555
* If width or height has negative value,
5656
* it will be re-calculated to be proportional to resolution.
5757
*/
58-
void set_size(const LVecBase2i& size);
58+
void set_size(const LVecBase2i& size) NOEXCEPT;
5959
/** @overload set_size(const LVecBase2i&) */
60-
void set_size(int size);
60+
void set_size(int size) NOEXCEPT;
6161
/** @overload set_size(const LVecBase2i&) */
62-
void set_size(int width, int height);
62+
void set_size(int width, int height) NOEXCEPT;
6363

6464
/** Get current active. */
6565
bool get_active(void) const;
@@ -108,8 +108,8 @@ class RPCPP_DECL RenderTarget: public RPObject
108108

109109
void consider_resize(void);
110110

111-
const boost::optional<int>& get_sort(void) const;
112-
void set_sort(int sort);
111+
const boost::optional<int>& get_sort(void) const NOEXCEPT;
112+
void set_sort(int sort) NOEXCEPT;
113113

114114
bool get_support_transparency(void) const;
115115
bool get_create_default_region(void) const;

src/rpcore/effect.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include <virtualFileSystem.h>
88
#include <graphicsWindow.h>
99

10-
#include <boost/filesystem.hpp>
1110
#include <boost/algorithm/string.hpp>
12-
#include <boost/functional/hash.hpp>
1311

1412
#include "render_pipeline/rpcore/render_pipeline.h"
1513
#include "render_pipeline/rpcore/globals.h"
@@ -121,7 +119,7 @@ std::string Effect::Impl::generate_hash(const std::string& filename, const Optio
121119
// will cause a cache miss)
122120
Filename fname = Filename(filename);
123121
fname.make_absolute();
124-
const std::string& file_hash = std::to_string(boost::filesystem::hash_value(fname.to_os_specific()));
122+
const std::string& file_hash = std::to_string(fname.get_hash());
125123

126124
// Hash the options, that is, sort the keys to make sure the values
127125
// are always in the same order, and then convert the flags to strings using
@@ -164,7 +162,7 @@ void Effect::Impl::parse_content(YAML::Node& parsed_yaml)
164162
void Effect::Impl::parse_shader_template(const PassType& pass_id_multiview, const std::string& stage, YAML::Node& data)
165163
{
166164
const std::string& pass_id = pass_id_multiview.first;
167-
bool stereo_mode = RenderPipeline::get_global_ptr()->get_setting<bool>("pipeline.stereo_mode") && pass_id_multiview.second;
165+
bool stereo_mode = RenderPipeline::get_global_ptr()->get_setting<bool>("pipeline.stereo_mode", false) && pass_id_multiview.second;
168166

169167
std::string template_src;
170168
if (stage == "fragment")

src/rpcore/pluginbase/manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <virtualFileSystem.h>
66
#include <virtualFileMountSystem.h>
77

8-
#include <boost/filesystem.hpp>
98
#include <boost/detail/winapi/dll.hpp>
109
#include <boost/dll/import.hpp>
1110

src/rpcore/render_target.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <auxBitplaneAttrib.h>
88
#include <transparencyAttrib.h>
99

10+
#include <spdlog/fmt/fmt.h>
11+
1012
#include "render_pipeline/rpcore/globals.h"
1113
#include "render_pipeline/rppanda/showbase/showbase.h"
1214

@@ -26,7 +28,7 @@ struct RenderTarget::Impl
2628
{
2729
Impl(RenderTarget& self);
2830

29-
int percent_to_number(const std::string& v);
31+
int percent_to_number(const std::string& v) const NOEXCEPT;
3032

3133
void create_buffer(void);
3234
void compute_size_from_constraint(void);
@@ -81,9 +83,17 @@ RenderTarget::Impl::Impl(RenderTarget& self): self(self)
8183
});
8284
}
8385

84-
int RenderTarget::Impl::percent_to_number(const std::string& v)
86+
int RenderTarget::Impl::percent_to_number(const std::string& v) const NOEXCEPT
8587
{
86-
return percent_to_number_map.at(v);
88+
try
89+
{
90+
return percent_to_number_map.at(v);
91+
}
92+
catch (...)
93+
{
94+
self.error(fmt::format("Invalid percent: {}", v));
95+
return -1;
96+
}
8797
}
8898

8999
void RenderTarget::Impl::create_buffer(void)
@@ -325,17 +335,17 @@ void RenderTarget::set_layers(int layers)
325335
impl_->layers_ = layers;
326336
}
327337

328-
void RenderTarget::set_size(int width, int height)
338+
void RenderTarget::set_size(int width, int height) NOEXCEPT
329339
{
330340
impl_->size_constraint_ = LVecBase2i(width, height);
331341
}
332342

333-
void RenderTarget::set_size(int size)
343+
void RenderTarget::set_size(int size) NOEXCEPT
334344
{
335345
impl_->size_constraint_ = LVecBase2i(size);
336346
}
337347

338-
void RenderTarget::set_size(const LVecBase2i& size)
348+
void RenderTarget::set_size(const LVecBase2i& size) NOEXCEPT
339349
{
340350
impl_->size_constraint_ = size;
341351
}
@@ -360,22 +370,22 @@ Texture* RenderTarget::get_aux_tex(size_t index) const
360370
return impl_->targets_.at(std::string("aux_") + std::to_string(index));
361371
}
362372

363-
const boost::optional<int>& RenderTarget::get_sort(void) const
373+
const boost::optional<int>& RenderTarget::get_sort(void) const NOEXCEPT
364374
{
365375
return impl_->sort_;
366376
}
367377

368-
void RenderTarget::set_sort(int sort)
378+
void RenderTarget::set_sort(int sort) NOEXCEPT
369379
{
370380
impl_->sort_ = sort;
371381
}
372382

373-
void RenderTarget::set_size(const std::string& width, const std::string& height)
383+
void RenderTarget::set_size(const std::string& width, const std::string& height) NOEXCEPT
374384
{
375385
impl_->size_constraint_ = LVecBase2i(impl_->percent_to_number(width), impl_->percent_to_number(height));
376386
}
377387

378-
void RenderTarget::set_size(const std::string& size)
388+
void RenderTarget::set_size(const std::string& size) NOEXCEPT
379389
{
380390
set_size(size, size);
381391
}

src/rppanda/gui/direct_gui_base.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,25 @@
99
#include <nodePathCollection.h>
1010
#include <throw_event.h>
1111

12-
#include <boost/format.hpp>
12+
#include <boost/core/typeinfo.hpp>
13+
14+
#include <spdlog/fmt/fmt.h>
15+
16+
#include "rppanda/config_rppanda.h"
1317

1418
namespace rppanda {
1519

1620
const std::type_info& DirectGuiBase::_type_handle(typeid(DirectGuiBase));
1721

1822
boost::any& DirectGuiBase::create_component(const std::string& component_name, boost::any&& component)
1923
{
20-
// Check for invalid component name
21-
if (component_name.find("_") != component_name.npos)
22-
{
23-
throw std::runtime_error(std::string("Component name \"") + component_name + "\" must not contain \"_\"");
24-
}
24+
// Check for invalid component name
25+
if (component_name.find("_") != component_name.npos)
26+
{
27+
const std::string& msg = fmt::format("Component name \"{}\" must not contain \"_\"", component_name);
28+
rppanda_cat.error() << msg << std::endl;
29+
throw std::runtime_error(msg);
30+
}
2531

2632
// Get construction keywords
2733

@@ -413,7 +419,8 @@ void DirectGuiWidget::set_border_uv_width(const LVecBase2& border_uv_width)
413419
void DirectGuiWidget::print_config(int indent)
414420
{
415421
std::string space(' ', indent);
416-
std::cout << boost::format("%1%%2% - %3%") % space % get_gui_id() % "DirectGuiWidget" << std::endl;
422+
423+
std::cout << fmt::format("{}{} - DirectGuiWidget", space, get_gui_id()) << std::endl;
417424
std::cout << space << "Pos: " << get_pos() << std::endl;
418425
std::cout << space << "Scale: " << get_scale() << std::endl;
419426

src/rppanda/interval/meta_interval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MetaInterval::MetaInterval(std::initializer_list<CInterval*> ivals, const Parame
2020
else if (ivals.size() == 1)
2121
add_c_interval(*ivals.begin(), 0.0, CMetaInterval::RS_level_begin);
2222
else
23-
rppanda_cat.error("Cannot build list from MetaInterval directly.");
23+
rppanda_cat.error() << "Cannot build list from MetaInterval directly." << std::endl;
2424
}
2525

2626
} // namespace rppanda

src/rppanda/showbase/showbase.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ void ShowBase::Impl::enable_music(bool enable)
7272
// This is useful when we want to play different music
7373
// from what the manager has queued
7474
throw_event_directly(*EventHandler::get_global_event_handler(), "MusicEnabled");
75-
rppanda_cat.debug() << "Enabling music\n";
75+
rppanda_cat.debug() << "Enabling music" << std::endl;
7676
}
7777
else
7878
{
79-
rppanda_cat.debug() << "Disabling music\n";
79+
rppanda_cat.debug() << "Disabling music" << std::endl;
8080
}
8181
}
8282

@@ -86,7 +86,7 @@ ShowBase::ShowBase(PandaFramework* framework, WindowFramework* window_framework)
8686
{
8787
if (global_showbase)
8888
{
89-
rppanda_cat.error() << "ShowBase was already created!\n";
89+
rppanda_cat.error() << "ShowBase was already created!" << std::endl;
9090
return;
9191
}
9292

@@ -519,7 +519,7 @@ void ShowBase::disable_all_audio(void)
519519
// self.SetAllSfxEnables(0)
520520
if (impl_->music_manager_is_valid_)
521521
impl_->music_manager_->set_active(false);
522-
rppanda_cat.debug() << "Disabling audio\n";
522+
rppanda_cat.debug() << "Disabling audio" << std::endl;
523523
}
524524

525525
void ShowBase::enable_all_audio(void)
@@ -528,7 +528,7 @@ void ShowBase::enable_all_audio(void)
528528
// self.SetAllSfxEnables(self.sfxActive)
529529
if (impl_->music_manager_is_valid_)
530530
impl_->music_manager_->set_active(impl_->music_active_);
531-
rppanda_cat.debug() << "Enabling audio\n";
531+
rppanda_cat.debug() << "Enabling audio" << std::endl;
532532
}
533533

534534

0 commit comments

Comments
 (0)