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

Pages: [1]
1
General discussions / [CPP Source] - Load Assets using PhysicsFS
« on: July 22, 2011, 01:06:35 pm »
Yeah, got some right noobish mistakes there huh? lol.


 Lesson to be learnt.. Don't put fingers to keyboard before first cup of morning coffee has taken effect.

2
General discussions / [CPP Source] - Load Assets using PhysicsFS
« on: July 21, 2011, 08:00:46 am »
As stated on the first post, It's just a quick dirty method lol.. I haven't delved that deep in the documentation of SFML as of yet to provide the most efficient way of doing it.

 But thanks for the link, I'll have a dig about and see about updating the method thoroughly when I have the time available :)

3
SFML projects / Open Spriter
« on: July 17, 2011, 06:40:04 pm »
This looks great, and definitely a useful little tool for those who will be using animated sprites.

 A few little queries;

 Will the OSF file format be processor architecture friendly? I.e. Will a file generated on a 32bit machine work on a 64bit machine?

 Can the programmer specify an animation range using it's name, or a short name defined within the GUI?

4
General discussions / [CPP Source] - Load Assets using PhysicsFS
« on: July 17, 2011, 06:26:13 pm »
Hey folks,

    I have spent a few hours knocking up a quick method for loading assets (images, fonts, etc.) using the PhysicsFS library.

 Feel free to rip it apart as much as you like, though please take a moment just to let me know what it's being used in as well as any changes that have been made to make it more efficient.

 Thanks :)


 Mikey


PLEASE NOTE: This is to be used in conjunction with the PhysFS library, and all initialisation, adding of paths etc. has to be done using the standard PhysFS methods.

PhysFSLoader.hpp
Code: [Select]

// ----------------------------------------------------------------------------------------------------
// Title: SFML PhysFS Asset Loader
// Description: Load Assets (Images, Fonts, etc.) using the PhysFS library.
// Revision: 1 (17 July 2011)
// Author(s): Michael R. King (mrking2910@gmail.com)
// Dependencies: SFML (http://www.sfml-dev.org/) (Designed for version 2.0)
// PhysFS (http://icculus.org/physfs/) (Designed for version 2.0.2)
// Notes: Will only load the assets.
// ----------------------------------------------------------------------------------------------------

// - Include Protection -
#ifndef _H_SFML_PHYSFS_LOADER_
#define _H_SFML_PHYSFS_LOADER_

// - Include SFML -
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

// - Include PhysFS -
#include <physfs.h>

// - Include in SFML Namespace -
namespace sf
{
// - Error Codes -
enum PFSL_Error
{
PFSL_Error_None,
PFSL_Error_PhysFSNotReady,
PFSL_Error_InvalidFileHandle,
PFSL_Error_FileNotFound,
PFSL_Error_LoadFailed,
PFSL_Error_FileTooBig,
PFLS_Error_NotEnoughRead
};

// - Loader Class Declaration -
class PhysFSLoader
{
protected:
PFSL_Error m_lastError;
PHYSFS_sint64 m_maxFileSize;
char* m_fileBuffer;
PHYSFS_sint64 m_fileSize;

protected:
bool doLoad(sf::String Filename);

public:
PFSL_Error GetLastError();
void SetMaxFileSize(PHYSFS_sint64 Size);
bool Load(sf::Font* Object, sf::String Filename);
bool Load(sf::Image* Object, sf::String Filename);
bool Load(sf::SoundBuffer* Object, sf::String Filename);

public:
PhysFSLoader();
~PhysFSLoader();
};

}

#endif //_H_SFML_PHYSFS_LOADER_


PhysFSLoader.cpp
Code: [Select]

#include <PhysFSLoader.hpp>

