From 3705064b109580103a3d13f44693503da9927281 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Thu, 12 Jun 2008 12:09:34 +0000 Subject: renamed .h to .hpp in game because they are c++ headers --- src/game/editor/array.h | 238 ------------------------------------- src/game/editor/array.hpp | 238 +++++++++++++++++++++++++++++++++++++ src/game/editor/ed_editor.cpp | 8 +- src/game/editor/ed_editor.hpp | 10 +- src/game/editor/ed_layer_quads.cpp | 6 +- src/game/editor/ed_layer_tiles.cpp | 6 +- 6 files changed, 253 insertions(+), 253 deletions(-) delete mode 100755 src/game/editor/array.h create mode 100755 src/game/editor/array.hpp (limited to 'src/game/editor') diff --git a/src/game/editor/array.h b/src/game/editor/array.h deleted file mode 100755 index fe9f2739..00000000 --- a/src/game/editor/array.h +++ /dev/null @@ -1,238 +0,0 @@ - -template -class array -{ - // - // - void init() - { - list = 0; - clear(); - } - -public: - array() - { - init(); - } - - // - array(const array &other) - { - init(); - setsize(other.len()); - for(int i = 0; i < len(); i++) - (*this)[i] = other[i]; - } - - - // - // - virtual ~array() - { - delete [] list; - list = 0; - } - - // - // - void deleteall() - { - for(int i = 0; i < len(); i++) - delete list[i]; - - clear(); - } - - - // - // - void clear() - { - delete [] list; - - list_size = 1; - list = new T[1]; - num_elements = 0; - } - - int find(T val) - { - for(int i = 0; i < len(); i++) - if((*this)[i] == val) - return i; - return -1; - } - - bool exist(T val) - { - return find(val) != -1; - } - - // - // returns the number of elements in the list - // - int len() const - { - return num_elements; - } - - // - // This doesn't conserve the order in the list. Be careful - // - void removebyindexfast(int index) - { - //ASSUME(_Pos >= 0 && _Pos < num_elements); - list[index] = list[num_elements-1]; - setsize(len()-1); - } - - void removefast(const T& _Elem) - { - for(int i = 0; i < len(); i++) - if(list[i] == _Elem) - { - removebyindexfast(i); - return; - } - } - - // - // - void removebyindex(int index) - { - //ASSUME(_Pos >= 0 && _Pos < num_elements); - - for(int i = index+1; i < num_elements; i++) - list[i-1] = list[i]; - - setsize(len()-1); - } - - void insert(int index, const T& element) - { - int some_len = len(); - if (index < some_len) - setsize(some_len+1); - else - setsize(index + 1); - - for(int i = num_elements-2; i >= index; i--) - list[i+1] = list[i]; - - list[index] = element; - } - - bool remove(const T& element) - { - for(int i = 0; i < len(); i++) - if(list[i] == element) - { - removebyindex(i); - return true; - } - return false; - } - - // - // - int add(const T& element) - { - //if(num_elements == list_size) - setsize(len()+1); - list[num_elements-1] = element; - return num_elements-1; - } - - // - // - int add(const T& elem, int index) - { - setsize(len()+1); - - for(int i = num_elements-1; i > index; i--) - list[i] = list[i-1]; - - list[index] = elem; - - //num_elements++; - return num_elements-1; - } - - // - // - T& operator[] (int index) - { - return list[index]; - } - - const T& operator[] (int index) const - { - return list[index]; - } - - // - // - T *getptr() - { - return list; - } - - const T *getptr() const - { - return list; - } - - // - // - // - void setsize(int new_len) - { - if (list_size < new_len) - allocsize(new_len); - num_elements = new_len; - } - - // removes unnessasary data, returns how many bytes was earned - int optimize() - { - int Before = memoryusage(); - setsize(num_elements); - return Before - memoryusage(); - } - - // returns how much memory this dynamic array is using - int memoryusage() - { - return sizeof(array) + sizeof(T)*list_size; - } - - // - array &operator = (const array &other) - { - setsize(other.len()); - for(int i = 0; i < len(); i++) - (*this)[i] = other[i]; - return *this; - } -private: - void allocsize(int new_len) - { - list_size = new_len; - T *new_list = new T[list_size]; - - long end = num_elements < list_size ? num_elements : list_size; - for(int i = 0; i < end; i++) - new_list[i] = list[i]; - - delete [] list; - list = 0; - num_elements = num_elements < list_size ? num_elements : list_size; - list = new_list; - } - - T *list; - long list_size; - long num_elements; -}; - diff --git a/src/game/editor/array.hpp b/src/game/editor/array.hpp new file mode 100755 index 00000000..fe9f2739 --- /dev/null +++ b/src/game/editor/array.hpp @@ -0,0 +1,238 @@ + +template +class array +{ + // + // + void init() + { + list = 0; + clear(); + } + +public: + array() + { + init(); + } + + // + array(const array &other) + { + init(); + setsize(other.len()); + for(int i = 0; i < len(); i++) + (*this)[i] = other[i]; + } + + + // + // + virtual ~array() + { + delete [] list; + list = 0; + } + + // + // + void deleteall() + { + for(int i = 0; i < len(); i++) + delete list[i]; + + clear(); + } + + + // + // + void clear() + { + delete [] list; + + list_size = 1; + list = new T[1]; + num_elements = 0; + } + + int find(T val) + { + for(int i = 0; i < len(); i++) + if((*this)[i] == val) + return i; + return -1; + } + + bool exist(T val) + { + return find(val) != -1; + } + + // + // returns the number of elements in the list + // + int len() const + { + return num_elements; + } + + // + // This doesn't conserve the order in the list. Be careful + // + void removebyindexfast(int index) + { + //ASSUME(_Pos >= 0 && _Pos < num_elements); + list[index] = list[num_elements-1]; + setsize(len()-1); + } + + void removefast(const T& _Elem) + { + for(int i = 0; i < len(); i++) + if(list[i] == _Elem) + { + removebyindexfast(i); + return; + } + } + + // + // + void removebyindex(int index) + { + //ASSUME(_Pos >= 0 && _Pos < num_elements); + + for(int i = index+1; i < num_elements; i++) + list[i-1] = list[i]; + + setsize(len()-1); + } + + void insert(int index, const T& element) + { + int some_len = len(); + if (index < some_len) + setsize(some_len+1); + else + setsize(index + 1); + + for(int i = num_elements-2; i >= index; i--) + list[i+1] = list[i]; + + list[index] = element; + } + + bool remove(const T& element) + { + for(int i = 0; i < len(); i++) + if(list[i] == element) + { + removebyindex(i); + return true; + } + return false; + } + + // + // + int add(const T& element) + { + //if(num_elements == list_size) + setsize(len()+1); + list[num_elements-1] = element; + return num_elements-1; + } + + // + // + int add(const T& elem, int index) + { + setsize(len()+1); + + for(int i = num_elements-1; i > index; i--) + list[i] = list[i-1]; + + list[index] = elem; + + //num_elements++; + return num_elements-1; + } + + // + // + T& operator[] (int index) + { + return list[index]; + } + + const T& operator[] (int index) const + { + return list[index]; + } + + // + // + T *getptr() + { + return list; + } + + const T *getptr() const + { + return list; + } + + // + // + // + void setsize(int new_len) + { + if (list_size < new_len) + allocsize(new_len); + num_elements = new_len; + } + + // removes unnessasary data, returns how many bytes was earned + int optimize() + { + int Before = memoryusage(); + setsize(num_elements); + return Before - memoryusage(); + } + + // returns how much memory this dynamic array is using + int memoryusage() + { + return sizeof(array) + sizeof(T)*list_size; + } + + // + array &operator = (const array &other) + { + setsize(other.len()); + for(int i = 0; i < len(); i++) + (*this)[i] = other[i]; + return *this; + } +private: + void allocsize(int new_len) + { + list_size = new_len; + T *new_list = new T[list_size]; + + long end = num_elements < list_size ? num_elements : list_size; + for(int i = 0; i < end; i++) + new_list[i] = list[i]; + + delete [] list; + list = 0; + num_elements = num_elements < list_size ? num_elements : list_size; + list = new_list; + } + + T *list; + long list_size; + long num_elements; +}; + diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 3632a034..731d4f4a 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -11,10 +11,10 @@ extern "C" { #include } -#include -#include -#include -#include +#include +#include +#include +#include #include "ed_editor.hpp" diff --git a/src/game/editor/ed_editor.hpp b/src/game/editor/ed_editor.hpp index 62f8871a..dbca4a0e 100644 --- a/src/game/editor/ed_editor.hpp +++ b/src/game/editor/ed_editor.hpp @@ -2,10 +2,10 @@ #include #include -#include "array.h" -#include "../g_mapitems.h" -#include "../g_math.h" -#include "../client/gc_render.h" +#include "array.hpp" +#include "../g_mapitems.hpp" +#include "../g_math.hpp" +#include "../client/gc_render.hpp" extern "C" { #include @@ -14,7 +14,7 @@ extern "C" { #include } -#include +#include typedef void (*INDEX_MODIFY_FUNC)(int *index); diff --git a/src/game/editor/ed_layer_quads.cpp b/src/game/editor/ed_layer_quads.cpp index f3df3818..8c8a47a7 100644 --- a/src/game/editor/ed_layer_quads.cpp +++ b/src/game/editor/ed_layer_quads.cpp @@ -1,7 +1,7 @@ #include "ed_editor.hpp" -#include -#include -#include +#include +#include +#include LAYER_QUADS::LAYER_QUADS() { diff --git a/src/game/editor/ed_layer_tiles.cpp b/src/game/editor/ed_layer_tiles.cpp index 18e3b695..d77f0970 100644 --- a/src/game/editor/ed_layer_tiles.cpp +++ b/src/game/editor/ed_layer_tiles.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include "ed_editor.hpp" LAYER_TILES::LAYER_TILES(int w, int h) -- cgit 1.4.1