Author Topic: Native Simutrans on OSX via Quartz  (Read 14667 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashley

Native Simutrans on OSX via Quartz
« on: December 15, 2011, 03:02:23 AM »
I've compiled a new version of this for r5583 (112.2.2), please test.

It works only on OSX 10.7 (Lion). The app bundle includes pak64, you can add other paksets by right-clicking on the app bundle, selecting "show package contents" and then copying your pakset into Contents/MacOS/ (equivalent to the simutrans/ folder on other platforms).

Please let me know if you have any problems with it. It's still fairly new/crude but should have all the basic functionality.

http://entropy.me.uk/simutrans/simutrans_112.2.2.dmg
The source has been available on Github for a while, here: https://github.com/tbentropy/Simutrans-OSX



So I have been working on this, it's still early work (learning Objective-C as I go along) but I have managed to get it to work!

(I think I need to fix the colourspace though...)

« Last Edit: July 09, 2012, 09:42:54 AM by Fabio »
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Isaac.Eiland-Hall

  • Benevolent Dictator
  • Administrator
  • *
  • Posts: 3345
  • Total likes: 228
  • Helpful: 90
  • PanamaCityPC.com/support/
    • Facebook Profile
  • Languages: EN
Re: Native Simutrans on OSX via Quartz
« Reply #1 on: December 15, 2011, 03:50:32 AM »
What? Colourspace looks fine to me. hehehe

Offline mEGa

  • 2D painter
  • Devotee
  • *
  • Posts: 1041
  • Total likes: 1
  • Helpful: 35
  • Pak128 graphics
    • mEGa_Simutrans
  • Languages: FR, EN, ru
Re: Native Simutrans on OSX via Quartz
« Reply #2 on: December 15, 2011, 06:54:49 AM »
Is it a 3D adaptation screen? need of adapted glasses ? LOL
Current projects in progress : improvements of few designed french paks

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #3 on: December 15, 2011, 09:25:42 AM »
What? Colourspace looks fine to me. hehehe

You might want to get your eyes tested Isaac ;)
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #4 on: December 15, 2011, 12:32:33 PM »
Question - does makeobj store the image data in pak files internally as 24bits (e.g. 8 bits for R, 8 bits for G, 8 bits for B) or as RGB565/1555? Some of the graphics backends seem to be able to use either RGB565 or RGB1555 for display. Quartz only natively supports RGB1555 mode without conversion to RGB888 however. It would likely be possible to implement a 24 bit version of simgraph but obviously there would be little point if the source image data from pak files isn't 24bit.

Otherwise I could implement a conversion from RGB565 data into RGB888 - though this would seem silly if we're going from RGB888 source data, to RGB565 in simgraph, and then back to RGB888 for display... Or just stick to RGB1555 and miss out on the potential extra colour information in the green channel.

A 24-bit simgraph could benefit the SDL or other backends too of course.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4070
  • Total likes: 98
  • Helpful: 146
  • Languages: EN, DE, AT
Re: Native Simutrans on OSX via Quartz
« Reply #5 on: December 15, 2011, 12:51:06 PM »
Question - does makeobj store the image data in pak files internally as 24bits (e.g. 8 bits for R, 8 bits for G, 8 bits for B) or as RGB565/1555?
Images are converted by makeobj to RGB 555, register_image is called with RGB 555 data. There seems to be no conversion RGB 555 -> 565 ???
« Last Edit: December 15, 2011, 01:52:13 PM by Dwachs »
Parsley, sage, rosemary, and maggikraut.

Offline VS

  • Senior Plumber (Devotee)
  • Devotee
  • *
  • Posts: 4849
  • Total likes: 23
  • Helpful: 63
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: Native Simutrans on OSX via Quartz
« Reply #6 on: December 15, 2011, 01:21:02 PM »
555 == 1555?

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #7 on: December 15, 2011, 01:30:15 PM »
Ah ok, e.g. in simsys_w.cc you see:

Code: [Select]
/**
 * Transform a 24 bit RGB color into the system format.
 * @return converted color value
 * @author Hj. Malthaner
 */
unsigned int get_system_color(unsigned int r, unsigned int g, unsigned int b)
{
#ifdef USE_16BIT_DIB
return ((r & 0x00F8) << 8) | ((g & 0x00FC) << 3) | (b >> 3);
#else
return ((r & 0x00F8) << 7) | ((g & 0x00F8) << 2) | (b >> 3); // 15 Bit
#endif
}

