Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Problems with memblocks and pointers

Author
Message
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 9th Sep 2005 16:59
I´m having another bash at converting one of BatVink´s tutorials to DGSDK. I´m stuck at the only part that doesn´t involve just adding a db to the function names.
In BatVink´s memeblock tutorial he uses the function copy memory to write a screen line´s worth of data to the backbuffer (actually I don´t know what it is. I´m just taking it as the screen). Copy memory doesn´t exist in the DGSDK so I guessed that I could just use pointers in some way to copy what the memblock has to the screen.
Is that possible or is there a command in the c libary that does the same as copy memory? I found one that was simular but it only accept void pointers and I don´t know what they are.
P.S I realise that I´ve been asking for alot of help recently so I promise that this is the last time I ask for help this month. Honest.

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 9th Sep 2005 17:03
You've got CopyMemory, memcpy, strcpy...

I suspect the DBPro CopyMemory would cast a DWORD to an LPSTR pointer.

Come to the third DarkBasic Pro Sci Fi Con - Be there and be square
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 9th Sep 2005 17:30 Edited at: 9th Sep 2005 17:31
Thank you.
It works! Kind of. At least now it compiles. I casted the dbGetPixelsPointer() and (LPSTR*)dbGetMemblockPtr(CurrentMemblock) to a LPSTR pointer:

and it now compiles but with two warnings saying conversion of DWORD to LPSTR* of greater size. Should I ignore those warnings or are they important? I´m a bitworried that the screen is showing up black still though. If it isn´t changing the screen then what is it changing?

That´s the function is anyone wants it.

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 9th Sep 2005 17:38 Edited at: 9th Sep 2005 17:39
Quote: "Should I ignore those warnings or are they important?"

Thats a 64-bit conversion warning - It can be safely ignored for now.

I would simplfy the function though - whilst not efficient it may help, thus :

pp=(LPSTR) dbGetPixelsPointer();
pp+=ScreenLineStart;

pp2=(LPSTR) dbGetMemblockPtr(CurrentMemblock);
pp2+=LineStart+12;

CopyMemory(pp,pp2,ScreenBytes);

Come to the third DarkBasic Pro Sci Fi Con - Be there and be square
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 9th Sep 2005 18:27
I´ve added your addition and fixed a silly bug I had and now it works. There is the tiny problem of it running at 57fps instead of the 100s that paste image would give

That concludes the test as a complete failier. Oh well. Thanks for your help. I think I´ll have a play around to make it faster but I doubt I can make it 10 times faster!

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Sep 2005 19:03
I can't believe the performance is so poor in DGSDK

I don't do C, but I would expect it to be better by default.

The next tutorial really screws around with memblocks and the screen, and works at 500 FPS+ on my PC! I would persevere and get this running well, because the next tut will blow your socks off if you liked this one.

MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 9th Sep 2005 19:13 Edited at: 9th Sep 2005 19:19
Quote: " I can't believe the performance is so poor in DGSDK

I don't do C, but I would expect it to be better by default."

I was thinking that and I came up with 2 possible reasons.
1. I´ve done something somewhere which makes it slower.
2. The fps counter in your tutorial is much higher because you sync after every line and I sync after every screen.
Quote: "The next tutorial really screws around with memblocks and the screen, and works at 500 FPS+ on my PC! I would persevere and get this running well, because the next tut will blow your socks off if you liked this one.
"

ooooh. Sounds interesting. I will. Mucking around with memblocks is fun anyway. I might be able to program pixel perfect colision using them soon.

Edit: Just read your other thread. I´m now attempting putting less in the forloop but it just keeps comming up with fatal errors caused by the pointers going places they shouldn´t.

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 9th Sep 2005 20:46
Dont keep locking and then unlocking the screen - that will save some time...

Come to the third DarkBasic Pro Sci Fi Con - Be there and be square
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 9th Sep 2005 21:00
Quote: " Dont keep locking and then unlocking the screen - that will save some time..."

