Changeset - r17629:21e9dfd343cd
[Not reviewed]
master
0 51 0
rubidium - 13 years ago 2011-05-02 16:14:23
rubidium@openttd.org
(svn r22410) -Document: some more bits ;)
51 files changed with 241 insertions and 39 deletions:
0 comments (0 inline, 0 general)
src/debug.h
Show inline comments
 
@@ -52,47 +52,52 @@
 
	extern int _debug_desync_level;
 
	extern int _debug_console_level;
 

	
 
	void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
 
#endif /* NO_DEBUG_MESSAGES */
 

	
 
void SetDebugString(const char *s);
 
const char *GetDebugString();
 

	
 
/* Shorter form for passing filename and linenumber */
 
#define FILE_LINE __FILE__, __LINE__
 

	
 
/**
 
 * Get the tick counter from the CPU (high precision timing).
 
 * @return The count.
 
 */
 
uint64 ottd_rdtsc();
 

	
 
/* Used for profiling
 
 *
 
 * Usage:
 
 * TIC();
 
 *   --Do your code--
 
 * TOC("A name", 1);
 
 *
 
 * When you run the TIC() / TOC() multiple times, you can increase the '1'
 
 *  to only display average stats every N values. Some things to know:
 
 *
 
 * for (int i = 0; i < 5; i++) {
 
 *   TIC();
 
 *     --Do yuor code--
 
 *   TOC("A name", 5);
 
 * }
 
 *
 
 * Is the correct usage for multiple TIC() / TOC() calls.
 
 *
 
 * TIC() / TOC() creates its own block, so make sure not the mangle
 
 *  it with another block.
 
 **/
 
#define TIC() {\
 
	extern uint64 ottd_rdtsc();\
 
	uint64 _xxx_ = ottd_rdtsc();\
 
	static uint64 __sum__ = 0;\
 
	static uint32 __i__ = 0;
 

	
 
#define TOC(str, count)\
 
	__sum__ += ottd_rdtsc() - _xxx_;\
 
	if (++__i__ == count) {\
 
		DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, __sum__, __sum__/(double)__i__);\
 
		__i__ = 0;\
 
		__sum__ = 0;\
 
	}\
 
}
src/music.cpp
Show inline comments
 
@@ -2,37 +2,38 @@
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file music.cpp The songs that OpenTTD knows. */
 

	
 
#include "stdafx.h"
 

	
 
/* The type of set we're replacing */
 
/** The type of set we're replacing */
 
#define SET_TYPE "music"
 
#include "base_media_func.h"
 

	
 
INSTANTIATE_BASE_MEDIA_METHODS(BaseMedia<MusicSet>, MusicSet)
 

	
 
/** Names corresponding to the music set's files */
 
static const char * const _music_file_names[] = {
 
	"theme",
 
	"old_0", "old_1", "old_2", "old_3", "old_4", "old_5", "old_6", "old_7", "old_8", "old_9",
 
	"new_0", "new_1", "new_2", "new_3", "new_4", "new_5", "new_6", "new_7", "new_8", "new_9",
 
	"ezy_0", "ezy_1", "ezy_2", "ezy_3", "ezy_4", "ezy_5", "ezy_6", "ezy_7", "ezy_8", "ezy_9",
 
};
 
/** Make sure we aren't messing things up. */
 
assert_compile(lengthof(_music_file_names) == NUM_SONGS_AVAILABLE);
 

	
 
template <class T, size_t Tnum_files, Subdirectory Tsubdir>
 
/* static */ const char * const *BaseSet<T, Tnum_files, Tsubdir>::file_names = _music_file_names;
 

	
 
template <class Tbase_set>
 
/* static */ const char *BaseMedia<Tbase_set>::GetExtension()
 
{
 
	return ".obm"; // OpenTTD Base Music
 
}
 

	
 
template <class Tbase_set>
src/music/allegro_m.h
Show inline comments
 
@@ -5,40 +5,42 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file allegro_m.h Base support for playing music via allegro. */
 

	
 
#ifndef MUSIC_ALLEGRO_H
 
#define MUSIC_ALLEGRO_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** Allegro's music player. */
 
class MusicDriver_Allegro: public MusicDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void PlaySong(const char *filename);
 

	
 
	/* virtual */ void StopSong();
 

	
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "allegro"; }
 
};
 

	
 
/** Factory for allegro's music player. */
 
class FMusicDriver_Allegro: public MusicDriverFactory<FMusicDriver_Allegro> {
 
public:
 
#if !defined(WITH_SDL) && defined(WITH_ALLEGRO)
 
	/* If SDL is not compiled in but Allegro is, chances are quite big
 
	 * that Allegro is going to be used. Then favour this sound driver
 
	 * over extmidi because with extmidi we get crashes. */
 
	static const int priority = 9;
 
#else
 
	static const int priority = 2;
 
#endif
 

	
 
	/* virtual */ const char *GetName() { return "allegro"; }
src/music/bemidi.cpp
Show inline comments
 
@@ -7,26 +7,28 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file bemidi.cpp Support for BeOS midi. */
 

	
 
#include "../stdafx.h"
 
#include "../openttd.h"
 
#include "bemidi.h"
 

	
 
/* BeOS System Includes */
 
#include <MidiSynthFile.h>
 

	
 
/** The file we're playing. */
 
static BMidiSynthFile midiSynthFile;
 

	
 
/** Factory for BeOS' midi player. */
 
static FMusicDriver_BeMidi iFMusicDriver_BeMidi;
 

	
 
const char *MusicDriver_BeMidi::Start(const char * const *parm)
 
{
 
	return NULL;
 
}
 

	
 
void MusicDriver_BeMidi::Stop()
 
{
 
	midiSynthFile.UnloadFile();
 
}
 

	
src/music/bemidi.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file bemidi.h Base of BeOS Midi support. */
 

	
 
#ifndef MUSIC_BEMIDI_H
 
#define MUSIC_BEMIDI_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** The midi player for BeOS. */
 
class MusicDriver_BeMidi: public MusicDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void PlaySong(const char *filename);
 

	
 
	/* virtual */ void StopSong();
 

	
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "bemidi"; }
 
};
 

	
 
/** Factory for the BeOS midi player. */
 
class FMusicDriver_BeMidi: public MusicDriverFactory<FMusicDriver_BeMidi> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "bemidi"; }
 
	/* virtual */ const char *GetDescription() { return "BeOS MIDI Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new MusicDriver_BeMidi(); }
 
};
 

	
 
#endif /* MUSIC_BEMIDI_H */
src/music/dmusic.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file dmusic.h Base of playing music via DirectMusic. */
 

	
 
#ifndef MUSIC_DMUSIC_H
 
#define MUSIC_DMUSIC_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** Music player making use of DirectX. */
 
class MusicDriver_DMusic: public MusicDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void PlaySong(const char *filename);
 

	
 
	/* virtual */ void StopSong();
 

	
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "dmusic"; }
 
};
 

	
 
/** Factory for the DirectX music player. */
 
class FMusicDriver_DMusic: public MusicDriverFactory<FMusicDriver_DMusic> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "dmusic"; }
 
	/* virtual */ const char *GetDescription() { return "DirectMusic MIDI Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new MusicDriver_DMusic(); }
 
};
 

	
 
#endif /* MUSIC_DMUSIC_H */
src/music/extmidi.cpp
Show inline comments
 
@@ -17,27 +17,29 @@
 
#include "../video/video_driver.hpp"
 
#include "../gfx_func.h"
 
#include "extmidi.h"
 
#include <fcntl.h>
 
#include <sys/types.h>
 
#include <sys/wait.h>
 
#include <unistd.h>
 
#include <signal.h>
 
#include <sys/stat.h>
 
#include <errno.h>
 

	
 
#ifndef EXTERNAL_PLAYER
 
/** The default external midi player. */
 
#define EXTERNAL_PLAYER "timidity"
 
#endif
 

	
 
/** Factory for the midi player that uses external players. */
 
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
 

	
 
const char *MusicDriver_ExtMidi::Start(const char * const * parm)
 
