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

Pages: 1 2 [3]
31
General discussions / Filesystem from SFML?
« on: July 01, 2011, 12:01:15 am »
Thank you for the link. Interesting. I should make better use of the search function.

32
General discussions / Filesystem from SFML?
« on: June 30, 2011, 10:42:16 pm »
I figured I'd ask here to double-check, but I'm guessing the answer is no. Anyway, is there a way to interact with the file system from SFML? Something basic, like finding the names of the files in a directory and the like. If not, what would a good way of doing it be? I think Boost has a library for that?

33
System / DeltaTime question
« on: June 30, 2011, 12:52:59 pm »
How are frames delimited? Calls to sf::Window::Display()?

34
General / Clock Class/Time Class
« on: June 18, 2011, 08:38:12 am »
sf::Clock::GetElapsedTime() returns an Uint32 (32-bit unsigned integer) with the elapsed number of milliseconds (ms) that have passed since you started the clock (or the last time you reset it).

The reason you can't cast it to a string is because sf::String is meant to be used with different representations of, well, strings. Characters, not binary representations of numbers. When you write, say,
Code: [Select]
sf::String s;
s='a';
the character 'a' has a representation and a meaning. The representation is the binary code, a number in essence. The meaning is the letter a. For example,
Code: [Select]
char x = 97;
(x == 'a')
evaluates to true.

So, referring to your problem. Let's say you call GetElapsedTime(). You get a number like 1357, meaning it's been 1.357 seconds since the clock was started or reset. If you want to convert this to a string to write it out, you have to find a way of converting each digit into a character.

Thankfully, this is a common need, and there are many functions that do it. itoa() in the <cstdlib> header can do it, you can look up a reference for it here.

Given your number and a char array, it will fill the char array with a null terminated string with the depiction of the number in the appropriate base. You can then pass this array to sf::String, which can then do whatever you need it to do.

This will not format the time into a readable format, however. You'll need to massage the numbers to get them to read as time (meaning seconds, minutes, hours).

For an example of how to do it:
Code: [Select]
#include <cstdlib>
#include <SFML/System.hpp>

int main()
{
    sf::Clock Clock;
    sf::String s;
    char buffer[10];
    Uint32 time;

    time=Clock.GetElapsedTime();
    while(time<5000)
    {
       
        int hours = time/3600000; // We get the number of hours, there's 3600000 milliseconds in each hour
        time -= hours * 3600000; // Now that we know the number of hours, we remove that number of milliseconds from time so we can figure out the minutes left over.
        itoa(hours, buffer, 10);
        s=buffer;      // I took a quick look at String's documentation, I think this is valid.
                       // You might have to do a bit more magic to get the chars into the string, but at least buffer now has the right values
        s+=" hours, "; //s only contained a number (written in characters), now it contains the string "hh hours, " where hh means the number of hours

        int minutes = time / 60000 ; // There's 60000ms in each minute
        time -= minutes * 60000;
        itoa(minutes, buffer, 10);
        s+=buffer; s+=" minutes, ";

        int seconds = time / 1000; // Naturally, there are 1000ms per second
        time -= seconds * 1000;
        itoa(seconds, buffer, 10);
        s+=buffer; s+=".";
        itoa(time, buffer, 10);
        s+=buffer; s+=" seconds.\n";

        // Right now, s contains a string that looks like "hh hours, mm minutes, ss.mmm seconds."
        // You can now attempt to display the string in whatever manner best suits your needs.
        time=Clock.GetElapsedTime();
    } // The loop will run for 5 seconds before exiting.
       
    return 0;
}

35
SFML projects / Asteroids!
« on: June 17, 2011, 07:13:14 am »
Asteroids! blog

Latest post - 14/Nov/2011 - Giving shape to the world - One step closer to the dream.

Latest demo - 07/Nov/2011 - Framework-0.0.8 - Moved to zip files so that people didn't have to deal with unpacking 7z files.

Now with YouTube video! This should give the people that can't see the videos a glimpse of what I'm working on.

Basically, I started out with the grand, ridiculous dream of building a procedural universe. A sci-fi sandbox to fit an Elder Scrolls sort of open ended RPG into.

While this remains the ultimate goal of this project, it would be unrealistic to hope to reach that point on the first go. Instead, for it's first iteration, I want to make a relatively simple 'Asteroids 3D!' game, with newtonian physics and blastery, crashing (into the asteroids, hopefully not the computer) fun.



While still pretty up there in terms of difficulty, especially for a single developer's first attempt, it should be achievable in a reasonable timeframe.

The project's overarching goals, however, require a pretty robust framework be put in place. So that's what this project is about; trying to figure out a program design that will be extensible, flexible, portable (though this is low priority) and powerful enough for my needs, while still keeping it fun and focused.

