Jump to content

Recommended Posts

Posted
-- Loading Barr Progress Map.
-- Yue Rexie
-- Engine LeadWerks


ventana = Window:Create("Test",0,0, 800,600, Window.Titlebar + Window.Center )
lienzo  = Context:Create( ventana )
 

fuente = Font:Load("Fonts/space age.ttf",24)
lienzo:SetFont(fuente)
mundo = World:Create()

local x = 0
mapa = 0

co = coroutine.create(function () 


mapa = Map:Load("Maps/start.map") 


end)


while x <= 199 do

	-- Salir.
	if ventana:Closed() then return false end 
	if ventana:KeyHit(Key.Escape ) then return false end 

	x = x + 1

	if x == 150 then 
		
		coroutine.resume(co)

	end 
	 lienzo:SetBlendMode(Blend.Alpha)
	 lienzo:SetColor(1,1,1)
	lienzo:DrawText("LOADING", lienzo:GetWidth()/2-fuente:GetTextWidth("LOADING")/2, lienzo:GetHeight()-75 )
	
	 lienzo:DrawRect(lienzo:GetWidth()/2-100, lienzo:GetHeight()-50, x, 25)
	 lienzo:SetColor(0.5,0.5,0.5)
	 lienzo:DrawRect(lienzo:GetWidth()/2-100, lienzo:GetHeight()-50,200, 25, 1 )
	 lienzo:Sync()


end 




while true do

	if ventana:Closed() then return false end 
	if ventana:KeyHit(Key.Escape ) then return false end 
	
    Time:Update()
	mundo:Update()
	mundo:Render()
	
	
	lienzo:Sync()

end 

 

Loading.png

  • Upvote 2

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Posted

Im confused. Is this a fake loading bar? As far as I know Map:Load() is blocking as it loads the map from file. Why put it in the coroutine function?

Posted

Hi, Rick.
 

If it is a false load bar, because I understand that in Lua you can not work with threads.

When a certain percentage is reached, the map is loaded and while the load is being loaded the progress bar is paused, and then continues its animation.

I put it in a coroutine, because when the coroutine is loaded, it goes to a dead state and it does not run any more. I would like to find another alternative, but I see no other more feasible.

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

  • 1 month later...
Posted

If you tried this on a mechanical disk and also a SSD would the results vary a lot do you think? I think the SSD may load before 100% complete or the mechanical may say 100% for some time I think. I suppose you could first do a quick estimate of I/O speed by reading a small test file in and then adjusting the timer accordingly to better guess when 100% might hit.

Maybe with a larger map you might want something more like a spinner where you are not saying how much is loaded but rather that loading is taking place?

Neat example.  Never tried co-routines but they seem like a nice easy way to get a simple loading screen going.  Thanks!

 

Posted

@mdgunn, I posted this in another thread but you can just pre-load all the models (trees, rocks, grass, etc.) yourself and show the progress bar at that time.  Then, when you load the map, it should load very quickly since all of the models are already loaded and in memory.  Not to take anything away from Yue's work; I can't speak to it as I haven't tried it.  This is just another option.

  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...