SIrrlichtCreationParameters and IrrXML problem

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Bodzio
Posts: 15
Joined: Mon Nov 10, 2008 8:53 am

SIrrlichtCreationParameters and IrrXML problem

Post by Bodzio »

hello, i want to implement XML config reader to my game by irrXML

I'm using IrrXML example and this SIrrlichtCreationParameters code:

Code: Select all

 param.DriverType = video::EDT_OPENGL; // Testing OPENGL driver
    param.WindowSize = core::dimension2d<s32>(CGame::WindowSizeHeight,CGame::WindowSizeHeight);
    param.Bits = CGame::Bits;
    param.Fullscreen = CGame::FullScreen;
    param.Stencilbuffer = CGame::StencilBuffer;
    param.Vsync = CGame::VSync;
    param.AntiAlias = CGame::AntiAlias;
,std::string declarations

Code: Select all

    std::string FullScreen;
    std::string StencilBuffer;
    std::string VSync;
    std::string AntiAlias;
    std::string WindowSizeWidth;
    std::string WindowSizeHeight;
    std::string Bits;
and GetXMLData code

Code: Select all

void CGame::GetXMLData()
{
    while(xml && xml->read())
    {

                if (!strcmp("windowsizewidth", xml->getNodeName()))
                    CGame::WindowSizeWidth = xml->getAttributeValueAsFloat("value");

                if (!strcmp("windowsizeheight", xml->getNodeName()))
                        CGame::WindowSizeHeight = xml->getAttributeValue("value");

                if (!strcmp("bits", xml->getNodeName()))
                        CGame::Bits = xml->getAttributeValue("value");

                if (!strcmp("fullscreen", xml->getNodeName()))
                        CGame::FullScreen = xml->getAttributeValue("on");

                if (!strcmp("stencilbuffer", xml->getNodeName()))
                        CGame::StencilBuffer = xml->getAttributeValue("on");

                if (!strcmp("vsync", xml->getNodeName()))
                        CGame::VSync = xml->getAttributeValue("on");

                if (!strcmp("antialias", xml->getNodeName()))
                        CGame::AntiAlias = xml->getAttributeValue("on");

    }
}
And i have this compile errors :evil:

Code: Select all

D:\SteelHearts\src\CGame.cpp:26: error: no matching function for call to `irr::core::dimension2d<irr::s32>::dimension2d(std::string&, std::string&)'
../../include/Irrlicht/dimension2d.h:18: note: candidates are: irr::core::dimension2d<irr::s32>::dimension2d(const irr::core::dimension2d<irr::s32>&)
../../include/Irrlicht/dimension2d.h:24: note:                 irr::core::dimension2d<T>::dimension2d(const T&, const T&) [with T = irr::s32]
../../include/Irrlicht/dimension2d.h:21: note:                 irr::core::dimension2d<T>::dimension2d() [with T = irr::s32]
D:\SteelHearts\src\CGame.cpp:27: error: cannot convert `std::string' to `irr::u8' in assignment
D:\SteelHearts\src\CGame.cpp:28: error: cannot convert `std::string' to `bool' in assignment
D:\SteelHearts\src\CGame.cpp:29: error: cannot convert `std::string' to `bool' in assignment
D:\SteelHearts\src\CGame.cpp:30: error: cannot convert `std::string' to `bool' in assignment
D:\SteelHearts\src\CGame.cpp:31: error: cannot convert `std::string' to `bool' in assignment
TNX FOR HELP , BODZIO

=== MinGW Code::Blocks and Irrlicht 1.5
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Re: SIrrlichtCreationParameters and IrrXML problem

Post by vitek »

The type of SIrrlichtCreationParams::Bits is u8, and the type of CGame::Bits is std::string. There is no provided function that converts a std::string to a u8, so it fails to compile. Just like the following code would...

Code: Select all

#include <string> // for std::string

int main ()
{
  const std::string str ("17");
  const unsigned char dat = str; // can't assign from string

  return 0;
}
There are additional methods in the xml reader that allow you to get values as different types. I suggest you change your CGame implementation to store a SIrrlichtCreationParameters instance (instead of all of those strings), and then you use the previoulsy mentioned methods to read values of the correct type from the xml.

Travis
Bodzio
Posts: 15
Joined: Mon Nov 10, 2008 8:53 am

Post by Bodzio »

I decided to use the config concept from Opensource Irrlicht game "Arena of Honor" (the code was very Advanced) when i running my app the console write to me :
[...]
Switch to fullscreen: The graphics mode is not supported
[...]

Can someone check my code

CGame.cpp

Code: Select all

#include "CGame.h"
#include "CConfig.h"

#ifdef __cplusplus
extern "C" {
#endif

#if (SYSTEM == 3)
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main()
#endif
{
    bool fullscreen = false;

	CGame game(fullscreen);
//	CConfig config;
	game.Run();
   // config.LoadConfig();
	return 0;
}
#ifdef __cplusplus
}
#endif


CGame::CGame(bool fullscreen)
{
    device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(VideoMode.Width, VideoMode.Height),VideoDepth, EnableFullscreen, true, false);

    driver = device->getVideoDriver();
    smgr = device->getSceneManager();

    device->setWindowCaption(L"Test");
}

CGame::~CGame()
{
    device->drop();
}

void CGame::Run()
{
	while(device->run() && driver)
	{
		driver->beginScene(true, true, video::SColor(0,200,200,200));
			smgr->drawAll();
		driver->endScene();
	}
}

void CGame::LoadConfig()
{
    io::IXMLReader* xml;
    io::IFileSystem* filesystem;
		xml = filesystem->createXMLReader("Data/config.xml");
	while(xml && xml->read())
    {
        switch(xml->getNodeType())
        {
	        case io::EXN_ELEMENT:
	        {
                if (core::stringw("video") == xml->getNodeName())
				{
					swscanf(xml->getAttributeValue(L"mode"), L"%dx%d", &VideoMode.Width, &VideoMode.Height);
					swscanf(xml->getAttributeValue(L"depth"), L"%d", &VideoDepth);
					if ( core::stringw("on") == xml->getAttributeValue(L"fullscreen"))
						EnableFullscreen = true;
					else
						EnableFullscreen = false;
				}


				}
				            break;
				            }
			}
			if (xml)
            xml->drop(); // don't forget to delete the xml reader

        }


CGame.h

Code: Select all

//Irrlicht headers
#include <irrlicht.h>
//Irrlicht namespaces
using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace std;

class CGame
{
public:
    CGame(bool fullscreen);
    ~CGame();

/*	core::dimension2d<s32> ScreenResolution;
    u32 CurrentResolution; // index of the array
    u32 CurrentDepth;*/



    void LoadConfig();
	bool EnableFullscreen ;
	core::dimension2d<s32> VideoMode;
	s32 VideoDepth;
	int VideoDriver ;


    void Run();

private:
    IrrlichtDevice* device;
    IVideoDriver*   driver;
    ISceneManager*  smgr;
    IrrXMLReader*   xml;
};

Config:

Code: Select all

<?xml version="1.0" ?> 
<config>
	<video  mode="800x600" depth="32" fullscreen="off" /> 
</config>
Post Reply