Opened 16 years ago

Closed 16 years ago

Last modified 2 years ago

#8422 closed patch

Common line-drawing function

Reported by: eriktorbjorn Owned by: fingolfin
Priority: normal Component: Graphics
Keywords: Cc:
Game: Broken Sword 2


The Broken Sword 2 engine has always had a line drawing function. It would be nice if this could be made a common function so that other engines (e.g. GOBLINS) could use it as well. I just rewrote the function to make this kind easier; the patch simply moves that new function.

Since each engine has its own ideas of how to draw to the screen - particularly if they handle screen dirtying - the function works by using a callback to plot each individual point.

The patch changes the BS2 engine to use the new function.

I'm not sure if util.cpp is the appropriate place for it. It doesn't fit in the graphics directory, though, since it doesn't actually do any drawing on its own.

Ticket imported from: #1186744. Ticket imported from: patches/527.

Attachments (2)

drawLine.diff (3.8 KB ) - added by eriktorbjorn 16 years ago.
Patch against an April 20 CVS snapshot
drawLine2.diff (6.1 KB ) - added by eriktorbjorn 16 years ago.
Patch against an April 23 CVS snapshot

Download all attachments as: .zip

Change History (11)

by eriktorbjorn, 16 years ago

Attachment: drawLine.diff added

Patch against an April 20 CVS snapshot

comment:1 by sev-, 16 years ago

Also SAGA engine draws lines and currently features its own implementation. So it will benefit from common code as well.

Though in my opinion this functions perfectly fits in graphics/surface.cpp along hLine and vLine primitives.

comment:2 by eriktorbjorn, 16 years ago

The difference is that, at least in its current incarnation, my drawLine() does not draw on a surface.

With at least BS2 I want to know which pixels are plotted, because that allows me to mark only the parts of the screen that are actually covered by the line as dirty, rather than putting the line inside a rectangle and dirty the whole thing.

Of course, I could get the same effect by drawing the lines on a transparent surface and copy that to my image, but that seems pretty awkward to me.

comment:3 by fingolfin, 16 years ago

Erik, that makes some sense, but I'd still put it into the graphics/ directory. While it is generic, people still will think about it as a graphics function, won't they?

Oh, and maybe add a "line" method to Graphics::Surface, which calls your generic drawLine() :-)

by eriktorbjorn, 16 years ago

Attachment: drawLine2.diff added

Patch against an April 23 CVS snapshot

comment:4 by eriktorbjorn, 16 years ago

Here's an alternative version of the patch that puts drawLine in the graphics sub-directory, in a newly created primitives.cpp file. How does that sound?

comment:5 by sev-, 16 years ago

Again, it would be nice to implement Surface::line() method which will use this function to actually draw over Surface. Otherwise it looks nice.

comment:6 by eriktorbjorn, 16 years ago

Maybe so, but it's hardly a vital feature of this patch, which was just to add the generic line-drawing function. (Yes, it does patch the BS2 engine, but that's mostly because it's moving the function from there to a common directory.)

I figured that making use of the function was something that could be done gradually if the patch was accepted.

And besides, I couldn't get it to compile. :-)

(All this "const" stuff is giving me a headache. I take it that using "this" from within a struct is not quite the same as using it from within a class...?)

comment:7 by fingolfin, 16 years ago

Owner: set to fingolfin
Status: newclosed

comment:8 by fingolfin, 16 years ago

The patch is fine, I simply forgot to check it in earlier.

Using "this" from inside a struct and inside a class shouldn't be different. In fact, classes and structs are (almost) completely identical, the only differenc is that in a class, everything is "private" by default and in a struct, everything is "public".

OTOH, "const" qualifiers on methods and structs/classes of course do have an impact, I'll be happy to answer any questions you may have about that :-)

comment:9 by digitall, 2 years ago

Component: Graphics
Game: Broken Sword 2
Note: See TracTickets for help on using tickets.