Difference between revisions of "API"

From WowWiki
Jump to navigation Jump to search
Line 145: Line 145:
 
Description:
 
Description:
  
:Effect (Combobox) [ Mosaic ] - at now only one selection
+
Description:
 +
: Render a texture with chosen algorithm and parameters.
 +
Arguments:
 +
: ''effectId''
 +
:: Define algorithm to render texture.
 +
:: Available values : G2D_DYNAMIC_TEXTURE_MOSAIC
  
:So in effect named 'mosaic' we have 10 parameters each one - 1 byte, so we need get memory buffer of 10 bytes, and need to pack them in four int32 values
+
: ''time ''
:For example if we have values above 1,2,3,4,5,6,7,8,9,10
+
:: Current time value. Use any fixed value to static texture or set current time value in milliseconds to make texture alive.
:We must have command parameters
+
: ''args'', ''argsCount''
 +
:: Byte stream of algorithm settings it's aligned to 4 bytes, because of pawn supports only 32-bit values.
 +
:: Size of array depends on algorithm. For example mosaic algorithm has size of settings equals 10 bytes , so we must use aligned 4 bytes - 12 bytes array and argsCount = 3
 +
 
 +
: ''g2d''
 +
:: false - Use pawn default buffer to draw texture.
 +
:: true - Use g2d buffer to draw texture - not supported now.
 +
 
 +
 
 +
/*G2D_DYNAMIC_TEXTURE_MOSAIC*/ alogrithm description
 +
 
 +
:So in effect named 'mosaic' we have settings of 10 parameters each one 1 byte
  
 
:Noise factors :
 
:Noise factors :
::factor x : Slider + Textbox [values : 0 - 10]
+
::factor x : values from 0 to 10
::factor y : Slider + Textbox [values : 0 - 10]
+
::factor y : values from 0 to 10
::factor xy : Slider + Textbox [values : 0 - 10]
+
::factor xy : values from 0 to 10
 
:Time factors :
 
:Time factors :
::factor x : Slider + Textbox [values : 0 - 10]
+
::factor x : values from 0 to 10
::factor y : Slider + Textbox [values : 0 - 10]
+
::factor y : values from 0 to 10
::factor xy : Slider + Textbox [values : 0 - 10]
+
::factor xy : values from 0 to 10
 
:Color factors :
 
:Color factors :
::r : Slider + Textbox [values : 0 - 10]
+
::r : values from 0 to 10
::g : Slider + Textbox [values : 0 - 10]
+
::g : values from 0 to 10
::b : Slider + Textbox [values : 0 - 10]
+
::b : values from 0 to 10
 
:Zoom factor :
 
:Zoom factor :
::Slider + Textbox [values : 0 - 10]
+
::zoom  values from 0 to 10
 +
 
 +
For example we want to set all parameters above with values in order 1,2,3,4,5,6,7,8,9,10. Take in attention that each parameter is 1 byte we must make array of 32-bit values
 +
0x04030201, 0x08070605, 0x00000A09
 +
 
 +
Example:
 +
mosaic_effect_settings = { 0x04030201, 0x08070605, 0x00000A09  };
 +
mosaic_effect_settings_length = 3;
 +
abi_CMD_TEXT(G2D_DYNAMIC_TEXTURE_MOSAIC , currentTime, mosaic_effect_settings, mosaic_effect_settings_length);

Revision as of 08:39, 10 September 2020

Template:Notice

Introduction

The main functions of the API are listed here, the features of the work of the environment are described

WOWCube Paradigms

WOWCube executes 8 copies of the byte-code of the script at the same time, providing functions for the interaction of scripts with each other, drawing functions, functions for accessing resources, and other specific functions. Each copy of the script has access to 3 displays. Resource scripts are packed into a package.

Pawn API

Graphic functions

Graphics 2D acceleration (G2D)

WOWCube provides the 2D acceleration interfaces to enhance gaming experience . Basically G2D engine allows to blend up to the 4 image layers at once with a HW acceleration. However there is no limit of layers, they are blended in a cascade. For example, if Pawn script requested 7 layers to be blended then 2 HW blending will occur:

G2D cascading scheme

Result of the blending can be saved as an internal G2D resource or flushed immediately on the specified display. Internal G2D resources can be used as an usual bitmap primitive (abi_CMD_BITMAP) or reused as an input for the next G2D action. Basic coordinate principle:

G2D coordinates sceme

Coordinates are limited from -2048 to 2047. Maximum layers size is 240x240.

abi_CMD_G2D_BEGIN_BITMAP

Syntax:

abi_CMD_G2D_BEGIN_BITMAP(const resID, const width, const height, const bool:replace)

Description:

abi_CMD_G2D_BEGIN_BITMAP and abi_CMD_G2D_END delimits the group of layers to be blended into internal G2D resource. This API is not intended for frequent usage. It is better suited for complex background generation on game initialization or dynamic resource modification triggered by rare game events.

Arguments:

resID
ID of the resource that will be generated from blending layers presented between abi_CMD_G2D_BEGIN_BITMAP and the subsequent abi_CMD_G2D_END. G2D engine can keep up to 3 different resources with IDs: 0, 1 and 2.
width
Width of the resulting resource. G2D engine can keep resource of 240px width maximum.
height
Height of the resulting resource. G2D engine can keep resource of 240px height maximum.
replace
If true, then an existing image will be replaced completely, otherwise it will be overwritten by reusing itself as a background layer.
abi_CMD_G2D_BEGIN_DISPLAY

Syntax:

abi_CMD_G2D_BEGIN_DISPLAY(const display, const bool:replace)

Description:

abi_CMD_G2D_BEGIN_DISPLAY and abi_CMD_G2D_END delimits the group of layers to be blended directly into display framebuffer. Obviously this API is designed for rendering scene on game tick. This API is not limited by layers count as well as abi_CMD_G2D_BEGIN_BITMAP. However it is strictly recommended to blend no more than 4 layers. Otherwise cascade blending will be initiated resulting in some FPS drop.

Arguments:

display
ID of the display which framebuffer will be used for blending. Each module have 3 displays with ID starting from 0.
replace
If true then an existing image will be replaced completely, otherwise it will be overwritten by reusing itself as a background layer.
abi_CMD_G2D_ADD_SPRITE

Syntax:

abi_CMD_G2D_ADD_SPRITE(const resID, const bool:g2d, const x, const y, const alpha, const color, const rotation, const mirror)

Description:

Specifies game resource which will be used as a layer for blending.

Arguments:

resID
ID of the resource to be uses as a layer.
g2d
Indicates if an internal G2D resource is specified or not.
x, y
Coordinates of the bitmap center to place on the layer.
alpha
Layer transparency in range between 0x00 and 0xFF, where 0x00 is a fully transparent layer.
color
Layer's source key - a color in ARGB8888 format to be avoided.
rotation
Clockwise rotation angle in degrees. It is possible to specify free angle, but only right angles have HW acceleration. Currently rotation only applicable for external resources.
mirror
Mirroring variant. Possible values are self-explained: MIRROR_BLANK, MIRROR_X, MIRROR_Y, MIRROR_XY.
abi_CMD_G2D_ADD_RECTANGLE

Syntax:

abi_CMD_G2D_ADD_RECTANGLE(const x, const y, const width, const height, const color)

Description:

Specifies rectangle area which will be used as layer of blending. This API is not intended for frequent usage, i.e. particles generation. It is better suited for changing image background or applying color mask.

Arguments:

x, y
Coordinates of top left rectangle corner.
width
Rectangle width.
height
Rectangle height.
color
Rectangle color in ARGB8888 format.
abi_CMD_G2D_END

Syntax:

abi_CMD_G2D_END()

Description:

abi_CMD_G2D_END() and abi_CMD_G2D_BEGIN_BITMAP/abi_CMD_G2D_BEGIN_DISPLAY delimits the group of layers to be blended. After abi_CMD_G2D_END call final blending will be initiated and results will be stored according to the begin comand.
Examples

1. Render into inner G2D resource buffer #face and display it on the display #face. Please, note that last argument of abi_CMD_BITMAP is a `true` flag, which means G2D resource should be used:

...
abi_CMD_G2D_BEGIN_BITMAP(face, 240, 240, true);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize0, 120 - animationSquareSize0, animationSquareSize0 * 2, animationSquareSize0 * 2, 0xdfff0000);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize1, 120 - animationSquareSize1, animationSquareSize1 * 2, animationSquareSize1 * 2, 0xdfffff00);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize2, 120 - animationSquareSize2, animationSquareSize2 * 2, animationSquareSize2 * 2, 0xdfff00ff);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize3, 120 - animationSquareSize3, animationSquareSize3 * 2, animationSquareSize3 * 2, 0xdf00ffff);
abi_CMD_G2D_ADD_SPRITE(resID, false, 120, 120, animationAlpha, 0x00000000, animationAngle, MIRROR_BLANK);
abi_CMD_G2D_END();
...
abi_CMD_BITMAP(face, 120, 120, 0, MIRROR_BLANK, true);
...
abi_CMD_REDRAW(face);
...

2. Render directly into display framebuffer #face. This will produce same result on display as example #1, but the generated image is not saved:

...
abi_CMD_G2D_BEGIN_DISPLAY(face, true);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize0, 120 - animationSquareSize0, animationSquareSize0 * 2, animationSquareSize0 * 2, 0xdfff0000);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize1, 120 - animationSquareSize1, animationSquareSize1 * 2, animationSquareSize1 * 2, 0xdfffff00);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize2, 120 - animationSquareSize2, animationSquareSize2 * 2, animationSquareSize2 * 2, 0xdfff00ff);
abi_CMD_G2D_ADD_RECTANGLE(120 - animationSquareSize3, 120 - animationSquareSize3, animationSquareSize3 * 2, animationSquareSize3 * 2, 0xdf00ffff);
abi_CMD_G2D_ADD_SPRITE(resID, false, 120, 120, animationAlpha, 0x00000000, animationAngle, MIRROR_BLANK);
abi_CMD_G2D_END();
...

Font drawing functions

abi_CMD_TEXT

API:

 abi_CMD_TEXT(const text[], const fontResID, const x, const y, const scale, const angle, const r, const g, const b)

Description:

Intended to render a system font or a custom font from resources with specified coordinates, scale and rotation at an arbitrary angle.

Arguments:

text
Array of chars.
fontResID
Custom font resource identifier.
x, y
Coordinates of top left rectangle corner.
scale, angle
Percentage scale and clockwise rotation angle in degrees. Max size of font is 200x200 px. (scale = 100%)
r, g, b
Font color in RGB format.

Example:

new text[4] = ['A', 'p', 'p', '\0'];
abi_CMD_TEXT(text, RES_ID_FONT, 90, 160, 16, current_angles[face], 255, 0, 0);

TEXTURE drawing functions

abi_CMD_DYNAMIC_TEXTURE

API:

abi_CMD_DYNAMIC_TEXTURE(const effectId = 1, const time = any value, const args[] = {0x04030201, 0x08070605, 0x00000A09}, const argsCount = 3, const bool:g2d = false)

Description:

Description:

Render a texture with chosen algorithm and parameters.

Arguments:

effectId
Define algorithm to render texture.
Available values : G2D_DYNAMIC_TEXTURE_MOSAIC
time
Current time value. Use any fixed value to static texture or set current time value in milliseconds to make texture alive.
args, argsCount
Byte stream of algorithm settings it's aligned to 4 bytes, because of pawn supports only 32-bit values.
Size of array depends on algorithm. For example mosaic algorithm has size of settings equals 10 bytes , so we must use aligned 4 bytes - 12 bytes array and argsCount = 3
g2d
false - Use pawn default buffer to draw texture.
true - Use g2d buffer to draw texture - not supported now.


/*G2D_DYNAMIC_TEXTURE_MOSAIC*/ alogrithm description

So in effect named 'mosaic' we have settings of 10 parameters each one 1 byte
Noise factors :
factor x : values from 0 to 10
factor y : values from 0 to 10
factor xy : values from 0 to 10
Time factors :
factor x : values from 0 to 10
factor y : values from 0 to 10
factor xy : values from 0 to 10
Color factors :
r : values from 0 to 10
g : values from 0 to 10
b : values from 0 to 10
Zoom factor :
zoom values from 0 to 10

For example we want to set all parameters above with values in order 1,2,3,4,5,6,7,8,9,10. Take in attention that each parameter is 1 byte we must make array of 32-bit values 0x04030201, 0x08070605, 0x00000A09

Example:

mosaic_effect_settings = { 0x04030201, 0x08070605, 0x00000A09  };
mosaic_effect_settings_length = 3;
abi_CMD_TEXT(G2D_DYNAMIC_TEXTURE_MOSAIC , currentTime, mosaic_effect_settings, mosaic_effect_settings_length);