[ott3d] Game resources management.

Discussions related to programming Transport Empire.

Moderator: Transport Empire Moderators

Post Reply
ohlidalp
Engineer
Engineer
Posts: 98
Joined: 27 Aug 2007 18:46
Location: mapy.cz/?query=rajhrad
Contact:

[ott3d] Game resources management.

Post by ohlidalp »

I have two ideas regarding resource management in the ott3d branch.

First, I wouldn't use the ogre's default resources.cfg and media.cfg scripts because they make it uncomfortable for the player to download new graphics. Instead, let's dedicate one folder for resources and make the game recursively parse everything in it. Ogre has built-in filesystem acces functions, so no extra libs are necessary.

Second, we need to assign various game-specific attributes to graphical entities, for example checkpoints to rails or weight to vaggons. I suggest using xml files to describe and reference each resource. The game should first parse all the xml-s and then load resources using the obtained data.

This is a sample xml:

Code: Select all

<xml>
<resources version="1"> <!-- Version of the resources file format -->
    <resource type="mesh" name="House" path="house.mesh">
        <property name="Population" value="10">
        <property name="RemovalCost" value="10,000">
        <labels>
            <label name="Structure" />
            <label name="Residental" />
            <label name="House" />
        </labels>
    </resource>

    <resource type="mesh" name="Tree" path="tree.mesh">
        <!-- properties -->
    </resource>

    <!-- and more.... -->
</resources>
</xml>
I'm willing to code both features if they are approved.

~An00biS
Rigs of Rods maintainer.
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: [ott3d] Game resources management.

Post by CommanderZ »

<property name="RemovalCost" value="10,000">
You would better use a more XML-valid (semantic) syntax:

Code: Select all

<property name="RemovalCost">10000</property>
Or even better:

Code: Select all

<properties>
    <RemovalCost>10000</RemovalCost>
</properties>
Or maybe combine the last two options (wrap the first in tag properties)

Attributes should carry only some additional data related to the main tag data. The real data should be carried by the tag content.

And code-wise all the ways are mostly equivalent (I even think the most correct option is easiest to code)

I the same way:

Code: Select all

        <labels>
            <label>House</label>
            <label>Residential</label>
        </labels>
ohlidalp
Engineer
Engineer
Posts: 98
Joined: 27 Aug 2007 18:46
Location: mapy.cz/?query=rajhrad
Contact:

Re: [ott3d] Game resources management.

Post by ohlidalp »

CommanderZ wrote:You would better use a more XML-valid (semantic) syntax:
Thanks for advice. Here's a fixed xml:

Code: Select all

<xml>
<resources version="1"> <!-- Version of the resources file format -->
    <resource type="mesh" name="House" path="house.mesh">
        <population>10</population>
        <removal-cost>10,000</removal-cost>
        <labels>
            <label>Structure</label>
            <label>Residental</label>
            <label>House</label>
        </labels>
    </resource>

    <resource type="mesh" name="Tree" path="tree.mesh">
        <planting-cost>150</planting-cost>
        <removal-cost>500</removal-cost>
        <labels>
            <label>Vegetation</label>
            <label>Tree</label>
        </labels>
    </resource>

    <!-- and more.... -->
</resources>
</xml>
Rigs of Rods maintainer.
User avatar
lonwolf89
Engineer
Engineer
Posts: 55
Joined: 09 Sep 2009 18:36
Skype: same as y!
Location: Bucharest
Contact:

Re: [ott3d] Game resources management.

Post by lonwolf89 »

An excellent idea. I never really bothered to change the resource management, just used .cfgs to configure various game aspects.

i would just need 2 things clarified:
1. how does the improved resource management affect the download of the game. You want to put all files in 1 folder? That would work for the release version of course and it's a good idea.( but for me while coding and managing new files (adding, removing, changing) it would be way fast to have them categorized on the base directory tree.)

2. i used xmls with the OgreOSM loader (files exported by oFusion for ogre) and workes with tinyXml in that plug-in lib. Every entity does need a custom description (like in your example).
A suggestion for tracks:
entity base name (adding 1,2,3, etc dynamically in-game with a counter), mesh name, type (forward, curved15, curved30, etc, junctionTypeY or any other types), number of checkpoints(1 line tracks have 4, 2 main, 2 secondary so 2 pairs), list of checkpoints (for 1 line tracks - no junctions - 4 vector3 data types - as pairs), cost of placing, cost of removing.
This data should be parsed to an instance of a class: e.g.

Code: Select all

class RailTrack
{
public:
     //constructor (to read data from xml using a "xmlManager" class), destructor( to delete dynamical data - vectors) etc
     //make the data public (or if needed return_functions (getBuildCost() for example))
Entity *mEntity;
OT33DTrackType mTrackType;
unsigned short mCheckpointNumber;
std::pair<std::vector<Vector3>,std::vector<Vector3>> mCheckpointsVector; //it's length is mCheckpointNumber /2;
// or use std::vector<Vector3> mCheckpointsVector; with a total length equal to mCheckpointNumber
// i could script the code to use any of those variations.

Ogre::Real mBuildCost;
Ogre::Real mDemolishCost;
};
Besides the build costs, it has everything it needs so i can script it nicely with the "buildTracks" tool.

So you have a go from me to start writing the xml management of the game. :mrgreen:
And let me know when it's ready to be scripted in the main version so i don't have to hardcode everything :lol:
ohlidalp
Engineer
Engineer
Posts: 98
Joined: 27 Aug 2007 18:46
Location: mapy.cz/?query=rajhrad
Contact:

Re: [ott3d] Game resources management.

Post by ohlidalp »

lonwolf89 wrote:You want to put all files in 1 folder?
In one folder and it's subfolders; the game will recursively parse everything. So, the player can organize his downloads in any way he wants and it'll still work.
lonwolf89 wrote:...i used xmls with the OgreOSM loader...
I'd prefer to have a single format for all models. If you'd like to use this tool, I can write a converter.
lonwolf89 wrote:A suggestion for tracks:
entity base name (adding 1,2,3, etc dynamically in-game with a counter)
I'd prefer not to change any attributes in the code, it would only mess things up IMO. If you'd like to do it anyway, please explain why. To to organize the tracks in any way, I suggest using custom entity attributes instead of mesh name.
lonwolf89 wrote:(forward, curved15, curved30, etc, junctionTypeY or any other types)
You'd rather not use statically defined track types, it limits adding new types. Try designing something dynamic. Also, please explain what those types mean, i.e. what's 15, 30, etc...

~An00biS
Rigs of Rods maintainer.
User avatar
lonwolf89
Engineer
Engineer
Posts: 55
Joined: 09 Sep 2009 18:36
Skype: same as y!
Location: Bucharest
Contact:

Re: [ott3d] Game resources management.

Post by lonwolf89 »

I'd prefer not to change any attributes in the code, it would only mess things up IMO. If you'd like to do it anyway, please explain why. To to organize the tracks in any way, I suggest using custom entity attributes instead of mesh name.
it needs a suffix for 2 reasons: 1.) 2 entities can't have the same name. 2.) entity names (part of the prefix is a vital key to determine what a ray hit; in the most simplest and effective way.)
When you script the xml you create a "prefab" for it. that's a template on which the other duplicates will "mold" on. And the duplicates can't have the same name, and you do not know their number since they are created dynamically (creating a xml entry for all the houses that have the same proprietes except the entity name sounds a waste of time and memory don't you think? :P )
You'd rather not use statically defined track types, it limits adding new types. Try designing something dynamic. Also, please explain what those types mean, i.e. what's 15, 30, etc...
you need to identify them in the code also.. As far as i'm concerned there is no way to declare an "enum" dynamically. You can specify the type in .xml but code-wise you still need to compare the type from .xml with something! (enum, string, whatever). So that's the same problem. Each track different type (e.g. straight lines compared to junctions) would need separate cases in some algorithms. I can't really think of a method that allows you just to script everything by reading something new from an xml file and not adding some cases in the code.... (adding construction button, automatically be accepted by pathfinding and autoFit algorithms and so on) by not knowing it's type.

15,30, etc, that's the curved section angle in degrees.
I'd prefer to have a single format for all models. If you'd like to use this tool, I can write a converter.
no, that was just my "previous experience with tinyXML" a new one designed for this game is required of course.
In one folder and it's subfolders; the game will recursively parse everything. So, the player can organize his downloads in any way he wants and it'll still work.
that's kinda the thing with the media folder now.. (the only one) and it contains folders with models, textures, sounds, cg programs, etc.. i don't get what you want to change.
ohlidalp
Engineer
Engineer
Posts: 98
Joined: 27 Aug 2007 18:46
Location: mapy.cz/?query=rajhrad
Contact:

Re: [ott3d] Game resources management.

Post by ohlidalp »

lonwolf89 wrote:that's kinda the thing with the media folder .... i don't get what you want to change.
Right now you have to add every resource dir into resources.cfg, manually. I suggest loading everything automatically from the Media folder. It's a small change allright.

~An00biS
Rigs of Rods maintainer.
User avatar
lonwolf89
Engineer
Engineer
Posts: 55
Joined: 09 Sep 2009 18:36
Skype: same as y!
Location: Bucharest
Contact:

Re: [ott3d] Game resources management.

Post by lonwolf89 »

ah sweet then. let me know what changes you do :)
ohlidalp
Engineer
Engineer
Posts: 98
Joined: 27 Aug 2007 18:46
Location: mapy.cz/?query=rajhrad
Contact:

Re: [ott3d] Game resources management.

Post by ohlidalp »

I've improved my knowledge of OGRE's resource management and changed my proposed designs.

Resources:
I'll not tie resource loading and game-object management together. I'll make ogre load resources the standard way and subsequentially organize them into game-entities. We'll keep ogre's resources.cfg file, but I'll make the game to parse every directory recursively. So, defining the Media directory will be enough for most people (default cfg file), devs can add their own resources and locations.

Game entities
All game-specific objects (Track sections, structures, vehicles etc..) will be reffered to as "items" and derived from a common "Item" class. Items will be defined using xml file(s) and parsed wigh "ItemManager" class. I'm adding "Item.h" and "Item.cpp" for this purpose.

Code: Select all

<xml>
<!-- "Items": Root element of items file. -->
<!-- Contains elements defining individual item types -->
<!-- This example shows all possible types -->
<!-- "version": Version of the file format (integer) -->
<Items version="1">
    <RailroadTrackSection>
        <Name>Straight Track</Name>
        <Mesh>StraightTrack.mesh</Mesh>
        <TrackSectionType>Straight</TrackSectionType>
        <BuildCost>100</BuildCost>
        <DemolishCost>-50</DemolishCost>
        <!-- Checkpoints allow snapping sections when building track -->
        <!-- Various track section types require various sets of checkpoints -->
        <Checkpoints>
            <Checkpoint x="0" y="1" z="2"></Checkpoint>
            <Checkpoint x="5" y="6" z="7"></Checkpoint>
        </Checkpoints>
    </RailroadTrackSection>

    <!-- More to come... -->
</Items>
</xml>
[Edit] I also suggest identifying track types and item types by ints instead of enums. Ints can be defined dynamically and seem more forward-compatible to me. This is how I would do it:

Code: Select all

namespace TrackType{
    static int Straight = 0;
    static int Station = 2;
    static int Curve15 = 3;
    // etc...
}
~An00biS
Rigs of Rods maintainer.
User avatar
lonwolf89
Engineer
Engineer
Posts: 55
Joined: 09 Sep 2009 18:36
Skype: same as y!
Location: Bucharest
Contact:

Re: [ott3d] Game resources management.

Post by lonwolf89 »

sweet. it will need some linking with construction manager.

i also created a temporary class named railtrackmanager, but it should be replaced by the item manager.

also, i have used enumerations to determine track type. after the xml scripting is done to implement with the current code (not the svn one now :P) those enumerations need to be replaced with strings read from the xml.
User avatar
lonwolf89
Engineer
Engineer
Posts: 55
Joined: 09 Sep 2009 18:36
Skype: same as y!
Location: Bucharest
Contact:

Re: [ott3d] Game resources management.

Post by lonwolf89 »

if you do this in the xml

Code: Select all

<TrackSectionType>Straight</TrackSectionType>
you will read a string. Then you convert it into

Code: Select all

namespace TrackType{
    static int Straight = 0;
    static int Station = 2;
    static int Curve15 = 3;
    // etc...
}
.... it's the same as using enums (the advantage is that enums are easier to handle and the code is cleaner. You can check that lots of the types in ogre are also used with enums only, not like that).

If you want to improve the current system, you would need to replace enums with Ogre::String and make a vector / collection / namespace with them. That removes the enumeration from between. After i commit the latest version, take a look on how the track type is read and added to the enum.
User avatar
Expresso
Tycoon
Tycoon
Posts: 1760
Joined: 09 Aug 2004 00:14
Location: Gouda, the Netherlands

Re: [ott3d] Game resources management.

Post by Expresso »

How about yaml instead of xml?

It's easier to parse for both humans and computers.
Post Reply

Return to “Transport Empire Coding”

Who is online

Users browsing this forum: No registered users and 2 guests