From 1995f61d463dd2a1920ec6d88cf5c4be562be3f9 Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 15 Sep 2011 10:46:41 +0200 Subject: [PATCH] Put up a warning about not using BaseObject.at_init() at this time (it's not called, as per issue 188). Also removed the deprecated at_cache() hook (it doesn't work anymore now that the caching system is much more efficient and only caches once). --- game/gamesrc/objects/baseobjects.py | 7 +++---- src/commands/default/building.py | 1 - src/objects/objects.py | 10 ++-------- src/server/server.py | 14 +++++++++++++- src/utils/idmapper/base.py | 9 --------- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/game/gamesrc/objects/baseobjects.py b/game/gamesrc/objects/baseobjects.py index 437fef86f5..e40866107f 100644 --- a/game/gamesrc/objects/baseobjects.py +++ b/game/gamesrc/objects/baseobjects.py @@ -90,12 +90,11 @@ class Object(BaseObject): at_drop(dropper) - called when this object has been dropped. at_say(speaker, message) - by default, called if an object inside this object speaks - at_cache() - called when this typeclass is instantiated and cached at_server_reload() - called when server is reloading - at_server_shutdown() - called when server is resetting/shutting down - + at_server_shutdown() - called when server is resetting/shutting down """ - pass + + class Character(BaseCharacter): """ diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 753ce91d15..bbfc9aa40b 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -137,7 +137,6 @@ class CmdSetObjAlias(MuxCommand): # save back to object. obj.aliases = aliases # we treat this as a re-caching (relevant for exits to re-build their exit commands with the correct aliases) - obj.at_cache() caller.msg("Aliases for '%s' are now set to %s." % (obj.key, ", ".join(obj.aliases))) class CmdCopy(ObjManipCommand): diff --git a/src/objects/objects.py b/src/objects/objects.py index d77a226f31..a0ae4dfe49 100644 --- a/src/objects/objects.py +++ b/src/objects/objects.py @@ -77,6 +77,8 @@ class Object(TypeClass): def at_init(self): """ + OBS: CURRENTLY NOT CALLED! + This is always called whenever this object initiated -- both when the object is first created as well as after each restart. @@ -96,14 +98,6 @@ class Object(TypeClass): """ pass - def at_cache(self): - """ - Called whenever this object is cached to the idmapper backend. - This is the place to put eventual reloads of non-persistent attributes - you saved in the at_server_reload() below. - """ - pass - def at_server_reload(self): """ This hook is called whenever the server is shutting down for restart/reboot. diff --git a/src/server/server.py b/src/server/server.py index 0352bde31c..ef6434bb39 100644 --- a/src/server/server.py +++ b/src/server/server.py @@ -100,7 +100,9 @@ class Evennia(object): reactor.addSystemEventTrigger('before', 'shutdown', self.shutdown, _abrupt=True) self.game_running = True - + + self.run_init_hooks() + # Server startup methods def sqlite3_prep(self): @@ -140,6 +142,16 @@ class Evennia(object): initial_setup.handle_setup(int(last_initial_setup_step)) print '-'*50 + def run_init_hooks(self): + """ + Called every server start + """ + from src.objects.models import ObjectDB + from src.players.models import PlayerDB + + print "run_init_hooks:", ObjectDB.get_all_cached_instances() + [(o.typeclass(o), o.at_init()) for o in ObjectDB.get_all_cached_instances()] + [(p.typeclass(p), p.at_init()) for p in PlayerDB.get_all_cached_instances()] def terminal_output(self): """ diff --git a/src/utils/idmapper/base.py b/src/utils/idmapper/base.py index b03f94ca77..f9b3cd6c22 100755 --- a/src/utils/idmapper/base.py +++ b/src/utils/idmapper/base.py @@ -101,15 +101,6 @@ class SharedMemoryModel(Model): """ if instance._get_pk_val() is not None: cls.__instance_cache__[instance._get_pk_val()] = instance - try: - object.__getattribute__(instance, "at_cache")() - except (TypeError, AttributeError), e: - #print e, instance._get_pk_val() - pass - - #key = "%s-%s" % (cls, instance.pk) - #TCACHE[key] = instance - #print "cached: %s (%s: %s) (total cached: %s)" % (instance, cls.__name__, len(cls.__instance_cache__), len(TCACHE)) cache_instance = classmethod(cache_instance) def get_all_cached_instances(cls):