View previous topic :: View next topic |
Author |
Message |
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Sun Apr 10, 2022 4:45 pm Post subject: large loop - Not responding |
|
|
hi, sorry for my bad English again
I creating a tile-set map editor,
I have no problem when the map is relatively small like 4x4,
but when I attempt medium or large like 35x35 = 1225 tiles,
the program hangs about 700-800/ 1225 for 3-10 seconds
I tried to add sleep code, but the program run longer and the not responding still happens, any idea?
Code: | k = 0
for i = 0, 35, 1 do
for j = 0, 35, 1 do
k = k + 1
form1.Caption = "Loading " .. k .. " / " .. 35 * 35
sleep(100)
--[[
do creating stuff here
--]]
end
end |
|
|
Back to top |
|
|
Csimbi I post too much Reputation: 94
Joined: 14 Jul 2007 Posts: 3110
|
Posted: Sun Apr 10, 2022 5:12 pm Post subject: |
|
|
The loops look okay.
It must be something in your code deeper down (lots of heavy lifting that take a while?).
You could try running this in a separate thread.
|
|
Back to top |
|
|
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Sun Apr 10, 2022 5:47 pm Post subject: |
|
|
Q:It must be something in your code deeper down (lots of heavy lifting that take a while?)
A:this is the code:
Code: | MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(250, 250)
form1.Position = "poScreenCenter"
k = 0
-- 5x5 table
for i = 0 ,4, 1 do
for j = 0 ,4, 1 do
k = k + 1
MapTiles[k] = createImage(form1)
MapTiles[k].Picture.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
MapTiles[k].Height = 50
MapTiles[k].width = 50
MapTiles[k].top = i * MapTiles[k].Height
MapTiles[k].left = j * MapTiles[k].width
MapTiles[k].stretch = true
MapTiles[k].ShowHint = true
MapTiles[k].Hint = i + 1 .. ":" .. j + 1
end
end
form1.Caption = k .. " tiles" |
Q:You could try running this in a separate thread.
A:how?
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Sun Apr 10, 2022 10:25 pm Post subject: |
|
|
add processMessages() in the loop.
also, instead of multiple images on the form i recommend a single image that only updates when an image changes (and only that one spot
that way you can use createPicture instead of createImage so you can use threads
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Mon Apr 11, 2022 1:34 am Post subject: |
|
|
thank you Dark Byte for the reply,
the processMessages() work flawlessly,
but about createPicture() I still don't get it,
it seems createPicture() do not have width property : attempt to perform arithmetic on a nil value (field 'width')
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1253
|
Posted: Mon Apr 11, 2022 2:36 pm Post subject: |
|
|
An example;
Code: | MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(250, 250)
form1.Position = "poScreenCenter"
function crtPic(url)
int = getInternet()
local logostr=int.getURL(url)
int.destroy ()
local ss=createStringStream(logostr)
i3=createPicture()
i3.loadFromStream(ss)
ss.destroy()
return i3
end
pic1=crtPic("https://i.ibb.co/ZYqHBBF/ce-logo-770.png")
k = 0
-- 5x5 table
for i = 0 ,4, 1 do
for j = 0 ,4, 1 do
k = k + 1
MapTiles[k] = createImage(form1)
MapTiles[k].Picture=pic1 --.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
MapTiles[k].Height = 50
MapTiles[k].width = 50
MapTiles[k].top = i * MapTiles[k].Height
MapTiles[k].left = j * MapTiles[k].width
MapTiles[k].stretch = true
MapTiles[k].ShowHint = true
MapTiles[k].Hint = i + 1 .. ":" .. j + 1
end
end
form1.Caption = k .. " tiles" |
in your case
An example;
Code: | MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(250, 250)
form1.Position = "poScreenCenter"
function crtPic(name)
i3=createPicture()
i3.loadFromStream(findTableFile(name).stream)
return i3
end
pic1=crtPic("Block_QM.png")
k = 0
-- 5x5 table
for i = 0 ,4, 1 do
for j = 0 ,4, 1 do
k = k + 1
MapTiles[k] = createImage(form1)
MapTiles[k].Picture=pic1 --.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
MapTiles[k].Height = 50
MapTiles[k].width = 50
MapTiles[k].top = i * MapTiles[k].Height
MapTiles[k].left = j * MapTiles[k].width
MapTiles[k].stretch = true
MapTiles[k].ShowHint = true
MapTiles[k].Hint = i + 1 .. ":" .. j + 1
end
end
form1.Caption = k .. " tiles" |
_________________
|
|
Back to top |
|
|
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Tue Apr 12, 2022 3:37 am Post subject: |
|
|
sorry for the late reply,
I tried your code, it seems the result is relative the same between createPicture() vs createImage(),
the dark byte mention using "threads", is there any step to activate it?
and thank you again for your reply
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1253
|
Posted: Tue Apr 12, 2022 5:23 am Post subject: |
|
|
Maybe it can give some idea.
Code: | MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(875, 875)
form1.Position = "poScreenCenter"
form1.visible = false
function crtPic(name)
i3=createPicture()
i3.loadFromStream(findTableFile(name).stream)
return i3
end
pic1=crtPic("aylinCE.png")
i = 0
j = 0
k = 0
l = 0
m = 35 * 35 + 1
n = 0
-- 35x35 table
function crtImg1()
while true do
if i~=m then
i = i + 1
j = j + 1
k = k + 1
MapTiles[k] = createImage(form1)
MapTiles[k].Picture=pic1 --.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
MapTiles[k].Height = 25
MapTiles[k].width = 25
if j==36 then l = l + 25 j = 0 n = 0 end
MapTiles[k].top = l
MapTiles[k].left = n
n = n + 25
MapTiles[k].stretch = true
MapTiles[k].ShowHint = true
MapTiles[k].Hint = i .. ":" .. j + 1
else
form1.visible = true
return false
end
form1.Caption = k .. " tiles"
end
end
createNativeThread(crtImg1) |
Description: |
|
Filesize: |
47.46 KB |
Viewed: |
1745 Time(s) |
|
_________________
|
|
Back to top |
|
|
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Tue Apr 12, 2022 5:35 am Post subject: |
|
|
I expect it will be fast, but instantaneous, I don't expect that,
thank you thank you thank you
|
|
Back to top |
|
|
|