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

Pages: 1 ... 5 6 [7] 8 9 ... 15
91
Feature requests / sf::Thread::GetThreadID + Wait Events
« on: July 16, 2011, 06:46:09 am »
FWIW, I was able to simulate the event idea with just basic threads and mutexes.  A native implementation would be better, though, as the below approach involves creating an entirely separate thread, and has additional latency due to sleeping:

Code: [Select]

class ThreadEvent : public sf::NonCopyable
{
public:
    ThreadEvent()
        : mThread(&ThreadEvent::ThreadLogic,this)
        , mState(state_none)
        , mWantExit(false)
        , mIsLocked(false)
    {
        mThread.Launch();
    }

    ~ThreadEvent()
    {
        mWantExit = true;
        mThread.Wait();
    }

    inline bool IsLocked()  {   return mIsLocked;                   }
    inline void Lock()      {   ChangeState( state_wantlock );      }
    inline void Unlock()    {   ChangeState( state_wantunlock );    }

    inline void Wait()      {   mStateLock.Lock(); mStateLock.Unlock(); }

private:
    void ThreadLogic()
    {
        while(!mWantExit)
        {
            if(mState == state_wantlock)
            {
                if(!mIsLocked)
                {
                    mStateLock.Lock();
                    mIsLocked = true;
                }
                mState = state_none;
            }
            if(mState == state_wantunlock)
            {
                if(mIsLocked)
                {
                    mStateLock.Unlock();
                    mIsLocked = false;
                }
                mState = state_none;
            }
            try{
            sf::Sleep(1);
            }catch(...){}
        }

        if(mIsLocked)
            mStateLock.Unlock();
    }

    sf::Thread      mThread;
    sf::Mutex       mStateLock;     // locked by mThread when state is "reset"
    sf::Mutex       mStateChange;   // locked to guard state changes

    enum state_t
    {
        state_none,
        state_wantlock,
        state_wantunlock
    };
    volatile state_t    mState;
    volatile bool       mIsLocked;
    volatile bool       mWantExit;

   
    void     ChangeState(state_t newstate)
    {
        sf::Lock lock(mStateChange);
        mState = newstate;
        while(mState != state_none)
            sf::Sleep(1);
    }
};

92
Feature requests / sf::Thread::GetThreadID + Wait Events
« on: July 16, 2011, 04:15:46 am »
I'm a little surprised that sf::Thread doesn't have static GetThreadID or similar function which returns a thread-unique identifier for the current thread.

Can we get this added?


EDIT:

Also WinAPI has a threading feature that I just realized I need if I want to implement this thing I have in mind.

WinAPI has these "Event Objects" which are used for inter-thread communication.  The idea is, the event has a boolean state (set or unset).  Threads can then "wait" for the event until it has been set.

As soon as the event has been set, all threads waiting for it are resumed.

Any thread can set/unset the event state.

Of course, since SFML uses "Event" for something completely different, it would have to be renamed.  But I think it would be a great addition.

EDIT2:  More reading:

http://msdn.microsoft.com/en-us/library/ms686915%28v=VS.85%29.aspx

93
Graphics / Collision detection problem
« on: July 15, 2011, 04:39:35 pm »
Somewhat offtopic, but I felt obligated to chime in because I see people doing this a lot.


Pythagorean Theorum is a*a + b*b = c*c
Somehow people got it in their heads that sqrt(a*a + b*b) = c is a better way to do it.  But really, it's not, because sqrt is expensive.

You're better off sticking with the original theorum unless you need the exact value of c (which, for this collision detection, you don't).

Example of what I mean:

Code: [Select]

   // what you're doing:
   distance = sqrt((distX*distX)+(distY*distY));
   sumOfRadii = r1 + r2;

   return distance <= sumOfRadii;

Code: [Select]

   // what would be better:
   distanceSquared = (distX*distX)+(distY*distY);  // get rid of sqrt
   sumOfRadiiSquared = r1 + r2;
   sumOfRadiiSquared *= sumOfRadiiSquared;  // multiplication is cheaper

   return distanceSquared <= sumOfRadiiSquared;

94
Graphics / How do I display a variable?
« on: July 14, 2011, 07:53:12 pm »
Quote
I've noticed that on some systems/compilers/environments/whatever, you need to include "string.h" and not "string" to get all of its functions. Dont ask me why. Personally I've only came across this using GCC


<string.h>  (aka <cstring>) and <string> are two completely different headers.

<cstring> has things like strcpy, strcmp, etc
<string> has the std::string class

95
General discussions / Naming conventions - functions
« on: July 13, 2011, 07:09:13 am »
I've always preferred capitalized function and class names.

The Java-esque approach where you lowercase the first letter but capitalize all the later ones (getWhateverValue) always seemed out of whack and weird to me.  The lowercase just looks/feels out of place.  I never understood how that became commonly accepted.

lowercase with underscores (get_whatever_value) is even worse because underscores are harder to type.

SFML more or less follows the same trend of already existing APIs in the same field.

- DirectX shares the same style as WinAPI (practically identical to SFML)

- OpenGL does the same thing, but prefixes functions with "gl" (glGetWhatever), similar to how SFML is if you include the namespace qualifier (sf::GetWhatever)

- SDL also does the same thing, but prefixes with "SDL_"  (SDL_GetWhatever)


Changing styles now would be going further from existing conventions, IMO.  Personally I like it the way it is.


EDIT:

As far as boost and std are concerned, it makes sense for boost to mimic std's style because it acts as an extention of std.  Personally I'm not crazy about that style but it does make sense in that context.

I don't put SFML in the same category as boost though.  Sure it's a 3rd party library, but that's as far as the similarities go.  Boost and std are targetting generic infrastructure issues, whereas SFML's target(s) is/are very specific.

96
Feature requests / Request: Exceptionhandling?
« on: July 10, 2011, 01:02:34 pm »
For SFSL, I was strongly considering taking the WinAPI approach to error handling.  Keep the simplistic true/false return, but provide more details about the error if needed via a GetLastError/SetLastError mechanism.

The last error could be stored in a sf::ThreadLocalPtr making it threadsafe.

Adding the possibility of throwing on failure is relatively easy with this setup, as well.  You could allow the user to specify boolean values to indicate whether or not they want it to throw on specific errors.  Then in SetLastError, if you set such an error, just throw it.


EDIT:

Another possibility is deriving classes from a common "Errorer" class which has its own Get/Set error functions.

97
Graphics / Share your collisiondetection techniques!
« on: July 01, 2011, 04:43:44 am »
Can you elaborate on that?

I know the separating axis theorum is that any two convex polygons that do not intersect have an line that separates them.  However I never understood how you'd go about finding that line and/or whether or not it exists.

I'd be very interested in a more detailed explanation and/or example code.

EDIT:  and I can see how it could apply to object/object collision, but how could you apply it to object/world collision?

98
General discussions / Filesystem from SFML?
« on: July 01, 2011, 12:08:04 am »
Progress on SFSL has been slowed because I'm in the middle of a job transition, but I am still working on it!

99
Graphics / Share your collisiondetection techniques!
« on: July 01, 2011, 12:06:32 am »
My latest [serious] game attempt (2D platformer) does everything line based.  The map itself is not tile based like many platformers.  Instead it consists of a series of line segments forming the walls/ground.  This allows for slopes at any angle.

Objects are represented by "a bounding box with a twist".  Basically the bottom-center point represents the "foot".  The bottom left and right corners are raised.  So it ends up looking kind of like this:
Code: [Select]

__
||
\/


How steep the 'V' at the bottom is determines how steep a slope the object is able to climb.


The actual collision detection is all based on line-line collisions.  When an object moves, I draw lines from each of the corners moving in the direction the object wants to move.  If those lines intersect with any wall lines, then I stop the object.

There are other tricks to get it all working, but that's the general idea.

100
General / SFML with CodeBlocks problem
« on: June 28, 2011, 05:19:15 am »
You need to add whatever directory Code Blocks is in to your %PATH% environment variable.

How to do this though, I'm not entirely sure.  Maybe someone else can fill in the blanks.

101
General / SFML with CodeBlocks problem
« on: June 27, 2011, 06:49:06 am »
Probably have to compile SFML.  Try this (from same page):

Quote
a batch script named build.bat exists in SFML-x.y\build\codeblocks\batch-build. This script automatically compiles the SFML libraries for all configurations (debug/release static/dynamic) and performs the extra step required for static libraries. All you have to do before running it is to make your Code::Blocks executable (codeblocks.exe) available, i.e. add its path to the PATH environment variable.


Find that batch file and run it.  It should produce the dlls you need.


Quote
Sorry for all the trouble.


No need to apologize.  It's hard starting out.  We've all been there.

102
Graphics / Load from resource file
« on: June 26, 2011, 07:38:20 pm »
The only way I could see that code failing is if FindResource is failing.

Did you check resBlock to make sure it's non-NULL?

103
General / SFML with CodeBlocks problem
« on: June 26, 2011, 02:17:58 am »
That's because you need to link to the library.   =P

See this page:

http://www.sfml-dev.org/tutorials/1.6/start-cb.php

Scroll down to the "Compiling your first SFML program". Note the steps after the code snippit. Do those.

104
General / SFML with CodeBlocks problem
« on: June 26, 2011, 12:59:06 am »
You need to link to the library.

See this page:

http://www.sfml-dev.org/tutorials/1.6/start-cb.php

Scroll down to the "Compiling your first SFML program".  Note the steps after the code snippit.  Do those.

105
Graphics / game engine question 2
« on: June 25, 2011, 09:28:17 pm »
Quote
I'm using straight OpenGL for rendering, but I'd imagine a good strategy to use in SFML would be to render each chunk to a single sf::Image (or if you're using layers, one sf::Image per layer). Then, you only need one sf::Sprite per chunk, saving rendering time (though it would be more memory-expensive, as you'll need a large sf::Image per chunk).


I don't recommend this.

1)  Drawing individual tiles is not that much slower.  (try it and see)

2)  Drawing full layers might actually be slower if you have large portions of the layer which are fully transparent.  You can skip over/ignore individual tiles that are transparent, but if you're drawing the full layer all at once, the renderer will have to draw all of them.

3)  Drawing individual tiles lets you do other snazzy things, like have tiles that animate.

Pages: 1 ... 5 6 [7] 8 9 ... 15
anything