Difference between revisions of "SpriteSheetApplicationSAB"

From The Battle for Wesnoth Wiki
 
(32 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{SoC2014Student}}
 +
[[Category:SoC_Ideas_SpriteSheets2014]]
 +
 +
==Description==
 
<h4>Aishiko GSOC 2014 SpriteSheets</h4>
 
<h4>Aishiko GSOC 2014 SpriteSheets</h4>
 
My proposal is to take the current functions for drawing sprites and
 
My proposal is to take the current functions for drawing sprites and
Line 6: Line 10:
 
sheets.
 
sheets.
  
Posted 28 Feb 2014
+
==IRC==
1) Basics
+
Aishiko, Aishiko_laptop
 
 
1.1) Write a small introduction to yourself.
 
 
 
1.2) State your preferred email address.
 
 
 
1.3) If you have chosen a nick for IRC and Wesnoth forums, what is it?
 
 
 
1.4) Why do you want to participate in summer of code?
 
 
 
I'd like to participate in the summer of code for several reasons, and
 
yes money is one of them.  but experience is the biggest one.
 
 
 
1.5) What are you studying, subject, level and school?
 
 
 
I am currently studying computer science (read programming) and networking
 
technology.  I am a Softmore in both, I am a current student at Sandhills
 
Community College.
 
 
 
1.6) What country are you from, at what time are you most likely to be able to
 
join IRC?
 
 
 
I currently live on the east coast of the US and can be in IRC pretty
 
much all day, either at home or school, though if at school there will
 
be a delay if in class and not lab.
 
 
 
1.7) Do you have other commitments for the summer period ? Do you plan to take
 
any vacations ? If yes, when.
 
 
 
I have no current commitments that would impact my ability to give GSOC
 
40 hours a week of work and attention.  But if an emergency comes up
 
I'll find a way to make up the hours.
 
 
 
2) Experience
 
 
 
2.1) What programs/software have you worked on before?
 
 
 
Mostly personal projects and class projects, in C, C++, C#, PHP, Python,
 
& the Arduino.  One of C++ classes was using DarkGTK (yes I know its
 
windows only) but we used SpriteSheets, sprite collision, and mouse interaction.
 
 
 
2.2) Have you developed software in a team environment before? (As opposed to
 
hacking on something on your own)
 
 
 
I have in a class environment, but I'm usually the only one left doing
 
the heavy lifting of coding.  Though next year I'll be doing the
 
programming capstone class where the class of 1-20 students work
 
together to produce a program for a client, either for the college or
 
for a community member/business.  I'm both looking forward to and
 
dreading working on a team, wondering if I'll be able to fit in and
 
create code that is easy to maintain and follow.
 
 
 
2.3) Have you participated to the Google Summer of Code before? As a mentor or a
 
student? In what project? Were you successful? If not, why?
 
 
 
I applied last year, however, I wasn't choosen mostly because I lack
 
good writing skills for technical documents.  At least that is what I
 
was told.
 
 
 
2.4) Are you already involved with any open source development projects? If yes,
 
please describe the project and the scope of your involvement.
 
 
 
None, I have submitted patches to the linux kernel but, I never
 
bothered to see if they made it in.
 
 
 
2.5) Gaming experience - Are you a gamer?
 
 
 
Sometimes, depends on my mood.
 
 
 
2.5.1) What type of gamer are you?
 
 
 
Casual.
 
 
 
2.5.2) What type of games?
 
 
 
2.5.3) What type of opponents do you prefer?
 
 
 
AI oppenents, I'm not really into the whole competetive thing.
 
 
 
2.5.4) Are you more interested in story or gameplay?
 
 
 
I think BOTH have to be there for a successful game. 
 
Though to be honest I'm better at critecing story then gameplay.
 
 
 
2.5.5) Have you played Wesnoth? If so, tell us roughly for how long and whether
 
you lean towards single player or multiplayer.
 
 
 
We do not plan to favor Wesnoth players as such, but some particular projects
 
require a good feeling for the game which is hard to get without having played
 
intensively.
 
 
 
I've played Wesnoth for a year or 2, and I play exclusively single player.
 
 
 
2.6) If you have contributed any patches to Wesnoth, please list them below. You
 
can also list patches that have been submitted but not committed yet and patches
 
that have not been specifically written for GSoC. If you have gained commit
 
access to our repository (during the evaluation period or earlier) please state
 
so.
 
 
 
  
3) Communication skills
+
==Patches==
 +
Pull Request 119
 +
Pull Request 130
 +
===Proof of Concept===
 +
https://github.com/Aishiko/getSprite
  
