Zoning

Blitz3D Forums/Blitz3D Programming/Zoning

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Okay, I got something down, but I need some help with speed optimization. really need help.

Function ZN_Init(mapn$)
	zn_zone=LoadImage(mapn$)
	zn_size=ImageWidth(zn_zone)
	zn_tex=LoadTexture(mapn$)
End Function

Function ZN_Update(ent=-1)
	DrawImage(zn_zone,0,0)			;The current zone image
	If ent=-1
		ent=zn_ent					;A default parameter
	EndIf
	tx=EntityX(ent)*10;/100			This is the x times map scale.
	tz=EntityZ(ent)*10;/100
	If tx<=zn_size And ty<=zn_size	;If in area
		GetColor tx,tz
		zn_r=ColorRed()
		zn_g=ColorGreen()
		zn_b=ColorBlue()
		;Tolerence Function
		zn_r=(zn_r/128)*128			;Get a solid color. Either 0/128/255. Needs to be fixed
		zn_g=(zn_g/128)*128			;Gives bad output
		zn_b=(zn_b/128)*128
		thisclr$=ZN_GetColor$(zn_r,zn_g,zn_b)	;A Function to return the color name.
		If thisclr$="darkgreen"					; 0 128 0
			zn_inzone=1
		Else If thisclr$="darkred"				; 128 0 0
			zn_inzone=3
		Else If thisclr$="grey"					; 128 128 128
			zn_inzone=2
		Else
			zn_inzone=0							;No zone
		EndIf
	EndIf
	zn_x=tx							;Debug out image position
	zn_y=tz
	Color 255,255,255
	;RuntimeError zn_r+","+zn_g+","+zn_b
End Function

Function ZN_DrawZone(znum=1,ent=-1,size=1)
	SetBuffer ImageBuffer(zn_zone)
	If ent=-1
		ent=zn_ent
	EndIf
	tx=EntityX(ent)*10;/100
	tz=EntityZ(ent)*10;/100
	Select znum
		Case 1					;Get zone number
			Color 255,0,0
			For x=tx-(size/2) To size*2
			  For y=tz-(size/2) To size*2
				Plot x,y		;Draw a box based on zone and size
			  Next
			Next
	End Select
	SetBuffer TextureBuffer(zn_tex)	;Set to terrain texture
	DrawImage zn_zone,0,0			;Copy zone image to texture
	SetBuffer BackBuffer()			;Back to the game
End Function