Thursday, December 27, 2012

to do list

I've written a bit of hobby code this semester, but I haven't posted any of it. I'm posting this to make me go do it. I also plan on setting up a git server started, so I don't have to use other file servers.

If you know me, remind mute to get that code up here.

Tuesday, September 11, 2012

School is starting

School is starting now and my summer is over. I'm very disappointed in myself that I didn't get more coding done, however, I've learned a bit about SDL and my Sudoku solver blows my dad's out of the water (it can even solve some puzzles that his cannot).

This semester, I'm taking Game Programming 1 and Game Physics. For both of those classes, I might be writing relevant code, so I might post some assignments I found interesting.

I would like to write a UI for my Sudoku solver, but we'll see. I'm trying to spend my spare time working relevant stuff like this (instead of just using my laptop for gaming), however I've got a lot of homework too, so we'll see about that too.

Saturday, August 18, 2012

I was bored because I couldn't figure out this thing...

Building a (week) game engine using SDL, will probably convert it to OpenGL eventually, but until then, THIS:

 #include <iostream>  
   
 class Number  
 {  
 private:  
      float x;  
 public:  
      Number( float input)  
      {  
           x = input;  
      }  
 }  
   
 class OtherNumber : public Number  
 {  
 private:  
   
 public:  
      OtherNumber( float input )  
      {  
           x = 0;  
           x -= input;  
      }  
 }  
   
   
 int main()  
 {  
   
   
   
 }  

Now, I like to think of my self as pretty fluent in C++ syntax, but for the life of me I can't figure out what the heck I'm doing wrong. This isn't the code I'm actually working, but it has the same syntax problem as what I'm actually doing. I have a class that acts one way, then another one the is almost exactly the same, but it has a compleatly differnt constructor and a few extra functions attached to it. So, I was going just inharit off of it overloading the constructor, but it doesn't seem to be working... clearly I'm doing something wrong...


Saturday, July 21, 2012

I was bored, so I wrote a Sudoku Solver

My Dad wrote a Sudoku solver that works in Excel . It's slow. I was discussing with him how he built it and I starting thinking how I would build one.

So I did. And it's messy. But it works!


It's messy, it's not a release, and the comments suck... but it works! (now, someone give me a puzzle that breaks it!

ToDo:
1: Better Input System
2: Better Debug Logging
3: Suggestions?


http://www.mediafire.com/?mg9elrhbwkb63om

1:  #include <iostream>  
2:  #include "math.h"  
3:  #include <string>  
4:  using namespace std;  
5:  bool Debug = 0;  
6:  char abs(char x) //GCC is missing a char abs(char) function... wrote this as an after thought.  
7:  {  
8:    if( x < 0)  
9:    {  
10:      return (0-x);  
11:    }  
12:    else return x;  
13:  }  
14:  class puzzle  
15:  {  
16:       char PuzzleValues[9][9];  
17:       unsigned short sets[3][9];  
18:  public:  
19:       int updateSets() //returns number of changes. return system could be faster if integrated into  
20:       {  
21:            puzzle temp = *this;  
22:            //horizontal sets  
23:            for(int y = 0; y < 9 ; y++)  
24:            {  
25:                 sets[0][y] = 0;  
26:                 for(int x = 0; x < 9 ; x++)  
27:                 {  
28:                      if( GetValue(y,x) != 0 )  
29:                      {  
30:                           sets[0][y] += ((1 << (abs(GetValue(y,x))-1)) );  
31:                      }  
32:                 }  
33:            }  
34:            //vertical sets  
35:            for(int x = 0; x < 9 ; x++)  
36:            {  
37:                 sets[1][x] = 0;  
38:                 for(int y = 0; y < 9 ; y++)  
39:                 {  
40:                      if( GetValue(y,x) != 0 )  
41:                      {  
42:                           sets[1][x] += ( (1 << (abs(GetValue(y,x))-1)) );  
43:                      }  
44:                 }  
45:            }  
46:            //box sets  
47:            for(int group = 0; group < 9 ; group++)  
48:            {  
49:                 sets[2][group] = 0;  
50:                 for(int cell = 0; cell < 9; cell++)  
51:                 {  
52:                      int x = (3*(group%3)+cell%3);  
53:                      int y = (3*(group/3)+cell/3);  
54:                      if( GetValue(y,x) != 0 )  
55:                      {  
56:                           sets[2][group] += ( (1 << (abs(GetValue(y,x))-1)) );  
57:                      }  
58:                 }  
59:            }  
60:            int changes = 0;  
61:            for(int loop = 0; loop < 27 ; loop++ )  
62:            {  
63:                 if( sets[loop/9][loop%9] != temp.sets[loop/9][loop%9] )  
64:                 {  
65:                      changes++;  
66:                 }  
67:            }  
68:            return changes;  
69:       }  
70:       /*Objects of pointers are set to CELL Sets and Ranks, returns 0 for success, 1 or 3 for failed Set Pointer, 2 or 3 for failed RankPointer*/  
71:       short cellSet( int y , int x , short* Rank )  
72:       {  
73:            if( !PuzzleValues[y][x] )  
74:            {  
75:                 short Set = 0;  
76:                 short Temp;  
77:                 Temp = ( (short)  
78:                      0x1ff - //4: then take 1 1111 1111 and subtract the row ORs from that  
79:                      (  
80:                      sets[0][y] | //1: check first row  
81:                      sets[1][x] | //2: OR that with 2nd row  
82:                      sets[2][(x/3)+(y - (y % 3 ))] //3: OR that with 3rd row to for the list of numbers that are close to a number  
83:                 )  
84:                      );  
85:                 Set = Temp;  
86:                 if(Rank != NULL )  
87:                 {  
88:                      short count = 0 ;  
89:                      while (Temp) //count the number of 1s in Temp  
90:                      {  
91:                           count++;  
92:                           Temp &= (Temp - 1) ;  
93:                      }  
94:                      *Rank = count;  
95:                 }  
96:                 return Set;  
97:            }  
98:            else  
99:            {  
100:                 if(Rank != NULL)  
101:                 {  
102:                      *Rank = 0;  
103:                 }  
104:                 return 0;  
105:            }  
106:       }  
107:       //returns value at point, negitive for orignal puzzle  
108:       char GetValue( int y, int x )  
109:       {  
110:            return PuzzleValues[y][x];  
111:       }  
112:       //pass negitive VALUE for orignal puzzle  
113:       int SetValue( int y, int x, char VALUE /*-9 to 9*/ )  
114:       {  
115:            if( -9 <= VALUE && VALUE <= 9 )  
116:            {  
117:                 PuzzleValues[y][x] = VALUE;  
118:                 return 1;  
119:            }  
120:            else return 0;  
121:       }  
122:       //display the table. build a better table with ascii lines  
123:       string Display()  
124:       {  
125:            string OUTPUT;  
126:            for( int y = 0 ; y < 9 ; y++)  
127:            {  
128:                 if( !(y%3))  
129:                 {  
130:                      OUTPUT += "+---------+---------+---------+\n";  
131:                 }  
132:                 for( int x = 0 ; x < 9 ; x++)  
133:                 {  
134:                      if( !(x%3) )  
135:                      {  
136:                           OUTPUT += "|";  
137:                      }  
138:                      if( 1 <= GetValue(y,x) && GetValue(y,x) <= 9 )  
139:                      {  
140:                           OUTPUT += ' ';  
141:                           OUTPUT += (GetValue(y,x) + 48);  
142:                           OUTPUT += ' ';  
143:                      }  
144:                      else if( -9 <= GetValue(y,x) && GetValue(y,x) <= -1 )  
145:                      {  
146:                           OUTPUT += '{';  
147:                           OUTPUT += (( 0 - GetValue(y,x) ) + 48 );  
148:                           OUTPUT += '}';  
149:                      }  
150:                      else  
151:                      {  
152:                           OUTPUT += "  ";  
153:                      }  
154:                 }  
155:                 OUTPUT += "|\n";  
156:            }  
157:            OUTPUT += "+---------+---------+---------+\n";  
158:            return OUTPUT;  
159:       }  
160:       //fills cells currently at rank1 that aren't full. returns number of changes  
161:       int fillCells()  
162:       {  
163:            int changes = 0;  
164:            //int CellInfluance[9][9];  
165:            for ( int x = 0; x < 9 ; x++ )  
166:            {  
167:                 for ( int y = 0; y < 9 ; y++ )  
168:                 {  
169:                      //////should be replaced with the new fuction that does this for you.  
170:                      //finds the binary list of 1 to 9 that are there.  
171:                      int q = 0x1ff - ( //4: then take 1 1111 1111 and subtract the row ORs from that  
172:                           sets[0][y] | //1: check first row  
173:                           sets[1][x] | //2: OR that with 2nd row  
174:                           sets[2][(x/3)+(y - (y % 3 ))] //3: OR that with 3rd row to for the list of numbers that are close to a number  
175:                      );  
176:                      //if power of 2, then return  
177:                      for ( int p = 0 ; p < 9 ; p++ )  
178:                      {  
179:                           //reworked with previusly mentioned relacement  
180:                           if(q == (1 << p) && GetValue( y , x ) == 0)  
181:                           {  
182:                                SetValue( y , x , (p+1) );  
183:                                changes++;  
184:                           }  
185:                      }  
186:                 }  
187:            }  
188:            return changes;  
189:       }  
190:       int Solved()  
191:       {  
192:            for(int x = 0 ; x < 81 ; x++)  
193:            {  
194:                 if( !GetValue( x/9 , x%9 ) )  
195:                      return 0;  
196:            }  
197:            return 1;  
198:       }  
199:       int unSolveable() //returns 0 if puzzle is unsolveable, 1 if it might be solveable  
200:       {  
201:            for(int x = 0 ; x < 81 ; x++)  
202:            {  
203:                 if( !GetValue( x/9 , x%9 ) && !cellSet( x/9 , x%9 , NULL ) )  
204:                 {  
205:                      return 1;  
206:                 }  
207:            }  
208:            return 0;  
209:       }  
210:  };  
211:  int Solve(puzzle *inPuzzle)  
212:  {  
213:       puzzle WCopy = *inPuzzle;  
214:       do  
215:       {  
216:            if( Debug == 1){  
217:                 cout << WCopy.Display();  
218:            }  
219:            WCopy.updateSets();  
220:       } while( WCopy.fillCells() );  
221:       if( Debug == 1){  
222:            cout << WCopy.Display();  
223:       }  
224:       if( !WCopy.Solved() )  
225:       {  
226:            if( !WCopy.unSolveable() )  
227:            {  
228:                 if( Debug == 1){  
229:                      cout << WCopy.Display();  
230:                 }  
231:                 short LowestRank = 10;  
232:                 short LowestSet;  
233:                 char LowestRankX;  
234:                 char LowestRankY;  
235:                 //for loop that finds first lowest rank  
236:                 for(char y = 0 ; y < 9 ; y++ )  
237:                 {  
238:                      for (char x = 0; x < 9 ; x++ )  
239:                      {  
240:                           short RANK = 0;  
241:                           short SET = WCopy.cellSet( y , x , &RANK );  
242:                           if( RANK != 0 && RANK < LowestRank && !WCopy.GetValue(y, x))  
243:                           {  
244:                                LowestRank = RANK;  
245:                                LowestSet = SET;  
246:                                LowestRankX = x;  
247:                                LowestRankY = y;  
248:                           }  
249:                      }  
250:                 }  
251:                 //loop that guesses values out of that xy rank  
252:                 for( short Guess = 0 ; Guess < 9 ; Guess++ )  
253:                 {  
254:                      if( (1 << Guess) & LowestSet )  
255:                      {  
256:                           puzzle GuessCopy = WCopy; //make a copy  
257:                           GuessCopy.SetValue( LowestRankY , LowestRankX , Guess + 1 ); //dump guess into the copy  
258:                           if( Debug == 1){  
259:                                cout << WCopy.Display();  
260:                           }  
261:                           if( Solve( &GuessCopy ) )  
262:                           {  
263:                                if( Debug == 1){  
264:                                     cout << WCopy.Display();  
265:                                }  
266:                                *inPuzzle = WCopy = GuessCopy;  
267:                                return 1;  
268:                           }  
269:                      }  
270:                 }  
271:                 return 0;  
272:                 //if one guess wins, "*inPuzzle = WCopy;" and return 1  
273:                 //if a guess fails, try next  
274:                 //if all guesses fail, return 0;  
275:            }  
276:            else  
277:                 return 0;  
278:       }  
279:       else  
280:       {  
281:            if( inPuzzle != NULL )  
282:                 *inPuzzle = WCopy;  
283:            return 1;  
284:       }  
285:  }  
286:  int main(int argc, char *argv[])  
287:  {  
288:       string Input;  
289:       if(argc <= 1)  
290:       {  
291:            cout << "ERROR!, you're doing it wrong... Imma put more detal here later... \n" <<  
292:                 "OR I could just solve a puzzle for you! How's that sound!?\n" <<  
293:                 "how about this hard one! =D\n";  
294:            Input = "86..2.......7...59.............6.8...4.........53....7..........2....6....75.9..."; //hard puzzle  
295:            Debug = 0;  
296:       }  
297:       if(argc > 1)  
298:       {  
299:            Input = argv[1];  
300:       }  
301:       if(argc > 2)  
302:       {  
303:  //          char test =  
304:            Debug = ( *argv[2] - '0');  
305:       }  
306:       //system("mode con cols=82");  
307:       puzzle MainPuzzle;  
308:       //     Input = "86..2.......7...59.............6.8...4.........53....7..........2....6....75.9..."; //hard puzzle  
309:       //     Input = ".931.564.7.......55.12.93.72.......3.369.752.9.......13.24.81.96.......4.473.285."; //easy puzzle  
310:       //     Input = ".3..........28.1.7.78.6.4.....8.2.7..82...54..9.5.4.....1.7.25.8.6.21..........8."; //mid puzzle  
311:       cout << "starting input:\n" << Input << "\nstarting puzzle:\n";  
312:       for(int y = 0; y < 9 ; y++ )  
313:       {  
314:            for(int x = 0; x < 9 ; x++ )  
315:            {  
316:                 cout << Input[y*9 + x];  
317:                 char q = Input[ 9 * y + x ];  
318:                 if( q != '.' )  
319:                 {  
320:                      MainPuzzle.SetValue( y , x , 0 - (q - 48) );  
321:                 }  
322:                 else  
323:                 {  
324:                      MainPuzzle.SetValue( y , x , 0 );  
325:                 }  
326:            }  
327:            cout << '\n';  
328:       }  
329:       cout << MainPuzzle.Display();  
330:       Solve( &MainPuzzle );  
331:       cout << "\n\nDERP!\n\n";  
332:       cout << MainPuzzle.Display();  
333:       //MainPuzzle.updateSets();  
334:       //short CellSets[2][9][9];  
335:       //bool run = true;  
336:       //while( run )  
337:       //{  
338:       //     MainPuzzle.updateSets();  
339:       //     while(MainPuzzle.fillCells() )  
340:       //     {  
341:       //          MainPuzzle.updateSets();  
342:       //          cout << '\n' << MainPuzzle.Display();  
343:       //     }  
344:       //     for( int x = 0; x < 81 ; x++)  
345:       //     {  
346:       //          short q; //rack  
347:       //          short p; //sets  
348:       //          p = MainPuzzle.cellSet( x%9 , x/9 , &q );  
349:       //          CellSets[0][x/9][x%9] = q;  
350:       //          CellSets[1][x/9][x%9] = p;  
351:       //     }  
352:       //     run = true;  
353:       //  
354:       //}  
355:  //     system( "pause" ); //works only Visual Studio compiler.  
356:  }  

Tuesday, June 19, 2012

I wasn't bored so I haven't been blogging

This blog is still a thing, and I still want to produce content for it, but I haven't been blogging lately because I've been busy (and my code is dumb).

Right now I'm taking 8 credit hours over 4 weeks. These classes are Linear Algebra and Physics. The things I'm learning in these classes make my code look really stupid. The code I've writen was created for simple 2d side scroller simulation, but I was solving collision equations using Geometry. Made sense to a guy with a High School level education, but now I'm learning things that makes that look really dumb because you can do the same thing with half as many calculations.

For example, the last thing I was working on was a way to detect if a point was left or right of a line. I was going to use a look a geometry based collision algorithm combines with a look up table, but now I know that if you have a line that is AB and you want to see if point C is left of that line, then you could just use this code:

 int Q = (Bx-Ax)(Cy-Ay) - (By-Ay)(Cx-Cy)  

Then the sign of Q is related to the leftness or rightness of the point to the line (can't remember which, and 0 is on the line). A lot of my code could be simplified using things I've learned in Linear Algebra and I was in the process of rewriting the whole thing anyway (I knew it was flawed and overly complicated, but I couldn't figure out how).

Anyway, I miss blogging and writing code for fun, but I'm really busy learning why the code I've already written is dumb and inefficient. Once I finish, I'll start up again!

Thursday, May 3, 2012

Steam for Linux means Linux for Steam

Steam on Linux. That's a thing. It's coming. They have a naively running L4D2 working on Ubuntu using AMD's Linux drivers.

Steam on Linux has been "coming" for a long time. They've had job postings for Linux OpenGL developers for years. The reason why it's actually news now is because a member of the press was aloud to see Steam on Linux.

Valve is also working on a version of Steam designed to be used on a TV. That means UI designed for a lower resolution and to be controlled with something like a console controller (XBox controller is a Windows USB device).  They are going to great efforts to clone an console-like experience.

What we need is a distro of Linux Designed for Steam. Why? Because for most people, Linux is entirely to much effort.

Ubuntu answers most of those problems for day to day computer use.  If all you do is web applications and simple Office-style work, Ubuntu is a great Linux distro.

We need Ubuntu for gaming. We need a Linux distro that uses minimal background CPU and Memory, give games as much of the graphics card as possible, include Linux drivers for gaming level graphics cards, and as little else as possible. No OpenOffice, no ThunderBird, no IDE. Just a web browser, Steam, and an Ubuntu-like app-store to let people add what they'll use. It needs a UI designed for both Keyboard/Mouse and TV/Gamepad.

Valve could build this Linux distribution, and could even help push Nvidia and ATI to better their driver support, but more likely it would have to come out of the Linux comunity and, with Steam support, I can see the Linux community getting behind gaming in a big way if a company as influential as Valve pushed full native support for Linux.

If we had Gamebuntu... SteamBuntu, yeah, lets go with that. If we had SteamBuntu, then HP, Dell, Toshiba, Acer, Asus, or anyone else could build computers like we saw for early HP/Dell netbooks with Ubuntu.  We could see Alienware style gaming grade machines that ship with SteamBuntu instead of Windows. We might even see smaller formfactor systems designed like a modern game console that fit next to your TV.  These systems would ship working with Steam and all the drivers they need.

Valve has said that they are not planning on going into the hardware market any time soon, but they don't have to for there to be a ValveBox.

I not only think this is what should happen, but I think it will happen. Assuming Valve gets Steam on Linux by the end of the year (I know, maybe a bit too hopeful), I think we could see more game studios publish for Linux (we're already seeing that with many indie studios). Within a year or two we will probably see a version of Linux pre-configured with Steam. Assuming Linux For Steam becomes a popular alternative to Windows, we will start to see Dell or HP making gaming grade systems that ship with SteamBuntu (Microsoft will probably pay them to not do this for as long as possible, but that can't last if their is a large enough demand).

Thursday, April 26, 2012

Still working on the NewLine... it's boring...

GameMath.h is getting more complex than I original thought it would get.  I'm working on ways to make it faster and I'm adding functionality to Line. I may divide it into a separate .h/.cpp per class to make it a little more readable.

Here's what it looks like now.


 //GameMath.h  
 //designed to handle all the 2D math  
 //involved in making a 2D game engine.  
 //I may pull out stuff like the line   
 //and intPoint class as seperate .h/.cpp  
 //for readablilty. That will depend   
 //on how complex this thing gets  
 //intPoint CLASS :D  
 class intPoint  
 {  
 public:  
      //default constructor  
      intPoint();  
      //constructor for x/y  
      intPoint(int X, int Y);  
      //add two intPoints  
      intPoint operator+ (intPoint B);  
      intPoint operator+= (intPoint B);  
      //subtract two intPoints  
      intPoint operator- (intPoint B);  
      intPoint operator-= (intPoint B);  
      //multiply  
      intPoint operator* (float Mult);  
      intPoint operator/ (float Dev);  
      bool operator< ( intPoint input );  
      bool operator> ( intPoint input );  
      bool operator<= ( intPoint input );  
      bool operator>= ( intPoint input );  
      //these are public since there isn't really   
      //a point to making them private  
      int x;  
      int y;  
 };  
 //line class  
 class line  
 {  
      intPoint Org;  
      intPoint Dis;  
      float M;  
      float B;  
 public:  
      //Intersection Stuff  
      bool SlideTo( intPoint* OUTPUT , line CD );  
      bool IntersectIntPoint( intPoint* OUTPUT , line CD );  
      //Change Values  
      line Shift( intPoint ShiftBy ); //Shift the point of org by a value  
      line SetOrg( intPoint MoveTo ); //set a new point of org  
      line SetDis( intPoint NewEnd ); //set new endpoint  
      //get fuctions  
      intPoint GetOrg();  
      intPoint GetDis();  
      float GetM();  
      float GetB();  
      //Constructors  
      line( line LineWith , intPoint newSlope );  
      line( intPoint Origin , intPoint Displacement );  
      line(); //base constructor  
      void Draw();  
 };  
 //region  
 class Region  
 {  
 public:  
      bool InRegion( intPoint C );  
 };  
 class BoxRegion : public Region  
 {  
      intPoint Org;  
      intPoint Size;  
 public:  
      bool InRegion( intPoint C );  
      BoxRegion( intPoint Org , intPoint Size );  
      BoxRegion();  
 };  
 class CircleRegion : public Region  
 {  
      intPoint Org;  
      int SizeSquared;  
 public:  
      bool InRegion( intPoint C );  
      CircleRegion( intPoint CenterPoint , short unsigned int Size );  
      CircleRegion();  
 };  


Wednesday, April 25, 2012

I was REALLY bored... so I wrote TheMemoryEater1000


I haven't posted anything in a while, so here is The Memory Eater: 1000. All it does it eat memory until it crashes... cuz yeah... why not. The 2000 version might have more features, but hopefully I won't be so bored I have to write it.

 //THE MEMORY EATER: 1000  
 #include <iostream>  
 using namespace std;  
 void CreateDumbMemory( int INPUT )  
 {  
      int KBToEat = INPUT * 1024;  
      for(int x = 0; x < KBToEat ; x++ )  
      {  
           new char[1024];  
      }  
      cout << "OMNOMNOM! (ate " << INPUT << "meg)\n";  
 }  
 void main()  
 {  
      int INPUT;  
      cout << "I am the Memory Eater 5000!\n\n";  
      do  
      {  
           cout << "Please Enter (in MegaBytes)\n"   
                "how more memory I should eat?\n:";  
           cin >> INPUT;  
           CreateDumbMemory( INPUT );  
      }while(INPUT);  
 }  

Wednesday, April 11, 2012

I had two seconds, so I made an update

Lately I've been extremely busy and it's been a full week since the last time I posted an update, so I figured I'd post this saying that I haven't given up on this, I just have no time between helping with Minecraft, TX and school.

THIS IS STILL A THING!, I've just too busy to doing things lately. I'll be back! I'll finish the new Line class this weekend!

Thursday, April 5, 2012

New "line" class

Prototype for new "line" class.

 class line  
 {  

      intPoint Org;  
      intPoint Dis;  
      float M;  

 public:  

      //Intersection Stuff  
      bool SlideTo( intPoint* OUTPUT , line CD );  
      bool IntersectPoint( intPoint* OUTPUT , line CD );  

      //change values  
      void Shift( intPoint ShiftBy );  
      void SetOrg( intPoint MoveTo );  
      void SetDis( intPoint NewEnd );  

      //Constructors  
      line( line LineWith , intPoint newSlope );  
      line( intPoint Origin , intPoint Displacement );  

      //Draw!  
      void Draw();  

 };  

This new version has two primary changes.

  • I added a float for the slope (M).
  • I converted the definition to be a point relative to the Origin and a Displacement relative to the first point.

I did both of these (and created the new constructors) to make polygon collision faster. My method of detecting if two polygons collide is based on drawing a line from each point of polygon A that represent the displacement, then you detect if those lines intersect with any line of polygon B. This means you are calculating the same slope (each displacement line) several times. If you make slope part of the line and build constructors that let you shift the point of origin you only have to calculate the slope once.

It doesn't make it easier, but it does make it faster. (I still don't know, however, if "faster" will even be relevant)

(ohyeah, and renamed Point to be intPoint because I might make a floatPoint someday)

Wednesday, April 4, 2012

Priorities

Ok, so I really need to figure out what I need to do next. SO, Imma make a simple billeted list of things to do with witch I will sort by priority!

HERE WE GO:
  • redesign Line class (HIGH priority)
  • Boxes (after LineClass)
  • Polygons (more complex Box)
  • Polygon Collision (fiction in Polygon)
  • Sliding  collision (use of Line Class for sliding collision)
  • Jumping Box "Game"! (use all that BS above to build a SUPER simple side scrolled)
EVENTUALLY: (maybe now, maybe later?)
  • Build a full render system (work queues, window placements, zoom, pan, sprite handling)  (meh)
  • Build a concept render system (window placement, zoom, pan)! (will make the thing above easier and make porting to a new engine easier [AGK] )
  • switch to APK (gawgawgw)
The "eventually" stuff can be done at any point, but I'm going to procrastinate and push it way back... except maybe the "Concept Render System" (haven't decided on that yet).

edit:
also, I might might clone Tetris... but I don't think that will be my test tools for the Render System thingies.

Saturday, March 31, 2012

Polymorphic Queue Problems

And now this doesn't work. I assume I'm going to have to do something involving "new" and "delete"...


 #include <iostream>  
 #include <queue>  
 using namespace std;  
 class thing1  
 {  
 public:  
   virtual void thingTest()  
   {  
     cout << "I AM THING 1\n";  
   }  
 };  
 class thing2: public thing1  
 {  
 public:  
    void thingTest()  
   {  
     cout << "I AM THING 2\n";  
   }  
 };  
 void DoMoreStuff( thing1& temp )  
 {  
      temp.thingTest();  
 }  
 queue <thing1> QueueThingy;  
 int main()  
 {  
      QueueThingy.push( thing2() );  
      QueueThingy.push( thing1() );  
      QueueThingy.push( thing2() );  
      QueueThingy.push( thing1() );  
      QueueThingy.push( thing2() );  
      while( QueueThingy.size() )  
      {  
           QueueThingy.front().thingTest();  
           QueueThingy.pop();  
      }  
 }  

Expected:
I AM THING 2
I AM THING 1
I AM THING 2
I AM THING 1
I AM THING 2

Actual:
I AM THING 1
I AM THING 1
I AM THING 1
I AM THING 1
I AM THING 1

Edit (thanks Matt):
Now I get expected... but I'm not TOTALLY convinced this doesn't cause a memory leak...

 #include <iostream>  
 #include <queue>  
 using namespace std;  
 class thing1  
 {  
 public:  
   virtual void thingTest()  
   {  
     cout << "I AM THING 1\n";  
   }  
 };  
 class thing2: public thing1  
 {  
 public:  
    void thingTest()  
   {  
     cout << "I AM THING 2\n";  
   }  
 };  
 void DoMoreStuff( thing1& temp )  
 {  
      temp.thingTest();  
 }  
 queue <thing1 * > QueueThingy;  
 void main()  
 {  
      QueueThingy.push( new thing2() );  
      QueueThingy.push( new thing1() );  
      QueueThingy.push( new thing2() );  
      QueueThingy.push( new thing1() );  
      QueueThingy.push( new thing2() );  
      while( QueueThingy.size() )  
      {  
           QueueThingy.front()->thingTest();  
           delete QueueThingy.front();  
           QueueThingy.pop();  
      }  
 }  

Friday, March 30, 2012

Weekend Started, so I fixed this:

http://stackoverflow.com/questions/9939739/simple-polymorphism

so with some help from Stack Overflow (and Matt, one of my only commenters; HI MATT!) , I did this stuff:

 #include <iostream>  
 using namespace std;  
 class thing1  
 {  
 public:  
   virtual void thingTest()  
   {  
     cout << "I AM THING 1\n";  
   }  
 };  
 class thing2: public thing1  
 {  
 public:  
    void thingTest()  
   {  
     cout << "I AM THING 2\n";  
   }  
 };  
 void DoStuff( thing1 temp )  
 {  
   temp.thingTest();  
 }  
 void DoMoreStuff( thing1& temp )  
 {  
      temp.thingTest();  
 }  
 int main()  
 {  
      //these look more like a thing1  
   DoStuff( thing2() );  
      ( (thing1) thing2() ).thingTest();  
      //look like thing2s  
      thing2().thingTest();  
      DoMoreStuff( thing2() );  
 }  

This outputs:
I AM THING 1
I AM THING 1
I AM THING 2
I AM THING 2
so, now to make the LinkedList to store Queues of Thing1s that could actually be Thing2s. (my render system will work by letting the coder dump things into a "todo list" and render the whole list at once)

Thursday, March 29, 2012

My Linked List

So... I can't figure out how to make this work. I'm pretty sure I have to do something involving pointers or something. My RenderSys will work on the same principle, so this totally needs to work. Anyway, here's what I'm having problems with:

 #include <iostream>  
 using namespace std;  
 class thing1  
 {  
 public:  
      void thingTest()  
      {  
           cout << "I AM THING 1!\n";  
      }  
 };  
 class thing2: public thing1  
 {  
 public:  
      void thingTest()  
      {  
           cout << "I AM THING 2\n";  
      }  
 };  
 void DoStuff( thing1 temp )  
 {  
      temp.thingTest();  
 }  
 void main()  
 {  
      DoStuff( thing2() );  
 }  

I expected it to output: 
"I AM THING 2"
But instead I got:
"I AM THING 1!"
clearly, I'm doing something wrong...

Protecting Myself

So, I've been reading all these stories online about tiny developers who make the interesting a new games only to have their games stolen quickly by bigger developers.

Now, I don't nearly have a game yet, BUT, someday I might. Right now I have a few building blocks of the massive structure of a working game. If some day I decide to sell it (or, more likely, give it away along with a "Donate" button), I will probably need to find a way to protect my code somehow.

The real problem here isn't that I think someone is going to steal my work and make money off it. That's fine, I don't mind if people do that at all (yeay free-flow of information!). The problem is that they could sue me if they copyright code based on mine, unless I can prove that I did it first. 

Also, just because I'm a coder and full of myself, I'd also like credit where it's due. If some one uses some of my code to build their awesome million dolor game (lol, no, that would never happen!), then I want credit (well, really I'd like a cut if I can get it, but w/e).

Licences I'm looking at:
Apache License
Creative Commons (they have a few for different uses)
CopyLeft
GNU General Public License
Any others that I missed?
Thoughts? (comments below)

Wednesday, March 28, 2012

Int to Char[4] and back again

I have decided to write a render system that creates a string class and as you add things to be rendered it add info to the string like a script. then when go to render, it pops off chars one at a time, reading it like a script and positioning objects on the screen based on their relative location the the camera definitions.  In order to do all this, I need a way to pass a int (4bytes) into 4 char values (1byte each).  Here is some example code I wrote to do just that:

 int CharsToInt( char top , char midt , char midb , char bot )  
 {  
      return(       
           (((int) top & 0xFF ) << 24) |   
           (((int) midt & 0xFF ) << 16) |   
           (((int) midb & 0xFF ) << 8) |   
           (((int) bot & 0xFF )) );  
 }  
 bool IntToChars( int INPUT , char *top , char *midt , char *midb , char *bot )  
 {  
      //going to rewrite this so that you just pass a pointer to a char[4].  
      //this would make passing from a String class easier  
      if( top && midt && midb && bot )  
      {  
           *top = (char) ( INPUT >> 24 ) & 0xFF;  
           *midt = (char) ( INPUT >> 16 ) & 0xFF;  
           *midb = (char) ( INPUT >> 8 ) & 0xFF;  
           *bot = (char) ( INPUT & 0xFF );  
           return true;  
      }  
      else  
           return false;  
 }  

