Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Game Development by Example - 4th SFML book  (Read 183108 times)

0 Members and 2 Guests are viewing this topic.

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re : SFML Game Development by Example - 4th SFML book
« Reply #120 on: August 01, 2016, 11:57:14 pm »
EDIT: Looks like I missed some includes, no more error for the SharedContext. But now I have another bunch of errors  8) I will try to correct them first before posting them

Hello  :)

I have an issue in Chapter 7 regarding the header of the class "Map".

When I try to build the code, there is an error here:

struct TileInfo {
    /// C-tor & D-tor ///
    TileInfo(SharedContext* context, const std::string &texture = "", TileId id = 0)

[...]Map.hpp|17|error: expected ')' before '*' token|

So it seems there is a problem with the "SharedContext *" parameter. The SharedContext header should be good:

class Map;
struct SharedContext
{
    SharedContext():
    mWindow(nullptr)
    , mEventManager(nullptr)
    , mTextureManager(nullptr)
    , mEntityManager(nullptr)
    , mGameMap(nullptr)
    {}

    Window          *mWindow;
    EventManager    *mEventManager;
    TextureManager  *mTextureManager;
    EntityManager   *mEntityManager;
    Map             *mGameMap;
};
 

I read somewhere in previous answers that
SharedContext *
member in StateManager.hpp should be
SharedContext
but it doesn't seem to resolve the problem  :(
« Last Edit: August 02, 2016, 12:15:28 am by Nayk0_x »

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #121 on: August 02, 2016, 01:28:30 am »
I was just about to reply to you about including the shared context header. Please make sure you consult the code files that came with the book. You will find complete source code there, with all of the necessary includes in place.

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re : SFML Game Development by Example - 4th SFML book
« Reply #122 on: August 02, 2016, 02:44:24 am »
Quote
I was just about to reply to you about including the shared context header. Please make sure you consult the code files that came with the book. You will find complete source code there, with all of the necessary includes in place.

Yes, I'm going through your code line by line at the moment and found some answers to my problem.

There is however one last error that I didn't manage to resolve:
[...]\Character.cpp|7|undefined reference to `EntityManager::getContext()'|

and the code snippet:
Character::Character(EntityManager *entityMgr)
: EntityBase(entityMgr)
, mSpriteSheet(mEntityManager->getContext()->mTextureManager)

I probably missed something in your code (I should be sleeping but this error bugs me so hard !)

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #123 on: August 02, 2016, 03:50:45 am »
In EntityManager.h, SharedContext is forward-declared:
struct SharedContext;
This means it has to be included in the EntityManager.cpp file:
#include "SharedContext.h"
Also, make sure Character.cpp includes EntityManager.h:
#include "EntityManager.h"

In case you don't have the GetContext() method defined for the EntityManager class, here's what you need to add:
Header:
class EntityManager{
public:
        ...
        SharedContext* GetContext();
private:
        ...
        SharedContext* m_context;
};
Implementation:
SharedContext* EntityManager::GetContext(){ return m_context; }

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re : SFML Game Development by Example - 4th SFML book
« Reply #124 on: August 02, 2016, 11:23:19 am »
EDIT: I didn't link to libshlwapi.a correclty, now it works  :)
Thank you, I didn't implement the getContext() method, no more errors about that.

There is now a problem with the method
PathRemoveFileSpec(path);
from
#include <Shlwapi.h>

Utilities.hpp|22|undefined reference to `_imp__PathRemoveFileSpecA@4'|

I assumed it's a linker error and tried to add the
Shlwapi.dll
in the bin folder but with no success (I'm using CodeBlocks, if that matters)
« Last Edit: August 02, 2016, 01:21:20 pm by Nayk0_x »

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re : SFML Game Development by Example - 4th SFML book
« Reply #125 on: August 02, 2016, 02:10:34 pm »
Hello again,

It seems like
strcat_s(path, "\\")
can't be used in CodeBlocks (or am I wrong ?)
It's supposed to be a Visual C++ or Visual Studio function, is there an alternative ? Like using std::string
instead of a char* ?

The code:

#pragma once
#define RUNNING_WINDOWS
#include <iostream>
#include <cstring>
#include <algorithm>

namespace Utils
{
    #ifdef RUNNING_WINDOWS
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <Shlwapi.h>
    inline std::string getWorkingDirectory()
    {
        HMODULE hModule = GetModuleHandle(nullptr);
        if(hModule)
        {
            char path[256];
            GetModuleFileName(hModule, path, sizeof(path));
            PathRemoveFileSpecA(path);
            strcat_s(path, "\\");
            return std::string(path);
        }
        return "";
    }

and the error:

Utilities.hpp|21|error: 'strcat_s' was not declared in this scope|

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #126 on: August 02, 2016, 05:22:57 pm »
Try using std::strcat instead of strcat_s. When doing so, make sure that <cstring> is included as well.

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #127 on: August 02, 2016, 11:12:03 pm »
I already tried that and it failed to load any files (so no more build errors but it just crash when trying to load the files).
I tried to build and run your code and same thing, crashed when trying to load any files.
I even tried to change the location of the media and config files with no success.

The old loading method (without using methods from Utilities.h) works well but I don't want to use that since it's not optimized.

The worst thing is that I'm pretty sure the solution is so obvious that I can't see it  ;D

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #128 on: August 03, 2016, 12:10:38 am »
In that case, just get rid of strcat_s completely and return like this:
inline std::string GetWorkingDirectory() {
        HMODULE hModule = GetModuleHandle(nullptr);
        if (!hModule) { return ""; }
        char path[256];
        GetModuleFileName(hModule,path,sizeof(path));
        PathRemoveFileSpec(path);
        return std::string(path) + "\\";
}

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #129 on: August 03, 2016, 01:21:09 am »
It still crashes after it tried to load keys.cfg, textures.cfg and EnemyList.list.

Something has to be wrong about how I named some of my paths or the location (I placed them just like you did, in a "Resources" folder).

I also have a LOT of warning messages but it's mostly "X will be initialized after", I don't know if it can be the root of my problem.

Thank you for your patience tho, I feel like a total noob with these loading problems  :P

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #130 on: August 03, 2016, 04:03:39 am »
Without really having access to your code, I can't really say what might be wrong with it at this point. If you could archive all of your code, as well as the Resources folder, and send it to me in a PM, that would be great. I'll take a look at it and get back to you as soon as I can. :)

Nayk0_x

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #131 on: August 03, 2016, 04:20:17 pm »
OK thank you ! I will send it to you in 2 days (not at home for now)

stenol

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #132 on: August 10, 2016, 02:12:11 pm »
Since 2 weeks, I'm reading your book and I really love it. I'm now in the middle of chapter 7.I have some little projects in mind for when I will finish your book. I will probably use the framework that we build in the book to make my own little engine while making my own little game. Can I use it to do this ? Do I have some licence restriction ? Grats again for your book :)

OrderNexus

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #133 on: August 10, 2016, 09:59:05 pm »
Thank you! I'm glad you're enjoying the book so far. :) Yes, you are free to use the code as you please. I'd appreciate if you gave credit, but you are by no means obligated to do so. That's just for the code though. Make sure you check the licenses of whatever resources you're going to use from the book. If you use the same graphics, and/or music/sounds, I can't guarantee that the original copyright holders won't mind. All of the resources used in the book have been linked to, however, so you can easily find them and make sure.

stenol

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML Game Development by Example - 4th SFML book
« Reply #134 on: August 11, 2016, 01:37:25 pm »
Tank you for your answer. I will certainly give you credit. :)

 

anything