1 #include <SDL/SDL_endian.h>
\r
6 #include "../mydef.h"
\r
7 #include "../nicodef.h"
\r
9 int initChat(FILE* log,CHAT* chat,const char* file_path,CHAT_SLOT* slot,int video_length){
\r
11 int max_no = INTEGER_MIN;
\r
12 int min_no = INTEGER_MAX;
\r
15 FILE* com_f = fopen(file_path,"rb");
\r
17 fputs("[chat/init]failed to open comment file.\n",log);
\r
20 /*
\97v
\91f
\90\94\82Ì
\8eæ
\93¾*/
\r
21 if(fread(&max_item,sizeof(max_item),1,com_f) <= 0){
\r
22 fputs("[chat/init]failed to read the number of comments.\n",log);
\r
25 max_item = SDL_SwapLE32(max_item);
\r
26 fprintf(log,"[chat/init]%d comments.\n",max_item);
\r
27 chat->max_item = max_item;
\r
28 //
\83A
\83C
\83e
\83\80\94z
\97ñ
\82Ì
\8am
\95Û
\r
29 chat->item = malloc(sizeof(CHAT_ITEM) * max_item);
\r
30 if(chat->item == NULL){
\r
31 fputs("[chat/init]failed to malloc for comment.\n",log);
\r
34 /*
\8cÂ
\95Ê
\97v
\91f
\82Ì
\8f\89\8aú
\89»*/
\r
43 for(i=0;i<max_item;i++){
\r
44 item = &chat->item[i];
\r
46 item->showed = FALSE;
\r
47 //
\83R
\83\81\83\93\83g
\94Ô
\8d\86\r
48 if(fread(&no,sizeof(no),1,com_f) <= 0){
\r
49 fputs("[chat/init]failed to read comment number.\n",log);
\r
52 no = SDL_SwapLE32(no);
\r
53 max_no = MAX(max_no,no);
\r
54 min_no = MIN(min_no,no);
\r
56 if(fread(&vpos,sizeof(vpos),1,com_f) <= 0){
\r
57 fputs("[chat/init]failed to read comment vpos.\n",log);
\r
60 vpos = SDL_SwapLE32(vpos);
\r
61 //
\95¶
\8e\9a\82Ì
\8fê
\8f\8a\r
62 if(fread(&location,sizeof(location),1,com_f) <= 0){
\r
63 fputs("[chat/init]failed to read comment location.\n",log);
\r
66 location = SDL_SwapLE32(location);
\r
68 if(fread(&size,sizeof(size),1,com_f) <= 0){
\r
69 fputs("[chat/init]failed to read comment size.\n",log);
\r
72 size = SDL_SwapLE32(size);
\r
74 if(fread(&color,sizeof(color),1,com_f) <= 0){
\r
75 fputs("[chat/init]failed to read comment color.\n",log);
\r
78 color = SDL_SwapLE32(color);
\r
80 if(fread(&str_length,sizeof(str_length),1,com_f) <= 0){
\r
81 fputs("[chat/init]failed to read comment length.\n",log);
\r
84 str_length = SDL_SwapLE32(str_length);
\r
86 str = malloc(str_length);
\r
88 fputs("[chat/init]failed to malloc for comment text.\n",log);
\r
91 if(fread(str,str_length,1,com_f) <= 0){
\r
92 fputs("[chat/init]failed to read comment text.\n",log);
\r
95 //
\95Ï
\90\94\83Z
\83b
\83g
\r
98 item->location = location;
\r
100 item->color = color;
\r
102 /*
\93à
\95\94\8f\88\97\9d\82æ
\82è*/
\r
103 if(location != CMD_LOC_DEF){
\r
104 item->vstart = vpos;
\r
105 item->vend = vpos + TEXT_SHOW_SEC - TEXT_AHEAD_SEC;
\r
107 item->vstart = vpos - TEXT_AHEAD_SEC;
\r
108 item->vend = item->vstart + TEXT_SHOW_SEC;
\r
110 int fix = item->vend - video_length;
\r
114 item->vstart -= fix;
\r
115 fprintf(log,"[chat/fix]comment %d time adjusted.\n",i);
\r
117 /*
\93à
\95\94\8f\88\97\9d\82æ
\82è
\81@
\82¨
\82í
\82è*/
\r
120 chat->max_no = max_no;
\r
121 chat->min_no = min_no;
\r
125 void closeChat(CHAT* chat){
\r
127 int max_item = chat->max_item;
\r
128 for(i=0;i<max_item;i++){
\r
129 free((void*)chat->item[i].str);
\r
135 *
\83C
\83e
\83\8c\81[
\83^
\82ð
\83\8a\83Z
\83b
\83g
\82·
\82é
\81B
\r
137 void resetChatIterator(CHAT* chat){
\r
138 chat->iterator_index = 0;
\r
141 *
\83C
\83e
\83\8c\81[
\83^
\82ð
\93¾
\82é
\r
143 CHAT_ITEM* getChatShowed(CHAT* chat,int now_vpos){
\r
144 int *i = &chat->iterator_index;
\r
145 int max_item = chat->max_item;
\r
147 for(;*i<max_item;(*i)++){
\r
148 item = &chat->item[*i];
\r
149 if(now_vpos >= item->vstart && now_vpos <= item->vend && !item->showed){
\r