Optimized resource encoder
Is now three times faster Former-commit-id: 39397911e4b87d1831d15a32d7125a707c353bf7
This commit is contained in:
parent
0e99205046
commit
3026d8b9ac
|
|
@ -1,30 +1,28 @@
|
||||||
function encodeResources()
|
function encodeResources()
|
||||||
print("Encoding resources ...")
|
print("Encoding resources ...")
|
||||||
|
local startClock = os.clock()
|
||||||
local modules = os.matchdirs("../src/Nazara/*")
|
local modules = os.matchdirs("../src/Nazara/*")
|
||||||
for k, modulePath in pairs(modules) do
|
for k, modulePath in pairs(modules) do
|
||||||
local file
|
|
||||||
local headerContent
|
|
||||||
local moduleName = modulePath:sub(15, -1)
|
local moduleName = modulePath:sub(15, -1)
|
||||||
local resourceContent
|
|
||||||
local files = os.matchfiles(modulePath .. "/Resources/**")
|
local files = os.matchfiles(modulePath .. "/Resources/**")
|
||||||
for k, filePath in pairs(files) do
|
for k, filePath in pairs(files) do
|
||||||
if (filePath:sub(-2) ~= ".h") then
|
if (filePath:sub(-2) ~= ".h") then
|
||||||
file = filePath:sub(modulePath:len() + 12, -1)
|
local file = filePath:sub(modulePath:len() + 12, -1)
|
||||||
local resource, err = io.open(filePath, "rb")
|
local resource, err = io.open(filePath, "rb")
|
||||||
if (not resource) then
|
if (not resource) then
|
||||||
error("Failed to read resource file " .. file .. ": " .. err)
|
error("Failed to read resource file " .. file .. ": " .. err)
|
||||||
end
|
end
|
||||||
|
|
||||||
resourceContent = resource:read("*a")
|
local resourceContent = resource:read("*a")
|
||||||
resource:close()
|
resource:close()
|
||||||
|
|
||||||
local contentLength = resourceContent:len()
|
local contentLength = resourceContent:len()
|
||||||
|
|
||||||
headerContent = ""
|
local headerContentTable = {}
|
||||||
for i = 1, contentLength do
|
for i = 1, contentLength do
|
||||||
local b = resourceContent:sub(i, i):byte()
|
table.insert(headerContentTable, string.format("%d,", resourceContent:byte(i)))
|
||||||
headerContent = headerContent .. string.format("%d,", b)
|
|
||||||
end
|
end
|
||||||
|
local headerContent = table.concat(headerContentTable)
|
||||||
|
|
||||||
local header, err = io.open(filePath .. ".h", "w+")
|
local header, err = io.open(filePath .. ".h", "w+")
|
||||||
if (not header) then
|
if (not header) then
|
||||||
|
|
@ -33,11 +31,12 @@ function encodeResources()
|
||||||
|
|
||||||
header:write(headerContent)
|
header:write(headerContent)
|
||||||
header:close()
|
header:close()
|
||||||
|
|
||||||
print(string.format("%s: %s (raw: %.3g kB, header: %.3g kB)", moduleName, file, contentLength/1024, string.format("%.3g", headerContent:len()/1024)))
|
print(string.format("%s: %s (raw: %.3g kB, header: %.3g kB)", moduleName, file, contentLength/1024, string.format("%.3g", headerContent:len()/1024)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
print("Finished (took " .. os.clock() - startClock .. "s)")
|
||||||
end
|
end
|
||||||
|
|
||||||
newaction
|
newaction
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue