SummerOfCodeProposal lfernando

From The Battle for Wesnoth Wiki
Revision as of 16:29, 11 April 2010 by Lfernando (talk | contribs) (Example)


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



This is a Summer of Code 2010 student page
Project: SoC Ideas Persistent Gameworld


Contents

Description

lfernando - Implement persistent storage of gameworld data between semi-related scenarios

The general idea of this project is introducing variables that are independent from savefiles and campaign lines. They will be accessible from any context and not lose validity once a particular game/campaign has ended. We'll call them global variables.

Global variables will be stored and retrieved using two special tags, [get_global_variable] and [set_global_variable]. They should be used on scenario WML, and their usage will allow that variables, as defined by the [set_variable] family of tags, (from now onwards we will call those ones "local" variables) should be saved to/loaded from an external source.

I'm planning to store global variables on simple wml files with syntax borrowed from uncompressed saves. Each add-on will have its own set of variables, and its own file for global variables.

IRC

lfernando

SoC Application

Implement persistent storage of gameworld data between semi-related scenarios

Questionnaire

Basics

Write a small introduction to yourself.

My name is Luiz Fernando and I'm a 23 years old programmer/gamer/graduate student.

State your preferred email address.

lucifernando@gmail.com

If you have chosen a nick for IRC and Wesnoth forums, what is it?

lfernando

Why do you want to participate in summer of code?

I'm very eager to get involved with the open source world and I want to know how it is to contribute in a big project used by many, many people. GSoC seems like a rewarding way to join an open source project.

What are you studying, subject, level and school?

I'm a master student on UNICAMP(University of Campinas) where I graduated two years ago. My research subject is graph theory.

What country are you from, at what time are you most likely to be able to join IRC?

I'm from Brazil(UTC-3) and I may be able to be on IRC mostly any time of the day on weekdays. IRC meet times should mostly depend on my mentor's time schedule.

Do you have other commitments for the summer period ? Do you plan to take any vacations ? If yes, when.

I just took a week-long vacation on the last week of March, so I don't plan to take any longer break until September. And besides, we have winter here in Brazil on the June - August period =).

Experience

What programs/software have you worked on before?

I've worked on a music technology institute inside my university called NICS, where I started development for a music experimenting tool/improviser called Chord Jammer. Also, I fixed some bugs for a project called Javox. Both projects were implemented on Java and can be found at www.nics.unicamp.br.

Have you developed software in a team environment before? (As opposed to hacking on something on your own)

On Chord Jammer I worked solo for the majority of the time, so I never really participated in a project with more than 10 members on it. Working in a big project, maintained by many people worldwide, that appealed on me greatly when I first thought of applying to SoC and diving in an open source project.

So, why not that FLOSS game that I already knew and enjoyed? ;)

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?

Never participated on any Summer of Code project.

Are you already involved with any open source development projects? If yes, please describe the project and the scope of your involvement.

My first experience with open source is Battle for Wesnoth.

Gaming experience - Are you a gamer?

Yeah!

What type of gamer are you?

Well, I play videogames since I was a little kid(the first game I remember playing was megaman 4 on NES when I was 5 years old). I kept playing until now, so I guess I'm some avid gamer =P. Heck, even while I was fixing the bugs, lots of times I would just take a break and resume playing Httt =P.

What type of games?

Fighting games(Street Fighter, Soul Calibur), strategy games(BfW, Warcraft, Age of Empires, Civilization), rpg's(Final Fantasy series, Chrono Trigger, Fallout, World of Warcraft, lots of other japanese rpgs), action games(Mario, Castlevania), shooters (Half-Life, Quake),

What type of opponents do you prefer?

The clever, unpredictable ones.

Are you more interested in story or gameplay?

Tough question! But I guess videogames are all about "playing", and some games don't even have a discernible story, so I'll choose gameplay. But some games(Fallout 1/2, Breath of Fire 2, Final Fantasy VII, Mother 3) grabbed me for the story alone if not for the great gameplay.

Have you played Wesnoth? If so, tell us roughly for how long and whether you lean towards single player or multiplayer.

I played mainly singleplayer campaigns on Wesnoth.

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 SVN (during the evaluation period or earlier) please state so.

Fix for bug #14114, on patch #1538.

Reported minor bug #15601, and fixed it on patch #1525.

Implemented a small example regarding the persistency idea, recorded on http://wesnoth.pastebin.com/g1hMez2J.

3) Communication skills

Though most of our developers are not native English speakers, English is the project's working language. Describe your fluency level in written English.

I'm not a native, but I think my english reading/writing skills are on a good level.

What spoken languages are you fluent in?

Portuguese and English.

Are you good at interacting with other players? Our developer community is friendly, but the player community can be a bit rough.

Yes, I prefer when the conversation is enjoyable, but I can handle angry complaining and trolling too if needed.

Do you give constructive advice?

Of course.

Do you receive advice well?

I think so. If it's the advice is constructive, I'm very attentious.

Are you good at sorting useful criticisms from useless ones?

Yes.

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?

If it's a very simple task I'll do it myself. If it's not the expected result, I'll just redo it the right way.