namespace sf
{
// - Shared loading routine -
bool PhysFSLoader::doLoad(sf::String Filename)
{
// - Check if PhysFS is initialised -
if(PHYSFS_isInit() == 0)
{
m_lastError = PFSL_Error_PhysFSNotReady;
return false;
}

// - Check if file exists -
if(! PHYSFS_exists(Filename.ToAnsiString().c_str()))
{
m_lastError = PFSL_Error_FileNotFound;
return false;
}

// - Attempt to open file -
PHYSFS_file* fileObj = PHYSFS_openRead(Filename.ToAnsiString().c_str());
if(fileObj == NULL)
{
m_lastError = PFSL_Error_InvalidFileHandle;
return false;
}

// - Check file size -
PHYSFS_sint64 fSize = PHYSFS_fileLength(fileObj);
if(fSize > m_maxFileSize)
{
m_lastError = PFSL_Error_FileTooBig;
return false;
}

// - Read data -
m_fileBuffer = new char [fSize];
PHYSFS_sint64 totalRead = PHYSFS_read(fileObj, m_fileBuffer, 1, fSize);
if(totalRead != fSize)
{
m_lastError = PFLS_Error_NotEnoughRead;
delete m_fileBuffer;
m_fileBuffer = NULL;
return false;
}
return true;
}

// - Return Last Error -
PFSL_Error PhysFSLoader::GetLastError()
{
return m_lastError;
}

// - Set Filesize Limit -
void PhysFSLoader::SetMaxFileSize(PHYSFS_sint64 Size)
{
m_maxFileSize = Size;
}

// - Load Font -
bool PhysFSLoader::Load(sf::Font* Object, sf::String Filename)
{
m_lastError = PFSL_Error_None;
if(doLoad(Filename))
{
if(Object->LoadFromMemory(m_fileBuffer, m_fileSize))
{
delete m_fileBuffer;
m_fileBuffer = NULL;
return true;
}
delete m_fileBuffer;
m_fileBuffer = NULL;
m_lastError = PFSL_Error_LoadFailed;
}
return false;
}

// - Load Image -
bool PhysFSLoader::Load(sf::Image* Object, sf::String Filename)
{
m_lastError = PFSL_Error_None;
if(doLoad(Filename))
{
if(Object->LoadFromMemory(m_fileBuffer, m_fileSize))
{
delete m_fileBuffer;
m_fileBuffer = NULL;
return true;
}
delete m_fileBuffer;
m_fileBuffer = NULL;
m_lastError = PFSL_Error_LoadFailed;
}
return false;
}

// - Load Sound Buffer -
bool PhysFSLoader::Load(sf::SoundBuffer* Object, sf::String Filename)
{
m_lastError = PFSL_Error_None;
if(doLoad(Filename))
{
if(Object->LoadFromMemory(m_fileBuffer, m_fileSize))
{
delete m_fileBuffer;
m_fileBuffer = NULL;
return true;
}
delete m_fileBuffer;
m_fileBuffer = NULL;
m_lastError = PFSL_Error_LoadFailed;
}
return false;
}

// - Constructor -
PhysFSLoader::PhysFSLoader()
{
m_fileBuffer = NULL;
m_lastError = PFSL_Error_None;
m_maxFileSize = 4194304; // 4 MB Limit
}

// - Deconstructor -
PhysFSLoader::~PhysFSLoader()
{
if(m_fileBuffer)
{
delete m_fileBuffer;
m_fileBuffer = NULL;
}
}
}


Usage
Code: [Select]

#include <physfs.h>
#include <physFSLoader.hpp>

#include <SFML\Graphics.hpp>

void main()
{
PHYSFS_init(NULL);

PHYSFS_addToSearchPath("test.zip", 1);

sf::PhysFSLoader Loader;

sf::Image MyImage;

Loader.Load(&MyImage, "test.jpg");
}

5
General / how to Program object oriented???!!!
« on: January 13, 2011, 03:15:16 pm »
So used to working with libraries, SDK's, API's etc that demand manual memory management, that it's just second nature now lol...

Will have to revise the KISS philosophy some time soon.

6
General / how to Program object oriented???!!!
« on: January 13, 2011, 02:34:42 pm »
Just a quick and dirty method to providing the quick and easy way to creating the objects.

Just assumed it was the answer grando was looking for.



Never Mind Eh

7
General / [Quick Solution] Using CodeLite to develop SFML Projects.
« on: November 15, 2010, 02:10:27 pm »
Hey All,

 When cross-platform development comes into mind, the best way to write software is to use a cross-platform IDE with a cross-platform compiler.

 In this case, I choose to use CodeLite, with the MinGW compiler.

 CodeLite is a very nifty little IDE, with a surplus of features, and can easily be extended either by writing plugins, or modifying the source code for personal use.


In order to quickly get a solution to using CodeLite, I used Code::Blocks to compile the SFML libraries using MinGW, and then included the compiled libraries into a CodeLite workspace.

Add the include files, the libraries into the CodeLite workspace settings, and you're good to go.

