Thread: Eek Too many npcs

Page 3 of 3 FirstFirst 123
Results 21 to 26 of 26
  1. #21  
    Donator


    Join Date
    Jan 2010
    Age
    29
    Posts
    4,122
    Thanks given
    274
    Thanks received
    551
    Rep Power
    738
    Quote Originally Posted by Jason View Post
    So far you seem to be encoding and decoding the opcode fine, but what you send for each mask is still not apparent. Paste the following functions referenced in this block.

    Code:
    if(npc.animation != -1)			appendAnimUpdate(npc, updateBlock);		if(npc.hit2 != -1)			appendHitUpdate2(npc, updateBlock);		if(npc.graphic != -1)			appendGraphic(npc, updateBlock);		if(npc.getFace() != -1)			appendFaceEntity(npc, updateBlock);		if (npc.forcedText.equals("") == false)			updateBlock.writeString(npc.forcedText);		if(npc.hit1 != -1)			appendHitUpdate(npc, updateBlock);		if(npc.transformId != -1)			appendTransformUpdate(npc, updateBlock);		if(npc.facingX != -1 && npc.facingY != -1)			appendFaceToUpdate(npc, updateBlock);
    
    Code:
    	private static void appendAnimUpdate(Npc npc, Stream stream) {
    		stream.writeWordBigEndian(npc.animation);
    		stream.writeByte(0);
    	}
    	
    	private static void appendHitUpdate2(Npc npc, Stream stream) {
    		stream.writeByteC(npc.hit2);
    		stream.writeByteS(npc.hitType2);
    		stream.writeByteS(getCurrentHP(npc.health, npc.maxHealth, 100));
    		stream.writeByteC(100);
    	}
    	
    	private static void appendGraphic(Npc npc, Stream str) {
    		str.writeWord(npc.graphic);
    		str.writeDWord(npc.graphicHeight << 16);
    	}
    	
    	private static void appendFaceEntity(Npc npc, Stream str) {
    		str.writeWord(npc.getFace());
    	}
    
    	private static void appendHitUpdate(Npc npc, Stream stream) {
    		stream.writeByteC(npc.hit1);
    		stream.writeByteS(npc.hitType1);
    		stream.writeByteS(getCurrentHP(npc.health, npc.maxHealth, 100));
    		stream.writeByteC(100);
    	}
    	
    	private static void appendTransformUpdate(Npc npc, Stream str) {
        	str.writeWordBigEndianA(npc.transformId);
    	}
    	
    	private static void appendFaceToUpdate(Npc npc, Stream stream) {
    		stream.writeWordBigEndian(npc.facingX);
    		stream.writeWordBigEndian(npc.facingY);
    	}
    Edit: If been looking and comparing for a while now but i could not find the diffrence my self

    and it just happend again and this is what k and npccount printed

    Code:
    k = 47
    java.lang.RuntimeException: eek
    npcCount = 9
    Reply With Quote  
     

  2. #22  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Nighel View Post
    ....
    It has to do with movement, show the server-sided code for updating movement in the update block. It's the server-side encoding block for method139, so the first block of the three. Show what that looks like.
    Reply With Quote  
     

  3. #23  
    Donator


    Join Date
    Jan 2010
    Age
    29
    Posts
    4,122
    Thanks given
    274
    Thanks received
    551
    Rep Power
    738
    Quote Originally Posted by Jason View Post
    It has to do with movement, show the server-sided code for updating movement in the update block. It's the server-side encoding block for method139, so the first block of the three. Show what that looks like.
    Code:
    	private static void updateNPCMovement(Npc npc, Stream stream) {
    		if (npc.steppedDir == -1) {
    			// don't have to update the npc position, because the npc is just
    			// standing
    			if (getUpdateMask(npc) != 0) {
    				// tell client there's an update block appended at the end
    				stream.writeBits(1, 1);
    				stream.writeBits(2, 0);
    			} else {
    				stream.writeBits(1, 0);
    			}
    		} else {
    			// send "walking packet"
    			stream.writeBits(1, 1);
    			stream.writeBits(2, 1); // updateType
    			stream.writeBits(3, npc.steppedDir);
    			stream.writeBits(1, (getUpdateMask(npc) != 0) ? 1 : 0);
    		}
    	}
    Reply With Quote  
     

  4. #24  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    So clearly the number of NPC's that you've determined as visible on the server end is greater than the number of visible NPC's on the client end. The client thinks there is 9 within viewing distance, and the server thinks there are 47. What does Position#isViewableFrom look like? Is the distance check > 12? What is the value of Misc#MAX_VIEWABLE_DISTANCE? Is that value greater than 12? Is it possible the algorithm you use to calculate distance is incorrect? You should post that as well. I'm not sure how much more I can help :/.
    Reply With Quote  
     

  5. #25  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by Nighel View Post
    Code:
    	private static void updateNPCMovement(Npc npc, Stream stream) {
    		if (npc.steppedDir == -1) {
    			// don't have to update the npc position, because the npc is just
    			// standing
    			if (getUpdateMask(npc) != 0) {
    				// tell client there's an update block appended at the end
    				stream.writeBits(1, 1);
    				stream.writeBits(2, 0);
    			} else {
    				stream.writeBits(1, 0);
    			}
    		} else {
    			// send "walking packet"
    			stream.writeBits(1, 1);
    			stream.writeBits(2, 1); // updateType
    			stream.writeBits(3, npc.steppedDir);
    			stream.writeBits(1, (getUpdateMask(npc) != 0) ? 1 : 0);
    		}
    	}
    pm teamviewer id and pass i'll see if i can sort it for you, free of charge

    edit*

    after testing his npc updating, it seemed all correct. my next step was to investigate if multiple threads were involved and they was, switched it to use a single thread and fingers crossed it solves it, pretty sure this was a simple concurrency issue corrupting the byte[] buffer of Stream class
    Last edited by Spooky; 12-25-2017 at 01:25 AM.
    Reply With Quote  
     

  6. Thankful users:


  7. #26  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Stuart View Post
    pm teamviewer id and pass i'll see if i can sort it for you, free of charge

    edit*

    after testing his npc updating, it seemed all correct. my next step was to investigate if multiple threads were involved and they was, switched it to use a single thread and fingers crossed it solves it, pretty sure this was a simple concurrency issue corrupting the byte[] buffer of Stream class
    Good job boss
    Reply With Quote  
     

Page 3 of 3 FirstFirst 123

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. NullPointerException - Too many NPCs
    By NICKname in forum Help
    Replies: 0
    Last Post: 10-02-2010, 04:12 PM
  2. Help [BattleScape] Too many npc error
    By dr dree6 in forum Help
    Replies: 2
    Last Post: 09-03-2010, 07:45 PM
  3. What actually causes t2: Too many NPCs
    By tj007razor in forum Help
    Replies: 0
    Last Post: 03-01-2010, 06:27 AM
  4. Too many npcs = Crash >.>
    By Alwaysstuck1 in forum Requests
    Replies: 14
    Last Post: 05-24-2009, 01:23 PM
  5. Too many npc spawn = Lag?
    By Homie Pimpson in forum Help
    Replies: 10
    Last Post: 04-21-2009, 09:40 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •