You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.5KB

  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="utf-8">
  4. <head>
  5. <style>
  6. #header
  7. {
  8. background: #2BA6E3;
  9. padding: 0.7em;
  10. text-align: left;
  11. }
  12. #header a
  13. {
  14. color: white;
  15. text-decoration: none;
  16. padding: 0.5em 1em 0.5em 1em;
  17. }
  18. .news_item
  19. {
  20. background: #FFFFFF;
  21. width: 720px;
  22. padding: 1em;
  23. margin-top: 2em;
  24. margin-bottom: 2em;
  25. border: 1px solid #E0E0E0;
  26. text-align: left;
  27. }
  28. .news_item_contents
  29. {
  30. color: #444;
  31. line-height: 1.5em;
  32. }
  33. .news_item_date
  34. {
  35. margin-bottom: 2em;
  36. color: #aaa;
  37. }
  38. body
  39. {
  40. background: #FAFAFA;
  41. }
  42. code, pre
  43. {
  44. font-family: monospace, serif;
  45. font-size: 1em;
  46. color: #7f0a0c;
  47. }
  48. figure
  49. {
  50. margin: 0px;
  51. padding: 0px;
  52. }
  53. img
  54. {
  55. width: 720px;
  56. }
  57. html
  58. {
  59. font-family: sans-serif;
  60. }
  61. a
  62. {
  63. color: #3A91CB;
  64. text-decoration: none;
  65. }
  66. #lang
  67. {
  68. float: right;
  69. }
  70. figcaption
  71. {
  72. color: #aaa;
  73. }
  74. table
  75. {
  76. border-collapse: collapse;
  77. }
  78. table, th, td
  79. {
  80. border: 1px solid #aaa;
  81. padding: 0.5em;
  82. margin-top: 0.5em;
  83. margin-bottom: 0.5em;
  84. }
  85. </style>
  86. </head>
  87. <body>
  88. <center>
  89. <div id="header">
  90. <a href="../../en/news/index.html">News</a>
  91. <a href="../../en/page/games.html">Games</a>
  92. <a href="../../en/page/about.html">About</a>
  93. <div id="lang">
  94. <a href="ios-tutorial.html">EN</a>
  95. <a href="../../ru/news/ios-tutorial.html">RU</a>
  96. </div>
  97. </div>
  98. <h1>In the news</h1>
  99. <div class="news_item">
  100. <h2 class="news_item_title">
  101. <a href="ios-tutorial.html">iOS tutorial</a>
  102. </h2>
  103. <p class="news_item_date">
  104. 2017-06-08 10:00
  105. </p>
  106. <div class="news_item_contents">
  107. <figure>
  108. <img src="../../images/2017-06-08-ios-refactoring.png" alt="Earth and a rocket" /><figcaption>Earth and a rocket</figcaption>
  109. </figure>
  110. <p>This article describes problems we faced during the creation of iOS tutorial in May 2017.</p>
  111. <p><a href="https://twitter.com/OpenGameStudio/status/826816343433498627">This February</a> we managed to get simple model rendered under iOS in just a few days. We expected to finish iOS tutorial in no time. However, the reality reminded us: it’s easy to come up with a hackish demo that works for one person, but it’s hard to create a concise example that works for everyone.</p>
  112. <p><strong>Native library</strong></p>
  113. <p>The first question we had to answer was: should the sample application be part of Xcode project or be a separately built library?</p>
  114. <p>We had to consider the following facts:</p>
  115. <ol type="1">
  116. <li>Xcode project can use C++ directly (thanks to Objective-C++) without stuff like JNI
  117. <ul>
  118. <li>There’s no need for a separate library (+ application)</li>
  119. <li>Creating a separate library is an additional work (- library)</li>
  120. </ul></li>
  121. <li>OpenSceneGraph builds libraries
  122. <ul>
  123. <li>It’s easier to use standard build process (+ library)</li>
  124. <li>It’s harder to create custom build process just for a single platform (- application)</li>
  125. </ul></li>
  126. <li>OpenSceneGraph uses CMake build system, which is not supported by Xcode
  127. <ul>
  128. <li>Xcode project can’t include CMake files (- application)</li>
  129. <li>It’s easy to create custom CMake file that includes OpenSceneGraph CMake file to build a single library (+ library)</li>
  130. </ul></li>
  131. <li>CMake can generate Xcode project
  132. <ul>
  133. <li>It’s possible to create a CMake file that builds both OpenSceneGraph and the sample application (+ application)</li>
  134. <li>Xcode is the de-facto tool to create Xcode projects; it’s easier to use standard build process (+ library)</li>
  135. </ul></li>
  136. </ol>
  137. <p>After evaluating the pros and cons of each approach, we decided to turn the sample application into a library and include it in Xcode project. The downside of this approach is that simulator and real device builds need separate library builds.</p>
  138. <p><strong>Refactoring</strong></p>
  139. <p>The second question we had to answer was: should there be a single source code base for all platforms or several ones, one for each platform?</p>
  140. <p>While doing Android tutorial we used single source code base because it worked fine for desktop and Android. As we started to work through iOS tutorial, it became apparent that particular features may or may not work on some platforms. For example, one feature may work on desktop and iOS, but not Android. Another feature may work on iOS and Android, but not desktop. Since we didn’t want to pollute the code with #ifdefs, we started to put each platform combination into a separate file. The number of files grew rapidly. The files were reusable, but it became extremely hard to see the whole picture.</p>
  141. <p>At this point, we realized there’s the second question. We reminded ourselves that the main purpose of the sample source code is to teach how to do basic OpenSceneGraph things, not create a reusable library with API that is stable across several years.</p>
  142. <p>That’s when our home grown feature tool came into play. With its help, we separated the code into several parts, which in the end produce just two files for each platform:</p>
  143. <ol type="1">
  144. <li>functions.h - contains reusable classless functions</li>
  145. <li>main.h - contains the rest of the sample application code</li>
  146. </ol>
  147. <p>Their contents differ slightly for each platform, but it’s easy to see the whole picture now.</p>
  148. <p>That’s it for describing problems we faced during the creation of iOS tutorial in May 2017.</p>
  149. </div>
  150. </div>
  151. </center>
  152. </body>
  153. </html>