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.


Topics - gsaurus

Pages: [1] 2
1
Network / Dynamism at Packet class again
« on: October 13, 2011, 07:55:48 pm »
I find sf::Packet not dynamic enough.

There is a public Append function to append any number of bytes from a void*, but the reverse operation isn't provided, making this function quite useless: There isn't a good way to read some number of bytes into an array.

We may say: Packet is for structured data only, there is no need to mix unstructured data with structured one. In this case Append shouldn't be public to start with. Though there are situations where it may be useful. Examples are image bytes and sound samples, but even assuming that we can stream them directly through Packet ojects (which we currently can't), there are other sistuatios. Some silly example may be transferring information of a tile-set based level to other peers that doesn't have it yet, the level may have some structured information like name and other properties, and a matrix of bytes (because there are no more than 256 tiles for instance). It makes sense to append the whole array at once instead of one cell at a time, because it will avoid unnecessary resizes of the internal vector of Packet, and many internal calls to memcpy.


Example:
Code: [Select]

// Write
char* myData = ... ;
std::size_t myDataSize = ... ;
// write some structured data before, like a header
packet << ... ;
// write some unstructured data
packet.Append(myData, myDataSize);
// write some more structured stuff
packet << ... ;

(...)
// Read
// Read some structured data before, like a header
packet >> ... ;
// read some unstructured data
???
// read some more structured stuff
packet >> ... ;


The first alternative that comes to mind is to use GetData() + offset, and do a memcpy to our array. The first possible obstacle is the need to compute the offset, i.e. the number of bytes of structured data already read, since there isn't a function to obtain the reading position.
The second obstacle can't be overpassed: after obtaining our unstructured data, there is no way to move the reading position of the packet, to read the structured data that comes next.

The second alternative that comes to mind is to only use raw data. Then we don't need a Packet, we send/receive directly from/to char* on the socket, but we must re-implement the structured streaming just like on Packet.

-------------------

A different possible problem is when we want to send the same data to many peers, only differing in few bytes (like header information). With packet we need to copy the whole information for every peer because we don't have random access to modify the header.
The silly workaround is using a packet object just to build up the serialized data and copy it only once into a byte array, leaving space at the beginning for the header. For every peer we use another packet to build the header, copy the resulting data into the beginning of the byte array. Finally we send the byte array directly through the socket.


This is one reason (but not the main one) of why I asked in some other topic about InputStream and OutputStream classes for data serialization, in replacement of sf::Packet, which is tied to the network.
Currently Packet can still be used as a serialization tool, even that it is not supposed to. We can serialize our structures into a packet, use GetData to obtain the serialized data and save it to somewhere else (ex: a file). And one can fill a Packet with data from somewhere else (ex: file) by using the Append function, and then use the >> operators to deserialize the information into our structures. This is silly, but is an alternative to creating our own Input/Output stream classes or using other serialization system.

True generic streaming may be too much for SFML, but instead of Packet we could have had a class to serialize/deserialize data to/from a byte array for example, pretty much like how Packet class currently works.
In particular, sockets could receive an OutputStream when Sending, and provide an InputStream when receiving, so it works exactly as Packet did, we just untied the serialization functionality from the network package.
This is different from the current InputStream, but it could be combined/merged somehow.


Sorry for the long post and for insisting on this, but whenever I start coding with SFML I feel like having to do many workarounds for things that were supposed to be simple, or for things that I feel being partially supported. I don't feel like using other more complex and specialized tools, because things like basic serialization is provided, it's just that it's tied to the network.

2
Network / timeout when receiving
« on: September 04, 2011, 09:04:42 pm »
When a (Udp)Socket is on blocking mode, is there a way to set a timeout when receiving?
The only way I currently see is using a SocketSelector around it to wait with a timeout.

3
SFML projects / Open Spriter
« on: July 17, 2011, 01:47:39 pm »
Aims:
  • Provide developers with a standard cross-platform and cross-application format for 2D sprites (osf file format).
  • Provide artists with a GUI tool to create sprites
So basically the idea is that people make sprites on a GUI, mainly by importing images and defining animations, and developers just load and use the resulting files. People can share sprites to be used on games, etc.

Planned for first version
  • Static frames - each one is an image with an origin. Frames can be stored either as discrete images or as a tileset.
  • Layered frames - each one is composed by several static frames (layers), each layer can have geometric transformations (translation, rotation, scale)
  • Animations - each one is composed by either static and/or composed frames. Each animation frame has a delay in milliseconds (unsigned int)
  • Support for indexed color images and palette swaps.
  • Save/load to/from file, from memory etc
  • Compression and encryption
The last two features are from Codex.
The layered frames are optional, can be used for .

Sometime I'd like to support frames based on text, shapes/SVG, not just images, maybe one day..


Currently I'm working on a core abstract lib, and a binding for SFML. I should be releasing a first build soon so I can have your feedback and help.
Bindings for SDL etc should be easy to create but I don't plan to do it myself.

