• Create Account

# ManTis

Member Since 27 Aug 2004
Offline Last Active Apr 01 2015 07:11 AM

### Work in games industry thread (with a twist)

30 September 2008 - 01:42 AM

How many of you out there got OUT of the games industry? We all got here lured by the promise of working on something we love and care about. After some time you see that it's not all awesome games making, it may be putting up with incredible deadlines set by marketing people that make you work in crunch mode for couple months, it may be making a game that you think will suck but you work on because you get payed to do that, it may be way smaller pay compared to the other IT industry parts, just because we are maniacs and want to work on games. Sometimes I look back at the times when I was only making small games for myself and realise how different it was. And get urge to go to some boring software company that churns out version 15.3.4 of their text editor, so that returning to home and working on the games will bring joy to me once more. Or leaving all the 'serious' games behind me and working on something casual, some puzzle games portal or thing like that. You ever was thinking about that? Did that? Have any opinions on making games as a job AND hobby and how does that affect your attitude towards the work? Please share.

### Tiles/Raycasting

30 October 2006 - 06:53 PM

Hi!

I was trying to do a raycasting algorithm based on paper by John Amanatides (http://www.cse.yorku.ca/~amana/research/grid.pdf), but something went wrong and I get very strange results, such as ray going through totally different tiles than it should go, or just plain crashes. The code is in SDL, but as I use it only to handle input and draw squares, I thought this forum is better for the question

Here goes the source:

```#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#include <SDL.h>
#include <iostream>

struct vec2D
{
float x, y;

vec2D():x(0),y(0){}
vec2D(float inx, float iny):x(inx),y(iny){}

vec2D operator*(const float t) const	{return vec2D(x*t, y*t);}
};

int main ( int argc, char** argv )
{
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}

// make sure SDL cleans up before exit
atexit(SDL_Quit);

// create a new window
SDL_Surface* screen = SDL_SetVideoMode(800, 600, 16,
SDL_SWSURFACE|SDL_DOUBLEBUF);
if ( !screen )
{
printf("Unable to set 800x600 video: %s\n", SDL_GetError());
return 1;
}

bool grid[10][10] = {0};
vec2D point;
point.x=320;
point.y=100;
vec2D at;

at.x= 520;
at.y = 400;

vec2D v;
v.x = at.x-point.x;
v.y = at.y-point.y;

int stepX, stepY;

if (v.x > 0)
stepX=1;
else if (v.x < 0)
stepX=-1;
else
stepX=0;

if (v.y > 0)
stepY=1;
else if (v.y < 0)
stepY=-1;
else
stepY = 0;

int SIZE = 60;
int column, row;

column = at.x/SIZE;
row = at.y/SIZE;
grid[row][column] = true;

column=point.x/SIZE;
row = point.y/SIZE;
grid[row][column] = true;

bool finished = false;
float tMaxX, tMaxY;

float deltaX, deltaY;

bool done = false;

while (!done)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
done = true;
break;

// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
break;
}
case SDL_MOUSEBUTTONUP:
{
if ((event.button.x >=0) && (event.button.x <= 600) && (event.button.y >=0) && (event.button.y <= 600))
{

for (int i=0;i<10;i++)
for (int j=0;j<10;j++)
grid[i][j]=false;

column = at.x/SIZE;
row = at.y/SIZE;
grid[row][column] = true;

finished = false;

point.x=event.button.x;
point.y=event.button.y;
std::cout << "Points chosen: \n";
std::cout << point.x <<std::endl;
std::cout << point.y <<std::endl;

v.x = at.x-point.x;
v.y = at.y-point.y;
std::cout << "Ray vector chosen: \n";
std::cout << v.x <<std::endl;
std::cout << v.y <<std::endl;
column = point.x/SIZE;
row = point.y/SIZE;

grid[row][column] = true;

std::cout << "Column, row:" << column << "," << row<<std::endl;
if (v.x > 0)
stepX=1;
else if (v.x < 0)
stepX=-1;
else
stepX=0;

if (v.y > 0)
stepY=1;
else if (v.y < 0)
stepY=-1;
else
stepY = 0;
}
}
} // end switch
} // end of message processing

while (!finished)
{

if (v.x > 0)
tMaxX=column*SIZE+SIZE;
else if (v.x < 0)
tMaxX=column*SIZE;
else
tMaxX = -1;

if (v.y > 0)
tMaxY=row*SIZE+SIZE;
else if (v.y < 0)
tMaxY=row*SIZE;
else
tMaxY = -1;

deltaX = tMaxX-point.x;
deltaY = tMaxY-point.y;

if (abs(deltaX) < abs(deltaY))
{
column+=stepX;
point.x+=deltaX;
point.y+=(v.y*deltaX)/v.x;
}
else
{
row+=stepY;
point.y+=deltaY;
point.x+=(v.x*deltaY)/v.y;
std::cout << column << "," << row << std::endl;

}

if (grid[row][column] == true)
finished = true;

grid[row][column] = true;

}

// DRAWING STARTS HERE

// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
SDL_Rect box;

for (int y = 0; y <= SIZE *10; y+=SIZE )
for (int x = 0; x <=SIZE *10; x +=SIZE )
{
box.x=x;
box.y=y;
box.w=SIZE;
box.h=SIZE;
SDL_FillRect(screen, &box, SDL_MapRGB(screen->format, 255, 255, 255));

box.x+=1;
box.y+=1;
box.w-=2;
box.h-=2;
if (grid[y/60][x/60] == 0)
SDL_FillRect(screen, &box, SDL_MapRGB(screen->format, 0, 0, 0));
else
SDL_FillRect(screen, &box, SDL_MapRGB(screen->format, 255, 0, 0));
}

// DRAWING ENDS HERE

// finally, update the screen :)
SDL_Flip(screen);
} // end main loop

// all is well ;)
printf("Exited cleanly\n");
return 0;
}

```

I'd be really grateful for helping me out with this one.

### stl stack fun

17 September 2006 - 02:44 PM

I'm creating an application that runs as a stack: exit->menu->game. every part of a stack is a separate function. since STL stack cannot use function pointers, i wrap it like that:
```struct StateStruct
{
typedef void (*StatePointer)();
};

```
It run fine when the Exit(), Menu() and Game() functions were global, but I decided to try to change it to oop (and here came the uglies) I have class App, containing basically whole my program,
```int main(int argc, char *argv[])
{
App *MyDemo = new App;
MyDemo->MainLoop();
delete MyDemo;
return 0;
}

void App::MainLoop()
{
while (!stateStack.empty())
{
stateStack.top().StatePointer();
}
}

```
I've created a method Exit() of the App
```void App::Exit()
{
cout << "I am exiting game." << endl;
stateStack.pop();
}

```
and now in App::Init(), I try to use
```StateStruct state;
state.StatePointer = Exit; // <-- DevCPP throws out error here
// state.StatePointer =&App::Exit; gives same error as the line above
stateStack.push(state);

```
the error is "invalid use of `StateStruct::StatePointer'" oh yeah,
```stack<StateStruct> stateStack; // application's state stack

```
is a private member variable of class App. I _really_ have no idea what to do now. Any help will be appreciated.

### OpenGL/SDL pbuffers

27 August 2006 - 10:47 PM

Didn't know which board to put it in, sorry if this was supposed to be in the other one ;). Is there possibility to use OpenGL pbuffer without wiggle, but in SDL? Regards, M.

### I was wondering

01 August 2006 - 05:55 AM

Who in your opinion is more accomplished game programmer? One who wrote millions lines of code and knows everything there is to opengl, creating of real time volumetric clouds and anything that put together makes actual game, but never took time to put it together, or one who after learning simple graphics library created pong?

PARTNERS