Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ksterker/adonthell
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Aug 4, 2010
2 parents 60fae2e + 978d76f commit a08d20d
Show file tree
Hide file tree
Showing 38 changed files with 1,190 additions and 363 deletions.
10 changes: 5 additions & 5 deletions src/audio/Makefile.am
Expand Up @@ -51,21 +51,21 @@ _sdl_la_DEPENDENCIES = libadonthell_audio.la

## Unit tests
test_CXXFLAGS = $(libgmock_CFLAGS) $(libgtest_CFLAGS)
test_LDADD = $(libgmock_LIBS) $(libgtest_LIBS)
test_LDADD = $(libgmock_LIBS) $(libgtest_LIBS) $(top_builddir)/src/audio/libadonthell_audio.la

test_audio_SOURCES = $(libadonthell_audio_la_SOURCES) test_audio.cc
test_audio_SOURCES = test_audio.cc
test_audio_CXXFLAGS = $(libadonthell_audio_la_CXXFLAGS) $(test_CXXFLAGS)
test_audio_LDADD = $(libadonthell_audio_la_LIBADD) $(test_LDADD)

test_audio_event_SOURCES = $(libadonthell_audio_la_SOURCES) test_audio_event.cc
test_audio_event_SOURCES = test_audio_event.cc
test_audio_event_CXXFLAGS = $(libadonthell_audio_la_CXXFLAGS) $(test_CXXFLAGS)
test_audio_event_LDADD = $(libadonthell_audio_la_LIBADD) $(test_LDADD)

test_audio_manager_SOURCES = $(libadonthell_audio_la_SOURCES) test_audio_manager.cc
test_audio_manager_SOURCES = test_audio_manager.cc
test_audio_manager_CXXFLAGS = $(libadonthell_audio_la_CXXFLAGS) $(test_CXXFLAGS)
test_audio_manager_LDADD = $(libadonthell_audio_la_LIBADD) $(test_LDADD)

test_sound_SOURCES = $(libadonthell_audio_la_SOURCES) test_sound.cc
test_sound_SOURCES = test_sound.cc
test_sound_CXXFLAGS = $(libadonthell_audio_la_CXXFLAGS) $(test_CXXFLAGS)
test_sound_LDADD = $(libadonthell_audio_la_LIBADD) $(test_LDADD)

Expand Down
9 changes: 0 additions & 9 deletions src/audio/audio_manager.cc
Expand Up @@ -90,13 +90,4 @@ namespace audio
return true;
}

bool audio_manager::set_sound_dir(const std::string sound_dir) {
LOG(INFO) << "set_sound_dir(" << sound_dir << "); was: "
<< sound_dir_;

sound_dir_ = sound_dir;

return true;
}

} // namespace{}
11 changes: 0 additions & 11 deletions src/audio/audio_manager.h
Expand Up @@ -85,10 +85,6 @@ namespace audio
*/
static const int get_audio_rate() { return audio_rate_; }

/** @return sound_dir directory in which sound files reside
*/
static const std::string get_sound_dir() { return sound_dir_; }

/** Sets the audio buffer size
*
* @param audio_buffers size of audio buffer, in bytes
Expand Down Expand Up @@ -125,13 +121,6 @@ namespace audio
*/
static bool set_audio_rate(const int audio_rate = DEFAULT_AUDIO_RATE);

/** Sets the directory in which sound files reside
*
* @param sound_dir directory in which sound files reside
* @return true on success, false otherwise
*/
static bool set_sound_dir(const std::string sound_dir = DEFAULT_SOUND_DIR);

protected:
static int audio_buffers_;
static int audio_channels_;
Expand Down
18 changes: 12 additions & 6 deletions src/audio/sound.cc
Expand Up @@ -28,6 +28,7 @@

#include <string>

#include "base/base.h"
#include "audio/audio.h"
#include "audio/audio_manager.h"
#include "audio/sound.h"
Expand All @@ -49,12 +50,17 @@ sound::sound (const std::string &filename)
LOG(INFO) << logging::indent() << "sound::sound(" << filename << ") called";
logging::increment_log_indent_level();

std::string sound_dir = audio_manager::get_sound_dir();
LOG(INFO) << logging::indent() << "sound_dir: '" << sound_dir << "'";

m_filename = sound_dir + filename;
open_file();

m_filename = "audio/" + filename;
if (base::Paths.find_in_path (m_filename))
{
open_file();
}
else
{
m_channel = -1;
m_sample = NULL;
}

