Skip to content

Commit 7a7f2aa

Browse files
committed
Color mobjs by type
Also reorder code to minimize reads for mobjs that aren't displayed
1 parent 2057554 commit 7a7f2aa

File tree

1 file changed

+55
-25
lines changed

1 file changed

+55
-25
lines changed

Assets/Lua/Doom/things-lines.lua

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ local CHAR_HEIGHT = 16
1515
local NEGATIVE_MAXIMUM = 1 << 63
1616
local POSITIVE_MAXIMUM = ~NEGATIVE_MAXIMUM
1717
local MAP_CLICK_BLOCK = "P1 Fire" -- prevent this input while clicking on map buttons
18+
19+
-- Map colors (0xAARRGGBB or "name" or false)
20+
local ENEMY_COLOR = 0xFFFF0000
21+
local ENEMY_WAIT_COLOR = 0xFFCC0000
22+
local CORPSE_COLOR = false -- 0x80CC0000
23+
local MISSILE_COLOR = 0xFFFF8000
24+
local PLAYER_COLOR = 0xFF0080FF
25+
local COUNTITEM_COLOR = false -- 0xA0FFFFFF
26+
local ITEM_COLOR = false -- 0xA0FFFFFF
27+
local MISC_COLOR = false -- 0xFFFFFFFF
28+
local INERT_COLOR = false -- 0x80808080
29+
1830
-- shortcuts
1931
local rl = memory.read_u32_le
2032
local rw = memory.read_u16_le
@@ -27,8 +39,14 @@ local box = gui.drawBox
2739
local drawline = gui.drawLine
2840
--local text = gui.pixelText -- INSANELY SLOW
2941

42+
local PlayerOffsets = dsda.player.offsets -- player member offsets in bytes
43+
local MobjOffsets = dsda.mobj.offsets -- mobj member offsets in bytes
44+
local LineOffsets = dsda.line.offsets -- line member offsets in bytes
45+
local MobjType = dsda.mobjtype
46+
local SpriteNumber = dsda.doom.spritenum
47+
local MobjFlags = dsda.mobjflags
48+
3049
-- TOP LEVEL VARIABLES
31-
local LastWheel = 0
3250
local Zoom = 1
3351
local Init = true
3452
-- tables
@@ -54,11 +72,6 @@ local LastMouse = {
5472
wheel = 0
5573
}
5674
-- forward declarations
57-
local PlayerOffsets = dsda.player.offsets -- player member offsets in bytes
58-
local MobjOffsets = dsda.mobj.offsets -- mobj member offsets in bytes
59-
local LineOffsets = dsda.line.offsets -- line member offsets in bytes
60-
local MobjType = dsda.mobjtype
61-
local SpriteNumber = dsda.doom.spritenum
6275
local Lines = {}
6376

6477
--gui.defaultPixelFont("fceux")
@@ -141,6 +154,21 @@ local function get_line_count(str)
141154
return lines, longest
142155
end
143156

157+
local function get_mobj_color(mobj)
158+
local flags = mobj.flags
159+
if flags & (MobjFlags.PICKUP | MobjFlags.FRIEND) ~= 0 then return PLAYER_COLOR end
160+
if flags & (MobjFlags.COUNTKILL | MobjFlags.SKULLFLY) ~= 0 then
161+
if flags & MobjFlags.CORPSE ~= 0 and flags & MobjFlags.RESSURECTED == 0 then return CORPSE_COLOR end
162+
if flags & MobjFlags.AMBUSH ~= 0 or mobj.target == 0 then return ENEMY_WAIT_COLOR end
163+
return ENEMY_COLOR
164+
end
165+
if flags & MobjFlags.COUNTITEM ~= 0 then return COUNTITEM_COLOR end
166+
if flags & MobjFlags.SPECIAL ~= 0 then return ITEM_COLOR end
167+
if flags & MobjFlags.MISSILE ~= 0 then return MISSILE_COLOR end
168+
if flags & MobjFlags.SHOOTABLE ~= 0 then return MISC_COLOR end
169+
return INERT_COLOR
170+
end
171+
144172
local function iterate_players()
145173
local playercount = 0
146174
local total_killcount = 0
@@ -170,25 +198,27 @@ local function iterate()
170198
if Init then return end
171199

172200
for addr, mobj in pairs(dsda.mobj.items) do
173-
local pos = { x = mapify_x(mobj.x), y = mapify_y(-mobj.y) }
174-
local radius = math.floor ((mobj.radius >> 16) * Zoom)
175-
-- local sprite = SpriteNumber[mobj.sprite]
176-
local type = MobjType[mobj.type]
177-
local color = "white"
178-
179-
if mobj.health <= 0 then color = "red" end
180-
--[[--
181-
local z = mobj.z
182-
local index = mobj.index
183-
local tics = mobj.tics
184-
--]]--
185-
if in_range(pos.x, 0, client.screenwidth())
186-
and in_range(pos.y, 0, client.screenheight())
187-
and type
188-
and not string.find(type, "MISC")
189-
then
190-
text(pos.x, pos.y, string.format("%s", type), color)
191-
box(pos.x - radius, pos.y - radius, pos.x + radius, pos.y + radius, color)
201+
local color = get_mobj_color(mobj)
202+
if color then -- not hidden
203+
local pos = { x = mapify_x(mobj.x), y = mapify_y(-mobj.y) }
204+
205+
if in_range(pos.x, 0, client.screenwidth())
206+
and in_range(pos.y, 0, client.screenheight())
207+
then
208+
local type = mobj.type
209+
local radius = math.floor ((mobj.radius >> 16) * Zoom)
210+
--[[--
211+
local z = mobj.z
212+
local index = mobj.index
213+
local tics = mobj.tics
214+
local health = mobj.health
215+
local sprite = SpriteNumber[mobj.sprite]
216+
--]]--
217+
218+
type = MobjType[type]
219+
text(pos.x, pos.y, string.format("%s", type), color)
220+
box(pos.x - radius, pos.y - radius, pos.x + radius, pos.y + radius, color)
221+
end
192222
end
193223
end
194224

0 commit comments

Comments
 (0)