Some minor performance enhancements and an experimental profiler.
This commit is contained in:
parent
c5975f522f
commit
18cf29b0cf
5 changed files with 53 additions and 47 deletions
|
|
@ -24,6 +24,12 @@ class Attribute(models.Model):
|
||||||
list_display = ('object', 'name', 'value',)
|
list_display = ('object', 'name', 'value',)
|
||||||
search_fields = ['name']
|
search_fields = ['name']
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
"""
|
||||||
|
Returns an attribute's name.
|
||||||
|
"""
|
||||||
|
return self.name
|
||||||
|
|
||||||
class Object(models.Model):
|
class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
The Object class is very generic representation of a THING, PLAYER, EXIT,
|
The Object class is very generic representation of a THING, PLAYER, EXIT,
|
||||||
|
|
@ -52,6 +58,9 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
return self.id == other.id
|
return self.id == other.id
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "%s" % (self.get_name(),)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("can_examine", "Can examine objects"),
|
("can_examine", "Can examine objects"),
|
||||||
|
|
@ -186,18 +195,18 @@ class Object(models.Model):
|
||||||
Returns an object's name.
|
Returns an object's name.
|
||||||
"""
|
"""
|
||||||
if fullname:
|
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:
|
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):
|
def get_ansiname(self, fullname=False):
|
||||||
"""
|
"""
|
||||||
Returns an object's ANSI'd name.
|
Returns an object's ANSI'd name.
|
||||||
"""
|
"""
|
||||||
if fullname:
|
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:
|
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):
|
def set_description(self, new_desc):
|
||||||
"""
|
"""
|
||||||
|
|
@ -222,7 +231,7 @@ class Object(models.Model):
|
||||||
else:
|
else:
|
||||||
return retval
|
return retval
|
||||||
except:
|
except:
|
||||||
return None
|
return ""
|
||||||
|
|
||||||
def get_flags(self):
|
def get_flags(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -250,20 +259,19 @@ class Object(models.Model):
|
||||||
else:
|
else:
|
||||||
return False
|
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):
|
def get_all_attributes(self):
|
||||||
"""
|
"""
|
||||||
Returns a QuerySet of an object's attributes.
|
Returns a QuerySet of an object's attributes.
|
||||||
"""
|
"""
|
||||||
attribs = Attribute.objects.filter(object=self)
|
return self.attribute_set.all()
|
||||||
return attribs
|
|
||||||
|
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):
|
def destroy(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -584,8 +592,5 @@ class Object(models.Model):
|
||||||
type_string = global_defines.OBJECT_TYPES[self.type][1][0]
|
type_string = global_defines.OBJECT_TYPES[self.type][1][0]
|
||||||
return type_string
|
return type_string
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "%s(#%d%s)" % (self.get_ansiname(), self.id, self.flag_string())
|
|
||||||
|
|
||||||
import functions_db
|
import functions_db
|
||||||
import session_mgr
|
import session_mgr
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,13 @@ import os
|
||||||
Generic command module. Pretty much every command should go here for
|
Generic command module. Pretty much every command should go here for
|
||||||
now.
|
now.
|
||||||
"""
|
"""
|
||||||
|
def cmd_idle(cdat):
|
||||||
|
"""
|
||||||
|
Returns nothing, this lets the player set an idle timer without spamming
|
||||||
|
his screen.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def cmd_inventory(cdat):
|
def cmd_inventory(cdat):
|
||||||
"""
|
"""
|
||||||
Shows a player's inventory.
|
Shows a player's inventory.
|
||||||
|
|
@ -46,7 +53,7 @@ def cmd_look(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
return
|
return
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
|
|
@ -54,11 +61,8 @@ def cmd_look(cdat):
|
||||||
else:
|
else:
|
||||||
target_obj = results[0]
|
target_obj = results[0]
|
||||||
|
|
||||||
retval = "%s%s(#%i%s)\r\n%s" % (
|
retval = "%s\r\n%s" % (
|
||||||
target_obj.get_ansiname(),
|
target_obj.get_ansiname(),
|
||||||
ansi.ansi["normal"],
|
|
||||||
target_obj.id,
|
|
||||||
target_obj.flag_string(),
|
|
||||||
target_obj.get_description(),
|
target_obj.get_description(),
|
||||||
)
|
)
|
||||||
session.msg(retval)
|
session.msg(retval)
|
||||||
|
|
@ -79,15 +83,15 @@ def cmd_look(cdat):
|
||||||
if con_players:
|
if con_players:
|
||||||
session.msg("%sPlayers:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
session.msg("%sPlayers:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||||
for player in con_players:
|
for player in con_players:
|
||||||
session.msg('%s' %(player,))
|
session.msg('%s' %(player.get_ansiname(),))
|
||||||
if con_things:
|
if con_things:
|
||||||
session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||||
for thing in con_things:
|
for thing in con_things:
|
||||||
session.msg('%s' %(thing,))
|
session.msg('%s' %(thing.get_ansiname(),))
|
||||||
if con_exits:
|
if con_exits:
|
||||||
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||||
for exit in con_exits:
|
for exit in con_exits:
|
||||||
session.msg('%s' %(exit,))
|
session.msg('%s' %(exit.get_ansiname(),))
|
||||||
|
|
||||||
def cmd_examine(cdat):
|
def cmd_examine(cdat):
|
||||||
"""
|
"""
|
||||||
|
|
@ -105,18 +109,15 @@ def cmd_examine(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
return
|
return
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = results[0]
|
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),
|
target_obj.get_ansiname(fullname=True),
|
||||||
ansi.ansi["normal"],
|
|
||||||
target_obj.id,
|
|
||||||
target_obj.flag_string(),
|
|
||||||
target_obj.get_description(no_parsing=True),
|
target_obj.get_description(no_parsing=True),
|
||||||
))
|
))
|
||||||
session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags()))
|
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(),))
|
session.msg("Zone: %s" % (target_obj.get_zone(),))
|
||||||
|
|
||||||
for attribute in target_obj.get_all_attributes():
|
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_players = []
|
||||||
con_things = []
|
con_things = []
|
||||||
con_exits = []
|
con_exits = []
|
||||||
|
|
||||||
for obj in target_obj.get_contents():
|
for obj in target_obj.get_contents():
|
||||||
if obj.is_player:
|
if obj.is_player():
|
||||||
con_players.append(obj)
|
con_players.append(obj)
|
||||||
elif obj.is_exit:
|
elif obj.is_exit():
|
||||||
con_exits.append(obj)
|
con_exits.append(obj)
|
||||||
else:
|
elif obj.is_thing():
|
||||||
con_things.append(obj)
|
con_things.append(obj)
|
||||||
|
|
||||||
if con_players or con_things:
|
if con_players or con_things:
|
||||||
session.msg("Contents:")
|
session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||||
for player in con_players:
|
for player in con_players:
|
||||||
session.msg('%s' %(player,))
|
session.msg('%s' % (player.get_ansiname(fullname=True),))
|
||||||
for thing in con_things:
|
for thing in con_things:
|
||||||
session.msg('%s' %(thing,))
|
session.msg('%s' % (thing.get_ansiname(fullname=True),))
|
||||||
|
|
||||||
if con_exits:
|
if con_exits:
|
||||||
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||||
for exit in con_exits:
|
for exit in con_exits:
|
||||||
session.msg('%s' %(exit,))
|
session.msg('%s' %(exit.get_ansiname(fullname=True),))
|
||||||
|
|
||||||
if not target_obj.is_room():
|
if not target_obj.is_room():
|
||||||
if target_obj.is_exit():
|
if target_obj.is_exit():
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ def cmd_destroy(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
return
|
return
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
|
|
@ -106,7 +106,7 @@ def cmd_description(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
return
|
return
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
|
|
@ -141,7 +141,7 @@ def cmd_newpassword(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
elif not pobject.controls_other(results[0]):
|
elif not pobject.controls_other(results[0]):
|
||||||
|
|
@ -206,7 +206,7 @@ def cmd_name(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
return
|
return
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
|
|
@ -422,7 +422,7 @@ def cmd_unlink(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
return
|
return
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
|
|
@ -491,7 +491,7 @@ def cmd_teleport(cdat):
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
session.msg("More than one match found (please narrow target):")
|
session.msg("More than one match found (please narrow target):")
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(),))
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
session.msg("I don't see that here.")
|
||||||
return
|
return
|
||||||
|
|
@ -596,7 +596,7 @@ def cmd_find(cdat):
|
||||||
if len(results) > 0:
|
if len(results) > 0:
|
||||||
session.msg("Name matches for: %s" % (searchstring,))
|
session.msg("Name matches for: %s" % (searchstring,))
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result,))
|
session.msg(" %s" % (result.get_ansiname(fullname=True),))
|
||||||
session.msg("%d matches returned." % (len(results),))
|
session.msg("%d matches returned." % (len(results),))
|
||||||
else:
|
else:
|
||||||
session.msg("No name matches found for: %s" % (searchstring,))
|
session.msg("No name matches found for: %s" % (searchstring,))
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export DJANGO_SETTINGS_MODULE="settings"
|
export DJANGO_SETTINGS_MODULE="settings"
|
||||||
python2.5 server.py
|
python2.5 -m cProfile -o profiler.log -s time server.py
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue