1
0

Fix console for BIG

This commit is contained in:
otya128
2016-12-10 17:02:17 +09:00
parent 1a6332d830
commit 92e5f3abc4
3 changed files with 170 additions and 255 deletions

View File

@@ -1418,7 +1418,7 @@ class BuiltinFunction
} }
static int CHKCHR(PetitComputer p, int x, int y) static int CHKCHR(PetitComputer p, int x, int y)
{ {
return cast(int)(p.console.console[y][x].character); return cast(int)(p.console.console[p.displaynum][y][x].character);
} }
struct FixedBuffer(T, size_t S) struct FixedBuffer(T, size_t S)
{ {

View File

@@ -63,9 +63,7 @@ class Console
0xFFFFFFFF, 0xFFFFFFFF,
]; ];
int[] consoleColorGL = new int[16]; int[] consoleColorGL = new int[16];
ConsoleCharacter[][] console; ConsoleCharacter[][][] console;
ConsoleCharacter[][] consoleDisplay1;
ConsoleCharacter[][] console4;
int[2] CSRXs; int[2] CSRXs;
int[2] CSRYs; int[2] CSRYs;
int[2] CSRZs; int[2] CSRZs;
@@ -113,28 +111,16 @@ class Console
fontWidth = fontHeight = w; fontWidth = fontHeight = w;
consoleWidth = petitcom.screenWidth / fontWidth; consoleWidth = petitcom.screenWidth / fontWidth;
consoleHeight = petitcom.screenHeight / fontHeight; consoleHeight = petitcom.screenHeight / fontHeight;
consoleWidthDisplay1 = petitcom.screenWidthDisplay1 / fontWidth; console = new ConsoleCharacter[][][petitcom.currentDisplay.rect.length];
consoleHeightDisplay1 = petitcom.screenHeightDisplay1 / fontHeight;
consoleWidth4 = 320 / fontWidth;
consoleHeight4 = 480 / fontHeight;
console = new ConsoleCharacter[][consoleHeight];
consoleDisplay1 = new ConsoleCharacter[][consoleHeightDisplay1];
console4 = new ConsoleCharacter[][consoleHeight4];
consoleForeColor = 15;//#T_WHITE consoleForeColor = 15;//#T_WHITE
for(int i = 0; i < console.length; i++) for(int i = 0; i < console.length; i++)
{ {
console[i] = new ConsoleCharacter[consoleWidth]; console[i] = new ConsoleCharacter[][petitcom.currentDisplay.rect[i].h / fontHeight];
console[i][] = ConsoleCharacter(0, consoleForeColor, consoleBackColor); for(int j = 0; j < console[i].length; j++)
} {
for(int i = 0; i < consoleDisplay1.length; i++) console[i][j] = new ConsoleCharacter[petitcom.currentDisplay.rect[i].w / fontWidth];
{ console[i][j][] = ConsoleCharacter(0, consoleForeColor, consoleBackColor);
consoleDisplay1[i] = new ConsoleCharacter[consoleWidthDisplay1]; }
consoleDisplay1[i][] = ConsoleCharacter(0, consoleForeColor, consoleBackColor);
}
for(int i = 0; i < console4.length; i++)
{
console4[i] = new ConsoleCharacter[consoleWidth4];
console4[i][] = ConsoleCharacter(0, consoleForeColor, consoleBackColor);
} }
CSRXs[] = 0; CSRXs[] = 0;
CSRYs[] = 0; CSRYs[] = 0;
@@ -142,6 +128,11 @@ class Console
display(petitcom.displaynum); display(petitcom.displaynum);
} }
} }
//FIXME:画面サイズが変わらないと画面はクリアされないのにクリアされる
void changeDisplay(ref Display display)
{
width(fontWidth);
}
bool visible() bool visible()
{ {
return visibles[petitcom.displaynum]; return visibles[petitcom.displaynum];
@@ -220,23 +211,9 @@ class Console
{ {
synchronized(this) synchronized(this)
{ {
if(petitcom.xscreenmode == 2) consoleHeightC = petitcom.currentDisplay.rect[number].h / fontHeight;
{ consoleWidthC = petitcom.currentDisplay.rect[number].w / fontWidth;
consoleHeightC = consoleHeight4; consoleC = console[number];
consoleWidthC = consoleWidth4;
consoleC = console4;
return;
}
if(number == 1)
{
consoleHeightC = consoleHeightDisplay1;
consoleWidthC = consoleWidthDisplay1;
consoleC = consoleDisplay1;
return;
}
consoleHeightC = consoleHeight;
consoleWidthC = consoleWidth;
consoleC = console;
} }
} }
void drawCharacter(int x, int y, ConsoleCharacter ch) void drawCharacter(int x, int y, ConsoleCharacter ch)
@@ -319,53 +296,20 @@ class Console
} }
synchronized(this) synchronized(this)
{ {
if(petitcom.xscreenmode == 2 && (visibles[0] || showCursor)/*XSCREEN4*/) glBindTexture(GL_TEXTURE_2D, GRPF.glTexture);
for (int i = 0; i < petitcom.currentDisplay.rect.length; i++)
{ {
glBindTexture(GL_TEXTURE_2D, GRPF.glTexture); if (!visibles[i] && !showCursor)
glDisable(GL_TEXTURE_2D); continue;
glBegin(GL_QUADS); petitcom.chScreen2(petitcom.currentDisplay.rect[i].x, petitcom.currentDisplay.rect[i].y, petitcom.currentDisplay.rect[i].w, petitcom.currentDisplay.rect[i].h);
for(int y = 0; y < consoleHeight4; y++) int consoleWidth = petitcom.currentDisplay.rect[i].w / fontWidth;
for(int x = 0; x < consoleWidth4; x++) int consoleHeight = petitcom.currentDisplay.rect[i].h / fontHeight;
{
auto back = consoleColorGL[console4[y][x].backColor];
if(back)
{
glColor4ubv(cast(ubyte*)&back);
glVertex3f(x * 8, y * 8 + 8, 1024);
glVertex3f(x * 8, y * 8, 1024);
glVertex3f(x * 8 + 8, y * 8, 1024);
glVertex3f(x * 8 + 8, y * 8 + 8, 1024);
}
}
if(showCursor && animationCursor)
{
glColor4ubv(cast(ubyte*)&consoleColorGL[15]);
glVertex3f((CSRX * 8), (CSRY * 8 + 8), -256);
glVertex3f((CSRX * 8), (CSRY * 8), -256);
glVertex3f((CSRX * 8 + 2), (CSRY * 8), -256);
glVertex3f((CSRX * 8 + 2), (CSRY * 8 + 8), -256);
}
glEnd();
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
for(int y = 0; y < consoleHeight4; y++)
for(int x = 0; x < consoleWidth4; x++)
{
drawCharacter(x, y, console4[y][x]);
}
glEnd();
return;
}
if (showCursor || visibles[0])
{
glBindTexture(GL_TEXTURE_2D, GRPF.glTexture);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS); glBegin(GL_QUADS);
for(int y = 0; y < consoleHeight; y++) for(int y = 0; y < consoleHeight; y++)
for(int x = 0; x < consoleWidth; x++) for(int x = 0; x < consoleWidth; x++)
{ {
auto back = consoleColorGL[console[y][x].backColor]; auto back = consoleColorGL[console[i][y][x].backColor];
if(back) if(back)
{ {
glColor4ubv(cast(ubyte*)&back); glColor4ubv(cast(ubyte*)&back);
@@ -375,7 +319,7 @@ class Console
glVertex3f(x * 8 + 8, y * 8 + 8, 1024); glVertex3f(x * 8 + 8, y * 8 + 8, 1024);
} }
} }
if(petitcom.displaynum == 0 && showCursor && animationCursor) if(petitcom.displaynum == i && showCursor && animationCursor)
{ {
glColor4ubv(cast(ubyte*)&consoleColorGL[15]); glColor4ubv(cast(ubyte*)&consoleColorGL[15]);
glVertex3f((CSRX * 8), (CSRY * 8 + 8), -256); glVertex3f((CSRX * 8), (CSRY * 8 + 8), -256);
@@ -390,51 +334,7 @@ class Console
for(int y = 0; y < consoleHeight; y++) for(int y = 0; y < consoleHeight; y++)
for(int x = 0; x < consoleWidth; x++) for(int x = 0; x < consoleWidth; x++)
{ {
drawCharacter(x, y, console[y][x]); drawCharacter(x, y, console[i][y][x]);
}
glEnd();
if(petitcom.xscreenmode != 1)
{
return;
}
}
if (visibles[1] || showCursor)
{
//下画面
petitcom.chScreen(40, 0, 400, 240);
adjustScreen();
glBindTexture(GL_TEXTURE_2D, GRPF.glTexture);
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
for(int y = 0; y < consoleHeightDisplay1; y++)
for(int x = 0; x < consoleWidthDisplay1; x++)
{
auto back = consoleColorGL[consoleDisplay1[y][x].backColor];
if(back)
{
glColor4ubv(cast(ubyte*)&back);
glVertex3f(x * 8, y * 8 + 8, 1024);
glVertex3f(x * 8, y * 8, 1024);
glVertex3f(x * 8 + 8, y * 8, 1024);
glVertex3f(x * 8 + 8, y * 8 + 8, 1024);
}
}
if(petitcom.displaynum == 1 && showCursor && animationCursor)
{
glColor4ubv(cast(ubyte*)&consoleColorGL[15]);
glVertex3f((CSRX * 8), (CSRY * 8 + 8), -256);
glVertex3f((CSRX * 8), (CSRY * 8), -256);
glVertex3f((CSRX * 8 + 2), (CSRY * 8), -256);
glVertex3f((CSRX * 8 + 2), (CSRY * 8 + 8), -256);
}
glEnd();
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
for(int y = 0; y < consoleHeightDisplay1; y++)
for(int x = 0; x < consoleWidthDisplay1; x++)
{
drawCharacter(x, y, consoleDisplay1[y][x]);
} }
glEnd(); glEnd();
} }

View File

@@ -156,9 +156,14 @@ struct Slot
} }
} }
} }
struct Size
{
int width, height;
}
struct Display struct Display
{ {
SDL_Rect[] rect; SDL_Rect[] rect;
Size windowSize;
} }
class PetitComputer class PetitComputer
{ {
@@ -306,6 +311,7 @@ class PetitComputer
screenHeight = 240; screenHeight = 240;
screenWidthDisplay1 = 320; screenWidthDisplay1 = 320;
screenHeightDisplay1 = 240; screenHeightDisplay1 = 240;
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)]);
console = new Console(this); console = new Console(this);
if(!exists(fontTableFile)) if(!exists(fontTableFile))
{ {
@@ -317,7 +323,6 @@ class PetitComputer
{ {
console.loadFontTable(); console.loadFontTable();
} }
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)]);
display(0); display(0);
writeln("OK"); writeln("OK");
} }
@@ -391,12 +396,15 @@ class PetitComputer
glLoadIdentity(); glLoadIdentity();
glOrtho(0, w, h, 0, 1024, -2048); glOrtho(0, w, h, 0, 1024, -2048);
} }
void chScreen2(int x, int y, int w, int h)
{
glViewport(x, currentDisplay.windowSize.height - h - y, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0, 1024, -2048);
}
Button[] buttonTable; Button[] buttonTable;
Sprite sprite; Sprite sprite;
struct Size
{
int width, height;
}
Size[7] resolutionTable = [Size(256, 192), Size(320, 200), Size(320, 240), Size(400, 240), Size(640, 400), Size(640, 480), Size(854, 480)]; Size[7] resolutionTable = [Size(256, 192), Size(320, 200), Size(320, 240), Size(400, 240), Size(640, 400), Size(640, 480), Size(854, 480)];
int xscreenmode = 0; int xscreenmode = 0;
int bgmax; int bgmax;
@@ -411,56 +419,59 @@ class PetitComputer
Display currentDisplay; Display currentDisplay;
void xscreen(int mode, int tv, int gamepad, int sprite, int bg) void xscreen(int mode, int tv, int gamepad, int sprite, int bg)
{ {
this.sprite.spclr();
this.sprite.spmax = sprite;
this.bgmax = bg;
//BG
int mode2 = mode / 2; int mode2 = mode / 2;
xscreenmode = mode2; synchronized(renderSync)
if(mode2 == 0)
{ {
SDL_SetWindowSize(window, 400, 240); this.sprite.spclr();
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)]); this.sprite.spmax = sprite;
} this.bgmax = bg;
if(mode2 == 1) //BG
{ xscreenmode = mode2;
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight), SDL_Rect((screenWidth - screenWidthDisplay1) / 2, screenHeight, screenWidthDisplay1, screenHeightDisplay1)]); if(mode2 == 0)
SDL_SetWindowSize(window, 400, 480);
display(1);
graphic.clip(false);
graphic.clip(true);
}
if(mode == 4)
{
SDL_SetWindowSize(window, 320, 240 * 2);
currentDisplay = Display([SDL_Rect(0, 0, screenWidthDisplay1, screenHeight + screenHeightDisplay1)]);
}
if (mode == 5)
{
SDL_SetWindowSize(window, resolutionTable[tv].width, resolutionTable[tv].height);
currentDisplay = Display([SDL_Rect(0, 0, resolutionTable[tv].width, resolutionTable[tv].height)]);
xscreenmode = 3;
}
if (mode == 6)
{
auto display0 = SDL_Rect(0, 0, resolutionTable[tv].width, resolutionTable[tv].height);
auto display1 = SDL_Rect(0, resolutionTable[tv].height, resolutionTable[gamepad].width, resolutionTable[gamepad].height);
if (resolutionTable[tv].width > resolutionTable[gamepad].width)
{ {
display1.x = (resolutionTable[tv].width - resolutionTable[gamepad].width) / 2; currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)], Size(400, 240));
} }
else if(mode2 == 1)
{ {
display0.x = (resolutionTable[gamepad].width - resolutionTable[tv].width) / 2; currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight), SDL_Rect((screenWidth - screenWidthDisplay1) / 2, screenHeight, screenWidthDisplay1, screenHeightDisplay1)], Size(400, 480));
}
if(mode == 4)
{
currentDisplay = Display([SDL_Rect(0, 0, screenWidthDisplay1, screenHeight + screenHeightDisplay1)], Size(320, 480));
}
if (mode == 5)
{
currentDisplay = Display([SDL_Rect(0, 0, resolutionTable[tv].width, resolutionTable[tv].height)], Size(resolutionTable[tv].width, resolutionTable[tv].height));
xscreenmode = 3;
}
if (mode == 6)
{
auto display0 = SDL_Rect(0, 0, resolutionTable[tv].width, resolutionTable[tv].height);
auto display1 = SDL_Rect(0, resolutionTable[tv].height, resolutionTable[gamepad].width, resolutionTable[gamepad].height);
if (resolutionTable[tv].width > resolutionTable[gamepad].width)
{
display1.x = (resolutionTable[tv].width - resolutionTable[gamepad].width) / 2;
}
else
{
display0.x = (resolutionTable[gamepad].width - resolutionTable[tv].width) / 2;
}
currentDisplay = Display([display0, display1], Size(std.algorithm.max(resolutionTable[gamepad].width, resolutionTable[tv].width), std.algorithm.max(resolutionTable[gamepad].height, resolutionTable[tv].height)));
xscreenmode = 4;
}
displaynum = 0;
console.changeDisplay(currentDisplay);
for (int i = currentDisplay.rect.length - 1; i >= 0; i--)
{
display(i);
graphic.clip(false);
graphic.clip(true);
} }
currentDisplay = Display([display0, display1]);
SDL_SetWindowSize(window, std.algorithm.max(resolutionTable[gamepad].width, resolutionTable[tv].width), std.algorithm.max(resolutionTable[gamepad].height, resolutionTable[tv].height));
xscreenmode = 4;
} }
display(0);
graphic.clip(false); SDL_SetWindowSize(window, currentDisplay.windowSize.width, currentDisplay.windowSize.height);
graphic.clip(true);
} }
BG getBG(int layer) BG getBG(int layer)
{ {
if(displaynum) if(displaynum)
@@ -517,6 +528,7 @@ class PetitComputer
{ {
return petitcomBackcolor; return petitcomBackcolor;
} }
Object renderSync = new Object();
void render() void render()
{ {
try try
@@ -640,101 +652,104 @@ class PetitComputer
loopcnt = 0; loopcnt = 0;
} }
} }
glLoadIdentity(); synchronized(renderSync)
graphic.draw();
chScreen(0, 0, 400, 240);
if(xscreenmode == 1)
{ {
chScreen(0, 240, 400, 240); glLoadIdentity();
} graphic.draw();
if(xscreenmode == 2) chScreen(0, 0, 400, 240);
{ if(xscreenmode == 1)
chScreen(0, 0, 320, 480);
}
{
ubyte r, g, b, a;
RGBRead(petitcomBackcolor, r, g, b, a);
glClearColor(r / 255f, g / 255f, b / 255f, 1);
}
//描画の順位
//sprite>GRP>console>BG
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
version(test) glLoadIdentity();
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
console.render();
if(xscreenmode == 1)
{
chScreen(0, 240, 400, 240);
}
if(xscreenmode == 2)
{
graphic.render(0, 320, 480);
}
else
{
graphic.render(0, 400, 240);
}
if(xscreenmode == 1)
{
chScreen(40, 0, 320, 240);
graphic.render(1, 320, 240);
chScreen(0, 240, 400, 240);
}
if(xscreenmode == 2)
{
chScreen(0, 0, 320, 480);
}
if(xscreenmode == 1)
{
chScreen(0, 240, 400, 240);
}
version(test) glLoadIdentity();
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
glBindTexture(GL_TEXTURE_2D, graphic.GRP[bgpage].glTexture);
if(xscreenmode == 2 && BGvisibles[0])
{
for(int i = 0; i < bgmax; i++)
{ {
bg[i].render(320f, 480f); chScreen(0, 240, 400, 240);
} }
} if(xscreenmode == 2)
else {
{ chScreen(0, 0, 320, 480);
if (BGvisibles[0]) }
{
ubyte r, g, b, a;
RGBRead(petitcomBackcolor, r, g, b, a);
glClearColor(r / 255f, g / 255f, b / 255f, 1);
}
//描画の順位
//sprite>GRP>console>BG
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
version(test) glLoadIdentity();
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
console.render();
if(xscreenmode == 1)
{
chScreen(0, 240, 400, 240);
}
if(xscreenmode == 2)
{
graphic.render(0, 320, 480);
}
else
{
graphic.render(0, 400, 240);
}
if(xscreenmode == 1)
{
chScreen(40, 0, 320, 240);
graphic.render(1, 320, 240);
chScreen(0, 240, 400, 240);
}
if(xscreenmode == 2)
{
chScreen(0, 0, 320, 480);
}
if(xscreenmode == 1)
{
chScreen(0, 240, 400, 240);
}
version(test) glLoadIdentity();
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
glBindTexture(GL_TEXTURE_2D, graphic.GRP[bgpage].glTexture);
if(xscreenmode == 2 && BGvisibles[0])
{ {
for(int i = 0; i < bgmax; i++) for(int i = 0; i < bgmax; i++)
{ {
bg[i].render(400f, 240f); bg[i].render(320f, 480f);
} }
} }
if(xscreenmode == 1 && BGvisibles[1]) else
{ {
chScreen(40, 0, 320, 240); if (BGvisibles[0])
for(int i = bgmax; i < bg.length; i++)
{ {
bg[i].render(320f, 240f); for(int i = 0; i < bgmax; i++)
{
bg[i].render(400f, 240f);
}
} }
if(xscreenmode == 1 && BGvisibles[1])
{
chScreen(40, 0, 320, 240);
for(int i = bgmax; i < bg.length; i++)
{
bg[i].render(320f, 240f);
}
chScreen(0, 240, 400, 240);
}
glMatrixMode(GL_MODELVIEW);
}
version(test) glLoadIdentity();
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
if(xscreenmode == 1)
{
chScreen(0, 240, 400, 240); chScreen(0, 240, 400, 240);
} }
glMatrixMode(GL_MODELVIEW); //http://marina.sys.wakayama-u.ac.jp/~tokoi/?date=20081122 みたいな方法もあるけどとりあえず
//とりあえず一番楽な方法
//これだと同一Zでスプライトが一番下に来てしまうのでZ値を補正する必要がある->やった
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);//スプライト同士でのZバッファは半透明だと邪魔なので無効
sprite.render();//Zソートすべき->やった->プチコンの挙動的に安定ソートか非安定ソートか
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
SDL_GL_SwapWindow(window);
} }
version(test) glLoadIdentity();
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
if(xscreenmode == 1)
{
chScreen(0, 240, 400, 240);
}
//http://marina.sys.wakayama-u.ac.jp/~tokoi/?date=20081122 みたいな方法もあるけどとりあえず
//とりあえず一番楽な方法
//これだと同一Zでスプライトが一番下に来てしまうのでZ値を補正する必要がある->やった
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);//スプライト同士でのZバッファは半透明だと邪魔なので無効
sprite.render();//Zソートすべき->やった->プチコンの挙動的に安定ソートか非安定ソートか
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
SDL_GL_SwapWindow(window);
auto renderticks = (SDL_GetTicks() - profile); auto renderticks = (SDL_GetTicks() - profile);
if(renderprofile) writeln(renderticks); if(renderprofile) writeln(renderticks);
int mousex, mousey; int mousex, mousey;