OSDN Git Service

ソースの文字コードと改行コードを修正
[coroid/inqubus.git] / vhook / main.c
1
2 #include <SDL/SDL.h>
3 #include <SDL/SDL_ttf.h>
4 #include <stdio.h>
5 #include "main.h"
6 #include "mydef.h"
7 #include "nicodef.h"
8 #include "process.h"
9 /**
10  * ライブラリ初期化
11  */
12 int init(FILE* log){
13         fputs("[main/init]initializing libs...\n",log);
14         //SDL
15         if(SDL_Init(SDL_INIT_VIDEO)>=0){
16                 fputs("[main/init]initialized SDL.\n",log);
17         }else{
18                 fputs("[main/init]failed to initialize SDL.\n",log);
19             return FALSE;
20         }
21         //SDL_ttf
22         if(TTF_Init() >= 0){
23                 fputs("[main/init]initialized SDL_ttf.\n",log);
24         }else{
25                 fputs("[main/init]failed to initialize SDL_ttf.\n",log);
26             return FALSE;
27         }
28         fputs("[main/init]initialized libs.\n",log);
29         return TRUE;
30 }
31 /*
32  * データの初期化
33  */
34 int initData(DATA* data,FILE* log,const SETTING* setting){
35         int i;
36     data->user_comment.common = data;
37     data->owner_comment.common = data;
38         data->user_comment.enable = setting->enable_user_comment;
39         data->owner_comment.enable = setting->enable_owner_comment;
40         data->user_comment.opaque_comment = setting->opaque_comment;
41     data->owner_comment.opaque_comment = 1; // オーナコメントは常に不透明
42         data->log = log;
43         data->fontsize_fix = setting->fontsize_fix;
44         data->show_video = setting->show_video;
45         data->shadow_kind = setting->shadow_kind;
46         data->process_first_called=FALSE;
47         data->video_length = setting->video_length;
48         fputs("[main/init]initializing context...\n",log);
49         //フォント
50         TTF_Font** font = data->font;
51         const char* font_path = setting->font_path;
52         const int font_index = setting->font_index;
53         for(i=0;i<CMD_FONT_MAX;i++){
54                 int fontsize = COMMENT_FONT_SIZE[i];
55                 if(setting->fontsize_fix){
56                         fontsize <<= 1;
57                 }
58                 font[i] = TTF_OpenFontIndex(font_path,fontsize,font_index);
59                 if(font[i] == NULL){
60                     fprintf(log,"[main/init]failed to load font:%s index:[%d].\n",font_path,font_index);
61                     //0でも試してみる。
62                     fputs("[main/init]retrying to open font at index:0...",log);
63                     font[i] = TTF_OpenFontIndex(font_path,fontsize,0);
64                     if(font[i] == NULL){
65                             fputs("failed.\n",log);
66                             return FALSE;
67                     }else{
68                             fputs("success.\n",log);
69                     }
70                 }
71                 TTF_SetFontStyle(font[i],TTF_STYLE_BOLD);
72         }
73         fputs("[main/init]initialized font.\n",log);
74         /*
75          * ユーザコメント
76          */
77         if(data->user_comment.enable){
78                 fputs("[main/init]User Comment is enabled.\n",log);
79                 //コメントデータ
80                 if(initChat(log,&data->user_comment.chat,setting->data_user_path,&data->user_comment.slot,data->video_length)){
81                         fputs("[main/init]initialized comment.\n",log);
82                 }else{
83                         fputs("[main/init]failed to initialize comment.",log);
84                         return FALSE;
85                 }
86                 //コメントスロット
87                 if(initChatSlot(log,&data->user_comment.slot,setting->user_slot_max,&data->user_comment.chat)){
88                         fputs("[main/init]initialized comment slot.\n",log);
89                 }else{
90                         fputs("[main/init]failed to initialize comment slot.",log);
91                         return FALSE;
92                 }
93         }
94         /*
95          * オーナコメント
96          */
97         if(data->owner_comment.enable){
98                 fputs("[main/init]Owner Comment is enabled.\n",log);
99                 //コメントデータ
100                 if(initChat(log,&data->owner_comment.chat,setting->data_owner_path,&data->owner_comment.slot,data->video_length)){
101                         fputs("[main/init]initialized comment.\n",log);
102                 }else{
103                         fputs("[main/init]failed to initialize comment.",log);
104                         return FALSE;
105                 }
106                 //コメントスロット
107         // TODO とりあえず最大数は1024にしておくが...
108                 if(initChatSlot(log,&data->owner_comment.slot,1024,&data->owner_comment.chat)){
109                         fputs("[main/init]initialized comment slot.\n",log);
110                 }else{
111                         fputs("[main/init]failed to initialize comment slot.",log);
112                         return FALSE;
113                 }
114         }
115         
116         //終わり。
117         fputs("[main/init]initialized context.\n",log);
118         return TRUE;
119 }
120 /*
121  * 映像の変換
122  */
123 int main_process(DATA* data,SDL_Surface* surf,const int now_vpos){
124         FILE* log = data->log;
125         if(!data->process_first_called){
126                 fprintf(log,"[main/process]screen size is %dx%d.\n",surf->w,surf->h);
127                 fflush(log);
128         }
129         /*フィルタをかける*/
130         if(process(data,surf,now_vpos)){
131         }
132         fflush(log);
133         /*変換した画像を見せる。*/
134         if(data->show_video){
135                 if(!data->process_first_called){
136                         data->screen = SDL_SetVideoMode(surf->w, surf->h, 24, SDL_HWSURFACE | SDL_DOUBLEBUF);
137                         if(data->screen == NULL){
138                                 fputs("[main/process]failed to initialize screen.\n",log);
139                                 fflush(log);
140                                 return FALSE;
141                         }
142                 }
143                 SDL_BlitSurface(surf,NULL,data->screen,NULL);
144                 SDL_Flip(data->screen);
145                 SDL_Event event;
146                 while(SDL_PollEvent(&event)){}
147         }
148         //一回目以降はTRUEになる。
149         data->process_first_called=TRUE;
150         fflush(log);
151         return TRUE;
152 }
153 /*
154  * データのクローズ
155  */
156 int closeData(DATA* data){
157         int i;
158         //ユーザコメントが有効なら開放
159         if(data->user_comment.enable){
160                 closeChat(&data->user_comment.chat);
161                 closeChatSlot(&data->user_comment.slot);
162         }
163         //オーナコメントが有効なら開放
164         if(data->owner_comment.enable){
165                 closeChat(&data->owner_comment.chat);
166                 closeChatSlot(&data->owner_comment.slot);
167         }
168     //フォント開放
169         for(i=0;i<CMD_FONT_MAX;i++){
170                 TTF_CloseFont(data->font[i]);
171         }
172         return TRUE;
173 }
174
175 /*
176  * ライブラリシャットダウン
177  */
178 int close(){
179     //SDLをシャットダウン
180     SDL_Quit();
181         //同じくTTFをシャットダウン
182     TTF_Quit();
183         return TRUE;
184 }