Skip to content

Commit

Permalink
add debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Jul 31, 2024
1 parent 36f98c9 commit f52bf85
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion newmodels_reborn/core/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ local function setElementResource(element, theResource)
end
end

local function getBaseModelIdFromCustomModelId(id)
function getBaseModelIdFromCustomModelId(id)
local customInfo = customModels[id]
if customInfo then
return customInfo.baseModel
Expand Down
1 change: 1 addition & 0 deletions newmodels_reborn/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<export function="setPickupType" type="shared"/>
<export function="setElementModel" type="shared"/>
<export function="getElementModel" type="shared"/>
<export function="getBaseModelIdFromCustomModelId" type="shared"/>
<export function="getLoadedModels" type="client"/>

<!-- Files -->
Expand Down
41 changes: 39 additions & 2 deletions newmodels_reborn/optional/c_testing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local SW = guiGetScreenSize()

local debugTimer = nil
local drawStr = ""
local streamedElements = {}

local function getElementInfoStr(element, level)
local spaces = string.rep("----- ", level)
Expand Down Expand Up @@ -41,7 +42,21 @@ local function pairsByKeys(t)
return iter
end

local function updateDebugStr()
local function getElementCustomModelString(element)
local customModel = tonumber(getElementData(element, getCustomModelDataKey("vehicle")))
if customModel and customModels[customModel] then
local name, baseModel = customModels[customModel].name, customModels[customModel].baseModel
if name then
return ("%d \"%s\" (%d)"):format(customModel, name, baseModel)
else
return ("%d (%d)"):format(customModel, baseModel)
end
else
return ("%d"):format(getElementModel(element))
end
end

local function updateDebugViewInfo()
local loadedModelsStr = ""
for customModel, v in pairsByKeys(loadedModels) do
local str
Expand All @@ -57,15 +72,37 @@ local function updateDebugStr()
if loadedModelsStr ~= "" then
drawStr = "Loaded models:\n" .. loadedModelsStr .. "\n\n" .. drawStr
end

streamedElements = {}
for _, element in pairs(getElementsByType("vehicle", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
for _, element in pairs(getElementsByType("object", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
for _, element in pairs(getElementsByType("ped", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
for _, element in pairs(getElementsByType("player", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
end

local function drawDebug()
dxDrawText(drawStr, SW/2, 30, SW, 0, 0xFFFFFFFF, 1, "default-bold")

for element, customModelStr in pairs(streamedElements) do
local x, y, z = getElementPosition(element)
local sx, sy = getScreenFromWorldPosition(x, y, z + 0.5)
if sx and sy then
dxDrawText(customModelStr, sx, sy, 0, 0, 0xFFFFFFFF, 1, "default")
end
end
end

local function toggleDebugView(cmd)
if not enabled then
if not (debugTimer) or (not isTimer(debugTimer)) then debugTimer = setTimer(updateDebugStr, 1000, 0) end
if not (debugTimer) or (not isTimer(debugTimer)) then debugTimer = setTimer(updateDebugViewInfo, 1000, 0) end
addEventHandler("onClientRender", root, drawDebug, false)
else
if debugTimer and isTimer(debugTimer) then killTimer(debugTimer); debugTimer = nil end
Expand Down
Binary file added ss1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f52bf85

Please sign in to comment.