local Experiment = lib "class" ("Experiment") Experiment:include(mixin "_has" ("Started")) Experiment:include(mixin "_has" ("Function")) Experiment:include(mixin "_has" ("StartTime")) Experiment:include(mixin "_has" ("LogInterval")) Experiment:include(mixin "_has" ("Frame")) function Experiment:initialize() self.date = os.date() self.logger = (class "Logger"):new(self:getName() .. ".log.csv") self:setStarted(false) -- stop by default self:setLogInterval(0) end function Experiment:start() self:setStarted(true) self:setStartTime(lovr.timer.getTime()) self:setFrame(0) self.logTime = 0 end function Experiment:stop() self:setStarted(false) self.logger:getFile():flush() end function Experiment:getName() return "experiment-" .. self.date end function Experiment:update(dt) if self:getStarted() then -- update experiment self:setFrame(self:getFrame() + 1) self.logTime = self.logTime + dt if self.logTime >= self:getLogInterval() then self.logTime = self.logTime - self:getLogInterval() -- get all necessary values and print local f = self:getFunction() local values = f() self.logger:log(values) end end end return Experiment