Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

calling display update..


Postby BIGBEN » Mar 29, 2006 @ 8:08pm

Interesting... thanks for sharing!

fast_rx wrote:you don't have juggle a global pointer to display


I really do not see why global variables are bad for games?

Why people need to pass pDisplay to functions initializing 4byte pointer in any drawing function each time it is called (which will cost in time and size).

I really do not see a reason why :(

Please help me to understand the benefits of passing pointer to the Display each time.
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby jaguard » Mar 29, 2006 @ 10:46pm

the main this is that it does a little at a time, so the display gets updated frequently and you don't have juggle a global pointer to display or use a bunch of getDisplay's stacked up in one function.


I wonder, how many of such switchcases I will need to do, considering that in my game(which is, btw being released today or tomorrow, depending on your time zone :)) there are a ~1700 gfx files to be loaded(though they are in a pak file, it woundn't matter).
jaguard
pm Member
 
Posts: 230
Joined: Mar 2, 2004 @ 6:45pm


Postby fast_rx » Mar 29, 2006 @ 10:48pm

The main benefit for me is knowing I'm not going to start using a display pointer that's already been ->Update()'d or never started with GetDisplay(), or a double ->Update() which seems to cause a crash.

I've spent a lot of time tracking down problems like that - so I've changed the way I do things. It's more of a problem I've created myself by poor programming.

The other reason for me is code reuse... If I pass the display pointer into the functions, I don't care what I named it or what the scope is.

For instance, I have a class that contains all information about enemy tanks. So I call enemies.Draw(display)
If I don't pass the display, how is this class going to get the display pointer? The global is in another .cpp file, so you'd at least have to declare it extern, right?

I'm not trying to tell anyone the way to code, just the way I'm doing it to keep me from shooting myself in the foot.
User avatar
fast_rx
pm Member
 
Posts: 660
Joined: Jun 10, 2003 @ 4:24pm


Postby BIGBEN » Mar 30, 2006 @ 9:18am

fast_rx wrote:If I pass the display pointer into the functions, I don't care what I named it or what the scope is.

If I don't pass the display, how is this class going to get the display pointer? The global is in another .cpp file, so you'd at least have to declare it extern, right?

I'm not trying to tell anyone the way to code, just the way I'm doing it to keep me from shooting myself in the foot.


Funny, but for the same reasons (not to care about the name & scope) I do use it as global pointer, all I need is (as you said):

extern pDisplay;
in Globals.h

Not trying to shoot in your feet ;)

Thanks for telling your experience.

jaguard wrote:I wonder, how many of such switchcases I will need to do, considering that in my game(which is, btw being released today or tomorrow, depending on your time zone :)) there are a ~1700 gfx files to be loaded


You don't need switches at all, if you just load files by passing name as a string that is loaded by string number (from external txt or by resource string).
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby Presto » Mar 30, 2006 @ 3:30pm

In my main Game class I have the following:
Code: Select all





void CMyGame::DrawScreen()
{
  pDisplay->Update();
  pDisplay = GetDisplay();
}
5 lines; 1 keywds; 0 nums; 15 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
In the rare case where I need to call Update() outside of the main game loop, I use pMyGame->DrawScreen(); which updates the screen and then gets a new pointer to it. Both pDisplay and pMyGame are global variables.

-John
User avatar
Presto
pm Insider
 
Posts: 763
Joined: Jan 20, 2003 @ 5:51am
Location: Kalesian Archipelago


Postby jaguard » Apr 1, 2006 @ 5:42pm

Presto wrote:In my main Game class I have the following:
Code: Select all





void CMyGame::DrawScreen()
{
  pDisplay->Update();
  pDisplay = GetDisplay();
}
5 lines; 1 keywds; 0 nums; 15 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


That's what I did in a first place. And this is where ipaq hx 2xxx(WM5) hangs. I didn't entirely understand what happened there, but I now have special functions like this:

Code: Select all









10 
11 
12 
13 
14 
15 
16 
17 
18 
// To make sure that display is always updated before draw is occured.
void displayGetDisplay()
{
    if (g_displayState == 1)
    {
        GamePointer->UpdateDisplayPointer();
        g_displayState = 0;
    }
}

void displayUpdate()
{
    if (g_displayState == 0)
    {
        display->Update();
        g_displayState = 1;
    }
}
18 lines; 4 keywds; 4 nums; 34 ops; 0 strs; 1 coms    Syntactic Coloring v0.4 - Dan East  


UpdateDisplayPointer is a realisation of display = GetDisplay();

So I make sure that every time I call draw or update I have correct display pointer.
Looks like it works.
jaguard
pm Member
 
Posts: 230
Joined: Mar 2, 2004 @ 6:45pm


Previous

Return to PocketFrog & PocketHAL


Sort


Forum Description

SDKs for fast and robust device-independent access to Pocket PC display hardware.

Moderators:

sponge, Kzinti

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron