My World Map对象应该是标准的(x,y)Tiles数组 (除非有更好的方法?) 每个Tile有一个布尔/一位值:0或False为Water,1或True for Land。 每个Tile都有一个对象(类),但类型为对象取决于 无论是水还是地块: - Land对象需要六个六角中每个角的数据结构 (即。给定的六边形包含一个海岸线,一座山,一座桥 e tc。)+建筑物数据(城堡,港口等)。最后它需要 链接到哪些军队驻留在Tile上。 - 一个Water对象只需要链接到哪些军队驻留在Tile上 (即帆船/舰队)。 所以在我看来,我不仅可以节省大量内存,还可以节省处理器功率80%的瓷砖绘制:每个Land Tile我都有来检查Hex Side值和构建列表以绘制特殊功能。 所有这些都是完全没必要的用水瓦片。 如果有人在这里可以告诉我如何制作这样的数据集,其中每个 Tile / element可能是两个对象之一类型,我真的很感激 it :) 0 :)无罪 Hi I''ve been considering how to optimize map data structures for a tilebased Python game. However, since I''m a Python newbie I lackexperience with Pythons ''exotic'' data types like lists and tuples, andthus I''m unsure whether such types could solve my problem. My basic thought is this: If my world map consists of 80% water and20% land, then why reserve full data-structures for all the watertiles? I''m looking for a way to do the following: My World Map object should likely be a standard (x,y) array of Tiles(unless there''s a better way?)Each Tile has a boolean/one-bit value: 0 or False for Water, 1 or Truefor Land.Each Tile has an object (class), but the type of object depends onwhether it''s a Water or Land Tile:- A Land object needs data structures for each of the six hex corners(ie. does a given hex-side contain a Coastline, a Mountain, a Bridgeetc.) + data for buildings (Castle, Harbour etc.). Finally it needslinks to which armies reside on the Tile. - A Water object need only links to which armies reside on the Tile(ie. sailing armies/fleets). So it seems to me I could save not only a fair deal of memory but alsoprocessor power on 80% of the Tiles drawn: With each Land Tile I haveto check Hex Side values and building lists to draw special features.All this is totally unnecessary with Water Tiles. If anyone here could tell me how to make such a data-set, where eachTile/element might be one of two object types, I''d really appreciateit :) 0:) Innocence推荐答案 2004年6月18日星期五15:58:36 +0200,Innocence< innocence(a)klog(dot)dk> 在comp.lang.python中声明了以下内容: On Fri, 18 Jun 2004 15:58:36 +0200, Innocence <innocence(a)klog(dot)dk>declaimed the following in comp.lang.python: 我的世界地图对象应该是b ea标准(x,y)Tiles数组(除非有更好的方法?)每个Tile都有一个布尔值/一位值:0或False表示Water,1或True 每个Tile都有一个对象(类),但对象的类型取决于它是水还是Land Tile: 嗯,要么你使用两个相似的类,一个用于陆地,而另一个用于水的b - 在这种情况下你根本不需要布尔值,只需要一个 表示从实例中获取类。或者你使用一个类,对于两种类型的瓷砖,它们的启动方式不同。 - 一个Land对象需要六个六角中每个角的数据结构 (即,给定的六边形包含海岸线,山脉,桥梁等)+建筑物数据(城堡,港口等)。最后它需要链接到哪些军队驻留在Tile上。 class Tile:#我知道,老式班...... def __init __(Land = False): self.Land =土地 如果土地: self.Side = [无] * 6 #sides undefined self.Buildings = [] #empty list self.Armies = [] #land或water both def SetSide(侧面,地形): 尝试: self.Side [side] = terrain 除外: print"无法为水十六进制设置地形 .... 与C ++和其他静态语言不同,其中必须使用预先声明所有可能的数据成员(或者来自虚拟的子类并添加 成员),Python实例不必包含相同的数据 - 数据成员是由成员函数添加的。 - ================================================ == ============< wl ***** @ ix。 netcom.com | Wulfraed Dennis Lee Bieber KD6MOG< wu******@dm.net | Bestiaria支持人员< ========================================= ========= ============< 主页:< http://www.dm.net/~wulfraed/> < 溢出页面:< http://wlfraed.home.netcom.com/> < My World Map object should likely be a standard (x,y) array of Tiles (unless there''s a better way?) Each Tile has a boolean/one-bit value: 0 or False for Water, 1 or True for Land. Each Tile has an object (class), but the type of object depends on whether it''s a Water or Land Tile:Well, either you are using two similar classes, one for land andone for water -- in which case you don''t need the boolean at all, just ameans to obtain the class from the instance. Or you use one class whichis initiated differently for the two types of tiles. - A Land object needs data structures for each of the six hex corners (ie. does a given hex-side contain a Coastline, a Mountain, a Bridge etc.) + data for buildings (Castle, Harbour etc.). Finally it needs links to which armies reside on the Tile.class Tile:# I know, old-style class...def __init__(Land= False):self.Land = Landif Land:self.Side = [None] * 6#sides undefinedself.Buildings = []#empty listself.Armies = []#land or water bothdef SetSide(side, terrain):try:self.Side[side] = terrainexcept:print "Can not set terrain for water hex".... Unlike C++, and other static languages, where one has topredeclare all possible data members (or subclass from virtuals and addmembers), Python instances do not have to contain identical data -- thedata members are added by member functions. -- ================================================== ============ < wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < wu******@dm.net | Bestiaria Support Staff < ================================================== ============ < Home Page: <http://www.dm.net/~wulfraed/> < Overflow Page: <http://wlfraed.home.netcom.com/> < 通过让所有水砖指向同一水来节省内存 实例。 water = WaterTile() ....建立你的瓷砖: 如果瓷砖应该是水: 瓷砖[x] [y] =水#不会瞬间 其他: 瓷砖[ x] [y] = GroundTile()#instanciate new object Save memory by having all the water tiles pointing to the same waterinstance. water = WaterTile() .... build your tiles : if tile should be water:tile[x][y] = water# doesn''t instanciateelse:tile[x][y] = GroundTile()# instanciate new object 2004年6月18日星期五22:58:45 +0200, Pierre-FrédéricCaillaud< pe **** @ free.fr>写道:On Fri, 18 Jun 2004 22:58:45 +0200,Pierre-Frédéric Caillaud <pe****@free.fr> wrote: 通过让所有水砖指向相同的水实例来节省内存。 water = WaterTile() ...建造你的瓷砖: 如果瓷砖应该是水:瓷砖[x] [y] =水#不会瞬间否则: tile [x] [y] = GroundTile()#instanciate new object Save memory by having all the water tiles pointing to the same water instance. water = WaterTile() ... build your tiles : if tile should be water: tile[x][y] = water# doesn''t instanciate else: tile[x][y] = GroundTile()# instanciate new object 这将使得很难确定哪些船是在 给定的水砖上。 - Sam Holden That''s going to make it really hard to determine which boats are on agiven water tile. --Sam Holden 这篇关于游戏 - 映射数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 08:01