lua, font updates, licenses added
This commit is contained in:
@@ -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 <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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; i<argc; i++)
|
||||
{
|
||||
if (*argv[i]!='-') /* end of options; keep it */
|
||||
break;
|
||||
else if (IS("--")) /* end of options; skip it */
|
||||
{
|
||||
++i;
|
||||
if (version) ++version;
|
||||
break;
|
||||
}
|
||||
else if (IS("-")) /* end of options; use stdin */
|
||||
break;
|
||||
else if (IS("-l")) /* list */
|
||||
++listing;
|
||||
else if (IS("-o")) /* output file */
|
||||
{
|
||||
output=argv[++i];
|
||||
if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))
|
||||
usage("'-o' needs argument");
|
||||
if (IS("-")) output=NULL;
|
||||
}
|
||||
else if (IS("-p")) /* parse only */
|
||||
dumping=0;
|
||||
else if (IS("-s")) /* strip debug information */
|
||||
stripping=1;
|
||||
else if (IS("-v")) /* show version */
|
||||
++version;
|
||||
else /* unknown option */
|
||||
usage(argv[i]);
|
||||
}
|
||||
if (i==argc && (listing || !dumping))
|
||||
{
|
||||
dumping=0;
|
||||
argv[--i]=Output;
|
||||
}
|
||||
if (version)
|
||||
{
|
||||
printf("%s\n",LUA_COPYRIGHT);
|
||||
if (version==argc-1) exit(EXIT_SUCCESS);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
#define FUNCTION "(function()end)();"
|
||||
|
||||
static const char* reader(lua_State *L, void *ud, size_t *size)
|
||||
{
|
||||
UNUSED(L);
|
||||
if ((*(int*)ud)--)
|
||||
{
|
||||
*size=sizeof(FUNCTION)-1;
|
||||
return FUNCTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
*size=0;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#define toproto(L,i) getproto(L->top+(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; i<n; i++)
|
||||
{
|
||||
f->p[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; i<argc; i++)
|
||||
{
|
||||
const char* filename=IS("-") ? NULL : argv[i];
|
||||
if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));
|
||||
}
|
||||
f=combine(L,argc);
|
||||
if (listing) luaU_print(f,listing>1);
|
||||
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 <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#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; i<n; i++)
|
||||
{
|
||||
int c=(int)(unsigned char)s[i];
|
||||
switch (c)
|
||||
{
|
||||
case '"': printf("\\\""); break;
|
||||
case '\\': printf("\\\\"); break;
|
||||
case '\a': printf("\\a"); break;
|
||||
case '\b': printf("\\b"); break;
|
||||
case '\f': printf("\\f"); break;
|
||||
case '\n': printf("\\n"); break;
|
||||
case '\r': printf("\\r"); break;
|
||||
case '\t': printf("\\t"); break;
|
||||
case '\v': printf("\\v"); break;
|
||||
default: if (isprint(c))
|
||||
printf("%c",c);
|
||||
else
|
||||
printf("\\%03d",c);
|
||||
}
|
||||
}
|
||||
printf("%c",'"');
|
||||
}
|
||||
|
||||
static void PrintConstant(const Proto* f, int i)
|
||||
{
|
||||
const TValue* o=&f->k[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; pc<n; pc++)
|
||||
{
|
||||
Instruction i=code[pc];
|
||||
OpCode o=GET_OPCODE(i);
|
||||
int a=GETARG_A(i);
|
||||
int b=GETARG_B(i);
|
||||
int c=GETARG_C(i);
|
||||
int ax=GETARG_Ax(i);
|
||||
int bx=GETARG_Bx(i);
|
||||
int sbx=GETARG_sBx(i);
|
||||
int line=getfuncline(f,pc);
|
||||
printf("\t%d\t",pc+1);
|
||||
if (line>0) 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; i<n; i++)
|
||||
{
|
||||
printf("\t%d\t",i+1);
|
||||
PrintConstant(f,i);
|
||||
printf("\n");
|
||||
}
|
||||
n=f->sizelocvars;
|
||||
printf("locals (%d) for %p:\n",n,VOID(f));
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
printf("\t%d\t%s\t%d\t%d\n",
|
||||
i,getstr(f->locvars[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; i<n; i++)
|
||||
{
|
||||
printf("\t%d\t%s\t%d\t%d\n",
|
||||
i,UPVALNAME(i),f->upvalues[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; i<n; i++) PrintFunction(f->p[i],full);
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -203,6 +203,7 @@
|
||||
<ClCompile Include="LUA\ltablib.c" />
|
||||
<ClCompile Include="LUA\ltm.c" />
|
||||
<ClCompile Include="LUA\lua.c" />
|
||||
<ClCompile Include="LUA\luac.c" />
|
||||
<ClCompile Include="LUA\lundump.c" />
|
||||
<ClCompile Include="LUA\lutf8lib.c" />
|
||||
<ClCompile Include="LUA\lvm.c" />
|
||||
@@ -747,7 +748,7 @@
|
||||
<ItemGroup>
|
||||
<Text Include="..\features.txt" />
|
||||
<Text Include="..\readme.txt" />
|
||||
<Text Include="info.txt" />
|
||||
<Text Include="licenses.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="bloomSeparatePS.hlsl">
|
||||
|
||||
@@ -728,6 +728,9 @@
|
||||
<ClCompile Include="wiLua.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LUA\luac.c">
|
||||
<Filter>LUA</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="typelib.h">
|
||||
@@ -1745,9 +1748,7 @@
|
||||
<ItemGroup>
|
||||
<Text Include="..\readme.txt" />
|
||||
<Text Include="..\features.txt" />
|
||||
<Text Include="info.txt">
|
||||
<Filter>LUA</Filter>
|
||||
</Text>
|
||||
<Text Include="licenses.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="circleGS.hlsl">
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
Lua version 5.3.1
|
||||
|
||||
Added to Wicked Engine on 02.08.2015.
|
||||
@@ -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.
|
||||
|
||||
###############################################################################################################################
|
||||
|
||||
+44
-19
@@ -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<string> command(0);
|
||||
while(!commandStream.eof()){
|
||||
string a = "";
|
||||
commandStream>>a;
|
||||
command.push_back(a);
|
||||
}
|
||||
command.pop_back();
|
||||
GameComponents::consoleCommands.clear();
|
||||
GameComponents::consoleCommands=vector<string>(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<<history[history.size()-1-historyPos];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wiBackLog::setBackground(ID3D11ShaderResourceView* texture)
|
||||
{
|
||||
backgroundTex = texture;
|
||||
}
|
||||
|
||||
int wiBackLog::ClearLua(lua_State* L)
|
||||
{
|
||||
clear();
|
||||
return 0;
|
||||
}
|
||||
int wiBackLog::PostLua(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;
|
||||
}
|
||||
}
|
||||
|
||||
wiBackLog::post(ss.str().c_str());
|
||||
|
||||
//number of results
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#ifndef BACKLOG
|
||||
#define BACKLOG
|
||||
#ifndef WIBACKLOG
|
||||
#define WIBACKLOG
|
||||
#include "CommonInclude.h"
|
||||
#include "wiFont.h"
|
||||
#include "wiImage.h"
|
||||
#include "wiLua.h"
|
||||
|
||||
class wiBackLog
|
||||
{
|
||||
@@ -15,12 +16,13 @@ private:
|
||||
static int scroll;
|
||||
static stringstream inputArea;
|
||||
enum State{
|
||||
IDLE,
|
||||
DISABLED,
|
||||
IDLE,
|
||||
ACTIVATING,
|
||||
DEACTIVATING,
|
||||
};
|
||||
static State state;
|
||||
static ID3D11ShaderResourceView* backgroundTex;
|
||||
public:
|
||||
static void Initialize();
|
||||
static void CleanUp();
|
||||
@@ -43,6 +45,11 @@ public:
|
||||
static void historyNext();
|
||||
|
||||
static bool isActive(){return state==IDLE;}
|
||||
|
||||
static void setBackground(ID3D11ShaderResourceView* texture);
|
||||
|
||||
static int ClearLua(lua_State* L);
|
||||
static int PostLua(lua_State* L);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+61
-104
@@ -21,6 +21,19 @@ DWORD wiFont::counter;
|
||||
vector<wiFont::Vertex> wiFont::vertexList;
|
||||
vector<wiFont::wiFontStyle> 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; i<vertexList.size(); i += 4){
|
||||
|
||||
FLOAT leftX=0.0f,rightX=(FLOAT)fontStyles[style].charSize,upperY=0.0f,lowerY=(FLOAT)fontStyles[style].charSize;
|
||||
BOOL compatible=FALSE;
|
||||
float leftX=0.0f,rightX=(float)fontStyles[style].charSize,upperY=0.0f,lowerY=(float)fontStyles[style].charSize;
|
||||
bool compatible=FALSE;
|
||||
|
||||
|
||||
if(text[i/4]==10){ //line break
|
||||
line+=(SHORT)fontStyles[style].recSize;
|
||||
pos=0;
|
||||
if (text[i / 4] == '\n'){
|
||||
line += (short)(fontStyles[style].recSize + props.size + props.spacingY);
|
||||
pos = 0;
|
||||
}
|
||||
else if(text[i/4]==32){ //space
|
||||
pos+=(SHORT)(fontStyles[style].recSize+sizSpa.x+sizSpa.y);
|
||||
else if (text[i / 4] == ' '){
|
||||
pos += (short)(fontStyles[style].recSize + props.size + props.spacingX);
|
||||
}
|
||||
else if (text[i / 4] == '\t'){
|
||||
pos += (short)((fontStyles[style].recSize + props.size + props.spacingX) * 5);
|
||||
}
|
||||
else if(fontStyles[style].lookup[text[i/4]].code==text[i/4]){
|
||||
leftX+=fontStyles[style].lookup[text[i/4]].offX*(FLOAT)fontStyles[style].charSize;
|
||||
rightX+=fontStyles[style].lookup[text[i/4]].offX*(FLOAT)fontStyles[style].charSize;
|
||||
upperY+=fontStyles[style].lookup[text[i/4]].offY*(FLOAT)fontStyles[style].charSize;
|
||||
lowerY+=fontStyles[style].lookup[text[i/4]].offY*(FLOAT)fontStyles[style].charSize;
|
||||
leftX += fontStyles[style].lookup[text[i / 4]].offX*(float)fontStyles[style].charSize;
|
||||
rightX += fontStyles[style].lookup[text[i / 4]].offX*(float)fontStyles[style].charSize;
|
||||
upperY += fontStyles[style].lookup[text[i / 4]].offY*(float)fontStyles[style].charSize;
|
||||
lowerY += fontStyles[style].lookup[text[i / 4]].offY*(float)fontStyles[style].charSize;
|
||||
compatible=TRUE;
|
||||
}
|
||||
|
||||
if(compatible){
|
||||
leftX/=(FLOAT)fontStyles[style].texWidth;
|
||||
rightX/=(FLOAT)fontStyles[style].texWidth;
|
||||
upperY/=(FLOAT)fontStyles[style].texHeight;
|
||||
lowerY/=(FLOAT)fontStyles[style].texHeight;
|
||||
leftX /= (float)fontStyles[style].texWidth;
|
||||
rightX /= (float)fontStyles[style].texWidth;
|
||||
upperY /= (float)fontStyles[style].texHeight;
|
||||
lowerY /= (float)fontStyles[style].texHeight;
|
||||
|
||||
vertexList[i].Pos=XMFLOAT2(pos+0-sizSpa.x*0.5f,0-line+sizSpa.x*0.5f); vertexList[i].Tex=XMFLOAT2(leftX,upperY);
|
||||
vertexList[i+1].Pos=XMFLOAT2(pos+fontStyles[style].recSize+sizSpa.x*0.5f,0-line+sizSpa.x*0.5f); vertexList[i+1].Tex=XMFLOAT2(rightX,upperY);
|
||||
vertexList[i+2].Pos=XMFLOAT2(pos+0-sizSpa.x*0.5f,-fontStyles[style].recSize-line-sizSpa.x*0.5f); vertexList[i+2].Tex=XMFLOAT2(leftX,lowerY);
|
||||
vertexList[i+3].Pos=XMFLOAT2(pos+fontStyles[style].recSize+sizSpa.x*0.5f,-fontStyles[style].recSize-line-sizSpa.x*0.5f); vertexList[i+3].Tex=XMFLOAT2(rightX,lowerY);
|
||||
vertexList[i].Pos = XMFLOAT2(pos + 0 - props.size*0.5f, 0 - line + props.size*0.5f); vertexList[i].Tex = XMFLOAT2(leftX, upperY);
|
||||
vertexList[i + 1].Pos = XMFLOAT2(pos + fontStyles[style].recSize + props.size*0.5f, 0 - line + props.size*0.5f); vertexList[i + 1].Tex = XMFLOAT2(rightX, upperY);
|
||||
vertexList[i + 2].Pos = XMFLOAT2(pos + 0 - props.size*0.5f, -fontStyles[style].recSize - line - props.size*0.5f); vertexList[i + 2].Tex = XMFLOAT2(leftX, lowerY);
|
||||
vertexList[i + 3].Pos = XMFLOAT2(pos + fontStyles[style].recSize + props.size*0.5f, -fontStyles[style].recSize - line - props.size*0.5f); vertexList[i + 3].Tex = XMFLOAT2(rightX, lowerY);
|
||||
|
||||
pos+=(SHORT)(fontStyles[style].recSize+sizSpa.x+sizSpa.y);
|
||||
pos += (short)(fontStyles[style].recSize + props.size + props.spacingX);
|
||||
}
|
||||
}
|
||||
//wiRenderer::getImmediateContext()->UpdateSubresource( 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<len){
|
||||
if(text[i]==10) {//ENDLINE
|
||||
if(max<lineW) max=lineW;
|
||||
@@ -424,13 +381,13 @@ int wiFont::textWidth(const wchar_t* text,FLOAT spacing,const int& style)
|
||||
}
|
||||
if(max==0) max=lineW;
|
||||
|
||||
return (int)(max*(fontStyles[style].recSize+spacing));
|
||||
return (int)(max*(fontStyles[style].recSize+props.spacingX));
|
||||
}
|
||||
int wiFont::textHeight(const wchar_t* text,FLOAT siz,const int& style)
|
||||
int wiFont::textHeight()
|
||||
{
|
||||
int i=0;
|
||||
int lines=1;
|
||||
int len=wcslen(text);
|
||||
int len=text.length();
|
||||
while(i<len){
|
||||
if(text[i]==10) {//ENDLINE
|
||||
lines++;
|
||||
@@ -438,7 +395,7 @@ int wiFont::textHeight(const wchar_t* text,FLOAT siz,const int& style)
|
||||
i++;
|
||||
}
|
||||
|
||||
return (int)(lines*(fontStyles[style].recSize+siz));
|
||||
return (int)(lines*(fontStyles[style].recSize+props.size));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+41
-14
@@ -2,7 +2,33 @@
|
||||
#include "CommonInclude.h"
|
||||
#define MAX_TEXT 20000
|
||||
|
||||
class wiRenderer;
|
||||
enum wiFontAlign
|
||||
{
|
||||
WIFALIGN_LEFT,
|
||||
//same as mid
|
||||
WIFALIGN_CENTER,
|
||||
//same as center
|
||||
WIFALIGN_MID,
|
||||
WIFALIGN_RIGHT,
|
||||
WIFALIGN_TOP,
|
||||
WIFALIGN_BOTTOM,
|
||||
WIFALIGN_COUNT,
|
||||
};
|
||||
|
||||
class wiFontProps
|
||||
{
|
||||
public:
|
||||
int size;
|
||||
int spacingX, spacingY;
|
||||
float posX, posY;
|
||||
wiFontAlign h_align, v_align;
|
||||
|
||||
//zero-based properties: add or subtract from values
|
||||
wiFontProps(float posX = 0, float posY = 0, int size = 0, wiFontAlign h_align = WIFALIGN_LEFT, wiFontAlign v_align = WIFALIGN_TOP
|
||||
, int spacingX = 0, int spacingY = 0)
|
||||
:posX(posX), posY(posY), size(size), h_align(h_align), v_align(v_align), spacingX(spacingX), spacingY(spacingY)
|
||||
{}
|
||||
};
|
||||
|
||||
class wiFont
|
||||
{
|
||||
@@ -64,26 +90,27 @@ protected:
|
||||
static vector<wiFontStyle> 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 );
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace wiInitializer
|
||||
|
||||
if (requestedFeautures & WICKEDENGINE_INITIALIZE_FONT)
|
||||
{
|
||||
wiFont::Initialize();
|
||||
wiFont::SetUpStaticComponents();
|
||||
}
|
||||
|
||||
|
||||
+123
-11
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+35
-2
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user