logging::decrement_log_indent_level();
}

Expand Down
8 changes: 4 additions & 4 deletions src/audio/test_audio_event.cc
Expand Up @@ -67,23 +67,23 @@ namespace audio
}; // class{}

TEST_F(audio_event_Test, constructor_Default) {
EXPECT_EQ("foo.ogg", ev->sample().getfilename());
EXPECT_EQ("audio/foo.ogg", ev->sample().getfilename());
}

TEST_F(audio_event_Test, put_state_Filename) {
EXPECT_EQ("foo.ogg", ev->sample().getfilename());
EXPECT_EQ("audio/foo.ogg", ev->sample().getfilename());

base::flat f;
ev->put_state(f);

sound_noop *s2 = new sound_noop("bar.ogg");
audio_event *ev2 = new audio_event(s2);

EXPECT_EQ("bar.ogg", ev2->sample().getfilename());
EXPECT_EQ("audio/bar.ogg", ev2->sample().getfilename());

ev2->get_state(f);

EXPECT_EQ("foo.ogg", ev2->sample().getfilename());
EXPECT_EQ("audio/foo.ogg", ev2->sample().getfilename());

delete ev2;
delete s2;
Expand Down
12 changes: 0 additions & 12 deletions src/audio/test_audio_manager.cc
Expand Up @@ -86,12 +86,6 @@ namespace audio
EXPECT_EQ(DEFAULT_AUDIO_RATE, audio_manager::get_audio_rate());
}

TEST_F(audio_manager_Test, set_sound_dir_Default) {
audio_manager::set_sound_dir();

EXPECT_EQ(DEFAULT_SOUND_DIR, audio_manager::get_sound_dir());
}

TEST_F(audio_manager_Test, set_audio_buffers) {
audio_manager::set_audio_buffers(27);

Expand Down Expand Up @@ -122,12 +116,6 @@ namespace audio
EXPECT_EQ(27, audio_manager::get_audio_rate());
}

TEST_F(audio_manager_Test, set_sound_dir) {
audio_manager::set_sound_dir("27");

EXPECT_EQ("27", audio_manager::get_sound_dir());
}

} // namespace{}


Expand Down
6 changes: 3 additions & 3 deletions src/audio/test_sound.cc
Expand Up @@ -64,19 +64,19 @@ namespace audio
}; // class{}

TEST_F(sound_Test, constructor_Default) {
EXPECT_EQ("foo.ogg", s->getfilename());
EXPECT_EQ("audio/foo.ogg", s->getfilename());
}