But presumably this is just for mapping it into the OS's native colourspace, and since the source data is always RGB555 (yes, RGB1555 means the same, but slightly more specific about where the "spare" bit goes).

There's also a lot of logic in simgraph16.cc which seems related, e.g.:

Code: [Select]
/* from here code for transparent images */
typedef void (*blend_proc)(PIXVAL *dest, const PIXVAL *src, const PIXVAL colour, const PIXVAL len);

// different masks needed for RGB 555 and RGB 565
#define ONE_OUT_16 (0x7bef)
#define TWO_OUT_16 (0x39E7)
#define ONE_OUT_15 (0x3DEF)
#define TWO_OUT_15 (0x1CE7)

static void pix_blend75_15(PIXVAL *dest, const PIXVAL *src, const PIXVAL , const PIXVAL len)
{
const PIXVAL *const end = dest + len;
while (dest < end) {
*dest = (3*(((*src)>>2) & TWO_OUT_15)) + (((*dest)>>2) & TWO_OUT_15);
dest++;
src++;
}
}

etc...



And I fixed the psychedelic colours, was an endianness problem in converting it to a Quartz type image.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8573
  • Total likes: 254
  • Helpful: 226
  • Languages: De,EN,JP
Re: Native Simutrans on OSX via Quartz
« Reply #8 on: December 15, 2011, 01:33:44 PM »
Internally the colors in the image are RGB555 + 256 special colors. However, simgraph16.cc uses RBG 565 for the colors. (Technically is uses a lookup table to translate those. However, almost no architekture support 16 bit paletted graphics reasonably.) Thus dr_textur() is called with a textur containing a 16 bit RBG 565 bitmap. If you need other colors or another order, you must modify the return values of get_system_color() to obtain RBG555.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #9 on: December 15, 2011, 11:58:52 PM »


Looking better now, had to implement locking so that the Cocoa application thread and game thread draw/render the graphics in sync. One interesting aspect of the Quartz rendering is that you can perform transforms on the rendered image, e.g. stretching/skewing it, with little performance penalty.

Next things to do are events, mapping between screen space and game space, resizing of the screen buffer, clipboard, screenshots (should be easy, in fact implementing game video recording would be almost trivial...)

And then the iPhone version :P
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Isaac.Eiland-Hall

  • Benevolent Dictator
  • Administrator
  • *
  • Posts: 3345
  • Total likes: 228
  • Helpful: 90
  • PanamaCityPC.com/support/
    • Facebook Profile
  • Languages: EN
Re: Native Simutrans on OSX via Quartz
« Reply #10 on: December 16, 2011, 01:16:50 AM »
WOAH THAT LOOK HORRIBLE WAT DID YOU DO TO THE COLOURS?!?!

hehe.

Nicely done. :D

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #11 on: December 21, 2011, 05:46:59 PM »
I've got events working via a threadsafe queue, though there is quite some work to do to wire up every event...

Why do mouse events have both an mb property (which is a bitmask of the mousebuttons pressed) and a code property (which indicates which button has been pressed)? Is this purely to pick up on what other mouse buttons were pressed at the time the event occurred? How is this used internally? I am not sure there's an easy way to fill in information about other buttons using the implementation I have now...
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8573
  • Total likes: 254
  • Helpful: 226
  • Languages: De,EN,JP
Re: Native Simutrans on OSX via Quartz
« Reply #12 on: December 21, 2011, 09:23:20 PM »
Old MAC gave the button state with every event, some GEM and Windows copied this. Moreover serial mouse always gave this in Allegro, which were the first backend under DOS then. Otherwise use a static to rember last state, as it does for instance also current implementation of simevent.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #13 on: December 21, 2011, 10:43:09 PM »
Right, so, what I mean is does simevent need this information, or does it remember the last state itself? The SDL implementation for example looks like it gets the current mouse states at the moment when the game retrieves the event, which may be a different set of states to those when the event was actually generated...
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8573
  • Total likes: 254
  • Helpful: 226
  • Languages: De,EN,JP
