Permalink
Browse files

PlayBook modifications required to run.

  • Loading branch information...
jnicholl committed Oct 3, 2011
1 parent 35b3893 commit ac9246f81da5c48dfabe536342ffd48393997f03
View
@@ -304,7 +304,7 @@ class BuildAirportWindow : public PickerWindowBase {
const AirportSpec *as = AirportSpec::Get(i);
if (!as->enabled) continue;
- size->width = max(size->width, GetStringBoundingBox(as->name).width);
+ size->width = ::max(size->width, GetStringBoundingBox(as->name).width);
}
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
View
@@ -67,7 +67,7 @@ static FORCEINLINE T min(const T a, const T b)
*/
static FORCEINLINE int min(const int a, const int b)
{
- return min<int>(a, b);
+ return ::min<int>(a, b);
}
/**
@@ -81,7 +81,7 @@ static FORCEINLINE int min(const int a, const int b)
*/
static FORCEINLINE uint minu(const uint a, const uint b)
{
- return min<uint>(a, b);
+ return ::min<uint>(a, b);
}
/**
@@ -230,7 +230,7 @@ static FORCEINLINE uint16 ClampToU16(const uint64 a)
* match for min(uint64, uint) than uint64 min(uint64, uint64). As such we
* need to cast the UINT16_MAX to prevent MSVC from displaying its
* infinite loads of warnings. */
- return (uint16)min<uint64>(a, (uint64)UINT16_MAX);
+ return (uint16)::min<uint64>(a, (uint64)UINT16_MAX);
}
/**
View
@@ -51,7 +51,7 @@ DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index)
assert(index >= this->size);
assert(index < Tmax_size);
- size_t new_size = min(Tmax_size, Align(index + 1, Tgrowth_step));
+ size_t new_size = ::min(Tmax_size, Align(index + 1, Tgrowth_step));
this->data = ReallocT(this->data, new_size);
MemSetT(this->data + this->size, 0, new_size - this->size);
@@ -99,7 +99,7 @@ DEFINE_POOL_METHOD(inline void *)::AllocateItem(size_t size, size_t index)
{
assert(this->data[index] == NULL);
- this->first_unused = max(this->first_unused, index + 1);
+ this->first_unused = ::max(this->first_unused, index + 1);
this->items++;
Titem *item;
@@ -180,7 +180,7 @@ DEFINE_POOL_METHOD(void)::FreeItem(size_t index)
free(this->data[index]);
}
this->data[index] = NULL;
- this->first_free = min(this->first_free, index);
+ this->first_free = ::min(this->first_free, index);
this->items--;
if (!this->cleaning) Titem::PostDestructor(index);
}
View
@@ -0,0 +1,13 @@
+/*
+ * endian_target.h
+ *
+ * Created on: Jun 7, 2011
+ * Author: jnicholl
+ */
+
+#ifndef ENDIAN_TARGET_H_
+#define ENDIAN_TARGET_H_
+
+#define TTD_ENDIAN TTD_LITTLE_ENDIAN
+
+#endif /* ENDIAN_TARGET_H_ */
View
@@ -22,7 +22,7 @@
#include <Path.h>
#include <storage/FindDirectory.h>
#else
-#if defined(OPENBSD) || defined(DOS)
+#if defined(OPENBSD) || defined(DOS) || defined(__QNXNTO__)
#include <unistd.h>
#endif
#include <pwd.h>
@@ -532,8 +532,8 @@ static void TarAddLink(const std::string &srcParam, const std::string &destParam
std::string src = srcParam;
std::string dest = destParam;
/* Tar internals assume lowercase */
- std::transform(src.begin(), src.end(), src.begin(), tolower);
- std::transform(dest.begin(), dest.end(), dest.begin(), tolower);
+ std::transform(src.begin(), src.end(), src.begin(), std::tolower);
+ std::transform(dest.begin(), dest.end(), dest.begin(), std::tolower);
TarFileList::iterator dest_file = _tar_filelist.find(dest);
if (dest_file != _tar_filelist.end()) {
@@ -949,7 +949,11 @@ bool DoScanWorkingDirectory()
void DetermineBasePaths(const char *exe)
{
char tmp[MAX_PATH];
-#if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR)
+#if defined(__PLAYBOOK__)
+ snprintf(tmp, MAX_PATH, "." PATHSEP "data");
+ AppendPathSeparator(tmp, MAX_PATH);
+ _searchpaths[SP_PERSONAL_DIR] = strdup(tmp);
+#elif defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR)
_searchpaths[SP_PERSONAL_DIR] = NULL;
#else
#ifdef __HAIKU__
@@ -1008,6 +1012,10 @@ void DetermineBasePaths(const char *exe)
#if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2)
_searchpaths[SP_INSTALLATION_DIR] = NULL;
#else
+
+#if defined(__PLAYBOOK__)
+#define GLOBAL_DATA_DIR "app/native"
+#endif
snprintf(tmp, MAX_PATH, "%s", GLOBAL_DATA_DIR);
AppendPathSeparator(tmp, MAX_PATH);
_searchpaths[SP_INSTALLATION_DIR] = strdup(tmp);
@@ -1078,7 +1086,7 @@ void DeterminePaths(const char *exe)
_hotkeys_file = str_fmt("%shotkeys.cfg", _personal_dir);
/* Make the necessary folders */
-#if !defined(__MORPHOS__) && !defined(__AMIGA__) && defined(WITH_PERSONAL_DIR)
+#if defined(__PLAYBOOK__) || (!defined(__MORPHOS__) && !defined(__AMIGA__) && defined(WITH_PERSONAL_DIR))
FioCreateDirectory(_personal_dir);
#endif
View
@@ -173,13 +173,15 @@ void GamelogPrint(GamelogPrintProc *proc)
char buf[GAMELOG_BUF_LEN];
GrfIDMapping grf_names;
+ //fprintf(stderr, "GamelogPrint start\n");
proc("---- gamelog start ----");
const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
assert((uint)la->at < GLAT_END);
+ //fprintf(stderr, "GamelogPrint tick\n");
snprintf(buf, GAMELOG_BUF_LEN, "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
proc(buf);
@@ -188,6 +190,7 @@ void GamelogPrint(GamelogPrintProc *proc)
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
_dbgofs = 0;
AddDebugText(buf, " ");
+ //fprintf(stderr, "GamelogPrint change (ct=%d)\n", lc->ct);
switch (lc->ct) {
default: NOT_REACHED();
@@ -318,6 +321,7 @@ void GamelogPrint(GamelogPrintProc *proc)
}
proc("---- gamelog end ----");
+ //fprintf(stderr, "GamelogPrint end\n");
}
View
@@ -33,6 +33,10 @@ struct MixerChannel {
};
static MixerChannel _channels[8];
+#if defined(__PLAYBOOK__)
+static MixerChannel _musicChannel;
+void (*musicCallback)(int16*,uint);
+#endif
static uint32 _play_rate = 11025;
static uint32 _max_size = UINT_MAX;
@@ -152,6 +156,11 @@ void MxMixSamples(void *buffer, uint samples)
if (mc->samples_left == 0) MxCloseChannel(mc);
}
}
+#if defined(__PLAYBOOK__)
+ if (_musicChannel.active) {
+ (*musicCallback)((int16*)buffer, samples);
+ }
+#endif
}
MixerChannel *MxAllocateChannel()
@@ -167,6 +176,35 @@ MixerChannel *MxAllocateChannel()
return NULL;
}
+#if defined(__PLAYBOOK__)
+MixerChannel *MxAllocateMusicChannel(void (*callback)(int16*,uint))
+{
+ musicCallback = callback;
+ if (!_musicChannel.active) {
+ return &_musicChannel;
+ }
+ return NULL;
+}
+
+void MxDeactivateMusic()
+{
+ _musicChannel.active = false;
+}
+
+void MxMixMusic(int16* buffer, uint samples, const int16 *music)
+{
+ int volume_left = _musicChannel.volume_left;
+ int volume_right = _musicChannel.volume_right;
+ do {
+ buffer[0] = Clamp(buffer[0] + (*music * volume_left >> 16), -MAX_VOLUME, MAX_VOLUME);
+ music++;
+ buffer[1] = Clamp(buffer[0] + (*music * volume_right >> 16), -MAX_VOLUME, MAX_VOLUME);
+ music++;
+ buffer += 2;
+ } while (--samples > 0);
+}
+#endif
+
void MxSetChannelRawSrc(MixerChannel *mc, int8 *mem, size_t size, uint rate, bool is16bit)
{
mc->memory = mem;
View
@@ -22,4 +22,12 @@ void MxSetChannelRawSrc(MixerChannel *mc, int8 *mem, size_t size, uint rate, boo
void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan);
void MxActivateChannel(MixerChannel*);
+#if defined(__PLAYBOOK__)
+MixerChannel *MxAllocateMusicChannel(void (*callback)(int16*,uint));
+void MxMixMusic(int16* buffer, uint samples, const int16 *music);
+void MxDeactivateMusic();
+//int8* MxGetMusicPtr();
+//void MxSetMusicChannelSrc(size_t size, uint rate, bool is16bit);
+#endif
+
#endif /* MIXER_H */
View
@@ -26,6 +26,10 @@
#include <pspaudiolib.h>
#endif /* PSP */
+#if defined(__PLAYBOOK__)
+#include "../mixer.h"
+#endif /* PLAYBOOK */
+
/** The state of playing. */
enum MidiState {
MIDI_STOPPED = 0,
@@ -40,6 +44,9 @@ static struct {
MidiState status;
uint32 song_length;
uint32 song_position;
+#if defined(__PLAYBOOK__)
+ MixerChannel *channel;
+#endif
} _midi; ///< Metadata about the midi we're playing.
#if defined(PSP)
@@ -52,9 +59,46 @@ static void AudioOutCallback(void *buf, unsigned int _reqn, void *userdata)
}
#endif /* PSP */
+#if defined(__PLAYBOOK__)
+static void MusicCallback(int16* buffer, uint samples)
+{
+ if (_midi.status == MIDI_PLAYING) {
+ static int8 mem[4096];
+ int8* memory = &mem[0];
+ bool allocated = false;
+ if (samples*4 != 4096) {
+ memory = (int8*)malloc(samples*4);
+ allocated = true;
+ }
+
+ size_t size = mid_song_read_wave(_midi.song, memory, samples*4);
+ bool deactivate = false;
+ if (samples > size/4) {
+ samples = size/4;
+ deactivate = true;
+ }
+ MxMixMusic(buffer, samples, (const int16 *)memory);
+ if (allocated)
+ free(memory);
+
+ if (deactivate) {
+ MxDeactivateMusic();
+ }
+ } else {
+ MxDeactivateMusic();
+ }
+}
+#endif /* PLAYBOOK */
/** Factory for the libtimidity driver. */
static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity;
+#ifdef __PLAYBOOK__
+void ForceInitMusicDriver_Timidity()
+{
+ fprintf(stderr, "Initializing Timidity music driver\n");
+}
+#endif
+
const char *MusicDriver_LibTimidity::Start(const char * const *param)
{
_midi.status = MIDI_STOPPED;
@@ -79,6 +123,15 @@ const char *MusicDriver_LibTimidity::Start(const char * const *param)
_midi.options.buffer_size = _midi.options.rate;
#endif
+#if defined(__PLAYBOOK__)
+ _midi.channel = MxAllocateMusicChannel(&MusicCallback);
+ if (_midi.channel == NULL) {
+ return "Failed to allocate music channel";
+ } else {
+ MxSetChannelVolume(_midi.channel, 16384, 0.5);
+ }
+#endif
+
#if defined(PSP)
pspAudioInit();
pspAudioSetChannelCallback(_midi.options.channels, &AudioOutCallback, NULL);
@@ -115,6 +168,11 @@ void MusicDriver_LibTimidity::PlaySong(const char *filename)
mid_song_start(_midi.song);
_midi.status = MIDI_PLAYING;
+#if defined(__PLAYBOOK__)
+ if (_midi.channel != NULL) {
+ MxActivateChannel(_midi.channel);
+ }
+#endif
}
void MusicDriver_LibTimidity::StopSong()
@@ -123,6 +181,7 @@ void MusicDriver_LibTimidity::StopSong()
/* mid_song_free cannot handle NULL! */
if (_midi.song != NULL) mid_song_free(_midi.song);
_midi.song = NULL;
+ MxDeactivateMusic();
}
bool MusicDriver_LibTimidity::IsSongPlaying()
@@ -141,4 +200,6 @@ bool MusicDriver_LibTimidity::IsSongPlaying()
void MusicDriver_LibTimidity::SetVolume(byte vol)
{
if (_midi.song != NULL) mid_song_set_volume(_midi.song, vol);
+ if (_midi.channel != NULL)
+ MxSetChannelVolume(_midi.channel, vol * 128, 0.5);
}
View
@@ -25,7 +25,11 @@ class MusicDriver_Null: public MusicDriver {
/* virtual */ void StopSong() { }
+#ifdef __PLAYBOOK__
+ /* virtual */ bool IsSongPlaying() { return false; }
+#else
/* virtual */ bool IsSongPlaying() { return true; }
+#endif
/* virtual */ void SetVolume(byte vol) { }
/* virtual */ const char *GetName() const { return "null"; }
@@ -128,8 +128,8 @@ static inline void OTTDfreeaddrinfo(struct addrinfo *ai)
#endif /* WIN32 */
/* UNIX stuff */
-#if defined(UNIX) && !defined(__OS2__)
-# if defined(OPENBSD) || defined(__NetBSD__)
+#if defined(__QNXNTO__) || (defined(UNIX) && !defined(__OS2__))
+# if defined(OPENBSD) || defined(__NetBSD__) || defined(__PLAYBOOK__)
# define AI_ADDRCONFIG 0
# endif
# define SOCKET int
View
@@ -293,7 +293,7 @@ struct NewGRFInspectWindow : Window {
{
if (widget != NIW_MAINPANEL) return;
- resize->height = max(11, FONT_HEIGHT_NORMAL + 1);
+ resize->height = ::max(11, FONT_HEIGHT_NORMAL + 1);
resize->width = 1;
size->height = 5 * resize->height + TOP_OFFSET + BOTTOM_OFFSET;
@@ -641,7 +641,7 @@ struct SpriteAlignerWindow : Window {
{
if (widget != SAW_LIST) return;
- resize->height = max(11, FONT_HEIGHT_NORMAL + 1);
+ resize->height = ::max(11, FONT_HEIGHT_NORMAL + 1);
resize->width = 1;
/* Resize to about 200 pixels (for the preview) */
@@ -676,7 +676,7 @@ struct SpriteAlignerWindow : Window {
int step_size = nwid->resize_y;
SmallVector<SpriteID, 256> &list = _newgrf_debug_sprite_picker.sprites;
- int max = min<int>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), list.Length());
+ int max = ::min<int>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), list.Length());
int y = r.top + WD_FRAMERECT_TOP;
for (int i = this->vscroll->GetPosition(); i < max; i++) {
Oops, something went wrong.

0 comments on commit ac9246f

Please sign in to comment.