From d584d9454904666d8de69a99dd4fb29e5dbab433 Mon Sep 17 00:00:00 2001 From: spog Date: Sun, 26 Feb 2006 22:27:38 +0000 Subject: [PATCH] added string-pooling for shader variable names and entity keys git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@26 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- include/ientity.h | 2 ++ libs/container/hashfunc.h | 9 ++++++ libs/container/hashtable.h | 4 +-- libs/convert.h | 4 +-- libs/entitylib.h | 13 ++++++-- libs/fs_filesystem.h | 6 ++-- libs/generic/arrayrange.h | 26 ++++++++------- libs/generic/constant.h | 2 ++ libs/generic/static.h | 38 +++++++++++++--------- libs/gtkutil/dialog.cpp | 2 +- libs/libs.vcproj | 6 ++++ libs/stream/textstream.h | 4 +-- libs/string/string.h | 41 +++++++++++++---------- libs/uniquenames.h | 2 +- plugins/entity/entity.cpp | 5 +++ plugins/entity/modelskinkey.h | 2 +- plugins/mapq3/plugin.cpp | 4 +-- plugins/md3model/model.h | 2 +- plugins/shaders/shaders.cpp | 61 ++++++++++++++++++----------------- radiant/commands.cpp | 2 +- radiant/dialog.cpp | 8 ++--- radiant/eclass_def.cpp | 2 +- radiant/eclass_doom3.cpp | 2 +- radiant/main.cpp | 1 + radiant/map.cpp | 2 ++ radiant/texwindow.cpp | 18 +++++------ radiant/xywindow.cpp | 2 +- 27 files changed, 159 insertions(+), 111 deletions(-) diff --git a/include/ientity.h b/include/ientity.h index ac10c1a6..34a5638d 100644 --- a/include/ientity.h +++ b/include/ientity.h @@ -111,6 +111,8 @@ public: virtual bool getShowNames() = 0; virtual void setShowAngles(bool showAngles) = 0; virtual bool getShowAngles() = 0; + + virtual void printStatistics() const = 0; }; #include "modulesystem.h" diff --git a/libs/container/hashfunc.h b/libs/container/hashfunc.h index 03e5e26b..a4ec5fee 100644 --- a/libs/container/hashfunc.h +++ b/libs/container/hashfunc.h @@ -320,6 +320,15 @@ inline hash_t string_hash_nocase(const char* string, hash_t previous = 0) return hash_ub1_nocase(reinterpret_cast(string), string_length(string), previous); } +struct RawStringHash +{ + typedef hash_t hash_type; + hash_type operator()(const char* string) const + { + return string_hash(string); + } +}; + struct HashString { typedef hash_t hash_type; diff --git a/libs/container/hashtable.h b/libs/container/hashtable.h index c38739a8..c4b1aded 100644 --- a/libs/container/hashtable.h +++ b/libs/container/hashtable.h @@ -166,11 +166,11 @@ namespace HashTableDetail increment(); return tmp; } - value_type& operator*() + value_type& operator*() const { return m_node->m_value; } - value_type* operator->() + value_type* operator->() const { return &(operator*()); } diff --git a/libs/convert.h b/libs/convert.h index ea7a71f1..f7f4f992 100644 --- a/libs/convert.h +++ b/libs/convert.h @@ -248,7 +248,7 @@ inline TextOutputStreamType& ostream_write(TextOutputStreamType& ostream, const return ostream << convert.m_range; } - for(const char* p = convert.m_range.begin; p != convert.m_range.end;) + for(const char* p = convert.m_range.first; p != convert.m_range.last;) { if(!char_is_ascii(*p)) { @@ -286,7 +286,7 @@ inline TextOutputStreamType& ostream_write(TextOutputStreamType& ostream, const return ostream << convert.m_range; } - for(const char* p = convert.m_range.begin; p != convert.m_range.end; ++p) + for(const char* p = convert.m_range.first; p != convert.m_range.last; ++p) { if(!char_is_ascii(*p)) { diff --git a/libs/entitylib.h b/libs/entitylib.h index 5c477c66..b9e93002 100644 --- a/libs/entitylib.h +++ b/libs/entitylib.h @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "math/vector.h" #include "math/aabb.h" #include "undolib.h" -#include "string/string.h" +#include "string/pooledstring.h" #include "generic/referencecounted.h" #include "scenelib.h" #include "container/container.h" @@ -421,14 +421,21 @@ public: virtual void erase(const char* key, Value& value) = 0; }; + static StringPool& getPool() + { + return Static::instance(); + } private: static EntityCreator::KeyValueChangedFunc m_entityKeyValueChanged; static Counter* m_counter; EntityClass* m_eclass; + class KeyContext{}; + typedef Static KeyPool; + typedef PooledString Key; typedef SmartPointer KeyValuePtr; - typedef UnsortedMap KeyValues; + typedef UnsortedMap KeyValues; KeyValues m_keyValues; typedef UnsortedSet Observers; @@ -504,7 +511,7 @@ private: (*i).second->instanceDetach(m_undo.map()); } - CopiedString key((*i).first); + Key key((*i).first); KeyValuePtr value((*i).second); m_keyValues.erase(i); notifyErase(key.c_str(), *value); diff --git a/libs/fs_filesystem.h b/libs/fs_filesystem.h index 653d60dc..0c22a4b3 100644 --- a/libs/fs_filesystem.h +++ b/libs/fs_filesystem.h @@ -57,8 +57,8 @@ class GenericFileSystem : m_path(path), m_depth(path_get_depth(c_str())) { } - Path(const char* start, const char* finish) - : m_path(start, finish), m_depth(path_get_depth(c_str())) + Path(StringRange range) + : m_path(range), m_depth(path_get_depth(c_str())) { } bool operator<(const Path& other) const @@ -121,7 +121,7 @@ public: const char* end = path_remove_directory(path.c_str()); while(end[0] != '\0') { - Path dir(path.c_str(), end); + Path dir(StringRange(path.c_str(), end)); m_entries.insert(value_type(dir, Entry(0))); end = path_remove_directory(end); } diff --git a/libs/generic/arrayrange.h b/libs/generic/arrayrange.h index 7bb31888..a05489a1 100644 --- a/libs/generic/arrayrange.h +++ b/libs/generic/arrayrange.h @@ -29,36 +29,36 @@ template struct ArrayRange { typedef Element* Iterator; - ArrayRange(Iterator _begin, Iterator _end) - : begin(_begin), end(_end) + ArrayRange(Iterator first, Iterator last) + : first(first), last(last) { } - Iterator begin; - Iterator end; + Iterator first; + Iterator last; }; template -inline ArrayRange makeArrayRange(Element* begin, Element* end) +inline ArrayRange makeArrayRange(Element* first, Element* last) { - return ArrayRange(begin, end); + return ArrayRange(first, last); } template struct ArrayConstRange { typedef const Element* Iterator; - ArrayConstRange(Iterator _begin, Iterator _end) - : begin(_begin), end(_end) + ArrayConstRange(Iterator first, Iterator last) + : first(first), last(last) { } - Iterator begin; - Iterator end; + Iterator first; + Iterator last; }; template -inline ArrayConstRange makeArrayRange(const Element* begin, const Element* end) +inline ArrayConstRange makeArrayRange(const Element* first, const Element* last) { - return ArrayConstRange(begin, end); + return ArrayConstRange(first, last); } #define ARRAY_SIZE(array) (sizeof(array) / sizeof(*array)) @@ -69,4 +69,6 @@ inline ArrayConstRange makeArrayRange(const Element* begin, const Eleme typedef ArrayConstRange StringArrayRange; #define STRING_ARRAY_RANGE(array) (StringArrayRange(array, ARRAY_END(array))) +typedef ArrayRange StringRange; + #endif diff --git a/libs/generic/constant.h b/libs/generic/constant.h index 0c2f1b52..42b2fa5d 100644 --- a/libs/generic/constant.h +++ b/libs/generic/constant.h @@ -45,4 +45,6 @@ inline TextOutputStreamType& ostream_write(TextOutputStreamType& ostream, const #define STRING_CONSTANT(name, value) TYPE_CONSTANT(name, value, const char*) #define INTEGER_CONSTANT(name, value) TYPE_CONSTANT(name, value, int) +STRING_CONSTANT(EmptyString, ""); + #endif diff --git a/libs/generic/static.h b/libs/generic/static.h index 50fb3b71..81691827 100644 --- a/libs/generic/static.h +++ b/libs/generic/static.h @@ -27,14 +27,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include +class Null +{ +}; + /// \brief A singleton which is statically initialised. /// /// \param Type The singleton object type. +/// \param Type The type distinguishing this instance from others of the same type. /// /// \dontinclude generic/static.cpp /// \skipline Static example /// \until end example -template +template class Static { static Type m_instance; @@ -45,19 +50,20 @@ public: } }; -template -Type Static::m_instance; +template +Type Static::m_instance; /// \brief A singleton which is lazily initialised. /// The instance is constructed the first time it is referenced, and is never destroyed. /// /// \param Type The singleton object type. +/// \param Type The type distinguishing this instance from others of the same type. /// /// \dontinclude generic/static.cpp /// \skipline LazyStatic example /// \until end example -template +template class LazyStatic { static Type* m_instance; // this will be initialised to 0 by the CRT, according to the c++ standard @@ -72,8 +78,8 @@ public: } }; -template -Type* LazyStatic::m_instance; +template +Type* LazyStatic::m_instance; /// \brief A singleton which keeps a count of the number of times it is referenced. @@ -82,7 +88,8 @@ Type* LazyStatic::m_instance; /// Use with SmartStatic. /// /// \param Type The singleton object type. -template +/// \param Type The type distinguishing this instance from others of the same type. +template class CountedStatic { static std::size_t m_refcount; // this will be initialised to 0 by the CRT, according to the c++ standard @@ -108,34 +115,35 @@ public: } }; -template -std::size_t CountedStatic::m_refcount; // this will be initialised to 0 by the CRT, according to the c++ standard -template -Type* CountedStatic::m_instance; +template +std::size_t CountedStatic::m_refcount; // this will be initialised to 0 by the CRT, according to the c++ standard +template +Type* CountedStatic::m_instance; /// \brief A reference to a CountedStatic. /// Guarantees that CountedStatic will be constructed for the lifetime of this object. /// /// \param Type The type parameter of the CountedStatic to reference. +/// \param Type The type distinguishing this instance from others of the same type. /// /// \dontinclude generic/static.cpp /// \skipline SmartStatic example /// \until end example -template +template class SmartStatic { public: SmartStatic() { - CountedStatic::capture(); + CountedStatic::capture(); } ~SmartStatic() { - CountedStatic::release(); + CountedStatic::release(); } Type& instance() { - return CountedStatic::instance(); + return CountedStatic::instance(); } }; diff --git a/libs/gtkutil/dialog.cpp b/libs/gtkutil/dialog.cpp index 0529178a..0f95e9ae 100644 --- a/libs/gtkutil/dialog.cpp +++ b/libs/gtkutil/dialog.cpp @@ -209,7 +209,7 @@ RadioHBox RadioHBox_new(StringArrayRange names) GSList* group = 0; GtkRadioButton* radio = 0; - for(StringArrayRange::Iterator i = names.begin; i != names.end; ++i) + for(StringArrayRange::Iterator i = names.first; i != names.last; ++i) { radio = GTK_RADIO_BUTTON(gtk_radio_button_new_with_label(group, *i)); gtk_widget_show(GTK_WIDGET(radio)); diff --git a/libs/libs.vcproj b/libs/libs.vcproj index 56f067f8..c418b703 100644 --- a/libs/libs.vcproj +++ b/libs/libs.vcproj @@ -193,6 +193,12 @@ + + + + diff --git a/libs/stream/textstream.h b/libs/stream/textstream.h index 96fc7a6a..8e0c72c4 100644 --- a/libs/stream/textstream.h +++ b/libs/stream/textstream.h @@ -302,13 +302,11 @@ inline TextOutputStreamType& ostream_write(TextOutputStreamType& ostream, const } -typedef ArrayRange StringRange; - /// \brief Writes a \p range of characters to \p ostream. template inline TextOutputStreamType& ostream_write(TextOutputStreamType& ostream, const StringRange& range) { - ostream.write(range.begin, range.end - range.begin); + ostream.write(range.first, range.last - range.first); return ostream; } diff --git a/libs/string/string.h b/libs/string/string.h index cf6c064d..9e0bcb03 100644 --- a/libs/string/string.h +++ b/libs/string/string.h @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "memory/allocator.h" +#include "generic/arrayrange.h" /// \brief Returns true if \p string length is zero. /// O(1) @@ -191,10 +192,10 @@ inline char* string_clone(const char* other, Allocator& allocator) /// \brief Returns a newly-allocated string which is a clone of [\p first, \p last), using \p allocator. /// The returned buffer must be released with \c string_release using a matching \p allocator. template -inline char* string_clone_range(const char* first, const char* last, Allocator& allocator) +inline char* string_clone_range(StringRange range, Allocator& allocator) { - std::size_t length = last - first; - char* copied = strncpy(string_new(length, allocator), first, length); + std::size_t length = range.last - range.first; + char* copied = strncpy(string_new(length, allocator), range.first, length); copied[length] = '\0'; return copied; } @@ -224,10 +225,10 @@ inline char* string_clone(const char* other) /// \brief Returns a newly-allocated string which is a clone of [\p first, \p last). /// The returned buffer must be released with \c string_release. -inline char* string_clone_range(const char* first, const char* last) +inline char* string_clone_range(StringRange range) { DefaultAllocator allocator; - return string_clone_range(first, last, allocator); + return string_clone_range(range, allocator); } typedef char* char_pointer; @@ -343,8 +344,8 @@ public: : Buffer(string) { } - String(const char* first, const char* last) - : Buffer(first, last) + String(StringRange range) + : Buffer(range) { } @@ -360,6 +361,12 @@ public: temp.swap(*this); return *this; } + String& operator=(StringRange range) + { + String temp(range); + temp.swap(*this); + return *this; + } void swap(String& other) { @@ -426,9 +433,9 @@ class CopiedBuffer : private Allocator { char* m_string; - char* copy_range(const char* first, const char* last) + char* copy_range(StringRange range) { - return string_clone_range(first, last, static_cast(*this)); + return string_clone_range(range, static_cast(*this)); } char* copy(const char* other) { @@ -461,8 +468,8 @@ public: : Allocator(allocator), m_string(copy(string)) { } - CopiedBuffer(const char* first, const char* last, const Allocator& allocator = Allocator()) - : Allocator(allocator), m_string(copy_range(first, last)) + CopiedBuffer(StringRange range, const Allocator& allocator = Allocator()) + : Allocator(allocator), m_string(copy_range(range)) { } const char* c_str() const @@ -485,11 +492,11 @@ class SmartBuffer : private Allocator { char* m_buffer; - char* copy_range(const char* first, const char* last) + char* copy_range(StringRange range) { - char* buffer = Allocator::allocate(sizeof(std::size_t) + (last - first) + 1); - strncpy(buffer + sizeof(std::size_t), first, last - first); - buffer[sizeof(std::size_t) + (last - first)] = '\0'; + char* buffer = Allocator::allocate(sizeof(std::size_t) + (range.last - range.first) + 1); + strncpy(buffer + sizeof(std::size_t), range.first, range.last - range.first); + buffer[sizeof(std::size_t) + (range.last - range.first)] = '\0'; *reinterpret_cast(buffer) = 0; return buffer; } @@ -541,8 +548,8 @@ public: { incref(m_buffer); } - SmartBuffer(const char* first, const char* last, const Allocator& allocator = Allocator()) - : Allocator(allocator), m_buffer(copy_range(first, last)) + SmartBuffer(StringRange range, const Allocator& allocator = Allocator()) + : Allocator(allocator), m_buffer(copy_range(range)) { incref(m_buffer); } diff --git a/libs/uniquenames.h b/libs/uniquenames.h index 4c4a531f..868336d3 100644 --- a/libs/uniquenames.h +++ b/libs/uniquenames.h @@ -130,7 +130,7 @@ inline name_t name_read(const char* name) end = p; } - return name_t(CopiedString(name, end), Postfix(end)); + return name_t(CopiedString(StringRange(name, end)), Postfix(end)); } diff --git a/plugins/entity/entity.cpp b/plugins/entity/entity.cpp index 06f91737..58669348 100644 --- a/plugins/entity/entity.cpp +++ b/plugins/entity/entity.cpp @@ -258,6 +258,11 @@ public: { return g_showAngles; } + + void printStatistics() const + { + StringPool_analyse(EntityKeyValues::getPool()); + } }; Quake3EntityCreator g_Quake3EntityCreator; diff --git a/plugins/entity/modelskinkey.h b/plugins/entity/modelskinkey.h index 6c02a8ef..58c7da24 100644 --- a/plugins/entity/modelskinkey.h +++ b/plugins/entity/modelskinkey.h @@ -34,7 +34,7 @@ inline void parseTextureName(CopiedString& name, const char* token) { StringOutputStream cleaned(256); cleaned << PathCleaned(token); - name = CopiedString(cleaned.c_str(), path_get_filename_base_end(cleaned.c_str())); // remove extension + name = StringRange(cleaned.c_str(), path_get_filename_base_end(cleaned.c_str())); // remove extension } class ModelSkinKey : public ModuleObserver diff --git a/plugins/mapq3/plugin.cpp b/plugins/mapq3/plugin.cpp index 8fa75327..8e031edb 100644 --- a/plugins/mapq3/plugin.cpp +++ b/plugins/mapq3/plugin.cpp @@ -500,11 +500,11 @@ public: typedef Value* const_iterator; const_iterator begin() const { - return m_children.begin; + return m_children.first; } const_iterator end() const { - return m_children.end; + return m_children.last; } }; diff --git a/plugins/md3model/model.h b/plugins/md3model/model.h index 0aca555c..1b41e161 100644 --- a/plugins/md3model/model.h +++ b/plugins/md3model/model.h @@ -75,7 +75,7 @@ inline void parseTextureName(CopiedString& name, const char* token) { StringOutputStream cleaned(256); cleaned << PathCleaned(token); - name = CopiedString(cleaned.c_str(), path_get_filename_base_end(cleaned.c_str())); // remove extension + name = StringRange(cleaned.c_str(), path_get_filename_base_end(cleaned.c_str())); // remove extension } // generic renderable triangle surface diff --git a/plugins/shaders/shaders.cpp b/plugins/shaders/shaders.cpp index 77326810..3a7fae2d 100644 --- a/plugins/shaders/shaders.cpp +++ b/plugins/shaders/shaders.cpp @@ -51,7 +51,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "debugging/debugging.h" -#include "string/string.h" +#include "string/pooledstring.h" #include "math/vector.h" #include "generic/callback.h" #include "generic/referencecounted.h" @@ -225,21 +225,29 @@ Image* loadSpecial(void* environment, const char* name) return GlobalTexturesCache().loadImage(name); } - +class ShaderPoolContext +{ +}; +typedef Static ShaderPool; +typedef PooledString ShaderString; +typedef ShaderString ShaderVariable; +typedef ShaderString ShaderValue; +typedef CopiedString TextureExpression; // clean a texture name to the qtexture_t name format we use internally // NOTE: case sensitivity: the engine is case sensitive. we store the shader name with case information and save with case // information as well. but we assume there won't be any case conflict and so when doing lookups based on shader name, // we compare as case insensitive. That is Radiant is case insensitive, but knows that the engine is case sensitive. //++timo FIXME: we need to put code somewhere to detect when two shaders that are case insensitive equal are present -void parseTextureName(CopiedString& name, const char* token) +template +void parseTextureName(StringType& name, const char* token) { StringOutputStream cleaned(256); cleaned << PathCleaned(token); - name = CopiedString(cleaned.c_str(), path_get_filename_base_end(cleaned.c_str())); // remove extension + name = CopiedString(StringRange(cleaned.c_str(), path_get_filename_base_end(cleaned.c_str()))).c_str(); // remove extension } -bool Tokeniser_parseTextureName(Tokeniser& tokeniser, CopiedString& name) +bool Tokeniser_parseTextureName(Tokeniser& tokeniser, TextureExpression& name) { const char* token = tokeniser.getToken(); if(token == 0) @@ -251,13 +259,6 @@ bool Tokeniser_parseTextureName(Tokeniser& tokeniser, CopiedString& name) return true; } -void parseShaderName(CopiedString& name, const char* token) -{ - StringOutputStream cleaned(256); - cleaned << PathCleaned(token); - name = cleaned.c_str(); -} - bool Tokeniser_parseShaderName(Tokeniser& tokeniser, CopiedString& name) { const char* token = tokeniser.getToken(); @@ -266,11 +267,11 @@ bool Tokeniser_parseShaderName(Tokeniser& tokeniser, CopiedString& name) Tokeniser_unexpectedError(tokeniser, token, "#shader-name"); return false; } - parseShaderName(name, token); + parseTextureName(name, token); return true; } -bool Tokeniser_parseString(Tokeniser& tokeniser, CopiedString& string) +bool Tokeniser_parseString(Tokeniser& tokeniser, ShaderString& string) { const char* token = tokeniser.getToken(); if(token == 0) @@ -284,12 +285,10 @@ bool Tokeniser_parseString(Tokeniser& tokeniser, CopiedString& string) -typedef std::list ShaderParameters; -typedef std::list ShaderArguments; +typedef std::list ShaderParameters; +typedef std::list ShaderArguments; -typedef CopiedString TextureExpression; -typedef CopiedString ShaderValue; -typedef std::pair BlendFuncExpression; +typedef std::pair BlendFuncExpression; class ShaderTemplate { @@ -406,7 +405,7 @@ public: }; -bool Doom3Shader_parseHeightmap(Tokeniser& tokeniser, CopiedString& bump, CopiedString& heightmapScale) +bool Doom3Shader_parseHeightmap(Tokeniser& tokeniser, TextureExpression& bump, ShaderValue& heightmapScale) { RETURN_FALSE_IF_FAIL(Tokeniser_parseToken(tokeniser, "(")); RETURN_FALSE_IF_FAIL(Tokeniser_parseTextureName(tokeniser, bump)); @@ -416,20 +415,20 @@ bool Doom3Shader_parseHeightmap(Tokeniser& tokeniser, CopiedString& bump, Copied return true; } -bool Doom3Shader_parseAddnormals(Tokeniser& tokeniser, CopiedString& bump) +bool Doom3Shader_parseAddnormals(Tokeniser& tokeniser, TextureExpression& bump) { RETURN_FALSE_IF_FAIL(Tokeniser_parseToken(tokeniser, "(")); RETURN_FALSE_IF_FAIL(Tokeniser_parseTextureName(tokeniser, bump)); RETURN_FALSE_IF_FAIL(Tokeniser_parseToken(tokeniser, ",")); RETURN_FALSE_IF_FAIL(Tokeniser_parseToken(tokeniser, "heightmap")); - CopiedString heightmapName; - CopiedString heightmapScale; + TextureExpression heightmapName; + ShaderValue heightmapScale; RETURN_FALSE_IF_FAIL(Doom3Shader_parseHeightmap(tokeniser, heightmapName, heightmapScale)); RETURN_FALSE_IF_FAIL(Tokeniser_parseToken(tokeniser, ")")); return true; } -bool Doom3Shader_parseBumpmap(Tokeniser& tokeniser, CopiedString& bump, CopiedString& heightmapScale) +bool Doom3Shader_parseBumpmap(Tokeniser& tokeniser, TextureExpression& bump, ShaderValue& heightmapScale) { const char* token = tokeniser.getToken(); if(token == 0) @@ -465,7 +464,7 @@ class LayerTemplate { public: LayerTypeId m_type; - CopiedString m_texture; + TextureExpression m_texture; BlendFuncExpression m_blendFunc; bool m_clampToBorder; ShaderValue m_alphaTest; @@ -741,9 +740,9 @@ bool ShaderTemplate::parseDoom3(Tokeniser& tokeniser) if(string_equal_nocase(lightFalloffImage, "makeintensity")) { RETURN_FALSE_IF_FAIL(Tokeniser_parseToken(tokeniser, "(")); - CopiedString name; + TextureExpression name; RETURN_FALSE_IF_FAIL(Tokeniser_parseTextureName(tokeniser, name)); - m_lightFalloffImage = name.c_str(); + m_lightFalloffImage = name; RETURN_FALSE_IF_FAIL(Tokeniser_parseToken(tokeniser, ")")); } else @@ -797,7 +796,7 @@ ShaderDefinitionMap g_shaderDefinitions; bool parseTemplateInstance(Tokeniser& tokeniser, const char* filename) { CopiedString name; - RETURN_FALSE_IF_FAIL(Tokeniser_parseTextureName(tokeniser, name)); + RETURN_FALSE_IF_FAIL(Tokeniser_parseShaderName(tokeniser, name)); const char* templateName = tokeniser.getToken(); ShaderTemplate* shaderTemplate = findTemplate(templateName); if(shaderTemplate == 0) @@ -1312,7 +1311,7 @@ void FreeShaders() bool ShaderTemplate::parseQuake3(Tokeniser& tokeniser) { // name of the qtexture_t we'll use to represent this shader (this one has the "textures\" before) - m_textureName = m_Name; + m_textureName = m_Name.c_str(); tokeniser.nextLine(); @@ -1486,7 +1485,7 @@ class Layer { public: LayerTypeId m_type; - CopiedString m_texture; + TextureExpression m_texture; BlendFunc m_blendFunc; bool m_clampToBorder; float m_alphaTest; @@ -1924,6 +1923,8 @@ void Shaders_Load() lst = lst->next; } } + + //StringPool_analyse(ShaderPool::instance()); } void Shaders_Free() diff --git a/radiant/commands.cpp b/radiant/commands.cpp index e873b6a8..30154143 100644 --- a/radiant/commands.cpp +++ b/radiant/commands.cpp @@ -486,7 +486,7 @@ public: } else // special key { - CopiedString keyName(value, keyEnd); + CopiedString keyName(StringRange(value, keyEnd)); accelerator.key = global_keys_find(keyName.c_str()); if(accelerator.key != 0) { diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index f413f122..e57dae78 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -558,7 +558,7 @@ void Dialog::addCombo(GtkWidget* vbox, const char* name, StringArrayRange values { GtkWidget* combo = gtk_combo_box_new_text(); - for(StringArrayRange::Iterator i = values.begin; i != values.end; ++i) + for(StringArrayRange::Iterator i = values.first; i != values.last; ++i) { gtk_combo_box_append_text(GTK_COMBO_BOX(combo), *i); } @@ -640,7 +640,7 @@ void Dialog::addRadio(GtkWidget* vbox, const char* name, int& data, StringArrayR void Dialog::addRadioIcons(GtkWidget* vbox, const char* name, StringArrayRange icons, const IntImportCallback& importViewer, const IntExportCallback& exportViewer) { - GtkWidget* table = gtk_table_new (2, static_cast(icons.end - icons.begin), FALSE); + GtkWidget* table = gtk_table_new (2, static_cast(icons.last - icons.first), FALSE); gtk_widget_show (table); gtk_table_set_row_spacings (GTK_TABLE (table), 5); @@ -648,9 +648,9 @@ void Dialog::addRadioIcons(GtkWidget* vbox, const char* name, StringArrayRange i GSList* group = 0; GtkWidget* radio = 0; - for(StringArrayRange::Iterator icon = icons.begin; icon != icons.end; ++icon) + for(StringArrayRange::Iterator icon = icons.first; icon != icons.last; ++icon) { - guint pos = static_cast(icon - icons.begin); + guint pos = static_cast(icon - icons.first); GtkImage* image = new_local_image(*icon); gtk_widget_show(GTK_WIDGET(image)); gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(image), pos, pos+1, 0, 1, diff --git a/radiant/eclass_def.cpp b/radiant/eclass_def.cpp index 266968a5..01341ed5 100644 --- a/radiant/eclass_def.cpp +++ b/radiant/eclass_def.cpp @@ -182,7 +182,7 @@ void setSpecialLoad(EntityClass *e, const char* pWhat, CopiedString& p) where = strchr(pText,'\"'); if (where) { - p = CopiedString(pText, where); + p = StringRange(pText, where); } else { diff --git a/radiant/eclass_doom3.cpp b/radiant/eclass_doom3.cpp index 56e84d60..966590f8 100644 --- a/radiant/eclass_doom3.cpp +++ b/radiant/eclass_doom3.cpp @@ -313,7 +313,7 @@ void EntityClassDoom3_parseEntityDef(Tokeniser& tokeniser) const char* key = tokeniser.getToken(); const char* last = string_findFirstSpaceOrTab(key); - CopiedString first(key, last); + CopiedString first(StringRange(key, last)); if(!string_empty(last)) { diff --git a/radiant/main.cpp b/radiant/main.cpp index 7668fb4d..c9a50833 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -619,3 +619,4 @@ int main (int argc, char* argv[]) return EXIT_SUCCESS; } + diff --git a/radiant/map.cpp b/radiant/map.cpp index f4a23c16..c846ca7e 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -1046,6 +1046,8 @@ void Map_LoadFile (const char *filename) globalOutputStream() << makeLeftJustified(Unsigned(g_brushCount.get()), 5) << " primitive\n"; globalOutputStream() << makeLeftJustified(Unsigned(g_entityCount.get()), 5) << " entities\n"; + + //GlobalEntityCreator().printStatistics(); // // move the view to a start position diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 2e5c0fb9..58285259 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -159,9 +159,9 @@ void texturegroup_activated(GtkWidget* widget, gpointer data) reinterpret_cast(data)->loadGroup(); } -bool string_equal_start(const char* string, const char* start) +bool string_equal_start(const char* string, StringRange start) { - return string_equal_n(string, start, string_length(start)); + return string_equal_n(string, start.first, start.last - start.first); } GtkMenuItem* MenuItem_create(const char* name) @@ -210,7 +210,7 @@ void TextureGroupsMenu_Construct(GtkMenu* menu, const TextureGroups& groups) { const char* dirName = (*i).c_str(); const char* firstUnderscore = strchr(dirName, '_'); - CopiedString dirRoot(dirName, (firstUnderscore == 0) ? dirName : firstUnderscore + 1); + StringRange dirRoot(dirName, (firstUnderscore == 0) ? dirName : firstUnderscore + 1); // do we shrink the menus? // we shrink only if we have at least two things to shrink :-) @@ -218,16 +218,15 @@ void TextureGroupsMenu_Construct(GtkMenu* menu, const TextureGroups& groups) ++next; if(firstUnderscore != 0 && next != groups.end() - && string_equal_start((*next).c_str(), dirRoot.c_str())) + && string_equal_start((*next).c_str(), dirRoot)) { - CopiedString itemName(dirName, firstUnderscore); - GtkMenuItem* item = Menu_addItem(menu, itemName.c_str()); + GtkMenuItem* item = Menu_addItem(menu, CopiedString(StringRange(dirName, firstUnderscore)).c_str()); GtkMenu *pSubMenu = GTK_MENU(gtk_menu_new()); gtk_menu_item_set_submenu(item, GTK_WIDGET(pSubMenu)); // keep going... - while(i != groups.end() && string_equal_start((*i).c_str(), dirRoot.c_str())) + while(i != groups.end() && string_equal_start((*i).c_str(), dirRoot)) { TextureGroupsMenu_addItem(pSubMenu, (*i).c_str()); @@ -266,7 +265,7 @@ void TextureGroups_addShader(TextureGroups& groups, const char* shaderName) const char* last = path_remove_directory(texture); if(!string_empty(last)) { - groups.insert(CopiedString(texture, --last)); + groups.insert(CopiedString(StringRange(texture, --last))); } } } @@ -811,8 +810,7 @@ class LoadShaderVisitor : public Archive::Visitor public: void visit(const char* name) { - CopiedString shaderName(name, path_get_filename_base_end(name)); - IShader* shader = QERApp_Shader_ForName(shaderName.c_str()); + IShader* shader = QERApp_Shader_ForName(CopiedString(StringRange(name, path_get_filename_base_end(name))).c_str()); shader->DecRef(); } }; diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index d80787d6..b0c2c055 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -1152,7 +1152,7 @@ public: { popMenu(); } - pushMenu(CopiedString(name, underscore)); + pushMenu(CopiedString(StringRange(name, underscore))); } else if(m_stack.size() == 2) { -- 2.39.2