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 - The Terminator

Pages: 1 ... 3 4 [5] 6 7 ... 15
61
General / Trouble switching states...
« on: February 03, 2014, 02:57:12 am »
Never never never poll after window.display(). Have you read the SFML tutorials?

62
System / Re: I need urgent help with a project's music player
« on: February 01, 2014, 02:28:24 pm »
...fixed it by placing my music.openFromFile() outside of the window loop, and my first music.play() outside of the window loop.


It's good that you got it working, but hopefully this will become a lesson to you. Learn C++ now so you can be independent and won't have to depend on others telling you what to do or by trial and error. I wish you the best of luck. :)

63
SFML projects / Thor 2.0
« on: January 31, 2014, 01:44:26 pm »

Another advantage of namespaces is that you can keep them long and expressive:
namespace ShockEngine
{
    // your library
}

In user code, you can still create aliases, even for nested namespaces:
namespace shk = ShockEngine;
namespace si = ShockEngine::Input;

shk::InputManager mgr;

You can also locally "empty out" the namespace (but never do this in headers):
using namespace ShockEngine;

I am using namespaces as well. Well known libraries and engines have a prefix similar to mine such as Ogre3D. I am open to new ideas, but I think that the prefix will stay.

64
SFML projects / Re: Thor 2.0
« on: January 31, 2014, 03:54:28 am »
You still need _1 as the last argument in std::bind() -- it specifies the thor::ActionContext argument that is forwarded. Furthermore, for member functions you should pass a pointer, not a reference to the object.
std::bind(&SE::SInputManager::onTextEntered, this, _1)

If you struggle at understanding std::bind(), just use lambda expressions.

And have you seen my advice concerning "S" prefixes? ;)

Thanks a lot! Regarding the S prefixes, they are not being used in the same way C prefixes were. In my engine, all code that belongs to it is marked with an S (stands for Shock, my engine is called Shock Engine) prefix to differentiate between engine code and user game code.

65
SFML projects / Re: Thor 2.0
« on: January 29, 2014, 09:57:37 pm »
Anyway, it would be easier to have a non-static member function, and pass this as the second parameter (first after function name) to std::bind().

I've been reading a little bit about std::bind and functors. I fully understand functors now, but I'm still having a little bit of trouble with std::bind. I've done exactly what you said (remove static and pass this to connect) but I'm still having some issues. My code:

m_callback_system.connect(User_Input::TEXTENTERED, std::bind(&SE::SInputManager::onTextEntered, *this));

Thanks again!

66
SFML projects / Re: Thor 2.0
« on: January 26, 2014, 06:07:30 pm »
There are multiple possibilities what you can pass to connect().

Functor:
struct Functor
{
    void operator() (const thor::ActionContext<...>& context) const
    {
        SInputManager::onTextEntered(context, instance);
    }

    const SInputManager& instance;
    ...
}

Lambda expression:
[&instance] (const thor::ActionContext<...>& context)
{
    onTextEntered(context, instance);
}

Bind (_1 is in namespace std::placeholders):
std::bind(&SInputManager::onTextEntered, _1, std::cref(instance))

onTextEntered() can also be a non-static member function, you have to adapt the function objects accordingly. I recommend reading more about function objects in C++, they're very powerful.

And don't use those S prefixes for classes, there is really no reason to :(

I'm going to std::bind route, and the code compiles, but the application crashes right as invokeCallbacks is called. My code:

static void onTextEntered(const thor::ActionContext<User_Input>& context,
                           const SInputManager& instance);

m_callback_system.connect(User_Input::TEXTENTERED, std::bind(&SE::SInputManager::onTextEntered,
                                                                     std::placeholders::_1,
                                                                     std::cref(*this)));

m_user_map.invokeCallbacks(m_callback_system, nullptr);

    void SInputManager::onTextEntered(const thor::ActionContext<User_Input>& context, const SInputManager& instance)
    {
        sf::Uint32 character = context.event->text.unicode;

        m_textEntered += character;
    }

