I am currently developing an addon that runs Doom inside WoW. It consists of two main parts: the addon containing the game and a CPU emulator.
Currently, the game runs at 2-4 FPS, depending on the hardware, and a significant portion of that time is spent rendering the framebuffer for each frame.
The game uses a 256-color palette and returns a buffer that is (W*H*1) bytes long. I have not found a better way than creating (W*H) "pixel" textures and setting them in a loop. While the loop itself is not extremely optimized, the majority of the time is spent on pixel:SetColorTexture
Lua Code:
-- Renders the frame from the given framebuffer address.
-- @param framebuffer_addr The address of the framebuffer to render.
function Frame:RenderFrame(framebuffer_addr)
local read4 = self.CPU.memory:Read(4)
for x = 0, 320-1, 4 do
for y = 0, 200-1 do
local offset = y * 320 + x
local data = read4(framebuffer_addr + offset)
for i=0,3 do
local data_loc = data % 0x100
local color = self.vga_to_rgb[data_loc]
local pixel = self.pixels[offset + i + 1]
if data_loc ~= pixel.color then
pixel:SetColorTexture(unpack(color))
pixel.color = data_loc
end
data = bit.rshift(data, 8)
end
end
end
end
Please see the full source code on
GitHub.
Could there be a faster way to achieve the desired result of rendering the framebuffer?
Current ideas:
* Pre-generate 256*256 2-pixel (2x1) textures to reduce the number of texture modification calls by half.
* I could potentially generate a BLP-compatible string pretty effectively, but there doesn’t seem to be a way to load a texture from a string.