{"id":3789,"date":"2022-11-26T14:00:46","date_gmt":"2022-11-26T14:00:46","guid":{"rendered":"https:\/\/castle-engine.io\/wp\/?p=3789"},"modified":"2022-11-28T03:50:47","modified_gmt":"2022-11-28T03:50:47","slug":"documentation-enhancements-using-children-components-api-and-code-conventions-about-memory-management-nils-beforedestruction-and-more","status":"publish","type":"post","link":"https:\/\/castle-engine.io\/wp\/2022\/11\/26\/documentation-enhancements-using-children-components-api-and-code-conventions-about-memory-management-nils-beforedestruction-and-more\/","title":{"rendered":"Documentation enhancements: using children components, API and code conventions about memory management, nils, BeforeDestruction and more"},"content":{"rendered":"<table class=\"thumbnails thumbnails-align-right\"><tr><td>\n          <a href=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2022\/11\/Zrzut-ekranu-z-2022-11-26-02-52-46.png\"\n             class=\"screenshot\"\n             title=\"Raspberry Pi Pico by abdoubouam from https:\/\/sketchfab.com\/3d-models\/raspberry-pi-pico-79aba8c863a14b4682e34e241f2159d2\"><img loading=\"lazy\" decoding=\"async\"\n            style=\"float: right\"\n            src=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2022\/11\/Zrzut-ekranu-z-2022-11-26-02-52-46-200x113.png\"\n             width=\"200\" height=\"113\" \n            alt=\"Raspberry Pi Pico by abdoubouam from https:\/\/sketchfab.com\/3d-models\/raspberry-pi-pico-79aba8c863a14b4682e34e241f2159d2\"\n          ><\/a><\/td><\/tr><\/table>\n<p>We have a number of enhancements to our 2 large documentation pages (targeting mostly advanced engine users \/ developers):<\/p>\n<ol>\n<li>\n    <a href=\"https:\/\/castle-engine.io\/custom_components\">Custom Components<\/a> documentation was extended with description how do we advise to create children components in your custom components. This is useful when you want to create a new component, register it in <a href=\"https:\/\/castle-engine.io\/manual_editor.php\">CGE editor<\/a>, and you want to use existing components as children.<\/p>\n<ol>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/custom_components#_internal_children_components_using_settransient\">You can have internal children (using <code>SetTransient<\/code>).<\/a><\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/custom_components#_children_components_that_user_can_freely_edit_and_remove_using_tregisteredcomponent_oncreate\">You can create regular components in <code>OnCreate<\/code> method that the user can later completely change and even remove (free).<\/a><\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/custom_components#_children_components_on_which_user_can_edit_properties_using_setsubcomponent\">You can have subcomponents (where user can configure properties, but shouldn&#8217;t free \/ assign a different instance).<\/a>\n    <\/ol>\n<p>All cases are documented with example code.<\/p>\n<li>\n<p>We have a big <a href=\"https:\/\/castle-engine.io\/coding_conventions\">Coding Conventions<\/a> page that documents a lot of low-level and high-level guidelines about how the engine is developed. It starts with some mundane stuff (like indentation &#8212; 2 spaces, never tabs!) but later discussed more interesting topics that I recommend to read:<\/p>\n<ol>\n<li>\n<p>Our guidelines for <a href=\"https:\/\/castle-engine.io\/coding_conventions#_use_beforedestruction_for_finalization_tasks_that_keep_the_object_state_consistent\"><code>BeforeDestruction<\/code> usage<\/a>. Big thanks for <i>Andrzej Kilija\u0144ski<\/i> for talking it over with me &#8212;  it&#8217;s a very powerful mechanism when combined with clear guidelines when to use it.<!-- (to avoid moving code between <code>BeforeDestruction<\/code> and <code>Destroy<\/code> without a clear reason).--><\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/coding_conventions#_you_can_and_should_free_the_things_you_allocated_you_should_never_free_other_things_unless_explicitly_allowed\">You can (and should) free the things you allocated; you should never free other things, unless explicitly allowed<\/a>.<\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/coding_conventions#_what_can_be_nil\">What can be nil<\/a>.<\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/coding_conventions#_declarative_api_classes_with_independent_properties_is_simple_to_use\">Declarative API (classes with independent properties) is simple to use<\/a>.<\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/coding_conventions#_optimize_smartly_profile_optimize_where_it_matters_and_not_where_it_doesnt_think_about_smarter_algorithms_and_moving_cpu_work_to_gpu_to_get_big_benefits\">Optimize smartly: profile, optimize where it matters (and not where it doesn\u2019t), think about smarter algorithms and moving CPU work to GPU to get big benefits<\/a>.<\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/coding_conventions#_fix_warnings_let_the_compiler_help_you_write_reliable_code\">Fix warnings (let the compiler help you write reliable code)<\/a>. (Shining example: recent <a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/commit\/825bde15aafb8b397d90f8e781c4cd5a6ab59d90\">critical TCastleThirdPersonNavigation fix for seemingly-random bug<\/a>.)<\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/coding_conventions#_be_consistent_in_api_design\">Be consistent in API design<\/a>.<\/p>\n<li>\n<p><a href=\"https:\/\/castle-engine.io\/coding_conventions#_backward_compatibility_is_important_having_a_consistent_easy_to_learn_api_and_useful_features_is_even_more_important\">Backward compatibility is important; having a consistent (easy to learn) API and useful features is even more important<\/a>.\n    <\/ol>\n<\/ol>\n<p>This post&#8217;s image follows our tradition <i>if there&#8217;s no clear image to illustrate this, just search for any pretty 3D model<\/i>. It turns out that if you search for <i>&#8220;documentation&#8221;<\/i> on Sketchfab, one of the things that comes up are 3D models of <a href=\"https:\/\/www.raspberrypi.org\/\">Raspberry Pi<\/a>, which we love and support in CGE (both as a platform where you can work, and as a platform to which you can compile your games). So here&#8217;s a screenshot of CGE editor rendering a 3D model of <a href=\"https:\/\/sketchfab.com\/3d-models\/raspberry-pi-pico-79aba8c863a14b4682e34e241f2159d2\">Raspberry Pi Pico<\/a> by <a href=\"https:\/\/www.artstation.com\/abdoubouam\">abdou bouam<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have a number of enhancements to our 2 large documentation pages (targeting mostly advanced engine users \/ developers): Custom Components documentation was extended with description how do we advise to create children components in your custom components. This is useful when you want to create a new component, register it in CGE editor, and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/castle-engine.io\/wp\/2022\/11\/26\/documentation-enhancements-using-children-components-api-and-code-conventions-about-memory-management-nils-beforedestruction-and-more\/\" class=\"more-link\">Continue reading  \u27a4<span class=\"screen-reader-text\"> &#8220;Documentation enhancements: using children components, API and code conventions about memory management, nils, BeforeDestruction and more&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3800,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"publish_to_discourse":"0","publish_post_category":"9","wpdc_auto_publish_overridden":"1","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"2308","discourse_permalink":"https:\/\/forum.castle-engine.io\/t\/documentation-enhancements-using-children-components-api-and-code-conventions-about-memory-management-nils-beforedestruction-and-more\/685","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-3789","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\/11\/Zrzut-ekranu-z-2022-11-26-02-52-46.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9IgYW-Z7","jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/3789","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=3789"}],"version-history":[{"count":15,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/3789\/revisions"}],"predecessor-version":[{"id":3820,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/3789\/revisions\/3820"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media\/3800"}],"wp:attachment":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media?parent=3789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/categories?post=3789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/tags?post=3789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}