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)
{
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)
{

View File

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

View File

@@ -156,9 +156,14 @@ struct Slot
}
}
}
struct Size
{
int width, height;
}
struct Display
{
SDL_Rect[] rect;
Size windowSize;
}
class PetitComputer
{
@@ -306,6 +311,7 @@ class PetitComputer
screenHeight = 240;
screenWidthDisplay1 = 320;
screenHeightDisplay1 = 240;
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)]);
console = new Console(this);
if(!exists(fontTableFile))
{
@@ -317,7 +323,6 @@ class PetitComputer
{
console.loadFontTable();
}
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)]);
display(0);
writeln("OK");
}
@@ -391,12 +396,15 @@ class PetitComputer
glLoadIdentity();
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;
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)];
int xscreenmode = 0;
int bgmax;
@@ -411,56 +419,59 @@ class PetitComputer
Display currentDisplay;
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;
xscreenmode = mode2;
if(mode2 == 0)
synchronized(renderSync)
{
SDL_SetWindowSize(window, 400, 240);
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)]);
}
if(mode2 == 1)
{
currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight), SDL_Rect((screenWidth - screenWidthDisplay1) / 2, screenHeight, screenWidthDisplay1, screenHeightDisplay1)]);
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)
this.sprite.spclr();
this.sprite.spmax = sprite;
this.bgmax = bg;
//BG
xscreenmode = mode2;
if(mode2 == 0)
{
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);
graphic.clip(true);
SDL_SetWindowSize(window, currentDisplay.windowSize.width, currentDisplay.windowSize.height);
}
BG getBG(int layer)
{
if(displaynum)
@@ -517,6 +528,7 @@ class PetitComputer
{
return petitcomBackcolor;
}
Object renderSync = new Object();
void render()
{
try
@@ -640,101 +652,104 @@ class PetitComputer
loopcnt = 0;
}
}
glLoadIdentity();
graphic.draw();
chScreen(0, 0, 400, 240);
if(xscreenmode == 1)
synchronized(renderSync)
{
chScreen(0, 240, 400, 240);
}
if(xscreenmode == 2)
{
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++)
glLoadIdentity();
graphic.draw();
chScreen(0, 0, 400, 240);
if(xscreenmode == 1)
{
bg[i].render(320f, 480f);
chScreen(0, 240, 400, 240);
}
}
else
{
if (BGvisibles[0])
if(xscreenmode == 2)
{
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(400f, 240f);
bg[i].render(320f, 480f);
}
}
if(xscreenmode == 1 && BGvisibles[1])
else
{
chScreen(40, 0, 320, 240);
for(int i = bgmax; i < bg.length; i++)
if (BGvisibles[0])
{
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);
}
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);
if(renderprofile) writeln(renderticks);
int mousex, mousey;