* Implemented a non-persistent cache in src/cache.py. The cache is lost when restarting the server but it has the advantage of not hitting the database, and so is useful for implementing things that should be remembered over time but does not need to be persistently saved in the database at every point, like fast-updating combat systems, timers etc. Using the cache can substantially cut down on database access at the cost of memory comsumption. It is easiest accessed through the object model using normal dot notation. So to store a variable in volatile memory e.g. from your script parent, you can do things like self.scripted_obj.cache.myvariable = variable and be sure that later (unless there was a reboot) doing self.scripted_obj.cache.myvariable will return the value you stored there.

* OBS - doing e.g. self.scripted_obj.myvariable = variable was always iffy and since a few revisions back this will NOT work - this is because the objects are now consistently synced with the database (in the past this was not done consistently which caused strange behaviour).
* Fixed some bugs in the multi-word command handler. It can handle multi-word exits as well now.
This commit is contained in:
Griatch 2009-11-01 15:12:38 +00:00
parent af19724bb2
commit 642932a403
9 changed files with 177 additions and 58 deletions

View file

@ -89,8 +89,9 @@ class Command(object):
# add a space after the raw input; this cause split() to always
# create a list with at least two entries.
raw = "%s " % self.raw_input
cmd_words = raw.split()
raw = "%s " % self.raw_input
cmd_words = raw.split(' ')
try:
if '/' in cmd_words[0]:
# if we have switches we directly go for the first command form.
@ -112,8 +113,9 @@ class Command(object):
# as tuples (commandname, args). They are stored with
# the longest possible name first.
try:
command_alternatives.append( (" ".join(cmd_words[:spacecount+1]),
" ".join(cmd_words[spacecount+1:])) )
command_alternatives.append( (" ".join([w.strip()
for w in cmd_words[:spacecount+1]]).strip(),
" ".join(cmd_words[spacecount+1:]).strip()) )
except IndexError:
continue
if command_alternatives:
@ -362,6 +364,8 @@ def command_table_lookup(command, command_table, eval_perms=True,
"""
cmdtuple = None
if command.command_alternatives:
#print "alternatives:",command.command_alternatives
#print command_table.ctable
# we have command alternatives (due to spaces in command definition)
for cmd_alternative in command.command_alternatives:
# the alternatives are ordered longest -> shortest.
@ -375,7 +379,7 @@ def command_table_lookup(command, command_table, eval_perms=True,
if not cmdtuple:
# None of the alternatives match, go with the default one-word name
cmdtuple = command_table.get_command_tuple(command.command_string)
if cmdtuple:
# if we get here we have found a command match in the table
if test:
@ -411,8 +415,9 @@ def match_neighbor_ctables(command,test=False):
location = source_object.get_location()
if location:
# get all objects, including the current room
neighbors = location.get_contents() + [location]
neighbors = location.get_contents() + [location] + source_object.get_contents()
for neighbor in neighbors:
#print "neighbor:", neighbor
if command_table_lookup(command,
neighbor.scriptlink.command_table,
test=test, neighbor=neighbor):