Commit 205da1f5 authored by ROOL's avatar ROOL 🤖

Moderate spray can density based on time not CPU speed

Detail:
  The spray tool rate was ultimately determined by the number of wimp polls per second, which on a fast CPU can be 10,000's making the spray can more of a circle drawing tool.
  Use OS_ReadMonotonicTime to moderate the spray rate, so the speed of the CPU doesn't matter.
  Default density increased to 100 to achieve roughly the same density as a StrongARM Risc PC would previously.
Admin:
  Submission for the Paint bounty.

Version 2.21. Tagged as 'Paint-2_21'
parent c2a2a721
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "2.20"
Module_Version SETA 220
Module_MajorVersion SETS "2.21"
Module_Version SETA 221
Module_MinorVersion SETS ""
Module_Date SETS "14 Oct 2015"
Module_ApplicationDate SETS "14-Oct-15"
Module_Date SETS "20 May 2017"
Module_ApplicationDate SETS "20-May-17"
Module_ComponentName SETS "Paint"
Module_ComponentPath SETS "castle/RiscOS/Sources/Apps/Paint"
Module_FullVersion SETS "2.20"
Module_HelpVersion SETS "2.20 (14 Oct 2015)"
Module_FullVersion SETS "2.21"
Module_HelpVersion SETS "2.21 (20 May 2017)"
END
/* (2.20)
/* (2.21)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 2.20
#define Module_MajorVersion_CMHG 2.21
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 14 Oct 2015
#define Module_Date_CMHG 20 May 2017
#define Module_MajorVersion "2.20"
#define Module_Version 220
#define Module_MajorVersion "2.21"
#define Module_Version 221
#define Module_MinorVersion ""
#define Module_Date "14 Oct 2015"
#define Module_Date "20 May 2017"
#define Module_ApplicationDate "14-Oct-15"
#define Module_ApplicationDate "20-May-17"
#define Module_ComponentName "Paint"
#define Module_ComponentPath "castle/RiscOS/Sources/Apps/Paint"
#define Module_FullVersion "2.20"
#define Module_HelpVersion "2.20 (14 Oct 2015)"
#define Module_LibraryVersionInfo "2:20"
#define Module_FullVersion "2.21"
#define Module_HelpVersion "2.21 (20 May 2017)"
#define Module_LibraryVersionInfo "2:21"
......@@ -68,10 +68,11 @@ static int textxsize;
static int textysize;
static int textxspace;
char tools_spray_density [5] = "20";
char tools_spray_density [5] = "100";
char tools_spray_radius [5] = "30";
static int spraydensity;
static int sprayradius;
static int spraytime = 0;
/* SMC: The following are not sprite names. They are tokens which must be
* used to look up the real sprite name in the Messages file.
......@@ -2174,63 +2175,91 @@ static void spraycanpaint_splot (main_window *window, wimp_mousestr *mpos)
/*Do nothing if radius == 0. J R C 5th Oct 1993*/
if (sprayradius > 0)
{
int pxs, pys;
tools_mouse_to_pixel (window, mpos, &x, &y);
pxs=tools_pixel_to_point_x(&window->data->sprite, 1);
pys=tools_pixel_to_point_y(&window->data->sprite, 1);
int pxs, pys, elapsed, adjusted_density;
/*Adjust spray density according to CPU speed */
os_swix1r(OS_ReadMonotonicTime, 0, &elapsed);
if (spraytime > 0)
{
elapsed -= spraytime;
/*Divide this by a bigger constant to slow down the spray rate*/
adjusted_density = (spraydensity * elapsed) / 8;
if (adjusted_density > 0)
{
/*Reset the timer*/
spraytime += elapsed;
/*Sanity checks to stop unresponsiveness*/
if (adjusted_density > 999)
adjusted_density = 999;
if (adjusted_density > spraydensity * 2)
adjusted_density = spraydensity * 2;
}
}
else
{
/*Initial spray iteration*/
spraytime = elapsed;
adjusted_density = spraydensity / 10;
}
colour = colours_pack_colour(sprite, gcol);
mask = colours_pack_mask(sprite, gcol);
if (adjusted_density > 0)
{
tools_mouse_to_pixel (window, mpos, &x, &y);
pxs=tools_pixel_to_point_x(&window->data->sprite, 1);
pys=tools_pixel_to_point_y(&window->data->sprite, 1);
sprite->toolspace [0] = x;
sprite->toolspace [1] = y;
ftracef2 ("0x%X->toolspace [0]: 0x%X\n",
sprite, sprite->toolspace [0]);
colour = colours_pack_colour(sprite, gcol);
mask = colours_pack_mask(sprite, gcol);
sid.s.addr = psprite_address (sprite);
sid.tag = sprite_id_addr;
sprite->toolspace [0] = x;
sprite->toolspace [1] = y;
ftracef2 ("0x%X->toolspace [0]: 0x%X\n",
sprite, sprite->toolspace [0]);
dopix = gcol.alpha || (psprite_transparency_type(sprite) == transparency_type_alphachannel);
domask = psprite_hasmask (sprite);
sid.s.addr = psprite_address (sprite);
sid.tag = sprite_id_addr;
visdelay_begin ();
for (i = 0; i < spraydensity; i++)
{ int r, nx, ny;
double theta;
dopix = gcol.alpha || (psprite_transparency_type(sprite) == transparency_type_alphachannel);
domask = psprite_hasmask (sprite);
/*nx = (myrnd () >> 24) % sprayradius;
ny = (myrnd () >> 23) % sprayradius;*/
visdelay_begin ();
for (i = 0; i < adjusted_density; i++)
{ int r, nx, ny;
double theta;
/*nx = myrnd ()%sprayradius;
ny = myrnd ()%sprayradius;*/
/*nx = (myrnd () >> 24) % sprayradius;
ny = (myrnd () >> 23) % sprayradius;*/
r = myrnd ()%sprayradius;
theta = fmod ((double) myrnd (), 2*3.1415926);
/*nx = myrnd ()%sprayradius;
ny = myrnd ()%sprayradius;*/
nx = x + (int) (r*cos (theta))/pxs;
ny = y + (int) (r*sin (theta))/pys;
r = myrnd ()%sprayradius;
theta = fmod ((double) myrnd (), 2*3.1415926);
if (dopix)
{ sprite_colour newcolour = colour;
nx = x + (int) (r*cos (theta))/pxs;
ny = y + (int) (r*sin (theta))/pys;
MUNGE_PIXEL (nx, ny, &newcolour, &gcol, sarea, &sid, sprite)
ftracef2 ("sprite_writepixel (GCOL 0x%X, TINT 0x%X)\n",
newcolour.colour, newcolour.tint);
sprite_writepixel (sarea, &sid, nx, ny, &newcolour);
}
if (dopix)
{ sprite_colour newcolour = colour;
if (domask)
sprite_writemask (sarea, &sid, nx, ny, &mask);
}
visdelay_end ();
MUNGE_PIXEL (nx, ny, &newcolour, &gcol, sarea, &sid, sprite)
ftracef2 ("sprite_writepixel (GCOL 0x%X, TINT 0x%X)\n",
newcolour.colour, newcolour.tint);
sprite_writepixel (sarea, &sid, nx, ny, &newcolour);
}
if (domask)
sprite_writemask (sarea, &sid, nx, ny, &mask);
}
visdelay_end ();
redraw_area.x0=tools_pixel_to_point_x(&window->data->sprite, x) - sprayradius;
redraw_area.y0=tools_pixel_to_point_y(&window->data->sprite, y) - sprayradius;
redraw_area.x1=tools_pixel_to_point_x(&window->data->sprite, x+1) + sprayradius + 1;
redraw_area.y1=tools_pixel_to_point_y(&window->data->sprite, y+1) + sprayradius + 1;
sprwindow_redisplay (sprite, &redraw_area);
redraw_area.x0=tools_pixel_to_point_x(&window->data->sprite, x) - sprayradius;
redraw_area.y0=tools_pixel_to_point_y(&window->data->sprite, y) - sprayradius;
redraw_area.x1=tools_pixel_to_point_x(&window->data->sprite, x+1) + sprayradius + 1;
redraw_area.y1=tools_pixel_to_point_y(&window->data->sprite, y+1) + sprayradius + 1;
sprwindow_redisplay (sprite, &redraw_area);
}
}
}
......@@ -2273,7 +2302,11 @@ static void spraycanpaint_null (main_window *window, wimp_mousestr *mpos)
{ ftracef0 ("spraycanpaint_null\n");
if (mpos->bbits == 0) /*if the mouse button is now up, stop tracking*/
{
sprwindow_release_idle_events (window->data->sprite.sprite);
/*Reset spray timer*/
spraytime = 0;
}
else
spraycanpaint_splot (window, mpos);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment