Mercurial > sdl-ios-xcode
comparison src/video/SDL_rect.c @ 2223:175754591a13
Optimized dirty rect code
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 11 Aug 2007 21:34:08 +0000 |
parents | c121d94672cb |
children | 29cc9e9c76bd |
comparison
equal
deleted
inserted
replaced
2222:926294b2bb4e | 2223:175754591a13 |
---|---|
120 | 120 |
121 void | 121 void |
122 SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect) | 122 SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect) |
123 { | 123 { |
124 SDL_DirtyRect *dirty; | 124 SDL_DirtyRect *dirty; |
125 SDL_DirtyRect *check, *prev, *next; | 125 |
126 /* FIXME: At what point is this optimization too expensive? */ | |
127 for (dirty = list->list; dirty; dirty = dirty->next) { | |
128 if (SDL_HasIntersection(&dirty->rect, rect)) { | |
129 SDL_UnionRect(&dirty->rect, rect, &dirty->rect); | |
130 return; | |
131 } | |
132 } | |
126 | 133 |
127 if (list->free) { | 134 if (list->free) { |
128 dirty = list->free; | 135 dirty = list->free; |
129 list->free = dirty->next; | 136 list->free = dirty->next; |
130 } else { | 137 } else { |
132 if (!dirty) { | 139 if (!dirty) { |
133 return; | 140 return; |
134 } | 141 } |
135 } | 142 } |
136 dirty->rect = *rect; | 143 dirty->rect = *rect; |
137 | |
138 /* FIXME: At what point is this optimization too expensive? */ | |
139 for (prev = NULL, check = list->list; check; check = next) { | |
140 next = check->next; | |
141 | |
142 if (SDL_HasIntersection(&dirty->rect, &check->rect)) { | |
143 SDL_UnionRect(&dirty->rect, &check->rect, &dirty->rect); | |
144 if (prev) { | |
145 prev->next = next; | |
146 } else { | |
147 list->list = next; | |
148 } | |
149 check->next = list->free; | |
150 list->free = check; | |
151 --list->count; | |
152 } else { | |
153 prev = check; | |
154 } | |
155 } | |
156 | |
157 dirty->next = list->list; | 144 dirty->next = list->list; |
158 list->list = dirty; | 145 list->list = dirty; |
159 ++list->count; | 146 ++list->count; |
160 } | 147 } |
161 | 148 |
162 void | 149 void |
163 SDL_ClearDirtyRects(SDL_DirtyRectList * list) | 150 SDL_ClearDirtyRects(SDL_DirtyRectList * list) |
164 { | 151 { |
165 while (list->list) { | 152 list->free = list->list; |
166 SDL_DirtyRect *elem = list->list; | 153 list->list = NULL; |
167 list->list = elem->next; | |
168 elem->next = list->free; | |
169 list->free = elem; | |
170 } | |
171 list->count = 0; | 154 list->count = 0; |
172 } | 155 } |
173 | 156 |
174 void | 157 void |
175 SDL_FreeDirtyRects(SDL_DirtyRectList * list) | 158 SDL_FreeDirtyRects(SDL_DirtyRectList * list) |