1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

high performance world drawing functions

Discussion in 'Suggestions & Ideas' started by Shadowblitz16, Sep 30, 2017.

Tags:
?

do you think this is a good idea?

  1. yes

    6 vote(s)
    85.7%
  2. maybe

    1 vote(s)
    14.3%
  3. no

    0 vote(s)
    0.0%
Mods: Rainbows
  1. Shadowblitz16

    Shadowblitz16 Ballista Bolt Thrower

    Messages:
    158
    can the devs implement drawing functions for world map drawing?
    there is currently gui drawing functions but they are a little slow and do not scale according to camera or have depth to them.

    I have been trying to make a lightning projectile but it seems that alot of the things I need to do this don't exist
    [​IMG]
    things I have tried that do not work
    - drawing gui lines
    - drawing to multiple textures and creating particles out of them
    - drawing to a map sized texture and creating a particle out of it

    I suggest that the following be implemented..
    - draw_pixel(Vec2f pos1, u32 color)
    - draw_line(Vec2f pos1, Vec2f pos2, u32 color, u32 width)
    - draw_circleloid(Vec2f pos1, u32 sides, u32 size, u32 color, bool outline)
    - draw_ellipse(Vec2f pos1, Vec2f pos2, u32 color, bool outline)
    - draw_rectangle(Vec2f pos1, Vec2f pos2, u32 color, bool outline)
    - draw_triangle(Vec2f pos1, Vec2f pos2, Vec2f pos3, u32 color, bool outline)
    - draw_poly(Vec2f[] poses, u32 color, bool outline, bool closed)
     
    Last edited: Sep 30, 2017
    Osmal and Vamist like this.
  2. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    I wouldn't be surprised if GUI was slow, I've already seen quite a few HUD scripts and rendering in general take a relatively large part of the CPU time. Generally you will want to avoid GUI functions for anything that isn't GUI.
    Can you define "not work"?
    Using sprite layers seems to be the smart way to do it, because you can use render styles over them: CSprite::setRenderStyle and CSpriteLayer::setRenderStyle, see Enums.txt at line 310 for the available render styles. I'm also pretty sure this is what the Wizard Wars mod uses (and it looks superb).
     
  3. Shadowblitz16

    Shadowblitz16 Ballista Bolt Thrower

    Messages:
    158
    thankyou @Asu
    sprite layers I'm sure won't work since there is alot of points and lines involved a single lightning spell casts 4-7 lightning bolts which travel until they reach the end of the map of a solid tile or blob
     
  4. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    I'd actually be ok with some sort of world-space triangle rendering being implemented; textured and untextured, and probably 2 uv-scale versions (0-1 and pixel-sized), from arrays of vertices and probably optionally indexed. I'd be ok with a simple "quads" API but it'd still be triangles under the hood; it'd just handle quad indexing for you to avoid duplicating verts.

    No lines or pixels or whatever shapes; you can (and we'd have to internally anyway) implement those with triangles or quads.

    It's never going to be particularly high performance as I'm not interested in exposing low level graphics primitives (gpu buffers etc) directly, at least not at this stage, but I think wanting to be able to implement your own sprite or tilemap is "fair enough". The efficiency would be roughly proportional to how many tris you render at one time.

    Would allow you to totally bypass the sprite system if you wanted for mods as well.



    As for what you're doing with lightning bolts

    It sounds and looks like it could be done with sprites. Look at how the grappling hook draws its rope between 2 points.
    Drawing to a map sized texture is insanity; drawing to smaller 32x32 or so chunks would "probably work" but I would probably avoid updating too many textures every frame if I could help it.
     
  5. Shadowblitz16

    Shadowblitz16 Ballista Bolt Thrower

    Messages:
    158
    @Geti that would be fine if it didn't look awful when you connected the rotated lines
    take a close look at this the lines. the second one does not connect seamlessly it has gaps in the corners where the overlapping is not perfect. this is what it would look like if I did rotated sprites
    [​IMG]

    I would need draw line functions so that I can draw the lines with perfect connection like on the left
    drawing to chunks still probably wouldn't work because of blitting pixels one by one which takes alot of time. also I have no idea how to do chunk drawing.

    world drawing would solve all of these issues. and would make things like this so much easier.
     
  6. JaytleBee

    JaytleBee Ballista Bolt Thrower
    1. [Server] Sandbox Reborn

    Messages:
    117
    PLEASE PLEASE PLEASE PLEASE PLEASE
     
    Achillios, blackjoker77777 and Osmal like this.
  7. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    I now understand a little better what the problem is. I was messing a bit around with a progress bar and was never quite happy with the result, because of camera scaling and such.

    Anyway. It seems for now, the idea about using sprites seem to be the only way to go. Instead of rotating sprites, you could manually (or programmatically) create your sprites for a set of fixed angles, and swap accordingly. That way you'll avoid gaps and antialising issues. You'll have to draw it yourself. You could possibly get away with just drawing the joints. Sounds like a lot of work though.

    Some basic world drawing would be nice, I guess. I don't suppose it would be possible to open up all the existing gui stuff also for world drawing? Technically, it shouldn't be so different?
     
    Last edited: Oct 15, 2017
  8. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    I honestly probably wouldn't provide "copies" of the gui rendering code engine side. You could freely re-implement them on your own as a reusable library if you were so inclined.

    The reason the GUI stuff is in screen space is that it's for drawing GUI, not for drawing stuff in the world.
     
  9. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    For things like the HUD, that is certainly the case. And for most menus and stuff, it is sufficient with a reference point from the world. But, some elements, such as progress bars follow world objects more than the rest of the GUI. Since they are part of the screen space, they don't scale with the zoom, and end up looking bad. As it is now, if you're not happy with it, you'll have to add some sprite layers and stuff, which is cumbersome.
     
  10. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    I'm personally happy with progress bars being in screenspace instead of world space, but I understand wanting the option :) Either way, it'd be doable to write up equivalents to all the gui functions using any world-space drawing functions that end up happening.
     
Mods: Rainbows