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.

AppGameKit Classic Chat / manipulating bytes

Author
Message
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 22nd Nov 2016 04:28 Edited at: 22nd Nov 2016 04:47
just what the title says!

i was doing some work to see if i could infact store more information inside a single byte.
as everyone knows... i hope... a byte can be in the range of 0-255

you can store allot in a single byte surprisingly.
you could have 8 on off switches
you could have two 0-15 valued numbers
you could have 4 0-3 valued numbers

and more combinations....

what id like to do is store map data for a scene in the smallest possible compact way to conserve space and memory.

after writting this i also realized that it would be easy to hide code from others in a way of bit shifting and swapping...lol


comments... let me know what you think

Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Nov 2016 07:20
Quote: " map data"

which size?
in relationship to image data size i don't think you save memory, but your attitude is good.
i prefer real var names.
often code optimize end up in kludge and you lost overview.
AGK (Steam) V2.0.21 : Windows 10 Pro 64 Bit : AMD (16.6) Radeon R7 265 : Mac mini OS Sierra (10.12)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Nov 2016 08:10
This is how Sprite groups work, so you would be extending what is already part of AGK.
Personally, I get confused with bit-shifting, but if you can get your head around it comfortably then it's a good way to go.
I don't worry too much about file sizes these days. Reducing 10K to 2K doesn't make much difference. But if you are reducing 10MB to 2 MB then it might be worth considering.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 22nd Nov 2016 16:46
This was my whole idea of introducing Byte Code to the DB family of products... originally I had intended it to be used to make a download of a game (in code) as tiny as possible, with the use of a browser plugin "player" to decode and interpret the source, downloading media from remote locations as required. Bytecode also serves as an excellent way to obfuscate source code. Win-win.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 22nd Nov 2016 17:19
This could also be good for networking a game. You could pack more information in your sent messages keeping the chunks smaller.

Im going to do one more... extracting a byte from a short.

Also Processing midi sometimes has its data coded in 3 bytes of data. Extracting the number from 3 bytes is currently not possible with akg basic so i will add functions for this also.
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 24th Nov 2016 12:48
Quote: "i was doing some work to see if i could infact store more information inside a single byte."

I am quite astonished by the fact that I work on nearly the same problems as you do, at the same time.

Have you found a way to store the information of 4 bytes into an integer? This borders me, because I want to store r,g,b,a values in it,
but I think this is not possible This is for an online image transmitter.





Sorry for going a little bit off topic, but this is also a nice formula to play around, if you try to store information in strings
Tuppers formula
Tuppers Sandbox

[/url]
damothegreat
User Banned
Posted: 24th Nov 2016 13:07 Edited at: 24th Nov 2016 13:13
R - possible colours 0-255
G - possible colours 0-255
B - possible colours 0-255
A - possible transparency 0-255

= 4 single Bytes

Integer come in 4 bytes anyway

So maybe R = 255, G = 255, B = 0 , A = 255

So maybe could do:-

INT = R + (G * 255) + ( ( G * 255) + ( B * 0 ) ) + ( ( G * 255 ) + ( B * 0 ) + ( A * 255 ) )

or something along those lines

to convert back jyst reverse by minus and divides etc

Maybe completely wrong, but its all a learning curve from the top programming geniuses here

Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
damothegreat
User Banned
Posted: 24th Nov 2016 14:30
Try this



Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 24th Nov 2016 15:37
@damo
Impressive! Thank you!


[/url]
damothegreat
User Banned
Posted: 24th Nov 2016 15:40
ur welcome
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Nov 2016 19:27 Edited at: 24th Nov 2016 20:30
More bitwise fun:



A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 24th Nov 2016 23:18

Regarding ARGB colour packing and depacking, the math just boils down some shifts and masks, the same goes for pulling nibbles and bits etc

NOTE: mock up code

MyColour = rgb(255,50,100,200) ; Assuming colour levels are in A,R,G,B order.. They can be in in order but R,G,B,A is likely


A = ( MyColour >>24) and 255
R = ( MyColour >>16) and 255
G = ( MyColour >> 8) and 255
B = ( MyColour >>0) and 255 ; The shift here isn't needed here

Masking A would only be needed with the shift is arthimetic, which it shouldn't be in AGK

To roll your own RGB function we mask the inputs and then shift and OR into position, you can use addition also.


Function MyRGB(A,R,G,B)
NewColour = ((A and 255) << 24) or ((R and 255) << 16) or ((A and 255) << 8) or (A and 255 )
EndFunction NewColour




PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 25th Nov 2016 00:30
Ok so im building a new quarter float word.

It uses 1 bit for the sign and 2 bits for the quarter and the rest for the whole part of the number. This gives me a number range of -8191.75 to 8191.75

I think i can make adjustments to my 3d level and model editor to save this data and then to load back into agk as words instead of floats ... then reconstructing the model at run time. A normal float would be 4 bytes so this should cut my 3d scene and model data in half to 2 bytes rounding to the nearest quarter for the decimal place.

I will post with my new quarterfloat word function when completed.... if anyone interested in using it.

I know microsoft developed a half float using 16bits but i think i like the quarter approach better for the numbers i need.

Does anyone feel like taking a crack at coding a 16 bit float? Im no good with exponent math. What would that range be compared to mine?
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Nov 2016 23:58

you can try using Float to Fixed Point

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 26th Nov 2016 18:10 Edited at: 26th Nov 2016 18:13
@kevin... I like that idea thanks!

ok so here is my next addition

a byte float. This number range is -1.27 to 1.27 . im hoping to use this to store 3d texture alignment mapping. It only has two decimal places but I think it should work with certain atlas texture sizes.

ill report back after I test it.

here are the functions
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Nov 2016 03:33

if you've something in mind, then a look up table of 256 32bit values should do. So each byte is just indexes into a precalc table.

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 27th Nov 2016 19:41
Yes that will work for sure!

If i have 256 possible atlas textures then i can calculate the offsets just from a single byte value.

Thanks again

Login to post a reply

Server time is: 2024-11-24 22:48:42
Your offset time is: 2024-11-24 22:48:42