
Windows game developer about porting to and using OS X - levifig
http://www.shiningrocksoftware.com/2015-11-10-osx-progress/
======
lucozade
> Apparently my vi command muscle memory hasn't faded.

Back in the day I did most of my dev work on Solaris. I then spent 4 years as
CTO as a startup that was pretty much only Windows.

When I subsequently went back to working at a unix shop I was initially
struggling with vi as I tried to read some of the C++ code. I couldn't
remember commands, was having to refer to the man pages every few mins. It was
torture.

A couple of days in, I was writing up some notes in vi when someone walked
past my desk and started chatting. When we finished talking I looked down at
the monitor and I'd written more than I had when I was concentrating, nicely
formatted, the works. Turns out "my hands" had remembered a load of what I
thought I had forgotten.

For the next few days I had to keep finding ways to distract myself so that I
could work efficiently. Eventually it all came to the foreground but it was
the most bizarre experience while it was happening.

~~~
farresito
This always happens to me with passwords. I have trouble remembering some
passwords. Yet, when I'm in front of the page and I actually need to get in,
either I lose some focus and let my unconsciousness do the work or I won't get
it right.

~~~
knodi123
I was trying to share my banking passwords with my wife ("in case of
emergency" kind of stuff), and I was forced to admit that I had no idea what
my bank password was, even though I log into it several times a week. I had to
open a word processor and type my username and password for her all at once.
The act of typing my username allowed the password to pop into my memory.

~~~
danvideo
I tend to think it's a good thing that I don't actually know my bank passwords
- a password manager is much simpler. Having strong passwords for all
different banks is a piece of cake when you don't have to remember them.

------
SXX
_I’m not using SDL or any other library to hide those platform differences._

Once start working on Linux port he'll regret about that. Every developer that
start with own platform-specific code end up using SDL2 anyway. Don't do that
mistake.

~~~
picozeta
Furthermore SDL2 is absolutely fantastic and just works. You may say, you do
not want to use it as it "just" abstracts away keyboard/mouse/controller
input, window and GL context creation but these things are damn hard to get
right.

~~~
et1337
As a current SDL2 user: it is not fantastic and it does not just work.

\- On Windows, DPI scaling is broken (ask for a 1280x720 window, get 1600x900)

\- On Mac, mouse locking is broken

\- On Linux, my Xbox gamepads don't work at all

\- Required several hacks before it could be used as a CMake submodule

This stuff is under active development, which is shocking for such an
established and widespread library. I'm glad it exists, but it doesn't "just
work".

Can't really blame it though, it has a very boring and nearly impossible task.

~~~
mwcampbell
Does high-DPI support work if you put the right declaration in your
executable's manifest? Specifically:

    
    
        <application xmlns="urn:schemas-microsoft-com:asm.v3">
            <windowsSettings>
                <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
            </windowsSettings>
        </application>

~~~
et1337
Thanks, yeah I tried something equivalent to this (SetProcessDpiAwareness, as
mentioned by another commenter). It broke some other SDL stuff though. I'm
just gonna have to screw around with it when release time comes.

------
stinos
_Xcode isn’t too bad._

I wish the author told me more about it than just this. Can somebody comment
on how it compares to recent VS editions these days? About 5 years ago I also
looked into using OSX as main OS. As I've always been using non-commandline
graphic text editors and IDEs for most coding that made XCode the go-to
environment but I just couldn't deal with it even though I tried. I don't
remember all details but in general it just felt inferior to VS on like all
fronts, with no advantages of any kind (for C++). Again, IIRC, but it did
annoying things like opening the same document in multiple windows, one for
editing and one for debugging or so? Anyway, what's the state today?

~~~
yeureka
I use both on a regular basis, VS for my job and XCode for hobby work.

I prefer VS because it performs better when editing and navigating the code
base ( it is actually faster to run in it inside VirtualBox than XCode
natively ).

Also VS has code navigation and editing features that XCode lacks. For
instance if you want to do a find/replace in VS you can double click on a word
do Ctrl+H and the word you selected populates the search box. You can then
populate the replace box with what you have in the clipboard or just type in
what you want. In XCode you need to copy the word to replace into the
clipboard, do a Cmd+F, paste the word into the search box and then type in the
replace box. This is much slower.

In VS you can setup bookmarks in your code with Ctrl+F2 and jump between
bookmarks by pressing F2. This is great when you need to have present multiple
parts of the code base to accomplish some task. I don't know how to do this in
XCode.

In VS you have a stack of source code windows that you can easily move about
via Ctrl+W+n where n is the stack depth. This is incredibly useful to navigate
between multiple files. Again, I don't know how to this without using the
mouse in XCode.

Then there are other issues with XCode mentioned by other comments like the
incredibly confusing build settings and the instability of the IDE.

I often wonder if Apple actually uses it to develop their software.

~~~
interpol_p
I haven't used VS in many years, but I like what you describe. I don't know if
this will be helpful, but these are my alternatives in Xcode:

> _For instance if you want to do a find /replace in VS you can double click
> on a word do Ctrl+H and the word you selected populates the search box._

Your workflow sounds nicer than Xcode's here. While I don't often use
find+replace, I do use project level find constantly. My muscle memory
shortcut for this is:

Cmd+C, Cmd+Shift+F, Cmd+V, Return

I'm pretty sure I use this hundreds of times a day. Especially when analysing
unfamiliar code to trace its execution paths.

> _Ctrl+F2 code bookmarks_

These sound really cool. A bit like numbered unit groups in Starcraft.

The only similar mechanism in Xcode is quick open. Cmd+Shift+O then start
fuzzy-typing the name of a file, method or declaration and hit return to jump
to it in the editor (option+return for assistant editor). I have actually
changed my quick open shortcut to Cmd+Shift+D because it's easier to trigger
one-handed.

> _In VS you have a stack of source code windows that you can easily move
> about via Ctrl+W+n_

Unfortunately, while a stack of source locations is maintained in Xcode, you
can't jump to a direct location within the stack.

What I do here is use Ctrl+Cmd+Left and Ctrl+Cmd+Right to navigate back and
forward in the history stack for an editor window. So, for example, if you
Cmd+Click a symbol to jump to its declaration, you can press Ctrl+Cmd+Left to
go back.

The one thing I like about Xcode's version of this is that it keeps track of
source locations rather than files or windows. So you actually navigate
back/forward within the same file (if you were jumping around within the file)
as well as between files.

~~~
hungri-yeti
You can use Cmd+E to directly insert the selected text into the search buffer,
so for the Project-Wide search you wind up with the shorter sequence:

Cmd+E, Cmd+Shift+F, Return

This sequence seems to work in many other apps, I don't know if it's a system
command or just a common convention.

~~~
interpol_p
Thanks! That's really useful to know.

------
curyous
So he's got a working port on an OS he's never seen before, in only 1 week?
Does that seem extraordinarily productive to anyone else?

~~~
huhtenberg
Just the title screen, not a complete port. Nor would 1FPS be probably
considered "working" :)

