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