use dirty regin to optimize box update

This commit is contained in:
lyon1998 2021-11-04 23:50:03 +08:00
parent 2d51b4d4e2
commit 77db643997
5 changed files with 114 additions and 36 deletions

View File

@ -1,37 +1,78 @@
#include "Arm2D_Box.h"
#include "Arm2D_common.h"
#include "asset_corner_box.h"
#include "dataArgs.h"
void Arm2D_Box_init(PikaObj* self) {
obj_setInt(self, "posX", 0);
obj_setInt(self, "posY", 0);
obj_setInt(self, "sizeX", 50);
obj_setInt(self, "sizeY", 50);
obj_setInt(self, "alpha", 128);
obj_setStr(self, "color", "blue");
/* init elem info */
pika_arm2d_element_info_t elemInfo = {0};
elemInfo.alpha = 255;
elemInfo.x = 0;
elemInfo.y = 0;
args_setStruct(self, "elemInfo", &elemInfo, sizeof(pika_arm2d_element_info_t));
/* init box info */
pika_arm2d_box_info_t boxInfo = {0};
boxInfo.wight = 50;
boxInfo.hight = 50;
boxInfo.color_code = getColorCode("blue");
/* load box info to arg */
args_setStruct(self, "boxInfo", &boxInfo, sizeof(pika_arm2d_box_info_t));
/* add dirtyReginItem */
args_setStruct(self, "dirtyReginItem", NULL, sizeof(arm_2d_region_list_item_t));
}
int __min(int x,int y){
return x<y?x:y;
}
int __max(int x,int y){
return x>y?x:y;
}
void Arm2D_Box_update(PikaObj* self) {
pika_arm2d_box_info_t* boxInfo = args_getStruct(self, "boxInfo");
void* target_tile = pika_arm2d_window.pfb_tile_now;
bool bIsNewFrame = pika_arm2d_window.pfb_is_new_frame;
int posX = args_getInt(self, "posX");
int posY = args_getInt(self, "posY");
int sizeX = args_getInt(self, "sizeX");
int sizeY = args_getInt(self, "sizeY");
int alpha = args_getInt(self, "alpha");
char* color = args_getStr(self, "color");
arm_2d_region_t tBox = {
.tLocation = {posX, posY},
.tSize = {sizeX, sizeY},
};
draw_round_corner_box(target_tile, &tBox, getColorCode(color), alpha ,bIsNewFrame);
if(bIsNewFrame){
pika_arm2d_element_info_t* elemInfo = args_getStruct(self, "elemInfo");
boxInfo->arg2d_regin.tSize.iHeight = boxInfo->hight;
boxInfo->arg2d_regin.tSize.iWidth = boxInfo->wight;
boxInfo->arg2d_regin.tLocation.iX = elemInfo->x;
boxInfo->arg2d_regin.tLocation.iY = elemInfo->y;
memcpy(&(boxInfo->elem_info), elemInfo, sizeof(pika_arm2d_element_info_t));
arm_2d_region_list_item_t* dirtyReginItem = args_getStruct(self, "dirtyReginItem");
dirtyReginItem->ptNext = NULL;
int x_start = __min(boxInfo->elem_info.x, boxInfo->elem_info.x_last) - 14;
int y_start = __min(boxInfo->elem_info.y, boxInfo->elem_info.y_last) - 7;
int x_end = __max(boxInfo->elem_info.x + boxInfo->wight, boxInfo->elem_info.x_last + boxInfo->wight_last);
int y_end = __max(boxInfo->elem_info.y + boxInfo->hight, boxInfo->elem_info.y_last + boxInfo->hight_last);
int hight = y_end - y_start + 7;
int wight = x_end - x_start + 14;
dirtyReginItem->tRegion.tLocation.iX = x_start;
dirtyReginItem->tRegion.tLocation.iY = y_start;
dirtyReginItem->tRegion.tSize.iHeight = hight;
dirtyReginItem->tRegion.tSize.iWidth = wight;
pika_arm2d_window.dirty_region_list = dirtyReginItem;
}
draw_round_corner_box(target_tile, &(boxInfo->arg2d_regin), boxInfo->color_code,
boxInfo->elem_info.alpha, bIsNewFrame);
}
void Arm2D_Box_setColor(PikaObj* self, char* color) {
args_setStr(self, "color", color);
pika_arm2d_box_info_t* boxInfo = args_getStruct(self, "boxInfo");
boxInfo->color_code_last = boxInfo->color_code;
boxInfo->color_code = getColorCode(color);
}
void Arm2D_Box_setSize(PikaObj* self, int x, int y) {
args_setInt(self, "sizeX", x);
args_setInt(self, "sizeY", y);
pika_arm2d_box_info_t* boxInfo = args_getStruct(self, "boxInfo");
boxInfo->wight_last = boxInfo->wight;
boxInfo->hight_last = boxInfo->hight;
boxInfo->wight = x;
boxInfo->hight = y;
}

View File

