Mappy

BlitzMax Forums/BlitzMax Programming/Mappy

Gavin Beard(Posted 2005) [#1]
has anyone succesfully for a mappy tile map loaded into bmax? if so d'ya wonna share how :)


gman(Posted 2005) [#2]
when i read this i thought it would be a good way to cut my teeth on BlitzMax. i have a mostly finished mappy mod you can download here. i used pub.mod and it should go in a mappy.mod directory under that. also with the zip is the isotest converted to use the new MappyMap class. there are a couple of issues im hoping someone with more knowledge can pick up on what im doing wrong and fix.

the first is masking which isnt working. inside of the method MapDecodeBGFX is the code to set the mask information. the old BB code used the MaskImage command. i think i gathered enough info from the posts to convert it correctly to use MaskPixmap, but if i didnt then that may be where the problem lies. also, im not clear on the SetBlend functionality so i may be screwing something up there too. not sure where or when to use it. every image used is created manually from information stored in the mappy file. CreateImage with the MASKEDIMAGE option is being used. then each pixel is plotted individually. in any case, the iso example works, but the masking is not.

the second issue is converting the 6 parameter form of DrawImageRect. BlitzMax only has 4 parameters and im not sure how to replicate the desired functionality in BlitzMax. the locations where these are used can be found by searching on the word "PROBLEM".

anyone feel like taking a look and picking up where i left off?


tonyg(Posted 2005) [#3]
some heated discussions...
link
and unofficial code fixes...
link
No official response on whether it will be fixed.


Gavin Beard(Posted 2005) [#4]
apart from big purple bits (i'm guessing the masking prob u mention) this is quiet sweet, congrats

*edit: noticed if i do my own map and use that one then i get and error every time : "Attempt to index array element beyond array length"

its a 20x20 non iso map


gman(Posted 2005) [#5]
thx tonyg. didnt even think of the code archives! i also found:

Setimagemask

that appears to replicate the MaskImage of old. cant wait to try both these solutions out tonite and see how it goes! and thx gavin :) cant really take much credit for the code since im just converting, but it is doing wonders for allowing me to learn BMax syntax and such.


gman(Posted 2005) [#6]
could you please email me that map? id like to use it for testing tonite.

garritt@...

thx.


tonyg(Posted 2005) [#7]
Can you use SetMaskColor at load time?
Here's a couple of posts which found a workaround...
first
second
and from the code archives...
code archive
<edit> Mmm synchronised posting.


gman(Posted 2005) [#8]
hmm... maybe my problem is in the drawing, not the creation? im going to try storing the mask colors for each image and then writing a Draw routine that does the SetMaskColor, SetBlend, and draw. things to try :)


tonyg(Posted 2005) [#9]
Maybe this ?


gman(Posted 2005) [#10]
ok... i have made significant advances. most of the demos have been converted and are working. the original download link is now the new zip. the mod is still not completely converted due to DrawImageRect and how i had to accomplish masking. also, i am still have not looked at the custom map from gavin.

the masking issue was a curious one. i decided to get back to basics and just get it to work with a straight image. i was able to get it working multiple ways, but still could not figure out a way to get it working with an image that was created with CreateImage and WritePixel instead of LoadImage. what i ended up doing was masking the pixmap that WritePixel was using via MaskPixmap and storing it in the images masks array. instead of using DrawImage i use DrawPixmap directly from the masks array.


Gavin Beard(Posted 2005) [#11]
hey, that certainly is alot better and running quiet well, and my tst map seems to load and display with no probs at all


Kernle 32DLL_2(Posted 2005) [#12]
hey would it be possible to create a real bmx modul of mappy

edit: k, its done,everything works very well


Gavin Beard(Posted 2005) [#13]
lol, it sure does...


gman(Posted 2005) [#14]
kinda got sidetracked by a wrapper im working on for blitzmax. i will see if i can clean up the mappy mod and get the DrawImageRect functionality converted. will probably be a couple days before i get to it.


teamonkey(Posted 2005) [#15]
Hmmm. Under what conditions does it use DrawImageRect? It would be very inefficient if it used it for each tile and I'm not sure why you'd want to draw a small section of a tile if each tile is stored as a separate image.


gman(Posted 2005) [#16]
not quite sure what its there for (im just converting the BB code). its checking some user field properties for the map block and based on that drawing a portion of the image. all the images are stored inside of the map file and are built upon load via WritePixel. i would assume its something with how mappy stores the images inside the map file.


gman(Posted 2005) [#17]
this is interesting... do you think the Window method on TPixmap would be a way to replicate the 6 parameter format of DrawImageRect using pixmaps? so basically i could use a combination of TPixmap.Window() and DrawPixmap to replicate DrawImageRect. if thats the case i may switch to just using Pixmaps completely.


teamonkey(Posted 2005) [#18]
Pixmaps will be very very slow compared to TImages.

This function emulates the BlitzPlus/3D DrawImageRect, but I suspect it's best to avoid drawing partial images whenever possible.
Function DrawImageRect2(img:TImage, x#, y#, rx#, ry#, rw#, rh#, frame=0)
	Local vx, vy, vw, vh
	GetViewport(vx, vy, vw, vh)
	
	SetViewport(x, y, rw, rh)
	DrawImage(img, x-rx, x-ry, frame)
	
	SetViewport(vx, vy, vw, vh)
End Function



gman(Posted 2005) [#19]
thx for the reply TM.

thats unfortunate considering the only way i could get masking to work on an created image (using CreateImage) was to draw its pixmap directly. do you have any ideas on a resolution or maybe provide an example of drawing a masked image that was created using CreateImage and WritePixel? i can get masking to work fine using LoadImage, but since images are loaded pixel by pixel from the mappy file i have to use CreateImage.

also, for the "thats good to know" section, what is the reason for the slowness of using DrawPixmap?


dynaman(Posted 2005) [#20]
> also, for the "thats good to know" section, what is the reason for the slowness of using DrawPixmap?

I'm sure I have the technical names wrong, but a pixmap is stored in regular system memory while an image is stored on the video card's memory.


gman(Posted 2005) [#21]
thx dynaman :) i also found this to go along with that:

DrawPixmap slows down?

still at a loss at how to get masks working with CreateImage :(

edit: ive been able to get masking working with LoadImage either by using SetMaskColor() before loading or using the SetImageMask function from the code archives, but when i try SetImageMask on an image created by CreateImage or try using lock/maskpixmap/unlock, the masking simply wont work for me.


gman(Posted 2005) [#22]
after analyizing some of the Max2D and GLMax2D code, ive got a new lead im going to try. im going to attempt to manually create the frame from the masked pixmap. im already storing the masked pixmap back to the masks array. from the code i have seen, i also need to store the masked frame as well.


dynaman(Posted 2005) [#23]
This should work, I had submitted it to the code archives under graphics a while ago.


Function setimagemask(p_image:Timage, p_red,p_green,p_blue)
	Local l_maskrgb
	Local l_maskargb
	Local l_pixelrgb
	Local l_pixelraw
	Local l_x,l_y
	Local l_pix1:Tpixmap
	
	l_maskrgb = p_red * 65536 + p_green * 256 + p_blue
	l_pix1 = LockImage(p_image)
	For l_x = 0 To ImageWidth(p_image)
		For l_y = 0 To ImageHeight(p_image)
			l_pixelraw = ReadPixel(l_pix1,l_x,l_y)
			l_pixelrgb = l_pixelraw & 16777215
			If l_pixelrgb = l_maskrgb Then
				WritePixel(l_pix1,l_x,l_y,l_maskrgb)
			End if
		Next 
	next

	UnlockImage(p_image)
	Release l_pix1
End function



gman(Posted 2005) [#24]
i tried that and it worked beautifully for an image loaded with LoadImage... but when i tried it on an image created with CreateImage it ran without error, but it would not draw the image with the mask for some reason.


dynaman(Posted 2005) [#25]
I'll have to give it another go tonight, maybe something has changed with the latest updates. I'm using this in particular for images that are created.

I didn't make it clear, but this needs to be run after the image is updated with something, so first you would create the image, then draw whatever you plan to draw onto the image, and then run this command.


gman(Posted 2005) [#26]
hmmm. that is exactly what i was trying... hate to ask this but could you give a complete working example? maybe there is a Set command i am missing or something beyond the scope of creating. my code is basically like:

CreateImage
pixmap=LockImage
WritePixel in loop
UnlockImage
SetImageMask

doing this, i cannot get the mask working. from your example im hoping to glean what i am missing, whether it be a missing Set command or missing flags.


dynaman(Posted 2005) [#27]
You look like your doing it correct. I'll give this a shot tonight and post a complete example.


gman(Posted 2005) [#28]
whoooo! i think i have it :) have to wait a few for a full run but here is the solution:

Method MaskImage(img:TImage,red:Int=0,green:Int=0,blue:Int=0,frame:Int=0)
	Local pixmap:TPixmap=LockImage(img,frame)
	pixmap=MaskPixmap(pixmap,red,green,blue)		
	UnlockImage(img,frame)
	img.frames[frame]=blitz2d_driver.CreateFrameFromPixmap(pixmap,img.flags)
EndMethod



gman(Posted 2005) [#29]
ok, the mappy mod is complete (i think). its pretty much a straight conversion with a few new tweaks:

a) everything is wrapped up into a class, so no global vars to worry about

b) maxmaplayers defaults to 2, but is a parameter to loadmap now

c) i added the sample functions Collision() and PPCollision() to the MappyMap class as MapCollision() and MapPPCollision()

i fixed the drawing to use images instead of pixmaps (masking works!) and its much faster. i also completed the MapFlushMem method and added that to all the examples. the ZIP has been updated and can be downloaded here. have fun everyone :) if you see any problems please let me know.

and thanks for all the replies. the active and helpful blitz community is one of major reasons i decided to get into blitz in the first place :)


Gavin Beard(Posted 2005) [#30]
works a treat, thanks gman