Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7518 from Courseplay/DevXml
Browse files Browse the repository at this point in the history
Debug channel and dev setup changes.
  • Loading branch information
schwiti6190 authored Oct 10, 2021
2 parents f1e9c9c + f8be34e commit c516f06
Show file tree
Hide file tree
Showing 13 changed files with 317 additions and 231 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ reload/venv
reload.xml
.vscode


# Windows image file caches
Thumbs.db
ehthumbs.db
Expand Down
50 changes: 49 additions & 1 deletion CpManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,55 @@ addModEventListener(CpManager);

local modDirectory = g_currentModDirectory

--- Setups dev settings.
local function loadDevSetup()
local filePath = Utils.getFilename('config/DevSetup.xml', courseplay.path)
local xmlFile = loadXMLFile('devSetup', filePath)
local baseKey = "DevSetup"
CpManager.preDebugSetup = {
nameToChannel = {},
idToChannel = {}
}
CpManager.isDeveloper = false
if xmlFile then
CpManager.isDeveloper = Utils.getNoNil(getXMLBool(xmlFile,baseKey.."#isDev"),false)
if CpManager.isDeveloper then
print('Special dev magic for Courseplay developer unlocked. You go, girl!');
end

--- Checks if any debug channel should be active immediately.
baseKey = string.format("%s.%s",baseKey,"DebugChannels")
if hasXMLProperty(xmlFile, baseKey) then
CpManager.preDebugSetup = {
nameToChannel = {},
idToChannel = {}
}
local i = 0
while true do
local key = string.format("%s.%s(%d)",baseKey,"DebugChannel",i)
if not hasXMLProperty(xmlFile, key) then
break
end
local id = getXMLInt(xmlFile, key.."#id")
local name = getXMLString(xmlFile, key.."#name")
local active = getXMLBool(xmlFile, key)
if id then
CpManager.preDebugSetup.idToChannel[id] = active
end
if name then
CpManager.preDebugSetup.nameToChannel[name] = active
end
i = i + 1
if active then
print(string.format("Debug channel id: %s, name: %s is activated for dev.",tostring(id),tostring(name)))
end
end
end
delete(xmlFile)
end
end
loadDevSetup()

function CpManager:loadMap(name)
--print("CpManager:loadMap(name)")
self.isCourseplayManager = true;
Expand Down Expand Up @@ -54,7 +103,6 @@ function CpManager:loadMap(name)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- SETUP (continued)
courseplay.hud:setup(); -- NOTE: hud has to be set up after the xml settings have been loaded, as almost all its values are based on basePosX/Y
self:setUpDebugChannels(); -- NOTE: debugChannels have to be set up after the hud, as they rely on some hud values [positioning]
g_globalInfoTextHandler:setup() -- NOTE: globalInfoText has to be set up after the hud, as they rely on some hud values [colors, function]
courseplay.courses:setup(); -- NOTE: load the courses and folders from the XML
self:setup2dCourseData(true); -- NOTE: setup2dCourseData is called a second time, now we actually create the data and overlays
Expand Down
27 changes: 14 additions & 13 deletions Events/SettingEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ end

--- Reads the serialized data on the receiving end of the event.
function SettingEvent:readStream(streamId, connection) -- wird aufgerufen wenn mich ein Event erreicht

self.parentName = streamReadString(streamId)
self.name = streamReadString(streamId)
self.eventIx = streamReadUInt8(streamId)
self.debug("Parent name: %s, Setting name: %s, eventIx: %d",self.parentName, self.name,self.eventIx)
self.vehicle = nil
if streamReadBool(streamId) then
self.vehicle = NetworkUtil.getObject(streamReadInt32(streamId))
self.debugVehicle(self.vehicle,"Vehicle setting")
self.setting,self.eventData = self.encodeEventData(self.vehicle,self.parentName,self.name,self.eventIx)
else
self.debug("Global setting")
self.setting,self.eventData = self.encodeEventData(nil,self.parentName,self.name,self.eventIx)
end

self.parentName = streamReadString(streamId)
self.name = streamReadString(streamId)
self.eventIx = streamReadUInt8(streamId)

self.setting,self.eventData = self.encodeEventData(self.vehicle,self.parentName,self.name,self.eventIx)

if self.eventData.readFunc then
self.value = self.eventData.readFunc(streamId)
end
Expand All @@ -58,6 +59,10 @@ end
--- Writes the serialized data from the sender.
function SettingEvent:writeStream(streamId, connection) -- Wird aufgrufen wenn ich ein event verschicke (merke: reihenfolge der Daten muss mit der bei readStream uebereinstimmen
self.debug("SettingEvent:writeStream()")
streamWriteString(streamId, self.parentName)
streamWriteString(streamId, self.name)
streamWriteUInt8(streamId,self.eventIx)
self.debug("Parent name: %s, Setting name: %s, value: %s, eventIx: %d",self.parentName, self.name, tostring(self.value),self.eventIx)
if self.vehicle ~= nil then
self.debugVehicle(self.vehicle,"Vehicle setting")
streamWriteBool(streamId, true)
Expand All @@ -66,10 +71,6 @@ function SettingEvent:writeStream(streamId, connection) -- Wird aufgrufen wenn
self.debug("Global setting")
streamWriteBool(streamId, false)
end
self.debug("Parent name: %s, Setting name: %s, value: %s, eventIx: %d",self.parentName, self.name, tostring(self.value),self.eventIx)
streamWriteString(streamId, self.parentName)
streamWriteString(streamId, self.name)
streamWriteUInt8(streamId,self.eventIx)
if self.writeFunc then
self.writeFunc(streamId, self.value)
end
Expand All @@ -84,7 +85,7 @@ function SettingEvent:run(connection) -- wir fuehren das empfangene event aus
if not connection:getIsServer() then
self.debug("Send SettingEvent to clients")
g_server:broadcastEvent(SettingEvent:new(self.vehicle,self.setting,self.eventData,self.value), nil, connection, self.vehicle)
end;
end
end

--- Sends an Event either:
Expand Down Expand Up @@ -132,10 +133,10 @@ end
---@param eventIx number Event number received
function SettingEvent.encodeEventData(vehicle,parentName,settingName,eventIx)
local setting
if vehicle then
if vehicle ~= nil then
setting = vehicle.cp[parentName][settingName]
else
setting = courseplay.globalSettings[parentName][settingName]
setting = courseplay[parentName][settingName]
end
return setting,setting:getEvent(eventIx)
end
120 changes: 119 additions & 1 deletion GlobalSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,122 @@ function ShowMapHotspotSetting:getMapHotspotText(vehicle)
text = string.format("%s%s\n%s",text,nameNum(vehicle, true),vehicle.cp.currentCourseName or courseplay:loc('COURSEPLAY_TEMP_COURSE'))
end
return text
end
end


--- This Setting handles all debug channels.
--- For each debug channel is a code short cut created,
--- for example: DebugChannelsSetting.DBG_MODE_3.
--- This is defined in the debug config xml file.
--- For backwards compatibility are all
--- courseplay.debugChannels[ix] or courseplay["DBG_MODE_3"] calls still valid.
---@class DebugChannelsSetting : Setting
DebugChannelsSetting = CpObject(Setting)
function DebugChannelsSetting:init()
Setting.init(self,"debugChannels")
self.xmlFilePath = Utils.getFilename('config/DebugChannels.xml', courseplay.path)
self:load(self.xmlFilePath)
self.DEFAULT_EVENT = self:registerIntEvent(self.setFromNetwork)
end

function DebugChannelsSetting:load(xmlFilePath)
local xmlFile = loadXMLFile('debugChannels', xmlFilePath)
local baseKey = "DebugChannels"
self.channels = {}
self.numChannels = 0
self.toolTips = {}
if xmlFile and hasXMLProperty(xmlFile, baseKey) then
local i = 0
while true do
local key = string.format("%s.%s(%d)",baseKey,"DebugChannel",i)
if not hasXMLProperty(xmlFile, key) then
break
end
local text = getXMLString(xmlFile, key.."#text")
local name = getXMLString(xmlFile, key.."#name")
local active = getXMLBool(xmlFile, key.."#active")
i = i + 1
self[name] = i
courseplay[name] = i --- Old code
self.toolTips[i] = text

--- Evaluate pre debug setups from the DevSetup xml file.
--- Also make sure active ~= nil.
active = Utils.getNoNil(active or
CpManager.preDebugSetup.nameToChannel[name] or
CpManager.preDebugSetup.idToChannel[i]
,false)

self.channels[i] = active
if active then
print(string.format("Debug channel id: %s, name: %s is activated.",tostring(i),tostring(name)))
end
end
self.numChannels = i
delete(xmlFile)
end
courseplay.debugChannels = self.channels --- Old code
end

function DebugChannelsSetting:onWriteStream(streamID)
for ix,value in ipairs(self.channels) do
streamWriteBool(streamID,value)
end
end

function DebugChannelsSetting:onReadStream(streamID)
for ix,_ in ipairs(self.channels) do
self.channels[ix] = streamReadBool(streamID)
end
end

function DebugChannelsSetting:toggleChannel(ix,noEventSend)
self:set(ix,not self.channels[ix],noEventSend)
end

function DebugChannelsSetting:set(ix,value,noEventSend)
self.channels[ix] = value
if noEventSend == nil or noEventSend == false then
self:sendEvent(ix)
end
self:onChange()
end

function DebugChannelsSetting:get()
return self.channels
end

function DebugChannelsSetting:getNumberOfChannels()
return self.numChannels
end

function DebugChannelsSetting:getToolTips()
return self.toolTips
end

function DebugChannelsSetting:sendEvent(ix)
self:raiseEvent(self.DEFAULT_EVENT,ix)
end

function DebugChannelsSetting:setFromNetwork(ix)
self:toggleChannel(ix,true)
end

function DebugChannelsSetting:isActive(ix)
return self.channels[ix]
end

function SettingsContainer.createGlobalSettings()
local container = SettingsContainer("globalSettings")
container:addSetting(DebugChannelsSetting)
container:addSetting(LoadCoursesAtStartupSetting)
container:addSetting(AutoFieldScanSetting)
container:addSetting(WorkerWagesSetting)
container:addSetting(ClickToSwitchSetting)
container:addSetting(ShowMiniHudSetting)
container:addSetting(EnableOpenHudWithMouseGlobalSetting)
container:addSetting(AutoRepairSetting)
container:addSetting(ShowMapHotspotSetting)
container:addSetting(ShowActionEventTextsSetting)
return container
end
6 changes: 0 additions & 6 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,6 @@ function courseplay:onReadStream(streamId, connection)
-- SETUP 2D COURSE DRAW DATA
self.cp.course2dUpdateDrawData = true;

local debugChannelsString = streamReadString(streamId)
for k,v in pairs(StringUtil.splitString(",", debugChannelsString)) do
courseplay:toggleDebugChannel(self, k, v == 'true');
end;

if streamReadBool(streamId) then
self.cp.timeRemaining = streamReadFloat32(streamId)
Expand Down Expand Up @@ -768,8 +764,6 @@ function courseplay:onWriteStream(streamId, connection)
end
end

local debugChannelsString = table.concat(table.map(courseplay.debugChannels, tostring), ",");
streamWriteString(streamId, debugChannelsString)

if self.cp.timeRemaining then
streamWriteBool(streamId,true)
Expand Down
4 changes: 0 additions & 4 deletions button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ function courseplay.button:setSpecialButtonUVs()

elseif fn == 'generateCourse' then
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.pageButtonsUVsPx[courseplay.hud.PAGE_COURSE_GENERATION], txtSizeX, txtSizeY);

elseif fn == 'toggleDebugChannel' then
self:setSpriteSectionUVs('recordingStop');

-- CpManager buttons
elseif fn == 'goToVehicle' then
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.pageButtonsUVsPx[courseplay.hud.PAGE_DRIVING_SETTINGS], txtSizeX, txtSizeY);
Expand Down
35 changes: 35 additions & 0 deletions config/DebugChannels.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!--
This is the debug setup file.
All debug channel setup can be changed here.
active : can be changed to enable it on startup.
name : corresponds to the call name, for example courseplay.DBG_MODE_1.
text : is the tooltip shown in the hud.
-->
<DebugChannels>
<DebugChannel active="false" name="DBG_MODE_1" text="Debug: mode 1 - grain transport"/>
<DebugChannel active="false" name="DBG_MODE_2" text="Debug: mode 2 - unload combine"/>
<DebugChannel active="false" name="DBG_MODE_3" text="Debug: mode 3 - overloader"/>
<DebugChannel active="false" name="DBG_MODE_4" text="Debug: mode 4 - fertilizing and seeding"/>
<DebugChannel active="false" name="DBG_MODE_5" text="Debug: mode 5 - transport"/>
<DebugChannel active="false" name="DBG_MODE_6" text="Debug: mode 6 - fieldwork"/>
<DebugChannel active="false" name="DBG_MODE_7" text="Debug: mode 7 - bale collector"/>
<DebugChannel active="false" name="DBG_MODE_8" text="Debug: mode 8 - field supply"/>
<DebugChannel active="false" name="DBG_MODE_9" text="Debug: mode 9 - shovel fill/empty"/>
<DebugChannel active="false" name="DBG_MODE_10" text="Debug: mode 10 - bunker silo compacter"/>
<DebugChannel active="false" name="DBG_PATHFINDER" text="Debug: pathfinder"/>
<DebugChannel active="false" name="DBG_TRIGGERS" text="Debug: triggers"/>
<DebugChannel active="false" name="DBG_REVERSE" text="Debug: reverse driving"/>
<DebugChannel active="false" name="DBG_TURN" text="Debug: turns"/>
<DebugChannel active="false" name="DBG_PPC" text="Debug: pure pursuit controller"/>
<DebugChannel active="false" name="DBG_LOAD_UNLOAD" text="Debug: load and unload tippers"/>
<DebugChannel active="false" name="DBG_TRAFFIC" text="Debug: traffic collision/proximity"/>
<DebugChannel active="false" name="DBG_HUD" text="Debug: hud action"/>
<DebugChannel active="false" name="DBG_COURSES" text="Debug: course save/load/generation"/>
<DebugChannel active="false" name="DBG_MULTIPLAYER" text="Debug: multiplayer"/>
<DebugChannel active="false" name="DBG_IMPLEMENTS" text="Debug: implements"/>
<DebugChannel active="false" name="DBG_UNCATEGORIZED" text="Debug: other"/>
<DebugChannel active="false" name="DBG_AI_DRIVER" text="Debug: AIDriver common"/>
<!-- this is to prevent spamming the log if not necessary (e.g. raycasts)-->
<DebugChannel active="false" name="DBG_CYCLIC" text="Debug: activate cyclic prints"/>
</DebugChannels>
15 changes: 15 additions & 0 deletions config/DevSetup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!--
This is a dev setup file, where individual setup can be applied.
The isDeveloper state can be set with "isDev = true".
For example custom debug channel setups can be set on startup.
id : is the debug channel number 1-24.
name : corresponds to the call name, for example courseplay.DBG_MODE_1.
-->

<DevSetup isDev = "false">
<DebugChannels>
<DebugChannel id="1">false</DebugChannel>
<DebugChannel name="DBG_MODE_2">false</DebugChannel>
</DebugChannels>
</DevSetup>
18 changes: 0 additions & 18 deletions courseplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ courseplay.generation = {};
courseplay.lights = {};
courseplay.clock = 0;

local sonOfaBangSonOfaBoom = {
['56bb4a8d3f72d5a31aee0c317302dde5'] = true; -- Thomas
['9a9f028043394ff9de1cf6c905b515c1'] = true; -- Satis
['3e701b6620453edcd4c170543e72788b'] = true; -- Peter
['0d8e45a8ed916c1cd40820165b81e12d'] = true; -- Tensuko
['97c8e6d0d14f4e242c3c37af68cc376c'] = true; -- Dan
['8f5e9e8fb5a23375afbb3b7abbc6335c'] = true; -- Goof
};

local function initialize()
local fileList = {
'CpObject',
Expand Down Expand Up @@ -265,15 +256,6 @@ setVersionData();

initialize();

CpManager.isDeveloper = sonOfaBangSonOfaBoom[getMD5(g_gameSettings:getValue("nickname"))];

if CpManager.isDeveloper then
print('Special dev magic for Courseplay developer unlocked. You go, girl!');
else
--print('No cookies for you! (please wait until we have some limited form of a working version...)');
--courseplay.houstonWeGotAProblem = true;
--return;
end;

courseplay.inputBindings.updateInputButtonData();

Expand Down
Loading

0 comments on commit c516f06

Please sign in to comment.