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 - hayer

Pages: [1] 2 3 4
1
Graphics / Re: 'Slow' performance - what am I doing wrong?
« on: May 28, 2014, 09:35:32 pm »
Jeez, Nexus.. I was looking at Thor and was about to edit my post with; "Or I could grab Thor and use that. Well, guess I'll try out Thor then.

The main reason I asked was because I don't know how well the transformations should be handled. Like, I can figure it out, but I'm not always sure I get it a 100 per-cent correct.

Well, I guess I'll try looking at resource caching and see if that improves performance.


Thank you all for fast and very useful replies  :)




Edit: Just for testing; changed the sf::Texture to sf::Texture* in the Mesh class.. Now it uses 0.0002 sec per frame, in debug. Btw; how is SFML for drawing on a terminal server to clients? Like Windows Server 2008? I suddenly got the idea of implementing a renderer for work that uses SFML and the other one uses.. GDI+    :-\

2
Graphics / Re: 'Slow' performance - what am I doing wrong?
« on: May 28, 2014, 09:28:24 pm »
MeshCollection.add copies the texture argument. Then you copy it again when you store it inside the Mesh. That's a terrible idea, especially since it's all the same texture data in the end. And it would not only help to improve the loading time, but also the drawing performances because you would not make OpenGL switch to a different texture at every draw call.

So I should implement some sort of resources loader  that will;

1. User askes for "Assets\32x32_red.png"
2a. If not loaded, load it
2b. Its loaded, do nothing
3. Return a shared pointer to it

?

3
Graphics / Re: 'Slow' performance - what am I doing wrong?
« on: May 28, 2014, 09:19:21 pm »
have you used valgrind to profile your code?
did you use releasemode?
have you turned your debugger off?
are all optimizations turned on in your compiler?

what is this loop doing:
for (int x = 0; x < debugsize; x++)
   {
      for (int y = 0; y < debugsize; y++)
      {
         MeshCollection m;
         m.add(sf::Vector2f(0, 0), texture);
         mcArray[c] = m;
         tArray[c].position = sf::Vector2f(x * 32, y * 32);
         tArray[c].rotation = 0.0f;
         c++;
      }
   }

the add() method probably forces the internal vector to reallocate memory every single time you are using the function which is rather slow.
your code looks rather akward, why do you add new elements on each run that on first sight never seem to change? lots and lots of wasted performance.
ยจ

The code is ran once for creating a array of objects to draw. Can see how that will impact performance anything more than long load time?

No profiling yet.

Release mode, no debuggers attached. Yes, artemis and SFML was compiled in release mode with /O2.



Edit:
After a quick session with the VS2013 performance analyzer it seems that Renderer::render is the snail.. Pointing to this line; "target->draw(*m_meshCollections, rs);" -- any tips on how to optimize that?


Edit2:
@kingcools: My respons to you might seem a bit offsense. That was not intended, sorry. Thanks for a fast reply :)

4
Graphics / 'Slow' performance - what am I doing wrong?
« on: May 28, 2014, 07:17:13 pm »
So I am trying to make SFML integrate nicely with Artemis-C++ port(Entity component system).
At the moment it is using about 0.39-0.5sec to draw a frame when drawing 713 "meshes" as a tiled background.

This is obviously something I'm doing wrong so if anyone can point me in the right direction that would be great!

Edit
Meant to press preview, not save.

I know that I am calculating the transform every frame.
/Edit

Here is my current code;

Renderer
Quote
class Renderer
{
public:
   void addToQueue(MeshCollection* mc, Transform* t) {
      m_meshCollections.push_back(mc);
      m_transforms.push_back(t);
      m_count++;
   }

   void render(sf::RenderTarget* target) {
      sf::RenderStates rs = sf::RenderStates::Default;
      sf::Transform original = rs.transform;
      clock.restart();
      for (int i = 0; i < m_count; i++) {
         rs.transform = original;
         rs.transform *= Renderer::getTransform(m_transforms);;
         target->draw(*m_meshCollections, rs);
      }
      std::cout << m_count << " mesh collections drawn in " << clock.getElapsedTime().asSeconds() << "sec" << std::endl;
         
      m_meshCollections.clear();
      m_transforms.clear();

      m_count = 0;
   }

private:
   static inline sf::Transform getTransform(Transform* t) {
      float angle = -t->rotation * 3.141592654f / 180.f;
      float cosine = static_cast<float>(std::cos(angle));
      float sine = static_cast<float>(std::sin(angle));
      float sxc = cosine;
      float syc = cosine;
      float sxs = sine;
      float sys = sine;
      float tx = -0 * sxc - 0 * sys + t->position.x;
      float ty = 0 * sxs - 0 * syc + t->position.y;

      return sf::Transform(sxc, sys, tx, -sxs, syc, ty, 0.f, 0.f, 1.f);
   }

private:
   std::vector<MeshCollection*> m_meshCollections;
   std::vector<Transform*> m_transforms;
   int m_count;
   sf::Clock clock;
};


Mesh
Quote
class Mesh
{
   friend class MeshCollection;
public:
   sf::Vector2f offset;
   sf::Texture texture;
   sf::Vector2f size;
   float rotation;

private:
   sf::Vertex m_vertices[4];
   sf::Vector2f m_origin = sf::Vector2f(0, 0);

   void updateVertices() {
      sf::Vector2u size = texture.getSize();
      m_vertices[0].position = sf::Vector2f(0.0f, 0.0f);
      m_vertices[1].position = sf::Vector2f(0, size.y);
      m_vertices[2].position = sf::Vector2f(size.x, size.y);
      m_vertices[3].position = sf::Vector2f(size.x, 0);
   }

   sf::Transform getTransform() {
      float angle = -rotation * 3.141592654f / 180.f;
      float cosine = static_cast<float>(std::cos(angle));
      float sine = static_cast<float>(std::sin(angle));
      float sxc = size.x * cosine;
      float syc = size.y * cosine;
      float sxs = size.x * sine;
      float sys = size.y * sine;
      float tx = -m_origin.x * sxc - m_origin.y * sys + offset.x;
      float ty = m_origin.x * sxs - m_origin.y * syc + offset.y;

      return sf::Transform(sxc, sys, tx, -sxs, syc, ty, 0.f, 0.f, 1.f);
   }
};

MeshCollection
Quote
class MeshCollection : public sf::Drawable
{
public:
   void add(sf::Vector2f offset, sf::Texture texture, float rotation = 0.0f, sf::Vector2f size = sf::Vector2f(1.0f, 1.0f)) {
      Mesh m;
      m.offset = offset;
      m.texture = texture;
      m.rotation = rotation;
      m.size = size;
      m.updateVertices();
      m_meshes.push_back(m);
   }

   virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const {
      // sf::Transform originalTransform = states.transform;
      for (auto m : m_meshes) {
         // states.transform = states.transform.scale(m.size).rotate(m.rotation).translate(m.offset);
         states.transform *= m.getTransform();
         states.texture = &m.texture;
         target.draw((sf::Vertex*)&m.m_vertices, 4, sf::PrimitiveType::Quads, states);
         // states.transform = originalTransform;
      }
   }

private:
   std::vector<Mesh> m_meshes;
};

Transform
Quote
class Transform : public artemis::Component
   {
   public:
      sf::Vector2f position;
      float rotation;
      // size ?

      Transform() {

      }
   };

And here is my test.
Quote
int main() {

   sf::RenderWindow window(sf::VideoMode(1024, 768), "");
   Renderer r;

   sf::Texture texture;
   texture.loadFromFile("Assets\\32x32_red.png");

   const int debugsize = 50;
   MeshCollection mcArray[debugsize * debugsize];
   Transform tArray[debugsize * debugsize];
   int c = 0;
   for (int x = 0; x < debugsize; x++)
   {
      for (int y = 0; y < debugsize; y++)
      {
         MeshCollection m;
         m.add(sf::Vector2f(0, 0), texture);
         mcArray[c] = m;
         tArray[c].position = sf::Vector2f(x * 32, y * 32);
         tArray[c].rotation = 0.0f;
         c++;
      }
   }


   while (window.isOpen())
   {
      sf::Event event;
      while (window.pollEvent(event))
      {
         if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            window.close();
      }

      window.clear(sf::Color::Black);
      
      int c = 0;
      for (int x = 0; x < debugsize; x++)
      {
         for (int y = 0; y < debugsize; y++)
         {
            if (tArray[c].position.x > 0 && tArray[c].position.x < 1024 &&
               tArray[c].position.y > 0 && tArray[c].position.y < 768)
               r.addToQueue(&mcArray[c], &tArray[c]);

            c++;
         }
      }
      /*
      for (int i = 0; i < debugsize * debugsize; i++)
      {
         
         r.addToQueue(&mcArray, &tArray);
      }
      */
      r.render(&window);

      window.display();
   }

   return 0;
}

5
General / Re: Character movement & physics
« on: September 20, 2013, 11:38:45 am »
Quote
Are you sure you really need a full blown physics engine? Or if all your after is collision detection (running, jumping, falling, colliding into walls, basic platformer stuff) you might want to consider implementing your own system.

Yes, I do. As I also needs barrels rolling, explosions, walls to destroy - Removing this will take away too much from the game. I've already prototyped out explosions, walls that fall apart, the only thing I can't get right is the player movement.

Quote
Sounds like you need to adjust the velocity that your applying to your character. Yes getting it fine tuned can take some work, but I have never experienced Box2D feeling clunky.
Yea, was late last night. Clunky isn't the right word.

6
General / Character movement & physics
« on: September 20, 2013, 12:27:25 am »
Hi,

I'm in the progress of making a 2d multiplayer platformer. So the question is; how do I get some smooth movement for my actors? Right now I'm using Box2d, but it is very.. "cluncky" and "sloppy". I want more have more control over it. It feels like it takes like hours to just change the maximum movespeed. And that is after I've written nearly 800 lines of "special physics rules" just for the player actor.

So, any tips on what to do? Do I roll my own? Do I change to something like chipmunk?



And yes, I need physics -- if I remove it, it will take too much of the game experience away.

7
SFML projects / Re: GLLight2D
« on: June 23, 2013, 12:00:48 am »
This seems very interesting, and looks awesome!

But why not just put it up on GitHub? I would love to put in some work. Even if it is just my own fork it would still be epic :)

8
General / Re: Cannot open included file. Newbie problem!
« on: June 08, 2013, 03:23:02 pm »
What. You're SUPPOSED to name it main.cpp. If changing the filename to just main fixes it, something is seriously wrong.

Meh, guessing his main got named main.cpp.cpp ?

9
General / Re: Deleting a vector of Shape pointers
« on: June 08, 2013, 02:16:07 pm »
Don't mix debug and release configurations, as stated in the tutorial.

Okey, running in debug, as earlier, same problem - any specific settings I should check for?


Edit1:
Running in release I get this message;
Code: [Select]
Unhandled exception at 0x00042569 in OPEngine.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.

Edit2:
Okey, seems to be something more wrong in my release config. I get
Code: [Select]
Unhandled exception at 0x00D82569 in OPEngine.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.
with the shapes removed... God I need to clean this mess up -- and now it seems like SFML is forcing me to  ::)

Edit3:
Soo now everything seems a bit nicer. I have set all the projects to compile as MDd in debug and as MD in release. They all use "Use Unicode Character Set" as character set in both debug and release. What more should I check?

Currently I'm using dynamic libs from SFML - I can't see any problem with that?




Final edit:
Got it working. Changed to Multi-byte character set for all projects - as that was what SFML used in the build project. Reverted to stable source-code(Might not have made any difference but did it for simplicities sake). Built with stable, linked with solution - Tadaadaa  ;D

10
General / Re: Deleting a vector of Shape pointers
« on: June 08, 2013, 04:59:03 am »
Code: [Select]
int main(int argc, char *argv[])
{
sf::CircleShape myShape;
return 0;
}

gives me

Code: [Select]
Run-Time Check Failure #2 - Stack around the variable 'myShape' was corrupted.

And no, I'm not accessing them after deletion. I create a shape, add it to the vector, and pass it to draw. Later I call display and after that I clear the vector. Then I start over again.

11
General / Deleting a vector of Shape pointers
« on: June 08, 2013, 04:18:18 am »
I have a std::vector<sf::Shape*> that I clear at the end of my main loop.
In the main loop a unknown number of shapes get created and drawn( ConvexShape, CircleShape, etc).

The problem is; how do I clear the vector of shapes that has been drawn and is no longer needed?
The way I'm doing it now;

Code: [Select]
while(!this->m_shapes.empty())
{
delete this->m_shapes.back();
this->m_shapes.pop_back();
}

but this gives me a unhandled exception and brings up dbgheap.c

12
Graphics / Re: move.xxx runs crazy fast sometimes
« on: June 02, 2013, 01:01:28 am »
May I suggest that you watch this;

It is a series of videos on math related to game development  :)

13
SFML website / Re: New website
« on: May 06, 2013, 09:03:10 am »
Just dropping by to say that I love the new look, and the site feels more modern now than the previous version.
Great work  :D

14
Network / Re: SFML UDP packet fragmentation
« on: February 08, 2013, 05:05:15 pm »
... Okey, I want to say something that doesn't make me look like a retard, but my brain is still stuck at "WTF was I thinking".

And of course you are right.

15
Network / Re: Sending information to a Mysql table
« on: February 08, 2013, 05:03:00 pm »
Soo you guys are saying he should create a PHP script and use that as a "proxy" between his MySQL server and C++ application?... That is just insane - to me at least.

If the application communicating with the MySQL server is a game server then you should use MySQL++ or any other C++ MySQL lib. Why? Since you control all the queries against the server and having some kind of PHP proxy just makes everything turn into syrup.

If the MySQL is meant for use client side, then your better of using something like SQLite3 or any other of the "locally stored"(or whatever you call them) database engines.

Pages: [1] 2 3 4
anything