コード例 #1
0
 def send(self, id, value, op_id, recursion_id=""):
     """go parentwise collecting id until at root object, then send it"""
     #print "SharedObject:", id, value, op_id, recursion_id
     if recursion_id:
         if self._id: recursion_id = self._id + "." + recursion_id
     else:
         recursion_id = self._id
     #print "->", recursion_id
     self._changed = 1
     if self._parent:
         if op_id == "create": op_id = "set"
         self._parent.send(id, value, op_id, recursion_id)
     else:
         if op_id == "delete":
             if recursion_id: id = recursion_id + "." + id
             obj = atlas.Object(id=id)
         else:
             if recursion_id:
                 obj = atlas.Object()
                 obj[id] = value
                 obj.id = recursion_id
             else:
                 obj = atlas.Object()
                 obj.update(value)
                 obj.id = id
         op = atlas.Operation(op_id, obj)
         #print "<<", op, ">>"
         self.send_op(op)
コード例 #2
0
ファイル: dxf2atlas.py プロジェクト: greenermoose/atlas-cpp
 def as_atlas(self, amap, world_obj, media_map):
     obj = atlas.Object(parents=["layer"],
                        contains=[],
                        loc=world_obj,
                        name=self.name)
     amap.add(obj)
     id_m = obj.id + "m"
     id_2D = obj.id + "_2D"
     media_obj = atlas.Object(id=id_m,
                              parents=["media_info"],
                              media_groups=atlas.Object(media_2D=[id_2D]),
                              filter=atlas.Object(id="game_entity",
                                                  loc=obj.id))
     media_map.add(media_obj)
     if self.color in (1, 20):
         color = [255, 0, 0]
     elif self.color == 3:
         color = [0, 255, 0]
     elif self.color == 5:
         color = [0, 0, 255]
     elif self.color == 7:
         color = [255, 255, 255]
     else:
         color = [0, 0, 0]
     media_obj2D = atlas.Object(id=id_2D,
                                parents=["polyline_media_2D"],
                                summary="ACAD color: %i" % self.color,
                                rgb_color=color)
     media_map.add(media_obj2D)
     for ent in self:
         ent_obj = ent.as_atlas(amap, obj)
         if not ent_obj: continue
         obj.contains.append(ent_obj)
     return obj
コード例 #3
0
ファイル: simple_core_server.py プロジェクト: sajty/atlas-cpp
 def server_object(self):
     if self.server.worlds:
         world_ids = map(lambda o:o.id, self.server.worlds)
         return atlas.Object(name=server_name, id=server_id,
                             parents=["server"],
                             contains=world_ids)
     else:
         return atlas.Object(name=server_name, id=server_id,
                             parents=["server"],
                             contains=self.server.objects.keys())
コード例 #4
0
 def server_object(self):
     if self.server.worlds:
         world_ids = [o.id for o in self.server.worlds]
         return atlas.Object(name=server_name,
                             id=server_id,
                             parents=["server"],
                             contains=world_ids)
     else:
         return atlas.Object(name=server_name,
                             id=server_id,
                             parents=["server"],
                             contains=list(self.server.objects.keys()))
コード例 #5
0
ファイル: dxf2atlas.py プロジェクト: greenermoose/atlas-cpp
    def write(self, file, media_file):
        atlas.uri_type["loc"] = 1
        atlas.uri_list_type["contains"] = 1
        amap = AtlasMap()
        media_map = AtlasMap()
        world = atlas.Object(parents = ["world"], contains = [],
                             detailed_contents = 1,
                             summary = "Converted from %s" % self.file_name,
                             description = "Converted from %s by dxf2atlas into %s" % \
                                           (self.file_name, file),
                             source = "file://" + self.file_name)
        amap.add(world)
        amap.add(
            atlas.Object(
                parents=["game_entity"],
                id="layer",
                specification="atlas_dxf",
                summary="parent class to layer instances",
                detailed_contents=1,
                description=
                "layer instances: these are actual layers that contain other stuff"
            ))
        amap.add(
            atlas.Object(parents=["game_entity"],
                         id="polyline_obj",
                         specification="atlas_dxf",
                         p=[],
                         summary="object consisting of polyline"))

        amap.add(
            atlas.Object(parents=["game_entity"],
                         id="text_obj",
                         specification="atlas_dxf",
                         summary="object consisting of text"))

        amap.add(
            atlas.Object(parents=["uri"],
                         id="source",
                         specification="atlas_dxf",
                         summary="source of converted file"))

        for layer in self.layers.values():
            #if layer.name!="SVTEKSTI": continue
            layer_obj = layer.as_atlas(amap, world, media_map)
            world.contains.append(layer_obj)
            amap.add(layer_obj)

        self.write_in_order(amap, file)
        self.write_in_order(media_map, media_file)
コード例 #6
0
def test_speed(max):
    for i in range(max):
        account = atlas.Object()
        account.id="foo"
        account.password="******"
        op = atlas.Operation("login",account)
        s = str(op)
コード例 #7
0
 def talk(self, name, say):
     self.send_operation(
         atlas.Operation("talk",
                         atlas.Object(say=say),
                         from_=name,
                         id="gateway"))
     print("ATLAS: talk:", name, say)
コード例 #8
0
 def send_error(self, op, msg):
     err = atlas.Object(message=msg, op=op)
     try:
         refid = op.id
     except AttributeError:
         refid = ""
     self.send_operation(atlas.Operation("error", err, refid=refid))
コード例 #9
0
    def lookup_score(self, obj, media_type, original_obj):
        """find best match or if none try again with parents"""
        if self.has_key(obj.id):
            mi_lst = self[obj.id]
            if type(mi_lst) != ListType: return
            #print "SCORE---:", map(lambda obj:obj.id, mi_lst)
            best = None
            best_score = -1
            result = []
            for mi in mi_lst:
                mtype = "media_" + media_type
                if not hasattr(mi, "media_groups"): return []
                if mi.media_groups.has_key(mtype):
                    mi2 = mi.media_groups[mtype][0]
                    if type(mi2) == StringType:
                        mi2 = self[mi2]
                    new_score = self.score_match(original_obj, mi)
                    #print "SCORE?: ", original_obj.id, mi.filter, new_score
                    if new_score > best_score:
                        #print "SCORE!: ", original_obj.id, mi.filter, new_score
                        best = mi2
                        best_score = new_score
            return best

        else:
            parent = obj.parent
            if type(parent) == StringType:
                parent = atlas.Object(id=parent, parent=[])
            res = self.lookup_score(parent, media_type, original_obj)
            if res:
                return res
コード例 #10
0
def cc():
    #a.pond2_2D.rgb_color = [1.0, 1.0, 1.0]
    a.p3 = atlas.Object(id="p3",
                        objtype="object",
                        parents=["lake"],
                        loc="left_meadow",
                        area=[["1.p.4", "1.p.5", "1.p.0"]])
コード例 #11
0
    def init_shell(self, parent):
        self.shell = shell.Shell(parent, -1, introText=intro)
        self.shell.SetFocus()
        #timer
        self.timer = IdleTimer(self.idle)
        self.timer.Start(1000)
        self.lastTime = time()
        #self.shell.interp.locals["a"] = SharedObject(self.connection)
        self.shell.interp.locals["a"] = shared_factory(self.connection, None,
                                                       atlas.Object())
        self.shell.interp.locals["o"] = atlas.Object
        self.shell.interp.locals["app"] = self
        import local_code
        for key in local_code.__dict__.keys():
            if key[0] != "_":
                self.shell.interp.locals[key] = getattr(local_code, key)
        local_code.a = self.shell.interp.locals["a"]
        self.connection.objects = self.objects()
        self.connection.objects._send_flag = 1

        def send_op(op, connection=self.connection):
            connection.send_operation(op)

        self.shell.interp.locals["send"] = send_op

        def talk(nick, text, send_op=send_op):
            send_op(atlas.Operation("talk", atlas.Object(say=text),
                                    from_=nick))

        self.shell.interp.locals["talk"] = talk
        return self.shell
コード例 #12
0
 def login_op(self, op):
     account = op.arg.id
     if self.server.has_account(account):
         self.send_error(op, "somebody already in with that id")
     else:
         self.id = account
         ent = atlas.Object(parents=["player"], id=account)
         self.reply_operation(op, atlas.Operation("info", ent, to=account))