3.1) Though most of our developers are not native English speakers, English is
+
This is not quite done, its still rigid and inflexiable to meet our artists needs, however that can be fixed.  It also doesn't send an error code and needs to be tested.  It relies on all the images in row being the same height and each column being the same width was the plan but it really should be fine with varying widths I think.  All the images need to be pressed right up to each other, with borders of 1 pixel in width all around them. The first row needs to be blank put for pixel 0,0 for that contains the border colour and then Row1 HAS to start at pixel 1,0.  Otherwise its fine.  Ohhh and all it does is FIND the images and returns a std::vector<SDL_Rect> it doesn't actually do anything with them, no handling of malformed sheets, and no error codes or logging (though there is a place for it it just currently contains a comment).
the project's working language. Describe your fluency level in written English.
 
  
3.2) What spoken languages are you fluent in?
+
However I see this as becoming a powerful tool that devs that can compile wesnoth can compile as well, and as a standalone, it means the artists that don't mess with the code do not have to compile wesnoth once fully implemented.
  
English, I can understand a smattering of other languages but not enough
+
==Implementation Ideas==
to do anything deep or programming specific.
+
===Goals===
 +
Eliminate as many small single images as possible from the program.
 +
Enable Sprite Sheets to be used in;
 +
# Gameplay
 +
#* Units
 +
#* Terrain
 +
#* etc
 +
# Menus, mouse pointers, etc. Optional Goal  I doubt at this point that I'll make it this far.
 +
# Reuse as much as the existing syntax as possible
 +
# Create Unit Tests to make sure that the areas modified are as good as I can make them.
 +
# Make it easy for the artists to add sprites to a sprite sheet:
  
3.3) Are you good at interacting with other players? Our developer community is
+
===Problems===
friendly, but the player community can be a bit rough.
+
* Not all units and terrain are 72x72
 +
* Adding a boarder around each image to make it easier for the artists to see what sort of space they have to work with will make taking the current images and converting them a bit harder as well as creating a script to convert them (which remains a soft goal, ie if I have to do it AFTER the summer, I'll do that.) Stupid perfectionist leanings, at least for what I think of to get the project ready! 
 +
* Syntax making sure that its easy to use and understand for the average user
  
3.4) Do you give constructive advice?
+
===First Steps===
 +
I will create a test program that will allow me to make sure that the sprites
 +
are being parsed properly.  I'll need a spritesheet for this, preferably a big
 +
one.  Through this whole process if it breaks it should only break on the sprite
 +
sheets until then it shouldn't break anything exisiting.
  
I've been told I do on occasion.
+
===Cache===
 +
In cache the spritesheets need to be parsed, either all at once or only those
 +
grids that are currently needed and the found corners saved as above.  When an
 +
image is needed from a spritesheet it will gotten out of the sheet and then
 +
passed into the cache that will using and holding that image such as the
 +
scaled_to_zoom_ or tod_colored_images_.  The sheets will remained cached until
 +
the game is exited completely or the cache is full the oldest referenced image
 +
will be dropped.
  
3.5) Do you receive advice well?
+
==The Plan==
  
I do if its construtive and not attackingIf its yelling, screaming,
+
===How This Will Work===
and insults as well, not so muchHow its given usually impacts how well
+
The way this will work is each sheet will be a grid of one colour that is not
I receive it.
+
used in any of the sprites (say a shade of pink) this RGBA colour is a Primary
+
Key, it will lay out a grid of areas within our spritesheetThen
3.6) Are you good at sorting useful criticisms from useless ones?
+
each of those grid squares (or rectangles) each frame/image has a second border
 +
of colour, say a different shade of pinkEach unit's spritesheet will then be
 +
read at loading into the cache, each grid square will be searched for an image
 +
if found it will be loaded into an object that will contain the following
 +
information:
 +
*SpriteSheetName
 +
*Row
 +
*Column
 +
*Upper Y
 +
*Upper X
 +
*Lower Y
 +
*Lower X
 +
 +
Each sprite will be returned as a SDL_Rect in a vector, that vector will be named whatever the unit is.
  
Given enough time yes, but the painfully obvious ones I usually see
+
===WML===
right away.
+
Each Spritesheet will have a Spritesheet set of tags in the unit config file, it will look something like:
 +
[Spritesheet]
 +
    File=file_path/name.png
 +
    [Image]
 +
        ImageID=1
 +
        ImageName="Attack_1"
 +
        Upper_X=x
 +
        Upper_Y=y
 +
        Lower_X=x
 +
        Lower_Y=y
 +
    [/Image]
 +
    -- More Images here
 +
[/Spritesheet]
 +
OR
 +
[Spritesheet]
 +
    File=file_path/name.png
 +
    [Image]
 +
        ImageID=1
 +
        ImageName="Attack_1"
 +
        Coordinates=[x,y,x,y]  --upper followed by lower x,y
 +
    [/Image]
 +
    -- More Images here
 +
[/Spritesheet]
  
3.7) How autonomous are you when developing ? Would you rather discuss
 
intensively changes and not start coding until you know what you want to do or
 
would you rather code a proof of concept to "see how it turn out", taking the
 
risk of having it thrown away if it doesn't match what the project want
 
  
I'm usually fairly autonomous, once the design has been decided, and
+
Each animation sequence called by doing a call like:
if it doesn't work and needs a change I sometimes seek councel on what
+
$Elvish_Sorceress[1~10,1,2]:[80*5,100*2,80*5] or <Elvish_Sorceress>[1~10,1,2]:[80*5,100*2,80*5]
way I should go, but sometimes just go ahead and make the change.
+
Almost like a normal call but to a single image file instead of several files.  Out of the Elvish_Sorceress.png, images 1-10 and then 1 and finally 2 are called for the attack sequence in this case.
Examples:
 
1) The flow needs changing as it doesn't work right, usually I'll seek
 
help figuring it how to change the flow so it does work.
 
2) An array isn't giving the flexablity needed for a function but a
 
list will, I implement the list instead.  And inform whomever needs to
 
know that I have done that change.
 
  
4) Project
 
  
4.1) Did you select a project from our list? If that is the case, what project
+
The current syntax is:
did you select? What do you want to especially concentrate on?
 
  
I selected one from the list, the implementing the SpriteSheets.  
+
  image="units/elves-wood/sorceress-melee-attack-[1~10,1,2].png:[80*5,100*2,80*5]"
I would like to concentrate on 2 tasks, 1 getting SpriteSheets to just
 
work in wesnoth, and two, provide a script/tool/utility to allow easy
 
converting from the old single images to the sheet (assuming certian
 
naming conventions are followed).
 
  
4.2) If you have invented your own project, please describe the project and the
+
I envision it to be more like one of these to work as with a spritesheet:
scope.
 
  
N/A
+
<image>[1~30][80*5,100*2,80*5]", which expands to <image>1:[80],<image>2:[80],<image>3:[80],etc
  
4.3) Why did you choose this project?
+
or
  
I chosse it because I understand the concepts behind it, and felt it  
+
$image[2.1~2.10,2.1~2.2]:[80*5,100*2,80*5]
was a task that I could handleIt will also force me to learn and
+
This should take the current
will provide immediate gains to all users when the version that
+
markup language and merely extand it to allow for calling an SDL_Rect from the spritesheetThe <sheetName> will either relate to a memory address of
includes the change is pushed out.
+
the sheet or to an image under units/ like units/Elvish_Sorceress.png
  
4.4) Include an estimated timeline for your work on the project. Don't forget to
+
When the WML goes for the individual images that create that animation it'll
mention special things like "I booked holidays between A and B" and "I got an
+
look at the generated Autogenerated Spritesheet WML added to each.  The idea of holding a config of where each image is located and
exam at ABC and won't be doing much then".
+
saving that would remove the overhead of searching everytime a frame is called.
 +
These frames would then be passed to the normal cache used and stored there,
 +
until they expire.
  
I'm still working out a timeline but I would most likely do a commit
+
===Making WML Painless===
at least weeklyAnd break out the commits so that similar changes
+
I'll implement a standalone tool that will take 1 or 2 inputs, if 1 just the spritesheet it will then find each image and ask the user to define the image (attack_1 etc) it will then generate a barebones spritesheet config file to be appended to the unit.cfgIf 2 it will take the old unit.cfg, and look for NEW images and REMOVED images, and only add or remove those changed so it doesn't require the user to double check or change image numbers by 1 or 2 everywhere to make adding/removing/changing an image so painful they don't want to do it.
are only in that commit. Example, comment changes in one, (assuming
 
no code changes), a converted set of sprites (aka the spritesheet) as
 
one, and then code making use of it.  After checking to make sure that
 
the spritesheet works, removal of the converted individual sprite image  
 
files.
 
 
4.5) Include as much technical detail about your implementation as you can
 
  
At this point I think I would take 1 sprite (character) and create a
+
===Spritesheet Details===
spritesheet of it, and then test with that one.  To allow testing I'd
+
Each Spritesheet will have each unit outlined in a box (Colour and size matters not in this version unless we want to implement a side program that will parse out the correct information for the artists.)
likely have it check for a spritesheet if it finds one it uses that,
 
otherwise it uses the individual sprite images, in this way the game
 
still works, until all the sprites have been turned into spritesheets.
 
 
Once I have completed getting a character spritesheet to work, I'd
 
then move on to the map sprites to spritesheets, again using the same
 
methodology of check and if it finds a spritesheet use it otherwise,
 
use the individual images.  Though, on the grouping I'm not sure how
 
I'd do that mordante and I'd have to discuss grouping, since a map can
 
have any or all of the different tiles, and they are not chained like
 
the unit/character sprites are, I'd have to group similar tiles together.
 
Like the water images, shorelines, docks, and water villages, as one.
 
The fields, human villages and castles in one.  Swamp things together,
 
and so on.
 
     
 
        I've heard that some devs think that a spritesheet might cause issues
 
        with larger images that don't fit in a hex, I'll intentional create some
 
        sprite sheets just for testing this purpose.  I'll also see about creating
 
        some tests to check and see if the performance gains are really showing up.
 
       
 
  
4.6) What do you expect to gain from this project?
+
On loading an image if the [SpriteSheet] tags are found then it will automatically check for each called image within the spritesheet's definition pulling out the requried frames as needed. This method will require no more parsing overhead then the usual requirements of parsing the data in the config (IE no need to "scan" the image file looking for grids or borders or anything like that.  The spritesheet can be packed as tightly as desired by the artist, and even notes left in the file, such as a block of text that says "Attack animation here".  Each unit can have more then 1 spritesheet however, they can only have 1 image with an ImageID, this is unique to the unit not the spritesheet file.
  
Experience, learning to work on a team where most actually pull their
+
==Testing==
own weight and the success of the project as a whole is not on my
+
====Phase One====
shoulders.  This is too big a project for me to even think of that! 
+
I will create a test program that will allow me to make sure that the sprites
and I'd not be able to, not in 3 months.
+
are being parsed properly.  This program will be intergrated and become the
 +
spritesheet core of the program.  Having this out by itself will allow me to see
 +
what sort of difference there is when parsing just the needed gridboxes and the
 +
whole sheet.  This will allow me to come up with some decent error messages for
 +
malformed sprite boxes.
  
4.7) What would make you stay in the Wesnoth community after the conclusion of
+
====Phase Two====
SOC?
+
In addition to creating unit tests, I'll try out various hardware to see what
 +
sort of performance changes I can detect during the course of getting things
 +
working.  I'll test on a Quad-core with 8 or more GB RAM, a Dual-core with 4GB
 +
RAM, and a 32bit single core with 1-4 GB RAM (I don't have any Macs so I can not
 +
test on that and I only have Windows in a VM, so most testing will be done under
 +
Linux I'll depend on the various developers that use windows to let me know how
 +
it is affecting the running under Windows & Macs)
  
Finding that the community is a non-hostile place to contribute, that  
+
==Deliverables==
individuals are treated with courtsey or the respect they have earned.
+
{| align="center" border="1"
That I'm encouraged to help other areas of the code, such as, "Aishi,
+
|Status
the spritesheets work, do you think you could help with the transistion
+
|Requirement Level
effects for the map?"
+
|Number ID
 +
|Goal Defined
 +
|-
 +
|
 +
|Required
 +
|1A
 +
|Properly working Spritesheet cache to speed up loading and elimnate glithy and laging animations do to disk access times.
 +
|-
 +
|
 +
|Required
 +
|1B
 +
|dynamic so that low mem devices are not adversely effected.
 +
|-
 +
|
 +
|Plan A Only!
 +
|2
 +
|Properly parse spritesheets and quickly be able to pass that information on for each frame.
 +
|-
 +
|
 +
|Required
 +
|3A
 +
|Spritesheets that are flexible and easy for artists and WML users to implement.
 +
|-
 +
|
 +
|Required
 +
|3B
 +
|Spritesheets that do not have a fixed size for every frame they hold.
 +
|-
 +
|
 +
|Plan A Only!
 +
|3C
 +
|Nor a Fixed grid size that holds each frame in its border.
 +
|-
 +
|
 +
|Plan A Only!  Optional
 +
|3D
 +
|Not require to have the gridlines or the borders be a particular width (optional, could be axed for performance reasons).
 +
|-
 +
|
 +
|Plan B Only!  Optional
 +
|3D
 +
|Not require the borders be a particular width.
 +
|-
 +
|
 +
|Required
 +
|4
 +
|WML syntax for Spritesheets that is not long, complex, hard to understand, or prone to errors.
 +
|-
 +
|
 +
|Required
 +
|5
 +
|No negative or negible impact on loading times
 +
|}
 +
==Packages Required==
 +
{| align="center" border="1"
 +
|Package Name
 +
|Reason
 +
|Status
 +
|-
 +
|SDL
 +
|Needed for getting the colour information
 +
|Plan A required otherwise Not needed
 +
|-
 +
|Boost
 +
|Might be able to provide a performance boost (no pun intended)
 +
|Optional
 +
|}
  
 +
==13 Week Timeline==
 +
{| align="center" border="1"
 +
|
 +
===Status===
 +
|
 +
===Start/End_Dates===                               
 +
|
 +
===Goals===
 +
|-
 +
|Current
 +
|March 20 - April 20:
 +
|
 +
* Get more details and further flesh out the details of proposal.  Create more patches (at least one every 1-2 weeks that is some bug or feature request, something not trival).
 +
* Get more familiar with Git and GitHub.  Be active in the community and encouraging to others that want to create a patch.
 +
|-
 +
|Next
 +
|April 21 - May 18:
 +
|
 +
*More details hammered out and continue doing what I'd been doing during Mar 20 - April 20.  Perhaps begin a little pre-coding to test theories.
 +
|-
 +
|
 +
|May 19 - June 1:
 +
|
 +
* Add a cache for just the spritesheets
 +
** Here I'll add a spritesheets cache it will be the cache that will hold all the sprite sheets once loaded.  It will have to be felxible (in size and what's loaded) and perstant.
 +
|-
 +
|
 +
|June 1 - 15:
 +
|
 +
* Add a get_spritesheet_frame function to get the image of the sprite we need right now.
 +
* Start on the program to generate the WML spritesheet Code.
 +
|-
 +
|
 +
|June 16 - 29:
 +
|
 +
* Implement new WML snytax for the spritesheets. 
 +
* Continue on the program to generate the WML spritesheet Code, and have ready to go.
 +
|-
 +
|
 +
|June 23 - 27:
 +
|
 +
* Mid-term evaluation, I would like to receive feedback before this point so that if I'm not performing up to par I can work harder/longer.
 +
|-
 +
|
 +
|June 30 - July 13:
 +
|
 +
* Modify any existing functions that need to be modified to handle sheets that broke.
 +
|-
 +
|
 +
|July 14 - 27:
 +
|
 +
* Run tests and see what breaks and fix what broke
 +
** Unit tests would have to be added and commited to keep this up and make sure its as robust as I can make it in the timeframe allotted to make it all work.
 +
|-
 +
|
 +
|July 28 - Aug 10:
 +
|
 +
* Pad time in case something takes longer then expected
 +
** Something ALWAYS takes longer then expected or breaks in ways that we didn't expect and only a fool doesn't plan for the worst, so that is what this is, this is my, "OH CRAP" time.  Where I have some time to address the parts that take longer or where I work on optional extended tasks like writing a shell/python script to convert all the images to spritesheets.
 +
|-
 +
|
 +
|Aug 3:
 +
|
 +
* End of all major code additions/changes, begin of code clean-up and Minor fixes begin.
 +
|-
 +
|
 +
|Aug 11 - 17:
 +
|
 +
* Documentation and clean up anything that hasn't yet be done.
 +
|-
 +
|
 +
|Aug 22:
 +
|
 +
* Final evaluation and send the required code snippets to Google.
 +
|}
 +
===The Weeks in the Program===
 +
Week  1: May 19 to May 25
 +
Week  2: May 26 to June 1
 +
Week  3: June 2 to June 8
 +
Week  4: June 9 to June 15
 +
Week  5: June 16 to June 22
 +
Week  6: June 23 to June 29
 +
Week  7: June 30 to July 6
 +
Week  8: July 6 to July 13
 +
Week  9: July 14 to July 20
 +
Week 10: July 21 to July 27
 +
Week 11: July 28 to August 3
 +
Week 12: August 4 to August 10
 +
Week 13: August 11 to August 17
  
5) Practical considerations
+
Optional tasks if everything goes smoother and easier then planed in no
 +
particular order:
 +
* Convert all the sprites, update all the .cfg for the base units
 +
* Create script to allow Addon Artists convert their sprites
  
5.1) Are you familiar with any of the following tools or languages?
+
==Artists Weigh In==       
  
    Git (used for all commits)
+
OK, not just for artists, go to
    I don't get it yet but I'm confident that I can get it.
+
http://forums.wesnoth.org/viewtopic.php?f=9&t=40191 and weigh in on the details
    C++ (language used for all the normal source code)
+
that effect you as an user!  And only those details, and thank you for helping
    Its my favourite language and I'm comfortable using the language
+
me make Wesnoth a little bit better.
    and looking up what I don't know and making it work.  I'm also not
 
    afraid to ask, for help/documentation if I get stuck.
 
    STL, Boost, Sdl (C++ libraries used by Wesnoth)
 
    I've not, YET.  Well I might, I never really looked into where a lib or
 
    function comes from when I use, I'll have to pay a bit more attention
 
    now.  But they are no on my documentation read list, I'm confident
 
    that by the time coding begins that I'll be able to leverage them to
 
    obtain results, and be more effienent as I go.  Even going back and
 
    making a section more effient if I realize that I over looked a better
 
    tool then I orginally used.
 
    Python (optional, mainly used for tools)
 
    I'm familiar enough to use it, follow it (assuming good coding
 
    conventions are followed).
 
    build environments (eg cmake/scons)
 
    I tend to use cmake and the gcc compiler, basically I use which ever
 
    build environment I have available and if its a new one I look up (via
 
    the man page or the internet) how to use it, and if the defaults
 
    settings don't work to add flags/options to get it to compile.
 
    WML (the wesnoth specific scenario language)
 
    Absolutely none before now, again on my read list
 
    Lua (used in combination with WML to create scenarios)
 
    None but I don't create senarios at this point, and if its only used
 
    in that context, it shouldn't have any barring on the project(s) I'm
 
    interested in doing at this point.  
 
  
5.2) Which tools do you normally use for development? Why do you use them?
+
==Current Thoughts==
Kate, as its just what I'm used to, I like how it's mimaliztic and
+
To Happygrue
non-intrutsive.
 
Visual Studio for my C# class because that is what they have to work
 
in when I turn it in.
 
  
5.3) What programming languages are you fluent in?
+
In implementing the spritesheets I am considering storing a vector with the SDC_Rect info (IE {x,y,h,w}) so that when image 5 is needed it pulls out element(5) or element(-1) if the sprites are numbered from 1 instead of 0.  My plans for making this work are to create a spritesheet namespace and then when pulling out an image pass the surface (res) into the images_ cache where it will be handled as if it where a single image taken from the diskIn this way I won't have to change anything about how the images are handled for zooming, colouring, etcBut I'm finding that I really should work on getting the WML and parsing of the lua files done first.
I'm not sure what you mean by fluent, if you mean know every builtin
 
