Right so I basically took a c++ script and moded it to AGS. The issue is that on higher sensitivites the movement is weird, it doesn't jitter in any value of sensitivity, but the movement appears to be "laggy" even though the game runs at 40 fps constant. However increasing the fps to 60 by using SetGameSpeed seems to fix the lag yet there are, regardless of game speed, some weird unexpected jumps. Any ways to make this better? I really don't wanna re-arrange the entire game at 60fps.
float sensitivity = 2.0;
float ox;
float oy;
function repeatedly_execute_always()
{
if(mouse.x != FloatToInt(ox, eRoundNearest) || mouse.y != FloatToInt(oy, eRoundNearest))
{
// Mouse has moved
// Work out the mouse movementinteger
if (Game.DoOnceOnly("set_fx"))
{
ox= IntToFloat(mouse.x);
oy= IntToFloat(mouse.y);
mouse.Visible=false;
return;
}
float x = IntToFloat(mouse.x);
float y = IntToFloat(mouse.y);
float nx = ox + ((x - ox) * sensitivity);
float ny = oy + ((y - oy) * sensitivity);
Mouse.SetPosition(FloatToInt(nx, eRoundNearest), FloatToInt(ny, eRoundNearest));
mouse.Update();
bmouse.Visible=true;
bmouse.NormalGraphic = mouse.GetModeGraphic(mouse.Mode);
bmouse.SetPosition(mouse.x, mouse.y);
// Set old location ready for next time
ox = nx;
oy = ny;
}
game.debug_mode = true;
Debug(4, 1);
}
It seems to me that perhaps the issue is that you are trying to set coordinates for the mouse that are out-of-bounds and so the engine is (silently) forcing it back into bounds which your code isn't accounting for. I slightly modified your code to the following, and both the visible feedback and the log I'm writing look fine:
float sensitivity = 2.0;
float ox;
float oy;
bool IsNullOrError(static File, File *file)
{
return ((file == null) || (file.Error));
}
void LogCoordinates(this Mouse*)
{
String fileName = "mouse.log";
File *f;
if (Game.DoOnceOnly("Create mouse log"))
{
f = File.Open(fileName, eFileWrite);
}
else f = File.Open(fileName, eFileAppend);
if (File.IsNullOrError(f)) AbortGame("Error opening mouse log!");
f.WriteRawLine(String.Format("Mouse: (%d, %d)", this.x, this.y));
f.Close();
}
function repeatedly_execute_always()
{
if ((mouse.x != FloatToInt(ox, eRoundNearest)) || (mouse.y != FloatToInt(oy, eRoundNearest)))
{
// Mouse has moved
// Work out the mouse movementinteger
if (Game.DoOnceOnly("set_fx"))
{
ox = IntToFloat(mouse.x);
oy = IntToFloat(mouse.y);
mouse.Visible = false;
return;
}
float x = IntToFloat(mouse.x);
float y = IntToFloat(mouse.y);
float nx = ox + ((x - ox) * sensitivity);
float ny = oy + ((y - oy) * sensitivity);
int xx = FloatToInt(nx, eRoundNearest);
int yy = FloatToInt(ny, eRoundNearest);
if (xx < 0)
{
xx = 0;
nx = 0.0;
}
if (xx > System.ViewportWidth)
{
xx = System.ViewportWidth;
nx = IntToFloat(System.ViewportWidth);
}
if (yy < 0)
{
yy = 0;
ny = 0.0;
}
if (yy > System.ViewportHeight)
{
yy = System.ViewportHeight;
ny = IntToFloat(System.ViewportHeight);
}
mouse.SetPosition(xx, yy);
mouse.Update();
mouse.LogCoordinates();
bmouse.Visible = true;
bmouse.NormalGraphic = mouse.GetModeGraphic(mouse.Mode);
bmouse.SetPosition(mouse.x, mouse.y);
// Set old location ready for next time
ox = nx;
oy = ny;
}
game.debug_mode = true;
Debug(4, 1);
}
In particular, note that I have checked that the results of IntToFloat(nx, eRoundNearest) and IntToFloat(ny, eRoundNearest) fall within the bounds of 0..System.ViewportWidth and 0..System.ViewportHeight, respectively, and if not that I have forced nx and ny into the proper bounds.
Unfortunately the issue remains, try making a circle or a rectangle with your mouse, better yet try to follow a rectangle or a circle, and see that it will jump around. :(
Should I upload the game to point out what I'm saying?
Also concerning this whole sensitivity issue, why are we not using "void set_mouse_speed(int xspeed, int yspeed);" from Allegro?