Beispiel #1
0
static int load_file(const char* file_path, int offset_block, int blocks) {
    printf("Try to load:%s", file_path);
    if (blocks) {
        printf(", offset block:%d, blocks:%d\n", offset_block, blocks);
    } else {
        printf("\n");
    }
    bool ret = false;
    resource_content content;
    snprintf(content.path, sizeof(content.path), "%s", file_path);
    content.load_addr = 0;
    if (!get_content(&content)) {
        goto end;
    }
    if (!blocks) {
        if (!load_content(&content)) {
            goto end;
        }
    } else {
        void* data = malloc(blocks * BLOCK_SIZE);
        if (!data)
            goto end;
        if (!load_content_data(&content, offset_block, data, blocks)) {
            goto end;
        }
    }
    ret = true;
end:
    free_content(&content);
    return ret;
}
Beispiel #2
0
void open_callback(Fl_Widget* w)
{
    int allowed = 1;
    if (*CurrentFileSpec_str && Unsaved) {
        allowed = fl_choice("    Opening a new file now will discard unsaved work     ", 
                            "  Cancel open  ", "  Discard and open a new file  ", NULL);
    }
    
    if (allowed) {
        load_content(NULL);
    }
}
Beispiel #3
0
/**
 * content_init_file:
 *
 * Initializes and loads a content file for the currently
 * selected libretro core.
 *
 * Returns : true if successful, otherwise false.
 **/
static bool content_init_file(struct string_list *temporary_content)
{
   unsigned i;
   struct retro_game_info               *info = NULL;
   bool ret                                   = false;
   struct string_list* additional_path_allocs = NULL;
   struct string_list *content                = NULL;
   const struct retro_subsystem_info *special = NULL;
   rarch_system_info_t *system                = NULL;
   global_t *global                           = global_get_ptr();

   runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);

   if (*global->subsystem)
   {
      special = init_content_file_subsystem(&ret, system);
      if (!ret)
         goto error;
   }

   content = string_list_new();

   if (!content)
      goto error;

   if (!init_content_file_set_attribs(temporary_content,
            content, system, special))
      goto error;

   info                   = (struct retro_game_info*)
      calloc(content->size, sizeof(*info));
   additional_path_allocs = string_list_new();

   ret = load_content(temporary_content,
         info, content, special, additional_path_allocs); 

   for (i = 0; i < content->size; i++)
      free((void*)info[i].data);

   string_list_free(additional_path_allocs);
   if (info)
      free(info);

error:
   if (content)
      string_list_free(content);
   return ret;
}
Beispiel #4
0
void compile_shader(GLuint shader, const char *path)
{
    char *content;
    load_content(path, &content);
    const char *sources[] = { content };

    glShaderSource(shader, 1, sources, NULL/*null terminated strings*/);
    free(content);
    glCompileShader(shader);
    GLint compileStatus;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
    if (compileStatus != GL_TRUE)
    {
         GLint logLength;
         glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
         GLchar *infoLog = calloc(logLength+1, sizeof(char));
         glGetShaderInfoLog(shader, logLength, NULL, infoLog);
         fprintf(stderr, "failed to compile %s: %s\n", path, infoLog);
         free(infoLog);
         exit(EXIT_FAILURE);
    }
}
Beispiel #5
0
/**
 * content_init_file:
 *
 * Initializes and loads a content file for the currently
 * selected libretro core.
 *
 * Returns : true if successful, otherwise false.
 **/
