Arrays

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Arrays

Post by Kjell »

Hi,

Although Arrays are currently not supported by the ZGE Scripting Language, I've come up with a pretty solid alternative. For 1 Dimensional Arrays I'm using a Mesh, while Bitmaps make a perfect double for 2D Arrays. The trick is to have a dedicated model act as a Array Controller that you can set to request a certain key / store certain data at a specified location. In combination with a MeshExpression / BitmapExpression that checks the Array Controller Model for requests, you can have a pretty solid Array-like solution. The biggest downsides are that you'll need to define a number of variables equal to the maximum number of requests you support per frame, as well as the number of keys your Array ( Mesh:Vertices / Bitmap:Pixels ) supports.

Regards,
K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

great Idea!

Post by jph_wacheski »

that does sound like a good method,. I was thinking there could be a way to store data in a bitmap, but had not attempted this yet. Would you please post a small example file to help me figure out how set it up,. Im looking for a way to store note numbers for simple music phrases,. midi is cool, but I still have not found a simple editor for that format,. and of course little data bits will be usefull for so many game control things,.
and perhaps if the bitmaps would allow for 1xwhatever 2d arrays would be even cleaner when used this way,.
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hey jph,

Seems like I cheered a little too early :( When updating a Mesh / Bitmap in order to set / retrieve data, the Mesh / Bitmap seems to be diverted to it's original initial state before the query is executed, and with this losing all previously set data :? I wonder why this is though ...

By the way, there are plenty of great Midi-based Sequencers out there such as Logic / Sonar / Cubase as well as a wide variety of freeware alternatives. Even when you want to update you track dramatically in real-time, it's probably easier to go with multiple midi files then depending on Arrays.

Kind Regards,
Kjell
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

A good and creative idea Kjell!

I thought it might work too. However a vertex-expression operates on other mesh-data generated from MeshBox, MeshFile etc. And that data is initialized every time. This is because if you alter the properties on a mesh producer such as MeshBox it must be generated again.

For bitmapexpression the behavior is currently that pixels not touched can be assumed to have the value zero (black). If they were to keep the values from the previous run, it could give unpredictable results when editing the expression in the Editor.

I guess another downside to the suggested method is that it is quite inefficient since the whole content needs to be searched for the value, with an expression like this:

Code: Select all

if( (this.X==RequestedX) &&  (this.Y==RequestedY))
  RequestedValue = this.Pixel.R;
Did I understand correctly? For read-only data this will work, so when embedding a map like in the FileDemo it could be done in a bitmap instead.

I agree that for music, finding a good midi-editor will be more productive.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hej Ville,

Indeed, in order to set / get data from the Bitmap I used a script similar to your example that triggers a entire loop through the Bitmap. Inefficient yes, but in case it would have worked, it would have been a good "Ghetto" solution for now.

And it does work when you're only reading data yes. So it's still useful for simple level layouts, non-animated floor collision height-maps and such .. although the data has to be defined in the BitmapExpression, as it is not possible to use BitmapFromFile and BitmapExpression subsequently.

Regards,
K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

humm,.

Post by jph_wacheski »

well that is too bad, it would be a nice way to import level data, etc. into ZGE, could something be added to just read data from a bitmap,. as I can think of loads of uses for that. And I would like the data prootected in the exe. I was just going to use this to build 3d text however on reading this again we can not currrently read from imported maps,.
Attachments
stuff like this i used to make at work in paint when no one was looking,. . was going to use these in GM but i would rather use those pixels to build a ZGE level!
stuff like this i used to make at work in paint when no one was looking,. . was going to use these in GM but i would rather use those pixels to build a ZGE level!
40X30_level_X4.jpg (5.04 KiB) Viewed 10531 times
iterationGAMES.com
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

I've been thinking about adding a filecontent-property to the file component for embedding a file in the exe instead of reading a external file. That way you could embed the file with the alien-design in the loose-pixels game. Also if you save the bitmap above in a format that can be read by the file-component (either uncompressed binary bitmap without headers, or as ascii) you can read a map using that technique.

I will also examine the possibility of using a bitmapexpression on data from bitmapfile.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

ah,. indeed I will read up on my file formats,. I was under the mistaken impression that text was all that could be read,. or at least i had not considered other ways to save graphic files,. it looks as though a simple paint program will be useable for a level/gamedata editor. you keep me thinkin' thanks for that!
iterationGAMES.com
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

I had to look it up in the component reference too. You can use file-encoding Binary if you want to read single precision (4 byte) float values. I included this format because I wanted to be able to save high-score (although write is still not supported) and other game settings and then read them back. So to use this format you need to save your picture with 4-bytes (rgba) pixels size. Also the Char-encoding does not have to be text, it can be used for reading binary 1-byte format like an image saved in 256-color mode.

When I did the space-invader file for the FileDemo, I started from a bitmap and saved it uncompressed (bmp). Then I used a hex-editor to remove the header so only the pixel values were left. I can't remember now how I did the last step of transforming the data into a readable textfile, possibly I just did a search-and-replace in a texteditor. So it can be done that way although I'm sure there are simpler techniques. You can look for image-programs that can export to ascii-format, or raw bitmaps without headers.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

ASCII levels from images,. .

Post by jph_wacheski »

yeah I get sucked into the metaphor and forget that all this digital media is a bunch of digits, Matrix style. I am a big fan of the GIMP for all my image prossesing needs,. and a quick look throught the formats tought me a few things,. (it will even generate an HTML table based on an image,. cool ! ) The best one for this looks to be an X PixMap image it generates some sweet ASCII art from images,. and I can figure how to read this into ZGE from your file example,.

Code: Select all

/* XPM */
static char * 40X30_level_xpm[] = {
"40 30 7 1",
" 	c #000000",
".	c #008000",
"+	c #FF0000",
"@	c #00FF00",
"#	c #C0C0C0",
"$	c #FFFF00",
"%	c #FFFFFF",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%$%",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%...%%%.@@..",
"%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%.%%%%%....",
"%%%%%%.@.%#%..@@@@%%%%%%%%%%%%%%%%%%%%..",
"%$%%%%%.%%%%%....%%%%%%%%%%%%%%%%%%%%%%%",
".@@@%%%%%%#%%%..%%%%%%%%%%%%%%%%%%%%%%%%",
"...@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"...%%%%%%%#%%%%%%%%%%%%%@.%%%%%%%%%%%%%%",
"..%%%%%%%%%%%%%%%%%%%%$@...%%%%%%%%%%%%%",
"..%%%%%%%%#%%%%%%%%%%%......%%%%%%%%%%%%",
"..%%%%%%%%%%%%%%%%%%%@.......%%%%%%%%%+%",
"..%%%%%%%%#%%%%%%%%@.........%%%%%%@@@@%",
"...@%%%%%...%%%%........%%%%%%%%%%@@@.@.",
"....@% %....@@.@........%....%%%%%......",
"...................%%%%%%.....%#%.......",
"................%%%%..........%%%.......",
".....%%%%%%.....$%%%.......%%%%#%.......",
"...%%%%%%%%%%%...%%....%%%%%%%%%%%......",
".%%%%%%%%%%%%%%......%%%%%%%%%%#%%%%...%",
".%%%%%%%%%%%%%%%...%%%%%%%%%%%%%%%%%%%%%",
".%%%%%%%%%%%%%%%%%%%%%%%%%%....%%%%%%%%%",
".%%%%%%%%%%%%%%%%%%%%%%%%%.........%+%%%",
".$%%%%%%%%%%%%%%%%%%%%%%%.............%%",
".@$%%%%%%%%%%%%@@%%%%%%%%...............",
".@@$%%%%%%%%%@@@@@@.....................",
"..@@%%+%%...............................",
"........................................"};
wicked!
iterationGAMES.com
Post Reply