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

Pages: [1] 2
1
I do that in the game loop, the line :
m_displayMgr->PollWindowEvents(*InputManager::GetEventClass());
 

The PollWindowEvents method looks like this :

void DisplayManager::PollWindowEvents(sf::Event evnt) const
{
        m_window->pollEvent(evnt);
}
 

2
I'm having a problem where sf::Event::type is by "default" (as soon as the window opens) equal to sf::Event::Closed, which results in as soon as the window opening, it runs trough the game loop once and then exits the game.

My game loop looks like this :

        while (InputManager::CloseEventDetected() == false)
        {
                m_displayMgr->PollWindowEvents(*InputManager::GetEventClass());
                InputManager::HandleInput();

                m_displayMgr->GetRenderWindow()->draw(*m_levelMgr);
                m_displayMgr->Render();

                std::cout << "Closed evnt : " << InputManager::CloseEventDetected() << std::endl;
        }
 

And my InputManager header file looks like this :
#pragma once
#include <SFML\Graphics.hpp>

class InputManager
{
public:

        static void HandleInput();

        static bool IsKeyDown(sf::Keyboard::Key key);
        static bool isKeyDownRepeat(sf::Keyboard::Key key);

        static bool IsKeyUp(sf::Keyboard::Key key);
        static bool IsKeyUpRepeat(sf::Keyboard::Key key);

        static bool CloseEventDetected();

        static sf::Event* GetEventClass();

private:

        InputManager();

        static bool m_keys[sf::Keyboard::KeyCount];
        static bool m_keysLastFrame[sf::Keyboard::KeyCount];

        static bool m_closeEventDetected;

        static sf::Event* m_evnt;
};
 

And the cpp file looks like this :
#include "InputManager.h"

bool InputManager::m_keys[sf::Keyboard::KeyCount];
bool InputManager::m_keysLastFrame[sf::Keyboard::KeyCount];

bool InputManager::m_closeEventDetected = false;

sf::Event* InputManager::m_evnt = new sf::Event();

InputManager::InputManager()
{
        m_evnt = new sf::Event();
}

void InputManager::HandleInput()
{
        for (int i = 0; i < sf::Keyboard::KeyCount; i++)
        {
                m_keys[i] = (sf::Keyboard::isKeyPressed((sf::Keyboard::Key)i));

                m_keysLastFrame[i] = m_keys[i];
        }

        if (m_evnt->type == sf::Event::Closed)
        {
                printf("close detect");
                m_closeEventDetected = true;
        }

}

bool InputManager::IsKeyDown(sf::Keyboard::Key key)
{
        if (m_keys[key] == true && m_keysLastFrame[key] != true)
        {
                return true;
        }
        else
        {
                return false;
        }
}

bool InputManager::isKeyDownRepeat(sf::Keyboard::Key key)
{
        return m_keys[key];
}

bool InputManager::IsKeyUp(sf::Keyboard::Key key)
{
        if (m_keys[key] == true && m_keysLastFrame[key] != true) //TODO: Not sure if it works.
        {
                return false;
        }
        else
        {
                return true;
        }
}

bool InputManager::CloseEventDetected()
{
        return m_closeEventDetected;
}

sf::Event* InputManager::GetEventClass()
{
        return m_evnt;
}

bool InputManager::IsKeyUpRepeat(sf::Keyboard::Key key)
{
        return !m_keys[key];
}
 

Basically what happens is :

The window is created, and the game loop runs trough correctly once, but on the second loop InputManager::CloseEventDetected() returns true which results in the game loop breaking and the game closing.

But I can't seem to find any reason to why the sf::Event::type would be equal to Sf::Event::Closed.

3
General / Re: Cannot find cause of ntdll.dll crash in application
« on: February 20, 2017, 01:41:50 pm »
F12 is the Visual Studio shortcut for triggering a breakpoint.

Facepalm
Yeah, that explains it :P
Works now, thank you :)

4
General / Cannot find cause of ntdll.dll crash in application
« on: February 20, 2017, 12:44:01 pm »
Today I've been trying to implement a in-game console system for my game, I was just giving it a rectangle background, but when I ran the game it crashes as soon as I pressed F12 to open the console, and gave me ther error :

UntitledCppGame.exe has triggered a breakpoint.

When pressing the "break" button I was greeted by this page in visual studio :



And that is all information that Visual Studio gives me about the crash, and I have no idea at all how to find out what's causing it.

Here's the head and cpp file for the Console system :

Header :
#pragma once

#include "Input.h"
#include "BoxSprite.h"

class Console
{

public:

        Console();
        ~Console();

        void Initialize();

        void OpenConsole();
        void CloseConsole();

        void Draw();
        void Update();
        void HandleEvents();

        bool IsConsoleOpen();

        void PrintMessage(std::string file, std::string msg);
        void PrintWarning(std::string file, std::string msg);
        void PrintError(std::string file, std::string msg);
        void PrintFatal(std::string file, std::string msg);

private:

        const int M_CONSOLE_OPEN_BIND = sf::Keyboard::F12;

        bool m_isConsoleOpen;
        bool m_isConsoleReady = false;

        BoxSprite m_consoleRect;

};
 

Source :
#include "Console.h"

#include "Globals.h"

Console gConsole;

Console::Console()
{

}

Console::~Console()
{
}

void Console::Initialize()
{
        m_consoleRect = BoxSprite(Vector2(gGraphics.GetWindow().getSize().x, gGraphics.GetWindow().getSize().y / 3), Vector2(0, 0), Color::White);

        m_isConsoleReady = true;
}

void Console::Draw()
{
        if (m_isConsoleOpen == true)
        {
                m_consoleRect.Draw();
        }
}

void Console::Update()
{
       
}

void Console::HandleEvents()
{
       
        if (gInput.isKeyDown(M_CONSOLE_OPEN_BIND))
        {
                if (IsConsoleOpen() == true)
                {
                        CloseConsole();
                }
                else
                {
                        OpenConsole();
                }
        }

}

bool Console::IsConsoleOpen()
{
        return m_isConsoleOpen;
}

void Console::OpenConsole()
{

}

void Console::CloseConsole()
{

}

void Console::PrintMessage(std::string file, std::string msg)
{

}

void Console::PrintWarning(std::string file, std::string msg)
{

}

void Console::PrintError(std::string file, std::string msg)
{

}

void Console::PrintFatal(std::string file, std::string msg)
{

}
 

5
General / Re: Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 04, 2016, 09:34:15 pm »
Not at all... As already said, and probably well explained in the documentation, all the Texture::update functions upload new content to the texture. The Texture::update(Window&) overload uploads the contents of the window (ie. what you currently see) into the texture.

Don't try random stuff, just follow the doc and tutorials. And if you have problems, just ask.

Honestly not sure how, but when I read the docs, using update() seemed like the perfect solution to my problem. :P

Fixed the issue I had before I even tried using update though, for some reason SFML didn't like to render my .bmp so I made a png instead and it started working.

6
General / Re: Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 04, 2016, 08:58:32 pm »
Why would you overwrite a loaded texture with the content of the window? Usually you create an empty texture of the required size, when you want to update it from a window.

You should explain what you're trying to achieve, that will probably be faster than trying to fix whatever you think you must do ;)

I was having a problem where my game would run fine but not display a sprite.
After some playing around with it I found a update function which I assumed (for some reason) was used to update the texture when a image has been assigned to it.

Now on second thought, is that even what texture.update() should be used for...?

7
General / Re: Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 04, 2016, 08:01:55 pm »
No. You update the texture from the window. So the source is the window and the destination is the texture. So you're doing something wrong with your 32x32 texture.

Can't find out how to resize the texture so that it is the same size as my window since the texture resizes itself to the size of the loaded image.

