[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Adonthell-commits] CVS: adonthell/src Makefile.am,1.94,1.95 dialog.cc,1
From: |
Kai Sterker <address@hidden> |
Subject: |
[Adonthell-commits] CVS: adonthell/src Makefile.am,1.94,1.95 dialog.cc,1.30,1.31 dialog.h,1.52,1.53 event.cc,1.15,1.16 event.h,1.27,1.28 event_handler.cc,1.3,1.4 event_handler.h,1.3,1.4 event_handler_base.h,1.3,1.4 event_list.cc,1.3,1.4 event_list.h,1.2,1.3 gamedata.cc,1.23,1.24 gamedate.cc,1.4,1.5 map_event.cc,1.1,1.2 map_event.h,1.1,1.2 map_event_handler.cc,1.2,1.3 map_event_handler.h,1.2,1.3 mapcharacter.cc,1.44,1.45 mapcharacter.h,1.54,1.55 time_event.cc,1.2,1.3 time_event.h,1.3,1.4 time_event_handler.cc,1.3,1.4 time_event_handler.h,1.3,1.4 |
Date: |
Sun, 18 Aug 2002 15:53:19 -0400 |
Update of /cvsroot/adonthell/adonthell/src
In directory subversions:/tmp/cvs-serv882
Modified Files:
Makefile.am dialog.cc dialog.h event.cc event.h
event_handler.cc event_handler.h event_handler_base.h
event_list.cc event_list.h gamedata.cc gamedate.cc
map_event.cc map_event.h map_event_handler.cc
map_event_handler.h mapcharacter.cc mapcharacter.h
time_event.cc time_event.h time_event_handler.cc
time_event_handler.h
Log Message:
FIXED Makefile to properly recreate py_adonthell_wrap.cc
FIXED memory leak in dialog.cc
FIXED memory leak and other bugs in event_system
There might be bugs remaining, but I'm gonna try something dangerous with my
HD, so I better commit before completely destroying it ;)
Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/Makefile.am,v
retrieving revision 1.94
retrieving revision 1.95
diff -C2 -r1.94 -r1.95
*** Makefile.am 9 Aug 2002 20:01:26 -0000 1.94
--- Makefile.am 18 Aug 2002 19:53:16 -0000 1.95
***************
*** 17,32 ****
CLEANFILES = $(moddata_SCRIPTS)
! libadonthell_a_SOURCES = adonthell.cc animation.cc audio.cc \
! character_base.cc character.cc data_screen.cc dialog.cc dialog_screen.cc \
! drawable.cc drawing_area.cc event.cc event_handler.cc event_list.cc \
! fileops.cc game.cc gamedata.cc gamedate.cc gametime.cc image.cc input.cc \
! label.cc label_input.cc landmap.cc lex.prefs.cc map_event.cc \
! map_event_handler.cc mapsquare_walkable.cc mapcharacter.cc mapsquare.cc \
! mapobject.cc mapview.cc nls.cc path.cc pnm.cc prefs.cc py_callback.cc \
! python_class.cc py_adonthell_wrap.cc py_object.cc quest.cc screen.cc \
! surface.cc storage.cc text_bubble.cc time_event.cc time_event_handler.cc \
! win_background.cc win_base.cc win_border.cc win_container.cc win_font.cc \
! win_keys.cc win_manager.cc win_scrollbar.cc win_scroll.cc win_select.cc \
! win_theme.cc win_event.cc yarg.cc \
adonthell.h animation.h audio.h callback.h py_callback.h character_base.h \
character.h gamedata.h data_screen.h dialog.h dialog_screen.h drawable.h \
--- 17,21 ----
CLEANFILES = $(moddata_SCRIPTS)
! headers = \
adonthell.h animation.h audio.h callback.h py_callback.h character_base.h \
character.h gamedata.h data_screen.h dialog.h dialog_screen.h drawable.h \
***************
*** 40,46 ****
win_label.h win_mapview.h label.h label_input.h win_scrollbar.h win_scroll.h \
win_select.h win_theme.h win_keys.h win_event.h win_types.h win_write.h \
! win_manager.h win_object.h window.h win_wrappers.h yarg.h mixer.c music.c \
! music_cmd.c music_cmd.h music_ogg.c music_ogg.h wave.h wavestream.c \
! wavestream.h SDL_mixer.h
libadonthell_LDADD = $(SDL_LIBS) $(OGG_LIBS) $(PY_LIBS)
--- 29,48 ----
win_label.h win_mapview.h label.h label_input.h win_scrollbar.h win_scroll.h \
win_select.h win_theme.h win_keys.h win_event.h win_types.h win_write.h \
! win_manager.h win_object.h window.h win_wrappers.h yarg.h
!
! libadonthell_a_SOURCES = adonthell.cc animation.cc audio.cc \
! character_base.cc character.cc data_screen.cc dialog.cc dialog_screen.cc \
! drawable.cc drawing_area.cc event.cc event_handler.cc event_list.cc \
! fileops.cc game.cc gamedata.cc gamedate.cc gametime.cc image.cc input.cc \
! label.cc label_input.cc landmap.cc lex.prefs.cc map_event.cc \
! map_event_handler.cc mapsquare_walkable.cc mapcharacter.cc mapsquare.cc \
! mapobject.cc mapview.cc nls.cc path.cc pnm.cc prefs.cc py_callback.cc \
! python_class.cc py_adonthell_wrap.cc py_object.cc quest.cc screen.cc \
! surface.cc storage.cc text_bubble.cc time_event.cc time_event_handler.cc \
! win_background.cc win_base.cc win_border.cc win_container.cc win_font.cc \
! win_keys.cc win_manager.cc win_scrollbar.cc win_scroll.cc win_select.cc \
! win_theme.cc win_event.cc yarg.cc mixer.c music.c music_cmd.c music_cmd.h \
! music_ogg.c music_ogg.h wave.h wavestream.c wavestream.h SDL_mixer.h \
! $(headers)
libadonthell_LDADD = $(SDL_LIBS) $(OGG_LIBS) $(PY_LIBS)
***************
*** 51,55 ****
# Note: adonthell.py is also built by this target.
! py_adonthell_wrap.cc : py_adonthell.i
@if test "${P_SWIG}"; then \
${P_SWIG} -python -shadow ${SDL_CFLAGS} -I$(srcdir) -I$(srcdir)/..
-c++ -make_default -o $(srcdir)/$*.cc $(srcdir)/py_adonthell.i; \
--- 53,57 ----
# Note: adonthell.py is also built by this target.
! py_adonthell_wrap.cc : py_adonthell.i $(headers)
@if test "${P_SWIG}"; then \
${P_SWIG} -python -shadow ${SDL_CFLAGS} -I$(srcdir) -I$(srcdir)/..
-c++ -make_default -o $(srcdir)/$*.cc $(srcdir)/py_adonthell.i; \
Index: dialog.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/dialog.cc,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** dialog.cc 25 Jun 2002 16:24:15 -0000 1.30
--- dialog.cc 18 Aug 2002 19:53:16 -0000 1.31
***************
*** 24,28 ****
#include <algorithm>
#include <iostream>
! #include <string>
#include "character.h"
--- 24,28 ----
#include <algorithm>
#include <iostream>
! #include <string.h>
#include "character.h"
***************
*** 258,269 ****
// execute embedded functions and replace shortcuts
// yeah, the c string library hurts, but at least it's fast ;)
! char* dialog::scan_string (const char *s)
{
u_int32 begin, end, len;
PyObject *result;
! char *start, *mid, *string = NULL;
! char *tmp, *newstr = new char[strlen (s)+1];
character *the_player = data::the_player;
! strcpy (newstr, s);
// replace $... shortcuts
--- 258,268 ----
// execute embedded functions and replace shortcuts
// yeah, the c string library hurts, but at least it's fast ;)
! string dialog::scan_string (const char *s)
{
u_int32 begin, end, len;
PyObject *result;
! char *tmp, *start, *mid, *str = NULL;
character *the_player = data::the_player;
! string newstr (s);
// replace $... shortcuts
***************
*** 271,275 ****
{
// check wether the string contains shortcut code at all
! start = strchr (newstr, '$');
if (start == NULL) break;
--- 270,274 ----
{
// check wether the string contains shortcut code at all
! start = strchr (newstr.c_str (), '$');
if (start == NULL) break;
***************
*** 277,287 ****
if (strncmp (start, "$name", 5) == 0)
{
! begin = strlen (newstr) - strlen (start);
! tmp = new char[strlen (newstr) - 4 + strlen
(the_player->get_name().c_str ())];
! strncpy (tmp, newstr, begin);
tmp[begin] = 0;
strcat (tmp, the_player->get_name().c_str ());
strcat (tmp, start+5);
- delete[] newstr;
newstr = tmp;
--- 276,285 ----
if (strncmp (start, "$name", 5) == 0)
{
! begin = newstr.length () - strlen (start);
! tmp = new char[newstr.length () - 4 + strlen
(the_player->get_name().c_str ())];
! strncpy (tmp, newstr.c_str (), begin);
tmp[begin] = 0;
strcat (tmp, the_player->get_name().c_str ());
strcat (tmp, start+5);
newstr = tmp;
***************
*** 294,315 ****
// extract the "$fm{.../...} part
end = strcspn (start, "}");
! string = new char[end];
! string[end-1] = 0;
! strncpy (string, start+3, end);
if (the_player->storage::get_val ("gender") == FEMALE)
! mid = get_substr (string, "{", "/");
else
! mid = get_substr (string, "/", "}");
! begin = strlen(newstr) - strlen(start);
! tmp = new char[strlen(newstr) - end + strlen (mid)];
! strncpy (tmp, newstr, begin);
tmp[begin] = 0;
strcat (tmp, mid);
strcat (tmp, start+end+1);
! delete[] string;
! delete[] newstr;
delete[] mid;
newstr = tmp;
--- 292,312 ----
// extract the "$fm{.../...} part
end = strcspn (start, "}");
! str = new char[end];
! str[end-1] = 0;
! strncpy (str, start+3, end);
if (the_player->storage::get_val ("gender") == FEMALE)
! mid = get_substr (str, "{", "/");
else
! mid = get_substr (str, "/", "}");
! begin = newstr.length () - strlen(start);
! tmp = new char[newstr.length () - end + strlen (mid)];
! strncpy (tmp, newstr.c_str (), begin);
tmp[begin] = 0;
strcat (tmp, mid);
strcat (tmp, start+end+1);
! delete[] str;
delete[] mid;
newstr = tmp;
***************
*** 327,343 ****
{
// check wether the string contains python code at all
! start = strchr (newstr, '{');
if (start == NULL) break;
end = strcspn (start, "}");
! string = new char[end];
! string[end-1] = 0;
// extract the code without the brackets
! strncpy (string, start+1, end-1);
// run the string
! result = PyObject_CallMethod (dialogue.get_instance (), string, NULL);
#ifdef PY_DEBUG
python::show_traceback ();
--- 324,340 ----
{
// check wether the string contains python code at all
! start = strchr (newstr.c_str (), '{');
if (start == NULL) break;
end = strcspn (start, "}");
! str = new char[end];
! str[end-1] = 0;
// extract the code without the brackets
! strncpy (str, start+1, end-1);
// run the string
! result = PyObject_CallMethod (dialogue.get_instance (), str, NULL);
#ifdef PY_DEBUG
python::show_traceback ();
***************
*** 351,360 ****
// Replace existing with new, changed string
// 1. Calculate string's length
! len = strlen (newstr);
begin = len - strlen (start);
! tmp = new char[(mid ? strlen(mid) : 0) + len - strlen(string)];
// 2. Merge prefix, resulting string and postfix into new string
! strncpy (tmp, newstr, begin);
tmp[begin] = 0;
if (mid) strcat (tmp, mid);
--- 348,357 ----
// Replace existing with new, changed string
// 1. Calculate string's length
! len = newstr.length ();
begin = len - strlen (start);
! tmp = new char[(mid ? strlen(mid) : 0) + len - strlen(str)];
// 2. Merge prefix, resulting string and postfix into new string
! strncpy (tmp, newstr.c_str (), begin);
tmp[begin] = 0;
if (mid) strcat (tmp, mid);
***************
*** 362,371 ****
// 3. Exchange strings
- delete[] newstr;
newstr = tmp;
// Cleanup
Py_XDECREF (result);
! delete[] string;
}
--- 359,367 ----
// 3. Exchange strings
newstr = tmp;
// Cleanup
Py_XDECREF (result);
! delete[] str;
}
Index: dialog.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/dialog.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -r1.52 -r1.53
*** dialog.h 25 Jun 2002 16:24:15 -0000 1.52
--- dialog.h 18 Aug 2002 19:53:16 -0000 1.53
***************
*** 175,179 ****
void clear (); // Cleanup
bool setup (); // Further dialogue initialisation
! char* scan_string (const char*);// Look for enclosed code and execute it
char* get_substr (const char*, char*, char*);
};
--- 175,179 ----
void clear (); // Cleanup
bool setup (); // Further dialogue initialisation
! string scan_string (const char*);// Look for enclosed code and execute it
char* get_substr (const char*, char*, char*);
};
Index: event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.cc,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** event.cc 11 Aug 2002 13:02:29 -0000 1.15
--- event.cc 18 Aug 2002 19:53:16 -0000 1.16
***************
*** 29,36 ****
--- 29,38 ----
{
Repeat = -1;
+ Registered = false;
Script = NULL;
PyFunc = NULL;
Args = NULL;
Action = ACTION_NOTHING;
+ List = NULL;
}
***************
*** 39,44 ****
{
// automatically remove myself from the event_handler
! event_handler::remove_event (this);
clear ();
}
--- 41,49 ----
{
// automatically remove myself from the event_handler
! if (Registered) event_handler::remove_event (this);
+ // ... and from the event_list
+ if (List) List->remove_event (this);
+
clear ();
}
***************
*** 171,173 ****
--- 176,195 ----
return true;
+ }
+
+ // the event_list this event is kept in
+ void event::set_list (event_list *l)
+ {
+ List = l;
+ }
+
+ // repeat an event
+ s_int32 event::do_repeat ()
+ {
+ s_int32 count = -1;
+
+ if (Repeat > 0) count = --Repeat;
+ if (count == 0) delete this;
+
+ return count;
}
Index: event.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -r1.27 -r1.28
*** event.h 9 Aug 2002 20:01:26 -0000 1.27
--- event.h 18 Aug 2002 19:53:16 -0000 1.28
***************
*** 30,33 ****
--- 30,34 ----
using std::string;
+ class event_list;
/**
***************
*** 97,101 ****
return Type;
}
!
/**
* Return whether this event should be repeated.
--- 98,129 ----
return Type;
}
!
! /**
! * Test whether the %event is registered with the %event handler.
! *
! * @return \c true if this is the case, \c false otherwise.
! */
! bool registered () const
! {
! return Registered;
! }
! #ifndef SWIG
! /**
! * Set whether the %event is registered with the %event handler.
! *
! * @param reg Set to \c true if it is, to \c false otherwise.
! */
! void set_registered (bool reg)
! {
! Registered = reg;
! }
!
! /**
! * Tell the whether it is kept in an %event_list.
! *
! * @param list The %event_list this event has been added to.
! */
! void set_list (event_list *list);
! #endif // SWIG
/**
* Return whether this event should be repeated.
***************
*** 104,120 ****
* -1 in case it should be repeated unlimited times.
*/
! s_int32 repeat ()
{
- if (Repeat > 0) Repeat--;
-
return Repeat;
}
!
/**
* Set whether this event should be repeated. A number greater than 0
! * will repeat the event that many times, a number less than 0 will
* repeat the event forever. A number equal to 0 won't repeat the event.
*
! * @param count How often the event should be repeated.
*/
void set_repeat (s_int32 count)
--- 132,146 ----
* -1 in case it should be repeated unlimited times.
*/
! s_int32 repeat () const
{
return Repeat;
}
!
/**
* Set whether this event should be repeated. A number greater than 0
! * will execute the event that many times, a number less than 0 will
* repeat the event forever. A number equal to 0 won't repeat the event.
*
! * @param count How often the event should be repeated.
*/
void set_repeat (s_int32 count)
***************
*** 132,137 ****
*
* @param evnt The %event that triggered the execution.
*/
! virtual void execute (const event& evnt) = 0;
/**
--- 158,165 ----
*
* @param evnt The %event that triggered the execution.
+ *
+ * @return The number of times the %event needs to be repeated.
*/
! virtual s_int32 execute (const event* evnt) = 0;
/**
***************
*** 141,145 ****
* @return \e true if the events are equal, \e false otherwise.
*/
! virtual bool equals (const event& evnt) = 0;
//@}
--- 169,173 ----
* @return \e true if the events are equal, \e false otherwise.
*/
! virtual bool equals (const event* evnt) = 0;
//@}
***************
*** 206,209 ****
--- 234,246 ----
#ifndef SWIG
/**
+ * Decrease the event's repeat count and return the number of repeats
+ * left. If the repeat-count reaches 0, the %event will be destroyed.
+ *
+ * @return the number of times this event should be repeated or
+ * -1 in case it should be repeated unlimited times.
+ */
+ s_int32 do_repeat ();
+
+ /**
* @name Basic Event Data
*/
***************
*** 221,224 ****
--- 258,266 ----
/**
+ * Whether the %event is registered with the %event handler.
+ */
+ bool Registered;
+
+ /**
* Defines how often the %event should be repeated. <b>0</b> means
* never, <b>-1</b> means infinitely and <b>n</b> (n > 0) means
***************
*** 248,251 ****
--- 290,298 ----
*/
Functor0 Callback;
+
+ /**
+ * The event_list this event is kept in.
+ */
+ event_list *List;
//@}
#endif // SWIG
Index: event_handler.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event_handler.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** event_handler.cc 10 Aug 2002 12:18:21 -0000 1.3
--- event_handler.cc 18 Aug 2002 19:53:16 -0000 1.4
***************
*** 55,66 ****
}
- // cleanup
- void event_handler::clear ()
- {
- for (int i = 0; i < MAX_EVENTS; i++)
- if (Handler[i] != NULL)
- Handler[i]->clear ();
- }
-
// Clear the registered handlers
void event_handler::cleanup ()
--- 55,58 ----
Index: event_handler.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event_handler.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** event_handler.h 10 Aug 2002 12:18:21 -0000 1.3
--- event_handler.h 18 Aug 2002 19:53:16 -0000 1.4
***************
*** 26,29 ****
--- 26,30 ----
#include "event_handler_base.h"
+ #include "event_list.h"
/**
***************
*** 45,63 ****
static void cleanup ();
- /**
- * Remove all events from all handlers
- */
- static void clear ();
-
- /**
- * Registers an %event.
- *
- * @param ev pointer to the %event to register.
- */
- static void register_event (event* ev)
- {
- Handler[ev->type ()]->register_event (ev);
- }
-
/**
* Unregister an %event.
--- 46,49 ----
***************
*** 67,70 ****
--- 53,57 ----
static void remove_event (event* ev)
{
+ ev->set_registered (false);
Handler[ev->type ()]->remove_event (ev);
}
***************
*** 75,82 ****
* @param ev %event to raise.
*/
! static void raise_event (const event& ev)
{
! Handler[ev.type ()]->raise_event (ev);
}
private:
--- 62,87 ----
* @param ev %event to raise.
*/
! static void raise_event (const event* ev)
{
! Handler[ev->type ()]->raise_event (ev);
}
+
+ protected:
+ /**
+ * Registers an %event.
+ *
+ * @param ev pointer to the %event to register.
+ */
+ static void register_event (event* ev)
+ {
+ ev->set_registered (true);
+ Handler[ev->type ()]->register_event (ev);
+ }
+
+ /**
+ * Only %event_list is allowed to register events with the
+ * %event_handler.
+ */
+ friend void event_list::add_event (event* ev);
private:
Index: event_handler_base.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event_handler_base.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** event_handler_base.h 10 Aug 2002 12:18:21 -0000 1.3
--- event_handler_base.h 18 Aug 2002 19:53:16 -0000 1.4
***************
*** 41,49 ****
virtual ~event_handler_base () {}
- /**
- * Cleamup. Removes all events registered with the handler.
- */
- virtual void clear () = 0;
-
/**
* Registers an %event.
--- 41,44 ----
***************
*** 65,69 ****
* @param ev %event to raise.
*/
! virtual void raise_event (const event& ev) = 0;
};
--- 60,64 ----
* @param ev %event to raise.
*/
! virtual void raise_event (const event* ev) = 0;
};
Index: event_list.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event_list.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** event_list.cc 11 Aug 2002 13:02:29 -0000 1.3
--- event_list.cc 18 Aug 2002 19:53:16 -0000 1.4
***************
*** 22,25 ****
--- 22,26 ----
*/
+ #include <algorithm>
#include "event_list.h"
#include "event_handler.h"
***************
*** 37,47 ****
void event_list::clear ()
{
! event *e;
! while (!events.empty ())
{
! e = events.back ();
! events.pop_back ();
! delete e;
}
}
--- 38,49 ----
void event_list::clear ()
{
! event *ev;
! while (!Events.empty ())
{
! ev = Events.back ();
! ev->set_list (NULL);
! Events.pop_back ();
! delete ev;
}
}
***************
*** 50,57 ****
void event_list::add_event (event* ev)
{
! events.push_back (ev);
event_handler::register_event (ev);
}
// Register an event for loading
void event_list::register_event (u_int8 type, new_event e)
--- 52,72 ----
void event_list::add_event (event* ev)
{
! ev->set_list (this);
! Events.push_back (ev);
event_handler::register_event (ev);
}
+ // Remove an event from the list
+ void event_list::remove_event (event *ev)
+ {
+ vector<event*>::iterator i;
+
+ // Search for the event we want to remove
+ i = find (Events.begin (), Events.end (), ev);
+
+ // found? -> get rid of it :)
+ if (i != Events.end ()) Events.erase (i);
+ }
+
// Register an event for loading
void event_list::register_event (u_int8 type, new_event e)
***************
*** 65,73 ****
{
std::vector <event *>::iterator i;
! u_int32 nbr_events = events.size ();
nbr_events >> out;
! for (i = events.begin (); i != events.end (); i++)
(*i)->put_state (out);
}
--- 80,88 ----
{
std::vector <event *>::iterator i;
! u_int32 nbr_events = Events.size ();
nbr_events >> out;
! for (i = Events.begin (); i != Events.end (); i++)
(*i)->put_state (out);
}
***************
*** 78,81 ****
--- 93,97 ----
u_int32 nbr_events;
u_int8 type;
+ event *ev;
nbr_events << in;
***************
*** 83,96 ****
while (nbr_events--)
{
! event * e = NULL;
type << in;
// Instanciate an event of the given type
if (type < MAX_EVENTS && instanciate_event[type] != NULL)
! e = instanciate_event[type]();
// try to load it, ...
! if (e != NULL && e->get_state (in))
! add_event (e);
// ... otherwise fail.
--- 99,112 ----
while (nbr_events--)
{
! ev = NULL;
type << in;
// Instanciate an event of the given type
if (type < MAX_EVENTS && instanciate_event[type] != NULL)
! ev = instanciate_event[type]();
// try to load it, ...
! if (ev != NULL && ev->get_state (in))
! add_event (ev);
// ... otherwise fail.
Index: event_list.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event_list.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** event_list.h 9 Aug 2002 20:01:26 -0000 1.2
--- event_list.h 18 Aug 2002 19:53:16 -0000 1.3
***************
*** 62,80 ****
/**
! * Adds an event to this list. The event will be
! * registered with the event_handler and the list will then
* take care of it's deletion.
*
! * @param ev pointer to the event to add.
*/
void add_event (event* ev);
/**
! * Register an event for loading. Before the event_list can load
! * an event from file, it needs a callback function that returns
! * a new instance of the event of the given type.
*
! * @param type the type of the event to register
! * @param e a callback returning a new instance of an event of the
* given type.
*
--- 62,88 ----
/**
! * Adds an %event to this list. The %event will be
! * registered with the %event_handler and the list will then
* take care of it's deletion.
*
! * @param ev pointer to the %event to add.
*/
void add_event (event* ev);
/**
! * Removes an %event from the list. This is usually called when an
! * %event is destroyed.
*
! * @param ev pointer to the %event to remove.
! */
! void remove_event (event* ev);
!
! /**
! * Register an %event for loading. Before the %event_list can load
! * an %event from file, it needs a callback function that returns
! * a new instance of the %event of the given type.
! *
! * @param type the type of the %event to register
! * @param e a callback returning a new instance of an %event of the
* given type.
*
***************
*** 84,101 ****
/**
! * Save the event_list to a file.
*
! * @param out file where to save the event_list.
*/
void put_state (ogzstream& out) const;
/**
! * Loads the event_list from a file and registers all loaded events.
! * @warning Before the event_list can load an event from file, it needs
! * a callback function that returns a new instance of that event.
*
! * @param in file to load the event_list from.
*
! * @return \e true if the event_list was loaded successfully, \e false
otherwise.
* @sa register_event ()
*/
--- 92,110 ----
/**
! * Save the %event_list to a file.
*
! * @param out file where to save the %event_list.
*/
void put_state (ogzstream& out) const;
/**
! * Loads the %event_list from a file and registers all loaded events.
! * @warning Before the %event_list can load an %event from file, it needs
! * a callback function that returns a new instance of that %event.
*
! * @param in file to load the %event_list from.
*
! * @return \e true if the %event_list was loaded successfully, \e false
! * otherwise.
* @sa register_event ()
*/
***************
*** 107,115 ****
* List of events.
*/
! mutable std::vector<event*> events;
private:
/**
! * Array with callbacks that return a newly allocated instance of an
event.
* The event's type is the postion of the according callback in the array.
*/
--- 116,124 ----
* List of events.
*/
! mutable std::vector<event*> Events;
private:
/**
! * Array with callbacks that return a newly allocated instance of an
%event.
* The event's type is the postion of the according callback in the array.
*/
***************
*** 120,124 ****
#ifndef SWIG
/**
! * Registers an event with the event_list, allowing it to load this event
* without knowing about it at compile time.
*/
--- 129,133 ----
#ifndef SWIG
/**
! * Registers an %event with the %event_list, allowing it to load this %event
* without knowing about it at compile time.
*/
***************
*** 127,131 ****
/**
! * A function that returns a new instance of an event.
*/
#define NEW_EVENT(evt)\
--- 136,140 ----
/**
! * A function that returns a new instance of an %event.
*/
#define NEW_EVENT(evt)\
Index: gamedata.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gamedata.cc,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** gamedata.cc 11 Aug 2002 13:02:29 -0000 1.23
--- gamedata.cc 18 Aug 2002 19:53:16 -0000 1.24
***************
*** 565,570 ****
delete itq->second;
data::quests.clear ();
-
- // remove any events that are left over
- event_handler::clear ();
}
--- 565,567 ----
Index: gamedate.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gamedate.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** gamedate.cc 11 Aug 2002 11:58:21 -0000 1.4
--- gamedate.cc 18 Aug 2002 19:53:17 -0000 1.5
***************
*** 41,45 ****
Ticks += gametime::frames_to_skip ();
! // check whether a in-game minute has passed
while (Ticks >= tenth_minute)
{
--- 41,45 ----
Ticks += gametime::frames_to_skip ();
! // check whether an in-game minute has passed
while (Ticks >= tenth_minute)
{
***************
*** 48,52 ****
// raise time event
! event_handler::raise_event (time_event (Time));
}
}
--- 48,53 ----
// raise time event
! time_event evt (Time);
! event_handler::raise_event (&evt);
}
}
Index: map_event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/map_event.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** map_event.cc 9 Aug 2002 20:01:26 -0000 1.1
--- map_event.cc 18 Aug 2002 19:53:17 -0000 1.2
***************
*** 30,44 ****
// compare two map events
! bool map_event::equals (const event &e)
{
// we know that we've got an enter_event :)
! map_event tmp = (map_event &) e;
! if (submap != -1 && tmp.submap != submap) return false;
! if (x != -1 && tmp.x != x) return false;
! if (y != -1 && tmp.y != y) return false;
! if (dir != -1 && tmp.dir != dir) return false;
! if (map != -1 && tmp.map != map) return false;
! if (c && tmp.c != c) return false;
return true;
--- 30,44 ----
// compare two map events
! bool map_event::equals (const event* e)
{
// we know that we've got an enter_event :)
! map_event *t = (map_event *) e;
! if (submap != -1 && t->submap != submap) return false;
! if (x != -1 && t->x != x) return false;
! if (y != -1 && t->y != y) return false;
! if (dir != -1 && t->dir != dir) return false;
! if (map != -1 && t->map != map) return false;
! if (c && t->c != c) return false;
return true;
***************
*** 46,50 ****
// Execute map event's script
! void map_event::execute (const event& e)
{
switch (Action)
--- 46,50 ----
// Execute map event's script
! s_int32 map_event::execute (const event* e)
{
switch (Action)
***************
*** 52,59 ****
case ACTION_SCRIPT:
{
! map_event t = (map_event&) e;
PyObject *args = Py_BuildValue ("(i, i, i, i, s)",
! t.submap, t.x, t.y, t.dir, t.c->get_id ().c_str ());
Script->run (args);
--- 52,59 ----
case ACTION_SCRIPT:
{
! map_event *t = (map_event *) e;
PyObject *args = Py_BuildValue ("(i, i, i, i, s)",
! t->submap, t->x, t->y, t->dir, t->c->get_id ().c_str ());
Script->run (args);
***************
*** 75,80 ****
}
! default: return;
}
}
--- 75,82 ----
}
! default: break;
}
+
+ return do_repeat ();
}
Index: map_event.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/map_event.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** map_event.h 9 Aug 2002 20:01:26 -0000 1.1
--- map_event.h 18 Aug 2002 19:53:17 -0000 1.2
***************
*** 84,88 ****
mapcharacter *c;
- protected:
/**
* Compare two map events for equality.
--- 84,87 ----
***************
*** 91,95 ****
* @return <b>True</b> if the two events equal, <b>false</b> otherwise.
*/
! bool equals (const event& evnt);
/**
--- 90,94 ----
* @return <b>True</b> if the two events equal, <b>false</b> otherwise.
*/
! bool equals (const event* evnt);
/**
***************
*** 98,103 ****
*
* @param evnt The %event that triggered this map %event.
*/
! void execute (const event& evnt);
};
--- 97,104 ----
*
* @param evnt The %event that triggered this map %event.
+ *
+ * @return The number of times the %event needs to be repeated.
*/
! s_int32 execute (const event* evnt);
};
Index: map_event_handler.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/map_event_handler.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** map_event_handler.cc 10 Aug 2002 12:18:21 -0000 1.2
--- map_event_handler.cc 18 Aug 2002 19:53:17 -0000 1.3
***************
*** 24,49 ****
#include "map_event_handler.h"
- // cleanup
- void map_event_handler::clear ()
- {
- Events.clear ();
- }
// See whether a matching event is registered and execute the
// according script(s)
! void map_event_handler::raise_event (const event& e)
{
// As long as matching events are in the list
! for (vector<event*>::iterator i = Events.begin (); i != Events.end ();
i++)
if ((*i)->equals (e))
! {
! // execute the event
(*i)->execute (e);
-
- // if it does not repeat, remove it
- if ((*i)->repeat () == 0)
- Events.erase (i);
- }
return;
}
--- 24,47 ----
#include "map_event_handler.h"
// See whether a matching event is registered and execute the
// according script(s)
! void map_event_handler::raise_event (const event* e)
{
+ vector<event*>::iterator j;
+
// As long as matching events are in the list
! for (vector<event*>::iterator i = Events.begin (); i != Events.end ();)
! {
! j = i;
! j++;
!
if ((*i)->equals (e))
! // execute them. Note that events that use up their repeat
! // count are automatically deleted and unregistered.
(*i)->execute (e);
+ i = j;
+ }
return;
}
Index: map_event_handler.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/map_event_handler.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** map_event_handler.h 10 Aug 2002 12:18:21 -0000 1.2
--- map_event_handler.h 18 Aug 2002 19:53:17 -0000 1.3
***************
*** 36,44 ****
public:
/**
- * Cleamup. Removes all events registered with the handler.
- */
- void clear ();
-
- /**
* Register a map %event with the %event handler. The %event
* needs to be removed before it can be safely deleted.
--- 36,39 ----
***************
*** 63,67 ****
* @param evnt A map_event structure.
*/
! void raise_event (const event &evnt);
private:
--- 58,62 ----
* @param evnt A map_event structure.
*/
! void raise_event (const event *evnt);
private:
Index: mapcharacter.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/mapcharacter.cc,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -r1.44 -r1.45
*** mapcharacter.cc 11 Aug 2002 11:58:21 -0000 1.44
--- mapcharacter.cc 18 Aug 2002 19:53:17 -0000 1.45
***************
*** 62,65 ****
--- 62,67 ----
void mapcharacter::clear ()
{
+ event_list::clear ();
+
if (saying) delete saying;
***************
*** 301,304 ****
--- 303,314 ----
break;
}
+
+ enter_event evt;
+ evt.submap = submap ();
+ evt.x = posx ();
+ evt.y = posy ();
+ evt.c = this;
+ evt.dir = pos;
+ event_handler::raise_event (&evt);
}
***************
*** 616,623 ****
}
bool mapcharacter::goal_reached ()
{
return goal_reached_;
- // return (pathindex >= mypath.nbr_moves () && currentmove () <
WALK_NORTH);
}
--- 626,637 ----
}
+ void mapcharacter::stop_moving ()
+ {
+ set_goal (posx (), posy ());
+ }
+
bool mapcharacter::goal_reached ()
{
return goal_reached_;
}
***************
*** 669,672 ****
--- 683,694 ----
}
+ bool mapcharacter::do_stuff (string method, PyObject *args)
+ {
+ if (!schedule.has_attribute (method)) return false;
+ else schedule.call_method (method, args);
+
+ return true;
+ }
+
void mapcharacter::set_schedule (string file, PyObject * args)
{
***************
*** 944,948 ****
evt.c = this;
evt.dir = WALK_NORTH;
! event_handler::raise_event (evt);
occupy (submap (), posx (), posy () - 1);
--- 966,970 ----
evt.c = this;
evt.dir = WALK_NORTH;
! event_handler::raise_event (&evt);
occupy (submap (), posx (), posy () - 1);
***************
*** 967,971 ****
evt.c = this;
evt.dir = WALK_NORTH;
! event_handler::raise_event (evt);
}
break;
--- 989,993 ----
evt.c = this;
evt.dir = WALK_NORTH;
! event_handler::raise_event (&evt);
}
break;
***************
*** 985,989 ****
evt.c = this;
evt.dir = WALK_SOUTH;
! event_handler::raise_event (evt);
leave (submap (), posx (), posy ());
--- 1007,1011 ----
evt.c = this;
evt.dir = WALK_SOUTH;
! event_handler::raise_event (&evt);
leave (submap (), posx (), posy ());
***************
*** 1007,1011 ****
evt.c = this;
evt.dir = WALK_SOUTH;
! event_handler::raise_event (evt);
}
}
--- 1029,1033 ----
evt.c = this;
evt.dir = WALK_SOUTH;
! event_handler::raise_event (&evt);
}
}
***************
*** 1026,1030 ****
evt.c = this;
evt.dir = WALK_WEST;
! event_handler::raise_event (evt);
occupy (submap (), posx () - 1, posy ());
--- 1048,1052 ----
evt.c = this;
evt.dir = WALK_WEST;
! event_handler::raise_event (&evt);
occupy (submap (), posx () - 1, posy ());
***************
*** 1045,1049 ****
evt.c = this;
evt.dir = WALK_WEST;
! event_handler::raise_event (evt);
}
break;
--- 1067,1071 ----
evt.c = this;
evt.dir = WALK_WEST;
! event_handler::raise_event (&evt);
}
break;
***************
*** 1063,1067 ****
evt.c = this;
evt.dir = WALK_EAST;
! event_handler::raise_event (evt);
leave (submap (), posx (), posy ());
--- 1085,1089 ----
evt.c = this;
evt.dir = WALK_EAST;
! event_handler::raise_event (&evt);
leave (submap (), posx (), posy ());
***************
*** 1084,1088 ****
evt.c = this;
evt.dir = WALK_EAST;
! event_handler::raise_event (evt);
}
}
--- 1106,1110 ----
evt.c = this;
evt.dir = WALK_EAST;
! event_handler::raise_event (&evt);
}
}
Index: mapcharacter.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/mapcharacter.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -r1.54 -r1.55
*** mapcharacter.h 11 Aug 2002 11:58:21 -0000 1.54
--- mapcharacter.h 18 Aug 2002 19:53:17 -0000 1.55
***************
*** 42,45 ****
--- 42,46 ----
#include "path.h"
#include "text_bubble.h"
+ #include "event_list.h"
class landmap;
***************
*** 137,141 ****
*
*/
! class mapcharacter : public mapsquare_walkable_area, public character_base
{
public:
--- 138,142 ----
*
*/
! class mapcharacter : public mapsquare_walkable_area, public character_base,
public event_list
{
public:
***************
*** 594,598 ****
void set_callback (PyObject *callback, PyObject *args = NULL);
bool follow_path ();
! bool goal_reached ();
//@}
--- 595,600 ----
void set_callback (PyObject *callback, PyObject *args = NULL);
bool follow_path ();
! bool goal_reached ();
! void stop_moving ();
//@}
***************
*** 653,656 ****
--- 655,668 ----
}
+ /**
+ * Tell the character to do something. Will execute the given method
+ * of the current schedule with the given arguments.
+ *
+ * @param method The method of the schedule to call.
+ * @param args The arguments to pass to the method.
+ *
+ * @return \c true if the method has been called, \c false otherwise.
+ */
+ bool do_stuff (string method, PyObject *args = NULL);
//@}
Index: time_event.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/time_event.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** time_event.cc 9 Aug 2002 20:01:26 -0000 1.2
--- time_event.cc 18 Aug 2002 19:53:17 -0000 1.3
***************
*** 26,30 ****
time_event::time_event (const string & time, bool absolute) : event ()
{
! Repeat = 0;
Type = TIME_EVENT;
Time = gamedate::parse_time (time);
--- 26,30 ----
time_event::time_event (const string & time, bool absolute) : event ()
{
! Repeat = 1;
Type = TIME_EVENT;
Time = gamedate::parse_time (time);
***************
*** 40,44 ****
// execute the time event
! void time_event::execute (const event & evnt)
{
// nothing needs be passed to the script; it can get the
--- 40,44 ----
// execute the time event
! s_int32 time_event::execute (const event * evnt)
{
// nothing needs be passed to the script; it can get the
***************
*** 64,72 ****
}
! default: return;
}
// when the script needs be repeated, do so.
! if (Repeat != 0) Time += Interval;
}
--- 64,74 ----
}
! default: break;
}
// when the script needs be repeated, do so.
! if (Repeat > 1) Time += Interval;
!
! return do_repeat ();
}
Index: time_event.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/time_event.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** time_event.h 10 Aug 2002 12:18:21 -0000 1.3
--- time_event.h 18 Aug 2002 19:53:17 -0000 1.4
***************
*** 61,64 ****
--- 61,65 ----
{
Type = TIME_EVENT;
+ Repeat = 1;
}
***************
*** 73,76 ****
--- 74,78 ----
Type = TIME_EVENT;
Time = time;
+ Repeat = 1;
}
#endif // SWIG
***************
*** 97,104 ****
* @return <b>True</b> if the two events equal, <b>false</b> otherwise.
*/
! bool equals (const event & evnt)
{
! time_event e = (time_event &) evnt;
! return Time <= e.time ();
}
--- 99,106 ----
* @return <b>True</b> if the two events equal, <b>false</b> otherwise.
*/
! bool equals (const event * evnt)
{
! time_event *e = (time_event *) evnt;
! return Time <= e->time ();
}
***************
*** 108,113 ****
*
* @param evnt The %event that triggered this time %event.
*/
! void execute (const event & evnt);
//@}
--- 110,117 ----
*
* @param evnt The %event that triggered this time %event.
+ *
+ * @return The number of times the %event needs to be repeated.
*/
! s_int32 execute (const event * evnt);
//@}
Index: time_event_handler.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/time_event_handler.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** time_event_handler.cc 10 Aug 2002 12:18:21 -0000 1.3
--- time_event_handler.cc 18 Aug 2002 19:53:17 -0000 1.4
***************
*** 25,37 ****
#include "time_event_handler.h"
- // cleanup
- void time_event_handler::clear ()
- {
- Events.clear ();
- }
// See whether a matching event is registered and execute the
// according script(s)
! void time_event_handler::raise_event (const event& e)
{
s_int32 repeat;
--- 25,32 ----
#include "time_event_handler.h"
// See whether a matching event is registered and execute the
// according script(s)
! void time_event_handler::raise_event (const event * e)
{
s_int32 repeat;
***************
*** 43,54 ****
evt = Events.front ();
! // Note: we need to get the value of 'repeat' here, as
! // executing the event might destroy it
! repeat = evt->repeat ();
!
! // remove event before executing (see above)
Events.erase (Events.begin ());
! evt->execute (e);
// re-register event if it needs be repeated
--- 38,48 ----
evt = Events.front ();
! // we remove the event in any case, as it needs to be
! // re-registered at a new position if it repeats
Events.erase (Events.begin ());
+ evt->set_registered (false);
! // events that don't repeat are destroyed automatically
! repeat = evt->execute (e);
// re-register event if it needs be repeated
Index: time_event_handler.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/time_event_handler.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** time_event_handler.h 10 Aug 2002 12:18:21 -0000 1.3
--- time_event_handler.h 18 Aug 2002 19:53:17 -0000 1.4
***************
*** 38,46 ****
public:
/**
- * Cleamup. Removes all events registered with the handler.
- */
- void clear ();
-
- /**
* Register a time %event with the %event handler. It is inserted
* into the vector of registered events depending on its "alarm"
--- 38,41 ----
***************
*** 68,72 ****
* minutes.
*/
! void raise_event (const event &evnt);
private:
--- 63,67 ----
* minutes.
*/
! void raise_event (const event *evnt);
private:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Adonthell-commits] CVS: adonthell/src Makefile.am,1.94,1.95 dialog.cc,1.30,1.31 dialog.h,1.52,1.53 event.cc,1.15,1.16 event.h,1.27,1.28 event_handler.cc,1.3,1.4 event_handler.h,1.3,1.4 event_handler_base.h,1.3,1.4 event_list.cc,1.3,1.4 event_list.h,1.2,1.3 gamedata.cc,1.23,1.24 gamedate.cc,1.4,1.5 map_event.cc,1.1,1.2 map_event.h,1.1,1.2 map_event_handler.cc,1.2,1.3 map_event_handler.h,1.2,1.3 mapcharacter.cc,1.44,1.45 mapcharacter.h,1.54,1.55 time_event.cc,1.2,1.3 time_event.h,1.3,1.4 time_event_handler.cc,1.3,1.4 time_event_handler.h,1.3,1.4,
Kai Sterker <address@hidden> <=
- Prev by Date:
[Adonthell-commits] CVS: adonthell/src/input Makefile.am,1.1.2.1,1.1.2.2 listener.cc,1.1.2.1,1.1.2.2 listener.h,1.1.2.2,1.1.2.3 py_input.i,1.1.2.1,1.1.2.2
- Next by Date:
[Adonthell-commits] CVS: wastesedge mapengine.data,1.13,1.14
- Previous by thread:
[Adonthell-commits] CVS: adonthell/src/input Makefile.am,1.1.2.1,1.1.2.2 listener.cc,1.1.2.1,1.1.2.2 listener.h,1.1.2.2,1.1.2.3 py_input.i,1.1.2.1,1.1.2.2
- Next by thread:
[Adonthell-commits] CVS: wastesedge mapengine.data,1.13,1.14
- Index(es):