He put the OS glue in place in 1 week and that sounds about right for this
sort of effort, given some prior experience with writing portable code. The
bulk of effort was spent earlier on abstracting principal code from the
platform specifics, and sounds like he did all the right things there. Good
stuff.

~~~
a_bonobo
He is extremely productive, to be fair - "Shining Rock Software" is only him,
the entire game, pretty successful on Steam, is just coded and maintained by
him.

~~~
mattmanser
It's an absorbing simcity-esque game, as long as you don't go in expecting
Civ/SimCity replay value it's definitely worth it if you like those type of
games, or at the very least putting on your wishlist for the steam winter
sale.

The level of quality for a one-person team is phenomenal.

------
lmolnar
I recently went through a very similar process porting my screensaver [1] from
Windows to Mac without using a library like SDL. Here are some additional
difficulties I encountered during this process:

OpenGL on multiple monitors - this was much more difficult to do on MacOS. I
had to create a separate window for each monitor, create a rendering context
for each window, make sure my graphics code was issuing the drawing commands
to the proper context, then have each context queue/batch "pending" rendering
commands and issue them all at once at the end of a frame on a by-context
basis. Whereas on Windows you can pretty much create a window that spans
multiple monitors and draw to it with a single rendering context.

Input - I used DirectInput on Windows and wrangled a suitable implementation
using HID Utilities on Mac, which was not easy given my lack of previous USB
programming experience. A major annoyance was the lack of a device "guid" that
you can get via HID Utilities to uniquely identify an input device - I had to
manually contruct one using (among other things) the USB port # that the
device was plugged into. Not ideal.

SSE intrinsics - my experience was that Microsoft's compiler was MUCH better
at generating code from SSE/SSE2 intrinsics then clang - my Windows SSE-
optimized functions ran significantly faster then my "pure" C++
implementations, where as the Mac versions ran a bit slower! My next thought
was to take this particular bit of code gen responsibility away from clang and
write inline assembly versions of these functions, but I took a look at the
clang inline assembly syntax and decided to skip that effort. (I did write an
inline assembly version using the MS syntax and squeezed an additional 15%
perf over the MS intrinsic code.)

Prtty much everything else (porting audio from DirectSound to OpenAL, issuing
HTTP requests, kludging up a GUI etc) was pretty straight forward/did not have
any nasty surprises.

[1]
[http://www.ubernes.com/nesscreensaver.html](http://www.ubernes.com/nesscreensaver.html)

~~~
acdha
> SSE intrinsics - my experience was that Microsoft's compiler was MUCH better
> at generating code from SSE/SSE2 intrinsics then clang

I don't know whether this is still the case – or something like tweaking the
target CPUs would help – but assuming it is, did you report it to either the
open-source Clang project or Apple? The developers have seemed to be quite
responsive to reports like this.

~~~
lmolnar
I did not, I just #ifdef-ed that code out of the Mac port. I'll review what
I've done again and follow-up with the Clang people.

------
mavdi
Has he developed this game all by himself? How can people be so productive?
Develop, test, market... This is just crazy.

~~~
skrebbel
Does anyone know whether he did the graphics too? It's not world class art,
but it looks real good, so I'd be very impressed if that was the same guy
_too_.

~~~
skrebbel
Answering my own question, the sidebar on the right says:

> _Shining Rock Software has only a single developer doing all the software
> development, artwork, and audio._

I'm blown away. Really cool.

~~~
diqu
He used to be a console engine dev, so - naturally - he wrote even that from
scratch. On his own. Quite admirable, I think.

------
anton_gogolev
Tangentially related: Banished is _higly_ recommended. Quiet room, couple
glasses of whiskey and you're guaranteed to have a nice evening.

~~~
mediumdeviation
It's not a bad game, especially for its price, but remember that this is a
town, not city building game. That means that there is a hard limit to the
size of the town - any bigger, and the agents (citizens) will literally starve
to death en route to their next destination because it is too far from their
home.

If you want to expand further, all you're doing is making exact, self-
contained replicas of the same town in other places on the map. There's not
much variety because each town needs the same resources, and each map has
those same resources.

Like many games of this genre, the game has a reverse difficulty curve. This
is especially true here because of the focus on survival. That means that the
first few winters will be spent micromanaging every single resource to ensure
everyone has sufficient materials, but after that initial period is over, it's
impossible to fail because the town basically runs itself.

~~~
anton_gogolev
All true. But there's trading that can be quite a bit entertaining. And theres
Colonial Charter[1], which is an excellent mod, but it can be daunting because
of sheer volume of changes and new stuff.

[1]: [http://www.colonialcharter.com/](http://www.colonialcharter.com/)

------
trymas
For me the most interesting part (and answer to it) why on OS X the game runs
at 1FPS, whereas on windows machine with the same graphics card it runs just
fine?

What can make such considerable difference?

~~~
sitharus
Drivers. On MacOS they tend to be a bit behind the Windows versions, also
MacOS itself is reasonably GPU-heavy. Add to that Apple's tendency to lag
behind the latest (as in from the last five years) OpenGL standards and you've
got a recipe for slow OpenGL.

Though interesting that it's an Iris Pro, MacOS used to have the best Intel
drivers as Apple pulled them in-house. ATI and NVidia have always treated
MacOS as a secondary target.

~~~
reidrac
That doesn't sound completely right.

If it was a 10% performance hit, I could blame the driver but comparing 60 FPS
(I presume) with 1 FPS when people are playing the game in Mac OS X using
WINE; that sounds like something is probably not quite right in his code.

------
kevingadd
The comment about C++ templates is baffling and I wish the author would
elaborate. The behavior he describes that clang doesn't support is... how
templates are specified to work. They're near-useless without that property.

 _Most of these had to do with templates that expected the code inside them
not to be compiled until they were instantiated. The Microsoft compiler has
that behavior, while clang does not._

~~~
Kristine1975
He's talking about two-phase name lookup, which VS doesn't implement (yet?),
but clang does (as it should, striving to be a standard-compliant compiler).
Here's a nice article about it: [http://blog.llvm.org/2009/12/dreaded-two-
phase-name-lookup.h...](http://blog.llvm.org/2009/12/dreaded-two-phase-name-
lookup.html)

TL;DR: If a type, variable... depends on template parameters, code using it is
checked when the template is _instantiated_ with concrete template arguments.
Otherwise it is checked when the template is _defined_.

I don't quite understand why you call templates near-useless, if two-phase
name lookup didn't exist?

------
stevoski
I went the other way: last year I converted an OS X app to Windows. I hadn't
used Windows for six years, and had forgotten most things.

It took two weeks to get the code compiling and running. That turned out to be
the easy part. Getting the application performing well, feeling "native", and
getting the bug count down took another six months.

I love Banished and I'd like to see a completed OS X port. But I'm not
expecting this to be done, like, tomorrow!

------
shmerl
I'd be more interested in his experience about porting to Linux (since
supposedly he is working on it as well).

