|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <!DOCTYPE html>
- <head>
- <meta charset="utf-8" />
- <!-- Set the viewport width to device width for mobile -->
- <meta name="viewport" content="width=device-width" />
-
- <title>iOS tutorial</title>
-
- <link rel="stylesheet" href="http://opengamestudio.org/theme/css/normalize.css" />
- <link rel="stylesheet" href="http://opengamestudio.org/theme/css/foundation.min.css" />
- <link rel="stylesheet" href="http://opengamestudio.org/theme/css/style.css" />
- <link rel="stylesheet" href="http://opengamestudio.org/theme/css/pygments.css" />
- <script src="http://opengamestudio.org/theme/js/custom.modernizr.js"></script>
-
- <!-- So Firefox can bookmark->"abo this site" -->
- <link href="feeds/all.atom.xml" rel="alternate" title="Opensource Game Studio" type="application/atom+xml">
-
- </head>
-
- <body>
-
- <!-- Nav Bar -->
- <nav>
-
- <!-- Show menu items and pages -->
- <div class="row">
- <div class="large-12 columns top-bar">
- <h1><a href="http://opengamestudio.org">Opensource Game Studio</a></h1>
- </div>
- </div>
- <div class="row top-menu">
- <div class="large-12 columns">
- <a href="pages/projects.html" class="menu-button secondary">Projects</a>
- <a href="pages/about.html" class="menu-button secondary">About</a>
-
- </div>
- </div>
- </nav>
- <!-- End Nav -->
-
-
- <!-- Main Page Content and Sidebar -->
- <div class="row">
-
- <!-- Main Blog Content -->
- <div class="large-9 columns">
- <article>
- <header>
- <h3 class="article-title"><a href="http://opengamestudio.org/ios-tutorial.html" rel="bookmark"
- title="Permalink to iOS tutorial">iOS tutorial</a></h3>
- </header>
-
- <h6 class="subheader" title="2017-06-08T10:00:00+03:00">Чт 08 Июнь 2017
- <a class="button secondary small translation-button" href="http://opengamestudio.org/ios-tutorial-ru.html">ru</a>
-
- </h6> <p><img alt="iOS tutorial" src="http://opengamestudio.org/2017-06-08-ios-refactoring.png" /></p>
- <p>This article describes problems we faced during the creation of iOS tutorial in May 2017.</p>
- <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>
- <h3>Native library</h3>
- <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>
- <p>We had to consider the following facts:</p>
- <ol>
- <li>Xcode project can use C++ directly (thanks to Objective-C++) without stuff like JNI<ul>
- <li>There's no need for a separate library (+ application)</li>
- <li>Creating a separate library is an additional work (- library)</li>
- </ul>
- </li>
- <li>OpenSceneGraph builds libraries<ul>
- <li>It's easier to use standard build process (+ library)</li>
- <li>It's harder to create custom build process just for a single platform (- application)</li>
- </ul>
- </li>
- <li>OpenSceneGraph uses CMake build system, which is not supported by Xcode<ul>
- <li>Xcode project can't include CMake files (- application)</li>
- <li>It's easy to create custom CMake file that includes OpenSceneGraph CMake file to build a single library (+ library)</li>
- </ul>
- </li>
- <li>CMake can generate Xcode project<ul>
- <li>It's possible to create a CMake file that builds both OpenSceneGraph and the sample application (+ application)</li>
- <li>Xcode is the de-facto tool to create Xcode projects; it's easier to use standard build process (+ library)</li>
- </ul>
- </li>
- </ol>
- <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>
- <h3>Refactoring</h3>
- <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>
- <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>
- <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>
- <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>
- <ol>
- <li>functions.h - contains reusable classless functions</li>
- <li>main.h - contains the rest of the sample application code</li>
- </ol>
- <p>Their contents differ slightly for each platform, but it's easy to see the whole picture now.</p>
- <p>That's it for describing problems we faced during the creation of iOS tutorial in May 2017.</p>
- <p class="subheader">Category: <a href="http://opengamestudio.org/category/news.html">News</a>
-
- </p>
-
-
-
- </article>
- </div>
- <!-- End Main Content -->
-
- <!-- Sidebar -->
- <aside class="large-3 columns">
- <!--k
- <h5 class="sidebar-title">Site</h5>
- <ul class="side-nav">
- <li><a href="http://opengamestudio.org/archives.html">Archives</a>
- <li><a href="http://opengamestudio.org/tags.html">Tags</a>
-
-
- <li><a href="http://opengamestudio.org/feeds/all.atom.xml" rel="alternate">Atom feed</a></li>
- </ul>
-
-
- <h5 class="sidebar-title">Categories</h5>
- <ul class="side-nav">
- <li><a href="http://opengamestudio.org/category/news.html">News</a></li>
-
- </ul>
- -->
-
-
-
-
- <h5 class="sidebar-title">Ads</h5>
- <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
- <!-- ogs2 -->
- <ins class="adsbygoogle"
- style="display:block"
- data-ad-client="ca-pub-4473792248813084"
- data-ad-slot="9024247127"
- data-ad-format="auto"></ins>
- <script>
- (adsbygoogle = window.adsbygoogle || []).push({});
- </script>
-
- </aside> <!-- End Sidebar -->
-
- </div> <!-- End Main Content and Sidebar -->
-
-
- <!-- Footer -->
- <footer class="row">
- <div class="large-12 columns">
- <hr />
- <div class="row">
- <div class="large-7 columns">
- <p>Proudly powered by <a href="http://getpelican.com">Pelican</a>, which takes great advantage of <a href="http://python.org">Python</a>.</p>
- </div>
- </div>
- </div>
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-3773114-1']);
- _gaq.push(['_trackPageview']);
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- </script>
- </footer>
|