8
General / Re: Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 04, 2016, 06:46:05 pm »
There's no scaling, it's a raw copy from the source window to the target texture. So if the source is bigger than the destination, you are out of the memory range which results in undefined behaviour. That's what the assert checks.

Oh yeah, ofc theres no scaling, was thinking of sprites. lol :P

By "source > distination" you mean "texture > window" ?
If yes, I know that the texture is much smaller than the window is.
(the texture is 32.x32 pixels, and the window is 1024x720)

9
General / Re: Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 04, 2016, 02:35:18 pm »
You should have added the correct line in a new reply instead of editing your first post. Now the whole thread looks very confusing :P

Anyway. The assertion is clear: the size of the window is greater than the size of the texture. Now it should be pretty easy for you to figure out why.

Shouldn't the size of the window be more than the texture?
If the window size is less wouldn't that result in a texture which covers the entire screen?

Or should the texture be bigger than the screen and then scaled down?

10
General / Re: Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 03, 2016, 10:41:36 am »
But why did you mention it in your first post? And are you really really sure that the assertion is triggered by mSprite.setTexture?

Not sure what you mean by "why did you mention it in your first post" ?
Yes, that is the line that triggers the assertion (according to visual studio at least), but I have no idea why.

Ediiiit :
No, incorrect line. Pasted the wrong line in the post ._. Sorry. Edited the original post with the correct line.

And now I understand what you meant, and that's the reason I mentioned it in my post :P

11
General / Re: Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 03, 2016, 12:38:22 am »
The GetWindow  function is this :

sf::RenderWindow& Graphics::GetWindow()
{
        return mWindow;
}

and mWindow is this :

sf::RenderWindow mWindow;

12
General / Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 02, 2016, 06:46:59 pm »
So, I'm trying to update my texture but when I do that my game triggers a assertion which tells me :
Assertion failed: x + window.getSize().x <= m_size.x, file (long path)\Texture.cpp

In my code, this line triggers the assertion :
gResourceMgr.GetTexture(textureName)->update(gGraphics.GetWindow());

GetTexture() is this :
sf::Texture* ResourceManager::GetTexture(std::string file)
{
        if (textures.find(file) != textures.end())
        {
                return textures.find(file)->second;
        }
        else
        {
                std::cout << "Failed to get file : " << file << " from resource manager." << std::endl;
                return nullptr;
        }
}

And the textures map looks like this :
std::map<std::string, sf::Texture*> textures;

The gGraphics.GetWindow() function simply returns a reference to the games RenderWindow.

Unsure what I'm doing wrong :/

13
I should probably have read the std::function documentation thing before posting.
But that made it work! Thank you :)

14
Oh, okay.

The function has no parameters, so I replaced void* func in the parameter with :

std::function<void> func

But now I get these errors instead :
Error   C2027   use of undefined type 'std::_Get_function_impl<_Fty>'
and
Error   C2504   'type': base class undefined
ยจ

I guess this is completely unrelated to both SFML and TGUi, should I post this somewhere else instead?

15
(Note, this is a TGUI / C++ question, not sure if this is where I should post it.)

I'm trying to do this :


void GUIManager::CreateButton(std::string m_identifier, std::string m_buttonText, std::string m_fontPath, void* func, float m_xPos, float m_yPos, float m_width, float m_height)
{
       
        tgui::Button::Ptr m__temp_btn = std::make_shared<tgui::Button>();

        m__temp_btn->setFont(m_fontPath);
        m__temp_btn->setText(m_buttonText);
        m__temp_btn->setPosition(m_xPos, m_yPos);
        m__temp_btn->setSize(m_width, m_height);

        _buttonList.insert(std::make_pair(m_identifier, m__temp_btn));

        _buttonList[m_identifier]->connect("pressed", func); // It's because of this func parameter I get the error,

        _gui.add(_buttonList[m_identifier]);

}

 

Which TGUi doesn't want me to since it gives me this error :

Error   C2893   Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'   
 

What am I doing wrong? :/

(I think this should be enough code to reproduce the error)

Pages: [1] 2
anything