Overloaded function calling overloaded function

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Overloaded function calling overloaded function

Post by Endar »

Okay, quickly, here's the function prototypes for the addTerrainSceneNode function and another one designed to use a 2d array instead of a heightmap.

Code: Select all

// Original
ITerrainSceneNode* CSceneManager::addTerrainSceneNode(
	ISceneNode* parent, s32 id,	video::IImage* texture,
	video::IImage* heightmap, video::ITexture* detailmap, 
	const core::dimension2d<f32>& stretchSize, f32 maxHeight, 
	const core::dimension2d<s32>& defaultVertexBlockSize);

// New
ITerrainSceneNode* CSceneManager::addTerrainSceneNode(
	ISceneNode* parent, s32 id,	video::IImage* texture,
	f32* heightmap[], video::ITexture* detailmap, 
	const core::dimension2d<f32>& stretchSize, f32 maxHeight, 
	const core::dimension2d<s32>& defaultVertexBlockSize);
Now the actual code for each function is the exact same code as the original function.
So, each of these functions call a 'load' function in class CTerrainSceneNode. There is one load function that is the original and then an overloaded function which takes the array of floats.

The error I'm getting is 'cannot convert float* [] to Image* etc, etc'

So, it looked to me like it was trying to call the original function instead of the overloaded one. I'm confused, shouldn't it find the right one automatically?
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Did you also declare this as virtual function in ISceneManager.h?
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Oh heck!! But would that matter? Because I'm trying to recompile the dll, not keep them in seperate files.
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

@jox: I just declared the changed function in ISceneManager.h and it the error still comes up.
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Endar wrote:Because I'm trying to recompile the dll
That's what I thougth. The thing is: your app that's using the dll is refering the I*.h classes, not the C*.h ones. So your function needs to be declared there. (Your SceneManager instance is "ISceneManager*" and not "CSceneManager*".)

Are you sure your app is looking in the correct include-dir? Or better: you sure it's finding the correct (modified) ISceneManager.h?
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Okay, I'm a little confused (you threw me because you said "your app that's using the dll" - sounded like you thought I was trying to program something with the engine instead of re-compiling it). I'm going to try again and try to answer your questions, so, jox, please don't get offended if I don't understand exactly what you mean.

Okay, I am trying to re-compile the dll using the VC++ project file distributed with the engine source.

I have referenced the new 'addTerrainSceneNode' function right under the original one in both the CSceneManager and ISceneManager header files, and the code is in the CSceneManager source file.

And my compiler include folder is "irrlicht engine\include" whereas the source is in "irrlicht engine\source".

Did I answer your questions?
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Did you copy the changed file from your source dir to the include dir?
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

@Endar: Yes, that answerd my questions. :)

I think the problem is that you have one include dir in "irrlicht engine/" and one in "irrlicht engine/source".

So copy it over like bal proposed. Or what I would prefer is configure "irrlicht engine/source/include" instead of "irrlicht engine\include" as include folder in your project setup (so further changes will be recognized without copying files each time.)
Felipe
Posts: 25
Joined: Thu Jun 10, 2004 9:13 pm
Location: Rio de Janeiro

Post by Felipe »

Hey, Endar, if you're using the function I sent you, take a closer look and you'll see they're not exactly the same. The original uses RGB values, when the new one expects values between 0 and 1 (though, other values would work). Don't forguet to message me if you get to compile it. ;)
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Okay, lets rewind for just a second. <deep breath>

Okay, to create an overloaded function, is all I have to do is write a function with the exact same name and diff parameters? Because that's essentially what has been done.
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Actually, here are the protoypes for the addTerrainSceneNode functions:

Code: Select all

// Original
virtual ITerrainSceneNode* addTerrainSceneNode(
     ISceneNode* parent, s32 id,
     video::IImage* texture,
     video::IImage* heightmap, video::ITexture* detailmap,
     const core::dimension2d<f32>& stretchSize = core::dimension2d<f32>(10.0f,10.0f),
     f32 maxHeight=200.0f,
     const core::dimension2d<s32>& defaultVertexBlockSize = core::dimension2d<s32>(64,64)) = 0;

// Filipe's
virtual ITerrainSceneNode* addTerrainSceneNode(
     ISceneNode* parent, s32 id,
     video::IImage* texture,
     f32* heightmap[], video::ITexture* detailmap,
     const core::dimension2d<f32>& stretchSize = core::dimension2d<f32>(10.0f,10.0f),
     f32 maxHeight=200.0f,
     const core::dimension2d<s32>& defaultVertexBlockSize = core::dimension2d<s32>(64,64));
Sorry for the large amount of code!! And here are the prototypes for the load functions:

Code: Select all

//! loads the terrain
bool load(video::IImage* texture, video::IImage* heightmap,
     video::ITexture* detailmap, 
     const core::dimension2d<f32>& stretchSize,
     const core::dimension2d<s32>& defaultVertexBlockSize,
     f32 maxHeight);

// Filipe's
bool load(video::IImage* texture, f32 *heightmap[],
     core::dimension2d<s32> &hMapSize, video::ITexture* detailmap,
     const core::dimension2d<f32>& stretchSize,
     const core::dimension2d<s32>& vtxBlockSize,
     f32 maxHeight);
And last, and possibly least, the way the 'load' function is called inside the 'addTerrainSceneNode' functions. (is exactly the same for both, ie. kept the original code)

Code: Select all

node->load(texture, heightmap, detailmap, stretchSize, defaultVertexBlockSize, maxHeight);
If anyone sees something and thinks that I should beat myself over the head with a hardcopy of this code, let me know. :?

EDIT:: @Felipe: Sorry I spelt your name wrong. :D
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

What's the matter now? Do you still have the 'cannot convert float* [] to Image* etc, etc' error? Or did the include folder thing fix it?

One thing I see in the Original vs. Felipe's addTerrainSceneNode() prototype is that the Original is pure virtual and Felipe's not (the "= 0" is missing). In ISceneManager.h it should be pure virtual and in CSceneManger.h (regular) virtual.
Felipe
Posts: 25
Joined: Thu Jun 10, 2004 9:13 pm
Location: Rio de Janeiro

Post by Felipe »

well, you could try simply changing the name and not overloading. I wouldn't mind using loadMatrix instead. :?
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Felipe!!!! You fooled me!!!!! Okay, now everyone line up in a row to beat me over the head!! :D

I think I've found the problem.

Felipe commented out the declaration of 'hMapSize' and added it as a function parameter.

Now we come to the problem: I didn't actually notice, so it turns out that the compiler thought I was trying to call the load() function with 6 parameters instead of the function with 7. :D
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Okay, I did that and fixed my next small problem which was, in the header files, i didn't have '= 0' at the end of the prototype. Anyone care to explain what exactly that does and why it's necessary?

And that brings me to my last problem. I'm trying to test it, which means reading in a bunch of floats from a file.

So, could anyone tell me why I'm having such a problem with this segment of code?

Code: Select all

	while( fscanf(file, "%d %d %f\n", x, y, z) == 3){
		heightmap[x][y] = z;
	}
Basically a problem with the fscanf function call.

Whenever it tries as is, it comes up with a seg fault saying it can't write to memory 0x0000000etc... , but when I replace the vars with strings and read directly into a string (for use with atoi, etc) it has no problem whatsoever.

Not a big thing if no one knows, cause I'll just use strings, but any ideas?
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Post Reply