Skip to content

Commit

Permalink
Refactor: Added libdoomsday, relocated some files
Browse files Browse the repository at this point in the history
libdoomsday is the common denominator between the client and the
server applications.

Unlike liblegacy, it is intended to be a permanent and central part
of the architecture. All shared functionality that exists both in
the client and the server (but not at a more general level) should be
relocated there, after appropriate refactoring.

Relocated the following:
- logical sound manager
- old WAV parser
- base mobj struct declaration
- DualString
  • Loading branch information
skyjake committed May 3, 2014
1 parent 8ba4063 commit 5cd3352
Show file tree
Hide file tree
Showing 25 changed files with 341 additions and 162 deletions.
1 change: 1 addition & 0 deletions distrib/win32/setup.iss.template
Expand Up @@ -93,6 +93,7 @@ Source: "bin\wadtool.exe"; DestDir: "{app}\bin"; Flags: ignoreversion; Component

; Libraries
Source: "..\win32\vcredist_x86.exe"; DestDir: "{app}\bin"; Flags: ignoreversion deleteafterinstall; Components: Engine
Source: "bin\doomsday.dll"; DestDir: "{app}\bin"; Flags: ignoreversion; Components: Engine
Source: "bin\deng_appfw.dll"; DestDir: "{app}\bin"; Flags: ignoreversion; Components: Engine
Source: "bin\deng_core.dll"; DestDir: "{app}\bin"; Flags: ignoreversion; Components: Engine
Source: "bin\deng_gui.dll"; DestDir: "{app}\bin"; Flags: ignoreversion; Components: Engine
Expand Down
9 changes: 2 additions & 7 deletions doomsday/client/client.pro
Expand Up @@ -37,6 +37,7 @@ include(../dep_legacy.pri)
include(../dep_shell.pri)
include(../dep_gui.pri)
include(../dep_appfw.pri)
include(../dep_doomsday.pri)

# Definitions ----------------------------------------------------------------

Expand Down Expand Up @@ -185,11 +186,9 @@ DENG_HEADERS += \
include/audio/m_mus2midi.h \
include/audio/s_cache.h \
include/audio/s_environ.h \
include/audio/s_logic.h \
include/audio/s_main.h \
include/audio/s_mus.h \
include/audio/s_sfx.h \
include/audio/s_wav.h \
include/audio/sys_audio.h \
include/audio/sys_audiod_dummy.h \
include/busymode.h \
Expand Down Expand Up @@ -231,7 +230,6 @@ DENG_HEADERS += \
include/de_ui.h \
include/def_data.h \
include/def_main.h \
include/dualstring.h \
include/edit_bias.h \
include/edit_map.h \
include/face.h \
Expand Down Expand Up @@ -536,11 +534,9 @@ SOURCES += \
src/audio/m_mus2midi.cpp \
src/audio/s_cache.cpp \
src/audio/s_environ.cpp \
src/audio/s_logic.cpp \
src/audio/s_main.cpp \
src/audio/s_mus.cpp \
src/audio/s_sfx.cpp \
src/audio/s_wav.cpp \
src/audio/sys_audiod_dummy.cpp \
src/busymode.cpp \
src/client/cl_frame.cpp \
Expand Down Expand Up @@ -568,7 +564,6 @@ SOURCES += \
src/def_data.cpp \
src/def_main.cpp \
src/def_read.cpp \
src/dualstring.cpp \
src/edit_bias.cpp \
src/face.cpp \
src/filesys/file.cpp \
Expand Down Expand Up @@ -879,7 +874,7 @@ macx {
# Fix the dynamic linker paths so they point to ../Frameworks/ inside the bundle.
fixInstallName(Doomsday.app/Contents/MacOS/Doomsday, libdeng_core.2.dylib, ..)
fixInstallName(Doomsday.app/Contents/MacOS/Doomsday, libdeng_legacy.1.dylib, ..)
linkBinaryToBundledLibdengShell(Doomsday.app/Contents/MacOS/Doomsday)
linkBinaryToBundledLibshell(Doomsday.app/Contents/MacOS/Doomsday)

# Clean up previous deployment.
doPostLink("rm -rf Doomsday.app/Contents/PlugIns/")
Expand Down
16 changes: 16 additions & 0 deletions doomsday/client/include/audio/s_main.h
Expand Up @@ -91,6 +91,22 @@ mobj_t *S_GetListenerMobj(void);

void S_Drawer(void);

/**
* Loads a WAV sample from a file. All parameters must be passed, no NULLs are
* allowed.
*
* @note The WAV file must contain a mono sound: only one channel.
*
* @param filename File path of the WAV file.
* @param bits Bits per sample is written here.
* @param rate Sample rate is written here.
* @param samples Number of samples is written here.
*
* @return Buffer that contains the wave data. The caller must free the sample
* data using Z_Free() when it's no longer needed.
*/
void* WAV_Load(const char* filename, int* bits, int* rate, int* samples);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/de_audio.h
Expand Up @@ -34,7 +34,7 @@
#include "audio/s_main.h"
#include "audio/s_cache.h"
#include "audio/s_environ.h"
#include "audio/s_wav.h"
#include "audio/s_logic.h"
#include <doomsday/audio/s_wav.h>
#include <doomsday/audio/logical.h>

#endif
1 change: 1 addition & 0 deletions doomsday/client/include/filesys/fs_main.h
Expand Up @@ -34,6 +34,7 @@

#include "file.h"
#include "filehandle.h"
#include "filehandlebuilder.h"

#ifdef __cplusplus

Expand Down
10 changes: 1 addition & 9 deletions doomsday/client/include/world/p_object.h
Expand Up @@ -33,20 +33,12 @@
#endif
#include <de/Vector>
#include <de/aabox.h>
#include <doomsday/world/mobj.h>

class BspLeaf;
class Plane;
class SectorCluster;

// This macro can be used to calculate a mobj-specific 'random' number.
#define MOBJ_TO_ID(mo) ( (long)(mo)->thinker.id * 48 + ((unsigned long)(mo)/1000) )

// We'll use the base mobj template directly as our mobj.
typedef struct mobj_s
{
DD_BASE_MOBJ_ELEMENTS()
} mobj_t;

#define MOBJ_SIZE gx.mobjSize

#define DEFAULT_FRICTION FIX2FLT(0xe800)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/api_uri.cpp
Expand Up @@ -23,7 +23,7 @@
#include "api_uri.h"

#include "uri.hh"
#include "dualstring.h"
#include <doomsday/dualstring.h>
#include <de/writer.h>
#include <de/reader.h>

Expand All @@ -50,9 +50,9 @@ static void writeUri(const Uri* uri, Writer* writer, int omitComponents = 0)
}
else
{
Str_Write(de::DualString(self->scheme()).toStrUtf8(), writer);
Str_Write(DualString(self->scheme()).toStrUtf8(), writer);
}
Str_Write(de::DualString(self->path()).toStrUtf8(), writer);
Str_Write(DualString(self->path()).toStrUtf8(), writer);
}

