Implement FADE
This commit is contained in:
@@ -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;
|
||||
|
||||
77
SMILEBASIC/fade.d
Normal file
77
SMILEBASIC/fade.d
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user