{"id":237,"date":"2009-12-19T17:12:08","date_gmt":"2009-12-19T23:12:08","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=237"},"modified":"2009-12-19T17:12:08","modified_gmt":"2009-12-19T23:12:08","slug":"elephants-first-python-pygame-game-submitted-to-app-store","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2009\/12\/19\/elephants-first-python-pygame-game-submitted-to-app-store\/","title":{"rendered":"Elephants!  First python + pygame game submitted to App Store :)"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright\" src=\"http:\/\/www.galcon.com\/games\/elephant\/imgs\/160-icon.png\" alt=\"\" width=\"160\" height=\"160\" \/>So, I managed to submit a &#8220;python&#8221; app to the App Store &#8212; &#8220;Elephants!&#8221; Here&#8217;s a few crazy things I had to work out to get things going:<\/p>\n<ul>\n<li>I found that ObjC doesn&#8217;t care much for C++ objects that do their own reference counting. \u00a0To have a &#8220;Game&#8221; object at all, I had to use a pointer to my object instead of using my reference counting object. \u00a0It seems that during some of the &#8220;magic&#8221; of ObjC it copies objects without calling any of the C++ copying methods, so reference counting gets killed.<\/li>\n<li>I ported a basic subset of pygame to tinypyC++ and made it work under openGL. \u00a0I don&#8217;t have this available in my tinypyC++ repository because it takes a good deal of prep-work to use (isn&#8217;t out-of-the-box) so it wouldn&#8217;t be generally useful to anyone yet.<\/li>\n<li>I was able to get pause on call \/ resume working by saving the game state to a text file. \u00a0Since tab-separated files are so easy to create and parse in python this seemed to be the easiest route to getting the project done.<\/li>\n<li>I learned a ton about C++ templates. \u00a0I still haven&#8217;t even touched the tip of the iceberg, and I&#8217;m not sure I want to, but at least I&#8217;m getting the basics down and that seems to be enough for me to stumble through this project with.<\/li>\n<\/ul>\n<p>You can check out my current progress at svn:\/\/www.imitationpickles.org\/tinypy\/branches\/tinypy2 (in the tinypy\/example folder you can check out a julia fractal demo. \u00a0It also includes a mini pygame module that depends on SDL not OpenGL, so it actually works out-of-the-box.)<\/p>\n<p>Here are some things I&#8217;ve been adding this week in preparation for my next project:<\/p>\n<ul>\n<li>I&#8217;ve added &#8220;weak pointers&#8221; .. Since reference counting has the problem of cyclic references never getting collected, I had to do this for some use-cases. \u00a0In tinypyC++ weak pointers are just normal pointers, and if the object is collected, the pointer will be invalid, so be careful. \u00a0They are created by doing stuff like &#8220;x = ptr(GameData())&#8221;<\/li>\n<li>I&#8217;ve added more C style types. \u00a0I&#8217;ve got uint16, cstr, Array, etc. \u00a0This all makes it possible for me to have a different kind of object &#8211; a struct in tinypyC++. \u00a0The struct is meant to be a C oriented type that can be saved directly to disk. \u00a0In Elephants I serialized via saving CSV data. \u00a0In the future, if I keep all the game state in C struct type data, I can just use a single simple line like &#8220;open(&#8216;data.txt&#8217;,&#8217;wb&#8217;).write(struct_dump(game_data)&#8221;<\/li>\n<li>I found that STL extensions include a &#8220;hash_map&#8221; which turns out to be about 2x as fast as the normal &#8220;map&#8221;. \u00a0I&#8217;m using that now.<\/li>\n<\/ul>\n<p>I&#8217;m not entirely sure how useful this project is going to be for anyone else, or even for me for that matter. \u00a0But I think after my next game project I&#8217;ll have a much better feel for what the situation is. \u00a0TinypyC++ has some real tradeoffs in terms of being a bit of a hybrid of C++ and of python. \u00a0It doesn&#8217;t offer the full power of either language. \u00a0But I&#8217;m doing my best to capture a middle ground between them that will make my life easier.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, I managed to submit a &#8220;python&#8221; app to the App Store &#8212; &#8220;Elephants!&#8221; Here&#8217;s a few crazy things I had to work out to get things going: I found that ObjC doesn&#8217;t care much for C++ objects that do their own reference counting. \u00a0To have a &#8220;Game&#8221; object at all, I had to use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,13,6,2],"tags":[],"class_list":["post-237","post","type-post","status-publish","format-standard","hentry","category-c","category-crazy","category-development","category-python"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":8,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions\/245"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}