-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Namespaces instead of underscore prefix for binds, remove cruft #51627
Conversation
8bec623
to
dbcc2ba
Compare
@@ -41,39 +41,41 @@ | |||
#include "core/os/keyboard.h" | |||
#include "core/os/os.h" | |||
|
|||
////// _ResourceLoader ////// | |||
namespace core_bind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be:
namespace core_bind { | |
namespace CoreBind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took it from the original PR, and it seems common - if we want CamelCase for namespaces in Godot, I can switch it to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespaces in C++ are generally lower case/snake case. See for instance Google's C++ style guide: https://google.github.io/styleguide/cppguide.html#Namespace_Names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have strong guidelines on this as we haven't been using namespaces much so far. Current master
branch does have some and most are PascalCase:
$ rg -g'!thirdparty' -g'!mono' "^namespace "
tests/test_aabb.h
40:namespace TestAABB {
tests/test_path_follow_2d.h
39:namespace TestPathFollow2D {
tests/test_crypto.h
38:namespace TestCrypto {
tests/test_local_vector.h
38:namespace TestLocalVector {
tests/test_dictionary.h
40:namespace TestDictionary {
tests/test_geometry_2d.h
39:namespace TestGeometry2D {
tests/test_path_3d.h
39:namespace TestPath3D {
tests/test_vector.h
38:namespace TestVector {
tests/test_shader_lang.h
36:namespace TestShaderLang {
tests/test_path_follow_3d.h
39:namespace TestPathFollow3D {
tests/test_hashing_context.h
38:namespace TestHashingContext {
tests/test_physics_3d.h
36:namespace TestPhysics3D {
tests/test_variant.h
39:namespace TestVariant {
tests/test_image.h
40:namespace TestImage {
tests/test_marshalls.h
38:namespace TestMarshalls {
tests/test_physics_3d.cpp
410:namespace TestPhysics3D {
tests/test_text_server.h
40:namespace TestTextServer {
tests/test_translation.h
40:namespace TestTranslation {
tests/test_gui.cpp
59:namespace TestGUI {
tests/test_astar.h
43:namespace TestAStar {
tests/test_pck_packer.h
40:namespace TestPCKPacker {
tests/test_node_path.h
38:namespace TestNodePath {
tests/test_utils.h
36:namespace TestUtils {
tests/test_expression.h
38:namespace TestExpression {
tests/test_math.h
36:namespace TestMath {
tests/test_oa_hash_map.h
36:namespace TestOAHashMap {
tests/test_gui.h
36:namespace TestGUI {
tests/test_geometry_3d.h
41:namespace Test3DGeometry {
tests/test_render.cpp
44:namespace TestRender {
tests/test_resource.h
41:namespace TestResource {
tests/test_xml_parser.h
41:namespace TestXMLParser {
tests/test_basis.h
40:namespace TestBasis {
tests/test_json.h
38:namespace TestJSON {
tests/test_array.h
43:namespace TestArray {
tests/test_command_queue.h
45:namespace TestCommandQueue {
tests/test_rect2.h
38:namespace TestRect2 {
tests/test_file_access.h
37:namespace TestFileAccess {
tests/test_math.cpp
51:namespace TestMath {
tests/test_string.h
45:namespace TestString {
tests/test_gradient.h
40:namespace TestGradient {
tests/test_ordered_hash_map.h
41:namespace TestOrderedHashMap {
tests/test_class_db.h
45:namespace TestClassDB {
tests/test_paged_array.h
38:namespace TestPagedArray {
tests/test_oa_hash_map.cpp
36:namespace TestOAHashMap {
tests/test_color.h
38:namespace TestColor {
tests/test_list.h
38:namespace TestList {
tests/test_object.h
59:namespace TestObject {
tests/test_random_number_generator.h
37:namespace TestRandomNumberGenerator {
tests/test_physics_2d.cpp
398:namespace TestPhysics2D {
tests/test_config_file.h
38:namespace TestConfigFile {
tests/test_curve.h
38:namespace TestCurve {
tests/test_physics_2d.h
36:namespace TestPhysics2D {
tests/test_method_bind.h
42:namespace TestMethodBind {
core/variant/type_info.h
66:namespace GodotTypeInfo {
tests/test_render.h
36:namespace TestRender {
scene/resources/surface_tool.cpp
907:namespace {
tests/test_shader_lang.cpp
44:namespace TestShaderLang {
platform/uwp/app.h
43:namespace GodotUWP
modules/regex/tests/test_regex.h
39:namespace TestRegEx {
modules/navigation/nav_utils.h
44:namespace gd {
modules/fbx/fbx_parser/FBXDocumentUtil.cpp
83:namespace FBXDocParser {
84:namespace Util {
modules/fbx/fbx_parser/FBXDocument.h
50:namespace FBXDocParser {
1234:namespace std {
modules/fbx/fbx_parser/FBXImportSettings.h
79:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXMaterial.cpp
86:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXPose.cpp
81:namespace FBXDocParser {
modules/fbx/fbx_parser/ByteSwapper.h
82:namespace FBXDocParser {
244:namespace Intern {
modules/fbx/fbx_parser/FBXAnimation.cpp
83:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXTokenizer.h
86:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXModel.cpp
82:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXUtil.cpp
82:namespace FBXDocParser {
83:namespace Util {
modules/fbx/fbx_parser/FBXBinaryTokenizer.cpp
84:namespace FBXDocParser {
140:namespace {
modules/fbx/fbx_parser/FBXNodeAttribute.cpp
82:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXDeformer.cpp
85:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXParser.h
90:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXParser.cpp
90:namespace {
107:namespace FBXDocParser {
516:namespace {
modules/fbx/fbx_parser/FBXUtil.h
82:namespace FBXDocParser {
84:namespace Util {
modules/fbx/fbx_parser/FBXTokenizer.cpp
83:namespace FBXDocParser {
101:namespace {
modules/fbx/fbx_parser/FBXCommon.h
80:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXProperties.cpp
82:namespace FBXDocParser {
94:namespace {
modules/fbx/fbx_parser/FBXProperties.h
85:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXMeshGeometry.h
89:namespace FBXDocParser {
modules/mbedtls/tests/test_crypto_mbedtls.h
38:namespace TestCryptoMbedTLS {
modules/fbx/fbx_parser/FBXMeshGeometry.cpp
85:namespace FBXDocParser {
modules/fbx/fbx_parser/FBXDocumentUtil.h
84:namespace FBXDocParser {
85:namespace Util {
modules/mbedtls/tests/test_crypto_mbedtls.cpp
36:namespace TestCryptoMbedTLS {
modules/fbx/fbx_parser/FBXDocument.cpp
90:namespace FBXDocParser {
editor/debugger/debug_adapter/debug_adapter_types.h
37:namespace DAP {
modules/gdscript/tests/test_gdscript.cpp
50:namespace GDScriptTests {
modules/gdscript/tests/gdscript_test_runner.cpp
48:namespace GDScriptTests {
servers/physics_3d/gjk_epa.cpp
86:namespace GjkEpa2 {
modules/gdscript/tests/gdscript_test_runner.h
40:namespace GDScriptTests {
modules/gdscript/tests/test_gdscript.h
37:namespace GDScriptTests {
servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h
38:namespace RendererSceneRenderImplementation {
servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h
38:namespace RendererSceneRenderImplementation {
servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h
41:namespace RendererSceneRenderImplementation {
servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h
40:namespace RendererSceneRenderImplementation {
modules/gdscript/language_server/lsp.hpp
38:namespace lsp {
349:namespace TextDocumentSyncKind {
658:namespace DiagnosticSeverity {
766:namespace MarkupKind {
829:namespace CompletionItemKind {
862:namespace InsertTextFormat {
1076:namespace SymbolKind {
1338:namespace FoldingRangeKind {
1398:namespace CompletionTriggerKind {
drivers/png/png_driver_common.cpp
38:namespace PNGDriverCommon {
drivers/png/png_driver_common.h
36:namespace PNGDriverCommon {
modules/gdnative/tests/test_variant.h
39:namespace TestGDNativeVariant {
modules/gdscript/tests/gdscript_test_runner_suite.h
37:namespace GDScriptTests {
tests/test_lru.h
39:namespace TestLRU {
tests/test_time.h
47:namespace TestTime {
PascalCase looks more natural to me in Godot's context, but again since we don't use those much, it's not set in stone.
dbcc2ba
to
6eaa125
Compare
Update: this is now halfway working, singleton classes like Simple |
Missing renaming
|
I just tested this PR. Not sure what problem you're having with those classes. They show up in the documentation view and auto-completion. They're also generated in the C# bindings, which only happens if they're exposed. |
6220cf3
to
129cc41
Compare
Fixed, thanks. Also fixed some formatting things the CI complained about. |
129cc41
to
d9ce1ec
Compare
Update: Everything actually works, but this check triggers for classes like File/Directory/Thread changed to a namespace with this PR: godot/modules/gdscript/gdscript_analyzer.cpp Lines 3289 to 3295 in ca6c5cf
Seems like these are just superfluous warnings, and they even come with a comment saying they seem harmless. Everything works with this PR, but it'd still be nice to know the cause for these log messages. |
Okay, turns out there was a lot of hacks testing for underscores, and there was a list of classes that have underscores, and if they have not, they get the underscore added back. Removed all of those hacks, and now it works beautifully without warnings, errors, or log messages :) See the below, which the second commit now removes: godot/modules/gdscript/gdscript_parser.cpp Lines 97 to 129 in ca6c5cf
|
bfbc73a
to
3da0905
Compare
Rebased and fixed conflicts, and added Neikeq as co-author, as a large part of this is based on the original PR. :) |
3da0905
to
a0fb712
Compare
Thanks to neikeq for the initial work. Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
Way less cruft. :) Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
a0fb712
to
5161c97
Compare
@akien-mga This is now fully working and should be good to go. Let me know if you want me to change the namespaces to PascalCase. The only thing to note is in the PR description about class names for |
This will be a problem because AFAIK the |
I'm not sure it would make sense to disable any of those classes anyway, they're the most core you can get (aside from VisualScriptEditor but that's the odd one out, I don't even know why it's exposed this way, it's probably unnecessary). |
That was my thinking too. However if we decide this needs to work, I'm happy to work on that. I'd appreciate if we could merge this PR first however, I'm so not looking forward to conflicts and rebasing, as this mostly touches function/class signatures and so has a lot of surface area. Fixing up the macro or adding another one should be a small additional PR, easier to review that way. But I'd need time to get into the Godot macros and to test it, and thats time for conflicts to arise. :P |
There isn't a use case for disabling most of those, except that GodotSharp should be disabled when compiling without the Mono module, and VisualScriptEditor only makes sense to include in the editor so it should be disabled on export templates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks @mhilbrunner and @neikeq!
Redoing #26990 for current master.
This is now fully working and tested :)
The first commit moves underscored classes to namespaces,
the second removes a lot of hacks/cruft checking for underscores on classes, which we now no longer need to do.
I recommend reviewing both commits sperately.
Note: This currently means that for namespaced classes, the macros will check for defines like
ClassDB_Disable_core_bind::Directory
instead ofClassDB_Disable_Directory
. (In theGDREGISTER_CLASS
macro).(Used when passing
disabled_classes
to SCons.)This only affects the small handful of classes that were previously underscored:
Getting rid of the current special casing for all those underscore classes seems prudent, as even while working on this PR I found various bugs related to it - cases where underscores were checked in some cases, in some not, or were applied inconsistently; sometimes classes were displayed with underscores in Godot UI, sometimes not. The list of
underscore_classes
this removes even exhibits a few errors:JSON
is no longer current, andGeometry
has becomeGeometry2D
andGeometry3D
.