showing text really slow

Windows specific forum
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

showing text really slow

Post by Brujah »

In my game I have a screen that displays a lot of text.
In linux it works fine but in windows its painfully slow. Some users complain that the mouse is laggy because of that.
Could it be that in windows the routine draws real ttf characters which is slower than the system font that is used in linux?
Is there a way I could speed that up?
I use drawtext to write to the screen.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: showing text really slow

Post by Fluid Byte »

Code please
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: showing text really slow

Post by TomS »

Create a Sprite, draw the text on on it, then display the sprite.
Should be much, much faster that way.
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: showing text really slow

Post by Brujah »

the code you can get here from the subversion dir.
you have to load laby.pb and compile it.

http://sourceforge.net/projects/lostlaby/

the screen that makes problems is named: skills.pbi
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: showing text really slow

Post by TomS »

Try to make a small snippet for us that shows your problem.
First it's easier for us to answer.
Second you may come across the solution yourself in the process.

If you are drawing directly on the screen, use a sprite, as I suggested.
The 2D-Drawing lib is known to be quite slow (compared to sprites).
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: showing text really slow

Post by #NULL »

after adapting a dozens of repeated joystick-commands to my pb version (why don't you code things once only? put it inside a procedure..) i could compile it but the exe just finishes without telling me anything, so i have no chance to get a running skills-screen.

that screen has a lot of text, but i'm not convinced it is enough text for drawtext to cause mouse lagging. i had a qick test (on win xp) with 4000 sinlge characters of 'Arial.ttf' drawn to screen and the mouse is moving fine.
you are using some Delay() commands which could - even as Delay(1) - do very different on windows than they do on linux.

<edit>
- the 'lostlabyrinth_4.2.0.zip' from sourceforge doesn't contain any sourcecode.
- the code from http://www.lostlabyrinth.com/index.php?p=download needs 'sounds.pak' and 'graphics.pak' which are not present in the other packages from that dev-section on that side.
and finally the *.pak files from the sourceforge package do not work with that code..

:arrow: difficult to help you :lol:
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: showing text really slow

Post by Brujah »

That problem with the joystick is caused by an old compiler- We are still stuck on 4.20.
I just updated the svn so all joystick calls are in one procedure now.
Which is in other_procs.pbi. So it can be adapted to new joystick call very easily.

Easiest is to use the code from subversion. As its the newest and everything is contained in there.

The graphics.pak und sounds.pak is different for windows and linux.
So to make it work in windows you just have to switch into the Tools directory and run PackerGraphics.pb and PackerSound.pb
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: showing text really slow

Post by #NULL »

i found the svn download now, but still i can't get it to run. there are even syntax errors (missing first parameter for calls of draw_tile() ) after some doing i could compile it with pb451 but there's only a black fullscreen and i have to kill it. with pb420 (from the purebasic.com museum) it's even worse (many missing definitions of procedures, constants and whatnot ect.)
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: showing text really slow

Post by Brujah »

Try to create an executable and then run that.
Maybe its not possible to compile/run it.
Why you get compiler errors I can't really say. I have pb 4.20 installed here on Win XP and can compile the game without errors.

You have to start with laby.pb. This file defines and includes everything else.
Guess you alraedy knew that, so I have no clue.
But we already had help from a bunch of different people that got it compiled as well. So it has to be possible.
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: showing text really slow

Post by Demivec »

@Brujah: I have had no problems running Laby.

The text displays without any noticeable mouse lagging on all screens (i.e. skills, help, Faq, etc.).

I did not try to compile the code but did notice while examining the skills.pbi that the draw_skills() procedure uses StartDrawing()/StopDrawing() multiple times before a single FlipBuffers() seems to be called. If you did only a single StartDrawing() and a single StopDrawing() at the end it may speed things up a little bit more.


Nice program by the way. :)
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: showing text really slow

Post by Brujah »

