value::object_view value::as_object() & { return object_view(begin_object(), end_object()); }
int main(int argc, char *argv[]) { World *w; View *view; Intent *intent; Graphics_info *ginfo; Tcl_Interp *interp; Object *me; Boolean quit = False; #if PROFILE int fps_count = 0; double total_time = 0.0; double start_time; #endif interp = Tcl_CreateInterp(); updater = updater_create(interp); if (argc != 2) { fprintf(stderr, "Usage: %s <world file>\n", argv[0]); exit(EXIT_FAILURE); } ginfo = init_graphics(); #define TRUECOLOR #ifdef TRUECOLOR set_texture_trans(32, ginfo->palette.color_lookup); #else set_texture_trans(ginfo->palette.rgb_cube_size, ginfo->palette.color_lookup); #endif init_renderer(ginfo->width, ginfo->height); init_input_devices(); /* Initialize the view */ view = new_view(FLOAT_TO_FIXED(3.14159265 / 2.0)); w = new_world(); parser_init(interp, w); if (Tcl_EvalFile(interp, WT_INIT_FILENAME) != TCL_OK) { fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorCode", 0)); fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorInfo", 0)); exit(1); } if (Tcl_EvalFile(interp, argv[1]) != TCL_OK) { fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorCode", 0)); fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorInfo", 0)); exit(1); } while (!quit) { double sin_facing, cos_facing; double fx, fy, fz, torque; Framebuffer *fb; int i; start_time = current_time(); intent = read_input_devices(); me = get_controlled_object(); if (me == NULL) fatal_error("No controlled object"); for (i = 0; i < intent->n_special; i++) { switch (intent->special[i]) { case INTENT_END_GAME: quit = True; (void) Tcl_Eval(interp, "action_quit"); break; case INTENT_JUMP: (void) Tcl_Eval(interp, "action_jump"); break; case INTENT_ACTION1: (void) Tcl_Eval(interp, "action_1"); break; case INTENT_ACTION2: (void) Tcl_Eval(interp, "action_2"); break; case INTENT_ACTION3: (void) Tcl_Eval(interp, "action_3"); break; case INTENT_ACTION4: (void) (Tcl_Eval(interp, "action_4") != TCL_OK); break; case INTENT_ACTION5: (void) Tcl_Eval(interp, "action_5"); break; default: break; } } /* Determine forces on viewer. */ sin_facing = sin(me->angle); cos_facing = cos(me->angle); fx = cos_facing * intent->force_x - sin_facing * intent->force_y; fy = sin_facing * intent->force_x + cos_facing * intent->force_y; fz = -0.05 * me->mass; /* gravity */ torque = intent->force_rotate; /* Apply the forces. */ object_apply_force(me, fx, fy, fz); object_apply_torque(me, torque); object_update(me); if (me->z <= 0.0 && me->dz <= 0.0) { me->z = 0.0; me->dz = 0.0; } /* Determine the view. */ me = get_viewpoint_object(); if (me == NULL) fatal_error("No viewpoint object"); object_view(me, view); updater_run(updater); /* Display the world. */ fb = render(w, view); update_screen(fb); #if PROFILE fps_count++; total_time += current_time() - start_time; if (fps_count == 100) { printf("fps = %3.2f\n", (double) fps_count / total_time); fps_count = 0; total_time = 0.0; } #endif } end_input_devices(); end_graphics(); return EXIT_SUCCESS; }