コード例 #13
0
 def ask(self, id_lst):
     for id in id_lst:
         id = atlas.get_base_id(id)
         #print "?"*60, id, len(id_lst)
         if id and id not in self.pending and id not in self.objects:
             print("?", id)
             op = atlas.Operation("get", atlas.Object(id=id))
             self.send_operation(op)
             self.pending[id] = id
コード例 #14
0
ファイル: dxf2atlas.py プロジェクト: greenermoose/atlas-cpp
 def as_atlas(self, amap, layer_obj):
     obj = atlas.Object(parents=["polyline_obj"], loc=layer_obj)
     amap.add(obj)
     obj.p = []
     obj.polyline = []
     for p in self.get_points():
         obj.polyline.append("%s.p.%i" % (obj.id, len(obj.p)))
         obj.p.append([p[0], p[1], p[2]])
     return obj
コード例 #15
0
ファイル: test_server.py プロジェクト: worldforge/atlas-cpp
 def loop(self):
     op = atlas.Operation("talk",
                          atlas.Object(say="Hello world!"),
                          from_="Joe")
     self.send_operation(op)
     self.waiting = 1
     while self.waiting:
         time.sleep(0.1)
         self.process_communication()
コード例 #16
0
 def ask(self, id_lst):
     for id in id_lst:
         id = atlas.get_base_id(id)
         #print "?"*60, id, len(id_lst)
         if id and not self.pending.has_key(
                 id) and not self.objects.has_key(id):
             print "?", id
             op = atlas.Operation("get", atlas.Object(id=id))
             self.send_operation(op)
             self.pending[id] = id
コード例 #17
0
ファイル: test_server.py プロジェクト: worldforge/atlas-cpp
 def talk_op(self, op):
     if print_debug:
         print(repr(str(op)))
     self.server.str_op = str(op)
     reply = atlas.Operation("sound",
                             atlas.Operation("talk",
                                             atlas.Object(say="Hello %s!" %
                                                          op.from_),
                                             from_=op.from_),
                             from_=op.from_)
     self.reply_operation(op, reply)
     self.server.waiting = 0
コード例 #18
0
ファイル: dxf2atlas.py プロジェクト: greenermoose/atlas-cpp
 def as_atlas(self, amap, layer_obj):
     ca = math.cos(-self.angle)
     sa = math.sin(-self.angle)
     obj = atlas.Object(parents=["text_obj"],
                        loc=layer_obj,
                        pos=self.pos,
                        text=self.text,
                        rotation=[[ca, -sa, 0.0], [sa, ca, 0.0],
                                  [0.0, 0.0, 1.0]])
     #obj = atlas.Object(parents = ["text_obj"], loc=layer_obj,
     #                   pos = self.pos, text = self.text)
     amap.add(obj)
     return obj
コード例 #19
0
ファイル: bach.py プロジェクト: worldforge/atlas-cpp
 def get_next_mode(self, ch):
     if ch == "{":
         self.push(atlas.Object(), excepted_value="map_name")
     elif ch == "[":
         self.push([], excepted_value="list_value")
     elif ch in "}]":
         self.pop()
     elif ch in int_characters:
         self.push("", self.int, ch)
     elif ch == '"':
         self.push("", self.string)
     elif ch in plain_name_characters:
         self.push("", self.name, ch)
     elif ch in ",:" + string.whitespace:
         self.mode = self.skip_white_space
     elif ch == "#":
         self.mode = self.add_comment
     else:
         raise BachException("illegal character (%s (%s) at line %i)!" %
                             (ch, ord(ch), self.lineno))
コード例 #20
0
ファイル: test_bridge.py プロジェクト: MasterMann/atlas-cpp
        self.bridge = Bridge(NegotiationServer(), functions=self)


class TestClient(Common):
    def __init__(self):
        Common.__init__(self)
        self.bridge = Bridge(NegotiationClient(), functions=self)


bserver = TestServer()
bclient = TestClient()
bserver.other = bclient
bclient.other = bserver

bclient.bridge.process_operation(
    atlas.Operation("talk", atlas.Object(say="Hello world!"), from_="Joe"))

if print_debug:
    print "=" * 60

bserver.bridge.process_operation(
    atlas.Operation(
        "sound",
        atlas.Operation("talk", atlas.Object(say="Hello Joe!"), from_="Joe")))

assert (bclient.data_list == [
    'ATLAS client\012',
    'ICAN Bach_beta2\012ICAN XML\012ICAN XML2_test\012ICAN Packed\012ICAN Binary1_beta\012ICAN Binary2_test\012\012',
    '[\012\011{\012\011\011arg: {\012\011\011\011say: "Hello world!"\012\011\011},\012\011\011from: "Joe",\012\011\011objtype: "op",\012\011\011parents: ["talk"]\012\011}'
])
assert (len(bclient.op_list) == 1)
コード例 #21
0
    def draw_object(self, obj, depth, count=0):
        redraw_flag = 0
        if not obj: return
        if obj.id not in self.map.objects: return
        if id(obj)!=id(self.map.objects[obj.id]):
            print(obj.id, "not same id()!!")
        if not hasattr(obj, "detailed_contents"):
            print("????detailed_contents?", end=' ')
            atlas.print_parents(obj)
            #print "self.map.objects:",
            #atlas.print_parents(self.map.objects[obj.parents[0]])
            #import pdb; pdb.set_trace()
        if not obj.detailed_contents:
            if obj._polyline:

##                mi = self.media_info.lookup(obj, "2D")
##                if mi:
##                    apply(glColor3f, mi.rgb_color)
##                    glLineWidth(mi.line_width)
##                else:
##                    glColor3f(0.0, 0.0, 0.0)
##                    glLineWidth(1.0)
##                for i in range(len(obj._polyline)-1):
##                    p1, p2 = obj._polyline[i:i+2]
##                    glPushMatrix()
##                    glTranslated(p1.x, p1.y, 0.0)
##                    glBegin(GL_LINES)
##                    glVertex3f(0.0, 0.0, depth)
##                    glVertex3f(p2.x - p1.x, p2.y - p1.y, depth)
##                    glEnd()
##                    glPopMatrix()
##                glLineWidth(1.0)

                glPushMatrix()
                p = atlas.Object()
                p.x = self.middle_x
                p.y = self.middle_y
                #p = obj._polyline[0]
                glTranslated(p.x, p.y, 0.0)
                mi = self.media_info.lookup(obj, "2D")
                if mi:
                    glColor3f(*mi.rgb_color)
                    glLineWidth(mi.line_width)
                else:
                    glColor3f(0.0, 0.0, 0.0)
                    glLineWidth(1.0)
                glBegin(GL_LINE_STRIP)
                for v in obj._polyline:
                    glVertex3f(v.x - p.x, v.y - p.y, depth)
                glEnd()
                glLineWidth(1.0)
                glPopMatrix()

            if obj._area:
                use_texture = 0
                special_flag = 0
                mi = self.media_info.lookup(obj, "2D")
                if mi:
                    if texturing_enabled and hasattr(mi, "texture_coordinates"):
                        if type(mi.texture_source)==StringType:
                            art_info = self.media_info[mi.texture_source]
                        else:
                            art_info = mi.texture_source
                        if art_info.data_uri[:5]=="file:":
                            file_name = art_info.data_uri[5:]
                        else:
                            raise_(ValueError, "url type not supported (yet): "+art_info.data_uri)
                        use_texture = 1
                        if file_name[-4:]==".pnm":
                            fp = open(file_name)
                            fp.readline(); fp.readline()
                            width,height = list(map(int, string.split(fp.readline())))
                            special_flag = max(width, height)>256
                            if not special_flag: fp.close()
                        if special_flag:
                            print("special!")
                            special_flag = 1
                            fp.readline()
                            self.special_stuff.append(atlas.Object(texture = fp.read(),
                                                                   width = width,
                                                                   height = height,
                                                                   coordinates = mi.texture_coordinates))
                            fp.close()
                        else:
                            img = Image.open(file_name)
                            img = img.convert("RGBA")
                            print(img.size)
                            texture = img.tostring("raw", "RGBA", 0, -1)
                            if texture!=self.last_texture:
                                if use_mipmap:
                                    OpenGL.Tk.gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.size[0], img.size[1],
                                                                GL_RGBA, GL_UNSIGNED_BYTE, texture)
                                else:
                                    glTexImage2D(GL_TEXTURE_2D, 0, 3, img.size[0], img.size[1], 0,
                                                 GL_RGBA, GL_UNSIGNED_BYTE, texture)
                                self.last_texture = texture

                            redraw_flag = 1

    ##                        if count:
    ##                            rasterMap = freetype.drawString("a", font=font_file, size=444, type='pix')
    ##                            bitmap = rasterMap.tostring()
    ##                            bitmap2 = string.join(map(lambda c:chr(255)*3+c, bitmap), "")
    ##                            #bitmap2 = string.join(map(lambda c:"\0\0\0" + c, bitmap), "")
    ##                            #bitmap2 = string.join(map(lambda c:c+c+c+"\0", bitmap), "")
    ##                            #bitmap2 = string.join(map(lambda c:c*4, bitmap), "")
    ##                            print rasterMap.width, rasterMap.rows, len(bitmap), len(bitmap2)
    ##                            #img = freetype.toImage(rasterMap, type='pix')
    ##                            #img.save("a.png")

    ##                            img = Image.open("a_rgb.png")
    ##                            #58 68
    ##                            #glTexImage2D(GL_TEXTURE_2D, 0, 1, rasterMap.width, rasterMap.rows, 0,
    ##                            #glTexImage2D(GL_TEXTURE_2D, 0, 2, 256, 256, 0,
    ##                            #             GL_COLOR_INDEX, GL_BITMAP, bitmap)
    ##                            glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, 256, 256, 0,
    ##                                         GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, bitmap*3)
    ##                            #glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0,
    ##                            #             GL_RGBA, GL_UNSIGNED_BYTE, bitmap2)

                        
                            tx1, ty1, tz1 = mi.texture_coordinates[0]
                            tx2, ty2, tz2 = mi.texture_coordinates[1]
                            #glColor3f(1.0, 1.0, 0.0)
                            #glColor3f(0.0, 0.0, 0.0)
                            #glColor3f(1.0, 1.0, 1.0)
                    else:
                        try:
                            glColor3f(*mi.rgb_color)
                        except:
                            import pdb; pdb.set_trace()
                else:
                    glColor3f(0.0, 0.0, 0.0)

                if not special_flag:
                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

                    #glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0,
                    #             GL_RGBA, GL_UNSIGNED_BYTE, img.tostring)
                    #glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0,
                    #             GL_RGB, GL_UNSIGNED_BYTE, img.tostring)
                    #use_texture = obj.id=="right_meadow"
                    #use_texture = obj.id in ["left_meadow", "right_meadow"]
                    if use_texture:
                        #print "?"
                        glEnable(GL_TEXTURE_2D)
    ##                if count and fonts_enabled:
    ##                    glEnable(GL_ALPHA_TEST)
    ##                    glEnable(GL_BLEND)
    ##                    glAlphaFunc(GL_GEQUAL, 0.0625)
    ##                    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    ##                    #glEnable(GL_POLYGON_OFFSET)
    ##                    #glPolygonOffset(0.0, -3)
    ##                    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
    ##                    #glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
    ##                    #glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND)
    ##                    #glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
    ##                    glColor3f(1.0, 0.0, 0.0)
                    glBegin(GL_TRIANGLES)
                    for t in obj._area:
                        for v in t:
                            if use_texture:
                                #print "?"*10
                                #print v.x, v.y
                                #print tx1, tx2-tx1, ty1, ty2-ty1
                                #print (v.x-tx1)/(tx2-tx1), (v.y-ty1)/(ty2-ty1)
                                glTexCoord2d(old_div((v.x-tx1),(tx2-tx1)), old_div((v.y-ty1),(ty2-ty1)))
                            glVertex3f(v.x, v.y, depth)
                    glEnd()
                    if use_texture:
                        glDisable(GL_TEXTURE_2D)
    ##                if fonts_enabled:
    ##                    glDisable(GL_ALPHA_TEST)
    ##                    glDisable(GL_BLEND)
    ##                    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
                glColor3f(0.0, 0.0, 0.0)
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
                if draw_triangle_outline:
                    glBegin(GL_TRIANGLES)
                    for t in obj._area:
                        for v in t:
                            glVertex3f(v.x, v.y, depth)
                    glEnd()
                    
            if obj.get("text") and fonts_enabled:
                #print obj.text
                mi = self.media_info.lookup(obj, "2D")
                if mi:
                    glColor3f(*mi.rgb_color)
                    #print "with color:", mi.rgb_color
                else:
                    glColor3f(0.0, 0.0, 0.0)
                texture_size = hardware_texture_size
                if not self.font_texture_info:
                    texture = ["\0" * texture_size] * texture_size
                    curX = 0
                    curY = 0
                    curHeight = 0
                    extra_pixels = 1

                    bitmap_seen = {}
                    for char in map(chr, list(range(256))):
                    #for char in 'V\xc4 )(+-,/.1032547698?ACBEDFIHKJMLONPSRUT\xd6YX':
                        #render font
                        #print char, ord(char)
                        #rasterMap = drawCharacter(char, size=17)
                        rasterMap = drawCharacter(char, size=19)
                        #rasterMap = drawCharacter(char, size=41)
                        bitmap = rasterMap.tostring()
                        #img = freetype.toImage(rasterMap, 'pix')
                        #img.save("test.png")
                        #advance line if needed (and check limits)
                        while 1:
                            if rasterMap.cols + curX <= texture_size and \
                               rasterMap.rows + curY <= texture_size: break
                            if rasterMap.cols + curX > texture_size:
                                if curX:
                                    curX = 0
                                    curY += curHeight + extra_pixels
                                else:
                                    raise ValueError("too big size for fonts")
                            if rasterMap.rows + curY > texture_size:
                                raise ValueError("too big size for fonts")
                        #bitmap seen?
                        key = rasterMap.cols, rasterMap.rows, bitmap
                        if key in bitmap_seen:
                            self.font_texture_info[char] = bitmap_seen[key]
                            continue
                        bitmap_seen[key] = char

                        #store info about glyph
                        tbbox = atlas.Object(xmin = float(curX) / texture_size,
                                             ymin = float(curY) / texture_size,
                                             xmax = float(curX + rasterMap.cols) / texture_size,
                                             ymax = float(curY + rasterMap.rows) / texture_size)
                        fbbox = atlas.Object(xmin = rasterMap.metric.bbox.xMin,
                                             ymin = rasterMap.metric.bbox.yMin,
                                             xmax = rasterMap.metric.bbox.xMax,
                                             ymax = rasterMap.metric.bbox.yMax)
                        self.font_texture_info[char] = atlas.Object(
                            texture_bbox = tbbox,
                            font_bbox = fbbox,
                            advance = rasterMap.metric.advance)

                        #copy font into texture
                        y = curY + rasterMap.rows
                        for pos in range(0, len(bitmap), max(1, rasterMap.cols)):
                            y -= 1
                            texture[y] = texture[y][:curX] + \
                                         bitmap[pos:pos+rasterMap.cols] + \
                                         texture[y][curX+rasterMap.cols:]

