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 ... 8 9 [10]
136
SFML projects / Re: My Sonic the Hedgehog game (goes fine, but need help)
« on: September 24, 2013, 12:19:06 am »
The first link you had crashed for me, second link work was slightly better.  I got to the point where you could select a character (which, btw, you need to put that on a delay, you almost instantly skip over the middle character) and then the game goes blue with a memory used message, at which point I alt tabbed and it crashed.  It seems to crash whenever I alt tab, actually.

The music was also way too loud, but maybe that's just me.

137
SFML projects / Re: What are you working on?
« on: September 22, 2013, 07:09:36 am »
My pet project is a Civilization-like game.  At the moment I like to think of it as a mashup of Civilization II and Alpha Centauri, but with my own twist.

Most of these screenshots are months old, and all the graphics are temporary, but it is what it is.

Testing nation borders
http://i.imgur.com/jdI4C5C.jpg
http://i.imgur.com/Kdi7REF.png

Old prototype of the GUI on the city screen
http://i.imgur.com/JiWHiqi.png

Was testing overlaying nation colors onto the map
http://i.imgur.com/aYWdFem.jpg

I spent yesterday and today trying to see if I could implement an ocean floor for aesthetic reasons.  Don't like the look of it yet, but it's not done
http://i.imgur.com/H6rgzcv.png
http://i.imgur.com/2s4Rq1J.png

It's pretty rough, but I have fun working on it.

138
SFML projects / Re: Linavalanche
« on: September 08, 2013, 08:42:00 am »
Here's a screenshot I took for anyone curious


Basically the screen always is moving forward.  Your character can only move up and down the lines on the screen, and the lines are all rotating.  You have to jump from line to line in an attempt to stay on the screen.  Pretty interesting idea and pretty well executed, I liked it.

139
SFML projects / Re: Colonies - A Retro Sandbox Survival MMO
« on: August 19, 2013, 08:22:56 pm »
This looks incredible man.  I took a look at some of your early posts on your blog, you've come a very long way in such a short time.  I'm going to keep an eye on this, keep it up.

140
Graphics / Re: I have a question regarding the best way to draw shapes
« on: August 18, 2013, 07:14:29 pm »
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.
I get 1200 FPS in debug and 1800 FPS in release mode. ;)

Anyways you should not delete and recreate the whole vertex array every frame. sf::VertexArray uses a std::vector, thus whenever you call clear() it will also call clear() on the vector. So you're basically allocating and deallocating memory in every frame iteration, which is not the fastes operation and should be reduced to a minimum as much as possible. In fact you'll most likely even run into the issue, where the vector gets moved around in memory multiple times, because it's size gets too big, to hold all the data. Such a movement takes linear time, which will add up very quickly, especially if you do it every frame iteration.

The better way to go about it, is to create the vertex array with its vertices once and then apply the changes directly to the existing vertices. If you feel like you don't have enough access through the interface of sf::VertexArray, you can also go ahead and use a std::vector<sf::Vertex> directly and use window.draw(my_vector.data(), my_vector.size()) to draw it (.data() is a C++11 feature).

To prevent moving in memory, you can either set the size from beginning with the constructor or later by calling resize() or if you're using the vector directly, you can call reserve() to allocate enough space.

After all, if you don't change the vertex array at all, then you won't have to iterate over it, every frame, constructing it once in the beginning should be enough.

First of all, thanks for the response, that makes a good deal of sense.  Part of the reason I didn't keep a stored VertexArray with all the points on it is that the very array wasn't a fixed size, the program had an 'infinite grid', which was really just a series of 800x600 boards (well, I suppose 880 x 660 with the spacing) that could be allocated / deallocated anywhere needed.

http://i.imgur.com/MBmVmds.png
http://i.imgur.com/2cNJ54f.png

141
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();
        }
}

142
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.

143
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. 

144
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  -- https://www.youtube.com/watch?v=vkUx0RRj4Yc

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

145
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? 

146
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.

147
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 ... 8 9 [10]
anything