{
 
	if (strcmp(_video_driver->GetName(), "allegro") == 0 ||
 
			strcmp(_sound_driver->GetName(), "allegro") == 0) {
 
		return "the extmidi driver does not work when Allegro is loaded.";
 
	}
 

	
 
	const char *command = GetDriverParam(parm, "cmd");
 
	if (StrEmpty(command)) command = EXTERNAL_PLAYER;
 

	
src/music/libtimidity.cpp
Show inline comments
 
@@ -17,49 +17,51 @@
 
#include <fcntl.h>
 
#include <sys/types.h>
 
#include <sys/wait.h>
 
#include <unistd.h>
 
#include <signal.h>
 
#include <sys/stat.h>
 
#include <errno.h>
 
#include <timidity.h>
 
#if defined(PSP)
 
#include <pspaudiolib.h>
 
#endif /* PSP */
 

	
 
/** The state of playing. */
 
enum MidiState {
 
	MIDI_STOPPED = 0,
 
	MIDI_PLAYING = 1,
 
};
 

	
 
static struct {
 
	MidIStream *stream;
 
	MidSongOptions options;
 
	MidSong *song;
 

	
 
	MidiState status;
 
	uint32 song_length;
 
	uint32 song_position;
 
} _midi;
 
} _midi; ///< Metadata about the midi we're playing.
 

	
 
#if defined(PSP)
 
static void AudioOutCallback(void *buf, unsigned int _reqn, void *userdata)
 
{
 
	memset(buf, 0, _reqn * PSP_NUM_AUDIO_CHANNELS);
 
	if (_midi.status == MIDI_PLAYING) {
 
		mid_song_read_wave(_midi.song, buf, _reqn * PSP_NUM_AUDIO_CHANNELS);
 
	}
 
}
 
#endif /* PSP */
 

	
 
/** Factory for the libtimidity driver. */
 
static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity;
 

	
 
const char *MusicDriver_LibTimidity::Start(const char * const *param)
 
{
 
	_midi.status = MIDI_STOPPED;
 
	_midi.song = NULL;
 

	
 
	if (mid_init(param == NULL ? NULL : const_cast<char *>(param[0])) < 0) {
 
		/* If init fails, it can be because no configuration was found.
 
		 *  If it was not forced via param, try to load it without a
 
		 *  configuration. Who knows that works. */
 
		if (param != NULL || mid_init_no_config() < 0) {
src/music/libtimidity.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file libtimidity.h Base for LibTimidity music playback. */
 

	
 
#ifndef MUSIC_LIBTIMIDITY_H
 
#define MUSIC_LIBTIMIDITY_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** Music driver making use of libtimidity. */
 
class MusicDriver_LibTimidity: public MusicDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void PlaySong(const char *filename);
 

	
 
	/* virtual */ void StopSong();
 

	
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "libtimidity"; }
 
};
 

	
 
/** Factory for the libtimidity driver. */
 
class FMusicDriver_LibTimidity: public MusicDriverFactory<FMusicDriver_LibTimidity> {
 
public:
 
	static const int priority = 5;
 
	/* virtual */ const char *GetName() { return "libtimidity"; }
 
	/* virtual */ const char *GetDescription() { return "LibTimidity MIDI Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new MusicDriver_LibTimidity(); }
 
};
 

	
 
#endif /* MUSIC_LIBTIMIDITY_H */
src/music/music_driver.hpp
Show inline comments
 
@@ -5,38 +5,59 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file music_driver.hpp Base for all music playback. */
 

	
 
#ifndef MUSIC_MUSIC_DRIVER_HPP
 
#define MUSIC_MUSIC_DRIVER_HPP
 

	
 
#include "../driver.h"
 

	
 
/** Driver for all music playback. */
 
class MusicDriver: public Driver {
 
public:
 
	/**
 
	 * Play a particular song.
 
	 * @param filename The name of file with the song to play.
 
	 */
 
	virtual void PlaySong(const char *filename) = 0;
 

	
 
	/**
 
	 * Stop playing the current song.
 
	 */
 
	virtual void StopSong() = 0;
 

	
 
	/**
 
	 * Are we currently playing a song?
 
	 * @return True if a song is being played.
 
	 */
 
	virtual bool IsSongPlaying() = 0;
 

	
 
	/**
 
	 * Set the volume, if possible.
 
	 * @param vol The new volume.
 
	 */
 
	virtual void SetVolume(byte vol) = 0;
 
};
 

	
 
/** Base of the factory for the music drivers. */
 
class MusicDriverFactoryBase: public DriverFactoryBase {
 
};
 

	
 
/**
 
 * Factory for the music drivers.
 
 * @tparam T The type of the music factory to register.
 
 */
 
template <class T>
 
class MusicDriverFactory: public MusicDriverFactoryBase {
 
public:
 
	MusicDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_MUSIC, ((T *)this)->priority); }
 

	
 
	/**
 
	 * Get the long, human readable, name for the Driver-class.
 
	 */
 
	const char *GetName();
 
};
 

	
 
extern MusicDriver *_music_driver;
src/music/null_m.cpp
Show inline comments
 
@@ -3,14 +3,14 @@
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file null_m.cpp The music playback that is silent. */
 

	
 
#include "../stdafx.h"
 
#include "null_m.h"
 

	
 
/** The factory for the music player that does nothing. */
 
static FMusicDriver_Null iFMusicDriver_Null;
 

	
src/music/null_m.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file null_m.h Base for the silent music playback. */
 

	
 
#ifndef MUSIC_NULL_H
 
#define MUSIC_NULL_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** The music player that does nothing. */
 
class MusicDriver_Null: public MusicDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param) { return NULL; }
 

	
 
	/* virtual */ void Stop() { }
 

	
 
	/* virtual */ void PlaySong(const char *filename) { }
 

	
 
	/* virtual */ void StopSong() { }
 

	
 
	/* virtual */ bool IsSongPlaying() { return true; }
 

	
 
	/* virtual */ void SetVolume(byte vol) { }
 
	/* virtual */ const char *GetName() const { return "null"; }
 
};
 

	
 
/** Factory for the null music player. */
 
class FMusicDriver_Null: public MusicDriverFactory<FMusicDriver_Null> {
 
public:
 
	static const int priority = 1;
 
	/* virtual */ const char *GetName() { return "null"; }
 
	/* virtual */ const char *GetDescription() { return "Null Music Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new MusicDriver_Null(); }
 
};
 

	
 
#endif /* MUSIC_NULL_H */
src/music/os2_m.cpp
Show inline comments
 
@@ -20,34 +20,40 @@
 
#include <stdarg.h>
 
#include <os2.h>
 
#include <os2me.h>
 

	
 
/**********************
 
 * OS/2 MIDI PLAYER
 
 **********************/
 

	
 
/* Interesting how similar the MCI API in OS/2 is to the Win32 MCI API,
 
 * eh? Anyone would think they both came from the same place originally! ;)
 
 */
 

	
 
/**
 
 * Send a midi command.
 
 * @param cmd The command to send.
 
 * @return The result of sending it.
 
 */
 
static long CDECL MidiSendCommand(const char *cmd, ...)
 
{
 
	va_list va;
 
	char buf[512];
 
	va_start(va, cmd);
 
	vseprintf(buf, lastof(buf), cmd, va);
 
	va_end(va);
 
	return mciSendString(buf, NULL, 0, NULL, 0);
 
}
 

	
 
/** OS/2's music player's factory. */
 
static FMusicDriver_OS2 iFMusicDriver_OS2;
 

	
 
void MusicDriver_OS2::PlaySong(const char *filename)
 
{
 
	MidiSendCommand("close all");
 

	
 
	if (MidiSendCommand("open %s type sequencer alias song", filename) != 0) {
 
		return;
 
	}
 

	
 
	MidiSendCommand("play song from 0");
 
}
src/music/os2_m.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file os2_m.h Base for OS2 music playback. */
 

	
 
#ifndef MUSIC_OS2_H
 
#define MUSIC_OS2_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** OS/2's music player. */
 
class MusicDriver_OS2: public MusicDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void PlaySong(const char *filename);
 

	
 
	/* virtual */ void StopSong();
 

	
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "os2"; }
 
};
 

	
 
/** Factory for OS/2's music player. */
 
class FMusicDriver_OS2: public MusicDriverFactory<FMusicDriver_OS2> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "os2"; }
 
	/* virtual */ const char *GetDescription() { return "OS/2 Music Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new MusicDriver_OS2(); }
 
};
 

	
 
#endif /* MUSIC_OS2_H */
src/music/win32_m.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file win32_m.h Base for Windows music playback. */
 

	
 
#ifndef MUSIC_WIN32_H
 
#define MUSIC_WIN32_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** The Windows music player. */
 
class MusicDriver_Win32: public MusicDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void PlaySong(const char *filename);
 

	
 
	/* virtual */ void StopSong();
 

	
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "win32"; }
 
};
 

	
 
