- Timestamp:
- Sep 11, 2005, 10:30:38 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/debug.h
r5076 r5174 27 27 28 28 #include "confincl.h" 29 #include "shell .h"29 #include "shell_buffer.h" 30 30 31 31 #include <stdio.h> … … 100 100 //#ifdef 101 101 #define PRINTF(x) PRINT(x) 102 #define PRINT_EXEC Shell ::addBufferLineStatic102 #define PRINT_EXEC ShellBuffer::addBufferLineStatic 103 103 104 104 #ifndef PRINTF -
trunk/src/lib/shell/shell.cc
r5173 r5174 43 43 this->setName("Shell"); 44 44 45 this->keepBufferArray[0] = '\0';46 this->keepBuffer = false;47 45 48 46 this->bActive = false; 49 this->buffer = new tList<char>;50 47 this->bufferIterator = this->buffer->getIterator(); 51 48 … … 57 54 58 55 //this->bufferSize = 0; 59 this->bufferText = NULL;60 this->setBufferSize(10);61 this->bufferDisplaySize = 10;62 56 this->setAbsCoor2D(3, -400); 63 57 this->delayed = 0; … … 95 89 delete this->inputLine; 96 90 97 // delete all the Chars in the Buffers91 // delete all the Strings in the Buffers 98 92 char* charElem = this->bufferIterator->firstElement(); 99 93 while (charElem != NULL) -
trunk/src/lib/shell/shell.h
r5173 r5174 9 9 #include "element_2d.h" 10 10 #include "event_listener.h" 11 #include "shell_buffer.h"11 //#include "shell_buffer.h" 12 12 13 13 #include <stdarg.h> 14 15 #define SHELL_BUFFER_SIZE 16384 14 16 15 17 // FORWARD DECLARATION -
trunk/src/lib/shell/shell_buffer.cc
r5173 r5174 17 17 18 18 #include "shell_buffer.h" 19 #include "debug.h" 20 #include "list.h" 21 22 #include "stdlibincl.h" 19 23 20 24 using namespace std; … … 27 31 ShellBuffer::ShellBuffer () 28 32 { 29 // this->setClassID(CL_PROTO_ID, "ProtoClass"); 33 this->keepBufferArray[0] = '\0'; 34 this->keepBuffer = false; 35 this->buffer = new tList<char>; 30 36 31 /* If you make a new class, what is most probably the case when you write this file 32 don't forget to: 33 1. Add the new file new_class.cc to the ./src/Makefile.am 34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS 35 36 Advanced Topics: 37 - if you want to let your object be managed via the ObjectManager make sure to read 38 the object_manager.h header comments. You will use this most certanly only if you 39 make many objects of your class, like a weapon bullet. 40 */ 37 this->setBufferSize(10); 41 38 } 42 39 40 ShellBuffer* ShellBuffer::singletonRef = NULL; 43 41 44 42 /** … … 47 45 ShellBuffer::~ShellBuffer () 48 46 { 49 // delete what has to be deleted here 47 48 delete buffer; 49 50 ShellBuffer::singletonRef = NULL; 50 51 } 52 53 /** 54 * deletes all the Buffers 55 */ 56 void ShellBuffer::flushBuffers() 57 { 58 // delete all the Chars in the Buffers 59 tIterator<char>* charIterator = this->buffer->getIterator(); 60 char* charElem = charIterator->firstElement(); 61 while (charElem != NULL) 62 { 63 delete charElem; 64 65 charElem = charIterator->nextElement(); 66 } 67 delete charIterator; 68 delete this->buffer; 69 this->buffer = new tList<char>; 70 } 71 72 /** 73 * adds a new Line to the List of Buffers 74 * @param line the Line as in the first argument in printf 75 */ 76 bool ShellBuffer::addBufferLineStatic(const char* line, ...) 77 { 78 va_list arguments; 79 va_start(arguments, line); 80 81 #if DEBUG < 3 82 if (ShellBuffer::singletonRef == NULL) 83 #endif 84 85 // vprintf(line, arguments); 86 #if DEBUG < 3 87 else 88 #else 89 if (ShellBuffer::singletonRef != NULL) 90 #endif 91 ShellBuffer::singletonRef->addBufferLine(line, arguments); 92 return true; 93 } 94 95 /** 96 * add a Line to the List of Buffers 97 * @param line 98 * @param arguments 99 * 100 * This function Adds one line to the buffer. 101 * and displays the line as the First Line of the display-buffer 102 */ 103 void ShellBuffer::addBufferLine(const char* line, va_list arguments) 104 { 105 vsprintf(this->bufferArray, line, arguments); 106 107 char* inputEnd; 108 char* newLineBegin; 109 char* newLineEnd; 110 111 // check if we have something left in the buffers 112 if (unlikely(this->keepBuffer)) 113 { 114 strcat(this->keepBufferArray, this->bufferArray); 115 inputEnd = this->keepBufferArray + strlen(this->keepBufferArray); 116 newLineBegin = this->keepBufferArray; 117 this->keepBuffer = false; 118 } 119 else 120 { 121 inputEnd = this->bufferArray + strlen(this->bufferArray); 122 newLineBegin = this->bufferArray; 123 } 124 125 // adding all the new Lines 126 while (newLineBegin < inputEnd) 127 { 128 newLineEnd = strchr(newLineBegin, '\n'); 129 if (newLineEnd != NULL && *newLineEnd == '\n') 130 *newLineEnd = '\0'; 131 else 132 { 133 // newLineEnd = newLineBegin + strlen(newLineBegin); 134 strcpy(this->keepBufferArray, newLineBegin); 135 this->keepBuffer = true; 136 break; 137 } 138 139 char* addLine = new char[strlen(newLineBegin)+1]; 140 strcpy(addLine, newLineBegin); 141 142 this->buffer->add(addLine); 143 144 if (this->buffer->getSize() > this->bufferSize) 145 { 146 delete this->buffer->firstElement(); 147 this->buffer->remove(this->buffer->firstElement()); 148 } 149 150 newLineBegin = newLineEnd+1; 151 } 152 } 153 154 /** 155 * moves the buffer around lineCount lines upwards (negative values move down) 156 * @param lineCount the Count of lines to move upwards 157 * 158 * @todo 159 */ 160 void ShellBuffer::moveBuffer(unsigned int lineCount) 161 { 162 } 163 164 /** 165 * @param lineNumber the n-th line from the bottom 166 * @returns the Buffer at Line lineNumber 167 */ 168 const char* ShellBuffer::getBufferLine(unsigned int lineNumber) 169 { 170 tIterator<char>* charIterator = this->buffer->getIterator(); 171 char* charElem = charIterator->firstElement(); 172 173 int i = 1; 174 while (charElem != NULL) 175 { 176 if (i++ < lineNumber) 177 { 178 delete charIterator; 179 return charElem; 180 } 181 182 charElem = charIterator->nextElement(); 183 } 184 delete charIterator; 185 } -
trunk/src/lib/shell/shell_buffer.h
r5173 r5174 14 14 template<class T> class tList; 15 15 template<class T> class tIterator; 16 class Text;17 16 18 17 //! A class for ... … … 20 19 21 20 public: 22 ShellBuffer();23 21 virtual ~ShellBuffer(); 24 22 /** @returns a Pointer to the only object of this Class */ 23 inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer(); return ShellBuffer::singletonRef; }; 25 24 26 25 // BUFFER // 27 26 /** @param bufferSize the new Buffer-Size */ 28 27 void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; 29 void setBufferDisplaySize(unsigned int bufferDisplaySize);30 28 void flushBuffers(); 31 29 static bool addBufferLineStatic(const char* line, ...); 32 30 void addBufferLine(const char* line, va_list arg); 33 void printToDisplayBuffer(const char* text);34 31 void moveBuffer(unsigned int lineCount); 35 32 // void moveBufferTo(unsigned int lineNumber); 36 33 const char* getBufferLine(unsigned int lineNumber); 37 34 35 private: 36 ShellBuffer(); 38 37 39 private:40 unsigned int bufferSize; //!< The Size of the buffer41 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters)42 tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history43 tIterator<char>* bufferIterator; //!< An iterator for the Shells main buffer.44 38 45 Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer 39 private: 40 static ShellBuffer* singletonRef; //!< The singleton-reference to the only memeber of this class. 41 unsigned int bufferSize; //!< The Size of the buffer 42 tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history 43 tIterator<char>* bufferIterator; //!< An iterator for the Shells main buffer. 44 46 45 char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing 47 46 char keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. 48 bool keepBuffer; //!< if the keepbuffer contains unfinished lines.47 bool keepBuffer; //!< if the keepbuffer contains unfinished lines. 49 48 49 unsigned long lineCount; //!< how many Lines have been written out so far. 50 50 }; 51 51 -
trunk/src/lib/shell/shell_command.cc
r5172 r5174 25 25 #include <stdarg.h> 26 26 #include <stdio.h> 27 #include <string.h> 27 28 28 29 using namespace std; -
trunk/src/story_entities/world.cc
r5117 r5174 39 39 #include "text_engine.h" 40 40 #include "load_param.h" 41 #include "shell.h" 41 42 42 43 #include "track_manager.h" … … 115 116 World::~World () 116 117 { 117 delete Shell ::getInstance();118 delete ShellBuffer::getInstance(); 118 119 PRINTF(3)("World::~World() - deleting current world\n"); 119 120 … … 195 196 196 197 /* init the world interface */ 197 Shell ::getInstance();198 ShellBuffer::getInstance(); 198 199 199 200 LightManager::getInstance();
Note: See TracChangeset
for help on using the changeset viewer.