BGを実装.
This commit is contained in:
@@ -205,6 +205,7 @@
|
||||
<filesToClean>*.obj;*.cmd;*.build;*.json;*.dep</filesToClean>
|
||||
</Config>
|
||||
<Folder name="SMILEBASIC">
|
||||
<File path="bg.d" />
|
||||
<File path="builtinfunctions.d" />
|
||||
<File path="compiler.d" />
|
||||
<File path="draw.d" />
|
||||
|
||||
@@ -588,6 +588,44 @@ class BuiltinFunction
|
||||
static void TALK(wstring a1)
|
||||
{
|
||||
}
|
||||
static void BGCLR(PetitComputer p, DefaultValue!(int, false) layer)
|
||||
{
|
||||
if(layer.isDefault)
|
||||
{
|
||||
foreach(bg; p.bg)
|
||||
{
|
||||
bg.clear;
|
||||
}
|
||||
return;
|
||||
}
|
||||
p.bg[cast(int)layer].clear;
|
||||
}
|
||||
static void BGSCREEN(PetitComputer p, int layer, int w, int h)
|
||||
{
|
||||
p.bg[layer].screen(w, h);
|
||||
}
|
||||
static void BGOFS(PetitComputer p, int layer, int x, int y, DefaultValue!(int, false) z)
|
||||
{
|
||||
z.setDefaultValue(p.bg[layer].offsetz);
|
||||
p.bg[layer].ofs(x, y, cast(int)z);
|
||||
}
|
||||
static void BGCLIP(PetitComputer p, int layer, DefaultValue!(int, false) x, DefaultValue!(int, false) y,
|
||||
DefaultValue!(int, false) x2, DefaultValue!(int, false) y2)
|
||||
{
|
||||
if(x.isDefault && y.isDefault && x2.isDefault && y2.isDefault)
|
||||
{
|
||||
p.bg[layer].clip();
|
||||
}
|
||||
if(x.isDefault || y.isDefault || x2.isDefault || y2.isDefault)
|
||||
{
|
||||
throw new IllegalFunctionCall("BGCLIP");
|
||||
}
|
||||
p.bg[layer].clip(cast(int)x, cast(int)y, cast(int)x2, cast(int)y2);
|
||||
}
|
||||
static void BGPUT(PetitComputer p, int layer, int x, int y, int screendata)
|
||||
{
|
||||
p.bg[layer].put(x, y, screendata);
|
||||
}
|
||||
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
||||
static BuiltinFunction[wstring] builtinFunctions;
|
||||
static this()
|
||||
|
||||
@@ -895,13 +895,21 @@ class Compiler
|
||||
int[] addresses = new int[label.labels.length];
|
||||
foreach(int index, wstring l; label.labels)
|
||||
{
|
||||
if(label.sc.func)
|
||||
try
|
||||
{
|
||||
addresses[index] =label.sc.func.label[l];
|
||||
if(label.sc.func)
|
||||
{
|
||||
addresses[index] =label.sc.func.label[l];
|
||||
}
|
||||
else
|
||||
{
|
||||
addresses[index] = globalLabel[l];
|
||||
}
|
||||
}
|
||||
else
|
||||
catch(Error re)
|
||||
{
|
||||
addresses[index] = globalLabel[l];
|
||||
//undefined labelは実行時に出る(TECDEMOが動かない)
|
||||
addresses[index] = int.min;
|
||||
}
|
||||
}
|
||||
if(label.isGosub)
|
||||
|
||||
@@ -122,15 +122,15 @@ END
|
||||
writeln(t);
|
||||
}
|
||||
}
|
||||
try
|
||||
//try
|
||||
{
|
||||
auto pc = new PetitComputer();
|
||||
pc.run();
|
||||
}
|
||||
catch(Throwable t)
|
||||
/*(Throwable t)
|
||||
{
|
||||
writeln(std.windows.charset.toMBSz(t.to!string).to!string);
|
||||
readln();
|
||||
}
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import core.sync.mutex;
|
||||
import otya.smilebasic.parser;
|
||||
import otya.smilebasic.sprite;
|
||||
import otya.smilebasic.error;
|
||||
import otya.smilebasic.bg;
|
||||
enum Button
|
||||
{
|
||||
NONE = 0,
|
||||
@@ -155,35 +156,6 @@ class PetitComputer
|
||||
uint gcolor = -1;
|
||||
GraphicPage[] GRP;
|
||||
GraphicPage GRPF;
|
||||
GraphicPage[] GRPFColor;
|
||||
GraphicPage[][] GRPFColorFore;
|
||||
SDL_Surface* s8x8;
|
||||
SDL_Texture* t8x8;
|
||||
SDL_Surface* createSurfaceFromFile(string file)
|
||||
{
|
||||
SDL_RWops* stream = SDL_RWFromFile(toStringz(file), toStringz("rb"));
|
||||
auto surfacesrc = IMG_LoadPNG_RW(stream);
|
||||
SDL_RWclose(stream);
|
||||
return surfacesrc;
|
||||
}
|
||||
//PNG画像から透過色のpixelを指定して透過しGRPを作る
|
||||
GraphicPage createGraphicPage(string file, int pixel)
|
||||
{
|
||||
SDL_RWops* stream = SDL_RWFromFile(toStringz(file), toStringz("rb"));
|
||||
auto surfacesrc = IMG_LoadPNG_RW(stream);
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, surfacesrc.w, surfacesrc.h, 32, 0, 0, 0, 0);
|
||||
SDL_Rect rect;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.w = surfacesrc.w;
|
||||
rect.h = surfacesrc.h;
|
||||
SDL_SetColorKey(surfacesrc, SDL_TRUE, (cast(uint*)surface.pixels)[pixel]);
|
||||
int i = SDL_BlitSurface(surfacesrc, &rect, surface, &rect);
|
||||
auto grp = new GraphicPage(surface);
|
||||
SDL_FreeSurface(surfacesrc);
|
||||
SDL_RWclose(stream);
|
||||
return grp;
|
||||
}
|
||||
GraphicPage createGRPF(string file)
|
||||
{
|
||||
SDL_RWops* stream = SDL_RWFromFile(toStringz(file), toStringz("rb"));
|
||||
@@ -229,67 +201,6 @@ class PetitComputer
|
||||
SDL_FreeSurface(src);
|
||||
return new GraphicPage(surface);
|
||||
}
|
||||
GraphicPage createGRPF(int color, SDL_Surface *src)
|
||||
{
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0, 0, 0, 0);
|
||||
auto srcpixels = (cast(uint*)src.pixels);
|
||||
auto pixels = (cast(uint*)surface.pixels);
|
||||
for(int x = 0; x < src.w; x++)
|
||||
{
|
||||
for(int y = 0; y < src.h; y++)
|
||||
{
|
||||
ubyte r, g, b, a;
|
||||
SDL_GetRGBA(*srcpixels, src.format, &r, &g, &b, &a);
|
||||
//if(a == 0)
|
||||
{
|
||||
auto back = consoleColor[color];
|
||||
r = back >> 16 & 0xFF;
|
||||
g = back >> 8 & 0xFF;
|
||||
b = back & 0xFF;
|
||||
a = back >> 24 & 0xFF;
|
||||
}
|
||||
*pixels = SDL_MapRGBA(surface.format, r, g, b, a);
|
||||
pixels++;
|
||||
srcpixels++;
|
||||
}
|
||||
}
|
||||
return new GraphicPage(surface);
|
||||
}
|
||||
GraphicPage createGRPF(int color, int colorFore, SDL_Surface *src)
|
||||
{
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0, 0, 0, 0);
|
||||
auto srcpixels = (cast(uint*)src.pixels);
|
||||
auto pixels = (cast(uint*)surface.pixels);
|
||||
for(int x = 0; x < src.w; x++)
|
||||
{
|
||||
for(int y = 0; y < src.h; y++)
|
||||
{
|
||||
ubyte r, g, b, a;
|
||||
SDL_GetRGBA(*srcpixels, src.format, &r, &g, &b, &a);
|
||||
if(r == 158 && g == 0 && b == 93 && a == 255)
|
||||
{
|
||||
auto back = consoleColor[color];
|
||||
r = back >> 16 & 0xFF;
|
||||
g = back >> 8 & 0xFF;
|
||||
b = back & 0xFF;
|
||||
a = back >> 24 & 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
//雑
|
||||
auto fore = consoleColor[colorFore];
|
||||
r = fore >> 16 & 0xFF;
|
||||
g = fore >> 8 & 0xFF;
|
||||
b = fore & 0xFF;
|
||||
a = fore >> 24 & 0xFF;
|
||||
}
|
||||
*pixels = SDL_MapRGBA(surface.format, r, g, b, a);
|
||||
pixels++;
|
||||
srcpixels++;
|
||||
}
|
||||
}
|
||||
return new GraphicPage(surface);
|
||||
}
|
||||
GraphicPage createEmptyPage()
|
||||
{
|
||||
auto surface = SDL_CreateRGBSurface(0, 512, 512, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0xff);
|
||||
@@ -555,6 +466,7 @@ class PetitComputer
|
||||
}
|
||||
xscreenmode = mode2;
|
||||
}
|
||||
BG[4] bg;
|
||||
void render()
|
||||
{
|
||||
buttonTable = new Button[SDL_SCANCODE_SLEEP + 1];
|
||||
@@ -563,7 +475,7 @@ class PetitComputer
|
||||
buttonTable[SDL_SCANCODE_LEFT] = Button.LEFT;
|
||||
buttonTable[SDL_SCANCODE_RIGHT] = Button.RIGHT;
|
||||
buttonTable[SDL_SCANCODE_SPACE] = Button.A;
|
||||
bool renderprofile;// = true;
|
||||
bool renderprofile = true;
|
||||
try
|
||||
{
|
||||
version(Windows)
|
||||
@@ -634,6 +546,11 @@ class PetitComputer
|
||||
glViewport(0, 240, 400, 240);
|
||||
}
|
||||
sprite.render();
|
||||
glBindTexture(GL_TEXTURE_2D, GRP[bgpage].glTexture);
|
||||
for(int i = 0; i < bg.length; i++)
|
||||
{
|
||||
bg[i].render(400f, 240f);
|
||||
}
|
||||
/* if(this.sprite.sprites[0].define)
|
||||
if(this.sprite.sprites[0].u == 0)
|
||||
{
|
||||
@@ -731,6 +648,8 @@ class PetitComputer
|
||||
core.thread.Thread thread = new core.thread.Thread(&render);
|
||||
thread.start();
|
||||
sprite = new Sprite(this);
|
||||
for(int i = 0; i < bg.length; i++)
|
||||
bg[i] = new BG(this);
|
||||
auto startTicks = SDL_GetTicks();
|
||||
//とりあえず
|
||||
auto parser = new Parser(
|
||||
@@ -738,9 +657,10 @@ class PetitComputer
|
||||
//readText("./SYS/GAME2RPG.TXT").to!wstring
|
||||
//readText("./SYS/GAME1DOTRC.TXT").to!wstring
|
||||
//readText(input("LOAD PROGRAM:", true).to!string).to!wstring
|
||||
readText("./SYS/EX8TECDEMO.TXT").to!wstring
|
||||
//readText("./SYS/EX1TEXT.TXT").to!wstring
|
||||
//readText("FIZZBUZZ.TXT").to!wstring
|
||||
readText("TEST.TXT").to!wstring
|
||||
//readText("TEST.TXT").to!wstring
|
||||
/*"?ABS(-1)
|
||||
LOCATE 0,10
|
||||
COLOR 5
|
||||
@@ -783,8 +703,9 @@ class PetitComputer
|
||||
auto vm = parser.compile();
|
||||
bool running = true;
|
||||
vm.init(this);
|
||||
vm.dump;
|
||||
//vm.dump;
|
||||
this.vm = vm;
|
||||
bg[0].put(0,0,1);
|
||||
//gpset(0, 10, 10, 0xFF00FF00);
|
||||
//gline(0, 0, 0, 399, 239, RGB(0, 255, 0));
|
||||
//gfill(0, 78, 78, 40, 40, RGB(0, 255, 255));
|
||||
|
||||
Reference in New Issue
Block a user