67
SFML projects / Re: Thor 2.0
« on: January 26, 2014, 05:08:54 pm »
// Callback function that is called when text entered event is triggered
void onTextEntered(const thor::ActionContext<MyAction>& context)
{
        sf::Uint32 character = context.event->text.unicode;
        ...
}

// Action map initialization
thor::ActionMap<MyEnum> map;
map[MyTextAction] = thor::Action(sf::Event::TextEntered);

// Callback registering
thor::ActionMap<MyEnum>::CallbackSystem callbacks;
callbacks.connect(MyTextAction, &onTextEntered);

Thanks! I have one more question. Let's say I have the onTextEntered method, but want to change it a little bit:

static void onTextEntered(const thor::ActionContext<User_Input>& context,
                                  const SInputManager& instance);

How would I connect the callback to the system?

68
System / Re: I need urgent help with a project's music player
« on: January 25, 2014, 10:16:29 pm »
Well, your switch statement is totally unnecessary. You can accomplish the same thing more easily doing this:

if (trackNumber >= 0 && trackNumber <= 2)
    trackNumber++;

else
    trackNumber = 0;

69
SFML projects / Re: Thor 2.0
« on: January 25, 2014, 08:40:18 pm »
Hi Nexus,

I have a quick question regarding sf::TextEntered. Now, with the default SFML polling you can do things like this:

if (event.type == sf::Event::TextEntered)
{
    if (event.text.unicode < 128)
        std::cout << "ASCII character typed: " << static_cast<char>(event.text.unicode) << std::endl;
}

Using Thor's actions, how would I be able to find out what key the user has pressed?

Thanks!

70
SFML projects / Re: My small 2D game creation software - [Game Inventor]
« on: January 20, 2014, 10:21:57 pm »
Very neat! I downloaded and I didn't have any problems.

71
SFML projects / Re: Thor 2.0
« on: January 12, 2014, 01:17:23 am »
Hi there Nexus,

Is there a way to do this:

thor::Action left_press(sf::Mouse::Left, thor::Action::PressOnce);
thor::Action left_hold(sf::Mouse::Left, thor::Action::Hold);

m_input_map[User_Input::USER_MOUSE_LEFT_PRESS] = left_press | !left_hold;

Basically just saying that USER_MOUSE_LEFT_PRESS cannot be left_hold. The reason I want this is because of this:
 
if (m_input_manager.getInputMap().isActive(User_Input::USER_MOUSE_LEFT_PRESS))
        std::cout << "wassup" << std::endl;

else if (m_input_manager.getInputMap().isActive(User_Input::USER_MOUSE_LEFT_HOLD))
        std::cout << "wassup 2" << std::endl;

Whenever I click once, it'll say "wassup" once and "wassup 2" about 5-6 times. I want there to be a clear difference between USER_MOUSE_LEFT_PRESS and USER_MOUSE_LEFT_HOLD. Is there any way to do this? (PS: setKeyRepeatEnabled is already false)

Thanks!

72
System / Re: How would I do this every millisecond?
« on: December 30, 2013, 05:50:24 am »
There's a much simpler way to do that. Here's some code that gradually shifts from colour1 at 0 seconds, to colour2 at 3 seconds, to colour3 at 10 seconds;

Code: [Select]
// use vector2f's for our colours (0=min, 1=max)
sf::Vector2f c1, c2, c3;
sf::Clock clock;

// handy linear interpolation
sf::Vector2f lerp(sf::Vector2f a, sf::Vector2f b, float t){
  return a*(1-t) + b*t;
}

// main loop

const double seconds = clock.getElapsedTime.asSeconds();
sf::Vector2f c;
if (seconds <= 3){
  double t = seconds / 3; // t goes from 0 to 1
  c = lerp(c1, c2, t);
}
else if (seconds <= 10){
  double t = (seconds - 3) / (10-3);
  c = lerp(c2, c3, t);
}
else {
  // after 6 seconds stay as colour 3
  c = c3;
}

// transform c into an sf::Color which we can then use to draw something
sf::Color colour = sf::Color(255*c.x, 255*c.y, 255*c.z);



