OSDN Git Service

コメントの処理を配列とループで行うように変更
authoryukihane <yukihane.feather@gmail.com>
Wed, 21 Sep 2011 13:53:49 +0000 (22:53 +0900)
committeryukihane <yukihane.feather@gmail.com>
Wed, 21 Sep 2011 17:28:15 +0000 (02:28 +0900)
vhook/framehook.h
vhook/main.c
vhook/main.h
vhook/process.c

index 031d2cf..889312f 100644 (file)
@@ -5,10 +5,11 @@
 
 /**
  * コメント付与に関するパラメータ.
- * 要素数はmain.hのN_COMMENT_TYPEと関連があるので注意.
+ * 要素の並び順, 要素数はmain.hのCOMMENT_TYPE, N_COMMENT_TYPEと合わせる必要があることに注意.
+ * また, この並び順でコメントが処理される(後になるほど前面にオーバレイされる).
  */
 const char* const FRAMEHOOK_OPT_DATA[] = {
-    "--data-user:", "--data-owner:", "--data-optional:", "--data-owner-opt:"
+    "--data-optional:", "--data-owner-opt:", "--data-user:", "--data-owner:"
 };
 
 #define FRAMEHOOK_OPT_FONT             "--font:"
index e246e2a..489fa14 100644 (file)
@@ -32,13 +32,17 @@ int init(FILE* log){
  * データの初期化
  */
 int initData(DATA* data,FILE* log,const SETTING* setting){
-       int i;
-    data->comment[0].common = data;
-    data->comment[1].common = data;
-       data->comment[0].enable = setting->comment[0].enable;
-       data->comment[1].enable = setting->comment[1].enable;
-       data->comment[0].opaque_comment = setting->opaque_comment;
-    data->comment[1].opaque_comment = 1; // オーナコメントは常に不透明
+    for(int i = 0; i < N_COMMENT_TYPE; i++) {
+        COMMDATA* const commdata = &data->comment[i];
+        const SETTING_COMMENT* const commset = &setting->comment[i];
+
+        commdata->common = data;
+        commdata->enable = commset->enable;
+        commdata->opaque_comment = setting->opaque_comment;
+    }
+    // オーナコメントは常に不透明
+    data->comment[OWNER].opaque_comment = TRUE;
+
        data->log = log;
        data->fontsize_fix = setting->fontsize_fix;
        data->show_video = setting->show_video;
@@ -51,7 +55,7 @@ int initData(DATA* data,FILE* log,const SETTING* setting){
        TTF_Font** font = data->font;
        const char* font_path = setting->font_path;
        const int font_index = setting->font_index;
-       for(i=0;i<CMD_FONT_MAX;i++){
+       for(int i=0;i<CMD_FONT_MAX;i++){
                int fontsize = COMMENT_FONT_SIZE[i];
                if(setting->fontsize_fix){
                        fontsize <<= 1;
@@ -72,48 +76,29 @@ int initData(DATA* data,FILE* log,const SETTING* setting){
                TTF_SetFontStyle(font[i],TTF_STYLE_BOLD);
        }
        fputs("[main/init]initialized font.\n",log);
-       /*
-        * ユーザコメント
-        */
-       if(data->comment[0].enable){
-               fputs("[main/init]User Comment is enabled.\n",log);
-               //コメントデータ
-               if(initChat(log,&data->comment[0].chat,setting->comment[0].path,&data->comment[0].slot,data->video_length)){
-                       fputs("[main/init]initialized comment.\n",log);
-               }else{
-                       fputs("[main/init]failed to initialize comment.",log);
-                       return FALSE;
-               }
-               //コメントスロット
-               if(initChatSlot(log,&data->comment[0].slot,setting->user_slot_max,&data->comment[0].chat)){
-                       fputs("[main/init]initialized comment slot.\n",log);
-               }else{
-                       fputs("[main/init]failed to initialize comment slot.",log);
-                       return FALSE;
-               }
-       }
-       /*
-        * オーナコメント
-        */
-       if(data->comment[1].enable){
-               fputs("[main/init]Owner Comment is enabled.\n",log);
-               //コメントデータ
-               if(initChat(log,&data->comment[1].chat,setting->comment[1].path,&data->comment[1].slot,data->video_length)){
-                       fputs("[main/init]initialized comment.\n",log);
-               }else{
-                       fputs("[main/init]failed to initialize comment.",log);
-                       return FALSE;
-               }
-               //コメントスロット
-        // TODO とりあえず最大数は1024にしておくが...
-               if(initChatSlot(log,&data->comment[1].slot,1024,&data->comment[1].chat)){
-                       fputs("[main/init]initialized comment slot.\n",log);
-               }else{
-                       fputs("[main/init]failed to initialize comment slot.",log);
-                       return FALSE;
-               }
-       }
-       
+
+    for (int i = 0; i < N_COMMENT_TYPE; i++) {
+        COMMDATA* const commdata = &data->comment[i];
+        if (commdata->enable) {
+            fprintf(log, "[main/init]Comment[%d] is enabled.\n", i);
+            const SETTING_COMMENT* const commset = &setting->comment[i];
+            //コメントデータ
+            if (initChat(log, &commdata->chat, commset->path, &commdata->slot, data->video_length)) {
+                fputs("[main/init]initialized comment.\n", log);
+            } else {
+                fputs("[main/init]failed to initialize comment.", log);
+                return FALSE;
+            }
+            //コメントスロット
+            if (initChatSlot(log, &commdata->slot, setting->user_slot_max, &commdata->chat)) {
+                fputs("[main/init]initialized comment slot.\n", log);
+            } else {
+                fputs("[main/init]failed to initialize comment slot.", log);
+                return FALSE;
+            }
+        }
+    }
+
        //終わり。
        fputs("[main/init]initialized context.\n",log);
        return TRUE;
@@ -155,19 +140,17 @@ int main_process(DATA* data,SDL_Surface* surf,const int now_vpos){
  * データのクローズ
  */
 int closeData(DATA* data){
-       int i;
-       //ユーザコメントが有効なら開放
-       if(data->comment[0].enable){
-               closeChat(&data->comment[0].chat);
-               closeChatSlot(&data->comment[0].slot);
-       }
-       //オーナコメントが有効なら開放
-       if(data->comment[1].enable){
-               closeChat(&data->comment[1].chat);
-               closeChatSlot(&data->comment[1].slot);
-       }
+       // コメントが有効なら開放
+    for (int i = 0; i < N_COMMENT_TYPE; i++) {
+        COMMDATA* const comment = &data->comment[i];
+        if (comment->enable) {
+            closeChat(&comment->chat);
+            closeChatSlot(&comment->slot);
+        }
+    }
+
     //フォント開放
-       for(i=0;i<CMD_FONT_MAX;i++){
+       for(int i=0;i<CMD_FONT_MAX;i++){
                TTF_CloseFont(data->font[i]);
        }
        return TRUE;
index d74b705..7605fde 100644 (file)
@@ -9,10 +9,16 @@
 
 /**
  * コメント中間ファイル数. つまりオーバレイするコメントの種類数.
- * 並びはframehook.hで定義している情報に依存することに注意.
  */
 #define N_COMMENT_TYPE 4
 
+/**
+ * コメントの種類. 並びはframehook.hで定義している情報と関連があることに注意.
+ */
+typedef enum {
+    USER_OPT, OWNER_OPT, USER, OWNER
+} COMMENT_TYPE;
+
 struct COMMDATA {
     int enable;
     CHAT chat;
index 8c6541c..d377832 100644 (file)
@@ -5,21 +5,16 @@
 #include "chat/chat_slot.h"
 
 //プロセス
-int process(DATA* data,SDL_Surface* surf,const int now_vpos){
-       //ユーザコメント
-       if(data->comment[0].enable){
-               if(!chat_process(&data->comment[0],surf,now_vpos)){
-                       fputs("[process/process]failed to process comment.\n",data->log);
-                       return FALSE;
-               }
-       }
-       //オーナコメント
-       if(data->comment[1].enable){
-               if(!chat_process(&data->comment[1],surf,now_vpos)){
-                       fputs("[process/process]failed to process comment.\n",data->log);
-                       return FALSE;
-               }
-       }
-       return TRUE;
-}
+int process(DATA* data, SDL_Surface* surf, const int now_vpos) {
+    for (int i = 0; i < N_COMMENT_TYPE; i++) {
+        COMMDATA* comment = &data->comment[i];
+        if (comment->enable) {
+            if (!chat_process(comment, surf, now_vpos)) {
+                fputs("[process/process]failed to process comment.\n", data->log);
+                return FALSE;
+            }
+        }
+    }
 
+    return TRUE;
+}