diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index f100457..954b168 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -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 diff --git a/modules/NIGHTDLL/NIGHTDLL.c b/modules/NIGHTDLL/NIGHTDLL.c index b7057f1..435fa7c 100644 --- a/modules/NIGHTDLL/NIGHTDLL.c +++ b/modules/NIGHTDLL/NIGHTDLL.c @@ -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)); } diff --git a/modules/NIGHTDLL/night.h b/modules/NIGHTDLL/night.h index a6b8963..6874c5c 100644 --- a/modules/NIGHTDLL/night.h +++ b/modules/NIGHTDLL/night.h @@ -37,10 +37,6 @@ struct _night { int waitskiplv; int waitkey; - - // graph - // cginfo_t *cg[CGMAX]; - SDL_Rect updaterect; FontType fonttype; diff --git a/modules/NIGHTDLL/nt_msg.c b/modules/NIGHTDLL/nt_msg.c index 5e626fb..9ec18be 100644 --- a/modules/NIGHTDLL/nt_msg.c +++ b/modules/NIGHTDLL/nt_msg.c @@ -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; diff --git a/modules/NIGHTDLL/sactcg.c b/modules/NIGHTDLL/sactcg.c deleted file mode 100644 index f0e4595..0000000 --- a/modules/NIGHTDLL/sactcg.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * sactcg.c: CG作成 - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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 -#include -#include -#include - -#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; -} diff --git a/modules/NIGHTDLL/sactcg.h b/modules/NIGHTDLL/sactcg.h deleted file mode 100644 index 05a7164..0000000 --- a/modules/NIGHTDLL/sactcg.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * sactcg.h: CG作成 - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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 diff --git a/modules/NIGHTDLL/sprite.c b/modules/NIGHTDLL/sprite.c index 34ec5c3..abd621a 100644 --- a/modules/NIGHTDLL/sprite.c +++ b/modules/NIGHTDLL/sprite.c @@ -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; diff --git a/modules/NIGHTDLL/sprite.h b/modules/NIGHTDLL/sprite.h index 4b74096..eb80d28 100644 --- a/modules/NIGHTDLL/sprite.h +++ b/modules/NIGHTDLL/sprite.h @@ -4,6 +4,7 @@ #include "portab.h" #include +#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, diff --git a/modules/SACT/sact.h b/modules/SACT/sact.h index 564eb39..390726a 100644 --- a/modules/SACT/sact.h +++ b/modules/SACT/sact.h @@ -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; diff --git a/modules/SACT/sprite_msg.c b/modules/SACT/sprite_msg.c index 7d8b9c8..45fc692 100644 --- a/modules/SACT/sprite_msg.c +++ b/modules/SACT/sprite_msg.c @@ -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" diff --git a/modules/SACT/sprite_sel.c b/modules/SACT/sprite_sel.c index e9127a2..8a0d337 100644 --- a/modules/SACT/sprite_sel.c +++ b/modules/SACT/sprite_sel.c @@ -30,6 +30,7 @@ #include "portab.h" #include "nact.h" +#include "variable.h" #include "ags.h" #include "input.h" #include "sact.h" diff --git a/modules/SACT/sactcg.c b/modules/lib/sactcg.c similarity index 89% rename from modules/SACT/sactcg.c rename to modules/lib/sactcg.c index 1aa3f05..e5d7f8b 100644 --- a/modules/SACT/sactcg.c +++ b/modules/lib/sactcg.c @@ -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); } diff --git a/modules/SACT/sactcg.h b/modules/lib/sactcg.h similarity index 90% rename from modules/SACT/sactcg.h rename to modules/lib/sactcg.h index 1edfa3b..2ffc852 100644 --- a/modules/SACT/sactcg.h +++ b/modules/lib/sactcg.h @@ -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);