from os import makedirs, walk, sep, remove
from os.path import join, dirname, basename, exists
from shutil import rmtree, copy, rmtree
from itertools import chain
from zipfile import ZipFile

import py2exe

from Setup import Setup

class SetupWin(Setup):

    def __init__(self):
        Setup.__init__(self)
        self.replace_isSystemDLL()

    def replace_isSystemDLL(self):
        origIsSystemDLL = py2exe.build_exe.isSystemDLL
        def isSystemDLL(pathname):
            if basename(pathname).lower() in ("libogg-0.dll", "sdl_ttf.dll"):
                return 0
            return origIsSystemDLL(pathname)
        py2exe.build_exe.isSystemDLL = isSystemDLL

    def setup(self):
        config = self.config.get_section("setup")
	windows = [{}]
	if config["init-script"]:
	    windows[0]["script"] = config["init-script"]
	if config["windows-icon-path"]:
	    windows[0]["icon-resources"] = [(1, config["windows-icon-path"])]
        Setup.setup(self, windows,
                    {"py2exe": {"packages": self.build_package_list(),
                                "dist_dir": config["windows-dist-path"]}})
        rmtree("build")
        self.copy_data_files()
        self.create_archive()

    def copy_data_files(self):
	root = self.config.get("setup", "windows-dist-path")
        for path in chain(*zip(*self.build_data_map())[1]):
            dest = join(root, dirname(path))
            if not exists(dest):
                makedirs(dest)
            copy(path, dest)
	self.include_readme(root)

    def include_readme(self, root):
	name = "README"
	if exists(name):
	    readme = open(name, "r")
	    reformatted = open(join(root, name + ".txt"), "w")
	    for line in open(name, "r"):
	    	reformatted.write(line.rstrip() + "\r\n")

    def create_archive(self):
        config = self.config.get_section("setup")
        title = self.translate_title() + "-" + config["version"] + "-win"
        archive_name = title + ".zip"
        archive = ZipFile(archive_name, "w")
        destination = config["windows-dist-path"]
        for root, dirs, names in walk(destination):
            for name in names:
                path = join(root, name)
                archive.write(path, path.replace(destination, title + sep))
        archive.close()
        copy(archive_name, "dist")
        remove(archive_name)
        rmtree(destination)
import pygame
from pygame.locals import *

from GameChild import GameChild
from Mainloop import Mainloop
from Audio import Audio
from Display import Display
from Configuration import Configuration
from Delegate import Delegate
from Input import Input
from ScreenGrabber import ScreenGrabber
from Profile import Profile
from VideoRecorder import VideoRecorder
from Interpolator import Interpolator
from TimeFilter import TimeFilter

class Game(GameChild):

    resource_path = None

    def __init__(self, config_rel_path=None, type_declarations=None):
        self.profile = Profile(self)
        GameChild.__init__(self)
        self.print_debug(pygame.version.ver)
        self.config_rel_path = config_rel_path
        self.type_declarations = type_declarations
        self.set_configuration()
        pygame.init()
        self.set_children()
        self.subscribe(self.end, QUIT)
        self.subscribe(self.end)
        self.delegate.enable()

    def set_configuration(self):
        self.configuration = Configuration(self.config_rel_path,
                                           self.resource_path,
                                           self.type_declarations)

    def set_children(self):
        self.time_filter = TimeFilter(self)
        self.delegate = Delegate(self)
        self.display = Display(self)
        self.mainloop = Mainloop(self)
        self.input = Input(self)
        self.audio = Audio(self)
        self.screen_grabber = ScreenGrabber(self)
        self.video_recorder = VideoRecorder(self)
        self.interpolator = Interpolator(self)

    def frame(self):
        self.time_filter.update()
        self.delegate.dispatch()
        if not self.interpolator.is_gui_active():
            self.update()
        else:
            self.interpolator.gui.update()
        self.video_recorder.update()

    def run(self):
        self.mainloop.run()

    def update(self):
        pass

    def blit(self, source, destination, area=None, special_flags=0):
        self.get_screen().blit(source, destination, area, special_flags)

    def get_rect(self):
        return self.get_screen().get_rect()

    def end(self, evt):
        if evt.type == QUIT or self.delegate.compare(evt, "quit"):
            self.mainloop.stop()
            self.profile.end()
from os import makedirs
from os.path import exists, join
from tempfile import TemporaryFile
from time import strftime

from pygame.image import tostring, frombuffer, save
from pygame.time import get_ticks

from GameChild import GameChild

class VideoRecorder(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.delegate = self.get_delegate()
        self.load_configuration()
        self.reset()
        self.subscribe(self.respond)

    def load_configuration(self):
        config = self.get_configuration("video-recordings")
        self.root = config["path"]
        self.directory_name_format = config["directory-name-format"]
        self.file_extension = config["file-extension"]
        self.frame_format = config["frame-format"]
        self.framerate = config["framerate"]

    def reset(self):
        self.recording = False
        self.frame_length = None
        self.frames = None
        self.last_frame = 0

    def respond(self, event):
        compare = self.delegate.compare
        if compare(event, "record-video"):
            self.toggle_record()
        elif compare(event, "reset-game"):
            self.reset()

    def toggle_record(self):
        recording = not self.recording
        if recording:
            self.frame_length = len(self.get_string())
            self.frames = TemporaryFile()
        else:
            self.write_frames()
        self.recording = recording

    def get_string(self):
        return tostring(self.display_surface, self.frame_format)

    def write_frames(self):
        root = join(self.root, strftime(self.directory_name_format))
        if not exists(root):
            makedirs(root)
        size = self.display_surface.get_size()
        frames = self.frames
        frames.seek(0)
        for ii, frame in enumerate(iter(lambda: frames.read(self.frame_length),
                                        "")):
            path = join(root, "%04i.png" % ii)
            save(frombuffer(frame, size, self.frame_format), path)
        print "wrote video frames to " + root

    def update(self):
        ticks = get_ticks()
        if self.recording and ticks - self.last_frame >= self.framerate:
            self.frames.write(self.get_string())
            self.last_frame = ticks
18.217.182.45
18.217.182.45
18.217.182.45
 
December 3, 2013

Where in the mind's prism does light shine, inward, outward, or backward, and where in a plane does it intersect, experientially and literally, while possessing itself in a dripping wet phantasm?


Fig 1.1 What happens after you turn on a video game and before it appears?

The taxonomy of fun contains the difference between gasps of desperation and exaltation, simultaneously identical and opposite; one inspires you to have sex, while the other to ejaculate perpetually. A destruction and its procession are effervescent, while free play is an inseminated shimmer hatching inside you. Unlikely to be resolved, however, in such a way, are the climaxes of transitions between isolated, consecutive game states.

You walk through a door or long-jump face first (your face, not Mario's) into a painting. A moment passes for eternity, viscerally fading from your ego, corpus, chakra, gaia, the basis of your soul. It happens when you kill too, and especially when you precisely maim or obliterate something. It's a reason to live, a replicating stasis.


Fig 1.2 Sequence in a video game

Video games are death reanimated. You recurse through the underworld toward an illusion. Everything in a decision and logic attaches permanently to your fingerprint. At the core, you use its energy to soar, comatose, back into the biosphere, possibly because the formal structure of a mind by human standards is useful in the next world.