Exemplo n.º 1
0
static void do_opt(il_opts *opts, il_string modname, il_opt opt)
{
    for (unsigned i = 0; i < opts->opts.length; i++) {
        il_modopts *modopts = &opts->opts.data[i];
        if (il_string_cmp(modname, modopts->modname)) {
            IL_APPEND(modopts->args, opt);
            return;
        }
    }
    il_modopts modopts;
    memset(&modopts, 0, sizeof(il_modopts));
    modopts.modname = modname;
    IL_APPEND(modopts.args, opt);
    IL_APPEND(opts->opts, modopts);
}
Exemplo n.º 2
0
int ilG_trackPositionable(ilG_context* ctx, il_positionable* self)
{
#define check_null(n) if(!n) {il_error("Null " #n); return 0; }
    // make sure we have valid parameters, several bugs have been caught here
    check_null(ctx);
    check_null(self);
    //check_null(ctx->world);
    //check_null(ctx->world->id);
    check_null(self->drawable);
    check_null(self->material);
    check_null(self->texture);
    check_null(self->drawable->id);
    check_null(self->material->id);
    check_null(self->texture->id);
#undef check_null

    unsigned int i;
    for (i = 0; i < ctx->positionables.length; i++) {
        il_positionable* pos = ctx->positionables.data[i];
        if (pos->drawable->id > self->drawable->id) goto insert;
        if (pos->material->id > self->material->id) goto insert;
        if (pos->texture->id  > self->texture->id)  goto insert;
        continue;
insert:
        IL_INSERT(ctx->positionables, i, self);
        return 1;
    }
    // if we even reach here it means that there are no other drawable-material-texture pairs in the list
    IL_APPEND(ctx->positionables, self);
    return 1;
}
Exemplo n.º 3
0
il_opts il_opt_parse(int argc, char **argv)
{
    il_opts opts;
    memset(&opts, 0, sizeof(il_opts));
    for (int i = 1; i < argc; i++) {\
        if (argv[i][0] != '-') {
            il_string s = il_string_new(argv[i]);
            IL_APPEND(opts.args, s);
            continue;
        }
        il_opt opt;
        char *dot, *start = argv[i] + 1, *equals = strchr(start, '='),  *namestart = start, *nameend = argv[i] + strlen(argv[i]);
        il_string modname = {NULL, 0};
        il_string name    = {NULL, 0};
        il_string arg     = {NULL, 0};
        if (((dot = strchr(start, '.'))) && (!equals || dot < equals)) {
            modname = il_string_bin(start, dot - start);
            namestart = dot+1;
        }
        if (equals) {
            arg = il_string_new(equals+1);
            nameend = equals;
        }
        name = il_string_bin(namestart, nameend - namestart);
        opt = (il_opt){name, arg};
        do_opt(&opts, modname, opt);
    }
    return opts;
}
Exemplo n.º 4
0
static void heightmap_add_positionable(ilG_heightmap *self, il_positionable pos)
{
    IL_APPEND(self->positionables, pos);
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
    IL_ARRAY(char*,) scripts = {0,0,0};
    IL_ARRAY(char*,) script_paths = {0,0,0};
    int opt, idx, has_modules = 0, has_scripts = 0, found_bootstrap = 0, res;
    size_t i;
    ilS_script *s = ilS_new();
    void (*loop)();

    opterr = 0; // we don't want to print an error if another package uses an option
    while ((opt = getopt_long(argc, argv, optstring, longopts, &idx)) != -1) {
        switch(opt) {
            case 0:
            if (strcmp(longopts[idx].name, "scripts") == 0) {
                IL_APPEND(script_paths, strdup(optarg));
                has_scripts = 1;
            }
            break;
            case 'm':
            il_add_module_path(optarg); //IL_APPEND(module_paths, strdup(optarg));
            has_modules = 1;
            break;
            case 'r':
            IL_APPEND(scripts, strdup(optarg));
            break;
            case 'i':
            il_ignore_module(optarg);
            break;
            case 'h':
            printf("IntenseLogic %s\n", il_version);
            printf("Usage: %s [OPTIONS]\n\n", argv[0]);
            printf("Each module may have its own options, see relavent documentation for those.\n\n");
            printf("Options:\n");
            for (i = 0; longopts[i].name; i++) {
                printf(" %c%c %s%-12s %s\n", longopts[i].val? '-' : ' ', 
                       longopts[i].val? longopts[i].val : ' ',
                       longopts[i].name? "--" : "  ",
                       longopts[i].name? longopts[i].name : "",
                       help[i]
                );
            }
            return 0;
            case 'v':
            printf("IntenseLogic %s\n", il_version);
            printf("Built %s\n", __DATE__);
            return 0;
            case '?':
            default:
            break;
        }
    }

    fprintf(stderr, "MAIN: Initializing engine.\n");
    fprintf(stderr, "MAIN: IntenseLogic %s\n", il_version);
    fprintf(stderr, "MAIN: Built %s\n", __DATE__);

    if (!has_modules) {
        il_load_module_dir("modules", argc, argv); // default path
    }
    il_load_module_paths(argc, argv);

    if (!has_scripts) {
        IL_APPEND(script_paths, "script");
    }
    
    for (i = 0; i < script_paths.length; i++) {
        ilS_addPath(s, script_paths.data[i]);
    }
    for (i = 0; i < script_paths.length; i++) {
        char path[strlen(script_paths.data[i]) + strlen("/bootstrap.lua") + 1];
        sprintf(path, "%s/bootstrap.lua", script_paths.data[i]);
        if (!access(path, F_OK)) { // returns 0 on success
            ilS_fromFile(s, path);
            found_bootstrap = 1;
            break;
        }
    }
    if (!found_bootstrap) {
        fprintf(stderr, "MAIN: Could not find bootstrap.lua\n");
        return 1;
    }
    res = ilS_run(s);
    if (res != 0) {
        fprintf(stderr, "MAIN: %s\n", s->err);
        return 1;
    }
    for (i = 0; i < scripts.length; i++) {
        ilS_fromFile(s, scripts.data[i]);
        free(scripts.data[i]);
        res = ilS_run(s);
        if (res != 0) {
            fprintf(stderr, "MAIN: %s\n", s->err);
        }
    }
    /*for (i = 0; i < script_paths.length; i++) {
        free(script_paths.data[i]);
    }*/ // TODO: stop leaking memory here because of weird segfault bug
    IL_FREE(script_paths);
    IL_FREE(scripts);

    // main loop
    fprintf(stderr, "MAIN: Starting main loop\n");
    loop = (void(*)())il_get_symbol("ilcommon", "ilE_loop");
    if (!loop) {
        return 1;
    }
    loop();

    return 0;
}
Exemplo n.º 6
0
void ilG_texture_assignId(ilG_texture* self)
{
    if (self->id) return;
    self->id = texture_indices.length+1;
    IL_APPEND(texture_indices, self);
}
Exemplo n.º 7
0
void ilG_material_assignId(ilG_material* self)
{
    if (self->id) return;
    self->id = material_indices.length+1;
    IL_APPEND(material_indices, self);
}
Exemplo n.º 8
0
void ilG_drawable3d_assignId(ilG_drawable3d* self)
{
    if (self->id) return; // already has an ID???
    self->id = drawable_indices.length+1;
    IL_APPEND(drawable_indices, self);
}
Exemplo n.º 9
0
static void context_add_renderer(void *ptr, ilG_renderer r)
{
    ilG_context *self = ptr;
    IL_APPEND(self->renderers, r);
}