summaryrefslogtreecommitdiff
path: root/docs/packages.txt
blob: f29fbe8c45cf4c4f2f8df3ee41a4786b12481abf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
----------------------------------
AETHYRA PACKAGE SYSTEM
----------------------------------

1. INTRODUCTION
2. LOCATION OF DATA
3. CONTENTS OF DATA PACKAGE
4. TYPES OF DATA
5. INITIALIZING PACKAGE MANAGEMENT
6. LOADING A REQUESTED RESOURCE
7. RESOURCE MANAGEMENT DETAILS

(Note this file is a _little_ outdated in some ways -- kraant)


1. INTRODUCTION

Aethyra (Was The Mana Experiment, originally part of The Mana World) is expected to grow continuously with updates to the game
world occurring relatively frequently. More often so than for example new
releases of the game client. To make sure players don't have to update their
data manually all the time, by for example downloading the latest from the
website, the Aethyra client should be able to automatically obtain new data
packages from the server.

 Note: To reduce the load on the server (which isn't expected to have huge
 free uploading resources), the idea is that the server will only send a
 torrent file to the client and that the file is subsequently downloaded from
 several locations that have volunteered to spread Aethyra data files. Ultimately
 a simple option on the client will even allow players to contribute their
 excess bandwidth to help other players get the updates faster.

(This doesn't seem to have occurred we're still using http all the way
up to now even into Aethyra)


2. LOCATION OF DATA

There are two locations where Aethyra can look for game data. The install data
directory and the data directory in the user's home directory. The latter one
doesn't have to be used for Windows users, but is required for dynamic updates
for UNIX users, who generally won't have write permissions to the install
data directory. So for UNIX the two locations are:

 /usr/local/share/aethyra/data/*

 ~/.aethyra/updates/*

 ~/.aethyra/customdata

While for Windows all the data will be located at:

 C:\Program Files\Aethyra\data\*

In the UNIX case it doesn't matter in which order the data directories are
examined.


3. CONTENTS OF DATA PACKAGE

The contents of the data packages are strictly categorized and all packages
share a single root, similar to the paths on a UNIX system. The name of the
package is irrelevant. An example of the contents is given by:

 /graphics/sprites/forest/pinetree.png
 /graphics/sprites/furniture/bed.png
 /graphics/tiles/dark_forest.png
 /graphics/tiles/city.png
 /music/eagles_are_watching.xm
 /music/silent_rose.xm
 /sound/battle/sword1.ogg
 /sound/battle/sword2.ogg
 /maps/deep_desert.tmx
 /maps/desert_town.tmx
 /tilesets/dark_forest.tsx
 /tilesets/city.tsx
 /scripts/Portal.rb
 /scripts/PawnShop.rb
 /scripts/Fountain.rb


4. TYPES OF DATA

 png - The preferred format for images
 xm  - The preferred format for music (or other kinds of module formats)
 ogg - The preferred format for sound effects
 tmx - The map format (to be implemented)
 tsx - The tile set format (to be implemented)
 rb  - A Ruby script file (application to be discussed)


5. INITIALIZING PACKAGE MANAGEMENT

When Aethyra starts it will scan its data directories for both packages (archives)
and directories. When a directory is found with the same name as a package, the
directory is the preferred location to load data from as it is assumed to be
more up to date.

Each package will have an ID and a file listing associated with it. Having made
a list of all packages they are processed in the order of their IDs. A mapping
is made from file to package, as follows:

 /music/eagles_are_watching.xm  -> /usr/local/share/manaworld/data/musicpack
 /music/silent_rose.xm          -> /usr/local/share/manaworld/data/musicpack
 /sound/battle/sword1.ogg       -> ~/.manaworld/data/patch1
 /sound/battle/sword2.ogg       -> ~/.manaworld/data/patch1
 ...

Because the packages are loaded in the order of their IDs, it is made sure that
each file will always point to the package in which is was last updated. The
package IDs make sure that there is an absolute ordering of the packages.

To allow the client to get rid of old packages, a package can declare an
arbitrary amount of packages with a lower ID than itself as obsolete. These
packages will then be ignored by the client, and optionally they can be
automatically deleted.


6. LOADING A REQUESTED RESOURCE

When the game starts and during the game, resources will continuously be asked
for. A resource manager will take care that each resource is only loaded once.
It also makes sure that the resources are loaded from the right package using
the constructed mapping.

As noted above, the resource manager makes sure directories are preferred
to package files when resources are loaded. The presence of directories is
only expected in the case of developers that will relatively frequently update
the data while working on the next package to be released.


7. RESOURCE MANAGEMENT DETAILS

The resource management technique is critical to the overall success of the
package management system as a whole.  Resources are loaded at runtime as they
are needed, and unloaded as they become unused.  In order to ensure the 
autonomous functioning of this process reference counting is the agreed upon 
technique for managing loaded resources in Aethyra.  

For those unfamiliar with the practice of reference counting, it involves 
every resource object having a variable containing the number of references to
the object. When a reference is added the function addRef() is called and when
it is removed the function release() is called. When the reference count 
reaches zero the object will automatically delete itself, thus handling the 
cleanup of resources.

Reference counting will form the core of the resource management system.  Each
resource object will have the functionality of a reference counted object. The
resource manager will hold ResourceEntry objects.  The resource entry object 
contains a pointer to the resource as well as the location of the path of the 
file the resource was loaded from.  This would look something like:

  /**
   * A generic reference counted resource object.
   */
  class Resource { 
      public:
          /**
           * Loads the resource from the specified path.
           * @param filePath The path to the file to be loaded.
           * @return <code>true</code> if loaded <code>false</code> otherwise.
           */
          virtual bool Load(std::string filePath) = 0;
          ...
          /**
           * Increments the reference counted of this object.
           */
          void addRef() { ++referenceCount; }
 
          /**
           * Decrements the reference count and deletes the object
           * if no references are left.
           * @return <code>true</code> if the object was deleted
           * <code>false</code> otherwise.
           */
          void release() { 
              --referenceCount;

              if(!referenceCount)
              {
                  delete this;
                  return true;
              }

              return false;
          }
      private:
          unsigned int referenceCount;
  };
  ...
  /**
   * A resource entry descriptor.
   */
  struct ResourceEntry { 
      Resource*   resource; 
      std::string filePath; 
  };
  ...

The resource manager would then hold a mapping containing the resource entry as
well as the string defining its resource identification path. The resource 
manager would thus look something like this:

  /**
   * A class for loading and managing resources.
   */
  class ResourceManager {
      public:
          ...
      private:
          std::map<std::string, ResourceEntry> resources;
  };
  ...

This will allow the game to load resources with little awareness of the actual
path from which they were loaded.  The resource manager will also act as a
resource object factory.  A factory object is an object that creates an
instance of an object derived from a common base class.  In this case it will
create Resource objects. This would make the ResourceManager object look like
this:

  /**
   * A class for loading and managing resources.
   */
  class ResourceManager {
      public:
          enum E_RESOURCE_TYPE
          {
             MAP,
             MUSIC,
             IMAGE,
             SCRIPT,
             TILESET,
             SOUND_EFFECT
          };

          /**
           * Creates a resource and adds it to the resource map.
           * The idPath is converted into the appropriate path
           * for the current operating system and the resource
           * is loaded.
           * @param type The type of resource to load.
           * @param idPath The resource identifier path.
           * @return A valid resource or <code>NULL</code> if
           * the resource could not be loaded.
           */
          Resource* Create(const E_RESOURCE_TYPE& type,
                                            std::string idPath);
          ...
      private:
          std::map<std::string, ResourceEntry> resources;
  };
  ...

Loading a resource would then look something like:

  Image* img = (Image*) ResourceManager.Create(ResourceManager::IMAGE,
                                         "/graphics/tiles/dark_forest.png");