#undef Uri_Clear
Expand Down
42 changes: 41 additions & 1 deletion doomsday/client/src/audio/s_main.cpp
Expand Up @@ -31,6 +31,8 @@
#include "de_misc.h"
#include "de_defs.h"

#include "filesys/fs_main.h"
#include "api_filesys.h"
#include "audio/sys_audio.h"
#include "world/p_players.h"
#include "BspLeaf"
Expand Down Expand Up @@ -93,6 +95,8 @@ dd_bool S_Init(void)
dd_bool sfxOK, musOK;
#endif

Sfx_Logical_SetSampleLengthCallback(Sfx_GetSoundLength);

if(CommandLine_Exists("-nosound") || CommandLine_Exists("-noaudio"))
return true;

Expand Down Expand Up @@ -134,7 +138,7 @@ void S_Shutdown(void)
#undef S_MapChange
void S_MapChange(void)
{
// Stop everything in the LSM.
// Stop everything in the LSM.
Sfx_InitLogical();

#ifdef __CLIENT__
Expand Down Expand Up @@ -186,6 +190,7 @@ BEGIN_PROF( PROF_SOUND_STARTFRAME );
#endif

// Remove stopped sounds from the LSM.
Sfx_Logical_SetOneSoundPerEmitter(sfxOneSoundPerEmitter);
Sfx_PurgeLogical();

END_PROF( PROF_SOUND_STARTFRAME );
Expand Down Expand Up @@ -574,6 +579,41 @@ void S_Drawer(void)
#endif // __CLIENT__
}

void* WAV_Load(const char* filename, int* bits, int* rate, int* samples)
{
FileHandle* file = F_Open(filename, "rb");
void* sampledata;
uint8_t* data;
size_t size;

if(!file) return NULL;

// Read in the whole thing.
size = FileHandle_Length(file);

LOG_AS("WAV_Load");
LOGDEV_RES_XVERBOSE("Loading from \"%s\" (size %i, fpos %i)")
<< F_PrettyPath(Str_Text(F_ComposePath(FileHandle_File_const(file))))
<< size
<< FileHandle_Tell(file);

data = (uint8_t*) M_Malloc(size);

FileHandle_Read(file, data, size);
F_Delete(file);
file = 0;

// Parse the RIFF data.
sampledata = WAV_MemoryLoad((const byte*) data, size, bits, rate, samples);
if(!sampledata)
{
LOG_RES_WARNING("Failed to load \"%s\"") << filename;
}

M_Free(data);
return sampledata;
}

