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

Pages: 1 ... 9 10 [11]
151
Graphics / Re: I have a question regarding the best way to draw shapes
« on: August 18, 2013, 12:31:43 am »
230 FPS is great, but I have a very good PC.  I'm mainly wondering if I'm doing anything wrong because I'm concerned about others who might not have a PC as good as mine.

I took eXpl0it3r's advice and put together a terrible little test program.  Assuming I didn't make any mistakes, it should draw a bunch of tiny 10x10 rectangles on an 800x600 screen.  This one in release mode gives me 1,200 FPS, so I'm thinking I must have done something wrong in the original program.

#include <SFML/Graphics.hpp>
#include <sstream>

class FPS
{
private:
        unsigned int Frame;
        unsigned int Fps;
        sf::Clock FpsClock;

public:
        FPS();
        void update();
        const unsigned int getFPS();
};

//==================================

FPS::FPS()
{
        Frame = 0;
        Fps = 0;
        FpsClock.restart();
}

//==================================
 
void FPS::update()
{
        if (FpsClock.getElapsedTime().asSeconds() >= 1)
        {
                Fps = Frame;
                Frame = 0;
                FpsClock.restart();
        }
 
        Frame++;
}

//==================================
 
const unsigned int FPS::getFPS()
{
        return Fps;
}

//==================================

int main()
{
        sf::RenderWindow MainWindow;
       
        sf::ContextSettings ContextSetter(0,0,0);
       
        const int DEFAULT_SCREEN_WIDTH = 800;
        const int DEFAULT_SCREEN_HEIGHT = 600;
        MainWindow.create(sf::VideoMode(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32), "Primitive Drawing Test", sf::Style::Default, ContextSetter);
       
        sf::Event Event;

        sf::VertexArray VertArray;
        VertArray.setPrimitiveType(sf::Quads);
       
        const int CELL_SIZE = 10;
        int NumOfHorizontalCells = DEFAULT_SCREEN_WIDTH / CELL_SIZE;
        int NumOfVerticalCells = DEFAULT_SCREEN_HEIGHT / CELL_SIZE;

        FPS Fps;

        bool Quit = false;
        while (Quit != true)
        {
                Fps.update();
                std::stringstream ss;
                ss << Fps.getFPS();
                MainWindow.setTitle("Primitive Drawing Test -- FPS: " + ss.str());

                while (MainWindow.pollEvent(Event))
                {              
                        if (Event.type == sf::Event::Closed)
                        {
                                Quit = true;
                        }                      
                }

                MainWindow.clear(sf::Color(60, 150, 90));

                VertArray.clear();
                for (int x = 0; x < NumOfHorizontalCells; x++)
                        for (int y = 0; y < NumOfVerticalCells; y++)
                        {
                                const float xLoc = (float)x * CELL_SIZE;
                                const float yLoc = (float)y * CELL_SIZE;
                                sf::Vertex Vertices[4] =
                                {
                                        sf::Vertex(sf::Vector2f(xLoc, yLoc), sf::Color::Black), //top left
                                        sf::Vertex(sf::Vector2f(xLoc + CELL_SIZE, yLoc), sf::Color::Black),//top right
                                        sf::Vertex(sf::Vector2f(xLoc + CELL_SIZE, yLoc + CELL_SIZE), sf::Color::Black), //bottom right
                                        sf::Vertex(sf::Vector2f(xLoc, yLoc + CELL_SIZE), sf::Color::Black) //bottom left
                                };
                                                       
                                VertArray.append(Vertices[0]);
                                VertArray.append(Vertices[1]);
                                VertArray.append(Vertices[2]);
                                VertArray.append(Vertices[3]);
                               
                        }
                               
                MainWindow.draw(VertArray);

                MainWindow.display();
        }
}

152
Graphics / I have a question regarding the best way to draw shapes
« on: August 17, 2013, 11:00:26 pm »
I made a simple clone of Conway's Game of Life, but I'm not sure if I went about drawing the screen correctly.  When nothing is being displayed, I get 3,500 frames per second. If I were to pause the game and fill up every cell, the framerate drops to around 230.

It's basically just drawing a series of untextured rects which can be one of any arbitrary number of sf::colors. I'm thinking there has to be a way to draw the screen without such a drastic framerate drop. http://i.imgur.com/NxRJiYP.png

Right now what happens is this -- Every frame I create a sf::VertexArray, set the primitive type to sf::Quads, and then loop through every cell. If it encounters a cell that is alive, I create an sf::Vertex with the 4 points of that cell, and then append it to the vertex array.  When it's done checking every cell, the vertex array gets drawn.

That seems to be the way it's done in the tutorial, but I guess I just expected better fps than what I'm getting.

153
SFML projects / Re: Tetris + AI
« on: February 26, 2013, 06:08:20 pm »
The only planning it does is analyzing the best position (as far as it can discern) for the immediate piece it's placing.  In later versions I made it also analyzed the best position (again, as far as it can discern) for the current piece + next piece, but that slowed the program down quite a bit.  I think at its best it was getting around 3,000 lines per game.

There are programs out there that actually plan strategies for the AI to follow.  For example, they'll neatly stack everything except for one line on a side, and then wait for an l piece to get 4 rows at once.  Mine doesn't do anything like that.

Someone correct me if I'm wrong, but I think even the best Tetris AI's can't go on indefinitely.  There are just some piece combinations that will kill you no matter what you do. 

154
SFML projects / Tetris + AI
« on: February 24, 2013, 11:26:27 pm »
I made this back in October, but I think posting about it now can't hurt. 

There was a 48 hour game jam that I participated in, but I couldn't think of anything that I wanted to make with the theme, so I just decided to make and submit Tetris for a laugh.

After I had a working game of Tetris, I thought it might be fun to expand on it with an AI.

Video of the AI  --

Brief explanation of the AI -- It analyzes every possible location you can put the current shape and assigns each possible location a score based on aspects like height, how many lines you clear, etc. The highest score is the location chosen. There's also a bit of AI learning in that the value of each aspect of score is determined by a process similar to natural selection. Run a few games with different values, pick the best performing values and change them slightly and repeat the process and it should improve. For example, if the game started off with assigning height a positive score, then after a few generations it should see a downward trend since placing blocks high up is generally not a good strategy to get a good score.

This article explains the whole thing -- http://www.danieljosephpetersen.com/posts/how-my-tetris-ai-works.html

In this version, the AI learning is turned off.  It's always going to be using the same values, which actually weren't the best that I found (it's not as good as the video), but I unfortunately have a bunch of values saved and am not sure which ones were the best, I'd probably be better off just rerunning the thing again overnight.  There's a ton of room for improvement, but I did it over the course of a week and I'm happy enough with it.

Controls:
Enter turns AI on/off
Period (.) key increases time between ai moves
Comma (,) key decreases time between ai moves

155
SFML projects / Re: TGUI: a c++ GUI for SFML (with Form Builder)
« on: February 14, 2013, 09:46:11 pm »
I've been using this for the past few days, I rather like it.  Nicely done texus. 

Is there any possibility of adding an outline around text? 

156
Graphics / Getting an invalid pointer error while using sf::Text
« on: October 17, 2012, 03:06:47 am »
This is slightly odd.

I just switched from Visual Studio 2010 to 2012 Express. 

In 2012 I'm getting runtime errors whenever I assign an sf::Text both a font and a string.  If I assign one without the other, it will work fine.  I can assign character size, color, and position without any problem, but those two functions together are giving me a debug assertion failed error.  It says Expression: invalid null pointer.

I'm declaring the texts in a class and assigning the font and string in the constructor.  The same exact code in 2010 produces no errors, and I've double checked -- I'm using the same library files, they're the debug libraries for SFML 2.

I imagine that I'm doing something wrong to cause the problem, but I have no idea what that would be.  Any help would be appreciated.

157
Graphics / Drawing lines is incredibly slow?
« on: September 25, 2012, 02:54:08 am »
I'm currently trying to replicate this tutorial [http://gamedev.tutsplus.com/tutorials/implementation/simulate-fabric-and-ragdolls-with-simple-verlet-integration/] and I'm getting low FPS when I try to draw a grid. 

I have 2500 points on screen, each spaced 6 pixels apart from each other, and I want to draw a line between each point and its neighbor.  When I do so, my FPS goes from 4200 to 20-100.  Is this normal, or am I doing something wrong?

Here's the code I'm using to draw the lines.
void SFML_Program::drawLine(sf::Vector2f a, sf::Vector2f b)
{
        sf::Vertex line[2] = {a, b};
        MainWindow.draw(line, 2, sf::Lines);
}

I've also tried:
        void SFML_Program::drawLine(sf::Vector2f a, sf::Vector2f b)
{
        sf::VertexArray lines(sf::Lines, 2);
        lines[0].position = a;
        lines[1].position = b;
       
        MainWindow.draw(lines);
}

I'm calling that 4900 times to produce this. 

http://i.imgur.com/tI1tz.png

The code that calls it simply retrieves the two points it needs and then calls the drawline.  Am I doing something wrong?

Pages: 1 ... 9 10 [11]