Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 07-17-2009, 10:58 AM
Shendare
Dragon
 
Join Date: Apr 2009
Location: California
Posts: 814
Default

Yeah, KLS, MakeAnyLenString was certainly an option. I went with snprintf instead to lower a bunch of heap allocations I considered unnecessary. I can elaborate.

Utilizing snprintf, the memory for the string gets allocated just once at the beginning of the function, and is reused with each call to snprintf. The only caveat is to make sure I set aside a large enough buffer for all of my possible uses.

With MakeAnyLenString, for anyone reading who isn't familiar with it, the memory for the string is allocated with each MakeAnyLenString call, and re-allocated as many times as necessary within the function to fit the result string, starting with 256 bytes and doubling each time, re-performing the vsnprintf() call and its process time for each re-allocation as well. This means you don't have to worry about how large the string is, but it also means you could end up with three or four heap allocations per call for larger strings, and re-performing the vsnprintf() call for each allocation until you get one that fits within the buffer, potentially wasting time and fragmenting the heap.

If there's a standing dev preference for the use of MakeAnyLenString over snprintf, I have no problem changing the code to use it instead. I just felt I would explain why I didn't in this case, where the query string buffer might be re-used several times in a single function call.

As for your suggestions, Trev, at the very least adding a coordinate report in 'Move ToMe' is a simple and very worthwhile idea, requiring just one line addition at (what shows in my current source as) Line 14145:

File: command.cpp - object_command()
Code:
...
        // GetHeading() returns half of the actual heading, for some reason
        x2 = 10.0f * sin(c->GetHeading() * 2.0f / 256.0f * 3.14159265f);
        y2 = 10.0f * cos(c->GetHeading() * 2.0f / 256.0f * 3.14159265f);
        c->MovePC(c->GetX() - x2, c->GetY() - y2, c->GetZ(), c->GetHeading() * 2.0f);

+       c->Message(0, "Object %u moved to %.1f, %.1f, %.1f, heading %.1f", id, od.x, od.y, od.z, o->GetHeading());
      }
      else // Move to x, y, z [h]
...
Unfortunately, not bumping the player back when using 'Move ToMe' always caused problems during my debugging. The model would get summoned into my character's location at his feet, and because the model was always considered solid as a moveable tradeskill object, my character then either (1) couldn't move at all and I had to use #goto, or (2) got bumped up atop the object or bumped out of the object. Both rather throw a wrench in fine tuning location by moving your character slightly with another 'Move ToMe'.

However, adding the coordinate report before bumping your character back will allow numeric fine-tuning, at least, and was a very good idea. I should have thought to add it to 'Move' after putting it in 'Add'.

Now, what problem exactly were you having with door models, Trev? I was able to use FELDOOR2 and DOOR1 while debugging the command in Felwithe.
Reply With Quote
  #2  
Old 07-19-2009, 07:16 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Interesting... Doors do seem to work just fine when I test your example. The place I was testing them in was Dreadspire and most of the doors there have considerably longer names than doors in older zones. Here are some examples:

Quote:
OBJ_LIBRY_HIDEDOOR
OBJ_MAINCASTLE_DOOR
OBJ_DINE_LDOOR
OBJ_DINE_RDOOR
OBJ_DNGRM_LDOOR
OBJ_DINERM_RDOOR
OBJ_MAINCASTLE_DOOR
OBJ_HIDDENDOOR
OBJ_BDRM_LDOOR
OBJ_BDRM_RDOOR
OBJ_LIBRY_SWITCH
MAYONGSWITCHA
MAYONGSWITCHB
OBJ_MAINCASTLE_DOOR
OBJ_TORTURE_DOOR
I didn't try all of those, but I did try a few. My best guess is that the problem is with the length of the new door names. I made sure to try some under 16 chars, but that didn't make any difference. Maybe we are setting the limit lower than it should be somewhere. Also, for it to work on all doors, we might need to look into increasing the limit from 16 chars to 20 or so. I went through a while back and set it so doors can use 32 chars, because they were previously set to 16 for no reason. From looking at the packet structure on Titanium, it looks like we could easily bump objects up to 32 as well:

Code:
/*44*/	char	object_name[20];	// Name of object, usually something like IT63_ACTORDEF
/*64*/	float	unknown064;			// seems like coords, not always valid, all 0 on most world objects
/*68*/	float	unknown068;			// seems like coords, not always valid, all 0 on most world objects
/*72*/	float	unknown072;			// seems like coords, not always valid, all 0 on most world objects

Those last 3 fields there are bogus and could be combined with the 20 from the object name to make 32. For some reason, live sends bogus info in their name fields after the name, but it has no use at all and is somewhat random in many cases. I would guess that they do that to throw people like us off, but I'm not falling for it :P

So, if we change the structure, we would also have to change everything else related to object name to be able to handle 32 characters in length. I think that would fix the issue I was seeing in Dreadspire at least. Probably even some old zones would have issues with this limitation, so it wouldn't hurt to get it fixed at some point.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #3  
Old 07-22-2009, 11:54 AM
Yeormom
Discordant
 
Join Date: Apr 2004
Location: 127.0.0.1
Posts: 402
Default

I've always added my objects to the database directly and reloaded the zone. I'm sure some if you will run into the same problem I did with tradeskill objects. Improperly configured tradeskill objects will crash the client with a null pointer exception everytime a person clicks on them. Might be worth adding some additional logic handling in the future if you haven't already and this becomes common usage.
__________________
Yeorwned
Bane of Life [Custom Classic/PvP]
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:53 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3