And I've been wanting to convert a Ragnarok Sprite Viewer application (which has been coded in C/C++) to Java. At first I decided to give it a go in C sharp. Then I decided to try Java, since both languages are relatively easy to switch to and from.
On my second try, I made more progress, of course, but this time I've created myself a procedural programmed mindfuck of a cluster and have realized that the only real way to do this properly in Java is by converting it via OOP methods.
There is a problem, though: it's hard to distinguish the differences between arrays and pointers in C/C++, because even though the array bracket symbols ("[]") are typically used, I'll often find arrays declared like so, in addition to the former method:
array*; //as opposed to array[];
Other issues exist too, such as c methods/functions with strict, primitive return types (such as unsigned chars) being able to return as explicitly casted objects.
for example:
//example of casted reverse_palette function, which is supposed to return //unsigned char... sprite->palette =(SpritePalette *) reverse_palette (palette, 1024, &palette_size); sprite->palette_size = palette_size;
//structs for individual reference:
typedef struct {
unsigned char *data;
int len;
int width;
int height;
} SpriteImage;
typedef struct {
unsigned char b;
unsigned char g;
unsigned char r;
unsigned char unused;
} SpritePalette;
typedef struct {
char *filename;
unsigned int nimages;
SpriteImage *images;
unsigned int palette_size;
SpritePalette *palette;
} Sprite;
//the logic behind the casted method.
static unsigned char * //<--as you can see...
reverse_palette (unsigned char *palette, int palettelen, int *returnsize)
{
StrBuf *retbuf;
unsigned char *ret;
int x;
retbuf = strbuf_new ();
for (x = 0; x < palettelen; x += 4) {
unsigned char tmp[4];
tmp[0] = palette[x + 2];
tmp[1] = palette[x + 1];
tmp[2] = palette[x];
tmp[3] = '\0';
strbuf_append (retbuf, tmp, 4);
}
ret = retbuf->str;
if (returnsize) *returnsize = retbuf->len;
strbuf_free (retbuf, 0);
return ret;
}
I'm not looking for someone to tell me how to code this with object-oriented design methodology; I'm just looking for a good understanding between the differences of the two languages (besides the fact that C isn't object-oriented and Java is), as well as a guideline to follow when encountering specific problems such as these.

New Topic/Question
Reply



MultiQuote



|