/**
* Console command for playing a (local) sound effect.
*/
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/uri.cpp
Expand Up @@ -31,7 +31,7 @@

#include "de_base.h"
#include "de_filesys.h"
#include "dualstring.h"
#include <doomsday/dualstring.h>
#include "Game"

namespace de {
Expand Down
20 changes: 20 additions & 0 deletions doomsday/dep_doomsday.pri
@@ -0,0 +1,20 @@
# Build configuration for using C/legacy support.
INCLUDEPATH += $$PWD/libdoomsday/include

# Use the appropriate library path (trying some alternatives).
!useLibDir($$OUT_PWD/../libdoomsday) {
!useLibDir($$OUT_PWD/../../libdoomsday) {
useLibDir($$OUT_PWD/../../builddir/libdoomsday)
}
}

LIBS += -ldoomsday

macx {
defineTest(linkBinaryToBundledLibdoomsday) {
fixInstallName($${1}, libdoomsday.1.dylib, ..)
}
defineTest(linkToBundledLibdoomsday) {
fixInstallName($${1}.bundle/$$1, libdoomsday.1.dylib, ..)
}
}
3 changes: 3 additions & 0 deletions doomsday/dep_legacy.pri
Expand Up @@ -23,4 +23,7 @@ macx {
defineTest(linkToBundledLiblegacy) {
fixInstallName($${1}.bundle/$$1, libdeng_legacy.1.dylib, ..)
}
defineTest(linkDylibToBundledLiblegacy) {
fixInstallName($${1}.dylib, libdeng_legacy.1.dylib, ..)
}
}
9 changes: 6 additions & 3 deletions doomsday/dep_shell.pri
Expand Up @@ -14,10 +14,13 @@ INCLUDEPATH += $$PWD/$$shellDir/include
LIBS += -ldeng_shell

macx {
defineTest(linkBinaryToBundledLibdengShell) {
defineTest(linkBinaryToBundledLibshell) {
fixInstallName($${1}, libdeng_shell.1.dylib, ..)
}
defineTest(linkToBundledLibdengShell) {
linkBinaryToBundledLibdengShell($${1}.bundle/$$1)
defineTest(linkToBundledLibshell) {
linkBinaryToBundledLibshell($${1}.bundle/$$1)
}
defineTest(linkDylibToBundledLibshell) {
linkBinaryToBundledLibshell($${1}.dylib)
}
}
11 changes: 5 additions & 6 deletions doomsday/doomsday.pro
Expand Up @@ -13,12 +13,11 @@ SUBDIRS = \
liblegacy \
libshell

!deng_noclient|macx {
SUBDIRS += \
libgui \
libappfw \
client
}
!deng_noclient|macx: SUBDIRS += libgui libappfw

SUBDIRS += libdoomsday

!deng_noclient|macx: SUBDIRS += client

SUBDIRS += \
server \
Expand Down
@@ -1,4 +1,4 @@
/** @file
/** @file logical.h Logical Sound Manager.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -18,25 +18,28 @@
* Boston, MA 02110-1301 USA
*/

/*
* s_logic.h: The Logical Sound Manager
*/
#ifndef LIBDOOMSDAY_AUDIO_LOGICAL_H
#define LIBDOOMSDAY_AUDIO_LOGICAL_H

#ifndef __DOOMSDAY_SOUND_LOGICAL_H__
#define __DOOMSDAY_SOUND_LOGICAL_H__
#include "../libdoomsday.h"
#include "../world/mobj.h"
#include <de/types.h>

#ifdef __cplusplus
extern "C" {
#endif

void Sfx_InitLogical(void);
void Sfx_PurgeLogical(void);
void Sfx_StartLogical(int id, mobj_t *origin, dd_bool isRepeating);
int Sfx_StopLogical(int id, mobj_t *origin);
dd_bool Sfx_IsPlaying(int id, mobj_t *origin);
LIBDOOMSDAY_PUBLIC void Sfx_InitLogical(void);
LIBDOOMSDAY_PUBLIC void Sfx_PurgeLogical(void);
LIBDOOMSDAY_PUBLIC void Sfx_StartLogical(int id, mobj_t *origin, dd_bool isRepeating);
LIBDOOMSDAY_PUBLIC int Sfx_StopLogical(int id, mobj_t *origin);
LIBDOOMSDAY_PUBLIC dd_bool Sfx_IsPlaying(int id, mobj_t *origin);

LIBDOOMSDAY_PUBLIC void Sfx_Logical_SetOneSoundPerEmitter(dd_bool enabled);
LIBDOOMSDAY_PUBLIC void Sfx_Logical_SetSampleLengthCallback(uint (*callback)(int));

#ifdef __cplusplus
} // extern "C"
#endif

#endif
#endif // LIBDOOMSDAY_AUDIO_LOGICAL_H

0 comments on commit 5cd3352

Please sign in to comment.