FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

arc.tilemap
Goto page 1, 2  Next
 
Post new topic   Reply to topic     Forum Index -> ArcLib
View previous topic :: View next topic  
Author Message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Thu Oct 01, 2009 5:04 pm    Post subject: arc.tilemap Reply with quote

Hello everyone. I've begun work on code that I hope will eventually become the arc.tilemap and arc.parallax modules. Before I actually write any implementation code, I want to focus on designing a clean and easy-to-use API.

To reach that end, I need your help. Please respond with features you'd like to have in this module, some example use cases, etc.

I'll start off with my first thoughts.

Code:

import arc.window,
   arc.time,
   arc.input,
   arc.tilemap.tilemap,
   arc.tilemap.parallax;

void main(char[][] args)
{
   arc.window.open("Map Test", 640, 480, false);
   arc.input.open();
   bool loop = true;

   TileMap map = TileMap.loadFromXML("map.xml");
   Parallax parallax = Parallax.loadFromXML("map.xml");

   while(loop)
   {
      arc.time.process();
      arc.window.clear();
      arc.input.process();
      if(arc.input.keyDown(ARC_QUIT) || arc.input.keyDown(ARC_ESCAPE))
         loop = false;

      // Update x and y here
         
      parallax.drawLayer(x, y, 0);
      parallax.drawLayer(x, y, 1);
      parallax.drawLayer(x, y, 2);
      map.drawLayer(x, y, 0);
      map.drawLayer(x, y, 1);
      drawSprites();
      parallax.drawLayer(x, y, 3);
      
      arc.window.swap();
      arc.time.limitFPS(60);
   }
   arc.window.close();
   return 0;
}


Each layer of the map and parallax background will be draw individually. This allows you to change the ordering of backgrounds and map layers, as well as deciding which layer your sprites should be drawn on top of (or have multiple layers of sprites). An example use case here is that the parallax's first three layers are for things like background trees and the sky, while the fourth is a layer of fog.

Problems with this approach:

    The file is parsed twice, once to get the tile info, once to get the parallax info. To avoid this, I could have the Parallax and TileMap both be constructed by a loadFromXML function, but this would force the tilemap module to be dependent on the parallax module. Possible solutions are to introduce a third module that depends on both parallax and tilemap that is able to construct both parts. The parallax and tilemap modules would need functions to create their classes from parts of the already opened file. This could add complexity to the API, but may be worth it.

    You have to remember what order to draw things in, and it could change between maps, thus complicating the drawing code. The third module could have a way to load this info from a file. Something like a drawBelowSprites() then your sprite drawing code, and then drawAboveSprites().

_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Sat Oct 03, 2009 6:55 am    Post subject: Reply with quote

New idea: Organize the modules like this:

arcmap.level.level
arcmap.level.tilemap
arcmap.level.blazeworld
arcmap.level.parallax

This way the tilemap, blaze parser, and parallax code can be independent of each other, but you'd still be able to get an entire level loaded through arcmap.level.level if you wanted to use all three. Each of the tilemap, blazeworld, and parallax would have two parsing functions, one that takes a portion of the file, and one that takes a filename. With this reorganization the output of my map editor would change to a structure that looks more like this, with a level as the toplevel element, and each of the components as sub-elements.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<level>
   <tilemap>
      <layers>
         <layer name="Base" visible="True" z="0">
            <tile img="0" ix="10" iy="2" x="7" y="3"/>
            <tile img="0" ix="10" iy="2" x="16" y="9"/>
         </layer>
      </layers>
      <images>
         <img index="0" src="images/tiles/free_tileset_version_10.png"/>
      </images>
   </tilemap>
   <background color="#0e71baff">
      <parallax filename="examples.png" ... />
   </background>
   <blazeworld>
      <shapes>
         <polygon damage="0.0" friction="1.0" restitution="0.0">
            <point x="352" y="352"/>
            <point x="384" y="384"/>
            <point x="384" y="544"/>
            <point x="0" y="544"/>
            <point x="0" y="352"/>
         </polygon>
         <circle damage="0.0" friction="1.0" radius="32" restitution="0.0">
            <point x="46" y="319"/>
         </circle>
      </shapes>
   </blazeworld>
</level>


Thoughts?
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Tue Oct 06, 2009 7:55 am    Post subject: Reply with quote

More API design work.

http://www.hackerpilot.org/src/arclib/tilemap.d
http://www.hackerpilot.org/src/arclib/tilemap.html
http://www.hackerpilot.org/src/arclib/parallax.d
http://www.hackerpilot.org/src/arclib/parallax.html
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Mon Oct 19, 2009 10:43 pm    Post subject: Reply with quote

I'm seriously considring just dumping the XML support from these extensions. JSON is much easier to deal with on the python side of things (in the map editor) and is a much faster format from the parsing side of things. XML seems to be the wrong tool for the job for data that just needs to be structured in a basic manner and read quickly.

Any thoughts?
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Thu Oct 22, 2009 1:20 pm    Post subject: Reply with quote

SirAlaran wrote:
I'm seriously considring just dumping the XML support from these extensions. JSON is much easier to deal with on the python side of things (in the map editor) and is a much faster format from the parsing side of things. XML seems to be the wrong tool for the job for data that just needs to be structured in a basic manner and read quickly.

Any thoughts?


Well, since nobody seems to care that much, I'm going to go just with JSON.
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon Nov 02, 2009 2:56 pm    Post subject: Reply with quote

Hi,

You can use whichever format, worst case scenario I will translate JSON to XML and write the XML loader for your planned extension.

Sorry for not responding too quick, busy.
Back to top
View user's profile Send private message AIM Address
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Fri Nov 06, 2009 12:02 am    Post subject: Reply with quote

clayasaurus wrote:
Hi,

You can use whichever format, worst case scenario I will translate JSON to XML and write the XML loader for your planned extension.

Sorry for not responding too quick, busy.


I'm designing the actual modules to be separate from the file I/O, but writing a parser using Tango's JSON code myself. Do you need XML for any particular reason? If so I can just stick an option into the editor to export in XML.
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Fri Nov 06, 2009 2:51 am    Post subject: Reply with quote

Initial upload of the Parallax extension. (Having a working D/Tango was helpful with this...)

http://www.dsource.org/projects/arclib/browser/trunk/arc/x/level/parallax.d

Quick test: (Replace the file name with something you actually have on your machine)
Code:

module arctest;
import arc.window;
import arc.time;
import arc.input;
import arc.types;
import arc.x.level.parallax;
import tango.io.Stdout;

import derelict.opengl.gl;

int main()
{
   scope(exit)
   {
      arc.window.close();
   }

   arc.window.open("Arclib Test", 640, 480, false, true);
   arc.input.open();

   glClearColor(0.0, 0.5, 1.0, 1.0);

   auto parallax = new Parallax;

   auto index = parallax.addLayer("/home/alaran/mapeditor/images/parallax/forest.png");
   parallax.setScrollOptions(index, true, 0.5, false, float.nan);
   parallax.setRepeatOptions(index, true, false);

   index = parallax.addLayer("/home/alaran/mapeditor/images/parallax/forest.png");
   parallax.setScrollOptions(index, true, 0.75, false, float.nan);
   parallax.setRepeatOptions(index, true, false);

   int x = 0;
   int y = 0;
   int dx = 0;
   int dy = 0;

   while(!arc.input.keyPressed(ARC_QUIT))
   {
      arc.input.process();
      arc.time.process();
      arc.window.clear();

      x += dx;
      y += dy;

      dx = dy = 0;

      if(arc.input.keyPressed(ARC_DOWN))
         dy = 5;
      if(arc.input.keyPressed(ARC_UP))
         dy = -5;
      if(arc.input.keyPressed(ARC_RIGHT))
         dx = 5;
      if(arc.input.keyPressed(ARC_LEFT))
         dx = -5;

      parallax.drawAllLayers(x, y);

      arc.time.limitFPS(60);
      arc.window.swap();
   }

   return 0;
}


Comments and suggestions for improvement welcome.
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Fri Nov 06, 2009 10:09 am    Post subject: Reply with quote

I uploaded an initial example here based off of your code: http://svn.dsource.org/projects/arclib/trunk/examples/level/

It would be nice if you could work your test code off of the svn.

For all media that is required of the example, please add it to the testbin/
http://svn.dsource.org/projects/arclib/downloads/testbin/

Then just checkout or copy the testbin folder over to the examples/level folder, and reference media with "testbin/media".

Also, feel free to use the camera extension to do actual transformation of the entire scene. It will probably work a little bit better than the x,y,dx,dy vars.
Back to top
View user's profile Send private message AIM Address
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Fri Nov 06, 2009 10:11 am    Post subject: Reply with quote

I've created a folder for you to upload your map editor tool.

http://svn.dsource.org/projects/arclib/trunk/tools/

Put your tool in its own folder.
Back to top
View user's profile Send private message AIM Address
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Fri Nov 06, 2009 10:15 am    Post subject: Reply with quote

Also, the reason I wanted XML was because Tango is capable of reading and writing it, and its a logical human readable format that is easy to parse. Does Tango support JSON as well?
Back to top
View user's profile Send private message AIM Address
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Fri Nov 06, 2009 12:12 pm    Post subject: Reply with quote

clayasaurus wrote:
Also, the reason I wanted XML was because Tango is capable of reading and writing it, and its a logical human readable format that is easy to parse. Does Tango support JSON as well?


Many argue that JSON is more human-readable than XML. It is also faster to parse.

It's supported by Tango:
http://dsource.org/projects/tango/docs/current/tango.text.json.Json.html
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Fri Nov 06, 2009 3:16 pm    Post subject: Reply with quote

clayasaurus wrote:
I uploaded an initial example here based off of your code: http://svn.dsource.org/projects/arclib/trunk/examples/level/

It would be nice if you could work your test code off of the svn.

For all media that is required of the example, please add it to the testbin/
http://svn.dsource.org/projects/arclib/downloads/testbin/

Then just checkout or copy the testbin folder over to the examples/level folder, and reference media with "testbin/media".

Also, feel free to use the camera extension to do actual transformation of the entire scene. It will probably work a little bit better than the x,y,dx,dy vars.


Done. The updated example is here: http://dsource.org/projects/arclib/browser/trunk/examples/level/parallaxdemo.d
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Fri Nov 06, 2009 5:10 pm    Post subject: Reply with quote

Cool, although I'd be surprised if it did anything without the

cam.open()
drawingCode();
cam.close()

code : o
Back to top
View user's profile Send private message AIM Address
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Fri Nov 06, 2009 5:51 pm    Post subject: Reply with quote

clayasaurus wrote:
Cool, although I'd be surprised if it did anything without the

cam.open()
drawingCode();
cam.close()

code : o


The parallax code needs to know where to start and stop drawing on the screen, not on the game world.

Basically I'm using the camera as a place to store the x and y coordinates. If I want to use cam.open() and cam.close() I'll have to change the way that the parallax code treats the coordinates. Alternatively I could just specify that the parallax drawing code should happen outside of calls to cam.open and cam.close.
_________________
Current projects: Project Fermitas, Arctographer tile map editor, Arclib game library.
Gentoo | Textadept
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> ArcLib All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group