 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Kojima
Joined: 26 Jun 2006 Posts: 275
|
Posted: Mon Aug 28, 2006 12:11 am Post subject: Writing for multiple platforms? |
|
|
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: |
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.) |
|
| Back to top |
|
 |
stinos
Joined: 17 Oct 2005 Posts: 12
|
Posted: Mon Aug 28, 2006 2:12 am Post subject: |
|
|
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: |
#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: |
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[ 24 ]; //!< 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 (const CriticalSection&);
const CriticalSection& operator= (const CriticalSection&);
};
|
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 []-] |
|
| Back to top |
|
 |
Kojima
Joined: 26 Jun 2006 Posts: 275
|
Posted: Mon Aug 28, 2006 5:19 am Post subject: |
|
|
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) |
|
| Back to top |
|
 |
SamuraiX
Joined: 31 Jan 2006 Posts: 76 Location: USA
|
Posted: Mon Aug 28, 2006 8:37 am Post subject: |
|
|
To your previous question I tend to use..
| Code: |
#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(PSP)
// 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. |
|
| Back to top |
|
 |
Aion
Joined: 24 Jul 2006 Posts: 40 Location: Montreal
|
Posted: Mon Aug 28, 2006 11:02 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Kojima
Joined: 26 Jun 2006 Posts: 275
|
Posted: Tue Aug 29, 2006 3:39 am Post subject: |
|
|
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) |
|
| Back to top |
|
 |
onne
Joined: 29 Aug 2006 Posts: 24
|
Posted: Wed Aug 30, 2006 5:19 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|