[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
| 4 | * |
---|
| 5 | * This software was released into the Public Domain. As with most public |
---|
| 6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
| 7 | * Jonathan Clark. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include "config.h" |
---|
| 11 | |
---|
[88] | 12 | #include "game.hpp" |
---|
| 13 | |
---|
| 14 | |
---|
[2] | 15 | #include "profile.hpp" |
---|
| 16 | #include "jwindow.hpp" |
---|
| 17 | #include "property.hpp" |
---|
| 18 | #include "objects.hpp" |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | jwindow *prof_win=NULL; |
---|
| 22 | int prof_height=10; |
---|
| 23 | |
---|
| 24 | struct prof_info |
---|
| 25 | { |
---|
[17] | 26 | uint16_t otype; |
---|
[2] | 27 | float total_time; |
---|
| 28 | }; |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | prof_info *prof_list=NULL; |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | int profiling() { return prof_list!=NULL; } |
---|
| 35 | |
---|
| 36 | void profile_toggle() |
---|
| 37 | { |
---|
| 38 | if (prof_win) { profile_uninit(); } |
---|
| 39 | else profile_init(); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | int profile_handle_event(event &ev) |
---|
| 43 | { |
---|
| 44 | if (ev.type==EV_CLOSE_WINDOW && ev.window==prof_win) |
---|
| 45 | { |
---|
| 46 | profile_toggle(); |
---|
| 47 | return 1; |
---|
| 48 | } else return 0; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void profile_init() |
---|
| 52 | { |
---|
| 53 | if (prof_list) { profile_uninit(); } |
---|
| 54 | prof_list=(prof_info *)jmalloc(sizeof(prof_info)*total_objects,"prof info"); |
---|
| 55 | profile_reset(); |
---|
| 56 | |
---|
| 57 | |
---|
[106] | 58 | prof_win=wm->new_window(prop->getd("profile x",-1), |
---|
[2] | 59 | prop->getd("profile y",-1), |
---|
| 60 | 20*console_font->width(), |
---|
| 61 | (prof_height+1)*console_font->height(), |
---|
| 62 | NULL, |
---|
| 63 | "PROFILE"); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | void profile_reset() |
---|
| 68 | { |
---|
| 69 | int i; |
---|
| 70 | for (i=0;i<total_objects;i++) |
---|
| 71 | { |
---|
| 72 | prof_list[i].otype=i; |
---|
| 73 | prof_list[i].total_time=0; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | void profile_uninit() |
---|
| 80 | { |
---|
| 81 | if (prof_list) jfree(prof_list); |
---|
| 82 | prof_list=NULL; |
---|
[106] | 83 | if (prof_win) { wm->close_window(prof_win); prof_win=NULL; } |
---|
[2] | 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | void profile_add_time(int type, float amount) |
---|
| 88 | { |
---|
| 89 | if (prof_list) |
---|
| 90 | { prof_list[type].total_time+=amount; } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | static int p_sorter(const void *a, const void *b) |
---|
| 94 | { |
---|
| 95 | if (((prof_info *)a)->total_time<((prof_info *)b)->total_time) |
---|
| 96 | return 1; |
---|
| 97 | else if (((prof_info *)a)->total_time>((prof_info *)b)->total_time) |
---|
| 98 | return -1; |
---|
| 99 | else return 0; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | static void profile_sort() |
---|
| 103 | { |
---|
| 104 | qsort(prof_list,total_objects,sizeof(prof_info),p_sorter); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | void profile_update() |
---|
| 109 | { |
---|
| 110 | profile_sort(); |
---|
| 111 | if (prof_list[0].total_time<=0.0) return ; // nothing took any time! |
---|
| 112 | |
---|
| 113 | int i=0; |
---|
| 114 | int spliter=(prof_win->x2()+prof_win->x1())/2; |
---|
| 115 | int max_bar_length=spliter-prof_win->x1(); |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | float time_scaler=(float)max_bar_length/prof_list[0].total_time; |
---|
| 119 | |
---|
| 120 | prof_win->screen->bar(0,prof_win->y1(),prof_win->screen->width()-1,prof_win->screen->height(),0); |
---|
[111] | 121 | int dy = 0; |
---|
[2] | 122 | for (;i<prof_height;i++) |
---|
| 123 | { |
---|
| 124 | console_font->put_string(prof_win->screen,spliter+1,dy,object_names[prof_list[i].otype]); |
---|
| 125 | prof_win->screen->bar(spliter-1-(int)(prof_list[i].total_time*time_scaler),dy+1, |
---|
| 126 | spliter-1, |
---|
[106] | 127 | dy+console_font->height()-1,wm->bright_color()); |
---|
[2] | 128 | dy+=console_font->height()+1; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | |
---|