English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 27 December 2014, 11:00   #1
Sparticle
Registered User
 
Join Date: May 2009
Location: Leicester/U.K
Posts: 36
Screen glitches with mouse movement or key press

Hi,

I'm still working on the game I mentioned in my previous post.
The game doesn't flicker any more as its being drawn but when I move the mouse or press the keyboard I get screen glitches.

Here's the paint function I'm using:
Code:
void GamePaint()
{
  struct RastPort rp;
  struct BitMap* bm;
  bm = AllocBitMap(1024,1024,4,BMF_DISPLAYABLE|BMF_CLEAR,NULL);
 
  InitRastPort( &rp );
  rp.BitMap = bm;
 
   MoveSprite(vp, &my_sprite,X,Y);
     
  DrawImage(&rp, &BG,BitMapOrigin.X, BitMapOrigin.Y);
  Pipes[0].DrawPipe(&rp);
  Pipes[1].DrawPipe(&rp);       
 
 DrawImage(&rp, &Ground,X2, BitMapOrigin.Y+WINDOW_HEIGHT - Ground.Height);
           
         
 DrawImage(&rp, &Ground2,X3,  BitMapOrigin.Y+WINDOW_HEIGHT -Ground2.Height);
            
          
  BltBitMapRastPort(bm,
            BitMapOrigin.X,
            BitMapOrigin.Y,
            App.GetWindow()->RPort,App.GetWindow()->BorderLeft-4, 
           App.GetWindow()->BorderTop-12,WINDOW_WIDTH,WINDOW_HEIGHT,
          0xC0);

}
Sparticle is offline  
Old 27 December 2014, 12:01   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,026
A bitmap of 1024 x 1024 x 4 needs 512 KB continuous Chip RAM. It will never run on a A500. You should rather allocate the bitmap with a size of WINDOW_WIDTH x WINDOW_HEIGHT.

You should also specify the screen's bitmap as friend to AllocBitMap. This way the system will optimize the allocation in such a way that blitting into the screen is as fast as possible.

I would put MoveSprite after BltBitMapRastPort. Otherwise the sprite moves faster than the background.

Regarding your blitting dimensions, BorderLeft and BorderTop are font-sensitive, 4 and 12 are not. What do you intend with this calculation? If your window has a border, you overwrite part of it. If it does not have a border, you blit outside of the window. For a borderless window 0,0 should be right and for a window with border BorderLeft,BorderTop without substraction.

BitMapOrigin is not needed at all if your bitmap has the same size as the window (my first point above).

Talking about glitches, how do you wait for the next frame?
thomas is offline  
Old 27 December 2014, 13:14   #3
Sparticle
Registered User
 
Join Date: May 2009
Location: Leicester/U.K
Posts: 36
Quote:
Originally Posted by thomas View Post
A bitmap of 1024 x 1024 x 4 needs 512 KB continuous Chip RAM. It will never run on a A500. You should rather allocate the bitmap with a size of WINDOW_WIDTH x WINDOW_HEIGHT.

You should also specify the screen's bitmap as friend to AllocBitMap. This way the system will optimize the allocation in such a way that blitting into the screen is as fast as possible.

I would put MoveSprite after BltBitMapRastPort. Otherwise the sprite moves faster than the background.

Regarding your blitting dimensions, BorderLeft and BorderTop are font-sensitive, 4 and 12 are not. What do you intend with this calculation? If your window has a border, you overwrite part of it. If it does not have a border, you blit outside of the window. For a borderless window 0,0 should be right and for a window with border BorderLeft,BorderTop without substraction.

BitMapOrigin is not needed at all if your bitmap has the same size as the window (my first point above).

Talking about glitches, how do you wait for the next frame?
Thanks for the reply.

The Window does have a border. I used subtraction as it wasn't drawing from the top left corner of the window. I will change it as recommended.

I thought I would use a bigger bitmap because the pipes are tall and placed randomly vertically and didn't want them to be drawn outside the bitmap storage.

Im not sure about the next frame. The game is cycled through the windows outer main message loop like this:



Code:
while( !EndMsgLoop)
	{
	   
          
		while(Message = (struct IntuiMessage *) GetMsg(MyWindow->UserPort))
		{
                   // Handle messages etc
                }
GameCycle();
GamePaint();
        }
All the positions etc are updated in the GameCycle function and the drawing in GamePaint. Im not sure if this is the right way to go about it.
Sparticle is offline  
Old 27 December 2014, 16:37   #4
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,026
Quote:
Originally Posted by Sparticle View Post
I thought I would use a bigger bitmap because the pipes are tall and placed randomly vertically and didn't want them to be drawn outside the bitmap storage.
If you need clipping, here is an example how to use layers.library on an off-screen bitmap: http://thomas-rapp.homepage.t-online.de/examples/clip.c

Quote:
Im not sure about the next frame. The game is cycled through the windows outer main message loop like this:
I don't see any synchronisation with the display or with the clock. Is it really so that you just draw as fast as you can, without any synchronisation? This means on a fast machine the game might become unplayable fast?

I would expect a WaitTOF() or WaitBOVP() somewhere in the loop. Or some use of timer.device or IDCMP_INTUITICKS.
thomas is offline  
Old 28 December 2014, 02:52   #5
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,839
Quote:
Originally Posted by thomas View Post
I would expect a WaitTOF() or WaitBOVP() somewhere in the loop.
You shouldn't use WaitBOVP() because it busy-waits. If you want to sync with the bottom of the frame, use a copper interrupt handler and send a signal.
Thorham is offline  
Old 30 December 2014, 09:17   #6
Sparticle
Registered User
 
Join Date: May 2009
Location: Leicester/U.K
Posts: 36
Quote:
Originally Posted by thomas View Post
If you need clipping, here is an example how to use layers.library on an off-screen bitmap: http://thomas-rapp.homepage.t-online.de/examples/clip.c
I've tried to use clipping but still having the same problem. WaitTOF() doesn't solve the issue either no matter where i put it in the loop. Same as WaitBOVP().
Ive also tried controlling the frame rate using timing and still makes no difference even at 1 fps.

Iv'e noticed if I dont use a custom screen in the game and set the screenmode to 16 colors the issue goes away but only in hires. changing to lores still gives me the same problem
Sparticle is offline  
Old 30 December 2014, 09:23   #7
Sparticle
Registered User
 
Join Date: May 2009
Location: Leicester/U.K
Posts: 36
Quote:
Originally Posted by Thorham View Post
You shouldn't use WaitBOVP() because it busy-waits. If you want to sync with the bottom of the frame, use a copper interrupt handler and send a signal.
Thanks for the reply.

I don't have a clue how to set up a copper interupt handler.
Are there any examples on how to do this?
Sparticle is offline  
Old 31 December 2014, 10:11   #8
Jherek Carnelia
Dazed and Confused
 
Jherek Carnelia's Avatar
 
Join Date: Dec 2001
Location: portsmouth/uk
Posts: 242
You will find examples of using interrupts with C in the RKM - Libraries. I have attached an extract from the relevant chapter.
Attached Files
File Type: pdf Pages from Chapter 17 - 26 Exec.pdf (80.0 KB, 184 views)
Jherek Carnelia is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amiga Mouse Movement over VNC Enverex support.WinUAE 10 15 March 2015 18:28
getting a user to press a key via AmigaDOS DeafDaz Coders. System 3 10 January 2012 17:37
Mouse no horizontal movement - a1200 TomVS support.Hardware 8 13 November 2009 07:57
'Wait' program that checks for a joy button press instead of 'Return' key... Heavy Stylus request.Apps 7 10 May 2009 19:01
Jerky mouse movement andreas support.WinUAE 3 02 June 2002 19:14

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:07.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08012 seconds with 14 queries