Skip to content

Commit e6267e9

Browse files
committed
[Ending] Remove the extra font system
I usually try to keep code that was originally merely commented out, but this one not only contains a Win32 memory allocation, it also will be hard to port to non-DirectDraw renderers. I already "preserved" this one in the form of a video on the ReC98 blog as well. Completes P0251, funded by Ember2528.
1 parent 443752a commit e6267e9

File tree

8 files changed

+284
-218
lines changed

8 files changed

+284
-218
lines changed

GIAN07/ENDING.CPP

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ typedef struct tagEndingStTask{
2727
DWORD fadein; // フェードイン時刻
2828
DWORD fadeout; // フェードアウト時刻
2929

30-
DWORD NumStf; // 全スタッフ数
3130
DWORD StfID[10]; // スタッフID
3231
DWORD TitleID; // タイトル、すなわち役職ID
3332

33+
short NumStf; // 全スタッフ数
3434
short alpha; // パレットの状態
3535

3636
int ox, oy; // 表示基準座標
@@ -52,9 +52,25 @@ EndingGrpInfo EGrpInfo;
5252
EndingStTask EStfTask;
5353
EndingText EText;
5454

55-
// フォント情報格納用ね //
56-
ExtraFontInfo *pFontInfo[7];
57-
ExtraFontInfo *pMember[7];
55+
const PIXEL_LTRB StaffLabel[7] = {
56+
{ 0, 0, 160, 24 },
57+
{ 0, 24, 104, 48 },
58+
{ 0, 48, 160, 72 },
59+
{ 0, 72, 232, 96 },
60+
{ 0, 96, 168, 120 },
61+
{ 0, 144, 104, 168 },
62+
{ 0, (480 - 32), (9 * 32), 480 },
63+
};
64+
65+
const PIXEL_LTRB StaffMember[7] = {
66+
{ 0, 168, 72, 192 },
67+
{ 96, 168, 168, 192 },
68+
{ 192, 168, 264, 192 },
69+
{ 288, 168, 360, 192 },
70+
{ 0, 192, 144, 216 },
71+
{ 168, 192, 320, 216 },
72+
{ 0, 216, 336, 264 }
73+
};
5874

5975
// フラッシュの状態 //
6076
DWORD FlashState = 0;
@@ -68,8 +84,6 @@ void DrawStfInfo(); // スタッフの描画
6884

6985
void DrawFadeInfo(); // フェードIO情報の反映
7086

71-
void EndingCleanup(); // おしまい処理
72-
7387
void EndingSCLDecode(); // エンディング用 SCL のデコード
7488

7589

@@ -87,20 +101,6 @@ bool EndingInit(void)
87101
{
88102
PALETTE pal;
89103

90-
PIXEL_LTRB src[7] = {
91-
{0, 0,160, 24}, {0, 24,104, 48}, {0, 48,160, 72},
92-
{0,72,232, 96}, {0, 96,168,120}, {0,144,104,168},
93-
{0, 480-32, 9*32, 480},
94-
};
95-
96-
PIXEL_LTRB src2[7] = {
97-
{0, 168, 72, 192}, {96, 168, 168, 192}, {192, 168, 264, 192}, {288, 168, 360, 192},
98-
{0, 192, 144, 216}, {168, 192, 320, 216},
99-
{0, 216, 336, 264}
100-
};
101-
102-
int i;
103-
104104
GrpSetClip(0, 0, 640, 480);
105105
GrpCls();
106106
GrpFlip();
@@ -128,42 +128,16 @@ bool EndingInit(void)
128128
EText.Rect = TextObj.Register({ 640, 131 });
129129
EText.Rerender = true;
130130

131-
for(i=0; i<7; i++){
132-
pFontInfo[i] = CreateExtraFont(GrEndingCredits, &src[i]);
133-
if(pFontInfo[i] == NULL) return FALSE;
134-
}
135-
136-
for(i=0; i<7; i++){
137-
pMember[i] = CreateExtraFont(GrEndingCredits, &src2[i]);
138-
if(pMember[i] == NULL) return FALSE;
139-
}
140-
141131
return TRUE;
142132
}
143133

144134

145-
// おしまい処理 //
146-
void EndingCleanup()
147-
{
148-
int i;
149-
150-
for(i=0; i<7; i++){
151-
DeleteExtraFont(pFontInfo[i]);
152-
}
153-
154-
for(i=0; i<7; i++){
155-
DeleteExtraFont(pMember[i]);
156-
}
157-
}
158-
159-
160135
// エンディング状態推移用プロシージャ //
161136
void EndingProc(void)
162137
{/*
163138
Key_Read();
164139
165140
if(Key_Data){
166-
EndingCleanup();
167141
GameExit();
168142
return;
169143
}
@@ -274,16 +248,18 @@ void DrawGrpInfo()
274248
// スタッフの描画 //
275249
void DrawStfInfo()
276250
{
277-
int i;
278-
279251
if(!EStfTask.bWantDisp) return;
280252

281-
DrawExtraFont(pFontInfo[EStfTask.TitleID],
282-
EStfTask.ox, EStfTask.oy, 0);//255-EStfTask.alpha);
253+
// [src] is copied! For now.
254+
auto Blit = [](WINDOW_POINT dst, PIXEL_LTRB src) {
255+
dst -= (src.Size() / 2);
256+
GrpBlt(&src, dst.x, dst.y, GrEndingCredits);
257+
};
283258

284-
for(i=0; i<EStfTask.NumStf; i++){
285-
DrawExtraFont(pMember[EStfTask.StfID[i]],
286-
EStfTask.ox, EStfTask.oy+i*30+50, 0);//255-EStfTask.alpha);
259+
Blit({ EStfTask.ox, EStfTask.oy }, StaffLabel[EStfTask.TitleID]);
260+
for(decltype(EStfTask.NumStf) i = 0; i < EStfTask.NumStf; i++){
261+
const WINDOW_POINT dst = { EStfTask.ox, (EStfTask.oy + (i * 30) + 50) };
262+
Blit(dst, StaffMember[EStfTask.StfID[i]]);
287263
}
288264
}
289265

@@ -487,7 +463,6 @@ void EndingSCLDecode()
487463
break;
488464

489465
case(SCL_END): // カウントも変更させずにリターンするのだ
490-
EndingCleanup();
491466
EGrpInfo.bWantDisp = FALSE;
492467
EStfTask.bWantDisp = FALSE;
493468
NameRegistInit(FALSE);

GIAN07/FONTUTY.CPP

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55

66
#include "FONTUTY.H"
77
#include "LOADER.H"
8-
#include "game/coords.h"
98
#include "DirectXUTYs/DD_UTY.H"
10-
#include "DirectXUTYs/UT_MATH.H"
119
#include <ddraw.h>
1210

13-
// ヒミツの関数 //
14-
void __FillExpoint(EXPOINT *p, int x, int y, int w, int h);
15-
1611
// Glyph selection inside the 16×16 font //
1712
std::optional<PIXEL_LTRB> Glyph16x16(char c)
1813
{
@@ -292,136 +287,3 @@ void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, std::string_view str)
292287
}
293288
});
294289
}
295-
296-
297-
// フォント生成 //
298-
ExtraFontInfo *CreateExtraFont(SURFACE_DDRAW& Surface, PIXEL_LTRB *pSrc)
299-
{
300-
ExtraFontInfo *pInfo;
301-
int MaxSize;
302-
DWORD Width, Height;
303-
void *Target;
304-
305-
DDSURFACEDESC ddsd;
306-
307-
// 俺様メモリの確保ぉ //
308-
pInfo = (ExtraFontInfo *)LocalAlloc(LPTR, sizeof(ExtraFontInfo));
309-
if(pInfo == NULL) return NULL;
310-
311-
// 幅と高さを代入しましょう //
312-
pInfo->Width = Width = (pSrc->right) - (pSrc->left);
313-
pInfo->Height = Height = (pSrc->bottom) - (pSrc->top);
314-
315-
// 画像格納に必要なサイズを求める //
316-
MaxSize = pInfo->Width * pInfo->Height * sizeof(EXPOINT);
317-
318-
pInfo->Data = (EXPOINT *)LocalAlloc(LPTR, MaxSize);
319-
if(pInfo->Data == NULL){
320-
LocalFree(pInfo);
321-
return NULL;
322-
}
323-
324-
memset(&ddsd,0,sizeof(DDSURFACEDESC));
325-
ddsd.dwSize = sizeof(ddsd);
326-
auto ddret = Surface.surf->Lock(nullptr, &ddsd, DDLOCK_WAIT, nullptr);
327-
if(ddret != DD_OK){
328-
DeleteExtraFont(pInfo);
329-
return NULL;
330-
}
331-
332-
pInfo->DataSize = 0;
333-
334-
// 透過色をセットしましょう //
335-
std::visit([&ddsd, &pInfo, &pSrc, &Width, &Height](auto pixel) {
336-
auto* pPixel = reinterpret_cast<decltype(pixel) *>(ddsd.lpSurface);
337-
const auto TransID = pPixel[0];
338-
339-
for(decltype(Height) y = 0; y < Height; y++) {
340-
for(decltype(Width) x = 0; x < Width; x++) {
341-
const auto offset = (
342-
(x+pSrc->left) + ((y+pSrc->top) * ddsd.dwWidth)
343-
);
344-
if(pPixel[offset] != TransID){
345-
pInfo->Data[pInfo->DataSize].c = pPixel[offset];
346-
__FillExpoint(&(pInfo->Data[pInfo->DataSize]), x, y, Width, Height);
347-
pInfo->DataSize++;
348-
}
349-
}
350-
}
351-
}, DxObj.PixelFormat);
352-
353-
Surface.surf->Unlock(nullptr);
354-
355-
return pInfo;
356-
}
357-
358-
359-
void __FillExpoint(EXPOINT *p, int x, int y, int w, int h)
360-
{
361-
x -= w / 2;
362-
y -= h / 2;
363-
364-
p->x = x;
365-
p->y = y;
366-
367-
p->d = atan8(x * 64, y * 64);
368-
p->l = isqrt(x * x + y * y);
369-
}
370-
371-
372-
// フォント削除 //
373-
void DeleteExtraFont(ExtraFontInfo *pFont)
374-
{
375-
if(pFont == NULL) return;
376-
377-
if(pFont->Data) LocalFree(pFont->Data);
378-
379-
LocalFree(pFont);
380-
}
381-
382-
383-
// フォント描画 //
384-
void DrawExtraFont(ExtraFontInfo *pFont, int ox, int oy, int t, int radius_max)
385-
{
386-
DDSURFACEDESC ddsd;
387-
388-
if(pFont == NULL) return;
389-
390-
391-
memset(&ddsd,0,sizeof(DDSURFACEDESC));
392-
ddsd.dwSize = sizeof(ddsd);
393-
const auto ddret = DxObj.Back->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
394-
if(ddret != DD_OK) return;
395-
396-
std::visit([&pFont, &ox, &oy, &t, &radius_max, &ddsd](auto pixel) {
397-
auto* pData = pFont->Data;
398-
auto* pPixel = reinterpret_cast<decltype(pixel) *>(ddsd.lpSurface);
399-
400-
for(decltype(pFont->DataSize) i = 0; i < pFont->DataSize; i++, pData++){
401-
int x, y;
402-
if(t){
403-
//d = pData->d + (pData->l * (sinl(t-64,128)+128)) / 64;
404-
const auto d = pData->d + (sinl(t-64, 64)+64) * (pData->l) / 32;
405-
auto l1 = (pData->l+60) * cosm(t) / 256 - 60;
406-
auto l2 = (pData->l-10) * cosm(t) / 256 + 10;
407-
408-
if(radius_max){
409-
l1 = min(radius_max, abs(l1));
410-
l2 = min(radius_max, abs(l2));
411-
}
412-
413-
x = ox + cosl(d, l1);
414-
y = oy + sinl(d, l2);
415-
}
416-
else{
417-
x = ox + pData->x;
418-
y = oy + pData->y;
419-
}
420-
if(x < 0 || x > 639 || y < 0 || y > 399) continue;
421-
422-
pPixel[x + (y * ddsd.dwWidth)] = pData->c;
423-
}
424-
}, DxObj.PixelFormat);
425-
426-
DxObj.Back->Unlock(NULL);
427-
}

GIAN07/FONTUTY.H

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,6 @@
2222

2323

2424

25-
typedef struct tagEXPOINT {
26-
int x, y; // 元座標(中心からの相対座標)
27-
int l; // 極座標における長さ
28-
BYTE d; // 極座標における角度
29-
30-
PIXELFORMAT::LARGEST c; // 色情報
31-
} EXPOINT;
32-
33-
typedef struct tagExtraFontInfo {
34-
int Width; // 元画像の幅
35-
int Height; // 元画像の高さ
36-
37-
int DataSize; // 点の数
38-
39-
EXPOINT *Data; // データ格納先
40-
} ExtraFontInfo;
41-
4225
enum class GIAN_FONT_ID : uint8_t {
4326
SMALL = 0, // フォント(小さい文字用)
4427
NORMAL = 1, // フォント(通常の文字用)
@@ -69,14 +52,5 @@ extern void GrpPutMidNum(int x, int y, int n); // MIDI 用フォントを描画
6952
// グラデーション付きフォントを描画する
7053
void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, std::string_view str);
7154

72-
ExtraFontInfo *CreateExtraFont(SURFACE_DDRAW& Surface, PIXEL_LTRB *pSrc); // フォント生成
73-
void DeleteExtraFont(ExtraFontInfo *pFont); // フォント削除
74-
75-
// Renders [pFont] to the back buffer at the given left/top position. Setting
76-
// [t] renders the [t]th frame of a double-spiral moiré animation instead; in
77-
// that case, [radius_max] can be used to restrict this animation to the given
78-
// radius in the center of [pFont], which won't render any pixels outside.
79-
void DrawExtraFont(ExtraFontInfo *pFont, int ox, int oy, int t = 0, int radius_max = 0);
80-
8155

8256
#endif

game/coords.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Coordinate systems
3+
*
4+
*/
5+
6+
#include "coords.h"
7+
8+
PIXEL_POINT& operator -=(PIXEL_POINT& self, const PIXEL_SIZE& other) {
9+
self.x -= other.w;
10+
self.y -= other.h;
11+
return self;
12+
}

game/coords.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ struct PIXEL_SIZE {
4040
return { (w - other.x), (h - other.y) };
4141
}
4242

43+
PIXEL_SIZE operator /(int divisor) const {
44+
return { (w / divisor), (h / divisor) };
45+
}
46+
4347
std::strong_ordering operator <=>(const PIXEL_SIZE& other) const = default;
4448
};
4549

50+
PIXEL_POINT& operator -=(PIXEL_POINT& self, const PIXEL_SIZE& other);
51+
4652
// Left-top-width-height rectangle in unscaled pixel space. Relative to any
4753
// origin.
4854
struct PIXEL_LTWH {

0 commit comments

Comments
 (0)