Jump to content
Eternal Lands Official Forums
Florian

Oscilating effect for cooldown in inventory

Recommended Posts

Okay, I've just tried it out, and I have a few comments :confused:

- Please don't declare your variables in the middle of a block of code (MSVC won't allow it. gcc should give you a warning).

- Is gettimeofday() needed? Would SDL_GetTicks() (which returns milliseconds since the program started) suffice instead?

- It only does the items in inventory, not quickbar (which may not be a bad thing).

- The speed seems to be a little on the slow side, for my tastes... What do you think of it getting a bit faster as it reaches the end (Hey, look, I'm nearly ready!)?

Share this post


Link to post
Share on other sites

Okay, I've just tried it out, and I have a few comments :)

- Please don't declare your variables in the middle of a block of code (MSVC won't allow it. gcc should give you a warning).

- Is gettimeofday() needed? Would SDL_GetTicks() (which returns milliseconds since the program started) suffice instead?

- It only does the items in inventory, not quickbar (which may not be a bad thing).

- The speed seems to be a little on the slow side, for my tastes... What do you think of it getting a bit faster as it reaches the end (Hey, look, I'm nearly ready!)?

I would find a faster speed bothersome, others might as well.

Share this post


Link to post
Share on other sites
I would find a faster speed bothersome, others might as well.
I don't mean that much faster, but as it is now, it's not that noticeable (An increase in the range of colours would do the same thing to make it more visible). And yes, that may be a good thing; but then why make it change colour at all?

Share this post


Link to post
Share on other sites

Okay, I've just tried it out, and I have a few comments :(

Always welcome, I just started with C (I'm a Java for GUI stuff and perl for all the rest guy).

- Please don't declare your variables in the middle of a block of code (MSVC won't allow it. gcc should give you a warning).

4.2.0 does not. Why should it? It's just a helper variable with limited scope.

- Is gettimeofday() needed? Would SDL_GetTicks() (which returns milliseconds since the program started) suffice instead?

Any function that outputs something like this:

/|/|/|/|/|

from 0 to 1 so that the sin() can be used to lower and raise a base value by some amount.

So if SDL_GetTicks() gives the milliseconds since the program started, then (SDL_GetTicks() % 1000) / 1000 should be enough to get numbers from 0.0 to 0.999 as input.

The divisor in the modulo operation can be used to adjust the speed of the effect.

- It only does the items in inventory, not quickbar (which may not be a bad thing).

That's intended. I found it rather annoying in the quickbar.

- The speed seems to be a little on the slow side, for my tastes... What do you think of it getting a bit faster as it reaches the end (Hey, look, I'm nearly ready!)?

1 second was too fast, so I switched to 2 seconds.

Edited by Florian

Share this post


Link to post
Share on other sites
Java
Eww :icon8:
perl
Yay! :(
4.2.0 does not. Why should it? It's just a helper variable with limited scope.
Because according to the C89 standard, it's not legal to declare variables in amongst your code.

In the C99 standard you can, but few compilers fully support it. There's one that I believe does fully support the standard, but I wouldn't be suprised to hear that no other supports it. On the other hand, there are some things (like C++ style comments, // as opposed to C comments, /**/) that are widely supported.

Unless you state to the compiler that you with to use the C99 (or GNU99) standard, it should present a warning that your code is not conformant to the spec, and hence less portable :D

SDL_GetTicks() stuff
Yup, I was mostly just wondering why that wasn't used; whether it was because you didn't see it or because there was some other reason (execution speed? but SDL takes care of portability stuff, which is generally a win) why you didn't use it :(
That's intended. I found it rather annoying in the quickbar.
Fair enough, and the smaller size would make it less visable as well (I wonder, does the same problem exist with the shrunken inv window for small resolutions?)
1 second was too fast, so I switched to 2 seconds.
I can imagine double the speed being too much... I was thinking more around 1.5 sec.

Still, I'm partial to the idea of it flashing faster at the end, to make it more obvious just how close it is to done.

Share this post


Link to post
Share on other sites

New version w/o sys/time.h and with SDL_GetTicks, effect becomes faster as cooldown decreases:

Index: items.c
===================================================================
RCS file: /cvsroot/elc/elc/items.c,v
retrieving revision 1.126
diff -u -d -p -r1.126 items.c
--- items.c	 27 May 2007 06:20:15 -0000	  1.126
+++ items.c	 24 Jun 2007 18:19:35 -0000
@@ -342,7 +342,10 @@ int display_items_handler(window_info *w

							glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
							glBegin(GL_TRIANGLE_FAN);
-									   glColor4f(0.14f, 0.35f, 0.82f, 0.50f); 
+	 float effect_offset = 0.0f;
+	 float delay = 1500.0f; // larger values --> larger delay
+	 effect_offset = sin((float)SDL_GetTicks() / delay * 2.0f * M_PI * (1.0f + (1.0f - cooldown) * (1.0f - cooldown)));
+									   glColor4f(0.14f - effect_offset / 20.0f, 0.35f - effect_offset / 20.0f, 0.82f + effect_offset / 8.0f, 0.48f + effect_offset / 15.0f);

									glVertex2f(x_center, y_center);


(not yet on berlios)

 

I'm afraid I can't make a video of it. 0ctane, any ideas how to records parts of the screen?

Edited by Florian

Share this post


Link to post
Share on other sites
I'm afraid I can't make a video of it. 0ctane, any ideas how to records parts of the screen?

Well, there are commercial (like snapzprox) and maybe shareware programs out there that will record your GUI interactions, but there is nothing built into OS X to do so. A Windows user could use Fraps, but that is not free IIRC.

Share this post


Link to post
Share on other sites

I have a modified version that I'll put in CVS soon; the 2 main differences are that it's C89 compliant (variable declarations at start of scope) and the beat doesn't increase until it's down to the last quarter.

 

ed: Done. :w00t:

Edited by ttlanhil

Share this post


Link to post
Share on other sites

Ahhh :w00t:

Now I get what you mean with mixing vars and code ...

 

OK, lessons learned for next patch :)

 

/EDIT

 

two things:

- why grey and not red for the map borders? (I think I commited red)

- this:

[21:16:38] interface.c.draw_game_map:1021 - OpenGL stack underflow

[21:16:38] interface.c.Leave2DMode:269 - OpenGL stack underflow

when looking at the continent map.

 

/EDIT 2

... and the beat doesn't increase until it's down to the last quarter.

Hmm, does not work as intended. It gets very very fast at the end, almost flickering.

How do you like

flash_effect_offset = sinf((float)SDL_GetTicks()/flash_delay * powf(1.25f - min2f(0.25f, cooldown), 4));

Edited by Florian

Share this post


Link to post
Share on other sites

... and the beat doesn't increase until it's down to the last quarter.

Oh, I was just going to post that as bug, it does look crappy imo, I guess it's supposed to look good, but it just looks like bad flickering to me :P

(Not that the whole thing is good for anything anyways :evilgrin:)

Share this post


Link to post
Share on other sites
Oh, I was just going to post that as bug, it does look crappy imo, I guess it's supposed to look good, but it just looks like bad flickering to me :D

(Not that the whole thing is good for anything anyways :P)

Well, I played with the formula, the items I tested it on looked nice with the formula I came up with, but I've since seen how it looks with some other cooldowns, so yes, it does look wrong (my fault).
Hmm, does not work as intended. It gets very very fast at the end, almost flickering.

How do you like

flash_effect_offset = sinf((float)SDL_GetTicks()/flash_delay * powf(1.25f - min2f(0.25f, cooldown), 4));

I'll give that a try, thanks.

 

ed: Nope, it had the same problem with skipping. I think I've found a good one, though;

flash_effect_offset = sin((float)SDL_GetTicks()/(flash_delay * min2f(0.75f, 0.5f+cooldown)));

two things:

- why grey and not red for the map borders? (I think I commited red)

Err... I probably just made a goof applying the SDL_GetTicks() changes to your code... If you think a different colour would make much of a difference I can change it
- this:

[21:16:38] interface.c.draw_game_map:1021 - OpenGL stack underflow

[21:16:38] interface.c.Leave2DMode:269 - OpenGL stack underflow

when looking at the continent map.

Meh, that aint good... I don't know why that happens though :( Edited by ttlanhil

Share this post


Link to post
Share on other sites

Hmm, the end is still too hectic for my taste, try this out please

 

flash_effect_offset = sin((float)SDL_GetTicks()/(flash_delay * min2f(0.75f, 0.625f+cooldown/2)));

Share this post


Link to post
Share on other sites

Works for me, I'll put it in, thanks.

But if there's any more sign of the fast flashing, I'll do away with the scale-up and just have a number for <1/4 and one for >1/4 :pinch:

Share this post


Link to post
Share on other sites

Hehe, I've got another one :omg:

 

flash_effect_offset = sin((float)SDL_GetTicks() / flash_delay * (1.0f + 128.0f * (powf(max2f(0.0f, 0.25f - cooldown), 4))));

 

This one has a very smooth transition to flashing faster, as you can see in this plot.

 

/EDIT

too bad, this one also has the flickering :wacko::pinch:

Edited by Florian

Share this post


Link to post
Share on other sites

This really needs some more testing before really put into use =S

 

It looks really bad right now, in my opinion... all it does is adding flickering which is annoying for the eye to even look at, so I'm not very pleased with this feature. But I understand it's in a changing/tuning state right now, so we'll see later.

Share this post


Link to post
Share on other sites
I'm afraid I can't make a video of it. 0ctane, any ideas how to records parts of the screen?

Well, there are commercial (like snapzprox) and maybe shareware programs out there that will record your GUI interactions, but there is nothing built into OS X to do so. A Windows user could use Fraps, but that is not free IIRC.

Fraps is free, but the maximum length of video that can be recorded is 30 seconds. It also makes other things quite laggy..trying to record a video of EL using fraps is like trying to run a marathon while strapped to a car.

Share this post


Link to post
Share on other sites

I have a modified version that I'll put in CVS soon; the 2 main differences are that it's C89 compliant (variable declarations at start of scope) and the beat doesn't increase until it's down to the last quarter.

The second addition does not work properly.

 

Patch to set it to one speed:

 

Index: items.c
===================================================================
RCS file: /cvsroot/elc/elc/items.c,v
retrieving revision 1.141
diff -u -d -p -r1.141 items.c
--- items.c	 10 Nov 2007 22:09:41 -0000	  1.141
+++ items.c	 27 Nov 2007 00:24:36 -0000
@@ -401,7 +401,7 @@ int display_items_handler(window_info *w
							float x_center = (x_start + x_end)*0.5f;
							float y_center = (y_start + y_end)*0.5f;
							float flash_effect_offset = 0.0f;
-							   const float flash_delay = 600.0f; // larger values --> larger delay
+							   const float flash_delay = 400.0f; // larger values --> larger delay

							if (cooldown < 0.0f)
									cooldown = 0.0f;
@@ -414,7 +414,8 @@ int display_items_handler(window_info *w
							glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
							glBegin(GL_TRIANGLE_FAN);
									//glColor4f(0.14f, 0.35f, 0.82f, 0.50f); 
-									   flash_effect_offset = sin((float)SDL_GetTicks()/(flash_delay * min2f(0.75f, 0.625f+cooldown/2)));
+									   //flash_effect_offset = sin((float)SDL_GetTicks()/(flash_delay * min2f(0.75f, 0.625f+((float)cooldown/2.0))));
+									   flash_effect_offset = sin((float)SDL_GetTicks()/flash_delay);
									glColor4f(0.14f - flash_effect_offset / 20.0f, 0.35f - flash_effect_offset / 20.0f, 0.82f + flash_effect_offset / 8.0f, 0.48f + flash_effect_offset / 15.0f);

									glVertex2f(x_center, y_center);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×