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

Pages: [1]
1
General / Why degrees?
« on: April 03, 2014, 02:15:49 am »
Why is SFML using degrees as a default unit instead of radians? Radians is pretty much standard in every mathematical environment and the default sin, cos and tan only accept radians. Why would users have to go through the hassle of having to take note if they are working in degrees or radians, when it can all be simplified to only using radians?

2
General / Quadtrees
« on: February 25, 2014, 04:20:30 am »
I'm currently trying to implement a Quad Tree, the first example I've seen from it gave me the idea a Quad Tree is this:
Quote
Divide the playground in fixed equal squares and see in which one an object resides. For a collision check, only the objects in the same square are checked. According to the picture: only the same colored shapes will be checked for collision. If an object resides in multiple squares at once (such as the triangle) collision is checked for all objects in all squares. Optimization is done by correcting the size of the squares.


However, after some more searching I found that it was rather done using a recursive way:
Quote
Start with one square and divide it in four equal parts if more than N amount of objects are placed within it. All objects now go to a child square. Every part is again a Quad Tree and thus behaves the same as its parent. The dividing process keeps happening until all objects are placed or a maximum depth has been reached. Optimization is done by correcting the maximum amount of objects and the maximum depth.

So my question: what are the benefits of the one over the other?

These are my thoughts:
Properties of first Quad Tree
  • Pro: Indexing a shape on a fixed raster is not an expensive task.
  • Con: The number of objects returned from a square is uncertain which results in a less stable performance when a lot of objects are close to each other.
Properties of second Quad Tree
  • Pro: When getting all objects which might collide. You are certain about the maximum number of objects it can return resulting a more stable performance.
  • Con: However, when the maximum depth was reached, the certainty of the previous pro disappears.
  • Con: It would need to recalculate the place of objects every time a square needs to split which means the first couple of objects added will check collision several times with the Quad Tree.
  • Con: It constantly has to create and destroy Quad Tree objects for moving objects. And as far as I'm aware, creating and destroying objects is an extensive process.
  • Con: When 2 objects are about to collide, chances are higher that it needs to divide right at that moment which is bad for performance and could possibly break the collision if it results in a frame drop.

Where Quad Tree 1 is the obvious winner.

3
Graphics / Vertex array not drawing all points
« on: February 09, 2014, 12:05:47 am »
When I fill up a sf::VertexArray with a primitive type as Points, it does not draw all points I add to the array. For example, a vertex array filled as
sf::VertexArray vertexarray(sf::Points);
for (int i = 50; i < 400; i++) {
    sf::Vertex vertex(sf::Vector2f(i,50),sf::Color::Green);
    vertexarray.append(vertex);
}
will show something like

which is not what I intended.

How is this happening? Do the vertex coordinates not match the window coordinates exactly or something along these lines?
I'm using this to try and check my algorithms to make sure I have collected all points and didn't omit any. I'll be using it for quad-trees and pixel perfect collision.

4
System / sf::Time::asSeconds vs sf::Time::asMilliseconds
« on: December 30, 2013, 12:21:04 am »
Hi,

I've noticed that using sf::Time::asMilliseconds is not reliable. When trying to move a sprite, it's speed is depended on the fps which should not be the case. How is this happening?
Changing all sf::Time::asMilliseconds to sf::Time::asSeconds makes all speeds consistent. I used
sf::Sprite::move(speed*sf::Time::asMilliseconds,0);

I've added the file I used for testing this. Use Num1 to swap between unlimited and 30fps (using sf::RenderWindow::setFramerateLimit) and Num2 to swap between the use of sf::Time::asSeconds and sf::Time::asMilliseconds. Note how the object slows down when switching from unlimited framerate and sf::Time::asSeconds to sf::Time::asMilliseconds.

Did I do something wrong or is it really SFML?

5
I've just gone from MSVC2010 to MSVC2012, loaded my old project up and had a lot of errors. Managed to get them away by simply creating a new one and copying all .cpp and .h files into it. I've also recompiled SFML for MSVC11 and linked my project with those files.

The problem I now have is that when I want to start my application it asks for the msvcr100d.dll file which is still from MSVC2010. Does that mean that I have not correctly compiled SFML and that SFML still needs that .dll or something entirely different? I don't get any error when I don't link SFML or don't use anything of it.
Downloading the msvcr100d.dll does not seem like the correct solution... I have found the msvcr110d.dll in the install folder.

Sorry to be bothering you by this.

6
SFML projects / Minesweeper
« on: February 21, 2013, 03:37:26 am »
Hi there!

Been a pretty long time (~4 months) since I've been here. Stopped programming for a while, but I picked it up again a week or 2 ago or so and I decided to make a minesweeper to get familiar with working with tiles since I had an idea of a turn/tile-based game.

Mind that this is my first program in SFML apart from Pong :D
It's still pretty basic and I'm planning to add extra stuff such as rectangular tiles, and various other modes. But first of I'd like to improve the menu and the look of the game (adding borders and such).




If you want to play the game here is some useful info:
In the main menu:
... read the instructions shown on screen.
... you can also start the game using 'F8'. This will start the game in a debug mode instead of the normal mode. This will give some useful info on the output prompt and is recommended if you want to have an insight on how I implemented it before looking at my poorly commented code ::)
While playing:
... pressing 'h' will show a hint. It will highlight random tile that is not a bomb and prioritizes empty tiles. Use this only when you have to guess. I implemented this because I hate guessing in minesweeper 8)
... do not minimize the prompt. It will tell you how many bombs are left and will wish you good luck ;)
... pressing 'Escape' immediately takes you back to the main menu.



Here is my github. The executable is packed in Release.zip. Just press 'View Raw' to download. If you want to have a look at the code please do and write all your findings here ;)

Screenshots:




7
Graphics / Inherit from sf::Sprite or add variable sf::Sprite?
« on: November 21, 2012, 11:07:47 pm »
Inheritance:
class myClass : protected sf::Sprite {}
or adding it as member variable
class myClass {
    private sf::Sprite spr;
}

When using it as a variable it seems safer, but with inheritance it seems all a lot cleaner and more intuitive:
myClass obj;
// with inheritance
obj.loadFromFile("pic.png");
obj.setPosition(20,25);
window.draw(obj);
// with member variable
obj.getSpr()->loadFromFile("pic.png");
obj.getSpr()->setPosition(20,25);
obj.draw(window);

Are there any benefits by adding it as a member variable or is it all personal preference?



Edit: this actually should be in the general help, this is not only related to sf::Sprite but all other classes too.

8
General / Slow startup
« on: November 15, 2012, 05:06:33 pm »
This isn't really all too important, but I just wonder why:

I almost finished in remaking pong, but for the player to have time to react at startup (I have no menu screen), I put the ball close to his bat and made sure it could bounce of when he stood still. Problem is that the ball just went right through the bat because my time interval for the first couple of frames was around 0.3 sec (decreasing quickly to 0.004 sec). I called sf::Clock::restart() right before the game-loop.
I guess this has something to do with the graphics card rather than with SFML, correct?

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

Ignore the following, I was too dumb to not thinking about Google or the forum search being able to help me...
And while I'm asking I might as well ask what the PDB-files are. I didn't ask before because I thought I would not understand it yet. I think I will now but just in case I do I might as well ask it :)
I found how to get rid of the errors: by checking the download location of Microsoft Symbol Servers, but I didn't give any difference (or at least not that I noticed) apart from a slower start-up. I do notice there are files in like opengl32.dll or graphic card related dll-s which all seem like necessary files.

9
SFML projects / didii's simple classes
« on: November 12, 2012, 05:54:54 am »
I made a few simple classes I'm proud of even they don't do anything remotely useful at the time. For now I have created 3 classes:
  • Clickable: detects if mouse is hovering over the object or is clicked on with a certain mouse button.
  • Interactable: detects if object is hovering over the object or a certain button is pressed while hovering.
  • TileMap: Creates a map of tiles given by the user (more explanation below).
The classes Clickable and Interactable are meant to be parents of other objects to make them clickable or interactable, whereas TileMap should be fully functional on its own.

Here are all files (.h and .cpp in a .zip). If you just want to see what the functions do, click here (executable in .zip).
The program will draw a map on the screen, and will create an Interactable and a Clickable on the same place as the map. Moving your mouse or the red box over the map will trigger an output on the output screen. Move the red box with the arrow keys. More outputs are triggered when hovering and pressing the right button: for the mouse it's the left click, for the box it's space or enter.


