Archive for April, 2009

Awesome t-shirt

Thursday, April 30th, 2009

In other, more Fedora-related news, I have this sudden urge for a blue t-shirt.

Kross fixins

Thursday, April 30th, 2009

So this turned out kind of dry and boring, but it’s basically a laundry list for fixing up Kross and its language bridges.

Sigen uses Kross to allow for many scripting languages to be used to script up things in games that use the engine. Tonight I perused the source for the bindings (the KJS and QtScript bindings are very simple) and looked to see what could be improved or fixed. One thing that the bindings need are ways to use disconnect. Neither Python nor the Ruby bridge offers a disconnect that does anything. This should be just as simple as a state machine just like the one used for connect. Python ships a (most likely, I have to run diff over it yet) patched version of PyCXX which I’d like to get working on a system version in Fedora (still needs to be packaged) so that it’s not duplicate and other applications can use it. Ruby doesn’t implement a way for connecting an object to non-Ruby methods (such as back into the C++ objects). Falcon mostly works, but connect and disconnect are both non-functional due to some issues with what objects have the methods. I finally got the Java bridge to compile tonight and I haven’t gotten around to testing it yet. Unfortunately the state of the CMake file which searches for the libraries that it uses from Java is not very portable. It assumes the library directory and compiler imclude directory to find AWT stuff. Although my GSoC project to do this as well as add Kross support to an existing application wasn’t accepted, I’d like to at least fix up some of the language bridges and then polish up Kross so that it’s easier to use on the application side. Adding forwarding headers as well as allowing ActionCollections to host objects would be a start.

Looking at the code, making other language bridges shouldn’t be that tough. Lua offers a C API and has a Kross bridge at some level of completion in KDE’s playground. I can’t find documentation for PHP’s C API, so I don’t know how well this would work. Some variant of LISP is under way as I understand. With all these ways to script the engine, making new ways of doing things should be a snap.

Woah, world map editing is (almost) done

Tuesday, April 28th, 2009

So after some hacking, I have world map editing working. It’s quite shiny if I do say so myself (I know the last map moving is buggy…something is off when there are multiple anchored maps). There’s a bug with the web server saying that .ogv is a text file. I’ll talk to my host about that. In the meantime, make sure to save the video and then view it. There’s also another video of some other things (though it’s not really representative of anything) here. It shows some of the (incomplete) map editing, but it’s still worth a look-see I think. Feedback welcome.

Progress

Thursday, April 23rd, 2009

I got some progress done on the world map editor today. Last night while failing at going to sleep at a decent time, I figured out how to solve the problem I described earlier. I’ll outline my solution here. I’m pretty sure it’s O(n²), but it may be O(n³).

The algorithm has only one input, which is the size for the target area. This all occurs on an infinite 2-dimensional plane. Objects are limited to integer coordinates and sizes and all edges must be parallel to either the x or the y axis.

Add rectangles to the plane that the target rectangle is not allowed to be in (locked map positions). For each rectangle that already exists, check if the space between the rectangles is larger than the target size (horizontal space between must be greater than the width of the target area and similar for the vertical space with the height). (Unfortunately, I just found a corner case which I did not see before…ah well, this is a start in any case.) When finished adding all of the rectangles, it’s time to merge these into polygon outlines. Unfortunately, Qt does not do this with QPolygon::union, it just tacks on drawing paths as far as I can tell, which is not what I need or can use.

To combine these into polygons, first set up a list of bitfields, one ofr each rectangle. Initialize the ith bit in the ith bitfield as 1 and the rest as 0. Loop over each rectangle for every other rectangle. If the two touch, bitwise-or their fields together. Then remove duplicate entries in the list. Generate polygons from the bitfields using the following algorithm to preserve the outline(s):

The first part is to find where the collisions between the polygon and the rectangle are. By looping over each point in a polygon find out if it lies on an edge of the rectangle. If it does, store the information that it should start the next portion of the outline on the other polygon and where. If they share a vertex, there are two cases, the first is that the vertices are in a single edge that makes the vertices not on the outside anymore and the other being that the polygons touch each other at the vertex. If it is the former, the vertex should not occur in the final outline.

After finding the collision information between the polygon and the rectangle (and vice versa), find a point guaranteed to be on the outermost outline (finding the point closest to any of the four corners guarantees this). From here, start moving around the polygon going from point to point marking each as visited unless there is something to do with the collision info and we need to switch the outlining to the other polygon. When we return to our starting position, the outline is complete. Until all of the original vertices are visited, continue finding an outermost unvisited vertex. Any after the first are going to be holes inside of the first.

With these polygons, we have outlines of the collidable regions of the plane. In order to find the best positioning for the given area (as measured by distance from a point), we traverse the outside of the polygons. The only possible positions for the target area are concave corners and places where the edges intersect the axes extending from the requested point that are parallel to the x and y axes. Finding the best position given the possible candidate positions is trivial.

The corner case when generating the rectangles in between others to complete the mask is when two rectangles are not in line with each other, but the rectangle formed by their closest corners are smaller than the target area. This gives a bound on the edges towards the other rectangle. I’m not sure of how to handle this right now, but it’s a small case right now.

