Skip to content

Commit

Permalink
Performance improvements to map rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Tomes committed Jan 2, 2024
1 parent 333db60 commit abe8e04
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 35 deletions.
Binary file modified assets/OEM437_16_ex.pdn
Binary file not shown.
Binary file modified assets/OEM437_16_ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/video-preamble.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
μ-hack is a traditional roguelike written in MiniScript.

# References

- [Git](https://github.com/treytomes/micro-hack)
- [itch.io](https://treytomes.itch.io/micro-hack)
- The web viewer is a little buggy at the moment, but the OS-specific downloads have been working great.
- [MiniScript](https://miniscript.org/)
- [Mini Micro](https://miniscript.org/MiniMicro/)
28 changes: 14 additions & 14 deletions src/MapDisplay.ms
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ MapDisplay.flip = function()
self.activeDisplay = 1

self.display = self.display1
self.displayBack = self.display1Back
// self.displayBack = self.display1Back

self.display0.install self.displayNumberFront
self.display0Back.install self.displayNumberBack
// self.display0Back.install self.displayNumberBack
else
self.activeDisplay = 0

self.display = self.display0
self.displayBack = self.display0Back
// self.displayBack = self.display0Back

self.display1.install self.displayNumberFront
self.display1Back.install self.displayNumberBack
// self.display1Back.install self.displayNumberBack
end if
return self
end function
Expand All @@ -58,22 +58,22 @@ MapDisplay.scrollTo = function(x, y)
self.display0.scrollX = x
self.display0.scrollY = y

self.display0Back.scrollX = x
self.display0Back.scrollY = y
// self.display0Back.scrollX = x
// self.display0Back.scrollY = y

self.display1.scrollX = x
self.display1.scrollY = y

self.display1Back.scrollX = x
self.display1Back.scrollY = y
// self.display1Back.scrollX = x
// self.display1Back.scrollY = y
end function

MapDisplay.setCellBackColor = function(x, y, backColor)
if backColor isa Color then
backColor = backColor.str()
end if
self.displayBack.setCell x, y, constants.TILE_INDEX_SOLID
self.displayBack.setCellTint x, y, backColor
// if backColor isa Color then
// backColor = backColor.str()
// end if
// self.displayBack.setCell x, y, constants.TILE_INDEX_SOLID
// self.displayBack.setCellTint x, y, backColor
end function

MapDisplay.setCell = function(x, y, tile, color="#FFFFFF", backColor = "#00000000")
Expand All @@ -86,7 +86,7 @@ MapDisplay.setCell = function(x, y, tile, color="#FFFFFF", backColor = "#0000000
end if
self.display.setCell x, y, tile
self.display.setCellTint x, y, color
self.setCellBackColor x, y, backColor
// self.setCellBackColor x, y, backColor
end function

MapDisplay.clear = function(fg="#000000", bg="#00000000")
Expand Down
3 changes: 1 addition & 2 deletions src/factories/entities.ms
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Entity Factory

makePlayer = function()
// t = tile.make(char(57872), Color.white, Color.black, true, false) // TODO
t = tile.make(255+16-3, Color.white, Color.black, true, false)
e = (new entity.Entity).init(t, races.human, classes.fighter)

Expand Down Expand Up @@ -55,7 +54,7 @@ makePlayer = function()
end function

makeSign = function(map, pnt, msg)
t = tile.make("-", Color.white, Color.brown, true, false)
t = tile.make(24 * 16 + 8, Color.white, Color.brown, true, false)
e = (new entity.Entity).init(t, races.npc, classes.classless, pnt)
e.name = "sign"
e.description = "The sign reads: ""{0}""".fill([msg])
Expand Down
54 changes: 40 additions & 14 deletions src/factories/tiles.ms
Original file line number Diff line number Diff line change
@@ -1,31 +1,57 @@
// Colored tiles start at index 24 * 16 + 0.

makeFloor = function()
return tile.make(".", Color.brown.dark, Color.black, false, false).setName("floor")
// return tile.make(".", Color.brown.dark, Color.black, false, false).setName("floor")
return tile.make(24 * 16 + 0, Color.white, Color.white, false, false).
setName("floor").
setMapColor(Color.brown.dark)
end function

makeGrass = function()
return tile.make(".", Color.green.dark, Color.green.darker, false, false).setName("grass")
end function

makeMountain = function()
return tile.make("#", Color.gray.darker.darker, Color.gray.dark.dark, true, true).setName("mountain")
// return tile.make(".", Color.green.dark, Color.green.darker, false, false).setName("grass")
return tile.make(24 * 16 + 1, Color.white, Color.white, false, false).
setName("grass").
setMapColor(Color.green.dark)
end function

makeStairsUp = function()
return tile.make("<", Color.brown.dark, Color.black, false, false).setName("stairs up")
makeHidden = function()
// return tile.make("#", Color.black, Color.gray, true, true).setName("hidden")
return tile.make(24 * 16 + 2, Color.white, Color.white, true, true).
setName("hidden").
setMapColor(Color.black)
end function

makeStairsDown = function()
return tile.make(">", Color.brown.dark, Color.black, false, false).setName("stairs down")
makeMountain = function()
// return tile.make("#", Color.gray.darker.darker, Color.gray.dark.dark, true, true).setName("mountain")
return tile.make(24 * 16 + 3, Color.white, Color.white, true, true).
setName("mountain").
setMapColor(Color.gray.darker.darker)
end function

makeWall = function()
return tile.make("#", Color.brown, Color.black, true, true).setName("wall")
// return tile.make("#", Color.brown, Color.black, true, true).setName("wall")
return tile.make(24 * 16 + 4, Color.white, Color.white, true, true).
setName("wall").
setMapColor(Color.brown)
end function

makeDoor = function()
return tile.make("+", Color.black, Color.brown, false, true).setName("door")
// return tile.make("+", Color.black, Color.brown, false, true).setName("door")
return tile.make(24 * 16 + 5, Color.white, Color.white, false, true).
setName("door").
setMapColor(Color.black)
end function

makeHidden = function()
return tile.make("#", Color.black, Color.gray, true, true).setName("hidden")
makeStairsUp = function()
// return tile.make("<", Color.brown.dark, Color.black, false, false).setName("stairs up")
return tile.make(24 * 16 + 6, Color.white, Color.white, false, false).
setName("stairs up").
setMapColor(Color.brown.dark)
end function

makeStairsDown = function()
// return tile.make(">", Color.brown.dark, Color.black, false, false).setName("stairs down")
return tile.make(24 * 16 + 7, Color.white, Color.white, false, false).
setName("stairs down").
setMapColor(Color.brown.dark)
end function
10 changes: 5 additions & 5 deletions src/map.ms
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end function
Map.clear = function(dsp)
for y in range(0, SCREEN_MAX_Y - 1)
for x in range(0, SCREEN_MAX_X)
dsp.setCell x, y, "#", color.black, color.gray
dsp.setCell x, y, 24 * 16 + 2, color.white, color.white
end for
end for
end function
Expand All @@ -141,7 +141,7 @@ Map.drawTile = function(dsp, x, y, renderOffset=null)
end if
if not math.isInRange(x, 0, self.width - 1) or not math.isInRange(y, 0, self.height - 1) then
dsp.setCell rx, ry, "#", color.black, color.gray
dsp.setCell rx, ry, 24 * 16 + 2, color.white, color.white
return
end if
Expand All @@ -160,7 +160,7 @@ Map.drawTile = function(dsp, x, y, renderOffset=null)
// c = t.foregroundColor.str()
// Display.pixels.setPixel constants.PIXEL_WIDTH - x - 1, constants.PIXEL_HEIGHT - y - 1, c
else
dsp.setCell rx, ry, "#", color.black, color.gray
dsp.setCell rx, ry, 24 * 16 + 2, color.white, color.white
// // Draw minimap.
// c = color.gray
Expand All @@ -186,7 +186,7 @@ Map.drawMiniMap = function()
rx = constants.PIXEL_WIDTH - (renderWidth - x * cellSize) - borderSize - 1
ry = constants.PIXEL_HEIGHT - (renderHeight - y * cellSize) - borderSize - 1
if tile.hasBeenVisited then
c = tile.foregroundColor.str()
c = tile.mapColor.str()
// Display.pixels.setPixel rx, ry, c
Display.pixels.drawRect rx, ry, cellSize, cellSize, c, 1
else
Expand All @@ -205,7 +205,7 @@ Map.drawMiniMap = function()
continue
end if
c = e.tile.foregroundColor.str()
c = e.tile.mapColor.str()
rx = constants.PIXEL_WIDTH - (renderWidth - ex * cellSize) - borderSize - 1
ry = constants.PIXEL_HEIGHT - (renderHeight - ey * cellSize) - borderSize - 1
Expand Down
11 changes: 11 additions & 0 deletions src/tile.ms
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Tile = {}

// TODO: Remove tile background color.

Tile.init = function(char, foregroundColor, backgroundColor=null, blocksMovement=false, blocksVision=false)
self.char = char
self.foregroundColor = foregroundColor
self.backgroundColor = math.coalesce(backgroundColor, Color.black)

// The map color is used for the minimap.
self.mapColor = self.foregroundColor

self.blocksMovement = blocksMovement
self.blocksVision = blocksVision
self.name = ""
Expand Down Expand Up @@ -45,6 +51,11 @@ Tile.setName = function(name)
return self
end function

Tile.setMapColor = function(c)
self.mapColor = c
return self
end function

make = function(char, foregroundColor, backgroundColor, blocksMovement=false, blocksVision=false)
t = (new Tile)
t.init(char, foregroundColor, backgroundColor, blocksMovement, blocksVision)
Expand Down

0 comments on commit abe8e04

Please sign in to comment.