{"id":2983,"date":"2022-02-05T16:00:28","date_gmt":"2022-02-05T16:00:28","guid":{"rendered":"https:\/\/castle-engine.io\/wp\/?p=2983"},"modified":"2022-02-04T18:30:40","modified_gmt":"2022-02-04T18:30:40","slug":"code-cleanups-units-map-more-obvious-subdirectories-in-engine-automatically-checked-dependencies-moved-various-units-to-internal","status":"publish","type":"post","link":"https:\/\/castle-engine.io\/wp\/2022\/02\/05\/code-cleanups-units-map-more-obvious-subdirectories-in-engine-automatically-checked-dependencies-moved-various-units-to-internal\/","title":{"rendered":"Code cleanups: units map, more obvious subdirectories in engine, automatically checked dependencies, moved various units to internal"},"content":{"rendered":"<table class=\"thumbnails thumbnails-align-right\"><tr><td>\n          <a href=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2022\/02\/Zrzut-ekranu-z-2022-02-04-19-24-29.png\"\n             class=\"screenshot\"\n             title=\"Dungeon map in Tiled rendered using Castle Game Engine\"><img loading=\"lazy\" decoding=\"async\"\n            style=\"float: right\"\n            src=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2022\/02\/Zrzut-ekranu-z-2022-02-04-19-24-29-200x118.png\"\n             width=\"200\" height=\"118\" \n            alt=\"Dungeon map in Tiled rendered using Castle Game Engine\"\n          ><\/a><\/td><\/tr><\/table>\n<p>Lately I&#8217;ve done a number of rearrangements in CGE units, to make the engine code cleaner (easier to understand, both for new people and seasoned devs):<\/p>\n<ol>\n<li>\n    <a href=\"https:\/\/castle-engine.io\/units_map\">Units map<\/a> documentation is now up-to-date and more straightforward. <\/p>\n<li>\n<p>Unit dependencies outlined in <a href=\"https:\/\/castle-engine.io\/units_map\">units map<\/a> are (again) automatically checked by <a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/tools\/internal\/check_units_dependencies\">check_units_dependencies internal tool<\/a> (using <code>ppudump<\/code> from FPC underneath).<\/p>\n<li>\n<p>A lot of obscure\/internal units have been renamed to <code>CastleInternalXxx<\/code> or marked as deprecated. We&#8217;re not finished with this cleanup yet, see <a href=\"https:\/\/trello.com\/c\/4w4soULz\/115-various-cge-units-should-be-deprecated-or-just-renamed-to-castleinternalxxx-without-a-deprecated-bridge-if-really-low-actual-usa\">more potential units that can become internal<\/a>. But our <a href=\"https:\/\/castle-engine.io\/apidoc-unstable\/html\/AllUnits.html\">list of units<\/a> is already much shorter, making CGE API smaller so simpler to learn.<\/p>\n<li>\n<p>Subdirectory <code>src\/3d<\/code> is now <a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/src\/transform\">src\/transform<\/a>. It contains <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleTransform.TCastleTransform.html\">TCastleTransform<\/a><\/code> and friends, and is suitable for both 2D and 3D.<\/p>\n<li>\n<p>Subdirectory <code>src\/x3d<\/code> is now <a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/src\/scene\">src\/scene<\/a>. It contains <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleScene.TCastleScene.html\">TCastleScene<\/a><\/code> and friends (like <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleViewport.TCastleViewport.html\">TCastleViewport<\/a><\/code>). I moved the 2 big units that define X3D fields and nodes to a subdirectory <code>src\/scene\/x3d<\/code>. The code loading particular <a href=\"https:\/\/castle-engine.io\/creating_data_model_formats.php\">model formats<\/a> is now in <code>src\/scene\/load<\/code>, and some formats even get their own subdirectory, like <code>src\/scene\/load\/spine<\/code>.<\/p>\n<li>\n<p>I added subdirectory <a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/src\/base_rendering\">src\/base_rendering<\/a>, that contains some base OpenGL units (and will contain in the future alternative subdirectories for OpenGL, Vulkan etc.). <\/p>\n<li>\n<p>We no longer use <code>opengl<\/code> subdirectories inside various other CGE directories. Things from <code>base\/opengl\/<\/code>, <code>images\/opengl\/<\/code> mostly move to <code>base_rendering<\/code>. Things from <code>scene\/opengl\/<\/code>, <code>ui\/opengl\/<\/code> mostly move to parent dir, i.e. just <code>scene<\/code>, <code>ui<\/code>.<\/p>\n<p>Why?<\/p>\n<p>The original idea for separating units that depend on OpenGL from things that don&#8217;t was that it would make it easier to recognize what needs to change when we add another renderer (like Vulkan). <\/p>\n<p>However, a lot of CGE units now depend on OpenGL only &#8220;very indirectly&#8221; and they have a clear API independent from OpenGL. For example, <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleControls.html\">CastleControls<\/a><\/code> unit depends on OpenGL, but actually both its interface <i>and<\/i> implementation are completely independent from OpenGL, and they will likely look the same when we have Vulkan available. They just use <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleGLImages.TDrawableImage.html\">TDrawableImage<\/a><\/code> and <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleGLUtils.html#DrawPrimitive2D-TPrimitiveMode-arrayofTVector2SmallInt-TCastleColor-TBlendingSourceFactor-TBlendingDestinationFactor-boolean-Single-Cardinal-\">DrawPrimitive2D<\/a><\/code> that make sense for any renderer.<\/p>\n<p>Similar notes go for e.g. <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleScene.html\">CastleScene<\/a><\/code> or <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleViewport.html\">CastleViewport<\/a><\/code>. They depend on OpenGL now, but if (when?) we&#8217;ll jump to Vulkan, they will continue to exist with the same API, and even they&#8217;ll retain most of their implementation. We will just introduce then an abstraction layer, to make renderer &#8220;pluggable&#8221;, so that underneath <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleScene.TCastleScene.html\">TCastleScene<\/a><\/code>, <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleViewport.TCastleViewport.html\">TCastleViewport<\/a><\/code>, <code><a href=\"https:\/\/castle-engine.io\/apidoc\/html\/CastleUIControls.TCastleUserInterface.html\">TCastleUserInterface<\/a><\/code> will refer to the <em>&#8220;current renderer&#8221;<\/em> to do their drawing. <\/p>\n<p>All this meant that keeping these units in <code>opengl\/<\/code> subdirectory was not really very helpful. In fact, most of important CGE units were in <code>opengl\/<\/code> subdirectories, which was likely more confusing than helpful. E.g. <code>ui\/<\/code> looked like a mostly empty directory (mostly just joystick units) until you looked in <code>ui\/opengl\/<\/code> that contained a lot of important classes.<\/p>\n<li>\n<p>A few usages of <code>is nested<\/code> were cleaned &mdash; as it is not supported by Delphi. We previously tried to use &#8220;is nested&#8221; on FPC and anonymous methods on Delphi, but this resulted in a code complicated with <code>ifdef<\/code>s. It&#8217;s better to stick to a common subset of FPC and Delphi for now, which means &#8212; no &#8220;is nested&#8221;, no anonymous methods. (Of course you&#8217;re free to use them in your own projects, if you only care about using one of these compilers.)<\/p>\n<\/ol>\n<p>P.S. I don&#8217;t really have any relevant screenshot to go with this post. So enjoy a screenshot with a <a href=\"https:\/\/github.com\/stefanbeller\/tiled_examples\">sample Tiled dungeon map from here<\/a>, rendered of course using our <a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/examples\/tiled\/map_viewer\">examples\/tiled\/map_viewer<\/a> \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lately I&#8217;ve done a number of rearrangements in CGE units, to make the engine code cleaner (easier to understand, both for new people and seasoned devs): Units map documentation is now up-to-date and more straightforward. Unit dependencies outlined in units map are (again) automatically checked by check_units_dependencies internal tool (using ppudump from FPC underneath). A &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/castle-engine.io\/wp\/2022\/02\/05\/code-cleanups-units-map-more-obvious-subdirectories-in-engine-automatically-checked-dependencies-moved-various-units-to-internal\/\" class=\"more-link\">Continue reading  \u27a4<span class=\"screen-reader-text\"> &#8220;Code cleanups: units map, more obvious subdirectories in engine, automatically checked dependencies, moved various units to internal&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2993,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"publish_to_discourse":"1","publish_post_category":"9","wpdc_auto_publish_overridden":"","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"1744","discourse_permalink":"https:\/\/forum.castle-engine.io\/t\/code-cleanups-units-map-more-obvious-subdirectories-in-engine-automatically-checked-dependencies-moved-various-units-to-internal\/516","wpdc_publishing_response":"","wpdc_publishing_error":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-2983","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2022\/02\/Zrzut-ekranu-z-2022-02-04-19-24-29.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9IgYW-M7","jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/2983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/comments?post=2983"}],"version-history":[{"count":15,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/2983\/revisions"}],"predecessor-version":[{"id":2999,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/2983\/revisions\/2999"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media\/2993"}],"wp:attachment":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media?parent=2983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/categories?post=2983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/tags?post=2983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}