Writing for multiple platforms?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Writing for multiple platforms?

Post by Kojima »

I'm just wondering, how easy would it be to have a project compile simultaniously (Either through one or two make calls) for both psp and pc?

The codebase, is farly platform indepedent. Using glut to create the psp window, so to get to run on the pc i just need to write some input code probably using sdl. But what are my best options for a multi-system codebase? Should I write a system abstraction layer class, or just rely on IFDEFs etc.

Also, can I do this anyway?

Code: Select all

ifndef CPP_PSP
'psp initialization code
endif

ifndef WINDOWS
'windows code
endif
I know the windows one exist, i've seen it used to define windows lean and mean. (But please do tell me how it's worded exactly, I'm not sure)
but what about the psp equilivent?
Or should I simply finish the psp side of my game, then port it manually to pc?(I'd rather have something dynaminc, since it'll be nice to be able to debug on the pc version non psp specifc bugs.)
stinos
Posts: 12
Joined: Mon Oct 17, 2005 7:36 am

Post by stinos »

atm i'm writing code simultaneously for windows, mac, linux, psp and the ti c6xx platforms.
basically i use a global platfrom definition file for general stuff, which contains things like this:

Code: Select all

#ifdef WIN32
#define S_WIN32 1
#elif defined LINUX
#define S_LINUX 1
#elif defined MAC
#define S_MAC 1
#elif defined C6X
#define S_C6X 1
#elif defined DAVINCI
#define S_DAVINCI 1
#elif defined PSP
#define S_PSP 1
#else
#ERROR !no platform defined!
#endif

  #ifdef S_DEBUG

      /**
        * Output debug string.
        * @see Tracer::sf_TraceDebug()
        */ 
    #define DBG( text ) utils::Tracer::sf_TraceDebug( text );
    
      /**
        * Output debug string, printf style.
        * @see Tracer::sf_TraceDebugPrintf()
        */ 
    #define DBGPF( format, args ) utils::Tracer::sf_TraceDebugPrintf( format, args );

      //assert
    #if defined S_WIN32
      #define s_assertf   { __asm int 3 }
    #elif defined S_LINUX
        //ok here's something stupid: when using single stepping
        //using gdb, it will just step over the s_assert and
        //ignore the SIGTRAP raised.
        //It won't ignore it however if running, or if stepping
        //over a function that contains the assert inside.
        //Keep this in mind when debugging!
      #define s_assertf  { asm("int $3"); }
    #elif defined S_MAC
      #define s_assertf  Debugger();
    #elif defined S_C6X
      #define s_assertf { asm("int 3") }
    #elif defined S_PSP
      #define s_assertf { asm("int 3"); }
    #endif

      /**
        * Platform-independent assertion.
        * Gets optimized away in release builds.
        */
    #define s_assert( expr ) { if( !( expr ) ) s_assertf }

  #else
then i write interfaces for all things that are really platform specific: threads, criticalsections, waitable objects, sockets, basic ui stuff... and implement these for every platform.
eg the criticalsection interface looks like this:

Code: Select all

class CriticalSection
  {
  public:
      /**
        * Constructor.
        */
    CriticalSection();

      /**
        * Destructor.
        */
    ~CriticalSection();

      /**
        * Enters the CriticalSection.
        * If another thread has entered before, the method
        * blocks until that thread leaves it again.
        * Else the method returns immedeately.
        */
    void mf_Enter() const;

      /**
        * Trie to enter the CriticalSection.immedeately.
        * If another thread has entered before, the method
        * returns false and doe not enter, else it returns true
        * after entering.
        * @return false if the CriticalSection isn't free
        */
    bool mf_bTryEnter() const;

      /**
        * Leave the CriticalSection.
        * Make sure not to call this on a CriticalSection that
        * has not been entered.
        */
    void mf_Leave() const;

  private:
  #if defined S_WIN32
    char m_hMutex&#91; 24 &#93;;     //!< aka win32 CriticalSection
  #elif defined S_C6X
    LCK_Handle m_hMutex;
  #elif defined S_LINUX
    mutable pthread_mutex_t m_hMutex;
  #elif defined S_PSP
    SceUID m_hMutex;
  #endif

    CriticalSection &#40;const CriticalSection&&#41;;
    const CriticalSection& operator= &#40;const CriticalSection&&#41;;
  &#125;;
all methods are then implemented in psp_criticalsection.cpp/win32_criticalsection.cpp etc, so while building i just have to include the right file while compiling

the rest of the code uses the interfaces only, so all application code is completely platform independent.
i don't use fancy uis mostly, except on pc maybe and then i use qt which is pretty cross-platform, but opengl should do it too.
it's a *lot* of work, takes an equal lot of testing, but the pc/dsp part i have to code for my job anyway so i have the time..
once the code is there it's a dream to use: i first write it in my favorite ide on pc, test it for mem leaks etc, and when it works, i just use it on the platform i want, and i know it will work there too without surprises

hopefully this is a bit of interest for you, i'm not really allowed to post this code []-]
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

Yes, very interesting, thanks.

What would you reccomend for cross platform mouse/keyboard input btw? Know of a lib thats cross-platform across mac/linux/win? (only look for mouse/keyboard input, not joypad)
SamuraiX
Posts: 76
Joined: Tue Jan 31, 2006 6:28 am
Location: USA
Contact:

Post by SamuraiX »

To your previous question I tend to use..

Code: Select all

#if PSP || DOS
    // Code for PSP or DOS
#else
    // Code for All platforms but not PSP & DOS
#endif

#if PSP || SDL || DC
     // Code for PSP or SDL or DC
#if !defined&#40;PSP&#41;
     // Code only used in DC or SDL
#endif
     // Code for PSP or SDL or DC
#endif
and make sure you CFLAGS has the option set for that specific platform -DPSP

Your second question...
Kojima wrote:What would you reccomend for cross platform mouse/keyboard input btw? Know of a lib thats cross-platform across mac/linux/win? (only look for mouse/keyboard input, not joypad)
OpenBoR for example is supported in DOS, SDL, DC and PSP. Each one of them have there unique code to support controllers, but they all use the same naming convention for there respective functions in the main engine.
Aion
Posts: 40
Joined: Mon Jul 24, 2006 10:58 pm
Location: Montreal

Post by Aion »

The project I'm currently working on ( Psp Kanji :http://sourceforge.net/projects/pspkanji/ ) compile on both Psp and Windows/DirectX.

I just have the lower part of the code be platform specific but they all use the same interface. For example I have 2 class CPolygon, but implementation of them is different for DirectX/Psp. For the input, again I have a InputManager that just implement differently Psp/DirectX but use exactly the same interface.

In the end I do almost all of my debuging in Windows then test it on the Psp.

Could show you my code if interested.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

I was too eager to see the game running on a pc, so I hard coded a port of raptor etc using vc2005 express and it works fine now. runs about 50x slower than the psp though, which is odd seeing as i have a g5. Just reinstalling my gfx drivers to be sure i did install them when i re-installed windows.

But your suggestions have all been good, and once I do port raptor to windows properly it is what I will use. For now I'm just focusing on getting the game running, and may even drop the psp version.(It's a footy manager game so not really suited to a psp anyway)
onne
Posts: 24
Joined: Tue Aug 29, 2006 11:54 pm

Post by onne »

Kojima,
about the slowness on vc2005... I guess you _did_:
1. set you project to 'Release'
2.Project Settings \ ConfigurationProperties \ C/C++ \ Optimization: Optimization - Maximize Speed(/O2)

I was once also wondering about the slooow performance, until I saw I was running it in debug mode. eh.
Post Reply