PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Performance issues

Hi,

I'm currently working at porting my software from the eval version of GapiDraw to the eval version of Edgelib and I am not getting good results. Startup time has gone from "instantaneous" to ~5 seconds or so and in game performance is sluggish at best.

My background:
-Programmed in managed and scripting languages for a number of years now
-C++ learned after the fact for the past year on and off.
-I state this because I might have some c++ stuff wrong but I'm not a complete newbie ;)

My setup:
-I am basing this port on the helloworld example. (I have not changed any configuration options)
-I'm using vs2005 on vista deploying to an Axim 51v.

Extra Diffs between ports:
-I got rid of using CAtlString and replaced with std::wstring covered in a typedef.
-The Gapidraw version runs in a Windowed mode. Not sure exactly what technical context it is, but it has menus and handles window messages.

My Code:

Each surface (about 10 of them) are created at startup but only 5 are displayed. These are the steps that each goes through. (not exact code)
Code:

//Instantiate:
SurfacePtr sur(new NamSurface()); //typedef'd E2DSurface with boost shared_ptr
//Create:
UI::DIS->CreateSurface(this->surface.get(), this->width, this->height); //ClassEDisplay object referenced in static object
//Resize:
this->surface->Resize(width, height); //resize as part of greater sizing operation.
//paint:
surface->FillRect(NULL, this->backGroundClr, 0, NULL);
//some controls are slightly different but nothing extreme or taxing going on. It's REALLY basic! ;)

To help complete the context I will tell you that each surface is wrapped in a custom "UIControl" object. That object was developed based on my Gapidraw needs and the code shown below is the current state of it as I port to Edgelib. The basic api differences between Gapidraw and Edgelib seem pretty minimal so I'm pretty sure that there MUST be something wrong with my setup. Hopefully it is obvious to someone.

Thanks and please excuse the seemingly amateur nature of my incomplete code. :) (although any general pointers ARE appreciated)

Code:

UIControl::UIControl(UIControl * parent): children(0) {
this->parent = parent;
this->refresh = true;
this->responsive = true;
this->autofresh = false;
this->visible = true;
this->deepFresh = false;
this->backGroundClr = RGB(255,255,255);
this->width = 10;
this->height = 10;

SurfacePtr sur(new NamSurface());
this->surface = sur;
long x = UI::DIS->CreateSurface(this->surface.get(), this->width, this->height);
if (x != E_OK) {
switch (x) {
case E_INVALIDPARAM:
hitlog(_T("invalid param"));
break;
case E_UNSUPPORTED:
hitlog(_T("unsupported"));
break;
case E_NOMEMORY:
hitlog(_T("no mem"));
break;
case E_ERROR:
hitlog(_T("other error"));
break;
}
hitlog(_T("ERROR CREATING SURFACE: ")+stringify(x));
}
if (this->parent != 0) {
this->setSize(this->parent->width, this->parent->height);
}
else {
this->setSize(UI::GetWidth(),UI::GetHeight());
}
this->setLocation(0,0);
}
LPRECT UIControl::getRect() {
this->setLocation(this->x, this->y);
return &m_rect;
}
void UIControl::setLocation(int x, int y) {
this->x = x;
this->y = y;

int xo = 0, yo = 0;
UIControl * parenter = this;
while (parenter != NULL) {
xo += parenter->x;
yo += parenter->y;
parenter = parenter->parent;
}
::SetRect(&this->m_rect, xo, yo, xo+width, yo+height);
this->moved = true;
}
void UIControl::setSize(int width, int height) {
this->width = width;
this->height = height;
this->surface->Resize(width, height);
int l = m_rect.left;
int t = m_rect.top;
::SetRect(&this->m_rect,l, t, l + width, t+height);
this->refresh = true;
}
UIControlPtr UIControl::checkPoint(UIControlPtr thiz, POINT p) {
UIControlPtr control;
if (::PtInRect(&this->m_rect, p)) {
for (unsigned int i = 0; i < this->children.size(); i++) {
if (this->children[i]->responsive) {
control = this->children[i]->checkPoint(this->children[i],p);
}
if (control.get() != NULL) {
break;
}
}

if (control.get() == NULL) {
control = thiz;
}
}
return control;
}

void UIControl::Render(NamSurface* pBackBuffer) {
if (refresh) {
if (this->visible) {
this->Paint();
}
}
//then check children and paint them on top
for (int i = 0; i < this->children.size();i++) {
if (this->deepFresh) this->children[i]->refresh=true;
this->children[i]->Render(pBackBuffer);
}
NamSurface * back = this->parent != NULL ? this->parent->surface.get() : pBackBuffer;
back->BltFast(this->x, this->y, this->surface.get(), NULL,NULL,NULL);

if (!autofresh) this->refresh = false;
if (this->deepFresh) this->deepFresh = false;
if (this->moved) this->moved = false;
}
void UIControl::DrawString(NamString s, int x, int y, int size, int alignment,COLORREF fontColor) {
this->surface->DrawFont(x, y, &UI::DIS->fontinternal, (char *)Utf::ToUtf8(s).c_str(), 0, 0);
}
void UIControl::Paint() {
surface->FillRect(NULL, this->backGroundClr, 0, NULL);

}
void UIControl::AddChild(UIControlPtr child) {
UIControlPtr a(child);
this->children.push_back(a);
child->parent = this;
}


