Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - TomasRiker

Pages: [1]
1
Feature requests / Tabs in sf::Text and another suggestion
« on: December 19, 2009, 12:30:32 am »
For now there may only be this issue, but I guess there will be more. Basically this way of handling resources can often prevent you from caching things and thereby improving performance because some resources might change during their lifetime.

2
Feature requests / Tabs in sf::Text and another suggestion
« on: December 18, 2009, 09:29:05 pm »
Quote from: "Laurent"
They all still use operator=. We can't make immutable classes in C++. It works great in managed languages like C# (and that's what SFML.Net uses), but in C++ that would mean restricting the usage of resources to pointers only, which is not a good idea ;)

Why not make operator= private?
Most other libraries give access to a resource only via pointers, preferrably smart pointers. I think there's nothing wrong with that, as resources are usually "big" datatypes which you don't want to pass around anyway.

3
Feature requests / Tabs in sf::Text and another suggestion
« on: December 18, 2009, 07:04:31 am »
Quote from: "Laurent"
However your idea doesn't work: if the font changes, the text doesn't know about it and cannot update its positions. So it cannot be cached. I guess that all I can do is refactoring the code.

That's a problem indeed. The only way a font can change is when you call LoadFromFile, LoadFromMemory or operator= on it, right? Maybe it would be better if the Load methods were static or implemented as constructors or even provided my some resource manager. Resources would be "immutable" then, once created they would never be replaced by another one. Then you wouldn't have this problem.

4
Feature requests / Tabs in sf::Text and another suggestion
« on: December 17, 2009, 10:45:33 am »
In the current implementation, the tab size in sf::Text is always 4 times the width of a space. But the space added doesn't depend on the current cursor position as it is in "real" tabs.
I'd like to be able to set the tab size using SetTabWidth or something (default tab size can still be 4 * width of space). And the actual space should take the current cursor location into account.
I can provide a sample implementation for that.

I tried it like this and it works:

Code: [Select]
// Initialize the rendering coordinates
(...)
float tabSpace    = space * myTabSize;
(...)

        // Handle special characters
        switch (curChar)
        {
                (...)
                case L'\t' : x = tabSpace * static_cast<int>((x + space + tabSpace) / tabSpace); continue;
                (...)
        }


myTabSize is a new member variable that stores the tab size, in number of spaces.

Also, when looking at the source, I saw that essentially the same logic is there three times: once in GetCharacterPos, then in Render and finally in RecomputeRect. It would be easier to maintain the code if sf::Text used a std::vector of character positions. Then GetCharacterPos would need only O(1) time and Render could just use the vector to draw the characters at the appropriate position.

5
Feature requests / Proposal for Vector2 and Vector3 operations
« on: December 17, 2009, 10:32:02 am »
Hello,

I know this has been discussed before, and Laurent's last comment on it was (as far as I know) that it is on the roadmap, but he hasn't found a solution yet that he likes.

The proposal is to add VectorDotProduct (for 2D and 3D), VectorLengthSq (for 2D and 3D) and VectorCrossProduct (for 3D only). These functions are "safe" because they can use the same type for their result as used in the vector. VectorLength would be a bit tricky because a the length of a Vector3i should not be an integer, and what would happen when the user instances the Vector template with a custom type that SFML can't possibly know in advance?
The proposed solution still allows the user to call VectorLengthSq, cast accordingly and then call sqrt or whatever function. Also, it makes you think if you really need the length or if the squared length (faster to compute!) would suffice, like when comparing distanes.
For some built-in types SFML could provide a VectorLength function (float, double, ints).

However, these three functions mentioned are safe in this aspect.
This is how it could look like.

I know it's trivial, but it should be done at some point! ;)

Vector2.hpp:
Code: [Select]
////////////////////////////////////////////////////////////
/// \brief Vector dot product
///
/// This function computes the dot product of two vectors.
/// It is defined as the sum of the memberwise products.
/// When the result is zero, it means that the vectors point
/// into perpendicular directions.
///
/// \param left  Left operand (a vector)
/// \param right Right operand (a vector)
///
/// \return The dot product of \a left and \a right
///
////////////////////////////////////////////////////////////
template <typename T>
T VectorDotProduct(const Vector2<T>& left, const Vector2<T>& right);

////////////////////////////////////////////////////////////
/// \brief Vector squared length
///
/// This function computes the squared length of a vector.
/// If the true length is desired, take the square root.
///
/// \param vec The vector
///
/// \return The squared length of \a vec
///
////////////////////////////////////////////////////////////
template <typename T>
T VectorLengthSq(const Vector2<T>& vec);


Vector2.inl:
Code: [Select]
////////////////////////////////////////////////////////////
template <typename T>
inline T VectorDotProduct(const Vector2<T>& left, const Vector2<T>& right)
{
return (left.x * right.x) + (left.y * right.y);
}


////////////////////////////////////////////////////////////
template <typename T>
inline T VectorLengthSq(const Vector2<T>& vec)
{
return (vec.x * vec.x) + (vec.y * vec.y);
}


---

Vector3.hpp:
Code: [Select]
////////////////////////////////////////////////////////////
/// \brief Vector dot product
///
/// This function computes the dot product of two vectors.
/// It is defined as the sum of the memberwise products.
/// When the result is zero, it means that the vectors point
/// into perpendicular directions.
///
/// \param left  Left operand (a vector)
/// \param right Right operand (a vector)
///
/// \return The dot product of \a left and \a right
///
////////////////////////////////////////////////////////////
template <typename T>
T VectorDotProduct(const Vector3<T>& left, const Vector3<T>& right);

////////////////////////////////////////////////////////////
/// \brief Vector cross product
///
/// This function computes the cross product of two vectors.
/// The resulting vector is perpendicular to both vectors.
///
/// \param left  Left operand (a vector)
/// \param right Right operand (a vector)
///
/// \return The cross product of \a left and \a right
///
////////////////////////////////////////////////////////////
template <typename T>
Vector3<T> VectorCrossProduct(const Vector3<T>& left, const Vector3<T>& right);

////////////////////////////////////////////////////////////
/// \brief Vector squared length
///
/// This function computes the squared length of a vector.
/// If the true length is desired, take the square root.
///
/// \param vec The vector
///
/// \return The squared length of \a vec
///
////////////////////////////////////////////////////////////
template <typename T>
T VectorLengthSq(const Vector3<T>& vec);


Vector3.inl:
Code: [Select]
////////////////////////////////////////////////////////////
template <typename T>
inline T VectorDotProduct(const Vector3<T>& left, const Vector3<T>& right)
{
return (left.x * right.x) + (left.y * right.y) + (left.z * right.z);
}


////////////////////////////////////////////////////////////
template <typename T>
inline Vector3<T> VectorCrossProduct(const Vector3<T>& left, const Vector3<T>& right)
{
return Vector3<T>(left.y * right.z - left.z * right.y,
 left.z * right.x - left.x * right.z,
 left.x * right.y - left.y * right.x);
}


////////////////////////////////////////////////////////////
template <typename T>
inline T VectorLengthSq(const Vector3<T>& vec)
{
return (vec.x * vec.x) + (vec.y * vec.y) + (vec.z * vec.z);
}

Pages: [1]
anything