First blood

This commit is contained in:
vladislav.khorev committed 2013-01-19 20:02:34 +00:00
1 parent 04f270f322
commit 5720f8322b
250 files changed
+33215

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
#include "include/Engine.h"
namespace SE
{
TSoundManagerAndroid::TSoundManagerAndroid()
{
}
TSoundManagerAndroid::~TSoundManagerAndroid()
{
JniReleaseAllSoundsAndMusic();
}
void TSoundManagerAndroid::LoadSound(const std::string& soundFileName)
{
JniLoadSound(soundFileName);
}
void TSoundManagerAndroid::PlaySound(const std::string& soundName)
{
JniPlaySound(soundName);
}
void TSoundManagerAndroid::LoadMusic(const std::string& musicFileName)
{
//dummy. Not needed
}
void TSoundManagerAndroid::PlayMusic(const std::string& musicName)
{
JniPlayMusic(musicName);
}
void TSoundManagerAndroid::PlayMusicLooped(const std::string& musicName)
{
JniPlayMusicLooped(musicName);
}
void TSoundManagerAndroid::StopMusic(const std::string& musicName)
{
JniStopMusic();
}
} //namespace SE
@@ -0,0 +1,92 @@
#ifndef NOSOUND
#include "include/SoundManager/SoundManagerDataTypes.h"
namespace SE
{
extern "C"
{
size_t OggFileRead(void* toBuf, size_t varsize, size_t varcount, void* fromBuf);
int OggFileSeek(void *fromBuf, ogg_int64_t offset, int whence);
long OggFileTell(void *fromBuf);
}
size_t OggFileRead(void* toBuf, size_t varsize, size_t varcount, void* fromBuf)
{
TOggCallbackFileBuffer& callbackFileBuffer = *(reinterpret_cast<TOggCallbackFileBuffer*>(fromBuf));
if (callbackFileBuffer.FilePos+varsize*varcount > callbackFileBuffer.FileSize)
{
size_t dataLeft = callbackFileBuffer.FileSize - callbackFileBuffer.FilePos;
if (dataLeft != 0)
{
memcpy(toBuf, &callbackFileBuffer.FileData[callbackFileBuffer.FilePos], dataLeft);
}
callbackFileBuffer.FilePos += dataLeft;
return dataLeft;
}
else
{
memcpy(toBuf, &callbackFileBuffer.FileData[callbackFileBuffer.FilePos], varsize*varcount);
callbackFileBuffer.FilePos += varsize*varcount;
return varsize*varcount;
}
}
int OggFileSeek(void *fromBuf, ogg_int64_t offset, int whence)
{
TOggCallbackFileBuffer& callbackFileBuffer = *(reinterpret_cast<TOggCallbackFileBuffer*>(fromBuf));
size_t newPos;
switch(whence)
{
case SEEK_SET:
newPos = static_cast<size_t>(offset);
break;
case SEEK_CUR:
newPos = static_cast<size_t>(callbackFileBuffer.FilePos + offset);
break;
case SEEK_END:
newPos = static_cast<size_t>(callbackFileBuffer.FileSize - 1 - offset);
break;
};
callbackFileBuffer.FilePos = newPos;
return 0;
}
long OggFileTell(void *fromBuf)
{
TOggCallbackFileBuffer& callbackFileBuffer = *(reinterpret_cast<TOggCallbackFileBuffer*>(fromBuf));
return callbackFileBuffer.FilePos;
}
ov_callbacks OggCallbacks = {
(size_t (*)(void *, size_t, size_t, void *)) OggFileRead,
(int (*)(void *, ogg_int64_t, int)) OggFileSeek,
(int (*)(void *)) NULL,
(long (*)(void *)) OggFileTell
};
#endif //NOSOUND
} //namespace SE
+132
View File
@@ -0,0 +1,132 @@
//
// SoundManagerIos.mm
// Halibut Engine
//
// Created by vvv ооо on 21.07.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <string>
#include <map>
#import <Foundation/Foundation.h>
#import "PASoundMgr.h"
#import "PASoundListener.h"
#import "PASoundSource.h"
#include "include/Utils/Utils.h"
#include "include/SoundManager/SoundManagerIos.h"
namespace SE
{
std::map<std::string, PASoundSource*> AudioSourceMap;
TSoundManagerIos::TSoundManagerIos()
{
[PASoundMgr sharedSoundManager];
[[[PASoundMgr sharedSoundManager] listener] setPosition:CGPointMake(0, 0)];
}
TSoundManagerIos::~TSoundManagerIos()
{
for (std::map<std::string, PASoundSource*>::iterator i = AudioSourceMap.begin(); i != AudioSourceMap.end(); ++i)
{
//[i->second release];
}
AudioSourceMap.clear();
}
void TSoundManagerIos::LoadSound(const std::string& soundFileName)
{
LoadMusic(soundFileName);
}
void TSoundManagerIos::PlaySound(const std::string& soundName)
{
PlayMusic(soundName);
}
void TSoundManagerIos::LoadMusicLooped(const std::string& musicFileName)
{
//Hack for ios, see below
std::string musicName = GetFileName(musicFileName);
std::string fullFileName = GetPathToResources() + musicFileName;
NSString* nsFileName = [NSString stringWithCString:fullFileName.c_str() encoding:NSUTF8StringEncoding];
NSString* nsFileNameWithoutExt = [nsFileName stringByDeletingPathExtension];
NSString* nsFileExt = [nsFileName pathExtension];
if (AudioSourceMap.count(musicName) > 0)
{
//[AudioSourceMap[musicName] release];
}
/*AudioSourceMap[musicFileName] = [[[PASoundMgr sharedSoundManager] addSound:@"trance-loop" withExtension:@"ogg" position:CGPointMake(0, 0) looped:NO] retain];*/
AudioSourceMap[musicName] = [[PASoundMgr sharedSoundManager] addSound:nsFileNameWithoutExt withExtension:nsFileExt position:CGPointMake(0, 0) looped:YES];
}
void TSoundManagerIos::LoadMusic(const std::string& musicFileName)
{
std::string musicName = GetFileName(musicFileName);
std::string fullFileName = GetPathToResources() + musicFileName;
NSString* nsFileName = [NSString stringWithCString:fullFileName.c_str() encoding:NSUTF8StringEncoding];
NSString* nsFileNameWithoutExt = [nsFileName stringByDeletingPathExtension];
NSString* nsFileExt = [nsFileName pathExtension];
if (AudioSourceMap.count(musicName) > 0)
{
//[AudioSourceMap[musicName] release];
}
/*AudioSourceMap[musicFileName] = [[[PASoundMgr sharedSoundManager] addSound:@"trance-loop" withExtension:@"ogg" position:CGPointMake(0, 0) looped:NO] retain];*/
AudioSourceMap[musicName] = [[PASoundMgr sharedSoundManager] addSound:nsFileNameWithoutExt withExtension:nsFileExt position:CGPointMake(0, 0) looped:NO];
}
void TSoundManagerIos::PlayMusic(const std::string& musicName)
{
if (AudioSourceMap.count(musicName) == 0)
{
throw ErrorToLog("Sound or music not exists: "+musicName);
}
AudioSourceMap[musicName].looped = false;
[AudioSourceMap[musicName] playAtListenerPosition];
}
void TSoundManagerIos::PlayMusicLooped(const std::string& musicName)
{
if (AudioSourceMap.count(musicName) == 0)
{
throw ErrorToLog("Sound or music not exists: "+musicName);
}
AudioSourceMap[musicName].looped = true;
[AudioSourceMap[musicName] playAtListenerPosition];
}
void TSoundManagerIos::StopMusic(const std::string& musicName)
{
if (AudioSourceMap.count(musicName) == 0)
{
throw ErrorToLog("Sound or music not exists: "+musicName);
}
[AudioSourceMap[musicName] stop];
}
} //namespace SE
File diff suppressed because it is too large. Load diff