Re: Native Simutrans on OSX via Quartz
« Reply #14 on: December 21, 2011, 11:09:07 PM »
simevent remembers the last state; But it is reset every time a new event arrives. Thus maybe just save your last state too.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 14774
  • Total likes: 309
  • Helpful: 144
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Native Simutrans on OSX via Quartz
« Reply #15 on: December 22, 2011, 01:34:36 AM »
This looks very interesting. Would it be possible to do an Experimental version of this?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8573
  • Total likes: 254
  • Helpful: 226
  • Languages: De,EN,JP
Re: Native Simutrans on OSX via Quartz
« Reply #16 on: December 22, 2011, 10:25:48 AM »
Please james, stop making everything asking if it can be used for experimetnal. Especially, if you could have guessed the answer yourself. The backend should be not affected by what calls the engine uses internally, as long as you did not modified the dr_ calls. And you should know, if you did that.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #17 on: December 22, 2011, 11:18:06 AM »
This looks very interesting. Would it be possible to do an Experimental version of this?

Of course it's possible, all it would take is someone to do the work to port it over. In fact given that it doesn't modify the game files at all (except the makefile) so long as experimental has not changed the simsys interface it'd be a drop-in addition.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 14774
  • Total likes: 309
  • Helpful: 144
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Native Simutrans on OSX via Quartz
« Reply #18 on: December 22, 2011, 11:31:20 AM »
Of course it's possible, all it would take is someone to do the work to port it over. In fact given that it doesn't modify the game files at all (except the makefile) so long as experimental has not changed the simsys interface it'd be a drop-in addition.

No, I haven't changed that interface, so hopefully it should work. Do you cross-compile, or do you have a Mac on which you compile it? If the former, I'd be very interested in how you do it so that I could set it up.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #19 on: December 22, 2011, 11:41:03 AM »
I'm currently developing it natively on the Mac using Xcode (it was a bit of a pain to get the Xcode project set up, but it compiles nicely now - there are a lot of errors trying to compile using Clang/LLVM so I stick to LLVM-GCC for now. Fixing those errors to get it to compile may be my next project).

Once I'm done I'll modify the Makefile so that it can be compiled without using Xcode (and then probably make a script which can build the Application bundle etc.)

Cross-compilation for Mac is something I haven't looked into yet, so can't help you there. It's a shame my mac mini is slightly too old to run OSX Lion since I could set this up as a Mac build server for Simutrans otherwise.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 14774
  • Total likes: 309
  • Helpful: 144
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Native Simutrans on OSX via Quartz
« Reply #20 on: December 22, 2011, 11:46:02 AM »
Thank you for that. How would somebody, like me, without access to a Mac go about having this compiled for Experimental once you have finished setting it up?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #21 on: December 22, 2011, 12:01:49 PM »
Well, since you'd want to be able to test it as well I'd say try and get ahold of a Mac :) It's also possible to virtualise OSX (although it's pretty hard to get working properly unless you're running VMWare Fusion/Parrallels on another Mac...) or to install it on non-Mac hardware (again, tricky to get it working nicely).

Or you could rent a VPS, e.g.: http://www.hostmyapple.com/macvps.html

Cross-compiling is only really an option for doing production builds of the finished product, since obviously without access to an actual Mac you wouldn't be able to test it.

Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 14774
  • Total likes: 309
  • Helpful: 144
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Native Simutrans on OSX via Quartz
« Reply #22 on: December 22, 2011, 12:17:47 PM »
Hmm - I don't have the physical space at home for another computer! Renting a VPS just to compile for Mac seems somewhat inefficient.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Bughu Baas

Re: Native Simutrans on OSX via Quartz
« Reply #23 on: December 22, 2011, 04:05:58 PM »
A Mac mini has the volume of a handful CDs, so space shouldn't be the problem. Well, the price is another topic, but you haven't asked... ;-) Also 2 port KVM switches are handy.

Offline sdog

Re: Native Simutrans on OSX via Quartz
« Reply #24 on: December 23, 2011, 04:56:44 AM »
@james, just wait and rely on FOSS. Once it works for standard, there will be desire by people having macs to have experimental on it too, chances aren't bad at least one of them will do it. If not, as soon as people start to pester you about doing it, a sollution should be found.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 14774
  • Total likes: 309
  • Helpful: 144
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Native Simutrans on OSX via Quartz
« Reply #25 on: December 23, 2011, 11:37:04 AM »
@james, just wait and rely on FOSS. Once it works for standard, there will be desire by people having macs to have experimental on it too, chances aren't bad at least one of them will do it. If not, as soon as people start to pester you about doing it, a sollution should be found.

