[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 | #include "tmanage.hh"
|
---|
| 10 | #include "time/profile.hh"
|
---|
| 11 |
|
---|
| 12 | i4_profile_class pf_gc("texture gc");
|
---|
| 13 |
|
---|
| 14 | // returns total bytes available after garbage collection
|
---|
| 15 | // expired_time is the time in which all older textures are thrown out at
|
---|
| 16 | w32 r1_texture_manager_class::gc(sw32 system_ram_expire_time,
|
---|
| 17 | sw32 vram_expire_time)
|
---|
| 18 | {
|
---|
| 19 | /*
|
---|
| 20 | pf_gc.start();
|
---|
| 21 |
|
---|
| 22 | sw32 move_dist=0;
|
---|
| 23 | free_node *current=(free_node *)start_collectable;
|
---|
| 24 | r1_texture_node_struct *a;
|
---|
| 25 | sw32 free_size=0;
|
---|
| 26 | sw32 move_size, new_location;
|
---|
| 27 | i4_bool free_it=i4_F;
|
---|
| 28 |
|
---|
| 29 | next_load.in_use=i4_F; // since texture locations may change, invalid the 'next_load' hint
|
---|
| 30 |
|
---|
| 31 | // check_heap(system_ram_expire_time, vram_expire_time);
|
---|
| 32 |
|
---|
| 33 | while (current!=end)
|
---|
| 34 | {
|
---|
| 35 |
|
---|
| 36 | if (!isa_free_node(current))
|
---|
| 37 | {
|
---|
| 38 | a=(r1_texture_node_struct *)current;
|
---|
| 39 |
|
---|
| 40 | current=(free_node *)(((w8 *)a)+a->size()+sizeof(r1_texture_node_struct));
|
---|
| 41 | move_size=a->size()+sizeof(r1_texture_node_struct);
|
---|
| 42 |
|
---|
| 43 | if (a->is_loaded_in_vram() && a->last_used<vram_expire_time && a->lower)
|
---|
| 44 | free_vram_texture(a);
|
---|
| 45 |
|
---|
| 46 | // only free highlest level textures
|
---|
| 47 | if (!a->higher && a->last_used<system_ram_expire_time && a->lower && a->width()>16)
|
---|
| 48 | {
|
---|
| 49 | //i4_warning("freeing %d %d %d %d\n", a->width, a->height, a->size(), move_dist+move_size);
|
---|
| 50 | // for (r1_texture_node_struct *c=a->lower; c; c=c->lower)
|
---|
| 51 | // i4_warning(" child %d %d %d\n", c->width, c->height, c->size());
|
---|
| 52 |
|
---|
| 53 | if (a->is_loaded_in_vram())
|
---|
| 54 | free_vram_texture(a);
|
---|
| 55 |
|
---|
| 56 | r1_texture_entry_struct *te = a->entry;
|
---|
| 57 |
|
---|
| 58 | te->highest=a->lower;
|
---|
| 59 | a->lower->entry=te;
|
---|
| 60 | a->lower->higher=0;
|
---|
| 61 |
|
---|
| 62 | move_dist+=move_size;
|
---|
| 63 | free_size+=move_size;
|
---|
| 64 | }
|
---|
| 65 | else if (move_dist)
|
---|
| 66 | {
|
---|
| 67 | // w32 pre_check, post_check;
|
---|
| 68 | // pre_check=i4_check_sum32(a+1, a->width * a->height);
|
---|
| 69 |
|
---|
| 70 | r1_texture_node_struct *new_spot=(r1_texture_node_struct *)(((w8 *)a)-move_dist);
|
---|
| 71 |
|
---|
| 72 | // are we the highest mip level texture?
|
---|
| 73 | if (!a->higher)
|
---|
| 74 | a->entry->highest=new_spot;
|
---|
| 75 | else
|
---|
| 76 | a->higher->lower=new_spot;
|
---|
| 77 |
|
---|
| 78 | if (a->lower)
|
---|
| 79 | a->lower->higher=new_spot;
|
---|
| 80 |
|
---|
| 81 | //the killer memmove. this has a nasty habit of consuming 20% of our processing time.
|
---|
| 82 | memmove(new_spot, a, move_size);
|
---|
| 83 | //the killer memmove. this has a nasty habit of consuming 20% of our processing time.
|
---|
| 84 |
|
---|
| 85 | // post_check=i4_check_sum32(new_spot+1, new_spot->width * new_spot->height);
|
---|
| 86 |
|
---|
| 87 | // i4_warning("%d %d\n", pre_check, post_check);
|
---|
| 88 | }
|
---|
| 89 | // else if (!a->lower)
|
---|
| 90 | // start_collectable=a;
|
---|
| 91 | }
|
---|
| 92 | else
|
---|
| 93 | {
|
---|
| 94 | move_size=current->size+sizeof(free_node);
|
---|
| 95 | free_size+=move_size;
|
---|
| 96 | move_dist+=move_size;
|
---|
| 97 | current=(free_node *)((w8 *)current+current->size+sizeof(free_node));
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | if (!free_size)
|
---|
| 102 | first_free=0;
|
---|
| 103 | else
|
---|
| 104 | {
|
---|
| 105 | current=(free_node *)((w8 *)end-free_size);
|
---|
| 106 | current->size=(sw32)free_size-(sw32)sizeof(free_node);
|
---|
| 107 | current->next=(free_node *)end;
|
---|
| 108 | first_free=current;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | // check_heap(system_ram_expire_time, vram_expire_time);
|
---|
| 113 |
|
---|
| 114 | // i4_warning("gc : free = %d\n",free_size);
|
---|
| 115 |
|
---|
| 116 | pf_gc.stop();
|
---|
| 117 |
|
---|
| 118 | */
|
---|
| 119 | return 0;//free_size;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | void r1_texture_manager_class::do_collection()
|
---|
| 125 | {
|
---|
| 126 | return ;
|
---|
| 127 |
|
---|
| 128 | // can't do gc while textures are being loaded in
|
---|
| 129 | if (loading_textures)
|
---|
| 130 | {
|
---|
| 131 | if (need_gc)
|
---|
| 132 | {
|
---|
| 133 | if (!current_load.in_use)
|
---|
| 134 | {
|
---|
| 135 | enum { SYS=40, VRAM=20 };
|
---|
| 136 | sw32 system_ram_expire_time=frame_count>SYS ? frame_count-SYS : 0,
|
---|
| 137 | vram_expire_time=frame_count>VRAM ? frame_count-VRAM : 0;
|
---|
| 138 |
|
---|
| 139 | if (gc(system_ram_expire_time,
|
---|
| 140 | vram_expire_time))
|
---|
| 141 | need_gc=i4_F;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | }
|
---|