Changeset 134
- Timestamp:
- 06/28/09 14:40:31 (3 years ago)
- Files:
-
- trunk/src/yage/core/timer.d (modified) (3 diffs)
- trunk/src/yage/gui/style.d (modified) (4 diffs)
- trunk/src/yage/gui/surface.d (modified) (1 diff)
- trunk/src/yage/gui/textlayout.d (modified) (9 diffs)
- trunk/src/yage/resource/lazyresource.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/yage/core/timer.d
r132 r134 9 9 import tango.stdc.math; 10 10 import tango.util.Convert; 11 import tango.text.convert.Format; 11 12 import tango.time.StopWatch; 12 13 … … 30 31 protected StopWatch hpc; 31 32 32 protected Timer source; 33 protected Timer source; // TODO: allow using one timer as the souce of another, so pausing a scene could pause all timers in that scene. 33 34 34 35 /// Initialize and start the Timer. … … 171 172 /// 172 173 char[] toString() 173 { return to!(char[])(get());174 { return Format.convert("{:d8}", tell()); 174 175 } 175 176 trunk/src/yage/gui/style.d
r131 r134 22 22 import yage.gui.exceptions; 23 23 24 import std.stdio;24 import yage.core.timer; 25 25 26 26 /** … … 254 254 int zIndex; 255 255 256 private static Regex rxStyles; 257 private static Regex rxTokens; 258 private static Regex rxProperties; 259 static this() { 260 rxStyles = Regex(";\\s*"); 261 rxTokens = Regex(":\\s*"); 262 rxProperties = Regex("\\s+"); 263 } 264 256 265 /** 257 266 * Struct constructor, returns the default style. */ … … 271 280 if (!style.length) 272 281 return; 273 282 274 283 // Parse and apply the style 275 Regex rxTokens = Regex(":\\s*"); 276 Regex rxProperties = Regex("\\s+"); 277 foreach (exp; Regex(";\\s*").split(style)) 284 scope styles = rxStyles.split(style); 285 foreach (exp; styles) 278 286 { char[][] tokens = rxTokens.split(exp); 279 287 if (tokens.length<2) … … 343 351 throw new CSSException("Unsupported CSS Property: '", property, "'."); 344 352 } 345 } 353 } 346 354 } 347 355 trunk/src/yage/gui/surface.d
r131 r134 251 251 textTexture = new GPUTexture(textImage, false, false, text, true); 252 252 else 253 { //Timer a = new Timer(true); 253 254 textTexture.commit(textImage, false, false, text, true); 255 //Stdout("texture upload: ", a.tell()*1000).newline; 256 } 254 257 old_text = text; 255 258 } trunk/src/yage/gui/textlayout.d
r133 r134 29 29 { 30 30 private const char[] breaks = " *()-+=/\\,.;:|()[]{}<>\r\n"; // breaking characters 31 private static Regex rxSpaces; 32 private static Regex rxTags; 33 static this () 34 { rxSpaces = Regex(`\s{2,}`); 35 rxTags = Regex(`\>[^\<]+\<`); 36 } 31 37 32 38 static double lastRenderTime=0; … … 138 144 //text = .toString(lastRenderTime*1000, 6) ~ "<br/>" ~ text; // temporary profiling 139 145 //Stdout("test").newline(); 140 Timer a = new Timer( );146 Timer a = new Timer(false); 141 147 142 148 if (text.length && style.fontFamily) 143 149 { letters.length = 0; 144 150 lines.length = 0; 145 146 // Get an array of letter structs for the entire text. 147 scope nodes = getNodes(text, InlineStyle(style)); 148 151 152 // Get an array of letter structs for the entire text. (1ms) 153 scope nodes = getNodes(text, InlineStyle(style)); 149 154 foreach (ref node; nodes) // ref is req'd so that &node.style points to the real style. 150 { // Aditional text replacement 155 { // Aditional text replacement 151 156 node.text = htmlToText(node.text); 152 153 foreach (c; node.text) // render each letter 157 foreach (c; node.text) 154 158 { if (node.style.fontFamily) 155 159 { int h = node.style.fontSize; 156 160 int w = node.style.fontWeight == Style.FontWeight.BOLD ? h*3/2 : h; 157 Letter l= node.style.fontFamily.getLetter(c, w, h);161 Letter l= node.style.fontFamily.getLetter(c, w, h); 158 162 l.extra = &node.style; 159 163 letters ~= l; 160 164 } } } 161 162 // Build lines 165 166 // Build lines (.7ms) 163 167 { int i; 164 168 while (i<letters.length) … … 210 214 } } 211 215 216 lastRenderTime = a.tell(); 217 212 218 // Get total height 213 219 int totalHeight; 214 220 foreach (line; lines) 215 221 totalHeight += line.height; 216 totalHeight += lines[$-1].height / 3; 217 218 // Render Image 222 if (lines.length) 223 totalHeight += lines[$-1].height / 3; 224 225 226 227 // Render Image (7ms) 219 228 int x, y; 220 result = new Image(4, width, min(totalHeight, height)); 229 result = new Image(4, width, min(totalHeight, height)); // 1ms by itself 221 230 foreach (i, line; lines) 222 231 { … … 258 267 break; 259 268 } 260 } 261 lastRenderTime = a.tell(); 262 269 //Stdout(a.tell()*1000).newline; 270 lastRenderTime = a.tell(); 271 } 272 273 //lastRenderTime = a.tell(); 263 274 264 275 return result; 265 276 } 277 266 278 267 279 /* … … 270 282 private static HtmlNode[] getNodes(char[] htmlText, InlineStyle style) 271 283 { 272 // Preprocessing 273 htmlText = Regex(`\s{2,}`).replaceAll(htmlText, " "); // remove excess whitespace284 // Preprocessing (3ms !) 285 htmlText = rxSpaces.replaceAll(htmlText, " "); // remove excess whitespace 274 286 htmlText = substitute(htmlText, "<br/>", "\n"); // Add line returns 275 287 htmlText = "<span>"~htmlText~"</span>"; 276 288 289 290 // (3ms !) 277 291 // This will be fixed in Tango 0.99.9: http://dsource.org/projects/tango/ticket/1619#comment:1 278 292 int i=0; // [below] ensure every plain text child is wrapped in <span></span> to fix tango's xml parsing. 279 htmlText = Regex(`\>[^\<]+\<`).replaceAll(htmlText, (RegExpT!(char) input) {293 htmlText = rxTags.replaceAll(htmlText, (RegExpT!(char) input) { 280 294 return "><span"~input[i]~"/span><"; 281 295 i++; 282 296 }); 283 297 298 // .05ms 284 299 auto doc = new Document!(char); 285 300 doc.parse(htmlText); 286 return getNodesHelper(doc.query.nodes[0], style); 301 302 Timer a = new Timer(); 303 auto result = getNodesHelper(doc.query.nodes[0], style); // 0.15 ms 304 return result; 287 305 } 288 306 … … 291 309 * T is always of type NodeImpl. This only has to be templated because Tango's NodeImpl is private. */ 292 310 private static HtmlNode[] getNodesHelper(T)(T input, InlineStyle parentStyle) 293 { HtmlNode[] result; 311 { 312 HtmlNode[] result; 294 313 char[] tagName = toLower(input.name); 295 314 … … 297 316 HtmlNode node; // our own node class. 298 317 if (input.query.attribute("style").count) 299 { Style temp = parentStyle.toStyle(); 300 temp.set(input.query.attribute("style").nodes[0].value); 318 { Style temp = parentStyle.toStyle(); 319 temp.set(input.query.attribute("style").nodes[0].value); // 30ms for temp.set! 301 320 node.style = InlineStyle(temp); 302 321 } else … … 315 334 // Get any text children from the node. 316 335 if (input.value.length) 317 { node.text = input.value.dup; 336 { node.text = input.value.dup; // garbage! 318 337 result ~= node; 319 338 } else if (tagName=="br") … … 326 345 for (auto child = input.query.child.nodes[0]; child; child=child.next()) 327 346 result ~= getNodesHelper(child, node.style); 347 328 348 return result; 329 349 } trunk/src/yage/resource/lazyresource.d
r126 r134 14 14 /** 15 15 * This class manages a queue of operations that can only be performed in the rendering thread. 16 * This should eventually be replaced with a glContext that manages openGL state and can allow synchronized OpenGL calls from any thread.*/ 16 * This should eventually be replaced with a glContext that manages openGL state and can allow synchronized OpenGL calls from any thread. 17 * Alternatively, the renderer itself should be lazy and only load recources during rendering? */ 17 18 class LazyResourceManager 18 19 {
