TempleOSCD_150720.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:22 +02:00
1 parent 401601816c
commit f8c05f98f4
554 files changed
+26046 -24853

No files matched your search

+57 -47
View File
@@ -1,25 +1,18 @@
#help_index "Graphics/Sprite"
#help_index "Graphics/Sprite;Sprites"
/*
$LK,"CSprite",A="MN:CSprite"$s are stored as a sequence of var
length operations with a 1-byte type leading
each operation. The types available are lsted
here, $LK,"SPT_PT",A="MN:SPT_PT"$. They are stored, one after another,
in a chunk of memory terminated by a type $LK,"SPT_END",A="MN:SPT_END"$.
length operations with a 1-byte $LK,"type",A="MN:SPT_PT"$ leading
each operation. They are stored, one after another,
in a chunk of memory terminated by a $LK,"zero",A="MN:SPT_END"$.
$LK,"Sprite3",A="MN:Sprite3"$() shows how the $LK,"CSprite",A="MN:CSprite"$ unions are used.
It's kind-of a mess using a union.
$LK,"SpriteElemSize",A="MN:SpriteElemSize"$() will return the size of a single
element, while $LK,"SpriteSize",A="MN:SpriteSize"$() will return the size
of an entire lst. Look at $LK,"sprite_elem_base_sizes",A="MN:sprite_elem_base_sizes"$.
See $LK,"SpriteElem2Code",A="MN:SpriteElem2Code"$() to infer the raw storage
format. They are stored as raw binary values
when saved to files, not text code.
of an entire list. Look at $LK,"sprite_elem_base_sizes",A="MN:sprite_elem_base_sizes"$.
See $MA-X+PU,"::/Apps/GrModels",LM="Cd(\"::/Apps/GrModels\");Dir;View;\n"$ for an example of
making CSprite by hand. Those are type
$LK,"SPT_MESH",A="MN:SPT_MESH"$, one of the most complicated.
making CSprite by hand. It uses $LK,"SPT_MESH",A="MN:SPT_MESH"$,
one of the most complicated.
*/
public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
@@ -35,8 +28,11 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
CD3I32 *p;
CGrSym old_sym;
MemCpy(&old_sym,&dc->sym,sizeof(CGrSym));
if (dc->flags & DCF_LOCATE_NEAREST) {
dc->nearest_sprite_elem_num=0;
dc->dist=dc->nearest_dist=MAX_I64;
}
while (tempg->type) {
dc->cur_sprite_elem_num=cur_sprite_elem_num++;
switch (tempg->type) {
case SPT_COLOR:
dc->color=dc->color&~(COLORROP_COLORS_MASK|ROPF_DITHER)|tempg->c.color;
@@ -48,7 +44,7 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
break;
case SPT_WIDTH:
dc->pen_width=tempg->w.width;
GrScalePenWidth(dc);
DCPenWidthScale(dc);
break;
case SPT_TRANSFORM_ON:
if (!(dc->flags&DCF_TRANSFORMATION)) {
@@ -92,13 +88,17 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
y+=tempg->p.y1;
break;
case SPT_LINE:
GrLine3(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,tempg->pp.x2+x,tempg->pp.y2+y,z);
GrLine3(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,
tempg->pp.x2+x,tempg->pp.y2+y,z);
break;
case SPT_ARROW:
GrArrow3(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,tempg->pp.x2+x,tempg->pp.y2+y,z);
GrArrow3(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,
tempg->pp.x2+x,tempg->pp.y2+y,z);
break;
case SPT_PLANAR_SYMMETRY:
if (GrSetSymmetry3(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,tempg->pp.x2+x,tempg->pp.y2+y,z,tempg->pp.x2+x,tempg->pp.y2+y,z+1))
if (DCSymmetry3Set(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,
tempg->pp.x2+x,tempg->pp.y2+y,z,
tempg->pp.x2+x,tempg->pp.y2+y,z+1))
dc->flags|=DCF_SYMMETRY;
else
dc->flags&=~DCF_SYMMETRY;
@@ -114,22 +114,25 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
Free(img);
break;
case SPT_RECT:
GrRect3(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,tempg->pp.x2-tempg->pp.x1,tempg->pp.y2-tempg->pp.y1);
GrRect3(dc,tempg->pp.x1+x,tempg->pp.y1+y,z,
tempg->pp.x2-tempg->pp.x1,tempg->pp.y2-tempg->pp.y1);
break;
case SPT_ROTATED_RECT:
x1=tempg->ppa.x1+x;
y1=tempg->ppa.y1+y;
z1=z;
GrRot(dc->r,&x1,&y1,&z1);
Mat4x4MulXYZ(dc->r,&x1,&y1,&z1);
old_r=dc->r;
dc->flags|=DCF_TRANSFORMATION;
r2=GrRotZNew(-tempg->ppa.angle);
GrSetTranslation(r2,x1,y1,z1);
GrSetRotMat(dc,GrMulMat(old_r,r2));
GrRect3(dc,0,0,0,tempg->ppa.x2-tempg->ppa.x1,tempg->ppa.y2-tempg->ppa.y1);
r2=Mat4x4IdentNew;
Mat4x4RotZ(r2,-tempg->ppa.angle);
Mat4x4TranslationEqu(r2,x1,y1,z1);
DCMat4x4Set(dc,Mat4x4MulMat4x4New(old_r,r2));
GrRect3(dc,0,0,0,
tempg->ppa.x2-tempg->ppa.x1,tempg->ppa.y2-tempg->ppa.y1);
Free(dc->r);
Free(r2);
GrSetRotMat(dc,old_r);
DCMat4x4Set(dc,old_r);
dc->flags=dc->flags&~DCF_TRANSFORMATION|old_flags;
break;
case SPT_CIRCLE:
@@ -137,11 +140,11 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
break;
case SPT_ELLIPSE:
GrEllipse3(dc,tempg->pwha.x1+x,tempg->pwha.y1+y,z,tempg->pwha.width,
tempg->pwha.height,tempg->pwha.angle);
tempg->pwha.height,tempg->pwha.angle);
break;
case SPT_POLYGON:
GrRegPoly3(dc,tempg->pwhas.x1+x,tempg->pwhas.y1+y,z,tempg->pwhas.width,
tempg->pwhas.height,tempg->pwhas.sides,tempg->pwhas.angle);
tempg->pwhas.height,tempg->pwhas.sides,tempg->pwhas.angle);
break;
case SPT_POLYLINE:
ptr=&tempg->nu.u;
@@ -202,7 +205,7 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
p->z+=z;
}
Gr3Mesh(dc,tempg->mu.vertex_cnt,&tempg->mu.u,tempg->mu.tri_cnt,
(&tempg->mu.u)(U8 *)+sizeof(CD3I32)*tempg->mu.vertex_cnt);
(&tempg->mu.u)(U8 *)+sizeof(CD3I32)*tempg->mu.vertex_cnt);
p=&tempg->mu.u;
for (i=0;i<tempg->mu.vertex_cnt;i++,p++) {
p->x-=x;
@@ -230,7 +233,7 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
p->z+=z1;
}
Gr3Mesh(dc,tempg->pmu.vertex_cnt,&tempg->pmu.u,tempg->pmu.tri_cnt,
(&tempg->pmu.u)(U8 *)+sizeof(CD3I32)*tempg->pmu.vertex_cnt);
(&tempg->pmu.u)(U8 *)+sizeof(CD3I32)*tempg->pmu.vertex_cnt);
p=&tempg->pmu.u;
for (i=0;i<tempg->pmu.vertex_cnt;i++,p++) {
p->x-=x1;
@@ -244,6 +247,11 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
}
break;
}
if (dc->flags & DCF_LOCATE_NEAREST && dc->dist<dc->nearest_dist) {
dc->nearest_dist=dc->dist;
dc->nearest_sprite_elem_num=cur_sprite_elem_num;
}
cur_sprite_elem_num++;
if (just_one) break;
tempg(U8 *)+=SpriteElemSize(tempg);
}
@@ -257,7 +265,7 @@ public U0 Sprite3(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,Bool just_one=FALSE)
public U0 Sprite3B(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems)
{//Plot a sprite into a CDC, post transform xyz translation.
I64 old_x=dc->x,old_y=dc->y,old_z=dc->z,
old_flags=dc->flags&DCF_TRANSFORMATION;
old_flags=dc->flags&DCF_TRANSFORMATION;
dc->x=x; dc->y=y; dc->z=z;
dc->flags|=DCF_TRANSFORMATION;
Sprite3(dc,0,0,0,elems);
@@ -267,14 +275,13 @@ public U0 Sprite3B(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems)
public U0 SpriteMat3B(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,I64 *m)
{//Plot rotated by matrix.
I64 *old_r=dc->r,old_m[16],
old_flags=dc->flags&DCF_TRANSFORMATION;
I64 r[16],*old_r=dc->r,old_m[16],
old_flags=dc->flags&DCF_TRANSFORMATION;
MemCpy(old_m,m,16*sizeof(I64));
dc->flags|=DCF_TRANSFORMATION;
GrAddTranslation(m,x,y,z);
dc->r=GrMulMat(old_r,m);
Mat4x4TranslationAdd(m,x,y,z);
dc->r=Mat4x4MulMat4x4Equ(r,old_r,m);
Sprite3(dc,0,0,0,elems);
Free(dc->r);
dc->r=old_r;
MemCpy(m,old_m,16*sizeof(I64));
dc->flags=dc->flags&~DCF_TRANSFORMATION|old_flags;
@@ -282,23 +289,26 @@ public U0 SpriteMat3B(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,I64 *m)
public U0 SpriteX3B(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,F64 è=0)
{//Plot rotated around X axis.
I64 *r=GrRotXNew(è);
I64 r[16];
Mat4x4IdentEqu(r);
Mat4x4RotX(r,è);
SpriteMat3B(dc,x,y,z,elems,r);
Free(r);
}
public U0 SpriteY3B(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,F64 ê=0)
{//Plot rotated around Y axis.
I64 *r=GrRotYNew(ê);
I64 r[16];
Mat4x4IdentEqu(r);
Mat4x4RotY(r,ê);
SpriteMat3B(dc,x,y,z,elems,r);
Free(r);
}
public U0 SpriteZ3B(CDC *dc=gr.dc,I64 x,I64 y,I64 z,U8 *elems,F64 é=0)
{//Plot rotated around Z axis.
I64 *r=GrRotZNew(é);
I64 r[16];
Mat4x4IdentEqu(r);
Mat4x4RotZ(r,é);
SpriteMat3B(dc,x,y,z,elems,r);
Free(r);
}
public U0 SpriteExtents(U8 *elems,I64 *min_x=NULL,I64 *max_x=NULL,
@@ -340,14 +350,14 @@ public U8 *SpriteInterpolate(U8 *elems0,U8 *elems1,F64 t)
CD3I32 *p0,*p1,*pr;
U8 *result;
CSprite *tempg0=elems0-offset(CSprite.start),
*tempg1=elems1-offset(CSprite.start),*tempgr;
*tempg1=elems1-offset(CSprite.start),*tempgr;
if (t<0.5) {
i=SpriteSize(elems0),
result=MAlloc(i);
result=MAlloc(i);
MemCpy(result,elems0,i);
} else {
i=SpriteSize(elems1),
result=MAlloc(i);
result=MAlloc(i);
MemCpy(result,elems1,i);
}
tempgr=result-offset(CSprite.start);
@@ -443,10 +453,10 @@ public U8 *SpriteInterpolate(U8 *elems0,U8 *elems1,F64 t)
return result;
}
#help_index "Graphics/Sprite;DolDoc/Output"
#help_index "Graphics/Sprite;DolDoc/Output;StdOut/DolDoc"
public CDocEntry *DocSprite(CDoc *doc=NULL,U8 *elems,U8 *fmt=NULL)
{//Put a sprite into a document. You can, optionally, supply a fmt string
//for $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$ cmd with a %d for the bin_num.
//for $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$ cmd with a %d for the bin_num.
I64 size;
U8 *st;
Bool unlock;