PocketMatrix forums

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

Negative Numbers in array

For some reason, I can't use a negative sign in front to an indexed array...

Code:

t$ = -dx$[i$];


won't work. Says: Syntax Error at '['.

I tried wrapping a set of ()'s around it and it still won't compile.
Ok, fixed. Thanks for pointing it out!

Code:
dim(dx$, 10);
dx$[2] = -3;
t$ = -dx$[2];
ShowMessage(t$); // Display 3.


This code works here with the newest build.
I'm also having trouble with the g_lock still. Trying the simplest code... lock, then poke into the pixels location causes a crash.

Can you give it a try?
Yes, I will try it out tomorrow.

Can you give a sample of your code?
Here's the simplest of all - it causes an access violation at the poke statement

Code:

struct(lockinf$, LockInfo );
lockinf$ = G_Lock();

poke(lockinf.pixels$, 0, 1);

G_Unlock();


I know that this if only setting 'half' a pixel, but it should work...

I don't know what's under the code, but it would make a world of difference if you could treat the pixels$ pointer as an array like in C. i.e.
Code:

lockinf.pixels$[5 + 3*lockinf.pitch$] = G_RGB(255,0,0);


would be the same as
Code:
SetPixel(5,3, G_RGB(255,0,0));


Of course, if there's much overhead in the peek and poke operations, it may be just as slow as SetPixel and GetPixel - especially if you're using the PHAL based PFrog.
Btw, never use 1 for the size, use TBYTE or TSHORT. There is a difference.
Hmmm, using TBYTE or TSHORT gives a 'stack too small' error instead of an access violation.

Better or worse? Who knows...
I will make sure it works first thing tomorrow. I will get back to you.
Ok, I fixed the poke, there was a function definition problem. :cry:

And the g_lock, I think I need to add a parameter for discard. How will this be done in PF normally?
Discarding the lockinfo struct? It's just a pointer and an int...

Older versions of Pfrog would create a temporary linear buffer, but the unlock takes care of that... So, I don't think you should have anything to discard.
Do we need to a GetBackBuffer() first in PF and then an update? This could be it. I'll give a shot tomorrow first thing.
Yes... it looks like that's correct.

display->GetBackBuffer()->Lock()
Here is a little test I did:

Code:
// Default Game API skeleton

#include "GameAPI.ppl"

func mainproc(hWnd$, Msg$, wParam$, lParam$)
ok$ = true;

case (Msg$)
WM_CLOSE:
// Shutdown the GameAPI.
ShutGameAPI(hWnd$);

WM_MOUSEMOVE:
g_beginscene;
g_setpixel(LOWORD(lParam$), HIWORD(lParam$), g_RGB(255, 255, 255));
g_update;
end;

return (ok$);
end;

func WinMain
// Create a new form that will hold the GAPI.
h$ = newform({GAPI}, {GAPIClass}, &mainproc;);
ShowWindow(h$, SW_SHOW);

// Initialize GameAPI.
InitGameAPI(h$, NULL, 5);

G_AutoDraw(False);

ProcessMessages;
G_BeginScene;
G_Clear(0);
g_Update;

return (true);
end;


You might want to use the g_AutoDraw() which will not display any FPS and call WM_PAINT.

I also fixed the poke, like I told you.

I will have an update today.
I got the newest version, and now I crash by just calling Lock().

Code:

struct(lockinf$, LockInfo );
lockinf$ = G_Lock();

G_Unlock();


I don't get any message from PPL, just a basic windows "PPL.exe has encountered a problem and needs to close."

That code is inside the WM_PAINT of the GameProc function. Needless to say, I have no idea if you fixed the Poke statement since I can't get that far.
Sorry I made a small change (shouldn't have) to the pointer assignment procedure and it doesn't work anymore. I am fixing it right now.

Edit: I got it, simply do this: (add the & in front of the variable).

Code:

struct(lockinf$, LockInfo);
&lockinf;$ = G_Lock();
G_Unlock();


This will tell PPL to assign a new address to the variable instead of assigning the content of the LockInfo.
Ok, so now it doesn't crash... but I still can't get anything to the screen with a poke.

I also tried looking at the values of the pitch and pixels variable. They don't look right... i.e. pitch should be something like 240*2, but it is 1235348...
Damn! :evil: I got to make this thing work. Okay I will investigate this further. I will make sure I get something working before releasing the new version tomorrow. Do you have an MSN account? This way if I have a question or two, it can be resolve faster. PM me or use kornalius @ hotmail.com on MSN.