Framerate in a browser
#1
Posted 27 October 2009 - 10:55 AM
I'm trying to display application statistics and diagnostic information (e.g. framerate) in a web page, updating it in real time. Anyone know what technology I could use for this?
I'm currently already using WinSock 2 to directly open a socket and serve a web page with controls to modify application behavior. But it requires reloading the page to exchange data. For an FPS counter and such I was hoping it could continuously call a function on the server side and update the text field without reloading. Note that I'm trying to keep this as lightweight as possible. Any ideas?
Thanks!
Nicolas
#2
Posted 27 October 2009 - 01:48 PM
#3
Posted 27 October 2009 - 03:37 PM
#4
Posted 27 October 2009 - 03:45 PM
TheNut said:
Quote
Anyway, thanks for the suggestion! If anyone knows where I might find essential information about this technology or something similar that would be much appreciated.
#5
Posted 27 October 2009 - 03:49 PM
But, at the core, it is a browser's use of asynchronous calls, via Javascript, using an in-browser object (XMLHttpRequest) such that the browser can send and retrieve information. Typically, this information is then used to alter the browser's DOM. That's AJAX at it's core...
#6
Posted 27 October 2009 - 04:01 PM
alphadog said:
Quote
I've used this in SwiftShader 2.0, to control quality settings interactively (and remotely). Now I want to reuse that for a new project and extend it with real-time diagnostic information.
#7
Posted 27 October 2009 - 04:06 PM
Edit: Get familiar with low-level, cross-browser issues. Most of the AJAX libraries are made for app-building and encapsulate all the nitty-gritty for this.
#8
Posted 27 October 2009 - 04:36 PM
#9
Posted 27 October 2009 - 04:45 PM
Reedbeta said:
That reminds me. Ignore the 'X' in 'AJAX', Nick.
#10
Posted 27 October 2009 - 04:52 PM
<html>
<body>
<script type="text/JavaScript">
document.write("FPS: 0.23")
document.write("FPS: 0.24")
document.write("FPS: 0.21")
document.write("FPS: 0.23")
(...)
Each "document.write()" will overwrite the content of the browser window. You probably want something more sophisticated, like
var MyElement = document.getElementById("SomeID");
MyElement.innerHTML = "FPS: 0.23";
MyElement.innerHTML = "FPS: 0.21";
MyElement.innerHTML = "FPS: 0.25";
(...)
NOTE!!! Some browsers will not update unless they have recieved some minimum ammount of data. (like 1kB or something.)
#11
Posted 27 October 2009 - 05:14 PM
Thanks for the suggestions using XMLHttpRequest! It looks like that's the vital part for creating dynamically updated content. I assume it's no big deal to make JavaScript contact the server at fixed intervals?
#12
Posted 27 October 2009 - 05:22 PM
If you are trying to keep it absolutely dirt simple, then all you need to look at is the Javascript timer ( window.setTimeout() ) for polling your server. Careful with this though. All that polling can turn into a self-inflicted DDOS pretty quickly. Consider finding a way to do updates based on some client-side event, if possible, rather than on a fixed interval.
Essentially, COMET, like AJAX, has a big name, but at its core is the same XHR object plus polling.
Added: I think the main distinction is that COMET uses long polling, which means keeping the client connection in waiting. So, instead of "are we there yet?", "no", "are we there yet?", "no", "are we there yet?", "no" ... "are we there yet?", "yes!", you have "are we there yet?" <wait for a long time until Dad has an answer, could be one minute, could be one hour> "yes".
#13
Posted 27 October 2009 - 05:26 PM
Nick said:
Not at all; you can use Javascript's setTimeout() function to schedule a function call in the future.
#14
Posted 27 October 2009 - 06:10 PM
#15
Posted 27 October 2009 - 07:34 PM
// For Firefox, Opera 8.0+, Safari, use
new XMLHttpRequest();
// For IE, use
new ActiveXObject("Msxml2.XMLHTTP");
// For older versions of IE, use
new ActiveXObject("Microsoft.XMLHTTP");
They all carry the same API though. I just use a try/catch ladder and keep going until one of them works.
#16
Posted 27 October 2009 - 11:18 PM
alphadog said:
Thanks all for the help!
#17
Posted 28 October 2009 - 02:17 PM
First I was using the URL http://localhost:8080/configtest for the web page, and http://localhost:8080/configtest/fps for retrieving the FPS (i.e. the URL passed to XMLHttpRequest.open). Everything worked fine. Now I'm trying to change "configtest" to another name, and the browser hangs. No exception thrown, no error message, just 100% CPU usage.
I've checked like a hundred times that I replaced "configtest" everywhere. I was also able to verify that the request reaches the server, the URL is the correct one, and it sends the HTTP response containing the FPS. It just appears to never arrive. I've fully disabled my firewall but it still hangs.
Any clues? :huh:
#18
Posted 29 October 2009 - 01:55 PM
#19
Posted 29 October 2009 - 02:04 PM
Anyway, I'm glad I got that fixed, but I already discovered a new issue. It works fine using Internet Explorer (8), but not using FireFox 3.5. I get the FPS once and then it freezes. I guess I can use Venkman to attempt to debug it. If anyone has any guess what the issue could be please share.
#20
Posted 30 October 2009 - 01:53 PM
It abstracts away most of the retarded browser differences and annoying API:s.
If you are into functional programming, you will appreciate the jQuery API.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












