scale(5) { img.draw 0, 0, 0 }
has completely different performance characteristics than img.draw 0, 0, 0, 5, 5
. Transforms work best if they contain a lot of (Z-adjacent) operations as they push and pop OpenGL matrices. The draw
parameters work best to draw lots of images with different sets of parameters. The way they are currently being used is just right IMHO (on this board, anyway), and I'd like the keep the separation in principle.draw
parameters are terrible :( I've always wanted to come up with a very lightweight interface like image.rotate(5).scale(2).draw(x, y[, z])
, and I think it can be implemented at negligible overhead in C++. Ruby could use keyword args instead.pushZPos
/popZPos
are error prone IMHO, I'm planning to change the Gosu calls to something like scale(5, []{ ... }
soon, in beautiful symmetry with Ruby. Yay C++0x!
>I've always wanted to come up with a very lightweight interface like image.rotate(5).scale(2).draw(x, y[, z]), and I think it can be implemented at negligible overhead in C++. Ruby could use keyword args instead.
image.draw(Rotated(5), Scaled(3,7), LowerLeftCorner(x, y), ZPos(z));
100/double(image.width())
)>These solutions as well as the one you are proposing can be implemented 100% on top of Gosu, so considering how distracted I've been in the last months, it's likely that someone else would have time for experimentations and benchmarks before I do... :)
> such an interface would require every image instance to have it's own member values for rotation and scale
image.rotate(5)
would not modify the image (immutability ftw) - it would create something like an ImageDrawParameters
that might consist of a 2x2 matrix or four points, four colour values and an ImageData
pointer. Each method call on ImageDrawParameters
would create a new temporary object, and ideally this could also be optimised away, until it is only image.drawWithImageDrawParameters(...)
.ScaleAbsolute
would be great though. For some reason I've never thought about writing a wrapper for that operation.draw(rotate(scale(image, ...), ...))
, yuck! :(
image.draw("scale_x"_fpar = 1.5);
, but sadly c++11 doesn't allow templates to process string literals, only numeric literals are allowed :(
#include <iostream>
#include <type_traits>
template<typename T>
struct Par
{
T val;
Par& operator=(T& v)
{
val = v;
return *this;
}
};
template<typename T, typename T2>
constexpr bool isOneOf(T t, T2 first)
{
return (t == first);
}
template<typename T, typename T2, typename... Args>
constexpr bool isOneOf(T t, T2 first, Args... rest)
{
return (t == first) || isOneOf(t, rest...);
}
template<char c, char... rest> Par<double> operator "" _fpar()
{
static_assert(isOneOf(c, 's', 'a'), "invalid parameter name");
switch (c) {
case 's':
return Par<double>();
break;
case 'a':
return Par<double>();
break;
}
}
int main()
{
std::cout << ("angle"_fpar = 46.3).val << std::endl;
return 0;
}
draw((DrawArgs){ .angle = 5 })
image.draw(5_angle)
(omg the namespace pollution...)
image.draw(90_degrees, 1.3_scale_x, 100y, 50x, 10z, 0xFF0000_col)
image.draw(Angle(90_deg), Scale(1.3, 1), Pos(100, 50, 10), Color(0xFF0000))
image.draw(Pos(100, 50, 10), ZPos(30))
will draw at 100,50 with zpos 30image.draw<Angle(90_deg), Scale(1.3, 1), Pos(100, 50, 10), Color(0xFF0000)>()
image.draw(Angle(90_deg), Scale(1.3, 1), Pos(100, 50, 10), Color(0xFF0000))
Image::draw(x, y, z, …)
. Image::draw(...)
now simply calls Image::draw(0, 0, 0, ...)
class Test : public DrawModifier
{
public:
void apply(double&x, double&y, double&z, Color& c1, Color& c2, Color& c3, Color& c4, double& factorX, double& factorY, double& angle, double& centerX, double& centerY, AlphaMode& am)
{
x+=10;
}
};
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill