summaryrefslogtreecommitdiff
path: root/src/log.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-02-27 18:05:29 -0500
committerShadowNinja <shadowninja@minetest.net>2015-03-27 15:00:48 -0400
commit93fcab952b28f4db39d9326b83f14cbd86c0cf17 (patch)
tree4a2f0fcf7341c596f50ec24ff0a5a81d43d17ccd /src/log.cpp
parent284fefb0c32e8222fadd78eeec6e7e718fe25668 (diff)
downloadminetest-93fcab952b28f4db39d9326b83f14cbd86c0cf17.tar.gz
minetest-93fcab952b28f4db39d9326b83f14cbd86c0cf17.tar.bz2
minetest-93fcab952b28f4db39d9326b83f14cbd86c0cf17.zip
Clean up and tweak build system
* Combine client and server man pages. * Update unit test options and available databases in man page. * Add `--worldname` to man page. * Fix a bunch of places where `"Minetest"` was used directly instead of `PROJECT_NAME`. * Disable server build by default on all operating systems. * Make `ENABLE_FREETYPE` not fail if FreeType isn't found. * Enable LevelDB, Redis, and FreeType detection by default. * Remove the `VERSION_PATCH_ORIG` hack. * Add option to search for and use system JSONCPP. * Remove broken LuaJIT version detection. * Rename `DISABLE_LUAJIT` to `ENABLE_LUAJIT`. * Rename `minetest_*` variables in `version.{h,cpp}` to `g_*`. * Clean up style of CMake files.
Diffstat (limited to 'src/log.cpp')
0 files changed, 0 insertions, 0 deletions
30'>130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
-- train_related.lua
-- Occupation of track sections - mainly implementation of train callbacks

--[[
Track section occupation is saved as follows

In train:
train.il_sections = {
	[n] = {ts_id = <...> (origin = <sigd>)}
}
-- "origin" is the TCB (signal describer) the train initially entered this section

In track section
ts.trains = {
	[n] = <train_id>
}

When any inconsistency is detected, we will assume the most restrictive setup.
It will be possible to indicate a section "free" via the GUI.
]]

local ildb = advtrains.interlocking.db

local sigd_equal = advtrains.interlocking.sigd_equal

local function itexist(tbl, com)
	for _,item in ipairs(tbl) do
		if (item==com) then
			return true
		end
	end
	return false
end
local function itkexist(tbl, ikey, com)
	for _,item in ipairs(tbl) do
		if item[ikey] == com then
			return true
		end
	end
	return false
end

local function itremove(tbl, com)
	local i=1
	while i <= #tbl do
		if tbl[i] == com then
			table.remove(tbl, i)
		else
			i = i + 1
		end
	end
end
local function itkremove(tbl, ikey, com)
	local i=1
	while i <= #tbl do
		if tbl[i][ikey] == com then
			table.remove(tbl, i)
		else
			i = i + 1
		end
	end
end

local function setsection(tid, train, ts_id, ts, sigd)
	-- train
	if not train.il_sections then train.il_sections = {} end
	if not itkexist(train.il_sections, "ts_id", ts_id) then
		table.insert(train.il_sections, {ts_id = ts_id, origin = sigd})
	end
	
	-- ts
	if not ts.trains then ts.trains = {} end
	if not itexist(ts.trains, tid) then
		table.insert(ts.trains, tid)
	end
	
	-- routes
	local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
	
	-- route setting - clear route state
	if ts.route then
		--atdebug(tid,"enters",ts_id,"examining Routestate",ts.route)
		if not sigd_equal(ts.route.entry, sigd) then
			-- Train entered not from the route. Locate origin and cancel route!
			atwarn("Train",tid,"hit route",ts.route.rsn,"!")
			advtrains.interlocking.route.cancel_route_from(ts.route.origin)
			atwarn("Route was cancelled.")
		else
			-- train entered route regularily. Reset route and signal
			tcbs.route_committed = nil
			tcbs.route_comitted = nil -- TODO compatibility cleanup
			tcbs.aspect = nil
			tcbs.route_origin = nil
			advtrains.interlocking.update_signal_aspect(tcbs)
			if tcbs.signal and sigd_equal(ts.route.entry, ts.route.origin) then
				if tcbs.route_auto and tcbs.routeset then
					--atdebug("Resetting route (",ts.route.origin,")")
					advtrains.interlocking.route.update_route(ts.route.origin, tcbs)
				else
					tcbs.routeset = nil
				end
			end
		end
		ts.route = nil
	end
	if tcbs.signal then
		advtrains.interlocking.route.update_route(sigd, tcbs)
	end
end

local function freesection(tid, train, ts_id, ts)
	-- train
	if not train.il_sections then train.il_sections = {} end
	itkremove(train.il_sections, "ts_id", ts_id)
	
	-- ts