Пример #1
0
/* DLLibrary_load: load dynamic link library */
bool DLLibrary_load(DLLibrary *d, const char *dir, const char *file)
{
   char *buf;

   if(d == NULL || dir == NULL || file == NULL) return false;
   DLLibrary_clear(d);

   /* open */
   buf = (char *) malloc(sizeof(char) * (MMDAgent_strlen(dir) + 1 + MMDAgent_strlen(file) + 1));
   sprintf(buf, "%s%c%s", dir, MMDAGENT_DIRSEPARATOR, file);
   d->handle = MMDAgent_dlopen(buf);
   free(buf);
   if (!d->handle)
      return false;

   /* set function pointers */
   d->appStart = (void (*)(MMDAgent *)) MMDAgent_dlsym(d->handle, "extAppStart");
   d->appEnd = (void (*)(MMDAgent *)) MMDAgent_dlsym(d->handle, "extAppEnd");
   d->procCommand = (void (*)(MMDAgent *, const char *, const char *)) MMDAgent_dlsym(d->handle, "extProcCommand");
   d->procEvent = (void (*)(MMDAgent *, const char *, const char *)) MMDAgent_dlsym(d->handle, "extProcEvent");
   d->update = (void (*)(MMDAgent *, double)) MMDAgent_dlsym(d->handle, "extUpdate");
   d->render = (void (*)(MMDAgent *)) MMDAgent_dlsym(d->handle, "extRender");

   if (d->appStart || d->appEnd || d->procCommand || d->procEvent || d->update || d->render) {
      /* save file name */
      d->name = MMDAgent_strdup(file);
      return true;
   } else {
      /* if none, exit */
      DLLibrary_clear(d);
      return false;
   }
}
Пример #2
0
/* Audio_Thread::play: start playing */
void Audio_Thread::play(const char *alias, const char *file)
{
   /* check */
   if(isRunning() == false)
      return;
   if(MMDAgent_strlen(alias) <= 0 || MMDAgent_strlen(file) <= 0)
      return;

   /* wait buffer mutex */
   glfwLockMutex(m_mutex);

   /* save character name, speaking style, and text */
   if(m_alias) free(m_alias);
   if(m_file) free(m_file);
   m_alias = MMDAgent_strdup(alias);
   m_file = MMDAgent_strdup(file);
   m_count++;

   /* start playing thread */
   if(m_count <= 1)
      glfwSignalCond(m_cond);

   /* release buffer mutex */
   glfwUnlockMutex(m_mutex);
}
Пример #3
0
/* Variables::set: set value */
void Variables::set(const char *alias, const char *str1, const char *str2)
{
   Value *val;

   float max, min, tmp;

   if(MMDAgent_strlen(alias) <= 0) return;

   /* check the same alias */
   for(val = m_head; val; val = val->next) {
      if(MMDAgent_strequal(val->name, alias))
         break;
   }

   /* push */
   if(val == NULL) {
      val = (Value *) malloc(sizeof(Value));
      val->name = MMDAgent_strdup(alias);
      val->next = NULL;
      if(m_tail == NULL) {
         m_head = val;
         val->prev = NULL;
      } else {
         m_tail->next = val;
         val->prev = m_tail;
      }
      m_tail = val;
   } else {
      free(val->sval);
   }

   /* set string */
   if(str2 == NULL) {
      val->sval = MMDAgent_strdup(str1);
   } else {
      val->sval = (char *) malloc(sizeof(char) * (MMDAgent_strlen(str1) + 1 + MMDAgent_strlen(str2) + 1));
      sprintf(val->sval, "%s|%s", str1, str2);
   }

   /* set float */
   if(str2 == NULL) {
      val->fval = MMDAgent_str2float(str1);
   } else {
      min = MMDAgent_str2float(str1);
      max = MMDAgent_str2float(str2);
      if(max < min) {
         tmp = max;
         max = min;
         min = tmp;
      }
      val->fval = min + (max - min) * (rand() - 0.0f) * (1.0f / (RAND_MAX - 0.0f)); /* 0.0f is RAND_MIN */
   }

   m_mmdagent->sendEventMessage(VARIABLES_VALUESETEVENT, alias); /* send message */
}
/* callbackRecogResult: callback for recognitional result */
static void callbackRecogResult(Recog *recog, void *data)
{
   int i;
   int first;
   Sentence *s;
   RecogProcess *r;
   static char str[MMDAGENT_MAXBUFLEN]; /* static buffer */
   Julius_Thread *j = (Julius_Thread *) data;

   /* get status */
   r = recog->process_list;
   if (!r->live)
      return;
   if (r->result.status < 0) {
      return;
   }
   s = &(r->result.sent[0]);
   strcpy(str, "");
   first = 1;
   for (i = 0; i < s->word_num; i++) {
      if (MMDAgent_strlen(r->lm->winfo->woutput[s->word[i]]) > 0) {
         if (first == 0)
            strcat(str, ",");
         strcat(str, r->lm->winfo->woutput[s->word[i]]);
         if (first == 1)
            first = 0;
      }
   }

   if(first == 0)
      j->sendMessage(JULIUSTHREAD_EVENTSTOP, str);
}
Пример #5
0
/* extAppStart: load amodels and start thread */
EXPORT void extAppStart(MMDAgent *mmdagent)
{
   int len;
   char dic[MMDAGENT_MAXBUFLEN];
   char *config;

   /* get dictionary directory name */
   sprintf(dic, "%s%c%s", mmdagent->getConfigDirName(), MMDAGENT_DIRSEPARATOR, PLUGININTERFACE_NAME);

   /* get config file */
   config = MMDAgent_strdup(mmdagent->getConfigFileName());
   len = MMDAgent_strlen(config);

   /* load */
   if (len > 4) {
      config[len - 4] = '.';
      config[len - 3] = 'x';
      config[len - 2] = 'x';
      config[len - 1] = 'x';
      interface_manager.loadAndStart(mmdagent, dic, config);
   }

   if(config)
      free(config);

   enable = true;
   mmdagent->sendMessage(MMDAGENT_EVENT_PLUGINENABLE, "%s", PLUGININTERFACE_NAME);
}
/* PMDObject::setAlias: set alias name */
void PMDObject::setAlias(const char *alias)
{
   if(MMDAgent_strlen(alias) > 0 && m_alias != alias) {
      if(m_alias)
         free(m_alias);
      m_alias = MMDAgent_strdup(alias);
   }
}
Пример #7
0
/* Audio_Thread::startLipsync: start lipsync if HTK label file is existing */
bool Audio_Thread::startLipsync(const char *file)
{
   bool result = false;
   int i;
   char *label;
   size_t len;
   FILE *fp;
   char buff[MMDAGENT_MAXBUFLEN];
   char message[MMDAGENT_MAXBUFLEN];
   int startLen, startTime, endLen, endTime, phonemeLen;
   bool first = true;
   PMDObject *objs;

   len = MMDAgent_strlen(file);
   if(len > 4) {
      label = MMDAgent_strdup(file);
      label[len - 4] = '.';
      label[len - 3] = 'l';
      label[len - 2] = 'a';
      label[len - 1] = 'b';
      fp = MMDAgent_fopen(label, "r");
      if(fp != NULL) {
         /* load HTK label */
         strcpy(message, "");
         while(1) {
            startLen = MMDAgent_fgettoken(fp, buff);
            startTime = MMDAgent_str2int(buff);
            endLen = MMDAgent_fgettoken(fp, buff);
            endTime = MMDAgent_str2int(buff);
            phonemeLen = MMDAgent_fgettoken(fp, buff);
            if(startLen > 0 && endLen > 0 && phonemeLen > 0 && startTime < endTime) {
               if(first)
                  sprintf(message, "%s,%d", buff, (int) ((double) (endTime - startTime) * 1.0E-04 + 0.5));
               else
                  sprintf(message, "%s,%s,%d", message, buff, (int) ((double) (endTime - startTime) * 1.0E-04 + 0.5));
               first = false;
            } else {
               break;
            }
         }
         fclose(fp);
         /* send lipsync message */
         if(first == false) {
            objs = m_mmdagent->getModelList();
            for (i = 0; i < m_mmdagent->getNumModel(); i++) {
               if (objs[i].isEnable() == true && objs[i].allowMotionFileDrop() == true) {
                  m_mmdagent->sendMessage(MMDAGENT_COMMAND_LIPSYNCSTART, "%s|%s", objs[i].getAlias(), message);
                  result = true;
               }
            }
         }
      }
      free(label);
   }

   return result;
}
Пример #8
0
/* Open_JTalk_EventQueue_enqueue: enqueue */
static void Open_JTalk_EventQueue_enqueue(Open_JTalk_EventQueue *q, const char *str)
{
   if(MMDAgent_strlen(str) <= 0)
      return;

   if (q->tail == NULL) {
      q->tail = (Open_JTalk_Event *) calloc(1, sizeof (Open_JTalk_Event));
      Open_JTalk_Event_initialize(q->tail, str);
      q->head = q->tail;
   } else {
      q->tail->next = (Open_JTalk_Event *) calloc(1, sizeof (Open_JTalk_Event));
      Open_JTalk_Event_initialize(q->tail->next, str);
      q->tail = q->tail->next;
   }
}
Пример #9
0
/* MessageQueue_enqueue: enqueue */
static void MessageQueue_enqueue(MessageQueue *q, const char *type, const char *value)
{
   if(MMDAgent_strlen(type) <= 0)
      return;

   if(q->tail == NULL) {
      q->tail = (MessageLink *) malloc(sizeof(MessageLink));
      MessageLink_initialize(q->tail, type, value);
      q->head = q->tail;
   } else {
      q->tail->next = (MessageLink *) malloc(sizeof(MessageLink));
      MessageLink_initialize(q->tail->next, type, value);
      q->tail = q->tail->next;
   }
}
Пример #10
0
void VIManager_Logger::drawArc(unsigned int from, VIManager_Arc *arc)
{
    int i;
    static char buf1[MMDAGENT_MAXBUFLEN], buf2[MMDAGENT_MAXBUFLEN]; /* static buffer */

    strcpy(buf1, arc->input_event_type);
    for (i = 0; i < arc->input_event_argc; i++) {
        strcat(buf1, "|");
        strcat(buf1, arc->input_event_args[i]);
    }
    if (MMDAgent_strlen(arc->output_command_args) >= 0)
        sprintf(buf2, "%d %d %s %s|%s", from, arc->next_state->number, buf1, arc->output_command_type, arc->output_command_args);
    else
        sprintf(buf2, "%d %d %s %s", from, arc->next_state->number, buf1, arc->output_command_type);
    m_mmdagent->drawString(buf2);
}
/* PMDObject::renderError: render model error */
void PMDObject::renderError(TextRenderer * text)
{
   char buf[PMDOBJECT_MAXBUFLEN];
   btVector3 pos;
   float w, h;
   float tpos[3];
   char *p, *save;

   m_pmd.getErrorTextureList(buf, PMDOBJECT_MAXBUFLEN);
   if (MMDAgent_strlen(buf) <= 0)
      return;

   pos = m_pmd.getCenterBone()->getTransform()->getOrigin();
   pos.setZ(pos.z() + 5.0f);
   glDisable(GL_LIGHTING);
   glPushMatrix();
   glTranslatef(pos.x() - 0.3f, pos.y() - 0.3f, pos.z() - 0.01f);
   w = 10.0f;
   h = 6.0f;
   glNormal3f(0.0, 0.0, 1.0);
   glColor4f(0.0f, 0.0f, 0.0f, 0.7f);
   glBegin(GL_QUADS);
   glVertex3f(0, 0, 0);
   glVertex3f(w, 0, 0);
   glVertex3f(w, h, 0);
   glVertex3f(0, h, 0);
   glEnd();
   glPopMatrix();

   glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
   tpos[0] = pos.x();
   tpos[1] = pos.y() + 5.0f;
   tpos[2] = pos.z();
   glPushMatrix();
   glTranslatef(tpos[0], tpos[1], tpos[2]);
   text->drawString("[Texture Errors]");
   glPopMatrix();

   for (p = MMDAgent_strtok(buf, "\n", &save); p; p = MMDAgent_strtok(NULL, "\n", &save)) {
      tpos[1] -= 0.7f;
      glPushMatrix();
      glTranslatef(tpos[0], tpos[1], tpos[2]);
      text->drawString(p);
      glPopMatrix();
   }
   glEnable(GL_LIGHTING);
}
Пример #12
0
/* MMDAgent_opendir: open directory */
DIRECTORY *MMDAgent_opendir(const char *name)
{
#ifdef _WIN32
    DIRECTORY *dir;

    if(name == NULL)
        return NULL;

    dir = (DIRECTORY *) malloc(sizeof(DIRECTORY));
    dir->data = malloc(sizeof(WIN32_FIND_DATAA));
    char name2[MMDAGENT_MAXBUFLEN];
    if(MMDAgent_strlen(name) <= 0) {
        strcpy(name2, "*");
    } else {
        sprintf(name2, "%s%c*", name, MMDAGENT_DIRSEPARATOR);
    }
    dir->find = FindFirstFileA(name2, (WIN32_FIND_DATAA *) dir->data);
    dir->first = true;
    if(dir->find == INVALID_HANDLE_VALUE) {
        free(dir->data);
        free(dir);
        return NULL;
    }
#else
    DIRECTORY *dir;
    char *path;

    if(name == NULL)
        return NULL;

    dir = (DIRECTORY *) malloc(sizeof(DIRECTORY));

    path = MMDFiles_pathdup(name);
    dir->find = (void *) opendir(path);
    free(path);
    if(dir->find == NULL) {
        free(dir);
        return NULL;
    }
#endif /* _WIN32 */

    return dir;
}
Пример #13
0
/* Open_JTalk_Manager::synthesis: start synthesis */
void Open_JTalk_Manager::synthesis(const char *str)
{
   /* check */
   if(isRunning() == false || MMDAgent_strlen(str) <= 0)
      return;

   /* wait buffer mutex */
   glfwLockMutex(m_mutex);

   /* enqueue character name, speaking style, and text */
   Open_JTalk_EventQueue_enqueue(&m_bufferQueue, str);
   m_count++;

   /* start synthesis event */
   if(m_count <= 1)
      glfwSignalCond(m_cond);

   /* release buffer mutex */
   glfwUnlockMutex(m_mutex);
}
Пример #14
0
/* getArgFromString: get argument from string using separators */
static int getArgFromString(const char *str, int *index, char *buff, char separator)
{
   int i, j = 0, len;
   const char *c;
   unsigned char size;

   if (str == NULL) {
      buff[0] = '\0';
      return 0;
   }

   len = MMDAgent_strlen(str);
   if (len <= 0) {
      buff[0] = '\0';
      return 0;
   }

   c = str + (*index);
   for (i = 0; i < len && (*c == '\0' || *c == ' ' || *c == '\t' || *c == '\n' || *c == '\r'); i += size) {
      if (*c == '\0') {
         buff[0] = '\0';
         return 0;
      }
      size = MMDAgent_getcharsize(c);
      (*index) += size;
      c += size;
   }

   for (i = 0; i < len && *c != '\0' && *c != ' ' && *c != '\t' && *c != '\n' && *c != '\r' && *c != separator; i += size) {
      size = MMDAgent_getcharsize(c);
      memcpy(&buff[j], c, sizeof(char) * size);
      j += size;
      (*index) += size;
      c += size;
   }
   if (*c == separator)
      (*index)++;

   buff[j] = '\0';
   return j;
}
Пример #15
0
/* countArgs: count arguments */
static int countArgs(const char *str, char separator)
{
   int i, len, num;
   const char *c;
   unsigned char size;

   len = MMDAgent_strlen(str);
   if(len <= 0)
      return 0;

   num = 1;
   c = str;
   for(i = 0; i < len; i += size) {
      size = MMDAgent_getcharsize(c);
      if(*c == separator)
         num++;
      c += size;
   }

   return num;
}
/* Audio_Manager::play: start playing */
void Audio_Manager::play(const char *str)
{
   /* check */
   if(isRunning() == false)
      return;
   if(MMDAgent_strlen(str) <= 0)
      return;

   /* wait buffer mutex */
   glfwLockMutex(m_mutex);

   /* enqueue alias and file name */
   Audio_EventQueue_enqueue(&m_bufferQueue, str);
   m_count++;

   /* start playing event */
   if(m_count <= 1)
      glfwSignalCond(m_cond);

   /* release buffer mutex */
   glfwUnlockMutex(m_mutex);
}
Пример #17
0
/* extAppStart: load FST and start thread */
EXPORT void extAppStart(MMDAgent *mmdagent)
{
   char *buf;
   int len;

   setlocale(LC_CTYPE, "japanese");

   buf = MMDAgent_strdup(mmdagent->getConfigFileName());
   len = MMDAgent_strlen(buf);
   if (len > 4) {
      buf[len - 4] = '.';
      buf[len - 3] = 'f';
      buf[len - 2] = 's';
      buf[len - 1] = 't';
      vimanager_thread.loadAndStart(mmdagent, buf);
   }
   if(buf)
      free(buf);

   enable = true;
   enable_log = false;
   mmdagent->sendMessage(MMDAGENT_EVENT_PLUGINENABLE, "%s", PLUGINVIMANAGER_NAME);
}
Пример #18
0
/* extProcCommand: process command message */
EXPORT void extProcCommand(MMDAgent *mmdagent, const char *type, const char *args)
{
   if(enable == true) {
      if(MMDAgent_strequal(type, MMDAGENT_COMMAND_PLUGINDISABLE) == true) {
         if(MMDAgent_strequal(args, PLUGINWINDOWCONTROLLER_NAME)) {
            enable = false;
            mmdagent->sendEventMessage(MMDAGENT_EVENT_PLUGINDISABLE, PLUGINWINDOWCONTROLLER_NAME);
         }
      } else if(MMDAgent_strequal(type, PLUGINWINDOWCONTROLLER_EXECUTE) == true) {
         if(MMDAgent_strlen(args) > 0)
            ShellExecuteA(NULL, NULL, args, NULL, NULL, SW_SHOWNORMAL);
      } else if(MMDAgent_strequal(type, PLUGINWINDOWCONTROLLER_KEYPOST) == true) {
         postKeyMessage(args);
      }
   } else {
      if(MMDAgent_strequal(type, MMDAGENT_COMMAND_PLUGINENABLE) == true) {
         if(MMDAgent_strequal(args, PLUGINWINDOWCONTROLLER_NAME) == true) {
            enable = true;
            mmdagent->sendEventMessage(MMDAGENT_EVENT_PLUGINENABLE, PLUGINWINDOWCONTROLLER_NAME);
         }
      }
   }
}
Пример #19
0
/* getArgs: get event arguments */
static int getArgs(const char *str, char ***args, int *argc)
{
   int i, j, len, idx = 0;
   char buff[MMDAGENT_MAXBUFLEN];

   if (str == NULL) {
      (*argc) = 0;
      (*args) = NULL;
      return 0;
   }

   len = MMDAgent_strlen(str);
   if (len <= 0) {
      (*argc) = 0;
      (*args) = NULL;
      return 0;
   }

   /* get number of separator */
   (*argc) = 1;
   for (i = 0; i < len; i++)
      if (str[i] == VIMANAGER_SEPARATOR1 || str[i] == VIMANAGER_SEPARATOR2)
         (*argc)++;
   (*args) = (char **) calloc((*argc), sizeof(char *));
   for (i = 0; i < (*argc); i++)
      (*args)[i] = NULL;

   /* get event arguments */
   for (i = 0; i < (*argc); i++) {
      j = getArgFromString(str, &idx, buff);
      (*args)[i] = (char *) calloc(j + 1, sizeof(char));
      strcpy((*args)[i], buff);
   }

   return 1;
}
/* PMDObject::load: load model */
bool PMDObject::load(const char *fileName, const char *alias, btVector3 *offsetPos, btQuaternion *offsetRot, bool forcedPosition, PMDBone *assignBone, PMDObject *assignObject, BulletPhysics *bullet, SystemTexture *systex, LipSync *sysLipSync, bool useCartoonRendering, float cartoonEdgeWidth, btVector3 *light, float commentFrame)
{
   int i;
   int len;
   char *buf;
   LipSync *lip;

   if (fileName == NULL || alias == NULL) return false;

   /* apply given parameters */
   m_assignTo = assignObject;
   m_baseBone = assignBone;

   if (forcedPosition) {
      /* set offset by given parameters */
      if (offsetPos)
         m_offsetPos = (*offsetPos);
      if (offsetRot)
         m_offsetRot = (*offsetRot);
      m_pmd.getRootBone()->setOffset(&m_offsetPos);
      m_pmd.getRootBone()->update();
   } else {
      /* set offset by root bone */
      m_pmd.getRootBone()->getOffset(&m_offsetPos);
   }

   /* copy absolute position flag */
   for (i = 0; i < 3; i++)
      m_absPosFlag[i] = false;

   /* copy toon rendering flag */
   m_useCartoonRendering = useCartoonRendering;

   /* copy flag for motion file drop or all motion */
   if(assignBone || assignObject)
      m_allowMotionFileDrop = false;
   else
      m_allowMotionFileDrop = true;

   /* save position when position is fixed */
   if (m_baseBone) m_origBasePos = m_baseBone->getTransform()->getOrigin();

   /* set alpha frame */
   m_alphaAppearFrame = PMDOBJECT_ALPHAFRAME;
   m_alphaDisappearFrame = 0.0;

   /* set comment frame */
   m_displayCommentFrame = commentFrame;

   /* load model */
   if (m_pmd.load(fileName, bullet, systex) == false) {
      clear();
      return false;
   }

   /* set toon rendering flag */
   m_pmd.setToonFlag(useCartoonRendering);

   /* set edge width */
   m_pmd.setEdgeThin(cartoonEdgeWidth);

   /* load lip sync */
   m_globalLipSync = sysLipSync;
   if(m_localLipSync != NULL)
      delete m_localLipSync;
   m_localLipSync = NULL;
   lip = new LipSync();
   len = MMDAgent_strlen(fileName);
   if(len < 5) {
      delete lip;
   } else {
      buf = MMDAgent_strdup(fileName);
      buf[len - 4] = '.';
      buf[len - 3] = 'l';
      buf[len - 2] = 'i';
      buf[len - 1] = 'p';
      if(lip->load(buf) == true) {
         m_localLipSync = lip;
      } else
         delete lip;
      if(buf)
         free(buf);
   }

   /* set alias */
   setAlias(alias);

   /* reset */
   setLightForToon(light);
   m_moveSpeed = -1.0f;
   m_spinSpeed = -1.0f;

   /* set temporarily all body to Kinematic */
   /* this is fixed at first simulation */
   skipNextSimulation();

   /* enable */
   m_isEnable = true;

   return true;
}
Пример #21
0
/* VIManager::load: load FST */
int VIManager::load(const char *file)
{
   FILE *fp;
   char buff[MMDAGENT_MAXBUFLEN];
   int len;
   int idx;

   char buff_s1[MMDAGENT_MAXBUFLEN];
   char buff_s2[MMDAGENT_MAXBUFLEN];
   char buff_is[MMDAGENT_MAXBUFLEN];
   char buff_os[MMDAGENT_MAXBUFLEN];
   char buff_er[MMDAGENT_MAXBUFLEN];
   int size_s1;
   int size_s2;
   int size_is;
   int size_os;
   int size_er;
   char *err_s1;
   char *err_s2;
   unsigned int index_s1;
   unsigned int index_s2;

   /* open */
   fp = MMDAgent_fopen(file, "r");
   if (fp == NULL)
      return 0;

   /* unload */
   VIManager_SList_clear(&m_stateList);
   VIManager_SList_initialize(&m_stateList);

   while (fgets(buff, MMDAGENT_MAXBUFLEN - 3, fp) != NULL) { /* string + \r + \n + \0 */
      /* remove final \n and \r */
      len = MMDAgent_strlen(buff);
      while (len > 0 && (buff[len-1] == '\n' || buff[len-1] == '\r'))
         buff[--len] = '\0';

      /* check and load arc */
      if (len > 0) {
         idx = 0;
         size_s1 = getTokenFromString(buff, &idx, buff_s1);
         size_s2 = getTokenFromString(buff, &idx, buff_s2);
         size_is = getTokenFromString(buff, &idx, buff_is);
         size_os = getTokenFromString(buff, &idx, buff_os);
         size_er = getTokenFromString(buff, &idx, buff_er);
         if (size_s1 > 0 && size_s2 > 0 && size_is > 0 && size_os > 0 && size_er == 0 && buff_s1[0] != VIMANAGER_COMMENT) {
            index_s1 = (unsigned int) strtoul(buff_s1, &err_s1, 10);
            index_s2 = (unsigned int) strtoul(buff_s2, &err_s2, 10);
            if (buff_s1 + size_s1 == err_s1 && buff_s2 + size_s2 == err_s2)
               VIManager_SList_addArc(&m_stateList, index_s1, index_s2, buff_is, buff_os);
         }
      }
      if (feof(fp) || ferror(fp))
         break;
   }

   fclose(fp);

   /* set current state to zero */
   m_currentState = VIManager_SList_searchState(&m_stateList, VIMANAGER_STARTSTATE);

   return 1;
}
/* Option::load: load options from config file */
bool Option::load(const char *file)
{
   FILE *fp;
   char buf[OPTION_MAXBUFLEN];
   int len;
   char *p1;

   int ivec2[2];
   float fvec3[3];
   float fvec4[4];

   fp = MMDAgent_fopen(file, "r");
   if (fp == NULL)
      return false;

   while (fgets(buf, OPTION_MAXBUFLEN, fp)) {
      len = MMDAgent_strlen(buf);
      if(len <= 0) continue;
      p1 = &(buf[len - 1]);
      while (p1 >= &(buf[0]) && (*p1 == '\n' || *p1 == '\r' || *p1 == '\t' || *p1 == ' ')) {
         *p1 = L'\0';
         p1--;
      }
      p1 = &(buf[0]);
      if (*p1 == '#') continue;
      while (*p1 != L'=' && *p1 != L'\0') p1++;
      if (*p1 == L'\0') continue;
      *p1 = L'\0';
      p1++;

      /* overwrite option values */
      if(MMDAgent_strequal(buf, OPTION_USECARTOONRENDERING_STR)) {
         setUseCartoonRendering(MMDAgent_str2bool(p1));
      } else if(MMDAgent_strequal(buf, OPTION_USEMMDLIKECARTOON_STR)) {
         setUseMMDLikeCartoon(MMDAgent_str2bool(p1));
      } else if(MMDAgent_strequal(buf, OPTION_CARTOONEDGEWIDTH_STR)) {
         setCartoonEdgeWidth(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_CARTOONEDGESTEP_STR)) {
         setCartoonEdgeStep(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_CARTOONEDGESELECTEDCOLOR_STR)) {
         if(MMDAgent_str2fvec(p1, fvec4, 4))
            setCartoonEdgeSelectedColor(fvec4);
      } else if(MMDAgent_strequal(buf, OPTION_CAMERAROTATION_STR)) {
         if(MMDAgent_str2fvec(p1, fvec3, 3))
            setCameraRotation(fvec3);
      } else if(MMDAgent_strequal(buf, OPTION_CAMERATRANSITION_STR)) {
         if(MMDAgent_str2fvec(p1, fvec3, 3))
            setCameraTransition(fvec3);
      } else if(MMDAgent_strequal(buf, OPTION_CAMERADISTANCE_STR)) {
         setCameraDistance(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_CAMERAFOVY_STR)) {
         setCameraFovy(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_STAGESIZE_STR)) {
         if(MMDAgent_str2fvec(p1, fvec3, 3))
            setStageSize(fvec3);
      } else if(MMDAgent_strequal(buf, OPTION_SHOWFPS_STR)) {
         setShowFps(MMDAgent_str2bool(p1));
      } else if(MMDAgent_strequal(buf, OPTION_FPSPOSITION_STR)) {
         if(MMDAgent_str2fvec(p1, fvec3, 3))
            setFpsPosition(fvec3);
      } else if(MMDAgent_strequal(buf, OPTION_WINDOWSIZE_STR)) {
         if(MMDAgent_str2ivec(p1, ivec2, 2))
            setWindowSize(ivec2);
      } else if(MMDAgent_strequal(buf, OPTION_FULLSCREEN_STR)) {
         setFullScreen(MMDAgent_str2bool(p1));
      } else if(MMDAgent_strequal(buf, OPTION_LOGSIZE_STR)) {
         if(MMDAgent_str2ivec(p1, ivec2, 2))
            setLogSize(ivec2);
      } else if(MMDAgent_strequal(buf, OPTION_LOGPOSITION_STR)) {
         if(MMDAgent_str2fvec(p1, fvec3, 3))
            setLogPosition(fvec3);
      } else if(MMDAgent_strequal(buf, OPTION_LOGSCALE_STR)) {
         setLogScale(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_LIGHTDIRECTION_STR)) {
         if(MMDAgent_str2fvec(p1, fvec4, 4))
            setLightDirection(fvec4);
      } else if(MMDAgent_strequal(buf, OPTION_LIGHTINTENSITY_STR)) {
         setLightIntensity(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_LIGHTCOLOR_STR)) {
         if(MMDAgent_str2fvec(p1, fvec3, 3))
            setLightColor(fvec3);
      } else if(MMDAgent_strequal(buf, OPTION_CAMPUSCOLOR_STR)) {
         if(MMDAgent_str2fvec(p1, fvec3, 3))
            setCampusColor(fvec3);
      } else if(MMDAgent_strequal(buf, OPTION_MAXMULTISAMPLING_STR)) {
         setMaxMultiSampling(MMDAgent_str2int(p1));
      } else if(MMDAgent_strequal(buf, OPTION_MOTIONADJUSTTIME_STR)) {
         setMotionAdjustTime(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_LIPSYNCPRIORITY_STR)) {
         setLipsyncPriority(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_BULLETFPS_STR)) {
         setBulletFps(MMDAgent_str2int(p1));
      } else if(MMDAgent_strequal(buf, OPTION_GRAVITYFACTOR_STR)) {
         setGravityFactor(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_ROTATESTEP_STR)) {
         setRotateStep(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_TRANSLATESTEP_STR)) {
         setTranslateStep(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_DISTANCESTEP_STR)) {
         setDistanceStep(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_FOVYSTEP_STR)) {
         setFovyStep(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_USESHADOWMAPPING_STR)) {
         setUseShadowMapping(MMDAgent_str2bool(p1));
      } else if(MMDAgent_strequal(buf, OPTION_SHADOWMAPPINGTEXTURESIZE_STR)) {
         setShadowMappingTextureSize(MMDAgent_str2int(p1));
      } else if(MMDAgent_strequal(buf, OPTION_SHADOWMAPPINGSELFDENSITY_STR)) {
         setShadowMappingSelfDensity(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_SHADOWMAPPINGFLOORDENSITY_STR)) {
         setShadowMappingFloorDensity(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_SHADOWMAPPINGLIGHTFIRST_STR)) {
         setShadowMappingLightFirst(MMDAgent_str2bool(p1));
      } else if(MMDAgent_strequal(buf, OPTION_DISPLAYCOMMENTTIME_STR)) {
         setDisplayCommentTime(MMDAgent_str2float(p1));
      } else if(MMDAgent_strequal(buf, OPTION_MAXNUMMODEL_STR)) {
         setMaxNumModel(MMDAgent_str2int(p1));
      }
   }
   fclose(fp);

   return true;
}
Пример #23
0
/* extProcEvent: process event message */
EXPORT void extProcEvent(MMDAgent *mmdagent, const char *type, const char *args)
{
   int i;
   FILE *fp;
   char *buf, *p, *q;
   PMDObject *objs;
   MotionPlayer *motionPlayer;

   if(enable == true) {
      if(MMDAgent_strequal(type, MMDAGENT_EVENT_DRAGANDDROP)) {
         buf = MMDAgent_strdup(args);
         p = MMDAgent_strtok(buf, "|", &q);
         if(MMDAgent_strtailmatch(p, ".mp3") || MMDAgent_strtailmatch(p, ".MP3")) {
            /* if there is a motion file which have the same name, store it */
            if(drop_motion != NULL)
               free(drop_motion);
            drop_motion = MMDAgent_strdup(p);
            i = MMDAgent_strlen(drop_motion);
            drop_motion[i-4] = '.';
            drop_motion[i-3] = 'v';
            drop_motion[i-2] = 'm';
            drop_motion[i-1] = 'd';
            fp = MMDAgent_fopen(drop_motion, "rb");
            if(fp != NULL) {
               fclose(fp);
            } else {
               free(drop_motion);
               drop_motion = NULL;
            }
            /* start mp3 */
            audio_manager.stop(PLUGINAUDIO_DEFAULTALIAS);
            q = (char *) malloc(sizeof(char) * (strlen(PLUGINAUDIO_DEFAULTALIAS) + 1 + strlen(p) + 1));
            sprintf(q, "%s|%s", PLUGINAUDIO_DEFAULTALIAS, p);
            audio_manager.play(q);
            free(q);
         }
         if(buf)
            free(buf);
      } else if(MMDAgent_strequal(type, AUDIOTHREAD_EVENTSTART)) {
         if(drop_motion != NULL) {
            if(MMDAgent_strequal(args, PLUGINAUDIO_DEFAULTALIAS) == true) {
               objs = mmdagent->getModelList();
               for (i = 0; i < mmdagent->getNumModel(); i++) {
                  if (objs[i].isEnable() == true && objs[i].allowMotionFileDrop() == true) {
                     for (motionPlayer = objs[i].getMotionManager()->getMotionPlayerList(); motionPlayer; motionPlayer = motionPlayer->next) {
                        if (motionPlayer->active == true && MMDAgent_strequal(motionPlayer->name, "base") == true) {
                           mmdagent->sendCommandMessage(MMDAGENT_COMMAND_MOTIONCHANGE, "%s|%s|%s", objs[i].getAlias(), "base", drop_motion);
                           break;
                        }
                     }
                     if (!motionPlayer)
                        mmdagent->sendCommandMessage(MMDAGENT_COMMAND_MOTIONADD, "%s|%s|%s|FULL|ONCE|ON|ON", objs[i].getAlias(), "base", drop_motion);
                  }
               }
               mmdagent->resetAdjustmentTimer();
            }
            free(drop_motion);
            drop_motion = NULL;
         }
      }
   }
}
Пример #24
0
/* LogText::render: render log text */
void LogText::render()
{
#ifndef MMDAGENT_DONTRENDERDEBUG
   int i, j, size;
   float w, h, rate;

   if (m_textList == NULL) return;

   w = 0.5f * (float) (m_textWidth) * 0.85f + 1.0f;
   h = 1.0f * (float) (m_textHeight) * 0.85f + 1.0f;

   glPushMatrix();
   glDisable(GL_CULL_FACE);
   glDisable(GL_LIGHTING);
   glScalef(m_textScale, m_textScale, m_textScale);
   glNormal3f(0.0f, 1.0f, 0.0f);

   /* background */
   glColor4f(LOGTEXT_BGCOLOR);
   glBegin(GL_QUADS);
   glVertex3f(m_textX, m_textY, m_textZ);
   glVertex3f(m_textX + w, m_textY, m_textZ);
   glVertex3f(m_textX + w, m_textY + h, m_textZ);
   glVertex3f(m_textX, m_textY + h, m_textZ);
   glEnd();

   /* scroll bar */
   if(m_textHeight < LOGTEXT_MAXNLINES) {
      glColor4f(LOGTEXT_COLOR);
      glBegin(GL_LINE_LOOP);
      glVertex3f(m_textX + w, m_textY, m_textZ + 0.05f);
      glVertex3f(m_textX + w + LOGTEXT_SCROLLBARWIDTH, m_textY, m_textZ + 0.05f);
      glVertex3f(m_textX + w + LOGTEXT_SCROLLBARWIDTH, m_textY + h, m_textZ + 0.05f);
      glVertex3f(m_textX + w, m_textY + h, m_textZ + 0.05f);
      glEnd();
      rate = (float) m_viewIndex / LOGTEXT_MAXNLINES;
      glBegin(GL_QUADS);
      glVertex3f(m_textX + w, m_textY + h * rate, m_textZ + 0.05f);
      glVertex3f(m_textX + w + LOGTEXT_SCROLLBARWIDTH, m_textY + h * rate, m_textZ + 0.05f);
      rate = (float) (m_viewIndex + m_textHeight) / LOGTEXT_MAXNLINES;
      glVertex3f(m_textX + w + LOGTEXT_SCROLLBARWIDTH, m_textY + h * rate, m_textZ + 0.05f);
      glVertex3f(m_textX + w, m_textY + h * rate, m_textZ + 0.05f);
      glEnd();
   }

   /* text */
   glColor4f(LOGTEXT_COLOR);
   glTranslatef(m_textX + 0.5f, m_textY - 0.2f, m_textZ + 0.05f);
   size = LOGTEXT_MAXNLINES < m_textHeight ? LOGTEXT_MAXNLINES : m_textHeight;
   for(i = 0, j = m_textIndex - 1 - m_viewIndex; i < size; i++) {
      if(j < 0)
         j += LOGTEXT_MAXNLINES;
      glTranslatef(0.0f, 0.85f, 0.0f);
      if (MMDAgent_strlen(m_textList[j]) > 0) {
         if (m_lengthList[j] < 0)
            m_lengthList[j] = m_textRenderer->getDisplayListArrayOfString(m_textList[j], m_displayList[j], m_textWidth);
         if (m_lengthList[j] > 0) {
            glPushMatrix();
            m_textRenderer->renderDisplayListArrayOfString(m_displayList[j], m_lengthList[j]);
            glPopMatrix();
         }
      }
      j--;
   }

   glEnable(GL_LIGHTING);
   glEnable(GL_CULL_FACE);
   glPopMatrix();
#endif /* !MMDAGENT_DONTRENDERDEBUG */
}
Пример #25
0
/* postKeyMessage: post key message */
static void postKeyMessage(const char *args)
{
   int i;
   char *buff, *param1, *param2, *param3, *param4, *param5, *save;
   HWND window;
   unsigned int id = 0;
   INPUT input[8];
   int size;
   bool alt = false, ctrl = false, shift = false;
   LPARAM info;

   buff = MMDAgent_strdup(args);
   param1 = MMDAgent_strtok(buff, "|", &save); /* window name */
   param2 = MMDAgent_strtok(NULL, "|", &save); /* key */
   param3 = MMDAgent_strtok(NULL, "|", &save); /* shift-key */
   param4 = MMDAgent_strtok(NULL, "|", &save); /* control-key */
   param5 = MMDAgent_strtok(NULL, "|", &save); /* alt-key */

   /* check */
   if(buff == NULL || param1 == NULL || param2 == NULL) {
      free(buff);
      return;
   }

   /* get window handle */
   window = FindWindowA(param1, NULL);
   if(window == 0) {
      free(buff);
      return;
   }

   /* get key ID */
   if(MMDAgent_strlen(param2) == 1) {
      id = toupper(param2[0]);
   } else {
      for(i = 0; keys[i].name != NULL; i++) {
         if(MMDAgent_strequal(param2, keys[i].name) == true) {
            id = keys[i].id;
            break;
         }
      }
   }
   if(id == 0) {
      free(buff);
      return;
   }

   /* set forground window */
   SetForegroundWindow(window);

   /* get options */
   shift = MMDAgent_strequal(param3, "ON");
   ctrl = MMDAgent_strequal(param4, "ON");
   alt = MMDAgent_strequal(param5, "ON");

   /* create key message */
   size = 0;
   info = GetMessageExtraInfo();
   if(shift == true && id != VK_SHIFT) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_SHIFT;
      input[size].ki.wScan = MapVirtualKey(VK_SHIFT, 0);
      input[size].ki.dwFlags = 0;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(ctrl == true && id != VK_CONTROL) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_CONTROL;
      input[size].ki.wScan = MapVirtualKey(VK_CONTROL, 0);
      input[size].ki.dwFlags = 0;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(alt == true && id != VK_MENU) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_MENU;
      input[size].ki.wScan = MapVirtualKey(VK_MENU, 0);
      input[size].ki.dwFlags = 0;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   input[size].type = INPUT_KEYBOARD;
   input[size].ki.wVk = id;
   input[size].ki.wScan = MapVirtualKey(id, 0);
   input[size].ki.dwFlags = 0;
   input[size].ki.time = 0;
   input[size].ki.dwExtraInfo = info;
   size++;
   input[size].type = INPUT_KEYBOARD;
   input[size].ki.wVk = id;
   input[size].ki.wScan = MapVirtualKey(id, 0);
   input[size].ki.dwFlags = KEYEVENTF_KEYUP;
   input[size].ki.time = 0;
   input[size].ki.dwExtraInfo = info;
   size++;
   if(alt == true && id != VK_MENU) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_MENU;
      input[size].ki.wScan = MapVirtualKey(VK_MENU, 0);
      input[size].ki.dwFlags = KEYEVENTF_KEYUP;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(ctrl == true && id != VK_CONTROL) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_CONTROL;
      input[size].ki.wScan = MapVirtualKey(VK_CONTROL, 0);
      input[size].ki.dwFlags = KEYEVENTF_KEYUP;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }
   if(shift == true && id != VK_SHIFT) {
      input[size].type = INPUT_KEYBOARD;
      input[size].ki.wVk = VK_SHIFT;
      input[size].ki.wScan = MapVirtualKey(VK_SHIFT, 0);
      input[size].ki.dwFlags = KEYEVENTF_KEYUP;
      input[size].ki.time = 0;
      input[size].ki.dwExtraInfo = info;
      size++;
   }

   /* send key message */
   SendInput(size, input, sizeof(INPUT));

   free(buff);
}