The DOOM Classic for iPhone 1.0 source as released on November 3, 2009
This commit is contained in:
commit
0cdbbdf96e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* doomiphone.h
|
||||
* doom
|
||||
*
|
||||
* Created by John Carmack on 3/13/09.
|
||||
* Copyright 2009 idSoftware. All rights reserved.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
|
||||
Copyright (C) 2009 Id Software, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <setjmp.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include <dlfcn.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include <OpenGLES/ES1/gl.h>
|
||||
#include <OpenGLES/ES1/glext.h>
|
||||
#include "iphone/gles_glue.h"
|
||||
|
||||
#include <OpenAL/al.h>
|
||||
#include <OpenAL/alc.h>
|
||||
#include <OpenAL/oalStaticBufferExtension.h>
|
||||
#undef ALCAPI
|
||||
#define ALCAPI
|
||||
|
||||
#undef false
|
||||
#undef true
|
||||
|
||||
#include "prboom/SDL_opengl.h"
|
||||
|
||||
// prBoom code
|
||||
#include "prboom/m_fixed.h"
|
||||
#include "prboom/doomdef.h"
|
||||
#include "prboom/doomtype.h"
|
||||
#include "prboom/doomstat.h"
|
||||
#include "prboom/d_net.h"
|
||||
#include "prboom/dstrings.h"
|
||||
#include "prboom/sounds.h"
|
||||
#include "prboom/z_zone.h"
|
||||
#include "prboom/w_wad.h"
|
||||
#include "prboom/s_sound.h"
|
||||
#include "prboom/v_video.h"
|
||||
#include "prboom/f_finale.h"
|
||||
#include "prboom/f_wipe.h"
|
||||
#include "prboom/m_argv.h"
|
||||
#include "prboom/m_misc.h"
|
||||
#include "prboom/m_menu.h"
|
||||
#include "prboom/p_checksum.h"
|
||||
#include "prboom/i_main.h"
|
||||
#include "prboom/i_system.h"
|
||||
#include "prboom/i_sound.h"
|
||||
#include "prboom/i_video.h"
|
||||
#include "prboom/g_game.h"
|
||||
#include "prboom/hu_stuff.h"
|
||||
#include "prboom/wi_stuff.h"
|
||||
#include "prboom/st_stuff.h"
|
||||
#include "prboom/am_map.h"
|
||||
#include "prboom/p_setup.h"
|
||||
#include "prboom/r_draw.h"
|
||||
#include "prboom/r_main.h"
|
||||
#include "prboom/r_fps.h"
|
||||
#include "prboom/d_main.h"
|
||||
#include "prboom/d_deh.h"
|
||||
#include "prboom/lprintf.h"
|
||||
#include "prboom/am_map.h"
|
||||
#include "prboom/gl_intern.h"
|
||||
#include "prboom/p_mobj.h"
|
||||
#include "prboom/p_maputl.h"
|
||||
#include "prboom/p_map.h"
|
||||
// open / close name collision problem... #include "prboom/p_spec.h"
|
||||
#include "prboom/p_inter.h"
|
||||
#include "prboom/m_random.h"
|
||||
#include "prboom/m_bbox.h"
|
||||
#include "prboom/m_cheat.h"
|
||||
|
||||
// we will now define landscapeViewport / landscapeScissor to rotate the coords
|
||||
#undef glViewport
|
||||
#undef glScissor
|
||||
|
||||
// our vestigial system environment
|
||||
#include "iphone/misc.h"
|
||||
#include "iphone/cvar.h"
|
||||
|
||||
// new iphone code
|
||||
#include "iphone/ipak.h"
|
||||
#include "iphone/iphone_doom.h"
|
||||
#include "iphone/iphone_email.h" //gsh, adds support for emailing the console to id
|
||||
|
Binary file not shown.
|
@ -0,0 +1,539 @@
|
|||
/*
|
||||
* BackgroundMusic.cpp
|
||||
* doom
|
||||
*
|
||||
* Created by John Carmack on 5/15/09.
|
||||
* Copyright 2009 Id Software. All rights reserved.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
// Includes
|
||||
//==================================================================================================
|
||||
|
||||
// System Includes
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
#include <CoreFoundation/CFURL.h>
|
||||
#include <OpenAL/al.h>
|
||||
#include <OpenAL/alc.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <pthread.h>
|
||||
#include <mach/mach.h>
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include "doomiphone.h"
|
||||
}
|
||||
|
||||
enum {
|
||||
kSoundEngineErrUnitialized = 1,
|
||||
kSoundEngineErrInvalidID = 2,
|
||||
kSoundEngineErrFileNotFound = 3,
|
||||
kSoundEngineErrInvalidFileFormat = 4,
|
||||
kSoundEngineErrDeviceNotFound = 5
|
||||
};
|
||||
|
||||
|
||||
#define AssertNoError(inMessage, inHandler) \
|
||||
if(result != noErr) \
|
||||
{ \
|
||||
printf("%s: %d\n", inMessage, (int)result); \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
|
||||
#define kNumberBuffers 3
|
||||
|
||||
|
||||
static Float32 gMasterVolumeGain = 0.5f;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
// Helper functions
|
||||
//==================================================================================================
|
||||
|
||||
OSStatus LoadFileDataInfo(const char *inFilePath, AudioFileID &outAFID, AudioStreamBasicDescription &outFormat, UInt64 &outDataSize)
|
||||
{
|
||||
UInt32 thePropSize;
|
||||
|
||||
CFURLRef theURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8*)inFilePath, strlen(inFilePath), false);
|
||||
if (theURL == NULL)
|
||||
return kSoundEngineErrFileNotFound;
|
||||
|
||||
OSStatus result = AudioFileOpenURL(theURL, kAudioFileReadPermission, 0, &outAFID);
|
||||
CFRelease(theURL);
|
||||
AssertNoError("Error opening file", end);
|
||||
|
||||
thePropSize = sizeof(outFormat);
|
||||
result = AudioFileGetProperty(outAFID, kAudioFilePropertyDataFormat, &thePropSize, &outFormat);
|
||||
AssertNoError("Error getting file format", end);
|
||||
|
||||
thePropSize = sizeof(UInt64);
|
||||
result = AudioFileGetProperty(outAFID, kAudioFilePropertyAudioDataByteCount, &thePropSize, &outDataSize);
|
||||
AssertNoError("Error getting file data size", end);
|
||||
|
||||
end:
|
||||
return result;
|
||||
}
|
||||
|
||||
void CalculateBytesForTime (AudioStreamBasicDescription & inDesc, UInt32 inMaxPacketSize, Float64 inSeconds, UInt32 *outBufferSize, UInt32 *outNumPackets)
|
||||
{
|
||||
static const UInt32 maxBufferSize = 0x10000; // limit size to 64K
|
||||
static const UInt32 minBufferSize = 0x4000; // limit size to 16K
|
||||
|
||||
if (inDesc.mFramesPerPacket) {
|
||||
Float64 numPacketsForTime = inDesc.mSampleRate / inDesc.mFramesPerPacket * inSeconds;
|
||||
*outBufferSize = (long unsigned int)numPacketsForTime * inMaxPacketSize;
|
||||
} else {
|
||||
// if frames per packet is zero, then the codec has no predictable packet == time
|
||||
// so we can't tailor this (we don't know how many Packets represent a time period
|
||||
// we'll just return a default buffer size
|
||||
*outBufferSize = maxBufferSize > inMaxPacketSize ? maxBufferSize : inMaxPacketSize;
|
||||
}
|
||||
|
||||
// we're going to limit our size to our default
|
||||
if (*outBufferSize > maxBufferSize && *outBufferSize > inMaxPacketSize)
|
||||
*outBufferSize = maxBufferSize;
|
||||
else {
|
||||
// also make sure we're not too small - we don't want to go the disk for too small chunks
|
||||
if (*outBufferSize < minBufferSize)
|
||||
*outBufferSize = minBufferSize;
|
||||
}
|
||||
*outNumPackets = *outBufferSize / inMaxPacketSize;
|
||||
}
|
||||
|
||||
static Boolean MatchFormatFlags(const AudioStreamBasicDescription& x, const AudioStreamBasicDescription& y)
|
||||
{
|
||||
UInt32 xFlags = x.mFormatFlags;
|
||||
UInt32 yFlags = y.mFormatFlags;
|
||||
|
||||
// match wildcards
|
||||
if (x.mFormatID == 0 || y.mFormatID == 0 || xFlags == 0 || yFlags == 0)
|
||||
return true;
|
||||
|
||||
if (x.mFormatID == kAudioFormatLinearPCM)
|
||||
{
|
||||
// knock off the all clear flag
|
||||
xFlags = xFlags & ~kAudioFormatFlagsAreAllClear;
|
||||
yFlags = yFlags & ~kAudioFormatFlagsAreAllClear;
|
||||
|
||||
// if both kAudioFormatFlagIsPacked bits are set, then we don't care about the kAudioFormatFlagIsAlignedHigh bit.
|
||||
if (xFlags & yFlags & kAudioFormatFlagIsPacked) {
|
||||
xFlags = xFlags & ~kAudioFormatFlagIsAlignedHigh;
|
||||
yFlags = yFlags & ~kAudioFormatFlagIsAlignedHigh;
|
||||
}
|
||||
|
||||
// if both kAudioFormatFlagIsFloat bits are set, then we don't care about the kAudioFormatFlagIsSignedInteger bit.
|
||||
if (xFlags & yFlags & kAudioFormatFlagIsFloat) {
|
||||
xFlags = xFlags & ~kAudioFormatFlagIsSignedInteger;
|
||||
yFlags = yFlags & ~kAudioFormatFlagIsSignedInteger;
|
||||
}
|
||||
|
||||
// if the bit depth is 8 bits or less and the format is packed, we don't care about endianness
|
||||
if((x.mBitsPerChannel <= 8) && ((xFlags & kAudioFormatFlagIsPacked) == kAudioFormatFlagIsPacked))
|
||||
{
|
||||
xFlags = xFlags & ~kAudioFormatFlagIsBigEndian;
|
||||
}
|
||||
if((y.mBitsPerChannel <= 8) && ((yFlags & kAudioFormatFlagIsPacked) == kAudioFormatFlagIsPacked))
|
||||
{
|
||||
yFlags = yFlags & ~kAudioFormatFlagIsBigEndian;
|
||||
}
|
||||
|
||||
// if the number of channels is 0 or 1, we don't care about non-interleavedness
|
||||
if (x.mChannelsPerFrame <= 1 && y.mChannelsPerFrame <= 1) {
|
||||
xFlags &= ~kLinearPCMFormatFlagIsNonInterleaved;
|
||||
yFlags &= ~kLinearPCMFormatFlagIsNonInterleaved;
|
||||
}
|
||||
}
|
||||
return xFlags == yFlags;
|
||||
}
|
||||
|
||||
Boolean FormatIsEqual(AudioStreamBasicDescription x, AudioStreamBasicDescription y)
|
||||
{
|
||||
// the semantics for equality are:
|
||||
// 1) Values must match exactly
|
||||
// 2) wildcard's are ignored in the comparison
|
||||
|
||||
#define MATCH(name) ((x.name) == 0 || (y.name) == 0 || (x.name) == (y.name))
|
||||
|
||||
return
|
||||
((x.mSampleRate==0.) || (y.mSampleRate==0.) || (x.mSampleRate==y.mSampleRate))
|
||||
&& MATCH(mFormatID)
|
||||
&& MatchFormatFlags(x, y)
|
||||
&& MATCH(mBytesPerPacket)
|
||||
&& MATCH(mFramesPerPacket)
|
||||
&& MATCH(mBytesPerFrame)
|
||||
&& MATCH(mChannelsPerFrame)
|
||||
&& MATCH(mBitsPerChannel) ;
|
||||
}
|
||||
|
||||
#pragma mark ***** BackgroundTrackMgr *****
|
||||
//==================================================================================================
|
||||
// BackgroundTrackMgr class
|
||||
//==================================================================================================
|
||||
typedef struct BG_FileInfo {
|
||||
std::string mFilePath;
|
||||
AudioFileID mAFID;
|
||||
AudioStreamBasicDescription mFileFormat;
|
||||
UInt64 mFileDataSize;
|
||||
//UInt64 mFileNumPackets; // this is only used if loading file to memory
|
||||
Boolean mLoadAtOnce;
|
||||
Boolean mFileDataInQueue;
|
||||
} BackgroundMusicFileInfo;
|
||||
|
||||
class BackgroundTrackMgr
|
||||
{
|
||||
public:
|
||||
BackgroundTrackMgr();
|
||||
~BackgroundTrackMgr();
|
||||
|
||||
void Teardown();
|
||||
|
||||
static void QueueCallback( void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer);
|
||||
|
||||
OSStatus SetupQueue(BG_FileInfo *inFileInfo);
|
||||
OSStatus SetupBuffers(BG_FileInfo *inFileInfo);
|
||||
OSStatus LoadTrack(const char* inFilePath, Boolean inAddToQueue, Boolean inLoadAtOnce);
|
||||
|
||||
OSStatus SetVolume(Float32 inVolume);
|
||||
Float32 GetVolume() const;
|
||||
|
||||
OSStatus Start();
|
||||
OSStatus Stop(Boolean inStopAtEnd);
|
||||
|
||||
AudioQueueRef mQueue;
|
||||
AudioQueueBufferRef mBuffers[kNumberBuffers];
|
||||
UInt32 mBufferByteSize;
|
||||
SInt64 mCurrentPacket;
|
||||
UInt32 mNumPacketsToRead;
|
||||
Float32 mVolume;
|
||||
AudioStreamPacketDescription * mPacketDescs;
|
||||
static BG_FileInfo * CurFileInfo;
|
||||
Boolean mStopAtEnd;
|
||||
};
|
||||
|
||||
BG_FileInfo *BackgroundTrackMgr::CurFileInfo;
|
||||
|
||||
|
||||
BackgroundTrackMgr::BackgroundTrackMgr()
|
||||
: mQueue(0),
|
||||
mBufferByteSize(0),
|
||||
mCurrentPacket(0),
|
||||
mNumPacketsToRead(0),
|
||||
mVolume(1.0f),
|
||||
mPacketDescs(NULL),
|
||||
mStopAtEnd(false)
|
||||
{ }
|
||||
|
||||
BackgroundTrackMgr::~BackgroundTrackMgr() {
|
||||
Teardown();
|
||||
}
|
||||
|
||||
void BackgroundTrackMgr::Teardown() {
|
||||
if (mQueue) {
|
||||
AudioQueueDispose(mQueue, true);
|
||||
mQueue = NULL;
|
||||
}
|
||||
if ( CurFileInfo ) {
|
||||
AudioFileClose( CurFileInfo->mAFID);
|
||||
delete CurFileInfo;
|
||||
CurFileInfo = NULL;
|
||||
}
|
||||
if (mPacketDescs) {
|
||||
delete[] mPacketDescs;
|
||||
mPacketDescs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BackgroundTrackMgr::QueueCallback( void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer ) {
|
||||
// dispose of the buffer if no longer in use
|
||||
OSStatus result = noErr;
|
||||
BackgroundTrackMgr *THIS = (BackgroundTrackMgr*)inUserData;
|
||||
UInt32 nPackets = 0;
|
||||
// loop the current buffer if the following:
|
||||
// 1. file was loaded into the buffer previously
|
||||
// 2. only one file in the queue
|
||||
// 3. we have not been told to stop at playlist completion
|
||||
if ((CurFileInfo->mFileDataInQueue) && (!THIS->mStopAtEnd)) {
|
||||
nPackets = THIS->mNumPacketsToRead;
|
||||
} else {
|
||||
UInt32 numBytes;
|
||||
while (nPackets == 0) {
|
||||
// if loadAtOnce, get all packets in the file, otherwise ~.5 seconds of data
|
||||
nPackets = THIS->mNumPacketsToRead;
|
||||
result = AudioFileReadPackets(CurFileInfo->mAFID, false, &numBytes, THIS->mPacketDescs, THIS->mCurrentPacket, &nPackets,
|
||||
inCompleteAQBuffer->mAudioData);
|
||||
AssertNoError("Error reading file data", end);
|
||||
|
||||
inCompleteAQBuffer->mAudioDataByteSize = numBytes;
|
||||
|
||||
if (nPackets == 0) { // no packets were read, this file has ended.
|
||||
if (CurFileInfo->mLoadAtOnce) {
|
||||
CurFileInfo->mFileDataInQueue = true;
|
||||
}
|
||||
|
||||
THIS->mCurrentPacket = 0;
|
||||
|
||||
// we have gone through the playlist. if mStopAtEnd, stop the queue here
|
||||
if ( THIS->mStopAtEnd ) {
|
||||
result = AudioQueueStop(inAQ, false);
|
||||
AssertNoError("Error stopping queue", end);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = AudioQueueEnqueueBuffer(inAQ, inCompleteAQBuffer, (THIS->mPacketDescs ? nPackets : 0), THIS->mPacketDescs);
|
||||
if(result != noErr) {
|
||||
result = AudioQueueFreeBuffer(inAQ, inCompleteAQBuffer);
|
||||
AssertNoError("Error freeing buffers that didn't enqueue", end);
|
||||
}
|
||||
AssertNoError("Error enqueuing new buffer", end);
|
||||
if (CurFileInfo->mLoadAtOnce) {
|
||||
CurFileInfo->mFileDataInQueue = true;
|
||||
}
|
||||
|
||||
THIS->mCurrentPacket += nPackets;
|
||||
|
||||
end:
|
||||
return;
|
||||
}
|
||||
|
||||
OSStatus BackgroundTrackMgr::SetupQueue(BG_FileInfo *inFileInfo) {
|
||||
UInt32 size = 0;
|
||||
OSStatus result = AudioQueueNewOutput(&inFileInfo->mFileFormat, QueueCallback, this,
|
||||
CFRunLoopGetMain() /* CFRunLoopGetCurrent() */, kCFRunLoopCommonModes, 0, &mQueue);
|
||||
AssertNoError("Error creating queue", end);
|
||||
#if 0
|
||||
// (2) If the file has a cookie, we should get it and set it on the AQ
|
||||
size = sizeof(UInt32);
|
||||
result = AudioFileGetPropertyInfo (inFileInfo->mAFID, kAudioFilePropertyMagicCookieData, &size, NULL);
|
||||
|
||||
if (!result && size) {
|
||||
char* cookie = new char [size];
|
||||
result = AudioFileGetProperty (inFileInfo->mAFID, kAudioFilePropertyMagicCookieData, &size, cookie);
|
||||
AssertNoError("Error getting magic cookie", end);
|
||||
result = AudioQueueSetProperty(mQueue, kAudioQueueProperty_MagicCookie, cookie, size);
|
||||
delete [] cookie;
|
||||
AssertNoError("Error setting magic cookie", end);
|
||||
}
|
||||
#endif
|
||||
// channel layout
|
||||
OSStatus err = AudioFileGetPropertyInfo(inFileInfo->mAFID, kAudioFilePropertyChannelLayout, &size, NULL);
|
||||
if (err == noErr && size > 0) {
|
||||
AudioChannelLayout *acl = (AudioChannelLayout *)malloc(size);
|
||||
result = AudioFileGetProperty(inFileInfo->mAFID, kAudioFilePropertyChannelLayout, &size, acl);
|
||||
AssertNoError("Error getting channel layout from file", end);
|
||||
result = AudioQueueSetProperty(mQueue, kAudioQueueProperty_ChannelLayout, acl, size);
|
||||
free(acl);
|
||||
AssertNoError("Error setting channel layout on queue", end);
|
||||
}
|
||||
|
||||
// volume
|
||||
result = SetVolume(mVolume);
|
||||
|
||||
end:
|
||||
return result;
|
||||
}
|
||||
|
||||
OSStatus BackgroundTrackMgr::SetupBuffers(BG_FileInfo *inFileInfo) {
|
||||
int numBuffersToQueue = kNumberBuffers;
|
||||
UInt32 maxPacketSize;
|
||||
UInt32 size = sizeof(maxPacketSize);
|
||||
// we need to calculate how many packets we read at a time, and how big a buffer we need
|
||||
// we base this on the size of the packets in the file and an approximate duration for each buffer
|
||||
|
||||
// first check to see what the max size of a packet is - if it is bigger
|
||||
// than our allocation default size, that needs to become larger
|
||||
OSStatus result = AudioFileGetProperty(inFileInfo->mAFID, kAudioFilePropertyPacketSizeUpperBound, &size, &maxPacketSize);
|
||||
AssertNoError("Error getting packet upper bound size", end);
|
||||
bool isFormatVBR = (inFileInfo->mFileFormat.mBytesPerPacket == 0 || inFileInfo->mFileFormat.mFramesPerPacket == 0);
|
||||
|
||||
CalculateBytesForTime(inFileInfo->mFileFormat, maxPacketSize, 0.5/*seconds*/, &mBufferByteSize, &mNumPacketsToRead);
|
||||
|
||||
// if the file is smaller than the capacity of all the buffer queues, always load it at once
|
||||
if ((mBufferByteSize * numBuffersToQueue) > inFileInfo->mFileDataSize) {
|
||||
inFileInfo->mLoadAtOnce = true;
|
||||
}
|
||||
|
||||
if (inFileInfo->mLoadAtOnce) {
|
||||
UInt64 theFileNumPackets;
|
||||
size = sizeof(UInt64);
|
||||
result = AudioFileGetProperty(inFileInfo->mAFID, kAudioFilePropertyAudioDataPacketCount, &size, &theFileNumPackets);
|
||||
AssertNoError("Error getting packet count for file", end);
|
||||
|
||||
mNumPacketsToRead = (UInt32)theFileNumPackets;
|
||||
mBufferByteSize = (UInt32)inFileInfo->mFileDataSize;
|
||||
numBuffersToQueue = 1;
|
||||
} else {
|
||||
mNumPacketsToRead = mBufferByteSize / maxPacketSize;
|
||||
}
|
||||
|
||||
if (isFormatVBR) {
|
||||
mPacketDescs = new AudioStreamPacketDescription [mNumPacketsToRead];
|
||||
} else {
|
||||
mPacketDescs = NULL; // we don't provide packet descriptions for constant bit rate formats (like linear PCM)
|
||||
}
|
||||
|
||||
// allocate the queue's buffers
|
||||
for (int i = 0; i < numBuffersToQueue; ++i) {
|
||||
result = AudioQueueAllocateBuffer(mQueue, mBufferByteSize, &mBuffers[i]);
|
||||
AssertNoError("Error allocating buffer for queue", end);
|
||||
QueueCallback (this, mQueue, mBuffers[i]);
|
||||
if (inFileInfo->mLoadAtOnce) {
|
||||
inFileInfo->mFileDataInQueue = true;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
return result;
|
||||
}
|
||||
|
||||
OSStatus BackgroundTrackMgr::LoadTrack(const char* inFilePath, Boolean inAddToQueue, Boolean inLoadAtOnce) {
|
||||
// OSStatus result = LoadFileDataInfo(CurFileInfo->mFilePath.c_str(), CurFileInfo->mAFID, CurFileInfo->mFileFormat, CurFileInfo->mFileDataSize);
|
||||
// AssertNoError("Error getting file data info", fail);
|
||||
OSStatus result;
|
||||
UInt32 thePropSize;
|
||||
|
||||
CFURLRef theURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8*)inFilePath, strlen(inFilePath), false);
|
||||
if (theURL == NULL)
|
||||
result = kSoundEngineErrFileNotFound;
|
||||
else
|
||||
result = 0;
|
||||
AssertNoError("Error opening URL", fail);
|
||||
|
||||
CurFileInfo = new BG_FileInfo;
|
||||
CurFileInfo->mFilePath = inFilePath;
|
||||
|
||||
result = AudioFileOpenURL(theURL, kAudioFileReadPermission, 0, &CurFileInfo->mAFID);
|
||||
CFRelease(theURL);
|
||||
AssertNoError("Error opening file", fail);
|
||||
|
||||
thePropSize = sizeof(CurFileInfo->mFileFormat);
|
||||
result = AudioFileGetProperty(CurFileInfo->mAFID, kAudioFilePropertyDataFormat, &thePropSize, &CurFileInfo->mFileFormat);
|
||||
AssertNoError("Error getting file format", fail);
|
||||
|
||||
thePropSize = sizeof(UInt64);
|
||||
result = AudioFileGetProperty(CurFileInfo->mAFID, kAudioFilePropertyAudioDataByteCount, &thePropSize, &CurFileInfo->mFileDataSize);
|
||||
AssertNoError("Error getting file data size", fail);
|
||||
|
||||
CurFileInfo->mLoadAtOnce = inLoadAtOnce;
|
||||
CurFileInfo->mFileDataInQueue = false;
|
||||
|
||||
result = SetupQueue(CurFileInfo);
|
||||
AssertNoError("Error setting up queue", fail);
|
||||
|
||||
result = SetupBuffers(CurFileInfo);
|
||||
AssertNoError("Error setting up queue buffers", fail);
|
||||
|
||||
return result;
|
||||
|
||||
fail:
|
||||
if (CurFileInfo) {
|
||||
delete CurFileInfo;
|
||||
CurFileInfo = NULL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
OSStatus BackgroundTrackMgr::SetVolume(Float32 inVolume) {
|
||||
mVolume = inVolume;
|
||||
return AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, mVolume * gMasterVolumeGain);
|
||||
}
|
||||
|
||||
Float32 BackgroundTrackMgr::GetVolume() const {
|
||||
return mVolume;
|
||||
}
|
||||
|
||||
OSStatus BackgroundTrackMgr::Start() {
|
||||
OSStatus result = AudioQueuePrime(mQueue, 1, NULL);
|
||||
if (result) {
|
||||
printf("BackgroundTrackMgr: Error priming queue: %d\n", (int)result);
|
||||
return result;
|
||||
}
|
||||
return AudioQueueStart(mQueue, NULL);
|
||||
}
|
||||
|
||||
OSStatus BackgroundTrackMgr::Stop(Boolean inStopAtEnd) {
|
||||
if (inStopAtEnd) {
|
||||
mStopAtEnd = true;
|
||||
return noErr;
|
||||
} else {
|
||||
return AudioQueueStop(mQueue, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static BackgroundTrackMgr sBackgroundTrackMgr;
|
||||
|
||||
static char currentMusicName[1024];
|
||||
|
||||
void iphonePauseMusic() {
|
||||
if ( music->value == 0 ) {
|
||||
// music is disabled
|
||||
return;
|
||||
}
|
||||
AudioQueuePause(sBackgroundTrackMgr.mQueue);
|
||||
}
|
||||
void iphoneResumeMusic() {
|
||||
if ( music->value == 0 ) {
|
||||
// music is disabled
|
||||
return;
|
||||
}
|
||||
AudioQueueStart(sBackgroundTrackMgr.mQueue,NULL);
|
||||
}
|
||||
void iphoneStopMusic() {
|
||||
sBackgroundTrackMgr.Teardown();
|
||||
}
|
||||
|
||||
void iphoneStartMusic() {
|
||||
if ( music->value == 0 ) {
|
||||
// music is disabled
|
||||
return;
|
||||
}
|
||||
char fullName[1024];
|
||||
sprintf( fullName, "%s/base/music/d_%s.mp3", SysIphoneGetAppDir(), currentMusicName );
|
||||
|
||||
printf( "Starting music '%s'\n", fullName );
|
||||
|
||||
iphoneStopMusic();
|
||||
sBackgroundTrackMgr.LoadTrack( fullName, false, true);
|
||||
sBackgroundTrackMgr.Start();
|
||||
|
||||
if ( !strcmp( currentMusicName, "intro" ) ) {
|
||||
// stop the intro music at end, don't loop
|
||||
sBackgroundTrackMgr.mStopAtEnd = true;
|
||||
} else {
|
||||
sBackgroundTrackMgr.mStopAtEnd = false;
|
||||
}
|
||||
}
|
||||
|
||||
void iphonePlayMusic( const char *name ) {
|
||||
strcpy( currentMusicName, name );
|
||||
|
||||
iphoneStartMusic();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,574 @@
|
|||
// !$*UTF8*$!
|
||||
{
|
||||
1D6058900D05DD3D006BFB54 /* Doom */ = {
|
||||
activeExec = 0;
|
||||
executables = (
|
||||
ED9BAB90108380AC00166CDA /* Doom */,
|
||||
);
|
||||
};
|
||||
29B97313FDCFA39411CA2CEA /* Project object */ = {
|
||||
activeBuildConfigurationName = Debug;
|
||||
activeExecutable = ED9BAB90108380AC00166CDA /* Doom */;
|
||||
activeSDKPreference = iphonesimulator2.0;
|
||||
activeTarget = 1D6058900D05DD3D006BFB54 /* Doom */;
|
||||
addToTargets = (
|
||||
1D6058900D05DD3D006BFB54 /* Doom */,
|
||||
);
|
||||
codeSenseManager = ED9BABB0108380C600166CDA /* Code sense */;
|
||||
executables = (
|
||||
ED9BAB90108380AC00166CDA /* Doom */,
|
||||
);
|
||||
perUserDictionary = {
|
||||
PBXConfiguration.PBXFileTableDataSource3.PBXBookmarksDataSource = {
|
||||
PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
|
||||
PBXFileTableDataSourceColumnSortingKey = PBXBookmarksDataSource_NameID;
|
||||
PBXFileTableDataSourceColumnWidthsKey = (
|
||||
200,
|
||||
200,
|
||||
293.58349609375,
|
||||
);
|
||||
PBXFileTableDataSourceColumnsKey = (
|
||||
PBXBookmarksDataSource_LocationID,
|
||||
PBXBookmarksDataSource_NameID,
|
||||
PBXBookmarksDataSource_CommentsID,
|
||||
);
|
||||
};
|
||||
PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = {
|
||||
PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
|
||||
PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
|
||||
PBXFileTableDataSourceColumnWidthsKey = (
|
||||
20,
|
||||
484,
|
||||
20,
|
||||
48,
|
||||
43,
|
||||
43,
|
||||
20,
|
||||
);
|
||||
PBXFileTableDataSourceColumnsKey = (
|
||||
PBXFileDataSource_FiletypeID,
|
||||
PBXFileDataSource_Filename_ColumnID,
|
||||
PBXFileDataSource_Built_ColumnID,
|
||||
PBXFileDataSource_ObjectSize_ColumnID,
|
||||
PBXFileDataSource_Errors_ColumnID,
|
||||
PBXFileDataSource_Warnings_ColumnID,
|
||||
PBXFileDataSource_Target_ColumnID,
|
||||
);
|
||||
};
|
||||
PBXConfiguration.PBXFileTableDataSource3.PBXFindDataSource = {
|
||||
PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
|
||||
PBXFileTableDataSourceColumnSortingKey = PBXFindDataSource_LocationID;
|
||||
PBXFileTableDataSourceColumnWidthsKey = (
|
||||
200,
|
||||
498,
|
||||
);
|
||||
PBXFileTableDataSourceColumnsKey = (
|
||||
PBXFindDataSource_MessageID,
|
||||
PBXFindDataSource_LocationID,
|
||||
);
|
||||
};
|
||||
PBXConfiguration.PBXTargetDataSource.PBXTargetDataSource = {
|
||||
PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
|
||||
PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
|
||||
PBXFileTableDataSourceColumnWidthsKey = (
|
||||
20,
|
||||
444,
|
||||
60,
|
||||
20,
|
||||
48,
|
||||
43,
|
||||
43,
|
||||
);
|
||||
PBXFileTableDataSourceColumnsKey = (
|
||||
PBXFileDataSource_FiletypeID,
|
||||
PBXFileDataSource_Filename_ColumnID,
|
||||
PBXTargetDataSource_PrimaryAttribute,
|
||||
PBXFileDataSource_Built_ColumnID,
|
||||
PBXFileDataSource_ObjectSize_ColumnID,
|
||||
PBXFileDataSource_Errors_ColumnID,
|
||||
PBXFileDataSource_Warnings_ColumnID,
|
||||
);
|
||||
};
|
||||
PBXPerProjectTemplateStateSaveDate = 279053176;
|
||||
PBXWorkspaceStateSaveDate = 279053176;
|
||||
};
|
||||
perUserProjectItems = {
|
||||
ED2D127F10838A65003A9380 /* PBXBookmark */ = ED2D127F10838A65003A9380 /* PBXBookmark */;
|
||||
ED2D128210838A65003A9380 /* PBXBookmark */ = ED2D128210838A65003A9380 /* PBXBookmark */;
|
||||
ED9AB3E410967730000B5852 /* PlistBookmark */ = ED9AB3E410967730000B5852 /* PlistBookmark */;
|
||||
ED9AB3E510967730000B5852 /* PBXTextBookmark */ = ED9AB3E510967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3E610967730000B5852 /* PBXTextBookmark */ = ED9AB3E610967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3E710967730000B5852 /* PBXTextBookmark */ = ED9AB3E710967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3E910967730000B5852 /* PBXTextBookmark */ = ED9AB3E910967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3EC10967730000B5852 /* PBXTextBookmark */ = ED9AB3EC10967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3ED10967730000B5852 /* PBXTextBookmark */ = ED9AB3ED10967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3EF10967730000B5852 /* PBXTextBookmark */ = ED9AB3EF10967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3F210967730000B5852 /* PBXTextBookmark */ = ED9AB3F210967730000B5852 /* PBXTextBookmark */;
|
||||
ED9AB3F310967730000B5852 /* PBXTextBookmark */ = ED9AB3F310967730000B5852 /* PBXTextBookmark */;
|
||||
ED9BABDF1083850C00166CDA /* PlistBookmark */ = ED9BABDF1083850C00166CDA /* PlistBookmark */;
|
||||
ED9BABE11083850C00166CDA /* PlistBookmark */ = ED9BABE11083850C00166CDA /* PlistBookmark */;
|
||||
ED9BABE21083850C00166CDA /* PlistBookmark */ = ED9BABE21083850C00166CDA /* PlistBookmark */;
|
||||
EDAFC7F4109A575F002C3487 /* PBXTextBookmark */ = EDAFC7F4109A575F002C3487 /* PBXTextBookmark */;
|
||||
EDAFC7F5109A575F002C3487 /* PBXTextBookmark */ = EDAFC7F5109A575F002C3487 /* PBXTextBookmark */;
|
||||
EDAFC7F7109A575F002C3487 /* PBXTextBookmark */ = EDAFC7F7109A575F002C3487 /* PBXTextBookmark */;
|
||||
EDAFC7F8109A575F002C3487 /* PBXTextBookmark */ = EDAFC7F8109A575F002C3487 /* PBXTextBookmark */;
|
||||
EDAFC7F9109A575F002C3487 /* PBXTextBookmark */ = EDAFC7F9109A575F002C3487 /* PBXTextBookmark */;
|
||||
EDAFC818109A5B94002C3487 /* PBXTextBookmark */ = EDAFC818109A5B94002C3487 /* PBXTextBookmark */;
|
||||
EDAFC819109A5B94002C3487 /* PBXTextBookmark */ = EDAFC819109A5B94002C3487 /* PBXTextBookmark */;
|
||||
EDAFC81B109A5B94002C3487 /* PBXTextBookmark */ = EDAFC81B109A5B94002C3487 /* PBXTextBookmark */;
|
||||
EDFDF9B310A2054E0071CB9B /* PBXTextBookmark */ = EDFDF9B310A2054E0071CB9B /* PBXTextBookmark */;
|
||||
EDFDF9B410A2054E0071CB9B /* PBXTextBookmark */ = EDFDF9B410A2054E0071CB9B /* PBXTextBookmark */;
|
||||
EDFDF9B610A2054E0071CB9B /* PBXTextBookmark */ = EDFDF9B610A2054E0071CB9B /* PBXTextBookmark */;
|
||||
EDFDF9B710A2054E0071CB9B /* PBXTextBookmark */ = EDFDF9B710A2054E0071CB9B /* PBXTextBookmark */;
|
||||
EDFDF9C110A205F50071CB9B /* PBXTextBookmark */ = EDFDF9C110A205F50071CB9B /* PBXTextBookmark */;
|
||||
EDFDF9C310A205F50071CB9B /* PBXTextBookmark */ = EDFDF9C310A205F50071CB9B /* PBXTextBookmark */;
|
||||
EDFDF9C410A205F50071CB9B /* PBXTextBookmark */ = EDFDF9C410A205F50071CB9B /* PBXTextBookmark */;
|
||||
EDFDF9C810A2114E0071CB9B /* PBXTextBookmark */ = EDFDF9C810A2114E0071CB9B /* PBXTextBookmark */;
|
||||
};
|
||||
sourceControlManager = ED9BABAF108380C600166CDA /* Source Control */;
|
||||
userBuildSettings = {
|
||||
};
|
||||
};
|
||||
434669950F8D058400EA7D6D /* Doom_icon.png */ = {
|
||||
uiCtxt = {
|
||||
sepNavWindowFrame = "{{15, 250}, {800, 773}}";
|
||||
};
|
||||
};
|
||||
43CF03090F56D5C200E4A23D /* iphone_loop.c */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {732, 24640}}";
|
||||
sepNavSelRange = "{6159, 14}";
|
||||
sepNavVisRange = "{5677, 1070}";
|
||||
};
|
||||
};
|
||||
43E8D2DF0F4FC61E003F09B2 /* iphone_main.c */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {720, 7154}}";
|
||||
sepNavSelRange = "{8344, 0}";
|
||||
sepNavVisRange = "{8241, 409}";
|
||||
};
|
||||
};
|
||||
7229CC8E0F6B3363004123C5 /* doomiphone.h */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {662, 1512}}";
|
||||
sepNavSelRange = "{2492, 0}";
|
||||
sepNavVisRange = "{1199, 1295}";
|
||||
};
|
||||
};
|
||||
72A55EEE1003A94300F788A5 /* iphone_start.c */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {662, 3066}}";
|
||||
sepNavSelRange = "{0, 0}";
|
||||
sepNavVisRange = "{0, 757}";
|
||||
};
|
||||
};
|
||||
72A7E8F60F5F2063005B83C0 /* iphone_menus.c */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {662, 13314}}";
|
||||
sepNavSelRange = "{5284, 13}";
|
||||
sepNavVisRange = "{4701, 1236}";
|
||||
};
|
||||
};
|
||||
72D50DBA0F8ED98000BB49E6 /* ipak.h */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {662, 2478}}";
|
||||
sepNavSelRange = "{0, 0}";
|
||||
sepNavVisRange = "{287, 1502}";
|
||||
};
|
||||
};
|
||||
72D50DBB0F8ED98000BB49E6 /* ipak.c */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {864, 5586}}";
|
||||
sepNavSelRange = "{578, 8}";
|
||||
sepNavVisRange = "{1113, 1914}";
|
||||
};
|
||||
};
|
||||
72E731EA0F97E68100E702CD /* iphone_sound.c */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {864, 4214}}";
|
||||
sepNavSelRange = "{4675, 0}";
|
||||
sepNavVisRange = "{3563, 1771}";
|
||||
};
|
||||
};
|
||||
72E847CA0F94096C00AB3C99 /* SDL_opengl.h */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {870, 3024}}";
|
||||
sepNavSelRange = "{0, 0}";
|
||||
sepNavVisRange = "{0, 1327}";
|
||||
};
|
||||
};
|
||||
72E8495E0F942B9300AB3C99 /* misc.c */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {742, 1218}}";
|
||||
sepNavSelRange = "{1221, 0}";
|
||||
sepNavVisRange = "{1132, 433}";
|
||||
};
|
||||
};
|
||||
ED2D127F10838A65003A9380 /* PBXBookmark */ = {
|
||||
isa = PBXBookmark;
|
||||
fRef = 434669950F8D058400EA7D6D /* Doom_icon.png */;
|
||||
};
|
||||
ED2D128210838A65003A9380 /* PBXBookmark */ = {
|
||||
isa = PBXBookmark;
|
||||
fRef = 434669950F8D058400EA7D6D /* Doom_icon.png */;
|
||||
};
|
||||
ED9AB3CF10966E85000B5852 /* iphone_email.h */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {662, 621}}";
|
||||
sepNavSelRange = "{319, 0}";
|
||||
sepNavVisRange = "{0, 319}";
|
||||
};
|
||||
};
|
||||
ED9AB3D010966E85000B5852 /* iphone_email.m */ = {
|
||||
uiCtxt = {
|
||||
sepNavIntBoundsRect = "{{0, 0}, {750, 3024}}";
|
||||
sepNavSelRange = "{0, 0}";
|
||||
sepNavVisRange = "{0, 1042}";
|
||||
};
|
||||
};
|
||||
ED9AB3E410967730000B5852 /* PlistBookmark */ = {
|
||||
isa = PlistBookmark;
|
||||
fRef = 8D1107310486CEB800E47090 /* Info.plist */;
|
||||
fallbackIsa = PBXBookmark;
|
||||
isK = 0;
|
||||
kPath = (
|
||||
UIPrerenderedIcon,
|
||||
);
|
||||
name = /Users/greghodges/doom/code/iphone/Info.plist;
|
||||
rLen = 0;
|
||||
rLoc = 2147483647;
|
||||
};
|
||||
ED9AB3E510967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72A55EEE1003A94300F788A5 /* iphone_start.c */;
|
||||
name = "iphone_start.c: 1";
|
||||
rLen = 0;
|
||||
rLoc = 0;
|
||||
rType = 0;
|
||||
vrLen = 757;
|
||||
vrLoc = 0;
|
||||
};
|
||||
ED9AB3E610967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = ED9AB3CF10966E85000B5852 /* iphone_email.h */;
|
||||
name = "iphone_email.h: 15";
|
||||
rLen = 0;
|
||||
rLoc = 319;
|
||||
rType = 0;
|
||||
vrLen = 319;
|
||||
vrLoc = 0;
|
||||
};
|
||||
ED9AB3E710967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = ED9AB3D010966E85000B5852 /* iphone_email.m */;
|
||||
name = "iphone_email.m: 1";
|
||||
rLen = 0;
|
||||
rLoc = 0;
|
||||
rType = 0;
|
||||
vrLen = 1042;
|
||||
vrLoc = 0;
|
||||
};
|
||||
ED9AB3E910967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 7229CC8E0F6B3363004123C5 /* doomiphone.h */;
|
||||
name = "doomiphone.h: 106";
|
||||
rLen = 0;
|
||||
rLoc = 2492;
|
||||
rType = 0;
|
||||
vrLen = 1295;
|
||||
vrLoc = 1199;
|
||||
};
|
||||
ED9AB3EC10967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = ED9AB3CF10966E85000B5852 /* iphone_email.h */;
|
||||
name = "iphone_email.h: 15";
|
||||
rLen = 0;
|
||||
rLoc = 319;
|
||||
rType = 0;
|
||||
vrLen = 319;
|
||||
vrLoc = 0;
|
||||
};
|
||||
ED9AB3ED10967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72A55EEE1003A94300F788A5 /* iphone_start.c */;
|
||||
name = "iphone_start.c: 1";
|
||||
rLen = 0;
|
||||
rLoc = 0;
|
||||
rType = 0;
|
||||
vrLen = 757;
|
||||
vrLoc = 0;
|
||||
};
|
||||
ED9AB3EF10967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = ED9AB3D010966E85000B5852 /* iphone_email.m */;
|
||||
name = "iphone_email.m: 1";
|
||||
rLen = 0;
|
||||
rLoc = 0;
|
||||
rType = 0;
|
||||
vrLen = 1042;
|
||||
vrLoc = 0;
|
||||
};
|
||||
ED9AB3F210967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 43E8D2DF0F4FC61E003F09B2 /* iphone_main.c */;
|
||||
name = "iphone_main.c: 334";
|
||||
rLen = 0;
|
||||
rLoc = 8790;
|
||||
rType = 0;
|
||||
vrLen = 1755;
|
||||
vrLoc = 7979;
|
||||
};
|
||||
ED9AB3F310967730000B5852 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 7229CC8E0F6B3363004123C5 /* doomiphone.h */;
|
||||
name = "doomiphone.h: 106";
|
||||
rLen = 0;
|
||||
rLoc = 2492;
|
||||
rType = 0;
|
||||
vrLen = 1295;
|
||||
vrLoc = 1199;
|
||||
};
|
||||
ED9BAB90108380AC00166CDA /* Doom */ = {
|
||||
isa = PBXExecutable;
|
||||
activeArgIndices = (
|
||||
);
|
||||
argumentStrings = (
|
||||
);
|
||||
autoAttachOnCrash = 1;
|
||||
breakpointsEnabled = 0;
|
||||
configStateDict = {
|
||||
};
|
||||
customDataFormattersEnabled = 1;
|
||||
debuggerPlugin = GDBDebugging;
|
||||
disassemblyDisplayState = 0;
|
||||
dylibVariantSuffix = "";
|
||||
enableDebugStr = 1;
|
||||
environmentEntries = (
|
||||
);
|
||||
executableSystemSymbolLevel = 0;
|
||||
executableUserSymbolLevel = 0;
|
||||
libgmallocEnabled = 0;
|
||||
name = Doom;
|
||||
savedGlobals = {
|
||||
};
|
||||
sourceDirectories = (
|
||||
);
|
||||
};
|
||||
ED9BABAF108380C600166CDA /* Source Control */ = {
|
||||
isa = PBXSourceControlManager;
|
||||
fallbackIsa = XCSourceControlManager;
|
||||
isSCMEnabled = 0;
|
||||
scmConfiguration = {
|
||||
};
|
||||
};
|
||||
ED9BABB0108380C600166CDA /* Code sense */ = {
|
||||
isa = PBXCodeSenseManager;
|
||||
indexTemplatePath = "";
|
||||
};
|
||||
ED9BABDF1083850C00166CDA /* PlistBookmark */ = {
|
||||
isa = PlistBookmark;
|
||||
fRef = 4364BF3E0F5CB25900F29317 /* dist.plist */;
|
||||
fallbackIsa = PBXBookmark;
|
||||
isK = 0;
|
||||
kPath = (
|
||||
);
|
||||
name = /Users/greghodges/doom/code/iphone/dist.plist;
|
||||
rLen = 0;
|
||||
rLoc = 2147483647;
|
||||
};
|
||||
ED9BABE11083850C00166CDA /* PlistBookmark */ = {
|
||||
isa = PlistBookmark;
|
||||
fRef = 8D1107310486CEB800E47090 /* Info.plist */;
|
||||
fallbackIsa = PBXBookmark;
|
||||
isK = 0;
|
||||
kPath = (
|
||||
CFBundleIconFile,
|
||||
);
|
||||
name = /Users/greghodges/doom/code/iphone/Info.plist;
|
||||
rLen = 0;
|
||||
rLoc = 2147483647;
|
||||
};
|
||||
ED9BABE21083850C00166CDA /* PlistBookmark */ = {
|
||||
isa = PlistBookmark;
|
||||
fRef = 4364BF3E0F5CB25900F29317 /* dist.plist */;
|
||||
fallbackIsa = PBXBookmark;
|
||||
isK = 0;
|
||||
kPath = (
|
||||
);
|
||||
name = /Users/greghodges/doom/code/iphone/dist.plist;
|
||||
rLen = 0;
|
||||
rLoc = 2147483647;
|
||||
};
|
||||
EDAFC7F4109A575F002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72A7E8F60F5F2063005B83C0 /* iphone_menus.c */;
|
||||
name = "iphone_menus.c: 201";
|
||||
rLen = 13;
|
||||
rLoc = 5284;
|
||||
rType = 0;
|
||||
vrLen = 1236;
|
||||
vrLoc = 4701;
|
||||
};
|
||||
EDAFC7F5109A575F002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 43CF03090F56D5C200E4A23D /* iphone_loop.c */;
|
||||
name = "iphone_loop.c: 212";
|
||||
rLen = 14;
|
||||
rLoc = 6159;
|
||||
rType = 0;
|
||||
vrLen = 1070;
|
||||
vrLoc = 5677;
|
||||
};
|
||||
EDAFC7F7109A575F002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72E8495E0F942B9300AB3C99 /* misc.c */;
|
||||
name = "misc.c: 40";
|
||||
rLen = 0;
|
||||
rLoc = 768;
|
||||
rType = 0;
|
||||
vrLen = 807;
|
||||
vrLoc = 0;
|
||||
};
|
||||
EDAFC7F8109A575F002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72A7E8F60F5F2063005B83C0 /* iphone_menus.c */;
|
||||
name = "iphone_menus.c: 201";
|
||||
rLen = 13;
|
||||
rLoc = 5284;
|
||||
rType = 0;
|
||||
vrLen = 1236;
|
||||
vrLoc = 4701;
|
||||
};
|
||||
EDAFC7F9109A575F002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 43CF03090F56D5C200E4A23D /* iphone_loop.c */;
|
||||
name = "iphone_loop.c: 212";
|
||||
rLen = 14;
|
||||
rLoc = 6159;
|
||||
rType = 0;
|
||||
vrLen = 1070;
|
||||
vrLoc = 5677;
|
||||
};
|
||||
EDAFC818109A5B94002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72D50DBB0F8ED98000BB49E6 /* ipak.c */;
|
||||
name = "ipak.c: 28";
|
||||
rLen = 7;
|
||||
rLoc = 467;
|
||||
rType = 0;
|
||||
vrLen = 1190;
|
||||
vrLoc = 359;
|
||||
};
|
||||
EDAFC819109A5B94002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 43E8D2DF0F4FC61E003F09B2 /* iphone_main.c */;
|
||||
name = "iphone_main.c: 325";
|
||||
rLen = 7;
|
||||
rLoc = 8411;
|
||||
rType = 0;
|
||||
vrLen = 1755;
|
||||
vrLoc = 7979;
|
||||
};
|
||||
EDAFC81B109A5B94002C3487 /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72D50DBB0F8ED98000BB49E6 /* ipak.c */;
|
||||
name = "ipak.c: 28";
|
||||
rLen = 7;
|
||||
rLoc = 467;
|
||||
rType = 0;
|
||||
vrLen = 1190;
|
||||
vrLoc = 359;
|
||||
};
|
||||
EDFDF9B310A2054E0071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72D50DBA0F8ED98000BB49E6 /* ipak.h */;
|
||||
name = "ipak.h: 1";
|
||||
rLen = 0;
|
||||
rLoc = 0;
|
||||
rType = 0;
|
||||
vrLen = 1502;
|
||||
vrLoc = 287;
|
||||
};
|
||||
EDFDF9B410A2054E0071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72E8495E0F942B9300AB3C99 /* misc.c */;
|
||||
name = "misc.c: 60";
|
||||
rLen = 0;
|
||||
rLoc = 1496;
|
||||
rType = 0;
|
||||
vrLen = 964;
|
||||
vrLoc = 869;
|
||||
};
|
||||
EDFDF9B610A2054E0071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72D50DBA0F8ED98000BB49E6 /* ipak.h */;
|
||||
name = "ipak.h: 1";
|
||||
rLen = 0;
|
||||
rLoc = 0;
|
||||
rType = 0;
|
||||
vrLen = 1502;
|
||||
vrLoc = 287;
|
||||
};
|
||||
EDFDF9B710A2054E0071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72E8495E0F942B9300AB3C99 /* misc.c */;
|
||||
name = "misc.c: 60";
|
||||
rLen = 0;
|
||||
rLoc = 1496;
|
||||
rType = 0;
|
||||
vrLen = 964;
|
||||
vrLoc = 869;
|
||||
};
|
||||
EDFDF9C110A205F50071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = EDFDF9C210A205F50071CB9B /* alc.h */;
|
||||
name = "alc.h: 186";
|
||||
rLen = 0;
|
||||
rLoc = 3852;
|
||||
rType = 0;
|
||||
vrLen = 1365;
|
||||
vrLoc = 3211;
|
||||
};
|
||||
EDFDF9C210A205F50071CB9B /* alc.h */ = {
|
||||
isa = PBXFileReference;
|
||||
name = alc.h;
|
||||
path = /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk/System/Library/Frameworks/OpenAL.framework/Headers/alc.h;
|
||||
sourceTree = "<absolute>";
|
||||
};
|
||||
EDFDF9C310A205F50071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72E731EA0F97E68100E702CD /* iphone_sound.c */;
|
||||
name = "iphone_sound.c: 160";
|
||||
rLen = 16;
|
||||
rLoc = 5037;
|
||||
rType = 0;
|
||||
vrLen = 1820;
|
||||
vrLoc = 3514;
|
||||
};
|
||||
EDFDF9C410A205F50071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = EDFDF9C510A205F50071CB9B /* alc.h */;
|
||||
name = "alc.h: 186";
|
||||
rLen = 0;
|
||||
rLoc = 3852;
|
||||
rType = 0;
|
||||
vrLen = 1365;
|
||||
vrLoc = 3211;
|
||||
};
|
||||
EDFDF9C510A205F50071CB9B /* alc.h */ = {
|
||||
isa = PBXFileReference;
|
||||
name = alc.h;
|
||||
path = /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk/System/Library/Frameworks/OpenAL.framework/Headers/alc.h;
|
||||
sourceTree = "<absolute>";
|
||||
};
|
||||
EDFDF9C810A2114E0071CB9B /* PBXTextBookmark */ = {
|
||||
isa = PBXTextBookmark;
|
||||
fRef = 72E731EA0F97E68100E702CD /* iphone_sound.c */;
|
||||
name = "iphone_sound.c: 148";
|
||||
rLen = 0;
|
||||
rLoc = 4675;
|
||||
rType = 0;
|
||||
vrLen = 1771;
|
||||
vrLoc = 3563;
|
||||
};
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
|
||||
Copyright (C) 2009 Id Software, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <OpenGLES/EAGL.h>
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
#import <OpenGLES/ES1/glext.h>
|
||||
|
||||
/*
|
||||
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
|
||||
The view content is basically an EAGL surface you render your OpenGL scene into.
|
||||
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
|
||||
*/
|
||||
@interface EAGLView : UIView <UITextFieldDelegate> {
|
||||
@public
|
||||
UITextField *textField;
|
||||
|
||||
@private
|
||||
/* The pixel dimensions of the backbuffer */
|
||||
GLint backingWidth;
|
||||
GLint backingHeight;
|
||||
|
||||
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
|
||||
GLuint viewRenderbuffer, viewFramebuffer;
|
||||
|
||||
/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
|
||||
GLuint depthRenderbuffer;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,354 @@
|
|||
//
|
||||
// EAGLView.m
|
||||
// Doom
|
||||
//
|
||||
// Created by Cass Everitt on 2/20/09.
|
||||
// Copyright Id Software 2009. All rights reserved.
|
||||
//
|
||||
/*
|
||||
|
||||
Copyright (C) 2009 Id Software, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import <OpenGLES/EAGLDrawable.h>
|
||||
|
||||
#import "EAGLView.h"
|
||||
#import "doomAppDelegate.h"
|
||||
|
||||
#include "doomiphone.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
EAGLView *eaglview;
|
||||
EAGLContext *context;
|
||||
|
||||
@implementation EAGLView
|
||||
|
||||
// You must implement this method
|
||||
+ (Class)layerClass {
|
||||
return [CAEAGLLayer class];
|
||||
}
|
||||
|
||||
CAEAGLLayer *eaglLayer;
|
||||
|
||||
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
|
||||
- (id)initWithCoder:(NSCoder*)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
|
||||
eaglview = self;
|
||||
|
||||
// allow multiple touch events
|
||||
self.multipleTouchEnabled = true;
|
||||
|
||||
// Get the layer
|
||||
eaglLayer = (CAEAGLLayer *)self.layer;
|
||||
|
||||
// set opaque so UIKit doesn't try to blend it over other layers
|
||||
eaglLayer.opaque = YES;
|
||||
|
||||
// set it to no-backing-retained so it can do ast pageflips instead
|
||||
// of update copies, and go to 565 bit depth for higher performance.
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
|
||||
[NSNumber numberWithBool:NO],
|
||||
kEAGLDrawablePropertyRetainedBacking,
|
||||
|
||||
kEAGLColorFormatRGB565,
|
||||
/* kEAGLColorFormatRGBA8, */
|
||||
kEAGLDrawablePropertyColorFormat,
|
||||
|
||||
nil];
|
||||
|
||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
||||
assert( context );
|
||||
|
||||
if ( ![EAGLContext setCurrentContext:context]) {
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
glGenFramebuffersOES(1, &viewFramebuffer);
|
||||
glGenRenderbuffersOES(1, &viewRenderbuffer);
|
||||
|
||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
|
||||
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
|
||||
|
||||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
|
||||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
|
||||
|
||||
glGenRenderbuffersOES(1, &depthRenderbuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
|
||||
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
|
||||
|
||||
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
|
||||
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
|
||||
}
|
||||
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) handleTouches:(UIEvent*)event {
|
||||
int touchCount = 0;
|
||||
static int previousTouchCount;
|
||||
static int touchRover;
|
||||
int touchThisSequence[MAX_TOUCHES];
|
||||
|
||||
memset( touchThisSequence, 0, sizeof( touchThisSequence ) );
|
||||
|
||||
NSSet *touches = [event allTouches];
|
||||
// printf( "count: %i\n", [touches count] );
|
||||
|
||||
// lock the game out temporarily
|
||||
pthread_mutex_lock( &eventMutex );
|
||||
|
||||
for (UITouch *myTouch in touches)
|
||||
{
|
||||
CGPoint touchLocation = [myTouch locationInView:nil];
|
||||
|
||||
// handle landscape mode and flipping
|
||||
int x, y;
|
||||
if ( revLand->value ) {
|
||||
x = touchLocation.y;
|
||||
y = 319 - touchLocation.x;
|
||||
} else {
|
||||
x = 479 - touchLocation.y;
|
||||
y = touchLocation.x;
|
||||
}
|
||||
// printf( "%i, %i\n", x, y );
|
||||
touchCount++;
|
||||
|
||||
touch_t *t2;
|
||||
|
||||
// find which one it is closest to
|
||||
int minDist = 64 * 64; // allow up to 64 unit moves to be drags
|
||||
int minIndex = -1;
|
||||
for ( int i = 0 ; i < MAX_TOUCHES ; i++ ) {
|
||||
t2 = &sysTouches[i];
|
||||
if ( !t2->down ) {
|
||||
continue;
|
||||
}
|
||||
int dist = ( t2->x - x ) * ( t2->x - x ) + ( t2->y - y ) * ( t2->y - y );
|
||||
if ( dist < minDist ) {
|
||||
minDist = dist;
|
||||
minIndex = i;
|
||||
}
|
||||
}
|
||||
if ( minIndex != -1 ) {
|
||||
// reuse a touch
|
||||
sysTouches[minIndex].x = x;
|
||||
sysTouches[minIndex].y = y;
|
||||
if (myTouch.phase == UITouchPhaseEnded) {
|
||||
// if this was released before the game got to see it,
|
||||
// make it a special case
|
||||
if ( sysTouches[minIndex].stateCount == 1 ) {
|
||||
// leave it in the down state with a special count
|
||||
sysTouches[minIndex].stateCount = -1;
|
||||
// printf( "Tap release touch on a reuse\n" );
|
||||
} else {
|
||||
sysTouches[minIndex].down = false;
|
||||
sysTouches[minIndex].stateCount = 1;
|
||||
// printf( "Release touch on a reuse\n" );
|
||||
}
|
||||
} else {
|
||||
if (myTouch.phase == UITouchPhaseBegan) {
|
||||
sysTouches[minIndex].stateCount = 1;
|
||||
sysTouches[minIndex].controlOwner = NULL;
|
||||
// printf( "Begin touch on a reuse\n" );
|
||||
} else {
|
||||
// printf( "Drag touch on a reuse\n" );
|
||||
}
|
||||
sysTouches[minIndex].down = true;
|
||||
}
|
||||
touchThisSequence[minIndex] = true;
|
||||
} else {
|
||||
if ( myTouch.phase != UITouchPhaseBegan ) {
|
||||
printf( "Non-local touch wasn't a begin\n" );
|
||||
} else {
|
||||
// allocate a new one
|
||||
// grab the next rover spot
|
||||
// don't just use first-not-down, because that might
|
||||
// cause the release to be missed by the game code.
|
||||
int i, j;
|
||||
for ( j = 0 ; j < MAX_TOUCHES ; j++ ) {
|
||||
i = touchRover;
|
||||
t2 = &sysTouches[i];
|
||||
touchRover = ( touchRover + 1 ) % MAX_TOUCHES;
|
||||
if ( !t2->down ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( j == MAX_TOUCHES ) {
|
||||
printf( "MAX_TOUCHES, clearing everything!\n" );
|
||||
memset( sysTouches, 0, sizeof( sysTouches ) );
|
||||
continue;
|
||||
}
|
||||
// printf( "new touch down\n" );
|
||||
t2->x = x;
|
||||
t2->y = y;
|
||||
t2->down = true;
|
||||
t2->controlOwner = NULL;
|
||||
t2->stateCount = 1;
|
||||
|
||||
touchThisSequence[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Change any active touches to released if they weren't
|
||||
// in the touch set. This will happen if we forced a break because
|
||||
// a "moved" event was so large that it was very likely a release and
|
||||
// press of a different finger that happened to be in the same frame.
|
||||
for ( int i = 0 ; i < MAX_TOUCHES ; i++ ) {
|
||||
if ( sysTouches[i].down && !touchThisSequence[i] ) {
|
||||
printf( "clearing touch %i\n", i );
|
||||
sysTouches[i].down = false;
|
||||
sysTouches[i].stateCount = 0;
|
||||
touchCount--;
|
||||
}
|
||||
}
|
||||
|
||||
// toggle the console with four touches
|
||||
if ( touchCount == 4 && previousTouchCount != 4 ) {
|
||||
touchCount = 0; // won't get the releases, because the text field will eat them
|
||||
|
||||
if ( textField == nil ) {
|
||||
// do this before starting the textField, which
|
||||
// takes a long time
|
||||
// iphoneActivateConsole();
|
||||
|
||||
textField = [UITextField alloc];
|
||||
[textField initWithFrame:CGRectMake( 0, 0, 20, 20 ) ];
|
||||
[self addSubview:textField];
|
||||
[textField release];
|
||||
textField.hidden = true;
|
||||
textField.delegate = self;
|
||||
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
|
||||
textField.autocorrectionType = UITextAutocorrectionTypeNo;
|
||||
[textField becomeFirstResponder];
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
// the game is free to copy the touches now
|
||||
pthread_mutex_unlock( &eventMutex );
|
||||
|
||||
previousTouchCount = touchCount;
|
||||
}
|
||||
|
||||
|
||||
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
// printf( "touchesBegan\n" );
|
||||
[self handleTouches:event];
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
// printf( "touchesMoved\n" );
|
||||
[self handleTouches:event];
|
||||
}
|
||||
|
||||
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
// printf( "touchesEnded\n" );
|
||||
[self handleTouches:event];
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
// printf( "touchesCancelled\n" );
|
||||
[self handleTouches:event];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation EAGLView (UITextFieldDelegate)
|
||||
|
||||
char consoleCommand[1024];
|
||||
|
||||
- (BOOL)textFieldShouldReturn:(UITextField *)_textField
|
||||
{
|
||||
if ( eaglview->textField == nil ) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
// we can't just execute this, because we are running in another
|
||||
// thread, so fetch the line and the game will catch it next time
|
||||
// around
|
||||
|
||||
// lock the game out temporarily
|
||||
pthread_mutex_lock( &eventMutex );
|
||||
|
||||
const char *line = [ eaglview->textField.text UTF8String ];
|
||||
strncpy( consoleCommand, line, sizeof(consoleCommand)-1 );
|
||||
eaglview->textField.text = [ NSString stringWithUTF8String: "" ];
|
||||
|
||||
// put it away
|
||||
[textField resignFirstResponder];
|
||||
[textField removeFromSuperview];
|
||||
textField = nil;
|
||||
|
||||
// lock the game out temporarily
|
||||
pthread_mutex_unlock( &eventMutex );
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
const char * SysIPhoneGetConsoleTextField() {
|
||||
if ( eaglview->textField == nil ) {
|
||||
return "";
|
||||
}
|
||||
return [ eaglview->textField.text UTF8String ];
|
||||
}
|
||||
|
||||
void SysIPhoneSetConsoleTextField( const char * str) {
|
||||
assert( eaglview->textField != nil );
|
||||
eaglview->textField.text = [ NSString stringWithUTF8String: str ];
|
||||
}
|
||||
|
||||
void SysIPhoneSwapBuffers() {
|
||||
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
|
||||
}
|
||||
|
||||
void SysIPhoneOpenURL( const char *url ) {
|
||||
Com_Printf( "OpenURL char *: %s\n", url );
|
||||
|
||||
NSString *nss = [NSString stringWithCString: url encoding: NSASCIIStringEncoding];
|
||||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: nss]];
|
||||
}
|
||||
|
||||
void SysIPhoneSetUIKitOrientation( int isLandscapeRight ) {
|
||||
if ( isLandscapeRight ) {
|
||||
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
|
||||
} else {
|
||||
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key></key>
|
||||
<string></string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>${PRODUCT_NAME}_icon.png</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${PROFILE_PREFIX}.${PRODUCT_NAME:identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainWindow</string>
|
||||
<key>UIInterfaceOrientation</key>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<key>UIRequiresPersistentWiFi</key>
|
||||
<true/>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<true/>
|
||||
<key>UIPrerenderedIcon</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,233 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.03">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">528</int>
|
||||
<string key="IBDocument.SystemVersion">9G55</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">677</string>
|
||||
<string key="IBDocument.AppKitVersion">949.43</string>
|
||||
<string key="IBDocument.HIToolboxVersion">353.00</string>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="8"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBProxyObject" id="841351856">
|
||||
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
|
||||
</object>
|
||||
<object class="IBProxyObject" id="191355593">
|
||||
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
|
||||
</object>
|
||||
<object class="IBUICustomObject" id="664661524"/>
|
||||
<object class="IBUIWindow" id="380026005">
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">1316</int>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBUIView" id="773737154">
|
||||
<reference key="NSNextResponder" ref="380026005"/>
|
||||
<int key="NSvFlags">1298</int>
|
||||
<string key="NSFrameSize">{320, 480}</string>
|
||||
<reference key="NSSuperview" ref="380026005"/>
|
||||
<object class="NSColor" key="IBUIBackgroundColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MQA</bytes>
|
||||
<object class="NSColorSpace" key="NSCustomColorSpace">
|
||||
<int key="NSID">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSPSMatrix" key="NSFrameMatrix"/>
|
||||
<string key="NSFrameSize">{320, 480}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<object class="NSColor" key="IBUIBackgroundColor">
|
||||
<int key="NSColorSpace">1</int>
|
||||
<bytes key="NSRGB">MSAxIDEAA</bytes>
|
||||
</object>
|
||||
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
|
||||
<bool key="IBUIVisibleAtLaunch">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<object class="NSMutableArray" key="connectionRecords">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">delegate</string>
|
||||
<reference key="source" ref="841351856"/>
|
||||
<reference key="destination" ref="664661524"/>
|
||||
</object>
|
||||
<int key="connectionID">4</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">window</string>
|
||||
<reference key="source" ref="664661524"/>
|
||||
<reference key="destination" ref="380026005"/>
|
||||
</object>
|
||||
<int key="connectionID">5</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
||||
<string key="label">glView</string>
|
||||
<reference key="source" ref="664661524"/>
|
||||
<reference key="destination" ref="773737154"/>
|
||||
</object>
|
||||
<int key="connectionID">9</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<object class="NSArray" key="object" id="957960031">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">2</int>
|
||||
<reference key="object" ref="380026005"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="773737154"/>
|
||||
</object>
|
||||
<reference key="parent" ref="957960031"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-1</int>
|
||||
<reference key="object" ref="841351856"/>
|
||||
<reference key="parent" ref="957960031"/>
|
||||
<string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">3</int>
|
||||
<reference key="object" ref="664661524"/>
|
||||
<reference key="parent" ref="957960031"/>
|
||||
<string key="objectName">Game App Delegate</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">8</int>
|
||||
<reference key="object" ref="773737154"/>
|
||||
<reference key="parent" ref="380026005"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-2</int>
|
||||
<reference key="object" ref="191355593"/>
|
||||
<reference key="parent" ref="957960031"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>-1.CustomClassName</string>
|
||||
<string>-2.CustomClassName</string>
|
||||
<string>2.IBAttributePlaceholdersKey</string>
|
||||
<string>2.IBEditorWindowLastContentRect</string>
|
||||
<string>2.IBPluginDependency</string>
|
||||
<string>3.CustomClassName</string>
|
||||
<string>3.IBPluginDependency</string>
|
||||
<string>8.CustomClassName</string>
|
||||
<string>8.IBPluginDependency</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>UIApplication</string>
|
||||
<string>UIResponder</string>
|
||||
<object class="NSMutableDictionary">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<string>{{500, 343}, {320, 480}}</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>gameAppDelegate</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string>EAGLView</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="activeLocalization"/>
|
||||
<object class="NSMutableDictionary" key="localizations">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">10</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">EAGLView</string>
|
||||
<string key="superclassName">UIView</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">EAGLView.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">gameAppDelegate</string>
|
||||
<string key="superclassName">NSObject</string>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>glView</string>
|
||||
<string>window</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>EAGLView</string>
|
||||
<string>UIWindow</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">doomAppDelegate.h</string>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.LastKnownRelativeProjectPath">doom.xcodeproj</string>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
</data>
|
||||
</archive>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,383 @@
|
|||
/*
|
||||
|
||||
File: SoundEngine.h
|
||||
Abstract: These functions play background music tracks, multiple sound effects,
|
||||
and support stereo panning with a low-latency response.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
|
||||
("Apple") in consideration of your agreement to the following terms, and your
|
||||
use, installation, modification or redistribution of this Apple software
|
||||
constitutes acceptance of these terms. If you do not agree with these terms,
|
||||
please do not use, install, modify or redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and subject
|
||||
to these terms, Apple grants you a personal, non-exclusive license, under
|
||||
Apple's copyrights in this original Apple software (the "Apple Software"), to
|
||||
use, reproduce, modify and redistribute the Apple Software, with or without
|
||||
modifications, in source and/or binary forms; provided that if you redistribute
|
||||
the Apple Software in its entirety and without modifications, you must retain
|
||||
this notice and the following text and disclaimers in all such redistributions
|
||||
of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may be used
|
||||
to endorse or promote products derived from the Apple Software without specific
|
||||
prior written permission from Apple. Except as expressly stated in this notice,
|
||||
no other rights or licenses, express or implied, are granted by Apple herein,
|
||||
including but not limited to any patent rights that may be infringed by your
|
||||
derivative works or by other works in which the Apple Software may be
|
||||
incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
|
||||
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
|
||||
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
|
||||
COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
|
||||
DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
|
||||
CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
|
||||
APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2008 Apple Inc. All Rights Reserved.
|
||||
|
||||
*/
|
||||
|
||||
/*==================================================================================================
|
||||
SoundEngine.h
|
||||
==================================================================================================*/
|
||||
#if !defined(__SoundEngine_h__)
|
||||
#define __SoundEngine_h__
|
||||
|
||||
//==================================================================================================
|
||||
// Includes
|
||||
//==================================================================================================
|
||||
|
||||
// System Includes
|
||||
#ifndef WIN32
|
||||
#include <CoreAudio/CoreAudioTypes.h>
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
#else
|
||||
typedef int OSStatus;
|
||||
typedef int SInt32;
|
||||
typedef unsigned int UInt32;
|
||||
typedef float Float32;
|
||||
typedef unsigned char Boolean;
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//==================================================================================================
|
||||
// Sound Engine
|
||||
//==================================================================================================
|
||||
/*!
|
||||
@enum SoundEngine error codes
|
||||
@abstract These are the error codes returned from the SoundEngine API.
|
||||
@constant kSoundEngineErrUnitialized
|
||||
The SoundEngine has not been initialized. Use SoundEngine_Initialize().
|
||||
@constant kSoundEngineErrInvalidID
|
||||
The specified EffectID was not found. This can occur if the effect has not been loaded, or
|
||||
if an unloaded is trying to be accessed.
|
||||
@constant kSoundEngineErrFileNotFound
|
||||
The specified file was not found.
|
||||
@constant kSoundEngineErrInvalidFileFormat
|
||||
The format of the file is invalid. Effect data must be little-endian 8 or 16 bit LPCM.
|
||||
@constant kSoundEngineErrDeviceNotFound
|
||||
The output device was not found.
|
||||
|
||||
*/
|
||||
enum {
|
||||
kSoundEngineErrUnitialized = 1,
|
||||
kSoundEngineErrInvalidID = 2,
|
||||
kSoundEngineErrFileNotFound = 3,
|
||||
kSoundEngineErrInvalidFileFormat = 4,
|
||||
kSoundEngineErrDeviceNotFound = 5
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
@function SoundEngine_Initialize
|
||||
@abstract Initializes and sets up the sound engine. Calling after a previous initialize will
|
||||
reset the state of the SoundEngine, with all previous effects and music tracks
|
||||
erased. Note: This is not required, loading an effect or background track will
|
||||
initialize as necessary.
|
||||
@param inMixerOutputRate
|
||||
A Float32 that represents the output sample rate of the mixer unit. Setting this to
|
||||
0 will use the default rate (the sample rate of the device)
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_Initialize(Float32 inMixerOutputRate);
|
||||
|
||||
|
||||
OSStatus SoundEngine_Reactivate();
|
||||
|
||||
|
||||
/*!
|
||||
@function SoundEngine_Teardown
|
||||
@abstract Tearsdown the sound engine.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_Teardown();
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetMasterVolume
|
||||
@abstract Sets the overall volume of all sounds coming from the process
|
||||
@param inValue
|
||||
A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetMasterVolume(Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetListenerPosition
|
||||
@abstract Sets the position of the listener in the 3D space
|
||||
@param inX
|
||||
A Float32 that represents the listener's position along the X axis.
|
||||
@param inY
|
||||
A Float32 that represents the listener's position along the Y axis.
|
||||
@param inZ
|
||||
A Float32 that represents the listener's position along the Z axis.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetListenerPosition(Float32 inX, Float32 inY, Float32 inZ);
|
||||
OSStatus SoundEngine_SetListenerDirection(Float32 inX, Float32 inY, Float32 inZ);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetListenerGain
|
||||
@abstract Sets the gain of the listener. Must be >= 0.0
|
||||
@param inValue
|
||||
A Float32 that represents the listener's gain
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetListenerGain(Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_LoadBackgroundMusicTrack
|
||||
@abstract Tells the background music player which file to play
|
||||
@param inPath
|
||||
The absolute path to the file to play.
|
||||
@param inAddToQueue
|
||||
If true, file will be added to the current background music queue. If
|
||||
false, queue will be cleared and only loop the specified file.
|
||||
@param inLoadAtOnce
|
||||
If true, file will be loaded completely into memory. If false, data will be
|
||||
streamed from the file as needed. For games without large memory pressure and/or
|
||||
small background music files, this can save memory access and improve power efficiency
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_LoadBackgroundMusicTrack(const char* inPath, Boolean inAddToQueue, Boolean inLoadAtOnce);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_UnloadBackgroundMusicTrack
|
||||
@abstract Tells the background music player to release all resources and stop playing.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_UnloadBackgroundMusicTrack();
|
||||
|
||||
/*!
|
||||
@function SoundEngine_StartBackgroundMusic
|
||||
@abstract Tells the background music player to start playing.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_StartBackgroundMusic();
|
||||
|
||||
/*!
|
||||
@function SoundEngine_StopBackgroundMusic
|
||||
@abstract Tells the background music player to stop playing.
|
||||
@param inAddToQueue
|
||||
If true, playback will stop when all tracks have completed. If false, playback
|
||||
will stop immediately.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_StopBackgroundMusic(Boolean inStopAtEnd);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetBackgroundMusicVolume
|
||||
@abstract Sets the volume for the background music player
|
||||
@param inValue
|
||||
A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetBackgroundMusicVolume(Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_GetBackgroundMusicVolume
|
||||
@abstract Gets the volume for the background music player
|
||||
@result A Float32 representing the background music player volume, or 0 if it's not enabled
|
||||
*/
|
||||
Float32 SoundEngine_GetBackgroundMusicVolume();
|
||||
|
||||
/*!
|
||||
@function SoundEngine_LoadLoopingEffect
|
||||
@abstract Loads a sound effect from a file and return an ID to refer to that effect. Note: The files
|
||||
MUST all be in the same data format and sample rate
|
||||
@param inLoopFilePath
|
||||
The absolute path to the file to load. This is the file that will loop continually.
|
||||
@param inAttackFilePath
|
||||
The absolute path to the file to load. This will play once at the start of the effect.
|
||||
Set to NULL if no attack is desired, looping file will play immediately.
|
||||
@param inDecayFilePath
|
||||
The absolute path to the file to load. This will play once after looping has been ended.
|
||||
Triggered using SoundEngine_StopEffect with the inDoDecay set to true. Set to NULL if no
|
||||
decay is desired, looping file will stop immediately.
|
||||
@param outEffectID
|
||||
A UInt32 ID that refers to the effect.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_LoadLoopingEffect(const char* inLoopFilePath, const char* inAttackFilePath, const char* inDecayFilePath, UInt32* outEffectID);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_LoadEffect
|
||||
@abstract Loads a sound effect from a file and return an ID to refer to that effect.
|
||||
@param inPath
|
||||
The absolute path to the file to load.
|
||||
@param outEffectID
|
||||
A UInt32 ID that refers to the effect.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_LoadEffect(const char* inPath, UInt32* outEffectID);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_UnloadEffect
|
||||
@abstract Releases all resources associated with the given effect ID
|
||||
@param inEffectID
|
||||
The ID of the effect to unload.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_UnloadEffect(UInt32 inEffectID);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_StartEffect
|
||||
@abstract Starts playback of an effect
|
||||
@param inEffectID
|
||||
The ID of the effect to start.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_StartEffect(UInt32 inEffectID);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_StopEffect
|
||||
@abstract Stops playback of an effect
|
||||
@param inEffectID
|
||||
The ID of the effect to stop.
|
||||
@param inDoDecay
|
||||
Whether to play the decay file or stop immmediately (this is ignored
|
||||
for non-looping effects)
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_StopEffect(UInt32 inEffectID, Boolean inDoDecay);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_Vibrate
|
||||
@abstract Tells the device to vibrate
|
||||
*/
|
||||
#if TARGET_OS_IPHONE
|
||||
#define SoundEngine_Vibrate() AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetEffectPitch
|
||||
@abstract Applies pitch shifting to an effect
|
||||
@param inEffectID
|
||||
The ID of the effect to adjust
|
||||
@param inValue
|
||||
A Float32 that represents the pitch scalar, with 1.0 being unchanged. Must
|
||||
be greater than 0.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetEffectPitch(UInt32 inEffectID, Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetEffectVolume
|
||||
@abstract Sets the volume for an effect
|
||||
@param inEffectID
|
||||
The ID of the effect to adjust
|
||||
@param inValue
|
||||
A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetEffectLevel(UInt32 inEffectID, Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetEffectPosition
|
||||
@abstract Tells the engine whether a given effect should loop when played or if it should
|
||||
play through just once and stop.
|
||||
@param inEffectID
|
||||
The ID of the effect to adjust
|
||||
@param inX
|
||||
A Float32 that represents the effect's position along the X axis. Maximum distance
|
||||
is 100000.0 (absolute, not per axis), reference distance (distance from which gain
|
||||
begins to attenuate) is 1.0
|
||||
@param inY
|
||||
A Float32 that represents the effect's position along the Y axis. Maximum distance
|
||||
is 100000.0 (absolute, not per axis), reference distance (distance from which gain
|
||||
begins to attenuate) is 1.0
|
||||
@param inZ
|
||||
A Float32 that represents the effect's position along the Z axis. Maximum distance
|
||||
is 100000.0 by default (absolute, not per axis), reference distance (distance from
|
||||
which gain begins to attenuate) is 1.0
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetEffectPosition(UInt32 inEffectID, Float32 inX, Float32 inY, Float32 inZ);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetEffectsVolume
|
||||
@abstract Sets the overall volume for the effects
|
||||
@param inValue
|
||||
A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetEffectsVolume(Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_GetEffectsVolume
|
||||
@abstract Gets the overall volume for the effects
|
||||
@result A Float32 representing the effects volume, or 0 if it's disabled
|
||||
*/
|
||||
Float32 SoundEngine_GetEffectsVolume();
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetMaxDistance
|
||||
@abstract Sets the maximum distance for effect attenuation. Gain will attenuate between the
|
||||
reference distance and the maximum distance, after which gain will be 0.0
|
||||
@param inValue
|
||||
A Float32 that represents the level. Must be greater than 0.0.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetMaxDistance(Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetReferenceDistance
|
||||
@abstract Sets the distance at which effect gain attenuation begins. It will attenuate between
|
||||
the reference distance and the maximum distance. Sounds closer than the reference
|
||||
distance will have no attenuation applied
|
||||
@param inValue
|
||||
A Float32 that represents the level. Must be greater than 0.0.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetReferenceDistance(Float32 inValue);
|
||||
|
||||
/*!
|
||||
@function SoundEngine_SetEffectReferenceDistance
|
||||
@abstract Sets the distance at which effect gain attenuation begins. It will attenuate between
|
||||
the reference distance and the maximum distance. Sounds closer than the reference
|
||||
distance will have no attenuation applied
|
||||
@param inEffectId
|
||||
The sound engine effect Id
|
||||
@param inValue
|
||||
A Float32 that represents the level. Must be greater than 0.0.
|
||||
@result A OSStatus indicating success or failure.
|
||||
*/
|
||||
OSStatus SoundEngine_SetEffectReferenceDistance(UInt32 inEffectID, Float32 inValue);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
|
||||
Copyright (C) 2009 Id Software, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// generated by fontimg
|
||||
//
|
||||
|
||||
// struct GlyphRect { unsigned short x0, y0, x1, y1; float xoff, yoff, xadvance; };
|
||||
GlyphRect glyphRects[] = {
|
||||
/* ' ' */ { 2, 2, 2, 2, 0.000000, 0.000000, 7.958042 },
|
||||
/* '!' */ { 6, 2, 9, 22, 2.250000, -20.750000, 7.958042 },
|
||||
/* '"' */ { 14, 2, 21, 9, 1.250000, -20.750000, 10.167832 },
|
||||
/* '#' */ { 26, 2, 41, 23, 0.250000, -21.000000, 15.930070 },
|
||||
/* '$' */ { 46, 2, 59, 27, 1.000000, -22.500000, 15.930070 },
|
||||
/* '%' */ { 64, 2, 86, 24, 1.500000, -21.000000, 25.468531 },
|
||||
/* '&' */ { 92, 2, 109, 23, 1.000000, -21.000000, 19.104895 },
|
||||
/* ''' */ { 114, 2, 117, 9, 1.250000, -20.750000, 5.468532 },
|
||||
/* '(' */ { 122, 2, 129, 29, 1.500000, -21.000000, 9.538462 },
|
||||
/* ')' */ { 134, 2, 141, 29, 1.500000, -21.000000, 9.538462 },
|
||||
/* '*' */ { 146, 2, 155, 11, 0.750000, -21.000000, 11.146853 },
|
||||
/* '+' */ { 160, 2, 173, 15, 1.500000, -17.000000, 16.727272 },
|
||||
/* ',' */ { 178, 2, 181, 9, 2.250000, -3.000000, 7.958042 },
|
||||
/* '-' */ { 186, 2, 194, 4, 0.750000, -8.750000, 9.538462 },
|
||||
/* '.' */ { 198, 2, 201, 5, 2.500000, -3.000000, 7.958042 },
|
||||
/* '/' */ { 206, 2, 214, 23, 0.000000, -21.000000, 7.958042 },
|
||||
/* '0' */ { 218, 2, 231, 23, 1.000000, -20.750000, 15.930070 },
|
||||
/* '1' */ { 236, 2, 243, 22, 3.000000, -20.750000, 15.930070 },
|
||||
/* '2' */ { 2, 34, 15, 54, 0.750000, -20.750000, 15.930070 },
|
||||
/* '3' */ { 20, 34, 33, 55, 1.000000, -20.750000, 15.930070 },
|
||||
/* '4' */ { 38, 34, 52, 54, 0.250000, -20.750000, 15.930070 },
|
||||
/* '5' */ { 58, 34, 72, 54, 1.000000, -20.250000, 15.930070 },
|
||||
/* '6' */ { 76, 34, 89, 55, 1.000000, -20.750000, 15.930070 },
|
||||
/* '7' */ { 94, 34, 107, 54, 1.250000, -20.250000, 15.930070 },
|
||||
/* '8' */ { 112, 34, 125, 55, 1.000000, -20.750000, 15.930070 },
|
||||
/* '9' */ { 130, 34, 143, 55, 1.000000, -20.750000, 15.930070 },
|
||||
/* ':' */ { 148, 34, 151, 49, 2.500000, -15.000000, 7.958042 },
|
||||
/* ';' */ { 156, 34, 159, 53, 2.250000, -15.000000, 7.958042 },
|
||||
/* '<' */ { 164, 34, 177, 48, 1.500000, -17.250000, 16.727272 },
|
||||
/* '=' */ { 182, 34, 195, 42, 1.500000, -14.500000, 16.727272 },
|
||||
/* '>' */ { 200, 34, 213, 48, 1.500000, -17.250000, 16.727272 },
|
||||
/* '?' */ { 218, 34, 231, 55, 1.250000, -21.000000, 15.930070 },
|
||||
/* '@' */ { 2, 60, 28, 87, 1.500000, -21.000000, 29.076923 },
|
||||
/* 'A' */ { 34, 60, 53, 80, -0.250000, -20.750000, 19.104895 },
|
||||
/* 'B' */ { 58, 60, 73, 80, 2.000000, -20.750000, 19.104895 },
|
||||
/* 'C' */ { 78, 60, 96, 81, 1.250000, -21.000000, 20.685314 },
|
||||
/* 'D' */ { 102, 60, 119, 80, 2.000000, -20.750000, 20.685314 },
|
||||
/* 'E' */ { 124, 60, 139, 80, 2.250000, -20.750000, 19.104895 },
|
||||
/* 'F' */ { 144, 60, 158, 80, 2.250000, -20.750000, 17.496504 },
|
||||
/* 'G' */ { 162, 60, 181, 81, 1.500000, -21.000000, 22.279720 },
|
||||
/* 'H' */ { 186, 60, 202, 80, 2.250000, -20.750000, 20.685314 },
|
||||
/* 'I' */ { 208, 60, 211, 80, 2.500000, -20.750000, 7.958042 },
|
||||
/* 'J' */ { 216, 60, 227, 81, 0.750000, -20.750000, 14.321678 },
|
||||
/* 'K' */ { 232, 60, 249, 80, 2.000000, -20.750000, 19.104895 },
|
||||
/* 'L' */ { 2, 92, 15, 112, 2.000000, -20.750000, 15.930070 },
|
||||
/* 'M' */ { 20, 92, 39, 112, 2.000000, -20.750000, 23.860140 },
|
||||
/* 'N' */ { 44, 92, 60, 112, 2.000000, -20.750000, 20.685314 },
|
||||
/* 'O' */ { 66, 92, 85, 113, 1.250000, -21.000000, 22.279720 },
|
||||
/* 'P' */ { 90, 92, 106, 112, 2.000000, -20.750000, 19.104895 },
|
||||
/* 'Q' */ { 110, 92, 130, 114, 1.000000, -21.000000, 22.279720 },
|
||||
/* 'R' */ { 136, 92, 154, 112, 2.250000, -20.750000, 20.685314 },
|
||||
/* 'S' */ { 160, 92, 176, 113, 1.250000, -21.000000, 19.104895 },
|
||||
/* 'T' */ { 182, 92, 198, 112, 0.500000, -20.750000, 17.496504 },
|
||||
/* 'U' */ { 204, 92, 220, 113, 2.250000, -20.750000, 20.685314 },
|
||||
/* 'V' */ { 226, 92, 245, 112, 0.000000, -20.750000, 19.104895 },
|
||||
/* 'W' */ { 2, 120, 28, 140, 0.250000, -20.750000, 27.034966 },
|
||||
/* 'X' */ { 34, 120, 53, 140, 0.000000, -20.750000, 19.104895 },
|
||||
/* 'Y' */ { 58, 120, 77, 140, 0.000000, -20.750000, 19.104895 },
|
||||
/* 'Z' */ { 82, 120, 98, 140, 0.500000, -20.750000, 17.496504 },
|
||||
/* '[' */ { 104, 120, 109, 146, 1.750000, -20.750000, 7.958042 },
|
||||
/* '\' */ { 114, 120, 122, 141, 0.000000, -21.000000, 7.958042 },
|
||||
/* ']' */ { 126, 120, 131, 146, 0.500000, -20.750000, 7.958042 },
|
||||
/* '^' */ { 136, 120, 148, 131, 0.750000, -21.000000, 13.440559 },
|
||||
/* '_' */ { 152, 120, 169, 122, -0.500000, 3.750000, 15.930070 },
|
||||
/* '`' */ { 174, 120, 179, 124, 1.000000, -20.750000, 9.538462 },
|
||||
/* 'a' */ { 184, 120, 197, 135, 1.000000, -15.250000, 15.930070 },
|
||||
/* 'b' */ { 202, 120, 215, 141, 1.750000, -20.750000, 15.930070 },
|
||||
/* 'c' */ { 220, 120, 233, 135, 1.000000, -15.250000, 14.321678 },
|
||||
/* 'd' */ { 238, 120, 251, 141, 0.750000, -20.750000, 15.930070 },
|
||||
/* 'e' */ { 2, 152, 15, 167, 1.000000, -15.250000, 15.930070 },
|
||||
/* 'f' */ { 20, 152, 28, 173, 0.250000, -21.000000, 7.958042 },
|
||||
/* 'g' */ { 34, 152, 47, 173, 0.750000, -15.250000, 15.930070 },
|
||||
/* 'h' */ { 52, 152, 64, 172, 1.750000, -20.750000, 15.930070 },
|
||||
/* 'i' */ { 70, 152, 72, 172, 1.750000, -20.750000, 6.363636 },
|
||||
/* 'j' */ { 78, 152, 84, 179, -1.500000, -20.750000, 6.363636 },
|
||||
/* 'k' */ { 88, 152, 100, 172, 1.750000, -20.750000, 14.321678 },
|
||||
/* 'l' */ { 106, 152, 108, 172, 1.750000, -20.750000, 6.363636 },
|
||||
/* 'm' */ { 114, 152, 134, 167, 1.750000, -15.250000, 23.860140 },
|
||||
/* 'n' */ { 140, 152, 152, 167, 1.750000, -15.250000, 15.930070 },
|
||||
/* 'o' */ { 158, 152, 172, 167, 0.750000, -15.250000, 15.930070 },
|
||||
/* 'p' */ { 178, 152, 191, 173, 1.750000, -15.250000, 15.930070 },
|
||||
/* 'q' */ { 196, 152, 209, 173, 1.000000, -15.250000, 15.930070 },
|
||||
/* 'r' */ { 214, 152, 222, 167, 1.750000, -15.250000, 9.538462 },
|
||||
/* 's' */ { 228, 152, 240, 167, 0.750000, -15.250000, 14.321678 },
|
||||
/* 't' */ { 246, 152, 253, 172, 0.500000, -20.250000, 7.958042 },
|
||||
/* 'u' */ { 2, 184, 14, 199, 1.750000, -15.000000, 15.930070 },
|
||||
/* 'v' */ { 20, 184, 33, 199, 0.250000, -15.000000, 14.321678 },
|
||||
/* 'w' */ { 38, 184, 58, 199, 0.000000, -15.000000, 20.685314 },
|
||||
/* 'x' */ { 64, 184, 78, 199, 0.000000, -15.000000, 14.321678 },
|
||||
/* 'y' */ { 84, 184, 98, 205, 0.250000, -15.000000, 14.321678 },
|
||||
/* 'z' */ { 102, 184, 115, 199, 0.500000, -15.000000, 14.321678 },
|
||||
/* '{' */ { 120, 184, 128, 211, 0.750000, -21.000000, 9.566434 },
|
||||
/* '|' */ { 134, 184, 136, 211, 2.500000, -21.000000, 7.440559 },
|
||||
/* '}' */ { 142, 184, 150, 211, 0.500000, -21.000000, 9.566434 },
|
||||
/* '~' */ { 156, 184, 170, 188, 1.000000, -12.500000, 16.727272 },
|
||||
/* '' */ { 176, 184, 190, 202, 3.500000, -18.000000, 21.482517 }
|
||||
};
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* cmd.c
|
||||
* doom
|
||||
*
|
||||
* Created by John Carmack on 4/14/09.
|
||||
* Copyright 2009 id Software. All rights reserved.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "../doomiphone.h"
|
||||
|
||||
typedef struct cmd_function_s {
|
||||
struct cmd_function_s *next;
|
||||
const char *name;
|
||||
int hashid;
|
||||
xcommand_t function;
|
||||
} cmd_function_t;
|
||||
|
||||
|
||||
#define MAX_STRING_TOKENS 16
|
||||
#define MAX_STRING_CHARS 1024
|
||||
|
||||
int cmd_argc;
|
||||
char *cmd_argv[ MAX_STRING_TOKENS ];
|
||||
|
||||
cmd_function_t *cmd_functions; // possible commands to execute
|
||||
|
||||
int Cmd_Argc( void ) {
|
||||
return cmd_argc;
|
||||
}
|
||||
|
||||
const char *Cmd_Argv( int arg ) {
|
||||
if( arg >= cmd_argc ) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return cmd_argv[ arg ];
|
||||
}
|
||||
|
||||
|
||||
void Cmd_TokenizeString( const char *text ) {
|
||||
static char *stringCopy;
|
||||
|
||||
// clear the args from the last string
|
||||
// This better not be called recursively...
|
||||
if ( stringCopy ) {
|
||||
free( stringCopy );
|
||||
stringCopy = NULL;
|
||||
}
|
||||
|
||||
cmd_argc = 0;
|
||||
|
||||
if( ! text ) {
|
||||
return;
|
||||
}
|
||||
|
||||
stringCopy = strdup( text );
|
||||
char *strval = stringCopy;
|
||||
|
||||
while( 1 ) {
|
||||
char *start = strsep( &strval," \t\r\n");
|
||||
if ( !start ) {
|
||||
break;
|
||||
}
|
||||
if ( start[0] != 0 ) {
|
||||
cmd_argv[cmd_argc] = start;
|
||||
if ( ++cmd_argc == MAX_STRING_TOKENS ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Cmd_ListCommands_f() {
|
||||
for( cmd_function_t *cmd = cmd_functions ; cmd ; cmd = cmd->next ) {
|
||||
Com_Printf( "%s\n", cmd->name );
|
||||
}
|
||||
}
|
||||
|
||||
void Cmd_AddCommand( const char *cmd_name, xcommand_t function ) {
|
||||
cmd_function_t *cmd;
|
||||
int hashid;
|
||||
|
||||
hashid = HashString( cmd_name );
|
||||
|
||||
// fail if the command already exists
|
||||
for( cmd = cmd_functions ; cmd ; cmd = cmd->next ) {
|
||||
if( hashid == cmd->hashid && !strcmp( cmd_name, cmd->name ) ) {
|
||||
Com_Printf( "Cmd_AddCommand: \"%s\" already defined\n", cmd_name );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cmd = malloc( sizeof( cmd_function_t ) );
|
||||
cmd->name = cmd_name;
|
||||
cmd->hashid = hashid;
|
||||
cmd->function = function;
|
||||
cmd->next = cmd_functions;
|
||||
cmd_functions = cmd;
|
||||
|
||||
}
|
||||
|
||||
void Cmd_ExecuteString( const char *str ) {
|
||||
int l = strlen( str );
|
||||
if ( str[l-1] == '\n' ) {
|
||||
char *stripped = alloca( l+1 );
|
||||
strcpy( stripped, str );
|
||||
str = stripped;
|
||||
stripped[l-1] = 0;
|
||||
}
|
||||
|
||||
Com_Printf( "%s\n", str );
|
||||
Cmd_TokenizeString( str );
|
||||
|
||||
const char *arg0 = Cmd_Argv( 0 );
|
||||
int hashid = HashString( arg0 );
|
||||
|
||||
// check commands first
|
||||
for( cmd_function_t *cmd = cmd_functions ; cmd ; cmd = cmd->next ) {
|
||||
if( hashid == cmd->hashid && !strcmp( arg0, cmd->name ) ) {
|
||||
cmd->function();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// then check cvars
|
||||
cvar_t *cvar = Cvar_FindVar( arg0 );
|
||||
if ( cvar ) {
|
||||
Cvar_Set( arg0, Cmd_Argv( 1 ) );
|
||||
return;
|
||||
}
|
||||
Com_Printf( "Unknown command: %s\n", arg0 );
|
||||
}
|
||||
|
||||
// execute each line of the config file
|
||||
void Cmd_ExecuteFile( const char *fullPathName ) {
|
||||
Com_Printf( "Executing command file '%s'\n", fullPathName );
|
||||
FILE *f = fopen( fullPathName, "rb" );
|
||||
if ( !f ) {
|
||||
Com_Printf( "Failed to open.\n" );
|
||||
return;
|
||||
}
|
||||
char line[1024];
|
||||
while( fgets( line, sizeof( line ), f ) ) {
|
||||
Cmd_ExecuteString( line );
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
|
|
@ -0,0 +1,374 @@
|
|||
/*
|
||||
|
||||
Copyright (C) 2004 Michael Liebscher
|
||||
Copyright (C) 1997-2001 Id Software, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General License for more details.
|
||||
|
||||
You should have received a copy of the GNU General License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include "../doomiphone.h"
|
||||
|
||||
|
||||
cvar_t *cvar_vars;
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_FindVar -Return cvar;
|
||||
|
||||
Parameters: var_name -[in] Name of cvar to lookup.
|
||||
|
||||
Returns: NULL if cvar not found, otherwise returns the cvar.
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
cvar_t *Cvar_FindVar( const char *var_name )
|
||||
{
|
||||
cvar_t *var;
|
||||
int hashid;
|
||||
|
||||
hashid = HashString( var_name );
|
||||
|
||||
for( var = cvar_vars ; var ; var = var->next )
|
||||
{
|
||||
if( hashid == var->hashid && !strcasecmp( var_name, var->name ) )
|
||||
{
|
||||
return var;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_VariableValue -Get value of cvar.
|
||||
|
||||
Parameters: var_name -[in] Name of cvar to get value.
|
||||
|
||||
Returns: 0 if not found, other the value of the cvar.
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
float Cvar_VariableValue( const char *var_name )
|
||||
{
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar( var_name );
|
||||
if( ! var )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (float)atof( var->string );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_VariableString -Get cvar variable as string.
|
||||
|
||||
Parameters: var_name -[in] Name of cvar to get value.
|
||||
|
||||
Returns: Blank string on error, otherwise value string.
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
char *Cvar_VariableString( const char *var_name )
|
||||
{
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar( var_name );
|
||||
if( ! var )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return var->string;
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_CompleteVariable -Complete cvar string name.
|
||||
|
||||
Parameters: partial -[in] Partial name of string to look up.
|
||||
|
||||
Returns: NULL if partial string not found, otherwise the complete
|
||||
string name.
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
char *Cvar_CompleteVariable( const char *partial )
|
||||
{
|
||||
cvar_t *cvar;
|
||||
size_t len;
|
||||
|
||||
len = strlen( partial );
|
||||
|
||||
if( ! len )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Check partial match.
|
||||
//
|
||||
for( cvar = cvar_vars ; cvar ; cvar = cvar->next )
|
||||
{
|
||||
if( ! strncmp( partial, cvar->name, len ) )
|
||||
{
|
||||
return cvar->name;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_Get -Get cvar structure.
|
||||
|
||||
Parameters:
|
||||
var_name -[in] the name of the cvar variable.
|
||||
var_value -[in] string value of the cvar variable.
|
||||
flags -[in] see CVARFlags for more information.
|
||||
|
||||
Returns: NULL on error, otherwise valid pointer to cvar_t structure.
|
||||
|
||||
Notes:
|
||||
If the variable already exists, the value will not be set and
|
||||
the flags will be or'ed.
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
cvar_t *Cvar_Get( const char *var_name, const char *var_value, CVARFlags flags ) {
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar( var_name );
|
||||
if( var ) {
|
||||
var->flags |= flags;
|
||||
return var;
|
||||
}
|
||||
|
||||
if( ! var_value ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
var = malloc( sizeof( *var ) );
|
||||
var->name = strdup( var_name );
|
||||
var->string = strdup( var_value );
|
||||
var->defaultString = strdup( var_value );
|
||||
var->hashid = HashString( var_name );
|
||||
var->modified = true;
|
||||
var->value = (float)atof( var->string );
|
||||
|
||||
// link the variable in
|
||||
var->next = cvar_vars;
|
||||
cvar_vars = var;
|
||||
|
||||
var->flags = flags;
|
||||
|
||||
return var;
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function:
|
||||
|
||||
Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
void Cvar_Set( const char *var_name, const char *value ) {
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar( var_name );
|
||||
if( ! var ) {
|
||||
Com_Printf( "Cvar '%s' doesn't exist\n", var_name );
|
||||
return;
|
||||
}
|
||||
|
||||
if( var->flags & CVAR_NOSET ) {
|
||||
Com_Printf( "%s is write protected.\n", var_name );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( ! strcmp( value, var->string ) ) {
|
||||
return; // not changed
|
||||
}
|
||||
|
||||
var->modified = true;
|
||||
|
||||
free( var->string ); // free the old value string
|
||||
|
||||
var->string = strdup( value );
|
||||
var->value = (float)atof( var->string );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function:
|
||||
|
||||
Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
void Cvar_SetValue( const char *var_name, float value )
|
||||
{
|
||||
char val[ 32 ];
|
||||
|
||||
if( value == (int)value )
|
||||
{
|
||||
snprintf( val, sizeof( val ), "%i", (int)value );
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( val, sizeof( val ), "%f", value );
|
||||
}
|
||||
|
||||
Cvar_Set( var_name, val );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_Command -Handles variable inspection and changing from
|
||||
the console.
|
||||
|
||||
Parameters: Nothing.
|
||||
|
||||
Returns: false if variable not found, otherwise true.
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
boolean Cvar_Command( void )
|
||||
{
|
||||
cvar_t *v;
|
||||
|
||||
// check variables
|
||||
v = Cvar_FindVar( Cmd_Argv( 0 ) );
|
||||
if( ! v )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// perform a variable print or set
|
||||
if( Cmd_Argc() == 1 )
|
||||
{
|
||||
Com_Printf( "\"%s\" is \"%s\"\n", v->name, v->string );
|
||||
return true;
|
||||
}
|
||||
|
||||
Cvar_Set( v->name, Cmd_Argv( 1 ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_WriteVariables -Appends lines containing "set variable value"
|
||||
for all variables with the archive flag set
|
||||
to true.
|
||||
|
||||
Parameters:
|
||||
|
||||
Returns: Nothing.
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
void Cvar_WriteVariables( const char *path )
|
||||
{
|
||||
cvar_t *var;
|
||||
char buffer[1024];
|
||||
FILE *f;
|
||||
|
||||
f = fopen( path, "a" );
|
||||
for( var = cvar_vars ; var ; var = var->next )
|
||||
{
|
||||
if( var->flags & CVAR_ARCHIVE )
|
||||
{
|
||||
snprintf( buffer, sizeof( buffer ), "set %s %s\n", var->name, var->string );
|
||||
fprintf( f, "%s", buffer );
|
||||
}
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Function: Cvar_List_f -Print all cvars to the console.
|
||||
|
||||
Parameters: Nothing.
|
||||
|
||||
Returns: Nothing.
|
||||
|
||||
Notes:
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
void Cvar_List_f( void )
|
||||
{
|
||||
cvar_t *var;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
for( var = cvar_vars ; var ; var = var->next, ++i )
|
||||
{
|
||||
if( var->flags & CVAR_ARCHIVE )
|
||||
{
|
||||
Com_Printf ("*");
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_Printf (" ");
|
||||
}
|
||||
|
||||
|
||||
Com_Printf (" %s \"%s\"\n", var->name, var->string);
|
||||
}
|
||||
|
||||
Com_Printf ("%i cvars\n", i);
|
||||
}
|
||||
|
||||
|
||||
void Cvar_Reset_f( void ) {
|
||||
for( cvar_t *var = cvar_vars ; var ; var = var->next ) {
|
||||
Cvar_Set( var->name, var->defaultString );
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue