Results 1 to 10 of 87

Thread: Space Shooter Game Editor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Quote Originally Posted by SilverWarior View Post
    Main reasony why I use classes rather than records are class properties. Why? Class property can actually automaticly return you a value which is calculation of several class internal properties
    I Use them a lot too, although I've started to favour public setter procedures over writable properties simply to make my classes easier to read, no need to check properties in a class to see what they do. I've found it's a great time-saver as it removes any element of ambiguity that arises from writable properties, which is good when you're working on a code-base so big that you can't possibly remember everything you did and why
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  2. #2
    I did it


    Scrolling works now, and I've tested it in multiple scenarios , and I understand why it works now , so simple (now...)

    1. I move every available sprite down in the BackGround array
    2. Once I reach 32 with my LineHeight counter (that means I went trough 1 line of Map data) , i do the following :
    a) locate empty line inside BackGround array
    b) read next line of MapData and put it inside of this empty line inside the BackGround array

    Code:
    procedure TMain.ScrollMap;
    var x,y,z : integer;
        i : integer;
        a,b,c : integer;
    begin
      if RanOnce = false then
        begin
          for z:=0 to 3 do
            SetLength(AnimTable.Layer[z].TileAnim, Map.MapLength);
          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 z:=0 to 3 do
            for y:=0 to 15 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].Dead;
                          BackGround[z,x,y]:=nil;
                        end;
                    end;
                end; // X loop
          // screen scrolled down one line
          if LineHeight = 32 then
            begin
              Dec(MapOffset,1);
              OffsetEdit.Value:=MapOffset;
              LineHeight:=0;
              // locate an empty line in the BackGround array
              if MapOffset > 0 then
                begin
                  a:=0;
                  y:=0;
                  c:=0;
                  repeat
                    for z:=0 to 3 do
                      for x:=0 to 19 do
                        if BackGround[z,x,y] <> nil then
                          a:=-1;
                    if a = -1 then
                      begin
                        inc(y);
                        a:=0;
                      end
                    else
                      begin
                        b:=y;
                        c:=-1;
                      end;
                  until c = -1;
                  // get next line of tiles and put into free line in background array
                  for z:=0 to 3 do
                  for i:=0 to 19 do
                    if Map.Layer[z].Lines[MapOffset-1,i].ImageIndex <> 0 then
                      begin
                        BackGround[z,i,b] := TBackGround.Create(SpriteEngine);
                        BackGround[z,i,b].ImageName:= Images.Item[map.Layer[z].Lines[MapOffset-1,i].ImageIndex].Name;
                        BackGround[z,i,b].X:=i*32;
                        BackGround[z,i,b].Y:=-32;
                        BackGround[z,i,b].Z:=z;
                        // animation properties
                        if BackGround[z,i,b].PatternCount = 1 then
                          begin
                            BackGround[z,i,b].DoAnimate:=false;
                          end
                        else
                          begin
                            BackGround[z,i,b].AnimStart:=0;
                            BackGround[z,i,b].AnimCount:=map.Layer[z].Lines[MapOffset-1,i].AnimCount;
                            BackGround[z,i,b].AnimSpeed:=map.Layer[z].Lines[MapOffset-1,i].AnimSpeed;
                            BackGround[z,i,b].AnimPos:=AnimTable.Layer[z].TileAnim[MapOffset-1,i];
                            BackGround[z,i,b].DoAnimate:=true;
                            BackGround[z,i,b].AnimLooped:=true;
                          end;
                      end;
                end;
            end;
        end // if Offset
      else
        begin
          // Destroy sprites
          for x:=0 to SpriteEngine.Count-1 do
            SpriteEngine.Items[x].Dead;
          // Clear dynamic array
          for z:=0 to 3 do
            for y:=0 to 15 do
              for x:= 0 to 19 do
                BackGround[z,x,y]:=nil;
          // Start again
          RanOnce:=false;
        end;
    
    end;

    SilverWarrior :

    -I'll get the art in my next post, I'll reasemble the tree, cause I've cut it out into parts from a larger image
    -I'll also give you the shore tiles which are transparent

    If you can then please move this thread to myprojects as you've suggested and name it Space Shooter Game Editor . (think by the end it will be more then just a simple Level Editor)

    Next in plan :
    a) speed set by map position
    b) add snow (perhaps rain, but rain makes me depressed so i'll probably wont do that),
    when game reaches a part of map for example I have a special tile that triggers snow , till another special tile stops it, I planed to make it snow like this :
    -- snow would start faling at line 0 and be destroyed at line 2, next instance of snow would start falling at line 1 and be destroyed at line 3, etc (2,4,3,5,4,6...)
    hopefully with this I would achive a sense of depth, that the snow is actually falling down. This way I could do this without Collision detection, which would probably slow it down pretty much.





    ----
    As for the Object things, there was a reason I've used arrays, I must confess that I'll need to go back to reading and practicing object oriented programing, while I do understand the basics how it works , I did not write code at all in an object oriented way (excluding the Delphi 7 graphichs interface part , but that is automatic, so it doesn't count)
    I've started reading Mastering Delphi7 , that is why I updated my variable, procedure etc...names, as well as why I started commenting in a different way.
    ----

    Greetings
    Robert
    Attached Files Attached Files
    Last edited by robert83; 20-02-2013 at 10:20 AM.

  3. #3
    Quote Originally Posted by robert83 View Post
    SilverWarrior :

    -I'll get the art in my next post, I'll reasemble the tree, cause I've cut it out into parts from a larger image
    -I'll also give you the shore tiles which are transparent
    About the tree do also leave the pices that you have now.
    What I have in plan is only to show tree preview (replacing default selection sprite and snaping its position to grid) when you are placing it and then programaticly place tree pices into proper tiles.

    Quote Originally Posted by robert83 View Post
    If you can then please move this thread to myprojects as you've suggested and name it Space Shooter Game Editor . (think by the end it will be more then just a simple Level Editor)
    Done already

    Quote Originally Posted by robert83 View Post
    Next in plan :
    a) speed set by map position
    b) add snow (perhaps rain, but rain makes me depressed so i'll probably wont do that),
    when game reaches a part of map for example I have a special tile that triggers snow , till another special tile stops it, I planed to make it snow like this :
    -- snow would start faling at line 0 and be destroyed at line 2, next instance of snow would start falling at line 1 and be destroyed at line 3, etc (2,4,3,5,4,6...)
    hopefully with this I would achive a sense of depth, that the snow is actually falling down. This way I could do this without Collision detection, which would probably slow it down pretty much.
    Why not just use a good snow animation tiles which you then move when moving the map.

    Quote Originally Posted by robert83 View Post
    As for the Object things, there was a reason I've used arrays, I must confess that I'll need to go back to reading and practicing object oriented programing, while I do understand the basics how it works , I did not write code at all in an object oriented way (excluding the Delphi 7 graphichs interface part , but that is automatic, so it doesn't count)
    I've started reading Mastering Delphi7 , that is why I updated my variable, procedure etc...names, as well as why I started commenting in a different way.
    Since you are reading Mastering Delphi 7 do pay close atention to the chapter about making your own components as it covers some concepts that you will need for understanding my code.
    But since I have used some more advanced concepts that aren't presented there (data sharing between classes) I'm writing my own tutorial about that.

    Also if all goes wel I will ask Primož Gabrijelčič for opinion wheter my aproach is thread safe or not (I'm atending a Multithreading course tomorow) so pepole could easily use it in multithreading applications.

  4. #4
    Here it is , see attachment.

    Yep about the snow, you are right, for that I'll need a Animated Snow tile , that is two tiles in Height, and I'll get the same depth effect and it will be much less expensive....


    A few questions about this Editor / code :

    1. I've tried it on multiple machines, and there is a strange thing (I'll try to explain) . The map scrolling even though it says 60FPS always , does not seem smooth... it feels like its going down at a variable speed (which is impossible since I'm moving it by 4 always....) Any ideas why?

    2. Also on one machine Amd Sempron 7100GS , it hangs at random places , the computer itself freezes completely... need to reboot. But on my computer, and another one ( I have a few of them, for them LanParty's) it goes without a problem. In fact yesterday I left it to run all night to see if I have a memory leak, or some other bug somewhere. I guess the 7100GS is overheating and that is why it hangs.... anyway if you could take a moment to look at my Scrollmap
    procedure to see if there is some potentialy dangerous code in there...that under certain circumstances might be problematic.

    Anyway what anoys me the most is problem number 1 , maybe it's because I'm not fullscreen ? Maybe because I'm using Panel as renderingsurface? Is this because VSYNC ? I'm not sure if I've set MaxFPS correclty and SPEED, is there a magic ratio between the two that should be input ?


    3. A side-side question :
    I've got a Celeron 2000, GeForce 2GTS can only push out 30FPS max... , what is the culprit here ? My code ? Asphyre / SpriteEngine combo? I'm asking this because (and now I'm probably comparing apples to oranges) for example Tyrian 2000
    runs smoothly on ever lower specs... am I limited here by the programing language itself ? ( or by my knowledge to write fast code ) - I'm asking this because I always think it's my falt, but not 100% sure, I just want to make this 100% clear, so that I don't expect it to run as fast on older hardware ...when it's simply not possible ... (cause it uses some modern DirectX stuff that is even though my sprites themselves are not complex , it still taxes older generation gpu's more... )
    Greetings
    Robert
    Attached Files Attached Files

  5. #5
    Quote Originally Posted by robert83 View Post
    1. I've tried it on multiple machines, and there is a strange thing (I'll try to explain) . The map scrolling even though it says 60FPS always , does not seem smooth... it feels like its going down at a variable speed (which is impossible since I'm moving it by 4 always....) Any ideas why?
    Why would it be imposible? If for some reason part of your code takes longer than the desired time between screen refreshes it will create slowdowns which might be seen as variating movment speed.

    Quote Originally Posted by robert83 View Post
    2. Also on one machine Amd Sempron 7100GS , it hangs at random places , the computer itself freezes completely... need to reboot. But on my computer, and another one ( I have a few of them, for them LanParty's) it goes without a problem. In fact yesterday I left it to run all night to see if I have a memory leak, or some other bug somewhere. I guess the 7100GS is overheating and that is why it hangs.... anyway if you could take a moment to look at my Scrollmap
    procedure to see if there is some potentialy dangerous code in there...that under certain circumstances might be problematic.
    Can't be sure why this is happening without even seing the code (currently at work). But there is stil posibility that the reason for theese freezes is in the Asphyre graphic engine itself.
    Have you tried running the demos which come with the graphic engine? If they work OK then there is either problem in your code or in code for SpriteEngine. Unfortunately tracking this kind of freezes which make your whole computer to freeze is quite hard.

    Quote Originally Posted by robert83 View Post
    3. A side-side question :
    I've got a Celeron 2000, GeForce 2GTS can only push out 30FPS max... , what is the culprit here ? My code ? Asphyre / SpriteEngine combo? I'm asking this because (and now I'm probably comparing apples to oranges) for example Tyrian 2000
    runs smoothly on ever lower specs... am I limited here by the programing language itself ? ( or by my knowledge to write fast code ) - I'm asking this because I always think it's my falt, but not 100% sure, I just want to make this 100% clear, so that I don't expect it to run as fast on older hardware ...when it's simply not possible ... (cause it uses some modern DirectX stuff that is even though my sprites themselves are not complex , it still taxes older generation gpu's more... )
    Greetings
    Robert
    GeForce 2GTS is rather old graphic card so there is posibility that it doesn't support some feature Asphyre graphic engine usualy uses and this forces the while graphic engine to go into compatibility mode where all the graphical processing is actualy made by CPU (software rendering).
    I'll check the Asphyre engine code to se if there is any way of telling this.


    In the mean time I recomend you download yourself Process Explorer http://technet.microsoft.com/en-us/s.../bb896653.aspx
    Process Explorer is neat litle program which alows you to monitor resource usage on your computer. It even alows you to monitor resource usage per program.
    So by using this program you can quickly see if your program is using lots of CPU time which might result in slowdowns. And if you have Windows Vista or newer you can also monitor GPU usage and even Graphical memory usage. Unfortunately this feature isnt available on Windows XP

    Anywhay I'll take a look at your code when I get home to see if there are any dangerous places.

  6. #6
    I've been playing around with the other demos, though they use differnt Apshyre version so it seems... but I've noticed that when they create the asphyre Timer they set FPS to some extreemely large value like 4000 in the SHOOTER demo, and 15.0 to speed. If I set that speed my editor scrolls by to fast. So I've tried to change around the timer, and noticed for example if I set it to MaxFPS 60, and Speed 1 , the chopiness is even more evident, wonder if it's because I can't figure out howto set them timers properly? (I've disabled vsync completely..)


    I think I've located the possible offiending line, I've changed the code when a new line of sprites is created I create always the selection_image :
    Code:
    BackGround[z,i,b].ImageName:='selection.image';
    and now I think it's smooth , but how to solve this?
    Code:
    BackGround[z,i,b].ImageName:= Images.Item[map.Layer[z].Lines[MapOffset-1,x].ImageIndex].Name;
    I think the problem is cause by the lookup of ImageName ... , I've looked trough the properties, but ImageIndex is something else , if I use ImageIndex := I get an error.... it would probably be fast if I could somehow specify ImageIndex instead of ImageName.

    UPDATE2 :

    Now that I look at it, there might be another problem , my Layer cycle, I think I'm not reading data optimaly first reading layer then line then tile, I think I'll need to modify it so tha I read line, then layer then tile . I think I'm wasting a lot of cycles here. Layer data for Line1, should be next to each other...currently it's Layer0 : line1,2,3,4... then Layer1 : line1,2,3,4... , now when I think about it , when the map array grows I'm jumping here and there inside it to get just one line of data... ( I did not start coding this yet...but I really hope this is my problem, and will magicaly solve my spead issue...if I fix this...)

    Code:
    for z:=0 to 3 do
      for y:=0 to 15 do
        for x:=0 to 19 do
           begin
           //code
           end;
    While I think by moving the Layer cycle inside I will cut my cycles down.

    Code:
    for y:=0 to 15 do
      for z:=0 to 3 do
        for x:=0 to 15 do
           begin
              // code here
           end;
    or maybe

    Code:
    for y:=0 to 15 do
      for x:=0 to 15 do
        for z:=0 to 3 do
          begin
           //code
          end
    I'll change my code the way I save it, and the way I load it...into file.

    Greetings
    Robert
    Last edited by robert83; 21-02-2013 at 05:06 PM.

  7. #7
    Quote Originally Posted by robert83 View Post
    I've been playing around with the other demos, though they use differnt Apshyre version so it seems... but I've noticed that when they create the asphyre Timer they set FPS to some extreemely large value like 4000 in the SHOOTER demo, and 15.0 to speed. If I set that speed my editor scrolls by to fast. So I've tried to change around the timer, and noticed for example if I set it to MaxFPS 60, and Speed 1 , the chopiness is even more evident, wonder if it's because I can't figure out howto set them timers properly? (I've disabled vsync completely..)
    If you take a look at the timer you wil see that it has two values:
    1. MaxPFS: Is used to control how many redraws can there be done in one second. This directly controls how often is OnTimer event being fired. You use OnTimer event to process code needed for rendering.
    2. Speed: Is used to control the speed of your game. This directly controls how often is OnProcess event being fired. You use this event to proces the code which ontrols map movment, units movment, some ingame simulations etc.

    The main problem in your case is that you only use OnTimer event to process everything while this one should only be used to process graphics. So go and move code which controll map movment into OnProcess event and there should be no more variation in map movment speed.


    Quote Originally Posted by robert83 View Post
    but how to solve this?
    Code:
    BackGround[z,i,b].ImageName:= Images.Item[map.Layer[z].Lines[MapOffset-1,x].ImageIndex].Name;
    After some checking I figred out that the problem is in the SpriteEngine itself as it is always searching for proper image from TAsphyreImages using ImageName. And since it is doing this for every redraw of every sprite it is probably afecting the overal performance a bit.

    I'm trying to modify code from SpriteEngine so that it would be posible to set proper image for certain Sprite by any other means than just by providing ImageName. But the way how Sprites are implemented right now is making it dificult to achive this.


    Quote Originally Posted by robert83 View Post
    I think the problem is cause by the lookup of ImageName ... , I've looked trough the properties, but ImageIndex is something else , if I use ImageIndex := I get an error.... it would probably be fast if I could somehow specify ImageIndex instead of ImageName.
    Yes ImageIndex is used for entirely different purpose. What ImageIndex does is that it adds number to the ImageName. So if you have several images named Grass1, Grass2, Grass3, and so on you can acces theese images by providing ImageName and then seting Image index. So ImageName 'Grass' and ImageIndex 5 would be the same as if you would set ImageName to 'Grass5'.
    I suspect that this was some old way for doing animations.
    And the error you get when changing ImageIndex is becouse SpriteEngine is trying to render image whose ImageName can't be found in TAsphyreImages. SpriteEngine has no safety mechanism for handling such situations when desired image isn't found.

    So I'll try to change TSprite class in a way so you would be able to directly pass TAsphyreImage to it. This can be quickly got by using AsphyreImages[ImageIndex].
    Also I'll try to add safety mechanism to prevent those nasty errors when desired image isn't found.
    But as sad before I have to figure out a way of how to implement this while still retaining old functionality so that my changes won't break any programs using this old ackward way.

  8. #8
    Quote Originally Posted by robert83 View Post
    Now that I look at it, there might be another problem , my Layer cycle, I think I'm not reading data optimaly first reading layer then line then tile, I think I'll need to modify it so tha I read line, then layer then tile . I think I'm wasting a lot of cycles here. Layer data for Line1, should be next to each other...currently it's Layer0 : line1,2,3,4... then Layer1 : line1,2,3,4... , now when I think about it , when the map array grows I'm jumping here and there inside it to get just one line of data... ( I did not start coding this yet...but I really hope this is my problem, and will magicaly solve my spead issue...if I fix this...)
    Changing the order of how for loops are nested won't save you any cycles as for loop sizes remains the same. It could only confuse you even more.
    Also if you decide to implement layers with different sizes of their grids you definitly need to process one layer after another and not jum from one layer to other since in that case the lines between different layers won't be on same positions.

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
  •