/** Factory for Windows' music player. */
 
class FMusicDriver_Win32: public MusicDriverFactory<FMusicDriver_Win32> {
 
public:
 
	static const int priority = 5;
 
	/* virtual */ const char *GetName() { return "win32"; }
 
	/* virtual */ const char *GetDescription() { return "Win32 Music Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new MusicDriver_Win32(); }
 
};
 

	
 
#endif /* MUSIC_WIN32_H */
src/network/network_command.cpp
Show inline comments
 
@@ -266,24 +266,25 @@ static void DistributeCommandPacket(Comm
 
static void DistributeQueue(CommandQueue *queue, const NetworkClientSocket *owner)
 
{
 
	int to_go = _settings_client.network.commands_per_frame;
 

	
 
	CommandPacket *cp;
 
	while (--to_go >= 0 && (cp = queue->Pop(true)) != NULL) {
 
		DistributeCommandPacket(*cp, owner);
 
		NetworkAdminCmdLogging(owner, cp);
 
		free(cp);
 
	}
 
}
 

	
 
/** Distribute the commands of ourself and the clients. */
 
void NetworkDistributeCommands()
 
{
 
	/* First send the server's commands. */
 
	DistributeQueue(&_local_wait_queue, NULL);
 

	
 
	/* Then send the queues of the others. */
 
	NetworkClientSocket *cs;
 
	FOR_ALL_CLIENT_SOCKETS(cs) {
 
		DistributeQueue(&cs->incoming_queue, cs);
 
	}
 
}
 

	
src/network/network_gamelist.cpp
Show inline comments
 
@@ -16,25 +16,27 @@
 

	
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "../window_func.h"
 
#include "../thread/thread.h"
 
#include "network_internal.h"
 
#include "network_udp.h"
 
#include "network_gamelist.h"
 
#include "../newgrf_text.h"
 

	
 
NetworkGameList *_network_game_list = NULL;
 

	
 
/** Mutex for handling delayed insertion/querying of servers. */
 
static ThreadMutex *_network_game_list_mutex = ThreadMutex::New();
 
/** The games to insert when the GUI thread has time for us. */
 
static NetworkGameList *_network_game_delayed_insertion_list = NULL;
 

	
 
/**
 
 * Add a new item to the linked gamelist, but do it delayed in the next tick
 
 * or so to prevent race conditions.
 
 * @param item the item to add. Will be freed once added.
 
 */
 
void NetworkGameListAddItemDelayed(NetworkGameList *item)
 
{
 
	_network_game_list_mutex->BeginCritical();
 
	item->next = _network_game_delayed_insertion_list;
 
	_network_game_delayed_insertion_list = item;
 
@@ -63,25 +65,24 @@ static void NetworkGameListHandleDelayed
 
			if (item->manually) NetworkRebuildHostList();
 
			UpdateNetworkGameWindow(false);
 
		}
 
		free(ins_item);
 
	}
 
	_network_game_list_mutex->EndCritical();
 
}
 

	
 
/**
 
 * Add a new item to the linked gamelist. If the IP and Port match
 
 * return the existing item instead of adding it again
 
 * @param address the address of the to-be added item
 
 * @param port the port the server is running on
 
 * @return a point to the newly added or already existing item
 
 */
 
NetworkGameList *NetworkGameListAddItem(NetworkAddress address)
 
{
 
	const char *hostname = address.GetHostname();
 

	
 
	/* Do not query the 'any' address. */
 
	if (StrEmpty(hostname) ||
 
			strcmp(hostname, "0.0.0.0") == 0 ||
 
			strcmp(hostname, "::") == 0) {
 
		return NULL;
 
	}
src/network/network_type.h
Show inline comments
 
@@ -63,50 +63,53 @@ struct NetworkCompanyStats {
 
	uint16 num_station[NETWORK_VEH_END];            ///< How many stations are there of this type?
 
	bool ai;                                        ///< Is this company an AI
 
};
 

	
 
/** Some state information of a company, especially for servers */
 
struct NetworkCompanyState {
 
	char password[NETWORK_PASSWORD_LENGTH];         ///< The password for the company
 
	uint16 months_empty;                            ///< How many months the company is empty
 
};
 

	
 
struct NetworkClientInfo;
 

	
 
/** The type of password we're asking for. */
 
enum NetworkPasswordType {
 
	NETWORK_GAME_PASSWORD,
 
	NETWORK_COMPANY_PASSWORD,
 
	NETWORK_GAME_PASSWORD,    ///< The password of the game.
 
	NETWORK_COMPANY_PASSWORD, ///< The password of the company.
 
};
 

	
 
/** Destination of our chat messages. */
 
enum DestType {
 
	DESTTYPE_BROADCAST, ///< Send message/notice to all clients (All)
 
	DESTTYPE_TEAM,      ///< Send message/notice to everyone playing the same company (Team)
 
	DESTTYPE_CLIENT,    ///< Send message/notice to only a certain client (Private)
 
};
 

	
 
/** Actions that can be used for NetworkTextMessage */
 
enum NetworkAction {
 
	NETWORK_ACTION_JOIN,
 
	NETWORK_ACTION_LEAVE,
 
	NETWORK_ACTION_SERVER_MESSAGE,
 
	NETWORK_ACTION_CHAT,
 
	NETWORK_ACTION_CHAT_COMPANY,
 
	NETWORK_ACTION_CHAT_CLIENT,
 
	NETWORK_ACTION_GIVE_MONEY,
 
	NETWORK_ACTION_NAME_CHANGE,
 
	NETWORK_ACTION_COMPANY_SPECTATOR,
 
	NETWORK_ACTION_COMPANY_JOIN,
 
	NETWORK_ACTION_COMPANY_NEW,
 
};
 

	
 
/** The error codes we send around in the protocols. */
 
enum NetworkErrorCode {
 
	NETWORK_ERROR_GENERAL, // Try to use this one like never
 

	
 
	/* Signals from clients */
 
	NETWORK_ERROR_DESYNC,
 
	NETWORK_ERROR_SAVEGAME_FAILED,
 
	NETWORK_ERROR_CONNECTION_LOST,
 
	NETWORK_ERROR_ILLEGAL_PACKET,
 
	NETWORK_ERROR_NEWGRF_MISMATCH,
 

	
 
	/* Signals from servers */
 
	NETWORK_ERROR_NOT_AUTHORIZED,
src/newgrf_airport.cpp
Show inline comments
 
@@ -229,24 +229,31 @@ uint16 GetAirportCallback(CallbackID cal
 

	
 
	NewAirportResolver(&object, tile, st, st->airport.type, st->airport.layout);
 
	object.callback = callback;
 
	object.callback_param1 = param1;
 
	object.callback_param2 = param2;
 

	
 
	const SpriteGroup *group = SpriteGroup::Resolve(st->airport.GetSpec()->grf_prop.spritegroup[0], &object);
 
	if (group == NULL) return CALLBACK_FAILED;
 

	
 
	return group->GetCallbackResult();
 
}
 

	
 
/**
 
 * Get a custom text for the airport.
 
 * @param as The airport type's specification.
 
 * @param layout The layout index.
 
 * @param callback The callback to call.
 
 * @return The custom text.
 
 */
 
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback)
 
{
 
	const SpriteGroup *group;
 
	ResolverObject object;
 

	
 
	NewAirportResolver(&object, INVALID_TILE, NULL, as->GetIndex(), layout);
 
	object.callback = (CallbackID)callback;
 

	
 
	group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], &object);
 
	if (group == NULL) return STR_UNDEFINED;
 

	
 
	return GetGRFStringID(as->grf_prop.grffile->grfid, 0xD000 + group->GetResult());
src/newgrf_airport.h
Show inline comments
 
@@ -10,25 +10,25 @@
 
/** @file newgrf_airport.h NewGRF handling of airports. */
 

	
 
#ifndef NEWGRF_AIRPORT_H
 
#define NEWGRF_AIRPORT_H
 

	
 
#include "airport.h"
 
#include "date_type.h"
 
#include "map_type.h"
 
#include "newgrf_class.h"
 
#include "newgrf_commons.h"
 
#include "gfx_type.h"
 

	
 
/* Copy from station_map.h */
 
/** Copy from station_map.h */
 
typedef byte StationGfx;
 

	
 
/** Tile-offset / AirportTileID pair. */
 
struct AirportTileTable {
 
	TileIndexDiffC ti; ///< Tile offset from  the top-most airport tile.
 
	StationGfx gfx;    ///< AirportTile to use for this tile.
 
};
 

	
 
/** List of default airport classes. */
 
enum AirportClassID {
 
	APC_BEGIN     = 0,  ///< Lowest valid airport class id
 
	APC_SMALL     = 0,  ///< id for small airports class
 
@@ -84,26 +84,26 @@ struct AirportSpec {
 

	
 
	bool IsAvailable() const;
 

	
 
	static void ResetAirports();
 

	
 
	/** Get the index of this spec. */
 
	byte GetIndex() const
 
	{
 
		assert(this >= specs && this < endof(specs));
 
		return (byte)(this - specs);
 
	}
 

	
 
	static AirportSpec dummy;
 
	static AirportSpec dummy; ///< The dummy airport.
 

	
 
private:
 
	static AirportSpec specs[NUM_AIRPORTS];
 
	static AirportSpec specs[NUM_AIRPORTS]; ///< Specs of the airports.
 
};
 

	
 
/** Information related to airport classes. */
 
typedef NewGRFClass<AirportSpec, AirportClassID, APC_MAX> AirportClass;
 

	
 
void BindAirportSpecs();
 

	
 
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback);
 

	
 
#endif /* NEWGRF_AIRPORT_H */
src/newgrf_class_func.h
Show inline comments
 
@@ -4,24 +4,28 @@
 
 * This file is part of OpenTTD.
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file newgrf_class_func.h Implementation of the NewGRF class' functions. */
 

	
 
#include "newgrf_class.h"
 

	
 
#include "table/strings.h"
 

	
 
/**
 
 * Helper for defining the class method's signatures.
 
 * @param type The type of the class.
 
 */
 
#define DEFINE_NEWGRF_CLASS_METHOD(type) \
 
	template <typename Tspec, typename Tid, Tid Tmax> \
 
	type NewGRFClass<Tspec, Tid, Tmax>
 

	
 
/** Instantiate the array. */
 
template <typename Tspec, typename Tid, Tid Tmax>
 
NewGRFClass<Tspec, Tid, Tmax> NewGRFClass<Tspec, Tid, Tmax>::classes[Tmax];
 

	
 
/** Reset the classes, i.e. clear everything. */
 
DEFINE_NEWGRF_CLASS_METHOD(void)::Reset()
 
{
 
	for (Tid i = (Tid)0; i < Tmax; i++) {
src/newgrf_commons.cpp
Show inline comments
 
@@ -314,25 +314,25 @@ void ObjectOverrideManager::SetEntitySpe
 

	
 
	extern ObjectSpec _object_specs[NUM_OBJECTS];
 

	
 
	/* Now that we know we can use the given id, copy the spec to its final destination. */
 
	memcpy(&_object_specs[type], spec, sizeof(*spec));
 
	ObjectClass::Assign(&_object_specs[type]);
 
}
 

	
 
/**
 
 * Function used by houses (and soon industries) to get information
 
 * on type of "terrain" the tile it is queries sits on.
 
 * @param tile TileIndex of the tile been queried
 
 * @param upper_halftile If true, query upper halftile in case of rail tiles.
 
 * @param context The context of the tile.
 
 * @return value corresponding to the grf expected format:
 
 *         Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline
 
 */
 
uint32 GetTerrainType(TileIndex tile, TileContext context)
 
{
 
	switch (_settings_game.game_creation.landscape) {
 
		case LT_TROPIC: return GetTropicZone(tile);
 
		case LT_ARCTIC: {
 
			bool has_snow;
 
			switch (GetTileType(tile)) {
 
				case MP_CLEAR:
 
					/* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
 
@@ -385,24 +385,31 @@ uint32 GetTerrainType(TileIndex tile, Ti
 
				genworld:
 
					has_snow = (GetTileZ(tile) > GetSnowLine());
 
					break;
 

	
 
				default: NOT_REACHED();
 
			}
 
			return has_snow ? 4 : 0;
 
		}
 
		default:        return 0;
 
	}
 
}
 

	
 
/**
 
 * Get the tile at the given offset.
 
 * @param parameter The NewGRF "encoded" offset.
 
 * @param tile The tile to base the offset from.
 
 * @param signed_offsets Whether the offsets are to be interpreted as signed or not.
 
 * @return The tile at the offset.
 
 */
 
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets)
 
{
 
	int8 x = GB(parameter, 0, 4);
 
	int8 y = GB(parameter, 4, 4);
 

	
 
	if (signed_offsets && x >= 8) x -= 16;
 
	if (signed_offsets && y >= 8) y -= 16;
 

	
 
	/* Swap width and height depending on axis for railway stations */
 
	if (HasStationTileRail(tile) && GetRailStationAxis(tile) == AXIS_Y) Swap(x, y);
 

	
 
	/* Make sure we never roam outside of the map, better wrap in that case */
src/newgrf_config.cpp
Show inline comments
 
@@ -658,26 +658,26 @@ const GRFConfig *FindGRFConfig(uint32 gr
 
		if (mode == FGCM_COMPATIBLE && (c->version < desired_version || c->min_loadable_version > desired_version)) continue;
 
		/* remember the newest one as "the best" */
 
		if (best == NULL || c->version > best->version) best = c;
 
	}
 

	
 
	return best;
 
}
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */
 
struct UnknownGRF : public GRFIdentifier {
 
	UnknownGRF *next;
 
	GRFTextWrapper *name;
 
	UnknownGRF *next;     ///< The next unknown GRF.
 
	GRFTextWrapper *name; ///< Name of the GRF.
 
};
 

	
 
/**
 
 * Finds the name of a NewGRF in the list of names for unknown GRFs. An
 
 * unknown GRF is a GRF where the .grf is not found during scanning.
 
 *
 
 * The names are resolved via UDP calls to servers that should know the name,
 
 * though the replies may not come. This leaves "<Unknown>" as name, though
 
 * that shouldn't matter _very_ much as they need GRF crawler or so to look
 
 * up the GRF anyway and that works better with the GRF ID.
 
 *
 
 * @param grfid  the GRF ID part of the 'unique' GRF identifier
src/newgrf_config.h
Show inline comments
 
@@ -196,18 +196,18 @@ GRFConfig **CopyGRFConfigList(GRFConfig 
 
void AppendStaticGRFConfigs(GRFConfig **dst);
 
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
 
void ClearGRFConfigList(GRFConfig **config);
 
void ResetGRFConfig(bool defaults);
 
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
 
bool FillGRFDetails(GRFConfig *config, bool is_static);
 
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
 

	
 
/* In newgrf_gui.cpp */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
 

	
 
#ifdef ENABLE_NETWORK
 
/* For communication about GRFs over the network */
 
/** For communication about GRFs over the network */
 
#define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
 
GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
 
#endif /* ENABLE_NETWORK */
 

	
 
#endif /* NEWGRF_CONFIG_H */
src/newgrf_debug_gui.cpp
Show inline comments
 
@@ -26,24 +26,25 @@
 
#include "town.h"
 
#include "vehicle_base.h"
 

	
 
#include "newgrf_airporttiles.h"
 
#include "newgrf_debug.h"
 
#include "newgrf_object.h"
 
#include "newgrf_spritegroup.h"
 
#include "newgrf_station.h"
 
#include "newgrf_town.h"
 

	
 
#include "table/strings.h"
 

	
 
/** The sprite picker. */
 
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker = { SPM_NONE, NULL, 0, SmallVector<SpriteID, 256>() };
 

	
 
/**
 
 * Get the feature index related to the window number.
 
 * @param window_number The window to get the feature index from.
 
 * @return the feature index
 
 */
 
static inline uint GetFeatureIndex(uint window_number)
 
{
 
	return GB(window_number, 0, 24);
 
}
 

	
src/newgrf_generic.cpp
Show inline comments
 
@@ -37,27 +37,27 @@ static GenericCallbackList _gcl[GSF_END]
 
 * Reset all generic feature callback sprite groups.
 
 */
 
void ResetGenericCallbacks()
 
{
 
	for (uint8 feature = 0; feature < lengthof(_gcl); feature++) {
 
		_gcl[feature].clear();
 
	}
 
}
 

	
 

	
 
/**
 
 * Add a generic feature callback sprite group to the appropriate feature list.
 
 * @param feature
 
 * @param file
 
 * @param group
 
 * @param feature The feature for the callback.
 
 * @param file The GRF of the callback.
 
 * @param group The sprite group of the callback.
 
 */
 
void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *group)
 
{
 
	if (feature >= lengthof(_gcl)) {
 
		grfmsg(5, "AddGenericCallback: Unsupported feature 0x%02X", feature);
 
		return;
 
	}
 

	
 
	/* Generic feature callbacks are evaluated in reverse (i.e. the last group
 
	 * to be added is evaluated first, etc) thus we push the group to the
 
	 * beginning of the list so a standard iterator will do the right thing. */
 
	_gcl[feature].push_front(GenericCallback(file, group));
src/newgrf_generic.h
Show inline comments
 
@@ -5,46 +5,50 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file newgrf_generic.h Functions related to generic callbacks. */
 

	
 
#ifndef NEWGRF_GENERIC_H
 
#define NEWGRF_GENERIC_H
 

	
 
#include "cargo_type.h"
 
#include "industry_type.h"
 
#include "newgrf.h"
 

	
 
struct SpriteGroup;
 

	
 
/** AI events for asking the NewGRF for information. */
 
enum AIConstructionEvent {
 
	AICE_TRAIN_CHECK_RAIL_ENGINE     = 0x00, ///< Check if we should build an engine
 
	AICE_TRAIN_CHECK_ELRAIL_ENGINE   = 0x01,
 
	AICE_TRAIN_CHECK_MONORAIL_ENGINE = 0x02,
 
	AICE_TRAIN_CHECK_MAGLEV_ENGINE   = 0x03,
 
	AICE_TRAIN_GET_RAIL_WAGON        = 0x08,
 
	AICE_TRAIN_GET_ELRAIL_WAGON      = 0x09,
 
	AICE_TRAIN_GET_MONORAIL_WAGON    = 0x0A,
 
	AICE_TRAIN_GET_MAGLEV_WAGON      = 0x0B,
 
	AICE_TRAIN_GET_RAILTYPE          = 0x0F,
 
	AICE_TRAIN_CHECK_ELRAIL_ENGINE   = 0x01, ///< Check if we should build an engine
 
	AICE_TRAIN_CHECK_MONORAIL_ENGINE = 0x02, ///< Check if we should build an engine
 
	AICE_TRAIN_CHECK_MAGLEV_ENGINE   = 0x03, ///< Check if we should build an engine
 
	AICE_TRAIN_GET_RAIL_WAGON        = 0x08, ///< Check if we should build an engine
 
	AICE_TRAIN_GET_ELRAIL_WAGON      = 0x09, ///< Check if we should build an engine
 
	AICE_TRAIN_GET_MONORAIL_WAGON    = 0x0A, ///< Check if we should build an engine
 
	AICE_TRAIN_GET_MAGLEV_WAGON      = 0x0B, ///< Check if we should build an engine
 
	AICE_TRAIN_GET_RAILTYPE          = 0x0F, ///< Check if we should build a railtype
 

	
 
	AICE_ROAD_CHECK_ENGINE           = 0x00, ///< Check if we should build an engine
 
	AICE_ROAD_GET_FIRST_ENGINE       = 0x01, ///< Unused, we check all
 
	AICE_ROAD_GET_NUMBER_ENGINES     = 0x02, ///< Unused, we check all
 

	
 
	AICE_SHIP_CHECK_ENGINE           = 0x00, ///< Check if we should build an engine
 
	AICE_SHIP_GET_FIRST_ENGINE       = 0x01, ///< Unused, we check all
 
	AICE_SHIP_GET_NUMBER_ENGINES     = 0x02, ///< Unused, we check all
 

	
 
	AICE_AIRCRAFT_CHECK_ENGINE       = 0x00, ///< Check if we should build an engine
 

	
 
	AICE_STATION_GET_STATION_ID      = 0x00, ///< Get a station ID to build
 
};
 

	
 
static const IndustryType IT_AI_UNKNOWN = 0xFE; ///< The AI has no specific industry in mind.
 
static const IndustryType IT_AI_TOWN    = 0xFF; ///< The AI actually wants to transport to/from a town, not an industry.
 

	
 
void ResetGenericCallbacks();
 
void AddGenericCallback(uint8 feature, const struct GRFFile *file, const struct SpriteGroup *group);
 
void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *group);
 

	
 
uint16 GetAiPurchaseCallbackResult(uint8 feature, CargoID cargo_type, uint8 default_selection, IndustryType src_industry, IndustryType dst_industry, uint8 distance, AIConstructionEvent event, uint8 count, uint8 station_size, const struct GRFFile **file);
 
uint16 GetAiPurchaseCallbackResult(uint8 feature, CargoID cargo_type, uint8 default_selection, IndustryType src_industry, IndustryType dst_industry, uint8 distance, AIConstructionEvent event, uint8 count, uint8 station_size, const GRFFile **file);
 

	
 
#endif /* NEWGRF_GENERIC_H */
src/newgrf_industries.cpp
Show inline comments
 
@@ -26,24 +26,30 @@
 
#include "core/random_func.hpp"
 

	
 
#include "table/strings.h"
 

	
 
static uint32 _industry_creation_random_bits;
 

	
 
/* Since the industry IDs defined by the GRF file don't necessarily correlate
 
 * to those used by the game, the IDs used for overriding old industries must be
 
 * translated when the idustry spec is set. */
 
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
 
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
 

	
 
/**
 
 * Map the GRF local type to an industry type.
 
 * @param grf_type The GRF local type.
 
 * @param grf_id The GRF of the local type.
 
 * @return The industry type in the global scope.
 
 */
 
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
 
{
 
	if (grf_type == IT_INVALID) return IT_INVALID;
 
	if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 6);
 

	
 
	return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id);
 
}
 

	
 
/**
 
 * Make an analysis of a tile and check for its belonging to the same
 
 * industry, and/or the same grf file
 
 * @param tile TileIndex of the tile to query
 
@@ -377,24 +383,34 @@ static void NewIndustryResolver(Resolver
 
	res->callback        = CBID_NO_CALLBACK;
 
	res->callback_param1 = 0;
 
	res->callback_param2 = 0;
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 

	
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 
	res->grffile         = (indspec != NULL ? indspec->grf_prop.grffile : NULL);
 
}
 

	
 
/**
 
 * Perform an industry callback.
 
 * @param callback The callback to perform.
 
 * @param param1 The first parameter.
 
 * @param param2 The second parameter.
 
 * @param industry The industry to do the callback for.
 
 * @param type The type of industry to do the callback for.
 
 * @param tile The tile associated with the callback.
 
 * @return The callback result.
 
 */
 
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
 
{
 
	ResolverObject object;
 
	const SpriteGroup *group;
 

	
 
	NewIndustryResolver(&object, tile, industry, type);
 
	object.callback = callback;
 
	object.callback_param1 = param1;
 
	object.callback_param2 = param2;
 

	
 
	group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object);
 
	if (group == NULL) return CALLBACK_FAILED;
src/newgrf_railtype.cpp
Show inline comments
 
@@ -78,41 +78,55 @@ static inline void NewRailTypeResolver(R
 
	res->u.routes.tile = tile;
 
	res->u.routes.context = context;
 

	
 
	res->callback        = CBID_NO_CALLBACK;
 
	res->callback_param1 = 0;
 
	res->callback_param2 = 0;
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 
}
 

	
 
/**
 
 * Get the sprite to draw for the given tile.
 
 * @param rti The rail type data (spec).
 
 * @param tile The tile to get the sprite for.
 
 * @param rtsg The type of sprite to draw.
 
 * @param content Where are we drawing the tile?
 
 * @return The sprite to draw.
 
 */
 
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context)
 
{
 
	assert(rtsg < RTSG_END);
 

	
 
	if (rti->group[rtsg] == NULL) return 0;
 

	
 
	const SpriteGroup *group;
 
	ResolverObject object;
 

	
 
	NewRailTypeResolver(&object, tile, context);
 

	
 
	group = SpriteGroup::Resolve(rti->group[rtsg], &object);
 
	if (group == NULL || group->GetNumResults() == 0) return 0;
 

	
 
	return group->GetResult();
 
}
 

	
 
/**
 
 * Perform a reverse railtype lookup to get the GRF internal ID.
 
 * @param railtype The global (OpenTTD) railtype.
 
 * @param grffile The GRF to do the lookup for.
 
 * @return the GRF internal ID.
 
 */
 
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
 