Clickable
Key functions:
bool IsHovering();                 // return true when mouse on box
bool StartHovering();              // return true when mouse enters box
bool StopHovering();               // return true when mouse leaves box
bool IsClicked(sf::Mouse::Button); // return true when clicked on box
Not much to say about it, it's pretty obvious what it does and how it does it. IsHovering() is called for every other function mentioned above. None of these functions handle events, this is why the function IsClicked() is best called after testing if event == sf::Event::MouseButtonPressed.

Interactable
Key functions:
bool IsHovering();
bool StartHovering();
bool StopHovering();
bool InteractButton(sf::Keyboard::Key);
So basically the same as Clickable, but only accepts keyboard input. The biggest difference is that Interactable works with an interaction box or point. This means for example that you can create an invisible box ahead of your character. When that box hovers over an Interactable, IsHovering() will return true. The argument of InteractButton() should always be sf::Event.key.code. InteractButton() does not handle events.

TileMap
Key functions:
void Draw();  // draws map on app
This class uses a texture where all tiles are located in. It needs to know the size of the tiles and the width and height of the map in tiles. When it is given an int m[width*height], where m[i+j*height] (with i and j from a for-loop) has the value for which tile it should display at that position, it will draw the map on the given sf::RenderWindow.




If you wish to give me some advice on the functions, I know it's a little bit too much at once to handle. Just pick one random and give all you've got on that one. You should only need to look at the key functions (under // <class> functions in every file) and the variables under protected: or private:.

10
General / Unhandled exception in 2.0, NOT in 1.6
« on: November 07, 2012, 05:55:32 am »
Hi, I'm quite new to SFML but decent in C++ and encountered a weird problem I thought I might share with you :)

I was following this tutorial, which is written with SFML 1.6. I've made a minimal working example to be found at the bottom.
In 1.6 it works as it should, but when converting to 2.0 I got an Unhandled exception and I have no clue why. All should be setup correctly since I've read the tutorial Getting Started multiple times to make sure I've made no mistake.

The error is at line 4 when creating a sf::Renderwindow in the global scope.
Could this be a bug or is it intentional? If it is intentional, can anyone point out why?

Working under Windows 7, in MS Visual C++ 2010 Express. Linked SFML 2.0 statically and the exact error is: Unhandled exception at 0x777122b2 in TestSFML_2.0.exe: 0xC0000005: Access violation writing location 0x00000004.

Here is the minimal working example for 1.6, thus working:
#include <SFML/Graphics.hpp>

// create window in global scope
sf::RenderWindow window;

// MAIN FUNCTION
int main(int argc, char *argv[]) {
        window.Create(sf::VideoMode(640,380), "SFML Window"); // initialize window

        // wait for close event to close
        sf::Event ev;
        while(window.IsOpened()) {
                while (window.GetEvent(ev)) {
                        if (ev.Type == sf::Event::Closed)
                                window.Close();
                }
        }
        return 0;
}

And for the error in 2.0, which throws an exception on line 4
#include <SFML/Graphics.hpp>

// create window in global scope
sf::RenderWindow window;

// MAIN FUNCTION
int main(int argc, char *argv[]) {
        window.create(sf::VideoMode(640,380), "SFML Window"); // initialize window

        // wait for close event to close
        sf::Event ev;
        while(window.isOpen()) {
                while (window.pollEvent(ev)) {
                        if (ev.type == sf::Event::Closed)
                                window.close();
                }
        }
        return 0;
}

Debug window (why are none of these files anywhere on my pc?):
Code: [Select]
'TestSFML_2.0.exe': Loaded 'C:\Users\Dieter\Documents\Visual Studio 2010\Projects\TestProject\Debug\TestSFML_2.0.exe', Symbols loaded.
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
First-chance exception at 0x777122b2 in TestSFML_2.0.exe: 0xC0000005: Access violation writing location 0x00000004.
Unhandled exception at 0x777122b2 in TestSFML_2.0.exe: 0xC0000005: Access violation writing location 0x00000004.
The program '[1300] TestSFML_2.0.exe: Native' has exited with code -1073741819 (0xc0000005).

Pages: [1]