##                        y = curY
##                        for pos in range(0, len(bitmap), max(1, rasterMap.cols)):
##                            y += 1
##                            texture[y] = texture[y][:curX] + \
##                                         bitmap[pos:pos+rasterMap.cols] + \
##                                         texture[y][curX+rasterMap.cols:]
                        
                        curX += rasterMap.cols + extra_pixels
                        curHeight = max(curHeight, rasterMap.rows)
                        #print rasterMap.width, rasterMap.cols, rasterMap.rows, len(bitmap)
                        #print curX,curY, curHeight
                    #open("foo2.out", "w").write(repr(bitmap)) 
                   #open("foo.out", "w").write(repr(texture))
                    self.font_texture = string.join(texture, "")
                    #self.font_texture = string.join(map(lambda c:c*2, self.font_texture), "")
                    im = Image.fromstring("L", (texture_size, texture_size),
                                          self.font_texture, "raw", "L;I")
                    im.save("font_texture.png")


                if self.font_texture!=self.last_texture:
                    #glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, 256, 256, 0,
                    #             GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, texture*4)
                    if use_mipmap:
                        #OpenGL.Tk.gluBuild2DMipmaps(GL_TEXTURE_2D, GL_INTENSITY4, texture_size, texture_size,
                        #                            GL_LUMINANCE, GL_UNSIGNED_BYTE, self.font_texture)
                        OpenGL.Tk.gluBuild2DMipmaps(GL_TEXTURE_2D, GL_INTENSITY, texture_size, texture_size,
                                                    GL_LUMINANCE, GL_UNSIGNED_BYTE, self.font_texture)
                        #OpenGL.Tk.gluBuild2DMipmaps(GL_TEXTURE_2D, GL_INTENSITY, texture_size, texture_size,
                        #                            GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, self.font_texture)
                    else:
                        glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, texture_size, texture_size, 0,
                                     GL_LUMINANCE, GL_UNSIGNED_BYTE, self.font_texture)
                    self.last_texture = self.font_texture

                glEnable(GL_TEXTURE_2D)
                glEnable(GL_ALPHA_TEST)
                glEnable(GL_BLEND)
                glAlphaFunc(GL_GEQUAL, 0.0625)
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
                #glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA)
                #glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE)
                #glEnable(GL_POLYGON_OFFSET)
                #glPolygonOffset(0.0, -3)
                glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)


                glPushMatrix()
                glTranslated(self.middle_x, self.middle_y, 0.0)
                p = obj._pos
                glTranslated(p.x - self.middle_x, p.y - self.middle_y, 0.0)
                glMultMatrixd(rot2glmatrix(obj.rotation))
                x, y = 0.0, 0.0
                glBegin(GL_QUADS)
                if 0: #test...
                    x1 = x
                    y1 = y
                    x2 = x + 10.0
                    y2 = y + 10.0
                    glTexCoord2d(0.0, 0.0)
                    glVertex3f(x1, y1, depth)
                    glTexCoord2d(1.0, 0.0)
                    glVertex3f(x2, y1, depth)
                    glTexCoord2d(1.0, 1.0)
                    glVertex3f(x2, y2, depth)
                    glTexCoord2d(0.0, 1.0)
                    glVertex3f(x1, y2, depth)
                else:
                    fp = open("debug.log", "a+")
                    fp.write(obj.text+"\n")
                    for char in obj.text:
                        ti = self.font_texture_info[char]
                        size = 1./600
                        x1 = x + ti.font_bbox.xmin * size
                        y1 = y + ti.font_bbox.ymin * size
                        x2 = x + ti.font_bbox.xmax * size
                        y2 = y + ti.font_bbox.ymax * size
                        #print char, ord(char), ti
                        #print char, ord(char), x1,y1,x2,y2, ti.texture_bbox, x
                        fp.write(string.join(map(str, [char, ord(char), x, y, x1, y1, x2, y2, ti, ti.advance * size])) + "\n")
                        glTexCoord2d(ti.texture_bbox.xmin, ti.texture_bbox.ymin)
                        glVertex3f(x1, y1, depth)
                        glTexCoord2d(ti.texture_bbox.xmax, ti.texture_bbox.ymin)
                        glVertex3f(x2, y1, depth)
                        glTexCoord2d(ti.texture_bbox.xmax, ti.texture_bbox.ymax)
                        glVertex3f(x2, y2, depth)
                        glTexCoord2d(ti.texture_bbox.xmin, ti.texture_bbox.ymax)
                        glVertex3f(x1, y2, depth)
                        x += ti.advance * size
                    fp.close()