You can also replace the lerp with other easing functions, such as cubic, easeIn, quadratic, etc, to change how the colour shift behaves. See e.g., this page for other easing functions.

Thanks for the info! On transforming c, you use c.z which is nonexistent in a sf::Vector2f. Did you mean to put sf::Vector3f?

Thanks

73
System / How would I do this every millisecond?
« on: December 30, 2013, 03:49:52 am »
Hi there,

For a label that I'm creating on my main menu, I want it to animate over 3 colors in 9 seconds. The 3 color RGBA values are: (255, 255, 255, 50), (0, 161, 94, 50), (102, 0, 0, 50). To give it the "gradual" effect, I want it to increase or decrease the RGBA values of an sf::Color every millisecond. In order to get the value to increase or decrease per millisecond, I just found the difference of the respected values and divided it by 1000. Here's my (unworking) code that I've written:

(FYI: m_totalTime is a private float value in a class, m_animated_label_clock is a sf::Clock private member, and m_label_color is a sf::Color private member.)

if (m_totalTime <= 3)
        {
            if (m_animated_label_clock.getElapsedTime().asMilliseconds() == 0.001)
            {
                m_label_color.r -= 0.085;
                m_label_color.b -= 0.0313;
                m_label_color.g -= 0.0683;
            }
        }

        else if (m_totalTime > 3 && m_totalTime <= 6)
        {
            if (m_animated_label_clock.getElapsedTime().asMilliseconds() == 0.001)
            {
                m_label_color.r += 0.034;
                m_label_color.b -= 0.0536;
                m_label_color.g -= 0.0313;
            }
        }

        else if (m_totalTime > 6 && m_totalTime <= 9)
        {
            if (m_animated_label_clock.getElapsedTime().asMilliseconds() == 0.001)
            {
                m_label_color.r += 0.102;
                m_label_color.b -= 0.161;
                m_label_color.g -= 0.094;
            }
        }

        m_totalTime += m_animated_label_clock.getElapsedTime().asMilliseconds();
        m_animated_label_clock.restart();

Thanks for any and all help!

74
Ok, I got it all figured out and it works now. Thanks everyone for the help!

75
Alright, did that, more errors (Yippee!!!!!!!)


-------------- Build: Debug in Shock Engine (compiler: GNU GCC Compiler)---------------