If it's a bit more complicated, sometimes I'll sketch my idea in an example piece of code or some template files. Then I'll discuss it until I have a clear idea of what to do. Then I'll code it until it is implemented. Of course, doubts and questions arise as the project flows, and I'm eager to ask them as soon as I can.

Project

Did you select a project from our list? If that is the case, what project did you select? What do you want to especially concentrate on?

See project description.

Why did you choose this project?

First of all because I enjoyed playing the game =). Also, it is "minimalist" and has concepts which are very simple to grasp. That suggested some kind of elegance. The community is really friendly and present and answered my begginer questions promptly. And finally, when I downloaded the source and started studying it, it felt like it was made by folks with a firm grasp of C++ and I could learn a lot if I could understand the code and hack through it.

Include an estimated timeline for your work on the project. Don't forget to mention special things like "I booked holidays between A and B" and "I got an exam at ABC and won't be doing much then".

More on that on the project description.

Right now, I'm not enrolled to school disciplines, and I don't have any exams to make. My only time-expensive activity is my Master thesis. I'll keep working on my thesis, but I plan to finish it only by the end of the year. So while I'm on this project, it'll be first priority to finish it on time.

Include as much technical detail about your implementation as you can

See below.

What do you expect to gain from this project?

Having fun with open source development. Learning how to work with many people on a big software project. C++ Enlightenment. =)

What would make you stay in the Wesnoth community after the conclusion of SOC?

Well, I guess that after you start developing, things just aren't the same again. When you see a bug it's not "Cr**, another bug screwed my game. I hope they fix it on next patch." anymore. Your attitude becomes more hands-on, you know you can try fixing it if you want to.

As for me, it's too early to say. My first impression of the community was very good, though. Also, the code definitely has some programming depth, and I could say I was having fun while I was fixing the bugs. So, that could convince me to lend some more work here whenever I want to help an open source community.

Practical considerations

Are you familiar with any of the following tools or languages?

   * Subversion (used for all commits)

Yes.

   * C++ (language used for all the normal source code)

Yes.

   * STL, Boost, Sdl (C++ libraries used by Wesnoth)

STL and some Boost. Never worked with Sdl before.

   * Python (optional, mainly used for tools)

Wrote mostly little programs with it. Seems a really well designed language, eager to use it more on the future.

   * build environments (eg cmake/autotools/scons)

I know SCons and Autotools. Am using SCons to compile Wesnoth builds as for now.

   * WML (the wesnoth specific scenario language)

Started learning it and guess I know it well enough to understand this problem.

   * Lua (used in combination with WML to create scenarios)

No.

Which tools do you normally use for development? Why do you use them?

Eclipse. Gedit for programming in the small.

What programming languages are you fluent in?

C, C++, Java.

Would you mind talking with your mentor on telephone / internet phone? We would like to have a backup way for communications for the case that somehow emails and IRC do fail. If you are willing to do so, please do list a phone number (including international code) so that we are able to contact you. You should probably *only* add this number in the application for you submit to google since the info in the wiki is available in public. We will *not* make any use of your number unless some case of "there is no way to contact you" does arise!

Yeah! You can have my cell phone number and call me when any problem arise. You can have my family house number too, but if you want to call it'd be better be really important because my mother can't understand any english! =-D

Project Description

Overview

The general idea of this project is introducing variables that are independent from savefiles and campaign lines. They will be accessible from any context and not lose validity once a particular game/campaign has ended. We'll call them global variables.

Global variables will be stored and retrieved using two special tags, [get_global_variable] and [set_global_variable]. They should be used on scenario WML, and their usage will allow that variables, as defined by the [set_variable] family of tags, (from now onwards we will call those ones "local" variables) should be saved to/loaded from an external source.

I'm planning to store global variables on simple wml files with syntax borrowed from uncompressed saves. Each add-on will have its own set of variables, and its own file for global variables.

On multiplayer, we desire to support two different uses for global variables. The first would be player persistency, where you store the desired data in one(or all) of the players user data.

For example, you could use it to have an RPG-style UMC. You start with a hero, and you make adventures with him/her. The next time you started playing, your hero would be there, along with any items he had and quests he did. And since this data would be stored in your computer, when you joined games with different players, you could reuse the same hero that you developed from previous games.

Conceptually, MP player persistency is very similar to SP persistency. So, other than handling OOS errors and some MP specific problems, implementing MP player persistency from SP persistency would be fairly straightforward.

The other goal of this project is to not only make users, but also multiplayer scenarios capable of handling persistent storage. This kind of MP persistency involves data being with the "map", instead of with the "players". We will call it MP playerless persistency, and it should allow a kind of scenario that "changes" as different users play it.

Here is an example of this kind of application by Crab_:

"Imagine a game where there's a 'game master' - who creates a scenario, where you, for example, as a captain of a royal army, play for loyalists vs orcs. and then, if you win, the 'game master' changes the 'geopolitical map' to represent the fact that the border was defended, and orcs were defeated. Or imagine several games played in parallel, where you can transition from one game to another 'right-in-the-middle' (e..g, the gamemaster can store your units in one game and spawn them in another). and, it will not be hardcoded in c++ code. Every rule, every fantasy, can be achieved in wml, if we give a 'language' for it and implement engine support. "