TEST_F(sound_Test, put_state_Filename) {
EXPECT_EQ("foo.ogg", s->getfilename());
EXPECT_EQ("audio/foo.ogg", s->getfilename());

base::flat f;
s->put_state(f);

sound_noop *s2 = new sound_noop();
s2->get_state(f);

EXPECT_EQ("foo.ogg", s2->getfilename());
EXPECT_EQ("audio/foo.ogg", s2->getfilename());
EXPECT_EQ(-1, s2->get_channel());

EXPECT_FALSE(s2->get_forcedhalt());
Expand Down
8 changes: 0 additions & 8 deletions src/main/adonthell.cc
Expand Up @@ -118,14 +118,6 @@ bool app::init_modules (const u_int16 & modules)
if (m & AUDIO)
{
audio::setup (Cfg);
audio::audio_manager::set_sound_dir(Userdatadir + "/" + Game + "/audio/");

LOG(INFO) << logging::indent()
<< "audio::audio_manager::sound_dir: '"
<< audio::audio_manager::get_sound_dir()
<< "'"
;

if (!audio::init (Backend)) {
LOG(ERROR) << logging::indent() << "audio::init() failed";

Expand Down
2 changes: 1 addition & 1 deletion src/py-runtime/Makefile.am
@@ -1,6 +1,6 @@
AM_CXXFLAGS = -I$(top_srcdir)/src
EXTRA_DIST = py_runtime.i CMakeLists.txt
CLEANFILES = $(top_srcdir)/src/py-wrappers/runtime/py_*_wrap.cc
CLEANFILES = $(top_srcdir)/src/py-wrappers/runtime/py_runtime.cc

## SWIG runtime support
lib_LTLIBRARIES = libadonthell_py_runtime.la
Expand Down
9 changes: 9 additions & 0 deletions src/python/CMakeLists.txt
Expand Up @@ -26,6 +26,15 @@ target_link_libraries(adonthell_python
${PYTHON_LIBRARIES}
adonthell_base)

################################
# Unit tests
IF(DEVBUILD)
add_executable(test_python test_python.cc)
target_link_libraries(test_python ${TEST_LIBRARIES} adonthell_python)
add_test(NAME Python COMMAND test_python)
ENDIF(DEVBUILD)

################################
# install
adonthell_install_lib (adonthell_python)
adonthell_install_include(python "${adonthell_python_HEADERS}")
14 changes: 14 additions & 0 deletions src/python/Makefile.am
Expand Up @@ -27,3 +27,17 @@ libadonthell_python_la_CXXFLAGS = $(PY_CFLAGS) $(AM_CXXFLAGS)
libadonthell_python_la_LIBADD = $(PY_LIBS) \
$(top_builddir)/src/base/libadonthell_base.la \
$(SWIGRUNTIME_LIBS) -lstdc++


## Unit tests
test_CXXFLAGS = $(libgmock_CFLAGS) $(libgtest_CFLAGS)
test_LDADD = $(libgmock_LIBS) $(libgtest_LIBS) $(top_builddir)/src/python/libadonthell_python.la

test_python_SOURCES = test_python.cc
test_python_CXXFLAGS = $(libadonthell_python_la_CXXFLAGS) $(test_CXXFLAGS)
test_python_LDADD = $(libadonthell_python_la_LIBADD) $(test_LDADD)

TESTS = \
test_python

check_PROGRAMS = $(TESTS)
6 changes: 6 additions & 0 deletions src/python/method.h
Expand Up @@ -67,6 +67,12 @@ namespace python
*/
std::string name () const;

/**
* Return name of enclosing script.
* @return script name.
*/
std::string script () const { return Script->class_name(); }

/**
* Execute the connected %method with the given arguments.
* @param args a python tuple to be passed to the %method.
Expand Down
44 changes: 42 additions & 2 deletions src/python/python.cc
Expand Up @@ -102,17 +102,55 @@ namespace python
return ret;
}

// pad tuple
PyObject *pad_tuple (PyObject *tuple, const u_int16 & len)
{
// make sure the given arguments are a tuple
if (tuple && !PyTuple_Check (tuple))
{
fprintf (stderr, "*** error: python::pad_tuple: argument must be a tuple!\n");
return NULL;
}

// calculate size of argument tuple required
u_int16 size = tuple ? PyTuple_GET_SIZE (tuple) + len : len;

// prepare callback arguments
PyObject *new_tuple = PyTuple_New (size);

// pad with none object
for (u_int16 i = 0; i < len; i++)
{
PyTuple_SET_ITEM (new_tuple, i, Py_None);
}

// copy remaining objects, if any
for (u_int16 i = len; i < size; i++)
{
PyObject *o = PyTuple_GET_ITEM (tuple, i - len);
Py_XINCREF (o);
PyTuple_SET_ITEM (new_tuple, i, o);
}

return new_tuple;
}

// unflatten the contents of a tuple
PyObject *get_tuple (base::flat & in, const u_int16 & start)
{
u_int16 len = in.get_uint16 ("pln") + start;
PyObject *tuple = PyTuple_New (len);
void *value;

for (u_int16 i = start; i < len; i++)
{
switch (int type = in.next (&value))
{
case base::flat::T_CHAR:
{
PyTuple_SetItem (tuple, i, Py_None);
break;
}
case base::flat::T_STRING:
{
// Stolen reference
Expand Down Expand Up @@ -147,10 +185,12 @@ namespace python
{
// Borrowed reference
PyObject *item = PyTuple_GetItem (tuple, i);
if (item == NULL)
out.put_char ("n", ' ');

// Check for the type of this object
// String?
if (PyString_Check (item))
else if (PyString_Check (item))
out.put_string ("s", PyString_AsString (item));

// Integer?
Expand Down
12 changes: 11 additions & 1 deletion src/python/python.h
Expand Up @@ -316,9 +316,19 @@ namespace python
//@}

/**
* @name Loading / Saving
* @name Convenience functions.
*/
//@{
/**
* Pads the front of the given tuple, moving the existing
* entries to the end of the tuple. If the given tuple is
* NULL, returns a new tuple of size len. Reference count
* of the contents of the given tuple is increased by one.
*
* @return a new tuple or NULL on error.
*/
PyObject *pad_tuple (PyObject *tuple, const u_int16 & len);

/**
* Read the contents of a tuple from given stream.
* @param in flattener to read the tuple from.
Expand Down

0 comments on commit a08d20d

Please sign in to comment.