WARNING: Can't read file's timestamp: C:\Users\Peter Senyszyn\Desktop\Shock Engine\Shock_Engine\Engine\ShockScript\ParticleSystemParser.cpp
WARNING: Can't read file's timestamp: C:\Users\Peter Senyszyn\Desktop\Shock Engine\Shock_Engine\GUI\ParticleSystem.cpp
WARNING: Can't read file's timestamp: C:\Users\Peter Senyszyn\Desktop\Shock Engine\Shock_Engine\GUI\ParticleSystemManager.cpp
mingw32-g++.exe -L"C:\Program Files (x86)\SFML\lib" -L"C:\Program Files (x86)\thor\lib"  -o "bin\Debug\Shock Engine.exe" obj\Debug\main.o obj\Debug\Shock_Engine\Engine\Engine.o obj\Debug\Shock_Engine\Engine\ShockScript\GUIParser.o obj\Debug\Shock_Engine\Engine\ShockScript\Parser.o obj\Debug\Shock_Engine\Engine\ShockScript\ParticleSystemParser.o obj\Debug\Shock_Engine\Gameplay\Camera.o obj\Debug\Shock_Engine\Gameplay\ObjectManager.o obj\Debug\Shock_Engine\Gameplay\Player.o obj\Debug\Shock_Engine\GUI\Background.o obj\Debug\Shock_Engine\GUI\Button.o obj\Debug\Shock_Engine\GUI\FPS.o obj\Debug\Shock_Engine\GUI\GUI.o obj\Debug\Shock_Engine\GUI\GUIObject.o obj\Debug\Shock_Engine\GUI\Label.o obj\Debug\Shock_Engine\GUI\ParticleSystem.o obj\Debug\Shock_Engine\GUI\ParticleSystemManager.o obj\Debug\Shock_Engine\GUI\RadioBox.o obj\Debug\Shock_Engine\States\IntroState.o    -lthor-d -lsfml-audio-d -lsfml-graphics-d -lsfml-window-d -lsfml-system-d
obj\Debug\Shock_Engine\Engine\ShockScript\ParticleSystemParser.o: In function `ZN2SE14ParticleSystem17addTorqueAffectorEf':
C:\Users\Peter Senyszyn\Desktop\Shock Engine/Shock_Engine/GUI/ParticleSystem.hpp:27: undefined reference to `_imp___ZN4thor14TorqueAffector6createEf'
C:\Users\Peter Senyszyn\Desktop\Shock Engine/Shock_Engine/GUI/ParticleSystem.hpp:27: undefined reference to `_imp___ZN4thor14ParticleSystem11addAffectorESt10shared_ptrINS_8AffectorEE'
obj\Debug\Shock_Engine\Engine\ShockScript\ParticleSystemParser.o: In function `ZN2SE14ParticleSystem16addForceAffectorEN2sf7Vector2IfEE':
C:\Users\Peter Senyszyn\Desktop\Shock Engine/Shock_Engine/GUI/ParticleSystem.hpp:30: undefined reference to `_imp___ZN4thor13ForceAffector6createEN2sf7Vector2IfEE'
C:\Users\Peter Senyszyn\Desktop\Shock Engine/Shock_Engine/GUI/ParticleSystem.hpp:30: undefined reference to `_imp___ZN4thor14ParticleSystem11addAffectorESt10shared_ptrINS_8AffectorEE'
obj\Debug\Shock_Engine\Engine\ShockScript\ParticleSystemParser.o: In function `ZN2SE6Engine24getParticleSystemManagerEv':
C:\Users\Peter Senyszyn\Desktop\Shock Engine/Shock_Engine/Engine/Engine.hpp:63: undefined reference to `SE::Engine::m_particleSystemManager'
obj\Debug\Shock_Engine\GUI\ParticleSystem.o: In function `ZN2SE14ParticleSystemC2ERKSs':
C:/Users/Peter Senyszyn/Desktop/Shock Engine/Shock_Engine/GUI/ParticleSystem.cpp:10: undefined reference to `_imp___ZN4thor16UniversalEmitter6createEv'
C:/Users/Peter Senyszyn/Desktop/Shock Engine/Shock_Engine/GUI/ParticleSystem.cpp:12: undefined reference to `_imp___ZN4thor14ParticleSystemC1ESt10shared_ptrIKN2sf7TextureEE'
obj\Debug\Shock_Engine\GUI\ParticleSystem.o: In function `ZN2SE14ParticleSystem13createEmitterEffN2sf7Vector2IfEE':
C:/Users/Peter Senyszyn/Desktop/Shock Engine/Shock_Engine/GUI/ParticleSystem.cpp:24: undefined reference to `_imp___ZN4thor14ParticleSystem10addEmitterESt10shared_ptrINS_7EmitterEE'
obj\Debug\Shock_Engine\GUI\ParticleSystem.o: In function `ZN2SE14ParticleSystem16addFadeAnimationEff':
C:/Users/Peter Senyszyn/Desktop/Shock Engine/Shock_Engine/GUI/ParticleSystem.cpp:36: undefined reference to `_imp___ZN4thor17AnimationAffector6createESt8functionIFvRNS_8ParticleEfEE'
C:/Users/Peter Senyszyn/Desktop/Shock Engine/Shock_Engine/GUI/ParticleSystem.cpp:36: undefined reference to `_imp___ZN4thor14ParticleSystem11addAffectorESt10shared_ptrINS_8AffectorEE'
collect2.exe: error: ld returned 1 exit status

Of course for both... ::)

You should really learn how to linking works.

I know :D. It's a serious hole in my knowledge that I'm trying to fix.

Pages: 1 ... 3 4 [5] 6 7 ... 15
anything