I'm not sure that I solved anything, but after some testing modifications my perspective has changed a bit.

I transitioned my Gapidraw code to be closer to the Edgelib version (apart from the diff in gfx libraries the code should be exactly the same now) and found the the GapiDraw version is experience a performance drop as well. (both versions run fullscreen whereas my original gapidraw code runs in windowed mode based off the GDIDemo sample)

However the startup tests still are very clear that something is not right with my edgelib code. The fullscreen GapiDraw version still starts up instantaneously whereas the Edgelib version (after some proper timing checks) actually takes about 17-20 seconds to start. Unfortunately that is very much too slow for reasonable development.

Thanks.
Hi,

A startup delay of more than 3 seconds is not normal, all of our EDGELIB programs open the window immediately. Perhaps you're loading a large number of resources in the OnFrameworkConfig, OnDisplayConfig, OnInit or OnDisplayInit methods? Are you testing on Windows Desktop only, or also on mobile devices?

Could you please test the helloworld sample to see if there is a delay? Maybe you can send us your application, so we can test if the long delay happens here as well.
Hi,

Now that I've found the problem this probably doesn't matter, but to answer your questions I am creating my surfaces in the OnDisplayInit method and I am testing on a Dell Axim 51v.

To have a better look I wrapped the edgelib api calls with timing counts using ClassERTimer::Count() (very handy btw! :) ) and did some rough timing measurements.

(in milliseconds)
new surface: 0 (new E2DSurface())
create surface: 0 (display->CreateSurface(...))
resize surface: 1466 (surface->Resize(w,h))

So it's pretty obvious where the problem is!! surface->Resize(..) doesn't seem to be documented but as I scrolled through my IntelliSense window seemed like the obvious choice for resizing a surface. And it does it's job but seemingly performance isn't it's key feature. What is the context in which this method should be used? Is it deprecated?

Anyway I switched out the Resize call with display->CreateSurface and the time of 1466ms dropped down to 5ms. :) As a result I am finding the startup time to be just fine and am excited to proceed with my evaluation of edgelib. :)

Something to note is that the call-times to CreateSurface seem to increase for each of the first 3 calls, ~(0-5-20), but then drop back down to ~0 for any further calls. I messed around with the width and height parameters but they didn't seem to have an effect. I don't have anything concrete around this, but found it interesting so I thought I would pass it on. Whatever it is, it's not causing me any problems :)

Thanks
Hi,

Surface resizing could be used to handle different resolutions. For example, you could supply one graphics pack with the title screen, backdrop images and resize them to fit for each resolution. Performance isn't the most important part of this feature, it will resize with image resampling to make it look good when scaled down (it is quite similar to resizing an image with photoshop). We recommend using a loading progress bar when loading (and resizing) resources.

The different timings for CreateSurface may be caused by the fact that the operating system can use processing power while the application runs. This is usually true when just starting the application.

When you want to resize real-time (for example, for rotating/scaling sprites) we recommend using Blt(). This will not resample your images and has a high performance.
PS: We forgot to add the Resize function to the reference documentation. Good thing you pointed this out to us.

Find the entry for E2DSurface here:
http://www.edgelib.com/index.php?node=e2dsurface_resize
Hi,

Thanks for the info and I'm glad to see the documentation up for Resize. It might be helpful to mention in the description what options would be better suited if the developer is looking for "real-time" resizing. (at least for newbie's like myself)

Just as some feedback, I think it would be helpful if your function listings were sorting alphabetically. Due to the current format I needed to scan the list of functions for E2DSurface numerous times before I could confirm to myself that it was indeed not there. ;)

I'd also like to mention in reference to the thread topic that everything is now running very well.

Thanks for the help. :)
namGman wrote:Hi,
Just as some feedback, I think it would be helpful if your function listings were sorting alphabetically. Due to the current format I needed to scan the list of functions for E2DSurface numerous times before I could confirm to myself that it was indeed not there. ;)


We have alphabetized the function listings, thanks for the suggestions. Suppose this is something we should have done some time ago already. :wink:


namGman wrote:
I'd also like to mention in reference to the thread topic that everything is now running very well.

Thanks for the help. :)


I'm glad your app runs well now. Any chance you can show us something of your work in progress? We love to see EDGELIB-powered games and applications in the works!

If you have any other questions or suggestions, please feel free to open a new topic.
I'd planning to have an alpha/beta testing version up on the net in ~1 month. The application isn't focused on graphics and this is my first foray into the scene so I don't plan to have the application looking amazing for the initial release. I do however appreciate a good interface and very much hope to eventually produce a very slick and intuitive experience for my users.

Anyway, I'll definitely let you know when it's up and going. :)