diff --git a/include/ObjectRegistry.h b/include/ObjectRegistry.h index 96ad5e46b4c2b352099712f345dfafb89e51de68..0e7863d627fd095dac6089b971038e225c9ef0e5 100644 --- a/include/ObjectRegistry.h +++ b/include/ObjectRegistry.h @@ -1,6 +1,9 @@ /* Copyright (c) 2006, NIF File Format Library and Tools All rights reserved. Please see niflib.h for license. */ +#ifndef _OBJECT_REGISTRY_H_ +#define _OBJECT_REGISTRY_H_ + #include <map> #include <string> #include "obj/Niobject.h" @@ -29,7 +32,9 @@ public: NIFLIB_HIDDEN static NiObject * CreateObject( const string & type_name ); private: - static map<string, obj_factory_func> * object_map; + static map<string, obj_factory_func> object_map; }; -} //End namespace Niflib \ No newline at end of file +} //End namespace Niflib + +#endif diff --git a/include/obj/NiImage.h b/include/obj/NiImage.h index eeeb2971d9a462e105517ed9cbbf7854a3666f75..975f06444735ddb8b94a035ef54c275a7c245547 100644 --- a/include/obj/NiImage.h +++ b/include/obj/NiImage.h @@ -60,17 +60,38 @@ public: //--BEGIN MISC CUSTOM CODE--// /*! - * Sets a new external file texture. Removes any existing texture references. - * \param[in] file_name The file name of the new external texture. Often needs to follow game guidlines to be found. + * Used to check whether the texture referenced by this object is an external file. + * \return True if the texture is stored in an external file, false if it is stored within this NIF file. */ - NIFLIB_API void SetTextureFileName( string file_name ); + NIFLIB_API bool IsTextureExternal() const; /*! - * Returns the external texture file name. + * Sets a new external file texture. Removes any existing texture references, whether internal or external. + * \param[in] file_name The file name of the external texture. Often needs to follow game guidlines to be found. + */ + NIFLIB_API void SetExternalTexture( string file_name ); + + /*! + * Sets a new internal file texture. Removes any existing texture references, whether internal or external. + * \param[in] original_file_name The original file name of the texture. This may be optional. + * \param[in] raw_image_data The NiRawImageData object that contains the texture image data. + */ + NIFLIB_API void SetInternalTexture( NiRawImageData * raw_image_data ); + + + /*! + * Returns either the file name of the external texture, or the original file name of the internal one. * \return The name of the texture file. */ NIFLIB_API string GetTextureFileName() const; + /*! + * Returns a reference to the texture image data object used by this texture, if any. + * \return The iamge data object referenced by this texture, or NULL if one is not being used. + */ + NIFLIB_API Ref<NiRawImageData> GetRawImageData() const; + + //--END CUSTOM CODE--// protected: /*! 0 if the texture is internal to the NIF file. */ diff --git a/niflib.vcproj b/niflib.vcproj index 1c26b5ae2c6cc1b094ec3964ae91b6c5ae35b39d..ab6bc6a2e9e97cc79be5a76db20f9854395999f6 100644 --- a/niflib.vcproj +++ b/niflib.vcproj @@ -313,6 +313,10 @@ RelativePath=".\src\kfm.cpp" > </File> + <File + RelativePath=".\src\MaterialCollection.cpp" + > + </File> <File RelativePath=".\src\NIF_IO.cpp" > @@ -1551,6 +1555,10 @@ RelativePath=".\include\kfm.h" > </File> + <File + RelativePath=".\include\MaterialCollection.h" + > + </File> <File RelativePath=".\include\nif_basic_types.h" > diff --git a/src/ObjectRegistry.cpp b/src/ObjectRegistry.cpp index b2d8c7a292141be29c24b43cee5215b45bf4c315..c7bbf46b63a64b922d7accca571502098e96953c 100644 --- a/src/ObjectRegistry.cpp +++ b/src/ObjectRegistry.cpp @@ -5,29 +5,19 @@ All rights reserved. Please see niflib.h for license. */ namespace Niflib { -map<string, obj_factory_func> * ObjectRegistry::object_map = NULL; +map<string, obj_factory_func> ObjectRegistry::object_map; void ObjectRegistry::RegisterObject( const string & type_name, obj_factory_func create_func ) { - if (object_map == NULL) { - cout << "Initializing object map" << endl; - object_map = new map<string, obj_factory_func>; - } - - (*object_map)[type_name] = create_func; + object_map[type_name] = create_func; } NiObject * ObjectRegistry::CreateObject( const string & type_name ) { - if (object_map == NULL) { - throw runtime_error("Object Map was never initialized"); - //object_map = new map<string, obj_factory_func>; - } - NiObject * object = NULL; map<string, obj_factory_func>::iterator it; - it = (*object_map).find(type_name); + it = object_map.find(type_name); - if ( it != (*object_map).end() ) { + if ( it != object_map.end() ) { //Requested type has been registered return it->second(); } else { diff --git a/src/obj/NiImage.cpp b/src/obj/NiImage.cpp index 5b8ffbbdd2e16110e4208329dae7870bada42686..ccd41fab942912393ae8416067f23a7c7e59d411 100644 --- a/src/obj/NiImage.cpp +++ b/src/obj/NiImage.cpp @@ -130,12 +130,28 @@ std::list<NiObjectRef> NiImage::GetRefs() const { //--BEGIN MISC CUSTOM CODE--// -void NiImage::SetTextureFileName( string file_name ) { +bool NiImage::IsTextureExternal() const { + return (external != 0); +} + +void NiImage::SetExternalTexture( string file_name ) { + imageData = NULL; + external = 1; fileName = file_name; } +void NiImage::SetInternalTexture( NiRawImageData * raw_image_data ) { + external = 0; + fileName.clear(); + imageData = raw_image_data; +} + string NiImage::GetTextureFileName() const { return fileName; } +Ref<NiRawImageData> NiImage::GetRawImageData() const { + return imageData; +} + //--END CUSTOM CODE--//