[B3D] Konstanter Anstieg der Speicherauslastung [GELÖST]

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

N0X

Betreff: [B3D] Konstanter Anstieg der Speicherauslastung [GELÖST]

BeitragDi, Jan 06, 2009 23:39
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey, Community !
Mein kleines MMORPG hat ab ca. 22.600 K, konstanten Anstieg der Speicherauslastung !
Hab bereits alles versucht, Debug, alles ungenutzte gelöscht usw.
Kann mir einer sagen warum, und was noch so alles an meinem Code nicht stimmt ?

Server:
Code: [AUSKLAPPEN]
AppTitle "4Story-Klon-Server"

Type client
   Field name$
   Field ip,port
   Field mesh
End Type

;Type-Konstanten
Const PLYTYPE=2
Const TERTYPE=1
port = 7142

Global udp = CreateUDPStream(port)

If Not udp Then
   Print "Der UDP Stream konnte nicht erstellt werden."
   End
EndIf

;Variablen
Global level=1
Global sprung=0,jumpcount=0jumpPossible=0
entity# = 0

Global gx=2,gy=0,gz=0

Global tx=1,ty=1

Global seq=1

Global plySpeed=1

Global w=KeyDown(17)

Global fg=0.2

;--------------------------------------------------------------------------------------------|

Graphics3D ax,ay,fx,2
SeedRnd MilliSecs()

;--------------------------------------------------------------------------------------------|

Global player     = LoadAnimMesh("mesh\dwarf1.b3d")
Global clientp    = LoadAnimMesh("mesh\dwarf1.b3d")

Global font = LoadFont("Lucida Sans Unicode",15,1)

Global cam        = CreateCamera(player)
Global licht      = CreateLight()

Global gras       = LoadTexture("gfx\gras.jpg")

Global land       = CreatePlane()
Global testObjekt = LoadMesh("mesh\cube.3ds")

Global bgDing     = LoadImage("gfx\bgGegenstände.png")
Global maus       = LoadImage("gfx\mauszeiger.png")

Global baum       = LoadMesh("mesh\baum1.3ds")

;--------------------------------------------------------------------------------------------|
HideEntity clientp
PositionEntity cam,0,60,-60
PositionEntity land,0,-5,0
PositionEntity player,0,0,0
PositionEntity baum,0,0,100

CameraClsColor cam,150,170,255
CameraRange cam,1,999999999

EntityTexture land,gras

ScaleTexture gras,30,30

MaskImage bgDing,255,255,255
MaskImage maus,255,255,255

EntityType player,PLYTYPE
EntityType baum,PLYTYPE
EntityType land,TERTYPE

MoveMouse 840,525

EntityPickMode testObjekt,2,1 

SetFont font

;timer=CreateTimer(50)

;--------------------------------------------------------------------------------------------|

Collisions PLYTYPE,TERTYPE,2,2
Repeat
   
   Schwerkraft()
   PlayerBewegen()
   UDP()
   
   UpdateWorld()
   RenderWorld()
      
   DrawImage maus,MouseX(),MouseY()
   
   Pick()
   Texte()
   
   Flip
   Cls
   
Until KeyHit(1)
CloseUDPStream(udp)
End

FreeEntity player

;--------------------------------------------------------------------------------------------|

Function Schwerkraft()
   
   TranslateEntity player,0,-2,0
   
   TranslateEntity baum,0,-2,0
   
End Function


Function UDP()
   
   If RecvUDPMsg(udp) <> 0
      
      message = ReadByte(udp)
      
      Select message
      
         Case 1
            name$ = ReadString(udp)  ;Name des Clients lesen
              c.client = New client  ;Neues client objekt erstellen
              c\port = client_port ;Port speichern
              c\name$ = name$  ;Name speichern
            
         Case 2
            ShowEntity clientp
            px = ReadShort(udp)
            py = ReadShort(udp)
            pz = ReadShort(udp)
            For c.client = Each client
               c\mesh=clientp
               PositionEntity c\mesh,px,py,pz
            Next
            
         Case 3
            FreeEntity clientp
            
         Case 4
            End
      
      End Select
      
   EndIf
   
   ;WaitTimer timer
   
End Function



Function PlayerBewegen()

   ExtractAnimSeq player,2,14
   
   If KeyDown(17) Then
      MoveEntity player,0,0,1 : pz=pz+1
      Animate player,1,.2,seq,1
   EndIf
   
   If KeyDown(31)  Then
      MoveEntity player,0,0,-1 : pz=pz-1
      Animate player,1,-0.2,seq,1
   EndIf
   
   If KeyDown(57) Then sprung=1 Sprung()
   
   ;If Not ( KeyDown(17) Or KeyDown(31) Or KeyHit(57) ) Then Animate player,0
   
   If KeyHit(47) Then plySpeed=20
   
   
   If KeyDown(30)  Then TurnEntity player,0,1,0
   If KeyDown(32)  Then TurnEntity player,0,-1,0
   If KeyDown(16)  Then MoveEntity player,-1,0,0
   If KeyDown(18)  Then MoveEntity player,1,0,0
   If KeyDown(200) Then TurnEntity cam,1,0,0
   If KeyDown(208) Then TurnEntity cam,-1,0,0
   
   If MouseZ()=-1 Then MoveEntity cam,0,0,-1
   
   If MouseZ()=1 Then MoveEntity cam,0,0,1
   
End Function




Function Sprung()
   
   ExtractAnimSeq player,28,40
   
   If sprung = 1 Then
   
      Animate player,1,.2,seq,1
   
         jumpcount = jumpcount + 10
         TranslateEntity player, 0, 5, 0
         If jumpcount = 200 Then sprung = 0 : jumpcount = 0

      EndIf
   
End Function




Function Pick()

    CameraProject cam,EntityX(testObjekt),EntityY(testObjekt),EntityZ(testObjekt)

   If entity#=0
      EntityColor testObjekt,255,255,255
   EndIf

   pick = CameraPick (cam, MouseX(), MouseY())
   If MouseDown(1) And pick<>entity#
      If testObjekt Then EntityColor testObjekt,220,255,0 ShowClicked()
      entity#=pick
   EndIf
   
End Function




Function ShowClicked()

   tx=ProjectedX()
   ty=ProjectedY()-120

   txt$ = "Der Würfel namens Ralf"
   size = StringWidth(txt$)
   
   Text tx,ty,txt$,1,1
   
   DrawImage bgDing,tx-size/2-20,ty                       ;ProjectedX()-60,ProjectedY()-120
   DrawImage bgDing,tx+size/2+10,ty                       ;ProjectedX()+60,ProjectedY()-120   
   
End Function




Function Texte()
   
   Color 0,0,150
   Text 1,1, "Willkommen in Iberion!"
   Text 1,15,"Server gestartet."
   If message=1 Then
      Text 1,30,name$+" ist neu dabei."
   EndIf
   
End Function


Function INT_IP(IP$)
  a1=Int(Left(IP$,Instr(IP$,".")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
  a2=Int(Left(IP$,Instr(IP$,".")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
  a3=Int(Left(IP$,Instr(IP$,".")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
  a4=Int(IP$)
   
  Return (a1 Shl 24) + (a2 Shl 16) + (a3 Shl 8 ) +a4
End Function

Function newinput$(x1,y1,x2,y2,frage$,maxl)
   a = GetKey()
   If a => 32 And a <= 255 And Len(antwort$) <= maxl-1 Then antwort$ = antwort$ + Chr$(a)
   If KeyHit(28) Then Return antwort$
   If KeyDown(14) Or KeyDown(203) And Len(antwort$) > 0 And MilliSecs()-backtime > 125 Then
      antwort$ = Left(antwort$,(Len(antwort$)-1))
      backtime = MilliSecs()
   End If

   Color 25,100,200
   Rect x1, y1,x2-x1, y2-y1,1
   Color 10,50,150
   Rect x1, y1,x2-x1, y2-y1,0
   textlange = StringWidth(antwort$) ;Blinkener Cursor
   texthohe = StringHeight(antwort$)
   fragelange = StringWidth(frage$)
   Color 0,50,ccolor
   Rect x1+28+(Len(antwort$)*8),y1+4,10,texthohe-1,1
   ccolor = ccolor + 5
   If ccolor = 255 Then ccolor = 100

   Color 255,255,255
   Text x1+3,y1+3, frage$ + " " + antwort$
End Function


Client:
Code: [AUSKLAPPEN]
AppTitle "4Story-Klon-Client"

Type client
   Field name$
End Type

;Type-Konstanten
Const PLYTYPE=2
Const TERTYPE=1

server_ip$ = "127.0.0.1"
server_port = 7142
client_name$ = "Gast" + Str$(Rand(0,1000))

Global udp = CreateUDPStream()
If Not udp Then
  Print "Der UDP Stream konnte nicht erstellt werden."
  End
EndIf

;Variablen
Global level=1
Global sprung=0,jumpcount=0jumpPossible=0
entity# = 0

Global gx=2,gy=0,gz=0

Global tx=1,ty=1

Global px=100,py=0,pz=0

Global seq=1

Global plySpeed=1

Global w=KeyDown(17)

Global fg=0.2

;--------------------------------------------------------------------------------------------|

timer=CreateTimer(50)

Graphics3D ax,ay,fx,2

;--------------------------------------------------------------------------------------------|

Global player     = LoadAnimMesh("mesh\dwarf1.b3d")
Global clientp    = CopyEntity(player)

Global font = LoadFont("Lucida Sans Unicode",15,1)

Global cam        = CreateCamera(player)
Global licht      = CreateLight()

Global gras       = LoadTexture("gfx\gras.jpg")

Global land       = CreatePlane()
Global testObjekt = LoadMesh("mesh\cube.3ds")

Global bgDing     = LoadImage("gfx\bgGegenstände.png")
Global maus       = LoadImage("gfx\mauszeiger.png")

Global baum       = LoadMesh("mesh\baum1.3ds")

;--------------------------------------------------------------------------------------------|
PositionEntity cam,0,60,-60
PositionEntity land,0,-5,0
PositionEntity player,px,py,pz
PositionEntity baum,0,0,100

CameraClsColor cam,150,170,255
CameraRange cam,1,999999999

EntityTexture land,gras

ScaleTexture gras,30,30

MaskImage bgDing,255,255,255
MaskImage maus,255,255,255

EntityType player,PLYTYPE
EntityType baum,PLYTYPE
EntityType land,TERTYPE

MoveMouse 840,525

EntityPickMode testObjekt,2,1 

SetFont font

;--------------------------------------------------------------------------------------------|

WriteByte(udp,1)
WriteString(udp,client_name$)
SendUDPMsg udp,INT_IP(server_ip$),server_port

;--------------------------------------------------------------------------------------------|

Collisions PLYTYPE,TERTYPE,2,2
Repeat
   WriteByte(udp,2)
   WriteShort(udp,px)
   WriteShort(udp,py)
   WriteShort(udp,pz)
   SendUDPMsg udp,INT_IP(server_ip$),server_port
   
   WaitTimer timer
   
   Schwerkraft()
   PlayerBewegen()
   ;UDP()
   
   UpdateWorld()
   RenderWorld()
   
   If KeyHit(28) Then inp$ = newinput$(0,1000,300,200,">>", 100)
      
   DrawImage maus,MouseX(),MouseY()
   
   Pick()
   Texte()
   
   Flip 0
   Cls
   
Until KeyHit(1)
   WriteByte(udp,3)
   SendUDPMsg udp,INT_IP(server_ip$),server_port
   CloseUDPStream(udp)
End

FreeEntity player

;--------------------------------------------------------------------------------------------|

Function Schwerkraft()
   
   TranslateEntity player,0,-2,0
   
   TranslateEntity baum,0,-2,0
   
End Function


Function UDP()
   
   If RecvUDPMsg(udp) <> 0
      
      message = ReadByte(udp)
      
      Select message
      
         Case 1
            Text 100,100,"Neuer Server!"
            
         Case 2
            px = ReadInt(udp)
            py = ReadInt(udp)
            pz = ReadInt(udp)
            PositionEntity clientp,px,py,pz
            
         Case 3
            FreeEntity clientp
      
      End Select
      
      
   EndIf
   
End Function



Function PlayerBewegen()
   
   ExtractAnimSeq player,2,14
   
   If KeyDown(17) Then
      MoveEntity player,0,0,1 : pz=pz+1
      Animate player,1,.2,seq,1
   EndIf
   
   If KeyDown(31)  Then
      MoveEntity player,0,0,-1 : pz=pz-1
      Animate player,1,-0.2,seq,1
   EndIf
   
   If KeyDown(57) Then sprung=1 Sprung()
   
   If KeyHit(47) Then plySpeed=20
   
   If KeyDown(30)  Then TurnEntity player,0,1,0
   If KeyDown(32)  Then TurnEntity player,0,-1,0
   If KeyDown(16)  Then MoveEntity player,-1,0,0 : px=px-1
   If KeyDown(18)  Then MoveEntity player,1,0,0 : px=px+1
   If KeyDown(200) Then TurnEntity cam,1,0,0
   If KeyDown(208) Then TurnEntity cam,-1,0,0
   
   If MouseZ()=-1 Then MoveEntity cam,0,0,-1
   
   If MouseZ()=1 Then MoveEntity cam,0,0,1
   
End Function




Function Sprung()
   
   ExtractAnimSeq player,28,40
   
   If sprung = 1 Then
   
      Animate player,1,.2,seq,1
   
         jumpcount = jumpcount + 10
         TranslateEntity player, 0, 5, 0
         If jumpcount = 200 Then sprung = 0 : jumpcount = 0

      EndIf
   
End Function




Function Pick()

    CameraProject cam,EntityX(testObjekt),EntityY(testObjekt),EntityZ(testObjekt)

   If entity#=0
      EntityColor testObjekt,255,255,255
   EndIf

   pick = CameraPick (cam, MouseX(), MouseY())
   If MouseDown(1) And pick<>entity#
      If testObjekt Then EntityColor testObjekt,220,255,0 ShowClicked()
      entity#=pick
   EndIf
   
End Function




Function ShowClicked()

   tx=ProjectedX()
   ty=ProjectedY()-120

   txt$ = "Der Würfel namens Ralf"
   size = StringWidth(txt$)
   
   Text tx,ty,txt$,1,1
   
   DrawImage bgDing,tx-size/2-20,ty                       ;ProjectedX()-60,ProjectedY()-120
   DrawImage bgDing,tx+size/2+10,ty                       ;ProjectedX()+60,ProjectedY()-120   
   
End Function




Function Texte()
   
   Color 0,0,150
   Text 1,1, "Willkommen in Iberion!"
   Text 1,15,"Client gestartet."
   
End Function





Function INT_IP(IP$)

   a1=Int(Left(IP$,Instr(IP$,".")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
   a2=Int(Left(IP$,Instr(IP$,".")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
   a3=Int(Left(IP$,Instr(IP$,".")-1)):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
   a4=Int(IP$)
   
   Return (a1 Shl 24) + (a2 Shl 16) + (a3 Shl 8 ) +a4
   
End Function





Function newinput$(x1,y1,x2,y2,frage$,maxl)

   a = GetKey()
   If a => 32 And a <= 255 And Len(antwort$) <= maxl-1 Then antwort$ = antwort$ + Chr$(a)
    If KeyHit(28) Then Return antwort$
    If KeyDown(14) Or KeyDown(203) And Len(antwort$) > 0 And MilliSecs()-backtime > 125 Then
       antwort$ = Left(antwort$,(Len(antwort$)-1))
       backtime = MilliSecs()
    End If

    Color 25,100,200
    Rect x1, y1,x2-x1, y2-y1,1
    Color 10,50,150
    Rect x1, y1,x2-x1, y2-y1,0
    textlange = StringWidth(antwort$) ;Blinkener Cursor
    texthohe = StringHeight(antwort$)
    fragelange = StringWidth(frage$)
    Color 0,50,ccolor
    Rect x1+28+(Len(antwort$)*8),y1+4,10,texthohe-1,1
    ccolor = ccolor + 5
    If ccolor = 255 Then ccolor = 100

    Color 255,255,255
    Text x1+3,y1+3, frage$ + " " + antwort$

End Function


Der Code ist zum lokalen Testen geeignet.

Mfg,
N0X

Edit:
Soviel hab ich schon rausgefunden, es liegt an dem "ExtractAnimSeq" in der PlayerBewegen()-Funktion ...
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5%

The_Nici

BeitragMi, Jan 07, 2009 12:15
Antworten mit Zitat
Benutzer-Profile anzeigen
Man führt ExtracAnimSeq auch nicht in der Mainloop aus. Wink
Achja, noch viel Glück mit deinem MMORPG!
MfG
The_Nici

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group