Merged revisions 3729-3829 from 1.7 branch. Fixed serialization of camera nodes, fix array::erase, fix mem leaks in example 22, fix interpolation in SColorf, fix crash in collada loader.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3830 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
hybrid 2011-06-09 06:45:29 +00:00
parent 24e069488e
commit 7b5fa07671
10 changed files with 159 additions and 37 deletions

View File

@ -266,6 +266,15 @@ The following names can be queried for the given types:
-----------------------------
Changes in 1.7.3 (??.??.2011)
- Fix crash in collada (.dae) loading
- Fix memory-leaks in example 22 MaterialViewer
- Fix array::erase which did destroy objects more than once when used with a range (thx @ RedDragCZ for reporting + testcase).
- Copy now all membervariables for CCameraSceneNode when cloning.
- ICameraSceneNode::IsOrthogonal is correctly serialized and cloned now.
- CGUIScrollBar passes unused mousemove-events now to parent element. Fixes focus-bug in ComboBox reported by REDDemon here: http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=43474&highlight=

View File

@ -75,18 +75,11 @@ int main()
smgr->setAmbientLight(video::SColor(0,60,60,60));
/*
The next is just some standard stuff: Add a user controlled camera to
the scene, disable mouse cursor, and add a test cube and let it rotate
to make the scene more interesting.
The next is just some standard stuff: Add a test cube and let it rotate
to make the scene more interesting. The user defined camera and cursor
setup is made later on, right before the render loop.
*/
// add fps camera
scene::ICameraSceneNode* fpsCamera = smgr->addCameraSceneNodeFPS();
fpsCamera->setPosition(core::vector3df(-50,50,-150));
// disable mouse cursor
device->getCursorControl()->setVisible(false);
// create test cube
scene::ISceneNode* test = smgr->addCubeSceneNode(60);
@ -145,6 +138,13 @@ int main()
text->setOverrideColor(video::SColor(100,255,255,255));
}
// add fps camera
scene::ICameraSceneNode* fpsCamera = smgr->addCameraSceneNodeFPS();
fpsCamera->setPosition(core::vector3df(-50,50,-150));
// disable mouse cursor
device->getCursorControl()->setVisible(false);
/*
Nearly finished. Now we need to draw everything. Every frame, we draw
the scene twice. Once from the fixed camera into the render target

View File

@ -311,7 +311,8 @@ public:
{
ControlAmbientColor->drop();
ControlDiffuseColor->drop();
ControlEmissiveColor->drop();
if ( ControlEmissiveColor )
ControlEmissiveColor->drop();
ControlSpecularColor->drop();
}
@ -346,7 +347,7 @@ public:
}
// Update all changed colors in the light data
void updateMaterialColors(video::SLight & lightData)
void updateLightColors(video::SLight & lightData)
{
if ( ControlAmbientColor->isDirty() )
lightData.AmbientColor = video::SColorf( ControlAmbientColor->getColor() );
@ -362,7 +363,8 @@ public:
ControlAmbientColor->resetDirty();
ControlDiffuseColor->resetDirty();
ControlSpecularColor->resetDirty();
ControlEmissiveColor->resetDirty();
if ( ControlEmissiveColor )
ControlEmissiveColor->resetDirty();
}
protected:
@ -500,6 +502,8 @@ struct SMeshNodeControl
TextureControl2->drop();
if ( ControlVertexColors )
ControlVertexColors->drop();
if ( AllColorsControl )
AllColorsControl->drop();
}
void init(scene::IMeshSceneNode* node, IrrlichtDevice * device, const core::position2d<s32> & pos, const wchar_t * description)
@ -666,6 +670,12 @@ struct SLightNodeControl
{
}
virtual ~SLightNodeControl()
{
if ( AllColorsControl )
AllColorsControl->drop();
}
void init(scene::ILightSceneNode* node, gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t * description)
{
if ( Initialized || !node || !guiEnv) // initializing twice or with invalid data not allowed
@ -683,7 +693,7 @@ struct SLightNodeControl
return;
video::SLight & lightData = SceneNode->getLightData();
AllColorsControl->updateMaterialColors(lightData);
AllColorsControl->updateLightColors(lightData);
}
protected:
@ -797,7 +807,7 @@ protected:
return false;
Device->setWindowCaption( DriverTypeNames[Config.DriverType] );
Device->setEventReceiver(this);
scene::ISceneManager* smgr = Device->getSceneManager();
video::IVideoDriver * driver = Device->getVideoDriver ();
gui::IGUIEnvironment* guiEnv = Device->getGUIEnvironment();
@ -807,7 +817,7 @@ protected:
gui::IGUIFont* font = guiEnv->getFont("../../media/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
// remove some alpha value because it makes those menus harder to read otherwise
video::SColor col3dHighLight( skin->getColor(gui::EGDC_APP_WORKSPACE) );
col3dHighLight.setAlpha(255);
@ -818,7 +828,7 @@ protected:
// Add some textures which are useful to test material settings
createDefaultTextures(driver);
// create a menu
// create a menu
gui::IGUIContextMenu * menuBar = guiEnv->addMenu();
menuBar->addItem(L"File", -1, true, true);
@ -850,7 +860,7 @@ protected:
video::SColorf(1.0f, 1.0f, 1.0f),
100.0f);
LightControl.init(nodeLight, guiEnv, core::position2d<s32>(270,20), L"light" );
// one large cube around everything. That's mainly to make the light more obvious.
scene::IMeshSceneNode* backgroundCube = smgr->addCubeSceneNode (200.0f, 0, -1, core::vector3df(0, 0, 0),
core::vector3df(45, 0, 0),
@ -1001,6 +1011,8 @@ protected:
}
}
driver->addTexture (io::path("GRAYSCALE_A8R8G8B8"), imageA8R8G8B8);
imageA8R8G8B8->drop();
}
// Load a texture and make sure nodes know it when more textures are available.

View File

@ -166,8 +166,34 @@ namespace scene
/** @see bindTargetAndRotation() */
virtual bool getTargetAndRotationBinding(void) const =0;
//! Writes attributes of the camera node
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
{
ISceneNode::serializeAttributes(out, options);
if (!out)
return;
out->addBool ("IsOrthogonal", IsOrthogonal );
}
//! Reads attributes of the camera node
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
{
ISceneNode::deserializeAttributes(in, options);
if (!in)
return;
if ( in->findAttribute("IsOrthogonal") )
IsOrthogonal = in->getAttributeAsBool("IsOrthogonal");
}
protected:
void cloneMembers(ICameraSceneNode* toCopyFrom)
{
IsOrthogonal = toCopyFrom->IsOrthogonal;
}
bool IsOrthogonal;
};

View File

@ -722,19 +722,23 @@ namespace scene
//! Adds a billboard scene node to the scene graph.
/** A billboard is like a 3d sprite: A 2d element,
which always looks to the camera. It is usually used for things like explosions, fire,
lensflares and things like that.
\param parent: Parent scene node of the billboard. Can be null. If the parent moves,
the billboard will move too.
\param position: Position of the space relative to its parent
which always looks to the camera. It is usually used for things
like explosions, fire, lensflares and things like that.
\param parent Parent scene node of the billboard. Can be null.
If the parent moves, the billboard will move too.
\param size Size of the billboard. This size is 2 dimensional
because a billboard only has width and height.
\param position Position of the space relative to its parent
where the billboard will be placed.
\param size: Size of the billboard. This size is 2 dimensional because a billboard only has
width and height.
\param id: An id of the node. This id can be used to identify the node.
\param colorTop: The color of the vertices at the top of the billboard (default: white).
\param colorBottom: The color of the vertices at the bottom of the billboard (default: white).
\param id An id of the node. This id can be used to identify
the node.
\param colorTop The color of the vertices at the top of the
billboard (default: white).
\param colorBottom The color of the vertices at the bottom of
the billboard (default: white).
\return Pointer to the billboard if successful, otherwise NULL.
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
This pointer should not be dropped. See
IReferenceCounted::drop() for more information. */
virtual IBillboardSceneNode* addBillboardSceneNode(ISceneNode* parent = 0,
const core::dimension2d<f32>& size = core::dimension2d<f32>(10.0f, 10.0f),
const core::vector3df& position = core::vector3df(0,0,0), s32 id=-1,

View File

@ -540,7 +540,7 @@ namespace video
return SColorf (r * mul0 + c1.r * mul1 + c2.r * mul2,
g * mul0 + c1.g * mul1 + c2.g * mul2,
g * mul0 + c1.b * mul1 + c2.b * mul2,
b * mul0 + c1.b * mul1 + c2.b * mul2,
a * mul0 + c1.a * mul1 + c2.a * mul2);
}

View File

@ -558,12 +558,12 @@ public:
for (i=index+count; i<used; ++i)
{
if (i > index+count)
if (i-count >= index+count) // not already destructed before loop
allocator.destruct(&data[i-count]);
allocator.construct(&data[i-count], data[i]); // data[i-count] = data[i];
if (i >= used-count)
if (i >= used-count) // those which are not overwritten
allocator.destruct(&data[i]);
}

View File

@ -301,7 +301,7 @@ void CCameraSceneNode::recalculateViewArea()
//! Writes attributes of the scene node.
void CCameraSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
ISceneNode::serializeAttributes(out, options);
ICameraSceneNode::serializeAttributes(out, options);
out->addVector3d("Target", Target);
out->addVector3d("UpVector", UpVector);
@ -310,13 +310,13 @@ void CCameraSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeR
out->addFloat("ZNear", ZNear);
out->addFloat("ZFar", ZFar);
out->addBool("Binding", TargetAndRotationAreBound);
out->addBool("ReceiveInput", InputReceiverEnabled);
}
//! Reads attributes of the scene node.
void CCameraSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
ISceneNode::deserializeAttributes(in, options);
ICameraSceneNode::deserializeAttributes(in, options);
Target = in->getAttributeAsVector3d("Target");
UpVector = in->getAttributeAsVector3d("UpVector");
@ -325,6 +325,8 @@ void CCameraSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttribute
ZNear = in->getAttributeAsFloat("ZNear");
ZFar = in->getAttributeAsFloat("ZFar");
TargetAndRotationAreBound = in->getAttributeAsBool("Binding");
if ( in->findAttribute("ReceiveInput") )
InputReceiverEnabled = in->getAttributeAsBool("InputReceiverEnabled");
recalculateProjectionMatrix();
recalculateViewArea();
@ -348,6 +350,8 @@ bool CCameraSceneNode::getTargetAndRotationBinding(void) const
//! Creates a clone of this scene node and its children.
ISceneNode* CCameraSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
{
ICameraSceneNode::clone(newParent, newManager);
if (!newParent)
newParent = Parent;
if (!newManager)
@ -356,7 +360,19 @@ ISceneNode* CCameraSceneNode::clone(ISceneNode* newParent, ISceneManager* newMan
CCameraSceneNode* nb = new CCameraSceneNode(newParent,
newManager, ID, RelativeTranslation, Target);
nb->cloneMembers(this, newManager);
nb->ISceneNode::cloneMembers(this, newManager);
nb->ICameraSceneNode::cloneMembers(this);
nb->Target = Target;
nb->UpVector = UpVector;
nb->Fovy = Fovy;
nb->Aspect = Aspect;
nb->ZNear = ZNear;
nb->ZFar = ZFar;
nb->ViewArea = ViewArea;
nb->Affector = Affector;
nb->InputReceiverEnabled = InputReceiverEnabled;
nb->TargetAndRotationAreBound = TargetAndRotationAreBound;
if ( newParent )
nb->drop();

View File

@ -2191,7 +2191,7 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader,
}
else
{
for (u32 ind = 0; i+2 < indices.size(); ++ind)
for (u32 ind = 0; ind+2 < indices.size(); ++ind)
{
mbuffer->Indices.push_back(indices[0]);
mbuffer->Indices.push_back(indices[ind+1]);

View File

@ -8,6 +8,60 @@
using namespace irr;
using namespace core;
core::map<int, int> countReferences;
struct SDummy
{
SDummy(int a) : x(a)
{
countReferences.insert(x,1);
}
SDummy() : x(0)
{
countReferences.insert(x,1);
}
SDummy(const SDummy& other)
{
x = other.x;
countReferences[x] = countReferences[x] + 1;
}
~SDummy()
{
countReferences[x] = countReferences[x] - 1;
}
int x;
};
static bool testErase()
{
{
core::array<SDummy> aaa;
aaa.push_back(SDummy(0));
aaa.push_back(SDummy(1));
aaa.push_back(SDummy(2));
aaa.push_back(SDummy(3));
aaa.push_back(SDummy(4));
aaa.push_back(SDummy(5));
aaa.erase(0,2);
}
for ( core::map<int,int>::Iterator it = countReferences.getIterator(); !it.atEnd(); it++ )
{
if ( it->getValue() != 0 )
{
logTestString("testErase: wrong count for %d, it's: %d\n", it->getKey(), it->getValue());
return false;
}
}
return true;
}
struct VarArray
{
core::array < int, core::irrAllocatorFast<int> > MyArray;
@ -69,6 +123,7 @@ bool testIrrArray(void)
crashTestFastAlloc();
allExpected &= testSelfAssignment();
allExpected &= testSwap();
allExpected &= testErase();
if(allExpected)
logTestString("\nAll tests passed\n");