Title: iPort
1(No Transcript)
2iPort
- How to Bring Any C Game to the iPhone
Mike Smith - mike_at_elecorn.com
Spencer Nielsen - snielsen_at_aorensoftware.com
3Background
4iPhone Porting Process Preview
- PC Side
- Get your game running on a low end PC.
- Refactor create abstraction layers.
- Swap Rendering to OpenGL ES.
- Provide an "iPhone Mode" for PC.Â
5iPhone Porting Process Preview
- iPhone Side
- Get something up and running in the simulator.
- Get that same something up and running on the
iPhone Device. - Convert Assets.
- Swap UI handling to work with touch events.
- Swap the Audio Engine.
- Add additional iPhone specific goodness.
6PC vs. iPhone
"I own this desk"
"Really, I'm stronger than I look!"
7iPhone OSÂ Hardware
480 X 320 Display Wi-fi, Accelorometer Bluetooth,
speaker (except for 1st gen touch) Cell network,
camera (only on the phones) GPS (only on 3G
phones)
- 1st Gen Hardware
- 412-533 Mhz ARM11
- PowerVR MBX Lite
- 128 MB (40 usable)
- 4 - 32 GB
2nd Gen Hardware 600 Mhz Cortex-A8 PowerVR
SGX 256 MB (100 usable) 16 - 64 GB Digital
Compass
8Get Your Game Running on a Low End PC
- Fix this now
- High end pixel and shaders
- Multi threading
- Third Party Libraries and DLLs
- Â
- Save for laterÂ
- Â
- Physics
- AI
- Content?
9Create Abstraction Layers
- glBindTexture(GL_TEXTURE_2D, texture)
- vs.
- Â
- jrSetTexture2D(texture)
jrSetTexture2D(unsigned int texture) if
USE_OPENGL Â Â Â Â glBindTexture(GL_TEXTURE_2D,
texture) Â elif USE_DIRECTX Â Â Â Â SetTexture(0,
texture) endif
10Yes?     No?
11ifdef Messiness
- ifdef WIN32
- Â Â Â ... do this.
- Â
- elif __MACOSX__
- Â Â Â ... do mostly this but some of that
- Â
- elif __IPHONEOS__
- Â Â Â ... do mostly that
- elif __LINUX__
- Â Â Â ... do nothing like that.
- else
- Â Â Â ... do throw an error.
- Â
- endif
12Porting the Graphics Engine
- "If you want to really impress me, let's see you
pull that off in fixed function."
13iPhone Mode on Your PC
- "Look at me! I'm an iPhone now!"
"What?..."
14iPhone Mode on Your PC
 define BIG_SIMPLE_UI 1 define
USE_SHORT_CLIP 1Â define USE_IMMEDIATE_MODE 0Â
define USE_WAVE_IN_FRONT_END 0Â define
DO_FOV_BOOST 0Â define ALLOW_1BIT_ALPHA 1Â
define DO_TERRAIN_GLOW 0Â define
DO_SCREEN_DISTORTION_EFFECTS 0Â define
DO_HIGH_RES_TRAILS 0Â define USE_FRAME_BUFFER_FO
R_RENDER_TARGETS 1Â define DO_HACKER_CHECK 0Â
define USE_REDUCED_VERTEX 1Â define
DO_REFLECTIONS 0Â define ADD_BYTE_COLOR 1Â
define WINDOWED_MODE_SUPPORTED 0Â define
SLOW_ALPHA_BLEND 1Â define MAX_PHYSICS_STEP_SIZE
(1.0f/60.0f)Â define USE_WATER_FOG 0Â define
SKIP_ANIM 1
15Compiling Code For iPhone
- iphone-glu (iGLU) http//code.google.com/p/iphone
-glu/ - Â
- SDL 1.3 trunk http//svn.libsdl.org/trunk/SDL
16Xcode File Interpretation
17It works! Kinda...
18Open GL Landscape Mode
CGRect bounds UIScreen mainScreen
bounds  UIWindow window UIWindow alloc
initWithFramebounds  MyCustomEAGLView
mainView MyCustomEAGLView alloc
initWithFrameCGRectMake(0.0, 0.0,
bounds.size.height, bounds.size.width) CGAffineT
ransform rotate CGAffineTransformMakeRotation(M_
PI_2) mainView setTransformrotate  mainView
.center CGPointMake( mainView.frame.size.width/2
, mainView.frame.size.height/2 ) window
addSubviewmainView
19Fat Static Libraries
lipo -create \ BUILD_DIR/CONFIGURATION-iphonesim
ulator/libMyProduct.a \Â BUILD_DIR/CONFIGURATION
-iphoneos/libMyProduct.a \ -output
libMyProduct.a lipo -info libMyProduct.a Archite
ctures in the fat file libMyProduct.a are i386
armv6Â
20Simulator vs. Device
The Simulator is NOT an Emulator. What does this
mean to me?
21Useful Tidbits
- -fno-regmove
- Â
- Xcode iPhone / Mac OS X targets cannot share the
same project file.
22Optimization
23Asset Conversion
24Asset Conversion Tools
- oggdec - Convert ogg to wav
- afconvert - Convert wav files to caf
- sips - Resample images and convert image formats
- texturetool - Convert images to PVRTC format
- Custom tools, offline computing
25The Art of Optimizing Art
- Down sample vs. PVRTC - Fault tolerant PVRTC
loader - Â
- 3D Animation updates - Skinned vs. interpolated
vs. static - Â
- Draw distance
- Â
- Foliage / prop density
- Â
- Lower LOD pulled closer in
- Money where it matters
26Xcode Asset Management
Add file references and use "Copy Files" phase to
bypass the standard Xcode "Copy Bundle Resources"
phase.
27User Interface
28Text Input
29Useful UI Tidbits
- Double Tap issues in OS lt 3.0.
- Â
- Prompt Processing of input messages.
30Audio and Video
- Use AVAudioPlayer for music
- Â
- Use OpenAL for game sounds
- One sound source per instance.
- oalTouch sample code.
- Â
- Use MPMoviePlayerController for videos.
31Pay Attention to UIApplication Delegate Messages
32iPhone OS
- Performance inconsistency
- Easy to update applications
33App Store URLs
NSString appURL NSString stringWithContentsOfU
RLNSURL URLWithString_at_"http//www.casterthegame
.com/iPhoneLiteRedirect" Â appURL appURL
stringByTrimmingCharactersInSetNSCharacterSet
newlineCharacterSet if( !appURL ) appURL
_at_"http//www.casterthegame.com/"
UIApplication sharedApplication
openURLNSURL URLWithStringappURL
34Hardware Detection
size_t size  sysctlbyname("hw.machine", NULL,
size, NULL, 0) Â Â char machine
(char)malloc(size) Â Â sysctlbyname("hw.machine"
, machine, size, NULL, 0) Â
"iPhone1,1" Â Â Â Â Â - iPhone "iPhone1,2" Â Â Â Â Â -
iPhone 3G "iPhone2,1" Â Â Â Â Â - iPhone
3GS "iPod1,1" Â Â Â Â Â Â Â - iPod Touch "iPod2,1" Â Â
      - iPod Touch (2nd gen) "iPod3,1"     Â
   - iPod Touch (3rd gen)
35Pirated Game Experience
36Initial Crack Detection
- - (BOOL) isAppCracked return (NSBundle
mainBundle infoDictionary objectForKey_at_"SignerI
dentity" ! nil)
37Your Turn to Share