From c66c93ad0bb9f0f8de119009c8de2752482d0c23 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sun, 24 Dec 2006 06:38:08 +0000 Subject: [PATCH] Getting ready for ANSI handling, some SQLite3 optimizations (hopefully). --- evennia/trunk/ansi.py | 17 ++++++++++++++--- evennia/trunk/apps/objects/models.py | 5 +++-- evennia/trunk/commands_general.py | 2 +- evennia/trunk/functions_db.py | 2 -- evennia/trunk/functions_general.py | 6 +++--- evennia/trunk/server.py | 14 ++++++++++++++ 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/evennia/trunk/ansi.py b/evennia/trunk/ansi.py index dafd93b242..4d76485ffe 100755 --- a/evennia/trunk/ansi.py +++ b/evennia/trunk/ansi.py @@ -36,11 +36,19 @@ ansi["back_magenta"] = "\033[45m" ansi["back_cyan"] = "\033[46m" 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. """ ansi_subs = [ + (r'%r', ansi["return"]), + (r'%t', ansi["tab"]), + (r'%b', ansi["space"]), (r'%cf', ansi["blink"]), (r'%ci', ansi["inverse"]), (r'%ch', ansi["hilite"]), @@ -65,6 +73,9 @@ def parse_ansi(string): for sub in ansi_subs: 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"]) diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index aaf6d509ba..cfa3716e99 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -8,8 +8,8 @@ class Attribute(models.Model): 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 attributes, rather than making different classes for each object type and - storing them directly. The added benefit is that we can add/remove attributes - on the fly as we like. + storing them directly. The added benefit is that we can add/remove + attributes on the fly as we like. """ name = models.CharField(maxlength=255) value = models.CharField(maxlength=255) @@ -33,6 +33,7 @@ class Object(models.Model): modules or sub-classing. """ name = models.CharField(maxlength=255) + ansi_name = models.CharField(maxlength=255) owner = models.ForeignKey('self', related_name="obj_owner", 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) diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index 2f589d798f..983032dfd3 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -135,7 +135,7 @@ def cmd_examine(cdat): for obj in target_obj.get_contents(): if obj.is_player: - con_players.append(obj) + con_players.append(obj) elif obj.is_exit: con_exits.append(obj) else: diff --git a/evennia/trunk/functions_db.py b/evennia/trunk/functions_db.py index 15a2cfe27b..ba43691ef5 100644 --- a/evennia/trunk/functions_db.py +++ b/evennia/trunk/functions_db.py @@ -47,12 +47,10 @@ def get_nextfree_dbnum(): nextfree = Object.objects.filter(type__exact=6) if nextfree: # We've got at least one garbage object to recycle. - print 'GARB' return nextfree[0] else: # No garbage to recycle, find the highest dbnum and increment it # for our next free. - print 'NOTGARB' return int(Object.objects.order_by('-id')[0].id + 1) def global_object_name_search(ostring): diff --git a/evennia/trunk/functions_general.py b/evennia/trunk/functions_general.py index ac3e20a63c..777e91659d 100644 --- a/evennia/trunk/functions_general.py +++ b/evennia/trunk/functions_general.py @@ -17,11 +17,11 @@ def time_format(seconds, style=0): # We'll just use integer math, no need for decimal precision. seconds = int(seconds) - days = seconds / 86400 + days = seconds / 86400 seconds -= days * 86400 - hours = seconds / 3600 + hours = seconds / 3600 seconds -= hours * 3600 - minutes = seconds / 60 + minutes = seconds / 60 seconds -= minutes * 60 if style is 0: diff --git a/evennia/trunk/server.py b/evennia/trunk/server.py index e1fbfc1435..9e64226210 100755 --- a/evennia/trunk/server.py +++ b/evennia/trunk/server.py @@ -11,6 +11,7 @@ import functions_general import global_defines import session_mgr import gameconf +import settings class Server(dispatcher): """ @@ -21,6 +22,8 @@ class Server(dispatcher): self.game_running = True # Wipe our temporary flags on all of the objects. + if settings.DATABASE_ENGINE == "sqlite3": + self.sqlite3_prep() cursor = connection.cursor() cursor.execute("UPDATE objects_object SET nosave_flags=''") @@ -63,6 +66,17 @@ class Server(dispatcher): print 'Connection:', str(session) 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 """