News:

Welcome to RetroCoders Community

Main Menu

A simple starfield

Started by CharlieJV, Aug 29, 2023, 05:00 PM

Previous topic - Next topic

johnno56

Can never go wrong with a starfield... Cool... Nice job!
May your journey be free of incident.  Live long and prosper.

CharlieJV

Quote from: johnno56 on Aug 30, 2023, 02:18 AMCan never go wrong with a starfield... Cool... Nice job!


I can't take credit for that.

Maybe at best good sleuthing finding the code, and then figuring out an issue with  BAM's PSET and then fixing it.

I love finding snippets of code like that and having it work in BAM with little-to-no fuss.

johnno56

An issue with PSET? Interested in knowing the problem...
May your journey be free of incident.  Live long and prosper.

CharlieJV

Quote from: johnno56 on Aug 30, 2023, 12:12 PMAn issue with PSET? Interested in knowing the problem...

It was a ridiculously easy fix.  Probably a little bit of a performance hit when doing a ton of PSET in a loop, but meh.

In wwwBASIC, anything that puts anything on the screen actually puts data into a single-dimension array.  Each element in the array holds the colour of a pixel on the screen.

When something triggers it, the display gets refreshed with all of the data in the array (i.e. every pixel on the display gets set to the value of the related cell in the array.)

The array being one-dimensional, then the pixel at y=2 and x = 0 is in array(x + screen_width * (y-1) ).  Something like that.  (Just on a quick coffee break.)

Well, PSET was not checking to see if the coordinates were within the boundaries of the current SCREEN.  So when calculating the position of the coordinate in the array, an out-of-bounds coordinate (say by one pixel beyond the width of the screen), that would put the pixel colour in the next cell in the array.  The result: the dot that was going past the right side of the screen would come out of the left side of the screen, but one pixel lower.

Whooey, that is a brutal explanation.

The fix: ignore a PSET that is out of bounds for the width and height of a screen.

ZXDunny

All display memory is one-dimensional :)

CharlieJV

Quote from: ZXDunny on Aug 30, 2023, 01:35 PMAll display memory is one-dimensional :)

I think it would have been much easier on my sponge if a two-dimensional array had been used to match the screen dimensions.  Less math to think about.

But it is as it is, and I suffer it with the firm belief that it was implemented that way for a good reason.  Well, that gives me warm fuzzies, so I just roll with it.

ZXDunny

It's the same way I made displays in SpecBAS. At the end of the day, any two-dimensional implementation is going to have to multiply out the Y coordinate anyway so you may as well stay at the same implementation as the underlying hardware.

It makes drawing stuff super easy - grab a pointer to the first pixel of the display, and move +1/-1 for right/left, +width/-width for up and down and you're moving a lot quicker than having to convert from 2D to 1D every time you need to draw a pixel :)