diff --git a/WickedEngine/LUA/luac.c b/WickedEngine/LUA/luac.c new file mode 100644 index 000000000..c0c91d017 --- /dev/null +++ b/WickedEngine/LUA/luac.c @@ -0,0 +1,449 @@ +/* +** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $ +** Lua compiler (saves bytecodes to files; also lists bytecodes) +** See Copyright Notice in lua.h +*/ + +#define luac_c +#define LUA_CORE + +#include "lprefix.h" + +#include +#include +#include +#include +#include + +#include "lua.h" +#include "lauxlib.h" + +#include "lobject.h" +#include "lstate.h" +#include "lundump.h" + +static void PrintFunction(const Proto* f, int full); +#define luaU_print PrintFunction + +#define PROGNAME "luac" /* default program name */ +#define OUTPUT PROGNAME ".out" /* default output file */ + +static int listing=0; /* list bytecodes? */ +static int dumping=1; /* dump bytecodes? */ +static int stripping=0; /* strip debug information? */ +static char Output[]={ OUTPUT }; /* default output file name */ +static const char* output=Output; /* actual output file name */ +static const char* progname=PROGNAME; /* actual program name */ + +static void fatal(const char* message) +{ + fprintf(stderr,"%s: %s\n",progname,message); + exit(EXIT_FAILURE); +} + +static void cannot(const char* what) +{ + fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); + exit(EXIT_FAILURE); +} + +static void usage(const char* message) +{ + if (*message=='-') + fprintf(stderr,"%s: unrecognized option '%s'\n",progname,message); + else + fprintf(stderr,"%s: %s\n",progname,message); + fprintf(stderr, + "usage: %s [options] [filenames]\n" + "Available options are:\n" + " -l list (use -l -l for full listing)\n" + " -o name output to file 'name' (default is \"%s\")\n" + " -p parse only\n" + " -s strip debug information\n" + " -v show version information\n" + " -- stop handling options\n" + " - stop handling options and process stdin\n" + ,progname,Output); + exit(EXIT_FAILURE); +} + +#define IS(s) (strcmp(argv[i],s)==0) + +static int doargs(int argc, char* argv[]) +{ + int i; + int version=0; + if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; + for (i=1; itop+(i)) + +static const Proto* combine(lua_State* L, int n) +{ + if (n==1) + return toproto(L,-1); + else + { + Proto* f; + int i=n; + if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1)); + f=toproto(L,-1); + for (i=0; ip[i]=toproto(L,i-n-1); + if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0; + } + f->sizelineinfo=0; + return f; + } +} + +static int writer(lua_State* L, const void* p, size_t size, void* u) +{ + UNUSED(L); + return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); +} + +static int pmain(lua_State* L) +{ + int argc=(int)lua_tointeger(L,1); + char** argv=(char**)lua_touserdata(L,2); + const Proto* f; + int i; + if (!lua_checkstack(L,argc)) fatal("too many input files"); + for (i=0; i1); + if (dumping) + { + FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); + if (D==NULL) cannot("open"); + lua_lock(L); + luaU_dump(L,f,writer,D,stripping); + lua_unlock(L); + if (ferror(D)) cannot("write"); + if (fclose(D)) cannot("close"); + } + return 0; +} + +int main(int argc, char* argv[]) +{ + lua_State* L; + int i=doargs(argc,argv); + argc-=i; argv+=i; + if (argc<=0) usage("no input files given"); + L=luaL_newstate(); + if (L==NULL) fatal("cannot create state: not enough memory"); + lua_pushcfunction(L,&pmain); + lua_pushinteger(L,argc); + lua_pushlightuserdata(L,argv); + if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1)); + lua_close(L); + return EXIT_SUCCESS; +} + +/* +** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $ +** print bytecodes +** See Copyright Notice in lua.h +*/ + +#include +#include + +#define luac_c +#define LUA_CORE + +#include "ldebug.h" +#include "lobject.h" +#include "lopcodes.h" + +#define VOID(p) ((const void*)(p)) + +static void PrintString(const TString* ts) +{ + const char* s=getstr(ts); + size_t i,n=tsslen(ts); + printf("%c",'"'); + for (i=0; ik[i]; + switch (ttype(o)) + { + case LUA_TNIL: + printf("nil"); + break; + case LUA_TBOOLEAN: + printf(bvalue(o) ? "true" : "false"); + break; + case LUA_TNUMFLT: + { + char buff[100]; + sprintf(buff,LUA_NUMBER_FMT,fltvalue(o)); + printf("%s",buff); + if (buff[strspn(buff,"-0123456789")]=='\0') printf(".0"); + break; + } + case LUA_TNUMINT: + printf(LUA_INTEGER_FMT,ivalue(o)); + break; + case LUA_TSHRSTR: case LUA_TLNGSTR: + PrintString(tsvalue(o)); + break; + default: /* cannot happen */ + printf("? type=%d",ttype(o)); + break; + } +} + +#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-") +#define MYK(x) (-1-(x)) + +static void PrintCode(const Proto* f) +{ + const Instruction* code=f->code; + int pc,n=f->sizecode; + for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); + printf("%-9s\t",luaP_opnames[o]); + switch (getOpMode(o)) + { + case iABC: + printf("%d",a); + if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b); + if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c); + break; + case iABx: + printf("%d",a); + if (getBMode(o)==OpArgK) printf(" %d",MYK(bx)); + if (getBMode(o)==OpArgU) printf(" %d",bx); + break; + case iAsBx: + printf("%d %d",a,sbx); + break; + case iAx: + printf("%d",MYK(ax)); + break; + } + switch (o) + { + case OP_LOADK: + printf("\t; "); PrintConstant(f,bx); + break; + case OP_GETUPVAL: + case OP_SETUPVAL: + printf("\t; %s",UPVALNAME(b)); + break; + case OP_GETTABUP: + printf("\t; %s",UPVALNAME(b)); + if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); } + break; + case OP_SETTABUP: + printf("\t; %s",UPVALNAME(a)); + if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); } + if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); } + break; + case OP_GETTABLE: + case OP_SELF: + if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } + break; + case OP_SETTABLE: + case OP_ADD: + case OP_SUB: + case OP_MUL: + case OP_POW: + case OP_DIV: + case OP_IDIV: + case OP_BAND: + case OP_BOR: + case OP_BXOR: + case OP_SHL: + case OP_SHR: + case OP_EQ: + case OP_LT: + case OP_LE: + if (ISK(b) || ISK(c)) + { + printf("\t; "); + if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); + printf(" "); + if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); + } + break; + case OP_JMP: + case OP_FORLOOP: + case OP_FORPREP: + case OP_TFORLOOP: + printf("\t; to %d",sbx+pc+2); + break; + case OP_CLOSURE: + printf("\t; %p",VOID(f->p[bx])); + break; + case OP_SETLIST: + if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c); + break; + case OP_EXTRAARG: + printf("\t; "); PrintConstant(f,ax); + break; + default: + break; + } + printf("\n"); + } +} + +#define SS(x) ((x==1)?"":"s") +#define S(x) (int)(x),SS(x) + +static void PrintHeader(const Proto* f) +{ + const char* s=f->source ? getstr(f->source) : "=?"; + if (*s=='@' || *s=='=') + s++; + else if (*s==LUA_SIGNATURE[0]) + s="(bstring)"; + else + s="(string)"; + printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n", + (f->linedefined==0)?"main":"function",s, + f->linedefined,f->lastlinedefined, + S(f->sizecode),VOID(f)); + printf("%d%s param%s, %d slot%s, %d upvalue%s, ", + (int)(f->numparams),f->is_vararg?"+":"",SS(f->numparams), + S(f->maxstacksize),S(f->sizeupvalues)); + printf("%d local%s, %d constant%s, %d function%s\n", + S(f->sizelocvars),S(f->sizek),S(f->sizep)); +} + +static void PrintDebug(const Proto* f) +{ + int i,n; + n=f->sizek; + printf("constants (%d) for %p:\n",n,VOID(f)); + for (i=0; isizelocvars; + printf("locals (%d) for %p:\n",n,VOID(f)); + for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); + } + n=f->sizeupvalues; + printf("upvalues (%d) for %p:\n",n,VOID(f)); + for (i=0; iupvalues[i].instack,f->upvalues[i].idx); + } +} + +static void PrintFunction(const Proto* f, int full) +{ + int i,n=f->sizep; + PrintHeader(f); + PrintCode(f); + if (full) PrintDebug(f); + for (i=0; ip[i],full); +} diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index cc85e5463..c4f50e210 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -3,6 +3,9 @@ #include "wiRenderer.h" #include "wiHelper.h" #include "wiTimer.h" +#include "wiCpuInfo.h" +#include "wiInputManager.h" +#include "wiBackLog.h" MainComponent::MainComponent() @@ -67,6 +70,10 @@ void MainComponent::run() void MainComponent::Update() { + wiInputManager::Update(); + wiCpuInfo::Frame(); + wiBackLog::Update(); + getActiveComponent()->Update(); } diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj index abe09406b..708c02243 100644 --- a/WickedEngine/WickedEngine.vcxproj +++ b/WickedEngine/WickedEngine.vcxproj @@ -203,6 +203,7 @@ + @@ -747,7 +748,7 @@ - + diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters index b70101931..9bbbc024a 100644 --- a/WickedEngine/WickedEngine.vcxproj.filters +++ b/WickedEngine/WickedEngine.vcxproj.filters @@ -728,6 +728,9 @@ Source Files + + LUA + @@ -1745,9 +1748,7 @@ - - LUA - + diff --git a/WickedEngine/info.txt b/WickedEngine/info.txt deleted file mode 100644 index bc890e1dc..000000000 --- a/WickedEngine/info.txt +++ /dev/null @@ -1,3 +0,0 @@ -Lua version 5.3.1 - -Added to Wicked Engine on 02.08.2015. \ No newline at end of file diff --git a/WickedEngine/licenses.txt b/WickedEngine/licenses.txt new file mode 100644 index 000000000..3fb97d7ce --- /dev/null +++ b/WickedEngine/licenses.txt @@ -0,0 +1,35 @@ +LUA 5.3.1: + +Copyright © 1994–2015 Lua.org, PUC - Rio. +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation +files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, +modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +############################################################################################################################### + +BULLET 2.82: + +Bullet Collision Detection and Physics Library +Copyright (c) 2012 Advanced Micro Devices, Inc. http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use +this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + +############################################################################################################################### + diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index c6cf9b6b0..0592f7c5c 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -15,16 +15,20 @@ float wiBackLog::pos; int wiBackLog::scroll; stringstream wiBackLog::inputArea; int wiBackLog::historyPos=0; +ID3D11ShaderResourceView* wiBackLog::backgroundTex = nullptr; void wiBackLog::Initialize(){ - //stream.resize(0); pos = (float)wiRenderer::RENDERHEIGHT; scroll=0; state=DISABLED; deletefromline=100; inputArea=stringstream(""); - //post("wiBackLog Created"); + const unsigned char colorData[] = { 0, 0, 43, 200, 43, 31, 141, 223 }; + wiTextureHelper::CreateTexture(backgroundTex, colorData, 1, 2, 4); + + wiLua::GetGlobal()->Register("backlog_clear", ClearLua); + wiLua::GetGlobal()->Register("backlog_post", PostLua); } void wiBackLog::CleanUp(){ stream.clear(); @@ -55,9 +59,11 @@ void wiBackLog::Draw(){ wiImageEffects fx = wiImageEffects((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT); fx.pos=XMFLOAT3(0,pos,0); fx.opacity = wiMath::Lerp(0, 1, pos / wiRenderer::RENDERHEIGHT); - wiImage::Draw(wiTextureHelper::getInstance()->getColor(wiColor(0,0,240,200)),fx); - wiFont::Draw(wiBackLog::getText(), "01", XMFLOAT4(5, pos - wiRenderer::RENDERHEIGHT + 75 + scroll, 0, -8), "left", "bottom"); - wiFont::Draw(inputArea.str().c_str(), "01", XMFLOAT4(5, -(float)wiRenderer::RENDERHEIGHT + 10, 0, -8), "left", "bottom"); + wiImage::Draw(backgroundTex, fx); + wiFont(getText(), wiFontProps(5, pos - wiRenderer::RENDERHEIGHT + 75 + scroll, 0, WIFALIGN_LEFT, WIFALIGN_BOTTOM, -8)).Draw(); + wiFont(inputArea.str().c_str(), wiFontProps(5, -(float)wiRenderer::RENDERHEIGHT + 10, 0, WIFALIGN_LEFT, WIFALIGN_BOTTOM, -8)).Draw(); + //wiFont::Draw(wiBackLog::getText(), "01", XMFLOAT4(5, pos - wiRenderer::RENDERHEIGHT + 75 + scroll, 0, -8), "left", "bottom"); + //wiFont::Draw(inputArea.str().c_str(), "01", XMFLOAT4(5, -(float)wiRenderer::RENDERHEIGHT + 10, 0, -8), "left", "bottom"); } } @@ -97,20 +103,8 @@ void wiBackLog::acceptInput(){ if(history.size()>deletefromline){ history.pop_front(); } + wiLua::GetGlobal()->RunText(inputArea.str()); inputArea.str(""); - -#ifdef GAMECOMPONENTS - vector command(0); - while(!commandStream.eof()){ - string a = ""; - commandStream>>a; - command.push_back(a); - } - command.pop_back(); - GameComponents::consoleCommands.clear(); - GameComponents::consoleCommands=vector(command.begin(),command.end()); - GameComponents::wakeConsoleCommand=true; -#endif } void wiBackLog::deletefromInput(){ stringstream ss(inputArea.str().substr(0,inputArea.str().length()-1)); @@ -138,4 +132,35 @@ void wiBackLog::historyNext(){ inputArea.str(""); inputArea< wiFont::vertexList; vector wiFont::fontStyles; +wiFont::wiFont(const string& text, wiFontProps props, int style) : props(props), style(style) +{ + this->text = wstring(text.begin(), text.end()); +} +wiFont::wiFont(const wstring& text, wiFontProps props, int style) : text(text), props(props), style(style) +{ + +} +wiFont::~wiFont() +{ + +} + void wiFont::Initialize() { counter = 0; @@ -213,7 +226,7 @@ void wiFont::CleanUpStatic() } -void wiFont::ModifyGeo(const wchar_t* text, XMFLOAT2 sizSpa,const int& style, ID3D11DeviceContext* context) +void wiFont::ModifyGeo(const wchar_t* text, wiFontProps props, int style, ID3D11DeviceContext* context) { textlen=wcslen(text); line=0; pos=0; @@ -224,48 +237,45 @@ void wiFont::ModifyGeo(const wchar_t* text, XMFLOAT2 sizSpa,const int& style, ID } for (unsigned int i = 0; iUpdateSubresource( vertexBuffer, 0, NULL, vertexList.data(), 0, 0 ); wiRenderer::UpdateBuffer(vertexBuffer,vertexList.data(),context==nullptr?wiRenderer::getImmediateContext():context,sizeof(Vertex) * textlen * 4); - //D3D11_MAPPED_SUBRESOURCE mappedResource; - //Vertex* dataPtr; - //wiRenderer::getImmediateContext()->Map(vertexBuffer,0,D3D11_MAP_WRITE_DISCARD,0,&mappedResource); - //dataPtr = (Vertex*)mappedResource.pData; - //memcpy(dataPtr,vertexList.data(),sizeof(Vertex) * textlen * 4); - //wiRenderer::getImmediateContext()->Unmap(vertexBuffer,0); + } void wiFont::LoadVertexBuffer() @@ -303,61 +313,21 @@ void wiFont::LoadIndices() wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &indexBuffer ); } +void wiFont::Draw(wiRenderer::DeviceContext context){ -void wiFont::DrawBlink(wchar_t* text, XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context) -{ - if(toDraw){ - Draw(text,newPosSizSpa,Halign,Valign,context); - } -} -void wiFont::DrawBlink(const std::string& text, XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context) -{ - if(toDraw){ - Draw(text,newPosSizSpa,Halign,Valign,context); - } -} -void wiFont::Draw(const std::string& text, XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context) -{ - std::wstring ws(text.begin(), text.end()); + wiFontProps newProps = props; - Draw(ws.c_str(),newPosSizSpa,Halign,Valign,context); -} -void wiFont::Draw(const wchar_t* text, XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context) -{ - Draw(text,"",newPosSizSpa,Halign,Valign,context); -} - -void wiFont::DrawBlink(const string& text,const char* fontStyle,XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context){ - if(toDraw){ - Draw(text,fontStyle,newPosSizSpa,Halign,Valign,context); - } -} -void wiFont::DrawBlink(const wchar_t* text,const char* fontStyle,XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context){ - if(toDraw){ - Draw(text,fontStyle,newPosSizSpa,Halign,Valign,context); - } -} -void wiFont::Draw(const string& text,const char* fontStyle,XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context){ - wstring ws(text.begin(),text.end()); - Draw(ws.c_str(),fontStyle,newPosSizSpa,Halign,Valign,context); -} - - -void wiFont::Draw(const wchar_t* text,const char* fontStyle,XMFLOAT4 newPosSizSpa, const char* Halign, const char* Valign, wiRenderer::DeviceContext context){ - int fontStyleI = getFontStyleByName(fontStyle); - - - if(!strcmp(Halign,"center") || !strcmp(Valign,"mid")) - newPosSizSpa.x-=textWidth(text,newPosSizSpa.w+newPosSizSpa.z,fontStyleI)/2; - else if(!strcmp(Halign,"right")) - newPosSizSpa.x-=textWidth(text,newPosSizSpa.w+newPosSizSpa.z,fontStyleI); - if(!strcmp(Valign,"center") || !strcmp(Valign,"mid")) - newPosSizSpa.y+=textHeight(text,newPosSizSpa.z,fontStyleI)*0.5f; - else if(!strcmp(Valign,"bottom")) - newPosSizSpa.y+=textHeight(text,newPosSizSpa.z,fontStyleI); + if(props.h_align==WIFALIGN_CENTER || props.h_align==WIFALIGN_MID) + newProps.posX-= textWidth()*0.5f; + else if(props.h_align==WIFALIGN_RIGHT) + newProps.posX -= textWidth(); + if (props.v_align == WIFALIGN_CENTER || props.h_align == WIFALIGN_MID) + newProps.posY += textHeight()*0.5f; + else if(props.v_align==WIFALIGN_BOTTOM) + newProps.posY += textHeight(); - ModifyGeo(text,XMFLOAT2(newPosSizSpa.z,newPosSizSpa.w),fontStyleI,context); + ModifyGeo(text.c_str(), newProps, style, context); if(textlen){ @@ -372,13 +342,12 @@ void wiFont::Draw(const wchar_t* text,const char* fontStyle,XMFLOAT4 newPosSizSp wiRenderer::BindPS(pixelShader,context); - ConstantBuffer* cb = new ConstantBuffer(); - cb->mProjection = XMMatrixTranspose( wiRenderer::getCamera()->Oprojection ); - cb->mTrans = XMMatrixTranspose( XMMatrixTranslation(newPosSizSpa.x,newPosSizSpa.y,0) ); - cb->mDimensions = XMFLOAT4((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT, 0, 0); + ConstantBuffer cb = ConstantBuffer(); + cb.mProjection = XMMatrixTranspose( wiRenderer::getCamera()->Oprojection ); + cb.mTrans = XMMatrixTranspose(XMMatrixTranslation(newProps.posX, newProps.posY, 0)); + cb.mDimensions = XMFLOAT4((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT, 0, 0); - wiRenderer::UpdateBuffer(constantBuffer,cb,context); - delete cb; + wiRenderer::UpdateBuffer(constantBuffer,&cb,context); wiRenderer::BindConstantBufferVS(constantBuffer,0,context); @@ -389,31 +358,19 @@ void wiFont::Draw(const wchar_t* text,const char* fontStyle,XMFLOAT4 newPosSizSp wiRenderer::BindVertexBuffer(vertexBuffer,0,sizeof(Vertex),context); wiRenderer::BindIndexBuffer(indexBuffer,context); - wiRenderer::BindTexturePS(fontStyles[fontStyleI].texture,0,context); + wiRenderer::BindTexturePS(fontStyles[style].texture,0,context); wiRenderer::BindSamplerPS(sampleState,0,context); wiRenderer::DrawIndexed(textlen*6,context); } } -void wiFont::Blink(DWORD perframe,DWORD invisibleTime) -{ - counter++; - if(toDraw && counter>perframe){ - counter=0; - toDraw=FALSE; - } - else if(!toDraw && counter>invisibleTime){ - counter=0; - toDraw=TRUE; - } -} -int wiFont::textWidth(const wchar_t* text,FLOAT spacing,const int& style) +int wiFont::textWidth() { int i=0; int max=0,lineW=0; - int len=wcslen(text); + int len=text.length(); while(i fontStyles; - static void ModifyGeo(const wchar_t* text,XMFLOAT2 sizSpacing,const int& style, ID3D11DeviceContext* context = nullptr); + static void ModifyGeo(const wchar_t* text, wiFontProps props, int style, ID3D11DeviceContext* context = nullptr); + public: static void Initialize(); static void SetUpStaticComponents(); static void CleanUpStatic(); + + wstring text; + wiFontProps props; + int style; + + wiFont(const string& text, wiFontProps props = wiFontProps(), int style = 0); + wiFont(const wstring& text, wiFontProps props = wiFontProps(), int style = 0); + ~wiFont(); + - static void DrawBlink(wchar_t* text,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); - static void Draw(const wchar_t* text,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); - static void DrawBlink(const std::string& text,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); - static void Draw(const std::string& text,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); + void Draw(ID3D11DeviceContext* context = nullptr); - static void DrawBlink(const string& text,const char* fontStyle,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); - static void DrawBlink(const wchar_t* text,const char* fontStyle,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); - static void Draw(const string& text,const char* fontStyle,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); - static void Draw(const wchar_t* text,const char* fontStyle,XMFLOAT4 posSizSpacing=XMFLOAT4(0,0,0,0), const char* Halign="left", const char* Valign="top", ID3D11DeviceContext* context = nullptr); - static void Blink(DWORD perframe,DWORD invisibleTime); - - static int textWidth(const wchar_t*,FLOAT siz,const int& style); - static int textHeight(const wchar_t*,FLOAT siz,const int& style); + int textWidth(); + int textHeight(); static void addFontStyle( const string& toAdd ); static int getFontStyleByName( const string& get ); diff --git a/WickedEngine/wiInitializer.cpp b/WickedEngine/wiInitializer.cpp index 61d05a08f..84327ff68 100644 --- a/WickedEngine/wiInitializer.cpp +++ b/WickedEngine/wiInitializer.cpp @@ -34,6 +34,7 @@ namespace wiInitializer if (requestedFeautures & WICKEDENGINE_INITIALIZE_FONT) { + wiFont::Initialize(); wiFont::SetUpStaticComponents(); } diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 63aab0354..7f72b15d0 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -1,21 +1,133 @@ #include "wiLua.h" +#include "wiBackLog.h" -extern "C" -{ -#include "LUA\lua.h" -#include "LUA\lualib.h" -#include "LUA\lauxlib.h" -} - +wiLua *wiLua::globalLua = nullptr; wiLua::wiLua() { - m_lua_State = luaL_newstate(); - luaL_openlibs(m_lua_State); + m_luaState = NULL; + m_luaState = luaL_newstate(); + luaL_openlibs(m_luaState); + Register("debugout", DebugOut); } - wiLua::~wiLua() { - lua_close(m_lua_State); + lua_close(m_luaState); } + +wiLua* wiLua::GetGlobal() +{ + if (globalLua == nullptr) + { + globalLua = new wiLua(); + } + return globalLua; +} + +bool wiLua::Success() +{ + return m_status == 0; +} +bool wiLua::Failed() +{ + return m_status != 0; +} +string wiLua::GetErrorMsg() +{ + if (Failed()) { + string retVal = lua_tostring(m_luaState, -1); + return retVal; + } + return string(""); +} +string wiLua::PopErrorMsg() +{ + string retVal = lua_tostring(m_luaState, -1); + lua_pop(m_luaState, 1); // remove error message + return retVal; +} +void wiLua::PostErrorMsg(bool todebug, bool tobacklog) +{ + if (Failed()) + { + const char* str = lua_tostring(m_luaState, -1); + if (str == nullptr) + return; + stringstream ss(""); + ss << "[Lua Error] " << str; + if (tobacklog) + { + wiBackLog::post(ss.str().c_str()); + } + if (todebug) + { + ss << endl; + OutputDebugStringA(ss.str().c_str()); + } + lua_pop(m_luaState, 1); // remove error message + } +} +bool wiLua::RunFile(const string& filename) +{ + m_status = luaL_loadfile(m_luaState, filename.c_str()); + + if (Success()) { + return RunScript(); + } + + PostErrorMsg(); + return false; +} +bool wiLua::RunText(const string& script) +{ + m_status = luaL_loadstring(m_luaState, script.c_str()); + if (Success()) + { + return RunScript(); + } + + PostErrorMsg(); + return false; +} +bool wiLua::RunScript() +{ + m_status = lua_pcall(m_luaState, 0, LUA_MULTRET, 0); + if (Failed()) + { + PostErrorMsg(); + return false; + } + return true; +} +bool wiLua::Register(const string& name, lua_CFunction function) +{ + lua_register(m_luaState, name.c_str(), function); + + PostErrorMsg(); + + return Success(); +} + +int wiLua::DebugOut(lua_State* L) +{ + int argc = lua_gettop(L); + + stringstream ss(""); + + for (int i = 1; i <= argc; i++) + { + const char* str = lua_tostring(L, i); + if (str != nullptr) + { + ss << str; + } + } + ss << endl; + + OutputDebugStringA(ss.str().c_str()); + + //number of results + return 0; +} + diff --git a/WickedEngine/wiLua.h b/WickedEngine/wiLua.h index 21ad94a6d..41e1b6f64 100644 --- a/WickedEngine/wiLua.h +++ b/WickedEngine/wiLua.h @@ -1,13 +1,46 @@ #pragma once +#include "CommonInclude.h" -struct lua_State; +extern "C" +{ +#include "LUA\lua.h" +#include "LUA\lualib.h" +#include "LUA\lauxlib.h" +} + +typedef int(*lua_CFunction) (lua_State *L); class wiLua { private: - lua_State *m_lua_State; + lua_State *m_luaState; + int m_status; //last call status + + static wiLua* globalLua; + static int DebugOut(lua_State *L); + + //run the previously loaded script + bool RunScript(); public: wiLua(); ~wiLua(); + static wiLua* GetGlobal(); + + //check if the last call succeeded + bool Success(); + //check if the last call failed + bool Failed(); + //get error message for the last call + string GetErrorMsg(); + //remove and get error message from stack + string PopErrorMsg(); + //post error to backlog and/or debug output + void PostErrorMsg(bool todebug = true, bool tobacklog = true); + //run a script from file + bool RunFile(const string& filename); + //run a script from param + bool RunText(const string& script); + //register function to use in scripts + bool Register(const string& name, lua_CFunction function); };