static bool content_file_init(struct string_list *temporary_content)
{
   struct retro_game_info               *info = NULL;
   struct string_list *content                = NULL;
   bool ret                                   = false;
   const struct retro_subsystem_info *special = init_content_file_subsystem(&ret);

   if (!ret)
      goto error;

   content = string_list_new();

   if (!content)
      goto error;

   if (!init_content_file_set_attribs(temporary_content,
            content, special))
      goto error;

   info                   = (struct retro_game_info*)
      calloc(content->size, sizeof(*info));

   if (info)
   {
      unsigned i;
      ret = load_content(temporary_content, info, content, special);

      for (i = 0; i < content->size; i++)
         free((void*)info[i].data);

      free(info);
   }

error:
   if (content)
      string_list_free(content);
   return ret;
}
Beispiel #6
0
bool init_content_file(void)
{
   unsigned i;

   g_extern.temporary_content = string_list_new();
   if (!g_extern.temporary_content)
      return false;

   const struct retro_subsystem_info *special = NULL;

   if (*g_extern.subsystem)
   {
      special = libretro_find_subsystem_info(g_extern.system.special,
            g_extern.system.num_special, g_extern.subsystem);

      if (!special)
      {
         RARCH_ERR(
               "Failed to find subsystem \"%s\" in libretro implementation.\n",
               g_extern.subsystem);
         return false;
      }

      if (special->num_roms && !g_extern.subsystem_fullpaths)
      {
         RARCH_ERR("libretro core requires special content, but none were provided.\n");
         return false;
      }
      else if (special->num_roms && special->num_roms
            != g_extern.subsystem_fullpaths->size)
      {
         RARCH_ERR("libretro core requires %u content files for subsystem \"%s\", but %u content files were provided.\n",
               special->num_roms, special->desc,
               (unsigned)g_extern.subsystem_fullpaths->size);
         return false;
      }
      else if (!special->num_roms && g_extern.subsystem_fullpaths
            && g_extern.subsystem_fullpaths->size)
      {
         RARCH_ERR("libretro core takes no content for subsystem \"%s\", but %u content files were provided.\n",
               special->desc,
               (unsigned)g_extern.subsystem_fullpaths->size);
         return false;
      }
   }

   union string_list_elem_attr attr;
   attr.i = 0;

   struct string_list *content = (struct string_list*)string_list_new();
   if (!content)
      return false;

   if (*g_extern.subsystem)
   {
      for (i = 0; i < g_extern.subsystem_fullpaths->size; i++)
      {
         attr.i  = special->roms[i].block_extract;
         attr.i |= special->roms[i].need_fullpath << 1;
         attr.i |= special->roms[i].required << 2;
         string_list_append(content,
               g_extern.subsystem_fullpaths->elems[i].data, attr);
      }
   }
   else
   {
      attr.i  = g_extern.system.info.block_extract;
      attr.i |= g_extern.system.info.need_fullpath << 1;
      attr.i |= (!g_extern.system.no_content) << 2;
      string_list_append(content,
            g_extern.libretro_no_content ? "" : g_extern.fullpath, attr);
   }

#ifdef HAVE_ZLIB
   /* Try to extract all content we're going to load if appropriate. */
   for (i = 0; i < content->size; i++)
   {
      /* Block extract check. */
      if (content->elems[i].attr.i & 1)
         continue;

      const char *ext = path_get_extension(content->elems[i].data);

      const char *valid_ext = special ?
         special->roms[i].valid_extensions :
         g_extern.system.info.valid_extensions;

      if (ext && !strcasecmp(ext, "zip"))
      {
         char temporary_content[PATH_MAX];
         strlcpy(temporary_content, content->elems[i].data,
               sizeof(temporary_content));

         if (!zlib_extract_first_content_file(temporary_content,
                  sizeof(temporary_content), valid_ext,
                  *g_settings.extraction_directory ?
                  g_settings.extraction_directory : NULL))
         {
            RARCH_ERR("Failed to extract content from zipped file: %s.\n",
                  temporary_content);
            string_list_free(content);
            return false;
         }
         string_list_set(content, i, temporary_content);
         string_list_append(g_extern.temporary_content,
               temporary_content, attr);
      }
   }
#endif

   /* Set attr to need_fullpath as appropriate. */
   
   bool ret = load_content(special, content);
   string_list_free(content);
   return ret;
}
Beispiel #7
0
int test_charge(int argc, char** argv) {
    const char* desc;
    if (argc > 0) {
        desc = argv[0];
    } else {
        desc = DEF_CHARGE_DESC_PATH;
    }

    resource_content content;
    snprintf(content.path, sizeof(content.path), "%s", desc);
    content.load_addr = 0;
    if (!get_content(&content)) {
        goto end;
    }
    if (!load_content(&content)) {
        goto end;
    }

    char* buf = (char*)content.load_addr;
    char* end = buf + content.content_size - 1;
    *end = '\0';
    LOGD("desc:\n%s", buf);

    int pos = 0;
    while (1) {
        char* line = (char*) memchr(buf + pos, '\n', strlen(buf + pos));
        if (!line)
            break;
        *line = '\0';
        LOGD("splite:%s", buf + pos);
        pos += (strlen(buf + pos) + 1);
    }

    int delay = 900;
    int only_current_level = false;
    anim_level_conf* level_confs = NULL;
    int level_conf_pos = 0;
    int level_conf_num = 0;

    while (true) {
        if (buf >= end)
            break;
        const char* arg = buf;
        buf += (strlen(buf) + 1);

        LOGD("parse arg:%s", arg);
        if (!memcmp(arg, OPT_CHARGE_ANIM_LEVEL_CONF,
                    strlen(OPT_CHARGE_ANIM_LEVEL_CONF))) {
            if (!level_confs) {
                LOGE("Found level conf before levels!");
                goto end;
            }
            if (level_conf_pos >= level_conf_num) {
                LOGE("Too many level confs!(%d >= %d)", level_conf_pos, level_conf_num);
                goto end;
            }
            if (!parse_level_conf(arg, level_confs + level_conf_pos)) {
                LOGE("Failed to parse level conf:%s", arg);
                goto end;
            }
            level_conf_pos ++;
        } else if (!memcmp(arg, OPT_CHARGE_ANIM_DELAY,
                    strlen(OPT_CHARGE_ANIM_DELAY))) {
            delay = atoi(arg + strlen(OPT_CHARGE_ANIM_DELAY));
            LOGD("Found delay:%d", delay);
        } else if (!memcmp(arg, OPT_CHARGE_ANIM_LOOP_CUR,
                    strlen(OPT_CHARGE_ANIM_LOOP_CUR))) {
            only_current_level =
                !memcmp(arg + strlen(OPT_CHARGE_ANIM_LOOP_CUR), "true", 4);
            LOGD("Found only_current_level:%d", only_current_level);
        } else if (!memcmp(arg, OPT_CHARGE_ANIM_LEVELS,
                    strlen(OPT_CHARGE_ANIM_LEVELS))) {
            if (level_conf_num) {
                goto end;
            }
            level_conf_num = atoi(arg + strlen(OPT_CHARGE_ANIM_LEVELS));
            if (!level_conf_num) {
                goto end;
            }
            level_confs =
                (anim_level_conf*) malloc(level_conf_num * sizeof(anim_level_conf));
            LOGD("Found levels:%d", level_conf_num);
        } else {
            LOGE("Unknown arg:%s", arg);
            goto end;
        }
    }

    if (level_conf_pos != level_conf_num || !level_conf_num) {
        LOGE("Something wrong with level confs!");
        goto end;
    }

    int i = 0, j = 0, k = 0;
    for (i = 0; i < level_conf_num; i++) {
        if (!level_confs[i].delay) {
            level_confs[i].delay = delay;
        }
        if (!level_confs[i].delay) {
            LOGE("Missing delay in level conf:%d", i);
            goto end;
        }
        for (j = 0; j < i; j++) {
            if (level_confs[j].max_level == level_confs[i].max_level) {
                LOGE("Dup level conf:%d", i);
                goto end;
            }
            if (level_confs[j].max_level > level_confs[i].max_level) {
                anim_level_conf conf = level_confs[i];
                memmove(level_confs + j + 1, level_confs + j,
                        (i - j) * sizeof(anim_level_conf));
                level_confs[j] = conf;
            }
        }
    }

    printf("Parse anim desc(%s):\n", desc);
    printf("only_current_level=%d\n", only_current_level);
    printf("level conf:\n");
    for (i = 0; i < level_conf_num; i++) {
        printf("\tmax=%d, delay=%d, num=%d, prefix=%s\n",
                level_confs[i].max_level, level_confs[i].delay,
                level_confs[i].num, level_confs[i].prefix);
    }

end:
    free_content(&content);
    return 0;
}
Beispiel #8
0
/**
 * init_content_file:
 *
 * Initializes and loads a content file for the currently
 * selected libretro core.
 *
 * global->content_is_init will be set to the return value
 * on exit.
 *
 * Returns : true if successful, otherwise false.
 **/
bool init_content_file(void)
{
   unsigned i;
   union string_list_elem_attr attr;
   bool ret                                   = false;
   struct string_list *content                = NULL;
   const struct retro_subsystem_info *special = NULL;
   settings_t *settings                       = config_get_ptr();
   rarch_system_info_t *system                = rarch_system_info_get_ptr();
   global_t   *global                         = global_get_ptr();

   global->temporary_content                  = string_list_new();

   if (!global->temporary_content)
      goto error;

   if (*global->subsystem)
   {
      special = libretro_find_subsystem_info(system->special,
            system->num_special, global->subsystem);

      if (!special)
      {
         RARCH_ERR(
               "Failed to find subsystem \"%s\" in libretro implementation.\n",
               global->subsystem);
         goto error;
      }

      if (special->num_roms && !global->subsystem_fullpaths)
      {
         RARCH_ERR("libretro core requires special content, but none were provided.\n");
         goto error;
      }
      else if (special->num_roms && special->num_roms
            != global->subsystem_fullpaths->size)
      {
         RARCH_ERR("libretro core requires %u content files for subsystem \"%s\", but %u content files were provided.\n",
               special->num_roms, special->desc,
               (unsigned)global->subsystem_fullpaths->size);
         goto error;
      }
      else if (!special->num_roms && global->subsystem_fullpaths
            && global->subsystem_fullpaths->size)
      {
         RARCH_ERR("libretro core takes no content for subsystem \"%s\", but %u content files were provided.\n",
               special->desc,
               (unsigned)global->subsystem_fullpaths->size);
         goto error;
      }
   }

   content = string_list_new();

   attr.i = 0;

   if (!content)
      goto error;

   if (*global->subsystem)
   {
      for (i = 0; i < global->subsystem_fullpaths->size; i++)
      {
         attr.i  = special->roms[i].block_extract;
         attr.i |= special->roms[i].need_fullpath << 1;
         attr.i |= special->roms[i].required << 2;
         string_list_append(content,
               global->subsystem_fullpaths->elems[i].data, attr);
      }
   }
   else
   {
      attr.i  = system->info.block_extract;
      attr.i |= system->info.need_fullpath << 1;
      attr.i |= (!system->no_content) << 2;
      string_list_append(content,
            (global->inited.core.no_content && settings->core.set_supports_no_game_enable) ? "" : global->path.fullpath, attr);
   }

#ifdef HAVE_ZLIB
   /* Try to extract all content we're going to load if appropriate. */
   for (i = 0; i < content->size; i++)
   {
      const char *ext       = NULL;
      const char *valid_ext = NULL;

      /* Block extract check. */
      if (content->elems[i].attr.i & 1)
         continue;

      ext       = path_get_extension(content->elems[i].data);
      valid_ext = special ? special->roms[i].valid_extensions :
         system->info.valid_extensions;

      if (ext && !strcasecmp(ext, "zip"))
      {
         char temporary_content[PATH_MAX_LENGTH] = {0};

         strlcpy(temporary_content, content->elems[i].data,
               sizeof(temporary_content));

         if (!zlib_extract_first_content_file(temporary_content,
                  sizeof(temporary_content), valid_ext,
                  *settings->extraction_directory ?
                  settings->extraction_directory : NULL))
         {
            RARCH_ERR("Failed to extract content from zipped file: %s.\n",
                  temporary_content);
            goto error;
         }
         string_list_set(content, i, temporary_content);
         string_list_append(global->temporary_content,
               temporary_content, attr);
      }
   }
#endif

   /* Set attr to need_fullpath as appropriate. */
   ret = load_content(special, content);

error:
   global->inited.content = (ret) ? true : false;

   if (content)
      string_list_free(content);
   return ret;
}
Beispiel #9
0
int main(int argc, char **argv) {
    // Check command-line options
    char *p;
    int a = 1;
    Fl::args(argc, argv, a);
    Fl::scheme(NULL);  // NULL causes libr. to look up style in .Xdefaults

    memset(ExprEntry_str, '\0', sizeof(ExprEntry_str));
    clear_content();

/*    
    printf("fround(0.0) is %1.2lf\n", fround(0.0));
    printf("fround(0.1) is %1.2lf\n", fround(0.1));
    printf("fround(0.49) is %1.2lf\n", fround(0.49));
    printf("fround(0.50) is %1.2lf\n", fround(0.50));
    printf("fround(0.51) is %1.2lf\n", fround(0.51));
    printf("fround(0.9) is %1.2lf\n", fround(0.9));
    printf("fround(1.0) is %1.2lf\n", fround(1.0));
    printf("fround(1.1) is %1.2lf\n", fround(1.1));
    printf("fround(-0.1) is %1.2lf\n", fround(-0.1));
    printf("fround(-0.4) is %1.2lf\n", fround(-0.4));
    printf("fround(-0.5) is %1.2lf\n", fround(-0.5));
    printf("fround(-0.51) is %1.2lf\n", fround(-0.51));
    printf("fround(-0.9) is %1.2lf\n", fround(-0.9));
    printf("fround(-1.0) is %1.2lf\n", fround(-1.0));
    printf("fround(-1.1) is %1.2lf\n", fround(-1.1));
    printf("fround(-1.4) is %1.2lf\n", fround(-1.4));
    printf("fround(-1.5) is %1.2lf\n", fround(-1.5));
    printf("fround(-1.6) is %1.2lf\n", fround(-1.6));
    printf("fround(-1.9) is %1.2lf\n", fround(-1.9));
    printf("\n");
    
    printf("123.34 has %d significant digits\n", sig_digits(123.45));
    printf("7 has %d significant digits\n", sig_digits(7));
    printf("654.00001 has %d significant digits\n", sig_digits(654.00001));
    printf("-123.34 has %d significant digits\n", sig_digits(-123.45));
    printf("-7 has %d significant digits\n", sig_digits(-7));
    printf("-654.00001 has %d significant digits\n", sig_digits(-654.00001));
    printf("1.234e10 has %d significant digits\n", sig_digits(1.234e10));
    printf("0.0001200560000 has %d significant digits\n", sig_digits(0.0001200560000));
    printf("-1.20056e-4 has %d significant digits\n", sig_digits(-1.20056e-4));

    //return 0;
*/    
    char num_str[8];
    int i;
    for(i = 0; i < MAXENTRY; i++) {
        sprintf(num_str, "%d\n", i);
        strcat(RowLabels_str, num_str);
    }

    //printf("argc is %d\n", argc); fflush(0);
    char cmdline_expr[MAXENTRYLEN] = "";
    char expr_prepped_str[MAXENTRYLEN] = "";
    while (a < argc) {
        p = argv[a];
        if (*p == '-' && *(p+1) == '-') {
            // OK, it's some kind of option
            char option = *(p+2);
            if (option == 't') {
                // Change terseness/verbosity threshold
                if (*(p+3)) {
                    SayThreshold = *(p+3) - '0';
                    SAY(1, "Terseness level is %d\n", SayThreshold); 
                }
                else if (a+1 < argc) {
                    a++;
                    p = argv[a];
                    SayThreshold = *p - '0';
                    SAY(1, "Terseness level is %d\n", SayThreshold); 
                }
            }
            else if (option == 'd') {
                // Change angle encoding to degrees 
                AngleUnitsAreDegrees = 1;
                SAY(1, "Angles expressed as degrees\n"); 
            }
            else if (option == 'r') {
                // Change angle encoding to radians 
                AngleUnitsAreDegrees = 0;
                SAY(1, "Angles expressed as radians\n"); 
            }
            else if (option == 'p') {
                // Switch to Reverse Polish Notation (RPN) entry syntax
                InputMode = RPN_INPUT;
                SAY(1, "Input syntanx mode is RPN (Reverse Polish Notation)\n"); fflush(0);
            }
            else if (option == 'v') {
                // Print name and version 
                update_main_win_title();
                printf("%s\n", Title_str); fflush(0);
            }
            else if (option == 'f') {
                // Pre-load a specific workspace content file 
                char filespec_str[MAXENTRYLEN] = "";
                if (*(p+3)) {
                    strcpy (CurrentFileSpec_str, (p+3));
                }
                else {
                    a++;
                    if (*argv[a]) {
                        strcpy (CurrentFileSpec_str, argv[a]);
                    }
                }
                if (!*CurrentFileSpec_str) {
                    fl_alert("File not specified!\n");
                }
            }
            a++;
        }
        else {
            // assume the remainder of command-line is math expression
            while (a < argc) {
                strncat(cmdline_expr, argv[a], 32);
                strcat(cmdline_expr, " ");
                a++;
            }
            SAY(1, "Commandline expression is '%s'\n", cmdline_expr);
            if (strlen(cmdline_expr)) {
                int rc = calculate_expr(cmdline_expr, ExprEntry_str[Result], Result);
                if (rc == CALC_SUCCESS) {
                    char result_str[64];
                    render_item(result_str, &ResultList[Result]);
                    printf("%s = %s\n", ExprEntry_str[Result], result_str);
                    return 0;
                }
                else {
                    if (rc == CALC_UNBALANCED) {
                        printf("Expression is unbalanced! Check parentheses carefully.\n");
                    }
                    else if (rc == CALC_ERROR) {
                        printf("Expression cannot be calculated!\n");
                    }
                    return 1;
                }
            }
        }
    }
    //fl_register_images();
    update_main_win_title();
    MainWin_p = new Fl_Window(560,352, Title_str);

    MainWin_p->begin();
    
    Fl_Scroll expr_win_scroll(6, 12, 546, 258);
    expr_win_scroll.begin();    
    Fl_Pack expr_win_group(6, 12, 546, 1024);
    expr_win_group.type(FL_HORIZONTAL);
    expr_win_group.begin();
  
    RowLabels_p = new Fl_Multiline_Output(6, 12,  30, 1024 );
    RowLabels_p->box(FL_FLAT_BOX);
    RowLabels_p->color(FL_BACKGROUND_COLOR);
    RowLabels_p->align(FL_ALIGN_RIGHT);
    RowLabels_p->value(RowLabels_str);
    
    WorkArea_p = new Fl_Multiline_Input(40, 10,  500, 1024 );
    WorkArea_p->box(FL_FLAT_BOX);
    WorkArea_p->label("");
    WorkArea_p->when(FL_WHEN_ENTER_KEY);
    WorkArea_p->callback(workarea_callback);
    WorkArea_p->take_focus();
    update_results_display();
    WorkArea_p->position(0,0);
    expr_win_group.end();
    expr_win_scroll.end();
    
    QuitBtn_p =  new Fl_Button(30, 280, 60, 30, "Quit");
    QuitBtn_p->callback(quit_callback);
    QuitBtn_p->shortcut(FL_Escape);
        
    OpenBtn_p =  new Fl_Button(120, 280, 60, 30, "Open...");
    OpenBtn_p->callback(open_callback);
    OpenBtn_p->shortcut(FL_CTRL + 'o');
        
    SaveBtn_p =  new Fl_Button(210, 280, 60, 30, "Save...");
    SaveBtn_p->callback(save_callback);
    SaveBtn_p->deactivate();
    SaveBtn_p->shortcut(FL_CTRL + 's');
        
    ClearBtn_p =  new Fl_Button(300, 280, 60, 30, "Clear");
    ClearBtn_p->callback(clear_callback);
    ClearBtn_p->shortcut(FL_CTRL + 'c');

    HintBtn_p =  new Fl_Button(420, 280, 30, 30, "!");
    HintBtn_p->callback(hint_callback);
    HintBtn_p->tooltip("Hints");
    HintBtn_p->shortcut(FL_CTRL + 'i');

    AboutBtn_p =  new Fl_Button(460, 280, 30, 30, "a");
    AboutBtn_p->callback(about_callback);
    AboutBtn_p->tooltip("About Flume");
    AboutBtn_p->shortcut(FL_CTRL + 'a');

    HelpBtn_p =  new Fl_Button(500, 280, 30, 30, "?");
    HelpBtn_p->callback(help_callback);
    HelpBtn_p->tooltip("Help (F1)");
    HelpBtn_p->shortcut(FL_F + 1);

    Fl_Box* pAngleLabel = new Fl_Box(20, 325, 40, 12, "Angles:");
    pAngleLabel->box(FL_FLAT_BOX);
    RadAngleBtn_p = new Fl_Round_Button(72, 324, 80, 16, "Radians");
    RadAngleBtn_p->value(AngleUnitsAreDegrees ? 0 : 1);
    RadAngleBtn_p->callback(radians_callback);

    DegAngleBtn_p = new Fl_Round_Button(152, 324, 80, 16, "Degrees");
    DegAngleBtn_p->value(AngleUnitsAreDegrees ? 1 : 0);
    DegAngleBtn_p->callback(degrees_callback);
    
    RpnModeChk_p = new Fl_Check_Button(280, 324, 96, 16, "RPN mode");
    RpnModeChk_p->value((InputMode == RPN_INPUT) ? 1 : 0);
    RpnModeChk_p->callback(rpn_callback);
    
    TrackSigChk_p = new Fl_Check_Button(392, 324, 140, 16, "Track significance");
    TrackSigChk_p->value(TrackSignificance);
    TrackSigChk_p->callback(track_sig_callback);
    
    MainWin_p->end();
    
    if (*CurrentFileSpec_str) {
        if (!load_content(CurrentFileSpec_str)) {
            fl_alert("File not loadable!\n");
        }
    }
    
    MainWin_p->show(argc, argv);
    Running = 1;
    while(Running && Fl::wait());
    return 0;
}
Beispiel #10
0
bool Simulation::setup(const GLuint windowWidth, const GLuint windowHeight, const GLuint viewportWidth, const GLuint viewportHeight, AssetLoader& assetLoader)
{   
   setup_rand();
   
   this->windowWidth = windowWidth;
   this->windowHeight = windowHeight;
   this->viewportWidth = viewportWidth;
   this->viewportHeight = viewportHeight;

   const char VertexShaderCode[] = 
      "attribute vec4 a_position;      \n"
      "attribute lowp vec4 a_color;    \n"
      "varying lowp vec4 v_color;      \n"
      "                                \n"
      "void main() {                   \n"
      "   gl_Position = a_position;    \n"
      "   v_color = a_color;           \n"
      "}                               \n";

   const char FragmentShaderCode[] = 
      "precision mediump float;        \n"
      "varying lowp vec4 v_color;      \n"
      "void main() {                   \n"
      "  gl_FragColor = v_color;       \n"
      "}                               \n";

   program = createProgram(VertexShaderCode, FragmentShaderCode);
   if(!program)
   {
      LOGE("Could not create program.");
      return false;
   }

   // Load shader attribute locations
   positionAttribute = glGetAttribLocation(program, "a_position");
   checkGlError("glGetAttribLocation");
   LOGI("glGetAttribLocation(\"a_position\") = %d\n", positionAttribute);

   colorAttribute = glGetAttribLocation(program, "a_color");
   checkGlError("glGetAttribLocation");
   LOGI("glGetAttribLocation(\"a_color\") = %d\n", colorAttribute);

   // Load triangle currentBuffer
   glGenBuffers(1, &vboId);
   checkGlError("glGenBuffers");

   glBindBuffer(GL_ARRAY_BUFFER, vboId);
   checkGlError("glBindBuffer");

   // Set the currentBuffer's data
   glBufferData(GL_ARRAY_BUFFER, Constants::MaximumVertexCount * sizeof(ColorVertex), &currentVertices[0], GL_DYNAMIC_DRAW);
   checkGlError("glBufferData");
      
   // Create image buffers
   const int BufferSize = viewportWidth*viewportHeight*4; /* RGBA format*/
   currentBuffer = new unsigned char[BufferSize];
   std::fill_n(currentBuffer, BufferSize, 0);

   targetBuffer = new unsigned char[BufferSize];
   std::fill_n(targetBuffer, BufferSize, 0);
   
   if(!create_render_target())
   {
      LOGE("Could not create render target!");
      return false;
   }
   
   LOGW("Integer Sizes: %d %d", sizeof(unsigned long), sizeof(unsigned long));
   LOGI("Success engine_init_display");
      
   if(!load_content(assetLoader))
   {
      LOGE("Could not load content!");
      return false;
   }

   create_random_triangles();
   copy_current_to_best_triangles();
   LOGI("Simulation is ready to go.");
   return true;
}
Beispiel #11
0
int main(int argc, char *argv[]) {
	if (!init()) {
		return 1;
	}

	if (!load_content()) {
		return 1;
	}

	minefield_t minefield;
	minefield_reset(&minefield, MINEFIELD_WIDTH, MINEFIELD_HEIGHT);

	buttons = (button_t *)malloc(sizeof(button_t) * MINEFIELD_COUNT);

	int b = 0;
	for (int i = 0; i < MINEFIELD_WIDTH; ++i) {
		for (int j = 0; j < MINEFIELD_HEIGHT; ++j) {
			button_reset(
				i * 32, 
				j * 32 + 32,
				BUTTON_SIZE,
				BUTTON_SIZE,
				&buttons[b]
			);
			buttons[b].gx = i;
			buttons[b].gy = j;
			buttons[b].data = &minefield.blocks[b];
			++b;
		}
	}

	g_resetButton = button_new(SCREEN_WIDTH / 2 - 32, 0, 64, 32);
	g_resetButton->text = "reset";
	g_resetButton->showText = true;

	g_mouse.x = 0;
	g_mouse.y = 0;
	g_mouse.clickDown = false;

	strtextures_init();
	strtextures_add("0");
	strtextures_add("1");
	strtextures_add("2");
	strtextures_add("3");
	strtextures_add("4");
	strtextures_add("5");
	strtextures_add("6");
	strtextures_add("7");
	strtextures_add("8");
	strtextures_add("9");
	strtextures_add("reset");

	bool running = true;
	SDL_Event sdlEvent;

	while (running) {
		while (SDL_PollEvent(&sdlEvent) != 0) {
			switch (sdlEvent.type) {
			case SDL_QUIT:
				running = false;
				break;

			case SDL_KEYDOWN:
				switch (sdlEvent.key.keysym.sym) {
					case SDLK_ESCAPE:
						running = false;
						break;
				}
				break;

			case SDL_MOUSEMOTION:
				SDL_GetMouseState(&(g_mouse.x), &(g_mouse.y));
				break;

			case SDL_MOUSEBUTTONDOWN:
				SDL_GetMouseState(&(g_mouse.x), &(g_mouse.y));

				button_t *current;

				for (int b = 0; b < MINEFIELD_COUNT; ++b) {
					if (button_contains(&buttons[b],
										g_mouse.x,
										g_mouse.y)) {
						current = &buttons[b];
					}
				}				

				if (sdlEvent.button.button == SDL_BUTTON_LEFT) {
					g_mouse.clickDown = true;

					if (!current->data->flagged) {
						g_mouse.selectedX = current->gx;
						g_mouse.selectedY = current->gy;
					}					
				} else if (sdlEvent.button.button == SDL_BUTTON_RIGHT) {
					current->data->flagged = !current->data->flagged;
				}
				break;

			case SDL_MOUSEBUTTONUP:
				SDL_GetMouseState(&(g_mouse.x), &(g_mouse.y));

				if (sdlEvent.button.button == SDL_BUTTON_LEFT) {
					g_mouse.clickDown = false;


					int32_t index = xy_to_index(g_mouse.selectedX,
						g_mouse.selectedY,
						minefield.width,
						minefield.height);

					if (button_contains(&buttons[index],
						g_mouse.x, g_mouse.y)) {
						if (!minefield.seeded) {
							minefield_seed_mines(&minefield,
								10,
								g_mouse.selectedX,
								g_mouse.selectedY);					
						}

						minefield_reveal(&minefield, 
							g_mouse.selectedX,
							g_mouse.selectedY);
					}
				}
				break;
			}
		}

		SDL_SetRenderDrawColor(g_renderer, 0, 0, 0, 255);
		SDL_RenderClear(g_renderer);

		for (int button = 0; button < MINEFIELD_COUNT; ++button) {
			button_update_state(&buttons[button], &g_mouse);
			mine_button_render(&buttons[button]);
		}

		button_update_state(g_resetButton, &g_mouse);
		button_render(g_resetButton);

		SDL_RenderPresent(g_renderer);
	}

	cleanup();

	return 0;
}