Mirage Source
http://web.miragesource.net/forums/

What consumes RAM Client side?
http://web.miragesource.net/forums/viewtopic.php?f=201&t=3144
Page 1 of 2

Author:  Rezeyu [ Mon Dec 10, 2007 7:51 pm ]
Post subject:  What consumes RAM Client side?

For some reason, starting this morning, my client takes up 78k kb, using 81-100% of my CPU.

I'm not sure why.
Worse, I don't know where to start looking.

The only thing I checked was that everything is cleared properly, but I don't see how that'd affect during runtime.

In the menu, it uses 0%, as soon as the ingame packet is sent, it jumps to 100%.


I'm not sure if It's a DX7 issue, possibly an error in the extra tile types, it could be the "NPCDATA" packet, I think it's being sent too often for every NPC.


Ideas?
:cry:

Author:  Lea [ Mon Dec 10, 2007 8:21 pm ]
Post subject:  Re: What consumes RAM Client side?

get a code profiler and see what subs/functions are taking the most time :D

Or you can write a code profiler and (simply get the time a block of code starts, and time it until it ends. Write all the profiled results to a text file and calculate percentages, etc.

Author:  Spodi [ Mon Dec 10, 2007 8:50 pm ]
Post subject:  Re: What consumes RAM Client side?

The RAM usage is mostly going towards the graphic files most likely. They are all loaded into memory and stick there.

CPU usage is probably due to a lack of Sleep in the game loop. I'll just steal what I PMed to William a while ago to prevent having to re-type it:

Quote:
First, get the Sleep API declared.

http://allapi.mentalis.org/apilist/Sleep.shtml

Now, say this is your client's pseudo game loop:

Code:
Dim StartTime As Long
Dim ElapsedTime As Long

Do
StartTime = GetTickCount

'Do game loop

ElapsedTime = GetTickCount - StartTime
Loop


Now after you get the elapsed time per frame, check it in comparison to the frame rate you desire. I think MS already does something like this, but the "wait" loop is something like:

Code:
Do While (GetTickCount - StartTime) < (1000 / MyFrameRate)
DoEvents
Loop


If thats the case, then just put after the DoEvents a "Sleep 1".

The Sleep API just basically stops the application for X milliseconds, freeing up the resources. What is happening is I assume you're on a single-core CPU. Your client is sucking up all the CPU, and since it is the active window, Windows gives it the priority over the server.

It is also beneficial to those on a laptop since it keeps their CPU usage down, which means more battery life and less fan usage. ;)


Quote:
I added the declare, but the only thing the client have remotly close to that code you posted is the fps cap:
Code:
' Lock fps
Do While GetTickCount < Tick + 33
DoEvents
Loop

Should I put sleep 1 below the doevetnts?


Quote:
Yup, thats exactly it. So yeah, just add Sleep 1 below that DoEvents and you will no longer be an enemy of CPUs. :P

Author:  William [ Mon Dec 10, 2007 9:10 pm ]
Post subject:  Re: What consumes RAM Client side?

I already had the sleep declare so I think it's already in MS.

Author:  Rezeyu [ Tue Dec 11, 2007 1:39 am ]
Post subject:  Re: What consumes RAM Client side?

It was already declared, but used nowhere in the code.

I raised the FPS lock by 2 (to 35) and it dropped CPU usage by 10% on average.
Added a sleep 1 as you said, and brought the FPS lock back to 33, and now it only used 3% CPU.

=]



Only reason I noticed the issue was because I kept freezing changing maps, like I would change maps, and I couldn't move anymore, and when that happened, my CPU would be at 100%.

NPcs and Mobs were skipping too.


EDIT:
Sigh.. I still get stuck walking through maps randomly, like a 13% chance that when switching maps, I'm unable to move.

Author:  Rezeyu [ Tue Dec 11, 2007 3:45 am ]
Post subject:  Re: What consumes RAM Client side?

I toggled breakpoints on all the Canmove = False lines, and when I'm frozen, none of them are triggered. Moving = 0, and IsTryingToMove is false.

But NPCs and Mobs can still move around, warping to the map after being frozen fixes it.

Author:  L [ Tue Dec 11, 2007 4:44 am ]
Post subject:  Re: What consumes RAM Client side?

You could add a /sync command.

Send a packet to the server and simply warp to your current x/y.

Just a thought.

Author:  Lea [ Tue Dec 11, 2007 4:48 am ]
Post subject:  Re: What consumes RAM Client side?

Not a good idea, it adds a security hole.

Author:  Rezeyu [ Tue Dec 11, 2007 5:02 am ]
Post subject:  Re: What consumes RAM Client side?

Thought about it, decided against it.


I'd rather remove an issue than patch it up.

Author:  Rezeyu [ Tue Dec 11, 2007 11:55 pm ]
Post subject:  Re: What consumes RAM Client side?

=[


No ideas?
Never happened to anyone else game before?

Author:  Robin [ Wed Dec 12, 2007 12:45 pm ]
Post subject:  Re: What consumes RAM Client side?

I have 50 different tilesets which are only loaded one at a time, so I only take up 1.55mb of RAM with that :]

Gonna create an automatic sprite recognition system which will allow RMXP style spritesheets as well :D

Author:  Rezeyu [ Wed Dec 12, 2007 6:50 pm ]
Post subject:  Re: What consumes RAM Client side?

My compiled client uses 3.5 MB, and only 2% CPU now.

My problem now is I'm getting the problem that I've seen other have, where you need to resync. I leave/enter a map, and am completely frozen.

Author:  Robin [ Wed Dec 12, 2007 7:18 pm ]
Post subject:  Re: What consumes RAM Client side?

