Skip to content

Commit

Permalink
Log macro consistancy
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Sep 5, 2024
1 parent e9483c5 commit 824a526
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 64 deletions.
36 changes: 18 additions & 18 deletions addons/gdcef/gdcef/src/browser_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void GDBrowserView::keyPress(int key, bool pressed, bool shift, bool alt, bool c

if ((key >= 32) && (key <= 126)) // ASCII
{
BROWSER_DEBUG_VAL("ASCII CODE");
// BROWSER_DEBUG_VAL("ASCII CODE");
event.windows_key_code = key;
event.character = key16b;
event.unmodified_character = key16b;
Expand All @@ -259,7 +259,7 @@ void GDBrowserView::keyPress(int key, bool pressed, bool shift, bool alt, bool c
else if (key == godot::KEY_SPACE ||
key == godot::KEY_TAB)
{
BROWSER_DEBUG_VAL("KEY_SPACE / KEY_TAB");
// BROWSER_DEBUG_VAL("KEY_SPACE / KEY_TAB");
event.windows_key_code = key;
event.character = key16b;
event.native_key_code = key;
Expand All @@ -273,19 +273,19 @@ void GDBrowserView::keyPress(int key, bool pressed, bool shift, bool alt, bool c
key == godot::KEY_KP_ENTER )
{
if (key == godot::KEY_BACKSPACE) {
BROWSER_DEBUG_VAL("KEY_BACKSPACE");
// BROWSER_DEBUG_VAL("KEY_BACKSPACE");
event.windows_key_code = 8;
event.character = 8;
event.unmodified_character = 8;
}
else if (key == godot::KEY_ENTER) {
BROWSER_DEBUG_VAL("KEY_ENTER");
// BROWSER_DEBUG_VAL("KEY_ENTER");
event.windows_key_code = 13;
event.character = 13;
event.unmodified_character = 13;
}
else if (key == godot::KEY_KP_ENTER) {
BROWSER_DEBUG_VAL("KEY_KP_ENTER");
// BROWSER_DEBUG_VAL("KEY_KP_ENTER");
event.windows_key_code = 13;
event.character = 13;
event.unmodified_character = 13;
Expand All @@ -300,7 +300,7 @@ void GDBrowserView::keyPress(int key, bool pressed, bool shift, bool alt, bool c
}
else if (key >= 320 && key <= 329) // NUMBERS & NUMPAD
{
BROWSER_DEBUG_VAL("NUMBERS and NUMPAD");
// BROWSER_DEBUG_VAL("NUMBERS and NUMPAD");
event.windows_key_code = key;
event.character = key16b;
event.native_key_code = key;
Expand All @@ -324,43 +324,43 @@ void GDBrowserView::keyPress(int key, bool pressed, bool shift, bool alt, bool c
// https://keycode.info/

if (key == godot::KEY_RIGHT) {
BROWSER_DEBUG_VAL("KEY_RIGHT");
// BROWSER_DEBUG_VAL("KEY_RIGHT");
event.windows_key_code = 39;
}
else if (key == godot::KEY_LEFT) {
BROWSER_DEBUG_VAL("KEY_LEFT");
// BROWSER_DEBUG_VAL("KEY_LEFT");
event.windows_key_code = 37;
}
else if (key == godot::KEY_UP) {
BROWSER_DEBUG_VAL("KEY_UP");
// BROWSER_DEBUG_VAL("KEY_UP");
event.windows_key_code = 38;
}
else if (key == godot::KEY_DOWN) {
BROWSER_DEBUG_VAL("KEY_DOWN");
// BROWSER_DEBUG_VAL("KEY_DOWN");
event.windows_key_code = 40;
}
else if (key == godot::KEY_PAGEUP) {
BROWSER_DEBUG_VAL("KEY_PAGEUP");
// BROWSER_DEBUG_VAL("KEY_PAGEUP");
event.windows_key_code = 33;
}
else if (key == godot::KEY_PAGEDOWN) {
BROWSER_DEBUG_VAL("KEY_PAGEDOWN");
// BROWSER_DEBUG_VAL("KEY_PAGEDOWN");
event.windows_key_code = 34;
}
else if (key == godot::KEY_HOME) {
BROWSER_DEBUG_VAL("KEY_HOME");
// BROWSER_DEBUG_VAL("KEY_HOME");
event.windows_key_code = 36; // Debut
}
else if (key == godot::KEY_END) {
BROWSER_DEBUG_VAL("KEY_END");
// BROWSER_DEBUG_VAL("KEY_END");
event.windows_key_code = 35; // Fin
}
else if (key == godot::KEY_INSERT) {
BROWSER_DEBUG_VAL("KEY_INSERT");
// BROWSER_DEBUG_VAL("KEY_INSERT");
event.windows_key_code = 45; // Insert
}
else if (key == godot::KEY_DELETE) {
BROWSER_DEBUG_VAL("KEY_DELETE");
// BROWSER_DEBUG_VAL("KEY_DELETE");
event.windows_key_code = 46; // Del (not dot when no char event)
}

Expand All @@ -371,7 +371,7 @@ void GDBrowserView::keyPress(int key, bool pressed, bool shift, bool alt, bool c
}
else
{
BROWSER_DEBUG_VAL("Any Char");
// BROWSER_DEBUG_VAL("Any Char");
event.windows_key_code = key;
event.character = key16b;
event.native_key_code = key;
Expand All @@ -385,7 +385,7 @@ void GDBrowserView::keyPress(int key, bool pressed, bool shift, bool alt, bool c
}
else
{
BROWSER_DEBUG_VAL("PRESSED FALSE");
// BROWSER_DEBUG_VAL("PRESSED FALSE");
event.native_key_code |= int(0xC0000000);
event.type = KEYEVENT_KEYUP;
m_browser->GetHost()->SendKeyEvent(event);
Expand Down
6 changes: 3 additions & 3 deletions addons/gdcef/gdcef/src/gdbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ int GDBrowserView::init(godot::String const& url, CefBrowserSettings const& sett
#pragma omp single
GDCEF_DEBUG_VAL("OpenMP number of threads = " << omp_get_num_threads());
}
#else
GDCEF_DEBUG_VAL("OpenMP is not enabled");
#endif

// Create a new browser using the window parameters specified by
Expand Down Expand Up @@ -557,8 +559,6 @@ void GDBrowserView::navigateForward()
//------------------------------------------------------------------------------
void GDBrowserView::resize_(int width, int height)
{
std::cout << "SIZE: " << width << ", " << height << std::endl;

if (width <= 0) { width = 2; }
if (height <= 0) { height = 2; }
BROWSER_DEBUG_VAL(width << " x " << height);
Expand All @@ -575,7 +575,7 @@ void GDBrowserView::resize_(int width, int height)
//------------------------------------------------------------------------------
bool GDBrowserView::viewport(float x, float y, float w, float h)
{
BROWSER_DEBUG_VAL(x << ", " << y << ", " << w << ", " << h);
// BROWSER_DEBUG_VAL(x << ", " << y << ", " << w << ", " << h);

if (!(x >= 0.0f) && (x < 1.0f))
return false;
Expand Down
32 changes: 19 additions & 13 deletions addons/gdcef/gdcef/src/gdcef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ static bool sanity_checks(fs::path const& folder)
//void GDCef::_register_methods()
void GDCef::_bind_methods()
{
using namespace godot;
std::cout << "[GDCEF][GDCef::_register_methods]" << std::endl;
GDCEF_DEBUG_VAL("");

using namespace godot;
ClassDB::bind_method(D_METHOD("initialize"), &GDCef::initialize);
ClassDB::bind_method(D_METHOD("get_full_version"), &GDCef::version);
ClassDB::bind_method(D_METHOD("get_version_part"), &GDCef::versionPart);
Expand Down Expand Up @@ -233,8 +233,7 @@ static void configureCEF(fs::path const& folder, CefSettings& cef_settings,
// "browser-subprocess-path" command-line switch.
fs::path sub_process_path =
getConfig(config, "browser_subprocess_path", folder / SUBPROCESS_NAME);
std::cout << "[GDCEF][GDCef::configureCEF] Setting SubProcess path: "
<< sub_process_path.string() << std::endl;
GDCEF_DEBUG_VAL("Setting SubProcess path: " << sub_process_path.string());
CefString(&cef_settings.browser_subprocess_path)
.FromString(sub_process_path.string());

Expand All @@ -246,8 +245,7 @@ static void configureCEF(fs::path const& folder, CefSettings& cef_settings,
// result in the sandbox blocking read/write access to the cache_path
// directory.
fs::path root_cache = getConfig(config, "root_cache_path", folder / "cache");
std::cout << "[GDCEF][GDCef::configureCEF] Setting root cache path: "
<< root_cache.string() << std::endl;
GDCEF_DEBUG_VAL("Setting root cache path: " << root_cache.string());
CefString(&cef_settings.root_cache_path).FromString(root_cache.string());

// Incognito mode: cache directories not used.
Expand All @@ -265,16 +263,14 @@ static void configureCEF(fs::path const& folder, CefSettings& cef_settings,
const bool incognito = getConfig(config, "incognito", false);
if (incognito)
{
std::cout << "[GDCEF][GDCef::configureCEF] Setting cache path as incognito"
<< std::endl;
GDCEF_DEBUG_VAL("Setting cache path as incognito");
CefString(&cef_settings.cache_path).FromString("");
}
else
{
fs::path sub_process_cache =
getConfig(config, "cache_path", root_cache);
std::cout << "[GDCEF][GDCef::configureCEF] Setting cache path: "
<< sub_process_cache.string() << std::endl;
GDCEF_DEBUG_VAL("Setting cache path: " << sub_process_cache.string());
CefString(&cef_settings.cache_path)
.FromString(sub_process_cache.string());
}
Expand All @@ -286,6 +282,7 @@ static void configureCEF(fs::path const& folder, CefSettings& cef_settings,
// configurable using the "lang" command-line switch.
std::string locale = getConfig(config, "locale", std::string("en-US"));
CefString(&cef_settings.locale).FromString(locale);
GDCEF_DEBUG_VAL("Default locale: " << locale);

// The directory and file name to use for the debug log. If empty a default
// log file name and location will be used. On Windows and Linux a
Expand All @@ -311,7 +308,6 @@ static void configureCEF(fs::path const& folder, CefSettings& cef_settings,
// not enable this value if the application does not use windowless
// rendering as it may reduce rendering performance on some systems.
cef_settings.windowless_rendering_enabled = true;
//getConfig(config, "windowless_rendering_enabled", true);

// Create the browser using windowless (off-screen) rendering. No window
// will be created for the browser and all rendering will occur via the
Expand All @@ -327,13 +323,11 @@ static void configureCEF(fs::path const& folder, CefSettings& cef_settings,

// To allow calling OnPaint()
window_info.shared_texture_enabled = false;
// getConfig(config, "shared_texture_enabled", false);

// Set to true (1) to disable the sandbox for sub-processes. See
// cef_sandbox_win.h for requirements to enable the sandbox on Windows. Also
// configurable using the "no-sandbox" command-line switch.
cef_settings.no_sandbox = true;
// getConfig(config, "no_sandbox", true);

// Set to true (1) to disable configuration of browser process features
// using standard CEF and Chromium command-line arguments. Configuration can
Expand Down Expand Up @@ -379,11 +373,14 @@ static void configureBrowser(CefBrowserSettings& browser_settings,
// CefBrowserHost::SetWindowlessFrameRate.
browser_settings.windowless_frame_rate =
getConfig(config, "frame_rate", 30);
GDCEF_DEBUG_VAL("Using windowless_frame_rate: "
<< int(browser_settings.windowless_frame_rate));

// Controls whether JavaScript can be executed. Also configurable using the
// "disable-javascript" command-line switch.
browser_settings.javascript =
getConfig(config, "javascript", STATE_ENABLED);
GDCEF_DEBUG_VAL("Using javascript: " << int(browser_settings.javascript));

// Controls whether JavaScript can be used to close windows that were not
// opened via JavaScript. JavaScript can still be used to close windows that
Expand All @@ -392,18 +389,24 @@ static void configureBrowser(CefBrowserSettings& browser_settings,
// switch.
browser_settings.javascript_close_windows =
getConfig(config, "javascript_close_windows", STATE_DISABLED);
GDCEF_DEBUG_VAL("Using javascript_close_windows: "
<< int(browser_settings.javascript_close_windows));

// Controls whether JavaScript can access the clipboard. Also configurable
// using the "disable-javascript-access-clipboard" command-line switch.
browser_settings.javascript_access_clipboard =
getConfig(config, "javascript_access_clipboard", STATE_DISABLED);
GDCEF_DEBUG_VAL("Using javascript_access_clipboard: "
<< int(browser_settings.javascript_access_clipboard));

// Controls whether DOM pasting is supported in the editor via
// execCommand("paste"). The |javascript_access_clipboard| setting must also
// be enabled. Also configurable using the "disable-javascript-dom-paste"
// command-line switch.
browser_settings.javascript_dom_paste =
getConfig(config, "javascript_dom_paste", STATE_DISABLED);
GDCEF_DEBUG_VAL("Using javascript_dom_paste: "
<< int(browser_settings.javascript_dom_paste));

// Controls whether any plugins will be loaded. Also configurable using the
// "disable-plugins" command-line switch.
Expand All @@ -415,15 +418,18 @@ static void configureBrowser(CefBrowserSettings& browser_settings,
// "disable-image-loading" command-line switch.
browser_settings.image_loading =
getConfig(config, "image_loading", STATE_ENABLED);
GDCEF_DEBUG_VAL("Using image loading: " << int(browser_settings.image_loading));

// Controls whether databases can be used. Also configurable using the
// "disable-databases" command-line switch.
browser_settings.databases = getConfig(config, "databases", STATE_ENABLED);
GDCEF_DEBUG_VAL("Using databases: " << int(browser_settings.databases));

// Controls whether WebGL can be used. Note that WebGL requires hardware
// support and may not work on all systems even when enabled. Also
// configurable using the "disable-webgl" command-line switch.
browser_settings.webgl = getConfig(config, "webgl", STATE_ENABLED);
GDCEF_DEBUG_VAL("Using webgl: " << int(browser_settings.webgl));
}

//------------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions addons/gdcef/gdcef/src/helper_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//*****************************************************************************

#include "helper_files.hpp"
#include "helper_log.hpp"
#include <iostream>
#include <fstream>

Expand All @@ -45,9 +46,7 @@ bool are_valid_files(fs::path const& folder,
// TODO Compute SHA1 on files to check if they are correct
if (!fs::exists(f))
{
std::cout << "[GDCEF] [" << __func__ << "] File "
<< f << " does not exist and is needed for CEF"
<< std::endl;
STATIC_GDCEF_ERROR("File " << f << " does not exist and is needed for CEF");
failure = true;
}
}
Expand Down
13 changes: 12 additions & 1 deletion addons/gdcef/gdcef/src/helper_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,35 @@

// ****************************************************************************
// Logging
// TODO disable log in release mode or if log is required (from Godot)
// TODO Use Godot print instead of cout/cerr
// ****************************************************************************
#define GDCEF_DEBUG() \
std::cout << "[GDCEF][GDCEF::" << __func__ << "]" << std::endl

#define GDCEF_DEBUG_VAL(x) \
std::cout << "[GDCEF][GDCEF::" << __func__ << "] " << x << std::endl

#define GDCEF_ERROR(x) \
m_error << "[GDCEF][GDCEF::" << __func__ << "] " << x << std::endl

#define GDCEF_WARNING(x) \
std::cout << "[GDCEF][GDCEF::" << __func__ << "] " << x << std::endl

#define BROWSER_DEBUG() \
std::cout << "[GDCEF][BrowserView::" << __func__ << "][" << m_id << "]" \
<< std::endl

#define BROWSER_DEBUG_VAL(x) \
std::cout << "[GDCEF][BrowserView::" << __func__ << "][" << m_id << "] " \
<< x << std::endl

#define BROWSER_ERROR(x) \
m_error << "[GDCEF][BrowserView::" << __func__ << "][" << m_id << "] " \
<< x << std::endl; \
std::cerr << m_error.str()

#endif // GDCEF_HELPER_LOG_HPP
#define STATIC_GDCEF_ERROR(x) \
std::cerr << "[ERROR][GDCEF][" << __func__ << "]" << x << std::endl

#endif // GDCEF_HELPER_LOG_HPP
28 changes: 28 additions & 0 deletions addons/gdcef/subprocess/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,31 @@ int main(int argc, char* argv[])
}

#endif // _WIN32

//------------------------------------------------------------------------------
void GDCefBrowser::OnContextInitialized()
{
std::cout << "[SubProcess] [GDCefBrowser::OnContextInitialized] begin" << std::endl;
CEF_REQUIRE_UI_THREAD();

// Information used when creating the native window.
CefWindowInfo window_info;

#if defined(OS_WIN)
// On Windows we need to specify certain flags that will be passed to
// CreateWindowEx().
window_info.SetAsPopup(NULL, "CEF");
#endif

// GDCefClient implements browser-level callbacks.
std::cout << "[SubProcess] [GDCefBrowser::OnContextInitialized] Create client handler" << std::endl;
CefRefPtr<GDCefClient> handler(new GDCefClient());

// Specify CEF browser settings here.
CefBrowserSettings browser_settings;

// Create the first browser window.
std::cout << "[SubProcess] [GDCefBrowser::OnContextInitialized] Create the browser" << std::endl;
CefBrowserHost::CreateBrowser(window_info, handler.get(), "https://github.com/Lecrapouille/gdcef",
browser_settings, nullptr, nullptr);
}
Loading

0 comments on commit 824a526

Please sign in to comment.