2007-06-14
This commit is contained in:
1 parent
e20673c2cd
commit
1ae34ae340
96 files changed
+5680
-1020
No files matched your search
+1
-1
@@ -20,7 +20,7 @@ tick = 0
|
||||
-- every 100 ms, but it is pretty pointless at this time.
|
||||
function game_tick()
|
||||
if tick == 1 then
|
||||
screen.makeScreenShot("test.bmp")
|
||||
--screen.makeScreenShot("test.bmp")
|
||||
end
|
||||
tick = tick + 1
|
||||
end
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
screen.setFullscreen(true)
|
||||
|
||||
--screen.setFullscreen(true)
|
||||
camera.setCenter(61.4261, 7.56265, 2.2242)
|
||||
camera.setEye(61.4185, 8.72266, 0.810034)
|
||||
camera.setUp(0, 1, 0)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
function pairsByKeys (t, f)
|
||||
local a = {}
|
||||
for n in pairs(t) do table.insert(a, n) end
|
||||
table.sort(a, f)
|
||||
local i = 0 -- iterator variable
|
||||
local iter = function () -- iterator function
|
||||
i = i + 1
|
||||
if a[i] == nil then return nil
|
||||
else return a[i], t[a[i]]
|
||||
end
|
||||
end
|
||||
return iter
|
||||
end
|
||||
|
||||
function config_as_string()
|
||||
local conf_str = ""
|
||||
if type(config) ~= 'table' then return conf_str end
|
||||
table.sort(config)
|
||||
for i, j in pairsByKeys(config) do
|
||||
if type(j) == 'boolean' then
|
||||
if j == true then
|
||||
conf_str = conf_str .. i .. ' = true\n'
|
||||
else
|
||||
conf_str = conf_str .. i .. ' = false\n'
|
||||
end
|
||||
elseif type(j) == 'string' then
|
||||
conf_str = conf_str .. i .. ' = "' .. j .. '"\n'
|
||||
else
|
||||
conf_str = conf_str .. i .. ' = ' .. j .. '\n'
|
||||
end
|
||||
end
|
||||
return conf_str
|
||||
end
|
||||
|
||||
|
||||
print("-- CONFIG DUMP --")
|
||||
print(config_as_string())
|
||||
print("-- END OF CONFIG --")
|
||||
quit()
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
-- run it:
|
||||
-- ./lua_map_test $map_file scripts/map_test_blocktype.lua
|
||||
--
|
||||
-- may soon also work from within luaviewer
|
||||
|
||||
if rawget(_G, 'map') == nil then
|
||||
print("No map loaded!")
|
||||
os.exit()
|
||||
end
|
||||
|
||||
function block_type_name(t)
|
||||
if t == 0 then return "air" end
|
||||
if t == 1 then return "water" end
|
||||
if t == 2 then return "road" end
|
||||
if t == 3 then return "pavement" end
|
||||
if t == 4 then return "field" end
|
||||
if t == 5 then return "building" end
|
||||
if t == 6 then return "unused1" end
|
||||
if t == 7 then return "unused2" end
|
||||
return "????????"
|
||||
end
|
||||
|
||||
function find_all_of_type(t)
|
||||
list = {}
|
||||
for y = 0, 255 do
|
||||
for x = 0, 255 do
|
||||
c = map:getNumBlocksAt(x, y)
|
||||
for i = 0, c - 1 do
|
||||
info = map:getBlockAt(x, y, i)
|
||||
if info:getBlockType() == t then
|
||||
table.insert(list, { x, y, i })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
|
||||
function find_air_columns()
|
||||
for y = 0, 255 do
|
||||
for x = 0, 255 do
|
||||
c = map:getNumBlocksAt(x, y)
|
||||
is_air = true
|
||||
for i = 0, c - 1 do
|
||||
info = map:getBlockAt(x, y, i)
|
||||
if info:getBlockType() ~= 0 then
|
||||
is_air = false
|
||||
end
|
||||
end
|
||||
if is_air == true then
|
||||
for i = 0, c - 1 do
|
||||
info = map:getBlockAt(x, y, i)
|
||||
lid = info:getTextureId(0)
|
||||
if lid > 0 and i < 4 then
|
||||
print("Air-column: " .. x .. ", " .. y)
|
||||
print("Texture " .. lid .. " set at " .. i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function is_block_of_type(x, y, z, t)
|
||||
local c = map:getNumBlocksAt(x, y)
|
||||
assert(c > z)
|
||||
local info = map:getBlockAt(x, y, z)
|
||||
return info:getBlockType() == t
|
||||
end
|
||||
|
||||
--find_air_columns()
|
||||
|
||||
function find_block_holes()
|
||||
for y = 0, 255 do
|
||||
for x = 0, 255 do
|
||||
c = map:getNumBlocksAt(x, y)
|
||||
info = map:getBlockAt(x, y, c - 1)
|
||||
if info:getTextureId(0) > 0 and info:getBlockType() == 0 then
|
||||
print(x .. ", " .. y .. " has texture but no type above; level: " .. c - 1 ..
|
||||
" lid: " .. info:getTextureId(0))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
find_block_holes()
|
||||
|
||||
--num = map:getNumBlocksAt(25, 17)
|
||||
--for i = 0, num-1 do
|
||||
-- info = map:getBlockAt(25, 17, i)
|
||||
-- info:setBlockType(3)
|
||||
-- print(i)
|
||||
-- print("texture: " .. info:getTextureId(0))
|
||||
-- print("type: " .. info:getBlockType())
|
||||
--end
|
||||
@@ -0,0 +1,122 @@
|
||||
local n
|
||||
--definition_indices = {}
|
||||
--for n in pairs(definitions) do table.insert(definition_indices, n) end
|
||||
--table.sort(definition_indices)
|
||||
|
||||
command_indices = {}
|
||||
for n in pairs(commands) do table.insert(command_indices, n) end
|
||||
table.sort(command_indices)
|
||||
|
||||
function idx_by_gtaidx(gta_idx)
|
||||
local i
|
||||
for i = 1, #command_indices do
|
||||
if command_indices[i] == gta_idx then return i end
|
||||
end
|
||||
--error("Invalid gta-cmd-idx: " .. gta_idx)
|
||||
return -1
|
||||
end
|
||||
|
||||
-- from: http://lua-users.org/wiki/StringRecipes
|
||||
-- Compatibility: Lua-5.1
|
||||
function split(str, pat)
|
||||
local t = {} -- NOTE: use {n = 0} in Lua-5.0
|
||||
local fpat = "(.-)" .. pat
|
||||
local last_end = 1
|
||||
local s, e, cap = string.find(str, fpat, 1)
|
||||
while s do
|
||||
if s ~= 1 or cap ~= "" then
|
||||
table.insert(t,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = string.find(str, fpat, last_end)
|
||||
end
|
||||
if last_end <= string.len(str) then
|
||||
cap = string.sub(str, last_end)
|
||||
table.insert(t, cap)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function run_command(idx, cmd, params)
|
||||
local res = 0
|
||||
if cmd == "KICKSTART" then
|
||||
-- new_thread(idx, params[1])
|
||||
print("\tKICKSTART in " .. idx .. " from " .. params[1] .. " = " ..idx_by_gtaidx(params[1] + 0))
|
||||
new_thread(idx, idx_by_gtaidx(params[1] + 0))
|
||||
else
|
||||
print("\t" .. cmd .. " in line " .. idx)
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function iterate_commands(idx)
|
||||
local is_sleeping = false
|
||||
while idx <= #command_indices do
|
||||
local gta_idx = command_indices[idx]
|
||||
if is_sleeping == true then
|
||||
while true do
|
||||
print(" thread is sleeping in " .. gta_idx)
|
||||
coroutine.yield()
|
||||
end
|
||||
end
|
||||
--print("LINE " .. gta_idx)
|
||||
local cmd = commands[gta_idx]
|
||||
local cmd_split = split(cmd, " ")
|
||||
local cmd_name = cmd_split[1]
|
||||
--print(cmd)
|
||||
table.remove(cmd_split, 1)
|
||||
local ok_idx = cmd_split[2]
|
||||
local fail_idx = cmd_split[3]
|
||||
if idx == 1 then
|
||||
idx = idx + 1
|
||||
elseif idx > 1 then
|
||||
local next_idx = 0
|
||||
--print(" "..gta_idx .. " " .. cmd_name)
|
||||
if run_command(gta_idx, cmd_name, cmd_split) == 1 then
|
||||
next_idx = fail_idx + 0
|
||||
print(' failed '..fail_idx)
|
||||
else
|
||||
next_idx = ok_idx + 0
|
||||
print(' ok '..ok_idx)
|
||||
end
|
||||
if next_idx == 0 then
|
||||
idx = idx + 1
|
||||
elseif next_idx == -1 then
|
||||
if cmd_name == "CRANE" then idx = idx + 1
|
||||
else
|
||||
is_sleeping = true
|
||||
--error("EXIT: " .. next_idx)
|
||||
end
|
||||
else
|
||||
idx = idx_by_gtaidx(next_idx)
|
||||
end
|
||||
end
|
||||
coroutine.yield()
|
||||
print(' RESUMING2')
|
||||
end
|
||||
coroutine.yield()
|
||||
print(' RESUMING3')
|
||||
end
|
||||
|
||||
threads = {}
|
||||
thread_indices = {}
|
||||
function new_thread(t_id, start_at_idx)
|
||||
table.insert(threads, coroutine.create(function () iterate_commands(start_at_idx) end))
|
||||
print(" "..#threads .. " = " ..t_id)
|
||||
table.insert(thread_indices, t_id)
|
||||
end
|
||||
|
||||
|
||||
new_thread(0, 1)
|
||||
while #threads > 0 do
|
||||
for i, j in pairs(threads) do
|
||||
print("thread " .. thread_indices[i] .. " [" .. #threads .. "]")
|
||||
if coroutine.status(j) == "suspended" then
|
||||
coroutine.resume(j)
|
||||
elseif coroutine.status(j) == "dead" then
|
||||
table.remove(threads, i)
|
||||
table.remove(thread_indices, i)
|
||||
print("removing dead " .. i)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user