Top Mud Sites Forum

Top Mud Sites Forum (http://www.topmudsites.com/forums/index.php)
-   MUD Coding (http://www.topmudsites.com/forums/forumdisplay.php?f=9)
-   -   Modifying write_to_buffer (http://www.topmudsites.com/forums/showthread.php?t=274)

Jaegar 11-23-2003 03:30 AM

I am working with the Rom2.4 codebase and have added a new menu style creation process.  I would like to be able to add color into this but am unsure how I could modify the void write_to_buffer so that it will recognize the color codes (ie {RChoose Class{x     will result in Choose Class being displayed in bright red text).

Has anyone done something like this or is it even possible?

Thanks in advance,

Jaegar

erdos 11-23-2003 10:05 AM

Jaegar,

color tokens are meant to make in-game custom color possible, for example in helpfiles. using them in hardcode is a profound waste of CPU time because it means the code must look up the tokens each time to find the appropriate ANSI code-- when, in the hardcode, you could just explicitly give that ANSI string instead. The downside to this, though, is that you want to take care not to transmit this code to folks who are config -ANSI.
As for your creation menus: I'm not very familiar with ROM, but if it's anything like SMAUG, the uncreated player still has a char_data, almost from the start (look in your nanny function closely to find exactly where the descriptor is given a char_data). just because the char_data is not yet initialized with all the goodies like class, race, stats, max hp, etc., does not mean you can't use it as an argument for the usual send_to_char, send_to_char_color etc.
On a sidenote, while we're on the topic of write_to_buffer, a lot of codebases include a 3rd paramater, an int, meant to specify the length of the string, or 0 if you want it to explicitly calculate that length on the fly. People lazily (and/or ignorantly) use 0 even with long, constant strings, and this wastes CPU time unnecessarily. For example a call to write_to_buffer(d,"Hello world!",0) will force it to run strlen("Hello world!"), even though that result is never ever going to change. More efficient to do write_to_buffer(d,"Hello world!", 12)

Kylotan 11-23-2003 11:18 AM

And that just goes to show that excessively premature optimization is far from dead in the mud world.

Personally I'd construct a new write_to_buffer_color based on send_to_char_color. You'd only need to change a few lines.

11-24-2003 09:01 AM


Kastagaar 11-25-2003 08:51 AM

I ran a benchmarking suite on my computer the other day, and I measured my CPU efficiency at 100% - no pesky idle loop. I can thus reason that you need a better computer.

11-30-2003 08:22 PM

I got it fixed.  I wrote my own idleloop to kick its butt.

$ cat idleloop.c
main(int c, char** a) {eff: goto eff;}

For best results use gcc -O3 which puts the compiler in ninja-mode.

Kylotan 12-01-2003 12:59 PM

Best omit the c and a parameters there, or it'll chew up cycles having to ignore them!


All times are GMT -4. The time now is 01:10 PM.

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Top Mud Sites.com 2022