Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 May 2010
Offline Last Active Oct 16 2016 06:17 PM

Posts I've Made

In Topic: Raycasts on a 2d map for determining vision.

02 October 2016 - 02:15 PM

Loop over each fog of war tile in the unit's range and only perform the raycast for each tile. You can skip the raycast if the tile is already visible based in a previous unit's calculation significantly speeding up checking for large groups of units. You could then also decrease the fog of war resolution to improve performance.

This is pretty much what I ended up going with. I took the outer perimeter of the units view point and for each tile (80 tiles if the radius is 10 tiles) did a raycast with 15 iterations each from the unit to that tile. That's only 1,200 calculations where I had needed 36,000. This is good enough to have it run in the main thread without killing FPS. 
If anyone's still reading this I got a second question. So I have this code here that determines which tile a specific coordinate is located in:
bool pointInTriangle(point s, point a, point b, point c)
    //Find out if a point is in a particular triangle
    //The first point is the point to check
    //The other three are the three vertices of the triangle
    int as_x = s.x-a.x;
    int as_y = s.y-a.y;
    bool s_ab = (b.x-a.x)*as_y-(b.y-a.y)*as_x > 0;
    if(((c.x-a.x)*as_y-(c.y-a.y)*as_x > 0) == s_ab) return false;
    if(((c.x-b.x)*(s.y-b.y)-(c.y-b.y)*(s.x-b.x) > 0) != s_ab) return false;
    return true;
point terrainMap::getTileFromPos(point &miso)
    point ret(-1,-1); //blank coordinate, to be returned -1,-1 if out of bounds
    int tmpx = miso.x / 200; //From a non-isometric perspective the tiles are 200 wide and 100 long
    int tmpy = miso.y / 100; //Though in an isometric perspective they're actually squares 
    if(miso.y < 0)
        return ret;
    if(miso.x < -2*miso.y) //Is it out of bounds?
        return ret;
    if(miso.x > 2*miso.y)  //Keep in mind the map itself is a diamond as well, in addition to the individual tiles
        return ret;
    if(miso.y > (signed)(50*gridsize))
        if((signed)(miso.y-(50*gridsize)) > (miso.x+(100*(signed)gridsize))/2)
            return point(-2,-2);
        if((signed)(miso.y-(50*gridsize)) > (miso.x-(100*(signed)gridsize))/-2)
            return point(-3,-3);
    if(miso.x < 0) //A diagonal line cuts the map in two, on one side the X coordinates are negative on the other they're positive
    {              //We have to calculate differently depending on which side we're on
        point center(       (tmpx*200)-100   ,(tmpy*100)+50);
        point topRight(     (tmpx*200)       ,(tmpy*100));
        point topLeft(      (tmpx*200)-200   ,(tmpy*100));
        point bottomRight(  (tmpx*200)       ,(tmpy*100)+100);
        point bottomLeft(   (tmpx*200)-200   ,(tmpy*100)+100);
        ret.x = tmpx+tmpy;
        ret.y = tmpy*2;
        point center((tmpx*200)+100,(tmpy*100)+50);
        point topRight((tmpx*200)+200,(tmpy*100));
        point topLeft((tmpx*200),(tmpy*100));
        point bottomRight((tmpx*200)+200,(tmpy*100)+100);
        point bottomLeft((tmpx*200),(tmpy*100)+100);
        ret.x = tmpx+tmpy;
        ret.y = tmpy*2;
    return ret;
Basically it uses division to determine roughly where the coordinate is to a square, then divides that square into a center tile and four triangles around it containing adjacent tiles. It then uses pointInTriangle to determine which of these triangles it is in, or if it's in the center tile by process of elimination. The problem is this takes quite a lot of calculations for something I feel should be a lot simpler. Is there an easier way to convert coordinates to tile coordinates for diamond shaped tiles?

In Topic: Need help finding which tile my cursor is in?

27 December 2015 - 06:40 PM

You can also treat it as just normal squares, and use an additional mask image. First, find the tile as normal, then use the mask image to determine if you need to offset you position.

This technique will also work with other tile shapes.


See this for more detail (described near the bottom).

This is pretty much what I ended up going with. It works beatifically, the code is understandable, and it takes just as long to run the code if I have 10x10 or 10,000x10,000 tiles. 

In Topic: SDLNet server can only accept one client at a time.

31 May 2015 - 11:07 PM

I'm not 100% sure, but I think you need to add the TCP socket to a socket set first, and then call SDLNet_CheckSockets on the set, which returns the number of ready sockets in the set, at which point you would then call SDLNet_SocketReady on the server socket, after CheckSockets indicates that something is happening on the socket. This seems redundant to me, but SDLNet introduces a few of its own ideas to the whole convention of sockets as is. Keep us updated smile.png

sd was added to serverSet before the loop and in clients[freeClient].createClient(tempSocket) tempSocket is added to its own set with only itself in it.

I might try making it all one big socket set though.

In Topic: 3d online sandbox world I'd like help testing!

28 March 2014 - 01:51 AM

Seems nice but did you just list "Shaders" as a graphical feature? How else would you render a game these days ? smile.png

Guess I meant this game uses GLSL and OpenGL 3/4 whereas my previous projects were OpenGL 1/2 with fixed function pipelines.
Most of your OpenGL tutorials and thus a disproportionate amount of indie-games using OpenGL use OpenGL 1/2 still.

Added some screenshots to the OP.

In Topic: OpenGL program doesn't start on other peoples computers.

27 March 2014 - 09:12 AM

OK, first run, default settings:

0	: Program started.
0.00	: 4 quotes read.
0.00	: Could not find prefs file, creating with defaults.
0.30	: del --- c2 out of scope --- 
OpenGL error: 1280
0.33	: OpenAL: No Error
0.33	: Networking initalized.
0.33	: Initalized.
0.33	: Using glew version: 1.7.0
0.33	: AMD Radeon HD 6450
0.33	: ATI Technologies Inc.
0.33	: 4.0.12430 Core Profile Context
0.33	: 4.30
0.33	: Opengl version used: 4.0
0.33	: del --- c2 out of scope --- 
OpenGL error: 1280
Before shaders...
Shaders allocated.
Vertex shader length: 2230
Fragment shader length: 7481
0.33	: Compiling shader: shaders/StandardShadingVertex.glsl
0.37	: Vertex Error Message Size: 0,0
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid
Second run, LOG_SHADERS 0 .................................. IT WORKS! smile.png
0.33	: Vertex Error Message Size: 0,0
0.33	: Compiling shader: shaders/StandardShadingFragment.glsl
0.34	: Linking program.
0.36	: 
8.38	: UDP opened, address resolved.
8.88	: UDP opened, address resolved.
9.38	: UDP opened, address resolved.
16.49	: Window closed!
16.49	: OpenAL: No Error
16.64	: 0 frames ran.
16.64	: 16.6419 current time.
16.64	: 16.643 seconds elapsed.
16.64	: 0 fps average.
0	: Ended program.

Wow man, thanks a ton!
Can't believe all this time it had nothing to do with OpenGL at all lol