From 5e1385324a531ea12a179293c0463f88ddcc8a0b Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 22 Aug 2013 16:51:42 +0400 Subject: [PATCH 1/4] remove regex in renderer --- src/graphics/Renderer.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 833cec2bc..28e4d9ef9 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -912,7 +912,7 @@ void Renderer::DrawWalls() void Renderer::DrawSigns() { - int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq; + int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq,match; std::vector signs = sim->signs; #ifdef OGLR GLint prevFbo; @@ -923,14 +923,30 @@ void Renderer::DrawSigns() for (i=0; i < signs.size(); i++) if (signs[i].text.length()) { - std::string text = sim->signs[i].getText(sim); - sim->signs[i].pos(text, x, y, w, h); + std::string text = signs[i].getText(sim); + const char* str = signs[i].text.c_str(); + signs[i].pos(text, x, y, w, h); clearrect(x, y, w+1, h); drawrect(x, y, w+1, h, 192, 192, 192, 255); - if (sregexp(signs[i].text.c_str(), "^{[ct]:[0-9]*|.*}$")) - drawtext(x+3, y+3, text, 255, 255, 255, 255); - else + match=0; + // check if it's a link sign + if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9') + { + const char* p=str+4; + while (*p>='0' && *p<='9') + p++; + if (*p=='|') + { + while (*p) + p++; + if (p[-1]=='}') + match=1; + } + } + if (match) drawtext(x+3, y+3, text, 0, 191, 255, 255); + else + drawtext(x+3, y+3, text, 255, 255, 255, 255); x = signs[i].x; y = signs[i].y; From 95c01bcf0af64eed9e843346f3ff013cc7197cef Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 22 Aug 2013 16:51:58 +0400 Subject: [PATCH 2/4] regexless getText --- src/simulation/Sign.cpp | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 7ba94afda..f6b8420f9 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -31,25 +31,38 @@ std::string sign::getText(Simulation *sim) else sprintf(buff, "Temp: 0.00"); //...temperature } - else if (sregexp(signText, "^{[ct]:[0-9]*|.*}$")==0) - { - int sldr, startm; - memset(buff, 0, sizeof(buff)); - for (sldr=3; signText[sldr-1] != '|'; sldr++) - startm = sldr + 1; - sldr = startm; - while (signText[sldr] != '}') - { - buff[sldr - startm] = signText[sldr]; - sldr++; - } - } else { - sprintf(buff, "%s", signText); + int match=0; + const char* r; + const char* e; + if (signText[0]=='{' && (signText[1]=='c' || signText[1]=='t') && signText[2]==':' && signText[3]>='0' && signText[3]<='9') + { + const char* p=signText+4; + while (*p>='0' && *p<='9') + p++; + if (*p=='|') + { + r=p+1; + while (*p) + p++; + if (p[-1]=='}') + { + match=1; + e=p; + } + } + } + if (match) + { + strcpy(buff, r); + buff[e-r-1]=0; + } + else + strcpy(buff, signText); } - return std::string(buff,256); + return std::string(buff); } void sign::pos(std::string signText, int & x0, int & y0, int & w, int & h) From 4e9fe8b8e731d2edd5de254c0fd7b9162ebb0c77 Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 22 Aug 2013 16:52:14 +0400 Subject: [PATCH 3/4] regexless gameModel --- src/gui/game/GameController.cpp | 33 ++++++++++++++++++++++----------- src/gui/game/SignTool.cpp | 22 ++++++++++++++++++---- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 8b58b48ce..c514d3ea7 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -571,19 +571,30 @@ bool GameController::MouseUp(int x, int y, unsigned button) (*iter).pos((*iter).getText(sim), signx, signy, signw, signh); if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh) { - if (sregexp((*iter).text.c_str(), "^{[ct]:[0-9]*|.*}$")==0) + int match=0; + const char* str=(*iter).text.c_str(); + const char* e; + if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9') + { + const char* p=str+4; + while (*p>='0' && *p<='9') + p++; + e=p; + if (*p=='|') + { + while (*p) + p++; + if (p[-1]=='}') + { + match=1; + } + } + } + if (match) { - const char * signText = (*iter).text.c_str(); char buff[256]; - int sldr; - - memset(buff, 0, sizeof(buff)); - - for (sldr=3; signText[sldr] != '|'; sldr++) - buff[sldr-3] = signText[sldr]; - - buff[sldr-3] = '\0'; - + strcpy(buff, str+3); + buff[e-str-3]=0; int tempSaveID = format::StringToNumber(std::string(buff)); if (tempSaveID) { diff --git a/src/gui/game/SignTool.cpp b/src/gui/game/SignTool.cpp index 87ed59e96..a71f8e2bf 100644 --- a/src/gui/game/SignTool.cpp +++ b/src/gui/game/SignTool.cpp @@ -177,16 +177,30 @@ void SignWindow::DoDraw() for(std::vector::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter) { sign & currentSign = *iter; - int x, y, w, h, dx, dy; + int x, y, w, h, dx, dy, match=0; Graphics * g = ui::Engine::Ref().g; std::string text = currentSign.getText(sim); + const char* str = currentSign.text.c_str(); currentSign.pos(text, x, y, w, h); g->clearrect(x, y, w+1, h); g->drawrect(x, y, w+1, h, 192, 192, 192, 255); - if (sregexp(currentSign.text.c_str(), "^{[ct]:[0-9]*|.*}$")) - g->drawtext(x+3, y+3, text, 255, 255, 255, 255); - else + if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9') + { + const char* p=str+4; + while (*p>='0' && *p<='9') + p++; + if (*p=='|') + { + while (*p) + p++; + if (p[-1]=='}') + match=1; + } + } + if (match) g->drawtext(x+3, y+3, text, 0, 191, 255, 255); + else + g->drawtext(x+3, y+3, text, 255, 255, 255, 255); x = currentSign.x; y = currentSign.y; From 4a308cbf661bb40efdf53c6632f875c6c393a307 Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 22 Aug 2013 17:52:32 +0400 Subject: [PATCH 4/4] oh, and remove dependency --- SConscript | 2 +- src/Misc.cpp | 12 ------------ src/Misc.h | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/SConscript b/SConscript index 0e5068d38..a69b981d2 100755 --- a/SConscript +++ b/SConscript @@ -285,7 +285,7 @@ if(GetOption('rpi')): if(GetOption('win')): openGLLibs = ['opengl32', 'glew32'] - env.Prepend(LIBS=['mingw32', 'ws2_32', 'SDLmain', 'SDL', 'regex']) + env.Prepend(LIBS=['mingw32', 'ws2_32', 'SDLmain', 'SDL']) env.Append(CCFLAGS=['-std=gnu++98']) env.Append(LIBS=['winmm', 'gdi32']) env.Append(CPPDEFINES=["WIN"]) diff --git a/src/Misc.cpp b/src/Misc.cpp index 3128691cf..6b0c1d537 100644 --- a/src/Misc.cpp +++ b/src/Misc.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include "Config.h" @@ -173,17 +172,6 @@ void clean_text(char *text, int vwidth) } } -int sregexp(const char *str, char *pattern) -{ - int result; - regex_t patternc; - if (regcomp(&patternc, pattern, 0)!=0) - return 1; - result = regexec(&patternc, str, 0, NULL, 0); - regfree(&patternc); - return result; -} - void save_string(FILE *f, char *str) { int li = strlen(str); diff --git a/src/Misc.h b/src/Misc.h index 1a43fe34b..33601f632 100644 --- a/src/Misc.h +++ b/src/Misc.h @@ -62,8 +62,6 @@ void load_presets(void); void save_string(FILE *f, char *str); -int sregexp(const char *str, char *pattern); - int load_string(FILE *f, char *str, int max); void strcaturl(char *dst, char *src);