Reduce number of reads for sprite region
This commit is contained in:
parent
4d078da6f8
commit
aa6f8babc8
3 changed files with 19 additions and 14 deletions
17
game.lua
17
game.lua
|
@ -231,28 +231,29 @@ function _M.getJumpHeight()
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.getSprite(idx)
|
function _M.getSprite(idx)
|
||||||
local base_addr = idx * mem.size.sprite + mem.addr.spriteBase
|
local baseAddr = idx * mem.size.sprite + mem.addr.spriteBase
|
||||||
|
local spriteData = memory.readregion(baseAddr, mem.size.sprite)
|
||||||
|
|
||||||
local offsets = mem.offset.sprite
|
local offsets = mem.offset.sprite
|
||||||
local control = memory.readword(base_addr + offsets.control)
|
local control = util.regionToWord(spriteData, offsets.control)
|
||||||
|
|
||||||
if control == 0 then
|
if control == 0 then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local x = memory.readword(base_addr + offsets.x)
|
local x = util.regionToWord(spriteData, offsets.x)
|
||||||
local y = memory.readword(base_addr + offsets.y)
|
local y = util.regionToWord(spriteData, offsets.y)
|
||||||
local sprite = {
|
local sprite = {
|
||||||
control = control,
|
control = control,
|
||||||
screenX = x - 256 - _M.cameraX - 256,
|
screenX = x - 256 - _M.cameraX - 256,
|
||||||
screenY = y - 256 - _M.cameraY - 256,
|
screenY = y - 256 - _M.cameraY - 256,
|
||||||
jumpHeight = memory.readword(base_addr + offsets.jumpHeight),
|
jumpHeight = util.regionToWord(spriteData, offsets.jumpHeight),
|
||||||
-- style bits
|
-- style bits
|
||||||
-- 0x4000 0: Right facing 1: Flipped
|
-- 0x4000 0: Right facing 1: Flipped
|
||||||
-- 0x1000 0: Alive 1: Dying
|
-- 0x1000 0: Alive 1: Dying
|
||||||
style = memory.readword(base_addr + offsets.style),
|
style = util.regionToWord(spriteData, offsets.style),
|
||||||
velocityX = memory.readsword(base_addr + offsets.velocityX),
|
velocityX = util.regionToWord(spriteData, offsets.velocityX),
|
||||||
velocityY = memory.readsword(base_addr + offsets.velocityY),
|
velocityY = util.regionToWord(spriteData, offsets.velocityY),
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
good = spritelist.Sprites[control]
|
good = spritelist.Sprites[control]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
local classes = _SYSTEM.all_classes()
|
print(string.hex(bit.compose(0xef, 0xbe)))
|
||||||
io.stderr:write(classes:gsub(classes:sub(8,1), '\n'))
|
local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*[/\\])(.*)", "%1")
|
||||||
for k,v in pairs(_SYSTEM) do
|
local game = dofile(base.."/game.lua")
|
||||||
print(k)
|
|
||||||
|
function on_input()
|
||||||
end
|
end
|
7
util.lua
7
util.lua
|
@ -241,8 +241,11 @@ function _M.nearestColor(needle, colors)
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function _M.regionToWord(region, offset)
|
||||||
|
return bit.compose(region[offset], region[offset + 1])
|
||||||
|
end
|
||||||
|
|
||||||
return function(promise)
|
return function(promise)
|
||||||
Promise = promise
|
Promise = promise
|
||||||
return _M
|
return _M
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue