Page 1 of 3 123 LastLast
Results 1 to 40 of 91

Thread: Cairo Power?

  1. #1

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Cairo Power?

    Hi All,

    This might be a dumb question, but why is Cairo restricted to the CPU?

    I'm told by magical internet fairies that the GPU gives you super powers.

    YAOQ! Yet Another Olaf Question, most likely.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Cairo Power?

    According to the Cairo webpage it should use gpu acceleration when available.
    https://www.cairographics.org/

  3. #3
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    so the question is, do RC6+Cairo use X Render Extension.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    My understanding is that Cairo is basically just an interface that sits on top of a rendering engine, for example GDI or OpenGL. If the rendering engine is hardware accelerated then your flavor or Cairo would be to. The only question is, what is RC6's Cairo interface sitting on.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    Available back-ends
    Cairo supports output (including rasterisation) to a number of different back-ends, known as "surfaces" in its code. Back-ends support includes output to the X Window System, via both Xlib and XCB, Win32 GDI, OS X Quartz Compositor, the BeOS API, OS/2, OpenGL contexts (directly[7] and via glitz), local image buffers, PNG files, PDF, PostScript, DirectFB and SVG files.

    There are other back-ends in development targeting the graphics APIs OpenVG,[8] Qt,[9] Skia,[10] and Microsoft's Direct2D.[11] The BeOS, OS/2 and DirectFB backends were dropped in 2022.[12]

    source: https://en.wikipedia.org/wiki/Cairo_(graphics)

    so, if u want cross-platform, u need to be aware of this and not pick any backends that could lock the project to a system.
    but if we can create a class that would "recognize" the OS and switch to a backend that works for that OS it could make Cairo "fast".

    before I switched to only-Direct2d. I did have 2 classes. 1 class uses GDI32/+ and one class uses Direct2D.
    and using "Variant" I could set the "engine = as new whateverclass"
    the importance is that both class are identical in names.
    in direct2d u have 0.0-1 while gdi 0-255 for RGB. and a few other difference, when dealing with "RECT" as in direct2d the rect is left/top/right/bottom, while GDI32 u use left/top/width/height

    so, the same could be done with direct2d and opengl and other graphic engines.

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Cairo Power?

    Quote Originally Posted by -Corso-> View Post
    This might be a dumb question, but why is Cairo restricted to the CPU?
    As mentioned by others already, cairo itself can support multiple rendering-backends
    including GPU-based backends as OpenGL for example).

    The RC6-wrapper though currently only supports:
    - the default "System-Memory-Backend" for Surfaces (which are handled directly on the CPU)
    - the SVG- and the PDF-backends (able to produce these formats from the same drawing-commands).

    And the current CPU-backend is IMO entirely sufficient for "high framerates on a Desktop-CPU on a Win-OS).

    Have played with the cairo-OpenGL-backend a few years ago -
    and the support on Windows was "underwhelming" and "difficult to compile" for the Win-platform.

    The GPU-backends cairo offers, work better on Linux-systems or ARM-devices (OpenGL-ES).
    I'll consider them, as soon as VB6 starts working "multi-plaform"...

    Is there a performance-related issues currently in your game-development
    (thought it was performing nicely so far...)?

    Olaf

  7. #7
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    as for multi-platform.
    I think when TB is there as well, Schmidt can start working on it.
    right now its quite pointless.

    I think Schmidt mentioned that each system will have its own library.
    that are compatible, code-wise. so u dont need to change the code in the project.

    so, cairo-windows could use direct2d
    while cairo-linux could use opengl-es
    and cairo-mac could use ???
    or whatever that works best together with cairo and its easiest to implement for both stability and similarities between the engines for all cross-platform.

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Quote Originally Posted by Schmidt View Post
    Is there a performance-related issues currently in your game-development
    (thought it was performing nicely so far...)?
    I can't speak for the OP but I've been through this twice. If you're doing anything like a game engine, a software renderer just won't cut it after a certain point. In my case, alpha blending was a serious bottleneck. I used alpha blending to implement a different kinds of special effects and when you have to perform alpha blending operations on many dozens of sprites every frame, even at 24 FPS, performance takes a massive hit when using a software renderer. There's just no way around it, you need a GPU to do it.

    [EDIT]

    Here's one thread that documents my suffering with software rendering:-
    https://www.vbforums.com/showthread....ics&highlight=

    [EDIT]

    Later in that thread, my reaction to finally using DirectX:-
    https://www.vbforums.com/showthread....=1#post4656369

    Fun times
    Last edited by Niya; Feb 25th, 2023 at 04:48 AM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Cairo Power?

    Quote Originally Posted by Niya View Post
    ...a software renderer just won't cut it after a certain point...
    That's not my experience with the cairo-alphablend-routines.
    (which are more than fast enough for 2D-games, since the SSE3-extensions of the CPU are used).

    E.g. in your example-code from the Link you've posted,
    the performance of "alpha-blitting a 100x100 sprite" was about 1-2seconds...

    With cairo-alpha-blitting I can do the same test in about 100msec (about factor 10 faster):
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim Img As cCairoSurface 'create a Sprite in 100x100 size
      Set Img = Cairo.ImageList.AddIconFromResourceFile("", "shell32", 167, 100, 100) 
      
      Dim CC As cCairoContext 'create a "Game-Surface" in 800x600
      Set CC = Cairo.CreateSurface(800, 600).CreateContext 
     
      New_c.Timing True 'now simulate "a lot of Alpha-Sprite-Blittings"
        Dim i As Long
        For i = 1 To 10000
          CC.RenderSurfaceContent Img, 5, 5
        Next
      Caption = New_c.Timing
      
      Set Picture = CC.Surface.Picture 'show the result
    End Sub
    Olaf

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Quote Originally Posted by Schmidt View Post
    ...since the SSE3-extensions of the CPU are used
    I imagine this here would make a substantial difference. SSE3 uses XMM registers if I'm not mistaken which are 128 bits wide. This means you can process 4 pixels at a time so at the very least you could earn a 4x improvement in graphics performance. I wish I had thought of this back then though in the end, it still won't beat a GPU which can process hundreds of pixels simultaneously.

    To be honest, unless you plan to animate thousands of sprites at very high framerates, a software renderer is more than adequate, especially if the renderer is using vector instructions for processing pixel data. In my case, I was a little ambitious(hundreds of sprites, all kinds of physics calculations, a bunch of special effects and a pseudo-scripting engine, all running at the same time) so I couldn't get away with software rendering for long.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Cairo Power?

    Quote Originally Posted by Niya View Post
    To be honest, unless you plan to animate thousands of sprites at very high framerates, a software renderer is more than adequate, especially if the renderer is using vector instructions for processing pixel data.
    Yep.

    Quote Originally Posted by Niya View Post
    In my case, I was a little ambitious(hundreds of sprites, all kinds of physics calculations, a bunch of special effects and a pseudo-scripting engine, all running at the same time) so I couldn't get away with software rendering for long.
    FWIW, RC5/RC6 has a high-performance physics-engine integrated already (based on the "chipmunk"-project) -
    an example is in the Codebank:
    https://www.vbforums.com/showthread....-for-Starters)

    Olaf
    Last edited by Schmidt; Feb 25th, 2023 at 12:49 PM.

  12. #12

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    Hiy’all, thanks for taking the time to respond.
    Yes Olaf, I’ve had to re-approach the screen rendering. I need to operate two screen render modes:

    1. Where the map is fixed and the user walks around, changes when they hit the border. Performance, ok-ish. But I need to add more ‘objects, characters and placement lighting’, each of them is affected by draw speed and sun overlays. I’ve had to cut out certain lighting effects sadly.
    2. User is fixed in the middle, map moves around them. Performance is rubbish. All day-morning-evening overlays have to be switched off. I don’t even want to think about what adding characters and lighting will do.

    There are times when a static map is beneficial, and other times when it is not. I need those two options for the user to switch when they need to.
    My outlook, it’s my modus operandi to ‘overwhelm’ the user and have them love every little bit of the visuals (Autobuilders+ diversity of environment + effects ). With the sun shading, evening, morning effects, it adds a whole impressive visual aspect. Forests, deserts, other coloured biomes all look eye-catchingly good under the sun shaders.

    So I don’t particularly want to cut them out. I’ve hit the speed wall on the CPU rendering.

  13. #13
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    I switched from gdi32 to direct2d because even using gdialphablend (hardware acc.) is slower.
    that is why I have numerous times posted about this to people that are making graphic-tools to use d2d.
    if Olaf can add gpu support it would help greatly. otherwise u are stuck doing compromise work. and even that maybe will not help u in the end.
    if u want to work with cpu u need to:
    - create everything in a memory buffer. and when done, render it to screen. do not use multiple screens if u want to work with layers. use just one screen.
    I do that with my game, and I have many layers, UI etc. and I render everything in 1 picturebox, even the mousepointer is rendered (mouse pointer is hidden)
    that is the fastest approach I could find for gdi32. and a game-loop with peekmessage.

  14. #14
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Oh you definitely need hardware acceleration. This is a lot more involved than anything I was talking about or imagined. Sounds like you're doing a lot of dynamic lighting and other blending effects that affect the entire scene being rendered. You definitely want the power of the GPU backing this. Based on what you've described here, I am confident you're hitting the limits of what software rendering can do. You really need to start thinking about something like DirectX.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  15. #15
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Cairo Power?

    Quote Originally Posted by -Corso-> View Post
    2. User is fixed in the middle, map moves around them.
    Not sure, what you mean with that.
    Is it more like a "flight mode", or a "rotation of the map beneath" (changing where "North" points to)?

    Quote Originally Posted by -Corso-> View Post
    I’ve hit the speed wall on the CPU rendering.
    I'm sure there's a whole lot of significant optimizations which could be applied, before you "really hit the wall"...
    (pre-renderings on different threads, in conjunction with clever caching of tiles or entire "already calculated region of tiles").

    Not easy to give good advice at this point, without something concrete (code-example wise).

    Olaf

  16. #16
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Quote Originally Posted by Schmidt View Post
    Not easy to give good advice at this point, without something concrete (code-example wise).
    I was thinking about this though I was thinking about asking him to post a screenshot of a fully rendered scene with all effects enabled so we can get a handle on how simple or sophisticated the scenes are.

    I think it really just comes down to does he need hardware acceleration or not. A single screenshot might be able to answer that.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  17. #17
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Cairo Power?

    Quote Originally Posted by Niya View Post
    I was thinking about asking him to post a screenshot of a fully rendered scene with all effects enabled so we can get a handle on how simple or sophisticated the scenes are.
    You can see a few (smaller) shots in earlier threads (when you follow Corsos posting-history) -
    but I'm sure he will post a "big, nice one" here soon (or maybe a link to his webpage for this project).

    Olaf

  18. #18
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Oh I found one:-


    From this thread:-
    https://www.vbforums.com/showthread....-up&highlight=

    Seems to be an RPG type game. Unless these games are combat heavy, they typically don't have too much happening on the screen at the same time. A software renderer is adequate in such scenarios.

    If the game is combat heavy with stuff flying and exploding all over the place then you might want some hardware acceleration.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  19. #19
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    I think the problem is that he apply effects in real-time.
    in my game everything is pre-made. so I just work with copy/paste method. and thats fast.
    but if I start to apply effects, like shadows/lightning for each picture it will start to eat up quite fast the cpu.

    what I would do (as Im extremely optimize-crazy when Im doing my game)
    - I would create a "builder-tool" that I run each time something new is added
    - the builder-tool would create DB for everything in a "most easy way to work for the game, requiring as little possible calculations"
    - each picture will apply a "shadow" to it and merge it to the picture in specific positions. so the only thing I need to do is: "render x,y,0,0,width,height" (the picture) + "render x,y,posx(i),posy(i),wid(i),hei(i)" (the shadow)
    that way I don't need to generate the shadow in-game, instead I just copy/paste it. or (as I do in my game) I append each pictures in 1 file. so I have 1 big file that I let "open" while the game is running, meaning I load everything in stream. (I don't like having thousands of files in folders, also its slower to load)

    not sure how many different shadows each picture has, but shadows should not take that much size.

    and of course more and more work like this so I dont need to apply too much heavy-calculations in the game-engine.

  20. #20

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    Hiy'all again. It's very late, I've got a splitting headache, but I'll post the images with comments. I'm probably forgetting a tonne of stuff. Might recall tomorrow.

    To my dismay, this site balks on Dropbox embedding, links are attached.

    A simplified definition:
    Mode 1: User travels all over the screen.
    Mode 2: User is 'always' centre screen.

    Sunset Overlay. Mode 2: Weak light sources need to be partly-stained the current sunset colour. I regretfully removed that effect when it was too slow to play in either mode. Now it just looks weird.
    https://www.dropbox.com/s/68okeyajrt...urces.jpg?dl=0

    Mode 1: 10:17pm, can’t add the night blue to weak light sources, due to lag. It was a super immersive effect though. Less weird, but still too contrasting in colour.
    https://www.dropbox.com/s/43g6nms05r2svc2/Fast%20Mode%201%20no%20light%20staning%20either.jpg?dl=0
    Mode 2: This I the general daytime, user is always centred. Though you won’t see it, there is an imperceptible horizontal mid band glow (overlay) light. It only works in Mode 1 otherwise it’s too slow.
    https://www.dropbox.com/s/q4kthayd6807w7h/Mode%202%20Always%20Centre.jpg?dl=0

    General:
    • The Cairo_Operator_Overlay & Black Paint adds the sunset/sunrise effect to the entire screen. This is a Slow Function via CPU.

    • Lamp lights are splodges of white on an empty surface to which the unaltered original images is boolean-style Cairo_Operator_Atop copied. The result surface is then pasted over the above sunset screen.

    • Mind you, for every character character present, each tree-block-object-item tile in front of them needs to be redrawn over them, complete with sunset effect. (About 12 tiles per every character) (Mode 1). It starts to lag out at 100 on screen characters. Worse if sunset is applied.

    • Each shadow is worked out for every object at the -specific- time of day using a Cario Matrix, this only ever occurs during a screen change. So it is unnoticeable in Mode 1 general traverse. It takes 100-200 ms to draw a screen change. Most of the time, with a single character, 4 to 6 ms screen update on Mode 1. About 8-15 ms with Sunset overlay on.

    Mode 2: is carnage. It requires redrawing of the tile sets + trees + objects + items + characters + shadows + light sources + overlay per every move. When sunset overlays and daytime overlay are removed, that brings it down to about 60ms per move. It’ll get hideous in a market place with mass loads of items and people. Because all their moves, variations, whatnot need to be redrawn every move.

    Mode 2: Is necessary for small screens in particular, as well as general traverse. Big monitors are excellent for Mode 1 and ‘noticing details’, but do need Mode 2 when you are at the border of screens. At the moment, spacebar manually re-centres.

    Note: Sunset colours ‘always’ change per move. Shadows are slow and don’t need to be re-calculated very often.

    There’s not much on the website, nelfid.com is the WIP home.
    Reddit has the overview, https://www.reddit.com/r/roguelikedev/comments/10l5vp5/2023_in_roguelikedev_monstergirl_trl/

    Apologies if I'm a bit slow and disorderly. Having mega-insomnia... Maybe better after massive probiotic-glucose loading tonight.

  21. #21
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Ok looking at your screenshots, my instincts scream hardware acceleration.

    However, I can see some ways where you can optimize a software renderer and it's mainly by pre-rendering. For example, the sunset overlay could be blended once, cached, presumably when the map is being loaded and simply blitted on every frame. If you're actually performing the blending on every frame, I'd consider this wasteful since the image, from what I can tell, doesn't change. It's static. The same for applies for lighting effects and shadows.

    Now, the reason I'd be strongly for hardware rendering is more personal so take it as such. Optimizing a software renderer for something like this would require a lot of caching which complicates the code. With a hardware renderer you could just blend on every frame and not have to worry about it, even if it's a bit wasteful. A GPU does this stuff so quickly that if anything, you'd still be under utilizing it's power.

    There is another problem I have with caching pre-rendered images, it's memory intensive. I'm looking at your sunset overlay. Let's say you have different levels of sunlight, lets say 5. Lets further assume that while you're playing it can change. You'd have to prepare for that by pre-rendering the entire map at 5 distinct light levels and hold that in memory for when they are needed. I think it would be much better if you could simple pass the engine a light level value and it calculates this on-the-go so you don't have to use enormous amounts of memory holding different versions of the same image. GPU rendering would allow you to do this very comfortably.

    Another thing I though about was movement. What if you had say, a bird flying across the map. If the bird is flying in random directions, you'd have to pre-render and cache all it's frames based on all possible places it could fly that have different types of lighting. If it flies into a dark area with no light, you'd need to recall the sprites that correspond with that light level. It would be easier if the engine could change the sprite on-the-go to save you the trouble.

    Anyways, that's my take on it. You could certainly optimizing a software renderer to handle this smoothly but it will complicate your engine. You'd need to cache a lot which means higher memory usage and more complicated code. It's my personally opinion that it's ultimately much simpler to use hardware rendering. It's up to you what you want to do.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  22. #22

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    Thank you Niya Automata 2B for the detailed description.

    I use a Photoshop gradient sticker for the colour of light. I just select the pixel from it's band (per time of day). Darkness (black paint) is calculated per move, every move.
    Sky tone: https://www.dropbox.com/s/cvdormbyee...lours.png?dl=0

    I was planning on making other bizarre lighting for alternate dimensions and places, which would enhance the 'I’m not in Kansas anymore', effect on the user.

    That does sound incredible with hardware acceleration, I could certainly go to town with that, and not have to pull everything desirable out.

    I was trying to make the character ‘slip’ into a new square with in between frames at one stage, ie: nice transition from square to square, instead of one square then the other. But the CPU doesn’t like it and the caching code was certainly a mess. Sounds like hardware acceleration could handle it as well.

  23. #23
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Quote Originally Posted by -Corso-> View Post
    That does sound incredible with hardware acceleration, I could certainly go to town with that, and not have to pull everything desirable out.
    Yea, hardware acceleration would remove the need for caching strategies which greatly simplifies your engine design. How this doesn't mean that caching is a bad strategy for optimization. For simpler engines, it's definitely a good strategy but for something like what you're doing where you're rendering an entire environment with differing light effects like day, night, shadows, light fixtures etc, scrolling, movement and such, I think it will make the engine way too complicated.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  24. #24
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    another thing is multithreading.
    if u feel "its too hard", u can create 2 applications.
    both point at the same "hdc".
    one app, will only be the background
    another app, will be the main-game and the character.
    its not that hard to do.
    u could even have all the "UI" in different thread as well.
    again, not that hard to do really.

    if u want to stick with the method u are using instead of changing render-engine.

    also, sure u ignore my advice. but Im a game-dev. remember that.
    maybe not an expert like Olaf/Niha and all other, but when its gaming, I have been doing it for years.
    some credibility I have.

    and the different light of the day/night. u can use 1 layer that u render above everything.
    I do that with my game, I just render with different opacity levels. just using black (0,0,0) u make it darker
    using white (255,255,255) u want it lighter. and using (255,0,0) red, u will increase the red-color.
    so its all about finding the right rgb that fits.
    I mean, render something like that takes milliseconds. at least when I use gdialphablend.
    Last edited by baka; Feb 27th, 2023 at 04:53 AM.

  25. #25
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: Cairo Power?

    Personally, if I were doing anything where I wanted to rotate/zoom/pan with a camera in 3D space (which I've done with VB6), I'd never consider anything that wasn't GPU accelerated. And that doesn't even consider the fast handling of mesh objects and their UV texturing (which can also be nicely handled through GPU acceleration), keeping all that work out of our standard memory.

    The two options of which I'm aware for doing those things well are DirectX and OpenGL.

    But anyway, that's just my 2-cents.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  26. #26

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    Baka, Multi-threading wouldn't work in this case, as everything occurs after the user moves. Screen is redrawn, 'then' then overlays are placed over it. Parallel processing not required, sequential only. The UI isn't calculated either, it's on it's own sleepy layer.

    For lighting, I use the 'mathematical Photoshop' Overlay function (not the word, but the calculation set). It whitens whites and darkens darks, it saturates colours as needed too. It's a stunning effect that I use in art all the time.

    So much so, when I added the deep blue shift to night lighting it had my olfactory senses tingling, expecting to smell the dampness of the dark misty night. (True!) That's how profound overlay'ed visuals can be on sight. It makes anthill coloured rocks blaze in firey array of colours at sunset against a dark forest (just like being in the Aus Outback). Deserts become more stunning at dawn and day break. So, I also want to check out midday effects of overlay burning, light amplification to make it look like the user is in sweltering heat. Good Overlay effects seemingly prompt the brain to believe what our eyes see. It should look especially unreal when I use different overlay atmospheres in alternate dimensions with irregular coloured terrain. A Pandora's box of things to discover, besides just the game.

    You mentioned how you do it Baka, but using flat white doesn't work, that just adds mist. Same with red. Black is required though.

    I like the layered magic screens of Cairo, as I can work them exaclty like Photoshop, which is important to make 100% what I prototype to become 100% game-exact. It's just that they are slow at a certain point. The only reason my game is fast (for the moment) is because I only update a tiny segment of the screen currently, that changes when more characters are added or walking modes, or shading... So I'm fast approaching a point of dilemma
    Last edited by -Corso->; Feb 27th, 2023 at 03:40 PM.

  27. #27
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Quote Originally Posted by -Corso-> View Post
    For lighting, I use the 'mathematical Photoshop' Overlay function (not the word, but the calculation set).
    Are you performing the calculations on the pixels yourself for this or are you using a combination of blend options in Cairo to do it?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  28. #28

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    Niya, Cairo_Operator_Overlay & Black Paint (with night alpha level)

  29. #29
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    yeah. I dont know how cairo works here. I have only experience with gdi32/+ and direct2d.
    so, its hard to help out, that is why Olaf is the best suited for this.
    I can only give advice when its gdi/d2d as I have worked with that a lot.
    I dont like giving away too much to classes that I dont know whats going on behind the scene.
    but Im sure Olaf did a splendid job to make it as optimized possible. even so, I like to have everything raw.
    meaning, I do all the small things myself. creating a bitmap with everything on it and render it to screen.
    and we are talking 60+ frames per seconds with multiple layers, animations, monsters walking around, ui if called and more.

    right now I use "multi-threading" to play background music. since it can change during game-play. (and having 1 thread will result in a bit of freeze since it need to load and unpack) using an external.app. the game will not freeze. also used to take screenshot and a built-in word-checker. (since the game also have a editor-build it, in real-time)

    that is why I told u about multi-threading. if possible to add something that is not needed in the main-app, why not?
    now my game is a bit faster to load, between areas, since the music is loaded from another application. so its a win.

    I get it, now with all the work u have done its hell to start over. I have done that 3 times and I dont want to do it again.
    all the reason I started over was before of direct2d and some other solutions that made the game more smooth.

  30. #30
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Olaf says that Cairo uses SIMD vector instructions which is nothing to scoff at. It will yield significant performance boosts compared to non-vectorized algorithms. However, there are still limits. A vector register could only be so big. For example if we are being generous and say we have 256 bit vector registers, we can process 8 pixels simultaneously at a time which for modest applications is quite good. However, modern GPUs have thousands of cores which means it can process thousands of pixels at the same time.

    I suspect he is running into the limits of Cairo's capabilities as he adds more and more special effects. Now he has a choice to make, he can either start implementing caching strategies to take some load of the CPU or he can go for GPU rendering. In my opinion he should go for GPU rendering. Adding caching mechanisms to an already fleshed out engine can be quite a painful experience if your engine is fairly sophisticated. However, the downside is that he may have to spend a bit of time learning something like DirectX, OpenGL or some other library that wraps these APIs.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  31. #31
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    Re: Cairo Power?

    Draw only what needs to be redrawn...

    If you are stationary, as a player, while the background moves... Pre-render "zones", it's a one-time render, unless there is something IN that zone, which is also moving. Then you only have to "think about" new zones that are about to load, just out of view.

    O = Old (drawn and just blitted in new location, from a back-buffer)
    X = New zone, just drawn, now merging into the "shifted" back-buffer, one thin pixel seen at the border
    U = Unloaded zone that you just fell out of (FAR VIEW), never immediately unload a zone you just walked past, they may stop and turn around!
    P = Player

    Code:
    XXXXXXXXX
    UOOOOOOOX
    UOOOOOOOX
    UOOOPOOOX
    UOOOOOOOX
    UOOOOOOOX
    UUUUUUUUU
    In those MANY zones... You may have about 3-20 "things" moving around. Those individual cells have the "blank-cell-image", plus the "cropped alpha-blended layer" that is a mix of z-ordered stuff. (The "blank" used to restore the background after every refresh, before you start drawing the blended layers back above it, which you saved from the original RECT, before you started blending.)

    There was an awesome example of this called "Dancing santas" or something stupid like that. It used bitblt, but any form of drawing would work and gain from that method.

    This is as opposed to constantly trying to redraw "tiles" and the same static things, over and over. Including things that you can't even walk behind and have no real z-order, past the initial stack of drawing. (Like roofs over houses or tree-tops over tree-trunks, or paths across grass.)

    This is why you can use something like SetPixel with great speeds, in some instances. It returns the color that was originally in that location, after it draws the new pixel. Saving that, makes for an easy micro-effect "restoration" of a particle-effect, without needing a costly "alpha-blend" or huge data-chunk bitblt, or whatever.

    The action of simply "moving" a canvas, is faster than actually blitting a whole screen too. Having a motion "dead-zone" can help give pause to reduce lag. (A dead zone would be an area in the middle that does not cause background scrolling. Like in Zelda, or Mario, the screen stops moving if you stop pushing forward in a direction. You can walk back and the screen will not begin to move again, until you get past the dead-zone, in the other direction. (You can drift the user back into the center, when they are "pushing forward", and it won't feel odd. The second they stop pushing forward, the dead-zone kicks-in, slowly expanding, the more they stay in it. But if they start moving forward again, with the dead-zone only partially expanded, then the screen continues to move and they drift back to the center again. Or even counter-center, so they get a larger "forward view". (I think Ray-man and Earthworm-Jim did that. Maybe they just auto-zoomed out, when you started going faster?)

  32. #32

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    I used that method at one stage, that was how I tested the smooth transition mechanism too. But Cairo for some wierd reason was pushing the main image slightly off it's tracks until it hit the final spot. In the end, the speed performance wasn't anything to write about, even just jumping to the new spot, as all the characters and the materials in front of them had to be redrawn regardless (because characters move).

    I'm going to try something else soon, which is generate as many small surfaces as there are tiles on the screen. And treat each tile_surface like a planter box.
    Much like this.
    https://upload.wikimedia.org/wikiped...C_pot_rows.jpg

    It will use up a crap load of image space, but only new tiles need to be worked out and all tile_surfaces copied over to their new planter homes. I won't need to worry about drawing things in front of characters using this method, as all tiles will just be dumped onto the screen in sequence.... Though, it'll be spectacularly memory intensive....

    It won't be as quick as Mode 1, but I hope it'll work for Mode 2 and many characters on screen....

  33. #33
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    here is "parts" of my "gameloop"

    Code:
    Do While .Running = 0
            engine.Cls
            Do While .Running = 0
    the engine has 2 loops. one is internal and the other is external. so, if something happens, it will exit the inner loop, so I can "re-enter" the innerloop after "restart" procedure.
    .Running will take care of that. error- or if using any "quit" methods. automatic or manually.

    Code:
    Select Case .ui
                    Case 0 ' map
                        If Keys.Down Then MapMoveDown Ply.mm
                        If Keys.up Then MapMoveUP Ply.mm
                        If Keys.right Then MapMoveRight Ply.mm
                        If Keys.Left Then MapMoveLeft Ply.mm
                        If .Center Then MakeCenterMap
                        map_RenderBack
                        npc_render
                        mob_Render
                        map_RenderPortal
                        map_RenderFront
                        mob_FrontRender
                        npc_Bubbles
                        npc_FrontRender
                        map_OptionRender
                        Skills_Render
                        If .Tick = 0 Then SecondOption
                        map_MapLoading
                        engine.Rendering
                    Case 1 ' inventory
                        map_RenderBack
                        npc_RenderEx
                        mob_RenderNon
                        map_RenderFront
                        inv_Render
                        map_OptionRender
                        map_MapLoading
                        engine.Rendering
    if .ui=0 means it "freemode", u can move around, talk, kill, etc. if 1 the inventory is open.
    as u can see some functions are reused.

    Code:
    DoPeek
            Loop
            Select Case .Running
                Case 199
                    Stash.engine = 0
                    engine.Restart Stash.engine
                    .Running = 0
    after many different "ui" we get to the end of the inner-loop. and as u see I have a "DoPeek"
    this is used to control keys/mouse/paint etc. Im using PeekMessage only. I do not use any form_keydown or subclassing.
    and if something happens and u exit the loop. I can "restart" depending on the "code". 199 is restarting.

    so, in the innerloop we have many functions. tons of stuff, but the most important thing is that they "create" the bitmap.
    but the last one is engine.Rendering. and its only at that point I render the graphics to screen. and only using 1 area. only 1 picturebox.

    map_MapLoading is using for fadein/out and other effects.
    so, no matter whats going on, the game is always inside a loop. never exit.
    loading, showing windows, settings menu, fighting, checking inventory and other stuff.

    theres a little possible graphic work that I do. as I wrote before.
    I try to make everything "read" so I only need to do copy the pictures in positions.

    also u see If Keys.Down Then
    even the movement is part of the loop. so its not external, that can cause irregularities.

    not sure if this can help u at all.
    at least u know how I do things and maybe theres something u can use.
    Last edited by baka; Mar 1st, 2023 at 04:38 AM.

  34. #34

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    UI. The Cario widgets are all self contained classes. (Like their own form). They don't need to be re-drawn onto the screen, unless you are interacting with them. They don't affect game speed, the loop or anything. If the inventory is open, one can still walk around the map with it remaining open, or just push it to the side to interact with a watermellon (for pickup). They only need to be redrawn when you do a 'thing' with them.

  35. #35
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    the cario widgets are they in their own thread?
    if not they are affecting overall speed.

  36. #36

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    No Inventory window open: 3ms moves
    Inventory window open, taking up 3/4 of screen: 3ms moves

    They have no discernible effect on rendering, they are completely separate from the map.

  37. #37
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: Cairo Power?

    no matter. the widgets is not "idle", it will still render the window and the content. sure its fast. if nothing is changed.
    but it will still drain a bit the thread.

    everything u do takes power. all forms, pictureboxes, labels, everything is taking "a bit".
    and u need to understand the "paint" event.
    if u read peekmessage, u will see that kernel will send a paint-message to all .hwnd windows
    when something require a refresh. that will also take speed.

    I feel that u are just defending your cairo and how u made the game. but still u have issues. why did u make this post? do u want to learn and optimize your game at all?
    do u want to make it better or is this just discussion how good cairo is?

  38. #38

    Thread Starter
    Hyperactive Member -Corso->'s Avatar
    Join Date
    Oct 2021
    Posts
    379

    Re: Cairo Power?

    I don't really need to optimize the game (anymore) than what's already been tested and dumped. I'm no stranger to this stuff.

    The main issue is the mathematical colouring Overlays and lighting. The lighting effects make the game screen pretty, and "Pretty" is marketing, Having alternate dimensions and odd colored terrain enhances "Newness" through environmental discovery, and that keeps users enthralled.

    Cairo, yet, is incapable of handling realtime screen rendering for game speeds of specialized lighting for the above. But, it is superior for all the other little bits it has. Just lack of documentation.

    Which is why I asked at the beginning. GPU - CPU for Cairo.

    Direct2d has zero tutorials and info. It's been superseded by Direct3d which is a subset of DirectX. But I've read people would rather drink concentrated dish washing liquid than learn the horrid abyss that is DirectX. Considering it's dead for VB, and tutorials are missing, aged, blanked, it's not a very good option to switch to. I have tried to do what little tutorials there are regardless, they suck.

    PyCario may be the saving grace. I don't know if it's GPU enabled for it, but Python was on my agenda to learn. I don't want to migrate to Python, but that's pending more analysis.
    At the moment, Niya recommends hardware acceleration, I am inclined to agree.

    Optimizing the 'presentation' of the map is a nothingburger when the GPU kicks in.
    If there was anyway I could help make Cairo GPU enabled, I'd gladly join in, but it's solely Olaf's domain, so it's probably beyond most of us. Though, it'd be amazing to see Cario-VB-GPU speeds vs CPU.

    Anyway, the only thing I can do now, this minute is write code that abuses memory for speed, and that's a tomorrow job. I don't want to cut lighting, or have to learn Python, but we'll see what's best after some more testing and reading.

  39. #39
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Cairo Power?

    Yes, DirectX is quite intimidating. You have to figure out the boilerplate like setting up backbuffers, swap chains, vertices etc.

    There are a few DirectX experts here like baka and the trick who could probably help you get started if you're determined to use DirectX. I personally haven't touched DirectX in years but from what I remember it wasn't that hard to set it up in VB6 using dx7vb.dll or dx8vb.dll.

    You could also explore using the GPU yourself through something like OpenCL but you will have to write blending functions yourself as OpenCL kernels. OpenCL looks far less intimidating to learn that something like DirectX. There's also CUDA which from what I've seen is even easier to use than OpenCL but requires you have an Nvidia GPU.

    With CUDA and OpenCL you'd have to use another language like C to execute the kernels and expose it to VB6 as a standard DLL.
    Last edited by Niya; Mar 1st, 2023 at 08:00 AM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  40. #40
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    Re: Cairo Power?

    Hello Corso
    I want to try my hand at developing the basics of a similar graphics engine to see the difficulties involved and for exercise.
    I will be using RC6.
    I notice from the screnshots that you do not use "symmetrical" isonometry.

    I would like to know the dimensions and aspect ratio you use for tiles.

    For example, this is the most commonly used one:
    AC = 2* BD
    Code:
    '      B
    '   /     \
    'A           C
    '   \     /
    '      D
    What are the dimensions of your tiles and the distances along the X and Y directions of the vertices A B C D ?
    specifically:
    ACx = ?
    ACy = ?
    BDx = ?
    BDy = ?
    Code:
    '     B
    '   /  \
    ' /      C
    'A      /
    '  \  /
    '   D
    Thank you!

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width