Getting ready for ANSI handling, some SQLite3 optimizations (hopefully).

This commit is contained in:
Greg Taylor 2006-12-24 06:38:08 +00:00
parent ec2e39fa3e
commit c66c93ad0b
6 changed files with 35 additions and 11 deletions

View file

@ -36,11 +36,19 @@ ansi["back_magenta"] = "\033[45m"
ansi["back_cyan"] = "\033[46m" ansi["back_cyan"] = "\033[46m"
ansi["back_white"] = "\033[47m" ansi["back_white"] = "\033[47m"
def parse_ansi(string): # Formatting Characters
ansi["return"] = "\n\r"
ansi["tab"] = "\t"
ansi["space"] = " "
def parse_ansi(string, strip_ansi=False):
""" """
Parses a string, subbing color codes as needed. Parses a string, subbing color codes as needed.
""" """
ansi_subs = [ ansi_subs = [
(r'%r', ansi["return"]),
(r'%t', ansi["tab"]),
(r'%b', ansi["space"]),
(r'%cf', ansi["blink"]), (r'%cf', ansi["blink"]),
(r'%ci', ansi["inverse"]), (r'%ci', ansi["inverse"]),
(r'%ch', ansi["hilite"]), (r'%ch', ansi["hilite"]),
@ -65,6 +73,9 @@ def parse_ansi(string):
for sub in ansi_subs: for sub in ansi_subs:
p = re.compile(sub[0], re.DOTALL) p = re.compile(sub[0], re.DOTALL)
string = p.sub(sub[1], string) if strip_ansi:
string = p.sub("", string)
else:
string = p.sub(sub[1], string)
print '%s%s' % (string, ansi["normal"]) return '%s%s' % (string, ansi["normal"])

View file

@ -8,8 +8,8 @@ class Attribute(models.Model):
example, a drink container needs to store its fill level, whereas an exit example, a drink container needs to store its fill level, whereas an exit
needs to store its open/closed/locked/unlocked state. These are done via needs to store its open/closed/locked/unlocked state. These are done via
attributes, rather than making different classes for each object type and attributes, rather than making different classes for each object type and
storing them directly. The added benefit is that we can add/remove attributes storing them directly. The added benefit is that we can add/remove
on the fly as we like. attributes on the fly as we like.
""" """
name = models.CharField(maxlength=255) name = models.CharField(maxlength=255)
value = models.CharField(maxlength=255) value = models.CharField(maxlength=255)
@ -33,6 +33,7 @@ class Object(models.Model):
modules or sub-classing. modules or sub-classing.
""" """
name = models.CharField(maxlength=255) name = models.CharField(maxlength=255)
ansi_name = models.CharField(maxlength=255)
owner = models.ForeignKey('self', related_name="obj_owner", blank=True, null=True) owner = models.ForeignKey('self', related_name="obj_owner", blank=True, null=True)
zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True) zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True)
home = models.ForeignKey('self', related_name="obj_home", blank=True, null=True) home = models.ForeignKey('self', related_name="obj_home", blank=True, null=True)

View file

@ -135,7 +135,7 @@ def cmd_examine(cdat):
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: else:

View file

@ -47,12 +47,10 @@ def get_nextfree_dbnum():
nextfree = Object.objects.filter(type__exact=6) nextfree = Object.objects.filter(type__exact=6)
if nextfree: if nextfree:
# We've got at least one garbage object to recycle. # We've got at least one garbage object to recycle.
print 'GARB'
return nextfree[0] return nextfree[0]
else: else:
# No garbage to recycle, find the highest dbnum and increment it # No garbage to recycle, find the highest dbnum and increment it
# for our next free. # for our next free.
print 'NOTGARB'
return int(Object.objects.order_by('-id')[0].id + 1) return int(Object.objects.order_by('-id')[0].id + 1)
def global_object_name_search(ostring): def global_object_name_search(ostring):

View file

@ -17,11 +17,11 @@ def time_format(seconds, style=0):
# We'll just use integer math, no need for decimal precision. # We'll just use integer math, no need for decimal precision.
seconds = int(seconds) seconds = int(seconds)
days = seconds / 86400 days = seconds / 86400
seconds -= days * 86400 seconds -= days * 86400
hours = seconds / 3600 hours = seconds / 3600
seconds -= hours * 3600 seconds -= hours * 3600
minutes = seconds / 60 minutes = seconds / 60
seconds -= minutes * 60 seconds -= minutes * 60
if style is 0: if style is 0:

View file

@ -11,6 +11,7 @@ import functions_general
import global_defines import global_defines
import session_mgr import session_mgr
import gameconf import gameconf
import settings
class Server(dispatcher): class Server(dispatcher):
""" """
@ -21,6 +22,8 @@ class Server(dispatcher):
self.game_running = True self.game_running = True
# Wipe our temporary flags on all of the objects. # Wipe our temporary flags on all of the objects.
if settings.DATABASE_ENGINE == "sqlite3":
self.sqlite3_prep()
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("UPDATE objects_object SET nosave_flags=''") cursor.execute("UPDATE objects_object SET nosave_flags=''")
@ -63,6 +66,17 @@ class Server(dispatcher):
print 'Connection:', str(session) print 'Connection:', str(session)
print 'Sessions active:', len(session_mgr.get_session_list()) print 'Sessions active:', len(session_mgr.get_session_list())
def sqlite3_prep(self):
"""
Optimize some SQLite stuff at startup since we can't save it to the
database.
"""
cursor = connection.cursor()
cursor.execute("PRAGMA cache_size=10000")
cursor.execute("PRAGMA synchronous=OFF")
cursor.execute("PRAGMA count_changes=OFF")
cursor.execute("PRAGMA temp_store=2")
""" """
BEGIN GENERAL METHODS BEGIN GENERAL METHODS
""" """