##                tex_size = 1.0
##                glTexCoord2d(0, 0)
##                glVertex3f(p.x, p.y, depth)
##                glTexCoord2d(tex_size, 0)
##                glVertex3f(p.x+1, p.y, depth)
##                glTexCoord2d(tex_size, tex_size)
##                glVertex3f(p.x+1, p.y+1, depth)
##                glTexCoord2d(0, tex_size)
##                glVertex3f(p.x, p.y+1, depth)
                glEnd()
                glPopMatrix()

                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)


                glDisable(GL_TEXTURE_2D)
                glDisable(GL_ALPHA_TEST)
                glDisable(GL_BLEND)
                glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)


        for sub_obj in obj.contains:
            #print "unhashable?", type(sub_obj.id), "for:", obj.id
            #if self.map.objects.has_key(sub_obj.id) and id(sub_obj)!=id(self.map.objects[sub_obj.id]):
            #    print obj.id, sub_obj.id, "obj/sub: not same id()!!"
            #    print obj.__class__, sub_obj.__class__
            self.draw_object(sub_obj, depth)

##        if not count and redraw_flag:
##            self.draw_object(obj, depth, count+1)

        obj._changed = 0
コード例 #22
0
 def create_character(self, name):
     char = atlas.Object(id=name, objtype="object", parents=["character"])
     self.send_operation(atlas.Operation("create", char))
     print("ATLAS: create_character:", name)
