Efficiently retrieve tiles in a big texture

Introduced properties

fun [](x: Int, y: Int): Texture

gamnit :: TileSet :: []

Subtexture for the tile at x, y
init defaultinit(texture: Texture, width: Numeric, height: Numeric)

gamnit :: TileSet :: defaultinit

fun height: Numeric

gamnit :: TileSet :: height

Height of a tile
protected fun height=(height: Numeric)

gamnit :: TileSet :: height=

Height of a tile
fun nb_cols: Int

gamnit :: TileSet :: nb_cols

Number of columns of tiles in the texture
protected fun nb_cols=(nb_cols: Int)

gamnit :: TileSet :: nb_cols=

Number of columns of tiles in the texture
fun nb_rows: Int

gamnit :: TileSet :: nb_rows

Number of rows of tiles in the texture
protected fun nb_rows=(nb_rows: Int)

gamnit :: TileSet :: nb_rows=

Number of rows of tiles in the texture
fun subtextures: Array[Texture]

gamnit :: TileSet :: subtextures

Cache of the subtextures of tiles
protected fun subtextures=(subtextures: Array[Texture])

gamnit :: TileSet :: subtextures=

Cache of the subtextures of tiles
fun texture: Texture

gamnit :: TileSet :: texture

Texture containing the tileset
protected fun texture=(texture: Texture)

gamnit :: TileSet :: texture=

Texture containing the tileset
fun width: Numeric

gamnit :: TileSet :: width

Width of a tile
protected fun width=(width: Numeric)

gamnit :: TileSet :: width=

Width of a tile

Redefined properties

redef type SELF: TileSet

gamnit $ TileSet :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun [](x: Int, y: Int): Texture

gamnit :: TileSet :: []

Subtexture for the tile at x, y
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(texture: Texture, width: Numeric, height: Numeric)

gamnit :: TileSet :: defaultinit

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun height: Numeric

gamnit :: TileSet :: height

Height of a tile
protected fun height=(height: Numeric)

gamnit :: TileSet :: height=

Height of a tile
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun nb_cols: Int

gamnit :: TileSet :: nb_cols

Number of columns of tiles in the texture
protected fun nb_cols=(nb_cols: Int)

gamnit :: TileSet :: nb_cols=

Number of columns of tiles in the texture
fun nb_rows: Int

gamnit :: TileSet :: nb_rows

Number of rows of tiles in the texture
protected fun nb_rows=(nb_rows: Int)

gamnit :: TileSet :: nb_rows=

Number of rows of tiles in the texture
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun subtextures: Array[Texture]

gamnit :: TileSet :: subtextures

Cache of the subtextures of tiles
protected fun subtextures=(subtextures: Array[Texture])

gamnit :: TileSet :: subtextures=

Cache of the subtextures of tiles
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun texture: Texture

gamnit :: TileSet :: texture

Texture containing the tileset
protected fun texture=(texture: Texture)

gamnit :: TileSet :: texture=

Texture containing the tileset
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun width: Numeric

gamnit :: TileSet :: width

Width of a tile
protected fun width=(width: Numeric)

gamnit :: TileSet :: width=

Width of a tile
package_diagram gamnit::TileSet TileSet core::Object Object gamnit::TileSet->core::Object gamnit::TileSetFont TileSetFont gamnit::TileSetFont->gamnit::TileSet

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class TileSetFont

gamnit :: TileSetFont

A monospace bitmap font where glyphs are stored in a tileset

Class definitions

gamnit $ TileSet
# Efficiently retrieve tiles in a big texture
class TileSet
	# Texture containing the tileset
	var texture: Texture

	# Width of a tile
	var width: Numeric

	# Height of a tile
	var height: Numeric

	# Number of columns of tiles in the texture
	var nb_cols: Int = (texture.width / width.to_f).to_i is lazy

	# Number of rows of tiles in the texture
	var nb_rows: Int = (texture.height / height.to_f).to_i is lazy

	# Cache of the subtextures of tiles
	var subtextures: Array[Texture] is lazy do
		var subtextures = new Array[Texture]
		for j in [0..nb_rows[ do
			for i in [0..nb_cols[ do
				subtextures.add texture.subtexture(
					i.to_f*width.to_f, j.to_f*height.to_f, width.to_f, height.to_f)
			end
		end
		return subtextures
	end

	# Subtexture for the tile at `x, y`
	#
	# Require: `x < nb_cols and y < nb_rows`
	fun [](x,y: Int): Texture
	do
		assert x >= 0 and x < nb_cols and y >= 0 and y <= nb_rows else print "{x}x{y}<?{nb_cols}x{nb_rows}"
		var idx = x + y * nb_cols
		return subtextures[idx]
	end
end
lib/gamnit/tileset.nit:20,1--58,3