Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into gui-audio-feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua committed Jul 9, 2012
2 parents 461cb7b + 02c7b37 commit 9829837
Show file tree
Hide file tree
Showing 46 changed files with 2,059 additions and 520 deletions.
8 changes: 8 additions & 0 deletions src/base/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@

#include <string>

namespace base
{
void stderr_to_log::write (const char *msg)
{
LOG(ERROR) << msg;
}
}

namespace google
{
int log_level = 3;
Expand Down
21 changes: 21 additions & 0 deletions src/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
#ifndef LOGGING_H_
#define LOGGING_H_

namespace base
{
/*
* Redirect Python stderr to our own logging
* implementation. For this to work, an instance
* of this class has to be assigned to sys.stderr.
*/
class stderr_to_log
{
public:
/*
* Redirect message to log, using level ERROR.
* @param msg the message to append to the log.
*/
void write (const char *msg);
};
}

#ifndef SWIG

#include <iostream> // provide std::endl
#include <string>
#include <cstdlib>
Expand Down Expand Up @@ -122,3 +142,4 @@ namespace logging
} // namespace{}

#endif
#endif
18 changes: 9 additions & 9 deletions src/event/listener_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ bool listener_python::connect_callback (const string & file, const string & clas

// first argument is the listener itself
PyTuple_SET_ITEM (Args, 0, python::pass_instance (this));

// better than NULL
Py_INCREF(Py_None);
PyTuple_SET_ITEM(Args, 1, Py_None);
}

// second argument will be the event that triggered the callback
Expand All @@ -98,7 +102,7 @@ bool listener_python::connect_callback (const string & file, const string & clas
// copy remaining arguments, if any
PyObject *arg = PyTuple_GET_ITEM (args, i-2);
Py_INCREF (arg);
PyTuple_SET_ITEM (Args, i, arg);
PyTuple_SetItem (Args, i, arg);
}

return true;
Expand All @@ -115,22 +119,18 @@ s_int32 listener_python::raise_event (const event* evnt)
{
if (Method && Event->repeat ())
{
// make sure that arguments remain valid while the script executes
PyObject *args = Args;
Py_INCREF (args);

// event that triggered the script is 2nd argument of callback
PyTuple_SET_ITEM (args, 1, python::pass_instance ((event*) evnt));
PyTuple_SetItem (Args, 1, python::pass_instance ((event*) evnt));

// adjust repeat count
Event->do_repeat ();

// execute callback
Method->execute (args);
Method->execute (Args);

// clean up
Py_DECREF (PyTuple_GET_ITEM (args, 1));
Py_DECREF (args);
Py_INCREF(Py_None);
PyTuple_SetItem(Args, 1, Py_None);
}
else
{
Expand Down
20 changes: 15 additions & 5 deletions src/gui/decoration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ bool decoration::init (const std::string & name)
// reset in case we're called more than once
cleanup ();

FileName = name;

base::diskio file;
if (!file.get_record (DECORATION_DIR + name))
{
Expand All @@ -254,7 +256,7 @@ bool decoration::init (const std::string & name)
}
else
{
LOG(ERROR) << logging::indent() << "decoration::init: error loading state '" << id << "'.";
LOG(ERROR) << logging::indent() << "decoration::init: error loading state '" << id << "' from '" << name << "'.";
delete di;
}
}
Expand All @@ -275,6 +277,9 @@ void decoration::cleanup ()
// make sure iterators remain valid
CurrentState = Decoration.end();
FocusOverlay = Decoration.end();

CurrentStateName = "";
HasFocus = false;
}

// set decoration size
Expand All @@ -289,31 +294,36 @@ void decoration::set_size (const u_int16 & length, const u_int16 & height)
// set decoration state
void decoration::set_state (const std::string & state)
{
if (Decoration.size() > 0)
if (Decoration.size() > 0 && CurrentStateName != state)
{
// this is the new state, no matter if it is valid or not
CurrentStateName = state;

decoration_map::iterator NewState = Decoration.find (state);
if (NewState != Decoration.end())
{
CurrentState = NewState;
}
else
{
LOG(WARNING) << logging::indent() << "decoration::set_state: unknown state '" << state << "'.";
LOG(WARNING) << logging::indent() << "decoration '" << FileName << "' missing state '" << state << "'.";
}
}
}