コード例 #23
0
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Lesser General Public License for more details.

#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from __future__ import print_function
from builtins import input
import sys, time
sys.path.append("..")
from atlas.transport.TCP.client import TcpClient
from atlas.transport.connection import args2address
import atlas


class HelloWorldClient(TcpClient):
    def sound_op(self, op):
        talk_op = op.arg
        print("%s said %s" % (op.from_, talk_op.arg.say))


if __name__ == "__main__":
    s = HelloWorldClient("Hello World client", args2address(sys.argv))
    name = input("Nick/Name to use: ")
    s.send_operation(
        atlas.Operation("talk", atlas.Object(say="Hello World!"), from_=name))
    s.loop()
コード例 #24
0
 def ask(self, id):
     op = atlas.Operation("get", atlas.Object(id=id))
     self.send_operation(op)
     self.waiting[id] = 1
コード例 #25
0
 def talk(nick, text, send_op=send_op):
     send_op(atlas.Operation("talk", atlas.Object(say=text),
                             from_=nick))
コード例 #26
0
## t=atlas.Object()
## t.seconds=23.4
## o.time=t

## #print str(o)

## op = atlas.Operation("move",o,from_="bah")

sock=atlas.TCPSocket()
print sock.getSock()
print "Connect:", sock.connect("localhost",6767)
xml = atlas.XMLProtocol()
codec = atlas.Codec(xml)
client = atlas.Client(sock, codec)

account = atlas.Object()
account.id="foo"
account.password="******"
op = atlas.Operation("login",account)
print str(op)

#5.64s 10000kpl
##         account = atlas.Object()
##         account.id="foo"
##         account.password="******"
##         op = atlas.Operation("login",account)
#17.42s with following added
##         s = str(op)
#10.99s with 100kpl and 100 times data=printCodec->encodeMessage(*obj->obj);
#16.28s using PackedProtocol instead of XMLProtocol
#11.03s with 100kpl and 100 times data=printCodec->encodeMessage(*obj->obj);
コード例 #27
0
ファイル: parse_xml.py プロジェクト: greenermoose/atlas-cpp
 def start_map(self, attributes):
     self.push_value(attributes, atlas.Object())
コード例 #28
0
ファイル: test_glue.py プロジェクト: worldforge/atlas-cpp
            if debug_flag:
                print("%s: %s <-%s-> %s" % (msg, obj.id, point_id, obj2.id))
        else:
            if debug_flag:
                print("%s: %s:%s <-> %s:%s" %
                      (msg, obj.id, point_id, obj2.id, point_id2))
        del id_dict[other_id]
        return 1
    return 0


for obj in meadow_map:
    if hasattr(obj, "polyline"): obj.polyline_ids = deepcopy(obj.polyline)
    if hasattr(obj, "area"): obj.area_ids = deepcopy(obj.area)
    if hasattr(obj, "volume"): obj.volume_ids = deepcopy(obj.volume)
meadow_map.append(atlas.Object(id="polyline_ids", parents=["polyline"]))
meadow_map.append(atlas.Object(id="area_ids", parents=["area"]))
meadow_map.append(atlas.Object(id="volume_ids", parents=["volume"]))

#resolve and fill attributes
atlas.analyse.fill_attributes(meadow_map)

#calculate absolute locations
from atlas.geomap import GeoMap
gm = GeoMap(obj_dict)

if debug_flag:
    print("-" * 60)
#create dictionary indexed by absolute coordinates
point_dict = {}
for obj in list(gm.objects.values()):