From c4add72a28d879214e3c83cad876ea450b8e80e8 Mon Sep 17 00:00:00 2001 From: otya128 Date: Mon, 10 Jul 2017 18:29:22 +0900 Subject: [PATCH] Implement FADE --- SMILEBASIC/builtinfunctions.d | 12 ++++++ SMILEBASIC/fade.d | 77 +++++++++++++++++++++++++++++++++++ SMILEBASIC/petitcomputer.d | 17 +++++++- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 SMILEBASIC/fade.d diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 6339b68..0c84aa7 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -3996,6 +3996,18 @@ class BuiltinFunction { return p.clipboard; } + static void FADE(PetitComputer p, int color) + { + p.fade.fade(color); + } + static void FADE(PetitComputer p, int color, int time) + { + p.fade.fade(color, time); + } + static int FADE(PetitComputer p) + { + return p.fade.fade(); + } //alias void function(PetitComputer, Value[], Value[]) BuiltinFunc; static BuiltinFunctions[wstring] builtinFunctions; diff --git a/SMILEBASIC/fade.d b/SMILEBASIC/fade.d new file mode 100644 index 0000000..3eadf95 --- /dev/null +++ b/SMILEBASIC/fade.d @@ -0,0 +1,77 @@ +module otya.smilebasic.fade; +import otya.smilebasic.petitcomputer; +import derelict.opengl3.gl; + +class Fade +{ + PetitComputer petitcom; + int display; + public this(PetitComputer p, int display) + { + petitcom = p; + this.display = display; + fade(0); + } + int color; + int start; + int startColor; + int end; + int endColor; + public void fade(int color) + { + this.color = color; + end = -1; + start = -1; + } + public void fade(int color, int time) + { + this.startColor = this.color; + this.endColor = color; + this.start = petitcom.maincntRender; + this.end = this.start + time; + } + public int fade() + { + return color; + } + Tt linear(Tx, Tt)(Tx x1, Tx x2, Tt t) + { + return (x2 - x1) / t; + } + void render() + { + auto m = petitcom.maincntRender; + ubyte a, r, g, b; + petitcom.RGBRead(color, r, g, b, a); + if (m <= end) + { + int a1, r1, g1, b1, a2, r2, g2, b2; + petitcom.RGBRead(startColor, r1, g1, b1, a1); + petitcom.RGBRead(endColor, r2, g2, b2, a2); + auto t1 = m - start; + auto t2 = end - start; + a = cast(ubyte)(a1 + (linear(a1, a2, cast(double)t2) * t1)); + r = cast(ubyte)(r1 + (linear(r1, r2, cast(double)t2) * t1)); + g = cast(ubyte)(g1 + (linear(g1, g2, cast(double)t2) * t1)); + b = cast(ubyte)(b1 + (linear(b1, b2, cast(double)t2) * t1)); + color = petitcom.RGB(a, r, g, b); + } + if (!a) + return; + petitcom.chRenderingDisplay(display); + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); + glColor4ub(r, g, b, a); + glDisable(GL_TEXTURE_2D); + glBegin(GL_QUADS); + glVertex2i(0, 0); + glVertex2i(petitcom.currentDisplay.rect[display].w, 0); + glVertex2i(petitcom.currentDisplay.rect[display].w, petitcom.currentDisplay.rect[display].h); + glVertex2i(0, petitcom.currentDisplay.rect[display].h); + glEnd(); + glDepthMask(GL_TRUE); + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + } +} \ No newline at end of file diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 477625b..d3c5c00 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -23,6 +23,7 @@ import otya.smilebasic.graphic; import otya.smilebasic.dialog; import otya.smilebasic.program; import otya.smilebasic.random; +import otya.smilebasic.fade; static import otya.smilebasic.token; const static rot_test_deg = 45f; const static rot_test_x = 0f; @@ -284,6 +285,7 @@ class PetitComputer int[2] bgpage; Projects project; bool redirectConsole; + int displayCount; void init() { random = new Random(); @@ -317,6 +319,7 @@ class PetitComputer screenWidthDisplay1 = 320; screenHeightDisplay1 = 240; currentDisplay = Display([SDL_Rect(0, 0, screenWidth, screenHeight)]); + displayCount = 2; console = redirectConsole ? new NativeConsole(std.stdio.stdout, this) : new Console(this); if(!exists(fontTableFile)) { @@ -903,13 +906,17 @@ class PetitComputer version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z); //http://marina.sys.wakayama-u.ac.jp/~tokoi/?date=20081122 みたいな方法もあるけどとりあえず - //とりあえず一番楽な方法 + //とりあえず一番楽な方法main //これだと同一Zでスプライトが一番下に来てしまうのでZ値を補正する必要がある->やった glEnable(GL_BLEND); glDepthMask(GL_FALSE);//スプライト同士でのZバッファは半透明だと邪魔なので無効 sprite.render();//Zソートすべき->やった->プチコンの挙動的に安定ソートか非安定ソートか glDepthMask(GL_TRUE); glDisable(GL_BLEND); + for (int i = 0; i < currentDisplay.rect.length; i++) + { + fades[i].render(); + } if (dialog) { dialog.render(); @@ -1153,6 +1160,9 @@ class PetitComputer sprite = new Sprite(this); for(int i = 0; i < bg.length; i++) bg[i] = new BG(this); + fades = new Fade[displayCount]; + for (int i = 0; i < displayCount; i++) + fades[i] = new Fade(this, i); core.thread.Thread thread = new core.thread.Thread(&render); renderCondition = new Condition(new Mutex()); thread.start(); @@ -1856,6 +1866,11 @@ class PetitComputer return a << 24 | r << 16 | g << 8 | b; } public Random random; + Fade[] fades; + public Fade fade() + { + return fades[displaynum]; + } } unittest