// set focused state
void decoration::set_focused (const bool & has_focus)
{
if (Decoration.size() > 0)
if (Decoration.size() > 0 && HasFocus != has_focus)
{
HasFocus = has_focus;

if (has_focus)
{
FocusOverlay = Decoration.find("Focused");
if (FocusOverlay == Decoration.end())
{
LOG(WARNING) << logging::indent() << "decoration::set_state: unknown state 'Focused'.";
LOG(WARNING) << logging::indent() << "decoration '" << FileName << "' missing state 'Focused'.";
}
}
else
Expand Down
17 changes: 17 additions & 0 deletions src/gui/decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class decoration
CurrentState = Decoration.end();
FocusOverlay = Decoration.end();

FileName = "<default>";
CurrentStateName = "";
HasFocus = false;

init ();
}

Expand Down Expand Up @@ -323,6 +327,19 @@ class decoration
decoration_map::const_iterator CurrentState;
/// decoration by state
decoration_map Decoration;

/*
* @name Members required for logging only.
*/
//@{
/// file the decoration was loaded from
std::string FileName;
/// name of current state
std::string CurrentStateName;
/// whether focus overlay is active
bool HasFocus;
//@}

/// a border of thickness 0
static gfx::drawing_area EMPTY_BORDER;
};
Expand Down
12 changes: 12 additions & 0 deletions src/gui/layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ typedef std::vector<gui::layoutchild> vector_layoutchild;
// select next child
bool layout::moveright()
{
// no next child that could possibly receive the focus
if (Children.size() < 2) return false;

u_int32 old = Selected;
do
{
Expand All @@ -59,6 +62,9 @@ bool layout::moveright()
// select next child
bool layout::movedown()
{
// no next child that could possibly receive the focus
if (Children.size() < 2) return false;

u_int32 old = Selected;
do
{
Expand All @@ -83,6 +89,9 @@ bool layout::movedown()
// select previous child
bool layout::moveleft()
{
// no previous child that could possibly receive the focus
if (Children.size() < 2) return false;

u_int32 old = Selected;
do
{
Expand All @@ -107,6 +116,9 @@ bool layout::moveleft()
// select previous child
bool layout::moveup()
{
// no previous child that could possibly receive the focus
if (Children.size() < 2) return false;

u_int32 old = Selected;
do
{
Expand Down
2 changes: 1 addition & 1 deletion src/py-runtime/Makefile.am
Original file line number Diff line number Diff line change
@@ -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_runtime.cc
CLEANFILES = $(top_srcdir)/src/py-runtime/py_runtime.cc

## SWIG runtime support
lib_LTLIBRARIES = libadonthell_py_runtime.la
Expand Down
32 changes: 23 additions & 9 deletions src/py-runtime/py_runtime.i
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
%{

#include "base/logging.h"

extern "C" {

#ifndef SWIGVERSION
Expand All @@ -19,7 +22,7 @@ static void print_type_info (swig_type_info **typelist)
for (swig_type_info *ti = *typelist; ti != NULL; ti = ti->prev)
{
const char *name = SWIG_TypePrettyName (ti);
fprintf (stderr, " - %s\n", name);
LOG(ERROR) << " - " << name;
}
}

Expand All @@ -30,7 +33,7 @@ void log_py_objects ()
swig_type_info ** typelist = SWIG_Python_GetTypeListHandle();
if (*typelist != NULL)
{
fprintf (stderr, "These types are known to SWIG:\n");
LOG(ERROR) << "These types are known to SWIG:";
print_type_info (typelist);
}
}
Expand All @@ -44,7 +47,7 @@ PyObject *cxx_to_py (void *instance, const char *name, const bool & ownership)
swig_type_info * tt = SWIG_TypeQueryTL (*typelist, name);
if (tt) return SWIG_NewPointerObj (instance, tt, ownership);

fprintf (stderr, "*** cxx_to_py: '%s' not found in SWIGs typelist:\n", name);
LOG(ERROR) << "cxx_to_py: '" << name << "' not found in SWIGs typelist:";
print_type_info (typelist);
exit(1);
}
Expand All @@ -58,7 +61,7 @@ void py_to_cxx (PyObject *instance, const char *name, void **retval)
swig_type_info * tt = SWIG_TypeQueryTL (*typelist, name);
if (tt == NULL || SWIG_ConvertPtr (instance, retval, tt, 0) == -1)
{
fprintf (stderr, "*** py_to_cxx: '%s' not found in SWIGs typelist:", name);
LOG(ERROR) << "py_to_cxx: '" << name << "' not found in SWIGs typelist:";
print_type_info (typelist);
exit(1);
}
Expand Down Expand Up @@ -93,10 +96,10 @@ struct type_collector
// print list of types
void print ()
{
printf ("%s\n", name);
LOG(ERROR) << name;

for (type_collector *tc = next; tc != NULL; tc = tc->next)
printf (" - %s\n", tc->name);
LOG(ERROR) << " - " << tc->name;
}

const char *name;
Expand Down Expand Up @@ -143,12 +146,12 @@ SWIGEXPORT PyObject *cxx_to_py (void *instance, const char *name, const bool & o
swig_type_info * tt = SWIG_Python_TypeQuery (name);
if (tt) return SWIG_NewPointerObj (instance, tt, ownership);

fprintf (stderr, "*** cxx_to_py: '%s' not found. ", name);
LOG(ERROR) << "cxx_to_py: '" << name << "' not found. ";
log_py_objects ();
}
else
{
fprintf (stderr, "*** cxx_to_py: no Python module imported!\n");
LOG(ERROR) << "cxx_to_py: no Python module imported!";
}

exit(1);
Expand All @@ -160,13 +163,24 @@ SWIGEXPORT void py_to_cxx (PyObject *instance, const char *name, void **retval)
swig_type_info * tt = SWIG_Python_TypeQuery (name);
if (tt == NULL || SWIG_ConvertPtr (instance, retval, tt, 0) == -1)
{
fprintf (stderr, "*** py_to_cxx: '%s' not found. ", name);
LOG(ERROR) << "py_to_cxx: '" << name << "' not found. ";
log_py_objects();
exit(1);
}
}

#endif // SWIGVERSION <= 0x010324

SWIGEXPORT void check_module_version (const char *name, const unsigned int & module_ver)
{
if (SWIGVERSION != module_ver)
{
LOG(ERROR) << "Module '" << name << "' and SWIG runtime versions are different!";
LOG(FATAL) << "Please make clean and recompile to resolve this issue and ensure "
<< "that the Adonthell engine is properly installed.";
}
}

}

%}
11 changes: 10 additions & 1 deletion src/py-wrappers/adonthell/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
AM_CXXFLAGS = -I$(top_srcdir)/src
EXTRA_DIST = py_debug.i py_base.i py_event.i py_gfx.i py_gui.i py_input.i py_audio.i py_main.i py_rpg.i py_world.i CMakeLists.txt
CLEANFILES = $(top_srcdir)/src/py-wrappers/adonthell/py_*_wrap.cc
CLEANFILES = $(top_srcdir)/src/py-wrappers/adonthell/py_debug_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_base_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_event_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_gfx_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_gui_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_input_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_audio_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_main_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_rpg_wrap.cc \
$(top_srcdir)/src/py-wrappers/adonthell/py_world_wrap.cc

## Python wrapper files.
pkgpyexec_PYTHON = __init__.py debug.py base.py event.py gfx.py gui.py input.py audio.py main.py rpg.py world.py
Expand Down
8 changes: 8 additions & 0 deletions src/py-wrappers/adonthell/py_audio.i
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@

using namespace audio;

extern "C" {
void check_module_version (const char *name, const unsigned int & module_ver);
}
%}

%init %{
check_module_version (SWIG_name, SWIGVERSION);
%}


%include "stdint.i"
%include "std_string.i"

Expand Down
10 changes: 10 additions & 0 deletions src/py-wrappers/adonthell/py_base.i
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ namespace base
Py_XDECREF (load);
}
}

extern "C" {
void check_module_version (const char *name, const unsigned int & module_ver);
}
%}

%init %{
check_module_version (SWIG_name, SWIGVERSION);
%}


%include "stdint.i"
%include "std_string.i"

Expand Down Expand Up @@ -161,6 +170,7 @@ namespace base {
typedef long time_t;
%include "base/savegame.h"
%include "base/serializer.h"
%include "base/logging.h"

%template(py_serializer) base::serializer<PyObject>;

Expand Down
Loading

0 comments on commit 9829837

Please sign in to comment.