{"id":217,"date":"2016-09-16T12:44:24","date_gmt":"2016-09-16T12:44:24","guid":{"rendered":"http:\/\/dlang.org\/blog\/?p=217"},"modified":"2021-10-08T11:10:13","modified_gmt":"2021-10-08T11:10:13","slug":"project-highlight-timur-gafarov","status":"publish","type":"post","link":"https:\/\/dlang.org\/blog\/2016\/09\/16\/project-highlight-timur-gafarov\/","title":{"rendered":"Project Highlight: Timur Gafarov"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"alignleft size-full wp-image-219\" src=\"http:\/\/dlang.org\/blog\/wp-content\/uploads\/2016\/09\/dlib-logo.png\" alt=\"dlib-logo\" width=\"128\" height=\"128\" \/>To begin with, let&#8217;s be clear that Timur Gafarov is a person and not a project. The impetus for this post was an open source <a href=\"https:\/\/en.wikipedia.org\/wiki\/First-person_shooter\">first-person shooter<\/a>, called <a href=\"https:\/\/github.com\/gecko0307\/atrium\">Atrium<\/a>, that he develops and maintains. In the course of making the game, he has created a few other\u00a0D projects, each of which could be the focus of its own post. So this time around, we&#8217;re going to do a plural Project Highlight and introduce you to <a href=\"https:\/\/github.com\/gecko0307\">the GitHub repository<\/a> of Timur Gafarov.<\/p>\n<p>When Timur first came to D six years ago, you might say it was love at first sight.<\/p>\n<blockquote><p>As an indie game developer with a strong bias toward graphics engines and rendering tech, I always try to keep track of modern compiled languages effective enough for writing real-time stuff. The most obvious choice in this field is C++, and I actually used it for several years until I found D in 2010. I immediately fell in love with the language&#8217;s clean, beautiful syntax,\u00a0its powerful template system, the numerous built-in features absent in C++, and the rich and easy to use standard library.<\/p><\/blockquote>\n<p>Interestingly, he was actually attracted by one of the things often cited as a turn-off about D back then: the lack of libraries. It was a situation in which he saw\u00a0opportunities to create things from scratch, without worrying about reinventing the wheel. At the time, <a href=\"https:\/\/code.dlang.org\/getting_started\">DUB <\/a>was not yet a thing, so the first task he set himself\u00a0was coding up a build system called <a href=\"https:\/\/github.com\/gecko0307\/cook2\">Cook<\/a>, which he still uses sometimes instead of DUB.<\/p>\n<p>After that, he was ready to start making a game. He wanted to use\u00a0<a href=\"https:\/\/www.opengl.org\/\">OpenGL<\/a>, and\u00a0found\u00a0an <a href=\"https:\/\/github.com\/DerelictOrg\/DerelictGL3\">existing binding<\/a> in\u00a0<a href=\"https:\/\/github.com\/DerelictOrg\">Derelict<\/a>\u00a0(a collection of dynamic bindings maintained by this post&#8217;s author &#8212; there also exists a collection of static bindings called <a href=\"https:\/\/github.com\/D-Programming-Deimos\">Deimos<\/a>) that allowed him to do so in D. With that off his plate, he\u00a0next sat down to write a game engine. The first few steps in that direction\u00a0resulted in a\u00a0set of utility packages that coalesced into\u00a0<a href=\"https:\/\/github.com\/gecko0307\/dlib\">dlib<\/a>.<\/p>\n<blockquote><p>At first, there were no clear plans or goals. After a previous period of using third-party engines, I had some experience with low-level graphics coding in C++ and just wanted to port my stuff to D for a start. I began with vector\/matrix algebra and image I\/O. These efforts resulted in dlib, a general purpose library.<\/p><\/blockquote>\n<p>He next turned his attention to 3D physics. Even though there were existing libraries with bindable C interfaces, like <a href=\"http:\/\/www.ode.org\/\">ODE <\/a>(with a dynamic binding that existed then in the form of <a href=\"https:\/\/github.com\/DerelictOrg\/DerelictODE\">DerelictODE<\/a>\u00a0and <a href=\"https:\/\/github.com\/D-Programming-Deimos\/ODE\">a static binding<\/a> in Deimos) and <a href=\"https:\/\/github.com\/MADEAPPS\/newton-dynamics\">Newton<\/a>\u00a0(for which\u00a0<a href=\"https:\/\/github.com\/resurtm\/DeimosGameDynamics\">Deimos-like<\/a> and<a href=\"https:\/\/github.com\/Sycam0inc\/derelictnewton\"> Derelict-like<\/a> bindings have since been created by third parties), he just couldn&#8217;t help himself. Enter <a href=\"https:\/\/github.com\/gecko0307\/dmech\">dmech<\/a>.<\/p>\n<blockquote><p>Atrium was born as part of my experiment with writing a 3D physics engine, called dmech. OK, this wasn&#8217;t strictly necessary, but the chance of being the first one to write this kind of thing in D was so attractive that I couldn&#8217;t stand it \ud83d\ude42 Of course, I didn&#8217;t dare to compete with such industry standards as <a href=\"http:\/\/bulletphysics.org\/wordpress\/\">Bullet<\/a>, but nevertheless it was an amazing experience. I&#8217;ve learned a lot.<\/p><\/blockquote>\n<div id=\"attachment_229\" style=\"width: 670px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-229\" loading=\"lazy\" class=\"wp-image-229 size-large\" src=\"http:\/\/dlang.org\/blog\/wp-content\/uploads\/2016\/09\/013-1024x542.jpg\" alt=\"A screenshot from Atrium.\" width=\"660\" height=\"349\" srcset=\"https:\/\/dlang.org\/blog\/wp-content\/uploads\/2016\/09\/013-1024x542.jpg 1024w, https:\/\/dlang.org\/blog\/wp-content\/uploads\/2016\/09\/013-300x159.jpg 300w, https:\/\/dlang.org\/blog\/wp-content\/uploads\/2016\/09\/013-768x407.jpg 768w, https:\/\/dlang.org\/blog\/wp-content\/uploads\/2016\/09\/013.jpg 1280w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><p id=\"caption-attachment-229\" class=\"wp-caption-text\">A screenshot from Atrium.<\/p><\/div>\n<p>A\u00a0physics engine and utility library weren&#8217;t all he needed. That&#8217;s where <a href=\"https:\/\/github.com\/gecko0307\/dgl\">DGL<\/a> comes in.<\/p>\n<blockquote><p>The next milestone was writing a graphics engine that I call DGL. I can&#8217;t consider this step fully completed, because I&#8217;m never happy with my abstractions and design solutions. Finally, I ended up with some kind of simplified <a href=\"https:\/\/www.marmoset.co\/toolbag\/learn\/pbr-theory\">Physically-Based Rendering<\/a> pipeline, <a href=\"http:\/\/ogldev.atspace.co.uk\/www\/tutorial42\/tutorial42.html\">Percentage Closer Filtering<\/a> shadows and multipass rendering, with which I&#8217;m sort of satisfied for now.<\/p>\n<p>There was a period when I had to use outdated hardware, so DGL uses OpenGL 1.x, relying on extensions to utilize modern GPU technologies. Yeah, in 2016 this sounds funny \ud83d\ude42 But recently I started experimenting with OpenGL 4, so the engine is likely to be rewritten. Again!<\/p><\/blockquote>\n<p>But for Timur, the graphics system isn&#8217;t the most important part of Atrium.<\/p>\n<blockquote><p>It&#8217;s the collision detection and character kinematics. I think that believable character behavior and interactions with the virtual world are crucial for any realistic game. In Atrium, these are fully physics-based, with as few hacks and workarounds as possible. Rigid body dynamics natively &#8216;talk&#8217; with player-controllable kinematics. That means, for example, that a character can be pushed with moving objects and can push other objects himself. A stack of dynamic boxes can be transported via a kinematic moving platform. A gravity gun can be used to move things. And so on. I&#8217;m deeply inspired by Valve&#8217;s masterpieces, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Half-Life_2\">Half-Life 2<\/a> and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Portal_(video_game)\">Portal<\/a>, so I want to make my own &#8216;physical&#8217; first person puzzle.<\/p><\/blockquote>\n<p>Working on this project has certainly been a labor of love.<\/p>\n<blockquote><p>It has already taken me about six years of spare-time work and it still exists only in the form of an early gameplay demo. Of course, if I&#8217;d used an existing mature engine, like <a href=\"https:\/\/unity3d.com\/\">Unity<\/a> or <a href=\"https:\/\/www.unrealengine.com\/what-is-unreal-engine-4\">UE<\/a>, things would be much simpler. Constraining myself to use D for such a complex task may look strange, but it&#8217;s fun. And that&#8217;s that.<\/p><\/blockquote>\n<p>Through those years, he has learned a good deal about the ups and downs of game development with D. Particularly that ever popular bugbear known as the GC.<\/p>\n<blockquote><p>Modern D is a very attractive choice as a language for game development. Even the garbage collector is not a problem, because you can use object pools, custom allocators, or simply <code>malloc<\/code>\u00a0and <code>free<\/code>. The key point is to know when the GC is invoked and try to avoid those cases in performance critical code. Personally, I prefer using <code>malloc<\/code>\u00a0so that I can free the memory when I want, since <code>delete<\/code>\u00a0has been deprecated and <code>destroy<\/code>\u00a0 just releases all the references to an object instance without actually deleting it. Using manual memory management imposes some restrictions on the code&#8211;for example, you can&#8217;t use closures or D&#8217;s built-in containers&#8211;but that, again, is not a big problem. A large effort is currently underway to lessen GC usage in dlib, so that you can use it to write fully unmanaged applications with ease. It has GC-free containers, file I\/O streams, image decoders, and so on.<\/p><\/blockquote>\n<p>If you are interested in game development with D, <a href=\"https:\/\/github.com\/gecko0307\">Timur&#8217;s GitHub repository<\/a> should be an early point of call. Even if you aren&#8217;t making a game or a game engine, you may well find something useful in <a href=\"https:\/\/github.com\/gecko0307\/dlib\">dlib<\/a>. With its growing list of contributors, it&#8217;s getting a good deal of care and attention.<\/p>\n<p>Thanks to Timur for taking the time to contribute to this post. We wish him luck with all of his projects!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To begin with, let&#8217;s be clear that Timur Gafarov is a person and not a project. The impetus for this post was an open source first-person shooter, called Atrium, that he develops and maintains. In the course of making the game, he has created a few other\u00a0D projects, each of which could be the focus [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,13],"tags":[],"_links":{"self":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/217"}],"collection":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":26,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":304,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions\/304"}],"wp:attachment":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}