Get a better server, or sort out your packets.

Author:  Lea [ Wed Dec 12, 2007 8:53 pm ]
Post subject:  Re: What consumes RAM Client side?

It's a strange problem, and it seems to happen consistently randomly, if that makes sense :P

For example, with Playerworlds back in the day, there was the ice skating bug. It seemed to happen only sometimes, and only for certain people. These kinds of bugs are the hardest to squish :P

To fix it, I would make certain all the values client side are the same as the ones server side, and probably just get rid of the CanMove sub client side, and instead send a "Can move?" to the server, which replies yes or no.

Author:  Robin [ Wed Dec 12, 2007 9:28 pm ]
Post subject:  Re: What consumes RAM Client side?

Actually.. I think Dave might have hit the nail on the head.

Because it's simply the player stopping moving, it's most probably a problem with that sub.

I've been meaning to remove the CanMove sub for a while, because it required twice the amount of work for the same effect as just having it serverside.

<3 Dave.

Author:  Rezeyu [ Wed Dec 12, 2007 10:32 pm ]
Post subject:  Re: What consumes RAM Client side?

Alright, I'll do that today. however the Canmove sub is never called when it happens.
I added breakpoints on canmove, and all the canmove = false's inside of it, as well as every instance of 'istryingtomove' and everything detecting keypresses.

None of them are triggered when I'm frozen, yet NPCs and Mobs are able to move.

Author:  Lea [ Wed Dec 12, 2007 11:22 pm ]
Post subject:  Re: What consumes RAM Client side?

Actually, thinking about it more, I would send a "Try To Move" and then have the server either move you and say "good" or not move you and say, "wtf you little fuck quit wasting my time with bogus shit!"

That way you avoid the whole "can I move here?" "Yes" "Ok, move me there" "kkthx" loop, and instead turns into "Move me here" "No."

Rez, that's strange. I would guess, since not even keypresses are registering, that you're getting stuck in a loop somewhere.

Author:  Rezeyu [ Wed Dec 12, 2007 11:43 pm ]
Post subject:  Re: What consumes RAM Client side?

Well, I tried compiling and running..

And I noticed that ONLY when I freeze, upon exiting the game, I get the RTE 91, the object variable one.

I'm not sure what object I've fucked up though.
I must be stuck in something like you said, since that RTE is the one that usually pops up when you didn't end something right?

Running through the IDE, I never get that error.

Author:  Lea [ Thu Dec 13, 2007 12:55 am ]
Post subject:  Re: What consumes RAM Client side?

do you have any classes in your code?

Author:  Rezeyu [ Thu Dec 13, 2007 1:29 am ]
Post subject:  Re: What consumes RAM Client side?

Nope.

I never use objects either, I used one for centering font once.. but took it out.
I don't fully understand objects and such, so I don't use them.


Whatever it is is client side, but why don't I get the RTE when running through the IDE?

Author:  Spodi [ Thu Dec 13, 2007 2:13 am ]
Post subject:  Re: What consumes RAM Client side?

Wouldn't it be easier to just do:

- Can I move here pl0x?

Then either:

- Ya shure, I tells everyone yous move'd

or:

- Lol u can't move, i dun process yer packet

Quote:
I never use objects either, I used one for centering font once.. but took it out.
I don't fully understand objects and such, so I don't use them.


Thats because objects are worthless crap in VB6.

Author:  Lea [ Thu Dec 13, 2007 2:32 am ]
Post subject:  Re: What consumes RAM Client side?

That's what I meant :P

kkthx.

Author:  Rezeyu [ Thu Dec 13, 2007 5:07 am ]
Post subject:  Re: What consumes RAM Client side?

But I haven't added any objects.


The only objects being set are the DX7 Surface ones, and they're all release properly as well.
I don't understand why the RTE doesn't pop up in the IDE or during Compilation.


EDIT: I narrowed it down slightly..

you know that bit that displays "Receiving Map..." that's commented out?
I had a gut feeling, and uncommented it.

sure enough, whenever my player freezes, that message is displaying nonstop.


Sooo... for some reason, the 'GettingMap = False' in the map completed packet isn't being read.

For the time being, until I figure out Wtf is wrong, I added a gettickcount timer that sets it back to false after a few seconds, since getting a map never takes that long.

But my coordinates are freaking out, so they must not be getting sent properly, but it happens so randomly..

I think it has something to do with my NPCs for some reason.

Author:  Robin [ Thu Dec 13, 2007 11:54 am ]
Post subject:  Re: What consumes RAM Client side?

Rezeyu wrote:
But I haven't added any objects.


The only objects being set are the DX7 Surface ones, and they're all release properly as well.
I don't understand why the RTE doesn't pop up in the IDE or during Compilation.


EDIT: I narrowed it down slightly..

you know that bit that displays "Receiving Map..." that's commented out?
I had a gut feeling, and uncommented it.

sure enough, whenever my player freezes, that message is displaying nonstop.


Sooo... for some reason, the 'GettingMap = False' in the map completed packet isn't being read.

For the time being, until I figure out Wtf is wrong, I added a gettickcount timer that sets it back to false after a few seconds, since getting a map never takes that long.

But my coordinates are freaking out, so they must not be getting sent properly, but it happens so randomly..

I think it has something to do with my NPCs for some reason.


Remove CanMove.

:D

Author:  Rezeyu [ Thu Dec 13, 2007 6:02 pm ]
Post subject:  Re: What consumes RAM Client side?

But it doesn't even reach that sub, I'm stuck receiving the map.

Page 1 of 2 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/