Pocket Burning Sand (Open Source)

neilnapier

Active Member
Licensed User
Longtime User
Is it possible to change the square shaped pen to a circlular one?

Also yes I see the cyellow thing and deleted that comment about five minutes ago when I saw it.
 

colin9876

Active Member
Licensed User
colours!

Great addition with the colours, will integrate that library into the BS code now so it can use the colour functionality

RE librarys/dlls. SO Express c# can do libraries, but ppc apps cant use libraries?
What do u use to create these dlls, is it many steps on top of writing the code to get it as a dll?
 

agraham

Expert
Licensed User
Longtime User
RE librarys/dlls. SO Express c# can do libraries, but ppc apps cant use libraries??
Let me try to explain.

Devices run the Compact Framework (CF) which is a (mostly) compatible subset of the full .NET Framework. Desktops run the full .NET Framework (NF).

Code compiled for the CF can run on the NF. Code compiled for the NF will NOT run on the CF. This is how you can usually use the same library in B4PPC on the device and the desktop, they are compiled for the device. There are some B4PPC libraries that have different versions for the desktop and device due to differences between the two environments. Some B4PPC libraries are available only for the desktop (e.g my FormExDesktop) because the device does not include that functionality.

The Express versions can only compile for the NF even if the code itself is perfectly capable of running on the CF. This is a marketing decison by Microsoft not a fundamental limitation of the Express versions.

Dlls are actually p**s easy to do. You just tell Visual Studio or SharpDevelop what you want, dll, Windows exe or console app and it makes it. Your code has to suit that use of course.
 

colin9876

Active Member
Licensed User
ok, well Im just reorganising the BSinterface because it needs to be done more logically to go fast. It was drawing pens on the foreground all the time, e.g. in black when a colour wasnt selected

I can implement everything Neil wants from Basic if I have two more things passed to the the library,

Firstly a ELEMENTS() array defining the color, spread
attributes of particles 0 to MAXELMENTS

A rules table rules(MAXELEMENTS,MAXELEMENTS)
which has arguments saying what happens when two colored particles meet
ChangetoElement, dx, dy is all it will need

Ill map out the C# lines in anticipation of Neil working out how to do dlls
Ive got a french exam tomorrow so must go and revise now but will catch up with this later. A Bientot!

Update- what does that FromArgb( col) change do?
Does C# store colours as doubles? Does .Net have a RGB function?
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Firstly a ELEMENTS() array defining the color, spread attributes of particles 0 to MAXELMENTS
Already got colour, need an additional array for spread - easy.

A rules table rules(MAXELEMENTS,MAXELEMENTS)
which has arguments saying what happens when two colored particles meet
ChangetoElement, dx, dy is all it will need
I don't think you realise the implications of this. At present each particle is treated individually. The only way they can "meet" at the moment is when they ovelap due to spreading. There is no provision for static "objects" for particles and the library fiddles with the array and moves particles around to keep the array compacted. I could go on ... but I'll be interested to see your C# "psuedo code" in case you've got some ideas that I haven't thought of.
 

colin9876

Active Member
Licensed User
Yep have a brill way of making it all work simply

the elements array maps the RGB colours to a simple int 0 to MAX

u know what color u are(say 5), then u look at the colour pixel ur going to on the screen(say 6) and look up rule(5,6) say
then add dx to px, dy to py, and change element type if a different element is specified.

Ive got it running in basic, it can react to all fixed objects and all other moving pixels without slowing it down
I actually could get rid of the spread parameter by combining it in a rule - but Neil wanted it

all the boundry checking can be done by adding a rule in the array too to say e.g. yellow pixels change to black space if they hit a white border

codes not long - just not sure about arrays in C#- whats the best way to pass a 2 dimentional array that has 3 arguments
rule(m,m)=int,int,int etc
 
Last edited:

agraham

Expert
Licensed User
Longtime User
just not sure about arrays in C#- whats the best way to pass a 2 dimentional array that has 3 arguments
rule(m,m)=int,int,int etc
Sorry Colin but I don't get this. Arrays don't HAVE arguments. What do you really mean?

Also multiple arbitrary rules per colour may have a bigger performance hit than you assume. If you have some code that works then post it and I will have a look at coding it.
 

colin9876

Active Member
Licensed User
Yes sorry arguments wasnt the right word ... how do u say for each rule(1,2) it looks up a few things (sort of like DIM rule(64,64) Type colchange,dy) ... maybe structure is the right word

u only look up one rule, doesnt matter how many there are in the list- only look up the one relevant to the color u are, and the color of the pixel ur going to.
Heres a rough guide - Ill give u the exact code next week when Ive got it exactly right

bithandler(px(),py(),pcolor(),pspread(),n,rules(,))
for i=0 to n
plot(px(i),py(i),cBlack)
newpx=px(i) + our random spreadline
newpy=py(i)+1

tocolor=getpixelcolor(newpx,newpy)

if tocolor<>cblack
thisrule=rule(condense(pcolor(i)) , condense(tocolor))
newpy=py(i) + thisrule.dy
pcolor(i)= thisrule.colchange

if getpixel(newpx,newpy)<>cBlack then
newpx=px(i)
newpy=py(i)
end

end

px(i)=newpx
py(i)=newpy
plot(px(i),py(i),pcolor(i))
Next

N.B the condense function just reduces the distinction of the colors so it doesnt need a 64000x64000 rule table. Then I dont need the element look up table either

Condense(R,G,B)=((R Mod64)+1)x((G Mod64)+1)x((R Mod64)+1)
e.g condense(200,100,0)=4*3*1=12
so 4*4*4 distinct colors, rule table is rules(64x64)
 
Last edited:

neilnapier

Active Member
Licensed User
Longtime User
That coding goes right through me. I looked through almost every help thing in the help database and I don't think I understood any of that.

I knew that the way that I had created the program was very glitchy and am glad you are willing to sort it.

I find it quite amusing that some members of this forum said that this program couldn't be done.

Youz certainly should them!
 

colin9876

Active Member
Licensed User
Mini request for Agraham..

Just as an interim measure can we have this line in the current bithandler library, it will help me merge what we have to Neils BS interface to give a half playable result!

for i=0 to n
plot(px(i),py(i),cBlack)

nexpx=px(i)+(2*rnd-1)*spread
newpy=py(i)+1

if form1.getpixel(newpx,newpy)<>black then
newpy=py(i)
if form1.getpixel(newpx,py(i))<>black then
newpx=px(i)
end
end


px(i)=newpx(i)
py(i)=newpy(i)

plot(px(i),py(i),pcolor(i))

Next

Basically calc new position, if u hit something dont go down just do the horizontal movement. If ur still going to hit something dont move position at all

This means the sand, water etc wont plough through the background but wiggle its way round it if it can!
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I find it quite amusing that some members of this forum said that this program couldn't be done.
I did NOT say it couldn't be done. I said
So I am afraid that the bottom line is that to get a viable BS to run under B4PPC you would have to write it in a library
which is exactly what is now happening! - with my help I may add.
 

agraham

Expert
Licensed User
Longtime User
maybe structure is the right word
Exactly right. A two-dimensional array of structures is required, which compiles down to arrays of array (i.e a three-dimensional array). B4PPC can manage this but I will have to ask Erel if it can successfully pass it to a library as I can think of a possible typing problem here.

EDIT:- If arrays of structures can't be used then a plain three-dimensional array of ints or doubles could be used.
 
Last edited:

colin9876

Active Member
Licensed User
BSv2.0

If u can do the half way house modification of adding those few lines that say

if something where Im goingto then only move horizontally
..if something still where Im goingto then dont move at all

bithandler(px(),py()...

nexpx=px(i)+(2*rnd-1)*spread
newpy=py(i)+1

if form1.getpixel(newpx,newpy)<>black then
newpy=py(i)
if form1.getpixel(newpx,py(i))<>black then
newpx=px(i)
end if
end if

px(i)=newpx(i)
py(i)=newpy(i)

plot(px(i),py(i),pcolor(i))



Here is a cutdown version of BS (no other libraries required) u can test it with; v2.01 allows u to choose sanding colors, or static wall colours

It runs nicely with ur library - needs one addition tho to transfer the pixel color accross when off the screen pixels get removed out of the array {px(i)=px(n),py(i)=py(n),pc(i)=pc(n) }

N.B. Neil, dont worry that ur graphics are temporarily missing, Ive taken them out so its easier to work on this demo without needing to pass the imagefiles etc
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Try this - it has changed significantly so you will have to look at the code and see what changes you in turn need to make. The main one is that you tell it what area to restrict drawing to. You can pass the background colour and you need to put error checking in the B4PPC code when you create a particle to make sure it is in the drawing area.
 

colin9876

Active Member
Licensed User
Very Nice

Brilliant! Can u post the updated C code, the one in the zip didnt seem to have all the code? n.b need to make the spread value for sand >1.5 to make it come off slopes properly

Also take a look at something;-
in the loop i<n does that mean the final value will be n or n-1?

the reason I ask is in the destroy pixel bit shouldnt it be

spread(i)=spread(n-1)
it currently says=spread(n)

as px(i) etc are passed over as the n-1 argument?
 

Attachments

  • BSv2.02.sbp
    2.3 KB · Views: 265
Last edited:

agraham

Expert
Licensed User
Longtime User
Update- what does that FromArgb( col) change do? Does C# store colours as doubles? Does .Net have a RGB function?
It's best not to update existing posts - notifications don't seem to get sent so no-one may see it. I only just saw this re-reading your bit about rules.

You have to remember that .NET is object based. Even ints and doubles can be treated as objects although subject to some optimisations. Therefore .NET stores colours as Color objects. C# and VB.NET are strongly typed but will do some explicit conversions that do not cause potential problems. They will promote an Int32 to a Double automatically but not the other way round. You can force some conversions by explicitly telling the compiler that it is OK by "casting" it as in (Int32)SomeDouble. Other conversion have to be done by built-in functions.

So finally what FromArgb(col) does is make a Color object from the Int32 ARGB value in col. A stands for Alpha which is a fourth colour parameter specifying transparency.

And yes, there is a .NET RGB function. It is a static method of the Information class. e.g. intRGB = Information.RGB(intRed, intGreen, inBlue). As a colour value is 4 bytes packed into a 32 bit integer it just does some shifting and adding to make the colour value.
 

agraham

Expert
Licensed User
Longtime User
Brilliant! Can u post the updated C code, the one in the zip didnt seem to have all the code?
Its C# not C and it's the right code, I just downloaded and checked.

in the loop i<n does that mean the final value will be n or n-1? the reason I ask is in the destroy pixel bit shouldnt it be

spread(i)=spread(n-1)
it currently says=spread(n)

as px(i) etc are passed over as the n-1 argument?
You are right, that is wrong. The exit value of the loop iterator i will be n on exit but the highest value the inside of the for loop sees is n-1. Amended stuff attached.
 

Attachments

  • BitmapHandlerDll.zip
    3.9 KB · Views: 254

colin9876

Active Member
Licensed User
great

Well its very good, got all the c# now - cleverly done, thanks for that, Im going to work on the basic part. Try it with the BSv2.02 Ive posted above - its interesting!
 
Last edited:
Top