{
 
	/* No rail type table present, return rail type as-is */
 
	if (grffile == NULL || grffile->railtype_max == 0) return railtype;
 

	
 
	/* Look for a matching rail type label in the table */
 
	RailTypeLabel label = GetRailTypeInfo(railtype)->label;
 
	for (uint i = 0; i < grffile->railtype_max; i++) {
 
		if (label == grffile->railtype_list[i]) return i;
 
	}
 

	
 
	/* If not found, return as invalid */
src/news_gui.cpp
Show inline comments
 
@@ -1383,17 +1383,20 @@ static const NWidgetPart _nested_message
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, MOS_BOTTOM_EDGE),
 
	EndContainer(),
 
};
 

	
 
static const WindowDesc _message_options_desc(
 
	WDP_AUTO, 0, 0,
 
	WC_GAME_OPTIONS, WC_NONE,
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_message_options_widgets, lengthof(_nested_message_options_widgets)
 
);
 

	
 
/**
 
 * Show the settings window for news messages.
 
 */
 
void ShowMessageOptions()
 
{
 
	DeleteWindowById(WC_GAME_OPTIONS, 0);
 
	new MessageOptionsWindow(&_message_options_desc);
 
}
src/news_type.h
Show inline comments
 
@@ -110,55 +110,63 @@ enum NewsDisplay {
 
};
 

	
 
/**
 
 * Per-NewsType data
 
 */
 
struct NewsTypeData {
 
	const char * const name;    ///< Name
 
	const byte age;             ///< Maximum age of news items (in days)
 
	const SoundFx sound;        ///< Sound
 
	NewsDisplay display;        ///< Display mode (off, summary, full)
 
	const StringID description; ///< Description of the news type in news settings window
 

	
 
	/**
 
	 * Construct this entry.
 
	 * @param name The name of the type.
 
	 * @param age The maximum age for these messages.
 
	 * @param sound The sound to play.
 
	 * @param description The description for this type of messages.
 
	 */
 
	NewsTypeData(const char *name, byte age, SoundFx sound, StringID description) :
 
		name(name),
 
		age(age),
 
		sound(sound),
 
		display(ND_FULL),
 
		description(description)
 
	{
 
	}
 
};
 

	
 
/** Information about a single item of news. */
 
struct NewsItem {
 
	NewsItem *prev;              ///< Previous news item
 
	NewsItem *next;              ///< Next news item
 
	StringID string_id;          ///< Message text
 
	Date date;                   ///< Date of the news
 
	NewsSubtype subtype;         ///< News subtype @see NewsSubtype
 
	NewsFlag flags;              ///< NewsFlags bits @see NewsFlag
 

	
 
	NewsReferenceType reftype1;  ///< Type of ref1
 
	NewsReferenceType reftype2;  ///< Type of ref2
 
	uint32 ref1;                 ///< Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleteing the news when the object is deleted.
 
	uint32 ref2;                 ///< Reference 2 to some object: Used for scrolling after clicking on the news, and for deleteing the news when the object is deleted.
 

	
 
	void *free_data;             ///< Data to be freed when the news item has reached its end.
 

	
 
	~NewsItem()
 
	{
 
		free(this->free_data);
 
	}
 

	
 
	uint64 params[10];
 
	uint64 params[10]; ///< Parameters for string resolving.
 
};
 

	
 
/**
 
 * Data that needs to be stored for company news messages.
 
 * The problem with company news messages are the custom name
 
 * of the companies and the fact that the company data is reset,
 
 * resulting in wrong names and such.
 
 */
 
struct CompanyNewsInformation {
 
	char company_name[64];       ///< The name of the company
 
	char president_name[64];     ///< The name of the president
 
	char other_company_name[64]; ///< The name of the company taking over this one
src/order_backup.cpp
Show inline comments
 
@@ -177,25 +177,25 @@ CommandCost CmdClearOrderBackup(TileInde
 
	OrderBackup *ob;
 
	FOR_ALL_ORDER_BACKUPS(ob) {
 
		/* If it's not an backup of us, so ignore it. */
 
		if (ob->user != user) continue;
 

	
 
		DoCommandP(0, 0, user, CMD_CLEAR_ORDER_BACKUP);
 
		return;
 
	}
 
}
 

	
 
/**
 
 * Reset the OrderBackups from GUI/game logic.
 
 * @param tile     The tile of the order backup.
 
 * @param t        The tile of the order backup.
 
 * @param from_gui Whether the call came from the GUI, i.e. whether
 
 *                 it must be synced over the network.
 
 */
 
/* static */ void OrderBackup::Reset(TileIndex t, bool from_gui)
 
{
 
	/* The user has CLIENT_ID_SERVER as default when network play is not active,
 
	 * but compiled it. A network client has its own variable for the unique
 
	 * client/user identifier. Finally if networking isn't compiled in the
 
	 * default is just plain and simple: 0. */
 
#ifdef ENABLE_NETWORK
 
	uint32 user = _networking && !_network_server ? _network_own_client_id : CLIENT_ID_SERVER;
 
#else
src/order_backup.h
Show inline comments
 
@@ -60,16 +60,26 @@ public:
 

	
 
	static void Backup(const Vehicle *v, uint32 user);
 
	static void Restore(Vehicle *v, uint32 user);
 

	
 
	static void ResetOfUser(TileIndex tile, uint32 user);
 
	static void ResetUser(uint32 user);
 
	static void Reset(TileIndex tile = INVALID_TILE, bool from_gui = true);
 

	
 
	static void ClearGroup(GroupID group);
 
	static void ClearVehicle(const Vehicle *v);
 
};
 

	
 
/**
 
 * Iterator over all order backups from a given ID.
 
 * @param var The variable to iterate with.
 
 * @param start The start of the iteration.
 
 */
 
#define FOR_ALL_ORDER_BACKUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(OrderBackup, order_backup_index, var, start)
 

	
 
/**
 
 * Iterator over all order backups.
 
 * @param var The variable to iterate with.
 
 */
 
#define FOR_ALL_ORDER_BACKUPS(var) FOR_ALL_ORDER_BACKUPS_FROM(var, 0)
 

	
 
#endif /* ORDER_BACKUP_H */
src/pathfinder/pf_performance_timer.hpp
Show inline comments
 
@@ -3,25 +3,25 @@
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file pf_performance_timer.hpp Performance timer for pathfinders. */
 

	
 
#ifndef PF_PERFORMANCE_TIMER_HPP
 
#define PF_PERFORMANCE_TIMER_HPP
 

	
 
extern uint64 ottd_rdtsc();
 
#include "../debug.h"
 

	
 
struct CPerformanceTimer
 
{
 
	int64    m_start;
 
	int64    m_acc;
 

	
 
	CPerformanceTimer() : m_start(0), m_acc(0) {}
 

	
 
	FORCEINLINE void Start()
 
	{
 
		m_start = QueryTime();
 
	}
src/pathfinder/yapf/nodelist.hpp
Show inline comments
 
@@ -142,22 +142,25 @@ public:
 
	{
 
		assert(m_open.Find(item.GetKey()) == NULL);
 
		m_closed.Push(item);
 
	}
 

	
 
	/** return the closed node specified by a key or NULL if not found */
 
	FORCEINLINE Titem_ *FindClosedNode(const Key& key)
 
	{
 
		Titem_ *item = m_closed.Find(key);
 
		return item;
 
	}
 

	
 
	/** The number of items. */
 
	FORCEINLINE int TotalCount() {return m_arr.Length();}
 
	/** Get a particular item. */
 
	FORCEINLINE Titem_& ItemAt(int idx) {return m_arr[idx];}
 

	
 
	/** Helper for creating output of this array. */
 
	template <class D> void Dump(D &dmp) const
 
	{
 
		dmp.WriteStructT("m_arr", &m_arr);
 
	}
 
};
 

	
 
#endif /* NODELIST_HPP */
src/pathfinder/yapf/yapf.h
Show inline comments
 
@@ -56,25 +56,25 @@ Track YapfTrainChooseTrack(const Train *
 
 * Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.
 
 * @param v            vehicle that needs to go to some depot
 
 * @param max_penalty  max distance (in pathfinder penalty) from the current vehicle position
 
 *                     (used also as optimization - the pathfinder can stop path finding if max_penalty
 
 *                     was reached and no depot was seen)
 
 * @return             the data about the depot
 
 */
 
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty);
 

	
 
/**
 
 * Used when user sends train to the nearest depot or if train needs servicing using YAPF.
 
 * @param v            train that needs to go to some depot
 
 * @param max_penalty  max distance (int pathfinder penalty) from the current train position
 
 * @param max_distance max distance (int pathfinder penalty) from the current train position
 
 *                     (used also as optimization - the pathfinder can stop path finding if max_penalty
 
 *                     was reached and no depot was seen)
 
 * @return             the data about the depot
 
 */
 
FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_distance);
 

	
 
/**
 
 * Returns true if it is better to reverse the train before leaving station using YAPF.
 
 * @param v the train leaving the station
 
 * @return true if reversing is better
 
 */
 
bool YapfTrainCheckReverse(const Train *v);
src/pathfinder/yapf/yapf_costbase.hpp
Show inline comments
 
@@ -3,40 +3,42 @@
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file yapf_costbase.hpp Handling of cost determination. */
 

	
 
#ifndef YAPF_COSTBASE_HPP
 
#define YAPF_COSTBASE_HPP
 

	
 
/** Base implementation for cost accounting. */
 
struct CYapfCostBase {
 
	/**
 
	 * Does the given track direction on the given tile yeild an uphill penalty?
 
	 * @param tile The tile to check.
 
	 * @param td   The track direction to check.
 
	 * @return True if there's a slope, otherwise false.
 
	 */
 
	FORCEINLINE static bool stSlopeCost(TileIndex tile, Trackdir td)
 
	{
 
		if (IsDiagonalTrackdir(td)) {
 
			if (IsBridgeTile(tile)) {
 
				/* it is bridge ramp, check if we are entering the bridge */
 
				if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are leaving it, no penalty
 
				/* we are entering the bridge */
 
				Slope tile_slope = GetTileSlope(tile, NULL);
 
				Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile));
 
				return !HasBridgeFlatRamp(tile_slope, axis);
 
			} else {
 
				/* not bridge ramp */
 
				if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
 
				Slope tile_slope = GetTileSlope(tile, NULL);
 
				return IsUphillTrackdir(tile_slope, td); // slopes uphill => apply penalty
 
			}
 
		}
 
		return false;
 
	}
 
};
 

	
 
struct CostRailSettings {
 
	/* look-ahead signal penalty */
 
};
 

	
 

	
 
#endif /* YAPF_COSTBASE_HPP */
src/pathfinder/yapf/yapf_costrail.hpp
Show inline comments
 
@@ -8,25 +8,24 @@
 
 */
 

	
 
/** @file yapf_costrail.hpp Cost determination for rails. */
 

	
 
#ifndef YAPF_COSTRAIL_HPP
 
#define YAPF_COSTRAIL_HPP
 

	
 
#include "../../pbs.h"
 

	
 
template <class Types>
 
class CYapfCostRailT
 
	: public CYapfCostBase
 
	, public CostRailSettings
 
{
 
public:
 
	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
 
	typedef typename Types::TrackFollower TrackFollower;
 
	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
 
	typedef typename Node::Key Key;               ///< key to hash tables
 
	typedef typename Node::CachedData CachedData;
 

	
 
protected:
 

	
 
	/* Structure used inside PfCalcCost() to keep basic tile information. */
 
	struct TILE {
src/pbs.h
Show inline comments
 
@@ -21,25 +21,35 @@ TrackBits GetReservedTrackbits(TileIndex
 

	
 
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b);
 

	
 
bool TryReserveRailTrack(TileIndex tile, Track t);
 
void UnreserveRailTrack(TileIndex tile, Track t);
 

	
 
/** This struct contains information about the end of a reserved path. */
 
struct PBSTileInfo {
 
	TileIndex tile;      ///< Tile the path ends, INVALID_TILE if no valid path was found.
 
	Trackdir  trackdir;  ///< The reserved trackdir on the tile.
 
	bool      okay;      ///< True if tile is a safe waiting position, false otherwise.
 

	
 
	/**
 
	 * Create an empty PBSTileInfo.
 
	 */
 
	PBSTileInfo() : tile(INVALID_TILE), trackdir(INVALID_TRACKDIR), okay(false) {}
 

	
 
	/**
 
	 * Create a PBSTileInfo with given tile, track direction and safe waiting position information.
 
	 * @param _t The tile where the path ends.
 
	 * @param _td The reserved track dir on the tile.
 
	 * @param _okay Whether the tile is a safe waiting point or not.
 
	 */
 
	PBSTileInfo(TileIndex _t, Trackdir _td, bool _okay) : tile(_t), trackdir(_td), okay(_okay) {}
 
};
 

	
 
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res = NULL);
 
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg = false);
 
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg = false);
 

	
 
Train *GetTrainForReservation(TileIndex tile, Track track);
 

	
 
/**
 
 * Check whether some of tracks is reserved on a tile.
 
 *
src/sound/allegro_s.h
Show inline comments
 
@@ -5,31 +5,33 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file allegro_s.h Base fo playing sound via Allegro. */
 

	
 
#ifndef SOUND_ALLEGRO_H
 
#define SOUND_ALLEGRO_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the allegro sound driver. */
 
class SoundDriver_Allegro: public SoundDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MainLoop();
 
	/* virtual */ const char *GetName() const { return "allegro"; }
 
};
 

	
 
/** Factory for the allegro sound driver. */
 
class FSoundDriver_Allegro: public SoundDriverFactory<FSoundDriver_Allegro> {
 
public:
 
	static const int priority = 4;
 
	/* virtual */ const char *GetName() { return "allegro"; }
 
	/* virtual */ const char *GetDescription() { return "Allegro Sound Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new SoundDriver_Allegro(); }
 
};
 

	
 
#endif /* SOUND_ALLEGRO_H */
src/sound/null_s.h
Show inline comments
 
@@ -5,29 +5,31 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file null_s.h Base for the sound of silence. */
 

	
 
#ifndef SOUND_NULL_H
 
#define SOUND_NULL_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the null sound driver. */
 
class SoundDriver_Null: public SoundDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param) { return NULL; }
 

	
 
	/* virtual */ void Stop() { }
 
	/* virtual */ const char *GetName() const { return "null"; }
 
};
 

	
 
/** Factory for the null sound driver. */
 
class FSoundDriver_Null: public SoundDriverFactory<FSoundDriver_Null> {
 
public:
 
	static const int priority = 1;
 
	/* virtual */ const char *GetName() { return "null"; }
 
	/* virtual */ const char *GetDescription() { return "Null Sound Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new SoundDriver_Null(); }
 
};
 

	
 
#endif /* SOUND_NULL_H */
src/sound/sdl_s.h
Show inline comments
 
@@ -5,29 +5,31 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file sdl_s.h Base fo playing sound via SDL. */
 

	
 
#ifndef SOUND_SDL_H
 
#define SOUND_SDL_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the SDL sound driver. */
 
class SoundDriver_SDL: public SoundDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 
	/* virtual */ const char *GetName() const { return "sdl"; }
 
};
 

	
 
/** Factory for the SDL sound driver. */
 
class FSoundDriver_SDL: public SoundDriverFactory<FSoundDriver_SDL> {
 
public:
 
	static const int priority = 5;
 
	/* virtual */ const char *GetName() { return "sdl"; }
 
	/* virtual */ const char *GetDescription() { return "SDL Sound Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new SoundDriver_SDL(); }
 
};
 

	
 
#endif /* SOUND_SDL_H */
src/sound/sound_driver.hpp
Show inline comments
 
@@ -5,33 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file sound_driver.hpp Base for all sound drivers. */
 

	
 
#ifndef SOUND_SOUND_DRIVER_HPP
 
#define SOUND_SOUND_DRIVER_HPP
 

	
 
#include "../driver.h"
 

	
 
/** Base for all sound drivers. */
 
class SoundDriver: public Driver {
 
public:
 
	/* Called once every tick */
 
	/** Called once every tick */
 
	virtual void MainLoop() {}
 
};
 

	
 
/** Base of the factory for the sound drivers. */
 
class SoundDriverFactoryBase: public DriverFactoryBase {
 
};
 

	
 
/**
 
 * Factory for the sound drivers.
 
 * @tparam T The type of the sound factory to register.
 
 */
 
template <class T>
 
class SoundDriverFactory: public SoundDriverFactoryBase {
 
public:
 
	SoundDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_SOUND, ((T *)this)->priority); }
 

	
 
	/**
 
	 * Get the long, human readable, name for the Driver-class.
 
	 */
 
	const char *GetName();
 
};
 

	
 
extern SoundDriver *_sound_driver;
src/sound/win32_s.h
Show inline comments
 
@@ -5,29 +5,31 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file win32_s.h Base for Windows sound handling. */
 

	
 
#ifndef SOUND_WIN32_H
 
#define SOUND_WIN32_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the sound driver for Windows. */
 
