FLIP... FLIP...

Started by drfloyd, April 29, 2019, 18:34:01

Previous topic - Next topic

drfloyd

Hello
Dr Floyd, french casual coder ! Sorry again for my english :/ I speak english like a spanish cow.

My last release in BLITZ 3D :
http://www.gamopat.com/2018/12/cosmos-the-secret-melody-v.10.html

All is ok in windowed mode, NO PROBLEMO, but when i come in fullscreen I have problem with FLIP. command.. Because I use sometimes 2 FLIPS in the same process.... because i add some images/animations in another loop

Exemple :

Graphics 320,240,32,1
setbuffer backbuffer()
do
   cls
   ;display images&animations
    gosub minigame                 ;or function minigame()   
    FLIP
loop


.minigame           ; or minigame() if function
do
    ;display additionnal images in a little part of the main image (a mini game)
    FLIP
    if keydown(28) then return
loop




So there is a FLIP into a FLIP... the result is bug display : vibrate image between 2 screens

how can i solve this ?

Thank you very much if you can help

Derron

only flip in the "main loop" if you did not do this "gosub" ?


bye
Ron

Qube

Do your main loop something easy like :

Code (blitzbasic) Select

Graphics 320,240,32,1
SetBuffer BackBuffer()

Do
   Cls

   Animations()
   MiniGame()

   Flip
Loop

Function Animations()
    ' draw cool stuff
End Function

Function MiniGame()
   ' draw more cool stuff
End Function


That way you'll only get one FLIP command in your main loop :)
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

drfloyd

yes,of course...

But I want to stop/freeze the animations/game when there is a windowed mini game.... the program is big (1000ko) and i don't want to recode lot of things.

There is no easy solution ? Like stopping the backbuffering when the function minigame start ?????

Derron

You only need the flip once - as Qube already suggested.

If you want to stop animations/game then have


if minigameActive
DoMinigameStuff()
else
DoNormalStuff()
endif

Flip


Qube's proposal even allows for more sophisticated stuff: like having the main game rendering in the background with the mini game in the foreground. Of course the physics/logic of the maingame should be set to "paused" then.


This is the benefit of splitting Logic and Rendering into two parts - it allows to render stuff (like a static screen) or to just update the game without even having to render out something (think of a headless server).

1mb of source code is ... manageable as most of the code will NOT handle your "maingame + minigame"-split.

bye
Ron

drfloyd

#5
I know that.

I try to explain in other way :

is it possible, just after a FLIP, to copy the new image (the frontbuffer image) into the backbuffer. I want the same image in front and back.

;D

TomToad

You could just take a "snapshot" of the back buffer just before the mini-game starts using GrabImage.  Then. while your mini-game is running, draw the image onto the screen instead of Cls, then set your viewport to the mini-game and render.

Code (blitzbasic) Select
Graphics 800,600
SetBuffer BackBuffer()

backImage = CreateImage(800,600) ;image for "Snapshot"

;create a bunch of balls for the "main game"
Type TBall
Field x#, y#, dx#, dy#
End Type

For i = 1 To 100
Ball.TBall = New TBall
Ball\x = Rnd(0,799)
Ball\y = Rnd(0,599)
Ball\dx = Rnd(-1,1)
Ball\dy = Rnd(-1,1)
Next

;create a bunch of squares for the "mini-game"
Type TSquare
Field x#, y#, dx#, dy#
End Type

For i = 1 To 100
Square.TSquare = New TSquare
Square\x = Rnd(0,319)
Square\y = Rnd(0,239)
Square\dx = Rnd(-1,1)
Square\dy = Rnd(-1,1)
Next
minigame = False

While Not KeyHit(1)
Viewport 0,0,800,600 ;set viewport for entire screen

;main game
If Not minigame Then
Cls ;clear the main screen
For Ball.TBall=Each TBall
Oval Ball\x-10,Ball\y-10,20,20,True
Ball\x = Ball\x + Ball\dx
If Ball\x > 809 Then Ball\X = -9
If Ball\x < -9 Then Ball\x = 809
Ball\y = Ball\y + Ball\dy
If Ball\y > 609 Then Ball\y = -9
If Ball\y < -9 Then Ball\y = 609
Next
;when space is hit, switch to mini-game
If KeyHit(57) Then
minigame = True
GrabImage backImage,0,0 ;this grabs the current back buffer

EndIf

;Mini-game
Else
DrawImage backImage,0,0 ;draw the "snapshot". No need to clear the screen as
; the snapshot will cover anything previously drawn
Viewport 240,180,320,240 ;set the viewport to the mini-game
Cls ;clear the mini-game screen
For Square.TSquare=Each TSquare
Rect Square\x+230,Square\y+170,20,20,True
Square\x = Square\x + Square\dx
If Square\x > 329 Then Square\X = -9
If Square\x < -9 Then Square\x = 329
Square\y = Square\y + Square\dy
If Square\y > 249 Then Square\y = -9
If Square\y < -9 Then Square\y = 249
Next
If KeyHit(57) Then minigame = False ;when space is hit, end mini-game
EndIf
Flip True
Wend
------------------------------------------------
8 rabbits equals 1 rabbyte.

drfloyd

thank you very much, i will try to understand your exemple...

it's crazy...

2 question relating to this :

- There is no possibility to do just a "refresh" in BLITZ ? instead of a flip between 2 images ???
- Why there is no problem in windowed mode ? (i can put FLIP everywhere just to refresh images)