Page 1 of 2

MSVCR90.dll isn't found {was:[Solved] C++ File Inclusion :(}

Posted: Tue Jul 24, 2012 6:56 pm
by RandomDever
Here's my dilemma.

I have an engine class which stores all me requisite variables( video, input etc. )
but all the classes contained in the engine must include the engine in order to know what the engine is
int order to do things like debugging( which is handle by a debug class in engine ). Mainly just debugging. Because right now I use an extern statement to always have access to the engine object which is declared in main.cpp. I'm wondering if there's some way to easily fix this or
if I'm going to have to figure out... *gulp* the 'singleton technique'?

Re: C++ File Inclusion :(

Posted: Tue Jul 24, 2012 7:17 pm
by Nokurn
Don't use a singleton. If your subsystems need a way to access the engine, give them a pointer or a reference. Better yet, isolate what parts of the engine they need access to (other subsystems, etc) and only give them pointers/references to those. Something like this would work:

Engine.hpp:

Code: Select all

#pragma once

#include "AudioSystem.hpp"
#include "InputSystem.hpp"
#include "VideoSystem.hpp"

class Engine {
    VideoSystem* _video;
    AudioSystem* _audio;
    InputSystem* _input;

public:
    Engine();
    ~Engine();

    VideoSystem* getVideo() { return _video; }
    AudioSystem* getAudio() { return _audio; }
    InputSystem* getInput() { return _input; }
};
Engine.cpp:

Code: Select all

#include "Engine.hpp"

Engine::Engine()
{
    _video = new VideoSystem(this);
    _audio = new AudioSystem(this);
    _input = new InputSystem(this);
}

Engine::~Engine()
{
    delete _input;
    delete _audio;
    delete _input;
}
VideoSystem.hpp:

Code: Select all

#pragma once

class Engine;

class VideoSystem {
    Engine* _engine;

public:
    VideoSystem(Engine* engine);

    Engine* getEngine() { return _engine; }
};
VideoSystem.cpp:

Code: Select all

#include "VideoSystem.hpp"
#include "Engine.hpp"

VideoSystem::VideoSystem(Engine* engine) : _engine(engine)
{
    // Initialize video system...
}
AudioSystem.hpp:

Code: Select all

#pragma once

class Engine;

class AudioSystem {
    Engine* _engine;

public:
    AudioSystem(Engine* engine);

    Engine* getEngine() { return _engine; }
};
AudioSystem.cpp:

Code: Select all

#include "AudioSystem.hpp"
#include "Engine.hpp"

AudioSystem::AudioSystem(Engine* engine) : _engine(engine)
{
    // Initialize audio system...
}
InputSystem.hpp:

Code: Select all

#pragma once

class Engine;

class InputSystem {
    Engine* _engine;

public:
    VideoSystem(Engine* engine);

    Engine* getEngine() { return _engine; }
};
InputSystem.cpp:

Code: Select all

#include "InputSystem.hpp"
#include "Engine.hpp"

InputSystem::InputSystem(Engine* engine) : _engine(engine)
{
    // Initialize input system...
    // Maybe you'd use _engine->getVideo() to get an input source from the window
}
I would recommend using references instead of pointers. Pointers should only really be used when null is a possibility. You will always have an Engine in your subsystems, so you could use a reference instead. There are a few other things about this code that I wouldn't advise you follow exactly, but this is just an example to give you an idea.

My main recommendation is to pass around specific members of the Engine class whenever possible, rather than the entire thing. If a class only needs access to your texture manager, you should only give it a reference to the texture manager, not the entire engine that happens to contain a texture manager. It's a bit more work, but your code will be better for it.

Edit: I forgot to mention why this code works. It uses forward declarations to avoid a circular header dependency. If a class's declaration only contains a reference or a pointer to another class, you only need to state that the type is a class for the code to compile. You will need to include the header in which the reference/pointer's class is declared in any source files that actually use it.

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 6:32 am
by RandomDever

Code: Select all

struct Time
{
	unsigned short int year;
	std::string month, dayOfWeek;
	unsigned short int day, hour, minute, second, millisecond;
};

Code: Select all

'struct' type redefinition
How is it possible to redefine a struct that doesn't even exist anywhere else?

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 6:46 am
by bbguimaraes
That's probably an include guard problem. It is being redefined because you include it in more than on file.

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 7:43 am
by RandomDever
Thank you bbguimaraes it was.
I mispelled utilities on the define. Well back to work. :mrgreen:

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 12:27 pm
by RandomDever
On a side note.
Does anyone know how to detect a window resize event for Microsoft Windows?

And handle them.

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 12:51 pm
by Nokurn
RandomDever wrote:On a side note.
Does anyone know how to detect a window resize event for Microsoft Windows?

And handle them.
WM_SIZE message:

Code: Select all

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg) {
    // ...
    case WM_SIZE: {
        // If you anticipate sizes of more than 65535, use GetClientRect instead
        int w = LOWORD(lParam);
        int h = HIWORD(lParam);

        // Handle the resize. Ex:
        //glViewport(0, 0, w, h);
        return 0;
    }
    // ...
    }
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
If you're using a library like SFML or SDL, you'll have to go through it instead.

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 1:51 pm
by Rebornxeno
I'm really confused.. I can't think of any reason a subsystem of your engine would need access to the engine for? Can you explain for me please?

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 1:56 pm
by RandomDever
I'm using SDL.
How do I make it so that it doesn't have black boxing when resizing?

Re: C++ File Inclusion :(

Posted: Wed Jul 25, 2012 2:27 pm
by Nokurn
RandomDever wrote:I'm using SDL.
How do I make it so that it doesn't have black boxing when resizing?
Wherever you're pumping SDL_Events:

Code: Select all

if (ev.type == SDL_VIDEORESIZE) {
    // ... use data in ev.resize ...
}
ev is an SDL_Event, ev.resize is an SDL_ResizeEvent.

I don't think there is a way to eliminate the black boxing while using SDL. It would require intercepting the WM_SIZING event and redrawing between mouse movements, which can slow things down.

Simple questions like this can be answered by using Google or RTFM. SDL 1.2 docs are at http://sdl.beuc.net/sdl.wiki/FrontPage, SDL 2.0 docs are at http://wiki.libsdl.org/moin.cgi/FrontPage.

Re: C++ File Inclusion :(

Posted: Thu Jul 26, 2012 9:21 am
by RandomDever
Does anyone know where SDL sets up the window ( in the code )?
If they use the windows API I may be able to modify SDL to do my bidding.

Re: C++ File Inclusion :(

Posted: Thu Jul 26, 2012 12:02 pm
by bbguimaraes
RandomDever wrote:Does anyone know where SDL sets up the window ( in the code )?
If they use the windows API I may be able to modify SDL to do my bidding.
In my experience, if you ask that question, you are not on the level to do it (no offense). Otherwise, grep is your friend.

But keep in mind you're going to loose much of the portability (if not all) that you gain by using SDL.

Re: C++ File Inclusion :(

Posted: Thu Jul 26, 2012 4:37 pm
by RandomDever
I have an application called PRGrep and I searched for various things within SDLs code that would be required for setting up a window.
No results.
I see SetVideoMode declared but not defined.
How exactly is that possible?
Is it in the DLLs?
In that case how am I supposed to edit it?
LATER: OK so I figured out I had to download the SDL source and dig through it to find the WndProc definition.
It's on Line 251 in SDL_sysevents.c.
So I've modified it to do my bidding *evil laugh* and rebuilt SDL.dll.
It works the way I intended except for one thing.
The window is updating slowly so if I call glClear it will clear the screen after a second but it is not perfectly filling the window (still minor black boxing).
I checked and minecraft has the same type of problem when resizing.
Does anyone know a way to fix this?

Re: C++ File Inclusion :(

Posted: Fri Jul 27, 2012 3:03 pm
by RandomDever
Well it's okay I'll blank the screen on resize.
Marking as solved.

Re: [Solved] C++ File Inclusion :(

Posted: Sat Jul 28, 2012 5:32 pm
by RandomDever
Just curious if there are still people monitoring this forum.
What is a good FPS for rendering 2500 textures to the screen?