|
screen refreshing irregularly Displaying 1-10 of 10 total.
1
Technetium
|
I have a map where it uses a hookretrace function. Every time the screen is drawn, it runs some code to randomly determine if it should fill the screen with a bright translucent color (this is to simulate the effect of a thunderstorm and lightning). However, when the color gets filled, it is uneven. Part of the screen will fill and get drawn and a tiny fraction of a second later, the rest will, with the division between the two being some arbitrary horizontal line across the screen.
When I wrote the code 2 years ago, it didn't have this porblem. I originally wrote the code with a computer that had an AMD K6-2. I now have a computer with a dual-core processor. The refresh rate is pretty incredible now, and I am wondering if perhaps the CPU is refreshing the screen faster than my monitor can. Would that be the sort of thing that would cause this to happen? I am pretty sure this is easy to fix by using the timer to keep the refresh rate in check, but I am wondering what causes it in the first place.
Posted on 2008-07-17 08:50:25
|
mcgrue
|
This sounds at first read like a lack of timer code. Frankly, I think this might be best solved by limiting v3 to 60 fps or some such (which would go a long way to letting it not peg CPUs).
If you come to #verge on the lunarnet irc servers after hours I can look into it. I'm usually home by 10 pm PST.
Posted on 2008-07-17 13:54:55
|
Technetium
|
Unfortunately I have no internet at home right now and I can't do IRC on my work computer. I can paste in the code, though, it's short. The following is hookretraced:
void trigulweather()
{
int tw_loop;
tw_loop=random(0,200);
setlucent(50);
if(tw_loop==150)
{
rectfill(0,0,639,479,rgb(255,255,128),screen);
}
else
{
rectfill(0,0,639,479,rgb(0,0,50),screen);
}
setlucent(0);
for(tw_loop=0;tw_loop<10;tw_loop++)
{
AdditiveBlit(0+random(0,639-32),0+random(0,479-64),rainstreakgfx,screen);
}
}
It's just the part where tw_loop=150 that it has problems.
Posted on 2008-07-17 16:12:06 (last edited on 2008-07-17 16:12:42)
|
mcgrue
|
Why the random, and why the 1-in-200 chance for the other thing?
Assuming you're running 60fps, assuming I'm reading this right, and assuming the universe is still running probability.exe correctly, you'd have one rendered frame of the alternate method about every 3.3 seconds.
One frame isn't much.
And this code is very framerate dependent: it'll perform differently on other computers.
What is the effect you're attempting to accomplish?
Posted on 2008-07-20 16:40:39
|
resident
|
I think this is doing something similar to my 100 Zombies demo. The idea there was to give a night-time effect, punctuated by flashes of red if the player get hurt. It has hookretraced along with all the rest of my hud code.
int overlay_color = 32;
retraced{
SetLucent(50); //nightime effect
if (overlay_color > 32) { overlay_color--; }
RectFill( 0, 0, 320, 240, RGB(overlay_color, 32, 125), screen);
SetLucent(0);
}
Then when the player got hit, I could simply change overlay colour to about 255, and the rectfill would be tinted with red that would fade with every passing frame. It would fade faster on a fast machine, but it didn't seem like a problem, except on slow machines where it might take an age to vanish.
Posted on 2008-07-21 02:37:07
|
Technetium
|
Quote:Originally posted by mcgrue
Why the random, and why the 1-in-200 chance for the other thing?
Assuming you're running 60fps, assuming I'm reading this right, and assuming the universe is still running probability.exe correctly, you'd have one rendered frame of the alternate method about every 3.3 seconds.
One frame isn't much.
And this code is very framerate dependent: it'll perform differently on other computers.
What is the effect you're attempting to accomplish?
What I'm trying to do is create the effect of a thunderstorm. Most of the time it dims the screen, but about 1/200 refreshes it flashes bright yellow as if a bolt of lightning were up in the sky. The effect is more realistic if you have it randomly dispersed, but it might be somewhat easier to code if it were programmed. And it is true, it flashes a lot more frequently on my current computer than on the one I wrote it on 3 years ago.
Still, I'm mainly just wondering what's causing the yellow fill to appear unequally. Sometimes it fills in the top half and then the bottom half an imperceptibly small amount of time after; other times it does a block in the middle and then the narrow bands on the top and bottom of the screen after.
Posted on 2008-07-21 08:06:18
|
resident
|
I've got a sneaking suspicion this might have something to do with Showpage(); When is the screen actually getting updated?
Posted on 2008-07-21 15:16:18 (last edited on 2008-07-21 15:18:31)
|
Technetium
|
There is no showpage(). The function I pasted in earlier is directly hookretraced in the start function of the map. This is probably something I should change, actually, but I'm not sure how to do it without messing up the ability to play. If I put something like:
timer2=timer;
while(timer2+1>timer)
{
showpage();
}
That would probably make it so that moving the character around on the screen would be choppy, since it wouldn't be able to process character movement during the while loop. I don't know, I get really confused with how to effectively use hookretrace in a way that allows me to control the rate of what is being hooked while still allowing fluid control over the character.
Posted on 2008-07-23 08:59:53 (last edited on 2008-07-23 09:00:51)
|
Overkill
|
Actually, I recommend that you don't use ShowPage() in HookRetrace unless you like flickering and wonky updates. The engine's gonna call ShowPage() *again* after the rendering finishes.
Also, that timer loop you got there would highly likely not even be executed, because it's done for at most a 1/100th of a second.
Also, instead of a random chance of lightning, you should have a timestamp variable, that's all like: if (timer > tw_timestamp)
{
//// Not shown here: the actual lightning event.
// Every 1 to 5 seconds, do this again.
tw_timestamp = timer + Random(100, 500);
}
And then have another timestamp that represents the actual flash effect of the lightning.
So to recap, a timer that tells when to draw lightning again, and another that'll do the lightning fade effect.
And instead of randomly placing rain particles, you'll need to store a position for each of them and update their position in relation to the timer to look nice.
Technetium, if you want I could look at your code in more detail by email (overkill9999 AT gmail DAWT com). But at any rate, don't use pure random drawing, it'll look ugly and super-fast on new machines.
Hopefully this helps.
Posted on 2008-07-23 10:51:31
|
Technetium
|
Quote:
if (timer > tw_timestamp)
{
//// Not shown here: the actual lightning event.
// Every 1 to 5 seconds, do this again.
tw_timestamp = timer + Random(100, 500);
}
Actually, I think this could work really well. I could even use it to show the flash of lightning for more than 1 screen refresh this way, if I were to expand it to the following:
if(timer>tw_timestamp)
{
//Lightning fill
if(timer>tw_timestamp+5)
{
tw_timestamp=timer+random(100,500);
}
}
And instead of randomly placing rain particles, you'll need to store a position for each of them and update their position in relation to the timer to look nice.
The thing about the rain is that it's not really "particles" but extremely elongated streaks. It's supposed to be fast, wind-driven rain, so you'd see a streak, but no actual movement of the particle. For this kind of rain, it makes sense to simple place randomized positions. I'm somewhat inclined to leave this as it is, because it seems to only look better at faster speeds.
Posted on 2008-07-23 12:14:33
|
Displaying 1-10 of 10 total.
1
|
|