OSDN Git Service

needsDownloadメソッドをインタフェースから削除
[coroid/inqubus.git] / vhook / main.c
1 \r
2 #include <SDL/SDL.h>\r
3 #include <SDL/SDL_ttf.h>\r
4 #include <stdio.h>\r
5 #include "main.h"\r
6 #include "mydef.h"\r
7 #include "nicodef.h"\r
8 #include "process.h"\r
9 /**\r
10  * \83\89\83C\83u\83\89\83\8a\8f\89\8aú\89»\r
11  */\r
12 int init(FILE* log){\r
13         fputs("[main/init]initializing libs...\n",log);\r
14         //SDL\r
15         if(SDL_Init(SDL_INIT_VIDEO)>=0){\r
16                 fputs("[main/init]initialized SDL.\n",log);\r
17         }else{\r
18                 fputs("[main/init]failed to initialize SDL.\n",log);\r
19             return FALSE;\r
20         }\r
21         //SDL_ttf\r
22         if(TTF_Init() >= 0){\r
23                 fputs("[main/init]initialized SDL_ttf.\n",log);\r
24         }else{\r
25                 fputs("[main/init]failed to initialize SDL_ttf.\n",log);\r
26             return FALSE;\r
27         }\r
28         fputs("[main/init]initialized libs.\n",log);\r
29         return TRUE;\r
30 }\r
31 /*\r
32  * \83f\81[\83^\82Ì\8f\89\8aú\89»\r
33  */\r
34 int initData(DATA* data,FILE* log,const SETTING* setting){\r
35         int i;\r
36     data->user_comment.common = data;\r
37     data->owner_comment.common = data;\r
38         data->user_comment.enable = setting->enable_user_comment;\r
39         data->owner_comment.enable = setting->enable_owner_comment;\r
40         data->user_comment.opaque_comment = setting->opaque_comment;\r
41     data->owner_comment.opaque_comment = 1; // \83I\81[\83i\83R\83\81\83\93\83g\82Í\8fí\82É\95s\93§\96¾\r
42         data->log = log;\r
43         data->fontsize_fix = setting->fontsize_fix;\r
44         data->show_video = setting->show_video;\r
45         data->shadow_kind = setting->shadow_kind;\r
46         data->process_first_called=FALSE;\r
47         data->video_length = setting->video_length;\r
48         fputs("[main/init]initializing context...\n",log);\r
49         //\83t\83H\83\93\83g\r
50         TTF_Font** font = data->font;\r
51         const char* font_path = setting->font_path;\r
52         const int font_index = setting->font_index;\r
53         for(i=0;i<CMD_FONT_MAX;i++){\r
54                 int fontsize = COMMENT_FONT_SIZE[i];\r
55                 if(setting->fontsize_fix){\r
56                         fontsize <<= 1;\r
57                 }\r
58                 font[i] = TTF_OpenFontIndex(font_path,fontsize,font_index);\r
59                 if(font[i] == NULL){\r
60                     fprintf(log,"[main/init]failed to load font:%s index:[%d].\n",font_path,font_index);\r
61                     //0\82Å\82à\8e\8e\82µ\82Ä\82Ý\82é\81B\r
62                     fputs("[main/init]retrying to open font at index:0...",log);\r
63                     font[i] = TTF_OpenFontIndex(font_path,fontsize,0);\r
64                     if(font[i] == NULL){\r
65                             fputs("failed.\n",log);\r
66                             return FALSE;\r
67                     }else{\r
68                             fputs("success.\n",log);\r
69                     }\r
70                 }\r
71                 TTF_SetFontStyle(font[i],TTF_STYLE_BOLD);\r
72         }\r
73         fputs("[main/init]initialized font.\n",log);\r
74         /*\r
75          * \83\86\81[\83U\83R\83\81\83\93\83g\r
76          */\r
77         if(data->user_comment.enable){\r
78                 fputs("[main/init]User Comment is enabled.\n",log);\r
79                 //\83R\83\81\83\93\83g\83f\81[\83^\r
80                 if(initChat(log,&data->user_comment.chat,setting->data_user_path,&data->user_comment.slot,data->video_length)){\r
81                         fputs("[main/init]initialized comment.\n",log);\r
82                 }else{\r
83                         fputs("[main/init]failed to initialize comment.",log);\r
84                         return FALSE;\r
85                 }\r
86                 //\83R\83\81\83\93\83g\83X\83\8d\83b\83g\r
87                 if(initChatSlot(log,&data->user_comment.slot,setting->user_slot_max,&data->user_comment.chat)){\r
88                         fputs("[main/init]initialized comment slot.\n",log);\r
89                 }else{\r
90                         fputs("[main/init]failed to initialize comment slot.",log);\r
91                         return FALSE;\r
92                 }\r
93         }\r
94         /*\r
95          * \83I\81[\83i\83R\83\81\83\93\83g\r
96          */\r
97         if(data->owner_comment.enable){\r
98                 fputs("[main/init]Owner Comment is enabled.\n",log);\r
99                 //\83R\83\81\83\93\83g\83f\81[\83^\r
100                 if(initChat(log,&data->owner_comment.chat,setting->data_owner_path,&data->owner_comment.slot,data->video_length)){\r
101                         fputs("[main/init]initialized comment.\n",log);\r
102                 }else{\r
103                         fputs("[main/init]failed to initialize comment.",log);\r
104                         return FALSE;\r
105                 }\r
106                 //\83R\83\81\83\93\83g\83X\83\8d\83b\83g\r
107         // TODO \82Æ\82è\82 \82¦\82¸\8dÅ\91å\90\94\82Í1024\82É\82µ\82Ä\82¨\82­\82ª...\r
108                 if(initChatSlot(log,&data->owner_comment.slot,1024,&data->owner_comment.chat)){\r
109                         fputs("[main/init]initialized comment slot.\n",log);\r
110                 }else{\r
111                         fputs("[main/init]failed to initialize comment slot.",log);\r
112                         return FALSE;\r
113                 }\r
114         }\r
115         \r
116         //\8fI\82í\82è\81B\r
117         fputs("[main/init]initialized context.\n",log);\r
118         return TRUE;\r
119 }\r
120 /*\r
121  * \89f\91\9c\82Ì\95Ï\8a·\r
122  */\r
123 int main_process(DATA* data,SDL_Surface* surf,const int now_vpos){\r
124         FILE* log = data->log;\r
125         if(!data->process_first_called){\r
126                 fprintf(log,"[main/process]screen size is %dx%d.\n",surf->w,surf->h);\r
127                 fflush(log);\r
128         }\r
129         /*\83t\83B\83\8b\83^\82ð\82©\82¯\82é*/\r
130         if(process(data,surf,now_vpos)){\r
131         }\r
132         fflush(log);\r
133         /*\95Ï\8a·\82µ\82½\89æ\91\9c\82ð\8c©\82¹\82é\81B*/\r
134         if(data->show_video){\r
135                 if(!data->process_first_called){\r
136                         data->screen = SDL_SetVideoMode(surf->w, surf->h, 24, SDL_HWSURFACE | SDL_DOUBLEBUF);\r
137                         if(data->screen == NULL){\r
138                                 fputs("[main/process]failed to initialize screen.\n",log);\r
139                                 fflush(log);\r
140                                 return FALSE;\r
141                         }\r
142                 }\r
143                 SDL_BlitSurface(surf,NULL,data->screen,NULL);\r
144                 SDL_Flip(data->screen);\r
145                 SDL_Event event;\r
146                 while(SDL_PollEvent(&event)){}\r
147         }\r
148         //\88ê\89ñ\96Ú\88È\8d~\82ÍTRUE\82É\82È\82é\81B\r
149         data->process_first_called=TRUE;\r
150         fflush(log);\r
151         return TRUE;\r
152 }\r
153 /*\r
154  * \83f\81[\83^\82Ì\83N\83\8d\81[\83Y\r
155  */\r
156 int closeData(DATA* data){\r
157         int i;\r
158         //\83\86\81[\83U\83R\83\81\83\93\83g\82ª\97L\8cø\82È\82ç\8aJ\95ú\r
159         if(data->user_comment.enable){\r
160                 closeChat(&data->user_comment.chat);\r
161                 closeChatSlot(&data->user_comment.slot);\r
162         }\r
163         //\83I\81[\83i\83R\83\81\83\93\83g\82ª\97L\8cø\82È\82ç\8aJ\95ú\r
164         if(data->owner_comment.enable){\r
165                 closeChat(&data->owner_comment.chat);\r
166                 closeChatSlot(&data->owner_comment.slot);\r
167         }\r
168     //\83t\83H\83\93\83g\8aJ\95ú\r
169         for(i=0;i<CMD_FONT_MAX;i++){\r
170                 TTF_CloseFont(data->font[i]);\r
171         }\r
172         return TRUE;\r
173 }\r
174 \r
175 /*\r
176  * \83\89\83C\83u\83\89\83\8a\83V\83\83\83b\83g\83_\83E\83\93\r
177  */\r
178 int close(){\r
179     //SDL\82ð\83V\83\83\83b\83g\83_\83E\83\93\r
180     SDL_Quit();\r
181         //\93¯\82\82­TTF\82ð\83V\83\83\83b\83g\83_\83E\83\93\r
182     TTF_Quit();\r
183         return TRUE;\r
184 }\r