Page 1 of 1

Converting Wetspot to C

Posted: Sat Aug 29, 2009 5:33 am
by Nodtveidt
OK so I'm in the process of converting WETSPOT.BAS to C+SDL. The original code is in pretty straightforward QBASIC which should, in theory, make it very easy. However, it is worthy of note that the original code is also exceptionally sloppy and makes a large number of rookie mistakes. Take this fragment of code for example:

Code: Select all

xA(0) = 0: yA(0) = 0
xA(1) = 0: yA(1) = 1
xA(2) = 1: yA(2) = 0
xA(3) = 0: yA(3) = -1
xA(4) = -1: yA(4) = 0
RESTORE
FOR i = 1 TO 4: READ xA(i), yA(i): NEXT i
FOR i = 1 TO 8: READ Value(i): NEXT i

DATA 0,1,1,0,0,-1,-1,0,100,150,200,250,200,350,300,400,20,20
Can someone please explain to me why someone would set values in an array and then read them from data directly afterward? This is illogical and baffles me. What's even more baffling is the two extra numbers of data at the end...there are no additional READ statements in the entire source code.

There are other such rookie issues in the source code as well, but as this code is well over a decade old, I guess everyone was a newbie once. :) Still, this is a shining example of why standards and required declaration of variables are a must when coding.

The program does not run in the latest QB64 due to the usage of TIMER OFF found at line 745.

Posted: Sat Aug 29, 2009 7:57 am
by Hristic
does it make any differnence if you remove the first five lines?
i also can see no reason for setting variables afterwards.

i would try to remove the first 5 lines, because they do not affect the rest
of the program ( - may be a mistake of the programmer?) :roll:

Posted: Sat Aug 29, 2009 3:18 pm
by Nodtveidt
What I would do is remove the READ and DATA lines...the variables can simply be filled in manually. In fact, C makes it even easier to fill in such arrays. It's not an issue of working around the code, it's an issue of "why was it coded this way in the first place". That's what baffles me. :)

Posted: Sat Aug 29, 2009 3:24 pm
by Mentat
Hm. I personally would probably put the unneeded code anyways into C, then mark it for deletion after making sure the whole program works. So far as I can see, it doesn't hurt to put it in. Just in case it really was important; or if ignoring it prematurely may lead to ignoring other important code accidentally.

Posted: Sun Aug 30, 2009 12:46 pm
by bongomeno
in C you can do an array like this if I am correct...

Code: Select all

#include <iostream>

int main(){

 int x[10];

 for (int i;i<10;i++){
  x[i]=i;
 }

 return 0;

}
or I think you could do...

Code: Select all


#include <iostream>

int x[10];

int main(){

 x[]={1,2,3,4,5,6,7,8,9,10};

 return 0;

}


Posted: Sun Aug 30, 2009 1:41 pm
by burger2227
I would guess that the programmer started out with one idea and saw another way to do it later. Then he forgot to remove the old way later on.

It's possible he just forgot about the duplicate idea. Besides, it does not hurt anything.

Posted: Sun Aug 30, 2009 2:19 pm
by Nodtveidt
That's pretty likely. The only thing is that the data doesn't match. The old values will end up being overwritten anyways though, so no biggie. I haven't traced the code deep enough to see what these arrays do just yet, but I'm sure they're important.

bongomeno: actually, that code you wrote would be C++, not C. You can only do

Code: Select all

#include <iostream>
in C++. The rest of that is correct though, although that particular code fragment wouldn't be used here. I would do something more like

Code: Select all

int xA[5] = { 0, 1, 0, 2, 1 };
which is not only much cleaner but also allows the insertion of absolute values, which is what this program requires.

Posted: Mon Aug 31, 2009 1:51 pm
by Pete
I believe Angelo Mottola might have actually recoded Wetspot 2 in C a few years ago...or maybe he was making another sequel in C. I remember he had a website called EC++ (Enhanced Creations ++) a while back with all of his projects on it, but it seems to be gone now.

Posted: Mon Aug 31, 2009 3:38 pm
by Nodtveidt
Nah, his new site's still around:

http://www.ecplusplus.com/

That's where I got the original Wetspot code from to begin with. :D He's been slowly working on Wetspot 3 which is coded in C...there's a demo version on the site. I haven't tried it yet...

Posted: Mon Aug 31, 2009 10:19 pm
by bongomeno
Nodtveidt wrote:That's pretty likely. The only thing is that the data doesn't match. The old values will end up being overwritten anyways though, so no biggie. I haven't traced the code deep enough to see what these arrays do just yet, but I'm sure they're important.

bongomeno: actually, that code you wrote would be C++, not C. You can only do

Code: Select all

#include <iostream>
in C++. The rest of that is correct though, although that particular code fragment wouldn't be used here. I would do something more like

Code: Select all

int xA[5] = { 0, 1, 0, 2, 1 };
which is not only much cleaner but also allows the insertion of absolute values, which is what this program requires.
I did not put iostream, but this forum take things off my code when I post here usually... I had the (dot) h after it lol :wink:

Posted: Wed Sep 02, 2009 8:16 pm
by Pete
Nodtveidt wrote:Nah, his new site's still around:

http://www.ecplusplus.com/
Whoops! I guess I am a poor Googler. Haha. Good luck with the port. :)