From 18cf29b0cfbac6c8f094dabbbc43b68372f964f1 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 2 Jan 2007 01:14:07 +0000 Subject: [PATCH] Some minor performance enhancements and an experimental profiler. --- evennia/trunk/apps/objects/models.py | 41 ++++++++++++++----------- evennia/trunk/commands_general.py | 43 ++++++++++++++------------- evennia/trunk/commands_staff.py | 14 ++++----- evennia/trunk/evennia.sql | Bin 48128 -> 48128 bytes evennia/trunk/prepenv.sh | 2 +- 5 files changed, 53 insertions(+), 47 deletions(-) diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index ab66f74cb1..fb52c7142e 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -23,6 +23,12 @@ class Attribute(models.Model): class Admin: list_display = ('object', 'name', 'value',) search_fields = ['name'] + + def get_name(self): + """ + Returns an attribute's name. + """ + return self.name class Object(models.Model): """ @@ -51,6 +57,9 @@ class Object(models.Model): Used to figure out if one object is the same as another. """ return self.id == other.id + + def __str__(self): + return "%s" % (self.get_name(),) class Meta: permissions = ( @@ -186,18 +195,18 @@ class Object(models.Model): Returns an object's name. """ if fullname: - return ansi.parse_ansi(self.name, strip_ansi=True) + return "%s(#%d%s)" % (ansi.parse_ansi(self.name, strip_ansi=True),self.id, self.flag_string()) else: - return ansi.parse_ansi(self.name.split(';')[0], strip_ansi=True) + return "%s(#%d%s)" % (ansi.parse_ansi(self.name.split(';')[0], strip_ansi=True),self.id, self.flag_string()) def get_ansiname(self, fullname=False): """ Returns an object's ANSI'd name. """ if fullname: - return ansi.parse_ansi(self.ansi_name) + return "%s(#%d%s)" % (ansi.parse_ansi(self.ansi_name), self.id, self.flag_string()) else: - return ansi.parse_ansi(self.ansi_name.split(';')[0]) + return "%s(#%d%s)" % (ansi.parse_ansi(self.ansi_name.split(';')[0]), self.id, self.flag_string()) def set_description(self, new_desc): """ @@ -222,7 +231,7 @@ class Object(models.Model): else: return retval except: - return None + return "" def get_flags(self): """ @@ -250,20 +259,19 @@ class Object(models.Model): else: return False - def clear_all_attributes(self): - """ - Clears all of an object's attributes. - """ - attribs = Attribute.objects.filter(object=self) - for attrib in attribs: - self.delete() - def get_all_attributes(self): """ Returns a QuerySet of an object's attributes. """ - attribs = Attribute.objects.filter(object=self) - return attribs + return self.attribute_set.all() + + def clear_all_attributes(self): + """ + Clears all of an object's attributes. + """ + self.get_all_attributes() + for attrib in attribs: + self.delete() def destroy(self): """ @@ -584,8 +592,5 @@ class Object(models.Model): type_string = global_defines.OBJECT_TYPES[self.type][1][0] return type_string - def __str__(self): - return "%s(#%d%s)" % (self.get_ansiname(), self.id, self.flag_string()) - import functions_db import session_mgr diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index 8bd411eb9c..ef38c1b257 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -11,6 +11,13 @@ import os Generic command module. Pretty much every command should go here for now. """ +def cmd_idle(cdat): + """ + Returns nothing, this lets the player set an idle timer without spamming + his screen. + """ + pass + def cmd_inventory(cdat): """ Shows a player's inventory. @@ -46,7 +53,7 @@ def cmd_look(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -54,11 +61,8 @@ def cmd_look(cdat): else: target_obj = results[0] - retval = "%s%s(#%i%s)\r\n%s" % ( + retval = "%s\r\n%s" % ( target_obj.get_ansiname(), - ansi.ansi["normal"], - target_obj.id, - target_obj.flag_string(), target_obj.get_description(), ) session.msg(retval) @@ -79,15 +83,15 @@ def cmd_look(cdat): if con_players: session.msg("%sPlayers:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for player in con_players: - session.msg('%s' %(player,)) + session.msg('%s' %(player.get_ansiname(),)) if con_things: session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for thing in con_things: - session.msg('%s' %(thing,)) + session.msg('%s' %(thing.get_ansiname(),)) if con_exits: session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for exit in con_exits: - session.msg('%s' %(exit,)) + session.msg('%s' %(exit.get_ansiname(),)) def cmd_examine(cdat): """ @@ -105,18 +109,15 @@ def cmd_examine(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) return elif len(results) == 0: session.msg("I don't see that here.") return else: target_obj = results[0] - session.msg("%s%s(#%i%s)\r\n%s" % ( + session.msg("%s\r\n%s" % ( target_obj.get_ansiname(fullname=True), - ansi.ansi["normal"], - target_obj.id, - target_obj.flag_string(), target_obj.get_description(no_parsing=True), )) session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags())) @@ -124,31 +125,31 @@ def cmd_examine(cdat): session.msg("Zone: %s" % (target_obj.get_zone(),)) for attribute in target_obj.get_all_attributes(): - session.msg("%s%s%s: %s" % (ansi.ansi["hilite"], attribute.name, ansi.ansi["normal"], attribute.value)) + session.msg("%s%s%s: %s" % (ansi.ansi["hilite"], attribute.get_name(), ansi.ansi["normal"], attribute.value)) con_players = [] con_things = [] con_exits = [] for obj in target_obj.get_contents(): - if obj.is_player: + if obj.is_player(): con_players.append(obj) - elif obj.is_exit: + elif obj.is_exit(): con_exits.append(obj) - else: + elif obj.is_thing(): con_things.append(obj) if con_players or con_things: - session.msg("Contents:") + session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for player in con_players: - session.msg('%s' %(player,)) + session.msg('%s' % (player.get_ansiname(fullname=True),)) for thing in con_things: - session.msg('%s' %(thing,)) + session.msg('%s' % (thing.get_ansiname(fullname=True),)) if con_exits: session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for exit in con_exits: - session.msg('%s' %(exit,)) + session.msg('%s' %(exit.get_ansiname(fullname=True),)) if not target_obj.is_room(): if target_obj.is_exit(): diff --git a/evennia/trunk/commands_staff.py b/evennia/trunk/commands_staff.py index 55c7ec660a..52f362dc01 100644 --- a/evennia/trunk/commands_staff.py +++ b/evennia/trunk/commands_staff.py @@ -39,7 +39,7 @@ def cmd_destroy(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -106,7 +106,7 @@ def cmd_description(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -141,7 +141,7 @@ def cmd_newpassword(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) elif len(results) == 0: session.msg("I don't see that here.") elif not pobject.controls_other(results[0]): @@ -206,7 +206,7 @@ def cmd_name(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -422,7 +422,7 @@ def cmd_unlink(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -491,7 +491,7 @@ def cmd_teleport(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(),)) elif len(results) == 0: session.msg("I don't see that here.") return @@ -596,7 +596,7 @@ def cmd_find(cdat): if len(results) > 0: session.msg("Name matches for: %s" % (searchstring,)) for result in results: - session.msg(" %s" % (result,)) + session.msg(" %s" % (result.get_ansiname(fullname=True),)) session.msg("%d matches returned." % (len(results),)) else: session.msg("No name matches found for: %s" % (searchstring,)) diff --git a/evennia/trunk/evennia.sql b/evennia/trunk/evennia.sql index 476806277b073bc2e550ca97b22bfc4ba2ae05b1..cacdde8009573b78bd5161bb00de39951c441bf7 100755 GIT binary patch delta 61 zcmV-D0K)%(_yU0V0+1U4?Xeu_X9ofU;s68k1G6D`!2z+576K3s0tNsT69@rUNJT|? TVR-_x@@o<#vjl|v1EQ2Dml71J delta 50 zcmZqp!PM}BX@WH4#f>sA(%Bf9KQS