ID:2316077
 
(See the best response by Ter13.)
Just had a random thought. How many resources does mouse follow or mouse drag procs use? Im thinking of a game where you can cast different spells but all of the spells would use your cursor to be created, for instance if you cast a wall of fire, then use your mouse to actually draw that wall of fire onto the map... Or maybe a Ice projectile that has a sleep statement and you draw out your own projectile within the sleep timer THEN it fires the projectile once the timer is up?

I ask because I realized this would allow players complete control and customization of spells and or powers in such a way I personally havent seen before

*Edit*
This of course would be in a PVP enviroment, with multiple users, calling mouse follow procs, in theory if I could make this work, I dont want the game to be so bogged down and laggy that is unplayable

Best response
MouseMove()/MouseDrag() are called potentially dozens of times per frame.

To reduce the overhead of using them, it's probably best to only process mouse movement once per frame by caching mouse parameters and having a loop do the grunt work only once per frame.

#define TILE_WIDTH 32
#define TILE_HEIGHT 32

client
var
mouse_loc
mouse_x
mouse_y

MouseMove(atom/object,atom/location,control,params)
mouse_loc = params
..()

MouseDrag(atom/src_object,atom/over_object,atom/src_location,atom/over_location,src_control,over_control,params)
mouse_loc = params
..()

proc
MouseLoop()
set waitfor = 0
var/list/l, list/sx, list/sy
while(src)
if(mouse_loc)
l = splittext(params2list(mouse_loc)["screen-loc"],",")
sx = splittext(l[1],":")
sy = splittext(l[2],":")

mouse_x = text2num(sx[1]) * TILE_WIDTH + text2num(sx[2])-1
mouse_y = text2num(sy[1]) * TILE_HEIGHT + text2num(sy[2])-1

mouse_loc = null

sleep(world.tick_lag)

New()
. = ..()
MouseLoop()


Essentially, it's better to do as little as possible in MouseMove()/MouseDrag(). If you do any heavy lifting at all in these procs, you are going to pay the price. If you need to tie something to the mouse update proc, it's best to handle it in a ticker structure.
Hmmm figured as much, well would there be a way to make it so you could draw said spells in the same way, BUT it would save the "drawing" of the spells location in relation to the character? So when they learn a spell they can draw it out( could be down a bit cleaner by using Click() instead to make things less draining) then after its saved, they can just used the spell and it will spawn it there automatically but in the direction they are facing?
You should research games that have done a spell drawing system using the mouse.

Protip: Nobody liked any of them.
In response to Ter13
Ter13 wrote:
You should research games that have done a spell drawing system using the mouse.

Protip: Nobody liked any of them.

I liked Black & White. But yeah, you're pretty much right...

Login to reply.