From 32071d9053f01e20bbfa118324dcff81d9238af4 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 30 Jun 2013 03:42:32 +0200 Subject: [PATCH] Added skeleton for CDynMaterial. This class will be the new material. --HG-- branch : gsoc2013-dfighter --- code/nel/include/nel/3d/dynamic_material.h | 66 +++++++++++++++ code/nel/src/3d/dynamic_material.cpp | 95 ++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 code/nel/include/nel/3d/dynamic_material.h create mode 100644 code/nel/src/3d/dynamic_material.cpp diff --git a/code/nel/include/nel/3d/dynamic_material.h b/code/nel/include/nel/3d/dynamic_material.h new file mode 100644 index 000000000..e4db258f1 --- /dev/null +++ b/code/nel/include/nel/3d/dynamic_material.h @@ -0,0 +1,66 @@ +// NeL - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef DYN_MATERIAL_H +#define DYN_MATERIAL_H + +#include "nel/misc/stream.h" +#include +#include + +namespace NL3D +{ + + struct CDynMaterialProp + { + enum EPropertyType + { + Color, + Vector4, + Float, + Double, + Int, + Uint, + Matrix4, + Texture + }; + + std::string prop; + std::string label; + uint8 type; + std::string value; + }; + + class CDynMaterial : public NLMISC::IStreamable + { + public: + CDynMaterial(); + ~CDynMaterial(); + void serial( NLMISC::IStream &f ); + + void addProperty( const CDynMaterialProp &prop ); + void removeProperty( const std::string &name ); + void changeProperty( const std::string &name, const CDynMaterialProp &prop ); + + private: + std::vector< CDynMaterialProp > properties; + }; +} + +#endif + + diff --git a/code/nel/src/3d/dynamic_material.cpp b/code/nel/src/3d/dynamic_material.cpp new file mode 100644 index 000000000..332a67841 --- /dev/null +++ b/code/nel/src/3d/dynamic_material.cpp @@ -0,0 +1,95 @@ +// NeL - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "nel/3d/dynamic_material.h" + +namespace NL3D +{ + CDynMaterial::CDynMaterial() + { + } + + CDynMaterial::~CDynMaterial() + { + } + + void CDynMaterial::serial( NLMISC::IStream &f ) + { + int version = f.serialVersion( 1 ); + + std::vector< CDynMaterialProp >::const_iterator itr = properties.begin(); + while( itr != properties.end() ) + { + f.serial( std::string( itr->prop ) ); + f.serial( std::string( itr->label ) ); + f.serial( uint8( itr->type ) ); + f.serial( std::string( itr->value ) ); + + ++itr; + } + } + + void CDynMaterial::addProperty( const CDynMaterialProp &prop ) + { + std::vector< CDynMaterialProp >::const_iterator itr = properties.begin(); + while( itr != properties.end() ) + { + if( itr->prop == prop.prop ) + break; + ++itr; + } + if( itr != properties.end() ) + return; + + properties.push_back( prop ); + } + + void CDynMaterial::removeProperty( const std::string &name ) + { + std::vector< CDynMaterialProp >::iterator itr = properties.begin(); + while( itr != properties.end() ) + { + if( itr->prop == name ) + break; + ++itr; + } + if( itr == properties.end() ) + return; + + properties.erase( itr ); + } + + void CDynMaterial::changeProperty( const std::string &name, const CDynMaterialProp &prop ) + { + std::vector< CDynMaterialProp >::iterator itr = properties.begin(); + while( itr != properties.end() ) + { + if( itr->prop == name ) + break; + ++itr; + } + if( itr == properties.end() ) + return; + + itr->prop = prop.prop; + itr->label = prop.label; + itr->type = prop.type; + itr->value = prop.value; + } + +} + +