Both IDE's compile in MinGW and as such the SFML compiled libraries (static in my case) are compatible with both.



 Hope this Helps!

8
General / how to Program object oriented???!!!
« on: November 15, 2010, 02:05:40 pm »
Quick Tutorial

Code: [Select]

sf::Image* pImage = new sf::Image();
sf::Sprite* pSprite = new sf::Sprite();

pImage->LoadFromFile("MyImage.png");

pSprite->SetImage( (*pImage) ); // - Remember to include Pointer in brackets, prefixed with an asterix.

pMyRenderWindow->Draw( (*pSprite) );


The easy way to object-orientate SFML.

(Hope this helps!)

9
General / [Error] SFML2 CMake-Generated Files for VS2010 (Static)
« on: November 09, 2010, 12:33:11 am »
Brill.

10
General / [Error] SFML2 CMake-Generated Files for VS2010 (Static)
« on: November 07, 2010, 04:57:13 pm »
Hello Folks,

 Encountered a bit of a problem when generating Visual Studio 2010 Project Files using CMake (2.8.2) for the SFML2 pre-release.

 CMake Configuration Used

 BUILD_DOC: No
 BUILD_EXAMPLES: Yes
 BUILD_SHARED_LIBS: No
 CMAKE_BUILD_TYPE: Release


 Now all works fine using CMake, but when loading the generated solution into Visual Studio 2010 (Professional) it refuses to load the newly generated project files for the "sfml_xxx" projects.

 The following is the output from Visual Studio;

 
Quote

D:\Development_Kits\C++\sfml2\src\SFML\Audio\sfml-audio.vcxproj : error  : Unable to read the project file "sfml-audio.vcxproj".
D:\Development_Kits\C++\sfml2\src\SFML\Audio\sfml-audio.vcxproj(98,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 98, position 29.

D:\Development_Kits\C++\sfml2\src\SFML\Graphics\sfml-graphics.vcxproj : error  : Unable to read the project file "sfml-graphics.vcxproj".
D:\Development_Kits\C++\sfml2\src\SFML\Graphics\sfml-graphics.vcxproj(98,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 98, position 29.

D:\Development_Kits\C++\sfml2\src\SFML\Network\sfml-network.vcxproj : error  : Unable to read the project file "sfml-network.vcxproj".
D:\Development_Kits\C++\sfml2\src\SFML\Network\sfml-network.vcxproj(98,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 98, position 29.

D:\Development_Kits\C++\sfml2\src\SFML\Window\sfml-window.vcxproj : error  : Unable to read the project file "sfml-window.vcxproj".
D:\Development_Kits\C++\sfml2\src\SFML\Window\sfml-window.vcxproj(98,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 98, position 29.



 In the project files themselves, the lines indicated above are;

 
Quote


sfml-audio.vcxproj: Line 98

<AdditionalOptions> "&quot";"D:/Development_Kits/C++/sfml2/extlibs/libs-msvc/OpenAL32.lib&quot";"" "&quot";"D:/Development_Kits/C++/sfml2/extlibs/libs-msvc/sndfile.lib&quot";"" %(AdditionalOptions)</AdditionalOptions>

sfml-graphics.vcxproj: Line 98

<AdditionalOptions> "&quot";"D:/Development_Kits/C++/sfml2/extlibs/libs-msvc/freetype.lib&quot";"" "&quot";"D:/Development_Kits/C++/sfml2/extlibs/libs-msvc/glew.lib&quot";"" "&quot";"D:/Development_Kits/C++/sfml2/extlibs/libs-msvc/jpeg.lib&quot";"" %(AdditionalOptions)</AdditionalOptions>

sfml-network.vcxproj: Line 98

<AdditionalOptions> "&quot";"ws2_32.lib&quot";"" %(AdditionalOptions)</AdditionalOptions>

sfml-window.vcxproj: Line 98

 <AdditionalOptions> "&quot";"opengl32.lib&quot";"" "&quot";"winmm.lib&quot";"" "&quot";"gdi32.lib&quot";"" %(AdditionalOptions)</AdditionalOptions>




 
Please note: the invalid entries occur on more than just line 98 in each project file.




Solution

Remove the "&quot" entries, and format the lines as follows;

Quote
<AdditionalOptions>opengl32.lib;winmm.lib;gdi32.lib;%(AdditionalOptions)</AdditionalOptions>



Hope this can help someone.

Pages: [1]