Welcome, Guest. Please login or register.

Author Topic: Any way to speed up OpenTTD on OS3.X?  (Read 3092 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Any way to speed up OpenTTD on OS3.X?
« on: February 24, 2007, 09:23:35 PM »
One thing I always hated about SDL, the implementation quality varies so much.

I did some testing (admittedly some time ago now) with a WarpOS version and it causes a context switch orgy on basic things such as frame buffer flips and event handling.

There's no excuse for this, really. It's perfectly possible to code manual switches from PPC -> 68K and do all the basic OS calls 68K native (inclusive of gathering IDCMP event data into a small, shared bufffer for the PPC to act upon after returning) and then returning control to the PPC. I've written code that does this and you can get it down to one full context switch per frame and that's with PPC native event handling callbacks too.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Any way to speed up OpenTTD on OS3.X?
« Reply #1 on: February 25, 2007, 11:07:23 AM »
If I still had a working PPC classic and a job that didn't consume all my time these days, I might look into it.

-edit-

That said, the strategy for solving problems like this is as I already said.

Never call multiple 68K native OS functions directly from the PPC in time critical sections. Always, and I mean always, write a 68K "entry" function that can then call your OS functions before returning and have the PPC call this.

The solution I used had a Context structure. This contained the Screen, ScreenBuffer and Window pointers, it also contained a small Event buffer (implemented as an array of Event structures). These Event structures contained a type field and a bunch of unions the meanings of which depended on the type. The Context structure also contains several function pointers that act as callback handlers for events.

A PPC native function "update(struct Context*)" would take a Context instance and then pass it to a 68K function via Warpos/Run68K().

This 68K function would then flip the ScreenBuffers and then process the IDCMP events from the Window's IDCMP port using a standard GetMsg() based loop. Processing these events simply involved decoding them and filling up values in the Context's Event array.

Unless you are really unlucky, you'd never fill this buffer between frames though it is an obvious design flaw that it couldn't really hold more than 64 events per frame. Any more than that would end up waiting to be processed in the next frame. However, in practise I rarely managed to get more than four of five between frames even when blitzing the mouse ;-)

Once this was completed, the 68K function would return back to the PPC.

Before completing, the PPC would then step through the events that were received, calling the Context's appropriate callback functions for each event.

The upshot of all this is that you basically got 1 full PPC->68K->PPC round switch when flipping the screen buffer and retrieving the input.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Any way to speed up OpenTTD on OS3.X?
« Reply #2 on: February 25, 2007, 05:29:19 PM »
@Itix

Understood, but somewhere in the implementation of SDL you should be able to realise this particular type of switch-optimizing solution. The user of the SDL library doesn't necessarily need to be aware of any of this.
int p; // A