-
Mar 11th, 2023, 01:42 PM
#81
Re: Cairo Power?
 Originally Posted by -Corso->
Very smooth, even at full screen.
I can't get way with such speeds though, I've got 20 layers all needing attention, and multiple characters requiring redrawing.
It is fast because the map is drawn once and rendered on the screen in different coordinates.
In fact, the problem is when there are characters/objects moving. In which case you have to redraw the objects "in front". (those that hide it partially or entirely).
In my case, in "SetTile2" I tried to redraw only the moving object an its "'around", and hide it based on depth (Z/Distance from camera). It doesn't work correctly, though. If you/someone could "fix" such a system I think you could preserve the speed enough even for more characters.
-
Mar 13th, 2023, 01:48 AM
#82
Thread Starter
Hyperactive Member
Re: Cairo Power?
Well, updating.
Put the game on the larger monitor, 1920x1080.
Game speed with sunshine effects, runs at +70ms, with no extra characters.
That's really bad.
Quite rubbish actually and too slow to play a game with.
I have no choice but to pull out the sunshine/morning/sunset effects.
Last edited by -Corso->; Mar 13th, 2023 at 02:53 AM.
-
Mar 23rd, 2023, 11:04 AM
#83
Re: Cairo Power?
hey Corso
I have updated the Program.
I was able to implement moving objects.
They are "hidden" by the objects in front.
I used the MaskSurface function.
For each X+Y cell position value (manhattan distance) I created a Mask surface.
It is quite difficult to explain the technique I used, maybe by looking at the code you can understand.
I suggest you take a look it could be very interesting. bye.
Link is the same:
https://github.com/miorsoft/VB6-ISO-game-Test
EDIT:
It works quite well.
For now, the main problem is memory consumption, as I am generated a number of Mask Surfaces equal to MapWidth+MapHeight.
They also have a large size in pixels.
This could be remedied by using/generating only one Horizontal Stripe (What is enough) for each of them. [in this case, however, the appearance should be Isometric and not Trimetric so that the masks have a height dimension that is not too large]
I will try this in the future.
(I wrote the code very quickly, in a hurry, and so there may be some imperfections.)
Last edited by reexre; Mar 23rd, 2023 at 01:45 PM.
-
Mar 23rd, 2023, 07:23 PM
#84
Thread Starter
Hyperactive Member
Re: Cairo Power?
Nice job Reexre.
I saw the alpha swap code, so I assume that's your masking thingy. I don't think I can do that with my situation, as I'm going to run about 10,000 icons/images or more. My main issue is dumping tiles which contain about 20 images per each and every tile. And then there is the addition of sun and dark overlays, as well as shadow formation. And characters etc, etc.
I've tried other methods of saving time to regenerate drawings, particularly partial sections and (lastly)moving matrix index-references to static pre-built tile surfaces, but it's all extremely lame. The CPU is too underpowered and can't handle game-graphics necessities after a certain point.
-
Mar 23rd, 2023, 10:28 PM
#85
Re: Cairo Power?
 Originally Posted by -Corso->
The CPU is too underpowered and can't handle game-graphics necessities after a certain point.
Could you run the following "cairo-2D-game-layer-test" please?
Code:
Option Explicit
Const GW& = 1920, GH& = 1080, TS& = 32, SS& = 64 'Defs for game-width/height and Tile- and Sprite-Sizes
Private CCM As cCairoContext 'our main-surface-context
Private T1 As cCairoSurface, T2 As cCairoSurface 'two different Tiles
Private S1 As cCairoSurface, S2 As cCairoSurface 'two different Sprites
Private Sub Form_Load()
Set CCM = Cairo.CreateSurface(GW, GH).CreateContext 'create the "main-Game-Surface"(Context) in 1920x1080
Set T1 = Cairo.CreateSurface(TS, TS)
T1.CreateContext.Paint 1, Cairo.CreateCheckerPattern(8, vbRed)
T1.CreateContext.RenderSurfaceContent Cairo.ImageList.AddIconFromResourceFile("", "shell32", 28, TS, TS), 0, 0
Set T2 = Cairo.CreateSurface(TS, TS)
T2.CreateContext.Paint 1, Cairo.CreateCheckerPattern(8, vbBlue)
T2.CreateContext.RenderSurfaceContent Cairo.ImageList.AddIconFromResourceFile("", "shell32", 45, TS, TS), 0, 0
Set S1 = Cairo.ImageList.AddIconFromResourceFile("", "shell32", 250, SS, SS)
Set S2 = Cairo.ImageList.AddIconFromResourceFile("", "shell32", 249, SS, SS)
Me.WindowState = vbMaximized 'let's do a Full-Screen-Test
End Sub
Private Sub Form_Click()
New_c.Timing True 'now simulate "a lot of Alpha-Sprite-Blittings"
ClearSceneWithBackGroundTiles CCM
DrawEnvironmentSprites CCM
CCM.Save 'just to simulate a second layer of "environment-sprites"
CCM.TranslateDrawings TS, TS: DrawEnvironmentSprites CCM
CCM.Restore
CCM.Surface.DrawToDC Me.hDC 'show the result
Caption = New_c.Timing
End Sub
Private Sub ClearSceneWithBackGroundTiles(CC As cCairoContext)
CC.Operator = CAIRO_OPERATOR_OVER
Dim y As Long, x As Long, Tile As cCairoSurface
For y = 0 To CC.Surface.Height \ TS: For x = 0 To CC.Surface.Width \ TS
If (x + y) Mod 2 Then Set Tile = T1 Else Set Tile = T2
CC.SetSourceSurface Tile, x * TS, y * TS
CC.Paint
Next x, y
End Sub
Private Sub DrawEnvironmentSprites(CC As cCairoContext)
CC.Operator = CAIRO_OPERATOR_OVER
Dim y As Long, x As Long, Sprite As cCairoSurface
For y = 0 To CC.Surface.Height \ SS: For x = 0 To CC.Surface.Width \ SS
If (x + y) Mod 2 Then Set Sprite = S1 Else Set Sprite = S2
CC.SetSourceSurface Sprite, x * SS, y * SS
CC.Paint
Next x, y
End Sub
So, the above simulates "straight Alpha-Blitting, ensuring 3 Layers":
- on a (quite generous) 1920x1080 Pixel-Surface
- Layer1 = complete "Scene-Clearance", using Background-Tile-Rendering of 32x32 tiles
- Layer2 = simulation of a few "Tree- and Boulder-Sprites" (also fully ScreenCovering, using 64x64 Sprites)
- Layer3 = simulation of "more such stuff" (the Layer2-loop-routine is called again, with a slight translate-offs)
The timing here on my machine (in IDE-PCode-Mode) is:
- 7.5msec per 3-Layer-Scene (about 133 FPS) ... on a game-surface of 1920x1080
- and about 5msec per 3-Layer-Scene (200 FPS) ... when the game-surface is reduced to 1600x900
Note, that enlarging the tile- and sprite-sizes in the constant-defs at the top, will give only slightly better timings -
...because all layer-loops are implemented to "fully cover the game-surface" in their iterations -
(larger tiles cause less iterations, but cairos "alpha-blend-pixel-throughput" remains the same in the end)
As said, would be interested in your results, when you click the Form repeatedly.
For those interested, the shell32-icon-numbers I use here as "Alpha-Sprite-Surface-Resources" can be seen e.g. here:
http://glennslayden.com/code/win32/shell32-dll-icons
Olaf
Last edited by Schmidt; Mar 23rd, 2023 at 11:23 PM.
-
Mar 24th, 2023, 01:47 AM
#86
Thread Starter
Hyperactive Member
Re: Cairo Power?
17.5ms on 1920x1080
11.5ms on 1600x900
8.5ms on 1280x800 (Projector resolution I'm currently sitting at)
-
Mar 24th, 2023, 07:17 AM
#87
Re: Cairo Power?
In case an extra data-point helps, I get ~17ms per click.
-
Mar 24th, 2023, 11:21 AM
#88
Re: Cairo Power?
 Originally Posted by jpbro
In case an extra data-point helps, I get ~17ms per click.
So, on an "average, non-overpowered" Gaming-PC, one will achieve:
- about 17msec (on a quite high-res "Full-HD" Surface of 1920x1080
- which equals about 55-60FPS and means "quite fluent 2D GamePlay"
And all that, whilst performing the rendering based on:
- high-frequent re-drawings of relatively small tiles (32x32) and sprites(64x64) "from the ground up"
- which means, that "map-shifting underneath the Player-cursor" is already covered ...
- ... when the loops just lookup for "the right tiles, to place in the right render-slots of a shifted tile-matrix"
Note, that in case of slightly larger tiles (48x48) and sprites (96x96)-
the loops will be less frequented and thus would produce slightly better timings.
What remains to be solved is only, to come up with a faster alternative to Cairos "lighting" Blend-Operator
(CAIRO_OPERATOR_OVERLAY).
I already have a (to 90% functioning) new RC6-Class in the works (cOGL2D),
which will allow the upload of cairo-surfaces as textures - and from there:
- allow arbitrarily stretched output to rect-areas on the bound hWnd
- as well as "Shader-Processing on Texture-Pixels" by using .AddProgram and .UseProgram methods
Olaf
-
Mar 24th, 2023, 03:04 PM
#89
Re: Cairo Power?
The approach of redrawing all tiles/sprites is not optimal in my opinion.
Because if you use a map with a larger number of tiles you easily run into the problem of redraw time (thus low Frame Rate).
So, in my opinion, the best way consists of:
1) Draw the background (It consists of the floor, possibly the shadows and all static objects).
This will not be modified and it is useless to redraw it every time.
2) Draw over this background the moving objects. (At the moment though, I don't know how to draw the shadows of these objects)
As I carried out step 2:
When one of these objects is drawn, it does not have to be drawn entirely, as it will most likely be partially hidden by some other object "closer to the camera"
Therefore, to draw only the relevant part I used masks.
The mask to be used for each position in the map is given by the sum of the map coordinates X+Y. (That is, everything [or almost everything] that is rendered with base further down the screen than the position of the object to be drawn partially is excluded from rendering.)
Thus: For each diagonal of the map whose identification is given by the sum of the X,Y coordinates of it I created a mask.
01234
12345
23456
34567
Mask creation: Each mask of the diagonal (X+Y) was created by drawing only static objects with coordinates >(X+Y). Since the RenderMask function draws only where Alpha>0 and I need the opposite (i.e. draw the moving object only where Alpha=0 [Where the above static objects are not there]) I reversed the Alpha channel value.
This in my opinion is the optimal way.
The only problem I ran into ( which can be partially remedied) is memory consumption.
At the moment these masks occupy the entire "background," so they are large in size, and also their number is given by the sum of the map size (NTileX+NtilesY).
It is not necessary for them to be that large.
If the look of the game were isometric (So the diagonals of the map would be represented horizontally in the screen) a height equal to the height in pixels of the tallest tile or slightly more would suffice. (And the width dimensions would also be small: equal to the width of the tiles along the diagonal.)
Another way to solve this problem might be to create a mask (in a similar fashion) for each location on the map. These masks would be very numerous but would be small in size.
It was difficult for me to explain this technique in words; with drawings/illustrations it would be easier and also clearer for others to understand.
Still, I hope I have made at least a vague idea.
The gist of it is:
- Draw what is static only once, and what is dynamic always.
- When you draw a dynamic object, you do it using a mask that does not allow you to draw over another object closer to the camera.
That way precisely you only draw the background and the moving objects, which as many as they may be, I think certainly are less than the tile map.
Last edited by reexre; Mar 24th, 2023 at 03:36 PM.
-
Mar 24th, 2023, 05:28 PM
#90
Thread Starter
Hyperactive Member
Re: Cairo Power?
I already have a (to 90% functioning) new RC6-Class in the works (cOGL2D),
which will allow the upload of cairo-surfaces as textures
Sounds good Olaf.
Well, just to consider what is built per tile. 747 tiles on a small screen 1280x800.
Layer 1. Terrain, 80x36 pixels
Layer 1.a Corner Set 1, 80x36 pixels
Layer 1.b Corner Set 2, 80x36 pixels
Layer 1.c Corner Set 3, 80x36 pixels
Layer 1.d Corner Set 4, 80x36 pixels
Layer 2. Grass, 80x75 pixels
Layer 3. Object Shadow, 500x200 pixels (They can get quite huge at sunset hence the size)
Layer 4. Object, Tree or Rock, 100x100 pixels
Layer 4.b Decorations on objects, aka, Fireplaces, windows, torches, paintings, decorative shields, etc, 100x100 pixels
Layer 5. Characters Shadows, 500x200 pixels
Layers 6. Characters, 100x100 pixels
Layer 7. Characters with Grass, Object, Tree, Rock, Items/Clothing objects clipped (in front) (Sun effect added if needed), 100x100 pixels, from about 10 surrounding tiles, each.
Layer 8. Items shadows, 500x200 pixels
Layer 9. Items x 4 times, 26x26 pixels x 4
Layer 10. Night black layer, screen size, ie: 1280x800 pixels
Layer 11. Light Layer, white splodge layer for light sources, screen size, ie: 1280x800 pixels (Copies all layers above except black layer via ATOP)
Layer 12. Midband Overlay glow, 1280x800 pixels, pre adjusted to screen size.
Layer 13. Overlay colourizations, screen size, ie: 1280x800 pixels
I think that's all of them. I'd like to add a special 'lit torch/lamp' layer/s instead of having permanently visibly-on lights. But it'd be too slow currently. Plus there will need to be special effects eventually too, ie: like fire, oil, water, blood, magic stuff.
The flowerpot method (all things drawn onto a tile, on a separate surface) is ideal for all of this, as you can have virtually unlimited characters on screen without any major performance drain. Reason is because one doesn't need to redraw things in front of a character. Shifting the static surface indexs is fast, however, the code is awful. I already removed it as the CPU is still slow using it. For each flowerpot surface is 100x114 pixels x 747 on the small screen. But I didn't put in shadows during the test, that would require extra flowerpot surfaces, as the shadows do move over time. One only needs to build edge flowerpots when the avatar moves (from all of the layer data above).
Last edited by -Corso->; Mar 24th, 2023 at 05:46 PM.
-
Mar 25th, 2023, 06:14 AM
#91
Re: Cairo Power?
I implemented
 Originally Posted by reexre
It is not necessary for them to be that large.
If the look of the game were isometric (So the diagonals of the map would be represented horizontally in the screen) a height equal to the height in pixels of the tallest tile or slightly more would suffice. (And the width dimensions would also be small: equal to the width of the tiles along the diagonal.)
with 70x70 map with 50x25 tiles (moving objects 15) it works at 60 FPS
https://github.com/miorsoft/VB6-ISO-game-Test
Last edited by reexre; Mar 25th, 2023 at 06:39 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|