GameMonkey Script

GameMonkey Script Forums
It is currently Tue Mar 19, 2019 6:53 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Jul 25, 2009 8:43 am 
Offline

Joined: Fri Jul 24, 2009 1:09 pm
Posts: 27
My levels are read from XML files:
Code:
<?xml version="1.0" ?>
<level name="island" width="68" height="50">
    <background_tiles tile_ids="18 18 18 ... " />
    <object_tiles tile_ids="0 0 0 ... " />
    <foreground_tiles tile_ids="0 0 0 ... " />
    <passabilities passabilities="1 1 1 ... " />
    <portals>
        <portal to_level="Levels\\island_cave.xml" from_x="9" from_y="10" to_x="6" to_y="20" />
    </portals>
    <piles>
        <pile pos_x="19" pos_y="12">
            <contents>
                <item_stack qty="3">
                    <item id="0" />
                </item_stack>
            </contents>
        </pile>
        ...
    </piles>
    <music>
        <level_theme file_name="Audio/test.mid" volume="10" loops="0" fade_in="2" force_play="0" />
    </music>
    <triggers>
        <trigger pos_x="9" pos_y="11" script_fn="Scripts/play_music.gm" />
    </triggers>
</level>


Currently, I've got a crude event system going on where only the script file name of the script to be executed is stored. This means that I have to have a corresponding script file for each trigger that I want! The other alternative is to replace the script_fn attribute with a script attribute and just execute the script from a string. The only problem with this is that XML won't preserve indentation and it will look messy regardless.

Anyone have a suggestion for a better way to do this?

Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 25, 2009 10:56 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
I presume you really just want code snippets in XML while longer scripts would be in their own text files.

You might want to use CDATA blocks for your script sections. Indentation of XML is not going to be preserved if you are using various tools to transform the data. Due to the nature of script, you will have to do one of 1) use CDATA 2) use custom script parsing 3) use automatic symbol conversion to keep your data valid and still use things like operator '<'.

You might also want to consider using GM for configuration files. There are pros and cons but it is often quite workable and very flexible.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 25, 2009 11:58 am 
Offline

Joined: Fri Jul 24, 2009 1:09 pm
Posts: 27
Greg wrote:
I presume you really just want code snippets in XML while longer scripts would be in their own text files.

You might want to use CDATA blocks for your script sections. Indentation of XML is not going to be preserved if you are using various tools to transform the data. Due to the nature of script, you will have to do one of 1) use CDATA 2) use custom script parsing 3) use automatic symbol conversion to keep your data valid and still use things like operator '<'.

You might also want to consider using GM for configuration files. There are pros and cons but it is often quite workable and very flexible.
Hmm.. I have thought of using GM for config but it would involve a huge amount of work... I'll have a look at CDATA as I have no idea what it is haha.

Cheers.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 25, 2009 12:23 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
Mitch wrote:
...Hmm.. I have thought of using GM for config but it would involve a huge amount of work... I'll have a look at CDATA as I have no idea what it is haha...

Have a good browse of posts in this forum, it is full of gems. I posted an example of one way to use GM as a config file:
viewtopic.php?f=5&t=250&p=1161&hilit=gmConfigData#p1161
And related...
viewtopic.php?f=5&t=80
viewtopic.php?f=5&t=81&p=240


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 25, 2009 12:58 pm 
Offline

Joined: Fri Jul 24, 2009 1:09 pm
Posts: 27
That last link was especially helpful.. but there is a link inside that thread which is broken; it's just after:
Quote:
Now you may ask how do I get that data from the table into my C++ code?


Also, how fast would GM be loading hundreds of thousands of characters? Since my levels have three layers, a 200x500 level will have 300,000 tile indexes. XML is quite slow to load that many - would GM be any better?


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 25, 2009 1:50 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
I believe that broken link pointed to one of the other links I listed in this thread.

Would it be fast for hundreds of thousands of characters? I'm not sure. Probably not. When it comes to massive data structures, you really need to use platform specific optimized structures. Perhaps even memory mapped in for fast streaming or preloading. I would recommend GM for human readable and editable config files, not for level files. Perhaps use a binary block format or XML which converts to a binary block format as a middle ground between performance and flexible usage.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Group