Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Switchboy

Pages: [1]
1
Network / Piece of network conde not compiling in g++ (it does in VS19!)
« on: November 02, 2021, 05:19:07 pm »
The send code

sf::Packet actorDataPacket;
        sf::Uint8 actorDataHeader = dataType::actorsBlob;
        actorDataPacket << actorDataHeader;
        size_t amountOfActors = listOfActors.size();
        actorDataPacket << amountOfActors;

        for (actors& a : listOfActors) {
            int x = a.getActorCords().x;
            int y = a.getActorCords().y;
            int team = a.getTeam();
            int type = a.getType();
            actorDataPacket << x << y << team << type;
        }
        currentConnection.getTcpSocket()->send(actorDataPacket);

 
The recieve code:
sf::Packet recievePacket;
sf::Socket::Status statusOfSocket = currentConnection.getTcpSocket()->receive(recievePacket);
if (statusOfSocket == sf::Socket::Done) {
        sf::Uint8 recievedHeader;
        recievePacket >> recievedHeader;
        switch (recievedHeader) {

                case dataType::actorsBlob:
                    size_t amountOfActors;
                    recievePacket >> amountOfActors;
                    for (int i = 0; i < amountOfActors; i++) {
                        int x;
                        int y;
                        int team;
                        int type;
                        recievePacket >> x;
                        recievePacket >> y;
                        recievePacket >> team;
                        recievePacket >> type;
                        listOfActors.push_back(actors(type, { x, y }, team, static_cast<int>(listOfActors.size())));
                    }
                    actorBlobRecieved = true;

                    break;
}

On windows using Visual Studio Community 2019 this compiles just fine

On linux using g++ with VSCode and sfml-vscode-boilerplate it does not comile:
Error: invalid conversion from 'size_t'  {aka 'long unsigned int' to 'wchart_t*' [-fpermissive]

When turning on '-fpermissive' I believe it tries to use sf::bool, sf::string, sf::Uint8 to 64 and fails.

Am I right te presume that I am trying to do something undefined by putting a size_t into a SFML packet? And it was dumb luck it worked on windows?

Which sf:: datatype corresponds to a long unsigned int? So I could use that datatype instead to make this piece of code work.

2
I planned on adding smoothed edges for my sand and water tiles for my isometric RTS game. So while doing some prototyping I concluded that for the complexity of the effect of an adjacent tile I would need 2^8 different tiles per category to cover all possible tile arrangement.

Since I only have limited time there was no way I would sit down and create all these assets myself. So I set out to write a little program that could do it for me. And the idea for groundTilemapGenerator was formed.

It will generate a 16*16 tilemap of a category of ground/water. By switching a specific border on and off. Each tile wil have a 8-bit number (0-256) and if I use the same code to generate the same 8bit bitmask ingame it will allow me to show the pixels of the exact same tile number.

Sample of output:


This will save me a lot of work!

https://github.com/switchboy/groundTilemapGenerator

Currently it is hardcoded to work with 64*128 pixel assets

3
Graphics / VertexArray Quads not rendering in the right color or place
« on: August 23, 2021, 11:45:12 am »
I am currently working on a RTS game with a minimap. Since drawing this minimap is eating around 20% of my CPU time. I thought of reducing the amount of draw calls. So instead of using a rectangleShape for every map tile I might try using a vertex array of quads instead. And only draw the vertex array going from 62500 (for a 250*250 tiles map) draw calls per miniMap layer update to one!

So I came up with the following code:

        static const sf::Color colors[] =
        {
            {0, 0, 0},
            {152, 205, 115},
            {200, 160, 80},
            {200, 160, 80},
            {200, 160, 80},
            {200, 160, 80},
            {200, 160, 80},
            {69, 164, 208},
            {69, 164, 208},
            {69, 164, 208},
            {69, 164, 208},
            {69, 164, 208}
        };


sf::VertexArray miniMapPoints(sf::Quads, MAP_HEIGHT*MAP_WIDTH);
            minimapTexture.clear(sf::Color(0, 0, 0, 0));
            for (int j = 0; j < MAP_HEIGHT; j++)
            {
                for (int i = 0; i < MAP_WIDTH; i++)
                {
                    sf::Vertex* currentMiniMapQuad = &miniMapPoints[(i * MAP_HEIGHT) + j];

                    currentMiniMapQuad[0].color = colors[currentGame.currentMap[i][j]];
                    currentMiniMapQuad[1].color = colors[currentGame.currentMap[i][j]];
                    currentMiniMapQuad[2].color = colors[currentGame.currentMap[i][j]];
                    currentMiniMapQuad[3].color = colors[currentGame.currentMap[i][j]];

                    //cords miniMapSpace(cords location)
                    //{
                    //    int wX = mapOffsetX * 20 + (location.x - location.y) * (20 / 2);
                    //    int wY = mapOffsetY * 10 + (location.x + location.y) * (10 / 2);
                    //    return { wX, wY };
                    //}
                   
                    //Each quad should be 20px wide and 10px high. We define them clockwise from the top left (x + 0 and y + 0)
                    currentMiniMapQuad[0].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x), static_cast<float>(miniMapSpace({ i, j }).y)); //0,0
                    currentMiniMapQuad[1].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x) + 20.f, static_cast<float>(miniMapSpace({ i, j }).y)); //1,0
                    currentMiniMapQuad[2].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x) + 20.f, static_cast<float>(miniMapSpace({ i, j }).y) + 10.f); //1,1
                    currentMiniMapQuad[3].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x), static_cast<float>(miniMapSpace({ i, j }).y)+10.f); //0,1
                   
                   
                    //miniMapPixel.setFillColor(colors[currentGame.currentMap[i][j]]);
                    //miniMapPixel.setPosition(static_cast<float>(miniMapSpace({ i, j }).x), static_cast<float>(miniMapSpace({ i, j }).y));
                    //minimapTexture.draw(miniMapPixel);
                }

            }
            minimapTexture.draw(miniMapPoints);
            minimapTexture.display();

