Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Sat Dec 16, 2017 1:17 am

All times are UTC




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Sun Sep 20, 2009 9:08 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
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:
<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

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
PostPosted: Sun Sep 20, 2009 9:16 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Apr 07, 2008 6:29 pm
Posts: 1872
Location: Czech Republic
Quote:
<property name="RemovalCost" value="10,000">

You would better use a more XML-valid (semantic) syntax:
Code:
<property name="RemovalCost">10000</property>

Or even better:
Code:
<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:
        <labels>
            <label>House</label>
            <label>Residential</label>
        </labels>


Top
   
PostPosted: Sun Sep 20, 2009 10:15 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
CommanderZ wrote:
You would better use a more XML-valid (semantic) syntax:

Thanks for advice. Here's a fixed xml:
Code:
<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>

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
PostPosted: Mon Sep 21, 2009 3:01 pm 
Offline
Engineer
Engineer
User avatar

Joined: Wed Sep 09, 2009 6:36 pm
Posts: 55
Skype: same as y!
Location: Bucharest
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:
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:


Top
   
PostPosted: Mon Sep 21, 2009 10:02 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
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

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
PostPosted: Mon Sep 21, 2009 10:31 pm 
Offline
Engineer
Engineer
User avatar

Joined: Wed Sep 09, 2009 6:36 pm
Posts: 55
Skype: same as y!
Location: Bucharest
Quote:
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 )

Quote:
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.

Quote:
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.

Quote:
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.


Top
   
PostPosted: Tue Sep 22, 2009 10:00 am 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
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

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
PostPosted: Tue Sep 22, 2009 10:14 am 
Offline
Engineer
Engineer
User avatar

Joined: Wed Sep 09, 2009 6:36 pm
Posts: 55
Skype: same as y!
Location: Bucharest
ah sweet then. let me know what changes you do :)


Top
   
PostPosted: Sat Sep 26, 2009 9:54 am 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
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:
<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:
namespace TrackType{
    static int Straight = 0;
    static int Station = 2;
    static int Curve15 = 3;
    // etc...
}


~An00biS

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
PostPosted: Sat Sep 26, 2009 10:39 am 
Offline
Engineer
Engineer
User avatar

Joined: Wed Sep 09, 2009 6:36 pm
Posts: 55
Skype: same as y!
Location: Bucharest
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.


Top
   
PostPosted: Sat Sep 26, 2009 1:21 pm 
Offline
Engineer
Engineer
User avatar

Joined: Wed Sep 09, 2009 6:36 pm
Posts: 55
Skype: same as y!
Location: Bucharest
if you do this in the xml

Code:
<TrackSectionType>Straight</TrackSectionType>


you will read a string. Then you convert it into

Code:
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.


Top
   
PostPosted: Mon Oct 12, 2009 4:56 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Aug 09, 2004 12:14 am
Posts: 1293
Location: Gouda, The Netherlands
How about yaml instead of xml?

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2017 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2017.
Hosted by Zernebok Hosting.