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

Pages: [1]
1
System / Re: Is sf::Clock accurate enough for fixed Time step game loops?
« on: February 10, 2013, 04:18:19 pm »
Thank you very much!

2
System / Is sf::Clock accurate enough for fixed Time step game loops?
« on: February 10, 2013, 04:00:13 pm »
While asking on gamedev about fixed time steps, I was told clocks should never be used as a game timer and to use QueryPerformanceCounter() instead.  That solution however is Windows specific and I read somewhere that on multicore systems it could return different times since each cpu may not be synced.  That being said, does sf::Clock use something like QueryPerformanceCounter or does it use something like std::Clock.  Sorry I haven't checked the source code, I'm at work and this has been bugging me.

3
General / Re: SFML 2.0 crash after main()
« on: January 31, 2013, 04:04:26 pm »
You were right, it wasn't SFML causing the problem.  The sample game engine I was using had a bug in it and the sample resource management I was using had the same type of bug -.-".

Basically they were trying to call a vector erase on nothing (in the game engine) and in the resource mangement, they were trying to call a map erase on nothing.  They never checked to see if the size was > 0 which was causing the program to flip out after main.  The destructor of the resource class was getting called after main.

Thanks exploiter :)

(p.s. the code wasn't really long, it just looked that way, most of the methods were empty lol  thank you though ;))

4
General / Re: SFML 2.0 crash after main()
« on: January 30, 2013, 07:59:28 pm »
Sure

linker:
Code: [Select]
sfml-system-d.lib
sfml-main-d.lib
sfml-graphics-d.lib
sfml-window-d.lib
sfgui-d.lib
glew32.lib

Source Files:

main.cpp
Code: [Select]
#include <SFML\System.hpp>
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>
#include <SFGUI\SFGUI.hpp>
#include "GameEngine.h"
#include "IntroState.h"

int main(int argc, char* argv[]) {
CGameEngine game;

// initialize the engine
game.Init( "Engine Test v1.0" );

// load the intro
game.ChangeState( CIntroState::Instance() );

// main loop
while ( game.Running() )
{
game.HandleEvents();
game.Update();
game.Draw();
}

// cleanup the engine
game.Cleanup();

return EXIT_SUCCESS;
}

gameengine.h
Code: [Select]
#pragma once

#include <SFML\Graphics.hpp>

#include <vector>
using namespace std;

class CGameState;

class CGameEngine
{
public:

//void Init(const char* title, int width=640, int height=480,
//       int bpp=0, bool fullscreen=false);
void Init(const char* title, int width=800, int height=600);
void Cleanup();

void ChangeState(CGameState* state);
void PushState(CGameState* state);
void PopState();

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

bool Running() { return m_running; }
void Quit() { m_running = false; }

sf::RenderWindow app_window;

private:
// the stack of states
vector<CGameState*> states;

bool m_running;
bool m_fullscreen;
};

gameengine.cpp
Code: [Select]
#include "GameEngine.h"
#include "GameState.h"

void CGameEngine::Init(const char* title, int width, int height)
{
app_window.create( sf::VideoMode( width, height ), title, sf::Style::Titlebar | sf::Style::Close );
printf("CGameInit\n");
}

void CGameEngine::Cleanup()
{
// cleanup the all states
while ( !states.empty() ) {
states.back()->Cleanup();
states.pop_back();
}

printf("CGameEngine Cleanup\n");
}

void CGameEngine::ChangeState(CGameState* state)
{
// cleanup the current state
if ( !states.empty() ) {
states.back()->Cleanup();
states.pop_back();
}

// store and init the new state
states.push_back(state);
states.back()->Init();
}

void CGameEngine::PushState(CGameState* state)
{
// pause current state
if ( !states.empty() ) {
states.back()->Pause();
}

// store and init the new state
states.push_back(state);
states.back()->Init();
}

void CGameEngine::PopState()
{
// cleanup the current state
if ( !states.empty() ) {
states.back()->Cleanup();
states.pop_back();
}

// resume previous state
if ( !states.empty() ) {
states.back()->Resume();
}
}

void CGameEngine::HandleEvents()
{
// let the state handle events
states.back()->HandleEvents(this);
}

void CGameEngine::Update()
{
// let the state update the game
states.back()->Update(this);
}

void CGameEngine::Draw()
{
// let the state draw the screen
states.back()->Draw(this);
}

gamestate.h
Code: [Select]
#pragma once

#include "GameEngine.h"

class CGameState
{
public:
virtual void Init() = 0;
virtual void Cleanup() = 0;

virtual void Pause() = 0;
virtual void Resume() = 0;

virtual void HandleEvents(CGameEngine* game) = 0;
virtual void Update(CGameEngine* game) = 0;
virtual void Draw(CGameEngine* game) = 0;

void ChangeState(CGameEngine* game, CGameState* state) {
game->ChangeState(state);
}

protected:
CGameState() { }
};

introstate.h
Code: [Select]
#pragma once

#include <SFML\Graphics.hpp>
#include "gamestate.h"

class CIntroState : public CGameState
{
public:
void Init();
void Cleanup();

void Pause();
void Resume();

void HandleEvents(CGameEngine* game);
void Update(CGameEngine* game);
void Draw(CGameEngine* game);

static CIntroState* Instance() {
return &m_IntroState;
}

protected:
CIntroState() { }

private:
static CIntroState m_IntroState;

sf::Sprite bg;
sf::Texture* bgTexture;
int alpha;
};

introstate.cpp
Code: [Select]
#include "IntroState.h"
#include "TextureManager.h"

CIntroState CIntroState::m_IntroState;

void CIntroState::Init()
{
bgTexture = gTextureManager.getResource("C:\\Users\\SonicD007\\Desktop\\DragonBall Zeta\\BMPs\\loginscreen.png");
if (bgTexture != NULL)
bg.setTexture(*bgTexture);
bg.setPosition(0,0);
}


void CIntroState::Cleanup()
{
//if (bgTexture != NULL)
//gTextureManager.releaseResource("C:\\Users\\SonicD007\\Desktop\\DragonBall Zeta\\BMPs\\loginscreen.png");
}

void CIntroState::Pause()
{

}

void CIntroState::Resume()
{

}

void CIntroState::HandleEvents(CGameEngine* game)
{
sf::Event event;
while (game->app_window.pollEvent(event) )
{
switch (event.type)
{
case sf::Event::Closed:
game->Quit();
break;
}
}

}

void CIntroState::Update(CGameEngine* game)
{

}

void CIntroState::Draw(CGameEngine* game)
{
game->app_window.clear();
game->app_window.draw(bg);
game->app_window.display();
}

resourcemanager.h
Code: [Select]
#pragma once

#include <string>
#include <map>

template< class T >
class ResourceManager {
public:
typedef std::pair< std::string, T* > Resource;
typedef std::map< std::string, T* > ResourceMap;

private:
ResourceMap m_resource;

T* find( const std::string& strId ) {
T* resource = NULL;
typename ResourceMap::iterator it = m_resource.find( strId );
if ( it != m_resource.end() ) {
resource = it->second;
}

return resource;
}

protected:
virtual T* load( const std::string& strId ) = 0;

public:
ResourceManager(){}

virtual ~ResourceManager() { releaseAllResources(); }

T* getResource( const std::string& strId) {
T* resource = find( strId );
if ( resource == NULL ) {
resource = load( strId);
// If the resource loaded successfully
if ( resource != NULL )
m_resource.insert( Resource( strId, resource ) );
}
return resource;
}

void releaseResource( const std::string& strId) {
T* resource = find( strId );
if ( resource != NULL ) {
delete resource;
m_resource.erase( m_resource.find( strId ) );
}
}

void releaseAllResources() {
while( m_resource.begin() != m_resource.end() )
delete m_resource.begin()->second;
m_resource.erase( m_resource.begin() );
}
};

texturemanager.h
Code: [Select]
#pragma once

#include <SFML\Graphics.hpp>
#include "ResourceManager.h"

class TextureManager : public ResourceManager< sf::Texture > {
private:
protected:
virtual sf::Texture* load( const std::string& strId );
public:
};

extern TextureManager gTextureManager;

texturemanager.cpp
Code: [Select]

#include <iostream>
#include "TextureManager.h"

using namespace std;

TextureManager gTextureManager;

sf::Texture* TextureManager::load( const std::string& strId ) {
sf::Texture* image = new sf::Texture();
if( !image->loadFromFile(strId) ) {
cout << "[WARN] ImageManager failed to load: " << strId << endl;
delete image;
image = NULL;
}

return image;
}

I noticed that when I uncomment the two lines in introstate.cpp cleanup(), that's when the error pops up.  With those lines in there, the program crashes after main but I don't get the opengl error outputted

5
General / SFML 2.0 crash after main()
« on: January 30, 2013, 07:32:04 pm »
Hey everyone,

I'm using SFML 2.0 and I've built it from source (Windows 7 Visual Studio 2010)

I get the following error after the program exits from main

Code: [Select]
An internal OpenGL call failed in Texture.cpp (95) : GL_INVALID_OPERATION, the s
pecified operation is not allowed in the current state

Any idea if this is a library error or is it something in my source code that could cause this?

Pages: [1]
anything