mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-26 03:30:46 +00:00
Lunatic: move code in test/shadexfog.lua to engine.savePaletteDat() and complete it.
The function now writes out a full PALETTE.DAT: base balette, shade table and translucency table. git-svn-id: https://svn.eduke32.com/eduke32@4311 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
83d23092cd
commit
075d817ed7
2 changed files with 44 additions and 33 deletions
|
@ -226,5 +226,43 @@ function engine.nearcolor(r, g, b, lastokcol)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---------- Mapster32-only functions ----------
|
||||||
|
|
||||||
|
if (ismapster32) then
|
||||||
|
local io = require("io")
|
||||||
|
|
||||||
|
ffi.cdef[[size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, void * restrict stream);]]
|
||||||
|
|
||||||
|
-- [ok, errmsg] = engine.savePaletteDat(filename [, palnum [, blendnum]])
|
||||||
|
function engine.savePaletteDat(filename, palnum, blendnum)
|
||||||
|
local sht = engine.getshadetab(palnum or 0)
|
||||||
|
local tab = engine.getblendtab(blendnum or 0)
|
||||||
|
|
||||||
|
if (sht == nil) then
|
||||||
|
return nil, "no shade table with number "..palnum
|
||||||
|
elseif (tab == nil) then
|
||||||
|
return nil, "no blending table with number "..blendnum
|
||||||
|
end
|
||||||
|
|
||||||
|
local f, errmsg = io.open(filename, "w+")
|
||||||
|
if (f == nil) then
|
||||||
|
return nil, errmsg
|
||||||
|
end
|
||||||
|
|
||||||
|
local n1 = ffi.C.fwrite(C.palette, 3, 256, f)
|
||||||
|
f:write("\032\000") -- int16_t numshades
|
||||||
|
local n3 = ffi.C.fwrite(sht, 256, 32, f)
|
||||||
|
local n4 = ffi.C.fwrite(tab, 256, 256, f)
|
||||||
|
|
||||||
|
f:close()
|
||||||
|
if (n1 ~= 256 or n3 ~= 32 or n4 ~= 256) then
|
||||||
|
return nil, "failed writing enough data"
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Done!
|
-- Done!
|
||||||
return engine
|
return engine
|
||||||
|
|
|
@ -196,40 +196,13 @@ local function create_base_shtab_2(basesht)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (gv.LUNATIC_CLIENT == gv.LUNATIC_CLIENT_MAPSTER32) then
|
if (gv.LUNATIC_CLIENT == gv.LUNATIC_CLIENT_MAPSTER32) then
|
||||||
-- NOTE: It shouldn't be assumed that these will stay loadable in the future:
|
-- Wrapper around engine.savePaletteDat() that errors on unexpected events.
|
||||||
local ffi = require("ffi")
|
function shadexfog.save(filename, palnum, blendnum)
|
||||||
local io = require("io")
|
local ok, errmsg = engine.savePaletteDat(filename, palnum, blendnum)
|
||||||
|
if (not ok) then
|
||||||
ffi.cdef[[size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, void * restrict stream);]]
|
error(errmsg)
|
||||||
|
|
||||||
function shadexfog.save(filename, palnum_or_sht)
|
|
||||||
local sht = type(palnum_or_sht)~="number" and palnum_or_sht
|
|
||||||
or engine.getshadetab(palnum_or_sht)
|
|
||||||
if (sht == nil) then
|
|
||||||
error("No such shade table")
|
|
||||||
end
|
end
|
||||||
|
printf('Wrote base palette, shade and translucency tables to "%s"', filename)
|
||||||
local f, errmsg = io.open(filename, "w+")
|
|
||||||
if (f == nil) then
|
|
||||||
error(errmsg, 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- XXX: ought to be in engine.lua
|
|
||||||
local basepal = ffi.new("uint8_t [256][3]")
|
|
||||||
for i=0,255 do
|
|
||||||
local r, g, b = engine.getrgb(i)
|
|
||||||
basepal[i][0], basepal[i][1], basepal[i][2] = r, g, b
|
|
||||||
end
|
|
||||||
|
|
||||||
local n1 = ffi.C.fwrite(basepal, 3, 256, f)
|
|
||||||
f:write("\032\000")
|
|
||||||
local n3 = ffi.C.fwrite(sht, 256, 32, f)
|
|
||||||
|
|
||||||
f:close()
|
|
||||||
if (n1 ~= 256 or n3 ~= 32) then
|
|
||||||
error("didn't fully write out palette file")
|
|
||||||
end
|
|
||||||
printf("Wrote base palette + shade table (but NOT transluc table) to '%s'", filename)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue