- Timestamp:
- Mar 15, 2006, 3:10:45 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 164 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/Makefile.am
r7193 r7221 55 55 56 56 SUBDIRS = \ 57 . \ 57 58 math \ 58 59 graphics \ … … 65 66 parser \ 66 67 shell \ 67 gui \ 68 . 68 gui -
trunk/src/lib/coord/p_node.cc
r7193 r7221 540 540 * @param childName the name of the child to add to this PNode 541 541 */ 542 void PNode::addChild (const char*childName)542 void PNode::addChild (const std::string& childName) 543 543 { 544 544 PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE)); … … 624 624 * @param parentName the name of the Parent to set to this PNode 625 625 */ 626 void PNode::setParent (const char*parentName)626 void PNode::setParent (const std::string& parentName) 627 627 { 628 628 PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE)); … … 631 631 else 632 632 PRINTF(2)("Not Found PNode's (%s::%s) new Parent by Name: %s\n", 633 this->getClassName(), this->getName(), parentName);633 this->getClassName(), this->getName(), parentName.c_str()); 634 634 } 635 635 … … 680 680 * @param bias the speed to iterate to this new Positions 681 681 */ 682 void PNode::setParentSoft(const char*parentName, float bias)682 void PNode::setParentSoft(const std::string& parentName, float bias) 683 683 { 684 684 PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE)); … … 699 699 * @param parentMode a String representing this parentingMode 700 700 */ 701 void PNode::setParentMode (const char*parentingMode)702 { 703 this->setParentMode(PNode:: charToParentingMode(parentingMode));701 void PNode::setParentMode (const std::string& parentingMode) 702 { 703 this->setParentMode(PNode::stringToParentingMode(parentingMode)); 704 704 } 705 705 … … 927 927 this->getAbsDirV().y, 928 928 this->getAbsDirV().z, 929 this->parentingModeTo Char(parentMode),929 this->parentingModeToString(parentMode), 930 930 childNodeCount); 931 931 if (depth >= 2 || depth == 0) … … 1049 1049 * @return the converted string 1050 1050 */ 1051 const char* PNode::parentingModeTo Char(int parentingMode)1051 const char* PNode::parentingModeToString(int parentingMode) 1052 1052 { 1053 1053 if (parentingMode == PNODE_LOCAL_ROTATE) … … 1068 1068 * @return the int corresponding to the named parentingMode 1069 1069 */ 1070 PARENT_MODE PNode:: charToParentingMode(const char*parentingMode)1071 { 1072 if ( !strcmp(parentingMode, "local-rotate"))1070 PARENT_MODE PNode::stringToParentingMode(const std::string& parentingMode) 1071 { 1072 if (parentingMode == "local-rotate") 1073 1073 return (PNODE_LOCAL_ROTATE); 1074 else if ( !strcmp(parentingMode, "rotate-movement"))1074 else if (parentingMode == "rotate-movement") 1075 1075 return (PNODE_ROTATE_MOVEMENT); 1076 else if ( !strcmp(parentingMode, "movement"))1076 else if (parentingMode == "movement") 1077 1077 return (PNODE_MOVEMENT); 1078 else if ( !strcmp(parentingMode, "all"))1078 else if (parentingMode == "all") 1079 1079 return (PNODE_ALL); 1080 else if ( !strcmp(parentingMode, "rotate-and-move"))1080 else if (parentingMode == "rotate-and-move") 1081 1081 return (PNODE_ROTATE_AND_MOVE); 1082 1082 } -
trunk/src/lib/coord/p_node.h
r7076 r7221 143 143 // PARENTING // 144 144 void addChild (PNode* child); 145 void addChild (const char*childName);145 void addChild (const std::string& childName); 146 146 void removeChild (PNode* child); 147 147 void removeNode(); … … 151 151 /** @param parent the new parent of this node */ 152 152 inline void setParent (PNode* parent) { parent->addChild(this); }; 153 void setParent (const char*parentName);153 void setParent (const std::string& parentName); 154 154 /** @returns the parent of this PNode */ 155 155 inline PNode* getParent () const { return this->parent; }; … … 158 158 159 159 void setParentSoft(PNode* parentNode, float bias = 1.0); 160 void setParentSoft(const char*parentName, float bias = 1.0);160 void setParentSoft(const std::string& parentName, float bias = 1.0); 161 161 162 162 // PARENTING_MODE AND OTHER FLAGS // 163 163 void setParentMode (PARENT_MODE parentMode); 164 void setParentMode (const char*parentingMode);164 void setParentMode (const std::string& parentingMode); 165 165 /** @returns the Parenting mode of this node */ 166 166 int getParentMode() const { return 0x000f & this->parentMode; }; … … 183 183 184 184 // HELPER_FUNCTIONS // 185 static const char* parentingModeTo Char(int parentingMode);186 static PARENT_MODE charToParentingMode(const char*parentingMode);185 static const char* parentingModeToString(int parentingMode); 186 static PARENT_MODE stringToParentingMode(const std::string& parentingMode); 187 187 float distance(const PNode* node) const { return (this->getAbsCoor() - node->getAbsCoor()).len(); }; 188 188 -
trunk/src/lib/event/key_mapper.cc
r6998 r7221 129 129 * @param filename: The path and name of the file to load the bindings from 130 130 */ 131 void KeyMapper::loadKeyBindings (const char*fileName)131 void KeyMapper::loadKeyBindings (const std::string& fileName) 132 132 { 133 133 IniParser parser(fileName); … … 145 145 146 146 iniParser->firstVar(); 147 while(iniParser->getCurrentName() )147 while(iniParser->getCurrentName() != "") 148 148 { 149 149 PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); … … 164 164 165 165 iniParser->firstVar(); 166 while(iniParser->getCurrentName() )166 while(iniParser->getCurrentName() != "") 167 167 { 168 168 PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); … … 177 177 * @param the name of the button 178 178 */ 179 int* KeyMapper::nameToIndex (const char*name)179 int* KeyMapper::nameToIndex (const std::string& name) 180 180 { 181 181 coord[0] = -1; … … 199 199 * @param id of the key 200 200 */ 201 void KeyMapper::mapKeys(const char*name, int* index)201 void KeyMapper::mapKeys(const std::string& name, int* index) 202 202 { 203 203 for( int i = 0; map[i].pValue != NULL; ++i ) 204 204 { 205 if( !strcmp (name, map[i].pName))205 if( name == map[i].pName) 206 206 { 207 207 if( index[0] == 0) -
trunk/src/lib/event/key_mapper.h
r6998 r7221 29 29 virtual ~KeyMapper(); 30 30 31 void loadKeyBindings(const char* fileName = NULL);31 void loadKeyBindings(const std::string& fileName = "" ); 32 32 void loadKeyBindings(IniParser* iniParser); 33 33 … … 35 35 36 36 private: 37 int* nameToIndex (const char*name);38 void mapKeys(const char*name, int* index);37 int* nameToIndex (const std::string& name); 38 void mapKeys(const std::string& name, int* index); 39 39 40 40 public: -
trunk/src/lib/event/key_names.cc
r5476 r7221 23 23 using namespace std; 24 24 25 int buttonnameToSDLB(const char*name)25 int buttonnameToSDLB(const std::string& name) 26 26 { 27 if( !strcmp (name,"BUTTON_LEFT")) return EV_MOUSE_BUTTON_LEFT;28 if( !strcmp (name,"BUTTON_MIDDLE")) return EV_MOUSE_BUTTON_MIDDLE;29 if( !strcmp (name,"BUTTON_RIGHT")) return EV_MOUSE_BUTTON_RIGHT;30 if( !strcmp (name,"BUTTON_WHEELUP")) return EV_MOUSE_BUTTON_WHEELUP;31 if( !strcmp (name,"BUTTON_WHEELDOWN")) return EV_MOUSE_BUTTON_WHEELDOWN;27 if((name == "BUTTON_LEFT")) return EV_MOUSE_BUTTON_LEFT; 28 if((name == "BUTTON_MIDDLE")) return EV_MOUSE_BUTTON_MIDDLE; 29 if((name == "BUTTON_RIGHT")) return EV_MOUSE_BUTTON_RIGHT; 30 if((name == "BUTTON_WHEELUP")) return EV_MOUSE_BUTTON_WHEELUP; 31 if((name == "BUTTON_WHEELDOWN")) return EV_MOUSE_BUTTON_WHEELDOWN; 32 32 return -1; 33 33 } … … 43 43 } 44 44 45 int keynameToSDLK(const char*name)45 int keynameToSDLK(const std::string& name) 46 46 { 47 if( !strcmp (name,"BACKSPACE")) return SDLK_BACKSPACE;48 if( !strcmp (name,"TAB")) return SDLK_TAB;49 if( !strcmp (name,"CLEAR")) return SDLK_CLEAR;50 if( !strcmp (name,"RETURN")) return SDLK_RETURN;51 if( !strcmp (name,"ESCAPE")) return SDLK_ESCAPE;52 if( !strcmp (name,"SPACE")) return SDLK_SPACE;53 if( !strcmp (name,"EXCLAIM")) return SDLK_EXCLAIM;54 if( !strcmp (name,"QUOTEDBL")) return SDLK_QUOTEDBL;55 if( !strcmp (name,"HASH")) return SDLK_HASH;56 if( !strcmp (name,"PAUSE")) return SDLK_PAUSE;57 if( !strcmp (name,"DOLLAR")) return SDLK_DOLLAR;58 if( !strcmp (name,"AMPERSAND")) return SDLK_AMPERSAND;59 if( !strcmp (name,"QUOTE")) return SDLK_QUOTE;60 if( !strcmp (name,"LEFTPAREN")) return SDLK_LEFTPAREN;61 if( !strcmp (name,"RIGHTPAREN")) return SDLK_RIGHTPAREN;62 if( !strcmp (name,"ASTERISK")) return SDLK_ASTERISK;63 if( !strcmp (name,"PLUS")) return SDLK_PLUS;64 if( !strcmp (name,"COMMA")) return SDLK_COMMA;65 if( !strcmp (name,"MINUS")) return SDLK_MINUS;66 if( !strcmp (name,"PERIOD")) return SDLK_PERIOD;67 if( !strcmp (name,"SLASH")) return SDLK_SLASH;68 if( !strcmp (name,"0")) return SDLK_0;69 if( !strcmp (name,"1")) return SDLK_1;70 if( !strcmp (name,"2")) return SDLK_2;71 if( !strcmp (name,"3")) return SDLK_3;72 if( !strcmp (name,"4")) return SDLK_4;73 if( !strcmp (name,"5")) return SDLK_5;74 if( !strcmp (name,"6")) return SDLK_6;75 if( !strcmp (name,"7")) return SDLK_7;76 if( !strcmp (name,"8")) return SDLK_8;77 if( !strcmp (name,"9")) return SDLK_9;78 if( !strcmp (name,"COLON")) return SDLK_COLON;79 if( !strcmp (name,"SEMICOLON")) return SDLK_SEMICOLON;80 if( !strcmp (name,"LESS")) return SDLK_LESS;81 if( !strcmp (name,"EQUALS")) return SDLK_EQUALS;82 if( !strcmp (name,"GREATER")) return SDLK_GREATER;83 if( !strcmp (name,"QUESTION")) return SDLK_QUESTION;84 if( !strcmp (name,"AT")) return SDLK_AT;85 if( !strcmp (name,"LEFTBRACKET")) return SDLK_LEFTBRACKET;86 if( !strcmp (name,"BACKSLASH")) return SDLK_BACKSLASH;87 if( !strcmp (name,"RIGHTBRACKET")) return SDLK_RIGHTBRACKET;88 if( !strcmp (name,"CARET")) return SDLK_CARET;89 if( !strcmp (name,"UNDERSCORE")) return SDLK_UNDERSCORE;90 if( !strcmp (name,"BACKQUOTE")) return SDLK_BACKQUOTE;91 if( !strcmp (name,"a")) return SDLK_a;92 if( !strcmp (name,"b")) return SDLK_b;93 if( !strcmp (name,"c")) return SDLK_c;94 if( !strcmp (name,"d")) return SDLK_d;95 if( !strcmp (name,"e")) return SDLK_e;96 if( !strcmp (name,"f")) return SDLK_f;97 if( !strcmp (name,"g")) return SDLK_g;98 if( !strcmp (name,"h")) return SDLK_h;99 if( !strcmp (name,"i")) return SDLK_i;100 if( !strcmp (name,"j")) return SDLK_j;101 if( !strcmp (name,"k")) return SDLK_k;102 if( !strcmp (name,"l")) return SDLK_l;103 if( !strcmp (name,"m")) return SDLK_m;104 if( !strcmp (name,"n")) return SDLK_n;105 if( !strcmp (name,"o")) return SDLK_o;106 if( !strcmp (name,"p")) return SDLK_p;107 if( !strcmp (name,"q")) return SDLK_q;108 if( !strcmp (name,"r")) return SDLK_r;109 if( !strcmp (name,"s")) return SDLK_s;110 if( !strcmp (name,"t")) return SDLK_t;111 if( !strcmp (name,"u")) return SDLK_u;112 if( !strcmp (name,"v")) return SDLK_v;113 if( !strcmp (name,"w")) return SDLK_w;114 if( !strcmp (name,"x")) return SDLK_x;115 if( !strcmp (name,"y")) return SDLK_y;116 if( !strcmp (name,"z")) return SDLK_z;117 if( !strcmp (name,"DELETE")) return SDLK_DELETE;118 if( !strcmp (name,"KP0")) return SDLK_KP0;119 if( !strcmp (name,"KP1")) return SDLK_KP1;120 if( !strcmp (name,"KP2")) return SDLK_KP2;121 if( !strcmp (name,"KP3")) return SDLK_KP3;122 if( !strcmp (name,"KP4")) return SDLK_KP4;123 if( !strcmp (name,"KP5")) return SDLK_KP5;124 if( !strcmp (name,"KP6")) return SDLK_KP6;125 if( !strcmp (name,"KP7")) return SDLK_KP7;126 if( !strcmp (name,"KP8")) return SDLK_KP8;127 if( !strcmp (name,"KP9")) return SDLK_KP9;128 if( !strcmp (name,"KP_PERIOD")) return SDLK_KP_PERIOD;129 if( !strcmp (name,"KP_DIVIDE")) return SDLK_KP_DIVIDE;130 if( !strcmp (name,"KP_MULTIPLY")) return SDLK_KP_MULTIPLY;131 if( !strcmp (name,"KP_MINUS")) return SDLK_KP_MINUS;132 if( !strcmp (name,"KP_PLUS")) return SDLK_KP_PLUS;133 if( !strcmp (name,"KP_ENTER")) return SDLK_KP_ENTER;134 if( !strcmp (name,"KP_EQUALS")) return SDLK_KP_EQUALS;135 if( !strcmp (name,"UP")) return SDLK_UP;136 if( !strcmp (name,"DOWN")) return SDLK_DOWN;137 if( !strcmp (name,"RIGHT")) return SDLK_RIGHT;138 if( !strcmp (name,"LEFT")) return SDLK_LEFT;139 if( !strcmp (name,"INSERT")) return SDLK_INSERT;140 if( !strcmp (name,"HOME")) return SDLK_HOME;141 if( !strcmp (name,"END")) return SDLK_END;142 if( !strcmp (name,"PAGEUP")) return SDLK_PAGEUP;143 if( !strcmp (name,"PAGEDOWN")) return SDLK_PAGEDOWN;144 if( !strcmp (name,"F1")) return SDLK_F1;145 if( !strcmp (name,"F2")) return SDLK_F2;146 if( !strcmp (name,"F3")) return SDLK_F3;147 if( !strcmp (name,"F4")) return SDLK_F4;148 if( !strcmp (name,"F5")) return SDLK_F5;149 if( !strcmp (name,"F6")) return SDLK_F6;150 if( !strcmp (name,"F7")) return SDLK_F7;151 if( !strcmp (name,"F8")) return SDLK_F8;152 if( !strcmp (name,"F9")) return SDLK_F9;153 if( !strcmp (name,"F10")) return SDLK_F10;154 if( !strcmp (name,"F11")) return SDLK_F11;155 if( !strcmp (name,"F12")) return SDLK_F12;156 if( !strcmp (name,"F13")) return SDLK_F13;157 if( !strcmp (name,"F14")) return SDLK_F14;158 if( !strcmp (name,"F15")) return SDLK_F15;159 if( !strcmp (name,"NUMLOCK")) return SDLK_NUMLOCK;160 if( !strcmp (name,"CAPSLOCK")) return SDLK_CAPSLOCK;161 if( !strcmp (name,"SCROLLOCK")) return SDLK_SCROLLOCK;162 if( !strcmp (name,"RSHIFT")) return SDLK_RSHIFT;163 if( !strcmp (name,"LSHIFT")) return SDLK_LSHIFT;164 if( !strcmp (name,"RCTRL")) return SDLK_RCTRL;165 if( !strcmp (name,"LCTRL")) return SDLK_LCTRL;166 if( !strcmp (name,"RALT")) return SDLK_RALT;167 if( !strcmp (name,"LALT")) return SDLK_LALT;168 if( !strcmp (name,"RMETA")) return SDLK_RMETA;169 if( !strcmp (name,"LMETA")) return SDLK_LMETA;170 if( !strcmp (name,"LSUPER")) return SDLK_LSUPER;171 if( !strcmp (name,"RSUPER")) return SDLK_RSUPER;172 if( !strcmp (name,"MODE")) return SDLK_MODE;173 if( !strcmp (name,"HELP")) return SDLK_HELP;174 if( !strcmp (name,"PRINT")) return SDLK_PRINT;175 if( !strcmp (name,"SYSREQ")) return SDLK_SYSREQ;176 if( !strcmp (name,"BREAK")) return SDLK_BREAK;177 if( !strcmp (name,"MENU")) return SDLK_MENU;178 if( !strcmp (name,"POWER")) return SDLK_POWER;179 if( !strcmp (name,"EURO")) return SDLK_EURO;47 if((name == "BACKSPACE")) return SDLK_BACKSPACE; 48 if((name == "TAB")) return SDLK_TAB; 49 if((name == "CLEAR")) return SDLK_CLEAR; 50 if((name == "RETURN")) return SDLK_RETURN; 51 if((name == "ESCAPE")) return SDLK_ESCAPE; 52 if((name == "SPACE")) return SDLK_SPACE; 53 if((name == "EXCLAIM")) return SDLK_EXCLAIM; 54 if((name == "QUOTEDBL")) return SDLK_QUOTEDBL; 55 if((name == "HASH")) return SDLK_HASH; 56 if((name == "PAUSE")) return SDLK_PAUSE; 57 if((name == "DOLLAR")) return SDLK_DOLLAR; 58 if((name == "AMPERSAND")) return SDLK_AMPERSAND; 59 if((name == "QUOTE")) return SDLK_QUOTE; 60 if((name == "LEFTPAREN")) return SDLK_LEFTPAREN; 61 if((name == "RIGHTPAREN")) return SDLK_RIGHTPAREN; 62 if((name == "ASTERISK")) return SDLK_ASTERISK; 63 if((name == "PLUS")) return SDLK_PLUS; 64 if((name == "COMMA")) return SDLK_COMMA; 65 if((name == "MINUS")) return SDLK_MINUS; 66 if((name == "PERIOD")) return SDLK_PERIOD; 67 if((name == "SLASH")) return SDLK_SLASH; 68 if((name == "0")) return SDLK_0; 69 if((name == "1")) return SDLK_1; 70 if((name == "2")) return SDLK_2; 71 if((name == "3")) return SDLK_3; 72 if((name == "4")) return SDLK_4; 73 if((name == "5")) return SDLK_5; 74 if((name == "6")) return SDLK_6; 75 if((name == "7")) return SDLK_7; 76 if((name == "8")) return SDLK_8; 77 if((name == "9")) return SDLK_9; 78 if((name == "COLON")) return SDLK_COLON; 79 if((name == "SEMICOLON")) return SDLK_SEMICOLON; 80 if((name == "LESS")) return SDLK_LESS; 81 if((name == "EQUALS")) return SDLK_EQUALS; 82 if((name == "GREATER")) return SDLK_GREATER; 83 if((name == "QUESTION")) return SDLK_QUESTION; 84 if((name == "AT")) return SDLK_AT; 85 if((name == "LEFTBRACKET")) return SDLK_LEFTBRACKET; 86 if((name == "BACKSLASH")) return SDLK_BACKSLASH; 87 if((name == "RIGHTBRACKET")) return SDLK_RIGHTBRACKET; 88 if((name == "CARET")) return SDLK_CARET; 89 if((name == "UNDERSCORE")) return SDLK_UNDERSCORE; 90 if((name == "BACKQUOTE")) return SDLK_BACKQUOTE; 91 if((name == "a")) return SDLK_a; 92 if((name == "b")) return SDLK_b; 93 if((name == "c")) return SDLK_c; 94 if((name == "d")) return SDLK_d; 95 if((name == "e")) return SDLK_e; 96 if((name == "f")) return SDLK_f; 97 if((name == "g")) return SDLK_g; 98 if((name == "h")) return SDLK_h; 99 if((name == "i")) return SDLK_i; 100 if((name == "j")) return SDLK_j; 101 if((name == "k")) return SDLK_k; 102 if((name == "l")) return SDLK_l; 103 if((name == "m")) return SDLK_m; 104 if((name == "n")) return SDLK_n; 105 if((name == "o")) return SDLK_o; 106 if((name == "p")) return SDLK_p; 107 if((name == "q")) return SDLK_q; 108 if((name == "r")) return SDLK_r; 109 if((name == "s")) return SDLK_s; 110 if((name == "t")) return SDLK_t; 111 if((name == "u")) return SDLK_u; 112 if((name == "v")) return SDLK_v; 113 if((name == "w")) return SDLK_w; 114 if((name == "x")) return SDLK_x; 115 if((name == "y")) return SDLK_y; 116 if((name == "z")) return SDLK_z; 117 if((name == "DELETE")) return SDLK_DELETE; 118 if((name == "KP0")) return SDLK_KP0; 119 if((name == "KP1")) return SDLK_KP1; 120 if((name == "KP2")) return SDLK_KP2; 121 if((name == "KP3")) return SDLK_KP3; 122 if((name == "KP4")) return SDLK_KP4; 123 if((name == "KP5")) return SDLK_KP5; 124 if((name == "KP6")) return SDLK_KP6; 125 if((name == "KP7")) return SDLK_KP7; 126 if((name == "KP8")) return SDLK_KP8; 127 if((name == "KP9")) return SDLK_KP9; 128 if((name == "KP_PERIOD")) return SDLK_KP_PERIOD; 129 if((name == "KP_DIVIDE")) return SDLK_KP_DIVIDE; 130 if((name == "KP_MULTIPLY")) return SDLK_KP_MULTIPLY; 131 if((name == "KP_MINUS")) return SDLK_KP_MINUS; 132 if((name == "KP_PLUS")) return SDLK_KP_PLUS; 133 if((name == "KP_ENTER")) return SDLK_KP_ENTER; 134 if((name == "KP_EQUALS")) return SDLK_KP_EQUALS; 135 if((name == "UP")) return SDLK_UP; 136 if((name == "DOWN")) return SDLK_DOWN; 137 if((name == "RIGHT")) return SDLK_RIGHT; 138 if((name == "LEFT")) return SDLK_LEFT; 139 if((name == "INSERT")) return SDLK_INSERT; 140 if((name == "HOME")) return SDLK_HOME; 141 if((name == "END")) return SDLK_END; 142 if((name == "PAGEUP")) return SDLK_PAGEUP; 143 if((name == "PAGEDOWN")) return SDLK_PAGEDOWN; 144 if((name == "F1")) return SDLK_F1; 145 if((name == "F2")) return SDLK_F2; 146 if((name == "F3")) return SDLK_F3; 147 if((name == "F4")) return SDLK_F4; 148 if((name == "F5")) return SDLK_F5; 149 if((name == "F6")) return SDLK_F6; 150 if((name == "F7")) return SDLK_F7; 151 if((name == "F8")) return SDLK_F8; 152 if((name == "F9")) return SDLK_F9; 153 if((name == "F10")) return SDLK_F10; 154 if((name == "F11")) return SDLK_F11; 155 if((name == "F12")) return SDLK_F12; 156 if((name == "F13")) return SDLK_F13; 157 if((name == "F14")) return SDLK_F14; 158 if((name == "F15")) return SDLK_F15; 159 if((name == "NUMLOCK")) return SDLK_NUMLOCK; 160 if((name == "CAPSLOCK")) return SDLK_CAPSLOCK; 161 if((name == "SCROLLOCK")) return SDLK_SCROLLOCK; 162 if((name == "RSHIFT")) return SDLK_RSHIFT; 163 if((name == "LSHIFT")) return SDLK_LSHIFT; 164 if((name == "RCTRL")) return SDLK_RCTRL; 165 if((name == "LCTRL")) return SDLK_LCTRL; 166 if((name == "RALT")) return SDLK_RALT; 167 if((name == "LALT")) return SDLK_LALT; 168 if((name == "RMETA")) return SDLK_RMETA; 169 if((name == "LMETA")) return SDLK_LMETA; 170 if((name == "LSUPER")) return SDLK_LSUPER; 171 if((name == "RSUPER")) return SDLK_RSUPER; 172 if((name == "MODE")) return SDLK_MODE; 173 if((name == "HELP")) return SDLK_HELP; 174 if((name == "PRINT")) return SDLK_PRINT; 175 if((name == "SYSREQ")) return SDLK_SYSREQ; 176 if((name == "BREAK")) return SDLK_BREAK; 177 if((name == "MENU")) return SDLK_MENU; 178 if((name == "POWER")) return SDLK_POWER; 179 if((name == "EURO")) return SDLK_EURO; 180 180 return -1; 181 181 } 182 182 183 const char* SDLKToKeyname( 183 const char* SDLKToKeyname(int key) 184 184 { 185 185 if( key == SDLK_BACKSPACE) return "BACKSPACE"; -
trunk/src/lib/event/key_names.h
r5474 r7221 1 1 /*! 2 2 * @file keynames.h 3 4 5 6 */3 * Key/button naming functions 4 * 5 * Converts strings to SDLK/SDL_BUTTON values and vice versa 6 */ 7 7 #ifndef _KEY_NAMES_H 8 8 #define _KEY_NAMES_H 9 9 10 /** 11 * converts a button name string to a integer representing the corresponding SDL mouse button identifier 12 * @param name: the name of the mouse button 13 * @return an int containing the SDL identifier of the mouse button or -1 if the button name is not valid 14 */ 15 int buttonnameToSDLB(const char* name); 10 #include <string> 16 11 17 12 /** 18 * converst a SDL mouse button identifier to a name string 19 * @param button: an SDL mouse button identifier 20 * @return a pointer to a string containing the name of the mouse button 21 */ 13 * converts a button name string to a integer representing the corresponding SDL mouse button identifier 14 * @param name: the name of the mouse button 15 * @return an int containing the SDL identifier of the mouse button or -1 if the button name is not valid 16 */ 17 int buttonnameToSDLB(const std::string& name); 18 19 /** 20 * converst a SDL mouse button identifier to a name string 21 * @param button: an SDL mouse button identifier 22 * @return a pointer to a string containing the name of the mouse button 23 */ 22 24 const char* SDLBToButtonname( int button); 23 25 24 26 /** 25 26 27 28 */29 int keynameToSDLK(const char*name);27 * converts a key name string to a integer representing the corresponding SDLK sym 28 * @param name: the name of the key 29 * @return the SDLK sym of the named key or -1 if the key name is not valid 30 */ 31 int keynameToSDLK(const std::string& name); 30 32 31 33 /** 32 33 34 35 */34 * converts an SDLK sym to a name string 35 * @param key: the SDLK sym 36 * @return a pointer to a string containig the name of the key 37 */ 36 38 const char* SDLKToKeyname( int key); 37 39 -
trunk/src/lib/graphics/effects/fog_effect.cc
r7193 r7221 126 126 * @param mode the mode character 127 127 */ 128 GLint FogEffect:: charToFogMode(const char*mode)128 GLint FogEffect::stringToFogMode(const std::string& mode) 129 129 { 130 if( !strcmp( "GL_LINEAR", mode))130 if(mode == "GL_LINEAR") 131 131 return GL_LINEAR; 132 else if( !strcmp("GL_EXP", mode))132 else if(mode == "GL_EXP") 133 133 return GL_EXP; 134 else if( !strcmp("GL_EXP2", mode))134 else if(mode == "GL_EXP2" ) 135 135 return GL_EXP2; 136 136 else -
trunk/src/lib/graphics/effects/fog_effect.h
r7107 r7221 26 26 virtual bool deactivate(); 27 27 28 inline void setFogMode(const char* mode) { this->fogMode = this->charToFogMode(mode); }28 inline void setFogMode(const std::string& mode) { this->fogMode = this->stringToFogMode(mode); } 29 29 inline void setFogDensity(float density) { this->fogDensity = density; } 30 30 inline void setFogRange(float start, float end) { this->fogStart = start; this->fogEnd = end; } … … 33 33 34 34 private: 35 GLint charToFogMode(const char*mode);35 GLint stringToFogMode(const std::string& mode); 36 36 37 37 -
trunk/src/lib/graphics/effects/lense_flare.cc
r7193 r7221 131 131 * @param mode the mode character 132 132 */ 133 GLint LenseFlare:: charToFogMode(const char*mode)133 GLint LenseFlare::stringToFogMode(const std::string& mode) 134 134 {} 135 135 … … 147 147 * 7th: Texture of the third burst 148 148 */ 149 void LenseFlare::addFlare(const char*textureName)149 void LenseFlare::addFlare(const std::string& textureName) 150 150 { 151 151 if( this->flares.size() > LF_MAX_FLARES) … … 159 159 bb->setSize(50, 50); 160 160 this->flares.push_back(bb); 161 PRINTF( 0)("Added a Lenseflare Billboard with texture %s\n", textureName);161 PRINTF(4)("Added a Lenseflare Billboard with texture %s\n", textureName.c_str()); 162 162 163 163 // the first flare belongs to the light source … … 167 167 bb->setVisibility(true); 168 168 } 169 PRINTF( 0)("Finished adding\n", textureName);169 PRINTF(4)("Finished adding\n"); 170 170 } 171 171 -
trunk/src/lib/graphics/effects/lense_flare.h
r7015 r7221 39 39 virtual void tick(float dt); 40 40 41 void addFlare(const char*textureName);41 void addFlare(const std::string& textureName); 42 42 43 43 44 44 private: 45 GLint charToFogMode(const char*mode);45 GLint stringToFogMode(const std::string& mode); 46 46 void setSourceVisibility(bool visibility) ; 47 47 -
trunk/src/lib/graphics/graphics_engine.cc
r7193 r7221 78 78 this->screen = NULL; 79 79 80 81 // Hardware82 this->hwRenderer = NULL;83 this->hwVendor = NULL;84 this->hwVersion = NULL;85 this->hwExtensions = NULL;86 87 80 // initialize the Modules 88 81 TextEngine::getInstance(); … … 103 96 // delete what has to be deleted here 104 97 this->displayFPS( false ); 105 106 delete[] this->hwRenderer;107 delete[] this->hwVendor;108 delete[] this->hwVersion;109 delete this->hwExtensions;110 98 111 99 //TextEngine … … 169 157 { 170 158 // looking if we are in fullscreen-mode 171 const char*fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0");172 if ( strchr(fullscreen, '1') || !strcasecmp(fullscreen, "true"))159 const std::string fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0"); 160 if (fullscreen[0] == '1' || fullscreen == "true") 173 161 this->fullscreenFlag = SDL_FULLSCREEN; 174 162 175 163 // looking if we are in fullscreen-mode 176 const char*textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0");177 if ( strchr(textures, '1') || !strcasecmp(textures, "true"))178 Texture::setTextureEnableState( 164 const std::string textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0"); 165 if (textures[0] == '1' || textures == "true") 166 Texture::setTextureEnableState(true); 179 167 else 180 168 Texture::setTextureEnableState(false); 181 169 182 170 // searching for a usefull resolution 183 SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480") , 'x');171 SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480").c_str(), 'x'); ///FIXME 184 172 //resolution.debug(); 185 186 this->initVideo( atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);173 MultiType x = resolution.getString(0), y = resolution.getString(1); 174 this->initVideo(x.getInt(), y.getInt(), 16); 187 175 188 176 // GraphicsEffect* fe = new FogEffect(NULL); … … 262 250 * @param icon The name of the Icon on the Disc 263 251 */ 264 void GraphicsEngine::setWindowName(const char* windowName, const char*icon)265 { 266 SDL_Surface* iconSurf = SDL_LoadBMP(icon );252 void GraphicsEngine::setWindowName(const std::string& windowName, const std::string& icon) 253 { 254 SDL_Surface* iconSurf = SDL_LoadBMP(icon.c_str()); 267 255 if (iconSurf != NULL) 268 256 { 269 257 Uint32 colorkey = SDL_MapRGB(iconSurf->format, 0, 0, 0); 270 258 SDL_SetColorKey(iconSurf, SDL_SRCCOLORKEY, colorkey); 271 SDL_WM_SetIcon(iconSurf, NULL);259 SDL_WM_SetIcon(iconSurf, NULL); 272 260 SDL_FreeSurface(iconSurf); 273 261 } 274 262 275 SDL_WM_SetCaption (windowName , icon);263 SDL_WM_SetCaption (windowName.c_str(), icon.c_str()); 276 264 } 277 265 … … 312 300 // printf("%s %s %s\n %s", renderer, vendor, version, extensions); 313 301 314 if (this->hwRenderer == NULL && renderer != NULL) 315 { 316 this->hwRenderer = new char[strlen(renderer)+1]; 317 strcpy(this->hwRenderer, renderer); 318 } 319 if (this->hwVendor == NULL && vendor != NULL) 320 { 321 this->hwVendor = new char[strlen(vendor)+1]; 322 strcpy(this->hwVendor, vendor); 323 } 324 if (this->hwVersion == NULL && version != NULL) 325 { 326 this->hwVersion = new char[strlen(version)+11]; 327 strcpy(this->hwVersion, version); 328 } 329 330 if (this->hwExtensions == NULL && extensions != NULL) 331 this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), " \n\t,"); 302 if (renderer != NULL) 303 { 304 this->hwRenderer == renderer; 305 } 306 if (vendor != NULL) 307 { 308 this->hwVendor == vendor; 309 } 310 if (version != NULL) 311 { 312 this->hwVersion == version; 313 } 314 315 if (extensions != NULL) 316 this->hwExtensions.split(extensions, " \n\t,"); 332 317 333 318 PRINT(4)("Running on : vendor: %s, renderer: %s, version:%s\n", vendor, renderer, version); 334 319 PRINT(4)("Extensions:\n"); 335 if (this->hwExtensions != NULL) 336 for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++) 337 PRINT(4)("%d: %s\n", i, this->hwExtensions->getString(i)); 320 for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++) 321 PRINT(4)("%d: %s\n", i, this->hwExtensions.getString(i).c_str()); 338 322 339 323 … … 529 513 * @return true if it is, false otherwise 530 514 */ 531 bool GraphicsEngine::hwSupportsEXT(const char* extension) 532 { 533 if (this->hwExtensions != NULL) 534 for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++) 535 if (!strcmp(extension, this->hwExtensions->getString(i))) 536 return true; 515 bool GraphicsEngine::hwSupportsEXT(const std::string& extension) 516 { 517 for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++) 518 if ( this->hwExtensions.getString(i) == extension) 519 return true; 537 520 return false; 538 521 } … … 587 570 void GraphicsEngine::draw() const 588 571 { 589 // LightManager::getInstance()->draw();572 // LightManager::getInstance()->draw(); 590 573 591 574 GraphicsEngine::storeMatrices(); … … 668 651 switch (event.type) 669 652 { 670 671 672 673 } 674 } 653 case EV_VIDEO_RESIZE: 654 this->resolutionChanged(event.resize); 655 break; 656 } 657 } -
trunk/src/lib/graphics/graphics_engine.h
r6990 r7221 14 14 #include "sdlincl.h" 15 15 #include "glincl.h" 16 #include <list> 16 17 17 #include <list>18 #include "substring.h" 18 19 19 20 // Forward Declaration 20 21 class Text; 21 22 class IniParser; 22 class SubString;23 23 class WorldEntity; 24 24 class GraphicsEffect; … … 41 41 int initFromIniFile(IniParser* iniParser); 42 42 43 void setWindowName(const char* windowName, const char*icon);43 void setWindowName(const std::string& windowName, const std::string& icon); 44 44 45 45 int setResolution(int width, int height, int bpp); … … 74 74 75 75 void listModes(); 76 bool hwSupportsEXT(const char*extension);76 bool hwSupportsEXT(const std::string& extension); 77 77 78 78 /** @brief swaps the GL_BUFFERS */ … … 116 116 117 117 // HARDWARE-Settings: 118 char*hwRenderer; //!< HW-renderer-string119 char*hwVendor; //!< HW-vendor-string120 char*hwVersion; //!< HW-version-string121 SubString *hwExtensions; //!< All suported Extensions.118 std::string hwRenderer; //!< HW-renderer-string 119 std::string hwVendor; //!< HW-vendor-string 120 std::string hwVersion; //!< HW-version-string 121 SubString hwExtensions; //!< All suported Extensions. 122 122 123 123 // FPS-related -
trunk/src/lib/graphics/importer/height_map.cc
r7193 r7221 333 333 } 334 334 335 HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel() 335 HeightMap::HeightMap(const std::string& height_map_name = "") 336 : VertexArrayModel() 336 337 { 337 338 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 338 heightMap = IMG_Load(height_map_name );339 heightMap = IMG_Load(height_map_name.c_str()); 339 340 if(heightMap!=NULL) { 340 341 341 PRINTF(0)("loading Image %s\n", height_map_name);342 PRINTF(0)("loading Image %s\n", height_map_name.c_str()); 342 343 PRINTF(0)("width : %i\n", heightMap->w); 343 344 PRINTF(0)("height : %i\n", heightMap->h); … … 350 351 } 351 352 352 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);353 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str()); 353 354 354 355 … … 361 362 } 362 363 363 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel() 364 HeightMap::HeightMap(const std::string& height_map_name = NULL, const std::string& colour_map_name = NULL) 365 : VertexArrayModel() 364 366 { 365 367 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 366 368 367 heightMap = IMG_Load(height_map_name );369 heightMap = IMG_Load(height_map_name.c_str()); 368 370 if(heightMap!=NULL) { 369 371 370 PRINTF(0)("loading Image %s\n", height_map_name);372 PRINTF(0)("loading Image %s\n", height_map_name.c_str()); 371 373 PRINTF(0)("width : %i\n", heightMap->w); 372 374 PRINTF(0)("height : %i\n", heightMap->h); … … 379 381 } 380 382 381 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);383 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str()); 382 384 383 385 … … 385 387 386 388 colourMap=NULL; 387 if(colour_map_name != NULL)389 if(colour_map_name != "") 388 390 { 389 colourMap = IMG_Load(colour_map_name);391 colourMap = IMG_Load(colour_map_name.c_str()); 390 392 } 391 393 392 394 if(colourMap != NULL) 393 395 { 394 PRINTF(0)("loading Image %s\n", colour_map_name);396 PRINTF(0)("loading Image %s\n", colour_map_name.c_str()); 395 397 PRINTF(0)("width : %i\n", colourMap->w); 396 398 PRINTF(0)("height : %i\n", colourMap->h); -
trunk/src/lib/graphics/importer/height_map.h
r6981 r7221 59 59 void load(); 60 60 void load(int Mode); 61 void load(const char*, int Mode);61 void load(const std::string&, int Mode); 62 62 void scale( Vector V); 63 63 void setAbsCoor(Vector V); … … 65 65 float getNormal(float x, float y); 66 66 HeightMap(); 67 HeightMap(const char*);68 HeightMap(const char*, const char*);67 HeightMap(const std::string&); 68 HeightMap(const std::string&, const std::string&); 69 69 virtual ~HeightMap(); 70 70 -
trunk/src/lib/graphics/importer/material.cc
r7193 r7221 34 34 * @param mtlName Name of the Material to be added to the Material List 35 35 */ 36 Material::Material (const char*mtlName)36 Material::Material (const std::string& mtlName) 37 37 { 38 38 this->setClassID(CL_MATERIAL, "Material"); … … 278 278 * @param pathName The Path to add. 279 279 */ 280 void Material::addTexturePath(const char*pathName)280 void Material::addTexturePath(const std::string& pathName) 281 281 { 282 282 ResourceManager::getInstance()->addImageDir(pathName); … … 289 289 * @param dMap the Name of the Image to Use 290 290 */ 291 void Material::setDiffuseMap(const char*dMap, GLenum target)291 void Material::setDiffuseMap(const std::string& dMap, GLenum target) 292 292 { 293 293 PRINTF(5)("setting Diffuse Map %s\n", dMap); … … 297 297 //! @todo check if RESOURCE MANAGER is availiable 298 298 //! @todo Textures from .mtl-file need special care. 299 if ( dMap != NULL)299 if (!dMap.empty()) 300 300 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 301 301 else … … 308 308 @todo implement this 309 309 */ 310 void Material::setAmbientMap(const char*aMap, GLenum target)310 void Material::setAmbientMap(const std::string& aMap, GLenum target) 311 311 { 312 312 SDL_Surface* ambientMap; … … 319 319 @todo implement this 320 320 */ 321 void Material::setSpecularMap(const char*sMap, GLenum target)321 void Material::setSpecularMap(const std::string& sMap, GLenum target) 322 322 { 323 323 SDL_Surface* specularMap; … … 330 330 @todo implemet this 331 331 */ 332 void Material::setBump(const char*bump)333 { 334 335 } 332 void Material::setBump(const std::string& bump) 333 { 334 335 } -
trunk/src/lib/graphics/importer/material.h
r7057 r7221 26 26 { 27 27 public: 28 Material (const char* mtlName = NULL);28 Material (const std::string& mtlName = ""); 29 29 virtual ~Material (); 30 30 … … 49 49 50 50 // MAPPING // 51 void setDiffuseMap(const char*dMap, GLenum target = GL_TEXTURE_2D);52 void setAmbientMap(const char*aMap, GLenum target = GL_TEXTURE_2D);53 void setSpecularMap(const char*sMap, GLenum target = GL_TEXTURE_2D);54 void setBump(const char*bump);51 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D); 52 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 53 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 54 void setBump(const std::string& bump); 55 55 GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; }; 56 56 57 static void addTexturePath(const char*pathName);57 static void addTexturePath(const std::string& pathName); 58 58 59 59 private: -
trunk/src/lib/graphics/importer/md2Model.cc
r7193 r7221 75 75 \brief simple constructor initializing all variables 76 76 */ 77 MD2Model::MD2Model(const char* modelFileName, const char*skinFileName, float scale)77 MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale) 78 78 { 79 79 this->setClassID(CL_MD2_MODEL, "MD2Model"); 80 80 /* this creates the data container via ressource manager */ 81 this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale); 81 if (!modelFileName.empty()) 82 this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale); 82 83 if( unlikely(this->data == NULL)) 83 84 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); … … 352 353 { 353 354 PRINT(0)("\n==========================| MD2Model::debug() |===\n"); 354 PRINT(0)("= Model FileName:\t%s\n", this->data->fileName );355 PRINT(0)("= Skin FileName:\t%s\n", this->data->skinFileName );355 PRINT(0)("= Model FileName:\t%s\n", this->data->fileName.c_str()); 356 PRINT(0)("= Skin FileName:\t%s\n", this->data->skinFileName.c_str()); 356 357 PRINT(0)("= Size in Memory:\t%i Bytes\n", this->data->header->frameSize * this->data->header->numFrames + 64); // 64bytes is the header size 357 358 PRINT(0)("= Number of Vertices:\t%i\n", this->data->header->numVertices); … … 370 371 \brief simple constructor 371 372 */ 372 MD2Data::MD2Data(const char* modelFileName, const char*skinFileName, float scale)373 MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale) 373 374 { 374 375 scale *= 0.1f; … … 387 388 this->scaleFactor = scale; 388 389 389 this->fileName = NULL;390 this->skinFileName = NULL;390 this->fileName = ""; 391 this->skinFileName = ""; 391 392 this->loadModel(modelFileName); 392 393 this->loadSkin(skinFileName); … … 401 402 MD2Data::~MD2Data() 402 403 { 403 delete [] this->fileName;404 delete [] this->skinFileName;405 404 delete this->header; 406 405 … … 419 418 \return true if success 420 419 */ 421 bool MD2Data::loadModel(const char*fileName)420 bool MD2Data::loadModel(const std::string& fileName) 422 421 { 423 422 FILE *pFile; //file stream … … 428 427 429 428 //! @todo this chek should include deleting a loaded model (eventually) 430 if (fileName == NULL)429 if (fileName.empty()) 431 430 return false; 432 431 433 pFile = fopen(fileName , "rb");432 pFile = fopen(fileName.c_str(), "rb"); 434 433 if( unlikely(!pFile)) 435 434 { … … 442 441 if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT)) 443 442 { 444 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName );443 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); 445 444 return false; 446 445 } 447 446 448 this->fileName = new char[strlen(fileName)+1]; 449 strcpy(this->fileName, fileName); 447 this->fileName =fileName; 450 448 /* got the data: map it to locals */ 451 449 this->numFrames = this->header->numFrames; … … 507 505 \return true if success 508 506 */ 509 bool MD2Data::loadSkin(const char*fileName)510 { 511 if( fileName == NULL)512 { 513 this->skinFileName = NULL;507 bool MD2Data::loadSkin(const std::string& fileName) 508 { 509 if( fileName.empty()) 510 { 511 this->skinFileName = ""; 514 512 return false; 515 513 } 516 514 517 this->skinFileName = new char[strlen(fileName)+1]; 518 strcpy(this->skinFileName, fileName); 515 this->skinFileName = fileName; 519 516 520 517 this->material.setName("md2ModelMaterial"); -
trunk/src/lib/graphics/importer/md2Model.h
r7123 r7221 189 189 { 190 190 public: 191 MD2Data(const char* modelFileName, const char*skinFileName, float scale = 1.0f);191 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 192 192 virtual ~MD2Data(); 193 193 194 194 private: 195 bool loadModel(const char*fileName);196 bool loadSkin(const char* fileName = NULL);195 bool loadModel(const std::string& fileName); 196 bool loadSkin(const std::string& fileName = ""); 197 197 198 198 public: … … 202 202 int numTexCoor; //!< number of texture coordinates 203 203 int numGLCommands; //!< number of gl commands in the glList (tells how to draw) 204 char*fileName; //!< file name of the model File205 char*skinFileName; //!< file name of the skin file204 std::string fileName; //!< file name of the model File 205 std::string skinFileName; //!< file name of the skin file 206 206 MD2Header* header; //!< the header file 207 207 … … 223 223 224 224 public: 225 MD2Model(const char* modelFileName, const char* skinFileName = NULL, float scale = 1.0f);225 MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 226 226 virtual ~MD2Model(); 227 227 -
trunk/src/lib/graphics/importer/media_container.cc
r7193 r7221 34 34 * Default constructor 35 35 */ 36 MediaContainer::MediaContainer(const char*filename)36 MediaContainer::MediaContainer(const std::string& filename) 37 37 { 38 38 // set the class id for the base object … … 41 41 fps = 0; 42 42 mediaLoaded = false; 43 44 this->loadMedia(filename);43 if (!filename.empty()) 44 this->loadMedia(filename); 45 45 } 46 46 … … 84 84 } 85 85 86 bool MediaContainer::loadMedia(const char*filename)86 bool MediaContainer::loadMedia(const std::string& filename) 87 87 { 88 88 this->unloadMedia(); 89 89 90 if(filename == NULL)90 if(filename.empty()) 91 91 return false; 92 92 // check whether file exists 93 93 if(!ResourceManager::isInDataDir(filename)) 94 94 { 95 PRINTF(1)("Could not find %s\n", filename );95 PRINTF(1)("Could not find %s\n", filename.c_str()); 96 96 return false; 97 97 } … … 101 101 102 102 // Open video file 103 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename) , NULL, 0, NULL) !=0 )104 { 105 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename) );103 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 ) 104 { 105 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str()); 106 106 return false; 107 107 } … … 110 110 if (av_find_stream_info(format_context) < 0) 111 111 { 112 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename) );112 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str()); 113 113 return false; 114 114 } … … 116 116 // Find the first video stream and take it 117 117 video_stream = av_find_default_stream_index(format_context); 118 118 119 119 if(video_stream == -1) 120 120 { 121 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename) );121 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str()); 122 122 return false; 123 123 } … … 202 202 // Free the packet that was allocated by av_read_frame 203 203 av_free_packet(&packet); 204 204 205 205 // Did we get a video frame? 206 206 if(frame_finished) … … 216 216 memcpy(&data[i*codec_context->width*3], 217 217 ((AVPicture*)RGB_frame)->data[0]+i * 218 ((AVPicture*)RGB_frame)->linesize[0], 218 ((AVPicture*)RGB_frame)->linesize[0], 219 219 codec_context->width*sizeof(uint8_t)*3); 220 220 … … 258 258 } 259 259 else 260 return NULL;261 } 260 return 0; 261 } -
trunk/src/lib/graphics/importer/media_container.h
r6981 r7221 44 44 public: 45 45 46 MediaContainer(const char* filename = NULL);46 MediaContainer(const std::string& filename = ""); 47 47 virtual ~MediaContainer(); 48 48 49 bool loadMedia(const char*filename);49 bool loadMedia(const std::string& filename); 50 50 void loadFrames(); 51 51 -
trunk/src/lib/graphics/importer/movie_player.cc
r7193 r7221 31 31 32 32 33 MoviePlayer::MoviePlayer(const char*filename)33 MoviePlayer::MoviePlayer(const std::string& filename) 34 34 { 35 35 // set the class id for the base object … … 42 42 mediaLoaded = false; 43 43 44 this->loadMovie(filename);45 44 if (!filename.empty()) 45 this->loadMovie(filename); 46 46 } 47 47 … … 83 83 84 84 85 bool MoviePlayer::loadMovie(const char*filename)85 bool MoviePlayer::loadMovie(const std::string& filename) 86 86 { 87 87 this->unloadMedia(); 88 88 89 if(filename == NULL)89 if(filename.empty()) 90 90 return false; 91 91 // check whether file exists 92 92 if(!ResourceManager::isInDataDir(filename)) 93 93 { 94 PRINTF(1)("Could not find %s\n", filename );94 PRINTF(1)("Could not find %s\n", filename.c_str()); 95 95 return false; 96 96 } … … 100 100 101 101 // Open video file 102 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename) , NULL, 0, NULL) !=0 )103 { 104 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename) );102 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 ) 103 { 104 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str()); 105 105 return false; 106 106 } … … 109 109 if (av_find_stream_info(format_context) < 0) 110 110 { 111 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename) );111 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str()); 112 112 return false; 113 113 } … … 118 118 if(video_stream == -1) 119 119 { 120 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename) );120 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str()); 121 121 return false; 122 122 } -
trunk/src/lib/graphics/importer/movie_player.h
r6981 r7221 58 58 public: 59 59 60 MoviePlayer(const char* filename = NULL);60 MoviePlayer(const std::string& filename = ""); 61 61 virtual ~MoviePlayer(); 62 62 63 bool loadMovie(const char*filename);63 bool loadMovie(const std::string& filename); 64 64 65 65 void start(float start_time); -
trunk/src/lib/graphics/importer/objModel.cc
r6162 r7221 32 32 * @param scaling The factor that the model will be scaled with. 33 33 */ 34 OBJModel::OBJModel(const char* fileName, float scaling) : StaticModel(fileName) 34 OBJModel::OBJModel(const std::string& fileName, float scaling) 35 : StaticModel(fileName) 35 36 { 36 37 this->setClassID(CL_OBJ_MODEL, "OBJModel"); … … 51 52 */ 52 53 OBJModel::~OBJModel() 53 { 54 PRINTF(4)("Deleting the obj-names\n"); 55 if (this->objPath) 56 delete []this->objPath; 57 } 54 { } 58 55 59 56 /** … … 63 60 Splits the FileName from the DirectoryName 64 61 */ 65 bool OBJModel::importFile (const char* fileName) 66 { 62 bool OBJModel::importFile (const std::string& fileNameInput) 63 { 64 const char* fileName = fileNameInput.c_str(); 67 65 PRINTF(4)("preparing to read in file: %s\n", fileName); 68 66 // splitting the … … 74 72 { 75 73 int len = split - fileName+1; 76 this->objPath = new char[len +2];77 strncpy(this->objPath, fileName, len);74 this->objPath = fileName; 75 this->objPath.erase(len, this->objPath.size()); 78 76 this->objPath[len] = '\0'; 79 77 PRINTF(4)("Resolved file %s to Path %s.\n", fileName, this->objPath); … … 91 89 This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks 92 90 */ 93 bool OBJModel::readFromObjFile(const char*fileName)91 bool OBJModel::readFromObjFile(const std::string& fileName) 94 92 { 95 93 FILE* stream; 96 if( (stream = fopen (fileName , "r")) == NULL)97 { 98 PRINTF(2)("Object File Could not be Opened %s\n", fileName );94 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 95 { 96 PRINTF(2)("Object File Could not be Opened %s\n", fileName.c_str()); 99 97 return false; 100 98 } … … 162 160 * that a material does not have to be able to read itself in from a File. 163 161 */ 164 bool OBJModel::readMtlLib (const char* mtlFile) 165 { 166 char* fileName = new char [strlen(this->objPath) + strlen(mtlFile)+1]; 167 sprintf(fileName, "%s%s", this->objPath, mtlFile); 162 bool OBJModel::readMtlLib (const std::string& mtlFile) 163 { 164 std::string fileName = this->objPath + mtlFile; 168 165 169 166 FILE* stream; 170 if( (stream = fopen (fileName, "r")) == NULL) 171 { 172 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName); 173 delete[] fileName; 167 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 168 { 169 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName.c_str()); 174 170 return false; 175 171 } … … 258 254 } 259 255 fclose(stream); 260 delete []fileName;261 256 return true; 262 257 } -
trunk/src/lib/graphics/importer/objModel.h
r6022 r7221 13 13 { 14 14 public: 15 OBJModel(const char*fileName, float scaling = 1.0);15 OBJModel(const std::string& fileName, float scaling = 1.0); 16 16 virtual ~OBJModel(); 17 17 18 18 private: 19 19 ///// readin ///// 20 bool importFile (const char*fileName);21 bool readFromObjFile (const char*fileName);22 bool readMtlLib (const char*matFile);20 bool importFile (const std::string& fileName); 21 bool readFromObjFile (const std::string& fileName); 22 bool readMtlLib (const std::string& matFile); 23 23 24 24 private: 25 char*objPath; //!< The Path where the obj and mtl-file are located.25 std::string objPath; //!< The Path where the obj and mtl-file are located. 26 26 }; 27 27 -
trunk/src/lib/graphics/importer/static_model.cc
r6423 r7221 23 23 #include <stdarg.h> 24 24 25 #include "vector.h"26 27 25 using namespace std; 28 26 … … 86 84 { 87 85 PRINTF(4)("Adding new Group\n"); 88 this->name = NULL;86 this->name = ""; 89 87 this->faceMode = -1; 90 88 this->faceCount = 0; … … 109 107 if (this->listNumber != 0) 110 108 glDeleteLists(this->listNumber, 1); 111 112 if (this->name != NULL)113 delete[] this->name;114 109 115 110 if (this->next !=NULL) … … 142 137 * assigns it a Name and a Type 143 138 */ 144 StaticModel::StaticModel(const char*modelName)139 StaticModel::StaticModel(const std::string& modelName) 145 140 { 146 141 this->setClassID(CL_STATIC_MODEL, "StaticModel"); … … 230 225 ModelGroup* tmpGroup = this->firstGroup; 231 226 while (tmpGroup != NULL) 232 233 234 235 236 227 { 228 PRINTF(5)("Drawing model %s\n", tmpGroup->name); 229 glCallList (tmpGroup->listNumber); 230 tmpGroup = tmpGroup->next; 231 } 237 232 } 238 233 … … 247 242 { 248 243 if (unlikely(groupNumber >= this->groupCount)) 249 250 251 252 244 { 245 PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount); 246 return; 247 } 253 248 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 254 249 ModelGroup* tmpGroup = this->firstGroup; 255 250 int counter = 0; 256 251 while (tmpGroup != NULL) 252 { 253 if (counter == groupNumber) 257 254 { 258 if (counter == groupNumber) 259 { 260 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name); 261 glCallList (tmpGroup->listNumber); 262 return; 263 } 264 ++counter; 265 tmpGroup = tmpGroup->next; 255 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name); 256 glCallList (tmpGroup->listNumber); 257 return; 266 258 } 259 ++counter; 260 tmpGroup = tmpGroup->next; 261 } 267 262 PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getName()); 268 263 return; … … 276 271 * It does this by just calling the List that must have been created earlier. 277 272 */ 278 void StaticModel::draw (char* groupName) const 279 { 280 if (groupName == NULL) 281 return; 273 void StaticModel::draw (const std::string& groupName) const 274 { 282 275 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 283 276 ModelGroup* tmpGroup = this->firstGroup; 284 277 while (tmpGroup != NULL) 278 { 279 if (tmpGroup->name == groupName) 285 280 { 286 if (tmpGroup->name != NULL && !strcmp(tmpGroup->name, groupName)) 287 { 288 PRINTF(4)("Drawing model %s\n", tmpGroup->name); 289 glCallList (tmpGroup->listNumber); 290 return; 291 } 292 tmpGroup = tmpGroup->next; 281 PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str()); 282 glCallList (tmpGroup->listNumber); 283 return; 293 284 } 294 PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->getName()); 285 tmpGroup = tmpGroup->next; 286 } 287 PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getName()); 295 288 return; 296 289 } … … 341 334 * @returns the added material 342 335 */ 343 Material* StaticModel::addMaterial(const char*materialName)336 Material* StaticModel::addMaterial(const std::string& materialName) 344 337 { 345 338 ModelMaterial* modMat = new ModelMaterial; … … 357 350 * @returns the Material if found, NULL otherwise 358 351 */ 359 Material* StaticModel::findMaterialByName(const char*materialName)352 Material* StaticModel::findMaterialByName(const std::string& materialName) 360 353 { 361 354 list<ModelMaterial*>::iterator modMat; 362 355 for (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++) 363 if ( !strcmp((*modMat)->material->getName(), materialName))356 if (materialName == (*modMat)->material->getName()) 364 357 return (*modMat)->material; 365 358 return NULL; … … 373 366 * With it you should be able to create Models with more than one SubModel inside 374 367 */ 375 bool StaticModel::addGroup(const char*groupString)368 bool StaticModel::addGroup(const std::string& groupString) 376 369 { 377 370 PRINTF(5)("Read Group: %s.\n", groupString); 378 371 if (this->groupCount != 0 && this->currentGroup->faceCount > 0) 379 380 381 382 372 { 373 // finalizeGroup(currentGroup); 374 this->currentGroup = this->currentGroup->next = new ModelGroup; 375 } 383 376 // setting the group name if not default. 384 if (strcmp(groupString, "default")) 385 { 386 this->currentGroup->name = new char [strlen(groupString)+1]; 387 strcpy(this->currentGroup->name, groupString); 388 } 377 if (groupString == "default") 378 { 379 this->currentGroup->name = groupString; 380 } 389 381 ++this->groupCount; 390 382 } … … 396 388 * If a vertex line is found this function will inject it into the vertex-Array 397 389 */ 398 bool StaticModel::addVertex (const char*vertexString)390 bool StaticModel::addVertex (const std::string& vertexString) 399 391 { 400 392 float subbuffer1; 401 393 float subbuffer2; 402 394 float subbuffer3; 403 sscanf (vertexString , "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);395 sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 404 396 this->vertices.push_back(subbuffer1*scaleFactor); 405 397 this->vertices.push_back(subbuffer2*scaleFactor); … … 431 423 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 432 424 */ 433 bool StaticModel::addVertexNormal (const char*normalString)425 bool StaticModel::addVertexNormal (const std::string& normalString) 434 426 { 435 427 float subbuffer1; 436 428 float subbuffer2; 437 429 float subbuffer3; 438 sscanf (normalString , "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);430 sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 439 431 this->normals.push_back(subbuffer1); 440 432 this->normals.push_back(subbuffer2); … … 471 463 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 472 464 */ 473 bool StaticModel::addVertexTexture (const char*vTextureString)465 bool StaticModel::addVertexTexture (const std::string& vTextureString) 474 466 { 475 467 float subbuffer1; 476 468 float subbuffer2; 477 sscanf (vTextureString , "%f %f", &subbuffer1, &subbuffer2);469 sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2); 478 470 this->vTexture.push_back(subbuffer1); 479 471 this->vTexture.push_back(1 - subbuffer2); … … 507 499 * String is different from the argument addFace, 508 500 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0 509 */ 510 bool StaticModel::addFace (const char* faceString) 511 { 501 * 502 * @TODO make it std::string conform 503 */ 504 bool StaticModel::addFace (const std::string& faceStringInput) 505 { 506 const char* faceString = faceStringInput.c_str(); 512 507 if (this->currentGroup->faceCount >0) 513 508 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; … … 516 511 tmpElem->next = NULL; 517 512 while(strcmp (faceString, "\0")) 513 { 514 if (this->currentGroup->currentFace->vertexCount>0) 515 tmpElem = tmpElem->next = new ModelFaceElement; 516 tmpElem->next = NULL; 517 518 char tmpValue [50]; 519 int tmpLen; 520 char* vertex = NULL; 521 char* texture = NULL; 522 char* normal = NULL; 523 524 sscanf (faceString, "%s", tmpValue); 525 tmpLen = strlen(tmpValue); 526 vertex = tmpValue; 527 528 if ((texture = strstr (vertex, "/")) != NULL) 518 529 { 519 if (this->currentGroup->currentFace->vertexCount>0) 520 tmpElem = tmpElem->next = new ModelFaceElement; 521 tmpElem->next = NULL; 522 523 char tmpValue [50]; 524 int tmpLen; 525 char* vertex = NULL; 526 char* texture = NULL; 527 char* normal = NULL; 528 529 sscanf (faceString, "%s", tmpValue); 530 tmpLen = strlen(tmpValue); 531 vertex = tmpValue; 532 533 if ((texture = strstr (vertex, "/")) != NULL) 534 { 535 texture[0] = '\0'; 536 texture ++; 537 538 if ((normal = strstr (texture, "/")) !=NULL) 539 { 540 normal[0] = '\0'; 541 normal ++; 542 } 543 } 544 if (vertex) 545 tmpElem->vertexNumber = atoi(vertex)-1; 546 if (texture) 547 tmpElem->texCoordNumber = atoi(texture)-1; 548 if (normal) 549 tmpElem->normalNumber = atoi(normal)-1; 550 551 faceString += tmpLen; 552 if (strcmp (faceString, "\0")) 553 faceString++; 554 this->currentGroup->currentFace->vertexCount++; 530 texture[0] = '\0'; 531 texture ++; 532 533 if ((normal = strstr (texture, "/")) !=NULL) 534 { 535 normal[0] = '\0'; 536 normal ++; 537 } 555 538 } 539 if (vertex) 540 tmpElem->vertexNumber = atoi(vertex)-1; 541 if (texture) 542 tmpElem->texCoordNumber = atoi(texture)-1; 543 if (normal) 544 tmpElem->normalNumber = atoi(normal)-1; 545 546 faceString += tmpLen; 547 if (strcmp (faceString, "\0")) 548 faceString++; 549 this->currentGroup->currentFace->vertexCount++; 550 } 556 551 557 552 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; … … 575 570 576 571 for (int i = 0; i < faceElemCount; i++) 577 578 579 580 581 582 583 584 585 586 587 572 { 573 if (this->currentGroup->currentFace->vertexCount > 0) 574 tmpElem = tmpElem->next = new ModelFaceElement; 575 576 tmpElem->vertexNumber = va_arg (itemlist, int); 577 if (type & TEXCOORD) 578 tmpElem->texCoordNumber = va_arg (itemlist, int); 579 if (type & NORMAL) 580 tmpElem->normalNumber = va_arg(itemlist, int); 581 this->currentGroup->currentFace->vertexCount++; 582 } 588 583 va_end(itemlist); 589 584 … … 596 591 * @param matString the Material that will be set. 597 592 */ 598 bool StaticModel::setMaterial(const char*matString)593 bool StaticModel::setMaterial(const std::string& matString) 599 594 { 600 595 if (this->currentGroup->faceCount > 0) … … 647 642 ModelGroup* tmpGroup = firstGroup; 648 643 while (tmpGroup != NULL) 644 { 645 ModelFace* tmpFace = tmpGroup->firstFace; 646 while (tmpFace != NULL) 649 647 { 650 ModelFace* tmpFace = tmpGroup->firstFace; 651 while (tmpFace != NULL) 648 if (tmpFace->firstElem != NULL) 649 { 650 ModelFaceElement* firstElem = tmpFace->firstElem; 651 ModelFaceElement* prevElem; 652 ModelFaceElement* curElem = firstElem; 653 ModelFaceElement* nextElem; 654 ModelFaceElement* lastElem; 655 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 656 while (curElem != NULL) 652 657 { 653 if (tmpFace->firstElem != NULL) 654 { 655 ModelFaceElement* firstElem = tmpFace->firstElem; 656 ModelFaceElement* prevElem; 657 ModelFaceElement* curElem = firstElem; 658 ModelFaceElement* nextElem; 659 ModelFaceElement* lastElem; 660 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 661 while (curElem != NULL) 662 { 663 prevElem = curElem; 664 curElem = curElem->next; 665 } 666 lastElem = prevElem; 667 668 curElem = firstElem; 669 for (int j=0; j<tmpFace->vertexCount; j++) 670 { 671 if (!(nextElem = curElem->next)) 672 nextElem = firstElem; 673 curElem->normalNumber = curElem->vertexNumber; 674 675 curV = Vector (this->vertices[curElem->vertexNumber*3], 676 this->vertices[curElem->vertexNumber*3+1], 677 this->vertices[curElem->vertexNumber*3+2]); 678 679 prevV = Vector (this->vertices[prevElem->vertexNumber*3], 680 this->vertices[prevElem->vertexNumber*3+1], 681 this->vertices[prevElem->vertexNumber*3+2]) - curV; 682 683 nextV = Vector (this->vertices[nextElem->vertexNumber*3], 684 this->vertices[nextElem->vertexNumber*3+1], 685 this->vertices[nextElem->vertexNumber*3+2]) - curV; 686 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 687 688 prevElem = curElem; 689 curElem = curElem->next; 690 } 691 } 692 tmpFace = tmpFace->next; 658 prevElem = curElem; 659 curElem = curElem->next; 693 660 } 694 tmpGroup = tmpGroup->next; 661 lastElem = prevElem; 662 663 curElem = firstElem; 664 for (int j=0; j<tmpFace->vertexCount; j++) 665 { 666 if (!(nextElem = curElem->next)) 667 nextElem = firstElem; 668 curElem->normalNumber = curElem->vertexNumber; 669 670 curV = Vector (this->vertices[curElem->vertexNumber*3], 671 this->vertices[curElem->vertexNumber*3+1], 672 this->vertices[curElem->vertexNumber*3+2]); 673 674 prevV = Vector (this->vertices[prevElem->vertexNumber*3], 675 this->vertices[prevElem->vertexNumber*3+1], 676 this->vertices[prevElem->vertexNumber*3+2]) - curV; 677 678 nextV = Vector (this->vertices[nextElem->vertexNumber*3], 679 this->vertices[nextElem->vertexNumber*3+1], 680 this->vertices[nextElem->vertexNumber*3+2]) - curV; 681 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 682 683 prevElem = curElem; 684 curElem = curElem->next; 685 } 686 } 687 tmpFace = tmpFace->next; 695 688 } 689 tmpGroup = tmpGroup->next; 690 } 696 691 697 692 for (int i=0; i < this->vertices.size()/3;i++) 698 699 700 701 702 703 704 693 { 694 normArray[i].normalize(); 695 PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 696 697 this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z); 698 699 } 705 700 delete[] normArray; 706 701 } … … 721 716 722 717 while (this->currentGroup != NULL) 718 { 719 720 // creating a glList for the Group 721 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 723 722 { 724 725 // creating a glList for the Group 726 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 723 PRINTF(2)("glList could not be created for this Model\n"); 724 return false; 725 } 726 glNewList (this->currentGroup->listNumber, GL_COMPILE); 727 728 // Putting Faces to GL 729 ModelFace* tmpFace = this->currentGroup->firstFace; 730 while (tmpFace != NULL) 731 { 732 if (tmpFace->vertexCount == 0 && tmpFace->material != NULL) 733 { 734 if (this->currentGroup->faceMode != -1) 735 glEnd(); 736 this->currentGroup->faceMode = 0; 737 Material* tmpMat; 738 if (tmpFace->material != NULL) 727 739 { 728 PRINTF(2)("glList could not be created for this Model\n");729 return false;740 tmpFace->material->select(); 741 PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName()); 730 742 } 731 glNewList (this->currentGroup->listNumber, GL_COMPILE);732 733 // Putting Faces to GL734 ModelFace* tmpFace = this->currentGroup->firstFace;735 while (tmpFace != NULL)743 } 744 745 else if (tmpFace->vertexCount == 3) 746 { 747 if (this->currentGroup->faceMode != 3) 736 748 { 737 if (tmpFace->vertexCount == 0 && tmpFace->material != NULL) 738 { 739 if (this->currentGroup->faceMode != -1) 740 glEnd(); 741 this->currentGroup->faceMode = 0; 742 Material* tmpMat; 743 if (tmpFace->material != NULL) 744 { 745 tmpFace->material->select(); 746 PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName()); 747 } 748 } 749 750 else if (tmpFace->vertexCount == 3) 751 { 752 if (this->currentGroup->faceMode != 3) 753 { 754 if (this->currentGroup->faceMode != -1) 755 glEnd(); 756 glBegin(GL_TRIANGLES); 757 } 758 759 this->currentGroup->faceMode = 3; 760 PRINTF(5)("found triag.\n"); 761 } 762 763 else if (tmpFace->vertexCount == 4) 764 { 765 if (this->currentGroup->faceMode != 4) 766 { 767 if (this->currentGroup->faceMode != -1) 768 glEnd(); 769 glBegin(GL_QUADS); 770 } 771 this->currentGroup->faceMode = 4; 772 PRINTF(5)("found quad.\n"); 773 } 774 775 else if (tmpFace->vertexCount > 4) 776 { 777 if (this->currentGroup->faceMode != -1) 778 glEnd(); 779 glBegin(GL_POLYGON); 780 PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount); 781 this->currentGroup->faceMode = tmpFace->vertexCount; 782 } 783 784 ModelFaceElement* tmpElem = tmpFace->firstElem; 785 while (tmpElem != NULL) 786 { 787 // PRINTF(2)("%s\n", tmpElem->value); 788 this->addGLElement(tmpElem); 789 tmpElem = tmpElem->next; 790 } 791 tmpFace = tmpFace->next; 749 if (this->currentGroup->faceMode != -1) 750 glEnd(); 751 glBegin(GL_TRIANGLES); 792 752 } 793 glEnd(); 794 glEndList(); 795 796 this->currentGroup = this->currentGroup->next; 753 754 this->currentGroup->faceMode = 3; 755 PRINTF(5)("found triag.\n"); 756 } 757 758 else if (tmpFace->vertexCount == 4) 759 { 760 if (this->currentGroup->faceMode != 4) 761 { 762 if (this->currentGroup->faceMode != -1) 763 glEnd(); 764 glBegin(GL_QUADS); 765 } 766 this->currentGroup->faceMode = 4; 767 PRINTF(5)("found quad.\n"); 768 } 769 770 else if (tmpFace->vertexCount > 4) 771 { 772 if (this->currentGroup->faceMode != -1) 773 glEnd(); 774 glBegin(GL_POLYGON); 775 PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount); 776 this->currentGroup->faceMode = tmpFace->vertexCount; 777 } 778 779 ModelFaceElement* tmpElem = tmpFace->firstElem; 780 while (tmpElem != NULL) 781 { 782 // PRINTF(2)("%s\n", tmpElem->value); 783 this->addGLElement(tmpElem); 784 tmpElem = tmpElem->next; 785 } 786 tmpFace = tmpFace->next; 797 787 } 788 glEnd(); 789 glEndList(); 790 791 this->currentGroup = this->currentGroup->next; 792 } 798 793 } 799 794 … … 814 809 ModelFace* tmpFace; //!< the temporary face referece 815 810 811 bool warned = false; 812 816 813 /* count the number of triangles */ 817 814 /* now iterate through all groups and build up the triangle list */ … … 834 831 else if( tmpFace->vertexCount > 4) 835 832 { 836 PRINTF(1)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName()); 837 //exit(0); 833 if (!warned) 834 { 835 PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName()); 836 warned = true; 837 } 838 //exit(0); 838 839 } 839 840 tmpFace = tmpFace->next; … … 858 859 while( this->currentGroup != NULL) 859 860 { 860 861 // Putting Faces to GL 861 862 tmpFace = this->currentGroup->firstFace; 862 863 while( tmpFace != NULL) … … 931 932 932 933 if (elem->texCoordNumber != -1) 933 934 935 936 937 938 939 934 { 935 if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor)) 936 glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2); 937 else 938 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n", 939 elem->texCoordNumber, this->pModelInfo.numTexCoor); 940 } 940 941 if (elem->normalNumber != -1) 941 942 { 942 943 if (likely(elem->normalNumber < this->pModelInfo.numNormals)) 943 944 glNormal3fv(&this->normals[0] + elem->normalNumber * 3); 944 945 else 945 946 947 946 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete", 947 elem->normalNumber, this->pModelInfo.numNormals); 948 } 948 949 if (elem->vertexNumber != -1) 949 950 951 952 953 954 955 950 { 951 if (likely(elem->vertexNumber < this->pModelInfo.numVertices)) 952 glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3); 953 else 954 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete", 955 elem->vertexNumber, this->pModelInfo.numVertices); 956 } 956 957 957 958 } -
trunk/src/lib/graphics/importer/static_model.h
r6423 r7221 13 13 #include <vector> 14 14 #include <list> 15 16 // FORWARD DECLARATION //17 template<class T> class tArray;18 15 19 16 // definition of different modes for setting up Faces … … 70 67 void cleanup(); 71 68 72 char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char*name) function.69 std::string name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function. 73 70 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 74 71 GLuint listNumber; //!< The number of the GL-List this Group gets. … … 98 95 { 99 96 public: 100 StaticModel(const char* modelName = NULL);97 StaticModel(const std::string& modelName = ""); 101 98 virtual ~StaticModel(); 102 99 103 100 virtual void draw() const; 104 101 void draw(int groupNumber) const; 105 void draw(c har*groupName) const;102 void draw(const std::string& groupName) const; 106 103 107 104 void rebuild(); 108 105 109 106 Material* addMaterial(Material* material); 110 Material* addMaterial(const char*materialName);107 Material* addMaterial(const std::string& materialName); 111 108 112 bool addGroup(const char*groupString);109 bool addGroup(const std::string& groupString); 113 110 114 bool addVertex(const char*vertexString);111 bool addVertex(const std::string& vertexString); 115 112 bool addVertex(float x, float y, float z); 116 113 117 bool addFace(const char*faceString);114 bool addFace(const std::string& faceString); 118 115 bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); 119 116 120 bool addVertexNormal(const char*normalString);117 bool addVertexNormal(const std::string& normalString); 121 118 bool addVertexNormal(float x, float y, float z); 122 119 123 bool addVertexTexture(const char*vTextureString);120 bool addVertexTexture(const std::string& vTextureString); 124 121 bool addVertexTexture(float u, float v); 125 122 126 bool setMaterial(const char*mtlString);123 bool setMaterial(const std::string& mtlString); 127 124 bool setMaterial(Material* mtl); 128 125 … … 133 130 void cubeModel(); 134 131 135 Material* findMaterialByName(const char*materialName);132 Material* findMaterialByName(const std::string& materialName); 136 133 137 134 protected: -
trunk/src/lib/graphics/importer/texture.cc
r6871 r7221 32 32 * Constructor for a Texture 33 33 */ 34 Texture::Texture(const char*imageName, GLenum target)34 Texture::Texture(const std::string& imageName, GLenum target) 35 35 { 36 36 this->setClassID(CL_TEXTURE, "Texture"); … … 41 41 this->priority = 0.5; 42 42 43 if ( imageName != NULL)43 if (!imageName.empty()) 44 44 { 45 45 this->setName(imageName); … … 67 67 * @param imageName The image to load 68 68 */ 69 bool Texture::loadImage(const char*imageName, GLenum target)69 bool Texture::loadImage(const std::string& imageName, GLenum target) 70 70 { 71 71 if (Texture::texturesEnabled) … … 81 81 this->texture = 0; 82 82 } 83 if ( imageName != NULL)83 if (!imageName.empty()) 84 84 { 85 85 SDL_Surface* tmpSurf; … … 87 87 glDeleteTextures(1, &this->texture); 88 88 // load the new Image to memory 89 tmpSurf = IMG_Load(imageName );89 tmpSurf = IMG_Load(imageName.c_str()); 90 90 if(tmpSurf != NULL) 91 91 { -
trunk/src/lib/graphics/importer/texture.h
r6981 r7221 18 18 { 19 19 public: 20 Texture(const char* imageName = NULL, GLenum target = GL_TEXTURE_2D);20 Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D); 21 21 // Texture(TEXTURE_TYPE type, int resolution); 22 22 virtual ~Texture(); 23 23 24 bool loadImage(const char*imageName, GLenum target = GL_TEXTURE_2D);24 bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 25 25 virtual bool rebuild(); 26 26 -
trunk/src/lib/graphics/importer/texture_sequence.cc
r6624 r7221 124 124 * @returns true on success 125 125 */ 126 bool TextureSequence::addFrame(const char*imageName)126 bool TextureSequence::addFrame(const std::string& imageName) 127 127 { 128 if (imageName == NULL) 129 return false; 130 131 SDL_Surface* addSurface = IMG_Load(imageName); 128 SDL_Surface* addSurface = IMG_Load(imageName.c_str()); 132 129 bool success = this->addFrame(addSurface); 133 130 delete addSurface; -
trunk/src/lib/graphics/importer/texture_sequence.h
r7195 r7221 23 23 bool loadImageSeries(unsigned int count, ...); 24 24 bool loadImageSeries(unsigned int count, va_list textureNames); 25 bool addFrame(const char*image);25 bool addFrame(const std::string& image); 26 26 bool addFrame(SDL_Surface* surface); 27 27 bool addFrame(GLuint texture); -
trunk/src/lib/graphics/render2D/billboard.cc
r7193 r7221 78 78 void Billboard::loadParams(const TiXmlElement* root) 79 79 { 80 LoadParam(root, "texture", this , Billboard, setTexture)80 LoadParam(root, "texture", this->material, Material, setDiffuseMap) 81 81 .describe("the texture-file to load onto the Billboard"); 82 82 … … 100 100 * @param textureFile The texture-file to load onto the crosshair 101 101 */ 102 void Billboard::setTexture(const char*textureFile)102 void Billboard::setTexture(const std::string& textureFile) 103 103 { 104 104 this->material->setDiffuseMap(textureFile); -
trunk/src/lib/graphics/render2D/billboard.h
r6815 r7221 30 30 31 31 void setSize(float sizeX, float sizeY); 32 void setTexture(const char*textureFile);32 void setTexture(const std::string& textureFile); 33 33 void attachTo(PNode* pnode); 34 34 -
trunk/src/lib/graphics/render2D/element_2d.cc
r7199 r7221 180 180 * @param alignment the alignment @see loadParams 181 181 */ 182 void Element2D::setAlignment(const char*alignment)183 { 184 if ( !strcmp(alignment, "center"))182 void Element2D::setAlignment(const std::string& alignment) 183 { 184 if (alignment == "center") 185 185 this->setAlignment(E2D_ALIGN_CENTER); 186 else if ( !strcmp(alignment, "left"))186 else if (alignment == "left") 187 187 this->setAlignment(E2D_ALIGN_LEFT); 188 else if ( !strcmp(alignment, "right"))188 else if (alignment == "right") 189 189 this->setAlignment(E2D_ALIGN_RIGHT); 190 else if ( !strcmp(alignment, "screen-center"))190 else if (alignment == "screen-center") 191 191 this->setAlignment(E2D_ALIGN_SCREEN_CENTER); 192 192 } … … 213 213 /** 214 214 * sets the layer onto which this 2D-element is projected to. 215 * @param layer the layer @see loadParams @see Element2D::charToLayer2D(const char*layer)216 */ 217 void Element2D::setLayer(const char*layer)215 * @param layer the layer @see loadParams @see Element2D::charToLayer2D(const std::string& layer) 216 */ 217 void Element2D::setLayer(const std::string& layer) 218 218 { 219 219 this->setLayer(Element2D::charToLayer2D(layer)); … … 235 235 * @param bindNode the name of the Node (should be existing) 236 236 */ 237 void Element2D::setBindNode(const char*bindNode)237 void Element2D::setBindNode(const std::string& bindNode) 238 238 { 239 239 const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE)); … … 572 572 * @param childName the name of the child to add to this PNode 573 573 */ 574 void Element2D::addChild2D (const char*childName)574 void Element2D::addChild2D (const std::string& childName) 575 575 { 576 576 Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D)); … … 651 651 * @param parentName the name of the Parent to set to this Element2D 652 652 */ 653 void Element2D::setParent2D (const char*parentName)653 void Element2D::setParent2D (const std::string& parentName) 654 654 { 655 655 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D)); … … 658 658 else 659 659 PRINTF(2)("Not Found Element2D's (%s::%s) new Parent by Name: %s\n", 660 this->getClassName(), this->getName(), parentName );660 this->getClassName(), this->getName(), parentName.c_str()); 661 661 } 662 662 … … 704 704 * @param bias the speed to iterate to this new Positions 705 705 */ 706 void Element2D::setParentSoft2D(const char*parentName, float bias)706 void Element2D::setParentSoft2D(const std::string& parentName, float bias) 707 707 { 708 708 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D)); … … 724 724 * @param parentMode a String representing this parentingMode 725 725 */ 726 void Element2D::setParentMode2D (const char*parentingMode)727 { 728 this->setParentMode2D(Element2D:: charToParentingMode2D(parentingMode));726 void Element2D::setParentMode2D (const std::string& parentingMode) 727 { 728 this->setParentMode2D(Element2D::stringToParentingMode2D(parentingMode)); 729 729 } 730 730 … … 952 952 this->relCoordinate.y, 953 953 this->getAbsDir2D(), 954 Element2D::parentingModeTo Char2D(parentMode),954 Element2D::parentingModeToString2D(parentMode), 955 955 Element2D::layer2DToChar(this->layer)); 956 956 … … 1074 1074 * @return the converted string 1075 1075 */ 1076 const char* Element2D::parentingModeTo Char2D(int parentingMode)1076 const char* Element2D::parentingModeToString2D(int parentingMode) 1077 1077 { 1078 1078 if (parentingMode == E2D_PARENT_LOCAL_ROTATE) … … 1093 1093 * @return the int corresponding to the named parentingMode 1094 1094 */ 1095 E2D_PARENT_MODE Element2D:: charToParentingMode2D(const char*parentingMode)1096 { 1097 if ( !strcmp(parentingMode, "local-rotate"))1095 E2D_PARENT_MODE Element2D::stringToParentingMode2D(const std::string& parentingMode) 1096 { 1097 if (parentingMode == "local-rotate") 1098 1098 return (E2D_PARENT_LOCAL_ROTATE); 1099 else if ( !strcmp(parentingMode, "rotate-movement"))1099 else if (parentingMode == "rotate-movement") 1100 1100 return (E2D_PARENT_ROTATE_MOVEMENT); 1101 else if ( !strcmp(parentingMode, "movement"))1101 else if (parentingMode == "movement") 1102 1102 return (E2D_PARENT_MOVEMENT); 1103 else if ( !strcmp(parentingMode, "all"))1103 else if (parentingMode == "all") 1104 1104 return (E2D_PARENT_ALL); 1105 else if ( !strcmp(parentingMode, "rotate-and-move"))1105 else if (parentingMode == "rotate-and-move") 1106 1106 return (E2D_PARENT_ROTATE_AND_MOVE); 1107 1107 } … … 1139 1139 * @returns the E2D_LAYER on success, E2D_DEFAULT_LAYER on error. 1140 1140 */ 1141 E2D_LAYER Element2D::charToLayer2D(const char*layer)1142 { 1143 if ( !strcmp(layer, "top"))1141 E2D_LAYER Element2D::charToLayer2D(const std::string& layer) 1142 { 1143 if (layer =="top") 1144 1144 return (E2D_LAYER_TOP); 1145 else if ( !strcmp(layer, "medium"))1145 else if (layer == "medium") 1146 1146 return (E2D_LAYER_MEDIUM); 1147 else if ( !strcmp(layer, "bottom"))1147 else if (layer == "bottom") 1148 1148 return (E2D_LAYER_BOTTOM); 1149 else if ( !strcmp(layer, "below-all"))1149 else if (layer == "below-all") 1150 1150 return (E2D_LAYER_BELOW_ALL); 1151 1151 else -
trunk/src/lib/graphics/render2D/element_2d.h
r7052 r7221 102 102 /** @param alignment the new Alignment of the 2D-Element */ 103 103 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 104 void setAlignment(const char*alignment);104 void setAlignment(const std::string& alignment); 105 105 inline E2D_ALIGNMENT getAlignment() const { return this->alignment; }; 106 106 107 107 // LAYERING // 108 108 void setLayer(E2D_LAYER layer); 109 void setLayer(const char*layer);109 void setLayer(const std::string& layer); 110 110 /** @returns the Layer this Element is drawn to */ 111 111 inline E2D_LAYER getLayer() const { return this->layer; }; … … 121 121 /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ 122 122 inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; }; 123 void setBindNode(const char*bindNode);123 void setBindNode(const std::string& bindNode); 124 124 inline const PNode* getBindNode() const { return this->bindNode; }; 125 125 … … 181 181 182 182 void addChild2D (Element2D* child); 183 void addChild2D (const char*childName);183 void addChild2D (const std::string& childName); 184 184 void removeChild2D (Element2D* child); 185 185 void remove2D(); … … 187 187 /** @param parent the new parent of this Element2D */ 188 188 void setParent2D (Element2D* parent) { parent->addChild2D(this); }; 189 void setParent2D (const char*parentName);189 void setParent2D (const std::string& parentName); 190 190 /** @returns the parent of this Element2D */ 191 191 inline Element2D* getParent2D () const { return this->parent; }; … … 194 194 195 195 void setParentSoft2D(Element2D* parentNode, float bias = 1.0); 196 void setParentSoft2D(const char*parentName, float bias = 1.0);196 void setParentSoft2D(const std::string& parentName, float bias = 1.0); 197 197 198 198 void setParentMode2D (E2D_PARENT_MODE parentMode); 199 void setParentMode2D (const char*parentingMode);199 void setParentMode2D (const std::string& parentingMode); 200 200 /** @returns the Parenting mode of this node */ 201 201 int getParentMode2D() const { return this->parentMode; }; … … 212 212 213 213 // helper functions // 214 static const char* parentingModeTo Char2D(int parentingMode);215 static E2D_PARENT_MODE charToParentingMode2D(const char*parentingMode);214 static const char* parentingModeToString2D(int parentingMode); 215 static E2D_PARENT_MODE stringToParentingMode2D(const std::string& parentingMode); 216 216 217 217 static const char* layer2DToChar(E2D_LAYER layer); 218 static E2D_LAYER charToLayer2D(const char*layer);218 static E2D_LAYER charToLayer2D(const std::string& layer); 219 219 220 220 private: -
trunk/src/lib/graphics/shader.cc
r7193 r7221 36 36 * standard constructor 37 37 */ 38 Shader::Shader (const char* vertexShaderFile, const char*fragmentShaderFile)38 Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 39 39 { 40 40 this->setClassID(CL_SHADER, "Shader"); 41 41 42 this->fragmentShaderFile = NULL;43 this->vertexShaderFile = NULL;42 this->fragmentShaderFile = ""; 43 this->vertexShaderFile = ""; 44 44 this->shaderProgram = 0; 45 45 this->vertexShader = 0; … … 52 52 this->shaderProgram = glCreateProgramObjectARB(); 53 53 54 if ( vertexShaderFile != NULL)54 if (!vertexShaderFile.empty()) 55 55 this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile); 56 if ( fragmentShaderFile != NULL)56 if (!fragmentShaderFile.empty()) 57 57 this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile); 58 58 glLinkProgramARB(this->shaderProgram); … … 103 103 } 104 104 105 Shader* Shader::getShader(const char* vertexShaderFile, const char*fragmentShaderFile)105 Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 106 106 { 107 107 return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER, RP_LEVEL, fragmentShaderFile); … … 116 116 117 117 118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const char*fileName)118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const std::string& fileName) 119 119 { 120 120 GLhandleARB shader = 0; … … 129 129 if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader) 130 130 { 131 this->vertexShaderFile = new char[strlen(fileName)+1]; 132 strcpy(this->vertexShaderFile, fileName); 131 this->vertexShaderFile = fileName; 133 132 134 133 shader = this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); … … 137 136 if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader) 138 137 { 139 this->fragmentShaderFile = new char[strlen(fileName)+1]; 140 strcpy(this->fragmentShaderFile, fileName); 138 this->fragmentShaderFile = fileName; 141 139 142 140 shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); … … 146 144 { 147 145 GLint status = 0; 148 glShaderSourceARB(shader, program->size(), (const char**)&(*program)[0], NULL); 146 /// FIXME do it back 147 // glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL); 149 148 glCompileShaderARB(shader); 150 149 // checking on error. … … 160 159 } 161 160 162 char* Shader::fileRead(const char*fileName)161 char* Shader::fileRead(const std::string& fileName) 163 162 { 164 163 FILE* fileHandle; … … 167 166 int count = 0; 168 167 169 if (fileName == NULL)168 if (fileName.empty()) 170 169 return NULL; 171 170 172 fileHandle = fopen(fileName , "rt");171 fileHandle = fopen(fileName.c_str(), "rt"); 173 172 174 173 if (fileHandle == NULL) … … 187 186 188 187 189 std::vector<char*>* Shader::fileReadArray(const char*fileName)188 std::vector<char*>* Shader::fileReadArray(const std::string& fileName) 190 189 { 191 190 FILE* stream; //< The stream we use to read the file. 192 191 193 if( (stream = fopen (fileName , "rt")) == NULL)194 { 195 PRINTF(1)("Shader could not open %s\n", fileName );192 if( (stream = fopen (fileName.c_str(), "rt")) == NULL) 193 { 194 PRINTF(1)("Shader could not open %s\n", fileName.c_str()); 196 195 return NULL; 197 196 } … … 234 233 if (type == SHADER_VERTEX && this->vertexShader != 0) 235 234 { 236 delete[] this->vertexShaderFile; 237 this->vertexShaderFile = NULL; 235 this->vertexShaderFile = ""; 238 236 glDetachObjectARB(this->shaderProgram, this->vertexShader); 239 237 glDeleteObjectARB(this->vertexShader); … … 245 243 else if (type == SHADER_FRAGMENT && this->fragmentShader != 0) 246 244 { 247 delete[] this->fragmentShaderFile; 248 this->fragmentShaderFile = NULL; 245 this->fragmentShaderFile = ""; 249 246 glDetachObjectARB(this->shaderProgram, this->fragmentShader); 250 247 glDeleteObjectARB(this->fragmentShader); -
trunk/src/lib/graphics/shader.h
r7195 r7221 27 27 28 28 public: 29 Shader(const char* vertexShaderFile = NULL, const char* fragmentShaderFile = NULL);29 Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); 30 30 virtual ~Shader(); 31 static Shader* getShader(const char* vertexShaderFile, const char*fragmentShaderFile);31 static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile); 32 32 static bool unload(Shader* shader); 33 33 34 bool loadShaderProgramm(SHADER_TYPE type, const char*fileName);34 bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName); 35 35 void activateShader(); 36 36 static void deactivateShader(); 37 37 void deleteProgram(SHADER_TYPE type); 38 38 39 char* fileRead(const char*fileName);40 std::vector<char*>* fileReadArray(const char*fileName);39 char* fileRead(const std::string& fileName); 40 std::vector<char*>* fileReadArray(const std::string& fileName); 41 41 42 42 static bool checkShaderAbility(); … … 54 54 55 55 private: 56 char*fragmentShaderFile;57 char*vertexShaderFile;56 std::string fragmentShaderFile; 57 std::string vertexShaderFile; 58 58 GLhandleARB shaderProgram; 59 59 GLhandleARB vertexShader; -
trunk/src/lib/graphics/text_engine/font.cc
r6609 r7221 37 37 * @param fontSize the Size of the Font in Pixels 38 38 */ 39 Font::Font(const char*fontFile, unsigned int renderSize)39 Font::Font(const std::string& fontFile, unsigned int renderSize) 40 40 { 41 41 this->init(); … … 44 44 this->setStyle("c"); 45 45 46 if ( fontFile != NULL)46 if (!fontFile.empty()) 47 47 this->loadFontFromTTF(fontFile); 48 48 } … … 52 52 * @param imageFile the ImageFile to load the Font From. 53 53 */ 54 Font::Font(const char*imageFile)54 Font::Font(const std::string& imageFile) 55 55 { 56 56 this->init(); … … 58 58 // this->setSize(fontSize); 59 59 SDL_Surface* image = NULL; 60 if ( imageFile != NULL)61 image = IMG_Load(imageFile );60 if (!imageFile.empty()) 61 image = IMG_Load(imageFile.c_str()); 62 62 else 63 63 return; … … 68 68 } 69 69 else 70 PRINTF(1)("loading from surface %s failed: %s\n", imageFile , IMG_GetError());70 PRINTF(1)("loading from surface %s failed: %s\n", imageFile.c_str(), IMG_GetError()); 71 71 } 72 72 … … 114 114 115 115 //! @todo check if we really do not need to delete the fastTextureID here. 116 // if (this->fastTextureID != 0)117 // if(glIsTexture(this->fastTextureID))118 // glDeleteTextures(1, &this->fastTextureID);116 // if (this->fastTextureID != 0) 117 // if(glIsTexture(this->fastTextureID)) 118 // glDeleteTextures(1, &this->fastTextureID); 119 119 120 120 // erease this font out of the memory. … … 140 140 * @returns true if loaded, false if something went wrong, or if a font was loaded before. 141 141 */ 142 bool Font::loadFontFromTTF(const char*fontFile)142 bool Font::loadFontFromTTF(const std::string& fontFile) 143 143 { 144 144 // checking for existent Font. … … 222 222 * i: italic, b: bold, u, underline 223 223 */ 224 void Font::setStyle(const char*renderStyle)224 void Font::setStyle(const std::string& renderStyle) 225 225 { 226 226 this->renderStyle = TTF_STYLE_NORMAL; 227 227 228 for (int i = 0; i < strlen(renderStyle); i++) 229 if (strncmp(renderStyle+i, "b", 1) == 0) 228 for (int i = 0; i < renderStyle.size(); i++) 229 { 230 if (renderStyle[i] == 'b') 230 231 this->renderStyle |= TTF_STYLE_BOLD; 231 else if (strncmp(renderStyle+i, "i", 1) == 0)232 this->renderStyle |= TTF_STYLE_ITALIC;233 else if (strncmp(renderStyle+i, "u", 1) == 0)234 this->renderStyle |= TTF_STYLE_UNDERLINE;235 232 else if (renderStyle[i] == 'i') 233 this->renderStyle |= TTF_STYLE_ITALIC; 234 else if (renderStyle[i] == 'u') 235 this->renderStyle |= TTF_STYLE_UNDERLINE; 236 } 236 237 if (likely(this->fontTTF != NULL)) 237 238 TTF_SetFontStyle(this->fontTTF, this->renderStyle); 238 // else239 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");239 // else 240 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); 240 241 } 241 242 … … 247 248 * @param fileName the File to write the image into. 248 249 */ 249 void Font::createAsciiImage(const char*fileName, unsigned int size) const250 void Font::createAsciiImage(const std::string& fileName, unsigned int size) const 250 251 { 251 252 if (this->fontTTF == NULL) … … 258 259 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 259 260 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 260 261 261 height*size, height*size, 262 32, 262 263 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 263 264 265 266 264 0x000000FF, 265 0x0000FF00, 266 0x00FF0000, 267 0xFF000000 267 268 #else 268 269 270 271 269 0xFF000000, 270 0x00FF0000, 271 0x0000FF00, 272 0x000000FF 272 273 #endif 273 274 ); … … 299 300 } 300 301 } 301 SDL_SaveBMP(tmpSurf, fileName );302 SDL_SaveBMP(tmpSurf, fileName.c_str()); 302 303 SDL_FreeSurface(tmpSurf); 303 304 } … … 409 410 410 411 this->initGlyphs(32, numberOfGlyphs); 411 // this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space412 // this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space 412 413 413 414 int rectSize = this->findOptimalFastTextureSize(); … … 418 419 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 419 420 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 420 421 421 rectSize, rectSize, 422 32, 422 423 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 423 424 425 426 424 0x000000FF, 425 0x0000FF00, 426 0x00FF0000, 427 0xFF000000 427 428 #else 428 429 430 431 429 0xFF000000, 430 0x00FF0000, 431 0x0000FF00, 432 0x000000FF 432 433 #endif 433 434 ); … … 457 458 break; 458 459 } 459 460 // reading in the new Glyph 460 461 if (likely(this->fontTTF != NULL)) 461 462 { … … 521 522 for (int i = from; i <= lastGlyph; i++) 522 523 { 523 524 // setting up all the Glyphs we like. 524 525 glyphArray[i] = getGlyphMetrics(i); 525 526 } … … 555 556 if((tmpGlyph = this->glyphArray[i]) != NULL) 556 557 { 557 558 // getting the height of the highest Glyph in the Line. 558 559 if (tmpGlyph->height*this->renderSize > maxLineHeight) 559 560 maxLineHeight = (int)(tmpGlyph->height*this->renderSize); … … 563 564 x = 0; 564 565 y = y + maxLineHeight; 565 566 //maxLineHeight = 0; 566 567 } 567 568 if (y + maxLineHeight + 1 > size) … … 592 593 if(style==TTF_STYLE_NORMAL) 593 594 PRINTF(0)(" normal"); 594 else { 595 else 596 { 595 597 if(style&TTF_STYLE_BOLD) 596 598 PRINTF(0)(" bold"); -
trunk/src/lib/graphics/text_engine/font.h
r6609 r7221 55 55 { 56 56 public: 57 Font(const char*fontFile,57 Font(const std::string& fontFile, 58 58 unsigned int renderSize); 59 Font(const char*imageFile);59 Font(const std::string& imageFile); 60 60 Font(char** xpmArray); 61 61 virtual ~Font(); … … 64 64 65 65 // font 66 bool loadFontFromTTF(const char*fontFile);66 bool loadFontFromTTF(const std::string& fontFile); 67 67 bool loadFontFromSDL_Surface(SDL_Surface* surface); 68 68 69 void setStyle(const char*renderStyle);69 void setStyle(const std::string& renderStyle); 70 70 71 71 /** @returns a Pointer to the Array of Glyphs */ … … 78 78 inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; }; 79 79 80 void createAsciiImage(const char*fileName, unsigned int size) const;80 void createAsciiImage(const std::string& fileName, unsigned int size) const; 81 81 static void initDefaultFont(); 82 82 static void removeDefaultFont(); -
trunk/src/lib/graphics/text_engine/text.cc
r7193 r7221 32 32 * @param type The renderType to display this font in 33 33 */ 34 Text::Text(const char*fontFile, unsigned int textSize)34 Text::Text(const std::string& fontFile, unsigned int textSize) 35 35 { 36 36 this->init(); 37 37 38 if ( fontFile != NULL)38 if (!fontFile.empty()) 39 39 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 40 40 this->setSizeY2D(textSize); … … 50 50 if (this->font != NULL && this->font != Font::getDefaultFont()) 51 51 ResourceManager::getInstance()->unload(this->font); 52 53 if (this->text)54 delete[] this->text;55 52 } 56 53 … … 64 61 // initialize this Text 65 62 this->font = NULL; 66 this->text = NULL; 67 this->externText = NULL; 63 this->text = ""; 68 64 this->setAlignment(TEXT_DEFAULT_ALIGNMENT); 69 65 this->blending = TEXT_DEFAULT_BLENDING; 70 66 this->color = TEXT_DEFAULT_COLOR; 71 67 this->setSize(TEXT_DEFAULT_SIZE); 72 this->setText( NULL);68 this->setText(""); 73 69 } 74 70 … … 78 74 * @param fontSize the Size of the Font 79 75 */ 80 void Text::setFont(const char*fontFile, unsigned int fontSize)76 void Text::setFont(const std::string& fontFile, unsigned int fontSize) 81 77 { 82 78 Font* tmpFont; … … 90 86 91 87 // load a new Font 92 if ( fontFile != NULL)88 if (!fontFile.empty()) 93 89 { 94 90 tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize); … … 96 92 this->font = tmpFont; 97 93 else 98 PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile );94 PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str()); 99 95 } 100 96 } … … 104 100 * @param text the new text to set 105 101 */ 106 void Text::setText(const char* text, bool isExtern) 107 { 108 if (isExtern) 109 { 110 this->externText = text; 111 112 if (unlikely(this->text != NULL)) 113 { 114 delete[] this->text; 115 this->text = NULL; 116 } 117 } 118 else 119 { 120 this->externText = NULL; 121 if (this->text) 122 delete[] this->text; 123 if (text != NULL) 124 { 125 this->text = new char[strlen(text)+1]; 126 strcpy(this->text, text); 127 } 128 else 129 this->text = NULL; 130 } 102 void Text::setText(const std::string& text) 103 { 104 this->text = text; 131 105 132 106 // setting up the Text-Width if DYNAMIC … … 138 112 139 113 float width = 0; 140 const char* tmpText = this->externText; 141 if (this->externText == NULL) 142 tmpText = this->text; 143 if (tmpText != NULL) 114 if (!this->text.empty()) 144 115 { 145 while (*tmpText != '\0')116 for (unsigned int i = 0; i < this->text.size(); i++) 146 117 { 147 if(glyphArray[ *tmpText] != NULL)118 if(glyphArray[this->text[i]] != NULL) 148 119 { 149 width += glyphArray[ *tmpText]->advance;120 width += glyphArray[this->text[i]]->advance; 150 121 } 151 tmpText++;152 122 } 153 123 this->setSizeX2D(width *this->getSizeY2D()); … … 190 160 glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getTexture()); 191 161 } 192 const char* tmpText = this->externText; 193 if (this->externText == NULL) 194 tmpText = this->text; 195 if (likely(tmpText != NULL)) 162 if (likely(!this->text.empty())) 196 163 { 197 164 glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0); … … 201 168 202 169 glBegin(GL_QUADS); 203 while (likely(*tmpText != '\0'))170 for (unsigned int i = 0; i < this->text.size(); i++) 204 171 { 205 if(likely((tmpGlyph = glyphArray[ *tmpText]) != NULL))172 if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL)) 206 173 { 207 174 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); … … 219 186 posX += tmpGlyph->advance * this->getSizeY2D(); 220 187 } 221 ++tmpText;222 188 } 223 189 glEnd(); … … 232 198 void Text::debug() const 233 199 { 234 if (this->externText == NULL) 235 PRINT(0)("=== TEXT: %s ===\n", this->text); 236 else 237 PRINT(0)("=== TEXT: %s ===\n", this->externText); 200 PRINT(0)("=== TEXT: %s ===\n", this->text.c_str()); 238 201 239 202 if (this->getBindNode()) -
trunk/src/lib/graphics/text_engine/text.h
r6981 r7221 39 39 { 40 40 public: 41 Text(const char* fontFile = NULL, unsigned int fontSize = TEXT_DEFAULT_SIZE);41 Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE); 42 42 virtual ~Text(); 43 43 void init(); 44 44 45 void setFont(const char*fontFile, unsigned int renderSize);45 void setFont(const std::string& fontFile, unsigned int renderSize); 46 46 47 void setText(const char* text, bool isExtern = false);47 void setText(const std::string& text); 48 48 49 49 /** @returns the String this Text displays */ 50 inline const char* getText() const { return (externText == NULL)?this->text:this->externText; };50 inline const std::string& getText() const { return this->text; }; 51 51 /** @param blending the blending intensity to set (between 0.0 and 1.0) */ 52 52 inline void setBlending(float blending) { this->blending = blending; }; … … 69 69 Font* font; //!< Font of this text 70 70 71 char* text; //!< The text to display 72 const char* externText; //!< the text to Display from an external Source. 71 std::string text; //!< The text to display 73 72 Vector color; //!< The color of the font. 74 73 float blending; //!< The blending intensity. -
trunk/src/lib/gui/gl_gui/glgui_button.cc
r6287 r7221 54 54 } 55 55 56 void GLGuiButton::setLabel(const char*label)56 void GLGuiButton::setLabel(const std::string& label) 57 57 { 58 58 this->label->setText(label); -
trunk/src/lib/gui/gl_gui/glgui_button.h
r5427 r7221 35 35 36 36 void init(); 37 void setLabel(const char*label);37 void setLabel(const std::string& label); 38 38 39 39 virtual void draw() const; -
trunk/src/lib/gui/gl_gui/glgui_menu.h
r5391 r7221 24 24 void init(); 25 25 26 void addItem(const char*itemName);27 void removeItem(const char*itemName);26 void addItem(const std::string& itemName); 27 void removeItem(const std::string& itemName); 28 28 void removeItem(unsigned int itemNumber); 29 void selectItem(const char*itemName);29 void selectItem(const std::string& itemName); 30 30 void selectItem(unsigned int itemNumber); 31 31 -
trunk/src/lib/gui/gl_gui/glgui_widget.h
r7062 r7221 47 47 virtual char* save() {}; 48 48 /** loads options of the Widget. @param loadString a string containing the Options */ 49 virtual void load(const char*loadString) {};49 virtual void load(const std::string& loadString) {}; 50 50 51 51 void show(); -
trunk/src/lib/gui/gl_gui/glmenu/glmenu_imagescreen.cc
r7193 r7221 13 13 ### File Specific: 14 14 main-programmer: Patrick Boenzli 15 co-programmer: 15 co-programmer: Benjamin GRauer 16 16 */ 17 17 … … 84 84 85 85 /** 86 * sets the background image name86 * @brief sets the background image name 87 87 * @param backImageName name of the backgroun-image 88 88 */ 89 void GLMenuImageScreen::setBackgroundImage (const char*backImageName)89 void GLMenuImageScreen::setBackgroundImage (const std::string& backImageName) 90 90 { 91 91 this->backMat->setDiffuseMap(backImageName); … … 93 93 94 94 /** 95 * sets position of the ImageScreen95 * @brief sets position of the ImageScreen 96 96 * @param offsetX offset from the top left corner in percent(0-1) of the screensize 97 97 * @param offsetY offset from the top left corner in percent(0-1) of the screensize … … 104 104 105 105 /** 106 \brief sets size of the ImageScreen106 * @brief sets size of the ImageScreen 107 107 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1)) 108 108 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1)) … … 115 115 116 116 /** 117 \brief sets position and size of the ImageScreen118 * @param offsetX offset from the top left corner in percent(0-1) of the screensize119 * @param offsetY offset from the top left corner in percent(0-1) of the screensize120 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1))121 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1))117 * @brief sets position and size of the ImageScreen 118 * @param offsetX offset from the top left corner in percent(0-1) of the screensize 119 * @param offsetY offset from the top left corner in percent(0-1) of the screensize 120 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1)) 121 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1)) 122 122 */ 123 123 void GLMenuImageScreen::setPosScale(float offsetX, float offsetY, float scaleX, float scaleY) … … 130 130 * @param barImage An image for the Bar 131 131 */ 132 void GLMenuImageScreen::setBarImage(const char*barImage)132 void GLMenuImageScreen::setBarImage(const std::string& barImage) 133 133 { 134 134 this->barMat->setDiffuseMap(barImage); … … 136 136 137 137 /** 138 * sets the Position and the Size of the bar138 * @brief sets the Position and the Size of the bar 139 139 * @param barX The Position in the x-direction in percent of the screen (0-1) 140 140 * @param barY The Position in the y-direction in percent of the screen (0-1) … … 152 152 153 153 /** 154 * set the maximum of countable steps154 * @brief set the maximum of countable steps 155 155 * @param maxValue of steps 156 156 */ … … 161 161 162 162 /** 163 * set current value163 * @brief set current value 164 164 * @param currentValue value to set 165 165 */ … … 172 172 173 173 /** 174 * get the current value174 * @brief get the current value 175 175 */ 176 176 int GLMenuImageScreen::getValue() … … 181 181 182 182 /** 183 *call this to trigger a progress event184 185 183 * @brief call this to trigger a progress event 184 * 185 * this has to redraw the progress bar and the whole image 186 186 */ 187 187 void GLMenuImageScreen::step () … … 199 199 200 200 /** 201 * draws the ImageScreen to the screenbuffer201 * @brief draws the ImageScreen to the screenbuffer 202 202 */ 203 203 void GLMenuImageScreen::draw () -
trunk/src/lib/gui/gl_gui/glmenu/glmenu_imagescreen.h
r6512 r7221 13 13 14 14 //! A class to display a loadScreen 15 class GLMenuImageScreen : public BaseObject { 15 class GLMenuImageScreen : public BaseObject 16 { 16 17 17 18 public: 18 19 GLMenuImageScreen (const TiXmlElement* root = NULL); 19 20 virtual void loadParams(const TiXmlElement* root); … … 22 23 void draw(); 23 24 24 void setBackgroundImage(const char*backImageName);25 void setBackgroundImage(const std::string& backImageName); 25 26 void setPosition(float offsetX, float offsetY); 26 27 void setScale (float scaleX, float scaleY); 27 28 void setPosScale(float offsetX, float offsetY, float scaleX, float scaleY); 28 29 29 void setBarImage(const char*barImage);30 void setBarImage(const std::string& barImage); 30 31 void setBarPosScale(float barX, float barY, float barW, float barH); 31 32 … … 39 40 40 41 41 42 private: 42 43 // background image 43 char*backImageName; //!< the name of the file of the background image44 std::string backImageName; //!< the name of the file of the background image 44 45 float offsetX; //!< X-offset of the the image from the left 45 46 float offsetY; //!< Y-offset of the image from the top -
trunk/src/lib/gui/gtk_gui/gui_exec.cc
r7193 r7221 47 47 Frame* execFrame; //!< The Frame that holds the ExecutionOptions. 48 48 49 this->confFile = NULL;50 this->confDir = NULL;49 this->confFile = ""; 50 this->confDir = ""; 51 51 52 52 execFrame = new Frame("Execute-Tags:"); … … 137 137 GuiExec::~GuiExec() 138 138 { 139 if(this->confFile)140 delete []this->confFile;141 if(this->confDir)142 delete []this->confDir;143 139 } 144 140 … … 156 152 //! @todo F** Windows-support 157 153 #ifndef __WIN32__ 158 mkdir(this->confDir , 0755);154 mkdir(this->confDir.c_str(), 0755); 159 155 #else /* __WiN32__ */ 160 mkdir(this->confDir );156 mkdir(this->confDir.c_str()); 161 157 #endif /* __WIN32__ */ 162 158 } … … 170 166 void GuiExec::setConfFile(const char* fileName) 171 167 { 172 if ( !this->confDir)168 if (this->confDir.empty()) 173 169 this->setConfDir("~/"); 174 this->confFile = new char[strlen(this->confDir)+strlen(fileName)+2]; 175 sprintf(this->confFile, "%s/%s", this->confDir, fileName); 170 this->confFile = this->confDir + "/" + fileName; 176 171 PRINTF(5)("ConfigurationFile is %s.\n", this->confFile); 177 172 } … … 182 177 const char* GuiExec::getConfigFile() const 183 178 { 184 return this->confFile ;179 return this->confFile.c_str(); 185 180 } 186 181 … … 204 199 IniParser iniParser; 205 200 this->writeFileText(widget, &iniParser, 0); 206 char*fileName = ResourceManager::homeDirCheck(confFile);201 std::string fileName = ResourceManager::homeDirCheck(confFile); 207 202 iniParser.writeFile(fileName); 208 delete[] fileName;209 203 } 210 204 … … 259 253 void GuiExec::readFromFile(Widget* widget) 260 254 { 261 char*fileName = ResourceManager::homeDirCheck(confFile);255 std::string fileName = ResourceManager::homeDirCheck(confFile); 262 256 IniParser iniParser(fileName); 263 delete[] fileName;264 257 if (!iniParser.isOpen()) 265 258 return; … … 267 260 iniParser.firstSection(); 268 261 Widget* groupWidget = widget; 269 const char*groupName;270 const char*widgetName;262 std::string groupName; 263 std::string widgetName; 271 264 VarInfo varInfo; 272 while ( groupName = iniParser.getCurrentSection())265 while ((groupName = iniParser.getCurrentSection()) != "") 273 266 { 274 printf("GROUP:::%s\n", groupName);275 if((groupWidget = locateGroup(widget, groupName , 1))==NULL)267 PRINTF(4)("GROUP:::%s\n", groupName.c_str()); 268 if((groupWidget = locateGroup(widget, groupName.c_str(), 1))==NULL) 276 269 { 277 PRINTF(2)("!!There is no group called %s in this GUI.\n First best Widget will get the Infos assigned.\n Config-File will be updated in next Save\n", groupName);270 PRINTF(2)("!!There is no group called %s in this GUI.\n First best Widget will get the Infos assigned.\n Config-File will be updated in next Save\n", groupName.c_str()); 278 271 groupWidget = widget; 279 272 continue; … … 282 275 PRINT(4)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName); 283 276 284 const char*entryName;277 std::string entryName; 285 278 iniParser.firstVar(); 286 while( entryName = iniParser.getCurrentName())287 { 288 PRINTF(4)("ENTRY:::%s = %s\n", entryName , iniParser.getCurrentValue());289 varInfo.variableName = entryName ;290 varInfo.variableValue = iniParser.getCurrentValue() ;279 while((entryName = iniParser.getCurrentName()) != "") 280 { 281 PRINTF(4)("ENTRY:::%s = %s\n", entryName.c_str(), iniParser.getCurrentValue().c_str()); 282 varInfo.variableName = entryName.c_str(); 283 varInfo.variableValue = iniParser.getCurrentValue().c_str(); 291 284 groupWidget->walkThrough(this->readFileText, &varInfo, 0); 292 285 iniParser.nextVar(); -
trunk/src/lib/gui/gtk_gui/gui_exec.h
r6981 r7221 11 11 #include "gui_gtk.h" 12 12 13 #include <string> 14 13 15 class Widget; 14 16 class CheckButton; … … 22 24 CheckButton* saveSettings; //!< A CheckBox for if the Options should be saved. 23 25 24 char* confDir;//!< The directory of the orxonox-configuration-files.25 char* confFile;//!< The name of the .orxonox.conf(ig)-file.26 std::string confDir; //!< The directory of the orxonox-configuration-files. 27 std::string confFile; //!< The name of the .orxonox.conf(ig)-file. 26 28 27 29 //! A struct that holds informations about variables. … … 58 60 struct HashTable 59 61 { 60 char*name; //!< name of the entry61 char*value; //!< value of the entry62 std::string name; //!< name of the entry 63 std::string value; //!< value of the entry 62 64 HashTable* next; //!< pointer to the next entry 63 65 }; -
trunk/src/lib/lang/base_object.cc
r7193 r7221 34 34 BaseObject::BaseObject() 35 35 { 36 this->classID = CL_BASE_OBJECT; 36 37 this->className = "BaseObject"; 37 this->classID = CL_BASE_OBJECT; 38 39 this->objectName = NULL; 38 39 this->objectName = ""; 40 40 this->classList = NULL; 41 41 this->xmlElem = NULL; … … 52 52 53 53 // delete []this->className; 54 if (this->objectName)55 delete[] this->objectName;56 54 if (this->xmlElem != NULL) 57 55 delete this->xmlElem; … … 80 78 * @param className the class name 81 79 */ 82 void BaseObject::setClassID(ClassID classID, const char*className)80 void BaseObject::setClassID(ClassID classID, const std::string& className) 83 81 { 84 82 //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID); … … 95 93 * @brief set the name of the Object 96 94 */ 97 void BaseObject::setName (const char* objectName) 98 { 99 if (this->objectName) 100 delete[] this->objectName; 101 if (objectName != NULL) 102 { 103 this->objectName = new char[strlen(objectName)+1]; 104 strcpy(this->objectName, objectName); 105 } 106 else 107 this->objectName = NULL; 95 void BaseObject::setName (const std::string& objectName) 96 { 97 this->objectName = objectName; 108 98 } 109 99 … … 160 150 * @returns true if it is, false otherwise 161 151 */ 162 bool BaseObject::isA (const char*className) const152 bool BaseObject::isA (const std::string& className) const 163 153 { 164 154 ClassID classID = ClassList::StringToID(className); … … 173 163 * @returns true on match, false otherwise. 174 164 */ 175 bool BaseObject::operator==(const char* objectName) 176 { 177 if (likely(this->objectName != NULL && objectName != NULL)) 178 return (strcmp(this->objectName, objectName)) ? false : true; 165 bool BaseObject::operator==(const std::string& objectName) 166 { 167 return (this->objectName == objectName); 179 168 } 180 169 … … 197 186 int BaseObject::writeState( const byte * data, int length, int sender ) 198 187 { 199 SYNCHELP_READ_BEGIN(); 200 201 if ( objectName ) 188 /// FIXME STD 189 190 /* SYNCHELP_READ_BEGIN(); 191 192 if ( !objectName.empty() ) 202 193 { 203 194 delete[] objectName; … … 211 202 } 212 203 213 return SYNCHELP_READ_N; 204 return SYNCHELP_READ_N;*/ 214 205 } 215 206 … … 222 213 int BaseObject::readState( byte * data, int maxLength ) 223 214 { 224 SYNCHELP_WRITE_BEGIN(); 215 ///FIXME STD 216 /* SYNCHELP_WRITE_BEGIN(); 225 217 226 218 //PRINTF(0)("objectname = %s\n", this->objectName); 227 219 SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME ); 228 220 229 return SYNCHELP_WRITE_N; 230 } 221 return SYNCHELP_WRITE_N;*/ 222 } -
trunk/src/lib/lang/base_object.h
r6587 r7221 16 16 #endif 17 17 18 #include <string> 18 19 #include "stdincl.h" 19 20 … … 30 31 31 32 virtual void loadParams(const TiXmlElement* root); 32 void setName (const char*newName);33 void setName (const std::string& newName); 33 34 /** returns the Name of this Object */ 34 inline const char* getName ()const { return this->objectName ; };35 inline const char* getName ()const { return this->objectName.c_str(); }; 35 36 /** @returns the XML-Element with whicht this Object was loaded */ 36 37 inline TiXmlNode* getXmlElem() const { return this->xmlElem; }; 37 38 38 39 /** @returns the className of the corresponding Object */ 39 inline const char* getClassName() const { return this->className ; };40 inline const char* getClassName() const { return this->className.c_str(); }; 40 41 /** @returns the classID of the corresponding Object */ 41 42 inline int getClassID() const { return this->classID; }; … … 43 44 44 45 bool isA (ClassID classID) const; 45 bool isA (const char*className) const;46 bool isA (const std::string& className) const; 46 47 void whatIs() const; 47 48 48 bool operator==(const char*objectName);49 bool operator==(const std::string& objectName); 49 50 /** @param classID comparer for a ClassID @returns true on match, false otherwise */ 50 51 bool operator==(ClassID classID) { return this->isA(classID); }; … … 54 55 55 56 protected: 56 void setClassID(ClassID classID, const char*className);57 void setClassID(ClassID classID, const std::string& className); 57 58 58 59 private: 59 const char*className; //!< the name of the class60 std::string className; //!< the name of the class 60 61 long classID; //!< this is the id from the class_id.h enumeration 61 char*objectName; //!< The name of this object62 std::string objectName; //!< The name of this object 62 63 63 64 ClassList* classList; //!< Pointer to the ClassList this Object is inside of -
trunk/src/lib/lang/class_list.cc
r7199 r7221 37 37 * Creates a new ClassList 38 38 */ 39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const char*className)40 { 41 this->className = className; 39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const std::string& className) 40 : className(className) 41 { 42 42 this->classID = classID; 43 43 this->classIDFull = classIDFull; … … 56 56 57 57 //! a List of all strings of all classes, that have registered so far. 58 std::list< const char*> ClassList::classNames;58 std::list<std::string> ClassList::classNames; 59 59 60 60 /** … … 67 67 * !! Before unsing the ClassList, as it creates the ClassLits 68 68 */ 69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char*className)69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className) 70 70 { 71 71 if (unlikely(classList == NULL)) 72 72 ClassList::classList = new list<ClassList>(); 73 73 74 PRINTF(5)("subscribe a '%s'\n", className );74 PRINTF(5)("subscribe a '%s'\n", className.c_str() ); 75 75 76 76 ClassList* regClass = ClassList::getClassList(classID); … … 113 113 * befor it changes anything. 114 114 */ 115 const std::list< const char*>* ClassList::getClassNames()115 const std::list<std::string>* ClassList::getClassNames() 116 116 { 117 117 if (ClassList::classNames.size() != ClassList::classList->size()) … … 155 155 * @return the List accessed by classID, or NULL if not found 156 156 */ 157 const std::list<BaseObject*>* ClassList::getList(const char*className)157 const std::list<BaseObject*>* ClassList::getList(const std::string& className) 158 158 { 159 159 ClassList* fl; … … 191 191 * @returns the ClassList with className as specifyer, or NULL if not 192 192 */ 193 ClassList* ClassList::getClassList(const char*className)194 { 195 if (className == NULL)193 ClassList* ClassList::getClassList(const std::string& className) 194 { 195 if (className.empty()) 196 196 return NULL; 197 197 std::list<ClassList>::iterator classIT = find (classList->begin(), classList->end(), className); … … 207 207 * @todo: speed this up!! 208 208 */ 209 BaseObject* ClassList::getObject(const char*objectName, ClassID classID)209 BaseObject* ClassList::getObject(const std::string& objectName, ClassID classID) 210 210 { 211 211 if (classID != CL_NULL) … … 216 216 std::list<BaseObject*>::iterator bo; 217 217 for (bo = cl->objectList.begin(); bo != cl->objectList.end(); bo++) 218 if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))218 if ((*bo)->getName() != NULL && objectName == (*bo)->getName()) 219 219 return (*bo); 220 220 } … … 227 227 std::list<BaseObject*>::iterator bo; 228 228 for (bo = (*cl).objectList.begin(); bo != (*cl).objectList.end(); bo++) 229 if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))229 if ((*bo)->getName() != NULL && objectName == (*bo)->getName()) 230 230 return (*bo); 231 231 } … … 276 276 if (object->isA((*cl).classID)) 277 277 { 278 PRINT(0)("=%s::0x%.8X=-", (*cl).className , (*cl).classID);278 PRINT(0)("=%s::0x%.8X=-", (*cl).className.c_str(), (*cl).classID); 279 279 } 280 280 } … … 285 285 * @return a String containing the name of the Class, NULL if the Class was not found 286 286 */ 287 const char* ClassList::IDToString(ClassID classID) 288 { 287 const std::string& ClassList::IDToString(ClassID classID) 288 { 289 static const std::string empty(""); 290 289 291 ClassList* cl = ClassList::getClassList(classID); 290 return (cl != NULL) ? cl->className : NULL;292 return (cl != NULL) ? cl->className : empty; 291 293 } 292 294 … … 296 298 * @return the ClassID. CL_NULL, if the class was not found. 297 299 */ 298 ClassID ClassList::StringToID(const char*className)300 ClassID ClassList::StringToID(const std::string& className) 299 301 { 300 302 ClassList* cl = ClassList::getClassList(className); … … 307 309 * @returns true on match, false otherwise 308 310 */ 309 bool ClassList::operator==(const char* className) 310 { 311 if (likely( className != NULL && this->className != NULL)) 312 return (!strcmp(this->className, className)); 313 else 314 return false; 311 bool ClassList::operator==(const std::string& className) 312 { 313 return (this->className == className); 315 314 } 316 315 … … 342 341 while (pow(10, lenCount) <= (*cl).objectList.size()) 343 342 ++lenCount; 344 for (int i=0; i < 30- strlen((*cl).className) - lenCount; i++)343 for (int i=0; i < 30-(*cl).className.size() - lenCount; i++) 345 344 (niceString[i]) = ' '; 346 niceString[30- strlen((*cl).className) - lenCount] = '\0';347 348 PRINT(0)("| CLASS %s::%s %d\n", (*cl).className , niceString, (*cl).objectList.size());345 niceString[30-(*cl).className.size() - lenCount] = '\0'; 346 347 PRINT(0)("| CLASS %s::%s %d\n", (*cl).className.c_str(), niceString, (*cl).objectList.size()); 349 348 350 349 if (debugLevel >=2 && (*cl).objectList.size() > 0) … … 371 370 * @see ClassList::debug 372 371 */ 373 void ClassList::debugS(const char*className, unsigned int debugLevel)372 void ClassList::debugS(const std::string& className, unsigned int debugLevel) 374 373 { 375 374 ClassList::debug(debugLevel, ClassList::StringToID(className)); -
trunk/src/lib/lang/class_list.h
r7165 r7221 10 10 #include "class_id.h" 11 11 #include <list> 12 #include <string> 12 13 #ifndef NULL 13 14 #define NULL 0 //!< NULL … … 32 33 class ClassList { 33 34 public: 34 ClassList(ClassID classID, unsigned long classIDFull, const char*className);35 ClassList(ClassID classID, unsigned long classIDFull, const std::string& className); 35 36 virtual ~ClassList(); 36 37 37 38 /* MAINTENANCE FUNCTIONS THESE ARE !!ONLY FOR BASEOBJECT !! */ 38 static ClassList* addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char*className);39 static ClassList* addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className); 39 40 static void removeFromClassList(BaseObject* objectPointer); 40 41 … … 42 43 43 44 static const std::list<BaseObject*>* getList(ClassID classID = CL_NULL);// { return (ClassList* fl = ClassList::getClassList(classID) != NULL)? &(fl->objectList) : NULL; }; 44 static const std::list<BaseObject*>* getList(const char*className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL; };45 static const std::list< const char*>* getClassNames();46 static BaseObject* getObject(const char*name, ClassID classID = CL_NULL);45 static const std::list<BaseObject*>* getList(const std::string& className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL; }; 46 static const std::list<std::string>* getClassNames(); 47 static BaseObject* getObject(const std::string& name, ClassID classID = CL_NULL); 47 48 static bool exists(const BaseObject* object, ClassID classID = CL_NULL); 48 49 … … 51 52 static void whatIs(const BaseObject* object); 52 53 53 static const char*IDToString(ClassID classID = CL_NULL);54 static ClassID StringToID(const char*className);54 static const std::string& IDToString(ClassID classID = CL_NULL); 55 static ClassID StringToID(const std::string& className); 55 56 static void debug(unsigned int debugLevel = 0, ClassID classID = CL_NULL); 56 static void debugS(const char* className = NULL, unsigned int debugLevel = 0);57 static void debugS(const std::string& className = "", unsigned int debugLevel = 0); 57 58 58 59 inline bool operator==(ClassID classID) { return (this->classID == classID); }; 59 bool operator==(const char*className);60 bool operator==(const std::string& className); 60 61 inline ClassID getLeafClassID() const { return this->classID; }; 61 62 62 63 private: 63 64 static ClassList* getClassList(ClassID classID); 64 static ClassList* getClassList(const char*className);65 static ClassList* getClassList(const std::string& className); 65 66 66 67 private: 67 ClassID classID; //!< ClassID stored in this ClassList68 unsigned long classIDFull; //!< The Full ClassID of this Class.68 ClassID classID; //!< ClassID stored in this ClassList 69 unsigned long classIDFull; //!< The Full ClassID of this Class. 69 70 70 const char*className; //!< Name of the Class Stored here71 const std::string className; //!< Name of the Class Stored here 71 72 72 std::list<BaseObject*> objectList; //!< A list of Objects belonging to this Class73 std::list<BaseObject*> objectList; //!< A list of Objects belonging to this Class 73 74 74 75 // STATIC MEMBERS 75 static std::list<ClassList>* classList; //!< The first Class in the List76 static std::list< const char*>classNames; //!< a List of all Names of all classes, that have registered so far.76 static std::list<ClassList>* classList; //!< The first Class in the List 77 static std::list<std::string> classNames; //!< a List of all Names of all classes, that have registered so far. 77 78 }; 78 79 -
trunk/src/lib/parser/ini_parser/ini_parser.cc
r5953 r7221 40 40 * @param fileName: the path and name of the file to parse 41 41 */ 42 IniParser::IniParser (const char*fileName)43 { 44 this->fileName = NULL;45 this->comment = NULL;46 47 if ( fileName != NULL)42 IniParser::IniParser (const std::string& fileName) 43 { 44 this->fileName = ""; 45 this->comment = ""; 46 47 if (!fileName.empty()) 48 48 this->readFile(fileName); 49 49 } … … 56 56 { 57 57 this->deleteSections(); 58 this->setFileName(NULL); 59 } 58 this->setFileName(""); 59 } 60 61 const std::string IniParser::emptyString = ""; 60 62 61 63 … … 66 68 { 67 69 // in all sections 68 while(!this->sections.empty()) 69 { 70 IniSection section = this->sections.front(); 71 72 // in all entries of the sections 73 while(!section.entries.empty()) 74 { 75 // delete all strings of entries. 76 IniEntry entry = section.entries.front(); 77 delete[] entry.name; 78 delete[] entry.value; 79 delete[] entry.comment; 80 section.entries.pop_front(); 81 } 82 // delete all Sections 83 delete[] section.name; 84 delete[] section.comment; 85 this->sections.pop_front(); 86 } 70 this->sections.clear(); 71 87 72 this->currentSection = this->sections.end(); 88 this->setFileName( NULL);73 this->setFileName(""); 89 74 } 90 75 … … 95 80 * If fileName is NULL the new Name will be set to NULL too. 96 81 */ 97 void IniParser::setFileName(const char* fileName) 98 { 99 if (this->fileName != NULL) 100 delete[] this->fileName; 101 if (this->comment != NULL) 102 delete[] this->comment; 103 this->comment = NULL; 104 105 if (fileName != NULL) 106 { 107 this->fileName = new char[strlen(fileName)+1]; 108 strcpy(this->fileName, fileName); 109 } 110 else 111 this->fileName = NULL; 82 void IniParser::setFileName(const std::string& fileName) 83 { 84 this->comment = ""; 85 this->fileName = fileName; 112 86 } 113 87 … … 121 95 * and the new one will be opened. 122 96 */ 123 bool IniParser::readFile(const char*fileName)97 bool IniParser::readFile(const std::string& fileName) 124 98 { 125 99 FILE* stream; //< The stream we use to read the file. 126 100 int lineCount = 0; //< The Count of lines. 127 101 128 if ( this->fileName != NULL)102 if (!this->fileName.empty()) 129 103 this->deleteSections(); 130 if( fileName == NULL) 131 return false; 132 133 if( (stream = fopen (fileName, "r")) == NULL) 134 { 135 PRINTF(1)("IniParser could not open %s\n", fileName); 104 105 if( fileName.empty()) 106 return false; 107 108 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 109 { 110 PRINTF(1)("IniParser could not open %s\n", fileName.c_str()); 136 111 return false; 137 112 } … … 143 118 // READING IN THE INI-FILE // 144 119 ///////////////////////////// 145 char lineBuffer[PARSELINELENGHT ];146 char buffer[PARSELINELENGHT ];120 char lineBuffer[PARSELINELENGHT+1]; 121 char buffer[PARSELINELENGHT+1]; 147 122 const char* lineBegin; 148 123 char* ptr; … … 154 129 if( (ptr = strchr( lineBuffer, '\n')) != NULL) 155 130 *ptr = 0; 131 else 132 lineBuffer[PARSELINELENGHT] = 0; 156 133 // cut up to the beginning of the line. 157 134 while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer)) 158 135 ++lineBegin; 159 136 137 if ( !strcmp( lineBegin, "" ) ) 138 continue; 139 160 140 // check if we have a FileComment 161 141 if ( (*lineBegin == '#' || *lineBegin == ';')) 162 142 { 163 char* newCommenLine = new char[strlen(lineBegin)+1]; 164 strcpy(newCommenLine, lineBegin); 143 string newCommenLine = lineBegin; 165 144 this->commentList.push_back(newCommenLine); 166 145 continue; … … 191 170 continue; 192 171 } 193 if( ptr == lineBegin) { 172 if( ptr == lineBegin) 173 { 194 174 lineCount++; 195 175 continue; … … 228 208 * @return true on success false otherwise 229 209 */ 230 bool IniParser::writeFile(const char*fileName) const210 bool IniParser::writeFile(const std::string& fileName) const 231 211 { 232 212 FILE* stream; //!< The stream we use to read the file. 233 if( fileName == NULL && (fileName = this->fileName) == NULL)234 return false; 235 236 if( (stream = fopen (fileName , "w")) == NULL)237 { 238 PRINTF(1)("IniParser could not open %s\n", fileName );239 return false; 240 } 241 else 242 { 243 if ( this->comment != NULL)244 fprintf(stream, "%s\n\n", this->comment );213 if( fileName.empty()) 214 return false; 215 216 if( (stream = fopen (fileName.c_str(), "w")) == NULL) 217 { 218 PRINTF(1)("IniParser could not open %s\n", fileName.c_str()); 219 return false; 220 } 221 else 222 { 223 if (!this->comment.empty()) 224 fprintf(stream, "%s\n\n", this->comment.c_str()); 245 225 246 226 std::list<IniSection>::const_iterator section; 247 227 for (section = this->sections.begin(); section != this->sections.end(); section++) 228 { 229 if (!(*section).comment.empty()) 230 fprintf(stream, "%s", (*section).comment.c_str()); 231 fprintf(stream, "\n [%s]\n", (*section).name.c_str()); 232 233 std::list<IniEntry>::const_iterator entry; 234 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 248 235 { 249 if ((*section).comment != NULL) 250 fprintf(stream, "%s", (*section).comment); 251 fprintf(stream, "\n [%s]\n", (*section).name); 252 253 std::list<IniEntry>::const_iterator entry; 254 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 255 { 256 if ((*entry).comment != NULL) 257 fprintf(stream, "%s", (*entry).comment); 258 fprintf(stream, " %s = %s\n", (*entry).name, (*entry).value); 259 } 236 if (!(*entry).comment.empty()) 237 fprintf(stream, "%s", (*entry).comment.c_str()); 238 fprintf(stream, " %s = %s\n", (*entry).name.c_str(), (*entry).value.c_str()); 260 239 } 240 } 261 241 } 262 242 fclose(stream); 263 243 } 264 244 265 void IniParser::setFileComment(const char* fileComment) 266 { 267 if (this->comment != NULL) 268 delete this->comment; 269 270 if (fileComment != NULL) 271 { 272 this->comment = new char[strlen(fileComment)+1]; 273 strcpy(this->comment, fileComment); 274 } 275 else 276 this->comment = NULL; 277 } 278 245 void IniParser::setFileComment(const std::string& fileComment) 246 { 247 this->comment = fileComment; 248 } 279 249 280 250 /** … … 284 254 * @return true on success... there is only success or segfault :) 285 255 */ 286 bool IniParser::addSection(const char* sectionName) 287 { 288 if (sectionName == NULL) 289 return false; 290 this->sections.push_back(IniSection()); 291 this->sections.back().comment = NULL; 292 this->sections.back().name = new char[strlen(sectionName)+1]; 293 strcpy(this->sections.back().name, sectionName); 256 bool IniParser::addSection(const std::string& sectionName) 257 { 258 if (sectionName.empty()) 259 return false; 260 IniSection newSection; 261 newSection.name = sectionName; 262 newSection.comment = ""; 263 264 this->sections.push_back(newSection); 294 265 295 266 this->currentSection = --this->sections.end(); 296 267 if (!this->sections.empty()) 297 298 PRINTF(5)("Added Section %s\n", sectionName );268 this->currentEntry = (*this->currentSection).entries.begin(); 269 PRINTF(5)("Added Section %s\n", sectionName.c_str()); 299 270 return true; 300 271 } … … 306 277 * @return true on success or false if the section could not be found 307 278 */ 308 bool IniParser::getSection(const char*sectionName)279 bool IniParser::getSection(const std::string& sectionName) 309 280 { 310 281 this->currentSection = this->getSectionIT(sectionName); … … 321 292 * 322 293 */ 323 void IniParser::setSectionComment(const char* comment, const char*sectionName)294 void IniParser::setSectionComment(const std::string& comment, const std::string& sectionName) 324 295 { 325 296 std::list<IniSection>::iterator section = this->getSectionIT(sectionName); … … 327 298 return; 328 299 329 if ((*section).comment != NULL) 330 delete[] (*section).comment; 331 if (comment != NULL) 332 { 333 (*section).comment = new char[strlen (comment)+1]; 334 strcpy((*section).comment, comment); 335 } 336 else 337 (*section).comment = NULL; 300 (*section).comment = comment; 338 301 } 339 302 … … 342 305 * @returns the Comment, or NULL on error. 343 306 */ 344 const char* IniParser::getSectionComment(const char*sectionName) const307 const std::string& IniParser::getSectionComment(const std::string& sectionName) const 345 308 { 346 309 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); … … 348 311 return (*section).comment; 349 312 else 350 return NULL;313 return IniParser::emptyString; 351 314 } 352 315 … … 367 330 * @returns the name of the section if found, NULL otherwise 368 331 */ 369 const char*IniParser::nextSection()332 const std::string& IniParser::nextSection() 370 333 { 371 334 if (this->currentSection == this->sections.end()) 372 return NULL;335 return IniParser::emptyString; 373 336 374 337 this->currentSection++; 375 338 376 339 if (this->currentSection != this->sections.end()) 377 378 379 380 381 else 382 return NULL;340 { 341 this->currentEntry = (*this->currentSection).entries.begin(); 342 return this->currentSection->name; 343 } 344 else 345 return IniParser::emptyString; 383 346 } 384 347 … … 393 356 * @return true if everything is ok false on error 394 357 */ 395 bool IniParser::addVar(const char* entryName, const char* value, const char*sectionName)358 bool IniParser::addVar(const std::string& entryName, const std::string& value, const std::string& sectionName) 396 359 { 397 360 std::list<IniSection>::iterator section; 398 361 399 if ( sectionName != NULL)362 if (!sectionName.empty()) 400 363 { 401 364 for (section = this->sections.begin(); section != this->sections.end(); section++) 402 if ( !strcmp((*section).name, sectionName))365 if ((*section).name == sectionName) 403 366 break; 404 367 } … … 411 374 if (section == this->sections.end()) 412 375 { 413 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName , entryName);376 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str()); 414 377 return false; 415 378 } … … 417 380 { 418 381 (*section).entries.push_back(IniEntry()); 419 (*section).entries.back().comment = NULL; 420 (*section).entries.back().name = new char[strlen(entryName)+1]; 421 strcpy((*section).entries.back().name, entryName); 422 (*section).entries.back().value = new char[strlen(value)+1]; 423 strcpy((*section).entries.back().value, value); 382 (*section).entries.back().comment = ""; 383 (*section).entries.back().name = entryName; 384 (*section).entries.back().value = value; 424 385 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 425 (*section).entries.back().name ,426 (*section).entries.back().value ,427 (*section).name );386 (*section).entries.back().name.c_str(), 387 (*section).entries.back().value.c_str(), 388 (*section).name.c_str()); 428 389 this->currentEntry = --(*section).entries.end(); 429 390 return true; … … 442 403 * lead to unwanted behaviour. 443 404 */ 444 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char*defaultValue) const445 { 446 if ( this->fileName != NULL)405 const std::string& IniParser::getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue) const 406 { 407 if (!this->fileName.empty()) 447 408 { 448 409 std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName); 449 if (entry != NULL && !strcmp((*entry).name, entryName))410 if (entry != NULL && (*entry).name == entryName) 450 411 return (*entry).value; 451 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName); 452 412 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName.c_str(), sectionName.c_str()); 453 413 } 454 414 else … … 456 416 457 417 return defaultValue; 458 459 418 } 460 419 … … 465 424 * @param sectionName the Name of the Section 466 425 */ 467 void IniParser::setEntryComment(const char* comment, const char* entryName, const char*sectionName)426 void IniParser::setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName) 468 427 { 469 428 std::list<IniEntry>::iterator entry = this->getEntryIT(entryName, sectionName); 470 471 if ((*entry).comment != NULL) 472 delete[] (*entry).comment; 473 if (comment != NULL) 474 { 475 (*entry).comment = new char[strlen (comment)+1]; 476 strcpy((*entry).comment, comment); 477 } 478 else 479 (*entry).comment = NULL; 480 481 429 (*entry).comment = comment; 482 430 } 483 431 … … 487 435 * @returns the queried Comment. 488 436 */ 489 const char* IniParser::getEntryComment(const char* entryName, const char*sectionName) const437 const std::string& IniParser::getEntryComment(const std::string& entryName, const std::string& sectionName) const 490 438 { 491 439 std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName); … … 501 449 { 502 450 if (!this->sections.empty() && 503 451 this->currentSection != this->sections.end()) 504 452 this->currentEntry = (*this->currentSection).entries.begin(); 505 453 } … … 530 478 * @returns the name of the Current selected Section 531 479 */ 532 const char*IniParser::getCurrentSection() const480 const std::string& IniParser::getCurrentSection() const 533 481 { 534 482 if (!this->sections.empty() && … … 536 484 return this->currentSection->name; 537 485 else 538 return NULL;539 486 return IniParser::emptyString ; 487 } 540 488 541 489 … … 543 491 * @returns the current entries Name, or NULL if we havn't selected a Entry 544 492 */ 545 const char*IniParser::getCurrentName() const546 { 547 if (!this->sections.empty() &&548 this->currentSection != this->sections.end() &&549 this->currentEntry != (*this->currentSection).entries.end())550 return (*this->currentEntry).name;551 else552 return NULL;493 const std::string& IniParser::getCurrentName() const 494 { 495 if (!this->sections.empty() && 496 this->currentSection != this->sections.end() && 497 this->currentEntry != (*this->currentSection).entries.end()) 498 return (*this->currentEntry).name; 499 else 500 return emptyString; 553 501 } 554 502 … … 556 504 * @returns the current entries Value, or NULL if we havn't selected a Entry 557 505 */ 558 const char*IniParser::getCurrentValue() const506 const std::string& IniParser::getCurrentValue() const 559 507 { 560 508 if (!this->sections.empty() && … … 563 511 return (*this->currentEntry).value; 564 512 else 565 return NULL;513 return IniParser::emptyString; 566 514 } 567 515 … … 571 519 * @param sectionName the Name of the Section to get the Iterator from 572 520 */ 573 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char*sectionName) const521 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const std::string& sectionName) const 574 522 { 575 523 std::list<IniSection>::const_iterator section = this->currentSection; 576 if (sectionName == NULL)524 if (sectionName.empty()) 577 525 return this->currentSection; 578 526 else 579 527 for (section = this->sections.begin(); section != this->sections.end(); section++) 580 if ( !strcmp((*section).name, sectionName))528 if ((*section).name == sectionName) 581 529 break; 582 530 return section; … … 588 536 * @param sectionName the Name of the Section to get the Iterator from 589 537 */ 590 std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const char*sectionName)538 std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const std::string& sectionName) 591 539 { 592 540 std::list<IniSection>::iterator section = this->currentSection; 593 if (sectionName == NULL)541 if (sectionName.empty()) 594 542 return this->currentSection; 595 543 else 596 544 for (section = this->sections.begin(); section != this->sections.end(); section++) 597 if ( !strcmp((*section).name, sectionName))545 if ((*section).name == sectionName) 598 546 break; 599 547 return section; … … 606 554 * @param sectionName the Name of the Section to get the Iterator from 607 555 */ 608 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char*sectionName) const609 { 610 if (entryName == NULL)556 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName) const 557 { 558 if (entryName.empty()) 611 559 return this->currentEntry; 612 560 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); … … 615 563 if (section != this->sections.end()) 616 564 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 617 if ( !strcmp((*entry).name, entryName))565 if ((*entry).name == entryName) 618 566 break; 619 567 if (entry == (*section).entries.end()) … … 629 577 * @param sectionName the Name of the Section to get the Iterator from 630 578 */ 631 std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const char* entryName, const char*sectionName)632 { 633 if (entryName == NULL)579 std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName) 580 { 581 if (entryName.empty()) 634 582 return this->currentEntry; 635 583 std::list<IniSection>::iterator section = this->getSectionIT(sectionName); … … 638 586 if (section != this->sections.end()) 639 587 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 640 if ( !strcmp((*entry).name, entryName))588 if ((*entry).name == entryName) 641 589 break; 642 590 if (entry == (*section).entries.end()) … … 652 600 void IniParser::setFileComment() 653 601 { 654 if (this->comment != NULL) 655 delete[] this->comment; 656 657 if (this->commentList.empty()) { 658 this->comment = NULL; 602 if (this->commentList.empty()) 603 { 604 this->comment = ""; 659 605 return; 660 606 } 661 607 662 unsigned int stringLength = 1;663 608 std::list<char*>::iterator comment; 664 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 665 stringLength += strlen((*comment)) +1; 666 667 this->comment = new char[stringLength]; 668 this->comment[0] = '\0'; 609 669 610 while (!this->commentList.empty()) 670 611 { 671 if (*this->comment != '\0') 672 strcat(this->comment, "\n"); 673 strcat(this->comment, this->commentList.front()); 674 delete[] this->commentList.front(); 612 if (this->comment[0] != '\0') 613 this->comment += "\n"; 614 this->comment += this->commentList.front(); 675 615 this->commentList.pop_front(); 676 616 } … … 682 622 void IniParser::setSectionComment() 683 623 { 684 if ((*this->currentSection).comment != NULL) 685 delete[] (*this->currentSection).comment; 686 687 if (this->commentList.empty()) { 688 (*this->currentSection).comment = NULL; 624 (*this->currentSection).comment = ""; 625 626 if (this->commentList.empty()) 689 627 return; 690 } 691 692 unsigned int stringLength = 1; 693 std::list<char*>::iterator comment; 694 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 695 stringLength += strlen((*comment)) +1; 696 697 (*this->currentSection).comment = new char[stringLength]; 698 (*this->currentSection).comment[0] = '\0'; 628 699 629 while (!this->commentList.empty()) 700 630 { 701 if (*(*this->currentSection).comment != '\0') 702 strcat((*this->currentSection).comment, "\n"); 703 strcat((*this->currentSection).comment, this->commentList.front()); 704 delete[] this->commentList.front(); 631 if ((*this->currentSection).comment[0] != '\0') 632 (*this->currentSection).comment += "\n"; 633 (*this->currentSection).comment += this->commentList.front(); 705 634 this->commentList.pop_front(); 706 635 } … … 712 641 void IniParser::setEntryComment() 713 642 { 714 if ((*this->currentEntry).comment != NULL) 715 delete[] (*this->currentEntry).comment; 716 717 if (this->commentList.empty()) { 718 (*this->currentEntry).comment = NULL; 643 (*this->currentEntry).comment = ""; 644 if (this->commentList.empty()) 719 645 return; 720 } 721 722 unsigned int stringLength = 1; 723 std::list<char*>::iterator comment; 724 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 725 stringLength += strlen((*comment)) +1; 726 727 (*this->currentEntry).comment = new char[stringLength]; 728 (*this->currentEntry).comment[0] = '\0'; 646 729 647 while (!this->commentList.empty()) 730 648 { 731 if (*(*this->currentEntry).comment != '\0') 732 strcat((*this->currentEntry).comment, "\n"); 733 strcat((*this->currentEntry).comment, this->commentList.front()); 734 delete[] this->commentList.front(); 649 if ((*this->currentEntry).comment[0] != '\0') 650 (*this->currentEntry).comment += "\n"; 651 (*this->currentEntry).comment += this->commentList.front(); 735 652 this->commentList.pop_front(); 736 653 } 737 738 654 } 739 655 … … 744 660 void IniParser::debug() const 745 661 { 746 PRINTF(0)("Iniparser %s - debug\n", this->fileName );747 if ( this->comment != NULL)748 PRINTF(0)("FileComment:\n %s\n\n", this->comment );749 750 if ( this->fileName != NULL)662 PRINTF(0)("Iniparser %s - debug\n", this->fileName.c_str()); 663 if (!this->comment.empty()) 664 PRINTF(0)("FileComment:\n %s\n\n", this->comment.c_str()); 665 666 if (!this->fileName.empty()) 751 667 { 752 668 std::list<IniSection>::const_iterator section; 753 669 for (section = this->sections.begin(); section != this->sections.end(); section++) 754 670 { 755 if ( (*section).comment != NULL)756 PRINTF(0)(" %s\n", (*section).comment );757 PRINTF(0)(" [%s]\n", (*section).name );671 if (!(*section).comment.empty()) 672 PRINTF(0)(" %s\n", (*section).comment.c_str()); 673 PRINTF(0)(" [%s]\n", (*section).name.c_str()); 758 674 759 675 std::list<IniEntry>::const_iterator entry; 760 676 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 761 677 { 762 if ( (*entry).comment != NULL)763 PRINTF(0)(" %s\n", (*entry).comment );764 PRINTF(0)(" '%s' -> '%s'\n", (*entry).name , (*entry).value);678 if (!(*entry).comment.empty()) 679 PRINTF(0)(" %s\n", (*entry).comment.c_str()); 680 PRINTF(0)(" '%s' -> '%s'\n", (*entry).name.c_str(), (*entry).value.c_str()); 765 681 } 766 682 } -
trunk/src/lib/parser/ini_parser/ini_parser.h
r6981 r7221 15 15 16 16 #include <list> 17 #include <string> 17 18 18 19 //! ini-file parser … … 27 28 struct IniEntry 28 29 { 29 char*comment; //!< A Comment that is appendet to the Top of this Entry.30 char*name; //!< name of a given Entry31 char*value; //!< value of a given Entry30 std::string comment; //!< A Comment that is appendet to the Top of this Entry. 31 std::string name; //!< name of a given Entry 32 std::string value; //!< value of a given Entry 32 33 }; 33 34 … … 35 36 struct IniSection 36 37 { 37 char*comment; //!< A Comment that is appendet to the Top of this Section.38 char*name; //!< name of a given section38 std::string comment; //!< A Comment that is appendet to the Top of this Section. 39 std::string name; //!< name of a given section 39 40 std::list<IniEntry> entries; //!< a list of entries for this section 40 41 }; … … 42 43 43 44 public: 44 IniParser (const char* filename = NULL);45 IniParser (const std::string& filename = ""); 45 46 virtual ~IniParser (); 46 47 47 48 /** @returns true if the file is opened, false otherwise*/ 48 bool isOpen() const { return ( this->fileName != NULL)? true : false; };49 bool isOpen() const { return (!this->fileName.empty())? true : false; }; 49 50 /** @returns the fileName we have opened. */ 50 const char*getFileName() const { return this->fileName; };51 const std::string& getFileName() const { return this->fileName; }; 51 52 52 bool readFile(const char*fileName);53 bool writeFile(const char*fileName) const;53 bool readFile(const std::string& fileName); 54 bool writeFile(const std::string& fileName) const; 54 55 55 void setFileComment(const char*fileComment);56 const char*getFileComment() const { return this->comment; };56 void setFileComment(const std::string& fileComment); 57 const std::string& getFileComment() const { return this->comment; }; 57 58 58 bool addSection(const char*sectionName);59 bool getSection(const char*sectionName);60 void setSectionComment(const char* comment, const char*sectionName);61 const char* getSectionComment(const char*sectionNane) const;59 bool addSection(const std::string& sectionName); 60 bool getSection(const std::string& sectionName); 61 void setSectionComment(const std::string& comment, const std::string& sectionName); 62 const std::string& getSectionComment(const std::string& sectionNane) const; 62 63 63 64 // iterate through sections with these Functions 64 65 void firstSection(); 65 const char*nextSection();66 const std::string& nextSection(); 66 67 67 68 68 bool addVar(const char* entryName, const char* value, const char* sectionName = NULL);69 const char* getVar(const char* entryName, const char* sectionName, const char*defaultValue = "") const;70 void setEntryComment(const char* comment, const char* entryName, const char*sectionName);71 const char* getEntryComment(const char* entryName, const char*sectionName) const;69 bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" ); 70 const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const; 71 void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName); 72 const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const; 72 73 73 74 // iterate Through Variables with these Functions. … … 77 78 78 79 // retrieving functions when iterating. 79 const char*getCurrentSection() const;80 const char*getCurrentName() const;81 const char*getCurrentValue() const;80 const std::string& getCurrentSection() const; 81 const std::string& getCurrentName() const; 82 const std::string& getCurrentValue() const; 82 83 83 84 … … 88 89 private: 89 90 void deleteSections(); 90 void setFileName(const char*fileName);91 void setFileName(const std::string& fileName); 91 92 92 93 void setFileComment(); … … 94 95 void setEntryComment(); 95 96 96 std::list<IniSection>::const_iterator getSectionIT(const char*sectionName) const;97 std::list<IniSection>::iterator getSectionIT(const char*sectionName);97 std::list<IniSection>::const_iterator getSectionIT(const std::string& sectionName) const; 98 std::list<IniSection>::iterator getSectionIT(const std::string& sectionName); 98 99 99 std::list<IniEntry>::const_iterator getEntryIT(const char* entryName, const char* sectionName = NULL) const;100 std::list<IniEntry>::iterator getEntryIT(const char* entryName, const char* sectionName = NULL);100 std::list<IniEntry>::const_iterator getEntryIT(const std::string& entryName, const std::string& sectionName = "") const; 101 std::list<IniEntry>::iterator getEntryIT(const std::string& entryName, const std::string& sectionName = ""); 101 102 102 103 private: 103 char*fileName; //!< The name of the File that was parsed.104 char*comment; //!< A Comment for the header of this File.104 std::string fileName; //!< The name of the File that was parsed. 105 std::string comment; //!< A Comment for the header of this File. 105 106 std::list<IniSection> sections; //!< a list of all stored Sections of the Parser 106 107 std::list<IniSection>::iterator currentSection; //!< the current selected Section 107 108 std::list<IniEntry>::iterator currentEntry; //!< the current selected entry (in currentSection) 108 109 109 std::list<char*> commentList; //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.) 110 std::list<std::string> commentList; //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.) 111 112 113 static const std::string emptyString; 110 114 }; 111 115 -
trunk/src/lib/parser/tinyxml/tinyxml.h
r5819 r7221 26 26 #ifndef TINYXML_INCLUDED 27 27 #define TINYXML_INCLUDED 28 29 #define TIXML_USE_STL 28 30 29 31 #ifdef _MSC_VER … … 81 83 #define TIXML_SNSCANF snscanf 82 84 #endif 83 #endif 85 #endif 84 86 85 87 class TiXmlDocument; … … 96 98 const int TIXML_PATCH_VERSION = 2; 97 99 98 /* Internal structure for tracking location of items 100 /* Internal structure for tracking location of items 99 101 in the XML file. 100 102 */ … … 110 112 111 113 // Only used by Attribute::Query functions 112 enum 113 { 114 enum 115 { 114 116 TIXML_SUCCESS, 115 117 TIXML_NO_ATTRIBUTE, … … 162 164 /** All TinyXml classes can print themselves to a filestream. 163 165 This is a formatted print, and will insert tabs and newlines. 164 166 165 167 (For an unformatted stream, use the << operator.) 166 168 */ … … 206 208 static const int utf8ByteTable[256]; 207 209 208 virtual const char* Parse( const char* p, 209 TiXmlParsingData* data, 210 virtual const char* Parse( const char* p, 211 TiXmlParsingData* data, 210 212 TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; 211 213 … … 245 247 246 248 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); 247 inline static bool IsWhiteSpace( char c ) 248 { 249 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 249 inline static bool IsWhiteSpace( char c ) 250 { 251 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 250 252 } 251 253 … … 334 336 /// Field containing a generic user pointer 335 337 void* userData; 336 338 337 339 // None of these methods are reliable for any language except English. 338 340 // Good for approximation, not great for accuracy. … … 386 388 387 389 public: 388 #ifdef TIXML_USE_STL 390 #ifdef TIXML_USE_STL 389 391 390 392 /** An input stream operator, for every class. Tolerant of newlines and … … 400 402 a node to a stream is very well defined. You'll get a nice stream 401 403 of output, without any extra whitespace or newlines. 402 404 403 405 But reading is not as well defined. (As it always is.) If you create 404 406 a TiXmlElement (for example) and read that from an input stream, … … 408 410 A TiXmlDocument will read nodes until it reads a root element, and 409 411 all the children of that root element. 410 */ 412 */ 411 413 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); 412 414 … … 470 472 #ifdef TIXML_USE_STL 471 473 /// STL std::string form. 472 void SetValue( const std::string& _value ) 473 { 474 void SetValue( const std::string& _value ) 475 { 474 476 StringToBuffer buf( _value ); 475 SetValue( buf.buffer ? buf.buffer : "" ); 476 } 477 SetValue( buf.buffer ? buf.buffer : "" ); 478 } 477 479 #endif 478 480 … … 492 494 TiXmlNode* LastChild() { return lastChild; } 493 495 const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. 494 TiXmlNode* LastChild( const char * value ); 496 TiXmlNode* LastChild( const char * value ); 495 497 496 498 #ifdef TIXML_USE_STL … … 649 651 650 652 /** Create an exact duplicate of this node and return it. The memory must be deleted 651 by the caller. 653 by the caller. 652 654 */ 653 655 virtual TiXmlNode* Clone() const = 0; … … 731 733 /** QueryIntValue examines the value string. It is an alternative to the 732 734 IntValue() method with richer error checking. 733 If the value is an integer, it is stored in 'value' and 735 If the value is an integer, it is stored in 'value' and 734 736 the call returns TIXML_SUCCESS. If it is not 735 737 an integer, it returns TIXML_WRONG_TYPE. … … 750 752 #ifdef TIXML_USE_STL 751 753 /// STL std::string form. 752 void SetName( const std::string& _name ) 753 { 754 void SetName( const std::string& _name ) 755 { 754 756 StringToBuffer buf( _name ); 755 SetName ( buf.buffer ? buf.buffer : "error" ); 756 } 757 /// STL std::string form. 758 void SetValue( const std::string& _value ) 759 { 757 SetName ( buf.buffer ? buf.buffer : "error" ); 758 } 759 /// STL std::string form. 760 void SetValue( const std::string& _value ) 761 { 760 762 StringToBuffer buf( _value ); 761 SetValue( buf.buffer ? buf.buffer : "error" ); 763 SetValue( buf.buffer ? buf.buffer : "error" ); 762 764 } 763 765 #endif … … 801 803 /* A class used to manage a group of attributes. 802 804 It is only used internally, both by the ELEMENT and the DECLARATION. 803 805 804 806 The set can be changed transparent to the Element and Declaration 805 807 classes that use it, but NOT transparent to the Attribute … … 882 884 /** QueryIntAttribute examines the attribute - it is an alternative to the 883 885 Attribute() method with richer error checking. 884 If the attribute is an integer, it is stored in 'value' and 886 If the attribute is an integer, it is stored in 'value' and 885 887 the call returns TIXML_SUCCESS. If it is not 886 888 an integer, it returns TIXML_WRONG_TYPE. If the attribute 887 889 does not exist, then TIXML_NO_ATTRIBUTE is returned. 888 */ 890 */ 889 891 int QueryIntAttribute( const char* name, int* _value ) const; 890 892 /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). … … 913 915 914 916 /// STL std::string form. 915 void SetAttribute( const std::string& name, const std::string& _value ) 916 { 917 void SetAttribute( const std::string& name, const std::string& _value ) 918 { 917 919 StringToBuffer n( name ); 918 920 StringToBuffer v( _value ); 919 921 if ( n.buffer && v.buffer ) 920 SetAttribute (n.buffer, v.buffer ); 921 } 922 SetAttribute (n.buffer, v.buffer ); 923 } 922 924 ///< STL std::string form. 923 void SetAttribute( const std::string& name, int _value ) 924 { 925 void SetAttribute( const std::string& name, int _value ) 926 { 925 927 StringToBuffer n( name ); 926 928 if ( n.buffer ) 927 SetAttribute (n.buffer, _value); 928 } 929 SetAttribute (n.buffer, _value); 930 } 929 931 #endif 930 932 … … 954 956 and concise, GetText() is limited compared to getting the TiXmlText child 955 957 and accessing it directly. 956 958 957 959 If the first child of 'this' is a TiXmlText, the GetText() 958 960 returns the character string of the Text node, else null is returned. … … 964 966 @endverbatim 965 967 966 'str' will be a pointer to "This is text". 967 968 'str' will be a pointer to "This is text". 969 968 970 Note that this function can be misleading. If the element foo was created from 969 971 this XML: 970 972 @verbatim 971 <foo><b>This is text</b></foo> 973 <foo><b>This is text</b></foo> 972 974 @endverbatim 973 975 … … 975 977 another element. From this XML: 976 978 @verbatim 977 <foo>This is <b>text</b></foo> 979 <foo>This is <b>text</b></foo> 978 980 @endverbatim 979 981 GetText() will return "This is ". 980 982 981 WARNING: GetText() accesses a child node - don't become confused with the 982 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 983 WARNING: GetText() accesses a child node - don't become confused with the 984 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 983 985 safe type casts on the referenced node. 984 986 */ … … 1054 1056 1055 1057 1056 /** XML text. A text node can have 2 ways to output the next. "normal" output 1058 /** XML text. A text node can have 2 ways to output the next. "normal" output 1057 1059 and CDATA. It will default to the mode it was parsed from the XML file and 1058 you generally want to leave it alone, but you can change the output mode with 1060 you generally want to leave it alone, but you can change the output mode with 1059 1061 SetCDATA() and query it with CDATA(). 1060 1062 */ … … 1063 1065 friend class TiXmlElement; 1064 1066 public: 1065 /** Constructor for text element. By default, it is treated as 1067 /** Constructor for text element. By default, it is treated as 1066 1068 normal, encoded text. If you want it be output as a CDATA text 1067 1069 element, set the parameter _cdata to 'true' … … 1279 1281 - The ErrorDesc() method will return the name of the error. (very useful) 1280 1282 - The ErrorRow() and ErrorCol() will return the location of the error (if known) 1281 */ 1283 */ 1282 1284 bool Error() const { return error; } 1283 1285 … … 1290 1292 int ErrorId() const { return errorId; } 1291 1293 1292 /** Returns the location (if known) of the error. The first column is column 1, 1294 /** Returns the location (if known) of the error. The first column is column 1, 1293 1295 and the first row is row 1. A value of 0 means the row and column wasn't applicable 1294 1296 (memory errors, for example, have no row/column) or the parser lost the error. (An … … 1303 1305 to report the correct values for row and column. It does not change the output 1304 1306 or input in any way. 1305 1307 1306 1308 By calling this method, with a tab size 1307 1309 greater than 0, the row and column of each node and attribute is stored … … 1331 1333 state is automatically cleared if you Parse a new XML block. 1332 1334 */ 1333 void ClearError() { error = false; 1334 errorId = 0; 1335 errorDesc = ""; 1336 errorLocation.row = errorLocation.col = 0; 1337 //errorLocation.last = 0; 1335 void ClearError() { error = false; 1336 errorId = 0; 1337 errorDesc = ""; 1338 errorLocation.row = errorLocation.col = 0; 1339 //errorLocation.last = 0; 1338 1340 } 1339 1341 … … 1381 1383 @endverbatim 1382 1384 1383 Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 1385 Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 1384 1386 easy to write a *lot* of code that looks like: 1385 1387 … … 1401 1403 1402 1404 And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity 1403 of such code. A TiXmlHandle checks for null pointers so it is perfectly safe 1405 of such code. A TiXmlHandle checks for null pointers so it is perfectly safe 1404 1406 and correct to use: 1405 1407 … … 1422 1424 1423 1425 @verbatim 1424 int i=0; 1426 int i=0; 1425 1427 while ( true ) 1426 1428 { … … 1433 1435 @endverbatim 1434 1436 1435 It seems reasonable, but it is in fact two embedded while loops. The Child method is 1436 a linear walk to find the element, so this code would iterate much more than it needs 1437 It seems reasonable, but it is in fact two embedded while loops. The Child method is 1438 a linear walk to find the element, so this code would iterate much more than it needs 1437 1439 to. Instead, prefer: 1438 1440 … … 1464 1466 TiXmlHandle FirstChildElement( const char * value ) const; 1465 1467 1466 /** Return a handle to the "index" child with the given name. 1468 /** Return a handle to the "index" child with the given name. 1467 1469 The first child is 0, the second 1, etc. 1468 1470 */ 1469 1471 TiXmlHandle Child( const char* value, int index ) const; 1470 /** Return a handle to the "index" child. 1472 /** Return a handle to the "index" child. 1471 1473 The first child is 0, the second 1, etc. 1472 1474 */ 1473 1475 TiXmlHandle Child( int index ) const; 1474 /** Return a handle to the "index" child element with the given name. 1476 /** Return a handle to the "index" child element with the given name. 1475 1477 The first child element is 0, the second 1, etc. Note that only TiXmlElements 1476 1478 are indexed: other types are not counted. 1477 1479 */ 1478 1480 TiXmlHandle ChildElement( const char* value, int index ) const; 1479 /** Return a handle to the "index" child element. 1481 /** Return a handle to the "index" child element. 1480 1482 The first child element is 0, the second 1, etc. Note that only TiXmlElements 1481 1483 are indexed: other types are not counted. … … 1492 1494 1493 1495 /// Return the handle as a TiXmlNode. This may return null. 1494 TiXmlNode* Node() const { return node; } 1496 TiXmlNode* Node() const { return node; } 1495 1497 /// Return the handle as a TiXmlElement. This may return null. 1496 1498 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } -
trunk/src/lib/particles/dot_particles.h
r6652 r7221 21 21 virtual void loadParams(const TiXmlElement* root); 22 22 23 void setMaterialTexture(const char*textureFile);23 void setMaterialTexture(const std::string& textureFile); 24 24 25 25 /** @returns the Material that lies on this particles */ -
trunk/src/lib/particles/model_particles.cc
r7198 r7221 89 89 * @param textureFile the Texture to load onto these ModelParticles 90 90 */ 91 void ModelParticles::setMaterialTexture(const char*textureFile)91 void ModelParticles::setMaterialTexture(const std::string& textureFile) 92 92 { 93 93 this->material.setDiffuseMap(textureFile); -
trunk/src/lib/particles/model_particles.h
r6629 r7221 20 20 virtual void loadParams(const TiXmlElement* root); 21 21 22 void setMaterialTexture(const char*textureFile);22 void setMaterialTexture(const std::string& textureFile); 23 23 24 24 /** @returns the Material that lies on this particles */ -
trunk/src/lib/particles/particle_system.cc
r7199 r7221 485 485 void ParticleSystem::debug() const 486 486 { 487 PRINT(0)(" ParticleCount: %d emitters: %d, maximumCount: %d :: filled %d%%\n", this->count, this->emitters.size(), this->maxCount, 100*this->count/this->maxCount);487 PRINT(0)(" ParticleCount: %d emitters: %d, maximumCount: %d :: filled %d%%\n", this->count, this->emitters.size(), this->maxCount, ((this->maxCount!=0)?100*this->count/this->maxCount:0)); 488 488 if (deadList) 489 489 { -
trunk/src/lib/particles/spark_particles.cc
r7193 r7221 68 68 { 69 69 this->setClassID(CL_SPARK_PARTICLES, "SparkParticles"); 70 71 this->material = NULL;72 70 } 73 71 -
trunk/src/lib/particles/sprite_particles.cc
r7198 r7221 89 89 * @param textureFile the Texture to load onto these SpriteParticles 90 90 */ 91 void SpriteParticles::setMaterialTexture(const char*textureFile)91 void SpriteParticles::setMaterialTexture(const std::string& textureFile) 92 92 { 93 93 this->material.setDiffuseMap(textureFile); -
trunk/src/lib/particles/sprite_particles.h
r6626 r7221 21 21 virtual void loadParams(const TiXmlElement* root); 22 22 23 void setMaterialTexture(const char*textureFile);23 void setMaterialTexture(const std::string& textureFile); 24 24 25 25 /** @returns the Material that lies on this particles */ -
trunk/src/lib/physics/physics_connection.cc
r7193 r7221 73 73 * @param subjectName the name of the Subject for this PhysicsConnection 74 74 */ 75 void PhysicsConnection::setSubject(const char*subjectName)75 void PhysicsConnection::setSubject(const std::string& subjectName) 76 76 { 77 77 this->subject = PhysicsEngine::getInstance()->getPhysicsInterfaceByName(subjectName); 78 78 if (this->subject == NULL) 79 79 { 80 PRINTF(2)("subject: (%s) not found for PhysicsConnection\n", subjectName );80 PRINTF(2)("subject: (%s) not found for PhysicsConnection\n", subjectName.c_str()); 81 81 } 82 82 else … … 87 87 * @param fieldName the Name of the Field for this connection 88 88 */ 89 void PhysicsConnection::setField(const char*fieldName)89 void PhysicsConnection::setField(const std::string& fieldName) 90 90 { 91 91 this->field = PhysicsEngine::getInstance()->getFieldByName(fieldName); 92 92 if (this->field == NULL) 93 93 { 94 PRINTF(2)("field: (%s) not found for PhysicsConnection\n", fieldName);94 PRINTF(2)("field: (%s) not found for PhysicsConnection\n", fieldName.c_str()); 95 95 } 96 96 else -
trunk/src/lib/physics/physics_connection.h
r5257 r7221 35 35 virtual ~PhysicsConnection(); 36 36 37 void setSubject(const char*subjectName);38 void setField(const char*fieldName);37 void setSubject(const std::string& subjectName); 38 void setField(const std::string& fieldName); 39 39 40 40 void apply() const; -
trunk/src/lib/physics/physics_engine.cc
r7193 r7221 128 128 @returns the PhysicsInterface if found, or NULL if not 129 129 */ 130 PhysicsInterface* PhysicsEngine::getPhysicsInterfaceByName(const char*physicsInterfaceName) const130 PhysicsInterface* PhysicsEngine::getPhysicsInterfaceByName(const std::string& physicsInterfaceName) const 131 131 { 132 132 BaseObject* interface = ClassList::getObject(physicsInterfaceName, CL_PHYSICS_INTERFACE); … … 157 157 158 158 /** 159 * @param FieldName the Name of the PhysicsInterface to search for159 * @param fieldName the Name of the PhysicsInterface to search for 160 160 @returns the Field if found, or NULL if not 161 161 */ 162 Field* PhysicsEngine::getFieldByName(const char* FieldName) const162 Field* PhysicsEngine::getFieldByName(const std::string& fieldName) const 163 163 { 164 164 list<Field*>::const_iterator field; 165 165 for (field = this->fields.begin(); field != this->fields.end(); field++) 166 if ( !strcmp(FieldName, (*field)->getName()))166 if (fieldName == (*field)->getName()) 167 167 return (*field); 168 168 return NULL; … … 197 197 @returns the PhysicsConnection if found, or NULL if not 198 198 */ 199 PhysicsConnection* PhysicsEngine::getPhysicsConnectionByName(const char*physicsConnectionName) const199 PhysicsConnection* PhysicsEngine::getPhysicsConnectionByName(const std::string& physicsConnectionName) const 200 200 { 201 201 list<PhysicsConnection*>::const_iterator pc; 202 202 for (pc = this->connections.begin(); pc != this->connections.end(); pc++) 203 if ( !strcmp(physicsConnectionName, (*pc)->getName()))203 if (physicsConnectionName == (*pc)->getName()) 204 204 delete (*pc); 205 205 return NULL; -
trunk/src/lib/physics/physics_engine.h
r6512 r7221 31 31 void loadConnections(const TiXmlElement* root); 32 32 33 PhysicsInterface* getPhysicsInterfaceByName(const char*physicsInterfaceName) const;33 PhysicsInterface* getPhysicsInterfaceByName(const std::string& physicsInterfaceName) const; 34 34 35 35 void addField(Field* field); 36 36 void removeField(Field* field); 37 Field* getFieldByName(const char* FieldName) const;37 Field* getFieldByName(const std::string& fieldName) const; 38 38 39 39 void addConnection(PhysicsConnection* connection); 40 40 void removeConnection(PhysicsConnection* connection); 41 PhysicsConnection* getPhysicsConnectionByName(const char*physicsConnectionName) const;41 PhysicsConnection* getPhysicsConnectionByName(const std::string& physicsConnectionName) const; 42 42 43 43 -
trunk/src/lib/shell/shell.cc
r7198 r7221 85 85 this->lineSpacing = 0; 86 86 this->bActive = true; 87 this->fontFile = new char[strlen(SHELL_DEFAULT_FONT)+1]; 88 strcpy(this->fontFile, SHELL_DEFAULT_FONT); 87 this->fontFile = SHELL_DEFAULT_FONT; 89 88 90 89 … … 110 109 delete this->bufferText[i]; 111 110 delete[] this->bufferText; 112 delete[] this->fontFile;113 111 // delete the inputLine 114 112 delete this->shellInput; … … 139 137 if (!top) 140 138 { 141 this->bufferText[i]->setText((*textLine) , true);139 this->bufferText[i]->setText((*textLine)); 142 140 if (textLine != ShellBuffer::getInstance()->getBuffer()->begin()) 143 141 top = true; … … 167 165 if (textLine != ShellBuffer::getInstance()->getBuffer()->begin()) 168 166 { 169 this->bufferText[i]->setText((*textLine) , false);167 this->bufferText[i]->setText((*textLine)); 170 168 textLine--; 171 169 } … … 181 179 * (be aware that within orxonox fontFile is relative to the Data-Dir) 182 180 */ 183 void Shell::setFont(const char*fontFile)181 void Shell::setFont(const std::string& fontFile) 184 182 { 185 183 // if (!ResourceManager::isInDataDir(fontFile)) 186 184 // return false; 187 185 188 if (this->fontFile != NULL) 189 delete[] this->fontFile; 190 191 this->fontFile = new char[strlen(fontFile)+1]; 192 strcpy(this->fontFile, fontFile); 186 this->fontFile = fontFile; 193 187 194 188 this->rebuildText(); … … 245 239 * @param fileName the filename of the Image to load 246 240 */ 247 void Shell::setBackgroundImage(const char*fileName)241 void Shell::setBackgroundImage(const std::string& fileName) 248 242 { 249 243 this->backgroundMaterial->setDiffuseMap(fileName); … … 340 334 for (int i = 0; i < this->bufferDisplaySize; i++) 341 335 { 342 this->bufferText[i]->setText( NULL, true);336 this->bufferText[i]->setText(""); 343 337 } 344 338 … … 351 345 * @param text the text to output. 352 346 */ 353 void Shell::printToDisplayBuffer(const char*text)347 void Shell::printToDisplayBuffer(const std::string& text) 354 348 { 355 349 if(likely(bufferText != NULL)) … … 382 376 this->bufferText[0] = lastText; 383 377 384 this->bufferText[0]->setText(text , true);378 this->bufferText[0]->setText(text); 385 379 } 386 380 } … … 427 421 for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 428 422 { 429 this->bufferText[i]->setText((*it) , false);423 this->bufferText[i]->setText((*it)); 430 424 it--; 431 425 } -
trunk/src/lib/shell/shell.h
r5784 r7221 53 53 inline bool isActive() const { return this->bActive; }; 54 54 55 void setFont(const char*fontFile);55 void setFont(const std::string& fontFile); 56 56 void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); 57 57 void setTextColor(float r, float g, float b, float a); 58 58 void setBackgroundColor(float r, float g, float b, float a); 59 void setBackgroundImage(const char*fileName);59 void setBackgroundImage(const std::string& fileName); 60 60 61 61 void resetValues(); … … 64 64 // BUFFERS 65 65 void setBufferDisplaySize(unsigned int bufferDisplaySize); 66 void printToDisplayBuffer(const char*text);66 void printToDisplayBuffer(const std::string& text); 67 67 void moveDisplayBuffer(int lineCount); 68 68 … … 83 83 84 84 // void testI (int i); 85 // void testS (const char*s);85 // void testS (const std::string& s); 86 86 // void testB (bool b); 87 87 // void testF (float f); 88 // void testSF (const char*s, float f);88 // void testSF (const std::string& s, float f); 89 89 90 90 private: … … 95 95 unsigned int textSize; //!< The size of the text. 96 96 float textColor[4]; //!< The text's color [r,g,b,a]. 97 char*fontFile; //!< The file containing the font.97 std::string fontFile; //!< The file containing the font. 98 98 Material* backgroundMaterial; //!< A material for the background. 99 99 -
trunk/src/lib/shell/shell_command.cc
r7201 r7221 41 41 PRINTF(5)("create shellcommand %s %s\n", commandName, className); 42 42 this->setName(commandName); 43 this->description = NULL;44 this->alias = NULL;45 43 this->executor = executor.clone(); 46 44 this->executor->setName(commandName); … … 153 151 * @return true on success, false otherwise. 154 152 */ 155 bool ShellCommand::execute(const char*executionString)153 bool ShellCommand::execute(const std::string& executionString) 156 154 { 157 155 if (ShellCommandClass::commandClassList == NULL) … … 177 175 for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++ ) 178 176 { 179 if ( (*alias)->getName() != NULL && !strcmp((*alias)->getName(), inputSplits.getString(0)) && (*alias)->getCommand() != NULL &&177 if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL && 180 178 (*alias)->getCommand()->shellClass != NULL ) 181 179 { … … 184 182 { 185 183 if (inputSplits.getCount() > 1) 186 (*alias)->getCommand()->executor->execute(objectList->front(), executionString+inputSplits.getOffset(1)); 184 { 185 186 (*alias)->getCommand()->executor->execute(objectList->front(), executionString.substr(inputSplits.getOffset(1))); /// TODO CHECK IF OK 187 } 187 188 else 188 189 (*alias)->getCommand()->executor->execute(objectList->front(), ""); … … 198 199 for (commandClassIT = ShellCommandClass::commandClassList->begin(); commandClassIT != ShellCommandClass::commandClassList->end(); commandClassIT++) 199 200 { 200 if ((*commandClassIT)->getName() && !strcasecmp(inputSplits.getString(0), (*commandClassIT)->getName()))201 if ((*commandClassIT)->getName() && inputSplits.getString(0) == (*commandClassIT)->getName()) 201 202 { 202 203 //elemCL->getName(); … … 217 218 for (object = objectList->begin(); object != objectList->end(); object++) 218 219 { 219 if ((*object)->getName() != NULL && !strcasecmp((*object)->getName(), inputSplits.getString(1)))220 if ((*object)->getName() != NULL && inputSplits.getString(1) == (*object)->getName() ) 220 221 { 221 222 objectPointer = (*object); … … 235 236 for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++) 236 237 { 237 if ( !strcmp((*cmdIT)->getName(), inputSplits.getString(fktPos)))238 if (inputSplits.getString(fktPos) == (*cmdIT)->getName()) 238 239 { 239 240 if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective) 240 241 return false; 241 242 if (inputSplits.getCount() > fktPos+1) 242 (*cmdIT)->executor->execute(objectPointer, executionString +inputSplits.getOffset(fktPos +1));243 (*cmdIT)->executor->execute(objectPointer, executionString.substr(inputSplits.getOffset(fktPos +1))); /// TODO CHECK IF OK 243 244 else 244 245 (*cmdIT)->executor->execute(objectPointer, ""); … … 255 256 * @param description the description of the Given command 256 257 */ 257 ShellCommand* ShellCommand::describe(const char*description)258 ShellCommand* ShellCommand::describe(const std::string& description) 258 259 { 259 260 if (this == NULL) … … 326 327 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 327 328 { 328 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className , (*classIT)->commandList.size());329 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size()); 329 330 330 331 list<ShellCommand*>::iterator cmdIT; … … 335 336 /* for (unsigned int i = 0; i< elem->paramCount; i++) 336 337 printf("%s ", ShellCommand::paramToString(elem->parameters[i]));*/ 337 if ( (*cmdIT)->description != NULL)338 printf("- %s", (*cmdIT)->description);338 if (!(*cmdIT)->description.empty()) 339 printf("- %s", (*cmdIT)->description.c_str()); 339 340 printf("\n"); 340 341 -
trunk/src/lib/shell/shell_command.h
r7201 r7221 61 61 friend class ShellCommandClass; 62 62 public: 63 static bool execute (const char*executionString);63 static bool execute (const std::string& executionString); 64 64 65 ShellCommand* describe(const char*description);65 ShellCommand* describe(const std::string& description); 66 66 ShellCommand* setAlias(const char* alias); 67 67 ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, … … 89 89 ShellCommandAlias* alias; //!< An Alias for the Class. 90 90 91 const char*description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");91 std::string description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); 92 92 Executor* executor; //!< The Executor, that really executes the Function. 93 93 … … 100 100 public: 101 101 /** @returns the Name of the Alias. */ 102 const char*getName() const { return this->aliasName; };102 const std::string& getName() const { return this->aliasName; }; 103 103 /** @returns the Command, this Alias is asociated with */ 104 104 ShellCommand* getCommand() const { return this->command; }; … … 106 106 private: 107 107 /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */ 108 ShellCommandAlias(const char*aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };108 ShellCommandAlias(const std::string& aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; }; 109 109 110 110 private: 111 const char*aliasName; //!< the name of the Alias111 std::string aliasName; //!< the name of the Alias 112 112 ShellCommand* command; //!< a pointer to the command, this alias executes. 113 113 }; -
trunk/src/lib/shell/shell_command_class.cc
r5780 r7221 36 36 * @param className the Name of the command-class to create 37 37 */ 38 ShellCommandClass::ShellCommandClass(const char* className) 38 ShellCommandClass::ShellCommandClass(const std::string& className) 39 : className(className) 39 40 { 40 41 this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass"); 41 42 this->setName(className); 42 43 43 this->className = className;44 44 this->classID = CL_NULL; 45 45 … … 65 65 * @returns true on success, false otherwise 66 66 */ 67 bool ShellCommandClass::getCommandListOfClass(const char* className, std::list<const char*>* stringList)68 { 69 if (stringList == NULL || className == NULL)67 bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>* stringList) 68 { 69 if (stringList == NULL) 70 70 return false; 71 71 … … 73 73 for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++) 74 74 { 75 if ( !strcmp ((*elem)->getName(), className))75 if (className == (*elem)->getName()) 76 76 { 77 77 list<ShellCommand*>::iterator command; … … 88 88 * @returns true on success, false otherwise 89 89 */ 90 bool ShellCommandClass::getCommandListOfAlias(std::list< const char*>* stringList)90 bool ShellCommandClass::getCommandListOfAlias(std::list<std::string>* stringList) 91 91 { 92 92 if (stringList == NULL || ShellCommandClass::aliasList == NULL) … … 130 130 * @returns the CommandClass if found, NULL otherwise 131 131 */ 132 const ShellCommandClass* ShellCommandClass::isRegistered(const char*className)132 const ShellCommandClass* ShellCommandClass::isRegistered(const std::string& className) 133 133 { 134 134 if (ShellCommandClass::commandClassList == NULL) … … 138 138 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 139 139 { 140 if ( !strcmp(className, (*classIT)->className))140 if (className == (*classIT)->className) 141 141 { 142 142 if ((*classIT)->classID == CL_NULL) … … 154 154 * @returns the CommandClass if found, or a new CommandClass if not 155 155 */ 156 ShellCommandClass* ShellCommandClass::getCommandClass(const char*className)156 ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className) 157 157 { 158 158 if (ShellCommandClass::commandClassList == NULL) … … 162 162 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 163 163 { 164 if ( !strcmp(className, (*classIT)->className))164 if (className == (*classIT)->className) 165 165 { 166 166 return (*classIT); … … 186 186 * @param className: the Class of Commands to show help about 187 187 */ 188 void ShellCommandClass::help(const char* className) 189 { 190 if (className == NULL) 191 return; 188 void ShellCommandClass::help(const std::string& className) 189 { 192 190 if (likely(ShellCommandClass::commandClassList != NULL)) 193 191 { … … 195 193 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 196 194 { 197 if ( (*classIT)->className && !strcasecmp(className, (*classIT)->className))195 if (className == (*classIT)->className) 198 196 { 199 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className , (*classIT)->commandList.size());197 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size()); 200 198 list<ShellCommand*>::const_iterator cmdIT; 201 199 for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++) … … 205 203 /* for (unsigned int i = 0; i< elem->paramCount; i++) 206 204 PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));*/ 207 if ( (*cmdIT)->description != NULL)208 PRINT(0)("- %s", (*cmdIT)->description );205 if (!(*cmdIT)->description.empty()) 206 PRINT(0)("- %s", (*cmdIT)->description.c_str()); 209 207 PRINT(0)("\n"); 210 208 } … … 212 210 } 213 211 } 214 PRINTF(3)("Class %s not found in Command's classes\n", className );212 PRINTF(3)("Class %s not found in Command's classes\n", className.c_str()); 215 213 } 216 214 else -
trunk/src/lib/shell/shell_command_class.h
r6981 r7221 27 27 /** @returns the CommandClassList */ 28 28 static const std::list<ShellCommandClass*>* getCommandClassList() { return ShellCommandClass::commandClassList; }; 29 static bool getCommandListOfClass(const char* className, std::list<const char*>* stringList);30 static bool getCommandListOfAlias(std::list< const char*>* aliasList);29 static bool getCommandListOfClass(const std::string& className, std::list<std::string>* stringList); 30 static bool getCommandListOfAlias(std::list<std::string>* aliasList); 31 31 32 static ShellCommandClass* getCommandClass(const char*className);32 static ShellCommandClass* getCommandClass(const std::string& className); 33 33 static void unregisterAllCommands(); 34 34 35 static void help (const char*className);35 static void help (const std::string& className); 36 36 37 37 private: 38 ShellCommandClass(const char*className);38 ShellCommandClass(const std::string& className); 39 39 virtual ~ShellCommandClass(); 40 40 41 static const ShellCommandClass* isRegistered(const char*className);41 static const ShellCommandClass* isRegistered(const std::string& className); 42 42 static void initCommandClassList(); 43 43 44 44 private: 45 const char*className; //!< The Name of the Class. This should match the ClassName of the Commands Class.45 const std::string className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 46 46 long classID; //!< The classID of this Class 47 47 std::list<ShellCommand*> commandList; //!< A list of Commands from this Class -
trunk/src/lib/shell/shell_completion.cc
r5885 r7221 76 76 77 77 // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object 78 if (this->input->getInput() != NULL && 79 strrchr(this->input->getInput(), ' ') >= this->input->getInput() + strlen(this->input->getInput())-1) 78 if (this->input->getInput()[this->input->getInput().size()-1] == ' ') 80 79 { 81 80 emptyComplete = true; … … 83 82 84 83 // CREATE INPUTS 85 if (this->input->getInput() == NULL) 86 completionLine = ""; 87 else 88 completionLine = this->input->getInput() + strspn(this->input->getInput(), " \t\n"); 89 SubString inputSplits(completionLine, " \t\n,"); 84 SubString inputSplits(this->input->getInput(), " \t\n,"); 90 85 91 86 // What String will be completed … … 93 88 completeString = ""; 94 89 else 95 completeString = inputSplits.getString(inputSplits.getCount()-1) ;90 completeString = inputSplits.getString(inputSplits.getCount()-1).c_str(); 96 91 97 92 // CLASS COMPLETION … … 111 106 (inputSplits.getCount() == 2 && emptyComplete == false)) 112 107 { 113 classID = ClassList::StringToID(inputSplits.getString(0) );108 classID = ClassList::StringToID(inputSplits.getString(0).c_str()); //FIXME 114 109 objectList = ClassList::getList((ClassID)classID); 115 110 if (classID != CL_NULL) … … 121 116 (inputSplits.getCount() == 3 && emptyComplete == false)) 122 117 { 123 classID = ClassList::StringToID(inputSplits.getString(0) );118 classID = ClassList::StringToID(inputSplits.getString(0) .c_str()); // FIXME 124 119 if (classID == CL_NULL) 125 120 return false; … … 133 128 this->objectComplete(completeString, classID); 134 129 if (completeType & SHELLC_FUNCTION) 135 this->functionComplete(completeString, inputSplits.getString(0) );130 this->functionComplete(completeString, inputSplits.getString(0).c_str()); // FIXME 136 131 if (completeType & SHELLC_ALIAS) 137 132 this->aliasComplete(completeString); … … 151 146 if (unlikely(classBegin == NULL)) 152 147 return false; 153 const std::list< const char*>* clList = ClassList::getClassNames();148 const std::list<std::string>* clList = ClassList::getClassNames(); 154 149 if (clList != NULL) 155 150 { … … 195 190 if (unlikely(functionBegin == NULL)) 196 191 return false; 197 std::list< const char*> fktList;192 std::list<std::string> fktList; 198 193 ShellCommandClass::getCommandListOfClass(className, &fktList); 199 194 //printf("%s\n", boList->firstElement()->getName()); … … 212 207 if (unlikely(aliasBegin == NULL)) 213 208 return false; 214 std::list< const char*> aliasList;209 std::list<std::string> aliasList; 215 210 ShellCommandClass::getCommandListOfAlias(&aliasList); 216 211 //printf("%s\n", boList->firstElement()->getName()); … … 295 290 * !! The strings MUST NOT be deleted !! 296 291 */ 297 bool ShellCompletion::addToCompleteList(const std::list< const char*>* inputList, const char* completionBegin, SHELLC_TYPE type)292 bool ShellCompletion::addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type) 298 293 { 299 294 if (inputList == NULL || completionBegin == NULL) … … 301 296 unsigned int searchLength = strlen(completionBegin); 302 297 303 list< const char*>::const_iterator string;298 list<std::string>::const_iterator string; 304 299 for (string = inputList->begin(); string != inputList->end(); string++) 305 300 { 306 if ( strlen(*string) >= searchLength &&307 !strncasecmp(*string, completionBegin, searchLength))301 if ((*string).size() >= searchLength && 302 !strncasecmp((*string).c_str(), completionBegin, searchLength)) 308 303 { 309 304 ShellC_Element newElem; 310 newElem.name = *string;305 newElem.name = (*string).c_str(); 311 306 newElem.type = type; 312 307 this->completionList.push_back(newElem); -
trunk/src/lib/shell/shell_completion.h
r5784 r7221 52 52 bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); 53 53 54 bool addToCompleteList(const std::list< const char*>* inputList, const char* completionBegin, SHELLC_TYPE type);54 bool addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type); 55 55 bool addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type); 56 56 void emptyCompletionList(); -
trunk/src/lib/shell/shell_input.cc
r6222 r7221 41 41 * this also generates a ShellCompletion automatically. 42 42 */ 43 ShellInput::ShellInput () : Text ( (const char*)NULL)43 ShellInput::ShellInput () : Text ("") 44 44 { 45 45 this->pressedKey = SDLK_FIRST; 46 46 this->setClassID(CL_SHELL_INPUT, "ShellInput"); 47 47 48 this->inputLine = new char[1]; 49 this->inputLine[0] = '\0'; 48 this->inputLine = ""; 50 49 this->historyIT = this->history.begin(); 51 50 this->setHistoryLength(50); … … 70 69 { 71 70 // delete what has to be deleted here 72 delete[] this->inputLine;73 71 delete this->completion; 74 72 75 73 while (!this->history.empty()) 76 74 { 77 delete[] this->history.front();78 75 this->history.pop_front(); 79 76 } … … 96 93 void ShellInput::flush() 97 94 { 98 if (likely(this->inputLine != NULL)) 99 { 100 delete[] this->inputLine; 101 } 102 this->inputLine = new char[1]; 103 *this->inputLine = '\0'; 104 this->setText(this->inputLine, true); 95 this->inputLine.clear(); 96 this->setText(this->inputLine); 105 97 } 106 98 … … 109 101 * @param text the new Text to set as InputLine 110 102 */ 111 void ShellInput::setInputText(const char* text) 112 { 113 delete[] this->inputLine; 114 if (text == NULL) 115 { 116 this->inputLine = new char[1]; 117 this->inputLine[0] = '\0'; 118 } 119 else 120 { 121 this->inputLine = new char[strlen(text)+1]; 122 strcpy(this->inputLine, text); 123 } 124 this->setText(this->inputLine, true); 103 void ShellInput::setInputText(const std::string& text) 104 { 105 this->inputLine = text; 106 this->setText(this->inputLine); 125 107 } 126 108 … … 134 116 if (this->historyScrolling) 135 117 { 136 delete[] this->history.back();137 118 this->history.pop_back(); 138 119 this->historyScrolling = false; 139 120 } 140 121 141 char* addCharLine = new char[strlen(this->inputLine)+2]; 142 143 sprintf(addCharLine, "%s%c", this->inputLine, character); 144 delete[] this->inputLine; 145 this->inputLine = addCharLine; 146 this->setText(this->inputLine, true); 122 this->inputLine += character; 123 this->setText(this->inputLine); 147 124 } 148 125 … … 151 128 * @param characters a \\0 terminated char-array to add to the InputLine 152 129 */ 153 void ShellInput::addCharacters(const char*characters)130 void ShellInput::addCharacters(const std::string& characters) 154 131 { 155 132 if (this->historyScrolling) 156 133 { 157 delete[] this->history.back();158 134 this->history.pop_back(); 159 135 this->historyScrolling = false; 160 136 } 161 137 162 char* addCharLine = new char[strlen(this->inputLine)+strlen(characters)+1]; 163 164 sprintf(addCharLine, "%s%s", this->inputLine, characters); 165 delete[] this->inputLine; 166 this->inputLine = addCharLine; 167 this->setText(this->inputLine, true); 138 this->inputLine += characters; 139 this->setText(this->inputLine); 168 140 } 169 141 … … 176 148 if (this->historyScrolling) 177 149 { 178 delete[] this->history.back();179 150 this->history.pop_back(); 180 151 this->historyScrolling = false; 181 152 } 182 183 if (strlen(this->inputLine) == 0) 184 return; 185 186 if (characterCount > strlen(this->inputLine)) 187 characterCount = strlen(this->inputLine); 188 189 char* removeCharLine = new char[strlen(this->inputLine)-characterCount+1]; 190 191 strncpy(removeCharLine, this->inputLine, strlen(this->inputLine)-characterCount); 192 removeCharLine[strlen(this->inputLine)-characterCount] = '\0'; 193 delete[] this->inputLine; 194 this->inputLine = removeCharLine; 195 this->setText(this->inputLine, true); 153 if (this->inputLine.size() < characterCount) 154 characterCount = this->inputLine.size(); 155 156 this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size()); 157 this->setText(this->inputLine); 196 158 } 197 159 … … 202 164 bool ShellInput::executeCommand() 203 165 { 204 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine );205 206 if ( strlen(this->inputLine) == 0)166 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str()); 167 168 if (this->inputLine.empty()) 207 169 return false; 208 170 209 char* newCommand = new char[strlen(this->inputLine)+1]; 210 strcpy(newCommand, this->inputLine); 211 212 ShellCommand::execute(newCommand); 171 ShellCommand::execute(this->inputLine); 213 172 214 173 // removing the eventually added Entry (from scrolling) to the List 215 174 if (this->historyScrolling) 216 175 { 217 delete[] this->history.back();218 176 this->history.pop_back(); 219 177 this->historyScrolling = false; … … 221 179 222 180 // adding the new Command to the History 223 this->history.push_back( newCommand);181 this->history.push_back(this->inputLine); 224 182 if (this->history.size() > this->historyLength) 225 183 { 226 delete[] this->history.front();227 184 this->history.pop_front(); 228 185 } … … 241 198 if (!this->historyScrolling) 242 199 { 243 char* currentText = new char[strlen(this->inputLine)+1]; 244 strcpy(currentText, this->inputLine); 245 this->history.push_back(currentText); 200 this->history.push_back(this->inputLine); 246 201 this->historyScrolling = true; 247 202 this->historyIT = --this->history.end(); … … 250 205 if(this->historyIT != this->history.begin()) 251 206 { 252 char*prevElem = *(--this->historyIT);253 if (prevElem == NULL)207 std::string prevElem = *(--this->historyIT); 208 /*if (prevElem == NULL) /// TODO STD 254 209 return; 255 else 210 else */ 256 211 { 257 212 this->flush(); … … 270 225 if (this->historyIT != this->history.end()) 271 226 { 272 char*nextElem = *(++this->historyIT);273 if (nextElem == NULL)227 std::string nextElem = *(++this->historyIT); 228 /* if (nextElem == NULL) /// TODO FIX STD 274 229 return; 275 else 230 else */ 276 231 { 277 232 this->flush(); … … 285 240 * prints out some nice help about the Shell 286 241 */ 287 void ShellInput::help(const char* className, const char*functionName)288 { 289 printf("%s::%s\n", className , functionName);290 291 if ( strlen(className) == 0)242 void ShellInput::help(const std::string& className, const std::string& functionName) 243 { 244 printf("%s::%s\n", className.c_str(), functionName.c_str()); 245 246 if (className.empty()) 292 247 { 293 248 PRINT(0)("Help for the most important Shell-commands\n"); … … 298 253 PRINT(0)("- Also try 'help className'"); 299 254 } 300 else if ( strlen (className) > 0 && strlen (functionName) == 0)255 else if (!className.empty() && functionName.empty()) 301 256 { 302 257 ShellCommandClass::help(className); -
trunk/src/lib/shell/shell_input.h
r5786 r7221 31 31 32 32 /** @returns the inputLine */ 33 const char*getInput() const { return this->inputLine; };33 const std::string& getInput() const { return this->inputLine; }; 34 34 35 35 // InputLine 36 36 void flush(); 37 void setInputText(const char*text);37 void setInputText(const std::string& text); 38 38 void addCharacter(char character); 39 void addCharacters(const char*characters);39 void addCharacters(const std::string& characters); 40 40 void removeCharacters(unsigned int characterCount = 1); 41 41 void setRepeatDelay(float repeatDelay, float repeatRate); … … 47 47 void historyMoveDown(); 48 48 49 void help(const char* className = "", const char*function = "");49 void help(const std::string& className = "", const std::string& function = ""); 50 50 51 51 virtual void tick(float dt); … … 54 54 private: 55 55 // HANDLING TEXT INPUT 56 ShellCompletion* completion;//!< The Completion Interface.56 ShellCompletion* completion; //!< The Completion Interface. 57 57 58 char* inputLine;//!< the Char-Array of the Buffer59 float repeatRate;//!< The Repeat-Delay.60 float repeatDelay;//!< The delay of the first Character of a given Character.61 float delayed;//!< how much of the delay is remaining.62 Uint16 pressedKey;//!< the pressed key that will be repeated.58 std::string inputLine; //!< the Char-Array of the Buffer 59 float repeatRate; //!< The Repeat-Delay. 60 float repeatDelay; //!< The delay of the first Character of a given Character. 61 float delayed; //!< how much of the delay is remaining. 62 Uint16 pressedKey; //!< the pressed key that will be repeated. 63 63 64 std::list< char*> history;//!< The history of given commands.65 std::list< char*>::iterator historyIT;66 unsigned int historyLength;//!< The maximum length of the InputHistory.67 bool historyScrolling;//!< true if we are scrolling through the history.64 std::list<std::string> history; //!< The history of given commands. 65 std::list<std::string>::iterator historyIT; //!< The locator that tells us, where we are in the history. 66 unsigned int historyLength; //!< The maximum length of the InputHistory. 67 bool historyScrolling; //!< true if we are scrolling through the history. 68 68 }; 69 69 -
trunk/src/lib/sound/ogg_player.cc
r6987 r7221 31 31 * @param fileName the file to load 32 32 */ 33 OggPlayer::OggPlayer(const char*fileName)33 OggPlayer::OggPlayer(const std::string& fileName) 34 34 { 35 35 this->setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer"); … … 40 40 this->buffers[1] = 0; 41 41 42 if ( fileName != NULL)42 if (!fileName.empty()) 43 43 { 44 44 if (this->open(fileName)) … … 56 56 * @param fileName the file to open 57 57 */ 58 bool OggPlayer::open(const char*fileName)58 bool OggPlayer::open(const std::string& fileName) 59 59 { 60 60 if (this->buffers[0] == 0) … … 72 72 int result; 73 73 74 if(!(oggFile = fopen(fileName , "rb")))74 if(!(oggFile = fopen(fileName.c_str(), "rb"))) 75 75 { 76 76 PRINTF(2)("Could not open Ogg file."); -
trunk/src/lib/sound/ogg_player.h
r7054 r7221 27 27 { 28 28 public: 29 OggPlayer(const char* fileName = NULL);29 OggPlayer(const std::string& fileName = ""); 30 30 virtual ~OggPlayer(); 31 31 32 bool open(const char*fileName);32 bool open(const std::string& fileName); 33 33 void release(); 34 34 void debug(); -
trunk/src/lib/sound/sound_buffer.cc
r6836 r7221 32 32 * @param fileName The name of the File 33 33 */ 34 SoundBuffer::SoundBuffer(const char*fileName)34 SoundBuffer::SoundBuffer(const std::string& fileName) 35 35 { 36 36 this->setClassID(CL_SOUND_BUFFER, "SoundBuffer"); … … 54 54 * @returns true on success. 55 55 */ 56 bool SoundBuffer::loadWAV(const char*fileName)56 bool SoundBuffer::loadWAV(const std::string& fileName) 57 57 { 58 58 SDL_AudioSpec wavSpec; … … 61 61 62 62 /* Load the WAV */ 63 if( SDL_LoadWAV(fileName , &wavSpec, &wavBuffer, &wavLength) == NULL)63 if( SDL_LoadWAV(fileName.c_str(), &wavSpec, &wavBuffer, &wavLength) == NULL) 64 64 { 65 PRINTF(2)("Could not open %s: %s\n", fileName , SDL_GetError());65 PRINTF(2)("Could not open %s: %s\n", fileName.c_str(), SDL_GetError()); 66 66 return false; 67 67 } -
trunk/src/lib/sound/sound_buffer.h
r6981 r7221 17 17 { 18 18 public: 19 SoundBuffer(const char*fileName);19 SoundBuffer(const std::string& fileName); 20 20 virtual ~SoundBuffer(); 21 21 22 bool loadWAV(const char*fileName);22 bool loadWAV(const std::string& fileName); 23 23 24 24 /** @returns the ID of the buffer used in this SoundBuffer */ -
trunk/src/lib/sound/sound_engine.cc
r7193 r7221 99 99 void SoundEngine::loadSettings(IniParser* iniParser) 100 100 { 101 const char*channels = iniParser->getVar(CONFIG_NAME_AUDIO_CHANNELS, CONFIG_SECTION_AUDIO, "32");102 this->maxSourceCount = atoi(channels);103 104 const char*effectsVolume = iniParser->getVar(CONFIG_NAME_EFFECTS_VOLUME, CONFIG_SECTION_AUDIO, "80");105 this->effectsVolume = atof(effectsVolume)/100.0;106 107 const char*musicVolume = iniParser->getVar(CONFIG_NAME_MUSIC_VOLUME, CONFIG_SECTION_AUDIO, "75");108 this->musicVolume = atof(musicVolume)/100.0;101 MultiType channels = iniParser->getVar(CONFIG_NAME_AUDIO_CHANNELS, CONFIG_SECTION_AUDIO, "32"); 102 this->maxSourceCount = channels.getInt(); 103 104 MultiType effectsVolume = iniParser->getVar(CONFIG_NAME_EFFECTS_VOLUME, CONFIG_SECTION_AUDIO, "80"); 105 this->effectsVolume = effectsVolume.getFloat()/100.0; 106 107 MultiType musicVolume = iniParser->getVar(CONFIG_NAME_MUSIC_VOLUME, CONFIG_SECTION_AUDIO, "75"); 108 this->musicVolume = musicVolume.getFloat()/100.0; 109 109 } 110 110 … … 117 117 acctualy this is nothing more than a wrapper around the ResourceManager. 118 118 */ 119 SoundSource* SoundEngine::createSource(const char*fileName, PNode* sourceNode)119 SoundSource* SoundEngine::createSource(const std::string& fileName, PNode* sourceNode) 120 120 { 121 121 return new SoundSource(sourceNode, (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL)); -
trunk/src/lib/sound/sound_engine.h
r6849 r7221 33 33 void loadSettings(IniParser* iniParser); 34 34 35 SoundSource* createSource(const char*fileName, PNode* sourceNode = NULL);35 SoundSource* createSource(const std::string& fileName, PNode* sourceNode = NULL); 36 36 37 37 /** @param listener the listener in the scene */ -
trunk/src/lib/util/executor/executor.cc
r7201 r7221 105 105 value[4] = &value4; 106 106 107 printf("%s ::: paramCount: %d\n", this->getName(), this->paramCount);108 107 for (unsigned int i = 0; i < this->paramCount; i++) 109 108 { 110 109 if (*value[i] != MT_NULL) 111 110 { 112 printf("1:::: %d : %s \n",i, MultiType::MultiTypeToString(this->defaultValue[i].getType())); 113 114 this->defaultValue[i].debug(); 115 //this->defaultValue[i].setValueOf(*value[i]); 116 //printf("2::::%s\n", MultiType::MultiTypeToString(this->defaultValue[i].getType())); 117 //this->defaultValue[i].debug(); 118 //this->defaultValue[i].setValueOf(*value[i]); 111 this->defaultValue[i].setValueOf(*value[i]); 119 112 } 120 113 } -
trunk/src/lib/util/executor/executor.h
r7200 r7221 16 16 //! an enumerator for the definition of the Type. 17 17 typedef enum { 18 Executor_Objective = 0x00000001,19 Executor_Static = 0x00000002,20 21 Executor_NoLoadString = 0x00000010,18 Executor_Objective = 1, 19 Executor_Static = 2, 20 21 Executor_NoLoadString = 8, 22 22 } Executor_Type; 23 23 … … 48 48 49 49 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ 50 virtual void execute (BaseObject* object, const void* parameters = NULL) = 0;50 virtual void execute (BaseObject* object, const std::string& parameters = "") = 0; 51 51 52 52 /** @returns the Type of this Function (either static or objective) */ … … 87 87 #define l_FLOAT_DEFGRAB(i) this->defaultValue[i].getFloat() 88 88 //! where to chek for default STRING values 89 #define l_STRING_DEFGRAB(i) this->defaultValue[i].getString() 90 //! where to chek for default CSTRING values 89 91 #define l_CSTRING_DEFGRAB(i) this->defaultValue[i].getCString() 90 92 … … 190 192 #define ExecutorExecute1(t1) \ 191 193 else if (this->paramCount == 1 && this->defaultValue[0] == t1##_PARAM) \ 192 EXECUTOREXECUTER(_1_##t1)(t1##_FUNC( (const char*)parameters, t1##_DEFGRAB(0)))194 EXECUTOREXECUTER(_1_##t1)(t1##_FUNC(sub[0], t1##_DEFGRAB(0))) 193 195 194 196 //! execute-macro for functions with two parameters 195 197 #define ExecutorExecute2(t1,t2) \ 196 198 else if (this->paramCount == 2 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM) \ 197 EXECUTOREXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub .getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)))199 EXECUTOREXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1))) 198 200 199 201 //! execute-macro for functions with three parameters 200 202 #define ExecutorExecute3(t1,t2,t3) \ 201 203 else if (this->paramCount == 3 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM) \ 202 EXECUTOREXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub .getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)))204 EXECUTOREXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2))) 203 205 204 206 //! execute-macro for functions with four parameters 205 207 #define ExecutorExecute4(t1,t2,t3,t4) \ 206 208 else if (this->paramCount == 4 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM && this->defaultValue[3] == t4##_PARAM) \ 207 EXECUTOREXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub .getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3))) \209 EXECUTOREXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)), t4##_FUNC(sub[3], t4##_DEFGRAB(3))) \ 208 210 209 211 … … 211 213 #define ExecutorExecute5(t1,t2,t3,t4,t5) \ 212 214 else if (this->paramCount == 5 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM && this->defaultValue[3] == t4##_PARAM && this->defaultValue[4] == t5##_PARAM) \ 213 EXECUTOREXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub .getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)), t5##_FUNC(sub.getString(4), t5##_DEFGRAB(4)))215 EXECUTOREXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)), t4##_FUNC(sub[3], t4##_DEFGRAB(3)), t5##_FUNC(sub[4], t5##_DEFGRAB(4))) 214 216 215 217 … … 240 242 #define EXECUTORTYPE Executor_Objective 241 243 //! keeps information about a Executor 242 template<class T> class E xecutorObjective: public Executor244 template<class T> class EXECUTOR : public Executor 243 245 { 244 246 public: 245 E xecutorObjective() : Executor() { };247 EXECUTOR() : Executor() { }; 246 248 // COPY constuctor (virtual version) 247 249 virtual Executor* clone () const 248 250 { 249 E xecutorObjective<T>* executor = new ExecutorObjective<T>();251 EXECUTOR<T>* executor = new EXECUTOR<T>(); 250 252 this->cloning(executor); 251 253 executor->fp = this->fp; … … 266 268 } fp; 267 269 268 virtual void execute (BaseObject* object, const void* parameters = NULL)270 virtual void execute (BaseObject* object, const std::string& parameters = "") 269 271 { 270 SubString sub ((const char*) parameters, " \n\t,", '\\');271 printf("%s :: %s\n", this->getName(), (const char*) parameters);272 SubString sub; 273 sub.split(parameters, " \n\t,", '\\'); 272 274 //! FUNCTOR_LIST is the List of Executive Functions 273 275 #define FUNCTOR_LIST(x) ExecutorExecute ## x … … 305 307 { 306 308 public: 307 E xecutorStatic() : Executor() { };309 EXECUTOR() : Executor() { }; 308 310 // COPY constuctor 309 311 virtual Executor* clone () const 310 312 { 311 E xecutorStatic<T>* executor = new ExecutorStatic<T>();313 EXECUTOR<T>* executor = new EXECUTOR<T>(); 312 314 this->cloning(executor); 313 315 executor->fp = this->fp; … … 329 331 330 332 331 virtual void execute (BaseObject* object, const void* parameters = NULL)333 virtual void execute (BaseObject* object, const std::string& parameters = "") 332 334 { 333 SubString sub((const char*)parameters, " \n\t,"); 335 SubString sub; 336 sub.split(parameters, " \n\t,", '\\'); 334 337 //! FUNCTOR_LIST is the List of Executive Functions 335 338 #define FUNCTOR_LIST(x) ExecutorExecute ## x -
trunk/src/lib/util/executor/executor_specials.h
r7197 r7221 60 60 * @param loadString ignored in this case 61 61 */ 62 virtual void execute(BaseObject* object, const void* parameters = NULL)62 virtual void execute(BaseObject* object, const std::string& = "") 63 63 { 64 64 if (object != NULL && this->element != NULL) -
trunk/src/lib/util/executor/functor_list.h
r7199 r7221 21 21 l_SHORT: short 22 22 l_FLOAT: float 23 l_ CSTRING: const char*23 l_STRING: const std::string& 24 24 l_XML_ELEM: TiXmlElement* 25 25 */ … … 74 74 //#define l_VECTOR_DEFAULT Vector(0,0,0) //!< Default value for a VECTOR 75 75 76 #define l_CSTRING_TYPE const char* //!< The type of a STRING77 #define l_CSTRING_FUNC isString //!< The function to parse a STRING78 #define l_CSTRING_NAME "string" //!< The name of a STRING79 #define l_CSTRING_PARAM MT_STRING //!< the type of the parameter STRING80 #define l_CSTRING_DEFAULT "" //!< a default Value for an STRING81 82 76 #define l_STRING_TYPE const std::string& //!< The type of a STRING 83 77 #define l_STRING_FUNC isString //!< The function to parse a STRING 84 78 #define l_STRING_NAME "string" //!< The name of a STRING 85 #define l_STRING_PARAM MT_STRING 79 #define l_STRING_PARAM MT_STRING //!< the type of the parameter STRING 86 80 #define l_STRING_DEFAULT "" //!< a default Value for an STRING 87 81 … … 99 93 FUNCTOR_LIST(0)(); 100 94 //! makes functions with one string 101 FUNCTOR_LIST(1)(l_ CSTRING);95 FUNCTOR_LIST(1)(l_STRING); 102 96 //! makes functions with two strings 103 FUNCTOR_LIST(2)(l_ CSTRING, l_CSTRING);97 FUNCTOR_LIST(2)(l_STRING, l_STRING); 104 98 //! makes functions with three strings 105 FUNCTOR_LIST(3)(l_ CSTRING, l_CSTRING, l_CSTRING);99 FUNCTOR_LIST(3)(l_STRING, l_STRING, l_STRING); 106 100 //! makes functions with four strings 107 FUNCTOR_LIST(4)(l_CSTRING, l_CSTRING, l_CSTRING, l_CSTRING); 101 FUNCTOR_LIST(4)(l_STRING, l_STRING, l_STRING, l_STRING); 102 108 103 109 104 //! makes functions with one bool … … 141 136 142 137 //! mixed values: 143 FUNCTOR_LIST(2)(l_ CSTRING, l_FLOAT);138 FUNCTOR_LIST(2)(l_STRING, l_FLOAT); 144 139 FUNCTOR_LIST(2)(l_UINT, l_LONG); 145 FUNCTOR_LIST(2)(l_ CSTRING, l_UINT);140 FUNCTOR_LIST(2)(l_STRING, l_UINT); 146 141 147 FUNCTOR_LIST(3)(l_ CSTRING, l_FLOAT, l_UINT);142 FUNCTOR_LIST(3)(l_STRING, l_FLOAT, l_UINT); 148 143 149 144 -
trunk/src/lib/util/helper_functions.cc
r5331 r7221 22 22 23 23 /** 24 * checks if the input was a bool24 * @brief checks if the input was a bool 25 25 * @param BOOL a String that holds a bool: must be one of those: 1,0,true,false(case-insensitive) 26 26 * @param defaultValue a default value that is set, if BOOL is corrupt 27 27 * @return returns the bool, if BOOL was correct otherwise defaultValue 28 28 */ 29 bool isBool(const char*BOOL, bool defaultValue)29 bool isBool(const std::string& BOOL, bool defaultValue) 30 30 { 31 if (BOOL == NULL)31 if (BOOL.empty()) 32 32 return defaultValue; 33 if( !strcmp(BOOL, "1") || !strcasecmp( BOOL, "true"))33 if(BOOL[0] == '1' || BOOL == "true" ) 34 34 return true; 35 else if ( !strcmp(BOOL, "0") || !strcasecmp( BOOL, "false"))35 else if (BOOL[0] == '0' || BOOL == "false") 36 36 return false; 37 37 else 38 38 return defaultValue; 39 40 39 } 41 40 42 41 43 42 /** 44 * checks if the input was a int43 * @brief checks if the input was a int 45 44 * @param INT a String that holds an int. 46 45 * @param defaultValue a default value that is set, if INT is corrupt 47 46 * @return returns the contained int, if INT was correct otherwise defaultValue 48 47 */ 49 int isInt(const char*INT, int defaultValue)48 int isInt(const std::string& INT, int defaultValue) 50 49 { 51 if (INT == NULL)50 if (INT.empty()) 52 51 return defaultValue; 53 52 char* endPtr = NULL; 54 53 55 int result = strtol(INT , &endPtr, 10);54 int result = strtol(INT.c_str(), &endPtr, 10); 56 55 57 if ( endPtr >= INT && endPtr < INT + strlen(INT))56 if ( endPtr >= INT.c_str() && endPtr < INT.c_str()+ INT.size()) 58 57 return defaultValue; 59 58 else … … 63 62 64 63 /** 65 * checks if the input was a float64 * @brief checks if the input was a float 66 65 * @param FLOAT a String that holds an float. 67 66 * @param defaultValue a default value that is set, if FLOAT is corrupt 68 67 * @return returns the contained float, if FLOAT was correct otherwise defaultValue 69 68 */ 70 float isFloat(const char*FLOAT, float defaultValue)69 float isFloat(const std::string& FLOAT, float defaultValue) 71 70 { 72 if (FLOAT == NULL)71 if (FLOAT.empty()) 73 72 return defaultValue; 74 73 char* endPtr = NULL; 75 double result = strtod(FLOAT , &endPtr);74 double result = strtod(FLOAT.c_str(), &endPtr); 76 75 77 if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))76 if ( endPtr >= FLOAT.c_str() && endPtr < FLOAT.c_str() + FLOAT.size()) 78 77 return defaultValue; 79 78 else … … 83 82 84 83 /** 85 * checks if the input was a string84 * @brief checks if the input was a string 86 85 * @param STING a String(char-array) that holds an string. 87 86 * @param defaultValue a default value that is set, if STRING is corrupt 88 87 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 89 88 */ 90 const char* is String(const char*STRING, const char* defaultValue)89 const char* isCString(const std::string& STRING, const char* defaultValue) 91 90 { 92 if (STRING != NULL && strlen(STRING) > 0) 91 if (STRING.size() > 0) 92 return STRING.c_str(); 93 else 94 return defaultValue; 95 } 96 97 /** 98 * @brief checks if the input was a string 99 * @param STING a String(char-array) that holds an string. 100 * @param defaultValue a default value that is set, if STRING is corrupt 101 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 102 */ 103 std::string isString(const std::string& STRING, const std::string& defaultValue) 104 { 105 if (STRING.size() > 0) 93 106 return STRING; 94 107 else 95 108 return defaultValue; 96 109 } 110 111 112 /** 113 * @brief compares two strings without ignoring the case 114 * @param s1 first string 115 * @param s2 second string 116 */ 117 int nocase_cmp(const std::string& s1, const std::string& s2) 118 { 119 std::string::const_iterator it1=s1.begin(); 120 std::string::const_iterator it2=s2.begin(); 121 122 //stop when either string's end has been reached 123 while ( (it1!=s1.end()) && (it2!=s2.end()) ) 124 { 125 if(::toupper(*it1) != ::toupper(*it2)) //letters differ? 126 // return -1 to indicate smaller than, 1 otherwise 127 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; 128 //proceed to the next character in each string 129 ++it1; 130 ++it2; 131 } 132 size_t size1=s1.size(), size2=s2.size();// cache lengths 133 //return -1,0 or 1 according to strings' lengths 134 if (size1==size2) 135 return 0; 136 return (size1<size2) ? -1 : 1; 137 } 138 -
trunk/src/lib/util/helper_functions.h
r5141 r7221 7 7 #define _HELPER_FUNCTIONS_H 8 8 9 #include <string> 10 9 11 // FORWARD DECLARATION 10 12 … … 12 14 *** HELPER FUNCTIONS *** 13 15 ***********************/ 14 bool isBool(const char* BOOL, bool defaultValue); 15 int isInt(const char* INT, int defaultValue); 16 float isFloat(const char* FLOAT, float defaultValue); 17 const char* isString(const char* STRING, const char* defaultValue); 16 bool isBool(const std::string& BOOL, bool defaultValue); 17 int isInt(const std::string& INT, int defaultValue); 18 float isFloat(const std::string& FLOAT, float defaultValue); 19 const char* isCString(const std::string& STRING, const char* defaultValue); 20 std::string isString(const std::string& STRING, const std::string& defaultValue); 21 22 23 int nocase_cmp(const std::string& s1, const std::string& s2); 24 18 25 19 26 #endif /* _HELPER_FUNCTIONS_H */ -
trunk/src/lib/util/loading/factory.cc
r7193 r7221 23 23 //SHELL_COMMAND(create, Factory, fabricate); 24 24 25 26 /* -------------------------------------------------- 27 * Factory28 * --------------------------------------------------25 /** 26 * @brief constructor 27 * 28 * set everything to zero and define factoryName 29 29 */ 30 31 /** 32 * constructor 33 34 set everything to zero and define factoryName 35 */ 36 Factory::Factory (const char* factoryName, ClassID classID) 30 Factory::Factory (const std::string& factoryName, ClassID classID) 31 : className(factoryName), classID(classID) 37 32 { 38 33 this->setClassID(CL_FACTORY, "Factory"); 39 34 this->setName(factoryName); 40 41 this->classID = classID;42 this->className = factoryName;43 35 44 36 if( Factory::factoryList == NULL) … … 48 40 } 49 41 50 /** a reference to the First Factory */42 /** @brief a reference to the First Factory */ 51 43 std::list<Factory*>* Factory::factoryList = NULL; 52 44 53 45 /** 54 * destructor 55 * 56 * clear the Q 46 * @brief destructor 57 47 */ 58 48 Factory::~Factory () … … 64 54 65 55 /** 66 * deletes all the Factories. (cleanup)56 * @brief deletes all the Factories. (cleanup) 67 57 */ 68 58 void Factory::deleteFactories() … … 90 80 91 81 /** 92 * Compares the Factories Name against a given ClassName82 * @brief Compares the Factories Name against a given ClassName 93 83 * @param className the Name of the Class to Query 94 84 * @returns true on match, false otherwise. … … 96 86 bool Factory::operator==(const char* className) const 97 87 { 98 return(className != NULL && !strcmp(className, this->className)); 88 return(className != NULL && this->className == className); 89 } 90 91 /** 92 * @brief Compares the Factories Name against a given ClassName 93 * @param className the Name of the Class to Query 94 * @returns true on match, false otherwise. 95 */ 96 bool Factory::operator==(const std::string& className) const 97 { 98 return(this->className == className); 99 99 } 100 100 101 101 102 102 /** 103 * Creates a new Object of type root->Value() (name)103 * @brief Creates a new Object of type root->Value() (name) 104 104 * @param root the XML-Root to match for the newly created Object 105 105 * @returns a new Object of Type root->Value() on match, NULL otherwise … … 133 133 * @returns a new Object of Type className on match, NULL otherwise 134 134 */ 135 BaseObject* Factory::fabricate(const char*className)135 BaseObject* Factory::fabricate(const std::string& className) 136 136 { 137 if ( className == NULL ||Factory::factoryList == NULL)137 if (Factory::factoryList == NULL) 138 138 return NULL; 139 139 … … 178 178 else 179 179 { 180 PRINTF(2)("Could not Fabricate an Object of ClassID ' %h'\n", classID);180 PRINTF(2)("Could not Fabricate an Object of ClassID '0x%h'\n", classID); 181 181 return NULL; 182 182 } -
trunk/src/lib/util/loading/factory.h
r7167 r7221 27 27 #include "parser/tinyxml/tinyxml.h" 28 28 #include "base_object.h" 29 #include "debug.h"30 29 #include <vector> 31 30 #include <list> … … 34 33 * Creates a factory to a Loadable Class. 35 34 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 36 */35 */ 37 36 #define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \ 38 37 tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID) … … 49 48 static void deleteFactories(); 50 49 51 static BaseObject* fabricate(const char*className);50 static BaseObject* fabricate(const std::string& className); 52 51 static BaseObject* fabricate(ClassID classID); 53 52 static BaseObject* fabricate(const TiXmlElement* root = NULL); … … 56 55 bool operator==(ClassID classID) const; 57 56 bool operator==(const char* className) const; 57 bool operator==(const std::string& className) const; 58 58 59 59 protected: 60 Factory (const char*factoryName, ClassID classID);60 Factory (const std::string& factoryName, ClassID classID); 61 61 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0; 62 62 63 63 protected: 64 ClassIDclassID; //!< The Class-Identifyer of the Factory.65 const char*className; //!< The name of the Class.64 const ClassID classID; //!< The Class-Identifyer of the Factory. 65 const std::string className; //!< The name of the Class. 66 66 static std::list<Factory*>* factoryList; //!< List of Registered Factories 67 67 }; 68 68 69 69 /** 70 * a factory that is able to load any kind of Object70 * @brief a factory that is able to load any kind of Object 71 71 * (this is a Functor) 72 72 */ … … 75 75 public: 76 76 /** 77 * creates a new type Factory to enable the loading of T77 * @brief creates a new type Factory to enable the loading of T 78 78 * @param factoryName the Name of the Factory to load. 79 79 * @param classID the ID of the Class to be created. … … 85 85 private: 86 86 /** 87 * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)87 * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*) 88 88 * @param root the TiXmlElement T should load parameters from. 89 89 * @return the newly fabricated T. -
trunk/src/lib/util/loading/game_loader.cc
r7193 r7221 86 86 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 87 87 */ 88 ErrorMessage GameLoader::loadCampaign(const char*fileName)88 ErrorMessage GameLoader::loadCampaign(const std::string& fileName) 89 89 { 90 90 ErrorMessage errorCode; 91 char*campaignName = ResourceManager::getFullName(fileName);92 if ( campaignName)91 std::string campaignName = ResourceManager::getFullName(fileName); 92 if (!campaignName.empty()) 93 93 { 94 94 this->currentCampaign = this->fileToCampaign(campaignName); 95 delete[] campaignName;96 95 } 97 96 } … … 105 104 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 106 105 */ 107 ErrorMessage GameLoader::loadNetworkCampaign(const char*fileName)106 ErrorMessage GameLoader::loadNetworkCampaign(const std::string& fileName) 108 107 { 109 108 ErrorMessage errorCode; 110 char*campaignName = ResourceManager::getFullName(fileName);111 if ( campaignName)109 std::string campaignName = ResourceManager::getFullName(fileName); 110 if (!campaignName.empty()) 112 111 { 113 112 this->currentCampaign = this->fileToCampaign(campaignName); 114 delete[] campaignName;115 113 } 116 114 } … … 220 218 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 221 219 */ 222 Campaign* GameLoader::fileToCampaign(const char*fileName)220 Campaign* GameLoader::fileToCampaign(const std::string& fileName) 223 221 { 224 222 /* do not entirely load the campaign. just the current world … … 227 225 */ 228 226 229 if( fileName == NULL)227 if( fileName.empty()) 230 228 { 231 229 PRINTF(2)("No filename specified for loading"); … … 233 231 } 234 232 235 TiXmlDocument * XMLDoc = new TiXmlDocument(fileName);233 TiXmlDocument XMLDoc(fileName); 236 234 // load the campaign document 237 if( !XMLDoc ->LoadFile())235 if( !XMLDoc.LoadFile(fileName)) 238 236 { 239 237 // report an error 240 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 241 delete XMLDoc; 238 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); 242 239 return NULL; 243 240 } 244 241 245 242 // check basic validity 246 TiXmlElement* root = XMLDoc ->RootElement();243 TiXmlElement* root = XMLDoc.RootElement(); 247 244 assert( root != NULL); 248 245 … … 251 248 // report an error 252 249 PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n"); 253 delete XMLDoc;254 250 return NULL; 255 251 } 256 252 257 253 // construct campaign 258 Campaign* c = new Campaign( root); 259 260 // free the XML data 261 delete XMLDoc; 262 263 return c; 254 return new Campaign( root); 264 255 } 265 256 -
trunk/src/lib/util/loading/game_loader.h
r6981 r7221 44 44 static GameLoader* getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader(); return singletonRef; } 45 45 46 ErrorMessage loadCampaign(const char*name);46 ErrorMessage loadCampaign(const std::string& name); 47 47 ErrorMessage loadDebugCampaign(Uint32 campaignID); 48 ErrorMessage loadNetworkCampaign(const char*fileName);48 ErrorMessage loadNetworkCampaign(const std::string& fileName); 49 49 50 50 ErrorMessage init(); … … 62 62 GameLoader (); 63 63 64 Campaign* fileToCampaign(const char*name);64 Campaign* fileToCampaign(const std::string& name); 65 65 66 66 -
trunk/src/lib/util/loading/load_param.cc
r7201 r7221 28 28 * @param executor the Executor, that executes the loading procedure. 29 29 */ 30 CLoadParam::CLoadParam(const TiXmlElement* root, const char*paramName, BaseObject* object, const Executor& executor, bool inLoadCycle)31 { 32 this->paramName = paramName; 30 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, const Executor& executor, bool inLoadCycle) 31 : paramName(paramName), object(object) 32 { 33 33 this->object = object; 34 34 this->inLoadCycle = inLoadCycle; … … 37 37 if (likely(!inLoadCycle)) 38 38 this->loadElem = grabParameterElement(root, paramName); 39 //this->loadString = grabParameter(root, paramName); 40 else if (!strcmp(root->Value(), paramName)) 39 else if (paramName == root->Value()) 41 40 this->loadElem = (TiXmlElement*)root->FirstChild(); 42 41 else … … 46 45 this->executor = executor.clone(); 47 46 48 if (this->executor)49 this->executor->setName(paramName);47 //if (this->executor) 48 // this->executor->setName(paramName); 50 49 } 51 50 … … 60 59 if (likely(this->executor != NULL)) 61 60 { 61 std::string loadString = ""; 62 62 if (this->loadElem != NULL && this->loadElem->ToText()) 63 this->loadString = this->loadElem->Value(); 64 else 65 this->loadString = NULL; 63 loadString = this->loadElem->Value(); 66 64 if (likely(this->object != NULL) && 67 ( this->loadString != NULL||65 ( !loadString.empty() || 68 66 ((this->executor->getType() & Executor_NoLoadString) == Executor_NoLoadString))) 69 67 { 70 PRINTF(4)("Loading '%s' with Parameters '%s' onto: '%s'(%s)\n", this->paramName, this->loadString, this->object->getName(), this->object->getClassName());71 this->executor->execute(this->object, this->loadString);68 PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", this->paramName.c_str(), loadString.c_str(), this->object->getClassName(), this->object->getName()); 69 this->executor->execute(this->object, loadString); 72 70 } 73 71 delete this->executor; … … 99 97 * @returns a pointer to itself. 100 98 */ 101 CLoadParam& CLoadParam::describe(const char*descriptionText)102 { 103 if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())99 CLoadParam& CLoadParam::describe(const std::string& descriptionText) 100 { 101 if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty()) 104 102 { 105 103 this->paramDesc->setDescription(descriptionText); … … 230 228 * @returns the Value of the parameter if found, NULL otherwise 231 229 */ 232 const char* grabParameter(const TiXmlElement* root, const char*parameterName)230 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName) 233 231 { 234 232 const TiXmlElement* element; 235 233 const TiXmlNode* node; 236 234 237 if (root == NULL || parameterName == NULL) 238 return NULL; 239 assert( parameterName != NULL); 235 if (root == NULL) 236 return ""; 240 237 241 238 element = root->FirstChildElement( parameterName); 242 if( element == NULL) return NULL;239 if( element == NULL) return ""; 243 240 244 241 node = element->FirstChild(); … … 248 245 node = node->NextSibling(); 249 246 } 250 return NULL;247 return ""; 251 248 } 252 249 … … 256 253 * @returns the Element of the parameter if found, NULL otherwise 257 254 */ 258 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char*parameterName)255 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName) 259 256 { 260 257 const TiXmlElement* element; 261 258 const TiXmlNode* node; 262 259 263 if (root == NULL || parameterName == NULL)260 if (root == NULL) 264 261 return NULL; 265 assert( parameterName != NULL);266 262 267 263 element = root->FirstChildElement( parameterName); -
trunk/src/lib/util/loading/load_param.h
r7198 r7221 87 87 { 88 88 public: 89 CLoadParam(const TiXmlElement* root, const char*paramName, BaseObject* object, const Executor& executor, bool inLoadCycle = false);89 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, const Executor& executor, bool inLoadCycle = false); 90 90 virtual ~CLoadParam(); 91 91 92 CLoadParam& describe(const char*descriptionText);92 CLoadParam& describe(const std::string& descriptionText); 93 93 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 94 94 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 95 95 const MultiType& value4 = MT_NULL); 96 CLoadParam& attribute(const char*attributeName, const Executor& executor);96 CLoadParam& attribute(const std::string& attributeName, const Executor& executor); 97 97 98 98 … … 101 101 Executor* executor; 102 102 BaseObject* object; 103 const char*paramName;103 const std::string paramName; 104 104 105 105 LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter 106 106 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 107 107 const TiXmlElement* loadElem; //!< The Element to load. 108 const char* loadString; //!< The string loaded by this LoadParam109 108 const void* pointerToParam; //!< A Pointer to a Parameter. 110 109 … … 114 113 // helper function 115 114 116 const char* grabParameter(const TiXmlElement* root, const char*parameterName);117 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char*parameterName);115 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName); 116 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName); 118 117 119 118 #endif /* _LOAD_PARAM_H */ -
trunk/src/lib/util/loading/load_param_description.cc
r7130 r7221 22 22 * @param paramName the name of the parameter to load 23 23 */ 24 LoadParamDescription::LoadParamDescription(const char*paramName)24 LoadParamDescription::LoadParamDescription(const std::string& paramName) 25 25 { 26 26 this->types = NULL; 27 this->description = NULL;28 27 this->defaultValues = NULL; 29 this->paramName = new char[strlen(paramName)+1]; 30 strcpy(this->paramName, paramName); 28 this->paramName = paramName; 31 29 } 32 30 … … 46 44 delete[] this->types; 47 45 delete[] this->defaultValues; 48 delete[] this->paramName;49 delete[] this->description;50 46 } 51 47 … … 53 49 * @param descriptionText The text to set as a description for this Parameter 54 50 */ 55 void LoadParamDescription::setDescription(const char* descriptionText) 56 { 57 this->description = new char[strlen(descriptionText)+1]; 58 strcpy(this->description, descriptionText); 51 void LoadParamDescription::setDescription(const std::string& descriptionText) 52 { 53 this->description = descriptionText; 59 54 } 60 55 … … 64 59 void LoadParamDescription::print() const 65 60 { 66 PRINT(3)(" <%s>", this->paramName );61 PRINT(3)(" <%s>", this->paramName.c_str()); 67 62 for (int i = 0; i < this->paramCount; i++) 68 63 { … … 101 96 // } 102 97 } 103 PRINT(3)("</%s>", this->paramName );104 if ( this->description)105 PRINT(3)(" -- %s", this->description );98 PRINT(3)("</%s>", this->paramName.c_str()); 99 if (!this->description.empty()) 100 PRINT(3)(" -- %s", this->description.c_str()); 106 101 // default values 107 102 if (this->paramCount > 0) … … 139 134 * @param className the name of the class to be loadable 140 135 */ 141 LoadClassDescription::LoadClassDescription(const char* className) 142 { 143 this->className = new char[strlen(className)+1]; 144 strcpy(this->className, className); 136 LoadClassDescription::LoadClassDescription(const std::string& className) 137 { 138 this->className = className; 145 139 146 140 if (LoadClassDescription::classList == NULL) … … 161 155 this->paramList.pop_front(); 162 156 } 163 164 delete[] this->className;165 157 } 166 158 … … 187 179 Otherwise it returns a new classDescription 188 180 */ 189 LoadClassDescription* LoadClassDescription::addClass(const char*className)181 LoadClassDescription* LoadClassDescription::addClass(const std::string& className) 190 182 { 191 183 if (LoadClassDescription::classList != NULL) … … 194 186 while (it != LoadClassDescription::classList->end()) 195 187 { 196 if ( !strcmp((*it)->className, className))188 if ((*it)->className == className) 197 189 { 198 190 return (*it); … … 205 197 206 198 /** 207 * does the same as addClass(const char*className), but with params199 * does the same as addClass(const std::string& className), but with params 208 200 * @param paramName the name of the parameter to add. 209 201 */ 210 LoadParamDescription* LoadClassDescription::addParam(const char*paramName)202 LoadParamDescription* LoadClassDescription::addParam(const std::string& paramName) 211 203 { 212 204 std::list<LoadParamDescription*>::iterator it = this->paramList.begin(); 213 205 while (it != this->paramList.end()) 214 206 { 215 if ( !strcmp((*it)->paramName, paramName))207 if ((*it)->paramName == paramName) 216 208 { 217 209 return NULL; … … 231 223 * @todo implement it 232 224 */ 233 void LoadClassDescription::printAll(const char*fileName)225 void LoadClassDescription::printAll(const std::string& fileName) 234 226 { 235 227 PRINT(3)("===============================================================\n"); … … 240 232 while (classDesc != LoadClassDescription::classList->end()) 241 233 { 242 PRINT(3)("<%s>\n", (*classDesc)->className );234 PRINT(3)("<%s>\n", (*classDesc)->className.c_str()); 243 235 std::list<LoadParamDescription*>::iterator param = (*classDesc)->paramList.begin(); 244 236 while (param != (*classDesc)->paramList.end()) … … 247 239 param++; 248 240 } 249 PRINT(3)("</%s>\n\n", (*classDesc)->className );241 PRINT(3)("</%s>\n\n", (*classDesc)->className.c_str()); 250 242 classDesc++; 251 243 } … … 262 254 * !! The strings MUST NOT be deleted !! 263 255 */ 264 std::list< const char*> LoadClassDescription::searchClassWithShort(const char*classNameBegin)256 std::list<std::string> LoadClassDescription::searchClassWithShort(const std::string& classNameBegin) 265 257 { 266 258 /// FIXME 267 259 // NOT USED 268 260 /* unsigned int searchLength = strlen(classNameBegin); 269 std::list<const char*> retVal;261 std::list<const std::string&> retVal; 270 262 271 263 tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator(); -
trunk/src/lib/util/loading/load_param_description.h
r7130 r7221 36 36 friend class LoadParam; 37 37 friend class LoadClassDescription; 38 39 LoadParamDescription(const char*paramName);38 public: 39 LoadParamDescription(const std::string& paramName); 40 40 ~LoadParamDescription(); 41 41 42 void setDescription(const char*descriptionText);42 void setDescription(const std::string& descriptionText); 43 43 /** @returns the descriptionString */ 44 const char*getDescription() { return this->description; };44 const std::string& getDescription() { return this->description; }; 45 45 46 46 void print() const; 47 47 48 49 char*paramName; //!< The name of the parameter.48 private: 49 std::string paramName; //!< The name of the parameter. 50 50 int paramCount; //!< The count of parameters. 51 51 int* types; //!< What kind of parameters does this function take ?? 52 char*description; //!< A longer description about this function.52 std::string description; //!< A longer description about this function. 53 53 char** defaultValues; //!< The 'Default Values'. @TODO MAKE THIS A MULTITYPE 54 54 }; … … 58 58 { 59 59 friend class CLoadParam; 60 61 LoadClassDescription(const char*className);60 public: 61 LoadClassDescription(const std::string& className); 62 62 ~LoadClassDescription(); 63 63 64 static LoadClassDescription* addClass(const char*className);65 LoadParamDescription* addParam(const char*paramName);64 static LoadClassDescription* addClass(const std::string& className); 65 LoadParamDescription* addParam(const std::string& paramName); 66 66 67 67 static void deleteAllDescriptions(); 68 68 69 static void printAll(const char* fileName = NULL);70 static std::list< const char*> searchClassWithShort(const char*classNameBegin);71 // static const LoadParamDescription* getClass(const char*className);69 static void printAll(const std::string& fileName = ""); 70 static std::list<std::string> searchClassWithShort(const std::string& classNameBegin); 71 // static const LoadParamDescription* getClass(const std::string& className); 72 72 73 73 private: 74 74 static bool parametersDescription; //!< if parameter-description should be enabled. 75 75 static std::list<LoadClassDescription*>* classList; //!< a list, that stores all the loadable classes. (after one instance has been loaded) 76 char*className; //!< name of the class76 std::string className; //!< name of the class 77 77 78 78 std::list<LoadParamDescription*> paramList; //!< List of parameters this class knows. -
trunk/src/lib/util/loading/resource_manager.cc
r7199 r7221 59 59 this->setName("ResourceManager"); 60 60 61 this->dataDir = new char[3];62 strcpy(this->dataDir, "./");61 this->dataDir = "./"; 62 this->_cwd = ""; 63 63 this->tryDataDir("./data"); 64 65 this->_cwd = NULL;66 64 } 67 65 … … 80 78 PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); 81 79 82 // deleting the Directorie Lists83 while (!this->imageDirs.empty())84 {85 delete[] this->imageDirs.back();86 this->imageDirs.pop_back();87 }88 89 delete[] this->dataDir;90 if (this->_cwd)91 delete[] this->_cwd;92 80 ResourceManager::singletonRef = NULL; 93 81 } … … 97 85 * @param dataDir the DataDirectory. 98 86 */ 99 bool ResourceManager::setDataDir(const char*dataDir)100 { 101 char*realDir = ResourceManager::homeDirCheck(dataDir);87 bool ResourceManager::setDataDir(const std::string& dataDir) 88 { 89 std::string realDir = ResourceManager::homeDirCheck(dataDir); 102 90 if (isDir(realDir)) 103 91 { 104 delete[] this->dataDir; 105 if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\') 92 if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\') 106 93 { 107 this->dataDir = new char[strlen(realDir)+1]; 108 strcpy(this->dataDir, realDir); 94 this->dataDir = realDir; 109 95 } 110 96 else 111 97 { 112 this->dataDir = new char[strlen(realDir)+2]; 113 strcpy(this->dataDir, realDir); 114 this->dataDir[strlen(realDir)] = '/'; 115 this->dataDir[strlen(realDir)+1] = '\0'; 98 this->dataDir = realDir; 99 this->dataDir += '/'; 116 100 } 117 delete[] realDir;118 101 return true; 119 102 } 120 103 else 121 104 { 122 PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir, this->dataDir); 123 delete[] realDir; 105 PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir.c_str(), this->dataDir.c_str()); 124 106 return false; 125 107 } … … 132 114 * this is essentially the same as setDataDir, but it ommits the error-message 133 115 */ 134 bool ResourceManager::tryDataDir(const char*dataDir)135 { 136 char*realDir = ResourceManager::homeDirCheck(dataDir);116 bool ResourceManager::tryDataDir(const std::string& dataDir) 117 { 118 std::string realDir = ResourceManager::homeDirCheck(dataDir); 137 119 if (isDir(realDir)) 138 120 { 139 delete[] this->dataDir; 140 if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\') 121 if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\') 141 122 { 142 this->dataDir = new char[strlen(realDir)+1]; 143 strcpy(this->dataDir, realDir); 123 this->dataDir = realDir; 144 124 } 145 125 else 146 126 { 147 this->dataDir = new char[strlen(realDir)+2]; 148 strcpy(this->dataDir, realDir); 149 this->dataDir[strlen(realDir)] = '/'; 150 this->dataDir[strlen(realDir)+1] = '\0'; 127 this->dataDir = realDir; 128 this->dataDir += '/'; 151 129 } 152 delete[] realDir;153 130 return true; 154 131 } 155 delete[] realDir;156 132 return false; 157 133 } … … 162 138 * @param fileInside is iniside of the given directory. 163 139 */ 164 bool ResourceManager::verifyDataDir(const char*fileInside)140 bool ResourceManager::verifyDataDir(const std::string& fileInside) 165 141 { 166 142 bool retVal; 167 143 if (!isDir(this->dataDir)) 168 144 { 169 PRINTF(1)("%s is not a directory\n", this->dataDir); 170 return false; 171 } 172 173 char* testFile = new char[strlen(this->dataDir)+strlen(fileInside)+1]; 174 sprintf(testFile, "%s%s", this->dataDir, fileInside); 145 PRINTF(1)("%s is not a directory\n", this->dataDir.c_str()); 146 return false; 147 } 148 149 std::string testFile = this->dataDir + fileInside; 175 150 retVal = isFile(testFile); 176 delete[] testFile;177 151 return retVal; 178 152 } … … 185 159 false otherwise 186 160 */ 187 bool ResourceManager::addImageDir(const char* imageDir) 188 { 189 if (imageDir == NULL) 190 return false; 191 192 char* newDir; 193 if (imageDir[strlen(imageDir)-1] == '/' || imageDir[strlen(imageDir)-1] == '\\') 194 { 195 newDir = new char[strlen(imageDir)+1]; 196 strcpy(newDir, imageDir); 197 } 198 else 199 { 200 newDir = new char[strlen(imageDir)+2]; 201 strcpy(newDir, imageDir); 202 newDir[strlen(imageDir)] = '/'; 203 newDir[strlen(imageDir)+1] = '\0'; 161 bool ResourceManager::addImageDir(const std::string& imageDir) 162 { 163 std::string newDir; 164 if (imageDir[imageDir.size()-1] == '/' || imageDir[imageDir.size()-1] == '\\') 165 { 166 newDir = imageDir; 167 } 168 else 169 { 170 newDir = imageDir; 171 newDir += '/'; 204 172 } 205 173 // check if the param is a Directory … … 207 175 { 208 176 // check if the Directory has been added before 209 std::vector< char*>::const_iterator imageDir;177 std::vector<std::string>::const_iterator imageDir; 210 178 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 211 179 { 212 if ( !strcmp(*imageDir, newDir))180 if (*imageDir == newDir) 213 181 { 214 PRINTF(3)("Path %s already loaded\n", newDir); 215 delete[] newDir; 182 PRINTF(3)("Path %s already loaded\n", newDir.c_str()); 216 183 return true; 217 184 } … … 223 190 else 224 191 { 225 PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir); 226 delete[] newDir; 192 PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir.c_str()); 227 193 return false; 228 194 } … … 239 205 * @returns a pointer to a desired Resource. 240 206 */ 241 BaseObject* ResourceManager::load(const char*fileName, ResourcePriority prio,207 BaseObject* ResourceManager::load(const std::string& fileName, ResourcePriority prio, 242 208 const MultiType& param0, const MultiType& param1, const MultiType& param2) 243 209 { 244 if (fileName == NULL)245 return NULL;246 210 ResourceType tmpType; 247 211 #ifndef NO_MODEL 248 212 #define __IF_OK 249 if (!strncasecmp(fileName +(strlen(fileName)-4), ".obj", 4))213 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".obj", 4)) 250 214 tmpType = OBJ; 251 else if (!strncmp(fileName +(strlen(fileName)-4), ".md2", 4))215 else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md2", 4)) 252 216 tmpType = MD2; 253 else if (!strcasecmp(fileName , "cube") ||254 !strcasecmp(fileName, "sphere") ||255 !strcasecmp(fileName, "plane") ||256 !strcasecmp(fileName, "cylinder") ||257 !strcasecmp(fileName, "cone"))217 else if (!strcasecmp(fileName.c_str(), "cube") || 218 !strcasecmp(fileName.c_str(), "sphere") || 219 !strcasecmp(fileName.c_str(), "plane") || 220 !strcasecmp(fileName.c_str(), "cylinder") || 221 !strcasecmp(fileName.c_str(), "cone")) 258 222 tmpType = PRIM; 259 223 #endif /* NO_MODEL */ … … 263 227 #endif 264 228 #define __IF_OK 265 if (!strncasecmp(fileName +(strlen(fileName)-4), ".wav", 4))229 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".wav", 4)) 266 230 tmpType = WAV; 267 else if (!strncasecmp(fileName +(strlen(fileName)-4), ".mp3", 4))231 else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".mp3", 4)) 268 232 tmpType = MP3; 269 else if (!strncasecmp(fileName +(strlen(fileName)-4), ".ogg", 4))233 else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ogg", 4)) 270 234 tmpType = OGG; 271 235 #endif /* NO_AUDIO */ … … 275 239 #endif 276 240 #define __IF_OK 277 if (!strncasecmp(fileName +(strlen(fileName)-4), ".ttf", 4))241 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ttf", 4)) 278 242 tmpType = TTF; 279 243 #endif /* NO_TEXT */ … … 283 247 #endif 284 248 #define __IF_OK 285 if (!strncasecmp(fileName +(strlen(fileName)-5), ".vert", 5))249 if (!strncasecmp(fileName.c_str()+(fileName.size()-5), ".vert", 5)) 286 250 tmpType = SHADER; 287 251 #endif /* NO_SHADERS */ … … 308 272 * during the initialisation instead of at Runtime. 309 273 */ 310 bool ResourceManager::cache(const char*fileName, ResourceType type, ResourcePriority prio,274 bool ResourceManager::cache(const std::string& fileName, ResourceType type, ResourcePriority prio, 311 275 const MultiType& param0, const MultiType& param1, const MultiType& param2) 312 276 { 313 assert(fileName != NULL);314 315 277 // searching if the resource was loaded before. 316 278 Resource* tmpResource; … … 359 321 * @returns a pointer to a desired Resource. 360 322 */ 361 BaseObject* ResourceManager::load(const char*fileName, ResourceType type, ResourcePriority prio,323 BaseObject* ResourceManager::load(const std::string& fileName, ResourceType type, ResourcePriority prio, 362 324 const MultiType& param0, const MultiType& param1, const MultiType& param2) 363 325 { 364 assert(fileName != NULL);365 326 366 327 // searching if the resource was loaded before. … … 397 358 * @returns a pointer to a desired Resource. 398 359 */ 399 Resource* ResourceManager::loadResource(const char*fileName, ResourceType type, ResourcePriority prio,360 Resource* ResourceManager::loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio, 400 361 const MultiType& param0, const MultiType& param1, const MultiType& param2) 401 362 { … … 406 367 tmpResource->prio = prio; 407 368 tmpResource->pointer = NULL; 408 tmpResource->name = new char[strlen(fileName)+1]; 409 strcpy(tmpResource->name, fileName); 369 tmpResource->name = fileName; 410 370 411 371 // creating the full name. (directoryName + FileName) 412 char*fullName = ResourceManager::getFullName(fileName);372 std::string fullName = ResourceManager::getFullName(fileName); 413 373 // Checking for the type of resource \see ResourceType 414 374 switch(type) … … 425 385 else 426 386 { 427 PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName , dataDir);387 PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName.c_str(), dataDir.c_str()); 428 388 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat()); 429 389 } … … 435 395 tmpResource->param[0] = 1.0f; 436 396 437 if ( !strcmp(tmpResource->name, "cube"))397 if (tmpResource->name == "cube") 438 398 tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat()); 439 else if ( !strcmp(tmpResource->name, "sphere"))399 else if (tmpResource->name == "sphere") 440 400 tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat()); 441 else if ( !strcmp(tmpResource->name, "plane"))401 else if (tmpResource->name == "plane") 442 402 tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat()); 443 else if ( !strcmp(tmpResource->name, "cylinder"))403 else if (tmpResource->name == "cylinder") 444 404 tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat()); 445 else if ( !strcmp(tmpResource->name, "cone"))405 else if (tmpResource->name == "cone") 446 406 tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat()); 447 407 break; … … 468 428 tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt()); 469 429 else 470 PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName , this->dataDir);430 PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName.c_str(), this->dataDir.c_str()); 471 431 break; 472 432 #endif /* NO_TEXT */ … … 494 454 else 495 455 { 496 std::vector< char*>::iterator imageDir;456 std::vector<std::string>::iterator imageDir; 497 457 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 498 458 { 499 char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1]; 500 sprintf(imgName, "%s%s", *imageDir, fileName); 459 std::string imgName = *imageDir + fileName; 501 460 if(isFile(imgName)) 502 461 { 503 462 PRINTF(4)("Image %s resides to %s\n", fileName, imgName); 504 463 tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt()); 505 delete[] imgName;506 464 break; 507 465 } 508 delete[] imgName;509 466 } 510 467 } 511 468 if(!tmpResource) 512 PRINTF(2)("!!Image %s not Found!!\n", fileName );469 PRINTF(2)("!!Image %s not Found!!\n", fileName.c_str()); 513 470 break; 514 471 #endif /* NO_TEXTURES */ … … 520 477 { 521 478 MultiType param = param0; /// HACK 522 char*secFullName = ResourceManager::getFullName(param.getCString());479 std::string secFullName = ResourceManager::getFullName(param.getCString()); 523 480 if (ResourceManager::isFile(secFullName)) 524 481 { … … 526 483 tmpResource->pointer = new Shader(fullName, secFullName); 527 484 } 528 delete[] secFullName;529 485 } 530 486 else 531 487 { 532 488 tmpResource->param[0] = param0; 533 tmpResource->pointer = new Shader(fullName, NULL);489 tmpResource->pointer = new Shader(fullName, ""); 534 490 } 535 491 } … … 538 494 default: 539 495 tmpResource->pointer = NULL; 540 PRINTF(1)("No type found for %s.\n !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name );496 PRINTF(1)("No type found for %s.\n !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name.c_str()); 541 497 break; 542 498 } 543 499 if (tmpResource->pointer != NULL) 544 500 this->resourceList.push_back(tmpResource); 545 delete[] fullName;546 547 501 548 502 if (tmpResource->pointer != NULL) … … 550 504 else 551 505 { 552 PRINTF(2)("Resource %s could not be loaded\n", fileName); 553 delete[] tmpResource->name; 506 PRINTF(2)("Resource %s could not be loaded\n", fileName.c_str()); 554 507 delete tmpResource; 555 508 return NULL; … … 597 550 delete resource->pointer; 598 551 // deleting the List Entry: 599 PRINTF(4)("Resource %s safely removed.\n", resource->name); 600 delete[] resource->name; 552 PRINTF(4)("Resource %s safely removed.\n", resource->name.c_str()); 601 553 std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource); 602 554 this->resourceList.erase(resourceIT); … … 604 556 } 605 557 else 606 PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name , resource->count);607 } 608 else 609 PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name );558 PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count); 559 } 560 else 561 PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name.c_str()); 610 562 return true; 611 563 } … … 633 585 if (round == 3) 634 586 PRINTF(2)("unable to unload %s because there are still %d references to it\n", 635 this->resourceList[index]->name , this->resourceList[index]->count);587 this->resourceList[index]->name.c_str(), this->resourceList[index]->count); 636 588 removeCount++; 637 589 } … … 653 605 * @returns a Pointer to the Resource if found, NULL otherwise. 654 606 */ 655 Resource* ResourceManager::locateResourceByInfo(const char*fileName, ResourceType type,607 Resource* ResourceManager::locateResourceByInfo(const std::string& fileName, ResourceType type, 656 608 const MultiType& param0, const MultiType& param1, const MultiType& param2) const 657 609 { … … 659 611 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 660 612 { 661 if ((*resource)->type == type && !strcmp(fileName, (*resource)->name))613 if ((*resource)->type == type && fileName == (*resource)->name) 662 614 { 663 615 bool match = false; … … 743 695 } 744 696 745 char*ResourceManager::toResourcableString(unsigned int i)746 { 747 int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));748 len += strlen(this->resourceList[i]->name);697 std::string ResourceManager::toResourcableString(unsigned int i) 698 { 699 /* int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type)); 700 len += this->resourceList[i]->name.size(); 749 701 if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1; 750 702 if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1; 751 703 if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1; 752 704 len += 10; 753 char*tmp = new char[len];705 std::string tmp = new char[len]; 754 706 tmp[0] = '\0'; 755 strcat( 707 strcat(tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type)); 756 708 strcat(tmp,","); 757 709 strcat (tmp, this->resourceList[i]->name); … … 771 723 strcat( tmp, this->resourceList[i]->param[2].getCString()); 772 724 } 773 return tmp; 725 return tmp;*/ 774 726 } 775 727 … … 778 730 * @param resourceableString the String to cache the resource from. 779 731 */ 780 bool ResourceManager::fromResourceableString(const char*resourceableString)781 { 782 SubString splits(resourceableString, ',');732 bool ResourceManager::fromResourceableString(const std::string& resourceableString) 733 { 734 /* SubString splits(resourceableString, ','); 783 735 splits.debug(); 784 736 if (splits.getCount() == 2) … … 793 745 else if (splits.getCount() == 5) 794 746 return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]), 795 RP_LEVEL, splits[2], splits[3], splits[4]); 747 RP_LEVEL, splits[2], splits[3], splits[4]);*/ 796 748 } 797 749 … … 802 754 * @returns true if it is a directory/symlink false otherwise 803 755 */ 804 bool ResourceManager::isDir(const char* directoryName) 805 { 806 if (directoryName == NULL) 807 return false; 808 809 char* tmpDirName = NULL; 756 bool ResourceManager::isDir(const std::string& directoryName) 757 { 758 std::string tmpDirName = directoryName; 810 759 struct stat status; 811 760 812 761 // checking for the termination of the string given. If there is a "/" at the end cut it away 813 if (directoryName[strlen(directoryName)-1] == '/' || 814 directoryName[strlen(directoryName)-1] == '\\') 815 { 816 tmpDirName = new char[strlen(directoryName)]; 817 strncpy(tmpDirName, directoryName, strlen(directoryName)-1); 818 tmpDirName[strlen(directoryName)-1] = '\0'; 819 } 820 else 821 { 822 tmpDirName = new char[strlen(directoryName)+1]; 823 strcpy(tmpDirName, directoryName); 824 } 825 826 if(!stat(tmpDirName, &status)) 762 if (directoryName[directoryName.size()-1] == '/' || 763 directoryName[directoryName.size()-1] == '\\') 764 { 765 tmpDirName.erase(tmpDirName.size()-1); 766 } 767 768 if(!stat(tmpDirName.c_str(), &status)) 827 769 { 828 770 if (status.st_mode & (S_IFDIR … … 832 774 )) 833 775 { 834 delete[] tmpDirName;835 776 return true; 836 777 } 837 778 else 838 {839 delete[] tmpDirName;840 779 return false; 841 } 842 } 843 else 844 { 845 delete[] tmpDirName; 846 return false; 847 } 780 } 781 else 782 return false; 848 783 } 849 784 … … 853 788 * @returns true if it is a regular file/symlink, false otherwise 854 789 */ 855 bool ResourceManager::isFile(const char*fileName)856 { 857 if (fileName == NULL)858 return false; 859 char*tmpFileName = ResourceManager::homeDirCheck(fileName);790 bool ResourceManager::isFile(const std::string& fileName) 791 { 792 if (fileName.empty()) 793 return false; 794 std::string tmpFileName = ResourceManager::homeDirCheck(fileName); 860 795 // actually checks the File 861 796 struct stat status; 862 if (!stat(tmpFileName , &status))797 if (!stat(tmpFileName.c_str(), &status)) 863 798 { 864 799 if (status.st_mode & (S_IFREG … … 868 803 )) 869 804 { 870 delete[] tmpFileName;871 805 return true; 872 806 } 873 807 else 874 {875 delete[] tmpFileName;876 808 return false; 877 } 878 } 879 else 880 { 881 delete[] tmpFileName; 882 return false; 883 } 809 } 810 else 811 return false; 884 812 } 885 813 … … 888 816 * @param fileName The file to touch 889 817 */ 890 bool ResourceManager::touchFile(const char*fileName)891 { 892 char*tmpName = ResourceManager::homeDirCheck(fileName);893 if (tmpName == NULL)818 bool ResourceManager::touchFile(const std::string& fileName) 819 { 820 std::string tmpName = ResourceManager::homeDirCheck(fileName); 821 if (tmpName.empty()) 894 822 return false; 895 823 FILE* stream; 896 if( (stream = fopen (tmpName, "w")) == NULL) 897 { 898 PRINTF(1)("could not open %s fro writing\n", fileName); 899 delete[] tmpName; 824 if( (stream = fopen (tmpName.c_str(), "w")) == NULL) 825 { 826 PRINTF(1)("could not open %s fro writing\n", fileName.c_str()); 900 827 return false; 901 828 } 902 829 fclose(stream); 903 904 delete[] tmpName;905 830 } 906 831 … … 909 834 * @param fileName the File to delete 910 835 */ 911 bool ResourceManager::deleteFile(const char* fileName) 912 { 913 if (fileName == NULL) 914 return false; 915 char* tmpName = ResourceManager::homeDirCheck(fileName); 916 unlink(tmpName); 917 delete[] tmpName; 836 bool ResourceManager::deleteFile(const std::string& fileName) 837 { 838 std::string tmpName = ResourceManager::homeDirCheck(fileName); 839 unlink(tmpName.c_str()); 918 840 } 919 841 … … 921 843 * @param name the Name of the file to check 922 844 * @returns The name of the file, including the HomeDir 923 * IMPORTANT: this has to be deleted from the outside 924 */ 925 char* ResourceManager::homeDirCheck(const char* name) 926 { 927 if (name == NULL) 928 return NULL; 929 char* retName; 930 if (!strncmp(name, "~/", 2)) 931 { 932 char tmpFileName[500]; 845 */ 846 std::string ResourceManager::homeDirCheck(const std::string& name) 847 { 848 if (name.size() >= 2 && name[0] == '~' && name[1] == '/') 849 { 850 std::string homeDir; 851 std::string newName = name.substr(1); 933 852 #ifdef __WIN32__ 934 strcpy(tmpFileName, getenv("USERPROFILE"));853 homeDir = getenv("USERPROFILE"); 935 854 #else 936 strcpy(tmpFileName, getenv("HOME")); 937 #endif 938 retName = new char[strlen(tmpFileName)+strlen(name)]; 939 sprintf(retName, "%s%s", tmpFileName, name+1); 940 } 941 else 942 { 943 retName = new char[strlen(name)+1]; 944 strcpy(retName, name); 945 } 946 return retName; 855 homeDir = getenv("HOME"); 856 #endif 857 return homeDir + newName; 858 } 859 else 860 return name; 947 861 } 948 862 949 863 /** 950 864 * @param name the relative name of the File/Directory. 951 * @returns a new char* with the name in abs-dir-format 952 */ 953 char* ResourceManager::getAbsDir(const char* name) 954 { 955 if (name == NULL) 956 return NULL; 957 char* retName; 958 if (strncmp(name, "/", 1)) 959 { 960 if (*name == '.' && *(name+1) != '.') 961 name++; 962 const char* absDir = ResourceManager::cwd(); 963 retName = new char[strlen(absDir)+strlen(name)+1]; 964 sprintf(retName, "%s%s", absDir, name); 965 } 966 else 967 { 968 retName = new char[strlen(name)+1]; 969 strcpy(retName, name); 865 * @returns a new std::string with the name in abs-dir-format 866 */ 867 std::string ResourceManager::getAbsDir(const std::string& name) 868 { 869 if (name.empty()) 870 return ""; 871 std::string retName = name; 872 if (strncmp(name.c_str(), "/", 1)) 873 { 874 if (name[0] == '.' && name[1] != '.') 875 retName.erase(0); 876 const std::string& absDir = ResourceManager::cwd(); 877 retName = absDir + retName; 970 878 } 971 879 return retName; … … 978 886 * !!IMPORTANT: this has to be deleted from the outside!! 979 887 */ 980 char* ResourceManager::getFullName(const char* fileName) 981 { 982 if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL) 983 return NULL; 984 985 char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir()) 986 + strlen(fileName) + 1]; 987 sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName); 888 std::string ResourceManager::getFullName(const std::string& fileName) 889 { 890 if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty()) 891 return ""; 892 893 std::string retName = ResourceManager::getInstance()->getDataDir() +fileName; 988 894 if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName)) 989 895 return retName; 990 896 else 991 { 992 delete[] retName; 993 return NULL; 994 } 897 return ""; 995 898 } 996 899 … … 1005 908 * @returns the Current Woring Directory 1006 909 */ 1007 const char*ResourceManager::cwd()1008 { 1009 if (ResourceManager::getInstance()->_cwd == NULL)910 const std::string& ResourceManager::cwd() 911 { 912 if (ResourceManager::getInstance()->_cwd.empty()) 1010 913 { 1011 914 char cwd[1024]; 1012 915 char* errorCode = getcwd(cwd, 1024); 1013 916 if (errorCode == 0) 1014 return NULL; 1015 1016 ResourceManager::getInstance()->_cwd = new char[strlen(cwd)+1]; 1017 strcpy(ResourceManager::getInstance()->_cwd, cwd); 917 return ResourceManager::getInstance()->_cwd; 918 919 ResourceManager::getInstance()->_cwd = cwd; 1018 920 } 1019 921 return ResourceManager::getInstance()->_cwd; … … 1026 928 * @returns true if the file exists, false otherwise 1027 929 */ 1028 bool ResourceManager::isInDataDir(const char*fileName)1029 { 1030 if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)930 bool ResourceManager::isInDataDir(const std::string& fileName) 931 { 932 if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty()) 1031 933 return false; 1032 934 1033 935 bool retVal = false; 1034 char* checkFile = new char[strlen(ResourceManager::getInstance()->getDataDir()) 1035 + strlen(fileName) + 1]; 1036 sprintf(checkFile, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName); 936 std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName; 1037 937 1038 938 if (ResourceManager::isFile(checkFile) || ResourceManager::isDir(checkFile)) … … 1040 940 else 1041 941 retVal = false; 1042 delete[] checkFile;1043 942 return retVal; 1044 943 } … … 1055 954 // if it is not initialized 1056 955 PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef); 1057 PRINT(0)(" Data-Directory is: %s\n", this->dataDir );956 PRINT(0)(" Data-Directory is: %s\n", this->dataDir.c_str()); 1058 957 PRINT(0)(" List of Image-Directories: "); 1059 std::vector< char*>::const_iterator imageDir;958 std::vector<std::string>::const_iterator imageDir; 1060 959 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 1061 PRINT(0)("%s ", (*imageDir) );960 PRINT(0)("%s ", (*imageDir).c_str()); 1062 961 PRINT(0)("\n"); 1063 962 … … 1068 967 { 1069 968 PRINT(0)("-----------------------------------------\n"); 1070 PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name , (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));969 PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name.c_str(), (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type)); 1071 970 1072 971 PRINT(0)("gets deleted at "); -
trunk/src/lib/util/loading/resource_manager.h
r7196 r7221 71 71 unsigned int count; //!< How many times this Resource has been loaded. 72 72 73 char*name; //!< Name of the Resource.73 std::string name; //!< Name of the Resource. 74 74 ResourceType type; //!< ResourceType of this Resource. 75 75 ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) … … 96 96 inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager(); return singletonRef; }; 97 97 98 bool setDataDir(const char*dataDir);98 bool setDataDir(const std::string& dataDir); 99 99 /** @returns the Name of the data directory */ 100 inline const char*getDataDir() const { return this->dataDir; };100 inline const std::string& getDataDir() const { return this->dataDir; }; 101 101 102 102 103 bool tryDataDir(const char*dataDir);104 bool verifyDataDir(const char*fileInside);105 bool addImageDir(const char*imageDir);103 bool tryDataDir(const std::string& dataDir); 104 bool verifyDataDir(const std::string& fileInside); 105 bool addImageDir(const std::string& imageDir); 106 106 107 bool cache(const char*fileName, ResourceType type, ResourcePriority prio = RP_NO,107 bool cache(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO, 108 108 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 109 109 BaseObject* copy(BaseObject* resourcePointer); 110 110 111 BaseObject* load(const char*fileName, ResourcePriority prio = RP_NO,111 BaseObject* load(const std::string& fileName, ResourcePriority prio = RP_NO, 112 112 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 113 BaseObject* load(const char*fileName, ResourceType type, ResourcePriority prio = RP_NO,113 BaseObject* load(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO, 114 114 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 115 115 bool unload(BaseObject* pointer, ResourcePriority prio = RP_NO); … … 117 117 bool unloadAllByPriority(ResourcePriority prio); 118 118 119 Resource* locateResourceByInfo(const char*fileName, ResourceType type,119 Resource* locateResourceByInfo(const std::string& fileName, ResourceType type, 120 120 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const; 121 121 Resource* locateResourceByPointer(const void* pointer) const; 122 122 123 char*toResourcableString(unsigned int i);124 bool fromResourceableString(const char*resourceableString);123 std::string toResourcableString(unsigned int i); 124 bool fromResourceableString(const std::string& resourceableString); 125 125 /** @returns the Count of Resources the ResourceManager handles */ 126 126 unsigned int resourceCount() const { return this->resourceList.size(); } … … 130 130 131 131 // utility functions for handling files in and around the data-directory 132 static bool isDir(const char*directory);133 static bool isFile(const char*fileName);134 static bool touchFile(const char*fileName);135 static bool deleteFile(const char*fileName);136 static char* homeDirCheck(const char*fileName);137 static char* getFullName(const char*fileName);138 static bool isInDataDir(const char*fileName);139 static char* getAbsDir(const char*fileName);140 static const char*cwd();132 static bool isDir(const std::string& directory); 133 static bool isFile(const std::string& fileName); 134 static bool touchFile(const std::string& fileName); 135 static bool deleteFile(const std::string& fileName); 136 static std::string homeDirCheck(const std::string& fileName); 137 static std::string getFullName(const std::string& fileName); 138 static bool isInDataDir(const std::string& fileName); 139 static std::string getAbsDir(const std::string& fileName); 140 static const std::string& cwd(); 141 141 142 142 static const char* ResourceTypeToChar(ResourceType type); … … 145 145 private: 146 146 ResourceManager(); 147 Resource* loadResource(const char*fileName, ResourceType type, ResourcePriority prio,147 Resource* loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio, 148 148 const MultiType& param0, const MultiType& param1, const MultiType& param2); 149 149 150 150 private: 151 static ResourceManager* singletonRef; //!< singleton Reference151 static ResourceManager* singletonRef; //!< singleton Reference 152 152 153 char*_cwd; //!< The currend Working directory.154 char*dataDir; //!< The Data Directory, where all relevant Data is stored.155 std::vector< char*>imageDirs; //!< A list of directories in which images are stored.153 std::string _cwd; //!< The currend Working directory. 154 std::string dataDir; //!< The Data Directory, where all relevant Data is stored. 155 std::vector<std::string> imageDirs; //!< A list of directories in which images are stored. 156 156 157 std::vector<Resource*> resourceList; //!< The List of Resources, that has already been loaded.157 std::vector<Resource*> resourceList; //!< The List of Resources, that has already been loaded. 158 158 159 static const char* resourceNames[RESOURCE_TYPE_SIZE];159 static const char* resourceNames[RESOURCE_TYPE_SIZE]; 160 160 }; 161 161 -
trunk/src/lib/util/multi_type.cc
r7201 r7221 39 39 switch (this->type) 40 40 { 41 default: 42 this->value.Float = 0.0f; 43 break; 41 44 case MT_BOOL: 42 45 this->value.Bool = false; … … 90 93 { 91 94 this->setChar(value); 92 }93 94 /**95 * @brief creates a multiType out of a C-String96 * @param value the Value of this MulitType97 */98 MultiType::MultiType(const char* value)99 {100 this->setString(value);101 95 } 102 96 … … 482 476 * @returns: the Type as MT_Type 483 477 */ 484 MT_Type MultiType::StringToMultiType(const char*type)485 { 486 if ( !strncmp(type, "bool", 4))478 MT_Type MultiType::StringToMultiType(const std::string& type) 479 { 480 if (type == "bool") 487 481 return MT_BOOL; 488 if ( !strncmp(type, "int", 3))482 if (type == "int") 489 483 return MT_INT; 490 if ( !strncmp(type, "float", 5))484 if (type, "float") 491 485 return MT_FLOAT; 492 if ( !strncmp(type, "char", 4))486 if (type == "char") 493 487 return MT_CHAR; 494 if ( !strncmp(type, "string", 6))488 if (type == "string") 495 489 return MT_STRING; 496 490 -
trunk/src/lib/util/multi_type.h
r7200 r7221 39 39 MultiType(double value); 40 40 MultiType(char value); 41 MultiType(const char* value);42 41 MultiType(const std::string& value); 43 42 MultiType(const MultiType& multiType); … … 95 94 96 95 static const char* MultiTypeToString(MT_Type type); 97 static MT_Type StringToMultiType(const char*type);96 static MT_Type StringToMultiType(const std::string& type); 98 97 99 98 private: … … 106 105 // std::string* String; 107 106 } value; 108 107 std::string storedString; 109 108 MT_Type type; 110 111 std::string storedString;112 109 }; 113 110 -
trunk/src/lib/util/substring.cc
r5656 r7221 14 14 15 15 2005-06-10: some naming conventions 16 17 // 18 // splitLine 19 // STL string tokenizer 20 // 21 // Created by Clemens Wacha. 22 // Version 1.0 23 // Copyright (c) 2005 Clemens Wacha. All rights reserved. 24 // 25 16 26 */ 17 27 … … 24 34 #include "substring.h" 25 35 26 #include "debug.h"27 36 #include <string.h> 28 #include <assert.h> 29 30 SubString::SubString( const char* string, char splitter) 31 { 32 this->splittersCount = 0; 33 if (string == NULL) 34 { 35 this->strings = NULL; 36 this->offsets = NULL; 37 return; 38 } 39 40 for( int i = 0; i < strlen(string); i++) 41 if( string[i] == splitter) 42 this->splittersCount++; 43 44 this->splittersCount += 1; 45 46 this->strings = new char*[this->splittersCount]; 47 this->offsets = new unsigned int[this->splittersCount]; 48 assert (this->strings != NULL && this->offsets != NULL); 49 50 int i = 0; 51 int l = 0; 52 53 if( this->splittersCount > 1) 54 { 55 const char* offset = string; 56 const char* end = strchr( string, splitter); 57 while( end != NULL) 58 { 59 assert( i < this->splittersCount); 60 l = end - offset; 61 this->strings[i] = new char[l + 1]; 62 assert( strings[i] != NULL); 63 strncpy( strings[i], offset, l); 64 strings[i][l] = '\0'; 65 this->offsets[i] = offset - string; 66 i++; 67 end++; 68 offset = end; 69 end = strchr( offset, splitter); 70 } 71 72 l = strlen( offset); 73 strings[i] = new char[l + 1]; 74 strncpy( strings[i], offset, l); 75 strings[i][l] = '\0'; 76 this->offsets[i] = offset - string; 77 } 78 else 79 { 80 this->strings[0] = new char[strlen(string)+1]; 81 strcpy(this->strings[0], string); 82 this->offsets[0] = 0; 83 } 84 } 85 37 #include <cassert> 38 39 SubString::SubString(const std::string& string, char splitter) 40 { 41 char split[2]; 42 split[0] = splitter; 43 split[1] = '\0'; 44 SubString::splitLine(this->strings, this->offsets, 45 string, split); 46 } 86 47 87 48 /** … … 91 52 * 92 53 */ 93 SubString::SubString(const char* string, bool whiteSpaces) 94 { 95 this->splittersCount = 0; 96 if (string == NULL || whiteSpaces == false) 54 SubString::SubString(const std::string& string, bool whiteSpaces) 55 { 56 SubString::splitLine(this->strings, this->offsets, 57 string); 58 } 59 SubString::SubString(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char) 60 { 61 SubString::splitLine(this->strings, this->offsets, 62 string, splitters, escapeChar, safemode_char); 63 } 64 65 /** 66 * An empty String 67 */ 68 const std::string SubString::emptyString = ""; 69 70 71 72 unsigned int SubString::split(const std::string& string, char splitter) 73 { 74 this->offsets.clear(); 75 this->strings.clear(); 76 char split[2]; 77 split[0] = splitter; 78 split[1] = '\0'; 79 SubString::splitLine(this->strings, this->offsets, string, split); 80 return strings.size(); 81 } 82 83 84 /** 85 * Splits a String into a Substring removing all whiteSpaces 86 * @param string the String to Split 87 * @param whiteSpaces MUST BE __TRUE__ 88 * 89 */ 90 unsigned int SubString::split(const std::string& string, bool whiteSpaces) 91 { 92 this->offsets.clear(); 93 this->strings.clear(); 94 SubString::splitLine(this->strings, this->offsets, string); 95 return strings.size(); 96 } 97 98 unsigned int SubString::split(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char) 99 { 100 this->offsets.clear(); 101 this->strings.clear(); 102 SubString::splitLine(this->strings, this->offsets, 103 string, splitters, escapeChar, safemode_char); 104 return strings.size(); 105 } 106 107 108 /** 109 * @brief splits line into tokens and stores them in ret. 110 * @param ret the Array, where the Splitted strings will be stored in 111 * @param offsets an Array of Offsets, here the distance from the inputstring 112 * to the beginning of the current token is stored 113 * @param line the inputLine to split 114 * @param delimiters a String of Delimiters (here the input will be splitted) 115 * @param escape_char: Escape carater (escapes splitters) 116 * @param safemode_char: the beginning of the safemode is marked with this 117 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 118 * @param start_state: the Initial state on how to parse the String. 119 * @returns SPLIT_LINE_STATE the parser was in when returning 120 * 121 * Supports delimiters, escape characters, 122 * ignores special characters between safemode_char and between comment_char and linend '\n'. 123 * 124 */ 125 SPLIT_LINE_STATE SubString::splitLine(std::vector<std::string>& ret, std::vector<unsigned int>& offsets, 126 const std::string& line, const std::string& delimiters, 127 char escape_char, char safemode_char, char comment_char, 128 SPLIT_LINE_STATE start_state) 129 { 130 SPLIT_LINE_STATE state = start_state; 131 unsigned int i = 0; 132 std::string token; 133 134 if(start_state != SL_NORMAL && ret.size() > 0) 97 135 { 98 this->strings = NULL; 99 this->offsets = NULL; 100 return; 136 token = ret[ret.size()-1]; 137 ret.pop_back(); 101 138 } 102 139 103 // chop the input to the beginning of something usefull 104 if (strlen(string) > 0) 105 string = string + strspn(string, " \t\n"); 106 107 // count the Splitters 108 bool lastWasWhiteSpace = false; 109 for(unsigned int i = 0; i < strlen(string); i++) 110 if( string[i] == ' ' || string[i] == '\t' || string[i] == '\n' ) 111 lastWasWhiteSpace = true; 112 else 140 while(i < line.size()) 141 { 142 switch(state) 113 143 { 114 if (lastWasWhiteSpace) 115 this->splittersCount ++; 116 lastWasWhiteSpace = false; 144 case SL_NORMAL: 145 if(line[i] == escape_char) 146 { 147 state = SL_ESCAPE; 148 } 149 else if(line[i] == safemode_char) 150 { 151 state = SL_SAFEMODE; 152 } 153 else if(line[i] == comment_char) 154 { 155 /// FINISH 156 if(token.size() > 0) 157 { 158 ret.push_back(token); 159 offsets.push_back(i); 160 token.clear(); 161 } 162 token += line[i]; // EAT 163 state = SL_COMMENT; 164 } 165 else if(delimiters.find(line[i]) != std::string::npos) 166 { 167 // line[i] is a delimiter 168 /// FINISH 169 if(token.size() > 0) 170 { 171 ret.push_back(token); 172 offsets.push_back(i); 173 token.clear(); 174 } 175 } 176 else 177 { 178 token += line[i]; // EAT 179 } 180 break; 181 case SL_ESCAPE: 182 if(line[i] == 'n') token += '\n'; 183 else if(line[i] == 't') token += '\t'; 184 else if(line[i] == 'v') token += '\v'; 185 else if(line[i] == 'b') token += '\b'; 186 else if(line[i] == 'r') token += '\r'; 187 else if(line[i] == 'f') token += '\f'; 188 else if(line[i] == 'a') token += '\a'; 189 else if(line[i] == '?') token += '\?'; 190 else token += line[i]; // EAT 191 state = SL_NORMAL; 192 break; 193 case SL_SAFEMODE: 194 if(line[i] == safemode_char) 195 { 196 state = SL_NORMAL; 197 } 198 else if(line[i] == escape_char) 199 { 200 state = SL_SAFEESCAPE; 201 } 202 else 203 { 204 token += line[i]; // EAT 205 } 206 break; 207 case SL_SAFEESCAPE: 208 if(line[i] == 'n') token += '\n'; 209 else if(line[i] == 't') token += '\t'; 210 else if(line[i] == 'v') token += '\v'; 211 else if(line[i] == 'b') token += '\b'; 212 else if(line[i] == 'r') token += '\r'; 213 else if(line[i] == 'f') token += '\f'; 214 else if(line[i] == 'a') token += '\a'; 215 else if(line[i] == '?') token += '\?'; 216 else token += line[i]; // EAT 217 state = SL_SAFEMODE; 218 break; 219 case SL_COMMENT: 220 if(line[i] == '\n') 221 { 222 /// FINISH 223 if(token.size() > 0) 224 { 225 ret.push_back(token); 226 offsets.push_back(i); 227 token.clear(); 228 } 229 state = SL_NORMAL; 230 } 231 else 232 { 233 token += line[i]; // EAT 234 } 235 break; 236 default: 237 // nothing 238 break; 117 239 } 118 this->splittersCount += 1; 119 120 // allocate memory 121 this->strings = new char*[this->splittersCount]; 122 this->offsets = new unsigned int[this->splittersCount]; 123 assert (this->strings != NULL && this->offsets != NULL); 124 125 126 // split the String into substrings 127 int l = 0; 128 unsigned int i = 0; 129 if( this->splittersCount > 1) 240 i++; 241 } 242 243 /// FINISH 244 if(token.size() > 0) 130 245 { 131 const char* offset = string; 132 const char* end = offset + strcspn(offset, " \t\n"); 133 for (i = 0; i < this->splittersCount; i++) 134 { 135 assert( i < this->splittersCount); 136 l = end - offset; 137 this->strings[i] = new char[l + 1]; 138 assert( strings[i] != NULL); 139 strncpy( strings[i], offset, l); 140 strings[i][l] = '\0'; 141 this->offsets[i] = offset - string; 142 end += strspn(end, " \t\n"); 143 offset = end; 144 end = offset + strcspn(offset, " \t\n"); 145 } 246 ret.push_back(token); 247 offsets.push_back(i); 248 token.clear(); 146 249 } 147 else 148 { 149 unsigned int length = strcspn(string, " \t\n"); 150 this->strings[0] = new char[length+1]; 151 strncpy(this->strings[0], string, length); 152 this->strings[0][length] = '\0'; 153 offsets[0] = 0; 154 } 155 } 156 157 SubString::SubString(const char* string, const char* splitters, char escapeChar) 158 { 159 this->splittersCount = 0; 160 if (string == NULL || splitters == NULL) 161 { 162 this->strings = NULL; 163 this->offsets = NULL; 164 return; 165 } 166 167 // chop the input to the beginning of something usefull 168 if (strlen(string) > 0) 169 string = string + strspn(string, splitters); 170 171 // count the Splitters 172 bool lastWasSplitter = false; 173 for(unsigned int i = 0; i < strlen(string); i++) 174 { 175 176 if( strchr(splitters, string[i] )) 177 lastWasSplitter = true; 178 else 179 { 180 if (lastWasSplitter) 181 { 182 this->splittersCount ++; 183 lastWasSplitter = false; 184 } 185 } 186 } 187 this->splittersCount += 1; 188 189 // allocate memory 190 this->strings = new char*[this->splittersCount]; 191 this->offsets = new unsigned int[this->splittersCount]; 192 assert (this->strings != NULL && this->offsets != NULL); 193 194 195 // split the String into substrings 196 int l = 0; 197 unsigned int i = 0; 198 if( this->splittersCount > 1) 199 { 200 const char* offset = string; 201 const char* end = offset + strcspn(offset, splitters); 202 for (i = 0; i < this->splittersCount; i++) 203 { 204 assert( i < this->splittersCount); 205 l = end - offset; 206 this->strings[i] = new char[l + 1]; 207 assert( strings[i] != NULL); 208 strncpy( strings[i], offset, l); 209 strings[i][l] = '\0'; 210 this->offsets[i] = offset - string; 211 end += strspn(end, splitters); 212 offset = end; 213 end = offset + strcspn(offset, splitters); 214 } 215 } 216 else 217 { 218 unsigned int length = strcspn(string, splitters); 219 this->strings[0] = new char[length+1]; 220 strncpy(this->strings[0], string, length); 221 this->strings[0][length] = '\0'; 222 offsets[0] = 0; 223 } 224 } 225 250 return(state); 251 } 226 252 227 253 /** … … 229 255 */ 230 256 SubString::~SubString() 231 { 232 if (this->strings) 233 { 234 for(unsigned int i = 0; i < this->splittersCount; i++) 235 delete[] this->strings[i]; 236 delete[] this->strings; 237 } 238 delete[] this->offsets; 239 } 240 241 /** 242 * get a particular substring 243 * @param i the ID of the substring to return 244 * @returns the designated substring or NULL if an invalid ID was given 245 */ 246 const char* SubString::getString(unsigned int i) 247 { 248 if( i < this->splittersCount && i >= 0) 249 return this->strings[i]; 250 else 251 return NULL; 252 } 257 { } 253 258 254 259 /** … … 259 264 unsigned int SubString::getOffset(unsigned int i) 260 265 { 261 if( i < this-> splittersCount&& i >= 0)266 if( i < this->offsets.size() && i >= 0) 262 267 return this->offsets[i]; 263 268 else … … 270 275 void SubString::debug() const 271 276 { 272 PRINT(0)("Substring-information::count=%d ::", this->splittersCount); 273 if (this->strings != NULL) 274 for (unsigned int i = 0; i < this->splittersCount; i++) 275 PRINT(0)("s%d='%s'::", i, this->strings[i]); 276 PRINT(0)("\n"); 277 } 277 printf("Substring-information::count=%d ::", this->strings.size()); 278 for (unsigned int i = 0; i < this->strings.size(); i++) 279 printf("s%d='%s'::", i, this->strings[i].c_str()); 280 printf("\n"); 281 } -
trunk/src/lib/util/substring.h
r6648 r7221 7 7 #define _SUBSTRING_H 8 8 9 #include <vector> 10 #include <string> 11 12 typedef enum { 13 SL_NORMAL, 14 SL_ESCAPE, 15 SL_SAFEMODE, 16 SL_SAFEESCAPE, 17 SL_COMMENT, 18 } SPLIT_LINE_STATE; 19 9 20 //! A class that can load one string and split it in multipe ones 10 21 class SubString 11 22 { 12 23 public: 13 SubString(const char* string, char splitter = ',');14 SubString(const char*string, bool whiteSpaces);15 SubString(const char* string, const char* splitters, char escapeChar ='\\');24 SubString(const std::string& string = "", char splitter = ','); 25 SubString(const std::string& string, bool whiteSpaces); 26 SubString(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 16 27 ~SubString(); 17 28 18 const char* operator[](unsigned int i) { return this->getString(i); }; 29 unsigned int split(const std::string& string = "", char splitter = ','); 30 unsigned int split(const std::string& string, bool whiteSpaces); 31 unsigned int split(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 19 32 20 inline unsigned int getCount() { return this->splittersCount; }; 21 const char* getString(unsigned int i); 33 34 const std::string& operator[](unsigned int i) { return this->getString(i); }; 35 36 inline unsigned int getCount() { return this->strings.size(); }; 37 const std::string& getString(unsigned int i) { return (i < this->strings.size()) ? this->strings[i] : emptyString; }; 22 38 unsigned int getOffset(unsigned int i); 39 40 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,std::vector<unsigned int>& offsets, 41 const std::string& line, const std::string& delimiters = " \t\r\n", 42 char escape_char = '\\', char safemode_char = '"', char comment_char = '\0', 43 SPLIT_LINE_STATE start_state = SL_NORMAL); 23 44 24 45 void debug() const; 25 46 26 47 private: 27 char** strings; //!< strings produced from a single string splitted in multiple strings 28 unsigned int* offsets; //!< offsets of the beginning of the input-string to the beginning of each substring. 29 unsigned int splittersCount; //!< how many splitted parts 48 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 49 std::vector<unsigned int> offsets; //!< offsets of the beginning of the input-string to the beginning of each substring. 50 51 static const std::string emptyString; 30 52 }; 31 53 -
trunk/src/orxonox.cc
r7193 r7221 86 86 this->port = -1; 87 87 88 this->configFileName = NULL;88 this->configFileName = ""; 89 89 } 90 90 … … 117 117 // orxonox class-stuff 118 118 delete this->iniParser; 119 delete[] this->configFileName;120 119 121 120 SDL_QuitSubSystem(SDL_INIT_TIMER); … … 162 161 163 162 /** 164 * this finds the config file163 * @brief this finds the config file 165 164 * @returns the new config-fileName 166 165 * Since the config file varies from user to user and since one may want to specify different config files … … 168 167 * it's path and name into configfilename 169 168 */ 170 const char*Orxonox::getConfigFile ()169 const std::string& Orxonox::getConfigFile () 171 170 { 172 171 if (ResourceManager::isFile("orxonox.conf")) 173 172 { 174 this->configFileName = new char[strlen("orxonox.conf")+1]; 175 strcpy(this->configFileName, "orxonox.conf"); 173 this->configFileName = "orxonox.conf"; 176 174 } 177 175 else … … 231 229 GraphicsEngine::getInstance()->initFromIniFile(this->iniParser); 232 230 233 char*iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp");234 if ( iconName != NULL)231 std::string iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); 232 if (!iconName.empty()) 235 233 { 236 234 GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName); 237 delete[] iconName;238 235 } 239 236 return 0; … … 301 298 302 299 // init the resource manager 303 const char*dataPath;304 if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL)300 std::string dataPath; 301 if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= "") 305 302 { 306 303 if (!ResourceManager::getInstance()->setDataDir(dataPath) && 307 304 !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 308 305 { 309 PRINTF(1)("Data Could not be located in %s\n", dataPath );306 PRINTF(1)("Data Could not be located in %s\n", dataPath.c_str()); 310 307 } 311 308 } … … 315 312 PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ 316 313 "!!! Please Change in File %s Section %s Entry %s to a suitable value !!!\n", 317 ResourceManager::getInstance()->getDataDir(),318 this->configFileName,314 ResourceManager::getInstance()->getDataDir().c_str(), 315 this->configFileName.c_str(), 319 316 CONFIG_SECTION_DATA, 320 317 CONFIG_NAME_DATADIR ); … … 325 322 } 326 323 //! @todo this is a hack and should be loadable 327 char*imageDir = ResourceManager::getInstance()->getFullName("maps");324 std::string imageDir = ResourceManager::getInstance()->getFullName("maps"); 328 325 ResourceManager::getInstance()->addImageDir(imageDir); 329 delete[] imageDir;330 326 imageDir = ResourceManager::getInstance()->getFullName("pictures"); 331 327 ResourceManager::getInstance()->addImageDir(imageDir); 332 delete[] imageDir;333 328 334 329 DynamicLoader::loadDyLib("libtest.so"); -
trunk/src/orxonox.h
r5996 r7221 32 32 Orxonox (); 33 33 34 void parseIniFile(const char*fileName);34 void parseIniFile(const std::string& fileName); 35 35 36 36 int initResources (); … … 41 41 int initMisc (); 42 42 43 const char*getConfigFile ();43 const std::string& getConfigFile (); 44 44 45 45 private: … … 47 47 48 48 IniParser* iniParser; //!< Reference to the ini-parser used in orxonox 49 char*configFileName; //!< Filename of the configuration-file.49 std::string configFileName; //!< Filename of the configuration-file. 50 50 GameLoader* gameLoader; //!< The gameLoader 51 51 -
trunk/src/story_entities/game_world.cc
r7193 r7221 145 145 GameLoader* loader = GameLoader::getInstance(); 146 146 147 if( getLoadFile() == NULL)147 if( getLoadFile().empty()) 148 148 { 149 149 PRINTF(1)("GameWorld has no path specified for loading\n"); … … 155 155 if( !XMLDoc->LoadFile()) 156 156 { 157 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getLoadFile() , XMLDoc->ErrorRow(), XMLDoc->ErrorCol());157 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getLoadFile().c_str(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 158 158 delete XMLDoc; 159 159 return (ErrorMessage){213,"XML File parsing error","GameWorld::load()"}; -
trunk/src/story_entities/game_world_data.cc
r7193 r7221 129 129 // load the parameters 130 130 // name 131 const char*string = grabParameter( root, "name");132 if( string == NULL)131 std::string string = grabParameter( root, "name"); 132 if( string.empty() ) 133 133 { 134 134 PRINTF(2)("GameWorld is missing a proper 'name'\n"); … … 136 136 } 137 137 else 138 this->setName(string );138 this->setName(string.c_str()); 139 139 140 140 this->loadGUI(root); … … 343 343 344 344 if (this->music != NULL) 345 this->setSoundTrack( NULL);345 this->setSoundTrack(""); 346 346 this->music = NULL; 347 347 /* stop the sound eninge */ … … 354 354 355 355 356 void GameWorldData::setSoundTrack(const char*name)356 void GameWorldData::setSoundTrack(const std::string& name) 357 357 { 358 358 if (this->music != NULL) … … 360 360 this->music = NULL; 361 361 362 if ( name != NULL)363 { 364 PRINTF(3)("Setting Sound Track to %s\n", name );365 char* oggFile = ResourceManager::getFullName(name); /// FIXME362 if (!name.empty()) 363 { 364 PRINTF(3)("Setting Sound Track to %s\n", name.c_str()); 365 std::string oggFile = ResourceManager::getFullName(name); 366 366 this->music = new OggPlayer(oggFile); 367 delete[] oggFile;368 367 369 368 //(OggPlayer*)ResourceManager::getInstance()->load(name, OGG, RP_LEVEL); -
trunk/src/story_entities/game_world_data.h
r7020 r7221 42 42 43 43 /* interface functions */ 44 void setSoundTrack(const char*name);44 void setSoundTrack(const std::string& name); 45 45 void loadGameRule(const TiXmlElement* root); 46 46 -
trunk/src/story_entities/movie_loader.cc
r7193 r7221 36 36 } 37 37 38 MovieLoader::~MovieLoader() 38 MovieLoader::~MovieLoader() 39 39 { 40 40 delete this->movie_player; … … 56 56 } 57 57 58 void MovieLoader::loadMovie(const char*filename)58 void MovieLoader::loadMovie(const std::string& filename) 59 59 { 60 60 movie_player->loadMovie(filename); … … 78 78 79 79 this->movie_player->start(0); 80 80 81 81 this->isRunning = true; 82 82 this->run(); … … 139 139 140 140 // calculate time difference in milliseconds (Uint32) 141 this->dt = currentFrame - this->lastFrame; 141 this->dt = currentFrame - this->lastFrame; 142 142 // calculate time difference in seconds (float) 143 143 this->dts = (float)this->dt / 1000.0f; -
trunk/src/story_entities/movie_loader.h
r7022 r7221 43 43 44 44 private: 45 void loadMovie(const char*filename);45 void loadMovie(const std::string& filename); 46 46 void setFPS(float fps); 47 47 void tick(); -
trunk/src/story_entities/simple_game_menu.cc
r7193 r7221 63 63 this->menuSelectedIndex = 0; 64 64 65 this->loadParams(root); 65 if (root != NULL) 66 this->loadParams(root); 66 67 67 68 State::setMenuID(this->getNextStoryID()); … … 70 71 71 72 /** 72 * remove the SimpleGameMenu from memory73 * @brief remove the SimpleGameMenu from memory 73 74 * 74 75 * delete everything explicitly, that isn't contained in the parenting tree! … … 85 86 86 87 /** 87 * loads the parameters of a SimpleGameMenu from an XML-element88 * @brief loads the parameters of a SimpleGameMenu from an XML-element 88 89 * @param root the XML-element to load from 89 90 */ … … 99 100 100 101 /** 101 * this is executed just before load102 * @brief this is executed just before load 102 103 * 103 104 * since the load function sometimes needs data, that has been initialized … … 125 126 126 127 /** 127 * load the data128 * @brief load the data 128 129 */ 129 130 ErrorMessage SimpleGameMenu::loadData() … … 265 266 266 267 /** 267 * start the menu268 * @brief start the menu 268 269 */ 269 270 bool SimpleGameMenu::start() -
trunk/src/story_entities/story_entity.cc
r7193 r7221 40 40 this->isRunning = false; 41 41 42 this->loadFile = NULL;42 this->loadFile = ""; 43 43 this->storyID = -1; 44 this->description = NULL;45 this->menuItemImage = NULL;46 this->menuScreenshoot = NULL;44 this->description = ""; 45 this->menuItemImage = ""; 46 this->menuScreenshoot = ""; 47 47 this->nextStoryID = WORLD_ID_GAMEEND; 48 48 this->bMenuEntry = false; … … 100 100 * @param name the name of the path 101 101 */ 102 void StoryEntity::setLoadFile(const char*fileName)102 void StoryEntity::setLoadFile(const std::string& fileName) 103 103 { 104 if (this->loadFile)105 delete this->loadFile;106 104 if (ResourceManager::isFile(fileName)) 107 105 { 108 this->loadFile = new char[strlen(fileName)+1]; 109 strcpy(this->loadFile, fileName); 106 this->loadFile = fileName; 110 107 } 111 108 else … … 120 117 * @param name name 121 118 */ 122 void StoryEntity::setDescription(const char*description)119 void StoryEntity::setDescription(const std::string& description) 123 120 { 124 if (this->description) 125 delete[] this->description; 126 if (description!= NULL) 127 { 128 this->description= new char[strlen(description)+1]; 129 strcpy(this->description, description); 130 } 131 else this->description= NULL; 121 this->description = description; 132 122 } 133 123 … … 149 139 { 150 140 PRINTF(3)("Grabbing the Worlds Settings\n", this->getLoadFile()); 151 if( getLoadFile() == NULL)152 return;141 if( getLoadFile().empty()) 142 return; 153 143 TiXmlDocument XMLDoc(this->getLoadFile()); 154 144 // load the xml world file for further loading 155 145 if( !XMLDoc.LoadFile()) 156 146 { 157 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc.ErrorDesc(), this->getLoadFile() , XMLDoc.ErrorRow(), XMLDoc.ErrorCol());147 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc.ErrorDesc(), this->getLoadFile().c_str(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); 158 148 return; 159 149 } … … 181 171 * @param name name 182 172 */ 183 void StoryEntity::setMenuItemImage(const char*image)173 void StoryEntity::setMenuItemImage(const std::string& image) 184 174 { 185 if (this->menuItemImage) 186 delete[] this->menuItemImage; 187 if (image != NULL) 188 { 189 this->menuItemImage = new char[strlen(image)+1]; 190 strcpy(this->menuItemImage, image); 191 } 192 else this->menuItemImage = NULL; 175 this->menuItemImage = image; 193 176 } 194 177 195 178 196 /** sets the menu screenshoot of this StoryEntity @param name name */ 197 void StoryEntity::setMenuScreenshoot(const char* image) 179 /** sets the menu screenshoot of this StoryEntity 180 * @param name name 181 */ 182 void StoryEntity::setMenuScreenshoot(const std::string& image) 198 183 { 199 if (this->menuScreenshoot) 200 delete[] this->menuScreenshoot; 201 if (image != NULL) 202 { 203 this->menuScreenshoot = new char[strlen(image)+1]; 204 strcpy(this->menuScreenshoot, image); 205 } 206 else this->menuScreenshoot = NULL; 184 this->menuScreenshoot = image; 207 185 } 208 186 -
trunk/src/story_entities/story_entity.h
r6993 r7221 61 61 inline int getStoryID() { return this->storyID; } 62 62 63 void setLoadFile( const char*fileName);63 void setLoadFile(const std::string& fileName); 64 64 /** @returns the Filename this StoryEntity was loaded with */ 65 const char*getLoadFile() const { return this->loadFile; }65 const std::string& getLoadFile() const { return this->loadFile; } 66 66 67 67 void setNextStoryID(int nextStoryID); 68 68 /** gets the story id of the current entity @returns story id */ 69 69 inline int getNextStoryID() const { return this->nextStoryID; } 70 inline void setDescription(const char*description);70 inline void setDescription(const std::string& description); 71 71 /** @returns the description of this StoryEntity */ 72 inline const char*getDescription() { return this->description; }72 inline const std::string& getDescription() { return this->description; } 73 73 74 74 void grabWorldInfo(); … … 78 78 inline bool isContainedInMenu() { return this->bMenuEntry; } 79 79 /** sets the menu item image of this StoryEntity @param name name */ 80 inline void setMenuItemImage(const char*image);80 inline void setMenuItemImage(const std::string& image); 81 81 /** @returns the menu item image of this StoryEntity */ 82 inline const char*getMenuItemImage() { return this->menuItemImage; }83 inline void setMenuScreenshoot(const char*image);82 inline const std::string& getMenuItemImage() { return this->menuItemImage; } 83 inline void setMenuScreenshoot(const std::string& image); 84 84 /** @returns the menu screenshoot of this StoryEntity */ 85 inline const char*getMenuScreenshoot() { return this->menuScreenshoot; }85 inline const std::string& getMenuScreenshoot() { return this->menuScreenshoot; } 86 86 87 87 protected: 88 bool isInit; //!< if the entity is initialized, this has to be true.89 bool isRunning; //!< is true if the entity is running90 bool isPaused; //!< is true if the entity is paused88 bool isInit; //!< if the entity is initialized, this has to be true. 89 bool isRunning; //!< is true if the entity is running 90 bool isPaused; //!< is true if the entity is paused 91 91 92 92 93 93 private: 94 int storyID; //!< this is the number of this entity, identifying it in a list/tree...95 int nextStoryID; //!< if this entity has finished, this entity shall be called96 char*loadFile; //!< The file from which this world is loaded94 int storyID; //!< this is the number of this entity, identifying it in a list/tree... 95 int nextStoryID; //!< if this entity has finished, this entity shall be called 96 std::string loadFile; //!< The file from which this world is loaded 97 97 98 char*description; //!< the description of the StoryEntity99 char*menuItemImage; //!< the item image of the StoryEntity100 char*menuScreenshoot; //!< the screenshoot of the StoryEntity101 bool bMenuEntry; //!< If true, this GameWorld apears in the SimpleMenu: SimpleMenu specific98 std::string description; //!< the description of the StoryEntity 99 std::string menuItemImage; //!< the item image of the StoryEntity 100 std::string menuScreenshoot; //!< the screenshoot of the StoryEntity 101 bool bMenuEntry; //!< If true, this GameWorld apears in the SimpleMenu: SimpleMenu specific 102 102 }; 103 103 -
trunk/src/subprojects/others/TTFtoIMG.cc
r6348 r7221 2 2 #include <SDL/SDL.h> 3 3 #include <SDL/SDL_ttf.h> 4 4 #include <string> 5 5 6 6 … … 16 16 17 17 18 void createAsciiImage(const char*fileName, unsigned int size)18 void createAsciiImage(const std::string& fileName, unsigned int size) 19 19 { 20 20 if (fontTTF == NULL) … … 68 68 } 69 69 } 70 SDL_SaveBMP(tmpSurf, fileName );70 SDL_SaveBMP(tmpSurf, fileName.c_str()); 71 71 SDL_FreeSurface(tmpSurf); 72 72 } … … 81 81 82 82 fontTTF = TTF_OpenFont(argv[1], renderSize); 83 83 84 84 createAsciiImage(argv[2], renderSize); 85 85 86 86 // delete fontTTF; 87 87 TTF_Quit(); -
trunk/src/util/Makefile.am
r7193 r7221 15 15 animation/animation_player.cc \ 16 16 \ 17 track/pilot_node.cc \ 18 track/track_manager.cc \ 17 track/pilot_node.cc 18 19 # track/track_manager.cc \ 19 20 track/track_node.cc 20 21 … … 31 32 animation/t_animation.h \ 32 33 \ 33 track/pilot_node.h \ 34 track/track_manager.h \ 34 track/pilot_node.h 35 36 # track/track_manager.h \ 35 37 track/track_node.h -
trunk/src/util/fast_factory.cc
r5750 r7221 29 29 * @return a new FastFactory 30 30 */ 31 FastFactory::FastFactory (ClassID classID, const char*fastFactoryName)31 FastFactory::FastFactory (ClassID classID, const std::string& fastFactoryName) 32 32 { 33 33 this->setClassID(CL_FAST_FACTORY, "FastFactory"); … … 119 119 * @returns true if found, false otherwise. 120 120 */ 121 FastFactory* FastFactory::searchFastFactory(const char*fastFactoryName)121 FastFactory* FastFactory::searchFastFactory(const std::string& fastFactoryName) 122 122 { 123 123 if (FastFactory::first == NULL) … … 128 128 while (tmpFac != NULL) 129 129 { 130 if ( strcmp(tmpFac->getName(), fastFactoryName))130 if (fastFactoryName == tmpFac->getName()) 131 131 return tmpFac; 132 132 tmpFac = tmpFac->next; -
trunk/src/util/fast_factory.h
r5447 r7221 80 80 81 81 static FastFactory* searchFastFactory(ClassID classID); 82 static FastFactory* searchFastFactory(const char*fastFactoryName);82 static FastFactory* searchFastFactory(const std::string& fastFactoryName); 83 83 84 84 ClassID getStoredID() const { return this->storedClassID; }; 85 85 86 86 protected: 87 FastFactory (ClassID classID, const char* fastFactoryName = NULL);87 FastFactory (ClassID classID, const std::string& fastFactoryName = ""); 88 88 89 89 /** sets the Next factory in the list @param nextFactory the next factory */ … … 121 121 { 122 122 public: 123 static tFastFactory<T>* getFastFactory(ClassID classID, const char*fastFactoryName = NULL);123 static tFastFactory<T>* getFastFactory(ClassID classID, const std::string& fastFactoryName = NULL); 124 124 125 125 private: 126 tFastFactory(ClassID classID, const char*fastFactoryName);126 tFastFactory(ClassID classID, const std::string& fastFactoryName); 127 127 128 128 virtual void fabricate(); … … 136 136 */ 137 137 template<class T> 138 tFastFactory<T>::tFastFactory(ClassID classID, const char*fastFactoryName)138 tFastFactory<T>::tFastFactory(ClassID classID, const std::string& fastFactoryName) 139 139 : FastFactory(classID, fastFactoryName) 140 140 {} … … 147 147 */ 148 148 template<class T> 149 tFastFactory<T>* tFastFactory<T>::getFastFactory(ClassID classID, const char*fastFactoryName)149 tFastFactory<T>* tFastFactory<T>::getFastFactory(ClassID classID, const std::string& fastFactoryName) 150 150 { 151 151 tFastFactory<T>* tmpFac = NULL; -
trunk/src/util/multiplayer_team_deathmatch.cc
r7193 r7221 92 92 93 93 94 void MultiplayerTeamDeathmatch::setDeathScreen(const char*imageName)94 void MultiplayerTeamDeathmatch::setDeathScreen(const std::string& imageName) 95 95 { 96 96 if( this->deathScreen) -
trunk/src/util/multiplayer_team_deathmatch.h
r7044 r7221 38 38 inline void setDeathPenaltyTimeout(float time) { this->deathTimeout = time; } 39 39 inline void setMaxKills(int kills) { this->maxKills = kills; } 40 void setDeathScreen(const char*imageName);40 void setDeathScreen(const std::string& imageName); 41 41 42 42 protected: -
trunk/src/util/object_manager.cc
r7198 r7221 97 97 * this function also does a transformation from omList as char* to OM_LIST. 98 98 */ 99 void ObjectManager::toList (WorldEntity* entity, const char*omList)99 void ObjectManager::toList (WorldEntity* entity, const std::string& omList) 100 100 { 101 101 this->toList(entity, ObjectManager::StringToOMList(omList)); … … 153 153 * @param level: level 0: only show list info; level 1: also show entities and their names. 154 154 */ 155 void ObjectManager::debug(const char*listName, unsigned int level)155 void ObjectManager::debug(const std::string& listName, unsigned int level) 156 156 { 157 157 PRINT(0)("=================================\n"); 158 158 PRINT(0)("=ObjectManager-DEBUG=============\n"); 159 159 PRINT(0)("=================================\n"); 160 if (listName == NULL || listName[0] == '\0')160 if (listName.empty()) 161 161 for (unsigned int i = 0; i < OM_SIZE; ++i) 162 162 debug((OM_LIST) i, level); … … 189 189 * @returns the OM_LIST transformed from listName. or the default, if not found or NULL. 190 190 */ 191 OM_LIST ObjectManager::StringToOMList(const char*listName)192 { 193 if (unlikely(listName == NULL)) return OM_DEFAULT_LIST;191 OM_LIST ObjectManager::StringToOMList(const std::string& listName) 192 { 193 if (unlikely(listName.empty())) return OM_DEFAULT_LIST; 194 194 195 195 for(unsigned int i = 0; i < OM_SIZE; ++i) { 196 if( !strcmp(listName, ObjectManager::objectManagerListNames[i])) {196 if(listName == ObjectManager::objectManagerListNames[i]) { 197 197 return (OM_LIST)i; 198 198 } -
trunk/src/util/object_manager.h
r6142 r7221 76 76 77 77 void toList (WorldEntity* entity, OM_LIST omList = OM_DEFAULT_LIST); 78 void toList (WorldEntity* entity, const char*omList);78 void toList (WorldEntity* entity, const std::string& omList); 79 79 80 80 … … 85 85 86 86 void debug(OM_LIST omList, unsigned int level = 0) const; 87 void debug(const char* listName = NULL, unsigned int level = 0);87 void debug(const std::string& listName = "", unsigned int level = 0); 88 88 89 static OM_LIST StringToOMList(const char*listName);89 static OM_LIST StringToOMList(const std::string& listName); 90 90 static const char* OMListToString(OM_LIST omList); 91 91 -
trunk/src/util/track/track_manager.cc
r7193 r7221 123 123 * @returns The TrackElement if Found, NULL otherwise. 124 124 */ 125 TrackElement* TrackElement::findByName(const char*trackName)125 TrackElement* TrackElement::findByName(const std::string& trackName) 126 126 { 127 127 // return if Found. … … 532 532 * @param trackName the Name of the Track to work on 533 533 */ 534 void TrackManager::workOnS(const char*trackName)534 void TrackManager::workOnS(const std::string& trackName) 535 535 { 536 536 TrackElement* tmpElem = this->firstTrackElem->findByName(trackName); … … 657 657 @todo this must be better 658 658 */ 659 void TrackManager::setSavePointS(const char*nextElementName)659 void TrackManager::setSavePointS(const std::string& nextElementName) 660 660 { 661 661 this->setSavePoint(NULL); … … 725 725 for(int i = 0; i < count; i++) 726 726 { 727 this->firstTrackElem->findByID(trackIDs[i])->setName(va_arg(name, const char*));727 this->firstTrackElem->findByID(trackIDs[i])->setName(va_arg(name, const std::string&)); 728 728 } 729 729 va_end(name); … … 734 734 \see TrackManager::fork(unsigned int count, ...) 735 735 */ 736 void TrackManager::forkS(const char*forkString)736 void TrackManager::forkS(const std::string& forkString) 737 737 { 738 738 SubString strings(forkString, ','); … … 860 860 for(int i = 0; i < count; i++) 861 861 { 862 const char*name = va_arg (NAME, char*);862 const std::string& name = va_arg (NAME, char*); 863 863 TrackElement* tmpElem = this->firstTrackElem->findByName(name); 864 864 if (tmpElem) … … 875 875 \see void TrackManager::join(unsigned int count, ...) 876 876 */ 877 void TrackManager::joinS(const char*joinString)877 void TrackManager::joinS(const std::string& joinString) 878 878 { 879 879 SubString strings(joinString, ','); … … 884 884 for(unsigned int i = 0; i < strings.getCount(); i++) 885 885 { 886 TrackElement* tmpElem = this->firstTrackElem->findByName(strings.getString(i) );886 TrackElement* tmpElem = this->firstTrackElem->findByName(strings.getString(i).c_str()); 887 887 if (tmpElem != NULL) 888 888 trackIDs[i] = tmpElem->ID; 889 889 else 890 890 { 891 PRINTF(1)("Trying to join a Track, of which the name does not exist: %s\n", strings.getString(i) );891 PRINTF(1)("Trying to join a Track, of which the name does not exist: %s\n", strings.getString(i).c_str()); 892 892 trackIDs[i] = -1; 893 893 } -
trunk/src/util/track/track_manager.h
r7130 r7221 46 46 47 47 TrackElement* findByID(unsigned int trackID); 48 TrackElement* findByName(const char*trackName);48 TrackElement* findByName(const std::string& trackName); 49 49 bool backLoopCheck() const; 50 50 … … 142 142 // Methods to change the Path (initialisation) 143 143 void workOn(unsigned int trackID); 144 void workOnS(const char*trackName);144 void workOnS(const std::string& trackName); 145 145 146 146 /** \see setCurveType(CurveType curveType, TrackElement* trackElem); @param curveType the type of the Curve */ … … 153 153 void addHotPoint(float x, float y, float z); 154 154 int addHotPointV(Vector newPoint, TrackElement* trackElem = NULL); 155 void setSavePointS(const char*nextElementName);155 void setSavePointS(const std::string& nextElementName); 156 156 void setSavePoint(TrackElement* trackElem = NULL); 157 157 void fork(unsigned int count, ...); 158 158 void forkS(unsigned int count, ...); 159 void forkS(const char*forkString);159 void forkS(const std::string& forkString); 160 160 void forkV(unsigned int count, int* trackIDs, char** trackNames, TrackElement* trackElem = NULL); 161 161 void condition(unsigned int trackID, CONDITION cond, void* subject); 162 162 void condition(CONDITION cond, void* subject, TrackElement* trackElem = NULL); 163 163 void join(unsigned int count, ...); 164 void joinS(const char*joinString);164 void joinS(const std::string& joinString); 165 165 void joinS(unsigned int cound, ...); 166 166 void joinV(unsigned int count, int* trackIDs); -
trunk/src/world_entities/creatures/md2_creature.cc
r7193 r7221 52 52 * @param fileName the name of the File to load the MD2Creature from (absolute path) 53 53 */ 54 MD2Creature::MD2Creature(const char*fileName)54 MD2Creature::MD2Creature(const std::string& fileName) 55 55 { 56 56 this->init(); … … 59 59 if(!doc.LoadFile()) 60 60 { 61 PRINTF(2)("Loading file %s failed for md2 creature.\n", fileName );61 PRINTF(2)("Loading file %s failed for md2 creature.\n", fileName.c_str()); 62 62 return; 63 63 } … … 255 255 this->shiftCoor (move); 256 256 257 if( this->bJump )257 if( this->bJump && likely(this->getModel(0) != NULL)) 258 258 { 259 259 ((MD2Model*)this->getModel(0))->setAnim(JUMP); 260 260 } 261 else if( this->bFire )261 else if( this->bFire && likely(this->getModel(0) != NULL)) 262 262 { 263 263 if( ((MD2Model*)this->getModel(0))->getAnim() != ATTACK) ((MD2Model*)this->getModel(0))->setAnim(ATTACK); 264 264 } 265 else if( fabs(move.len()) > 0.0f )265 else if( fabs(move.len()) > 0.0f && likely(this->getModel(0) != NULL)) 266 266 { 267 267 if( ((MD2Model*)this->getModel(0))->getAnim() != RUN) ((MD2Model*)this->getModel(0))->setAnim(RUN); 268 268 } 269 else 269 else if (likely(this->getModel(0) != NULL)) 270 270 { 271 271 if( ((MD2Model*)this->getModel(0))->getAnim() != STAND) ((MD2Model*)this->getModel(0))->setAnim(STAND); -
trunk/src/world_entities/creatures/md2_creature.h
r7092 r7221 19 19 public: 20 20 21 MD2Creature(const char*fileName);21 MD2Creature(const std::string& fileName); 22 22 MD2Creature(const TiXmlElement* root = NULL); 23 23 virtual ~MD2Creature(); -
trunk/src/world_entities/elements/image_entity.cc
r7193 r7221 106 106 * @param textureFile The texture-file to load onto the crosshair 107 107 */ 108 void ImageEntity::setTexture(const char*textureFile)108 void ImageEntity::setTexture(const std::string& textureFile) 109 109 { 110 110 this->material->setDiffuseMap(textureFile); -
trunk/src/world_entities/elements/image_entity.h
r7016 r7221 30 30 31 31 void setSize(float sizeX, float sizeY); 32 void setTexture(const char*textureFile);32 void setTexture(const std::string& textureFile); 33 33 /** @param rotationSpeed the speed at what the crosshair should rotate */ 34 34 void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; }; -
trunk/src/world_entities/elements/text_element.cc
r7193 r7221 70 70 } 71 71 72 void TextElement::setText(const char*text)72 void TextElement::setText(const std::string& text) 73 73 { 74 74 Text::setText(text); 75 75 } 76 76 77 void TextElement::setFont(const char*font)77 void TextElement::setFont(const std::string& font) 78 78 { 79 79 Text::setFont(font, (unsigned int)this->getSizeY2D()); -
trunk/src/world_entities/elements/text_element.h
r7019 r7221 29 29 virtual void loadParams(const TiXmlElement* root); 30 30 31 void setText(const char*text);32 void setFont(const char*font);31 void setText(const std::string& text); 32 void setFont(const std::string& font); 33 33 34 34 private: -
trunk/src/world_entities/movie_entity.cc
r7193 r7221 74 74 } 75 75 76 void MovieEntity::loadMovie(const char*filename)76 void MovieEntity::loadMovie(const std::string& filename) 77 77 { 78 78 if(media_container->loadMedia(filename)) -
trunk/src/world_entities/movie_entity.h
r7010 r7221 37 37 virtual void loadParams(const TiXmlElement* root); 38 38 39 void loadMovie(const char*filename);39 void loadMovie(const std::string& filename); 40 40 void setAxis(float axis); 41 41 void setRotation(float rotation); -
trunk/src/world_entities/planet.cc
r7193 r7221 45 45 this->toList(OM_GROUP_01); 46 46 47 this->material = new Material();48 47 //this->material->setIllum(20); 49 48 //this->material->setAmbient(0.1, 0.1, 0.1); … … 71 70 { 72 71 PRINTF(5)("Deleting Planet\n"); 73 if( this->material)74 delete this->material;75 72 } 76 73 … … 92 89 * @param textureName the top texture. 93 90 */ 94 void Planet::setTexture(const char*textureName)91 void Planet::setTexture(const std::string& textureName) 95 92 { 96 this->material ->setDiffuseMap(textureName);93 this->material.setDiffuseMap(textureName); 97 94 } 98 95 … … 124 121 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 125 122 126 this->material ->select();123 this->material.select(); 127 124 128 125 // /WorldEntity::draw(); -
trunk/src/world_entities/planet.h
r6959 r7221 9 9 /* INCLUDES */ 10 10 #include "world_entity.h" 11 11 #include "material.h" 12 12 /* FORWARD DECLARATION */ 13 class Material;14 13 class Texture; 15 14 … … 26 25 void setSize(float size); 27 26 /** assumes jpg as input-format */ 28 void setTexture(const char*textureName);27 void setTexture(const std::string& textureName); 29 28 30 29 … … 34 33 35 34 private: 36 Material *material; //!< Materials for the Planet. sorted by number (0-5) top, bottom, left, right, front, back35 Material material; //!< Materials for the Planet. sorted by number (0-5) top, bottom, left, right, front, back 37 36 Texture* texture; //!< Textures for the CubeMap. 38 37 -
trunk/src/world_entities/power_ups/param_power_up.cc
r7193 r7221 81 81 } 82 82 83 void ParamPowerUp::setType(const char*type)83 void ParamPowerUp::setType(const std::string& type) 84 84 { 85 85 for(int i = 0; i < POWERUP_PARAM_size; ++i) { 86 if( strcmp(type, paramTypes[i]) == 0) {86 if(type == paramTypes[i]) { 87 87 this->type = (EnumParamPowerUpType)i; 88 88 break; -
trunk/src/world_entities/power_ups/param_power_up.h
r7065 r7221 28 28 void setMaxValue(float value); 29 29 void setMinValue(float value); 30 void setType(const char*type);30 void setType(const std::string& type); 31 31 EnumParamPowerUpType getType(); 32 32 float getValue(); … … 43 43 44 44 private: 45 static const char* paramTypes[]; 46 EnumParamPowerUpType type; 47 float value; 48 float max_value; 49 float min_value; 45 EnumParamPowerUpType type; 46 float value; 47 float max_value; 48 float min_value; 49 50 static const char* paramTypes[]; 51 50 52 }; 51 53 -
trunk/src/world_entities/power_ups/power_up.cc
r7193 r7221 33 33 this->respawnStart = 10; 34 34 this->model = NULL; 35 /* if(!PowerUp::sphereModel) {*/35 /* if(!PowerUp::sphereModel) {*/ 36 36 37 37 Model* sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); … … 75 75 76 76 77 void PowerUp::loadPickupSound(const char*pickupSound)77 void PowerUp::loadPickupSound(const std::string& pickupSound) 78 78 { 79 79 if (this->pickupBuffer != NULL) 80 80 ResourceManager::getInstance()->unload(this->pickupBuffer); 81 81 82 else if ( pickupSound != NULL)83 {84 this->pickupBuffer = (SoundBuffer*)ResourceManager::getInstance()->load(pickupSound, WAV);85 if (this->pickupBuffer != NULL)86 {87 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", pickupSound, this->getName());88 }89 else90 {91 PRINTF(2)("Failed to load sound %s to pickup %s.\n.", pickupSound, this->getName());92 }93 }82 else if (!pickupSound.empty()) 83 { 84 this->pickupBuffer = (SoundBuffer*)ResourceManager::getInstance()->load(pickupSound, WAV); 85 if (this->pickupBuffer != NULL) 86 { 87 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", pickupSound.c_str(), this->getName()); 88 } 89 else 90 { 91 PRINTF(2)("Failed to load sound %s to pickup %s.\n.", pickupSound.c_str(), this->getName()); 92 } 93 } 94 94 else 95 95 this->pickupBuffer = NULL; 96 96 } 97 97 98 void PowerUp::loadRespawnSound(const char*respawnSound)98 void PowerUp::loadRespawnSound(const std::string& respawnSound) 99 99 { 100 100 if (this->respawnBuffer != NULL) 101 101 ResourceManager::getInstance()->unload(this->respawnBuffer); 102 102 103 else if ( respawnSound != NULL)103 else if (!respawnSound.empty()) 104 104 { 105 105 this->respawnBuffer = (SoundBuffer*)ResourceManager::getInstance()->load(respawnSound, WAV); 106 106 if (this->respawnBuffer != NULL) 107 107 { 108 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", respawnSound , this->getName());108 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", respawnSound.c_str(), this->getName()); 109 109 } 110 110 else 111 111 { 112 PRINTF(2)("Failed to load sound %s to respawn %s.\n.", respawnSound , this->getName());112 PRINTF(2)("Failed to load sound %s to respawn %s.\n.", respawnSound.c_str(), this->getName()); 113 113 } 114 114 } … … 128 128 this->soundSource.play(this->pickupBuffer); 129 129 130 switch(respawnType) { 131 case RESPAWN_NONE: 132 this->toList(OM_DEAD); 133 break; 134 case RESPAWN_TIME: 135 this->toList(OM_DEAD_TICK); 136 this->respawnTime = this->respawnStart; 137 break; 130 switch(respawnType) 131 { 132 case RESPAWN_NONE: 133 this->toList(OM_DEAD); 134 break; 135 case RESPAWN_TIME: 136 this->toList(OM_DEAD_TICK); 137 this->respawnTime = this->respawnStart; 138 break; 138 139 } 139 140 } … … 141 142 } 142 143 143 void PowerUp::tick(float dt) { 144 if(this->getOMListNumber() != OM_COMMON) { 144 void PowerUp::tick(float dt) 145 { 146 if(this->getOMListNumber() != OM_COMMON) 147 { 145 148 this->respawnTime -= dt; 146 149 if(this->respawnTime <= 0) … … 157 160 void PowerUp::draw() const 158 161 { 159 if(this->model != NULL) { 162 if(this->model != NULL) 163 { 160 164 glMatrixMode(GL_MODELVIEW); 161 165 glPushMatrix(); … … 172 176 } 173 177 174 const char* PowerUp::respawnTypes[] = { 175 "none", 176 "time" 177 }; 178 179 void PowerUp::setRespawnType(const char* type) 180 { 181 for(int i = 0; i < RESPAWN_size; ++i) { 182 if(!strcmp(type, respawnTypes[i])) { 178 const char* PowerUp::respawnTypes[] = 179 { 180 "none", 181 "time" 182 }; 183 184 185 void PowerUp::setRespawnType(const std::string& type) 186 { 187 for(int i = 0; i < RESPAWN_size; ++i) 188 { 189 if(type == respawnTypes[i]) 190 { 183 191 this->respawnType = (PowerUpRespawn)i; 184 192 break; -
trunk/src/world_entities/power_ups/power_up.h
r7102 r7221 26 26 void collidesWith (WorldEntity* entity, const Vector& location); 27 27 28 void loadPickupSound(const char*pickupSound);29 void loadRespawnSound(const char* pickupSound);28 void loadPickupSound(const std::string& pickupSound); 29 void loadRespawnSound(const std::string& respawnSound); 30 30 31 31 virtual void draw () const; 32 32 virtual void tick(float dt); 33 void setRespawnType(const char*type);33 void setRespawnType(const std::string& type); 34 34 void setRespawnTime(const float respawn); 35 35 … … 45 45 46 46 private: 47 SoundSource soundSource;48 SoundBuffer* pickupBuffer;49 SoundBuffer* respawnBuffer;50 Material* sphereMaterial;51 PowerUpRespawn respawnType;52 float respawnTime;53 float respawnStart;54 static const char* respawnTypes[];47 SoundSource soundSource; 48 SoundBuffer* pickupBuffer; 49 SoundBuffer* respawnBuffer; 50 Material* sphereMaterial; 51 PowerUpRespawn respawnType; 52 float respawnTime; 53 float respawnStart; 54 static const char* respawnTypes[]; 55 55 56 WorldEntity* collider;56 WorldEntity* collider; 57 57 }; 58 58 -
trunk/src/world_entities/power_ups/weapon_power_up.cc
r7193 r7221 92 92 } 93 93 94 void WeaponPowerUp::setWeaponClass(const char*name)94 void WeaponPowerUp::setWeaponClass(const std::string& name) 95 95 { 96 96 this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name)); 97 97 if (this->weapon == NULL) 98 98 { 99 PRINTF(1)("Unable to load Weapon. %s\n", name );99 PRINTF(1)("Unable to load Weapon. %s\n", name.c_str()); 100 100 this->weapon = dynamic_cast<Weapon*>(Factory::fabricate("Turret")); 101 101 } -
trunk/src/world_entities/power_ups/weapon_power_up.h
r7065 r7221 22 22 23 23 Weapon* getWeapon(); 24 void setWeaponClass(const char*name);24 void setWeaponClass(const std::string& name); 25 25 26 26 virtual int writeBytes(const byte* data, int length, int sender); -
trunk/src/world_entities/projectiles/projectile.cc
r7193 r7221 61 61 62 62 63 void Projectile::loadExplosionSound(const char*explosionSound)63 void Projectile::loadExplosionSound(const std::string& explosionSound) 64 64 { 65 65 if (this->explosionBuffer != NULL) 66 66 ResourceManager::getInstance()->unload(this->explosionBuffer); 67 67 68 else if ( explosionSound != NULL)68 else if (!explosionSound.empty()) 69 69 { 70 70 this->explosionBuffer = (SoundBuffer*)ResourceManager::getInstance()->load(explosionSound, WAV); 71 71 if (this->explosionBuffer != NULL) 72 72 { 73 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound , this->getName());73 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound.c_str(), this->getName()); 74 74 } 75 75 else 76 76 { 77 PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound , this->getName());77 PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound.c_str(), this->getName()); 78 78 } 79 79 } … … 83 83 84 84 85 void Projectile::loadEngineSound(const char*engineSound)85 void Projectile::loadEngineSound(const std::string& engineSound) 86 86 { 87 87 if (this->engineBuffer != NULL) 88 88 ResourceManager::getInstance()->unload(this->engineBuffer); 89 89 90 else if ( engineSound != NULL)90 else if (!engineSound.empty()) 91 91 { 92 92 this->engineBuffer = (SoundBuffer*)ResourceManager::getInstance()->load(engineSound, WAV); 93 93 if (this->engineBuffer != NULL) 94 94 { 95 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound , this->getName());95 PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound.c_str(), this->getName()); 96 96 } 97 97 else 98 98 { 99 PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound , this->getName());99 PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound.c_str(), this->getName()); 100 100 } 101 101 } -
trunk/src/world_entities/projectiles/projectile.h
r7193 r7221 26 26 void setLifeSpan(float lifeSpan); 27 27 28 void loadExplosionSound(const char*explosionSound);29 void loadEngineSound(const char*engineSound);28 void loadExplosionSound(const std::string& explosionSound); 29 void loadEngineSound(const std::string& engineSound); 30 30 void setMinEnergy(float energyMin); 31 31 /** @returns the minimal charched energy */ -
trunk/src/world_entities/recorder.cc
r7193 r7221 54 54 55 55 LoadParam(root, "duration", this, Recorder, setStreamDuration); 56 56 57 LoadParam(root, "fps", this, Recorder, setFPS); 58 57 59 LoadParam(root, "name", this, Recorder, initVideo); 58 60 } … … 71 73 72 74 73 void Recorder::initVideo(const char*filename)75 void Recorder::initVideo(const std::string& filename) 74 76 { 75 77 frame_count = 0; … … 78 80 79 81 // auto detect the output format from the name, default is mpeg 80 output_format = guess_format(NULL, filename , NULL);82 output_format = guess_format(NULL, filename.c_str(), NULL); 81 83 if (!output_format) 82 84 { … … 93 95 94 96 format_context->oformat = output_format; 95 snprintf(format_context->filename, sizeof(format_context->filename), "%s", filename );97 snprintf(format_context->filename, sizeof(format_context->filename), "%s", filename.c_str()); 96 98 97 99 // add video stream using the default format codec and initialize the codec … … 104 106 105 107 // print some information 106 dump_format(format_context, 0, filename , 1);108 dump_format(format_context, 0, filename.c_str(), 1); 107 109 108 110 // now that all the parameters are set, we can open the … … 110 112 if(video_stream) 111 113 this->openVideo(); 112 114 113 115 // open the output file, if needed 114 116 if(!(output_format->flags & AVFMT_NOFILE)) 115 117 { 116 if(url_fopen(&format_context->pb, filename , URL_WRONLY) < 0)117 PRINTF(1)("Could not open %s\n", filename );118 if(url_fopen(&format_context->pb, filename.c_str(), URL_WRONLY) < 0) 119 PRINTF(1)("Could not open %s\n", filename.c_str()); 118 120 } 119 121 120 122 // write the stream header, if any 121 av_write_header(format_context); 123 av_write_header(format_context); 122 124 } 123 125 … … 129 131 av_free(buffer); 130 132 131 // write the trailer, if any 133 // write the trailer, if any 132 134 av_write_trailer(format_context); 133 135 134 136 // free the streams 135 137 for(int i = 0; i < format_context->nb_streams; i++) … … 175 177 176 178 void Recorder::allocPicture() 177 { 179 { 178 180 picture = avcodec_alloc_frame(); 179 181 if(!picture) … … 189 191 return; 190 192 } 191 avpicture_fill((AVPicture *)picture, picture_buf, 193 avpicture_fill((AVPicture *)picture, picture_buf, 192 194 codec_context->pix_fmt, width, height); 193 195 … … 211 213 if (!video_stream) 212 214 PRINTF(1)("Could not alloc stream\n"); 213 215 214 216 codec_context = video_stream->codec; 215 217 codec_context->codec_id = output_format->video_codec; … … 219 221 codec_context->bit_rate = 400000; 220 222 // resolution must be a multiple of two 221 codec_context->width = State::getResX(); 223 codec_context->width = State::getResX(); 222 224 codec_context->height = State::getResY(); 223 225 … … 229 231 // timebase should be 1/framerate and timestamp increments should be 230 232 // identically 1 231 codec_context->time_base.den = (int)stream_frame_rate; 233 codec_context->time_base.den = (int)stream_frame_rate; 232 234 codec_context->time_base.num = 1; 233 235 codec_context->gop_size = 12; // emit one intra frame every twelve frames at most … … 235 237 236 238 if (codec_context->codec_id == CODEC_ID_MPEG1VIDEO) 237 // needed to avoid using macroblocks in which some coeffs overflow 238 // this doesnt happen with normal video, it just happens here as the 239 // needed to avoid using macroblocks in which some coeffs overflow 240 // this doesnt happen with normal video, it just happens here as the 239 241 // motion of the chroma plane doesnt match the luma plane 240 242 codec_context->mb_decision=2; … … 275 277 { 276 278 int out_size, err; 277 279 278 280 codec_context = video_stream->codec; 279 281 280 282 if(frame_count >= stream_nb_frames) 281 283 { … … 287 289 this->fillYuvImage(); 288 290 289 291 290 292 if(format_context->oformat->flags & AVFMT_RAWPICTURE) 291 293 { … … 293 295 // futur for that 294 296 av_init_packet(&packet); 295 297 296 298 packet.flags |= PKT_FLAG_KEY; 297 299 packet.stream_index= video_stream->index; 298 300 packet.data= (uint8_t *)picture; 299 301 packet.size= sizeof(AVPicture); 300 302 301 303 err = av_write_frame(format_context, &packet); 302 304 } … … 309 311 { 310 312 av_init_packet(&packet); 311 313 312 314 packet.pts= av_rescale_q(codec_context->coded_frame->pts, codec_context->time_base, video_stream->time_base); 313 315 if(codec_context->coded_frame->key_frame) … … 316 318 packet.data= buffer; 317 319 packet.size= out_size; 318 320 319 321 // write the compressed frame in the media file 320 322 err = av_write_frame(format_context, &packet); -
trunk/src/world_entities/recorder.h
r6981 r7221 20 20 class Recorder : public WorldEntity 21 21 { 22 private:23 AVFrame* picture;24 uint8_t* buffer;25 int frame_count;26 int buffer_size;27 28 AVOutputFormat* output_format;29 AVFormatContext* format_context;30 AVCodecContext* codec_context;31 AVCodec *codec;32 AVStream* video_stream;33 AVPacket packet;34 double video_pts;35 36 uint8_t *picture_buf;37 int size;38 39 int height;40 int width;41 float time;42 43 float stream_duration;44 float stream_frame_rate;45 int stream_nb_frames;46 47 AVFrame* RGB_frame;48 22 public: 49 23 Recorder (const TiXmlElement* root = NULL); … … 56 30 57 31 private: 58 void initVideo(const char*filename);32 void initVideo(const std::string& filename); 59 33 void addVideoStream(); 60 34 void openVideo(); … … 66 40 void setStreamDuration(float duration); 67 41 void setFPS(float fps); 42 43 44 private: 45 AVFrame* picture; 46 uint8_t* buffer; 47 int frame_count; 48 int buffer_size; 49 50 AVOutputFormat* output_format; 51 AVFormatContext* format_context; 52 AVCodecContext* codec_context; 53 AVCodec* codec; 54 AVStream* video_stream; 55 AVPacket packet; 56 double video_pts; 57 58 uint8_t* picture_buf; 59 int size; 60 61 int height; 62 int width; 63 float time; 64 65 float stream_duration; 66 float stream_frame_rate; 67 int stream_nb_frames; 68 69 AVFrame* RGB_frame; 68 70 }; 69 71 -
trunk/src/world_entities/skybox.cc
r7193 r7221 38 38 * @param fileName the file to take as input for the SkyBox 39 39 */ 40 SkyBox::SkyBox(const char*fileName)40 SkyBox::SkyBox(const std::string& fileName) 41 41 { 42 42 this->preInit(); 43 if ( fileName)43 if (!fileName.empty()) 44 44 this->setTextureAndType(fileName, ".jpg"); 45 45 this->postInit(); … … 89 89 this->setParentMode(PNODE_MOVEMENT); 90 90 91 this->textureName = NULL;91 this->textureName = ""; 92 92 } 93 93 … … 106 106 for (int i = 0; i < 6; i++) 107 107 { 108 if (this->material[i])108 if (this->material[i]) 109 109 delete this->material[i]; 110 if (this->cubeTexture[i])110 if (this->cubeTexture[i]) 111 111 ResourceManager::getInstance()->unload(this->cubeTexture[i]); 112 112 } 113 113 } 114 115 void SkyBox::setTexture(const std::string& name) 116 { 117 this->textureName = name; 118 this->setTextureAndType (name, "jpg"); 119 }; 120 114 121 115 122 /** … … 122 129 "skybox_right.jpg", "skybox_front.jpg", "skybox_back.jpg"); 123 130 */ 124 void SkyBox::setTextureAndType(const char* name, const char* extension) 125 { 126 char* top = new char[strlen(name)+strlen(extension)+ 10]; 127 char* bottom = new char[strlen(name)+strlen(extension)+ 10]; 128 char* left = new char[strlen(name)+strlen(extension)+ 10]; 129 char* right = new char[strlen(name)+strlen(extension)+ 10]; 130 char* front = new char[strlen(name)+strlen(extension)+ 10]; 131 char* back = new char[strlen(name)+strlen(extension)+ 10]; 132 133 sprintf(top, "%s_top.%s", name, extension); 134 sprintf(bottom, "%s_bottom.%s", name, extension); 135 sprintf(left, "%s_left.%s", name, extension); 136 sprintf(right, "%s_right.%s", name, extension); 137 sprintf(front, "%s_front.%s", name, extension); 138 sprintf(back, "%s_back.%s", name, extension); 131 void SkyBox::setTextureAndType(const std::string& name, const std::string& extension) 132 { 133 std::string top = name + "_top." + extension; 134 std::string bottom = name + "_bottom." + extension; 135 std::string left = name + "_left." + extension; 136 std::string right = name + "_right." + extension; 137 std::string front = name + "_front." + extension; 138 std::string back = name + "_back." + extension; 139 139 140 140 this->setTextures(top, bottom, left, right, front, back); 141 142 // deleted alocated memory of this function143 delete []top;144 delete []bottom;145 delete []left;146 delete []right;147 delete []front;148 delete []back;149 141 } 150 142 … … 158 150 * @param back the back texture. 159 151 */ 160 void SkyBox::setTextures(const char* top, const char* bottom, const char*left,161 const char* right, const char* front, const char*back)152 void SkyBox::setTextures(const std::string& top, const std::string& bottom, const std::string& left, 153 const std::string& right, const std::string& front, const std::string& back) 162 154 { 163 155 this->material[0]->setDiffuseMap(top); … … 171 163 } 172 164 173 void SkyBox::loadCubeMapTextures(const char* top, const char* bottom, const char*left,174 const char* right, const char* front, const char*back)165 void SkyBox::loadCubeMapTextures(const std::string& top, const std::string& bottom, const std::string& left, 166 const std::string& right, const std::string& front, const std::string& back) 175 167 { 176 168 this->cubeTexture[0] = (Texture*)ResourceManager::getInstance()->load(top, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT); … … 304 296 305 297 SYNCHELP_READ_FLOAT( size, NWT_SB_SIZE ); 306 if ( textureName)298 if ( !this->textureName.empty() ) 307 299 { 308 delete[] textureName; 309 textureName = NULL; 300 textureName = ""; 310 301 } 311 SYNCHELP_READ_STRINGM( textureName, NWT_SB_TEXTURENAME ); 302 char* texName; 303 SYNCHELP_READ_STRINGM( texName, NWT_SB_TEXTURENAME ); 312 304 313 305 this->setSize( size ); 314 this->setTextureAndType( tex tureName, "jpg" );306 this->setTextureAndType( texName, "jpg" ); 315 307 this->rebuild(); 316 308 … … 338 330 339 331 SYNCHELP_WRITE_FLOAT(this->size, NWT_SB_SIZE); 340 SYNCHELP_WRITE_STRING(this->textureName , NWT_SB_TEXTURENAME);332 SYNCHELP_WRITE_STRING(this->textureName.c_str(), NWT_SB_TEXTURENAME); 341 333 342 334 return SYNCHELP_WRITE_N; -
trunk/src/world_entities/skybox.h
r6771 r7221 28 28 { 29 29 public: 30 SkyBox(const char* fileName = NULL);30 SkyBox(const std::string& fileName = ""); 31 31 SkyBox(const TiXmlElement* root); 32 32 … … 44 44 void setSize(float size); 45 45 /** assumes jpg as input-format */ 46 void setTexture(const char* name) { if (textureName) delete[] textureName; textureName = new char[strlen(name)+1]; strcpy(textureName, name); this->setTextureAndType (name, "jpg"); };46 void setTexture(const std::string& name); 47 47 48 void setTextureAndType(const char* name, const char*extension);49 void setTextures(const char* top, const char* bottom, const char*left,50 const char* right, const char* front, const char*back);48 void setTextureAndType(const std::string& name, const std::string& extension); 49 void setTextures(const std::string& top, const std::string& bottom, const std::string& left, 50 const std::string& right, const std::string& front, const std::string& back); 51 51 52 void loadCubeMapTextures(const char* top, const char* bottom, const char*left,53 const char* right, const char* front, const char*back);52 void loadCubeMapTextures(const std::string& top, const std::string& bottom, const std::string& left, 53 const std::string& right, const std::string& front, const std::string& back); 54 54 55 55 GLuint getTexture(SKY_SIDE side) const { return (this->material[side]) ? this->material[side]->getDiffuseTexture(): 0; }; … … 71 71 float size; //!< Size of the SkyBox. This should match the frustum maximum range. 72 72 float textureSize; //!< this is the length of a texture (assumes a square texture) 73 char*textureName; //!< Name of the Texture73 std::string textureName; //!< Name of the Texture 74 74 75 75 }; -
trunk/src/world_entities/space_ships/helicopter.cc
r7193 r7221 55 55 * @param fileName the name of the File to load the helicopter from (absolute path) 56 56 */ 57 Helicopter::Helicopter(const char*fileName)57 Helicopter::Helicopter(const std::string& fileName) 58 58 { 59 59 this->init(); … … 62 62 if(!doc.LoadFile()) 63 63 { 64 PRINTF(2)("Loading file %s failed for Helicopter.\n", fileName );64 PRINTF(2)("Loading file %s failed for Helicopter.\n", fileName.c_str()); 65 65 return; 66 66 } … … 110 110 this->loadModel("models/ships/helicopter_#.obj", 1.0); 111 111 112 EventHandler::getInstance()->grabEvents(true);112 //EventHandler::getInstance()->grabEvents(true); 113 113 114 114 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; -
trunk/src/world_entities/space_ships/helicopter.h
r7092 r7221 17 17 18 18 Helicopter(); 19 Helicopter(const char*fileName);19 Helicopter(const std::string& fileName); 20 20 Helicopter(const TiXmlElement* root); 21 21 virtual ~Helicopter(); -
trunk/src/world_entities/space_ships/hover.cc
r7193 r7221 47 47 * @param fileName the name of the File to load the hover from (absolute path) 48 48 */ 49 Hover::Hover(const char*fileName)49 Hover::Hover(const std::string& fileName) 50 50 { 51 51 this->init(); … … 54 54 if(!doc.LoadFile()) 55 55 { 56 PRINTF(2)("Loading file %s failed for Hover.\n", fileName );56 PRINTF(2)("Loading file %s failed for Hover.\n", fileName.c_str()); 57 57 return; 58 58 } -
trunk/src/world_entities/space_ships/hover.h
r7092 r7221 14 14 public: 15 15 16 Hover(const char*fileName);16 Hover(const std::string& fileName); 17 17 Hover(const TiXmlElement* root = NULL); 18 18 virtual ~Hover(); -
trunk/src/world_entities/space_ships/space_ship.cc
r7193 r7221 69 69 * @param fileName the name of the File to load the spaceship from (absolute path) 70 70 */ 71 SpaceShip::SpaceShip(const char*fileName)71 SpaceShip::SpaceShip(const std::string& fileName) 72 72 { 73 73 this->init(); … … 76 76 if(!doc.LoadFile()) 77 77 { 78 PRINTF(2)("Loading file %s failed for spaceship.\n", fileName );78 PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); 79 79 return; 80 80 } -
trunk/src/world_entities/space_ships/space_ship.h
r7116 r7221 21 21 22 22 public: 23 SpaceShip(const char*fileName);23 SpaceShip(const std::string& fileName); 24 24 SpaceShip(const TiXmlElement* root = NULL); 25 25 virtual ~SpaceShip(); -
trunk/src/world_entities/space_ships/turbine_hover.cc
r7193 r7221 49 49 * @param fileName the name of the File to load the turbine_hover from (absolute path) 50 50 */ 51 TurbineHover::TurbineHover(const char*fileName)51 TurbineHover::TurbineHover(const std::string& fileName) 52 52 { 53 53 this->init(); … … 56 56 if(!doc.LoadFile()) 57 57 { 58 PRINTF(2)("Loading file %s failed for TurbineHover.\n", fileName );58 PRINTF(2)("Loading file %s failed for TurbineHover.\n", fileName.c_str()); 59 59 return; 60 60 } -
trunk/src/world_entities/space_ships/turbine_hover.h
r7092 r7221 18 18 public: 19 19 20 TurbineHover(const char*fileName);20 TurbineHover(const std::string& fileName); 21 21 TurbineHover(const TiXmlElement* root = NULL); 22 22 virtual ~TurbineHover(); -
trunk/src/world_entities/terrain.cc
r7193 r7221 48 48 this->loadParams(root); 49 49 50 // if (this->model != NULL)51 50 // if (this->model != NULL) 51 //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f); 52 52 } 53 53 … … 59 59 this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found. 60 60 */ 61 Terrain::Terrain(const char*fileName)61 Terrain::Terrain(const std::string& fileName) 62 62 { 63 63 this->init(); 64 64 65 if ( !strstr(fileName, ".obj") || !strstr(fileName, ".OBJ"))66 67 68 65 if (fileName.rfind(".obj" ) != -1 || fileName.rfind(".OBJ") != -1 ) 66 { 67 this->loadModel(fileName); 68 } 69 69 else 70 71 72 70 { 71 // load the hightMap here. 72 } 73 73 } 74 74 … … 98 98 99 99 if(this->heightMap) 100 100 delete heightMap; 101 101 } 102 102 … … 122 122 123 123 LoadParam(root, "scale", this, Terrain, setScale) 124 124 .describe("The scale in x,y,z direction"); 125 125 126 126 LoadParam(root, "texture", this, Terrain, loadTexture) 127 127 .describe("The name of the Texture for this heightMap"); 128 128 129 129 LoadParam(root, "vegetation", this, Terrain, loadVegetation) 130 130 .describe("the fileName of the vegetation, that should be loaded onto this terrain. (must be relative to the data-dir)") ; 131 131 132 132 LoadParam(root, "height-map", this, Terrain, loadHeightMap) 133 133 .describe("The HeightMap, splitted into two strings seperated by ','. 1: HeighMap, 2: ColorMap"); 134 134 135 135 } … … 140 140 } 141 141 142 void Terrain::loadHeightMap(const char* heightMapFile, const char*colorMap)142 void Terrain::loadHeightMap(const std::string& heightMapFile, const std::string& colorMap) 143 143 { 144 144 if (this->heightMap != NULL) … … 146 146 this->heightMap = NULL; 147 147 148 char*hmName = ResourceManager::getFullName(heightMapFile);149 char*hmColorName = ResourceManager::getFullName(colorMap);148 std::string hmName = ResourceManager::getFullName(heightMapFile); 149 std::string hmColorName = ResourceManager::getFullName(colorMap); 150 150 151 151 152 152 this->heightMap = new HeightMap(hmName, hmColorName); 153 // heightMap->scale(Vector(43.0f,4.7f,43.0f));153 // heightMap->scale(Vector(43.0f,4.7f,43.0f)); 154 154 heightMap->scale(this->terrainScale); 155 155 heightMap->setAbsCoor(this->getAbsCoor()); 156 156 heightMap->load(); 157 delete[] hmName; 158 delete[] hmColorName; 159 160 } 161 162 163 void Terrain::loadTexture(const char* textureName) 164 { 165 PRINTF(0)("Load texture: %s\n", textureName); 166 167 heightMapMaterial->setDiffuse(1.0,1.0,1.0); 168 heightMapMaterial->setAmbient(1.0,1.0,1.0 ); 169 heightMapMaterial->setSpecular(1.0,1.0,1.0); 170 heightMapMaterial->setShininess(.5); 171 heightMapMaterial->setTransparency(1.0); 172 173 heightMapMaterial->setDiffuseMap(textureName); 174 heightMapMaterial->setAmbientMap(textureName); 175 heightMapMaterial->setSpecularMap(textureName); 176 } 177 178 179 180 void Terrain::loadVegetation(const char* vegetationFile) 181 { 182 PRINTF(0)("loadVegetation: %s\n", vegetationFile); 157 } 158 159 160 void Terrain::loadTexture(const std::string& textureName) 161 { 162 PRINTF(4)("Load texture: %s\n", textureName.c_str()); 163 164 heightMapMaterial->setDiffuse(1.0,1.0,1.0); 165 heightMapMaterial->setAmbient(1.0,1.0,1.0 ); 166 heightMapMaterial->setSpecular(1.0,1.0,1.0); 167 heightMapMaterial->setShininess(.5); 168 heightMapMaterial->setTransparency(1.0); 169 170 heightMapMaterial->setDiffuseMap(textureName); 171 // heightMapMaterial->setAmbientMap(textureName); 172 // heightMapMaterial->setSpecularMap(textureName); 173 } 174 175 176 177 void Terrain::loadVegetation(const std::string& vegetationFile) 178 { 179 PRINTF(4)("loadVegetation: %s\n", vegetationFile.c_str()); 183 180 if (this->vegetation) 184 181 ResourceManager::getInstance()->unload(this->vegetation, RP_LEVEL); 185 if ( vegetationFile != NULL)186 { 187 PRINTF(4)("fetching %s\n", vegetationFile );182 if (!vegetationFile.empty()) 183 { 184 PRINTF(4)("fetching %s\n", vegetationFile.c_str()); 188 185 this->vegetation = dynamic_cast<Model*>(ResourceManager::getInstance()->load(vegetationFile, OBJ, RP_CAMPAIGN)); 189 186 } … … 205 202 this->getAbsCoor ().z); 206 203 /* rotate */ 207 // Vector tmpRot = this->getAbsDir().getSpacialAxis();204 // Vector tmpRot = this->getAbsDir().getSpacialAxis(); 208 205 //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 209 206 … … 227 224 228 225 229 /*230 glMatrixMode(GL_MODELVIEW);231 glPushMatrix();232 glLoadIdentity();233 Vector camera = State::getCameraNode()->getAbsCoor(); // Go on here ..........!!!234 235 float height = heightMap->getHeight(camera.x, camera.z);236 237 glEnable (GL_COLOR_MATERIAL) ;238 glBegin(GL_QUADS); // Draw The Cube Using quads239 glColor3f(0.0f,1.0f,0.0f); // Color Blue240 glVertex3f(camera.x + 63.0f,Terrain->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Right Of The Quad (Top)241 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Left Of The Quad (Top)242 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Left Of The Quad (Top)243 glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Right Of The Quad (Top)244 glEnd(); // End Drawing The Plan245 246 glPopMatrix();*/247 248 249 /* THIS IS ONLY FOR DEBUGGING INFORMATION */226 /* 227 glMatrixMode(GL_MODELVIEW); 228 glPushMatrix(); 229 glLoadIdentity(); 230 Vector camera = State::getCameraNode()->getAbsCoor(); // Go on here ..........!!! 231 232 float height = heightMap->getHeight(camera.x, camera.z); 233 234 glEnable (GL_COLOR_MATERIAL) ; 235 glBegin(GL_QUADS); // Draw The Cube Using quads 236 glColor3f(0.0f,1.0f,0.0f); // Color Blue 237 glVertex3f(camera.x + 63.0f,Terrain->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Right Of The Quad (Top) 238 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Left Of The Quad (Top) 239 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Left Of The Quad (Top) 240 glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Right Of The Quad (Top) 241 glEnd(); // End Drawing The Plan 242 243 glPopMatrix();*/ 244 245 246 /* THIS IS ONLY FOR DEBUGGING INFORMATION */ 250 247 if (this->ssp != NULL) 251 248 this->ssp->drawQuadtree(); … … 257 254 // if the terrain is the Terrain of Dave 258 255 if (debugTerrain == TERRAIN_DAVE) 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 256 { 257 objectList = glGenLists(1); 258 glNewList (objectList, GL_COMPILE); 259 260 glColor3f(1.0,0,0); 261 262 int sizeX = 100; 263 int sizeZ = 80; 264 float length = 1000; 265 float width = 200; 266 float widthX = float (length /sizeX); 267 float widthZ = float (width /sizeZ); 268 269 float height [sizeX][sizeZ]; 270 Vector normal_vectors[sizeX][sizeZ]; 271 272 273 for ( int i = 0; i<sizeX-1; i+=1) 274 for (int j = 0; j<sizeZ-1;j+=1) 275 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 279 276 #ifdef __WIN32__ 280 277 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5; 281 278 #else 282 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;279 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5; 283 280 #endif 284 281 285 //Die Huegel ein wenig glaetten 286 for (int h=1; h<2;h++) 287 for (int i=1;i<sizeX-2 ;i+=1 ) 288 for(int j=1;j<sizeZ-2;j+=1) 289 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 290 291 //Berechnung von normalen Vektoren 292 for(int i=1;i<sizeX-2;i+=1) 293 for(int j=1;j<sizeZ-2 ;j+=1) 294 { 295 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); 296 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); 297 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); 298 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); 299 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); 300 301 Vector c1 = v2 - v1; 302 Vector c2 = v3 - v1; 303 Vector c3= v4 - v1; 304 Vector c4 = v5 - v1; 305 Vector zero = Vector (0,0,0); 306 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); 307 normal_vectors[i][j].normalize(); 308 } 309 310 glBegin(GL_QUADS); 311 int snowheight=3; 312 for ( int i = 0; i<sizeX; i+=1) 313 for (int j = 0; j<sizeZ;j+=1) 314 { 315 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); 316 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); 317 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); 318 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); 319 float a[3]; 320 if(height[i][j]<snowheight){ 321 a[0]=0; 322 a[1]=1.0-height[i][j]/10-.3; 323 a[2]=0; 324 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 325 } 326 else{ 327 a[0]=1.0; 328 a[1]=1.0; 329 a[2]=1.0; 330 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 331 332 } 333 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 334 glVertex3f(v1.x, v1.y, v1.z); 335 if(height[i+1][j]<snowheight){ 336 a[0]=0; 337 a[1] =1.0-height[i+1][j]/10-.3; 338 a[2]=0; 339 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 340 } 341 else{ 342 a[0]=1.0; 343 a[1]=1.0; 344 a[2]=1.0; 345 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 346 347 } 348 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 349 glVertex3f(v2.x, v2.y, v2.z); 350 if(height[i+1][j+1]<snowheight){ 351 a[0]=0; 352 a[1] =1.0-height[i+1][j+1]/10-.3; 353 a[2]=0; 354 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 355 } 356 else{ 357 a[0]=1.0; 358 a[1]=1.0; 359 a[2]=1.0; 360 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 361 362 363 } 364 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 365 glVertex3f(v3.x, v3.y, v3.z); 366 if(height[i][j+1]<snowheight){ 367 a[0]=0; 368 a[1] =1.0-height[i+1][j+1]/10-.3; 369 a[2]=0; 370 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 371 } 372 else{ 373 a[0]=1.0; 374 a[1]=1.0; 375 a[2]=1.0; 376 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 377 } 378 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 379 glVertex3f(v4.x, v4.y, v4.z); 380 381 } 382 glEnd(); 383 glEndList(); 384 } 282 //Die Huegel ein wenig glaetten 283 for (int h=1; h<2;h++) 284 for (int i=1;i<sizeX-2 ;i+=1 ) 285 for(int j=1;j<sizeZ-2;j+=1) 286 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 287 288 //Berechnung von normalen Vektoren 289 for(int i=1;i<sizeX-2;i+=1) 290 for(int j=1;j<sizeZ-2 ;j+=1) 291 { 292 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); 293 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); 294 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); 295 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); 296 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); 297 298 Vector c1 = v2 - v1; 299 Vector c2 = v3 - v1; 300 Vector c3= v4 - v1; 301 Vector c4 = v5 - v1; 302 Vector zero = Vector (0,0,0); 303 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); 304 normal_vectors[i][j].normalize(); 305 } 306 307 glBegin(GL_QUADS); 308 int snowheight=3; 309 for ( int i = 0; i<sizeX; i+=1) 310 for (int j = 0; j<sizeZ;j+=1) 311 { 312 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); 313 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); 314 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); 315 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); 316 float a[3]; 317 if(height[i][j]<snowheight) 318 { 319 a[0]=0; 320 a[1]=1.0-height[i][j]/10-.3; 321 a[2]=0; 322 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 323 } 324 else 325 { 326 a[0]=1.0; 327 a[1]=1.0; 328 a[2]=1.0; 329 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 330 331 } 332 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 333 glVertex3f(v1.x, v1.y, v1.z); 334 if(height[i+1][j]<snowheight) 335 { 336 a[0]=0; 337 a[1] =1.0-height[i+1][j]/10-.3; 338 a[2]=0; 339 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 340 } 341 else 342 { 343 a[0]=1.0; 344 a[1]=1.0; 345 a[2]=1.0; 346 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 347 348 } 349 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 350 glVertex3f(v2.x, v2.y, v2.z); 351 if(height[i+1][j+1]<snowheight) 352 { 353 a[0]=0; 354 a[1] =1.0-height[i+1][j+1]/10-.3; 355 a[2]=0; 356 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 357 } 358 else 359 { 360 a[0]=1.0; 361 a[1]=1.0; 362 a[2]=1.0; 363 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 364 365 366 } 367 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 368 glVertex3f(v3.x, v3.y, v3.z); 369 if(height[i][j+1]<snowheight) 370 { 371 a[0]=0; 372 a[1] =1.0-height[i+1][j+1]/10-.3; 373 a[2]=0; 374 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 375 } 376 else 377 { 378 a[0]=1.0; 379 a[1]=1.0; 380 a[2]=1.0; 381 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 382 } 383 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 384 glVertex3f(v4.x, v4.y, v4.z); 385 386 } 387 glEnd(); 388 glEndList(); 389 } 385 390 386 391 if (debugTerrain == TERRAIN_BENSCH) 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 392 { 393 /* 394 this->model = (OBJModel*) new Model(); 395 this->model->setName("CUBE"); 396 this->model->addVertex (-0.5, -0.5, 0.5); 397 this->model->addVertex (0.5, -0.5, 0.5); 398 this->model->addVertex (-0.5, 0.5, 0.5); 399 this->model->addVertex (0.5, 0.5, 0.5); 400 this->model->addVertex (-0.5, 0.5, -0.5); 401 this->model->addVertex (0.5, 0.5, -0.5); 402 this->model->addVertex (-0.5, -0.5, -0.5); 403 this->model->addVertex (0.5, -0.5, -0.5); 404 405 this->model->addVertexTexture (0.0, 0.0); 406 this->model->addVertexTexture (1.0, 0.0); 407 this->model->addVertexTexture (0.0, 1.0); 408 this->model->addVertexTexture (1.0, 1.0); 409 this->model->addVertexTexture (0.0, 2.0); 410 this->model->addVertexTexture (1.0, 2.0); 411 this->model->addVertexTexture (0.0, 3.0); 412 this->model->addVertexTexture (1.0, 3.0); 413 this->model->addVertexTexture (0.0, 4.0); 414 this->model->addVertexTexture (1.0, 4.0); 415 this->model->addVertexTexture (2.0, 0.0); 416 this->model->addVertexTexture (2.0, 1.0); 417 this->model->addVertexTexture (-1.0, 0.0); 418 this->model->addVertexTexture (-1.0, 1.0); 419 420 this->model->finalize(); 421 */ 422 } 418 423 } 419 424 … … 453 458 454 459 void Terrain::writeDebug( ) const 455 { 456 } 460 {} 457 461 458 462 void Terrain::readDebug( ) const 459 { 460 } 463 {} 461 464 462 465 float Terrain::getHeight(float x, float y) 463 466 { 464 465 466 467 } 467 if(this->heightMap != NULL) 468 return (this->heightMap->getHeight(x, y)); 469 return 0; 470 } -
trunk/src/world_entities/terrain.h
r7046 r7221 29 29 public: 30 30 Terrain(const TiXmlElement* root = NULL); 31 Terrain(const char*fileName);31 Terrain(const std::string& fileName); 32 32 Terrain(DebugTerrain debugTerrain); 33 33 virtual ~Terrain(); … … 41 41 virtual void loadParams(const TiXmlElement* root); 42 42 43 void loadVegetation(const char*vegetationFile);43 void loadVegetation(const std::string& vegetationFile); 44 44 45 void loadHeightMap(const char* heightMapFile, const char* colorMap = NULL);46 void loadTexture(const char*textureName);45 void loadHeightMap(const std::string& heightMapFile, const std::string& colorMap); 46 void loadTexture(const std::string& textureName); 47 47 void setScale(float x, float y, float z); 48 48 -
trunk/src/world_entities/weapons/aim.cc
r7193 r7221 147 147 * @param textureFile The texture-file to load onto the crosshair 148 148 */ 149 void Aim::setTexture(const char*textureFile)149 void Aim::setTexture(const std::string& textureFile) 150 150 { 151 151 this->material->setDiffuseMap(textureFile); -
trunk/src/world_entities/weapons/aim.h
r6724 r7221 46 46 47 47 void setSize(float size); 48 void setTexture(const char*textureFile);48 void setTexture(const std::string& textureFile); 49 49 /** @param rotationSpeed the speed at what the crosshair should rotate */ 50 50 inline void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; }; -
trunk/src/world_entities/weapons/aiming_turret.cc
r7193 r7221 168 168 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 169 169 170 this->getModel()->draw(); 170 if (this->getModel()) 171 this->getModel()->draw(); 171 172 glPopMatrix(); 172 173 } -
trunk/src/world_entities/weapons/crosshair.cc
r7193 r7221 79 79 EventListener::loadParams(root); 80 80 81 LoadParam(root, "texture", this , Crosshair, setTexture)81 LoadParam(root, "texture", this->material, Material, setDiffuseMap) 82 82 .describe("the texture-file to load onto the Crosshair"); 83 83 … … 103 103 * @param textureFile The texture-file to load onto the crosshair 104 104 */ 105 void Crosshair::setTexture(const char*textureFile)105 void Crosshair::setTexture(const std::string& textureFile) 106 106 { 107 107 this->material->setDiffuseMap(textureFile); -
trunk/src/world_entities/weapons/crosshair.h
r6512 r7221 31 31 32 32 void setSize(float size); 33 void setTexture(const char*textureFile);33 void setTexture(const std::string& textureFile); 34 34 /** @param rotationSpeed the speed at what the crosshair should rotate */ 35 35 void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; }; -
trunk/src/world_entities/weapons/weapon.cc
r7193 r7221 165 165 * @param projectile the Name of the Projectile. 166 166 */ 167 void Weapon::setProjectileTypeC(const char* projectile) 168 { 169 if (projectile == NULL) 170 return; 167 void Weapon::setProjectileTypeC(const std::string& projectile) 168 { 171 169 FastFactory* tmpFac = FastFactory::searchFastFactory(projectile); 172 170 if (tmpFac != NULL) … … 176 174 else 177 175 { 178 PRINTF(1)("Projectile %s does not exist for weapon %s\n", projectile , this->getName());176 PRINTF(1)("Projectile %s does not exist for weapon %s\n", projectile.c_str(), this->getName()); 179 177 } 180 178 } … … 232 230 * @param soundFile the soundFile's relative position to the data-directory (will be looked for by the ResourceManager) 233 231 */ 234 void Weapon::setActionSound(WeaponAction action, const char*soundFile)232 void Weapon::setActionSound(WeaponAction action, const std::string& soundFile) 235 233 { 236 234 if (action >= WA_ACTION_COUNT) … … 239 237 ResourceManager::getInstance()->unload(this->soundBuffers[action]); 240 238 241 else if ( soundFile != NULL)239 else if (!soundFile.empty()) 242 240 { 243 241 this->soundBuffers[action] = (SoundBuffer*)ResourceManager::getInstance()->load(soundFile, WAV); 244 242 if (this->soundBuffers[action] != NULL) 245 243 { 246 PRINTF(4)("Loaded sound %s to action %s.\n", soundFile , actionToChar(action));244 PRINTF(4)("Loaded sound %s to action %s.\n", soundFile.c_str(), actionToChar(action)); 247 245 } 248 246 else 249 247 { 250 PRINTF(2)("Failed to load sound %s to %s.\n.", soundFile , actionToChar(action));248 PRINTF(2)("Failed to load sound %s to %s.\n.", soundFile.c_str(), actionToChar(action)); 251 249 } 252 250 } … … 613 611 * @return The Action if known, WA_NONE otherwise. 614 612 */ 615 WeaponAction Weapon::charToAction(const char*action)616 { 617 if ( !strcmp(action, "none"))613 WeaponAction Weapon::charToAction(const std::string& action) 614 { 615 if (action == "none") 618 616 return WA_NONE; 619 else if ( !strcmp(action, "shoot"))617 else if (action == "shoot") 620 618 return WA_SHOOT; 621 else if ( !strcmp(action, "charge"))619 else if (action == "charge") 622 620 return WA_CHARGE; 623 else if ( !strcmp(action, "reload"))621 else if (action == "reload") 624 622 return WA_RELOAD; 625 else if ( !strcmp(action, "acitvate"))623 else if (action == "acitvate") 626 624 return WA_ACTIVATE; 627 else if ( !strcmp(action, "deactivate"))625 else if (action == "deactivate") 628 626 return WA_DEACTIVATE; 629 else if ( !strcmp(action, "special1"))627 else if (action == "special1") 630 628 return WA_SPECIAL1; 631 629 else 632 630 { 633 PRINTF(2)("action %s could not be identified.\n", action );631 PRINTF(2)("action %s could not be identified.\n", action.c_str()); 634 632 return WA_NONE; 635 633 } … … 674 672 * @return The State if known, WS_NONE otherwise. 675 673 */ 676 WeaponState Weapon::charToState(const char*state)677 { 678 if ( !strcmp(state, "none"))674 WeaponState Weapon::charToState(const std::string& state) 675 { 676 if (state == "none") 679 677 return WS_NONE; 680 else if ( !strcmp(state, "shooting"))678 else if (state == "shooting") 681 679 return WS_SHOOTING; 682 else if ( !strcmp(state, "charging"))680 else if (state == "charging") 683 681 return WS_CHARGING; 684 else if ( !strcmp(state, "reloading"))682 else if (state == "reloading") 685 683 return WS_RELOADING; 686 else if ( !strcmp(state, "activating"))684 else if (state == "activating") 687 685 return WS_ACTIVATING; 688 else if ( !strcmp(state, "deactivating"))686 else if (state == "deactivating") 689 687 return WS_DEACTIVATING; 690 else if ( !strcmp(state, "inactive"))688 else if (state == "inactive") 691 689 return WS_INACTIVE; 692 else if ( !strcmp(state, "idle"))690 else if (state == "idle") 693 691 return WS_IDLE; 694 692 else 695 693 { 696 PRINTF(2)("state %s could not be identified.\n", state );694 PRINTF(2)("state %s could not be identified.\n", state.c_str()); 697 695 return WS_NONE; 698 696 } -
trunk/src/world_entities/weapons/weapon.h
r7102 r7221 111 111 inline long getCapability() const { return this->capability; }; 112 112 void setProjectileType(ClassID projectile); 113 void setProjectileTypeC(const char*projectile);113 void setProjectileTypeC(const std::string& projectile); 114 114 /** @returns The projectile's classID */ 115 115 inline ClassID getProjectileType() { return this->projectile; }; … … 132 132 // STATE CHANGES // 133 133 /** @param state the State to time @param duration the duration of the State */ 134 inline void setStateDuration(const char*state, float duration) { setStateDuration(charToState(state), duration); };134 inline void setStateDuration(const std::string& state, float duration) { setStateDuration(charToState(state), duration); }; 135 135 /** @param state the State to time @param duration the duration of the State */ 136 136 inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; }; … … 148 148 inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;} 149 149 150 void setActionSound(WeaponAction action, const char*soundFile);151 /** @see void setActionSound(WeaponAction action, const char*soundFile); */152 void setActionSound(const char* action, const char*soundFile) { this->setActionSound(charToAction(action), soundFile); };150 void setActionSound(WeaponAction action, const std::string& soundFile); 151 /** @see void setActionSound(WeaponAction action, const std::string& soundFile); */ 152 void setActionSound(const std::string& action, const std::string& soundFile) { this->setActionSound(charToAction(action), soundFile); }; 153 153 154 154 Animation3D* getAnimation(WeaponState state, PNode* node = NULL); … … 176 176 177 177 // utility: 178 static WeaponAction charToAction(const char*action);178 static WeaponAction charToAction(const std::string& action); 179 179 static const char* actionToChar(WeaponAction action); 180 static WeaponState charToState(const char*state);180 static WeaponState charToState(const std::string& state); 181 181 static const char* stateToChar(WeaponState state); 182 182 -
trunk/src/world_entities/world_entity.cc
r7198 r7221 61 61 this->bCollide = true; 62 62 63 this->md2TextureFileName = NULL;64 65 63 this->objectListNumber = OM_INIT; 66 64 this->objectListIterator = NULL; … … 120 118 * @param fileName the name of the model to load 121 119 * @param scaling the Scaling of the model 122 * 123 * @todo fix this, so it only has one loadModel-Function. 124 */ 125 void WorldEntity::loadModel(const char* fileName, float scaling, unsigned int modelNumber) 120 */ 121 void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber) 126 122 { 127 123 this->modelLODName = fileName; 128 124 this->scaling = scaling; 129 if ( fileName != NULL && strcmp(fileName, ""))125 if (!fileName.empty()) 130 126 { 131 127 // search for the special character # in the LoadParam 132 if (strchr(fileName, '#') != NULL) 133 { 134 PRINTF(4)("Found # in %s... searching for LOD's\n", fileName); 135 char* lodFile = new char[strlen(fileName)+1]; 136 strcpy(lodFile, fileName); 137 char* depth = strchr(lodFile, '#'); 128 if (fileName.find('#') != std::string::npos) 129 { 130 PRINTF(4)("Found # in %s... searching for LOD's\n", fileName.c_str()); 131 std::string lodFile = fileName; 132 unsigned int offset = lodFile.find('#'); 138 133 for (unsigned int i = 0; i < 3; i++) 139 134 { 140 *depth= 48+(int)i;135 lodFile[offset] = 48+(int)i; 141 136 if (ResourceManager::isInDataDir(lodFile)) 142 137 this->loadModel(lodFile, scaling, i); … … 149 144 this->scaling = 1.0; 150 145 } 151 if( strstr(fileName, ".obj"))152 { 153 PRINTF(4)("fetching OBJ file: %s\n", fileName );146 if(fileName.find(".obj") != std::string::npos) 147 { 148 PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str()); 154 149 BaseObject* loadedModel = ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, this->scaling); 155 150 if (loadedModel != NULL) 156 151 this->setModel(dynamic_cast<Model*>(loadedModel), modelNumber); 152 else 153 PRINTF(1)("OBJ-File %s not found.\n", fileName.c_str()); 157 154 158 155 if( modelNumber == 0) 159 156 this->buildObbTree(4); 160 157 } 161 else if( strstr(fileName, ".md2"))162 { 163 PRINTF(4)("fetching MD2 file: %s\n", fileName );158 else if(fileName.find(".md2") != std::string::npos) 159 { 160 PRINTF(4)("fetching MD2 file: %s\n", fileName.c_str()); 164 161 Model* m = new MD2Model(fileName, this->md2TextureFileName, this->scaling); 165 162 //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0); … … 575 572 char* name = (char*)(getModel( 0 )->getName()); 576 573 577 if ( strstr(name, ResourceManager::getInstance()->getDataDir()))578 { 579 name += strlen(ResourceManager::getInstance()->getDataDir());574 if ( ResourceManager::getInstance()->getDataDir() == name ) /// FIXME (do not know what to do here.) 575 { 576 name += ResourceManager::getInstance()->getDataDir().size(); 580 577 } 581 578 -
trunk/src/world_entities/world_entity.h
r7095 r7221 36 36 virtual void loadParams(const TiXmlElement* root); 37 37 38 void loadModel(const char*fileName, float scaling = 1.0f, unsigned int modelNumber = 0);38 void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0); 39 39 void setModel(Model* model, unsigned int modelNumber = 0); 40 40 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; 41 41 42 inline void loadMD2Texture(const char*fileName) { this->md2TextureFileName = fileName; }42 inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } 43 43 44 44 bool buildObbTree(unsigned int depth); … … 113 113 114 114 std::vector<Model*> models; //!< The model that should be loaded for this entity. 115 const char*md2TextureFileName; //!< the file name of the md2 model texture, only if this116 const char*modelLODName; //!< the name of the model lod file115 std::string md2TextureFileName; //!< the file name of the md2 model texture, only if this 116 std::string modelLODName; //!< the name of the model lod file 117 117 BVTree* obbTree; //!< this is the obb tree reference needed for collision detection 118 118
Note: See TracChangeset
for help on using the changeset viewer.