I’m fairly proud of the algorithm despite it being less than optimal. I have it caching things so even if it is O(n³), it is only recalculated when the target size changes or the set of collidable rectangles change.

I also think I can redo the sigmodrtree library in a lot fewer lines using KWidgetDelegate to simplify the look of the items and cleave maybe 5k lines of code from it (it’s currently at 10k lines). And it should be able to be done by the 0.2.0 release time. I hope to have the Trac instance be public at some point, but with only 2 weeks left here, it’d be down for a while before summer plans get figured out.

In other news, we had an assignment to do Markov chains for my Intro to AI class. Since this class tends to have overly simple assignments, instead of just doing 1 or 2 length chains of words (my Falcon version is arbitrary length, but it runs out of RAM for low chain lengths and large text source), I made a C version which initially had RAM issues (allocating 256 pointers per tree node on x86_64 is expensive). It now runs with low RAM and a lot faster using realloc for the children of nodes for the tree (used to represent the database for the chains). Words would start to show up around chains of 4 or 5. Sentences at around 6 or 7. For 8 and up, it depended on the size of the input, but it was almost too much above 10 or 12 even given a large input such as big.txt (which is 6.2MB and contains a few books from Project Gutenberg). A chain size of 8 to 10 gave nearly grammatically correct sentences. Fifteen was too high and caused it to output verbatim paragraphs. Overall it was an interesting little assignment. I just wish that the class was actually more thought provoking than the simple assignments that are given make it out to be. That’s for another rime though.

Also, this is my first post using Lekhonee, a nice little application by Kushal Das. It needs some polishing, but it seems to do its job so far. Thanks.

Shape editor started

Sunday, April 19th, 2009

I’ve started work on the shape editor for the effects and warps on a map. I hope to have something to show either today or tomorrow.

Random crap

Saturday, April 18th, 2009

It’s been a…while since I last wrote here. Since then what’s happened…

I finished Island since then. I like books about dystopia societies because I have a lot of interest in sociology and psychology (more of a hobby though). Seeing how a society that is oppressed by the government allows one to see similarities between what was shown as wrong in the story and what is happening today. Island is a nice break from that to see what it would take to create a good society. Focusing on education, metal and physical well-being, minimal industry, and scientific progress were some of the main points. Also, a different “family” structure was used to help improve the childhood and parental experience. Instead of a child having two adults to always rely on, he or she could go to one of over a dozen other adults for help or comfort (after an argument with your parents, you can actually get away for a few days and let the steam actually cool off instead of keeping the water at a simmer). Unfortunately, the society was to be taken over by oil-hungry because it was a rich source of crude. Due to the minimal industry, there was no military and when one person with strong religious convictions was able to grab some power and opportunity, ruined the entire society for money and oil. I highly recommend the book for anyone that is interested in economics, sociology, or political science).

I updated to Rawhide yesterday. X.org and the Intel driver are much better here. Desktop effects don’t trigger the open file limit on the system, which is always a plus.

Strawberries, although not quite in season yet I think, are still delicious. So are Spanish omelette (though I had one without the ham or prosciutto). Tomatoes with vinegar, some salt, and olive oil as well. A friend’s girlfriend visited from Spain and we made dinner one day. First time I’ve eaten an omelette or uncooked tomatoes. I dont know if I could do actual raw tomatoes though. When she was here, I also found out that my French is not that bad. I just can’t remember verbs or nouns (forget the genders of them) all that well.

On the Sigen front, I’ve made some progress. The Game class can now handle the world map placement (not validating them, but I’m not quite sure how I want to do that yet). The map editor can be zoomed. There’s a rudimentary world map editor. Unfortunately there’s one thing I want to finish but I have to create an algorithm to do so. What the algorithm needs to do is take two polygons and merge them into one. Normally QPolygon can do this, but it takes shortcuts that I don’t have the luxury of being able to do. The polygons are limited to only vertical and horizontal edges with the vertices given in clockwise order from an arbitrary point. After merging so many of these, take a point and find out where on the perimeter a rectangle of size NxM it should be positioned to minimize the distance between the rectangle and the point. I have the second part. Getting the outline is the touch part right now. I also moved the plugins out into their own directory instead of inside of sigencore/plugins and cleaned them up. The Kross plugin bridge for arenas is started. I still need to write the actual arena for it yet though. There are now callgrind targets for all of the tests though they are of little use until I update the tests to use QBENCHMARK to get some accurate timings. I also fixed a bug in Hat and updated its test to check for the corner case.

I’ve set up my server to host a Trac instance. Got to learn quite a bit about mod_alias and mod_rewrite in lighttpd. Or at least how you can mess them up. I have some milestones and tickets written up to pester myself about. That said, I’ve pegged a 0.2.0 release in about 4 weeks and a 0.2.1 release two weeks later with test and documentation updates. Hopefully I can make it.

The semester is winding up and there are some projects due, but I don’t think they’re that major. Anyways, time for bed. Enough random crap for one night.