class SoundDriver_Win32: public SoundDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 
	/* virtual */ const char *GetName() const { return "win32"; }
 
};
 

	
 
/** Factory for the sound driver for Windows. */
 
class FSoundDriver_Win32: public SoundDriverFactory<FSoundDriver_Win32> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "win32"; }
 
	/* virtual */ const char *GetDescription() { return "Win32 WaveOut Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new SoundDriver_Win32(); }
 
};
 

	
 
#endif /* SOUND_WIN32_H */
src/video/allegro_v.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file allegro_v.h Base of the Allegro video driver. */
 

	
 
#ifndef VIDEO_ALLEGRO_H
 
#define VIDEO_ALLEGRO_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The allegro video driver. */
 
class VideoDriver_Allegro: public VideoDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
	/* virtual */ const char *GetName() const { return "allegro"; }
 
};
 

	
 
/** Factory for the allegro video driver. */
 
class FVideoDriver_Allegro: public VideoDriverFactory<FVideoDriver_Allegro> {
 
public:
 
	static const int priority = 4;
 
	/* virtual */ const char *GetName() { return "allegro"; }
 
	/* virtual */ const char *GetDescription() { return "Allegro Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Allegro(); }
 
};
 

	
 
#endif /* VIDEO_ALLEGRO_H */
src/video/dedicated_v.h
Show inline comments
 
@@ -5,40 +5,42 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file dedicated_v.h Base for the dedicated video driver. */
 

	
 
#ifndef VIDEO_DEDICATED_H
 
#define VIDEO_DEDICATED_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The dedicated server video driver. */
 
class VideoDriver_Dedicated: public VideoDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
	/* virtual */ const char *GetName() const { return "dedicated"; }
 
};
 

	
 
/** Factory for the dedicated server video driver. */
 
class FVideoDriver_Dedicated: public VideoDriverFactory<FVideoDriver_Dedicated> {
 
public:
 
#ifdef DEDICATED
 
	/* Automatically select this dedicated driver when making a dedicated
 
	 * server build. */
 
	static const int priority = 10;
 
#else
 
	static const int priority = 0;
 
#endif
 
	/* virtual */ const char *GetName() { return "dedicated"; }
 
	/* virtual */ const char *GetDescription() { return "Dedicated Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Dedicated(); }
src/video/null_v.h
Show inline comments
 
@@ -5,40 +5,42 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file null_v.h Base of the video driver that doesn't blit. */
 

	
 
#ifndef VIDEO_NULL_H
 
#define VIDEO_NULL_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The null video driver. */
 
class VideoDriver_Null: public VideoDriver {
 
private:
 
	uint ticks;
 
	uint ticks; ///< Amount of ticks to run.
 

	
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
	/* virtual */ const char *GetName() const { return "null"; }
 
};
 

	
 
/** Factory the null video driver. */
 
class FVideoDriver_Null: public VideoDriverFactory<FVideoDriver_Null> {
 
public:
 
	static const int priority = 0;
 
	/* virtual */ const char *GetName() { return "null"; }
 
	/* virtual */ const char *GetDescription() { return "Null Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Null(); }
 
};
 

	
 
#endif /* VIDEO_NULL_H */
src/video/sdl_v.h
Show inline comments
 
@@ -5,37 +5,39 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file sdl_v.h Base of the SDL video driver. */
 

	
 
#ifndef VIDEO_SDL_H
 
#define VIDEO_SDL_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The SDL video driver. */
 
class VideoDriver_SDL: public VideoDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
	/* virtual */ const char *GetName() const { return "sdl"; }
 
};
 

	
 
/** Factory for the SDL video driver. */
 
class FVideoDriver_SDL: public VideoDriverFactory<FVideoDriver_SDL> {
 
public:
 
	static const int priority = 5;
 
	/* virtual */ const char *GetName() { return "sdl"; }
 
	/* virtual */ const char *GetDescription() { return "SDL Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_SDL(); }
 
};
 

	
 
#endif /* VIDEO_SDL_H */
src/video/video_driver.hpp
Show inline comments
 
@@ -6,38 +6,65 @@
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file video_driver.hpp Base of all video drivers. */
 

	
 
#ifndef VIDEO_VIDEO_DRIVER_HPP
 
#define VIDEO_VIDEO_DRIVER_HPP
 

	
 
#include "../driver.h"
 
#include "../core/geometry_type.hpp"
 

	
 
/** The base of all video drivers. */
 
class VideoDriver: public Driver {
 
public:
 
	/**
 
	 * Mark a particular area dirty.
 
	 * @param left   The left most line of the dirty area.
 
	 * @param top    The top most line of the dirty area.
 
	 * @param width  The width of the dirty area.
 
	 * @param height The height of the dirty area.
 
	 */
 
	virtual void MakeDirty(int left, int top, int width, int height) = 0;
 

	
 
	/**
 
	 * Perform the actual drawing.
 
	 */
 
	virtual void MainLoop() = 0;
 

	
 
	/**
 
	 * Change the resolution of the window.
 
	 * @param w The new width.
 
	 * @param h The new height.
 
	 * @return True if the change succeeded.
 
	 */
 
	virtual bool ChangeResolution(int w, int h) = 0;
 

	
 
	/**
 
	 * Change the full screen setting.
 
	 * @param fullscreen The new setting.
 
	 * @return True if the change succeeded.
 
	 */
 
	virtual bool ToggleFullscreen(bool fullscreen) = 0;
 
};
 

	
 
/** Base of the factory for the video drivers. */
 
class VideoDriverFactoryBase: public DriverFactoryBase {
 
};
 

	
 
/**
 
 * Factory for the video drivers.
 
 * @tparam T The type of the video factory to register.
 
 */
 
template <class T>
 
class VideoDriverFactory: public VideoDriverFactoryBase {
 
public:
 
	VideoDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_VIDEO, ((T *)this)->priority); }
 

	
 
	/**
 
	 * Get the long, human readable, name for the Driver-class.
 
	 */
 
	const char *GetName();
 
};
 

	
 
extern VideoDriver *_video_driver;
src/video/win32_v.cpp
Show inline comments
 
@@ -215,24 +215,29 @@ static void CALLBACK TrackMouseTimerProc
 
	 * Compare this with the current screen coordinates of the mouse and if it
 
	 * falls outside of the area or our window we have left the window. */
 
	GetClientRect(hwnd, &rc);
 
	MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)(LPRECT)&rc, 2);
 
	GetCursorPos(&pt);
 

	
 
	if (!PtInRect(&rc, pt) || (WindowFromPoint(pt) != hwnd)) {
 
		KillTimer(hwnd, event);
 
		PostMessage(hwnd, WM_MOUSELEAVE, 0, 0L);
 
	}
 
}
 

	
 
/**
 
 * Instantiate a new window.
 
 * @param full_screen Whether to make a full screen window or not.
 
 * @return True if the window could be created.
 
 */
 
bool VideoDriver_Win32::MakeWindow(bool full_screen)
 
{
 
	_fullscreen = full_screen;
 

	
 
	/* recreate window? */
 
	if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
 
		DestroyWindow(_wnd.main_wnd);
 
		_wnd.main_wnd = 0;
 
	}
 

	
 
#if defined(WINCE)
 
	/* WinCE is always fullscreen */
src/video/win32_v.h
Show inline comments
 
@@ -5,39 +5,41 @@
 
 * OpenTTD 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, version 2.
 
 * OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file win32_v.h Base of the Windows video driver. */
 

	
 
#ifndef VIDEO_WIN32_H
 
#define VIDEO_WIN32_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The video driver for windows. */
 
class VideoDriver_Win32: public VideoDriver {
 
public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 

	
 
	/* virtual */ void MakeDirty(int left, int top, int width, int height);
 

	
 
	/* virtual */ void MainLoop();
 

	
 
	/* virtual */ bool ChangeResolution(int w, int h);
 

	
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
	/* virtual */ const char *GetName() const { return "win32"; }
 

	
 
	bool MakeWindow(bool full_screen);
 
};
 

	
 
/** The factory for Windows' video driver. */
 
class FVideoDriver_Win32: public VideoDriverFactory<FVideoDriver_Win32> {
 
public:
 
	static const int priority = 10;
 
	/* virtual */ const char *GetName() { return "win32"; }
 
	/* virtual */ const char *GetDescription() { return "Win32 GDI Video Driver"; }
 
	/* virtual */ Driver *CreateInstance() { return new VideoDriver_Win32(); }
 
};
 

	
 
#endif /* VIDEO_WIN32_H */
0 comments (0 inline, 0 general)