00001 // Filename: writableConfigurable.h 00002 // Created by: jason (19Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 // 00020 #ifndef WRITABLECONFIGURABLE_H 00021 #define WRITABLECONFIGURABLE_H 00022 // 00023 //////////////////////////////////////////////////////////////////// 00024 // Includes 00025 //////////////////////////////////////////////////////////////////// 00026 00027 #include <pandabase.h> 00028 00029 #include "typedWritable.h" 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Defines 00033 //////////////////////////////////////////////////////////////////// 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Class : WritableConfigurable 00037 // Description : Defined as a fix to allow creating Configurable and 00038 // Writable objects. Otherwise the compiler gets 00039 // confused since both TypedWritable and Configurable 00040 // inherit from TypedObject. 00041 // 00042 // An object that has data or parameters that are set 00043 // less frequently (at least occasionally) than every 00044 // frame. We can cache the configuration info by 00045 // by using the "dirty" flag. 00046 //////////////////////////////////////////////////////////////////// 00047 class EXPCL_PANDA WritableConfigurable : public TypedWritable { 00048 00049 public: 00050 WritableConfigurable( void ) { make_dirty(); } 00051 virtual void config( void ) { _dirty = false; } 00052 INLINE void check_config() const { 00053 if (_dirty) { 00054 // This is a sneaky trick to allow check_config() to be called 00055 // from a const member function. Even though we will be calling 00056 // config(), a non-const function that modifies the class 00057 // object, in some sense it's not really modifying the class 00058 // object--it's just updating a few internal settings for 00059 // consistency. 00060 ((WritableConfigurable *)this)->config(); 00061 } 00062 } 00063 00064 INLINE bool is_dirty(void) const { return _dirty; } 00065 INLINE void make_dirty(void) { _dirty = true; } 00066 00067 private: 00068 bool _dirty; 00069 00070 public: 00071 virtual void write_datagram(BamWriter*, Datagram&) = 0; 00072 00073 PUBLISHED: 00074 static TypeHandle get_class_type() { 00075 return _type_handle; 00076 } 00077 00078 public: 00079 static void init_type() { 00080 TypedWritable::init_type(); 00081 register_type(_type_handle, "WritableConfigurable", 00082 TypedWritable::get_class_type()); 00083 TypeRegistry::ptr()->record_alternate_name(_type_handle, 00084 "WriteableConfigurable"); 00085 } 00086 virtual TypeHandle get_type() const { 00087 return get_class_type(); 00088 } 00089 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00090 00091 00092 private: 00093 static TypeHandle _type_handle; 00094 }; 00095 00096 #endif