OpenGL on OS X is still behind the times, and so far it's not even clear if
Apple will add Vulkan support when it will come out.

------
packersville
> couldn’t figure out how an ‘All Files’ category was useful when browsing
> finder windows

To this day I still don't see or find how it is useful.

~~~
zaphoyd
It is a nice starting point for queries about files on the system as a whole
rather than in a particular folder. i.e. Show me all of the PDF files I've
used recently. Or find a file with name x but I have no idea where it is.
`find / -name foo` vs `find . -name foo`

------
indifferentalex
The man's commitment to his game, considering that he works alone is
incredible. Without using terms like "10xer" and "rockstar", he's got an
incredible level of perseverance and dedication, considering that he already
launched the game and at this point is working on features that are considered
by many boring and a grind, all to make a polished finished product. The fact
that he documented pretty much everything in his blog is great if you need
motivation or are just curious about how to make a game from zero.

------
885895
>unix-like

Not just unix-like, OS X is certified UNIX.

~~~
collyw
What does this atually mean (when compared to Linux, which is a UNIX clone)?
That they have paid someone for a certificate? Is it more than that?

~~~
ahoka
Yes, it means that someone payed money for a useless certificate. Nothing
more, nothing less.

BTW, Linux is UNIX too!

[http://www.opengroup.org/openbrand/register/brand3596.htm](http://www.opengroup.org/openbrand/register/brand3596.htm)
[https://en.wikipedia.org/wiki/Inspur_K-
UX](https://en.wikipedia.org/wiki/Inspur_K-UX)

~~~
pjmlp
So all APIs provided by all Linux distributions fully support the POSIX
specification to the smallest detail?

~~~
ahoka
Maybe after some nonsense like "export POSIXLY_CORRECT" and defining a few
macros.

~~~
pjmlp
Which means it isn't actually a proper UNIX out of the box.

~~~
ahoka
Verdict: no true scotsman is true unix.

------
DeveloperExtras
I do it this way, but it's based on my particular skill set:

First make the iOS version. Then, port it over to Java. Then, port it over to
C# or maybe ActionScript3/Flash.

This way, I can recursively update previous versions as the 'best solution' to
interesting problems become most clear by the end of the 2nd or 3rd port. This
gives the Objective-C/iOS version the attention it needs, and I can use the
rapid application development features for each new port.

~~~
gazsp
That sounds like a lot of work.

------
maljx
We develop our game on Mac OS X and port to Win32 and Linux. Using CMake, SDL2
and C++11 there is very little code that actually needs to be rewritten. The
windows build process is just a python script that pulls, cmake configure,
compiles and zips the latest build.

The code that is completely different on the platforms is stuff like HTTPS
requests, open file dialog, create/delete folders.

------
AdmiralAsshat
_The fact that it’s running at 1 FPS is a little disheartening – I know the
GPU is fast enough. I’ve got a Windows machine with an Intel Iris Pro 5000
that runs Banished just fine, which is the same graphics hardware in my
MacBook Pro. I’ve got my suspicions as to whats going on but I have a bunch of
testing ahead of me to make sure I fix the issue properly._

Did the author buy a MacBook Pro just for this purpose? I'd assume this is his
personal laptop, but his "Using a Mac" section sounds like he's not a Mac user
even in his free time.

~~~
TazeTSchnitzel
The first thing the author talks about is their unfamiliarity with the Mac
environment, and the game wasn't made for OS X in the first instance, which
would suggest they did buy a Mac purely for an OS X port.

------
jason_slack
What is the window in the background that is NOT Xcode. Off to the left.
Something "workspace"?

~~~
mrpippy
Perforce client (P4V). Consider yourself lucky you don't recognize it.

~~~
jason_slack
Thanks. I initially thought it was Valgrind.

------
jokoon
Well I sold my macbook pro because I wasn't able to build my ogre project
properly. For years. Also there was some OIS (not iOS, OIS) input issue. It
comes from apple force feeding Cocoa into opengl apps, or something like that,
which can only be remedied by using some SDL hack.

Anyway, I don't really care anymore, I bought a thinkpad instead. Cocoa is
just something I just can't even.

My experience has been pretty different. I'm not a professional developer
though.

~~~
sounds
Working through the Ogre issues on OS X is like a rite of passage, I thought?

I tried multiple times to contribute OS X fixes to the Ogre code base. They're
not hard things --

1\. Use SDL not OIS.

2\. The symlinking is broken.

3\. Link the frameworks properly.

There was one more thing, I think. Just minor issues that probably have crept
into the codebase because no one is able to contribute the fixes.

It's Ogre. It's not OS X.

~~~
jokoon
Thought too. But in my opinion, an OS has larger responsibilities when it
comes to improve inter compatibility, instead of breaking things to have
developers who stay loyal and ending up with apple-exclusive software. I
really wonder about the value objective C brings, especially since NextStep
did not work as a project. You can't always put the fault on library devs.

What boggles my mind, is that OSX is an unix underneath, so I don't understand
why it would do anything different and force developers to learn new habits.
That's not how you attract devs. Apple has made an habit to break backward
compatibility, something neither linux nor windows tend to do.

I think it's not so much to think that OS manufacturers should not to be
different than their competition by separating even how their development
tools work. The only objective of that is to have developers who stay loyal to
apple because they can't have their app running on both windows and mac. Not
to mention I had to re do everthing at each new XCode version.

So in the end, having my project run on both XCode and MSVC, was too much time
lost, so I just sold that aging laptop. Apple is just so special, and I guess
I was not good enough for that.

