Author |
Message |
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Fri Apr 02, 2010 4:37 pm Post subject: |
|
|
|
|
colors module has undergone a final redesign, and will most likely not be altered in the future.
if the file timestamp on your files is older than this post's timestamp, your version is outdated. grab a new copy.
there is really no reason why any zone should not have this module, all the cool kids have it...
:) _________________ SSC Distension Owner
SSCU Trench Wars Developer
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Thu Apr 29, 2010 1:11 am Post subject: |
|
|
|
|
fixed bug in new logic that sent arena messages to zone.
files updated.
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Wed Jun 02, 2010 7:23 am Post subject: |
|
|
|
|
updated interface.
should be slightly faster, and now you arent forced to use the color constants, even if theres no real reason not to :P
files updated.
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Mon Jun 28, 2010 3:52 pm Post subject: |
|
|
|
|
i think it was because i was testing something or other, and forgot to fix it...
in any case, its fixed.
files updated.
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Jun 28, 2010 8:01 pm Post subject: |
|
|
|
|
Another small thing I noticed... your module logs messages using the ERROR tag when it loads and unloads correctly, you might want to change that to Information
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Tue Jun 29, 2010 3:48 am Post subject: |
|
|
|
|
all my modules do
INFO level messages are by default not sent to chat
when the zone crashes because someone attached a module to a different arena, id want to know
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Jul 04, 2010 12:33 am Post subject: |
|
|
|
|
Suggestion: Would be nice to be able to use printf style format with the ColorA, ColorP, etc. functions
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Jul 05, 2010 9:10 pm Post subject: |
|
|
|
|
I modified the code so the interface handles printf style formatting.
I also added interface functions to send colored messages with sounds
Note that I stripped off the code of the Voice module in there, because I was lacking some constants, presumably in the xchat module, and I didn't want to bother with that... So do what you want with it
There are a few minor changes here and there I did while skimming through your code, mostly in code formatting (i.e. a switch (params[0]) instead of if...else if... chain).
colors_sama.zip - 18.54 KB
File downloaded or viewed 236 time(s)
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Mon Jul 05, 2010 10:09 pm Post subject: |
|
|
|
|
In matters of style, an if-else chain is generally preferred over switch statements. See the Java style for an example. The if statements are more flexible, and therefore easier to expand in the future, and of course the basic form generates the same machine code. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Jul 05, 2010 11:43 pm Post subject: |
|
|
|
|
Well it depends what is subject to change... if the input is subject to change, your if else if chain will be less flexible, since you'll need to change it all... But if the conditions might get changed or combined, then yeah.
Also if your condition is a function or some calculation, the switch avoids the need of a local variable to store the result before comparing it, which is practical.
IMHO
</offtopic>
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Tue Jul 06, 2010 10:39 am Post subject: |
|
|
|
|
Samapico wrote: | Suggestion: Would be nice to be able to use printf style format with the ColorA, ColorP, etc. functions |
it was on my to do list, but i hadnt added it yet because:
#1: its extra work
#2: you can use snprintf like samapico does before SendArenaMessage before PinkA
#3: idk
#4: its easy to do, and ill add it later sometime
#5: ???
#6: PROFIT
also, i use else if chains when i dont need fall-throughs or not-1-line code
edit:
keep in mind you can use %123 to add sounds to your messages...
its very infrequent that i actually use the SendSoundMessage stuff...
also, using
if(1) a++;
on one line is better than
if(1)
..........a++;
because its on one line instead of two, and is MORE readable.
only use two lines when one becomes less readable.
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Tue Jul 06, 2010 12:59 pm Post subject: |
|
|
|
|
I personally find it less readable when the statement is on the same line as the conditon... you have to visually scroll to the end of the condition (i.e. the closing parenthesis) and then find the statement...
Anyway.... if you didn't notice, I did the printf format style functions, so you don't need to, in the post just after the one you quoted
Also, I know you can send the % sounds when you type a colored messages, but I'm mainly using the color module's interface from other modules and I doubt adding a %# in the message string would make a sound... the % thing is client-side.
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Tue Jul 06, 2010 5:27 pm Post subject: |
|
|
|
|
when youre getting up to 10,000 lines of code, adding extra space for no reason makes you wait a really long time while scrolling to the part youre looking for.
yes, all sounds are client side, and yes, you did copy+paste from chat.c just like i will.
:)
|
|
Back to top |
|
|
L.C. Server Help Squatter
Age:33 Gender: Joined: Jan 03 2003 Posts: 574 Location: Missouri, US Offline
|
Posted: Tue Jul 06, 2010 10:41 pm Post subject: |
|
|
|
|
Cheese wrote: | when youre getting up to 10,000 lines of code, adding extra space for no reason makes you wait a really long time while scrolling to the part youre looking for. | It makes sense to do it because it makes your code look cleaner, more accessible, easier to read, and easier to work with. I say this based off my XHTML/CSS experience. (Take a look at the source code for hlrse.net's webpage to see what I mean.)
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Wed Jul 07, 2010 8:19 am Post subject: |
|
|
|
|
i find them to be equally readable at best, but one is a waste of space
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sun Jul 25, 2010 9:50 am Post subject: |
|
|
|
|
Samapico wrote: | Suggestion: Would be nice to be able to use printf style format with the ColorA, ColorP, etc. functions |
I finally got around to doing this.
Enjoy.
files updated
|
|
Back to top |
|
|
BaK (mgb wont reset pw) Guest
Offline
|
Posted: Sun Jul 25, 2010 8:01 pm Post subject: |
|
|
|
|
Dr Brain wrote: | if statements are more flexible, and therefore easier to expand in the future, and of course the basic form generates the same machine code. |
don't case statements generate jump tables while if statements use a series of comparisons?
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jul 25, 2010 9:58 pm Post subject: |
|
|
|
|
How would you generate a jump table without comparisons, exactly? A fully populated table for ints would be 4GB (assuming the relative jump could be packed into 1 byte, of course). A sparse table would require comparisons and would start to look very much like that if-else tree.
Jump tables are great for strictly defined things like interrupt handling vectors, and custom code where you can write assembly to get the very last nanosecond out.
|
|
Back to top |
|
|
BaK (mgb wont reset pw) Guest
Offline
|
Posted: Mon Jul 26, 2010 7:57 am Post subject: |
|
|
|
|
if you're dense near 0, you check the maximum range once and then after that assume the index is in bounds.
I think the compiler did it when I was learning asm and it took me a minute to figure out what was going on.
|
|
Back to top |
|
|
Guest
Offline
|
Posted: Mon Jul 26, 2010 7:59 am Post subject: |
|
|
|
|
Dr Brain wrote: | How would you generate a jump table without comparisons, exactly? |
// done by compiler
table[0] = case0;
table[1] = case1;
table[2] = case2;
table[3] = case3;
// done at runtime
if (index > 3)
goto caseDefault;
else
goto table[index];
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Mon Jul 26, 2010 10:05 am Post subject: |
|
|
|
|
You're right, you can do it with one comparison if you have fully dense cases. I've never seen it done, but again, I don't work with switch statements for the style reasons stated above.
I'd like to note that I don't think CPU branch predictors are well suited to that sort of jump table (relative jump with offset held in a register instead of an immediate). Branch predictors may have improved since I last studied them, but as I don't see how this kind of dependence could be resolved while still in the pipeline. So you'll get a pipeline flush every time you do the jump, which in deeply pipelined processors can hurt performance instead of helping it (modern x86_64 are deeply pipelined). The exact penalty depends on the probability distribution of the cases and the pipeline flush penalty, but except for truly massive switch statements or processors with shallow pipelines it won't reach break-even.
But, that said, any compiler smart enough to optimize a switch statement (if indeed there is an improvement from a jump table, which I tend to doubt) is probably smart enough to check if the if-else tree can follow the same optimization. It's a simple enough comparison of the AST to see if every branch of the if-else does an integer comparison against the same variable.
Perhaps the jump table is the -O0 behavior? That would make sense, since the argument could be made that it would more closely resemble the C code. Or perhaps it's -Os, if there's a code size savings (e.g. the relative offset could fit in a byte, but the branch opcodes are one word wide).
Most of the code I write isn't x86, so I may be unaware of new developments in the processor architecture. The last x86 I studied was the Pentium 4. Most of my code is C, written for the AVR and AVR32 architectures, compiled using gcc.
|
|
Back to top |
|
|
BaK (mgb wont reset pw) Guest
Offline
|
Posted: Thu Aug 12, 2010 12:11 pm Post subject: |
|
|
|
|
it doesn't need to be fully dense, as some gaps can be filled in with the same address (jump to the default handler, or after the switch statement).
Even in the case of a very sparse switch statement, it can be implemented using a binary search which will be faster than a sequential checking using if statements alone.
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Thu Aug 12, 2010 12:39 pm Post subject: |
|
|
|
|
The pipeline flush from the jump table is still going to drive the performance cost on any x86 and x86_64.
And you don't think an optimizing compiler can rewrite them both into the same exact machine code? That was my original point: they'll generate the same exact binary. Therefore one should use whichever is easier to read, which for my money is the if else-if.
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
|
Back to top |
|
|
|