SNAKE-DR.が動くようになった.SPCOLOR実装GPAINT実装
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
<useInline>0</useInline>
|
<useInline>0</useInline>
|
||||||
<release>0</release>
|
<release>0</release>
|
||||||
<preservePaths>0</preservePaths>
|
<preservePaths>0</preservePaths>
|
||||||
<warnings>0</warnings>
|
<warnings>1</warnings>
|
||||||
<infowarnings>0</infowarnings>
|
<infowarnings>0</infowarnings>
|
||||||
<checkProperty>0</checkProperty>
|
<checkProperty>0</checkProperty>
|
||||||
<genStackFrame>0</genStackFrame>
|
<genStackFrame>0</genStackFrame>
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
<debuglevel>0</debuglevel>
|
<debuglevel>0</debuglevel>
|
||||||
<debugids />
|
<debugids />
|
||||||
<versionlevel>0</versionlevel>
|
<versionlevel>0</versionlevel>
|
||||||
<versionids />
|
<versionids>NDirectMode</versionids>
|
||||||
<dump_source>0</dump_source>
|
<dump_source>0</dump_source>
|
||||||
<mapverbosity>0</mapverbosity>
|
<mapverbosity>0</mapverbosity>
|
||||||
<createImplib>0</createImplib>
|
<createImplib>0</createImplib>
|
||||||
|
|||||||
@@ -23,10 +23,17 @@ struct VMVariable
|
|||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
struct SourceLocation
|
||||||
|
{
|
||||||
|
int line;//何行目
|
||||||
|
int pos;//何文字目
|
||||||
|
byte slot;//スロット
|
||||||
|
}
|
||||||
class VM
|
class VM
|
||||||
{
|
{
|
||||||
DataTable globalDataTable;
|
DataTable globalDataTable;
|
||||||
Code[] code;
|
Code[] code;
|
||||||
|
SourceLocation[] location;
|
||||||
int stacki;
|
int stacki;
|
||||||
int pc;
|
int pc;
|
||||||
Value[] stack;
|
Value[] stack;
|
||||||
@@ -742,7 +749,6 @@ class NewArray : Code
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new TypeMismatch();
|
throw new TypeMismatch();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
vm.push(array);
|
vm.push(array);
|
||||||
}
|
}
|
||||||
@@ -885,7 +891,6 @@ class PopArray : Code
|
|||||||
//TODO:文字列の挙動
|
//TODO:文字列の挙動
|
||||||
throw new TypeMismatch();
|
throw new TypeMismatch();
|
||||||
//array.stringValue[index[0]] = assign.stringValue[0];
|
//array.stringValue[index[0]] = assign.stringValue[0];
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
throw new TypeMismatch();
|
throw new TypeMismatch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class BG
|
|||||||
glScalef(1.0f / aspect, 1.0f, 1.0f);
|
glScalef(1.0f / aspect, 1.0f, 1.0f);
|
||||||
glRotatef(360 - r, 0.0f, 0.0f, 1.0f );
|
glRotatef(360 - r, 0.0f, 0.0f, 1.0f );
|
||||||
glScalef(scalex * aspect, scaley, 1f);
|
glScalef(scalex * aspect, scaley, 1f);
|
||||||
version(test) glRotatef(45f, 1f, 0f, 0.5f);
|
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
|
||||||
//viewport
|
//viewport
|
||||||
//clipx,clipy
|
//clipx,clipy
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|||||||
@@ -228,6 +228,11 @@ class BuiltinFunction
|
|||||||
p.showGRP = showPage;
|
p.showGRP = showPage;
|
||||||
p.useGRP = usePage;
|
p.useGRP = usePage;
|
||||||
}
|
}
|
||||||
|
static void GPAINT(PetitComputer p, int x, int y, DefaultValue!(int, false) color, DefaultValue!(int, false) color2)
|
||||||
|
{
|
||||||
|
color.setDefaultValue(p.gcolor);
|
||||||
|
p.gpaint(p.useGRP, x, y, cast(int)color);
|
||||||
|
}
|
||||||
static void BGMPLAY(PetitComputer p, int music)
|
static void BGMPLAY(PetitComputer p, int music)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -477,6 +482,9 @@ class BuiltinFunction
|
|||||||
{
|
{
|
||||||
switch(va_args.length)
|
switch(va_args.length)
|
||||||
{
|
{
|
||||||
|
case 0:
|
||||||
|
p.sprite.spdef();//初期化
|
||||||
|
return;
|
||||||
case 1://array
|
case 1://array
|
||||||
{
|
{
|
||||||
if(va_args[0].isNumberArray)
|
if(va_args[0].isNumberArray)
|
||||||
@@ -557,6 +565,10 @@ class BuiltinFunction
|
|||||||
{
|
{
|
||||||
p.sprite.sprot(i, rot);
|
p.sprite.sprot(i, rot);
|
||||||
}
|
}
|
||||||
|
static void SPCOLOR(PetitComputer p, int id, int color)
|
||||||
|
{
|
||||||
|
p.sprite.spcolor(id, cast(uint)color);
|
||||||
|
}
|
||||||
static void BGMSTOP(PetitComputer p)
|
static void BGMSTOP(PetitComputer p)
|
||||||
{
|
{
|
||||||
writeln("NOTIMPL:BGMSTOP");
|
writeln("NOTIMPL:BGMSTOP");
|
||||||
@@ -709,16 +721,46 @@ class BuiltinFunction
|
|||||||
static void EFCWET(Value[])
|
static void EFCWET(Value[])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
static void COPY(PetitComputer p, Value[] rawargs)
|
||||||
|
{
|
||||||
|
auto args = retro(rawargs);
|
||||||
|
//文字列はリテラル渡すとType mismatch
|
||||||
|
if(args.length > 5 || args.length < 2 || !args[0].isArray)
|
||||||
|
{
|
||||||
|
throw new IllegalFunctionCall("COPY");
|
||||||
|
}
|
||||||
|
//COPY string, string->文字列COPY
|
||||||
|
//COPY array, string->DATA COPY
|
||||||
|
Value dst = args[0];
|
||||||
|
int dstoffset = 0;
|
||||||
|
int srcoffset = 0;
|
||||||
|
int len = dst.length;//省略時はコピー元の末尾まで
|
||||||
|
if(args[1].isString && !args[0].isString)
|
||||||
|
{
|
||||||
|
//DATAから
|
||||||
|
VM vm = p.vm;
|
||||||
|
vm.pushDataIndex();
|
||||||
|
vm.restoreData(args[1].castString);
|
||||||
|
for(int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
Value data = vm.readData();
|
||||||
|
dst[dstoffset++] = data;
|
||||||
|
}
|
||||||
|
vm.popDataIndex();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new IllegalFunctionCall("COPY (Not implemented error)");
|
||||||
|
}
|
||||||
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
||||||
static BuiltinFunction[wstring] builtinFunctions;
|
static BuiltinFunction[wstring] builtinFunctions;
|
||||||
static this()
|
static this()
|
||||||
{
|
{
|
||||||
foreach(name; __traits(derivedMembers, BuiltinFunction))
|
foreach(name; __traits(derivedMembers, BuiltinFunction))
|
||||||
{
|
{
|
||||||
writeln(name);
|
//writeln(name);
|
||||||
static if(/*__traits(isStaticFunction, __traits(getMember, BuiltinFunction, name)) && */name[0].isUpper)
|
static if(/*__traits(isStaticFunction, __traits(getMember, BuiltinFunction, name)) && */name[0].isUpper)
|
||||||
{
|
{
|
||||||
pragma(msg, AddFunc!(BuiltinFunction, name));
|
//pragma(msg, AddFunc!(BuiltinFunction, name));
|
||||||
wstring suffix = "";
|
wstring suffix = "";
|
||||||
if(is(ReturnType!(__traits(getMember, BuiltinFunction, name)) == wstring))
|
if(is(ReturnType!(__traits(getMember, BuiltinFunction, name)) == wstring))
|
||||||
{
|
{
|
||||||
@@ -732,7 +774,7 @@ class BuiltinFunction
|
|||||||
IsVariadic!(BuiltinFunction, name),
|
IsVariadic!(BuiltinFunction, name),
|
||||||
name,
|
name,
|
||||||
);
|
);
|
||||||
writeln(AddFunc!(BuiltinFunction, name));
|
//writeln(AddFunc!(BuiltinFunction, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -799,8 +841,7 @@ template AddFunc(T, string N)
|
|||||||
}
|
}
|
||||||
else static if(is(ReturnType!(__traits(getMember, T, N)) == void))
|
else static if(is(ReturnType!(__traits(getMember, T, N)) == void))
|
||||||
{
|
{
|
||||||
|
//pragma(msg, GetArgumentCount!(T,N));
|
||||||
pragma(msg, GetArgumentCount!(T,N));
|
|
||||||
const string AddFunc = "function void(PetitComputer p, Value[] arg, Value[] ret){/*if(ret.length != 0){throw new IllegalFunctionCall(\"" ~ N ~ "\");}*/" ~ OutArgsInit!(T,N) ~ N ~ "(" ~
|
const string AddFunc = "function void(PetitComputer p, Value[] arg, Value[] ret){/*if(ret.length != 0){throw new IllegalFunctionCall(\"" ~ N ~ "\");}*/" ~ OutArgsInit!(T,N) ~ N ~ "(" ~
|
||||||
AddFuncArg!(/*ParameterTypeTuple!(__traits(getMember, T, N)).length*/GetArgumentCount!(T,N) - 1, 0, 0, 0, T, N,
|
AddFuncArg!(/*ParameterTypeTuple!(__traits(getMember, T, N)).length*/GetArgumentCount!(T,N) - 1, 0, 0, 0, T, N,
|
||||||
ParameterTypeTuple!(__traits(getMember, T, N))) ~ ");}";
|
ParameterTypeTuple!(__traits(getMember, T, N))) ~ ");}";
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ class Compiler
|
|||||||
return ValueType.Integer;
|
return ValueType.Integer;
|
||||||
default:
|
default:
|
||||||
return ValueType.Double;//非DEFINT時
|
return ValueType.Double;//非DEFINT時
|
||||||
return ValueType.Integer;//DEFINT時
|
//return ValueType.Integer;//DEFINT時
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statements statements;
|
Statements statements;
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class Lexical
|
|||||||
wstring iden;
|
wstring iden;
|
||||||
for(;i < code.length;i++)
|
for(;i < code.length;i++)
|
||||||
{
|
{
|
||||||
c = cast(wchar)code[i].toUpper;;
|
c = cast(wchar)code[i].toUpper;
|
||||||
if(!c.isAlpha() && !c.isDigit() && c != '_')
|
if(!c.isAlpha() && !c.isDigit() && c != '_')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -374,7 +374,7 @@ class Parser
|
|||||||
this.code = input;
|
this.code = input;
|
||||||
lex = new Lexical(input);
|
lex = new Lexical(input);
|
||||||
}
|
}
|
||||||
const int opMax = 11;
|
const static int opMax = 11;
|
||||||
int getOPRank(TokenType type)
|
int getOPRank(TokenType type)
|
||||||
{
|
{
|
||||||
switch(type)
|
switch(type)
|
||||||
@@ -460,7 +460,6 @@ class Parser
|
|||||||
return - - -1;
|
return - - -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case NodeType.Variable:
|
case NodeType.Variable:
|
||||||
return 100;
|
return 100;
|
||||||
case NodeType.CallFunction:
|
case NodeType.CallFunction:
|
||||||
|
|||||||
@@ -10,10 +10,14 @@ import std.conv;
|
|||||||
import std.string;
|
import std.string;
|
||||||
import std.c.stdio;
|
import std.c.stdio;
|
||||||
import core.sync.mutex;
|
import core.sync.mutex;
|
||||||
import otya.smilebasic.parser;
|
|
||||||
import otya.smilebasic.sprite;
|
import otya.smilebasic.sprite;
|
||||||
import otya.smilebasic.error;
|
import otya.smilebasic.error;
|
||||||
import otya.smilebasic.bg;
|
import otya.smilebasic.bg;
|
||||||
|
import otya.smilebasic.parser;
|
||||||
|
const static rot_test_deg = 45f;
|
||||||
|
const static rot_test_x = 1f;
|
||||||
|
const static rot_test_y = 0f;
|
||||||
|
const static rot_test_z = 0f;
|
||||||
enum Button
|
enum Button
|
||||||
{
|
{
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
@@ -185,6 +189,7 @@ class PetitComputer
|
|||||||
int foreColor;
|
int foreColor;
|
||||||
int backColor;
|
int backColor;
|
||||||
byte attr;
|
byte attr;
|
||||||
|
int z;
|
||||||
}
|
}
|
||||||
SDL_Color PetitColor(ubyte r, ubyte g, ubyte b, ubyte a)
|
SDL_Color PetitColor(ubyte r, ubyte g, ubyte b, ubyte a)
|
||||||
{
|
{
|
||||||
@@ -471,6 +476,149 @@ class PetitComputer
|
|||||||
}
|
}
|
||||||
Mutex grpmutex;
|
Mutex grpmutex;
|
||||||
int displaynum;
|
int displaynum;
|
||||||
|
uint[] buffer;
|
||||||
|
static const MAXSIZE = 1024; /* バッファサイズ */
|
||||||
|
|
||||||
|
/* 画面サイズは 1024 X 1024 とする */
|
||||||
|
static const MINX = 0;
|
||||||
|
static const MINY = 0;
|
||||||
|
static const MAXX = 511;
|
||||||
|
static const MAXY = 511;
|
||||||
|
|
||||||
|
struct BufStr {
|
||||||
|
int lx; /* 領域右端のX座標 */
|
||||||
|
int rx; /* 領域右端のX座標 */
|
||||||
|
int y; /* 領域のY座標 */
|
||||||
|
int oy; /* 親ラインのY座標 */
|
||||||
|
};
|
||||||
|
BufStr buff[MAXSIZE]; /* シード登録用バッファ */
|
||||||
|
BufStr* sIdx, eIdx; /* buffの先頭・末尾ポインタ */
|
||||||
|
uint point(int x, int y)
|
||||||
|
{
|
||||||
|
return buffer.ptr[x + y * 512];
|
||||||
|
}
|
||||||
|
void pset(int x, int y, uint col)
|
||||||
|
{
|
||||||
|
buffer.ptr[x + y * 512] = col;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
scanLine : 線分からシードを探索してバッファに登録する
|
||||||
|
|
||||||
|
int lx, rx : 線分のX座標の範囲
|
||||||
|
int y : 線分のY座標
|
||||||
|
int oy : 親ラインのY座標
|
||||||
|
unsigned int col : 領域色
|
||||||
|
*/
|
||||||
|
void scanLine( int lx, int rx, int y, int oy, uint col )
|
||||||
|
{
|
||||||
|
while ( lx <= rx ) {
|
||||||
|
|
||||||
|
/* 非領域色を飛ばす */
|
||||||
|
for ( ; lx < rx ; lx++ )
|
||||||
|
if ( point( lx, y ) == col ) break;
|
||||||
|
if ( point( lx, y ) != col ) break;
|
||||||
|
|
||||||
|
eIdx.lx = lx;
|
||||||
|
|
||||||
|
/* 領域色を飛ばす */
|
||||||
|
for ( ; lx <= rx ; lx++ )
|
||||||
|
if ( point( lx, y ) != col ) break;
|
||||||
|
|
||||||
|
eIdx.rx = lx - 1;
|
||||||
|
eIdx.y = y;
|
||||||
|
eIdx.oy = oy;
|
||||||
|
|
||||||
|
if ( ++eIdx == &buff.ptr[MAXSIZE] )
|
||||||
|
eIdx = buff.ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
paint : 塗り潰し処理(高速版)
|
||||||
|
|
||||||
|
int x, y : 開始座標
|
||||||
|
unsigned int paintCol : 塗り潰す時の色(描画色)
|
||||||
|
*/
|
||||||
|
void paint( int x, int y, uint paintCol , out int dx, out int dy, out int dx2, out int dy2)
|
||||||
|
{
|
||||||
|
int lx, rx; /* 塗り潰す線分の両端のX座標 */
|
||||||
|
int ly; /* 塗り潰す線分のY座標 */
|
||||||
|
int oy; /* 親ラインのY座標 */
|
||||||
|
int i;
|
||||||
|
uint col = point( x, y ); /* 閉領域の色(領域色) */
|
||||||
|
dx = int.max, dy = int.max, dx2 = int.min, dy2 = int.min;
|
||||||
|
if ( col == paintCol ) return; /* 領域色と描画色が等しければ処理不要 */
|
||||||
|
sIdx = buff.ptr;
|
||||||
|
eIdx = buff.ptr + 1;
|
||||||
|
sIdx.lx = sIdx.rx = x;
|
||||||
|
sIdx.y = sIdx.oy = y;
|
||||||
|
|
||||||
|
do {
|
||||||
|
lx = sIdx.lx;
|
||||||
|
rx = sIdx.rx;
|
||||||
|
ly = sIdx.y;
|
||||||
|
oy = sIdx.oy;
|
||||||
|
|
||||||
|
int lxsav = lx - 1;
|
||||||
|
int rxsav = rx + 1;
|
||||||
|
|
||||||
|
if ( ++sIdx == &buff.ptr[MAXSIZE] ) sIdx = buff.ptr;
|
||||||
|
|
||||||
|
/* 処理済のシードなら無視 */
|
||||||
|
if ( point( lx, ly ) != col )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* 右方向の境界を探す */
|
||||||
|
while ( rx < MAXX ) {
|
||||||
|
if ( point( rx + 1, ly ) != col ) break;
|
||||||
|
rx++;
|
||||||
|
}
|
||||||
|
/* 左方向の境界を探す */
|
||||||
|
while ( lx > MINX ) {
|
||||||
|
if ( point( lx - 1, ly ) != col ) break;
|
||||||
|
lx--;
|
||||||
|
}
|
||||||
|
import std.algorithm;
|
||||||
|
dy = min(dy, ly);
|
||||||
|
dy2 = max(dy2, ly);
|
||||||
|
dx = min(dx, lx);
|
||||||
|
dx2 = max(dx2, rx);
|
||||||
|
//
|
||||||
|
/* lx-rxの線分を描画 */
|
||||||
|
for ( i = lx; i <= rx; i++ ) pset( i, ly, paintCol );
|
||||||
|
|
||||||
|
/* 真上のスキャンラインを走査する */
|
||||||
|
if ( ly - 1 >= MINY ) {
|
||||||
|
if ( ly - 1 == oy ) {
|
||||||
|
scanLine( lx, lxsav, ly - 1, ly, col );
|
||||||
|
scanLine( rxsav, rx, ly - 1, ly, col );
|
||||||
|
} else {
|
||||||
|
scanLine( lx, rx, ly - 1, ly, col );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 真下のスキャンラインを走査する */
|
||||||
|
if ( ly + 1 <= MAXY ) {
|
||||||
|
if ( ly + 1 == oy ) {
|
||||||
|
scanLine( lx, lxsav, ly + 1, ly, col );
|
||||||
|
scanLine( rxsav, rx, ly + 1, ly, col );
|
||||||
|
} else {
|
||||||
|
scanLine( lx, rx, ly + 1, ly, col );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while ( sIdx != eIdx );
|
||||||
|
}
|
||||||
|
void gpaintBuffer(uint* pixels, int x, int y, uint color, GLenum tf)
|
||||||
|
{
|
||||||
|
int dx, dy, dx2, dy2;
|
||||||
|
paint(x, y, color, dx, dy, dx2, dy2);
|
||||||
|
if(dx == int.max) return;
|
||||||
|
int h = dy2 - dy;
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D , 0, 0, dy, 512, h, tf, GL_UNSIGNED_BYTE, pixels + (dy * 512));
|
||||||
|
// glDrawPixels(512, dy2, tf, GL_UNSIGNED_BYTE, buffer.ptr);
|
||||||
|
}
|
||||||
|
int renderstartpos;
|
||||||
void renderGraphic()
|
void renderGraphic()
|
||||||
{
|
{
|
||||||
if(!drawMessageLength) return;
|
if(!drawMessageLength) return;
|
||||||
@@ -480,20 +628,23 @@ class PetitComputer
|
|||||||
drawflag = true;
|
drawflag = true;
|
||||||
//betuni kouzoutai demo sonnnani sokudo kawaranasasou
|
//betuni kouzoutai demo sonnnani sokudo kawaranasasou
|
||||||
auto len = drawMessageLength;
|
auto len = drawMessageLength;
|
||||||
drawMessageLength = 0;
|
int s = renderstartpos;
|
||||||
int s = 0;
|
|
||||||
GLint old;
|
GLint old;
|
||||||
auto a = & glBindFramebuffer;
|
auto a = & glBindFramebuffer;
|
||||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old);
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old);
|
||||||
int oldpage = drawMessageQueue[0].page;
|
int oldpage = drawMessageQueue[0].page;
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[oldpage].buffer);
|
glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[oldpage].buffer);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
//glDisable(GL_ALPHA_TEST);
|
||||||
glDisable(GL_ALPHA_TEST);
|
glDisable(GL_ALPHA_TEST);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
//
|
//
|
||||||
//glAlphaFunc(GL_GEQUAL, 0.0);
|
//glAlphaFunc(GL_GEQUAL, 0.0);
|
||||||
glViewport(0, 0, 512, 512);
|
glViewport(0, 0, 512, 512);
|
||||||
for(int i = s; i < len; i++)
|
DrawType dt;
|
||||||
|
auto start = SDL_GetTicks();
|
||||||
|
int i = s;
|
||||||
|
for(; i < len; i++)
|
||||||
{
|
{
|
||||||
DrawMessage dm = drawMessageQueue[i];
|
DrawMessage dm = drawMessageQueue[i];
|
||||||
if(oldpage != dm.page)
|
if(oldpage != dm.page)
|
||||||
@@ -545,8 +696,37 @@ class PetitComputer
|
|||||||
}
|
}
|
||||||
//draw.gbox(dm.page, dm.x, dm.y ,dm.x2, dm.y2, dm.color);
|
//draw.gbox(dm.page, dm.x, dm.y ,dm.x2, dm.y2, dm.color);
|
||||||
break;
|
break;
|
||||||
|
case DrawType.PAINT:
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, GRP[oldpage].glTexture);
|
||||||
|
if(dt != DrawType.PAINT)
|
||||||
|
{
|
||||||
|
glFinish();
|
||||||
|
//glGetTexImage(GL_TEXTURE_2D,0,GRP[oldpage].textureFormat,GL_UNSIGNED_BYTE,buffer.ptr);
|
||||||
|
glReadPixels(0, 0, 512, 512, GRP[oldpage].textureFormat, GL_UNSIGNED_BYTE, buffer.ptr);
|
||||||
|
}
|
||||||
|
gpaintBuffer(buffer.ptr, dm.x, dm.y, dm.color, GRP[oldpage].textureFormat);
|
||||||
|
//gpaintBufferExW(oldpage, dm.x, dm.y, dm.color);
|
||||||
|
if(SDL_GetTicks() - start >= 16 && i != len - 1)
|
||||||
|
{
|
||||||
|
s = i + 1;
|
||||||
|
goto brk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
dt = dm.type;
|
||||||
|
}
|
||||||
|
brk:
|
||||||
|
if(i == len)
|
||||||
|
{
|
||||||
|
renderstartpos = 0;
|
||||||
|
drawMessageLength = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
renderstartpos = s;
|
||||||
}
|
}
|
||||||
glBindFramebufferEXT(GL_FRAMEBUFFER, old);
|
glBindFramebufferEXT(GL_FRAMEBUFFER, old);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@@ -592,8 +772,10 @@ class PetitComputer
|
|||||||
return bg;
|
return bg;
|
||||||
}
|
}
|
||||||
protected BG[4] bg;
|
protected BG[4] bg;
|
||||||
|
bool quit;
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
|
buffer = new uint[512 * 512];
|
||||||
DerelictSDL2.load();
|
DerelictSDL2.load();
|
||||||
DerelictSDL2Image.load();
|
DerelictSDL2Image.load();
|
||||||
GRPF = createGRPF(fontFile);
|
GRPF = createGRPF(fontFile);
|
||||||
@@ -616,7 +798,7 @@ class PetitComputer
|
|||||||
buttonTable[SDL_SCANCODE_LEFT] = Button.LEFT;
|
buttonTable[SDL_SCANCODE_LEFT] = Button.LEFT;
|
||||||
buttonTable[SDL_SCANCODE_RIGHT] = Button.RIGHT;
|
buttonTable[SDL_SCANCODE_RIGHT] = Button.RIGHT;
|
||||||
buttonTable[SDL_SCANCODE_SPACE] = Button.A;
|
buttonTable[SDL_SCANCODE_SPACE] = Button.A;
|
||||||
bool renderprofile;// = true;
|
bool renderprofile = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
version(Windows)
|
version(Windows)
|
||||||
@@ -629,6 +811,11 @@ class PetitComputer
|
|||||||
window = SDL_CreateWindow("SMILEBASIC", SDL_WINDOWPOS_UNDEFINED,
|
window = SDL_CreateWindow("SMILEBASIC", SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_WINDOWPOS_UNDEFINED, 400, 240,
|
SDL_WINDOWPOS_UNDEFINED, 400, 240,
|
||||||
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
|
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
|
||||||
|
scope(exit)
|
||||||
|
{
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_GLContext context;
|
SDL_GLContext context;
|
||||||
@@ -662,9 +849,9 @@ class PetitComputer
|
|||||||
//glEnable(GL_ALPHA_TEST);
|
//glEnable(GL_ALPHA_TEST);
|
||||||
// sprite.spset(0, 0);
|
// sprite.spset(0, 0);
|
||||||
// sprite.spofs(0, 9, 8);
|
// sprite.spofs(0, 9, 8);
|
||||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glAlphaFunc(GL_GEQUAL, 0.1f);
|
||||||
glAlphaFunc(GL_GEQUAL, 0.5);
|
|
||||||
glEnable(GL_ALPHA_TEST);
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
auto profile = SDL_GetTicks();
|
auto profile = SDL_GetTicks();
|
||||||
@@ -690,18 +877,23 @@ class PetitComputer
|
|||||||
}
|
}
|
||||||
//描画の順位
|
//描画の順位
|
||||||
//sprite>GRP>console>BG
|
//sprite>GRP>console>BG
|
||||||
|
glDisable(GL_BLEND);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
version(test) glLoadIdentity();
|
version(test) glLoadIdentity();
|
||||||
version(test) glRotatef(45f, 1f, 0f, 0.5f);
|
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
|
||||||
if(xscreenmode == 1)
|
if(xscreenmode == 1)
|
||||||
{
|
{
|
||||||
glViewport(0, 240, 400, 240);
|
glViewport(0, 240, 400, 240);
|
||||||
}
|
}
|
||||||
sprite.render();
|
glEnable(GL_BLEND);
|
||||||
if(xscreenmode == 1)
|
if(xscreenmode == 1)
|
||||||
{
|
{
|
||||||
glViewport(0, 240, 400, 240);
|
glViewport(0, 240, 400, 240);
|
||||||
}
|
}
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
version(test) glLoadIdentity();
|
||||||
|
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
|
||||||
if(xscreenmode == 2)
|
if(xscreenmode == 2)
|
||||||
{
|
{
|
||||||
renderGraphicPage(0, 320, 480);
|
renderGraphicPage(0, 320, 480);
|
||||||
@@ -726,7 +918,7 @@ class PetitComputer
|
|||||||
glViewport(0, 240, 400, 240);
|
glViewport(0, 240, 400, 240);
|
||||||
}
|
}
|
||||||
version(test) glLoadIdentity();
|
version(test) glLoadIdentity();
|
||||||
version(test) glRotatef(45f, 1f, 0f, 0.5f);
|
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
|
||||||
glBindTexture(GL_TEXTURE_2D, GRP[bgpage].glTexture);
|
glBindTexture(GL_TEXTURE_2D, GRP[bgpage].glTexture);
|
||||||
if(xscreenmode == 2)
|
if(xscreenmode == 2)
|
||||||
{
|
{
|
||||||
@@ -752,12 +944,20 @@ class PetitComputer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
version(test) glLoadIdentity();
|
version(test) glLoadIdentity();
|
||||||
version(test) glRotatef(45f, 1f, 0f, 0.5f);
|
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
|
||||||
|
|
||||||
if(xscreenmode == 1)
|
if(xscreenmode == 1)
|
||||||
{
|
{
|
||||||
glViewport(0, 240, 400, 240);
|
glViewport(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);
|
SDL_GL_SwapWindow(window);
|
||||||
auto renderticks = (SDL_GetTicks() - profile);
|
auto renderticks = (SDL_GetTicks() - profile);
|
||||||
if(renderprofile) writeln(renderticks);
|
if(renderprofile) writeln(renderticks);
|
||||||
@@ -766,8 +966,7 @@ class PetitComputer
|
|||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
SDL_DestroyWindow(window);
|
quit = true;
|
||||||
SDL_Quit();
|
|
||||||
return;
|
return;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
{
|
{
|
||||||
@@ -806,22 +1005,9 @@ class PetitComputer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(drawMessageLength)
|
|
||||||
{
|
|
||||||
//renderGraphic;
|
|
||||||
}
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
long delay = (1000/60) - (cast(long)SDL_GetTicks() - profile);
|
long delay = (1000/60) - (cast(long)SDL_GetTicks() - profile);
|
||||||
if(delay > 0)
|
if(delay > 0)
|
||||||
SDL_Delay(cast(uint)delay);
|
SDL_Delay(cast(uint)delay);
|
||||||
break;
|
|
||||||
if(delay < 0) break;
|
|
||||||
renderGraphic();
|
|
||||||
SDL_Delay(1);
|
|
||||||
//if(delay > 0)
|
|
||||||
// SDL_Delay(cast(uint)delay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Throwable t)
|
catch(Throwable t)
|
||||||
@@ -854,8 +1040,11 @@ class PetitComputer
|
|||||||
thread.start();
|
thread.start();
|
||||||
while(!buttonTable){}
|
while(!buttonTable){}
|
||||||
auto startTicks = SDL_GetTicks();
|
auto startTicks = SDL_GetTicks();
|
||||||
//とりあえず
|
Parser parser;
|
||||||
auto parser = new Parser(
|
//デバッグ用
|
||||||
|
version(NDirectMode)
|
||||||
|
{
|
||||||
|
parser = new Parser(
|
||||||
//readText("./SYS/GAME6TALK.TXT").to!wstring
|
//readText("./SYS/GAME6TALK.TXT").to!wstring
|
||||||
//readText("./SYS/GAME4SHOOTER.TXT").to!wstring
|
//readText("./SYS/GAME4SHOOTER.TXT").to!wstring
|
||||||
//readText("./SYS/GAME2RPG.TXT").to!wstring
|
//readText("./SYS/GAME2RPG.TXT").to!wstring
|
||||||
@@ -904,6 +1093,26 @@ class PetitComputer
|
|||||||
CL=(CL+1) MOD 16 : VSYNC 1
|
CL=(CL+1) MOD 16 : VSYNC 1
|
||||||
GOTO @LOOP`*/
|
GOTO @LOOP`*/
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
auto file = input("LOAD PROGRAM:", true).to!string;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
parser = new Parser(readText(file).to!wstring);
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
writeln(t);
|
||||||
|
printConsole("can't open program \"", file, "\".\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} while(!quit);
|
||||||
|
}
|
||||||
|
if(quit) return;
|
||||||
auto vm = parser.compile();
|
auto vm = parser.compile();
|
||||||
bool running = true;
|
bool running = true;
|
||||||
vm.init(this);
|
vm.init(this);
|
||||||
@@ -915,11 +1124,12 @@ class PetitComputer
|
|||||||
//gfill(0, 78, 78, 40, 40, RGB(0, 255, 255));
|
//gfill(0, 78, 78, 40, 40, RGB(0, 255, 255));
|
||||||
//gbox(0, 78, 78, 40, 40, RGB(255, 255, 0));
|
//gbox(0, 78, 78, 40, 40, RGB(255, 255, 0));
|
||||||
int startcnt = SDL_GetTicks();
|
int startcnt = SDL_GetTicks();
|
||||||
|
float frame = 1000f / 60f;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
uint elapse;
|
uint elapse;
|
||||||
startTicks = SDL_GetTicks();
|
startTicks = SDL_GetTicks();
|
||||||
do
|
//do
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -956,14 +1166,24 @@ class PetitComputer
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elapse = SDL_GetTicks() - startTicks;
|
//elapse = SDL_GetTicks() - startTicks;
|
||||||
} while(elapse <= 1000 / 60);
|
} //while(elapse <= 1000 / 60);
|
||||||
maincnt = (SDL_GetTicks() - startcnt) / (1000 / 60);
|
if(vsyncFrame)
|
||||||
vsyncCount++;
|
{
|
||||||
if(vsyncFrame <= vsyncCount) vsyncFrame = 0;
|
SDL_Delay(cast(uint)(vsyncFrame * frame));
|
||||||
|
vsyncFrame = 0;
|
||||||
|
}
|
||||||
|
maincnt = cast(int)((SDL_GetTicks() - startcnt) / frame);
|
||||||
|
if(quit)
|
||||||
|
{
|
||||||
|
quit = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope(exit)
|
||||||
|
{
|
||||||
|
writeln("quit");
|
||||||
}
|
}
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
}
|
||||||
void clearKeyBuffer()
|
void clearKeyBuffer()
|
||||||
{
|
{
|
||||||
@@ -982,12 +1202,12 @@ class PetitComputer
|
|||||||
showCursor = true;
|
showCursor = true;
|
||||||
int oldCSRX = this.CSRX;
|
int oldCSRX = this.CSRX;
|
||||||
int oldCSRY = this.CSRY;
|
int oldCSRY = this.CSRY;
|
||||||
while(true)
|
while(!quit)
|
||||||
{
|
{
|
||||||
auto oldpos = keybufferpos;
|
auto oldpos = keybufferpos;
|
||||||
while(oldpos == keybufferpos)
|
while(oldpos == keybufferpos && !quit)
|
||||||
{
|
{
|
||||||
SDL_Delay(4);//適当 ストレスを感じないくらい
|
SDL_Delay(8);//適当 ストレスを感じないくらい
|
||||||
}
|
}
|
||||||
auto kbp = keybufferpos;
|
auto kbp = keybufferpos;
|
||||||
auto len = kbp - oldpos;
|
auto len = kbp - oldpos;
|
||||||
@@ -1088,6 +1308,7 @@ class PetitComputer
|
|||||||
BOX,
|
BOX,
|
||||||
CIRCLE,
|
CIRCLE,
|
||||||
TRI,
|
TRI,
|
||||||
|
PAINT,
|
||||||
}
|
}
|
||||||
struct DrawMessage
|
struct DrawMessage
|
||||||
{
|
{
|
||||||
@@ -1159,6 +1380,10 @@ class PetitComputer
|
|||||||
{
|
{
|
||||||
sendDrawMessage(DrawType.FILL, cast(byte)page, cast(short)x, cast(short)y, cast(short)x2, cast(short)y2, color);
|
sendDrawMessage(DrawType.FILL, cast(byte)page, cast(short)x, cast(short)y, cast(short)x2, cast(short)y2, color);
|
||||||
}
|
}
|
||||||
|
void gpaint(int page, int x, int y, uint color)
|
||||||
|
{
|
||||||
|
sendDrawMessage(DrawType.PAINT, cast(byte)page, cast(short)x, cast(short)y, color);
|
||||||
|
}
|
||||||
int gprio;
|
int gprio;
|
||||||
void renderGraphicPage(int display, float w, float h)
|
void renderGraphicPage(int display, float w, float h)
|
||||||
{
|
{
|
||||||
@@ -1261,15 +1486,16 @@ class PetitComputer
|
|||||||
{
|
{
|
||||||
auto fore = consoleColorGL[console[y][x].foreColor];
|
auto fore = consoleColorGL[console[y][x].foreColor];
|
||||||
auto rect = &fontTable[console[y][x].character];
|
auto rect = &fontTable[console[y][x].character];
|
||||||
|
float z = console[y][x].z / 1025f;
|
||||||
glColor4ubv(cast(ubyte*)&fore);
|
glColor4ubv(cast(ubyte*)&fore);
|
||||||
glTexCoord2f((rect.x) / 512f - 1 , (rect.y + 8) / 512f - 1);
|
glTexCoord2f((rect.x) / 512f - 1 , (rect.y + 8) / 512f - 1);
|
||||||
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, 0);
|
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, z);
|
||||||
glTexCoord2f((rect.x) / 512f - 1, (rect.y) / 512f - 1);
|
glTexCoord2f((rect.x) / 512f - 1, (rect.y) / 512f - 1);
|
||||||
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8) / 120f, 0);
|
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8) / 120f, z);
|
||||||
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y) / 512f - 1);
|
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y) / 512f - 1);
|
||||||
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8) / 120f, 0);
|
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8) / 120f, z);
|
||||||
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y +8) / 512f - 1);
|
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y +8) / 512f - 1);
|
||||||
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, 0);
|
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, z);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
if(xscreenmode != 1)
|
if(xscreenmode != 1)
|
||||||
@@ -1310,15 +1536,16 @@ class PetitComputer
|
|||||||
{
|
{
|
||||||
auto fore = consoleColorGL[consoleDisplay1[y][x].foreColor];
|
auto fore = consoleColorGL[consoleDisplay1[y][x].foreColor];
|
||||||
auto rect = &fontTable[consoleDisplay1[y][x].character];
|
auto rect = &fontTable[consoleDisplay1[y][x].character];
|
||||||
|
float z = consoleDisplay1[y][x].z / 1025f;
|
||||||
glColor4ubv(cast(ubyte*)&fore);
|
glColor4ubv(cast(ubyte*)&fore);
|
||||||
glTexCoord2f((rect.x) / 512f - 1 , (rect.y + 8) / 512f - 1);
|
glTexCoord2f((rect.x) / 512f - 1 , (rect.y + 8) / 512f - 1);
|
||||||
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, 0);
|
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, z);
|
||||||
glTexCoord2f((rect.x) / 512f - 1, (rect.y) / 512f - 1);
|
glTexCoord2f((rect.x) / 512f - 1, (rect.y) / 512f - 1);
|
||||||
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8) / 120f, 0);
|
glVertex3f((x * 8) / 200f - 1, 1 - (y * 8) / 120f, z);
|
||||||
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y) / 512f - 1);
|
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y) / 512f - 1);
|
||||||
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8) / 120f, 0);
|
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8) / 120f, z);
|
||||||
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y +8) / 512f - 1);
|
glTexCoord2f((rect.x + 8) / 512f - 1, (rect.y +8) / 512f - 1);
|
||||||
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, 0);
|
glVertex3f((x * 8 + 8) / 200f - 1, 1 - (y * 8 + 8) / 120f, z);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
// glFlush();
|
// glFlush();
|
||||||
@@ -1330,6 +1557,7 @@ class PetitComputer
|
|||||||
printConsoleString(i.to!wstring);
|
printConsoleString(i.to!wstring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
byte consoleAttr;
|
||||||
void printConsoleString(wstring text)
|
void printConsoleString(wstring text)
|
||||||
{
|
{
|
||||||
//consolem.lock();
|
//consolem.lock();
|
||||||
@@ -1346,6 +1574,8 @@ class PetitComputer
|
|||||||
consoleC[CSRY][CSRX].character = c;
|
consoleC[CSRY][CSRX].character = c;
|
||||||
consoleC[CSRY][CSRX].foreColor = consoleForeColor;
|
consoleC[CSRY][CSRX].foreColor = consoleForeColor;
|
||||||
consoleC[CSRY][CSRX].backColor = consoleBackColor;
|
consoleC[CSRY][CSRX].backColor = consoleBackColor;
|
||||||
|
consoleC[CSRY][CSRX].z = CSRZ;
|
||||||
|
consoleC[CSRY][CSRX].attr = consoleAttr;
|
||||||
}
|
}
|
||||||
CSRX++;
|
CSRX++;
|
||||||
if(CSRX >= consoleWidthC || c == '\n' || c == '\r')
|
if(CSRX >= consoleWidthC || c == '\n' || c == '\r')
|
||||||
@@ -1361,7 +1591,7 @@ class PetitComputer
|
|||||||
consoleC[i] = consoleC[i + 1];
|
consoleC[i] = consoleC[i + 1];
|
||||||
}
|
}
|
||||||
consoleC[consoleHeightC - 1] = tmp;
|
consoleC[consoleHeightC - 1] = tmp;
|
||||||
tmp[] = ConsoleCharacter(0, consoleForeColor, consoleBackColor);
|
tmp[] = ConsoleCharacter(0, consoleForeColor, consoleBackColor, consoleAttr, CSRZ);
|
||||||
//assert(console[0] != console[2]);
|
//assert(console[0] != console[2]);
|
||||||
CSRY = consoleHeightC - 1;
|
CSRY = consoleHeightC - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ struct SpriteData
|
|||||||
int defno;
|
int defno;
|
||||||
double x, y;
|
double x, y;
|
||||||
int homex, homey;
|
int homex, homey;
|
||||||
double z;/*!*/
|
int z;/*!*/
|
||||||
int u, v, w, h;//個々で保持してるみたい,SPSETをして後でSPDEFをしても変化しない
|
int u, v, w, h;//個々で保持してるみたい,SPSETをして後でSPDEFをしても変化しない
|
||||||
uint color;
|
uint color;
|
||||||
double[8] var;
|
double[8] var;
|
||||||
@@ -152,8 +152,10 @@ struct SpriteData
|
|||||||
double scalex;
|
double scalex;
|
||||||
double scaley;
|
double scaley;
|
||||||
double r;
|
double r;
|
||||||
this(bool flag)
|
this(int id)
|
||||||
{
|
{
|
||||||
|
this.id = id;
|
||||||
|
z = 0;
|
||||||
define = false;
|
define = false;
|
||||||
}
|
}
|
||||||
this(int id, int defno)
|
this(int id, int defno)
|
||||||
@@ -237,9 +239,22 @@ struct SpriteData
|
|||||||
this.homey = s.hy;
|
this.homey = s.hy;
|
||||||
this.attr = s.a;
|
this.attr = s.a;
|
||||||
}
|
}
|
||||||
|
double debugZ()
|
||||||
|
{
|
||||||
|
import std.stdio;
|
||||||
|
// writefln("sprite=%d, z=%f", id, z);
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
int opCmp(ref SpriteData spr)
|
||||||
|
{
|
||||||
|
import std.stdio;
|
||||||
|
writeln("WHAT!????");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class Sprite
|
class Sprite
|
||||||
{
|
{
|
||||||
|
SpriteDef[] defSPDEFTable;
|
||||||
SpriteDef[] SPDEFTable;
|
SpriteDef[] SPDEFTable;
|
||||||
SpriteData[] sprites;
|
SpriteData[] sprites;
|
||||||
PetitComputer petitcom;
|
PetitComputer petitcom;
|
||||||
@@ -248,13 +263,7 @@ class Sprite
|
|||||||
void initUVTable()
|
void initUVTable()
|
||||||
{
|
{
|
||||||
SPDEFTable = new SpriteDef[4096];
|
SPDEFTable = new SpriteDef[4096];
|
||||||
//UVTable[] = SDL_Rect(0, 0, 16, 16);//Ichigo
|
defSPDEFTable = new SpriteDef[4096];
|
||||||
for(int i = 0; i < 4096; i++)
|
|
||||||
{
|
|
||||||
SPDEFTable[i] = SpriteDef(0, 0, 16, 16, 0, 0, SpriteAttr.show);
|
|
||||||
}
|
|
||||||
SPDEFTable[4095] = SpriteDef(192, 480, 96, 32, 48, 16, SpriteAttr.show);
|
|
||||||
//UVTable[] = SDL_Rect(192, 480, 96, 32);
|
|
||||||
import std.csv;
|
import std.csv;
|
||||||
import std.typecons;//I X Y W H HX HY ATTR
|
import std.typecons;//I X Y W H HX HY ATTR
|
||||||
import std.file;
|
import std.file;
|
||||||
@@ -265,8 +274,13 @@ class Sprite
|
|||||||
auto csv = file.byLine.joiner("\n").csvReader!(Tuple!(int, "I", int, "X" ,int, "Y", int, "W", int, "H", int, "HX", int, "HY", int, "ATTR"));
|
auto csv = file.byLine.joiner("\n").csvReader!(Tuple!(int, "I", int, "X" ,int, "Y", int, "W", int, "H", int, "HX", int, "HY", int, "ATTR"));
|
||||||
foreach(record; csv)
|
foreach(record; csv)
|
||||||
{
|
{
|
||||||
SPDEFTable[record.I] = SpriteDef(record.X, record.Y, record.W, record.H, record.HX, record.HY, cast(SpriteAttr)record.ATTR);
|
defSPDEFTable[record.I] = SpriteDef(record.X, record.Y, record.W, record.H, record.HX, record.HY, cast(SpriteAttr)record.ATTR);
|
||||||
}
|
}
|
||||||
|
spdef;
|
||||||
|
}
|
||||||
|
void spdef()
|
||||||
|
{
|
||||||
|
this.SPDEFTable[] = (this.defSPDEFTable)[];
|
||||||
}
|
}
|
||||||
void spchr(int i, int d)
|
void spchr(int i, int d)
|
||||||
{
|
{
|
||||||
@@ -282,11 +296,24 @@ class Sprite
|
|||||||
this(PetitComputer petitcom)
|
this(PetitComputer petitcom)
|
||||||
{
|
{
|
||||||
sprites = new SpriteData[512];
|
sprites = new SpriteData[512];
|
||||||
sprites[] = SpriteData(false);
|
zsortedSprites = new SpriteData*[512];
|
||||||
|
for(int i = 0; i < sprites.length; i++)
|
||||||
|
{
|
||||||
|
zsortedSprites[i] = &sprites[i];
|
||||||
|
sprites[i] = SpriteData(i);
|
||||||
|
}
|
||||||
initUVTable;
|
initUVTable;
|
||||||
this.petitcom = petitcom;
|
this.petitcom = petitcom;
|
||||||
|
list = new SpriteBucket[512];
|
||||||
|
for(int i = 0; i < 512; i++)
|
||||||
|
{
|
||||||
|
list[i] = new SpriteBucket();
|
||||||
}
|
}
|
||||||
void animation(ref SpriteData sprite)
|
buckets = new SpriteBucket[1024 + 256];
|
||||||
|
listptr = list.ptr;
|
||||||
|
bucketsptr = buckets.ptr;
|
||||||
|
}
|
||||||
|
void animation(SpriteData* sprite)
|
||||||
{
|
{
|
||||||
foreach(i, ref d; sprite.anim)
|
foreach(i, ref d; sprite.anim)
|
||||||
{
|
{
|
||||||
@@ -307,7 +334,7 @@ class Sprite
|
|||||||
sprite.y = data.data.y;
|
sprite.y = data.data.y;
|
||||||
break;
|
break;
|
||||||
case SpriteAnimTarget.Z:
|
case SpriteAnimTarget.Z:
|
||||||
sprite.z = data.data.z;
|
sprite.z = cast(int)data.data.z;
|
||||||
break;
|
break;
|
||||||
case SpriteAnimTarget.UV:
|
case SpriteAnimTarget.UV:
|
||||||
sprite.u = data.data.u;
|
sprite.u = data.data.u;
|
||||||
@@ -343,7 +370,7 @@ class Sprite
|
|||||||
sprite.y = data.old.y + ((data.data.y - data.old.y) / data.frame) * frame;
|
sprite.y = data.old.y + ((data.data.y - data.old.y) / data.frame) * frame;
|
||||||
break;
|
break;
|
||||||
case SpriteAnimTarget.Z:
|
case SpriteAnimTarget.Z:
|
||||||
sprite.z = data.old.z + ((data.data.z - data.old.z) / data.frame) * frame;
|
sprite.z = cast(int)(data.old.z + ((data.data.z - data.old.z) / data.frame) * frame);
|
||||||
break;
|
break;
|
||||||
case SpriteAnimTarget.UV:
|
case SpriteAnimTarget.UV:
|
||||||
sprite.u = data.old.u + ((data.data.u - data.old.u) / data.frame) * frame;
|
sprite.u = data.old.u + ((data.data.u - data.old.u) / data.frame) * frame;
|
||||||
@@ -388,8 +415,78 @@ class Sprite
|
|||||||
}
|
}
|
||||||
bool lll;
|
bool lll;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
|
SpriteData*[] zsortedSprites;
|
||||||
|
bool zChange;
|
||||||
|
class SpriteBucket
|
||||||
|
{
|
||||||
|
SpriteData* sprite;
|
||||||
|
SpriteBucket next;
|
||||||
|
SpriteBucket last;
|
||||||
|
}
|
||||||
|
SpriteBucket[] list;
|
||||||
|
SpriteBucket[] buckets;
|
||||||
|
SpriteBucket* listptr;
|
||||||
|
SpriteBucket* bucketsptr;
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
|
//とりあえずZ更新されたら描画時にまとめてソート
|
||||||
|
//thread safe.....
|
||||||
|
if(zChange)
|
||||||
|
{
|
||||||
|
|
||||||
|
import std.range;
|
||||||
|
import std.algorithm;
|
||||||
|
zChange = false;
|
||||||
|
/*//TimSortImpl!(binaryFun!("a.z < b.z"), Range).sort(zsortedSprites, null);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sort!("a.z > b.z", SwapStrategy.stable)(zsortedSprites);
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
}//*/
|
||||||
|
//バケットソートっぽい奴
|
||||||
|
//基本的にほぼソートされてるので挿入ソートのほうが早そう
|
||||||
|
//std.algorithmソートだと例外出る
|
||||||
|
//m = 256+1024
|
||||||
|
//n = 512
|
||||||
|
import std.stdio;
|
||||||
|
//writeln("=============START==========");
|
||||||
|
//writeln("sort");
|
||||||
|
foreach(i, ref s; sprites)
|
||||||
|
{
|
||||||
|
//if(!s.define) continue;
|
||||||
|
auto zet = s.z + 256;
|
||||||
|
listptr[i].sprite = &s;
|
||||||
|
if(bucketsptr[zet])
|
||||||
|
{
|
||||||
|
//listptr[i].next = bucketsptr[zet].last;
|
||||||
|
bucketsptr[zet].last.next = listptr[i];
|
||||||
|
bucketsptr[zet].last = listptr[i];
|
||||||
|
listptr[i].next = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bucketsptr[zet] = listptr[i].last = listptr[i];
|
||||||
|
listptr[i].next = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int j;
|
||||||
|
foreach_reverse(i, b; buckets)
|
||||||
|
{
|
||||||
|
if(b)
|
||||||
|
{
|
||||||
|
while(b)
|
||||||
|
{
|
||||||
|
//writefln("z:%d, id:%d", b.sprite.z, b.sprite.id);
|
||||||
|
zsortedSprites[j] = b.sprite;
|
||||||
|
j++;
|
||||||
|
b = b.next;
|
||||||
|
}
|
||||||
|
bucketsptr[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
float disw = 200f, dish = 120f, disw2 = 400f, dish2 = 240f;
|
float disw = 200f, dish = 120f, disw2 = 400f, dish2 = 240f;
|
||||||
if(petitcom.xscreenmode == 2)
|
if(petitcom.xscreenmode == 2)
|
||||||
{
|
{
|
||||||
@@ -407,7 +504,7 @@ class Sprite
|
|||||||
// glDisable(GL_TEXTURE_2D);
|
// glDisable(GL_TEXTURE_2D);
|
||||||
version(test) glLoadIdentity();
|
version(test) glLoadIdentity();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
foreach(i,ref sprite; sprites)
|
foreach(i, sprite; zsortedSprites)
|
||||||
{
|
{
|
||||||
if(i == spmax)
|
if(i == spmax)
|
||||||
{
|
{
|
||||||
@@ -440,7 +537,7 @@ class Sprite
|
|||||||
int v = cast(int)sprite.v;
|
int v = cast(int)sprite.v;
|
||||||
int u2 = cast(int)sprite.u + sprite.w;//-1
|
int u2 = cast(int)sprite.u + sprite.w;//-1
|
||||||
int v2 = cast(int)sprite.v + sprite.h;
|
int v2 = cast(int)sprite.v + sprite.h;
|
||||||
z = sprite.z / 1025f;
|
z = (sprite.z - 1) / 1025f;//スプライトの描画順が一番上だけどスプライトは最後に描画しないといけないのでZ - 1で一番上にする
|
||||||
float flipx = cast(float)sprite.scalex, flipy = cast(float)sprite.scaley, flipx2 = x, flipy2 = y;
|
float flipx = cast(float)sprite.scalex, flipy = cast(float)sprite.scaley, flipx2 = x, flipy2 = y;
|
||||||
if(sprite.attr & SpriteAttr.hflip)
|
if(sprite.attr & SpriteAttr.hflip)
|
||||||
{
|
{
|
||||||
@@ -452,7 +549,7 @@ class Sprite
|
|||||||
flipy = -flipy;
|
flipy = -flipy;
|
||||||
flipy2 = y2 - cast(int)(sprite.homey * sprite.scaley);
|
flipy2 = y2 - cast(int)(sprite.homey * sprite.scaley);
|
||||||
}
|
}
|
||||||
version(test) glRotatef(45f, 1f, 0f, 0.5f);
|
version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z);
|
||||||
|
|
||||||
glTranslatef((flipx2) / disw - 1,
|
glTranslatef((flipx2) / disw - 1,
|
||||||
1 - ((flipy2) / dish), 0);
|
1 - ((flipy2) / dish), 0);
|
||||||
@@ -465,7 +562,7 @@ class Sprite
|
|||||||
glRotatef(360 - sprite.r, 0.0f, 0.0f, 1.0f );
|
glRotatef(360 - sprite.r, 0.0f, 0.0f, 1.0f );
|
||||||
glScalef(flipx * aspect, flipy, 1f);
|
glScalef(flipx * aspect, flipy, 1f);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glColor4ubv(cast(ubyte*)&sprite.color);
|
||||||
if((sprite.attr& 0b111) == SpriteAttr.show)
|
if((sprite.attr& 0b111) == SpriteAttr.show)
|
||||||
{
|
{
|
||||||
glTexCoord2f(u / 512f - 1, v / 512f - 1);
|
glTexCoord2f(u / 512f - 1, v / 512f - 1);
|
||||||
@@ -567,6 +664,7 @@ class Sprite
|
|||||||
sprites[id].x = x;
|
sprites[id].x = x;
|
||||||
sprites[id].y = y;
|
sprites[id].y = y;
|
||||||
sprites[id].z = z;
|
sprites[id].z = z;
|
||||||
|
zChange = true;
|
||||||
}
|
}
|
||||||
void sphide(int id)
|
void sphide(int id)
|
||||||
{
|
{
|
||||||
@@ -659,4 +757,9 @@ class Sprite
|
|||||||
i = spid(i);
|
i = spid(i);
|
||||||
sprites[i].r = rot;
|
sprites[i].r = rot;
|
||||||
}
|
}
|
||||||
|
void spcolor(int id, uint color)
|
||||||
|
{
|
||||||
|
id = spid(id);
|
||||||
|
sprites[id].color = petitcom.toGLColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,62 @@ struct Value
|
|||||||
return "default";
|
return "default";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@property int length()
|
||||||
|
{
|
||||||
|
switch(this.type)
|
||||||
|
{
|
||||||
|
case ValueType.String:
|
||||||
|
return cast(int)stringValue.length;
|
||||||
|
case ValueType.IntegerArray:
|
||||||
|
return cast(int)integerArray.length;
|
||||||
|
case ValueType.DoubleArray:
|
||||||
|
return cast(int)doubleArray.length;
|
||||||
|
case ValueType.StringArray:
|
||||||
|
return cast(int)stringArray.length;
|
||||||
|
default:
|
||||||
|
throw new TypeMismatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void opIndexAssign(Value v, int i)
|
||||||
|
{
|
||||||
|
switch(this.type)
|
||||||
|
{
|
||||||
|
//とりあえず破壊的に書き換えた
|
||||||
|
//どのみちこれだと文字数を増やすことができないのでArray!wcharで管理させたい
|
||||||
|
case ValueType.String:
|
||||||
|
(cast(wchar[])stringValue)[i] = v.castString[0];
|
||||||
|
break;
|
||||||
|
case ValueType.IntegerArray:
|
||||||
|
integerArray.array[i] = v.castInteger;
|
||||||
|
break;
|
||||||
|
case ValueType.DoubleArray:
|
||||||
|
doubleArray.array[i] = v.castDouble;
|
||||||
|
break;
|
||||||
|
case ValueType.StringArray:
|
||||||
|
stringArray.array[i] = v.castString;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new TypeMismatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Value opIndex(int i)
|
||||||
|
{
|
||||||
|
switch(this.type)
|
||||||
|
{
|
||||||
|
//とりあえず破壊的に書き換えた
|
||||||
|
//どのみちこれだと文字数を増やすことができないのでArray!wcharで管理させたい
|
||||||
|
case ValueType.String:
|
||||||
|
return Value(stringValue[i]);
|
||||||
|
case ValueType.IntegerArray:
|
||||||
|
return Value(integerArray.array[i]);
|
||||||
|
case ValueType.DoubleArray:
|
||||||
|
return Value(doubleArray.array[i]);
|
||||||
|
case ValueType.StringArray:
|
||||||
|
return Value(stringArray.array[i]);
|
||||||
|
default:
|
||||||
|
throw new TypeMismatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class Array(T)
|
class Array(T)
|
||||||
{
|
{
|
||||||
@@ -138,6 +194,10 @@ class Array(T)
|
|||||||
}
|
}
|
||||||
dimCount = 1;
|
dimCount = 1;
|
||||||
}
|
}
|
||||||
|
@property size_t length()
|
||||||
|
{
|
||||||
|
return array.length;
|
||||||
|
}
|
||||||
this(int[] dim)
|
this(int[] dim)
|
||||||
{
|
{
|
||||||
int len = 1;
|
int len = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user