Thanks. That has sped it up alot. It´s going twice as fast now and I´m running winrar. Not that it seems to affect print image which now runs at 730fps. Maybe it runs slow becasue it´s forcing the pc to use the CPU instead of the GPU or some such technical thing? Here´s the current code by the way:


My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Sep 2005 22:26
aah! I started replying earlier today regarding LOCKing and UNLOCKing pixels. Then I noticed you had done it, but I didn't spot that you had it inside the loop. Doh!

LOCKing pixels happens automatically every time you paste an image, or similar action. So in effect the code would LOCK and UNLOCK PIXELs every single loop anyway. By doing it ourselves outside the loop, it tells DB not to bother and thus saves a hell of a lot of processing.

You must always LOCK PIXELs when writing to the backbuffer. If you took these lines out, the chances are it would go seriously wacky. This is because Windows, and potentially your own program, would be interfering with the screen constantly.

Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 10th Sep 2005 01:03
Quote: "Maybe it runs slow becasue it´s forcing the pc to use the CPU instead of the GPU or some such technical thing?"


Most certainly.

Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice!Play Basic (Release V1.088 Out Now)- Play Extreme with Play Basic FX {TBA}
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 10th Sep 2005 11:00 Edited at: 10th Sep 2005 11:00
Quote: "730fps"

Wouldn't call that slow

Other optimisations include doing two lines per Y loop, getting the pointers once (its very doubtful they would have changed per loop) and using assembler...

Come to the third DarkBasic Pro Sci Fi Con - Be there and be square
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 10th Sep 2005 11:27
Quote: " Most certainly."

Ah. So it´s better to leave things to paste image. It seems to know what it´s doing.
Quote: "Wouldn't call that slow"

No. I was just seeing if using a memblock was any faster. Just incase.
Quote: "Other optimisations include doing two lines per Y loop, getting the pointers once (its very doubtful they would have changed per loop) and using assembler..."

I haven´t tried doing two lines yet though I´ve attempted reomiving the pointers from the forloop. It worked fine apart from the first line. It wasn´t pasting properly as there was no Y-1 if Y=0 being the first line. I don´t really want to try assembler just yet. A few more years of programming and I may attempt it.

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!
matt rochon
21
Years of Service
User Offline
Joined: 15th Mar 2003
Location: Canada
Posted: 25th Sep 2005 17:44
hey guys, on this topic, right now I'm blitting images to the screen using the backbuffer, should I be getting the "pixel pointer" or the backbuffer pointer? or does it work out to the same thing?

Pretty much just asking for a comparison on the getpixelpointer() and getbackbufferptr() functions.
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Sep 2005 23:05
Never heard of getpixelpointer()

Come to the third DarkBasic Pro Sci Fi Con - Be there and be square
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 26th Sep 2005 01:08
A suggestion to simplify and maybe increase performance:



Another variation doing a single memory copy might be:


Cheers,
Ancient Lady
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 30th Sep 2005 20:27
Sorry about the delayed reply. School has started and I´ve been trying to addapt to getting up at 6:45. This will/has seriously affect/ed my coding time.
Quote: " A suggestion to simplify and maybe increase performance:"

Thankyou for your help. I tried to do that but my attempt missed out the first line, yours doesn´t have that fault. Thanks. I´ve tested it and it came out at the same speed as the other code though that doesn´t matter as it makes it simpler and simple´s good.
Quote: " pp += PixelPitch; // (where is PixelPitch defined?)"

That´s i at the begining of the code as it only needs to be called once. I should have provided that that bit aswell realy.

Quote: "Another variation doing a single memory copy might be:"

Unfortunatly I don´t think it´s possible to write the whole thing at once. As BatVink mentioned in his tutorial some graphics cards add extra info to the end of each line meaning that one line isn´t width*depth apart from the next but width*depth+plus the extra info. Pixelpitch gets the full size of a line. (That´s how I´ve understood it, correct me if I´m wrong)

My signature has been erased by me because it's LARGE.
Thank you for the votez!1!

Login to post a reply

Server time is: 2024-04-24 00:38:42
Your offset time is: 2024-04-24 00:38:42