Skip to content

Commit

Permalink
Add nogame bundle; CMake zips and concats nogame;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed Nov 18, 2023
1 parent daea902 commit c969d43
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 11 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1.0)
cmake_minimum_required(VERSION 3.3.0)
cmake_policy(SET CMP0063 NEW)
cmake_policy(SET CMP0079 NEW)
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum macOS deployment version")
Expand Down Expand Up @@ -628,6 +628,13 @@ foreach(path ${LOVR_RESOURCES})
file(WRITE ${output} "const unsigned char ${identifier}[] = {${data}};\nconst unsigned int ${identifier}_len = sizeof(${identifier});\n")
endforeach()

add_custom_command(TARGET lovr POST_BUILD
DEPENDS "etc/nogame"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/etc/nogame"
COMMAND ${CMAKE_COMMAND} -E tar c "${CMAKE_CURRENT_BINARY_DIR}/nogame.zip" --format=zip arg.lua conf.lua main.lua
COMMAND ${CMAKE_COMMAND} -E cat "${CMAKE_CURRENT_BINARY_DIR}/nogame.zip" >> $<TARGET_FILE:lovr>
)

# Add a custom target that is always out of date so libraries are always moved
add_custom_target(move_files ALL)

Expand Down
2 changes: 1 addition & 1 deletion Tupfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ src += config.modules.math and 'src/lib/noise/*.c' or nil

-- embed resource files with xxd

res = { 'etc/boot.lua', 'etc/nogame.lua', 'etc/*.ttf', 'etc/shaders/*.glsl' }
res = { 'etc/boot.lua', 'etc/*.ttf', 'etc/shaders/*.glsl' }
tup.foreach_rule(res, '^ XD %b^ xxd -i %f > %o', '%f.h')

for i, pattern in ipairs(res) do
Expand Down
4 changes: 2 additions & 2 deletions etc/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function lovr.boot()
-- Figure out source archive and main module. CLI places source at arg[0]

local source, main
if cli or not fused then
if arg[0] and arg[0]:match('[^/\\]+%.lua$') then
if (cli or not fused) and arg[0] then
if arg[0]:match('[^/\\]+%.lua$') then
source = arg[0]:match('[/\\]') and arg[0]:match('(.+)[/\\][^/\\]+$') or '.'
main = arg[0]:match('[^/\\]+%.lua$')
else
Expand Down
66 changes: 66 additions & 0 deletions etc/nogame/arg.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
function lovr.arg(arg)
local options = {
_help = { short = '-h', long = '--help', help = 'Show help and exit' },
_version = { short = '-v', long = '--version', help = 'Show version and exit' },
debug = { long = '--debug', help = 'Enable debugging checks and logging' }
}

local shift

for i, argument in ipairs(arg) do
if argument:match('^%-') then
for name, option in pairs(options) do
if argument == option.short or argument == option.long then
arg[name] = true
break
end
end
else
shift = i
break
end
end

shift = shift or (#arg + 1)

for i = 0, #arg do
arg[i - shift], arg[i] = arg[i], nil
end

if arg._help then
local message = {}

local list = {}
for name, option in pairs(options) do
option.name = name
table.insert(list, option)
end

table.sort(list, function(a, b) return a.name < b.name end)

for i, option in ipairs(list) do
if option.short and option.long then
table.insert(message, (' %s, %s\t\t%s'):format(option.short, option.long, option.help))
else
table.insert(message, (' %s\t\t%s'):format(option.long or option.short, option.help))
end
end

table.insert(message, 1, 'usage: lovr [options] [<source>]\n')
table.insert(message, 2, 'options:')
table.insert(message, '\n<source> can be a Lua file, a folder, or a zip archive')
print(table.concat(message, '\n'))
os.exit(0)
end

if arg._version then
print(('LOVR %d.%d.%d'):format(lovr.getVersion()))
os.exit(0)
end

return function(conf)
if arg.debug then
conf.graphics.debug = true
end
end
end
6 changes: 6 additions & 0 deletions etc/nogame/conf.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function lovr.conf(t)
t.headset.supersample = true
t.modules.audio = false
t.modules.physics = false
t.modules.thread = false
end
7 changes: 0 additions & 7 deletions etc/nogame.lua → etc/nogame/main.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
function lovr.conf(t)
t.headset.supersample = true
t.modules.audio = false
t.modules.physics = false
t.modules.thread = false
end

function lovr.load()
if not lovr.graphics then
print(string.format('LÖVR %d.%d.%d\nNo game', lovr.getVersion()))
Expand Down

0 comments on commit c969d43

Please sign in to comment.