My tools are the OpenGL SuperBible 5th edition, Code::Blocks, MinGW, SFML, GLEW, and Git. And not enough free time.

I'm keeping a blog detailing my efforts here. I began writing for myself, so it can be difficult to follow at times, but I've been improving in that regard.

It recounts my struggles with NeHe's tutorials and SDL before I knew anything about shaders vs. fixed pipeline. In this regard, the SuperBible has been awesome. Highly recommend it to anyone who wants to work with OpenGL. It also has a nifty library and tutorials I've been canibalizing as I go.

I had a GitHub repository but I started using BitBucket instead. TortoiseHg is a much nicer GUI, I think. I want to clean up the code a bit before I let other people peek a it, though. It's an embarrasing mess of spaghetti right now.

--- Updates ---
Monday, November 14th, 2011
Giving shape to the world - One step closer to the dream.

Monday, November 7th, 2011
Been a while. New demo out :D Lighting now works. So shiny!

Looking good. Looking real good.

Framework-0.0.8 - Moved to zip files so that people didn't have to deal with unpacking 7z files.

Monday, October 10th, 2011
New Demo out! Now with collision detection worked into it.
Framework-0.0.7 - Bouncy
Also posted on the blog, how space partitioning helps cut down on the computation required for collision detection.
Collision Detection - Part 3 - Space Partitioning - Divide and Conquer

Monday, October 3, 2011
Been a busy week, couldn't get a lot of work in, but I had time for an update to the blog.

Collision Detection - Part 2 - Resolution - What do we do after detecting the collision?

Monday, September 26, 2011
Collision Detection - Part 1 - Detecting it - I'm going to spend a few weeks explaining how I go about doing the collision detection in the program, with hopefully a working example by next week.

Monday, September 12, 2011
Framework-0.0.6r - Shooting is important.

It's full of stars! - Working on the background, so I can get rid of the green lines.

Deus Ex is fun, but it kills productivity.

Monday, September 5, 2011
Framework-0.0.5.1 - Got the chase camera working. Switch with C. Exit key set to P to avoid quitting by accident.

Saturday, September 3, 2011
New version is up!
Framework-0.0.5r - Cockpit view; camera now moves about the world. The ship itself isn't visible while in this view (currently). Got a background to keep yourself oriented and spread a few spheres about to spice things up.

Next up, working out why the chase view is being difficult.

Wednesday, August 31, 2011

Last update for today:
Framework-0.0.4r - Now with angular momentum!

Wednesday, August 31, 2011

After quite a bit of work, undoing and redoing stuff, I have a working demo:

Framework-0.0.3r - Sphere Edition
Framework-0.0.2r - Triangle Edition

36
Window / Creating a double-buffered window
« on: June 15, 2011, 07:48:49 pm »
Oh, ok. Thought it might be, but wanted to be sure.

So sf::Window::Display() then swaps the buffers?

37
Window / Creating a double-buffered window
« on: June 15, 2011, 07:04:22 pm »
I wanted to ask, because I couldn't see it mentioned in the documentation for sf::Window. When creating a rendering context, how do you request that the context be double buffered?

Wondering what the equivalent of
Code: [Select]
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);would be in SFML.

38
Network / need help with UDP socket
« on: June 14, 2011, 10:52:04 pm »
Not sure if this helps, but port forwarding usually refers to messages arriving from the WAN side of the router, being routed to a specific IP on the LAN. Not sure how the router will handle a request to the router's WAN IP from the LAN.

Have you considered trying to mail the program to a friend for them to try hitting your router's IP from outside the LAN?

39
General discussions / Shared libraries management with Windows
« on: June 14, 2011, 09:50:06 pm »
Not sure about the side-by-side stuff and the like, but I was always under the impression that System32 was meant for applications to store their dlls if they wanted to?

40
Window / inconsistency on fullscreen stretching
« on: June 14, 2011, 08:14:17 pm »
Fullscreen only works correctly if you pass a valid videomode. You can look it up in the documentation:

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php

Quote
An optional style can be passed to customize the look and behaviour of the window (borders, title bar, resizable, closable, ...). If style contains Style::Fullscreen, then mode must be a valid video mode.