I left the old working code for drawing the miniMapPixels in there for reference. And also added the commented out function miniMapSpace() to make clear what is happening.

I attached the result of the miniMap draw and the expected result.

                        currentMiniMapQuad[0].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x), static_cast<float>(miniMapSpace({ i, j }).y) + 10.f); //0,1
                        currentMiniMapQuad[1].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x), static_cast<float>(miniMapSpace({ i, j }).y)); //0,0
                        currentMiniMapQuad[2].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x) + 20.f, static_cast<float>(miniMapSpace({ i, j }).y)); //1,0
                        currentMiniMapQuad[3].position = sf::Vector2f(static_cast<float>(miniMapSpace({ i, j }).x) + 20.f, static_cast<float>(miniMapSpace({ i, j }).y) + 10.f); //1,1

I tried different orders of the currentQuad corner coordinates. Like starting on the bottom left. While this somewhat fixed the colors the map drawn is not correct. Eg water tiles are drawn where grass tiles need to go. And there is distortion the lower Y goes and the higher X goes. So last attachment.

I think the error lies in the order of assigning the four corners of the quad. But I cant figure out the right order.

And doing this:
currentMiniMapQuad->color = colors[currentGame.currentMap[i][j]];
 
Also does not get the correct result.


4
SFML projects / Isometric RTS
« on: June 02, 2020, 04:29:30 pm »
About my project
For the last couple of months, I’ve been working in my spare time to create an isometrically projected RTS a la Age of Empires. Development has been on and off depending on how busy real life is. Bear is mind this is my second big project in C++. I've made an RPG roguelike before (which was quite far in development) but that codebase became such a mess that in the end I had to abandon it. So rather then start from scratch I decided to create another game in another (in my opinion underdeveloped by indie developers) genre.
 


The project goals that have been reached:
- Create a custom game engine based upon an isomorphic projection.
- Have actors move around in this world by issuing mouse commands.
- For pathfinding use A-star and or bidirectional A-star.
- Add collectable resources to the world
- Make villagers gather the different resources and bring them to a ‘town center’
- Use these resources to build different buildings
- Require specific buildings to house new population
- Make certain the buildings produce units
- Implement Fog of war
- Interact like an RTS game
- Robust villager AI for doing a task
- Show different animations for these resources
- Generate random map on game startup
- Make the units able fight each other using melee
- Make the actors fight each other using ranged attacks
- Make certain buildings able to perform a ranged attack
- Working minimap

Attainable project goals for the near future:
- Fighting animations
- Different units
- More buildings then houses and town centers
- Different colors on units and buildings for the eight teams
- Implant a basic Rock/Paper/Scissors for damage calculations during battle
- Researchable upgrades for units and buildings
- Flesh out the research with a tech tree
- Basic AI to play against
- Add sounds

Aim for the moon project goal:
- Working netcode to play against friends!

Cool! So where is the code?
https://github.com/switchboy/IsoRTS

Allright, I want to see it in action!
To show off some of the current gameplay I’ve attached a devlog video. For those of you who do not speak dutch it is better to watch it without sound :P



What do you think?

5
General / Solved: Trowing projectiles on 2d isometric map
« on: May 26, 2020, 09:39:44 pm »
I am creating an isometric RTS with SFML I have most of the unit AI and basic melee combat in place.

For a little demo see my devlog:


Now comes the hard part. It would be fun to add ranged units. In order to acomadate for this I've created a projectile class and started to work to try and render a paraboloic 3d trajectory in my 2d isometric space.

My projectiles move along x,y,z axis and I then translate their coördinates to my isometric projection:

Code: [Select]
screenX = x*2 //since a tile is 64 pixels wide and 32 tall
screenY = y+z //since any upward movement is only visable in the Y axis

around this concept I made the following class:

Code: [Select]
struct mouseWorldCord
{
    int x;
    int y;
};

class projectile
{
public:
projectile(int projectileStartX, int projectileStartY, int projectileTargetX, int projectileTargetY, int projectileType, int damageOnImpact, int splashDamageOnImpact);
void updatePosition();
void drawProjectile();
void doDamage();
void doSplashDamage();

private:
mouseWorldCord projectilePosition;
mouseWorldCord projectileTarget;
float timeFired;
int projectileType;
int damageOnImpact;
int splashDamageOnImpact;
float X;
float Y;
float Z;
float deltaX;
float deltaY;
float deltaZ;
bool reachedTarget;
};


std::vector<projectile> listOfProjectiles;

projectile::projectile(int projectileStartX, int projectileStartY, int projectileTargetX, int projectileTargetY, int projectileType, int damageOnImpact, int splashDamageOnImpact)
{
this->X = worldSpace(projectileStartX, projectileStartY, true)/2;
this->Y = worldSpace(projectileStartX, projectileStartY, false);
this->Z = 0;
this->projectileType = projectileType;
this->damageOnImpact = damageOnImpact;
this->projectileTarget = { projectileTargetX, projectileTargetY };
this->projectilePosition = {projectileStartX, projectileStartY};
this->splashDamageOnImpact = splashDamageOnImpact;
float travelTimeInSeconds = distEuclidean(projectileStartX * 32.f, projectileStartY * 32.f, projectileTargetX * 32.f, projectileTargetY * 32.f) / 32.f; //32 pixel/s
this->deltaX = ((projectileStartX * 32.f) - (projectileTargetX * 32.f)) / travelTimeInSeconds;
this->deltaY = ((projectileStartY * 32.f) - (projectileTargetY * 32.f)) / travelTimeInSeconds;
this->deltaZ = travelTimeInSeconds / 2;
this->timeFired = currentGame.getTime();
this->reachedTarget = false;
}

void projectile::updatePosition()
{
if (!reachedTarget) {
//speed is in pixels per second
if (this->timeFired + 0.016 < currentGame.getTime()) {
this->timeFired = currentGame.getTime();
this->X += this->deltaX/60.f;
this->Y += this->deltaY/60.f;
this->Z += this->deltaZ/60.f;
this->deltaZ -= 0.016f;
if (this->Z <= 0.0f) {
doDamage();
reachedTarget = true;
}
}
}
}

void projectile::drawProjectile()
{
int xScreenCord = this->X * int(2);
int yScreenCord = this->Y + this->Z;
currentGame.spriteArrow.setPosition(xScreenCord, yScreenCord);
window.draw(currentGame.spriteArrow);
}

void projectile::doDamage()
{
if (currentGame.occupiedByActorList[this->projectileTarget.x][this->projectileTarget.y] != -1) {
listOfActors[currentGame.occupiedByActorList[this->projectileTarget.x][this->projectileTarget.y]].takeDamage(this->damageOnImpact);
}
else if (currentGame.occupiedByBuildingList[this->projectileTarget.x][this->projectileTarget.y] != -1)
{
listOfBuildings[currentGame.occupiedByBuildingList[this->projectileTarget.x][this->projectileTarget.y]].takeDamage(this->damageOnImpact);
}
}


What I want to achieve is have a fixed horizontal velocity. I broke this down in an x-vector and y-vector. I vary the z velocity. My aim is to have the velocity decrease over time and be at 0 in the middle of the path and then have a negative velocity the second half which increases each frame. Just like gravity is pulling on the projectile. In this way I get a nice parabolic trajectory for my arrow without complicated math. Or so I thought.

I must have made a mistake somewhere because my arrow is not moving as intended. It just follows a straight line of the screen. There is probably something amiss in my initial deltaZ velocity.

Maybe a fresh set of eyes looking at the code will help.

Pages: [1]
anything