SystemMap = class("SystemMap")

function SystemMap:onNew(world)
	self.ents = {}
	self.world = world
end

function SystemMap:ent_added()
	assert(false)
end

function SystemMap:ent_removed()
	assert(false)
end

function SystemMap:add_ent(ent)
	assert(not self.ents[ent], "already here")
	self.ents[ent] = true
	self:ent_added(ent)
end

function SystemMap:has_ent(ent)
	return self.ents[ent] ~= nil
end

function SystemMap:remove_all_ents()
	for ent,_ in pairs(self.ents) do
		self.ents[ent] = nil
		self:ent_removed(ent)		
	end
end

function SystemMap:remove_ent(ent)
	assert(self.ents[ent], "already removed")
	self.ents[ent] = nil
	self:ent_removed(ent)	
end




SystemLinear = class("SystemLinear")

function SystemLinear:onNew(world)
	self.ents = {}
	self.world = world
end

function SystemLinear:ent_added()
	assert(false)
end

function SystemLinear:ent_removed()
	assert(false)
end

function SystemLinear:add_ent(ent)
	table.insert(self.ents, ent)
	self:ent_added(ent)
end

function SystemLinear:has_ent(ent)
	for index, cur_ent in pairs(self.ents) do
		if cur_ent == ent then
			return true
		end
	end
end


function SystemLinear:remove_all_ents()
	local n = #self.ents
	local ent = self.ents[n]
	while ent do
		table.remove(self.ents, n)
		self:ent_removed(ent)
		n = n - 1
		ent = self.ents[n]
	end
end

function SystemLinear:remove_ent(ent)
	for index, cur_ent in pairs(self.ents) do
		if cur_ent == ent then
			table.remove(self.ents, index)
			break
		end
	end
end
