Skip to main content
gamedev.net
🔒 Locked

Platform Independant Coding

Started by gimp 2 replies 250+ views
Original Post
gimp
gimp
I''m writing the platform independant base for my game and want to get it right the first time. (ie I don''t want to be one of thise guys writing a what not to do postmortum Besides core functionality like threading and syncronization, timers, input, sound, networking and graphics are there any special consideration I''m likely to have to deal with? For example I recall discussion at a previous employer regarding the difficulties in netowek transmission between Alpha''s and Vax''s due to the byte ordering of the data. (big vs little endianness). Since my target platforms for example are linux, win32 and beos... and all hopefully based on intel like architectures I won''t have to deal with this problem. I think... Is there anything else I should know? Perhaps tutorials on issues to be aware of when attempting something like this? As a side note, are there any open source games around that support these operating systems... just so I can look at how some things are handled in non Win32 environments. Thanks again gimp
Chris Brodie
RWarden
RWarden
You may want to define all of your own data types, especially integer data types. It''ll be a godawful mess if you try and use WORD and DWORD on different platforms, and even other things such as the size of an int can change (especially with 64-bit systems on the way). I usually define a core set of integer types: int8, int16, int32, uint8, uint16, uint32.
The other thing to watch for is compiler-specific things. There''s a lot of convenient stuff in Visual C++ that you have to forego when you''re making something cross-platform.

Big vs. little endian is very simple. In a 32 bit value there are 4 bytes. In a big endian system these four bytes are read just like you''d write it. For example, 1 in big endian hexadecimal would be:
00 00 00 01

A little endian system reads the bytes in the opposite order. 1 in little endian hex is:
01 00 00 00

This comes into play for network transmissions and loading data from files. The easiest way to get around potential problems is to read all data byte-by-byte and write your own functions to combine the bytes together in the right way.

I''m pretty sure Win32 uses little endian and I think Macs use big endian. I have no idea about other OSs. Good luck..

- RWarden (roberte@maui.net)
gimp
gimp
I was thinking about create a DLL for each operating system which will export the local flavor of the bits of the operating system I care about. Right now thats only threads, mutex''s and high performance timers.

Eventhough I have to recompile on each operating system the fact that mt core body of code contains nothing platform specific I think might be a reasonable goal.

Is this a reasonable goal or is there a flaw in my logic that makes this a waste of time?

thanks

gimp
Chris Brodie
Muzzafarath
Muzzafarath
>> I was thinking about create a DLL for each operating system which will export the local flavor of the bits of the operating system I care about. Right now thats only threads, mutex''s and high performance timers. <<

Do BeOS and Linux support DLLs?

- Muzzafarath

Mad House Software
The Field Marshals
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.