[Monkey] Performance bei TileMaps

Übersicht Andere Programmiersprachen Allgemein

Neue Antwort erstellen

 

DukeS87

Betreff: Performance bei TileMaps

BeitragDo, Feb 19, 2015 15:59
Antworten mit Zitat
Benutzer-Profile anzeigen
Heyho Leute, Ich bin gerade dabei ein Risiko Game zu programmieren. Dafür hab ich jetzt eine frühe Version des Editors fertiggestellt.
Die Gesamte Karte soll eine TileMap größe von (mind.) 180x180 Tiles haben.
Jetzt hab ich gerade einmal meine Karte zu 15% oder so fertig und es beginnt schon die framerate drastisch in den Keller zu gehen.
Zunächst habe ich die DrawRect befehle durch DrawImage ersetzt (gab irgendwie keinen erhofften Performance Gewinn).
Ich denke mal der Knackpunkt wird in der Funktion:
BlitzMax: [AUSKLAPPEN]
Method DrawFields(_X:Int,_Y:Int,_CntX:Int,_CntY:Int)
For Local x:Int = _X Until (_X+_CntX)
For Local y:Int = _Y Until (_Y+_CntY)
If x > MapX Then
x = MapX-1
EndIf
If y > MapY Then
y = MapY-1
EndIf
Local regID:Int = FieldArray2[x][y] 'FieldArray.Get(x,y)

#Rem
If RegionArray[regID+1] <> Null
Maniac_Color(RegionArray[regID+1].Color)
'DrawRect(X + (x-ScrollX)*fW,Y + (y-ScrollY)*fH,fW,fH)
DrawImage imgField,X + (x-ScrollX)*fW,Y + (y-ScrollY)*fH,0,fW/imgField.Width(),fH/imgField.Height()
EndIf
#End

For Local oReg:Region = EachIn ListRegion
If oReg.ID = regID
Maniac_Color(oReg.Color)
'DrawRect(X + (x-ScrollX)*fW,Y + (y-ScrollY)*fH,fW,fH)
DrawImage imgField,X + (x-ScrollX)*fW,Y + (y-ScrollY)*fH,0,fW/imgField.Width(),fH/imgField.Height()
Exit
EndIf
Next
Next
Next
End Method

