Converting Wetspot to C

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Converting Wetspot to C

Post 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.
Hristic
Newbie
Posts: 3
Joined: Thu Jan 29, 2009 1:57 pm
Location: Germany

Post 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:
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post 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. :)
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post 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.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

Post 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;

}

User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post 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.
User avatar
Pete
Site Admin
Posts: 887
Joined: Sun Dec 07, 2003 9:10 pm
Location: Candor, NY
Contact:

Post 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.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post 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...
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

Post 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:
User avatar
Pete
Site Admin
Posts: 887
Joined: Sun Dec 07, 2003 9:10 pm
Location: Candor, NY
Contact:

Post 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. :)
Post Reply