function and every conseviable combination of calls, I doubt very many
 
could claim to be fluentHowever if you mean, comfortable, and able
 
to figure out things you don't knoe, either by looking it up or by
 
context then C (and its children, C++, C#, Arduino) python, and PHP.   
 
After being fluent in English doesn't mean you know every word or
 
special rule for the language.
 
  
5.4) Would you mind talking with your mentor on telephone / internet phone? We
+
I think going with the following tags would be a good way to go;
would like to have a backup way for communications for the case that somehow
+
[Spritesheet]
emails and IRC do fail. If you are willing to do so, please do list a phone
+
    File=file_path/name.png
number (including international code) so that we are able to contact you. You
+
    [Sprite]
should probably *only* add this number in the application for you submit to
+
        SpriteID=1
google since the info in the wiki is available in public. We will *not* make any
+
        SpriteName="Attack_1" this an optional feild
use of your number unless some case of "there is no way to contact you" does
+
        Location=[x,y,w,h]
arise!
+
    [/Sprite]
+
    -- More Images here
 +
[/Spritesheet]
  
I wouldn't mind and in some cases prefer it.  I'm not the most observant
+
This differs from the proposal in that the [Image] tag already exists for another purpose, so I changed it to Sprite and changed the rest to match (uniformity and descriptive too) and Cooridante/Location now basically returns an SDL_Rect[Frame] tags are also already taken in the animation section.
when it comes to my email, I usually just get notices and spam that can
 
be ignored (high noise to signal ratio in my mailbox at the moment).   
 
Though when expecting something I check it more often at least once a
 
day if not more.
 
  
  **************Comments and Suggestions**************
+
I think that for this to work I need to get the basics in place for the following by mid June.
  Please place them after this line, all are appreciated and if I can't thank you
+
  1) working cache
personally (IE you don't attach your name to it, Thank you.
+
a) load the spritesheet into the proper cache
 +
b) extract and put an unscaled copy into the correct cache (unscaled I think)
 +
2) wml
 +
a) spritesheet tags
 +
b) spritesheet animation syntax

Latest revision as of 01:27, 23 May 2014


This page is related to Summer of Code 2014
See the list of Summer of Code 2014 Ideas



This is a Summer of Code 2014 student page


Description

Aishiko GSOC 2014 SpriteSheets

My proposal is to take the current functions for drawing sprites and move it to allow for spritesheets, while hiding any of the changes from campaign designers. It should allow for the seemless intergration of spritesheets and allow for a period of conversion from multiple files to sheets.

IRC

Aishiko, Aishiko_laptop

Patches

Pull Request 119 Pull Request 130

Proof of Concept

https://github.com/Aishiko/getSprite

This is not quite done, its still rigid and inflexiable to meet our artists needs, however that can be fixed. It also doesn't send an error code and needs to be tested. It relies on all the images in row being the same height and each column being the same width was the plan but it really should be fine with varying widths I think. All the images need to be pressed right up to each other, with borders of 1 pixel in width all around them. The first row needs to be blank put for pixel 0,0 for that contains the border colour and then Row1 HAS to start at pixel 1,0. Otherwise its fine. Ohhh and all it does is FIND the images and returns a std::vector<SDL_Rect> it doesn't actually do anything with them, no handling of malformed sheets, and no error codes or logging (though there is a place for it it just currently contains a comment).

However I see this as becoming a powerful tool that devs that can compile wesnoth can compile as well, and as a standalone, it means the artists that don't mess with the code do not have to compile wesnoth once fully implemented.

Implementation Ideas

Goals

Eliminate as many small single images as possible from the program. Enable Sprite Sheets to be used in;

  1. Gameplay
    • Units
    • Terrain
    • etc
  2. Menus, mouse pointers, etc. Optional Goal I doubt at this point that I'll make it this far.
  3. Reuse as much as the existing syntax as possible
  4. Create Unit Tests to make sure that the areas modified are as good as I can make them.
  5. Make it easy for the artists to add sprites to a sprite sheet:

Problems

  • Not all units and terrain are 72x72
  • Adding a boarder around each image to make it easier for the artists to see what sort of space they have to work with will make taking the current images and converting them a bit harder as well as creating a script to convert them (which remains a soft goal, ie if I have to do it AFTER the summer, I'll do that.) Stupid perfectionist leanings, at least for what I think of to get the project ready!
  • Syntax making sure that its easy to use and understand for the average user

First Steps

I will create a test program that will allow me to make sure that the sprites are being parsed properly. I'll need a spritesheet for this, preferably a big one. Through this whole process if it breaks it should only break on the sprite sheets until then it shouldn't break anything exisiting.

Cache

In cache the spritesheets need to be parsed, either all at once or only those grids that are currently needed and the found corners saved as above. When an image is needed from a spritesheet it will gotten out of the sheet and then passed into the cache that will using and holding that image such as the scaled_to_zoom_ or tod_colored_images_. The sheets will remained cached until the game is exited completely or the cache is full the oldest referenced image will be dropped.

The Plan

How This Will Work

The way this will work is each sheet will be a grid of one colour that is not used in any of the sprites (say a shade of pink) this RGBA colour is a Primary Key, it will lay out a grid of areas within our spritesheet. Then each of those grid squares (or rectangles) each frame/image has a second border of colour, say a different shade of pink. Each unit's spritesheet will then be read at loading into the cache, each grid square will be searched for an image if found it will be loaded into an object that will contain the following information:

  • SpriteSheetName
  • Row
  • Column
  • Upper Y
  • Upper X
  • Lower Y
  • Lower X

Each sprite will be returned as a SDL_Rect in a vector, that vector will be named whatever the unit is.

WML

Each Spritesheet will have a Spritesheet set of tags in the unit config file, it will look something like:

[Spritesheet]
    File=file_path/name.png
    [Image]
        ImageID=1
        ImageName="Attack_1"
        Upper_X=x
        Upper_Y=y
        Lower_X=x
        Lower_Y=y
    [/Image]
    -- More Images here
[/Spritesheet]

OR

[Spritesheet]
    File=file_path/name.png
    [Image]
        ImageID=1
        ImageName="Attack_1"
        Coordinates=[x,y,x,y]  --upper followed by lower x,y
    [/Image]
    -- More Images here
[/Spritesheet]


Each animation sequence called by doing a call like:

$Elvish_Sorceress[1~10,1,2]:[80*5,100*2,80*5] or <Elvish_Sorceress>[1~10,1,2]:[80*5,100*2,80*5]

Almost like a normal call but to a single image file instead of several files. Out of the Elvish_Sorceress.png, images 1-10 and then 1 and finally 2 are called for the attack sequence in this case.


The current syntax is:

image="units/elves-wood/sorceress-melee-attack-[1~10,1,2].png:[80*5,100*2,80*5]"

I envision it to be more like one of these to work as with a spritesheet:

<image>[1~30][80*5,100*2,80*5]", which expands to <image>1:[80],<image>2:[80],<image>3:[80],etc

or

$image[2.1~2.10,2.1~2.2]:[80*5,100*2,80*5]

This should take the current markup language and merely extand it to allow for calling an SDL_Rect from the spritesheet. The <sheetName> will either relate to a memory address of the sheet or to an image under units/ like units/Elvish_Sorceress.png

When the WML goes for the individual images that create that animation it'll look at the generated Autogenerated Spritesheet WML added to each. The idea of holding a config of where each image is located and saving that would remove the overhead of searching everytime a frame is called. These frames would then be passed to the normal cache used and stored there, until they expire.

Making WML Painless

I'll implement a standalone tool that will take 1 or 2 inputs, if 1 just the spritesheet it will then find each image and ask the user to define the image (attack_1 etc) it will then generate a barebones spritesheet config file to be appended to the unit.cfg. If 2 it will take the old unit.cfg, and look for NEW images and REMOVED images, and only add or remove those changed so it doesn't require the user to double check or change image numbers by 1 or 2 everywhere to make adding/removing/changing an image so painful they don't want to do it.

Spritesheet Details

Each Spritesheet will have each unit outlined in a box (Colour and size matters not in this version unless we want to implement a side program that will parse out the correct information for the artists.)

On loading an image if the [SpriteSheet] tags are found then it will automatically check for each called image within the spritesheet's definition pulling out the requried frames as needed. This method will require no more parsing overhead then the usual requirements of parsing the data in the config (IE no need to "scan" the image file looking for grids or borders or anything like that. The spritesheet can be packed as tightly as desired by the artist, and even notes left in the file, such as a block of text that says "Attack animation here". Each unit can have more then 1 spritesheet however, they can only have 1 image with an ImageID, this is unique to the unit not the spritesheet file.

Testing

Phase One

I will create a test program that will allow me to make sure that the sprites are being parsed properly. This program will be intergrated and become the spritesheet core of the program. Having this out by itself will allow me to see what sort of difference there is when parsing just the needed gridboxes and the whole sheet. This will allow me to come up with some decent error messages for malformed sprite boxes.

Phase Two

In addition to creating unit tests, I'll try out various hardware to see what sort of performance changes I can detect during the course of getting things working. I'll test on a Quad-core with 8 or more GB RAM, a Dual-core with 4GB RAM, and a 32bit single core with 1-4 GB RAM (I don't have any Macs so I can not test on that and I only have Windows in a VM, so most testing will be done under Linux I'll depend on the various developers that use windows to let me know how it is affecting the running under Windows & Macs)

Deliverables

Status Requirement Level Number ID Goal Defined
Required 1A Properly working Spritesheet cache to speed up loading and elimnate glithy and laging animations do to disk access times.
Required 1B dynamic so that low mem devices are not adversely effected.
Plan A Only! 2 Properly parse spritesheets and quickly be able to pass that information on for each frame.
Required 3A Spritesheets that are flexible and easy for artists and WML users to implement.
Required 3B Spritesheets that do not have a fixed size for every frame they hold.
Plan A Only! 3C Nor a Fixed grid size that holds each frame in its border.
Plan A Only! Optional 3D Not require to have the gridlines or the borders be a particular width (optional, could be axed for performance reasons).
Plan B Only! Optional 3D Not require the borders be a particular width.
Required 4 WML syntax for Spritesheets that is not long, complex, hard to understand, or prone to errors.
Required 5 No negative or negible impact on loading times

Packages Required

Package Name Reason Status
SDL Needed for getting the colour information Plan A required otherwise Not needed
Boost Might be able to provide a performance boost (no pun intended) Optional

13 Week Timeline

Status

Start/End_Dates

Goals

Current March 20 - April 20:
  • Get more details and further flesh out the details of proposal. Create more patches (at least one every 1-2 weeks that is some bug or feature request, something not trival).
  • Get more familiar with Git and GitHub. Be active in the community and encouraging to others that want to create a patch.
Next April 21 - May 18:
  • More details hammered out and continue doing what I'd been doing during Mar 20 - April 20. Perhaps begin a little pre-coding to test theories.
May 19 - June 1:
  • Add a cache for just the spritesheets
    • Here I'll add a spritesheets cache it will be the cache that will hold all the sprite sheets once loaded. It will have to be felxible (in size and what's loaded) and perstant.
June 1 - 15:
  • Add a get_spritesheet_frame function to get the image of the sprite we need right now.
  • Start on the program to generate the WML spritesheet Code.
June 16 - 29:
  • Implement new WML snytax for the spritesheets.
  • Continue on the program to generate the WML spritesheet Code, and have ready to go.
June 23 - 27:
  • Mid-term evaluation, I would like to receive feedback before this point so that if I'm not performing up to par I can work harder/longer.
June 30 - July 13:
  • Modify any existing functions that need to be modified to handle sheets that broke.
July 14 - 27:
  • Run tests and see what breaks and fix what broke
    • Unit tests would have to be added and commited to keep this up and make sure its as robust as I can make it in the timeframe allotted to make it all work.
July 28 - Aug 10:
  • Pad time in case something takes longer then expected
    • Something ALWAYS takes longer then expected or breaks in ways that we didn't expect and only a fool doesn't plan for the worst, so that is what this is, this is my, "OH CRAP" time. Where I have some time to address the parts that take longer or where I work on optional extended tasks like writing a shell/python script to convert all the images to spritesheets.
Aug 3:
  • End of all major code additions/changes, begin of code clean-up and Minor fixes begin.
Aug 11 - 17:
  • Documentation and clean up anything that hasn't yet be done.
Aug 22:
  • Final evaluation and send the required code snippets to Google.

The Weeks in the Program

Week  1:		May 19 to May 25
Week  2:		May 26 to June 1
Week  3:		June 2 to June 8
Week  4:		June 9 to June 15
Week  5:		June 16 to June 22
Week  6:		June 23 to June 29
Week  7:		June 30 to July 6
Week  8:		July 6 to July 13
Week  9:		July 14 to July 20
Week 10:		July 21 to July 27
Week 11:		July 28 to August 3
Week 12:		August 4 to August 10
Week 13:		August 11 to August 17

Optional tasks if everything goes smoother and easier then planed in no particular order:

  • Convert all the sprites, update all the .cfg for the base units
  • Create script to allow Addon Artists convert their sprites

Artists Weigh In

OK, not just for artists, go to http://forums.wesnoth.org/viewtopic.php?f=9&t=40191 and weigh in on the details that effect you as an user! And only those details, and thank you for helping me make Wesnoth a little bit better.

Current Thoughts

To Happygrue

In implementing the spritesheets I am considering storing a vector with the SDC_Rect info (IE {x,y,h,w}) so that when image 5 is needed it pulls out element(5) or element(-1) if the sprites are numbered from 1 instead of 0. My plans for making this work are to create a spritesheet namespace and then when pulling out an image pass the surface (res) into the images_ cache where it will be handled as if it where a single image taken from the disk. In this way I won't have to change anything about how the images are handled for zooming, colouring, etc. But I'm finding that I really should work on getting the WML and parsing of the lua files done first.

I think going with the following tags would be a good way to go;

[Spritesheet]
   File=file_path/name.png
   [Sprite]
       SpriteID=1
       SpriteName="Attack_1"		this an optional feild
       Location=[x,y,w,h]
   [/Sprite]
   -- More Images here
[/Spritesheet]

This differs from the proposal in that the [Image] tag already exists for another purpose, so I changed it to Sprite and changed the rest to match (uniformity and descriptive too) and Cooridante/Location now basically returns an SDL_Rect. [Frame] tags are also already taken in the animation section.

I think that for this to work I need to get the basics in place for the following by mid June.

1) working cache
	a) load the spritesheet into the proper cache
	b) extract and put an unscaled copy into the correct cache (unscaled I think)
2) wml
	a) spritesheet tags 
	b) spritesheet animation syntax
This page was last edited on 23 May 2014, at 01:27.