@ -7,32 +7,53 @@ void Arm2D_Element_update(PikaObj* self) {
}
void Arm2D_Element_init(PikaObj* self) {
args_setInt(self, "posX", 0);
args_setInt(self, "posY", 0);
args_setInt(self, "alpha", 255);
pika_arm2d_element_info_t elemInfo = {0};
elemInfo.alpha = 255;
elemInfo.x = 0;
elemInfo.y = 0;
args_setStruct(self, "elemInfo", &elemInfo, sizeof(pika_arm2d_element_info_t));
}
void Arm2D_Element_setAlpha(PikaObj* self, int alpha) {
args_setInt(self, "alpha", alpha);
pika_arm2d_element_info_t* elemInfo = args_getStruct(self, "elemInfo");
elemInfo->alpha_last = elemInfo->alpha;
elemInfo->alpha = alpha;
}
void Arm2D_Element_up(PikaObj* self, int y) {
args_setInt(self, "posY", obj_getInt(self, "posY") - y);
pika_arm2d_element_info_t* elemInfo = args_getStruct(self, "elemInfo");
elemInfo->y_last = elemInfo->y;
elemInfo->y = elemInfo->y - y;
}
void Arm2D_Element_down(PikaObj* self, int y) {
args_setInt(self, "posY", obj_getInt(self, "posY") + y);
pika_arm2d_element_info_t* elemInfo = args_getStruct(self, "elemInfo");
elemInfo->y_last = elemInfo->y;
elemInfo->y = elemInfo->y + y;
}
void Arm2D_Element_lift(PikaObj* self, int x) {
args_setInt(self, "posX", obj_getInt(self, "posX") - x);
}
pika_arm2d_element_info_t* elemInfo = args_getStruct(self, "elemInfo");
elemInfo->x_last = elemInfo->x;
void Arm2D_Element_move(PikaObj* self, int x, int y) {
args_setInt(self, "posX", x);
args_setInt(self, "posY", y);
elemInfo->x = elemInfo->x - x;
}
void Arm2D_Element_right(PikaObj* self, int x) {
args_setInt(self, "posX", obj_getInt(self, "posX") + x);
pika_arm2d_element_info_t* elemInfo = args_getStruct(self, "elemInfo");
elemInfo->x_last = elemInfo->x;
elemInfo->x = elemInfo->x + x;
}
void Arm2D_Element_move(PikaObj* self, int x, int y) {
pika_arm2d_element_info_t* elemInfo = args_getStruct(self, "elemInfo");
elemInfo->y_last = elemInfo->y;
elemInfo->x_last = elemInfo->x;
elemInfo->x = x;
elemInfo->y = y;
}

View File

@ -5,7 +5,7 @@ int32_t __foreach_ElementList_update(Arg* elem, Args* buffs) {
char* type = arg_getType(elem);
if (strIsStartWith(type, "_class")) {
PikaObj* elemObj = arg_getPtr(elem);
args_deinit(pikaVM_runAsm(elemObj, "0 RUN update\n"));
obj_deinit(pikaVM_runAsm(elemObj, "0 RUN update\n"));
}
return 0;
}

View File

@ -55,7 +55,7 @@ void pika_arm2d_init(void) {
LCD_WIDTH, //!< screen width
LCD_HEIGHT, //!< screen height
uint16_t, //!< colour date type
160, //!< PFB block width
160, //!< PFB block width
LCD_HEIGHT, //!< PFB block height
1, //!< number of PFB in the PFB pool
{
@ -82,9 +82,10 @@ void Arm2D_Window_init(PikaObj* self) {
pika_arm2d_window.pika_windows_object = self;
pika_arm2d_window.pika_elems_object = obj_getObj(self, "elems", 0);
pika_arm2d_window.pika_background_object = obj_getObj(self, "background", 0);
pika_arm2d_window.dirty_region_list = NULL;
}
void Arm2D_Window_update(PikaObj* self) {
while (arm_fsm_rt_cpl != arm_2d_helper_pfb_task(&s_tPFBHelper, NULL))
while (arm_fsm_rt_cpl != arm_2d_helper_pfb_task(&s_tPFBHelper, pika_arm2d_window.dirty_region_list))
;
}

View File

@ -13,9 +13,24 @@
#ifndef ARM2DQEMUBOOTER_APP_ARM2D_H_
#define APPLICATIONS_APP_ARM2D_H_
typedef struct pika_arm2d_window_t_ {
typedef struct __pika_arm2d_element_info_t {
int x, x_last;
int y, y_last;
int alpha, alpha_last;
} pika_arm2d_element_info_t;
typedef struct __pika_arm2d_box_info_t {
pika_arm2d_element_info_t elem_info;
arm_2d_region_t arg2d_regin;
int wight, wight_last;
int hight, hight_last;
uint16_t color_code, color_code_last;
} pika_arm2d_box_info_t;
typedef struct __pika_arm2d_window_t {
arm_2d_tile_t* pfb_tile_now;
bool pfb_is_new_frame;
arm_2d_region_list_item_t* dirty_region_list;
PikaObj* pika_windows_object;
PikaObj* pika_background_object;
PikaObj* pika_elems_object;