Fixed in svn now.
I did a test with removing the startdrawing and stopdrawing's.
but it seems I need to startdrawing before I output text. And Stopdrawing afterwards.
If I don't do that the screen stops working.
Guess you can't mix up drawing of text and drawing of sprites.
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: showing text really slow

Post by Demivec »

Brujah wrote:Guess you can't mix up drawing of text and drawing of sprites.
This is true but you can do something else. I'll abbreviate the contents (i.e. the code won't be runnable) of the procedure to illustrate just the loops with the drawing and sprite commands.

Instead of this (the way it is now):

Code: Select all

Procedure draw_skills(spalte, zeile, pos_aktuell, besch)
  
  ClearScreen(RGB(0,0,0))
  draw_plain_frame(33)
  
  wohin = ScreenOutput()
  StartDrawing(wohin)
    DrawText(500,17,Str(akt_spieler) + ") :")
  StopDrawing()
   
  For Shortcut_temp = -1 To #ANZ_SEKTIONEN
    
    StartDrawing(wohin)
      DrawText(x,y,skills(welche,akt_spieler)\name[1+language])
    StopDrawing()
    
    ClipSprite(#SPRITE_TILESET_JEWELS, j_art * 16 - 16, 1, 15, 15)
    DisplaySprite(#SPRITE_TILESET_JEWELS, x-20, y+2)
  Next
  
  For spalte_temp = 1 To 3
    For zeile_temp = 1 To #SKILLS_PRO_SPALTE
      StartDrawing(wohin)
        DrawText(x,y,skills(welche,akt_spieler)\name[1+language])
      StopDrawing()

      ClipSprite(#SPRITE_TILESET_JEWELS, 9 * 16 , 1, 15, 15)
      DisplayTransparentSprite(#SPRITE_TILESET_JEWELS, x-20, y+2)
    Next
  Next
  
EndProcedure
Do this:

Code: Select all

Procedure draw_skills(spalte, zeile, pos_aktuell, besch)
  
  ClearScreen(RGB(0,0,0))
  draw_plain_frame(33)
  
  wohin = ScreenOutput()
  StartDrawing(wohin)
    DrawText(500,17,Str(akt_spieler) + ") :")
    
    For Shortcut_temp = -1 To #ANZ_SEKTIONEN
      DrawText(x,y,skills(welche,akt_spieler)\name[1+language])
    Next
    
    For spalte_temp = 1 To 3
      For zeile_temp = 1 To #SKILLS_PRO_SPALTE
          DrawText(x,y,skills(welche,akt_spieler)\name[1+language])
      Next
    Next
  StopDrawing()
  
  For Shortcut_temp = -1 To #ANZ_SEKTIONEN
    ClipSprite(#SPRITE_TILESET_JEWELS, j_art * 16 - 16, 1, 15, 15)
    DisplaySprite(#SPRITE_TILESET_JEWELS, x-20, y+2)
  Next
    
  For spalte_temp = 1 To 3
    For zeile_temp = 1 To #SKILLS_PRO_SPALTE
      ClipSprite(#SPRITE_TILESET_JEWELS, 9 * 16 , 1, 15, 15)
      DisplayTransparentSprite(#SPRITE_TILESET_JEWELS, x-20, y+2)
    Next
  Next
  
EndProcedure
I hope that makes it clear. It seems that the sprites aren't overwritten by the text which means you should be able to draw all the text first, then display all the sprites afterward. If reordering the procedure this way doesn't help I must admit I'm out of ideas. I would also give the idea presented earlier of initializing sprites to contain the text and then displaying those instead.
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: showing text really slow

Post by Brujah »

I changed the code to do exactly that. Hopefully this solves the problem.
As I do not own a vista machine (where most people reported the error) I cannot test it its solved.
But code is definately better now as I do not do start/stopdrawing now all the time.

Thanks for your help.
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: showing text really slow

Post by Demivec »

Your Welcome. :D
Post Reply