You are telling the create function to make a fullscreen window with 800x600 resolution, which may not be a valid value. To be certain of what video modes your screen accepts, you can use GetFullscreenModes () (documentation for VideoMode class found here: http://www.sfml-dev.org/documentation/2.0/classsf_1_1VideoMode.php) which provides a vector with all the valid video modes.

If you just want to use the current resolution and bitdepth of the desktop, you can use GetDesktopMode().

The question I have to ask is, what is it that you want? Do you want to stretch a low resolution over the full screen (things will look pixelated and large) or get the full screen at the native resolution of the monitor (1920x1080)?

If it's the former, you need to make sure the resolution you are requesting is valid (use GetFullscreenModes() ). If it's the latter, DON'T specify a lower resolution and use GetDesktopMode().

To answer the last question: The default behavior is to provide you with the resolution you asked for. The documentation doesn't say what happens when the value is not valid, which means you should be making sure the value is valid before creating a full screen window.

41
General / Sine wave movement
« on: June 14, 2011, 08:01:48 pm »
Couple of things:

Are you passing x to the sine function as degrees, or radians? What does the function expect? If the function works with radians, and you are passing the x coordinate in the range 0-800, the sprite will advance about 120 waves (800 / 2pi) in the course of traversing the screen. This will lead to jerkiness as you grab it at different heights.

If it works with degrees, it should result in a more smooth result, as you'd only go through (800 / 360) 2 waves instead of 120.

Also, careful when multiplying by times; SFML uses ms, meaning at 60 frames per second you're multiplying by 16 (lower framerates provide a bigger multiplier).

Further, the result of sin(x) is going to be between -1 and 1. You'll need a scaling factor for this to even be evident (otherwise it's moving at most 1 pixel up or down). Multiplying by 10 only gets you up to a 20 pixel amplitude in the movement.

If you provide a more detailed sample we can help more.

42
General / Problem compiling SFML: 'GetThreadId' not declared in scope
« on: June 14, 2011, 03:21:12 pm »
Thanks. I took a moment to see the change yesterday, and look up the function. It appears on http://msdn.microsoft.com/en-us/library/ms683233%28v=vs.85%29.aspx, mentioning it should be in Winbase.h (with _WIN32_WINNT defined as 0x0502 or later, which should be Windows Server 2003 with SP1, Windows XP with SP2 if I understood the "Using the Windows Headers" page right), but at least in my compiler's headers it didn't appear.

Guessing maybe the next version of the compiler might have it? Not really used to the Windows API, that's one of the reasons why I'm using SFML in the first place :P

43
General / Problem compiling SFML: 'GetThreadId' not declared in scope
« on: June 14, 2011, 01:05:43 am »
I only just started using SFML and running a few tutorials. I used Git to get the project from GitHub, and ran CMake and compiled without problems. A couple days later I saw there were a few more commits to the project, so I ran fetch, merge, and tried to recompile. It then ran into a couple problems, but I assumed I had done something wrong and still had the compiled libraries, so I didn't think much of it.

Today I downloaded the project for a fresh install into another computer, so I could code on it as well, and again the make failed. So I thought I'd post it here.

I'm using Win7 with MingW, using MSYS for the console (I tried with the Git Bash and had the same issue).

After configuring the makefile for MinGW in CMake, I cd to the directory and run mingw32-make install, and this is the output:

Code: [Select]
$ mingw32-make install
Scanning dependencies of target sfml-system
[  1%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj
[  2%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Err.cpp.obj
[  3%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Lock.cpp.obj
[  5%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Mutex.cpp.obj
[  6%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Sleep.cpp.obj
[  7%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/String.cpp.obj
[  8%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Thread.cpp.obj
[ 10%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/ThreadLocal.cpp.obj
[ 11%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Win32/MutexImpl.cpp.obj
[ 12%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Win32/Platform.cpp.obj
[ 14%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Win32/ThreadImpl.cpp.obj
D:\libs\SFML\src\SFML\System\Win32\ThreadImpl.cpp: In member function 'void sf::priv::ThreadImpl::Wait()':
D:\libs\SFML\src\SFML\System\Win32\ThreadImpl.cpp:63:33: error: 'GetThreadId' was not declared in this scope
mingw32-make[2]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/Win32/ThreadImpl.cpp.obj] Error 1
mingw32-make[1]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/all] Error 2
mingw32-make: *** [all] Error 2


Can't tell right now if it's the same problem I ran into in the other computer (meaning a commit maybe did something?) or some configuration issue on my end.

44
General discussions / Switched times to Uint32 milliseconds in SFML 2
« on: June 09, 2011, 09:46:26 pm »
The beauty of ints is you just concatenate them together, and get a bigger int.

It's only fifty days if you don't check for an overflow. If you expect the timer to have to go longer than 50 days, you can make a quick check to see if the new time is greater than the old time. If it isn't, add one to another int. This new int holds the number of times you overflowed. Multiply by fifty, and you got the whole length of days. For a regular 32 bit int, this method gives you millisecond precision out to... 18,446,744,073,709,551,615ms, which works out to 584,542,046 years.

Half a billion years should be enough for most purposes. Add another counter in case you overflow this one, and it should provide room for longer than the age of the universe.

Pages: 1 2 [3]