Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 26 Aug 2012
Offline Last Active Jun 12 2016 02:55 AM

#5078965 Byproduct of Insomnia

Posted by on 19 July 2013 - 11:02 AM

One of the mistakes people make with Ambien is not immediately going to and staying in bed. If you take it and stay up, most people go into crazy mode and start doing a lot of weird things. I saw a thread once about the stuff people have done while on ambien. It's an oddball.


Well that's a good use-case for a macro and the string literal concatenation which is done by the preprocessor.


#define PREAMBLE "STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '"


Then you can do system(PREAMBLE "rest of stuff");


You don't even need an operator!


Very true, now that I'm off the med, I realize how crazy most of my coding was during those couple of months. I am under the firm belief that most new game companies fail because they push their employees too hard and don't let them sleep enough.

#5078864 Byproduct of Insomnia

Posted by on 19 July 2013 - 01:25 AM

This one needs a little explaining. A while back I was in the middle of a major life crisis and things where looking real bad for me, in a nutshell I couldn't sleep. I was put on ambien by my doctor, and found I did not go to sleep while on it. Instead I turned into a zombie of a person that walked into walls ocassionally. This is something I coded while awake on ambien.

//-----Generate Self Extracting patch installer----->
	if(generatePatch && numDiffs > 0){//-b flag
		//construct base source files
		system("mkdir /tmp/builder");
		system("echo '#include <stdio.h>' > /tmp/builder/headers.c");
		system("echo '#include <stdlib.h>' >> /tmp/builder/headers.c");
		system("echo \" \" >> /tmp/builder/headers.c");//space

		system("echo \" \" > /tmp/builder/decompile.c");//space
		system("echo 'int main(){' >> /tmp/builder/decompile.c");
		system("echo 'FILE *fp = fopen(\"TMP.tar.gz\",\"wb\");' >> /tmp/builder/decompile.c");
		system("echo 'fwrite(xxx, sizeof(xxx[0]), sizeof xxx/sizeof(xxx[0]), fp);' >> /tmp/builder/decompile.c");
		system("echo 'fclose(fp);' >> /tmp/builder/decompile.c");

		//do any additional installation work here-->
		system("ST=\\\"\necho \"system(${ST}> .install.py${ST});//create installer script\" >> /tmp/builder/decompile.c");//create script file
			//write python install script here-->
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'from Tkinter import * ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'from tkFileDialog import askdirectory ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'import os ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'def askd(): ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '	dir1 = askdirectory() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '	if dir1: ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		print ${STT}Directory ${STT} + dir1 + ${STT} Will Be Patched.${STT}' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}tar -zxf ./TMP.tar.gz -C .${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}mv -f .gamepatch.diff* ${STT} + dir1) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}rm ./TMP.tar.gz${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		os.system(${STT}cd dir1\\\\\\\ngamepatch -p 10000${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//patch system to latest patch
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		quit() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//exit tkinter
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '		exit() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//exit python
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top = Frame() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top.pack() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'Label(top, text=${STT}${STT}${STT}This patch is only designed for a specific game. ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'Do Not Use If Unsure What Game This Is For! ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '${STT}${STT}${STT}).pack(side=TOP) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'widget = Button(top, text=${STT}Choose Game Directory To Patch${STT}, command=askd) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'widget.pack(side=BOTTOM) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
			system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top.mainloop() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
		system("ST=\\\"\necho \"system(${ST}gnome-terminal -e 'python ./.install.py'${ST});\" >> /tmp/builder/decompile.c");//run script file
		system("ST=\\\"\necho \"system(${ST}rm .install.py${ST});\" >> /tmp/builder/decompile.c");//remove script file

		system("echo 'return 0;}' >> /tmp/builder/decompile.c");

		//build and merge source files
		system("tar -zcf /tmp/builder/TMP.tar.gz .gamepatch.diff*");
		system("cat /tmp/builder/TMP.tar.gz | ( echo \"unsigned char xxx[] = {\"; xxd -i; echo \"};\" ) > /tmp/builder/output_file.c");
		system("cat /tmp/builder/headers.c /tmp/builder/output_file.c /tmp/builder/decompile.c > /tmp/builder/builder.c");

		//compile source file
			system("gcc /tmp/builder/builder.c -o ./patcher");
			sprintf(buffer, "%s%s","gcc /tmp/builder/builder.c -o ",path);
		printf("\n-->Patch Installer Has Been Generated\n");

#5041285 When to start with C++?

Posted by on 09 March 2013 - 04:25 PM

I came into programming the old fashioned way. I started with Basic then moved to C and then C++. I personally would not recommend you learn C++ until you first learn the C way of doing things.

#5041062 Article Inspiration

Posted by on 08 March 2013 - 09:13 PM

Article ideas:


*Natural language processing

*Build systems

*Swig usage cases for generating wrappers

*Multi platform coding practices, how to set up environments on different target machines that act the same

*Coding exercises, with programs that test the output and gives a grade

#5040637 Code review for a Pygame project

Posted by on 07 March 2013 - 07:32 PM

Let's first define what type of functional programming you mean. To me functional programming is a style of programming that treats the program flow like an equation void of any variables. I think you view it from the perspective of lets make a function that moves a ship forward and to the left. If you have a function for every possible game action, that will eventually become very hard to maintain.


The single mother class would be your game class. Inside of which is the game loop and support functions for interacting with the entity system.

#5040281 Code review for a Pygame project

Posted by on 07 March 2013 - 01:11 AM

You should modularize and generalize things in python, a little bit more in your case can make things allot easier latter on. For example, limit the number of functions that act as specific game commands or actions. Too many will make it harder to re-use or modify latter on.


Start by building an entity system, then on top of this a pipeline for loading and managing the entities with basic string commands.

Please use classes to do the entity system, do not use functions in a flat file. That way you can abstract allot of the game away.

Later when you need a function that can build ships, move them or find certain tiles; it can all be done through a single mother class.


If you do not understand any of the concepts or words I described above, then please either ask for clarification or google it.

#5023432 Go language

Posted by on 20 January 2013 - 02:19 AM

I am experimenting with it right now for a game server.


Golang is the easiest binary compiled language for writing servers. It has support from google cloud and many google tool-kits.


Consider turning back now If you are planning to do front end stuff with Go and have zero experience with C/C++. Go has a couple wrappers for libs like SFML, SDL, OpenGL and DX. Only problem is the support for these wrappers is hit or miss, and most require extensive knowledge of C/C++, SWIG and cgo to update or fix.

#5023020 2D Isometric rendering with camera/viewport

Posted by on 18 January 2013 - 05:11 PM

Why are you starting at 0, start where the camera starts and end where the camera ends. Just draw whatever the camera shows us regardless of what that is. Then get rid of the range check you don't need that, the range check was shrinking the view on you. To ensure that the camera doesn't draw anything out of range make certain the camera position can never stray beyond the defined range, 1000X1000 in your case.


edit: In the camera's case the range is (0,0) and (1000-width,1000-height).


    public class Camera
      public void SetLoc(Point pt)
          this.X = pt.X;
          this.Y = pt.Y;
        else if(X_is_too_small)
          this.X = 0
          this.Y = pt.Y
        ... Yada Yada Yada...

#5021697 Beginning to code in C++, some rookie questions.

Posted by on 15 January 2013 - 12:05 AM

I wasn't going to laugh, nor was anyone else here.


Get rid of SDL_BlitSurface(logo,NULL,screen,NULL); SDL_BlitSurface(border,NULL,screen,NULL); SDL_Flip(screen); and SDL_Delay( 5000 );

In it's place put the following:



//use SDL_SetAlpha instead of SDL_SetSurfaceAlphaMod when using SDL 1.2 or under.
unsigned int basetick = SDL_GetTicks();
unsigned int currenttick = SDL_GetTicks();
unsigned int time = 1500;//one and half second

while(currenttick - basetick <= time)
    Uint8 alph = (((float)currenttick - (float)basetick) / (float)time) * 255;
    SDL_SetSurfaceAlphaMod(logo, alph);

    //clear the screen here SDL_FillRect works, there are other ways to
    //SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0, 0, 0));

    SDL_BlitSurface(logo, NULL, screen, NULL);
    SDL_BlitSurface(border, NULL, screen, NULL);
    SDL_Delay( 10 );
    currenttick = SDL_GetTicks();

basetick = SDL_GetTicks();
currenttick = SDL_GetTicks();
while(currenttick - basetick <= time)
    Uint8 alph = (((float)currenttick - (float)basetick) / (float)time) * 255;
    SDL_SetSurfaceAlphaMod(logo, 255-alph);

    //clear the screen here SDL_FillRect works, there are other ways to
    //SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0, 0, 0));

    SDL_BlitSurface(logo, NULL, screen, NULL);
    SDL_BlitSurface(border, NULL, screen, NULL);
    SDL_Delay( 10 );
    currenttick = SDL_GetTicks();


I typed this out quick, there might be errors, but for the most part it should work. It's been a while since I have used SDL.

#5021579 Game engine slection for a game programming course

Posted by on 14 January 2013 - 04:17 PM

I am afraid I do not know of any such papers that cover the selection process of engines in a course setting.  You might want to compile numbers on the most popular engines out there. The idea is, what engines are most popular by industry, indie and hobby standards, must be considered over less popular ones.


Try contacting Dr. Shaun Ramsey, at washcoll.edu. He did research on game engines look at http://www.washcoll.edu/live/news/698-game-engine-design.


Hope this helps.

#5020073 Lines of Coding Per Day

Posted by on 10 January 2013 - 05:39 PM

I can give my personal opinion on this matter, keep in mind this is just an opinion.


Low level languages > 2000

OO languages > 1000

Functional languages > 100


edit: Since personal opinions are not wanted here, I will simply state. Yes, a metric for any measurable thing does not mean anything concrete.

#5015515 Blits per second

Posted by on 29 December 2012 - 01:26 PM

Abstract away.  Personaly now that I think about it, as long as you don't blit more than the monitor refresh rate you don't need to worry about this. This should only be implimented to slow down a fast program, v-sync can be used in place of it if you want. In the cases of slow programs just let er rip and use delta time to calculate movements based on time, rather than frame number.

class TimeDif(){
     long range = 16;
     long lastTime = GetTime();

     bool getDif(){
          long dif = GetTime() - lastTime;

          if(dif >= range){
               lastTime = GetTime();
               return true;

          return false;


#5015376 Blits per second

Posted by on 29 December 2012 - 03:34 AM

You should cap renderer refresh rate at the monitor refresh rate, typically 60 fps.  This doesn't mean that you limit the number of game cycles to 60 hz, only the blitting.  As long as you keep it lined up at monitor refresh rate, it is okay to disable v-sync.  Otherwise v-sync might be needed on slower systems.  When the program is refreshing every say half second and there is no v-sync, this will result in tearing artifacts or partially drawn passes in cases of high fps.


Now if nothing changes, simply copy your last output and refresh. Sometimes it is best to draw to another target like a texture or surface(aka software renderer), then blit that until something changes.

#5002870 Composition Based Game Outline. Would like input

Posted by on 21 November 2012 - 03:14 AM

keeping track of limbs might be too much. Just use sprite sheets and animate that way, simple sometimes is better.

#5001505 Impotant! Books to start learning video game programming ! I need it...

Posted by on 16 November 2012 - 05:15 AM

If you are not a good programmer then you might want to get books that teach the languages themselves, not game architecture.

To other readers, please don't downvote beginner questions. It frightens them into not wanting to ask questions.