ID:2359937
 
i have a lag problem when i move but only when i host the game you can see the difference with the profile
Code:
              // When i don't Host              Profile results (total time)
Proc Name Self CPU Total CPU Real Time Calls
----------------------------------- --------- --------- --------- ---------
/client/Move 0.000 0.000 0.000 285
/client/West 0.000 0.000 0.000 110
/client/East 0.000 0.000 0.000 96
/client/North 0.000 0.000 0.000 44
/client/South 0.000 0.000 0.000 35


Code:
     //When i Host the game             Profile results (total time)
Proc Name Self CPU Total CPU Real Time Calls
------------- --------- --------- --------- ---------
/client/North 0.002 0.004 0.004 83
/client/Move 0.002 0.002 0.002 83
/atom/Click 0.000 0.000 0.000 1
/mob/verb/Run 0.000 0.000 0.000 1



you can see the difference when i host the game i only move 83 time and the cpu and real time increase.. and when i dont host it i move 285 time and the real time and cpu did not increase. do you guy have i idea what can cause that lag??
this is the move code itself
Code:
    Move(Loc)
var/GAME_MOB/M = mob
if(mob.isLoginMob)
return 0
if(mob.moving == TRUE || M.dead || M.defending || M.shop_open || M.using_jutsu != null || M.in_bind || M.charging == TRUE || M.casting_shadow == TRUE || M.CantMove == TRUE)
return 0
mob.moving = TRUE
if(M.swimming)
M.running = FALSE
M.step_size = 12
// mob.ActivateAI()
// CHECK_TICK()
// spawn(world.tick_lag)mob.moving = FALSE
spawn(0)mob.moving = FALSE
return ..()

it like the game run smooth when i dont host it but when i host it the game lag
Make a new version of EAST,WEST,NORTH,SOUTH,etc verbs that have set instant = TRUE on the first line (the verbs have to be new verbs) Then change the skin's macroset to use the new versions.

they should call the east/west/north/south verbs
i have this i forgot to show it
Code:
    North()
var/GAME_MOB/M = mob
if(M.dead)return
if(M.in_bind == 1)
return
if(M.key_pressing == TRUE)
M.key_pressed = "Up"
M.JutsuPress()
return
M.dir = NORTH
return ..()
South()
var/GAME_MOB/M = mob
if(M.dead)return
if(M.key_pressing == TRUE)
M.key_pressed = "Down"
M.JutsuPress()
return
if(M.in_bind == 1)
return

mob.dir = SOUTH
return ..()
West()
var/GAME_MOB/M = mob
if(M.dead)return
if(M.in_bind == 1)
return
if(M.key_pressing == TRUE)
M.key_pressed = "Left"
M.JutsuPress()
return
mob.dir = WEST
return ..()
East()
var/GAME_MOB/M = mob
if(M.dead)return
if(M.in_bind == 1)
return
if(M.key_pressing == TRUE)
M.key_pressed = "Right"
M.JutsuPress()
return
mob.dir = EAST
return ..()


and i have a verb for all movement that i dont show
I'd move it all out of client.

// Overrides mob/Move(), modify it as needed.
mob/Move(_,direction)
if(in_bind||dead||isLoginMob||moving||defending||shop_open||using_jutsu||charging||casting_shadow||CantMove){return}
moving = TRUE
if(swimming)
running = FALSE
M.step_size = 12
key_pressed = null
if(client && key_pressing)
// if the mob has a client, is alive, not binded, and is pressing a key, do eet.
// switch() is your friend, use it.
switch(direction)
if(NORTH) {key_pressed = "Up"}
if(EAST) {key_pressed = "Left"}
if(SOUTH) {key_pressed = "Down"}
if(WEST) {key_pressed = "Right"}
if(key_pressed)
src.JutsuPress() // sexy jutsu is a go
// This is horrible, but it's probably what your source is built upon.
spawn(world.tick_lag){moving = FALSE}
..() // happy ending
i just try your code, your code work put the game still lag.. if you want i can make you enter the game so you see on yourself what i mean by lag
and i was wondering can the var usr make all that bug ??
Again, these have to be NEW verbs, not the same internal byond verb, because set instant = TRUE doesn't work on overrides of internal byond verbs.

Rename them, edit the macro set, and add set instant = TRUE to all of them so that the server doesn't wait until the next tick to process them. This is the part that fixes the lag.

And that trick only works on the client's keypress verbs.
In response to Kozuma3
Kozuma3 wrote:
I'd move it all out of client.

Not sure that's appropriate, anything that's behind a if (client) check should be in the client itself. This allows you to seperate the movement logic that applies to players making a mob move, and the movement logic that applies to the mob moving, regardless of if its a player or a npc/game initiated move. If you put to much of that logic in the mob, you'll later run up against it when you make npc logic.

A good rule of object oriented programming, is that any explicit if check that can be made implicit by moving the code behind it to a different type/subtype, is a bad if check, and should be made implicit.
I Will try that
im trying what you say to fix my lag but in my macro the verb North command is .north i just when to know why it have a . before the command ??
In response to Carcanox32
The default North() client verb is hidden so it won't show up in the input box on a vanilla interface when you press the space bar to get a list of possible commands. Hence the . in front. You get the same effect by preceding any verb name with an underscore, so verb/_Hidden_Verb() would have to be entered as .hidden-verb in the input box to type it manually.
Oh oki thanks you :)