So, my project would be to:

  1. Implement SP persistency.
  2. Implement MP player persistency.
  3. Implement MP playerless persistency.

WML Syntax

Here goes a sample specification for the syntax of [load_global_variable] and [store_global_variable] as suggested by Crab_.

 [get_global_variable]
   side=1
   namespace=my_addon
   from_global=my_variable_name
   to_local=foo
 [/get_global_variable]
 [set_global_variable]
   side=1
   namespace=my_addon
   from_local=my_variable_name
   to_global=foo
 [/set_global_variable]
 [clear_global_variable]
   side=1
   namespace=my_addon
   global=foo
 [/clear_global_variable]


[get_global_variable]

Creates a local variable from the value of a global variable.

  • side: Relevant only in MP. Determines which player on MP will do the load operation.

On default, the player is the one who's playing the turn. There should be a special side value for storing data on the server/gamemaster.


  • namespace: Used for determining from which file this variable should be loaded.

As for now, we want to use different namespaces for different add-ons, and different files for different namespaces. On default it should write to the file of the add-on being played. But we want to maintain flexibility, especially regarding the "default" namespace, which should store the "real global" variables.

It still can support things like "On add-on A, load this variable from add-on B and save it on add-on C." But it should be some kind of "unholy" operation and not be encouraged unless you really know what you're doing. =)


  • from_global: Determines the name of the global variable that is loaded.
  • to_local: Determines the name of the local variable that receives the loaded value.

[set_global_variable]

Stores a local variable as a global variable.

It has the same syntax as [load_global_variable], except for noting that it stores local variable named from_local to a global variable named to_global.

[clear_global_variable]

Deletes a global variable with name foo.

Sample File

Global variable files should have very simple wml syntax. Here goes an example:

 [variables]
   tutorial_completed=1
   betrayed_darken_volk=1
   dragons_slain=2
   crafted_scepter=0
   king_of_wesnoth=1
   ...
 [/variables]

Playerless Persistency and the Gamemaster

Implementing SP and MP player persistency is just a matter of recording game values somewhere. Implementing MP playerless persistency, however, is trickier, since we need another place to store our data which is not on user data.

We plan to make a MP bot called a gamemaster. It can create games on demand, and watch their status. So, we want to make the GM able to launch several "headless" wesnoth instances on MP.

Storing the data in simple WML files as we want to do on SP and player MP persistency can lead to some problems. Most of them are related to concurrent operations. If more than one game writes to a same file, it could lead to possible mismatches if it is not handled properly. So one solution would be handling concurrent operations in a ad-hoc way, making special code to deal with it.

A better one would be using a database to store the variables. So, on GM mode launch, we would simultaneously launch a database, and all data operations that concern the gamemaster player would be done on this database. A relational or key-value database would do the trick here.

So, this "gamemaster" here is less of a guy who interferes with the gameworld ("Behold! All goblins were turned to frogs by the Gamemaster!") and more like a special observer that can record game values. The interefering gamemaster is already supported and made possible by the events engine.

Example

So, suppose we want to host that world war add-on. We have 3 scenarios:

  • RebelsxDrakes.cfg
  • LoyalistsxNortherners.cfg
  • KnalganxUndead.cfg

First I launch wesnoth on gamemaster mode.

  • ./wesnoth --gm

That launches the database too. And once I connect on the MP server, my GM will connect as well.

  • lfernando joins the lobby.
  • lfernando-GM joins the lobby.

So, I ask my GM to create a couple of games.

  • lfernando: /w lfernando-GM create KnalganxUndead.cfg
  • lfernando: /w lfernando-GM create RebelsxDrakes.cfg

This idea is still subject to further changes, and we want to fine-tune the details as we discuss it more.

Project Schedule

We are imagining this project implementation happening in three separate phases:

Phase one should be the implementation of persistency WML for singleplayer.

Phase two should be the extension of that for multiplayer.

Phase three should be the implementation of the "playerless persistency" via the gamemaster concept.

So, more specifically, phase one will happen in the beginning of the project alongside with the studying of WML and wesnoth code by the candidate. Especially code for WML implementation and save games file structure. That should take roughly three weeks.

Implementation of phase two will happen afterwards, and should be done at the same time that we resolve any bug or issue left from phase 1. Phase two should take roughly three weeks too.

Finally, there are some scenario makers interested for the content for phase 3. In the middle of playerless persistency implementation, we'll contact them and try to build a scenario that uses this concept. It should work as both a showcase and a testcase for our ideas. Phase three should be the most time expensive one, featuring a lot of dish cleaning and feature polishing. It should take about one month and a half or two to get it done.

So, for a timeline, we should expect something along this way:

  • April 26 - May 17: Make persistence work for singleplayer.
  • May 15 - June 4: Make persistence work for multiplayer.
  • June 6 - August 6: Finish the gamemaster for MP. And maybe some MP scenario using the work done if we have the time/help.

Luiz Fernando