EDIT: Rewrote it to be cleaner:

 int CharsToInt( char INPUT[] )  
 {  
      return(       
           (((int) INPUT[0] & 0xFF ) << 24) |   
           (((int) INPUT[1] & 0xFF ) << 16) |   
           (((int) INPUT[2] & 0xFF ) << 8) |  
           (((int) INPUT[3] & 0xFF )) );  
 }  
 bool IntToChars( int INPUT , char OUTPUT[] )  
 {  
      if( OUTPUT )  
      {  
           OUTPUT[0] = (char) ( INPUT >> 24 ) & 0xFF;  
           OUTPUT[1] = (char) ( INPUT >> 16 ) & 0xFF;  
           OUTPUT[2] = (char) ( INPUT >> 8 ) & 0xFF;  
           OUTPUT[3] = (char)  INPUT     & 0xFF;  
           return true;  
      }  
      else  
           return false;  
 }  

Wednesday, March 21, 2012

Render System Thoughts

I couldn't sleep, so I thought I'd jot some render system thoughts down.

I need to generate a render system that lives independently of my math system, but my math system has the power to dump data into the render system. I can't imagine a situation where my render system would need MathGraph logic, but it might happen.

The RenderSys I have in mind would have a list of things it is expected to do during a render cycle. Some of these commands might be:
DrawLine(  point , point , color );
DrawBox( point , point , color );
DrawSprite( string ObjectName , int SpriteFrame  );  [for now, my engine can remain vector-based, so sprites aren't strictly necessary]
To name a few. Every time something needs to be put on the screen from the main loop, what really happens  is a command is called that adds one of these to a queue. When the Render() function is called, it analyzes the render window, decides the dimensions of the that window, based on the it's location in the world and zoom, and then begins to dequeue the commands lined up during the rest of the program.

The main advantage to a system like this, is that rendering and game speed can run independently.  If the game should run at 200 cycles per second, then that is easily possible. The main loop would loop until a stopwatch function (called throughout the program, or after every main loop) says it's time to render again, and it takes the most recently completed RenderQueue, and then begins to operate on it.

This could also be used as a first step in multithreaded code. The main, more "mathy", loop (all the math of the game, with none of the graphics), could run on one thread, while the RenderSystem could run on a completely different thread. This would, again, mean that the main thread would run at exactly it's expected speed, but RenderSystem, would run as fast as it possibly can, taking the most recently completed RenderBuffer every time it runs. If the render system gets behind (ie, less than max frame rate), it doesn't hurt the main gameplay speed (if you aren't getting max frame rate, your game still appears to run at normal speed).

Finally, as a disclaimer, I've never done anything like this before (or even of this magnitude)... so I'm not even 100% sure I know if it would work they way I think it should or even how to create such a machine... we'll see...

And now I live on BlogSpot

I was using Tumblr, but I couldn't make it do the things I wanted to. In particular, I couldn't make it format code the way I wanted it to be formatted.

1:  //Scribbles.cpp  
2:  //if some one knows how to quote code better than this, I would be very happy  
3:  //http://www.mediafire.com/?ba62kkx78ft8p <-Scribbles.cpp and Scribbles.exe  
4:  //most of my code for now will probably use DarkGDK for now. it’s a very simple  
5:  //free c++ engine  
6:  #include “DarkGDK.h”   
7:  #define SCREENX 640  
8:  #define SCREENY 480  
9:  void Render()  
10:  {  
11:       dbText(0,0,”Press Space!”);  
12:       dbSync();  
13:  }  
14:  void DarkGDK ( void )  
15:  {  
16:       dbSyncOn  ( );  
17:       dbSyncRate ( 0 );  
18:       int x = dbRND(SCREENX);  
19:       int y = dbRND(SCREENY);  
20:       int LOOPS = 0;  
21:       // our main loop  
22:       while ( LoopGDK ( ) )  
23:       {  
24:            LOOPS++;  
25:            if(LOOPS == 60)  
26:            {  
27:                 Render();  
28:                 dbClear(0,0,0);  
29:                 LOOPS = 0;  
30:            }  
31:            int newX = x;  
32:            int newY = y;  
33:            x = dbRND(SCREENX);  
34:            y = dbRND(SCREENY);  
35:            dbInk(dbRGB(dbRND(256),dbRND(256),dbRND(256)),dbRGB(0,0,0));  
36:            dbLine(x,y,newX,newY);  
37:            if(dbKeyState(57))  
38:            {  
39:                 Render();  
40:            }  
41:       }  
42:       return;  
43:  }  

Tuesday, March 20, 2012

Cont' From Tumblr!

THIS BLOG WAS CONTINUED FROM TUMBLR

I couldn't make Tumblr format my code they way I wanted to, so I shifted over to blogger/blogspot. This will be the new blog, but if you want to see old posts, here it is:
http://iwasboredsoistartedcoding.tumblr.com/