Completely unrelated to the recent trend of this blog (generally obsessed with my independent game development) there's something that has been bugging me for a while.. and that's the suicide of Tony Scott.
Maybe for a person with suicidal tendencies it's not something strange, then it makes sense that those that don't "get it" should not be curious about it.
Still, I think that it's a waste and it's unfair to keep the motive private.
It's a waste because one could get insight that could go towards helping someone around them.
It's unfair because it caught a lot of attention and wasted a lot of people's time to follow the news.. and then nothing comes out of it.
The privacy of his family needs to be respected, ok, but still.. the greater good would be to know more.
Was he sick ? Was he having erectile disfunction ? Was his wife cheating on him ? Was it the antidepressant (which apparently can increase suicidal tendencies) ? If we don't know, we can't prevent from it to happen to others.
It's a popular case and it could be used to educate people to prevent similar things to happen...
The moral is that it's not just curiosity, but it's about sharing things that could help improve (and keep !) the life of others.
mumble mumble
v5.kazzuya.com
なんとかニャンコ
Sunday, June 2, 2013
Monday, March 25, 2013
More Fractal Combats !
Fractal Combat X has been out for a couple of months now, but I didn't write anything about it.
Can you guess ? It didn't go very well..
I'll write more in detail in a later post, but for now lets make a little logic game:
- FCX is much better looking than the 1.0 of FC (both in-game and UI)
- FCX is free, while FC was initially sold for $1.99 (now $0.99)
..therefore FCX should be loads more popular, right ?
But that wasn't the case.
For some reason, major mobile game review sites didn't bother talking about it, Apple itself didn't notice it and didn't put it in any sort of noteworthy section (not even where FC was placed at the time !).
Apple didn't even put it in a Flight Games section, where instead one can find things like Top Gun, which is rated at 2 and 1/2 stars.. famous title, never mind if it's a good game or not.
Unsurprisingly, FCX was reviewed and featured on Italian sites and even on a newspaper.. eh !
Anyhow, lack of marketing (resources) was the big problem for FCX.
One positive thing this test (let's call it that) is that the free-to-play model worked out decently. Although the game is rather generous and doesn't really beg users to purchase things, a few people do buy credits.
But the game should offer more purchasing options and, most importantly, it should be downloaded a lot more than this (187K times in 2 months and a half, with the downloads peak reached in the second week).
Another generally positive thing is the modest revenue coming from the free versions of the Final Freeway games. It's not much, but it's a big help to keep the business going.
Given that ads are working out well, we decided that our next Android game is going to be a free version of the first Fractal Combat . It's going to be with ads and optional In-App Purchase options to remove ads and to get additional content.
Unlockable features and content is not the best way to do freemium games, but the first FC wasn't meant to deal with virtual currency, and on the Android platform we're still working on the infrastructure to deal with these things.. namely, in a virtual currency setup, the user should be allowed to transfer the game status across devices (or on reinstall), and that requires some server storage, like iCloud, which is what I'm using on iOS.
FCX is based on virtual currency, so for the Android edition we'll have to come up with a solution. Which, if everything goes to plans, it should be the OpenKit system ...but it's not out yet.
Monday, December 17, 2012
What You See Is What You Want To See
I should be putting 100% of my time on FCX, but I need a break.
Making games, like many other things is mostly about perseverance.. it's incredibly psychological and thus one can be affected negatively by stress.. I reached the 99th gate and now I need now I sit for a little before I jump the 100th gate 8)
A lot is happening in the world right now, and I regret following the news, because it's mostly a waste of time.
For every time I read some news and especially people's comments on them, I could be coding or studying something.. that would only make things better for me and possibly for everyone (if only people were busier being busy than complaining and read complaints..).
We're in a period where people communicate on the Internet more than in any other way. There are all sort of news there and all sort of comments.
One thing that doesn't seem to have changed is how people take sides and hold strong onto their believes.
It's not easy to change a person's mind. In fact, it's practically impossible in the short term. Strong stances can only change with time. You get someone's opinion, let it simmer and eventually that will affect you and possibly make you change stance on things (or vice versa).
The big questions are often about political ideals and leaders. This is pretty much universal.
No matter how free and open the information can be, there'll always be some bias and a group of people that would rather feed their own bias.
That's even worse in countries like Italy, where freedom of press is lacking..
One thing that I noticed in regard to political ideals among Italians is that those are are in Italy and those that are abroad tend to think differently.
It could be that those in Italy have a cleared view.. or it could be that that they are more affected by the local media.
Either way, it comes to show how things can be predicted geographically.. we're stats 8)
Like most "educated" (to so speak) people, I tend to lean on the Liberal side of things.
It works very well in Japan, with its pros and cons, but of course that doesn't prove that it would work everywhere.
Most of all however, it's important to keep in mind that one can only try to guess on what's best.. but it's impossible to tell what's truly better for a "greater good", and it's of course pretty arbitrary to say what's a "greater good".
So, why bother with politics ? Better get busy with something more concrete, like physics..
One of my dreams is to get wealthy enough so that I can stop worrying about how society affects me (above society ?), not because I want to live at the expenses of somebody else, but because that way I'd be one less burden on society and possibly even be of help (hard to help the others when you're in trouble yourself).
When I think that the games I made as an independent reached at least one million of people.. I feel a certain gratification.
I'm not saving lives, but still, entertaining someone with a fun game can go a long way.
If a few of those people playing are also getting interested in development and in the technology behind it, then I may have contributed to get someone closer to science and engineering..
Entertaining is good, getting people to embrace a more logical way of thinking is even better 8)
Making games, like many other things is mostly about perseverance.. it's incredibly psychological and thus one can be affected negatively by stress.. I reached the 99th gate and now I need now I sit for a little before I jump the 100th gate 8)
| Cosa sta pensando il Pensatore Quiz? |
For every time I read some news and especially people's comments on them, I could be coding or studying something.. that would only make things better for me and possibly for everyone (if only people were busier being busy than complaining and read complaints..).
We're in a period where people communicate on the Internet more than in any other way. There are all sort of news there and all sort of comments.
One thing that doesn't seem to have changed is how people take sides and hold strong onto their believes.
It's not easy to change a person's mind. In fact, it's practically impossible in the short term. Strong stances can only change with time. You get someone's opinion, let it simmer and eventually that will affect you and possibly make you change stance on things (or vice versa).
The big questions are often about political ideals and leaders. This is pretty much universal.
No matter how free and open the information can be, there'll always be some bias and a group of people that would rather feed their own bias.
That's even worse in countries like Italy, where freedom of press is lacking..
One thing that I noticed in regard to political ideals among Italians is that those are are in Italy and those that are abroad tend to think differently.
It could be that those in Italy have a cleared view.. or it could be that that they are more affected by the local media.
Either way, it comes to show how things can be predicted geographically.. we're stats 8)
Like most "educated" (to so speak) people, I tend to lean on the Liberal side of things.
It works very well in Japan, with its pros and cons, but of course that doesn't prove that it would work everywhere.
Most of all however, it's important to keep in mind that one can only try to guess on what's best.. but it's impossible to tell what's truly better for a "greater good", and it's of course pretty arbitrary to say what's a "greater good".
So, why bother with politics ? Better get busy with something more concrete, like physics..
One of my dreams is to get wealthy enough so that I can stop worrying about how society affects me (above society ?), not because I want to live at the expenses of somebody else, but because that way I'd be one less burden on society and possibly even be of help (hard to help the others when you're in trouble yourself).
When I think that the games I made as an independent reached at least one million of people.. I feel a certain gratification.
I'm not saving lives, but still, entertaining someone with a fun game can go a long way.
If a few of those people playing are also getting interested in development and in the technology behind it, then I may have contributed to get someone closer to science and engineering..
Entertaining is good, getting people to embrace a more logical way of thinking is even better 8)
Friday, December 14, 2012
4:30 in the afternoon and half-asleep.. what a better time to update the blog after 3 months !
I've been almost completely focused on completing the next game.. which is basically a sequel of Fractal Combat.
This new version is better in pretty much every aspect. It's not just an update but a separate release, because the changes were just too drastic.
FC 1.0 was not bad, I think, but it wasn't nearly as polished as the current update of FC.
This new game (Fractal Combat X, or FCX) is even more polished than the current FC. So, the hope is that we'll get a good initial reception.. which is very essential to propel the game forward.
On the business side, the big change is that it's going to be a free-2-play game.
It's free to download and play, but some people will eventually (I hope !) feel the need to purchase some upgrades to reduce the amount of work required to earn upgrades by just playing.
We'll see how it goes.. it's going to be an interesting experiment.
I've learned to expect some decent income for the first month of sale. This time around however it's not plain sales, so who knows.
In any case, the hope is to get more than a decent income for the first 1-2 months.
I've now been rather broken for quite a while.. comes to think, last Christmas I was broke, and the situation hasn't improved this year.
Well, the time is now.. and in any case I feel like things can start getting better now.. or pretty soon.
The time I spent the last couple of years has been an investment.. games have been getting better, and the underlying infrastructure, both as code base and workflow in general, has improved a lot.
Also targetable hardware has been getting better.
I still can't afford decent lighting or dynamic shadows (not that I had the time to work on that), but the baseline mobile hardware has been getting better.
so... zzzzz !
I've been almost completely focused on completing the next game.. which is basically a sequel of Fractal Combat.
This new version is better in pretty much every aspect. It's not just an update but a separate release, because the changes were just too drastic.
FC 1.0 was not bad, I think, but it wasn't nearly as polished as the current update of FC.This new game (Fractal Combat X, or FCX) is even more polished than the current FC. So, the hope is that we'll get a good initial reception.. which is very essential to propel the game forward.
On the business side, the big change is that it's going to be a free-2-play game.
It's free to download and play, but some people will eventually (I hope !) feel the need to purchase some upgrades to reduce the amount of work required to earn upgrades by just playing.
We'll see how it goes.. it's going to be an interesting experiment.
I've learned to expect some decent income for the first month of sale. This time around however it's not plain sales, so who knows.
In any case, the hope is to get more than a decent income for the first 1-2 months.
I've now been rather broken for quite a while.. comes to think, last Christmas I was broke, and the situation hasn't improved this year.
Well, the time is now.. and in any case I feel like things can start getting better now.. or pretty soon.
The time I spent the last couple of years has been an investment.. games have been getting better, and the underlying infrastructure, both as code base and workflow in general, has improved a lot.
Also targetable hardware has been getting better.
I still can't afford decent lighting or dynamic shadows (not that I had the time to work on that), but the baseline mobile hardware has been getting better.
so... zzzzz !
Sunday, August 26, 2012
It sucks to be IN the simulation..
(Here's another recent attempt at writing a blog post)
I remember the summers of one or two years in the early 90s. I had an Amiga on which I'd spend practically all of my time on. Lunch and dinner breaks would be kept to a minimum and sleep was also practically just an interruption.
Needless to say that I was mostly involved trying to create some sort of video games.
Because I was on my own, I'd take turns between the coding and doing the graphics in Deluxe Paint.
Somewhat uncommonly at the time, DPaint had an undo feature. I'd spend hours working on those pixels and continuously use the undo feature, to the point in which it became the natural way of working.
I'd take breaks form time to time. In one case, I remember going to the kitchen, taking a knife to peel an orange and for an instant thinking: "what if I cut my finger accidentally ? Well, I can always undo !".
My mind was clearly still in DPaint-land (^^;) ..for me that was a remarkable moment when I realized that one can live in alternate realities with his mind. Potentially some dangerous alternate realities, if some kind of suggestion would last long enough to do actual damage before realizing that there is no Undo button.
I eventually continued the path towards game development. Put aside the more artistic side of things, because it was more something that I did out of necessity, and pushed with programming for many years.
This is not about art or code however, this is about determinism.
Life seems to be all about decisions, but not all decisions carry the same weight. Decisions taken in the context of a digital computer, for example, can lead to non-destructive outcomes, by design.
So, for example, if a crash happens to a program I'm writing, I can always go back, change the code and try again. My "human time" only goes forward, but the digital abstraction level at which I'm working on, makes it possible for me to go back in "computer time" to fix issues and run the software again as if the bug was never there.
Back to the non-digital world.. we only get one chance to do anything. The smallest thing can never truly be undone. You can undo many things, but there's always a level at which those things have left a permanent mark.
But why the topic ?
This comes up for me as I'm not only a programmer anymore, but also someone responsible to generate interest (and income) around the games I build.
While developing, I can still go back and fix bugs in "computer time", but once the game is released, the ability to undo certain choices is severely limited.
It's not just about bug fixing, but perhaps more importantly on what games one decides to make and how he intends to turn them into a profit. This, is terribly frustrating because determinism in the real world is very hard to obtain.
Of course, digital computers are made of non-digital components. To reproduce a signal consistently, you just need enough bandwidth to cope with the noise (I'm just dropping in some cheap signal processing buzzwords to make it sound more scientific).
If one has a big enough pool of users to test new features, then it's practically the same as running a computer simulation.
Companies like Google or Zynga, regularly make improvements to their systems by testing small changes on large pools of users... with large numbers, one can think statistically and determinism is true again.
The moral of all this is that for someone that spends most of his time in a controllable environment, the real world is just a mess 8)
I remember the summers of one or two years in the early 90s. I had an Amiga on which I'd spend practically all of my time on. Lunch and dinner breaks would be kept to a minimum and sleep was also practically just an interruption.
![]() |
| UN DO |
Because I was on my own, I'd take turns between the coding and doing the graphics in Deluxe Paint.
Somewhat uncommonly at the time, DPaint had an undo feature. I'd spend hours working on those pixels and continuously use the undo feature, to the point in which it became the natural way of working.
I'd take breaks form time to time. In one case, I remember going to the kitchen, taking a knife to peel an orange and for an instant thinking: "what if I cut my finger accidentally ? Well, I can always undo !".
My mind was clearly still in DPaint-land (^^;) ..for me that was a remarkable moment when I realized that one can live in alternate realities with his mind. Potentially some dangerous alternate realities, if some kind of suggestion would last long enough to do actual damage before realizing that there is no Undo button.
I eventually continued the path towards game development. Put aside the more artistic side of things, because it was more something that I did out of necessity, and pushed with programming for many years.
This is not about art or code however, this is about determinism.
![]() |
| This is what a cat inside a box looks like! |
So, for example, if a crash happens to a program I'm writing, I can always go back, change the code and try again. My "human time" only goes forward, but the digital abstraction level at which I'm working on, makes it possible for me to go back in "computer time" to fix issues and run the software again as if the bug was never there.
Back to the non-digital world.. we only get one chance to do anything. The smallest thing can never truly be undone. You can undo many things, but there's always a level at which those things have left a permanent mark.
But why the topic ?
This comes up for me as I'm not only a programmer anymore, but also someone responsible to generate interest (and income) around the games I build.
While developing, I can still go back and fix bugs in "computer time", but once the game is released, the ability to undo certain choices is severely limited.
It's not just about bug fixing, but perhaps more importantly on what games one decides to make and how he intends to turn them into a profit. This, is terribly frustrating because determinism in the real world is very hard to obtain.
Of course, digital computers are made of non-digital components. To reproduce a signal consistently, you just need enough bandwidth to cope with the noise (I'm just dropping in some cheap signal processing buzzwords to make it sound more scientific).
If one has a big enough pool of users to test new features, then it's practically the same as running a computer simulation.
Companies like Google or Zynga, regularly make improvements to their systems by testing small changes on large pools of users... with large numbers, one can think statistically and determinism is true again.
The moral of all this is that for someone that spends most of his time in a controllable environment, the real world is just a mess 8)
Thursday, July 19, 2012
About Fractal Combat 1.2
We recently released Fractal Combat 1.2 with drastically improved graphics for the environment.
For most terrains, I dropped my simple "plasma" generator and instead had Max create them with World Machine.
What's the tech angle on that ? ..it's the shift from procedural to compression. Two things that are in fact closer than they may seem. They are both about synthesizing data from a given source.
Procedural generated data is generally intended to come from a relatively small set of parameters, while decompression, which is more generic, starts off a much larger data set generated by the compression phase, which itself comes from an original.
So, these new terrains (still 2048x2048), had to be compressed.
The color data was easy: just JPEG.
The heightfield instead needed 16 bits per sample, but JPEG is limited to 8 bits. PNG supports 16 bits but it's a lossless format. There's no loss of quality, but the compression ratio is just too low on natural-looking images (or natural-looking heightfields in this case).
The solution was to make a new format which, at its core, uses the DCT transform like for JPEG, but that works with 16 bits samples.
That worked well and I got a decent compression ratio that kept the game at about 30 MB (including 2 new sound tracks added for the update).
The overall size of the game was previously less than 14 MB. It was important to keep below 20 MB so that people could download the game over 3G connections but, recently, that limit has been raised to 50 MB by Apple and so 30 is still small enough for downloading on-the-move.
I sometimes wonder how much are games really compressing their data. Some mobile games have very large data sets.. but I bet that they could be smaller with some extra effort.
Some users praise mobile games that take little space on their devices. But, on the other hand, I wonder if some other users aren't instead attracted by the prospect of a game with a big payload of data .."if it's big, it's got to be good !" 8)
Another thing that I did for the terrains is shadow baking.The baking is done in-house, because, firstly, I don't like the idea of another program doing the baking for me (!), secondly it's just more convenient.
With my own baking, I can change the light source and redo the baking quickly on the development PC.. (although the mobile devices are too slow for that and they simply get the baked data).
Another reason is that, for the future, I could export not simply the baking color but also the shadow volumes to be used to cast shadows on models in real-time.. even if just to roughly detect if a model is in shadow or not.
Baking took advantage of the fact that terrains are heightfields. So, samples are on a regular grid and one can cast rays by simply (virtually) rasterizing a 3D line projected onto this 2048x2048 heightfield bitmap !
For each terrain cell to check, I rasterize a line from that sample to the light source and see if in that path there is another terrain cell whose height intersects the ray.
I also added bloom from the Sun itself during the game. Bloom is light scattered in the eye, so it's something that needs to be rendered of top of every 3D object, as long as any portion of that light source is visible.
I ended up casting the ray from the Sun to the eye point, checking if it intersects the ship.
If it does, then the Sun is not visible and no bloom at all should happen (obviously simplifying thigs a lot here as the Sun really isn't just a point !).
For that raycasting I used a generic voxel structure. In this case, the ray is converted from world-space to the local-space of the object/voxel and again, a 3D line is (virtually) rasterized to select the voxel cells that contain polygons that may be hit.
(I wish Blogger had a way to make quick sketches and insert them in a post.. but it doesn't so there's no visualization this time 8)
I put this voxel generation and line checking code online.. it depends on my code base, but most things are easily replaced with STL and an alternative float3/vec3 of choice.
It's probably quite buggy, so I wouldn't rely on it too much. Also the line checking method is a big hacky.. it uses local persistent storage for the result and it collects all of the cells of the voxel touched by the line, at once.
A better implementation would allow to iterate so that one could stop early.
Another drawback is that polygon IDs may be referred in multiple voxel cells. So, blindly checking every polygon in every cell selected, may lead to duplicate checks. But it's something that can be avoided if it turns out to be a bottleneck.
so.. woooo.. that was a lot of text compared to Twitter 8)
See the video ! -> https://vimeo.com/45743006
What's the tech angle on that ? ..it's the shift from procedural to compression. Two things that are in fact closer than they may seem. They are both about synthesizing data from a given source.
Procedural generated data is generally intended to come from a relatively small set of parameters, while decompression, which is more generic, starts off a much larger data set generated by the compression phase, which itself comes from an original.
So, these new terrains (still 2048x2048), had to be compressed.The color data was easy: just JPEG.
The heightfield instead needed 16 bits per sample, but JPEG is limited to 8 bits. PNG supports 16 bits but it's a lossless format. There's no loss of quality, but the compression ratio is just too low on natural-looking images (or natural-looking heightfields in this case).
The solution was to make a new format which, at its core, uses the DCT transform like for JPEG, but that works with 16 bits samples.
That worked well and I got a decent compression ratio that kept the game at about 30 MB (including 2 new sound tracks added for the update).
The overall size of the game was previously less than 14 MB. It was important to keep below 20 MB so that people could download the game over 3G connections but, recently, that limit has been raised to 50 MB by Apple and so 30 is still small enough for downloading on-the-move.
I sometimes wonder how much are games really compressing their data. Some mobile games have very large data sets.. but I bet that they could be smaller with some extra effort.Some users praise mobile games that take little space on their devices. But, on the other hand, I wonder if some other users aren't instead attracted by the prospect of a game with a big payload of data .."if it's big, it's got to be good !" 8)
Another thing that I did for the terrains is shadow baking.The baking is done in-house, because, firstly, I don't like the idea of another program doing the baking for me (!), secondly it's just more convenient.
With my own baking, I can change the light source and redo the baking quickly on the development PC.. (although the mobile devices are too slow for that and they simply get the baked data).
Another reason is that, for the future, I could export not simply the baking color but also the shadow volumes to be used to cast shadows on models in real-time.. even if just to roughly detect if a model is in shadow or not.
Baking took advantage of the fact that terrains are heightfields. So, samples are on a regular grid and one can cast rays by simply (virtually) rasterizing a 3D line projected onto this 2048x2048 heightfield bitmap !
For each terrain cell to check, I rasterize a line from that sample to the light source and see if in that path there is another terrain cell whose height intersects the ray.
I also added bloom from the Sun itself during the game. Bloom is light scattered in the eye, so it's something that needs to be rendered of top of every 3D object, as long as any portion of that light source is visible.
I ended up casting the ray from the Sun to the eye point, checking if it intersects the ship.
If it does, then the Sun is not visible and no bloom at all should happen (obviously simplifying thigs a lot here as the Sun really isn't just a point !).
For that raycasting I used a generic voxel structure. In this case, the ray is converted from world-space to the local-space of the object/voxel and again, a 3D line is (virtually) rasterized to select the voxel cells that contain polygons that may be hit.
(I wish Blogger had a way to make quick sketches and insert them in a post.. but it doesn't so there's no visualization this time 8)
I put this voxel generation and line checking code online.. it depends on my code base, but most things are easily replaced with STL and an alternative float3/vec3 of choice.
It's probably quite buggy, so I wouldn't rely on it too much. Also the line checking method is a big hacky.. it uses local persistent storage for the result and it collects all of the cells of the voxel touched by the line, at once.
A better implementation would allow to iterate so that one could stop early.
Another drawback is that polygon IDs may be referred in multiple voxel cells. So, blindly checking every polygon in every cell selected, may lead to duplicate checks. But it's something that can be avoided if it turns out to be a bottleneck.
so.. woooo.. that was a lot of text compared to Twitter 8)
See the video ! -> https://vimeo.com/45743006
Friday, May 18, 2012
Many params in C++
I've been writing about business and sales for too long now.. it's unfortunately what I have to worry about every day.. but I'm still a programmer !
What we have here is a constructor with many parameters.
Two params clearly come with a default value, a third one "rowPitch" could be optional. But, because of how C++ works, we'd have to put it at the end grouped with the other parameters with default values, clearly imposing a dependency on which parameters can be truly optional.
Another thing that I don't like about this, is that it's easy to get confused:
..what is what ?
This gets worse when one starts overloading the constructor with versions that take a different series of parameters.
So, I prefer the following notation:
Where the class Image is declared as:
The declaration is longer, but what matters is the usage.
It's obvious which parameters are being set and anything can be left to default.
The drawback is that sometimes some parameters really ought to be set for the constructor or function to work, and in some other cases some parameters could be mutually exclusive.
So, the constructor in this case will have to assert on the usage at run-time, which is not an ideal thing.
One option is to make the
But, I'm not a big fan of this, and it doesn't work for all the cases (mutually exclusive params).
In conclusion, I find that passing parameters by "structure" sometimes helps to improve the code in C++ as well. It's not something new and it's common in Python and Objective-C (to some exent), but it's worth remembering that it's an option.
(Incidentally, I'm currently refactoring my image class 8)
See also the coding page.
One thing that I've been doing for a while is passing parameters in a structure, when the parameters are too many.
This is nothing new. I think I remember the first usage from an Amiga function that did blit stretching. It was a later version of the OS and the function was pretty slow.. At the time, stretching a bitmap in real-time, was somewhat of a dream.. and it didn't help that Amiga had a bitplanes architecture, which made it extra painful to operate on pixels discretely.
But, anyhow, here's a sample case:
class Image
{
public:
Image(
u_int w,
u_int h,
u_int rowPitch,
u_int depth,
u_int chans,
u_int flags=0,
const U8 *pSrcData=NULL );
};
What we have here is a constructor with many parameters.
Two params clearly come with a default value, a third one "rowPitch" could be optional. But, because of how C++ works, we'd have to put it at the end grouped with the other parameters with default values, clearly imposing a dependency on which parameters can be truly optional.
Another thing that I don't like about this, is that it's easy to get confused:
Image img( 320, 240, 0, 32, 4, 0 );
..what is what ?
This gets worse when one starts overloading the constructor with versions that take a different series of parameters.
So, I prefer the following notation:
Image::Params par; par.width = 320; par.height = 240; par.depth = 32; par.chans = 4; Image img( par );
Where the class Image is declared as:
class Image
{
public:
class Params
{
public:
u_int width;
u_int height;
u_int rowPitch;
u_int depth;
u_int chans;
u_int flags;
const U8 *pSrcData;
Params() :
width(0),
height(0),
rowPitch(0),
depth(0),
chans(0),
flags(0),
pSrcData(NULL)
{
}
};
Image( const Params &par );
};
The declaration is longer, but what matters is the usage.
It's obvious which parameters are being set and anything can be left to default.
The drawback is that sometimes some parameters really ought to be set for the constructor or function to work, and in some other cases some parameters could be mutually exclusive.
So, the constructor in this case will have to assert on the usage at run-time, which is not an ideal thing.
One option is to make the
Params constructor itself require some parameters. For example, if width and height must always be specified, then Params would look like this:Params( u_int width_, u_int height_ ) :
width(width_),
height(height_),
rowPitch(0),
But, I'm not a big fan of this, and it doesn't work for all the cases (mutually exclusive params).
In conclusion, I find that passing parameters by "structure" sometimes helps to improve the code in C++ as well. It's not something new and it's common in Python and Objective-C (to some exent), but it's worth remembering that it's an option.
(Incidentally, I'm currently refactoring my image class 8)
See also the coding page.
Subscribe to:
Posts (Atom)




