modules: Move SACT/sactcg.c to lib/ and use it from NIGHTDLL

This commit is contained in:
kichikuou
2026-03-17 11:09:47 +09:00
parent 4a5cd4a1c1
commit a726d577ef
13 changed files with 67 additions and 269 deletions
+1 -2
View File
@@ -15,7 +15,6 @@ add_library(modules STATIC
MsgSkip/MsgSkip.c
NIGHTDLL/NIGHTDLL.c
NIGHTDLL/nt_scenario.c
NIGHTDLL/sactcg.c
NIGHTDLL/sactstring.c
NIGHTDLL/sprite.c
NIGHTDLL/sprite_draw.c
@@ -30,7 +29,6 @@ add_library(modules STATIC
RandMT/RandMT.c
S3xMusic/S3xMusic.c
SACT/SACT.c
SACT/sactcg.c
SACT/sactsound.c
SACT/sacttimer.c
SACT/sactstring.c
@@ -68,6 +66,7 @@ add_library(modules STATIC
lib/drawtext.c
lib/list.c
lib/graph_blend_amap.c
lib/sactcg.c
nDEMO/nDEMO.c
nDEMOE/nDEMOE.c
oDEMO/oDEMO.c
+1 -1
View File
@@ -46,7 +46,7 @@ static void NIGHTDLL_reset(void) {
if (night.sp[i])
nt_sp_free(night.sp[i]);
}
nt_scg_freeall();
scg_freeall();
memset(&night, 0, sizeof(night));
}
-4
View File
@@ -37,10 +37,6 @@ struct _night {
int waitskiplv;
int waitkey;
// graph
// cginfo_t *cg[CGMAX];
SDL_Rect updaterect;
FontType fonttype;
+3 -3
View File
@@ -82,7 +82,7 @@ void ntmsg_init() {
nt_sp_add_updatelist(sp);
// 文字背景CG作成
nt_scg_create(CGNO_MSGFR_BG,
scg_create(CGNO_MSGFR_BG,
main_surface->w, main_surface->h,
0, 0, 0, 255);
// night.cg[CGNO_MSGFR_BG]->refcnt++;
@@ -92,9 +92,9 @@ void ntmsg_init() {
nt_sp_add_updatelist(sp);
// キー入力アニメーションCG作成
nt_scg_cut(CGNO_MSGHAK_1, CGNO_MSGHAK_LCG, 0, 0, 9, 9);
scg_cut(CGNO_MSGHAK_1, CGNO_MSGHAK_LCG, 0, 0, 9, 9);
//night.cg[CGNO_MSGHAK_1]->refcnt++;
nt_scg_cut(CGNO_MSGHAK_2, CGNO_MSGHAK_LCG, 0, 9, 9, 9);
scg_cut(CGNO_MSGHAK_2, CGNO_MSGHAK_LCG, 0, 9, 9, 9);
//night.cg[CGNO_MSGHAK_2]->refcnt++;
sp = night.sp[SPNO_MSG_KEYANIM] = nt_sp_new(SPNO_MSG_KEYANIM, CGNO_MSGHAK_1, CGNO_MSGHAK_2, 0, SPRITE_ANIME);
sp->u.anime.interval = HAKANIM_INTERVAL;
-146
View File
@@ -1,146 +0,0 @@
/*
* sactcg.c: CG作成
*
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: sactcg.c,v 1.2 2003/11/16 15:29:52 chikama Exp $ */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL.h>
#include "portab.h"
#include "nact.h"
#include "system.h"
#include "ags.h"
#include "cg.h"
#include "sactcg.h"
#define CGMAX 65536
static cginfo_t *cgs[CGMAX];
#define SPCG_ASSERT_NO(no) \
if ((no) > (CGMAX -1)) { \
WARNING("no is too large (should be %d < %d)", (no), CGMAX); \
return; \
} \
static cginfo_t *nt_scg_new(enum cgtype type, int no, SDL_Surface *sf) {
cginfo_t *info = calloc(1, sizeof(cginfo_t));
info->type = type;
info->no = no;
info->sf = sf;
info->refcnt = 1;
nt_scg_free(no);
cgs[no] = info;
return info;
}
/*
cgの読み込み
指定の番号のCGをリンクファイルから読み込んだり、
CG_xxxで作成したCGを参照する
@param no: 読み込むCG番号
*/
static cginfo_t *nt_scg_get(int no) {
if (no >= (CGMAX -1)) {
WARNING("no is too large (should be %d < %d)", (no), CGMAX);
return NULL;
}
if (cgs[no] != NULL)
return cgs[no];
SDL_Surface *sf = cg_load_as_sdlsurface(no - 1);
if (!sf) {
WARNING("load fail (%d)", no -1);
return NULL;
}
return nt_scg_new(CG_LINKED, no, sf);
}
cginfo_t *nt_scg_addref(int no) {
cginfo_t *info = nt_scg_get(no);
if (info)
info->refcnt++;
return info;
}
void nt_scg_deref(cginfo_t *cg) {
if (--cg->refcnt > 0)
return;
if (cg->sf)
SDL_FreeSurface(cg->sf);
free(cg);
}
// 指定の大きさ、色の矩形の CG を作成
void nt_scg_create(int wNumCG, int wWidth, int wHeight, int wR, int wG, int wB, int wBlendRate) {
SPCG_ASSERT_NO(wNumCG);
SDL_Surface *sf = SDL_CreateRGBSurfaceWithFormat(0, wWidth, wHeight, 32, SDL_PIXELFORMAT_ARGB8888);
SDL_FillRect(sf, NULL, SDL_MapRGBA(sf->format, wR, wG, wB, wBlendRate));
nt_scg_new(CG_SET, wNumCG, sf);
}
// CGの一部を切りぬいたCGを作成
void nt_scg_cut(int wNumDstCG, int wNumSrcCG, int wX, int wY, int wWidth, int wHeight) {
SPCG_ASSERT_NO(wNumDstCG);
SPCG_ASSERT_NO(wNumSrcCG);
cginfo_t *src = nt_scg_get(wNumSrcCG);
if (!src)
return;
SDL_Surface *sf = SDL_CreateRGBSurfaceWithFormat(0, wWidth, wHeight, src->sf->format->BitsPerPixel, src->sf->format->format);
SDL_BlitSurface(src->sf, &(SDL_Rect){wX, wY, wWidth, wHeight}, sf, NULL);
nt_scg_new(CG_SET, wNumDstCG, sf);
}
// 全てのCGの開放
void nt_scg_freeall(void) {
int i;
for (i = 1; i < CGMAX; i++) {
nt_scg_free(i);
}
}
/**
* 指定の番号の CG をオブジェクトリストから消し、オブジェクトがどこからも参照
* されていない(参照数が0の)場合のみ、オブジェクトを削除
*/
void nt_scg_free(int no) {
SPCG_ASSERT_NO(no);
cginfo_t *cg = cgs[no];
if (!cg) return;
nt_scg_deref(cg);
cgs[no] = NULL;
}
-37
View File
@@ -1,37 +0,0 @@
/*
* sactcg.h: CG作成
*
* Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
* 1998- <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: sactcg.h,v 1.2 2003/11/16 15:29:52 chikama Exp $ */
#ifndef __SACTCG_H__
#define __SACTCG_H__
#include "portab.h"
#include "night.h"
cginfo_t *nt_scg_addref(int no);
void nt_scg_deref(cginfo_t *cg);
void nt_scg_create(int wNumCG, int wWidth, int wHeight, int wR, int wG, int wB, int wBlendRate);
void nt_scg_cut(int wNumDstCG, int wNumSrcCG, int wX, int wY, int wWidth, int wHeight);
void nt_scg_freeall(void);
void nt_scg_free(int cg);
#endif
+8 -8
View File
@@ -16,9 +16,9 @@ sprite_t *nt_sp_new(int no, int cg1, int cg2, int cg3, int type) {
sp->no = no;
sp->type = type;
sp->cg1 = cg1 ? nt_scg_addref(cg1) : NULL;
sp->cg2 = cg2 ? nt_scg_addref(cg2) : NULL;
sp->cg3 = cg3 ? nt_scg_addref(cg3) : NULL;
sp->cg1 = cg1 ? scg_addref(cg1) : NULL;
sp->cg2 = cg2 ? scg_addref(cg2) : NULL;
sp->cg3 = cg3 ? scg_addref(cg3) : NULL;
sp->curcg = sp->cg1;
sp->show = true;
@@ -71,9 +71,9 @@ sprite_t *nt_sp_msg_new(int no, int x, int y, int width, int height) {
void nt_sp_free(sprite_t *sp) {
if (sp == NULL) return;
if (sp->cg1) nt_scg_deref(sp->cg1);
if (sp->cg2) nt_scg_deref(sp->cg2);
if (sp->cg3) nt_scg_deref(sp->cg3);
if (sp->cg1) scg_deref(sp->cg1);
if (sp->cg2) scg_deref(sp->cg2);
if (sp->cg3) scg_deref(sp->cg3);
if (sp->type == SPRITE_MSG) {
SDL_FreeSurface(sp->u.msg.canvas);
@@ -102,9 +102,9 @@ void nt_sp_set_cg(sprite_t *sp, int no) {
if (sp == NULL) return;
if (sp->curcg)
nt_scg_deref(sp->curcg);
scg_deref(sp->curcg);
cg = no ? nt_scg_addref(no) : NULL;
cg = no ? scg_addref(no) : NULL;
if (cg == NULL) {
sp->width = 0;
+1 -20
View File
@@ -4,6 +4,7 @@
#include "portab.h"
#include <SDL_rect.h>
#include "sactcg.h"
#define DEFAULT_UPDATE nt_sp_draw
@@ -21,7 +22,6 @@
#define SPNO_MSG_KEYANIM 12 // メッセージキー入力アニメーション
#define SPNO_MSG_ICON_MUTE 13 // メッセージウィンドアイコン
#define CGMAX 65536
// 0-9999: reserve for Link CG
// 2051: メッセージウィンド枠CG
#define CGNO_MSGFRAME_LCG 2051
@@ -40,25 +40,6 @@
#define CGNO_MSGFR_BG 10002
// CG_XX で作るCGの種類
enum cgtype {
CG_NOTUSED = 0,
CG_LINKED = 1,
CG_SET = 2,
CG_REVERSE = 3,
CG_STRETCH = 4
};
// cgに関する情報
struct _cginfo {
enum cgtype type; // CGの種類, 0: 未使用, 1:リンクされている, ...
int no; // CGの番号
struct SDL_Surface *sf;
int refcnt; // 参照カウンタ。0になったら開放してもよい。
};
typedef struct _cginfo cginfo_t;
enum spritetype {
SPRITE_NORMAL = 0,
SPRITE_ANIME = 5,
+2 -25
View File
@@ -30,14 +30,11 @@
#include "list.h"
#include "ags.h"
#include "sacttimer.h"
#include "variable.h"
#include "sactcg.h"
// スプライトの最大数
#define SPRITEMAX 21845
// CGの最大数
#define CGMAX 63336
// メッセージの最大長さ
#define MSGBUFMAX 257*10
@@ -59,24 +56,6 @@ typedef struct {
char *dst; // 置き換え文字列
} strexchange_t;
// CG_XX で作るCGの種類
enum cgtype {
CG_NOTUSED = 0,
CG_LINKED = 1,
CG_SET = 2,
CG_REVERSE = 3,
CG_STRETCH = 4
};
// cgに関する情報
struct _cginfo {
enum cgtype type; // CGの種類, 0: 未使用, 1:リンクされている, ...
int no; // CGの番号
struct SDL_Surface *sf;
int refcnt; // 参照カウンタ。0になったら開放してもよい。
};
typedef struct _cginfo cginfo_t;
// スプライトのタイプ
enum spritetype {
SPRITE_NORMAL = 0,
@@ -209,9 +188,7 @@ struct _sact {
SList *sp_quake; // Quakeで揺らすスプライトのリスト
SList *updatelist; // 再描画するスプライトのリスト
cginfo_t *cg[CGMAX]; // cgまたはCG_xxで作った CG
// 座標系の原点
SDL_Point origin;
+1
View File
@@ -31,6 +31,7 @@
#include "system.h"
#include "ags.h"
#include "nact.h"
#include "variable.h"
#include "input.h"
#include "sact.h"
#include "sprite.h"
+1
View File
@@ -30,6 +30,7 @@
#include "portab.h"
#include "nact.h"
#include "variable.h"
#include "ags.h"
#include "input.h"
#include "sact.h"
+34 -22
View File
@@ -33,26 +33,35 @@
#include "nact.h"
#include "system.h"
#include "ags.h"
#include "sact.h"
#include "variable.h"
#include "sactcg.h"
#include "cg.h"
#include "gfx.h"
#define CGMAX 65536
static cginfo_t **cg_store;
#define SPCG_ASSERT_NO(no) \
if ((no) > (CGMAX -1)) { \
WARNING("no is too large (should be %d < %d)", (no), CGMAX); \
return; \
} \
static cginfo_t *scg_new(enum cgtype type, int no, SDL_Surface *sf) {
static void scg_ensure_store(void) {
if (!cg_store)
cg_store = calloc(CGMAX, sizeof(cginfo_t *));
}
static cginfo_t *scg_new(enum sactcg_type type, int no, SDL_Surface *sf) {
cginfo_t *info = calloc(1, sizeof(cginfo_t));
info->type = type;
info->no = no;
info->sf = sf;
info->refcnt = 1;
scg_ensure_store();
scg_free(no);
sact.cg[no] = info;
cg_store[no] = info;
return info;
}
@@ -71,8 +80,8 @@ static cginfo_t *scg_get(int no) {
return NULL;
}
if (sact.cg[no] != NULL)
return sact.cg[no];
if (cg_store && cg_store[no])
return cg_store[no];
SDL_Surface *sf = cg_load_as_sdlsurface(no - 1);
if (!sf) {
@@ -292,11 +301,13 @@ void scg_partcopy(int wNumDstCG, int wNumSrcCG, int wX, int wY, int wWidth, int
// 全てのCGの開放
void scg_freeall(void) {
int i;
for (i = 1; i < CGMAX; i++) {
if (!cg_store)
return;
for (int i = 1; i < CGMAX; i++) {
scg_free(i);
}
free(cg_store);
cg_store = NULL;
}
/**
@@ -306,28 +317,29 @@ void scg_freeall(void) {
void scg_free(int no) {
SPCG_ASSERT_NO(no);
cginfo_t *cg = sact.cg[no];
if (!cg_store) return;
cginfo_t *cg = cg_store[no];
if (!cg) return;
scg_deref(cg);
sact.cg[no] = NULL;
cg_store[no] = NULL;
}
// CGの種類を取得
int scg_querytype(int wNumCG) {
if (wNumCG >= (CGMAX -1)) return CG_NOTUSED;
if (sact.cg[wNumCG] == NULL) return CG_NOTUSED;
return sact.cg[wNumCG]->type;
if (!cg_store || !cg_store[wNumCG]) return CG_NOTUSED;
return cg_store[wNumCG]->type;
}
// CGの大きさを取得
bool scg_querysize(int wNumCG, int *w, int *h) {
if (wNumCG >= (CGMAX -1)) goto errexit;
if (sact.cg[wNumCG] == NULL) goto errexit;
if (sact.cg[wNumCG]->sf == NULL) goto errexit;
if (!cg_store || !cg_store[wNumCG]) goto errexit;
if (cg_store[wNumCG]->sf == NULL) goto errexit;
*w = sact.cg[wNumCG]->sf->w;
*h = sact.cg[wNumCG]->sf->h;
*w = cg_store[wNumCG]->sf->w;
*h = cg_store[wNumCG]->sf->h;
return true;
@@ -339,15 +351,15 @@ bool scg_querysize(int wNumCG, int *w, int *h) {
// CGのBPPを取得
int scg_querybpp(int wNumCG) {
if (wNumCG >= (CGMAX -1)) return 0;
if (sact.cg[wNumCG] == NULL) return 0;
if (sact.cg[wNumCG]->sf == NULL) return 0;
return sact.cg[wNumCG]->sf->format->BitsPerPixel;
if (!cg_store || !cg_store[wNumCG]) return 0;
if (cg_store[wNumCG]->sf == NULL) return 0;
return cg_store[wNumCG]->sf->format->BitsPerPixel;
}
// CGの alphamap が存在するかを取得
bool scg_existalphamap(int wNumCG) {
if (wNumCG >= (CGMAX -1)) return false;
if (sact.cg[wNumCG] == NULL) return false;
if (sact.cg[wNumCG]->sf == NULL) return false;
return SDL_ISPIXELFORMAT_ALPHA(sact.cg[wNumCG]->sf->format->format);
if (!cg_store || !cg_store[wNumCG]) return false;
if (cg_store[wNumCG]->sf == NULL) return false;
return SDL_ISPIXELFORMAT_ALPHA(cg_store[wNumCG]->sf->format->format);
}
+15 -1
View File
@@ -25,7 +25,21 @@
#define __SACTCG_H__
#include "portab.h"
#include "sact.h"
enum sactcg_type {
CG_NOTUSED = 0,
CG_LINKED = 1,
CG_SET = 2,
CG_REVERSE = 3,
CG_STRETCH = 4
};
typedef struct {
enum sactcg_type type;
int no;
struct SDL_Surface *sf;
int refcnt;
} cginfo_t;
cginfo_t *scg_addref(int no);
void scg_deref(cginfo_t *cg);