There is much sense in this suggestion...
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #26 on: January 06, 2012, 12:09:37 AM »
I have put this on hold for a bit since I have to focus on studying at the moment. I'll come back to it though :)
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #27 on: February 17, 2012, 05:49:52 PM »
I'm working on this a bit again, I have mouse events working via an event queue. Keyboard events underway.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Markohs

  • DevTeam, Coder/patcher
  • Devotee
  • *
  • Posts: 1560
  • Total likes: 1
  • Helpful: 86
  • Languages: EN,ES,CAT
Re: Native Simutrans on OSX via Quartz
« Reply #28 on: February 17, 2012, 06:01:01 PM »
Keyboard will be the hard part I guess, I had a plan to implement it in OIS and the modifierkey and keycodes are not that easy to translate, quite a tedious work.

 I also used a queue for events, but are you sure simutrans asks for more than one event each frame? I browsed around and coudn't find it, but it might be related to my version having low framerrate and maybe the queue not being consumed fast enough.

 How do you implemented the queue, using STL or a simutrans type?

 Curious to see your code some day. :)

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #29 on: February 18, 2012, 09:37:24 AM »
Well the Mac may be kind of a special case, I'm running the Cocoa application in a different thread to the main game. The Cocoa wrapper simply draws the screen based on the contents of the frame buffer whenever needed (there's a lock to avoid modifying the buffer when drawing to screen). I plan on implementing double-buffering for performance too. The wrapper also handles events and places interesting ones onto a queue which Simutrans then reads the most recent one off whenever it asks for an event. The queue uses an NSMutableArray (this bit is Objective-C) and an NSCondition (essentially a lock) to ensure thread safety. This seemed the logical choice given that most of the additional code I've written is Objective-C.

AFAIK Simutrans can process more than one event per frame. There's also a blocking form of the GetEvents method to consider.

I'll post a patch once I have keyboard events working. Whenever I update the main Simutrans source to HEAD I have to spend some time fixing things :)


Edit: Quick update, I have screen resizing working mostly, it's a bit ugly though as I need to decide how to handle the interaction between the game thread and the UI thread in terms of buffering the display. Then it's just a case of plumbing the events and building a release version for testing :) I hope we have some mac players around...
« Last Edit: February 23, 2012, 12:29:29 AM by Timothy »
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #30 on: February 24, 2012, 12:35:48 AM »
Good progress today, fixed vsync issues and got the threads synchronised nicely. Screen resizing works, as does fullscreen mode on OSX Lion. I get a solid 25fps (ingame) and 4-5 simloops on a 1024x1024 map at the first three zoom levels. I think that's pretty good performance and it's the game rather than Quartz being the limiting factor there. That's at the native resolution on my macbook air of 1440x900 (1.7Ghz Core i5, 4GB RAM).

Comparing to the SDL mac version on performance alone this looks to be better, though I'll have to do more extensive testing.

I still need to plumb in keyboard events and make it quit cleanly, but after that's done I will post an app bundle for testing.

Gratuitous screenshot attached!

Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2446
  • Total likes: 223
  • Helpful: 86
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Native Simutrans on OSX via Quartz
« Reply #31 on: February 25, 2012, 03:55:00 AM »
It's looking perfect, too much things in the todo list Timolthy?

And by the way, can you emulate it on the iPhone screen? Just to check how big the graphics and buttons appear. It might help think about how to scale the buttons and dialogs.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #32 on: March 04, 2012, 01:14:56 AM »
Finally had a chance to do keyboard events, so here is a mostly working app. I think I'm going to have to overhaul event handling a bit to add support for touch events. Most things should work however. I think that this package will only work on OSX 10.7 (Lion). It incorporates pak64. If anything doesn't work let me know :)

http://entropy.me.uk/simutrans/simutrans.dmg
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline Ashley

Re: Native Simutrans on OSX via Quartz
« Reply #33 on: March 08, 2012, 11:27:41 PM »
Any feedback on this? Has anyone been able to test it/get it running?
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Offline alexbaettig

Re: Native Simutrans on OSX via Quartz
« Reply #34 on: March 09, 2012, 07:20:50 AM »
It did work for me. Even got an other pak installed (pak.Britain). Next I'm going to shut the music off… I completely forgot how terrible it was…