Page 9 of 9 FirstFirst ... 789
Results 81 to 87 of 87

Thread: Space Shooter Game Editor

  1. #81
    @SilverWarrior ,

    I did it, and to my dissapointment, it's worse then it was before on the other computer :
    Code:
    procedure TMain.ATimer1Process(Sender: TObject);
    begin
      if StartDemo = true then
        ScrollMap;
    end;
    Code:
    procedure TMain.ATimer1Timer(Sender: TObject);
    begin
      // draw stuff , background is black
      ADevice1.Render(clBlack, True);
      // do stuff that require steady speed here
      ATimer1.Process;
      // flip backbuffers , make it visible
      ADevice1.Flip();
    end;
    ATimer1.MaxFPS:=120;
    ATimer1.Speed:=60;

    Now even on my computer I get a hickup once... on the other computer constant hickups.

    I've just tried to simply down my Scrollmap procedure to this :
    Code:
    procedure TMain.ScrollMap;
    var x,y,z : integer;
        i : integer;
        a,b,c : integer;
    begin
      if RanOnce = false then
        begin
          if MapOffset in [0..15] then
            begin
              MapOffset:=Map.MapLength-15;
            end;
          LineHeight:=0;
          GameDrawGrid;
          RanOnce:=true;
        end;
     
      if MapOffset > 0 then
        begin
          LineHeight:=LineHeight+ScrollSpeed;
    // Background : Layers [0..3], Tiles [0..19], Lines [0..15] of TBackGround;
    // Map.Record : Layers [0..3], Lines [0..Map.Length-1] , Tiles [0..19]
          // move available sprites down
          for y:=0 to 15 do
            for z:=0 to 3 do
              for x:=0 to 19 do
                begin
                  if BackGround[z,x,y] <> nil then
                    begin
                      BackGround[z,x,y].Y:=BackGround[z,x,y].Y+ScrollSpeed;
                      if BackGround[z,x,y].Y = 480 then
                        begin
                          BackGround[z,x,y].Y:=-32;
                        end;
                    end;
                end; // X loop
        end; // if Offset
    end;
    My OnRender has only this
    Code:
    procedure TMain.ADevice1Render(Sender: TObject);
    begin
      FPSEdit.Value:=ATimer1.FrameRate;
      SpriteEdit.Value:=SpriteEngine.Count;
      MemEdit.Text:=FormatFloat(',.# KB', CurrentMemoryUsage / 1024) ;
    
      if StartDemo = true then
        begin
        //  ScrollMap;
         // AnimationPositionCalculator;
        end
      else
        begin
          if EditorAnimationCounter = 1000 then EditorAnimationCounter:=0;
          inc(EditorAnimationCounter,1);
          EditorXPos:=floor(myMouse.Position.X / (Panel1.Width / 20 ));
          EditorYPos:=floor(myMouse.Position.Y / (Panel1.Height / 15 ));
          with EditorCursor do
            begin
              X:=EditorXPos*32;
              Y:=EditorYPos*32;
            end;
        end;
    //  SpriteEngine.Collision;
      SpriteEngine.Dead;
      SpriteEngine.Move(1);
      SpriteEngine.Draw;
    end;
    ATimer1.MaxFPS:=1000;
    ATimer1.Speed:=60;

    And while the FPS is 1000 + on the other machine ( Windows 7 32bit, E3xxx, 3GB ram, 9800GTX+ ) , it does have hickups... and now I'm just scrolling existing sprites, I'm not updating, re-drawing, i'm just setting the position back to -32 . What am I possibly doing wrong here ? Is this not the way to go trough the sprites ? Is the Array causing the problem , the array I'm using to manipulate the sprites?

    UPDATE : no-no-no-no
    I've modified the code a bit further to see if the array can be the culprit :
    Code:
          for y:=0 to 15 do
            for z:=0 to 3 do
              for x:=0 to 19 do
                begin
                  if Map.Layer[z].Lines[y+MapOffset-1,x].ImageIndex <> 0 then
                    begin
                      BackGround[z,x,y].Y:=BackGround[z,x,y].Y+ScrollSpeed;
                      if BackGround[z,x,y].Y = 480 then
                        begin
    
                          BackGround[z,x,y].Y:=-32;
                        end;
                    end;
                end; // X loop
    This array is much larger then BackGround array. 18000 vs 960 things to check with IF . Guess the E7500 is fast enough not to make it noticable to go trough 960 ... but the E3xxx (Celeron....) is not.
    And now I have the same hickups on this faster computer, guess it takes to long to go trough the arra with if's like this, but how can I speed it up ? Can you give any tips ? ( and keeping it using array's , for now...)

    UPDATE2:

    I reran the code just to see it again, while I was googling for tips, changed nothing, and it runs smoothly on my machine again... with this
    Code:
          for y:=0 to 15 do
            for z:=0 to 3 do
              for x:=0 to 19 do
                begin
                  if Map.Layer[z].Lines[y+MapOffset-1,x].ImageIndex <> 0 then
                    begin
                      BackGround[z,x,y].Y:=BackGround[z,x,y].Y+ScrollSpeed;
                      if BackGround[z,x,y].Y = 480 then
                        begin
    
                          BackGround[z,x,y].Y:=-32;
                        end;
                    end;
                end; // X loop

    I'm getting pretty confused here, now it runs fine. Am I still doing something wrong here ? Or the Timer itself is playing with me...

    UPDATE 3 :
    re-wrote parts of the code to use Timer1.Process() . I've sepereated the Movement from the Line Creation . Sometimes it goes smooth on my computer, sometimes it's choppy on this one as well, as for the other "slower" machine it's choppy always even though I have 120FPS constantly...
    I've attached the code, I think I'm having some serious problem understanding something here. Can you please take a quick look at the Timer.Process(), Device.Render() , DemoScrollMapLines(), DemoDrawMapLines() ?
    Attached full source code, without exe.

    I've looked again at the Diablo like example that comes with sprite engine, but there is nothin in Timer.Process() , guess because it's done using OnMove for all Objects, and OnMove is probably tied to Timer1.Speed ?

    ps.: sorry a bit confused here, probably wrote to much

    Greetings
    Robert
    Attached Files Attached Files
    Last edited by robert83; 24-02-2013 at 01:44 PM.

  2. #82
    Quote Originally Posted by robert83 View Post
    I did it, and to my dissapointment, it's worse then it was before on the other computer :
    Code:
    procedure TMain.ATimer1Timer(Sender: TObject);
    begin
      // draw stuff , background is black
      ADevice1.Render(clBlack, True);
      // do stuff that require steady speed here
      ATimer1.Process;
      // flip backbuffers , make it visible
      ADevice1.Flip();
    end;
    You should always call ATime1.Process last. So code would look lie this.
    Code:
    procedure TMain.ATimer1Timer(Sender: TObject);
    begin
      // draw stuff , background is black
      ADevice1.Render(clBlack, True);
      // flip backbuffers , make it visible
      ADevice1.Flip();
      // do stuff that require steady speed here
      ATimer1.Process;  
    end;

    I also owe you a GREAT apology. Why? Becouse for the past few weeks I have been unintentionally misleading you to wrong direction.
    When I first started to help you I asumed that main problem you have is the fact that Sprite Engine you use doesn't have optimization code which would render only visible sprites.
    I must admit that my asumption was compleetly wrong (should have studied Sprite Engines code in the first place). Sprite Engine does have necessary code to prevent nonvisible sprites of not being rendered.
    The reason why you had so poor performance in the start was becouse Form which you used for rendering target was so big that optimization code hasn't even kicked in as it asumed that all that should be rendered even when most of that Form wasn't even visible on the screen. It was as if you would be rendering to realy large screen.

    What does this means?
    You CAN create sprites for the whole map.
    Instead of moving each sprite you SHOULD only cahnge world position.

    So you see most of my suggestions to you were wrong. I haven't realized this until yesteray when I studied Sprite Engines code compleetly.
    I hope you can forgive me for this.

  3. #83
    No problem , it was fun coding that stuff , and I still think it might come handy later. And after testing it out the way you told me to, I think I'll need it still...

    I've looked into the AsphyreSprite code as well, you mean this part takes care of what to draw and what not to draw?
    Code:
    procedure TSprite.Draw;
    var
         ImgName: string;
    begin
         if (FX > FEngine.WorldX + FVisibleArea.Left)  and
            (FY > FEngine.WorldY + FVisibleArea.Top)   and
            (FX < FEngine.WorldX + FVisibleArea.Right) and
            (FY < FEngine.WorldY + FVisibleArea.Bottom)then
         begin
              if not FVisible then Exit;
              case ImageType of
                   itSingleImage: ImgName := FImageName + IntToStr(FImageIndex);
                   itSpriteSheet: ImgName := FImageName;
              end;
    Anyway I created a few test maps to see if it does kick in , a map that is 1500 lines long, and has all layers filled with sprites , that is 120.000 sprites , and my framerate dropped to 75, then i've created a map that is 5000 Lines long
    and has a total of 400.000 Sprites , and I get 26 FPS , I know these are scenarios which I will probably not reach on the long run. Even if the VisibleArea does work , cause I think it does I did another Editor to test it :
    Code:
    procedure TMain.EditorDrawGrid;
    var x,y,z : integer;
    begin
      // 15 lines
      for y := 0 to Map.MapLength-1 do
        // 4 layers
        for z := 0 to 3 do
          // 20 columns
          for x := 0 to 19 do
            begin
              // create/modify sprite with image
              if map.Layer[z].Lines[y,x].ImageIndex <> 0 then
                begin
                  // if sprite was not created I create it
                  if BackGround[z,x,y] = nil then
                    begin
                      BackGround[z,x,y] := TBackGround.Create(SpriteEngine);
                      BackGround[z,x,y].ImageName:= Images.Item[map.Layer[z].Lines[y,x].ImageIndex].Name;
                      BackGround[z,x,y].X:=x*32;
                      BackGround[z,x,y].Y:=y*32;
                      BackGround[z,x,y].VisibleArea:= rect(-32,-32,640,480);
                      BackGround[z,x,y].Z:=z;
                    end
                  // otherwise I only set new image
                  else
                    begin
                      BackGround[z,x,y].ImageName:= Images.Item[map.Layer[z].Lines[y,x].ImageIndex].Name;
                    end;
                  // animation properties
                  if BackGround[z,x,y].PatternCount = 1 then
                    begin
                      BackGround[z,x,y].DoAnimate:=false;
                    end
                  else
                    begin
                      BackGround[z,x,y].AnimStart:=0;
                      BackGround[z,x,y].AnimCount:=map.Layer[z].Lines[y,x].AnimCount;
                      BackGround[z,x,y].AnimSpeed:=map.Layer[z].Lines[y,x].AnimSpeed;
                      BackGround[z,x,y].AnimPos:=(EditorAnimationCounter mod BackGround[z,x,y].AnimCount)+map.Layer[z].Lines[y,x].AnimStart;
                      BackGround[z,x,y].DoAnimate:=true;
                      BackGround[z,x,y].AnimLooped:=true;
                    end;
                end
              // if sprite is empty, I kill it , and set the array entry to nil
              else
                begin
                  if BackGround[z,x,y] <> nil then
                    begin
                      BackGround[z,x,y].Dead;
                      BackGround[z,x,y]:=Nil;
                    end;
                end;
            end;
    end;
    BackGround[z,x,y].VisibleArea:= rect(-32,-32,640,480); if I make this smaller , like 380, the Visible area is smaller, but the speed stays the same not to mention the memory usage, it seems even though it's NOT drawing, the part that does the calculations and who knows what are still taking a considerable tax on the machine.


    Anyway I've created a new version, using this simplified method, where I create all them tiles I need for the Entire Map, then I do the scrolling by moving to the WorldPosition:=(32*Map.MapLength)-480; (last screen) .
    Then Using SpriteEngine.WorldY:=SpriteEngine.WorldY-ScrollSpeed (or be it 4) , I move the map .... and, I don't know I just dont know, it still has hickups on my computer now, the strangest thing is, sometimes when i start it it goes pretty good, then all of a sudden a hickup then goes good for a while... sometimes I start it and it's downright choppy (even tough I have a modest 300FPS now...using all sprites) .

    I'm attaching the source code and a few images to show you what I mean. Can you take a look at the code, what am I doing wrong ?
    Also I've commented out all the inttostr conversions and formatfloat during the rendering onprocessing to make sure that the problem is not cased by them...

    UPDATE : the button DON'T PUSH ME , can be used to fill a map to the max with sprites.... (just carefull if map is very long, it takes a lot of time to create all them sprites...) 1500-5000 enough... for maplength

    UPDATE2 : found this via google.com http://dev.ixchels.net/forum/archive...php/t-139.html , they talk about jerky movement, and it's explained why it's jerky in non fullscreen mode,...guess I'll try to redo in full screen the scroll only, maybe I've missed something....

    UPDATE3 : did a quick test going fullscreen, removed all code again, only left the one necessary for loading level and moving, it still feels jerky if timer speed is 60 (max fps I get on laptop is around 100fps) , now If I move the movement code into device render is a lot smoother, but get that rollercoaster speed effect) , if I increase the speed to 100 on timer , then the movement is pretty fast and seems constant, though I'm not 100% sure it still files like it's doing the hickups but at a much quicker and constant rate. (or I'm seeing things, need someone to check this demo out) Attached is a fullscreen.zip , with executable, it goes fullscreen, map needs to be placed on c drive map is included inside zip, with ESC you can quit anytime, it just loops trough this one map... (I'm not sure if I'm doing this right, I'm right now moving the world down by 4 pixels ... I don't know why I keep thinking this but I think I should move the world map down by 1 pixel only at a much higher interval for worldmap movement only, is this not how it's done properly ?)

    Greetings
    Robert
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by robert83; 26-02-2013 at 07:58 AM.

  4. #84
    I could not attach to previous post for some reason , so here it is .

    I've edited a bit more , and added BackGround.OnMove
    Code:
    procedure TBackGround.Move(const MoveCount: Single);
    begin
      inherited;
      if StartDemo = true then
        begin
          WorldY:=WorldY+4;
        end;
    end;
    Using this it scrolls trough one screen of my map, but wont create new lines, wonder why? I tried playing with VisibleArea on a per sprite bases when creating the map but could not get it working properly
    Code:
    BackGround[z,x,y].VisibleArea := rect(-32,(y*32-32),640,(y*32)+480));
    The idea is that I'd create each sprite with a different Visible area... but for some reason, the above code does not do what I expected it to do...

    so for now I'm doing onmove using

    Y:=Y+4;

    seems smoth now on my laptop in smoothscreen, maybe I must do movement in onMove ?

    Greetings
    Robert
    Attached Files Attached Files
    Last edited by robert83; 26-02-2013 at 09:11 AM.

  5. #85
    (Sorry for some reason I cannot get the file upload to show when editing my post)

    Anyway I think I did it...

    Code:
    procedure TBackGround.Move(const MoveCount: Single);
    begin
      inherited;
      if StartDemo = true then
        begin
          if SpriteEngine.WorldY = 0 then
            SpriteEngine.WorldY:=(Map.MapLength*32)-480;
          SpriteEngine.WorldY:=SpriteEngine.WorldY-0.0010;
        end;
    end;
    Note I had to move SpriteEngine from Private to Public...

    The strangest thing is , if it's running non fullscreen I get 27FPS probably the visible area not kicking in, but if I run fullscreen it runs at full 60 fps smooth , on this laptop with integrated gpu...I think that is a big word... I set the visible area for each sprite, I did set it on purpose to be less then screen size to see what happens and if it works.

    So this means I have to make the Editor itself fullscreen to ? (or leave editor as is, since it's easier to work with components available, and do the game in fullscreen later....)

    Update : if Form size is same as asphyre device size, it works in non full screen mode as well at same speed.
    Question : why do I have to use such a low value to move the WorldY now ? 0.0010 , the Speed for Timer is 15 only...

    Greetings
    Robert
    Attached Files Attached Files
    Last edited by robert83; 26-02-2013 at 09:39 AM.

  6. #86
    For the past two hours I was trying to track this problem but unfortunately I had no luck in going this. I even tried mesuring execution time for Rendering procedure where time needed for completing it was jumping between a few miliseconds to 15 miliseconds. But in worse case it jumped to 247 miliseconds and this happened when I wasn't even moving the map. Why did this happend I have no real answer. I can only suspect that some program has been doing something on the same core that it was asigned to the editor.
    I even tried changing process afinity so that it alwasy ran on one of the cores and increasing the overal prioity but there were still theese hickups.

    Gues I'll need to go and try profiling execution time for each even so small method, probably even those in Asphyre graphic engine itself to pinpoint the problem. I will notify you of my results when I have some.
    But for now based on what is written on the link you provided theese hickups should be less comon when you run your application in FullScreen mode. But this means no VCL components so it might be only usable for game and not editor.

  7. #87
    Quote Originally Posted by robert83 View Post
    The strangest thing is , if it's running non fullscreen I get 27FPS probably the visible area not kicking in, but if I run fullscreen it runs at full 60 fps smooth , on this laptop with integrated gpu...I think that is a big word... I set the visible area for each sprite, I did set it on purpose to be less then screen size to see what happens and if it works.
    Not so strange. Most games run better in FullScreen.

    Quote Originally Posted by robert83 View Post
    So this means I have to make the Editor itself fullscreen to ? (or leave editor as is, since it's easier to work with components available, and do the game in fullscreen later....)
    I suggest that you leave editor as it is since you actually don't realy need smoth movment in editor. But when you would be designing your game you would deffinitly do it in FullScreen mode.
    But if you are prepared to do lot of work you could made Editor to work in FullScreen mode but for this you would need to recreate all VCL components in it and this is nowhere an easy job. I know since I'm trying to do something like this myself. I'm developing a library which would alow me to create VLC-like components which would be rendered by AsphyreSphinx graphic engine. And since 2D portion of AsphyreSphinx graphics engine isn't so different than Asphyre Extreme engine I could probably port my library to it also.

    Quote Originally Posted by robert83 View Post
    Question : why do I have to use such a low value to move the WorldY now ? 0.0010 , the Speed for Timer is 15 only...
    Speed of 15 in timer means that OnProcess will try to execute every 15 miliseconds which means aprox 66 times per second. You need to know that values in AsphyreTimer are just desired delays in miliseconds. And if Rendering takes to much time OnProcess would be executed more than once to catch up.

Page 9 of 9 FirstFirst ... 789

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •