• Content count

  • Joined

  • Last visited

Community Reputation

212 Neutral

About Syerjchep

  • Rank

Personal Information

  1. I've made an evolution simulator using Box2d.

    New video:
  2. Not a wholly new concept, of course, but some of the ways I'm handling the back end aren't common. I first made a non-physics based evolution simulator back in October of 2016: It was pretty decent in some ways, but quite underwhelming. Two days ago I started a new evolution simulator using opengl graphics and the box2d physics library: Over the weekend I actually got it to work: Now that evolution works, I have to add another feature or two (fighting, gene combination), then I'll post videos of evolutionary progress. Once I add a spiffy interface I'll probably release it as well. For an additional resource, here's a google doc with a sloppy code specification: I'm going to tidy that up, and maybe even make a video on how the code itself works.
  3. So I've recently gotten Box2d to work with C++ and am having fun with it, but I wanted to add heat and pressure to my game. Here's a decent example of the kind of pressure system I'm thinking of: That said, is there any page that summarizes the math required for this? I've searched "air pressure simulation" and "wind simulation" and haven't really come up with much in the way of guides and tutorials.
  4. You sure do like using emoticons in your reply. Anyway, if you or your teammates have previous work, post links to it here.
  5. Here's a little preview video I made for a different forum: I've only really been working on this a few days but basically the program simulations a map with many different cells on them. Each cell has its own script that tells it what to do each frame. The 'scripting language' is specific for this program and is stored as a string of bytes that are susceptible to mutation. Most of the preferences and such are still hard coded and I only started making an actual interface for the program yesterday. Once I can work on it a bit more I might release a really early version for people to try.
  6. So I'm making a 2d game where there's a part of the interface that's supposed to display a tilemap. And I'm writing a map displayer that can be resized by the user. It's pretty obvious that if you have a map display that's twice as large as the map, you simply give each tile two pixels. And if you have a display that's half the size map you take every two pixels and average their color together. But what happens if your display is one third the size of the map, or 1.5 times the size of the map? Can someone provide me with a starting point to learn about this?
  7. Raycasts on a 2d map for determining vision.

    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;           if(pointInTriangle(miso,center,topRight,topLeft))         {             ret.y--;             ret.x--;         }         if(pointInTriangle(miso,center,bottomRight,bottomLeft))             ret.y++;         if(pointInTriangle(miso,center,topLeft,bottomLeft))             ret.x--;     }     else     {         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;           if(pointInTriangle(miso,center,topRight,topLeft))             ret.y--;         if(pointInTriangle(miso,center,bottomRight,bottomLeft))         {             ret.y++;             ret.x++;         }         if(pointInTriangle(miso,center,topRight,bottomRight))             ret.x++;     }       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?
  8. So I'm making an RTS on a 2d isometric map. There is a 'fog of war' where units have line of sight and can reveal tiles around them. Making them simply reveal tiles in a box around their location is pretty easy, but I wanted a more realistic circular vision that can be obstructed by objects in the way.   I've already coded this, and the basic code is here:       resetFog();       for(unsigned int i = 0; i<calcUnits->size(); i++)     {         unsigned int tx = calcUnits->at(i).tileX;         unsigned int ty = calcUnits->at(i).tileY;           tmpExplored[tx+(ty*size)] = true;         for(double vi = 0; vi<360; vi++)         {             double xDir = sin(vi);             double yDir = cos(vi);             for(unsigned int m = 0; m<calcUnits->at(i).type->sightDistance; m++)             {                 double xPos = (xDir*m*15)+calcUnits->at(i).x;                 double yPos = (yDir*m*15)+calcUnits->at(i).y;                 point in(xPos,yPos);                 point aq(calcMap->getTileFromPos(in).toArray());                 if(aq.x > 0 && aq.x < size && aq.y > 0 && aq.y < size)                 {                     tmpExplored[(int)aq.x+(size*(int)aq.y)] = true;                     if(calcMap->treeGrid[(int)aq.x+((int)aq.y*size)])                         break;                 }                 else                     break;             }         }     }       updateHalfExplored(); resetFog() resets the buffer and updateHalfExplored() basically flips the buffer to the main array. As you can see for each unit 360 raycasts are made and each one is checked up to 100 times along the way stopping if an obstacle is found. This means there's up to 36,000 checks per unit which is a ton of processing, and is also far more checks than there are tiles in any units line of sight.   Is there anyway I can do this more efficiently?   The end result can be seen here:
  9. So I've got a primary renderer attached to a window, it works fine. However, I have a texture I want to render to before I use the primary renderer to render the texture to the screen. I understand you can change the target of a renderer, and I've done this successfully. The problem is that I want to have the rendering to my texture be in its own thread, and using the same renderer with two threads simultaneously tends to create issues.    How can I render things to a texture in a separate thread from the main thread safely? 
  10. Need help finding which tile my cursor is in?

    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. 
  11. Now I realize that sounds pretty easy, but I'm using a pseudo-isometric perspective with diamond shaped tiles. That means I can't just divide the x coord by the tile width and the y coord by the tile height to get the tile like I could with square tiles lined up straight.   Instead, my tiles are like this:   Now I have gotten this to work. The thing is, my solution used a formula to find out if the point was in a particular triangle or not. So I just divided each square/diamond into two triangles and used a loop to check though each of the triangles individually until I got one that the point was inside.    The problem with this is that using a loop means it gets slower the more tiles I have. I'm posting this because I just *know* at the back of my mind there has to be a simple equation to use for this, rather than a loop. I simply can't figure out what it might be.   So, can anyone help me write an equation to figure out what diamond shaped tile my cursor is in?
  12. I made this little webgame here: That's based off the popular webgame: The server is c++ with the sdlnet networking library. The client is an HTML5 canvas for graphics, javascript and websockets as the networking. I'm currently working on adding new features to make it into a unique game.
  13. I'm not kidding, between two points in the program where literally nothing happens, it crashes. I've got this snippet of code: if(totalLen > 0) { clients[i].lastActivity = SDL_GetTicks(); if(clients[i].websocket) { if(!clients[i].receivedFood) { for(int q = 0; q<maxFood; q++) { if(foodSent[q]) { if(!clients[i].send("fd " + istr(foodPositionsX[q]) + "," + istr(foodPositionsY[q]))) log("Couldn't send food!"); } } for(int zz = 0; zz<10; zz++) if(!clients[i].send("ch " + chatList[zz])) log("Couldn't send chat!"); clients[i].receivedFood = true; } //log("Len: " + istr(totalLen) + " ||" + string((char*)bigBuf) + "||"); if(totalLen > 5) { bool ba = getBit(bigBuf[0],0); bool bb = getBit(bigBuf[0],7); bool bc = getBit(bigBuf[1],7); if(ba && bb && bc) { unsigned int plength = 0; if(getBit(buffer[1],0)) plength += 1; if(getBit(buffer[1],1)) plength += 2; if(getBit(buffer[1],2)) plength += 4; if(getBit(buffer[1],3)) plength += 8; if(getBit(buffer[1],4)) plength += 16; if(getBit(buffer[1],5)) plength += 32; if(getBit(buffer[1],6)) plength += 64; if(plength < 126) { char mask[4]; mask[0] = bigBuf[2]; mask[1] = bigBuf[3]; mask[2] = bigBuf[4]; mask[3] = bigBuf[5]; char decodedMessage[plength]; for(int v = 6; v<totalLen; v++) decodedMessage[v-6] = bigBuf[v] ^ mask[(v-6)%4]; string message = string(decodedMessage).substr(0,plength); onReceive(message,i); //Code executes here fine almost always } else log("Frame too long."); } else log("Invalid websocket frame!"); } else log("Frame length too short."); } else { string message = string((char*)bigBuf); string key = getKeyFromHeader(message); if(key.length() > 0) { //log("Got page request, also websocket."); string returnKey = processKey(key); string packet = ""; packet += "HTTP/1.1 101 Switching Protocols\r\n"; packet += "Upgrade: websocket\r\n"; packet += "Connection: Upgrade\r\n"; packet += "Sec-WebSocket-Accept: " + returnKey +"\r\n"; packet += "\r\n"; SDLNet_TCP_Send(clients[i].socket,packet.c_str(),packet.length()); clients[i].websocket = true; } else { log("Got page request, no websocket request, client: " + istr(i)); if(!clients[i].used || clients[i].websocket) log("Got request from non-existent client."); else { string message = string((char*)bigBuf).substr(0,totalLen); if(message.substr(0,14) == "GET / HTTP/1.1") { string body = ""; string line; ifstream myfile("index.html"); if(myfile.is_open()) { while (getline(myfile,line)) body += line + "\n"; } else log("Could not find index html file!"); string responce = ""; responce += "HTTP/1.1 200 OK\r\n"; responce += "Content-Length: " + istr(body.length()) + "\r\n"; responce += "Connection: close\r\n"; responce += "Content-Type: text/html; charset=UTF-8\r\n"; responce += "\r\n"; responce += body; responce += "\r\n"; SDLNet_TCP_Send(clients[i].socket,responce.c_str(),responce.length()); } else log("Not index request."); } } //cout<<"|"<<message.substr(0,totalLen)<<"|\n"; } } //Place before which it may crash And between the "//Code executes here fine almost always" and "//Place before which it may crash" the program seems to crash. Now it's not always, but this is code that runs many times over and over again. When it *does* crash if I put a call to log at the first comment it will print that text, and a log at the second it will not before crashing. So if you guys could help me figure out how it's possible that in a case like this: if(var) { function(); log("test"); } log("ran okay"); I can somehow run it and get "test" in my console but not "ran okay" because it crashed inbetween the two log statements, please let me know.
  14. 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.
  15. So I'm rewriting a server with SDL_net and I'm working on the main loop. If I just do if((tempSocket = SDLNet_TCP_Accept(sd)) > 0)then I can accept sockets. But if I try to actually check the socket set as I have it below it will let me accept one client. Then once I have a client connected it won't say the socket set has activity when a client tries to connect until the first one disconnects.  while(cont)     {         int numReady = SDLNet_CheckSockets(serverSet,0);         if(numReady < 0)             log("Error checking server socket set.");         else if(numReady > 0)         {             if(SDLNet_SocketReady(sd))             {                 tempSocket = SDLNet_TCP_Accept(sd);                 if(tempSocket)                 {                     log("Connection accepted.");                     int freeClient = findFreeClient();                     if(freeClient != -1)                     {                         if(clients[freeClient].createClient(tempSocket))                         {                             log("Accepted client with ID " + istr(freeClient));                         }                         else                             log("Could not create new client.");                         tempSocket = NULL;                     }                     else                         log("Had to reject client. Too many connections.");                 }                 else                     log("Error accepting socket.");             }             else                 log("Checked socket not ready.");         }           SDL_Delay(10);     } Should I just check for accept sockets like above even though it throws an error with SDLNet_GetError() or is there a way around this. If it's relevant the sockets connecting are from the same IP. (localhost)