News:

The Forum Rules and Guidelines
Our forum has Rules and Guidelines. Please, be kind and read them ;).

Native Simutrans on OSX via Quartz

Started by Ashley, December 15, 2011, 03:02:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ashley

Quote from: Timothy on March 22, 2012, 12:17:37 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
Quote from: Timothy on July 03, 2012, 04:38:59 PM
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...)

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.

Isaac Eiland-Hall

What? Colourspace looks fine to me. hehehe

mEGa

Is it a 3D adaptation screen? need of adapted glasses ? LOL
Current projects in progress : improvements of few designed french paks

Ashley

Quote from: Isaac.Eiland-Hall on December 15, 2011, 03:50:32 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.

Ashley

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.

Dwachs

#5
Quote from: Timothy 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?
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 ???
Parsley, sage, rosemary, and maggikraut.

VS


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!

Ashley

Ah ok, e.g. in simsys_w.cc you see:


/**
* 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.:


/* 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.

prissi

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.

Ashley



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.

Isaac Eiland-Hall

WOAH THAT LOOK HORRIBLE WAT DID YOU DO TO THE COLOURS?!?!

hehe.

Nicely done. :D

Ashley

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.

prissi

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.

Ashley

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.

prissi

simevent remembers the last state; But it is reset every time a new event arrives. Thus maybe just save your last state too.

jamespetts

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.

prissi

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.

Ashley

Quote from: jamespetts on December 22, 2011, 01:34:36 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.

jamespetts

Quote from: Timothy on December 22, 2011, 11:18:06 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.

Ashley

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.

jamespetts

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.

Ashley

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.

jamespetts

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.

Bughu Baas

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.

sdog

@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.

jamespetts

Quote from: sdog 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.

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.

Ashley

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.

Ashley

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.

Markohs

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. :)

Ashley

#29
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...
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.

Ashley

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.

An_dz

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.

Ashley

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.

Ashley

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.

alexbaettig

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...