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.

167 lines
7.6KB

  1. <!DOCTYPE html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <!-- Set the viewport width to device width for mobile -->
  5. <meta name="viewport" content="width=device-width" />
  6. <title>iOS tutorial</title>
  7. <link rel="stylesheet" href="http://opengamestudio.org/theme/css/normalize.css" />
  8. <link rel="stylesheet" href="http://opengamestudio.org/theme/css/foundation.min.css" />
  9. <link rel="stylesheet" href="http://opengamestudio.org/theme/css/style.css" />
  10. <link rel="stylesheet" href="http://opengamestudio.org/theme/css/pygments.css" />
  11. <script src="http://opengamestudio.org/theme/js/custom.modernizr.js"></script>
  12. <!-- So Firefox can bookmark->"abo this site" -->
  13. <link href="feeds/all.atom.xml" rel="alternate" title="Opensource Game Studio" type="application/atom+xml">
  14. </head>
  15. <body>
  16. <!-- Nav Bar -->
  17. <nav>
  18. <!-- Show menu items and pages -->
  19. <div class="row">
  20. <div class="large-12 columns top-bar">
  21. <h1><a href="http://opengamestudio.org">Opensource Game Studio</a></h1>
  22. </div>
  23. </div>
  24. <div class="row top-menu">
  25. <div class="large-12 columns">
  26. <a href="/pages/games.html" class="menu-button secondary">Games</a>
  27. <a href="/pages/education.html" class="menu-button secondary">Education</a>
  28. <a href="/pages/about.html" class="menu-button secondary">About</a>
  29. </div>
  30. </div>
  31. </nav>
  32. <!-- End Nav -->
  33. <!-- Main Page Content and Sidebar -->
  34. <div class="row">
  35. <!-- Main Blog Content -->
  36. <div class="large-9 columns">
  37. <article>
  38. <header>
  39. <h3 class="article-title"><a href="http://opengamestudio.org/ios-tutorial.html" rel="bookmark"
  40. title="Permalink to iOS tutorial">iOS tutorial</a></h3>
  41. </header>
  42. <h6 class="subheader" title="2017-06-08T10:00:00+03:00">Чт 08 июня 2017
  43. <a class="button secondary small translation-button" href="http://opengamestudio.org/ios-tutorial-ru.html">ru</a>
  44. </h6> <p><img alt="iOS tutorial" src="http://opengamestudio.org/2017-06-08-ios-refactoring.png"></p>
  45. <p>This article describes problems we faced during the creation of iOS tutorial in May 2017.</p>
  46. <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>
  47. <h3>Native library</h3>
  48. <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>
  49. <p>We had to consider the following facts:</p>
  50. <ol>
  51. <li>Xcode project can use C++ directly (thanks to Objective-C++) without stuff like JNI<ul>
  52. <li>There's no need for a separate library (+ application)</li>
  53. <li>Creating a separate library is an additional work (- library)</li>
  54. </ul>
  55. </li>
  56. <li>OpenSceneGraph builds libraries<ul>
  57. <li>It's easier to use standard build process (+ library)</li>
  58. <li>It's harder to create custom build process just for a single platform (- application)</li>
  59. </ul>
  60. </li>
  61. <li>OpenSceneGraph uses CMake build system, which is not supported by Xcode<ul>
  62. <li>Xcode project can't include CMake files (- application)</li>
  63. <li>It's easy to create custom CMake file that includes OpenSceneGraph CMake file to build a single library (+ library)</li>
  64. </ul>
  65. </li>
  66. <li>CMake can generate Xcode project<ul>
  67. <li>It's possible to create a CMake file that builds both OpenSceneGraph and the sample application (+ application)</li>
  68. <li>Xcode is the de-facto tool to create Xcode projects; it's easier to use standard build process (+ library)</li>
  69. </ul>
  70. </li>
  71. </ol>
  72. <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>
  73. <h3>Refactoring</h3>
  74. <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>
  75. <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>
  76. <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>
  77. <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>
  78. <ol>
  79. <li>functions.h - contains reusable classless functions</li>
  80. <li>main.h - contains the rest of the sample application code</li>
  81. </ol>
  82. <p>Their contents differ slightly for each platform, but it's easy to see the whole picture now.</p>
  83. <p>That's it for describing problems we faced during the creation of iOS tutorial in May 2017.</p>
  84. <p class="subheader">Category: <a href="http://opengamestudio.org/category/news.html">News</a>
  85. </p>
  86. </article>
  87. </div>
  88. <!-- End Main Content -->
  89. <!-- Sidebar -->
  90. <aside class="large-3 columns">
  91. <!--k
  92. <h5 class="sidebar-title">Site</h5>
  93. <ul class="side-nav">
  94. <li><a href="http://opengamestudio.org/archives.html">Archives</a>
  95. <li><a href="http://opengamestudio.org/tags.html">Tags</a>
  96. <li><a href="http://opengamestudio.org/feeds/all.atom.xml" rel="alternate">Atom feed</a></li>
  97. </ul>
  98. <h5 class="sidebar-title">Categories</h5>
  99. <ul class="side-nav">
  100. <li><a href="http://opengamestudio.org/category/news.html">News</a></li>
  101. </ul>
  102. -->
  103. <h5 class="sidebar-title">Ads</h5>
  104. <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  105. <!-- ogs2 -->
  106. <ins class="adsbygoogle"
  107. style="display:block"
  108. data-ad-client="ca-pub-4473792248813084"
  109. data-ad-slot="9024247127"
  110. data-ad-format="auto"></ins>
  111. <script>
  112. (adsbygoogle = window.adsbygoogle || []).push({});
  113. </script>
  114. </aside> <!-- End Sidebar -->
  115. </div> <!-- End Main Content and Sidebar -->
  116. <!-- Footer -->
  117. <footer class="row">
  118. <div class="large-12 columns">
  119. <hr />
  120. <div class="row">
  121. <div class="large-7 columns">
  122. <p>Proudly powered by <a href="http://getpelican.com">Pelican</a>, which takes great advantage of <a href="http://python.org">Python</a>.</p>
  123. </div>
  124. </div>
  125. </div>
  126. <script type="text/javascript">
  127. var _gaq = _gaq || [];
  128. _gaq.push(['_setAccount', 'UA-3773114-1']);
  129. _gaq.push(['_trackPageview']);
  130. (function() {
  131. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  132. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  133. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  134. })();
  135. </script>
  136. </footer>