Currently using an existing sprite looks like this:
Code: [Select]
osf::SpriteResource resource;
resource.loadFromFile("MySprite.osf");
osf::Sprite sprite(resource); // inherits from sf::Sprite, so you can move, rotate, etc
...
// set sprite to static frame number 10
sprite.setFrame(10);
...
// set animation with the key 31.
sprite.setAnimation(31);
...
// update animation (time passed in milliseconds
sprite.update( window.GetFrameTime() );
...
// set animation progress to 30%
sprite.setProgress(0.3f);



The GUI will probably have to wait, or if someone want to volunteer for it it would be cool too. I did a prototype some months ago (it's not compatible with the new format)


Please let me know what you think of the idea and if you think people would use it  :wink:

4
General discussions / Naming conventions - functions
« on: July 12, 2011, 09:46:16 pm »
Is there any specific reason for functions in SFML to start with uppercase?
I think that starting with lowercase is a more widely used convention.

http://geosoft.no/development/cppstyle.html

5
Feature requests / Drawable::Flip / Negative scale
« on: July 10, 2011, 11:46:42 am »
Laurent, have you found why you restricted scaling to positive values already?

Code: [Select]
if (factor > 0)
could have been:
Code: [Select]
if (factor != 0)
That or FlipX/FlipY methods on sf::Drawable

Sorry to ask again but passed a long time :wink:

6
General discussions / workaround for Drawable::FlipX, Drawable::FlipY
« on: October 15, 2010, 10:34:51 am »
If someone needs it, here's my workaround to make drawables being flippable. I did it months ago.. I should have kept copies of the matrices, but it was just a quick workaround to test some stuff.
With that I was able to flip shapes, text, and my own drawable classes, like drawable trees.


Code: [Select]
#ifndef INVERSIBLE_DRAWABLE_HPP
#define INVERSIBLE_DRAWABLE_HPP

#include <SFML/Graphics.hpp>


namespace gm2{
// Note: T inherits from sf::Drawable
template<class T>
class InversibleDrawable: public T{
 public:


     // default constructor
     InversibleDrawable():
         T(), myFlipX(false), myFlipY(false)
     {
         // Nothing to do
     }

     void flipX(bool flipX){
         myFlipX = flipX;
     }

     void flipY(bool flipY){
         myFlipY = flipY;
     }

//TODO:
//        sf::Vector2f TransformToLocal(const sf::Vector2f& point) const;
//        sf::Vector2f TransformToGlobal(const sf::Vector2f& point) const;

private:

     // render method
     void Render(sf::RenderTarget& target, sf::Renderer& renderer) const{

         if (myFlipX || myFlipY){

             sf::Matrix3 tmp;
             float rot = T::GetRotation();
             sf::Vector2f origin = T::GetOrigin();

             // Revert origin and rotation
             tmp.Transformation( origin, sf::Vector2f(0,0), rot, sf::Vector2f(1,1));
             tmp = tmp.GetInverse();
             renderer.ApplyModelView(tmp);

             // Apply flip
             tmp.Transformation( sf::Vector2f(0,0), sf::Vector2f(0,0), 0, sf::Vector2f(myFlipX?-1:1,myFlipY?-1:1));
             renderer.ApplyModelView(tmp);

             // Apply origin and rotation on the f
             tmp.Transformation( origin, sf::Vector2f(0,0), rot, sf::Vector2f(1,1));
             renderer.ApplyModelView(tmp);
         }

         T::Render(target,renderer);
     }
       
private:

     // our flip flags
     bool myFlipX, myFlipY;


};

typedef InversibleDrawable<sf::Sprite> InversibleSprite;
typedef InversibleDrawable<sf::Shape> InversibleShape;
typedef InversibleDrawable<sf::Text> InversibleText;

}  // namespace gm2

#endif // INVERSIBLE_DRAWABLE_HPP

7
Feature requests / ConvertCoords from one view to another
« on: September 25, 2010, 01:53:33 pm »
RenderTarget has a ConvertCoords to convert from target coordinates to View coordinates, but not the reverse operation, and I'm needing it.

I'm doing an editor which has a zoom functionality that zooms the entire view, so everything on that view get intentionally pixelized with close zoom. But I have to draw non pixelized objects too, for example a text legend over something. For that I use the default view, and need to convert some view coords to screen coords.

In general, we're talking about coords conversion between any two views. That may be a function of sf::View. Receiving the coords and a view,  converts those coords to the other view.

8
Graphics / Graphical operations in a thread
« on: September 13, 2010, 05:35:00 pm »
Hi,

My images loading code was working fine, until I put a thread doing the job.
Here is the minimal code:

Code: [Select]

class ThreadProblems : public sf::Thread{
private:
    void Run(){
        unsigned int width = 150;
        unsigned int height = 100;
        sf::Uint8 pixelsData[width*height*4];
        sf::Image img;
        img.LoadFromPixels(width, height, pixelsData);
    }
};

int main(){
    ThreadProblems t;
    t.Launch();
    t.Wait();
}



std::cerr:

Quote
An internal OpenGL call failed in Image.cpp (549) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (624) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (630) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (631) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (632) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (633) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (634) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (635) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (636) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (637) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
An internal OpenGL call failed in Image.cpp (758) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state


What's happening here?  :?

9
Graphics / [SFML 2] Shaders
« on: June 11, 2010, 05:49:43 pm »
Well I have a few questions about Shaders on SFML 2

1 - PostFX was applied to the screen, now Shaders are applied to drawables when drawn on a RenderTarget. This is great, but is it still possible to apply shaders to the current state of the screen as before?
This may be explained somewhere but I didn't find it.

2 - I can only apply one shader to a drawable, right? Shaders can't be applied one after another on the same drawable (on 1.x it was possible to apply several PostFX on the screen).

10
SFML website / topics read
« on: April 17, 2010, 04:15:40 pm »
When I read topics with "new posts" (), for some reason they aren't being updated to "no new posts" (), and I have to use the "mark topics as read" instead.

This includes my own posts, threads are marked as having new posts when I post.

11
Graphics / Graphics\Rect.hpp - package location
« on: March 13, 2010, 12:56:47 pm »
I think Rect should be part of the System package instead. It's an utility like Vector2/3 (and like other shapes and geometric concepts that I guess will come on SFML2, independent of the drawing stuff).

I'm using a model-view-controller approach, I use Rect on my model but I would like to keep model not linking to sfml-graphics  :wink:

12
Graphics / [SFML 2] explicit Bind?
« on: February 23, 2010, 12:51:29 am »
I'm finally trying sfml2.
By accident, I got a sprite being drawn in white instead of it's original image.




I reproduced it this way:

Code: [Select]
#include <SFML\Graphics.hpp>

int main(){
    sf::RenderWindow App(sf::VideoMode(200, 200, 32), "press key for white picture!");

    sf::Image img;

    while (App.IsOpened()){
        sf::Event Event;
        while (App.GetEvent(Event)){
            if (Event.Type == sf::Event::Closed) App.Close();            
            if (Event.Type == sf::Event::KeyPressed){
                img.LoadFromFile("paddle_right.png");
            }
        }

        App.Clear();
        App.Draw(sf::Sprite(img));
        App.Display();
    }

    return EXIT_SUCCESS;
}


The image is from the pong example.
The same code works with SFML 1.6.
Calling img.Bind() after loading solves it. Am I supposed to explicitly call Bind?

13
Graphics / a tree of geom transforms
« on: February 12, 2010, 04:23:30 pm »
I just wanted to make sure this is right.

I want to render a composed object by applying a tree of 2D geom transformations before rendering the leafs (like on VRML, openGL, etc, but only using SFML).
So I'm going to extend a class from Drawable that owns other drawable objects. On the render function I call the draw of the children drawables.
The leafs are sprites, text, etc.
This will work just perfect, right?

14
Feature requests / sf::Image::SaveToMemory
« on: February 09, 2010, 01:01:23 pm »
There is a LoadFromFile, loadFromPixelsPtr and LoadFromMemory.
There is a SaveToFile, GetPixelsPtr, but no "SaveToMemory" method.

I use my own file protocols, saving and loading images along with other data in the same file. I can load them with loadFromMemory, but I can't save them that way. I have to use GetPixelsPtr to send it to a (file) stream, and loadFromPixelsPtr when loading.
But I guess load/save from/to file/memory uses specific image format compression, and so, better than saving the pixels full data.
A SaveToMemory should receive an indication about image format (png, jpg, etc)


I have another question:
 - When using LoadFromPixelsPtr, do I have to keep my pointer and free it when the image isn't in use anymore? I would like to just send the pointer to sf::Image and let it take care of it, as I don't need the pointer for anything else (but better would be using the Load & SaveToMemory instead :P)

Thanks,
G

15
SFML projects / [Suggestion] generic network game layer
« on: January 11, 2010, 09:44:25 pm »
SFML network support is very good: OO, simple, clean and all. But it only has what is reasonable for a multimedia library (I think).

I would like to suggest to someone do a quite generic network layer over SFML, handling all the client/server communication stuff (messages, losses, ordering..), server failover, lobby support, etc. Just like other libs like Grapples does, but using SFML.
It's a common need on netplay games, so I think it would be of great use for many SFML users.  :wink:


Networks isn't my best area, but I plan to add netplay support for my SFML project EvE. So I'm trying to decide if I go with a library like Grapples, or I try myself codding with SFML network layer (or ask someone to do a generic support to be used in whatever SFML networking game projects would need it, like EvE :) :oops:)

Hope this is not off-board

G

Pages: [1] 2