gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS homebrew announcements > COW - OS platform library

#138730 - Vich - Tue Aug 28, 2007 11:13 am

I would like to announce COW to you. This project is a C++ GPL'ed platform-independant platform library. It compiles with Visual Studio, makefile and SCons. It has been verified to compile for Windows, Linux and the DS.

COW offers a set of features including(but not limitted to):
- RTTI and serialization(XML, later also binary with conversion tools from&to)
- FixedPointMath template class that has conversion accessors for float/int conversion. Should work as fast as the defines from libnds, but is a lot more friendly to use.
- (Serializable) Storage types to replace STL. This saves LOTS of executable size. (array, list, dlist, string)
- (Serializable) Metrics and vector classes with the expected operators.
- A few bit operators.
- Handy 'tools' like AutoPtr, platform-independant asserts
- Pattern templates like Singleton and Factory
- A streaming system: filestream, stringstream, memorystream and more. This system allows uniform file handling and stream opening (eg. StreamManager::OpenStream("file://file.txt", [read/write mode])
- ImageReaders for different image file formats that can read image data from any kind of stream input to pixel data.
- etc.


COW also includes platform-independant unit tests, which help a lot during development.
It also includes a tutorial project with small sample applications that are well-documented.

The current project state is beta and although the code design might still change slightly, I think it is already grown-up enough to be shared among you. I'll be happy to fix bugs for you if you chose to use my library and post the bugs here.

A self-modified version of TinyXML(to make use of my own containers) is used for serialization, since this is the smallest XML library that I can find. I think that you will find the speed of serializing from/to XML very fast. I will make a binary serialization system later to make things even quicker, but at the moment I'm too busy with other matters to do this.

Project page:
http://www.lifeisdigital.net/index.php?page=projects/cow
(you find more up-to-date info here)
Source-forge page:
http://sourceforge.net/projects/cow
Get the files with SVN:
svn co https://cow.svn.sourceforge.net/svnroot/cow cow

Browse the source code:
http://cow.svn.sourceforge.net/viewvc/cow/trunk/Source/COW
Browse the demo source code(UnitTests and Tutorials are interesting):
http://cow.svn.sourceforge.net/viewvc/cow/trunk/Demos/Source/
The tutorials are still being worked on, but the UnitTest project also 'explains' quite a few features.

Got questions/suggestions/bugs? Please post them here!
_________________
[project website] [personal website]


Last edited by Vich on Tue Sep 25, 2007 8:59 am; edited 1 time in total

#138735 - Schyzophrenic - Tue Aug 28, 2007 12:05 pm

This is a great idea ! I am looking forward to seeing new versions !

I'll test it as soon as I can. It sounds really great !

#138736 - Vich - Tue Aug 28, 2007 12:24 pm

Schyzophrenic wrote:
This is a great idea ! I am looking forward to seeing new versions !

I'll test it as soon as I can. It sounds really great !


Thanks ^^;
I've spent quite a few years developping this, so I really hope it can be useful to someone else but me. This project was split off from the AlterNova project(2d/3d gfx engine) and it use used in the TINA project(GUI library). Both are also cross-platform(Win/Lin/DS) and OS, but still in alpha stage.

Addendum:

TINA serialization can looks like this with COW:
Code:

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Serialization data, created by COW -->
<object_list>

   <object type="ImageTemplate" version="1" name="image_template">
      <members>
         <control_type>"Image"</control_type>
      </members>
   </object>

   <object type="Image" version="1" name="logo">
      <members>
         <metrics>(0,200)(1024,256)</metrics>
         <texture>"data/logo.tga"</texture>
         <template>[image_template]</template>
      </members>
   </object>

   <object type="Image" version="1" name="title">
      <members>
         <metrics>(0,336)(1024,8)</metrics>
         <texture>"data/textures/title.tga"</texture>
         <template>[image_template]</template>
      </members>
   </object>

   <object type="TextLabel" version="1" name="program_title_text">
      <members>
         <metrics>(0,0)(128,16)</metrics>
         <caption>"Program title. All rights reserved."</caption>
         <color>#FFFFFFFF</color>
      </members>
   </object>

</object_list>


_________________
[project website] [personal website]

#138737 - kusma - Tue Aug 28, 2007 12:37 pm

This seems like a library of really useful tools. Good work! I especially love the serialization support!

Sorry if this part seems negative, but here's some potential issues I saw after a quick code-browse:

  • BreakPointMessage: This function seems to assume that a console is running in the NDS-builds. Assertion are usually expected to terminate the program - how about just initializing the console fully before displaying the error-message?
  • FpNumber-constructors should be made explicit to prevent unexpected code-paths for float-code.
  • FpNumber : "Fp" is commonly used to denote "floating point", How about FixedNumber instead?
  • Singleton: Argh, people of the world: stop encouraging this fundamentally flawed pattern. Globals are globals, no matter if they are hidden "inside" an object! :P
  • GPL : IMO wrong license for a library of this nature. You might disagree, this is politics I guess.

#138739 - Vich - Tue Aug 28, 2007 12:52 pm

kusma wrote:
This seems like a library of really useful tools. Good work! I especially love the serialization support!

Sorry if this part seems negative, but here's some potential issues I saw after a quick code-browse:

  • BreakPointMessage: This function seems to assume that a console is running in the NDS-builds. Assertion are usually expected to terminate the program - how about just initializing the console fully before displaying the error-message?

Good point. I will make a system that tells the state of the COW initialization. (what was initialized and what wasn't)

Quote:
  • FpNumber-constructors should be made explicit to prevent unexpected code-paths for float-code.
  • FpNumber : "Fp" is commonly used to denote "floating point", How about FixedNumber instead?

  • I will fix both name and ctors. (wasn't happy with the name either, but I couldn't find anything better ... I suck at finding good names sometimes :P)

    Quote:
  • Singleton: Argh, people of the world: stop encouraging this fundamentally flawed pattern. Globals are globals, no matter if they are hidden "inside" an object! :P

  • Hey, I had a phase, ok? :P
    I made it and used it and then just made static classes of the singletons I had. I just keep it just in case I ever need it again.

    Quote:

  • GPL : IMO wrong license for a library of this nature. You might disagree, this is politics I guess.

  • The older versions used to be LGPL. LGPL or other licenses will become available in the future at a cheap price. I spent about 4 years of spair time in my life to this and I think it's a shame if someone uses all that code without contributing anything to OS. So: yes, it will eventually be possible to use it for non-OS software, but at a (very fair) price. Probably something like the Bass library does(un4seen.com).

    As for the apologize: that's absolutely not needed, I appreciate your feedback very much.
    _________________
    [project website] [personal website]


    Last edited by Vich on Tue Aug 28, 2007 1:16 pm; edited 1 time in total

    #138743 - kusma - Tue Aug 28, 2007 1:13 pm

    Vich wrote:
    The older versions used to be LGPL. LGPL or other licenses will become available in the future at a cheap price. I spent about 4 years of spair time in my life to this and I think it's a shame if someone uses all that code without contributing anything to OS. So: yes, it will eventually be possible to use it for non-OS software, but at a (very fair) price. Probably something like the Bass library does(un4seen.com).

    Sure, I see your point. The problem I can see with it, is that it sets strict limitations to the licenses of the application using your library, thus it might limit your user base beyond what's needed to ensure what you seem to wish. I don't have any concrete suggestions to alternatives though, picking the right license is always tricky.

    #138744 - Vich - Tue Aug 28, 2007 1:21 pm

    kusma wrote:
    Sure, I see your point. The problem I can see with it, is that it sets strict limitations to the licenses of the application using your library, thus it might limit your user base beyond what's needed to ensure what you seem to wish. I don't have any concrete suggestions to alternatives though, picking the right license is always tricky.


    Well, I suppose it's more like a religion than politics. 'I believe' that if you develop non-commercial software, there shouldn't be a problem with publishing the source under GPL license(except that one might be ashamed of the quality).
    If someone makes a commercial benefit then it shouldn't be a problem to pay a very reasonable fee for a library. But that's just my opinion of course.

    I see of it more as sharing knowledge: I don't mind sharing my knowledge, as long as others don't mind sharing theirs. If people want to avoid this, they can always make a settlement with me by helping me to improve my hobby projects even further and donating a fee(and thus contributing in another way). (And the fee is probably the political part :P)

    But let's not start a license discussion here. For now it will be GPL-only, but that might change in the future. (I just felt like I should share my way-of-thinking here)
    _________________
    [project website] [personal website]

    #138745 - Payk - Tue Aug 28, 2007 1:28 pm

    neat! happy to see it growing.

    #138761 - tepples - Tue Aug 28, 2007 8:06 pm

    Vich wrote:
    'I believe' that if you develop non-commercial software, there shouldn't be a problem with publishing the source under GPL license(except that one might be ashamed of the quality).

    There exist free software licenses that are free but incompatible. For example, anything that uses Lick's RAM access library or Lick's rebooting library cannot be published under the GNU General Public License because Lick's license is not GPL compatible, which I have explained in this post.

    EDIT: Now a bad example, given that Lick's libraries are now MIT licensed. Substitute the Apache license and versions of the GNU General Public License prior to version 3.
    _________________
    -- Where is he?
    -- Who?
    -- You know, the human.
    -- I think he moved to Tilwick.


    Last edited by tepples on Wed Sep 12, 2007 11:34 am; edited 1 time in total

    #138770 - Vich - Tue Aug 28, 2007 11:57 pm

    kusma wrote:
    [*]BreakPointMessage: This function seems to assume that a console is running in the NDS-builds. Assertion are usually expected to terminate the program - how about just initializing the console fully before displaying the error-message?

    I fixed it. I made an option to disable/enable asserts in general. This might also be handy for debugging when there are a few hundreds of asserts when you only need to see one or a few in a specific place in the code.

    Quote:

    [*]FpNumber-constructors should be made explicit to prevent unexpected code-paths for float-code.

    Could you clarify that with a sample?

    Quote:
    [*]FpNumber : "Fp" is commonly used to denote "floating point", How about FixedNumber instead?

    Renamed.

    Thanks again for your feedback :)
    _________________
    [project website] [personal website]

    #138851 - Quirky - Wed Aug 29, 2007 8:56 pm

    Vich wrote:

    Quote:

    [*]FpNumber-constructors should be made explicit to prevent unexpected code-paths for float-code.

    Could you clarify that with a sample?


    Since the constructor is FpNumber(float inValue) I imagine you could end up using what you think are floats, but are really FpNumbers.
    Code:

    FpNumber f1(100);
    float f2;
    // more code here...
    f1 = 1.0;  // typo, meant f2, but allowed due to FpNumber(float inValue) constructor.


    After adding explicit, you would need to do this to set f1 to a temp value:
    Code:

    FpNumber f1(100);
    float f2;
    // more code here...
    f1 = FpNumber(1.0);
    f1 = 1.0; // ! error


    It is pretty unlikely to be a real problem IMO, but perhaps worth considering.

    #138854 - Vich - Wed Aug 29, 2007 10:01 pm

    Quirky wrote:
    Since the constructor is FpNumber(float inValue) I imagine you could end up using what you think are floats, but are really FpNumbers.
    Code:

    FpNumber f1(100);
    float f2;
    // more code here...
    f1 = 1.0;  // typo, meant f2, but allowed due to FpNumber(float inValue) constructor.


    After adding explicit, you would need to do this to set f1 to a temp value:
    Code:

    FpNumber f1(100);
    float f2;
    // more code here...
    f1 = FpNumber(1.0);
    f1 = 1.0; // ! error


    It is pretty unlikely to be a real problem IMO, but perhaps worth considering.


    I personally think it shouldn't be a problem, since there's there's no difference in code paths between:
    f1 = FpNumber(1.0);
    and
    f1 = 1.0;

    I personally think that any programmer should be able to see that in this case.

    p.s. 1.0 will be a double.
    _________________
    [project website] [personal website]

    #138921 - Quirky - Thu Aug 30, 2007 7:48 pm

    Oh yeah! Should be 1.0f, just goes to show how often I use "magic" decimal-point numbers in code ;)

    #138941 - kusma - Fri Aug 31, 2007 1:20 am

    Vich wrote:
    I personally think it shouldn't be a problem, since there's there's no difference in code paths between:
    f1 = FpNumber(1.0);
    and
    f1 = 1.0;

    I personally think that any programmer should be able to see that in this case.

    With big systems it's often not too easy to see what path the code takes. Let's say you've only implemented the fixed-point version of a function like log2() that returns an int; there's no way to tell 6 months later that your float will be automatically promoted to a fixed-point number (and thus potentially loosing range or precision), so you might spend hours debugging just that.

    It's not really the case above that is the issue here, it's whenever a floating-point number DOES get promoted without it being explicit in the code. The cost of having to explicitly construct the type from a float/double does not outweigh the uncertainty of the non-explicit constructor IMO.

    #139982 - Vich - Wed Sep 12, 2007 10:38 am

    kusma wrote:
    Vich wrote:
    I personally think it shouldn't be a problem, since there's there's no difference in code paths between:
    f1 = FpNumber(1.0);
    and
    f1 = 1.0;

    I personally think that any programmer should be able to see that in this case.

    With big systems it's often not too easy to see what path the code takes. Let's say you've only implemented the fixed-point version of a function like log2() that returns an int; there's no way to tell 6 months later that your float will be automatically promoted to a fixed-point number (and thus potentially loosing range or precision), so you might spend hours debugging just that.

    It's not really the case above that is the issue here, it's whenever a floating-point number DOES get promoted without it being explicit in the code. The cost of having to explicitly construct the type from a float/double does not outweigh the uncertainty of the non-explicit constructor IMO.


    Ah, thanks, that's clarifies it. I'll change it soon :)
    I've also made lots of improvements in the RTTI/serialization system(eg. linking to objects in external XML files). I will post the changes soon. They're still on my laptop, so I'll have to commit them first.
    _________________
    [project website] [personal website]

    #140336 - Vich - Sat Sep 15, 2007 1:26 pm

    Okay, here's a list of improvements:

    - I created a network stream that works in windows and *nix platforms and it is currently implemented for TCP/IP, just like files, you can now open streams like this:
    Quote:

    tcp://www.google.com:80
    tcp://127.0.0.1:80
    file://something.txt

    A Nintendo DS network stream will be implemented soon. Opening a network stream on the DS(or any other not-implented platform) now gives a network stream with a dummy socket which has HasEnded() set to true and IsValid() set to false.

    - I've made a tutorial for streaming that opens and downloads the Google "about" page.

    - External link loading from serialized XML objects.
    Quote:
    <link>[local_link]</link>
    <link>[folder/file:external_link]</link>

    Loading a link to an external file results in the loading of all objects in that file into the given object system.
    Note that an external link does not include a streaming prefix(eg. "file://"), because the serializer will chose the same prefix as the original file that was parsed. This way, you can stream your objects from different sources without having to change all the links.

    - A managed stream now has its source location stored in itself.
    - Renamed global functions to gName() and renamed names like Rtti to RTTI, Xml to XML, etc.
    - Fixed all builds that were broken(*nix, DS)
    - Created SCons build script for the unit tests and tutorials
    - Made foreign constructors for FixedPoint explicit.
    - Surpressed offsetof() warnings for GCC(DS and *nix), as I know that this data is platform-specific and all the compilers that I've test give valid offset data.

    I've been a busy bee :)
    _________________
    [project website] [personal website]

    #141175 - Vich - Sat Sep 22, 2007 11:32 pm

    More improvements and features:
    (I've been coding like a mad man)

    - 2D/3D integer/float point classes added.
    - Fixed network initialization
    - Improved streaming system (refactored a lot of code)
    - Created a MemoryStream so you can read/write a chunk of memory just like a network, a stringstream or a file stream. Very handy for Nintendo DS files that are attached to the executable.
    - Added my own memory functions like gMemSet (memset()) so I can later add validation there in debug mode.
    - Fixed bug in StringStream and improved it in general
    - Improved ObjectSystem
    - Refactored SerializationWriter (big improvement)
    - Created easy-to-use functions like gLoadAssetsFromXML() and gSaveAssetsToXML() that load and save a whole object from/to XML through serialization.
    - Imported a the latest version of TinyXML
    - Added COW_MEMORY_MODEL setting to COWSettings.h, which will control the typedef of types like int32, uint32, etc.
    _________________
    [project website] [personal website]

    #141308 - Vich - Sun Sep 23, 2007 11:39 pm

    More functionality:

    - Added Image and ImagePalette classes.
    - Added ImageStreamer, BMPStreamer and TGAStreamer that can use any kind of stream(FileStream, TCPStream, MemoryStream, etc.) to read one or more images.
    - Added tutorial for loading images.
    - Improved assert

    Fixes:

    - Fix for FileStream and Stream
    _________________
    [project website] [personal website]

    #141958 - Sh4wn - Tue Oct 02, 2007 12:03 pm

    Looks very nice :)

    Definitly going to use this, when I create my own nds app. :)

    #142604 - Vich - Wed Oct 10, 2007 7:49 pm

    Sh4wn wrote:
    Looks very nice :)

    Definitly going to use this, when I create my own nds app. :)


    Thanks. Tell me if you need any help setting stuff up or if you don't understand some functionality.
    I think that I need to add more tutorial applications.
    _________________
    [project website] [personal website]

    #142733 - Vich - Fri Oct 12, 2007 12:59 pm

    reply to http://forum.gbadev.org/viewtopic.php?p=142729#142729
    keldon wrote:
    I know, it's just my take on the "FREE" aspect. LGPL is more 'free' for the developer, but [potentially] less 'free' for the consumer.

    You're right.
    I've been thinking and I might do something like this:
    - completely free for non-commercial use (self-modified version of zlib/png or something similar ... suggestions are welcome)
    - GPL license remains available.
    - Different paid licenses available for commercial projects. Commercial projects can also use the GPL license of course. So people who want to earn money with my project can donate code or money.

    What do you think?

    Quote:
    You have a good take on GPL software, tutorials are (part of) the way forward!

    Thanks :) The tutorials project is relatively new so it will be expanded later. Suggestions and criticism are always welcome.

    @ other people who read this:
    What do you think of this licensing scheme suggestion?
    _________________
    [project website] [personal website]

    #142740 - gauauu - Fri Oct 12, 2007 2:50 pm

    I don't use COW, but I've always appreciated license schemes like what you are talking about.

    #142745 - keldon - Fri Oct 12, 2007 3:18 pm

    Hmm, that would be great but does either license allow such a clause? Technically it should, since the GPL version of the code is derived from your original code, although any GPL derived forks and advancements will not be allowed to return back to the original project unless the original project is GPL'd(I think).

    #142747 - Vich - Fri Oct 12, 2007 3:34 pm

    keldon wrote:
    Hmm, that would be great but does either license allow such a clause? Technically it should, since the GPL version of the code is derived from your original code, although any GPL derived forks and advancements will not be allowed to return back to the original project unless the original project is GPL'd(I think).


    With GPL it's definitely possible to have other licenses aside, Quake3 is proof of that.
    With the zlib/png scheme for non-commercial use it should be possible too. I'll have to add a non-commercial clause(for COW and derived products of COW), so the license remains non-commercial.
    Then what is left is a commercial license, which works in a very specific way for 1 or more derived software products(depending on the commercial license type), so that should work without any problem. I already have a prototype ready for this.

    Forks of GPL'ed and non-commercial zlib/png variants will of course remain within the license that was chosen to fork:
    - GPL will remain GPL, no problem there.
    - zlib/png with non-commercial clause will just remain zlib/png with commercial clause and with a notice that derived products must remain non-commercial.
    In this case, someone won't be able to fork a forked GPL project into the zlib/png&non-commercial license or vice versa, but I don't think that's a problem.

    The only real difficulty I can think of is how to describe "commercial" projects

    The "fork of a fork" problem could be solved by creating a new license which is a combination of GPL and zlib/png&non-commercial that states that you have to publish your fork always with these 2 licenses. What do you think about that?
    _________________
    [project website] [personal website]

    #142752 - keldon - Fri Oct 12, 2007 5:53 pm

    Replace "commercial" product with the clauses that you have assumed a "commercial" product implies. For example you may class a product as commercial if there is no fully functional freely available program for download, freely obtainable with costs going only to postal administration (or something of those lines). Also state that "justifiable" postal administration only covers the cost of the postal company (which can eventually be 5 paragraphs long covering every possible loop hole).

    #142765 - tepples - Fri Oct 12, 2007 9:08 pm

    The Sleepycat license, used for Berkeley DB, is probably the most compatible copyleft license around.

    As for "non-commercial", what about the cost of the blank media that a program ships on? The GNU GPL limits the cost of a source disc under section 6b to "a price no more than your reasonable cost of physically performing this conveying of source".
    _________________
    -- Where is he?
    -- Who?
    -- You know, the human.
    -- I think he moved to Tilwick.

    #142835 - Vich - Sun Oct 14, 2007 11:27 am

    Thank you keldon and tepples. I will create some kind of hybrid license and I'll post it here soon.
    _________________
    [project website] [personal website]

    #142909 - Vich - Mon Oct 15, 2007 12:23 am

    Aside from the licensing, I have some update information:
    This weekend I've added relative link support to the serialization system, so you can make links like this:
    Quote:

    <link>[local_link]</link>
    -> Link from within a file (not a new feature)

    <link>[folder/file.xml:external_link]</link>
    -> Link is absolute (not a new feature)

    <link>[./file.xml:external_link]</link>
    -> Link is relative to the file where it is linked from

    <link>[../../file.xml:external_link]</link>
    -> Link is 2 folders below the file that is linked from.


    I've added 2 new tutorials:
    - HTTPStream
    - Serialization

    There is also a code style document available.

    Aside from this I've submitted lots of other fixes and some structural OO improvements(concerning stream registration and serialization), but probably nobody will care about those :P
    _________________
    [project website] [personal website]