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

Pages: 1 2 [3] 4 5 ... 7
31
Graphics / Help with vertex arrays!
« on: February 15, 2012, 09:08:00 pm »
Quote from: "Laurent"
You create your vertex array with an initial number of 6 points, but with Append you add other points instead of filling the 6 initial points. So you end up with 12 points: 6 empty + 6 of your hexagon.

So either you set an initial number of points and use operator[] to access them, or you only use Append.

By the way, your function would be much more efficient (no dynamic allocation/deallocation) with a fixed-size array of vertices allocated on the stack:
Code: [Select]
void DrawHexagon(float X, float Y, float W, float H, sf::Color Col)
{
   float HalfWidth = W / 2;
   float HalfHeight = H / 2;
   sf::Vertex Hex[6] =
   {
      sf::Vertex(sf::Vector2f(X, Y + HalfHeight), Col),
      sf::Vertex(sf::Vector2f(X + (HalfWidth / 2), Y), Col),
      sf::Vertex(sf::Vector2f(X + HalfWidth + (HalfWidth / 2), Y), Col),
      sf::Vertex(sf::Vector2f(X + W, Y + HalfHeight), Col),
      sf::Vertex(sf::Vector2f(X + HalfWidth + (HalfWidth / 2), Y + H), Col),
      sf::Vertex(sf::Vector2f(X + (HalfWidth / 2), Y + H), Col)
   }
   App.Draw(Hex, 6, sf::TrianglesFan);
}


sf::VertexArray is really just a std::vector<sf::Vertex>. Don't overuse it.


Ah, that makes sense  :wink:

thanks.

is there a detailed shader documentation anywhere? for the newest builds?

32
Graphics / Help with vertex arrays!
« on: February 15, 2012, 08:16:44 pm »
Quote from: "texus"
Shapes still exist. For convex polygons you should take a look here.

I can't help you with your problem though, because I never used the vertex array.


That does help for what I need, thanks.

But i'd still like some info on vertex arrays :)

also, is there a crash course on using shaders in sfml I can find?
not just implementing, but writing the actual shader too?

33
Graphics / Help with vertex arrays!
« on: February 15, 2012, 05:22:51 pm »
Since laurent got rid of the old shape styles and added vertex arrays (not saying this is bad, but it did help)

I've had an issue with trying to make shapes that aren't quads.

basically if I try to do anything above 3(tri), or 4(quad) vertices it gets screwy.

I have a "DrawHexagon" function that draws 6 vertices successfully, as a triangle fan, however the first vertice of this is always 0,0 with a white color.
all others are fine.
here is code

Code: [Select]
void DrawHexagon(float X, float Y, float W, float H, sf::Color Col){
sf::VertexArray Hex(sf::TrianglesFan, 6);

float HalfWidth = W / 2;
float HalfHeight = H / 2;
Hex.Append(sf::Vertex(sf::Vector2f(X, Y + HalfHeight), Col));
Hex.Append(sf::Vertex(sf::Vector2f(X + (HalfWidth / 2), Y), Col));
Hex.Append(sf::Vertex(sf::Vector2f(X + HalfWidth + (HalfWidth / 2), Y), Col));
Hex.Append(sf::Vertex(sf::Vector2f(X + W, Y + HalfHeight), Col));
Hex.Append(sf::Vertex(sf::Vector2f(X + HalfWidth + (HalfWidth / 2), Y + H), Col));
Hex.Append(sf::Vertex(sf::Vector2f(X + (HalfWidth / 2), Y + H), Col));
App.Draw(Hex);
}


Is there something wrong? O_o
Am I using wrong primitive type? :?
Why is there no Polygon primitive type, like openGL?
I'm a noob to vertex's :/

I'm trying to make a bunch of custom shape functions for a new game we're developing  :wink:

So much new stuff lately in sfml2, i'm trying to keep up!
I feel dumb, can anyone help? :(

34
Another HUUUGE update! Game now contains an updater, that will detect when a new update is available and automatically download the required files! :D

SOOOO Many new features!! :D

Small list of Updates from 0.0.60 - 0.0.80 (Can't fit all ;) )
-NEW! Zombie AI! (Zombies now are smarter then eever!)
-Did much optimization with views (More fps)
-New appeal to Inventory/Crafting Slots and Screens
-Added Design for Main Menu/Login Screen (more features as well)
-Added Modding system added (For weapons, which increases certain stats of a weapon)
-Added Shop system (Enables you to sell resources and gain money to buy items! (mods/weapons/rares)
-Added Currency system (for shop system!)
-New Collision system for everything (Easier to get by smaller places! And less glitches!)
-Added building system (allows you to build with blocks you either make or buy)
-More work done with profiles (Longest day survived/Most money/Total score/Total kills/etc!) (only for users logged in)
-House generation (with random houses generated with goodies inside the house!)
-More items to craft (Think floors/Walls/minor-mods/weapons/etc)
-Hunger system! (Food heals you and it can kill you if you don't eat!)
-More information sent from the game to your profile at our site! (stats!) (http://xsgteam.net)
-Fixed a bunch of bugs when you could view things in Pause/Death screen!
-Also new variable handles which gui box displays first! (So hover over health and crafting box, wont display both)
-Added sfx (when buying/selling items)
-Added sfx (when punching zombie!)
-Added sfx (when drinking drink)
-Added sfx (when eating burger)
-Added option in menu to turn off tips.
-Made some new sounds (un-used atm, for cellslots)
-Made weapons sell value depend on durability!
-Some new hints/tips added!
-Tips/hints regenerate randomly every 30 seconds
-Successfully added menu (in-game)
-FIX: In Store the weapon will display sell value (in your inventory now)
-FIX: Bunch of bugs with zombiess!
-FIX: Moved ammo to Health Bar
-FIX: If Intersection with HotBar you will not be able to shoot!
-Removed Day/Night Orb because of problems! Will work on more...
-Added a lot more! (Check ittt ooout)

35
General / Question about optimizing in SFML
« on: June 08, 2011, 07:09:34 pm »
Quote from: "Groogy"
That means that you do test against each tile in the world? Try with this, implement a grid where each cell is as big as one screen. And then before checking against the tile you first check "What cell's are currently in view(A maximum of 4 can be seen in worst case scenario) and then you go into these cells and test against the tiles inside the cell.

Pseudo code:
Code: [Select]

for each cell in grid
{
        if( view.rect.intersects( cell.rect ) == true )
        {
                for each tile in cell
                {
                        if( view.rect.intersects( tile.rect ) == true )
                        {
                                window.draw( tile )
                        }
                }
        }
}


With this you will cut away a lot of tiles by effectively ignoring cells that is not inside the view.
This can also be used for cutting away impossible collision tests as you only need to test against the objects placed in the same cell or the neighbor cells.

Just gonna try some example math here. Let's say we have what you said, 192 x 192 tiles of the size 64. That means we got a total of 36864 tests to see if it is shown or not. Let's assume we have a 800x600 screen then only about 10x10 tiles are visible at the same time. But we still do 36864 tests to see if we can see them. With a grid we will arrange so we have 10x10 tiles in each grid cell. So that means we have 369 cells over our map. So now instead to find the tiles that can be shown we do 369 tests for see what cell is shown and 100x(the amount of cells shown,1-4) tests against the tiles to see what to draw. So instead of doing 36864 tests we have reduced it to 369 + 100 x (1-4). So worst case scenario is 769 tests.

NOTE: I might have done some numbers wrong but the fact stands that you do cut away a lot just by adding a higher hierarchy grid to test against. Depending on how your logic is you might need to tweak some things(like size of cells and so on) in order to get most optimal performance gain from it.


Very nice idea, we'll definitely look into it and incorporate it in the future!

Quote from: "Svenstaro"
Currently you only seem to be poking around. Why not actually profile your code?

Get valgrind and kcachegrind. Assuming your binary is called "zombies", do this:
Code: [Select]
valgrind --tool=callgrind --callgrind-out-file=zombies.callgrind ./zombies
This will run your game in a virtual CPU and record all function calls and see how long they will take. It also records API calls and everything. It will be very slow but don't worry, it will not produce false results.
Then use kcachegrind to visualize all this in an easy and colorful browser:
Code: [Select]
kcachegrind zombies.callgrind

This should get you a whole lot farther than any amount of guessing will.

EDIT: It will look something like this. Pay attention to the "self" bar which show you how long a function will take by itself.


I've been profiling our code alot actually, it's just so vague because it spends it's time in update/drawing, and I don't have enough specific functions just yet but thanks for the help.

P.S. you guys are awesome as always ^^

36
General / Question about optimizing in SFML
« on: June 08, 2011, 02:16:51 am »
Quote from: "Groogy"
It's kinda hard to help you over the forum like this since you have problem giving us more precise information. Also you seem to be in a different timezone. I should be sleeping now ^^

Did you gain anything major by commenting out the Draw call?

How large is the world? How do you cull the tiles from being updated/tested against/rendered?

If you do a test against each tile in the world if it is shown that might be your villain.


If the tile intersects the view (window) it's drawn.
however if I comment our draw line for TILES, I get 130 fps vs, 50.

Zombies are now fine. But Tiles are my issue...

World is (192x192)x64 now. (64 being width/height of tile)

37
General / Question about optimizing in SFML
« on: June 08, 2011, 12:17:15 am »
Quote from: "Groogy"
Quote from: "Laurent"
We're not gods
I am! :D j/k

Anyway what changes have you done since last? Since it wasn't that bad when I tried it for you? You could have several zombies on without any lag(staying around 60FPS).

Also the drawing is not the culprit here. (It might be a bit on tiles but not when it come to entities) so I would guess somewhere in your logic.

A very simple and probably one of the best debugging tests is what Laurent suggests. IF you think drawing is the culprit, just comment out THAT line and nothing more and see what happens. Does the FPS go up significantly? No then the problem is somewhere else and I think it's in your logic, especially since you got pixel collision. It is generally slow, there are tricks to speed it up but compared to other tests it is really slow. (Imagine a 16x16 image using a AABB test versus pixel test. Either we have 4 comparisons or we have 256 if it's a primitive version)



Well the problem seems to come within the for loops, which is to be expected.

once we removed PixelCollision and replaced with rectangular collision, it was a bit faster.

but we're not sure how to optimize for loops exactly...

38
General / Question about optimizing in SFML
« on: June 08, 2011, 12:03:44 am »
Quote from: "Disch"
Quote
Is it really that CPU consuming??


It can be very consuming.  Espeically if you're getting the pixel data from the video card for every check.

Every time you get pixels from the video card it has to move from VRAM to CPU RAM.  In addition to being a copy of the whole image (which is a big copy), it has to move along the bus which is also very slow.  What's more, while the video card is spending it's time getting pixel data, it can't do things it would otherwise be doing, like rendering stuff.


But all that aside, doing pixel-by-pixel collision is a rather absurd and overly complicated way to do this anyway.  Why not a simple bounding box?


Erm, To be honest, I'm not even sure why most of them are pixel collision...I've reverted most back to rectangular and it helps alot.

Thanks for pointing that out ^_^

39
General / Question about optimizing in SFML
« on: June 07, 2011, 11:46:44 pm »
Quote from: "Disch"
Code: [Select]
PixelCollision(Sprite,mainGame.bullets[j].BulletSprite,200))

PixelCollision?

You're not really checking every single pixel, are you?

If you are, that has to be the problem.


Is it really that CPU consuming??

Quote from: "Laurent"
I'm not sure you understand what I mean.

My point is that you should do tests, which consist of disabling parts of the code (drawing, collision detection, etc.) then run the game -- in order to identify the part of your code that eats all the performances. There's no point looking at your whole code if only a very small part of it is relevant -- and you can find it easily with tests.

By the way,
Quote
How would I make a detailed bug report? o.O

Open a new topic and describe the bug, with as many useful information as you can about it.


I understand, but I was trying to see if we screwed up, and someone with more C++ knowledge could help, we'll definitely do tests.

Btw, just a quick thanks to all of you who help us ;)

40
General / Question about optimizing in SFML
« on: June 07, 2011, 11:25:27 pm »
Quote from: "Laurent"
Quote
check if collision with player/world objects/ world items

What about this one? It looks quite heavy in terms of computation.

Have you tried to comment the line that draws zombies and see if it makes your app run faster?

More generally, you should gradually disable parts of your code to see which one is eating all the performances -- instead of trying to find the guilty line directly, just by looking at the code.


Here it is, with minor lines taken out (minimal)
remember we're not C++ masters, so if we made a "no-no" please tell us o.o


Code: [Select]

void Zombie::Update()
{
    int BulletSizeMax2 = mainGame.bullets.size();
    for (int j = 0; j < BulletSizeMax2; ++j)
                {
                    if (mainGame.bullets[j].Alive)
                        if (PixelCollision(Sprite,mainGame.bullets[j].BulletSprite,200))
                            {
                                if (Health > 0)
                                    {
                                        //hurt/move zombie.
                                        Sprite.SetPosition(ZomX, ZomY);
                                       //add new blood effect.
                                        mainGame.BloodSplatter.push_back(blood);
                                        break;
                                    }

                            }
                }

    if (Health <= 0 && Alive)
    {
        CanHurtPlayer = false;
        if (Alpha > 0 && Alive)
            Alpha -= 10;

        if (Alpha <= 0 && Alive)
        {
            Alive = false;
        }

    }

    if (Alive)
    {

            for (std::list<Item>::iterator lolk = mainGame.WorldItems.begin(); lolk != mainGame.WorldItems.end(); ++lolk)
            {

                if ((*lolk).UniqueID == 18)
                {
                        //check if item can interact with zombie
                        if (PixelCollision(Sprite, (*lolk).Sprite, 50) && CanHurtPlayer)
                        {
                            //do stuff, then delete item.
                            mainGame.WorldItems.erase(lolk);
                            break;
                        }
                }
            }
            //move zombie

            //check for collision with player
            if (PixelCollision(mainGame.Sprite, Sprite, 50) && CanHurtPlayer)
                {
                    //hurt player
                }
            int WorldObjectsSizeMax = mainGame.WorldObjects.size();
            for (int l = 0; l < WorldObjectsSizeMax; ++l)
            {
                  //loop through world objects, and have zombie interact with them.

            }
 //move zombie finally
}
}


all the above code is called within zombie class
and the code that calls it

Code: [Select]

int ZombieSizeMax = Zombies.size();
for (int i = 0; i < ZombieSizeMax; ++i)
{
                    Zombies[i].Update();
                }



Does this help?

41
General / Question about optimizing in SFML
« on: June 07, 2011, 11:01:17 pm »
Quote from: "Laurent"
Quote
and Even though we have the SAME lib, project settings/properties and files, it wont render on his but it does on mine?

So please make a detailed bug report :)

It's hard to tell what slows down a complete application. If you get better performances by simply commenting the Window->Draw(Zombie) line, then there's nothing you can do. If it doesn't help, there's definitely something to optimize in your own code.


How would I make a detailed bug report? o.O
Yeah, I know there's no real way of determining the problem. Maybe I can give more insight on our program.

the thing is, it only runs the window->Draw(zombies) code when the zombie is in view of player...

here's our basic structure of program.. VERY BASIC VIEW

main loop
App clear
game state switch loop
case game { game.sendvars(&App); game.update(); game.draw() }
App display

Game Update
for (zombies) //for each zombie in zombies (Not real code, lul)
check if collision with player/world objects/ world items.
move/hurt zombie accordingly.

Game Draw
for (zombies)
if zombies are in bounds of view rect, draw them

42
General / Question about optimizing in SFML
« on: June 07, 2011, 10:35:41 pm »
Quote from: "Laurent"
There's definitely something wrong in your code if you can draw hundreds of tiles but not 5 zombies.

Quote
2.0 is too buggy for our taste

May I ask what bugs are blocking you? I think 2.0 is already more stable than 1.6.


Well, me and my other dev-team partner tend to transfer our projects over to each other. and Even though we have the SAME lib, project settings/properties and files, it wont render on his but it does on mine?

As for drawing the tiles, it lags with those as well. Without them it's 150fps, with it's 50.
it only draws the ones I see too. and there is little updating on those, so what's going on?

I can't exactly show the updating code, as it's pretty messy atm.
but I can show you the drawing loops basically.

Code: [Select]

            int ZombieAmountSize = Zombies.size();
            for (int i = 0; i < ZombieAmountSize; ++i)
{
                if (Zombies[i].Alive)
{
float X1 = Zombies[i].Sprite.GetPosition().x;
float Y1 = Zombies[i].Sprite.GetPosition().y;
sf::FloatRect tempRect;
tempRect.Left = X1;
tempRect.Top = Y1;
tempRect.Right = X1 + 64;
tempRect.Bottom = Y1 + 64;

sf::FloatRect tempRect2;

tempRect2 = View.GetRect();
float R = Zombies[i].Sprite.GetColor().r;
float G = Zombies[i].Sprite.GetColor().g;
float B = Zombies[i].Sprite.GetColor().b;
Zombies[i].Sprite.SetColor(sf::Color(R, G, B, Zombies[i].Alpha));
if (tempRect.Intersects(tempRect2))
{
Window->Draw(Zombies[i].Sprite);
}
}
}


Keep in mind, this code is similar to the other drawing ones.
And the updating is really simple as well..

And yes I tried profiling, but I'm not a pro at that either =/

43
General / Question about optimizing in SFML
« on: June 07, 2011, 10:12:37 pm »
Hey guys. It's been awhile, and if you know us, "XSG Team" you know we have a game out called "Paradox".
unfortunately this is cancelled until further notice due to an increase of lag.

My questions are why is it that our game drops 30 fps when we spawn 5 "zombies".

Zombies are basically a small simple class, with a few int variables and a sprite, NOT IMAGE.

The game DOES do frustrum culling, and currently runs at 40-50+ fps with over 256x256 tiled (64x64 pixel) tiles.

I've tried optimizing like crazy, but to no avail.
We are no C++/SFML masters, so that's why we're reaching out to this awesome community.

We've tried to make a "Stamp" sprite instead of a bunch of sprites, and just have it change image/location each call in a for loop, but that made it WORSE.

I don't get it, the game does NOT draw outside the view window, yet it lags with 5 entities that aren't drawn? The updating is only a for loop that iterates for each entity.

it's not just the entities that cause lag, unfortunately.

Is there any further optimization tricks for SFML you guys can share? (v1.6 currently, 2.0 is too buggy for our taste).

44
New update!!
V0.0.60 is out
Here's what's new! (Most of)


Edit: Wiki now added for recipes!
http://xsgteam.net/ParadoxWiki.php

New Updates from 0.0.53 to 0.0.60
-Remade crafting system!
-Fixed up some GFX
-Durability added for weapons!
-Certain key items do not stack anymore! (Weapons, etc)
-Zombie AI made (Zombies now can chase you after sight!)
-NO zombies get spawned day one! (Go gather resources, fool!)
-Console added, for when logged in (Press T!)
-Fullscreen mode added! (Not for main-menu though) (FPS may drop depending on computer)
-Splash screen
-Save / Load fixing / tweaking (Current saves will not work Sad)
-Added zombie Brains (Zombie bait!) (1/20 chance dropped when kill)

Download Link:
http://xsgteam.net/Paradox/Paradoxv0.0.60P.zip

All feed back, negative or not is greatly appreciated!

45
Quote from: "DevilWithin"
What about a new version? :D I've been curious these days to play that ! :)


:D We're working 0.0.60 and it'll be released VERY soon, it's got HUGE updates, check back in 1-3 days :)

Glad to see you wanting to play, v0.0.53 is pretty cool, try it.

Pages: 1 2 [3] 4 5 ... 7