liegen. _X,_Y sind dabei die TileMap Koordinaten (oben links mit Scroll) und CntX,cntY die anzahl der Tiles in die jeweilige Richtung. (Da ich den Editor nur mit 50x50 Tiles benutze anstelle der gesamten Karte.
Ich habe dabei die Liste der Regionen durch ein array ersetzt, ergab genausowenig einen Performance gewinn Sad. Also hab ich das ganze erstmal wieder auskommentiert.

Meine konkreten Fragen:
1.kostet der SetColor Befehl einen nennenswerten Performanceverlust? dann würde ich vllt. versuchen immer Regionenweise (Felder mit gleicher Farbe) hintereinander zu zeichnen. sodass statt 50x50 Cls nur noch 80 Cls für 80 Regionen angewendet werden muss.
2. Ist es irgendwie möglich die Felder nur dann zu zeichnen wenn sich etwas verändert hat?
Der Editor (und später das Spiel dazu) ist ja nur ein Teil dieser Zeichnung, sodass der Cls Befehl irgendwie alles ausser der Karte selbst löscht?
Was mir dabei aufgefallen ist, Wenn ich keine Karte geladen habe, hab ich 60fps, wenn ich sie lade, sinkt es auf 20. Unabhängig davon ob nun der DrawImage teil ausgeführt wird, oder nicht. Also egal ob innerhalb der DrawFields(...) Methode nun Tiles auftauchen oder nicht. das finde ich merkwürdig. Ich würde ja erwarten, dass die Performance erst dann sinkt, wenn überhaupt irgendwelche Rechtecke gezeichnet werden?
Momentan lasse ich meine Karte so zeichnen:
BlitzMax: [AUSKLAPPEN]
Method Draw()
'HINTERGRUND DER KARTE
If BG <> Null And bShowBG
DrawImage BG,X - ScrollX*fW , Y - ScrollY*fH ,0,Width/BG.Width()*zoomX,Height/BG.Height()*zoomY
EndIf
'RAHMEN UM KARTE
Drw_Rect(X,Y,Width,Height,3)

'ZEICHNEN DES GITTERS,FALLS ERWUENSCHT
If bGrid = True
SetAlpha 0.2
Drw_Grid(X,Y,Width,Height,ViewMapX,ViewMapX)
EndIf

SetColor 0,0,0
SetAlpha 1
'AN DIESER STELLE WIRD UM DIE KARTE HERUM ALLES SCHWARZ GEZEICHNET
DrawRect(0,0,DW,DH*0.1)
DrawRect(DW*0.8,0,DW*0.2,DH)
DrawRect(0,Y+Height+3,DW,DH*1)

SetColor(255,255,255)
Drw_ManiacText("Scroll: "+ScrollX+"/"+ScrollY+" | Zoom: "+zoomX+"/"+zoomY ,X,Y+Height+5,Width,30,ALIGNMENT_LEFT,ALIGNMENT_MIDDLEY)

'ZEICHNEN DER FELDER DER KARTE
DrawFields(ScrollX,ScrollY,ViewMapX,ViewMapX)

'ZUR KARTE GEHOERENDE BUTTONS
Btn_ZoomIn.Draw()
Btn_ZoomOut.Draw()

End Method


Ich hoffe ich konnte mein Problem einigermaßen verständlich rüberbringen
mfG Stephan

Dottakopf

BeitragDo, Feb 19, 2015 20:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Setcolor ist langsam wenn du es jedesmal wieder ausführst.

ein Beispiel:
Code: [AUSKLAPPEN]

   Method OnRender()
      Cls()
      
         Local start:Int = Millisecs()
      
         For Local i:Int = 0 Until 30
            SetColor(255, 0, 0)
            DrawText("das ist ein Text", 50, 0 + i * 10)
         Next
         
         DrawText("MS: " + (Millisecs() -start), 0, 0)
         
      
   End



achte mal auf die MS wenn du das setcolor rausnimmst Smile
denke der Fehler sollte dann bei dir hier zu finden sein: Code: [AUSKLAPPEN]
 Maniac_Color(RegionArray[regID+1].Color)


Code: [AUSKLAPPEN]

   #Rem
         If RegionArray[regID+1] <> Null
                 Maniac_Color(RegionArray[regID+1].Color)
            'DrawRect(X + (x-ScrollX)*fW,Y + (y-ScrollY)*fH,fW,fH)
            DrawImage imgField,X + (x-ScrollX)*fW,Y + (y-ScrollY)*fH,0,fW/imgField.Width(),fH/imgField.Height()
         EndIf
         #End



Für die 2te frage bin ich zu unerfahren mit Monkey. Tut mir leid


Gruß
Dottakopf
 

DukeS87

BeitragDo, Feb 19, 2015 21:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Danke für die Antwort, aber selbst wenn ich auf ...until 1000 setze, hab ich in beiden fällen 56 - 59 ms.

und meine
Maniac_Color Funktion ist nicht anderes , als eine Sammlung von Farben:
BlitzMax: [AUSKLAPPEN]
Function Maniac_Color(_Color:Int)

Select _Color
Case 0 'Schwarz
SetColor 0,0,0
Case 1
SetColor 50,50,50
Case 2
SetColor 75,75,75
Case 3
SetColor 100,100,100
Case 4
SetColor 125,125,125
...

usw usf. hab bisher 80 Farben (8 Hauptfarben mit je 10 helligkeitsstufen im select abgefangen.

Also glaube ich, liegt das eher am Grund-Design der TileMap, bzw. der Darstellung eben dieser.

mfG

welche Werte kommen denn bei dir, wenn du SetColor drin hast und nicht?

Thunder

BeitragDo, Feb 19, 2015 22:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Hab kein Monkey, also kann ichs nicht selber testen, aber probier vielleicht mal die Schleifen zu vertauschen. Also außen Y und innen X. Das kann dir eventuell wegen Caching eine bessere Performance bringen (kommt drauf an, wie die Datenstrukturen im RAM liegen). Kann natürlich auch sein, dass sich nix verändert Confused
 

DukeS87

BeitragDo, Feb 19, 2015 23:36
Antworten mit Zitat
Benutzer-Profile anzeigen
Interessante Idee. Werd ich morgen gleich mal ausprobieren. Auch wenn ich mir irgendwie nicht so richtig vorstellen kann was sich dann aendern soll. Meine naechste idee waere irgendwie groessere flaechen mit gleicher regionsId zu finden und das zu zeichnende rechteck irgendwie so zu zeichnen das es meinetwegen 10x10 drawimages ersetzt. Hab nur noch nichtmal den hauch hauch einer idee wie das gehn soll.

DAK

BeitragFr, Feb 20, 2015 1:21
Antworten mit Zitat
Benutzer-Profile anzeigen
Mir fällt da grad nur eins auf:

Code: [AUSKLAPPEN]
For Local oReg:Region = EachIn ListRegion
   If oReg.ID = regID


Sowas lässt sich mit einer sinnvollen Datenstruktur deutlich beschleunigen!
Gewinner der 6. und der 68. BlitzCodeCompo

Dottakopf

BeitragFr, Feb 20, 2015 8:57
Antworten mit Zitat
Benutzer-Profile anzeigen
hä ? ich hab da 300 MS sobald ich setcolor einbaue Shocked
Hab natürlich zuhause nur das HTML Target getestet Confused
Rechtschreibfehler gelten der allgemeinen Belustigung!
 

DukeS87

BeitragFr, Feb 20, 2015 12:10
Antworten mit Zitat
Benutzer-Profile anzeigen
... Und ich hab nur glfw2 getestet ... Da ham wa aepfel mit birnen verglichen. Aber trotzdem konisch das es da sone unterschiede gibt.
 

DukeS87

BeitragFr, Feb 20, 2015 16:57
Antworten mit Zitat
Benutzer-Profile anzeigen
Ok, hab jetzt mal ein kleines Beispiel nur mit der Map programmiert, und hab ich dann recht konstant 60 fps.
Also liegt es höchst wahrscheinlich an meiner eigenen GUI oder so.
mit Q/A könnt ihr zoomen, mit den Pfeiltasten Scrollen.
Aber vorsicht, noch wird kein Array-Überlauf abgefangen, also immer schön innerhalb der 180x180 bleiben Very Happy.
HTML ist natürlich deutlich langsamer.

Die Regionen werd ich in zukünftigen Versionen dann in einem Array abspeichern, da das durchlaufen der Liste sicherlich mehr Zeit kostet als ein einfacher array[][] befehl.

Aber vllt. fällt euch ja trotzdem was am Design auf- was falsch ist, oder abgeändert werden sollte.
mfG

BlitzMax: [AUSKLAPPEN]
Import mojo

#GLFW_WINDOW_TITLE="Test"
#GLFW_WINDOW_WIDTH=1600
#GLFW_WINDOW_HEIGHT=800
#GLFW_WINDOW_RESIZABLE=True
#GLFW_WINDOW_FULLSCREEN=False

Global DW:Float
Global DH:Float
Global map:cMap

Const COLOR_BLACK:Int = 0
Const COLOR_GRAY:Int = 4
Const COLOR_WHITE:Int = 9
Const COLOR_RED:Int = 10
Const COLOR_GREEN:Int = 20
Const COLOR_DARKGREEN:Int = 27
Const COLOR_BLUE:Int = 30
Const COLOR_YELLOW:Int = 40
Const COLOR_ORANGE:Int = 50
Const COLOR_MAGENTA:Int = 60
Const COLOR_BROWN:Int = 70
Const COLOR_PURPLE:Int = 80

Const COLOR_PLAYER1:Int = 801
Const COLOR_PLAYER2:Int = 802
Const COLOR_PLAYER3:Int = 803
Const COLOR_PLAYER4:Int = 804


Global fps:Int
Global lastReset:Int
Global fpsSum:Int

Function Main:Int()
New Editor
End Function


Class Editor Extends App
Method OnCreate:Int()
SetUpdateRate( 60 )
DW = DeviceWidth()
DH = DeviceHeight()

map = New cMap(3,DH*0.1,DW*0.8-6,DH*0.85,180,180)
End Method


Method OnUpdate:Int()
map.Update()

'#### SCROLL STEUERUNG ####
If KeyHit(KEY_RIGHT)
map.setScrollX(5)
EndIf
If KeyHit(KEY_LEFT)
map.setScrollX(-5)
EndIf

If KeyHit(KEY_UP)
map.setScrollY(-5)
EndIf
If KeyHit(KEY_DOWN)
map.setScrollY(5)
EndIf

If KeyHit(KEY_Q)
map.ViewMapX -= 10
map.ViewMapY -= 10
map.fW = map.Width/map.ViewMapX
map.fH = map.Height/map.ViewMapY
map.zoomX = map.MapX*1.0 / map.ViewMapX*1.0 '1.5' ViewMapX / MapX
map.zoomY = map.MapY*1.0 / map.ViewMapY*1.0'1.5' ViewMapY / MapY
EndIf

If KeyHit(KEY_A)
map.ViewMapX += 10
map.ViewMapY += 10
map.fW = map.Width/map.ViewMapX
map.fH = map.Height/map.ViewMapY
map.zoomX = map.MapX*1.0 / map.ViewMapX*1.0 '1.5' ViewMapX / MapX
map.zoomY = map.MapY*1.0 / map.ViewMapY*1.0'1.5' ViewMapY / MapY
EndIf
End Method


Method OnRender:Int()
fpsSum += 1
If MilliSecs() - lastReset > 1000
fps = fpsSum
fpsSum = 0
lastReset = MilliSecs()
EndIf
Cls
map.Draw()

DrawText "fps: " + fps , 10,30
End Method
End Class


Class cMap

Field ListRegion:List<Region>
Field FieldArray2:Int[][]
Field MapX:Int 'Number of ALL Tiles (Horizontal)
Field MapY:Int 'Number of ALL Tiles (Vertical)
Field X:Float,Y:Float 'Offset from upper Left ScreenCorner
Field Width:Float,Height:Float 'Width & Height of the Whole Map (Pixel)
Field fW:Float,fH:Float 'Width & Height of one Tile (Pixel)
Field bGrid:Bool = True

Field ViewMapX:Int' = 50 'Viewable Tiles
Field ViewMapY:Int' = 50
Field zoomX:Float,zoomY:Float
Field ScrollX:Int,ScrollY:Int
Field BG:Image


Method New(_X:Float,_Y:Float,_Width:Float,_Height:Float,_MapX:Int=20,_MapY:Int=20)
MapX = _MapX
MapY = _MapY
Width = _Width
Height = _Height
X = _X
Y = _Y
ViewMapX = _MapX
ViewMapY = _MapY
fW = Width/ViewMapX
fH = Height/ViewMapY
zoomX = MapX*1.0 / ViewMapX*1.0 '1.5' ViewMapX / MapX
zoomY = MapY*1.0 / ViewMapY*1.0'1.5' ViewMapY / MapY

' FieldArray = New gArray2D<Int>(_MapX,_MapY)
FieldArray2 = Array2D(_MapX,_MapY,-1)
ListRegion = New List<Region>
addRegion("Region 1",10)
addRegion("Region 2",20)
addRegion("Region 3",30)
addRegion("Region 4",40)
addRegion("Region 5",50)
addRegion("Region 6",60)
addRegion("Region 7",70)
addRegion("Region 8",80)
addRegion("Region 9",13)
addRegion("Region 10",14)
addRegion("Region 11",22)
addRegion("Region 12",31)
addRegion("Region 13",15)
addRegion("Region 14",13)
addRegion("Region 15",14)
addRegion("Region 16",22)
addRegion("Region 17",31)
addRegion("Region 18",15)
addRegion("Region 10",14)
addRegion("Region 11",22)
addRegion("Region 12",31)
addRegion("Region 13",15)
addRegion("Region 14",13)
addRegion("Region 15",14)
addRegion("Region 16",22)
addRegion("Region 17",31)
addRegion("Region 18",15)
For Local x:Int = 0 Until 170
For Local y:Int = 20 Until 170
addField(Rnd(1,25),x,y)
Next
Next

End Method

Method setBackgroundImage:Void(_Img:Image)
BG = _Img
End Method

Method Draw()
If BG <> Null
fW = Width/ViewMapX
fH = Height/ViewMapY
zoomX = MapX*1.0 / ViewMapX*1.0 '1.5' ViewMapX / MapX
zoomY = MapY*1.0 / ViewMapY*1.0'1.5' ViewMapY / MapY
DrawImage BG,X - ScrollX*fW , Y - ScrollY*fH ,0,Width/BG.Width()*zoomX,Height/BG.Height()*zoomY
',EF_OffX - ScrollX*EF_TileW,EF_OffY- ScrollY*EF_TileH,0,EF_Width/BG_Image.Width()*EF_Zoom,EF_Height/BG_Image.Height()*EF_Zoom
EndIf
Drw_Rect(X,Y,Width,Height,3)

If bGrid = True
SetAlpha 0.2
Drw_Grid(X,Y,Width,Height,ViewMapX,ViewMapX)
EndIf
SetColor 0,0,0
SetAlpha 1
DrawRect(0,0,DW,DH*0.1)
DrawRect(DW*0.8,0,DW*0.2,DH)
DrawRect(0,Y+Height+3,DW,DH*1)

DrawFields(ScrollX,ScrollY,ViewMapX,ViewMapX)

SetColor 255,255,255
DrawText "Mouse: " + (ll_GridX(fW, X)+ScrollX) +"|" + (ll_GridY(fH, Y)+ScrollY),10,10
End Method

Method Update()

If TouchHit() Or TouchDown()
Local mX:Int = (ll_GridX(fW, X)+ScrollX)
Local mY:Int = (ll_GridY(fH, Y)+ScrollY)
If mX - ScrollX > -1 And mX -ScrollX < ViewMapX And mY-ScrollY > -1 And mY-ScrollY < ViewMapY
addField(2,mX,mY)
EndIf
EndIf
End Method

Method addField(_RegionID:Int,_X:Int,_Y:Int)
FieldArray2[_X][_Y] = _RegionID
End Method

Method addRegion(_Name:String,_Color:Int,_ID:Int = -1)
Local oReg:Region
If _ID <> -1
oReg = New Region(_ID,_Color,_Name)
Else
oReg = New Region(ListRegion.Count(),_Color,_Name)
EndIf
ListRegion.AddLast(oReg)
End Method

Method DrawFields(_X:Int,_Y:Int,_CntX:Int,_CntY:Int)
For Local x:Int = _X Until (_X+_CntX)
For Local y:Int = _Y Until (_Y+_CntY)
If x > MapX Then
x = MapX-1
EndIf
If y > MapY Then
y = MapY-1
EndIf
Local regID:Int = FieldArray2[x][y]'FieldArray.Get(x,y)

If regID <> -1 '-1 ist der Standardwert, dann braucht nichts gezeichnet zu werden
For Local oReg:Region = EachIn ListRegion
If oReg.ID = regID
Maniac_Color(oReg.Color)
DrawRect(X + (x-ScrollX)*fW,Y + (y-ScrollY)*fH,fW,fH)
EndIf
Next
EndIf
Next
Next
End Method

Method setScrollX(_i:Int)
ScrollX += _i
End Method

Method setScrollY(_i:Int)
ScrollY += _i
End Method

Method saveMap(file:FileStream)
'### Save Regions ###
file.WriteInt ListRegion.Count()

For Local oReg:Region = EachIn ListRegion
oReg.saveRegion(file)
Next


'### Save Fields ###
file.WriteInt MapX
file.WriteInt MapY
For Local x:Int = 0 Until MapX
For Local y:Int = 0 Until MapY
file.WriteInt FieldArray2[x][y]
Next
Next
End Method

Method loadMap(file:FileStream)
Editor.DropDown_Regions = New ManiacDropDown(DW*0.81+3,DH*0.1+35+3,DW*0.187-6,30,"Regions")
Editor.DropDown_Regions.setWrapToLines(True)
ListRegion = New List<Region>
Local nrReg:Int = file.ReadInt()
For Local i:Int = 0 Until nrReg
Local Reg:Region = Region.loadRegion(file)
ListRegion.AddLast(Reg)
Editor.DropDown_Regions.addLine(Reg.Name)
Next

'### Save Fields ###
MapX = file.ReadInt()
MapY = file.ReadInt()
For Local x:Int = 0 Until MapX
For Local y:Int = 0 Until MapY
FieldArray2[x][y] = file.ReadInt()
Next
Next
End Method
End Class

Class Region
Field ID:Int
Field Color:Int
Field Name:String
Field PlayerID:Int =-1
Field Soldiers:Int

Method New(_ID:Int,_Color:Int,_Name:String ="")
ID = _ID
Color =_Color
Name =_Name
End Method

Method saveRegion:Void(file:FileStream)
file.WriteInt ID
file.WriteInt Color
file.WriteInt Name.Length()
file.WriteString Name
file.WriteInt PlayerID
End Method

Function loadRegion:Region(file:FileStream)
Local id:Int = file.ReadInt()
Local color:Int = file.ReadInt()
Local il:Int = file.ReadInt()
Local name:String = file.ReadString(il)
Local pl:Int =file.ReadInt()

Return New Region(id,color,name)
End Function
End Class

Function ll_Width:Float(_Width:Float,_Number:Float,_Distance:Float)
Local fW:Float
fW = (_Width-_Number*_Distance-_Distance)/(_Number)
Return fW
End Function
Function ll_GridX:Int(width_p:Int, offset:Int = 0)

Return (MouseX() -offset) / (width_p)

End Function

Function ll_GridY:Int(width_p:Int, offset:Int = 0)

Return (MouseY() -offset) / (width_p)

End Function
Function Array2D:Int[][] (i:Int, j:Int,fill:Int = 0)

Local arr:Int[][] = New Int[i][]
For Local ind = 0 Until i
arr[ind] = New Int[j]
Next

For Local w:Int = 0 Until i
For Local h:Int = 0 Until j
arr[w][h] = fill
Next
Next
Return arr
End

#Rem monkeydoc
### READY To USE ###~n
This Function Draws a Outlining Rectangle at the Position _X,_Y with the Dimensions _Witdth And _Height with the thickness _Thickness.
You must call this within the OnRender() Method
#End
Function Drw_Rect:Int(_X:Float,_Y:Float,_Width:Float,_Height:Float,_Thickness:Int=1,_Angle:Float = 0.0)
'### Rotate The Matrix at the MidX/MidY Position around Angle
If _Angle <> 0.0
RotateAt(_X+_Width/2,_Y+_Height/2, _Angle)
EndIf

'### Drawing the Outline Rect with Thickness in Pixels for the Frame
For Local i:Int = 0 Until _Thickness
'Obere Kante
DrawLine (_X-i,_Y-i,_X +_Width+i,_Y-i)

'Untere Kante
DrawLine (_X-i,_Y+_Height+i,_X+_Width+i,_Y+_Height+i)

'Linke Seite
DrawLine (_X-i,_Y-i,_X-i,_Y+_Height+i)

'Recht Seite
DrawLine (_X+_Width+i,_Y-i,_X+_Width+i,_Y+_Height+i)
Next

'### Reset The MAtrix
If _Angle <> 0.0
ResetMatrix()
EndIf
End Function

#Rem monkeydoc
### READY To USE ###~n
This Function Draws a Grid at the Position _X,_Y with the Dimensions _Witdth And _Height And the number of cells in x And y direction
You must call this within the OnRender() Method
#End
Function Drw_Grid:Void(_X:Float,_Y:Float,_Width:Float,_Height:Float,_CellsX:Int,_CellsY:Int)

Local cell_w:Float = _Width/_CellsX
Local cell_h:Float = _Height/_CellsY

For Local x:Int = 1 To _CellsX-1
For Local y:Int = 1 To _CellsY-1

'Vertikale
DrawLine(_X+x*cell_w,_Y,_X+x*cell_w,_Y+_CellsY*cell_h)

'Horizontale
DrawLine(_X,_Y+y*cell_h,_X+_CellsX*cell_w,_Y+y*cell_h)

Next
Next

End Function

Function RotateAt:Void(x:Float, y:Float, angle:Float)
Translate(x, y)
Rotate(angle)
Translate(-x, -y)
End

Function ResetMatrix:Void()
SetMatrix(1,0,0,1,0,0)
End

#Rem monkeydoc
### EXPERIMENTAL ### ~n
This Function sets the Render-Color To a predefined color by The Maniac-Color-Consts.
You can find the Colors in the Functions Section.~n
Details:
COLOR_BLACK = 0, COLOR_GRAY = 4, COLOR_WHITE = 9
COLOR_RED = 10 To 19 ; 10 is 255,0,0, the part of Red decreases by higher ID
So, every COlOR has 10 brightnes grades.
You can use it like

Duke_Color2(COLOR_GREEN + brightness), whereas brightness can be an Int Value between 0 And 9
so, COLOR_GREEN + 8 is a very dark green
#End
Function Maniac_Color(_Color:Int)
'Maniac_Debug.addCall()
Select _Color
Case 0 'Schwarz
SetColor 0,0,0
Case 1
SetColor 50,50,50
Case 2
SetColor 75,75,75
Case 3
SetColor 100,100,100
Case 4
SetColor 125,125,125
Case 5
SetColor 150,150,150
Case 6
SetColor 175,175,175
Case 7
SetColor 200,200,200
Case 8
SetColor 225,225,225
Case 9 'Weiss
SetColor 255,255,255

'### ROT ### colors 10-19
Case 10
SetColor 255,0,0
Case 11
SetColor 230,0,0
Case 12
SetColor 210,0,0
Case 13
SetColor 190,0,0
Case 14
SetColor 170,0,0
Case 14
SetColor 150,0,0
Case 15
SetColor 130,0,0
Case 16
SetColor 110,0,0
Case 17
SetColor 90,0,0
Case 18
SetColor 70,0,0
Case 19
SetColor 50,0,0


'### GRUEN ### 20-29
Case 20
SetColor 0,255,0
Case 21
SetColor 0,230,0
Case 22
SetColor 0,210,0
Case 23
SetColor 0,190,0
Case 24
SetColor 0,170,0
Case 25
SetColor 0,150,0
Case 26
SetColor 0,130,0
Case 27
SetColor 0,110,0
Case 28
SetColor 0,90,0
Case 29
SetColor 0,70,0



'### BLAU ###
Case 30
SetColor 0,0,255
Case 31
SetColor 0,0,230
Case 32
SetColor 0,0,210
Case 33
SetColor 0,0,190
Case 34
SetColor 0,0,170
Case 35
SetColor 0,0,150
Case 36
SetColor 0,0,130
Case 37
SetColor 0,0,110
Case 38
SetColor 0,0,90
Case 39
SetColor 0,0,70

'### GELB ###
Case 40
SetColor 255,255,0
Case 41
SetColor 255,255,120
Case 42
SetColor 255,255,50
Case 43
SetColor 215,215,0


'### ORANGE ###
Case 50
SetColor 255,140,0

'### MAGENTA ###
Case 60
SetColor 255,0,255

'### BROWN ###
Case 70
SetColor 210,180,140
Case 71
SetColor 222,184,135
Case 72
SetColor 205,133,63
Case 73
SetColor 165,42, 42
Case 74
SetColor 160,82,45
Case 74
SetColor 139,69,19


'### PURPLE +####
Case 80
SetColor 75,0,130

Case COLOR_PLAYER1
SetColor 0,0,255

Case COLOR_PLAYER2
SetColor 0,255,0

Case COLOR_PLAYER3
SetColor 255,0,0

Case COLOR_PLAYER4
SetColor 255,255,255

End Select
End Function

Holzchopf

Meisterpacker

BeitragFr, Feb 20, 2015 21:55
Antworten mit Zitat
Benutzer-Profile anzeigen
1. Das ist ziemlich viel Code, um mal einfach so durchzuschauen. Zumal du offenbar schon einige Tipps erhalten hast und umsetzen konntest. Für eine einfache Stil-Kritik mag das ja gehen, aber solltest du mal ernsthaft wieder wo anstehen, wirst du wahrscheinlich länger warten müssen, bis sich einer erbarmt.

2. Code: [AUSKLAPPEN]
map = New cMap(3,DH*0.1,DW*0.8-6,DH*0.85,180,180)

180x180 Tiles sind schon recht viel (immerhin 32400).

3. Code: [AUSKLAPPEN]
            For Local oReg:Region = EachIn ListRegion
               If oReg.ID = regID

Für jedes Tile wird also statt der Region nur die Regions-ID gespeichert und bei jedem zeichnen soll er für jedes Tile die ganze Liste durchgehen, um die entsprechende Region zu finden? Das ist äusserst unästhetisch und zudem auch unnötig langsam. Verwende doch anstatt einem Int-Array einfach ein Region-Array und erspare dir den Umweg über die ID Wink Anstatt dem Defaultwert von -1 verwendest du dann einfach Null.
(Edit: Oh, das weisst du ja schon)

Und so nebenbei: Wenn du so "Suche in ungeordneter Liste genau einem Wert"-Sachen hast, dann verlasse die Schleife, sobald der Wert gefunden wurde.

4. Code: [AUSKLAPPEN]
DrawFields(ScrollX,ScrollY,ViewMapX,ViewMapX)

Das zweite ViewMapX sollte wohl ein ViewMapY sein Wink Spielt zwar hier keine Rolle, weil beides gleich gross ist.

5. Wieso verwendest du in Maniac_Color im Select-Statement nicht die Konstanten, die du definiert hast?

6. Die Drw_Grid Funktion ist in meinen Augen falsch konzipiert: Ein Gitter besteht nach meinem Verständnis aus Linien. Und zwar ViewMapX vertikalen und ViewMapY horizontalen linien Rolling Eyes Brauchst also nur zwei einzelne Schleifen statt zwei verschachtelte.

mfG
Holzchopf
Erledige alles Schritt um Schritt - erledige alles. - Holzchopf
CC BYBinaryBorn - Yogurt ♫ (31.10.2018)
Im Kopf da knackt's und knistert's sturm - 's ist kein Gedanke, nur ein Wurm
 

DukeS87

BeitragFr, Feb 20, 2015 22:05
Antworten mit Zitat
Benutzer-Profile anzeigen
Au danke für die Ausführliche Antwort.
Ja das mit der Regionenliste hab ich ja schon erwähnt, werde ich zu Array's abändern.
Aber trotzdem komisch, in meiner Version hatte ich da eigentlich ein "Exit" eingebaut. ist beim neuschreiben scheinbar auf mysteriöse weise verschwunden Very Happy.
Ja und mit dem Grid, oops, da hast du natürlich auch recht. Das mir das noch nie aufgefallen ist. dabei benutze ich die Funktion schon locker n halbes Jahr Rolling Eyes

Muss wohl noch etwas mehr Fleiß an den Tag legen beim überprüfen meiner Codes.
Danke soweit erstmal. Ich denke damit wurde mir insgesamt genug geholfen.

mfG Stephan

Neue Antwort erstellen


Übersicht Andere Programmiersprachen Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group