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.

пре 7 година
пре 7 година
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <feed xmlns="http://www.w3.org/2005/Atom"><title>Opensource Game Studio - News</title><link href="https://ogstudio.github.io/" rel="alternate"></link><link href="https://ogstudio.github.io/feeds/news.atom.xml" rel="self"></link><id>https://ogstudio.github.io/</id><updated>2017-06-08T10:00:00+07:00</updated><entry><title>iOS tutorial</title><link href="https://ogstudio.github.io/ios-tutorial.html" rel="alternate"></link><published>2017-06-08T10:00:00+07:00</published><updated>2017-06-08T10:00:00+07:00</updated><author><name>Opensource Game Studio</name></author><id>tag:ogstudio.github.io,2017-06-08:/ios-tutorial.html</id><summary type="html">&lt;p&gt;&lt;img alt="iOS tutorial" src="https://ogstudio.github.io/2017-06-08-ios-refactoring.png"&gt;&lt;/p&gt;
  3. &lt;p&gt;This article describes problems we faced during the creation of iOS tutorial in May 2017.&lt;/p&gt;
  4. &lt;p&gt;&lt;a href="https://twitter.com/OpenGameStudio/status/826816343433498627"&gt;This February&lt;/a&gt; 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 …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;img alt="iOS tutorial" src="https://ogstudio.github.io/2017-06-08-ios-refactoring.png"&gt;&lt;/p&gt;
  5. &lt;p&gt;This article describes problems we faced during the creation of iOS tutorial in May 2017.&lt;/p&gt;
  6. &lt;p&gt;&lt;a href="https://twitter.com/OpenGameStudio/status/826816343433498627"&gt;This February&lt;/a&gt; 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.&lt;/p&gt;
  7. &lt;h3&gt;Native library&lt;/h3&gt;
  8. &lt;p&gt;The first question we had to answer was: should the sample application be part of Xcode project or be a separately built library?&lt;/p&gt;
  9. &lt;p&gt;We had to consider the following facts:&lt;/p&gt;
  10. &lt;ol&gt;
  11. &lt;li&gt;Xcode project can use C++ directly (thanks to Objective-C++) without stuff like JNI&lt;ul&gt;
  12. &lt;li&gt;There's no need for a separate library (+ application)&lt;/li&gt;
  13. &lt;li&gt;Creating a separate library is an additional work (- library)&lt;/li&gt;
  14. &lt;/ul&gt;
  15. &lt;/li&gt;
  16. &lt;li&gt;OpenSceneGraph builds libraries&lt;ul&gt;
  17. &lt;li&gt;It's easier to use standard build process (+ library)&lt;/li&gt;
  18. &lt;li&gt;It's harder to create custom build process just for a single platform (- application)&lt;/li&gt;
  19. &lt;/ul&gt;
  20. &lt;/li&gt;
  21. &lt;li&gt;OpenSceneGraph uses CMake build system, which is not supported by Xcode&lt;ul&gt;
  22. &lt;li&gt;Xcode project can't include CMake files (- application)&lt;/li&gt;
  23. &lt;li&gt;It's easy to create custom CMake file that includes OpenSceneGraph CMake file to build a single library (+ library)&lt;/li&gt;
  24. &lt;/ul&gt;
  25. &lt;/li&gt;
  26. &lt;li&gt;CMake can generate Xcode project&lt;ul&gt;
  27. &lt;li&gt;It's possible to create a CMake file that builds both OpenSceneGraph and the sample application (+ application)&lt;/li&gt;
  28. &lt;li&gt;Xcode is the de-facto tool to create Xcode projects; it's easier to use standard build process (+ library)&lt;/li&gt;
  29. &lt;/ul&gt;
  30. &lt;/li&gt;
  31. &lt;/ol&gt;
  32. &lt;p&gt;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.&lt;/p&gt;
  33. &lt;h3&gt;Refactoring&lt;/h3&gt;
  34. &lt;p&gt;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?&lt;/p&gt;
  35. &lt;p&gt;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.&lt;/p&gt;
  36. &lt;p&gt;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.&lt;/p&gt;
  37. &lt;p&gt;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:&lt;/p&gt;
  38. &lt;ol&gt;
  39. &lt;li&gt;functions.h - contains reusable classless functions&lt;/li&gt;
  40. &lt;li&gt;main.h - contains the rest of the sample application code&lt;/li&gt;
  41. &lt;/ol&gt;
  42. &lt;p&gt;Their contents differ slightly for each platform, but it's easy to see the whole picture now.&lt;/p&gt;
  43. &lt;p&gt;That's it for describing problems we faced during the creation of iOS tutorial in May 2017.&lt;/p&gt;</content></entry></feed>