kein branch lol aber ULTRA PERFORMANCE

main
JanEhehalt 3 years ago
parent 5a7fa96cf4
commit 861b30aa4f

@ -16,8 +16,8 @@ IsometricMap * IsometricMapInit(int layer){
//map->tileTextures[0] = LoadTexture("assets/desert.png"); //map->tileTextures[0] = LoadTexture("assets/desert.png");
//map->tileTextures[1] = LoadTexture("assets/bigtower.png"); //map->tileTextures[1] = LoadTexture("assets/bigtower.png");
map->width = 200; map->width = 500;
map->height = 200; map->height = 500;
map->textureWidth = map->tileTextures[0].width; map->textureWidth = map->tileTextures[0].width;
map->textureHeight = map->tileTextures[0].height; map->textureHeight = map->tileTextures[0].height;
map->worldPixelWidth = map->width * map->textureWidth; map->worldPixelWidth = map->width * map->textureWidth;
@ -34,6 +34,8 @@ IsometricMap * IsometricMapInit(int layer){
int i = 0; int i = 0;
int j = 0; int j = 0;
int quarterTextureSize = map->textureWidth / 4;
int halfTextureSize = map->textureWidth / 2;
for(i=0; i < map->width; i++){ for(i=0; i < map->width; i++){
for(j=0; j < map->height; j++){ for(j=0; j < map->height; j++){
Tile *tmp = (Tile *) malloc(sizeof(Tile)); Tile *tmp = (Tile *) malloc(sizeof(Tile));
@ -42,6 +44,14 @@ IsometricMap * IsometricMapInit(int layer){
tmp->x = i; tmp->x = i;
tmp->y = j; tmp->y = j;
tmp->z = layer; tmp->z = layer;
Vector2 *offset = IsometricMapCalcOffsetForTileAtEfficient(i,j, halfTextureSize, quarterTextureSize);
// the higher the layer the higher it needs to be drawed
offset->y -= layer * quarterTextureSize;
tmp->offsetX = offset->x;
tmp->offsetY = offset->y;
free(offset);
tiles[i][j] = tmp; tiles[i][j] = tmp;
} }
} }

@ -7,10 +7,10 @@
#include "../game.h" #include "../game.h"
// @param deprecated // @param deprecated
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){ void IsometricRendererDrawMap(IsometricRenderer *renderer, int height)
{
printf("WARNING: Using deprecated Function IsometricRendererDrawMap!\n"); printf("WARNING: Using deprecated Function IsometricRendererDrawMap!\n");
float originX = 0.0f; float originX = 0.0f;
float originY = 0.0f; float originY = 0.0f;
@ -19,28 +19,33 @@ void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){
int j = 0; int j = 0;
int amount = 1; int amount = 1;
for(i=0; i<=height; i++){ for (i = 0; i <= height; i++)
for(j=0; j<amount; j++){ {
float x = originX - amount/2 * renderer->texture->width + j * renderer->texture->width; for (j = 0; j < amount; j++)
if(amount%2 == 1){ {
x -= renderer->texture->width/2; float x = originX - amount / 2 * renderer->texture->width + j * renderer->texture->width;
if (amount % 2 == 1)
{
x -= renderer->texture->width / 2;
} }
float y = i * renderer->texture->height/4; float y = i * renderer->texture->height / 4;
DrawTexture(*renderer->texture, x, y, WHITE); DrawTexture(*renderer->texture, x, y, WHITE);
} }
if(i < height/2){ if (i < height / 2)
{
amount++; amount++;
} }
else{ else
{
amount--; amount--;
} }
} }
} }
// parameter could be changed to only IsometricMap[] // parameter could be changed to only IsometricMap[]
void IsometricRendererRenderIsometricMap(Game *game){ void IsometricRendererRenderIsometricMap(Game *game)
{
/*
int n = 0; int n = 0;
int i = 0; int i = 0;
int j = 0; int j = 0;
@ -51,17 +56,74 @@ void IsometricRendererRenderIsometricMap(Game *game){
if(game->layers[n]->tiles[i][j]->textureId == -1){ if(game->layers[n]->tiles[i][j]->textureId == -1){
} }
else{ else{
int quarterTextureSize = game->layers[n]->textureWidth / 4; DrawTexture(
int halfTextureSize = game->layers[n]->textureWidth / 2; game->layers[n]->tileTextures[game->layers[n]->tiles[i][j]->textureId],
// SHOULD BE SET ONCE INITIALLY game->layers[n]->tiles[i][j]->offsetX,
Vector2 *offset = IsometricMapCalcOffsetForTileAtEfficient(i,j, halfTextureSize, quarterTextureSize); game->layers[n]->tiles[i][j]->offsetY,
// the higher the layer the higher it needs to be drawed WHITE);
offset->y -= n * quarterTextureSize; }
}
int textureId = game->layers[n]->tiles[i][j]->textureId; }
}
DrawTexture(game->layers[n]->tileTextures[textureId], offset->x, offset->y, WHITE); */
free(offset);
int windowWidth = GetScreenWidth();
int windowHeight = GetScreenHeight();
// HARDCODED
Vector2 topleft = {0, 0};
IsometricMapProject(game->layers[0], game->camera, topleft.x, topleft.y, &topleft);
Vector2 topright = {windowWidth, 0};
IsometricMapProject(game->layers[0], game->camera, topright.x, topright.y, &topright);
Vector2 botleft = {0, windowHeight};
IsometricMapProject(game->layers[0], game->camera, botleft.x, botleft.y, &botleft);
Vector2 botright = {windowWidth, windowHeight};
IsometricMapProject(game->layers[0], game->camera, botright.x, botright.y, &botright);
printf("%f\n", topright.y);
// drawing some extra corner tiles
// if extraTiles == 0 you can see flickering in the corners
int extraTiles = 1;
int n = 0;
int itmp = (int)(topleft.x / game->layers[0]->textureWidth) - extraTiles;
int jtmp = (int)(topright.y / game->layers[0]->textureHeight) - extraTiles;
int maxI = (int)(botright.x / game->layers[0]->textureWidth) + extraTiles;
int maxJ = (int)(botleft.y / game->layers[0]->textureHeight) + extraTiles;
if (itmp < 0)
{
itmp = 0;
}
if (jtmp < 0)
{
jtmp = 0;
}
if (maxI > game->layers[0]->width)
{
maxI = game->layers[0]->width;
}
if (maxJ > game->layers[0]->height)
{
maxJ = game->layers[0]->height;
}
int i = 0;
int j = 0;
for (n = 0; n < 10; n++)
{
for (i = itmp; i < maxI; i++)
{
for (j = jtmp; j < maxJ; j++)
{
if (game->layers[n]->tiles[i][j]->textureId == -1)
{
}
else
{
DrawTexture(
game->layers[n]->tileTextures[game->layers[n]->tiles[i][j]->textureId],
game->layers[n]->tiles[i][j]->offsetX,
game->layers[n]->tiles[i][j]->offsetY,
WHITE);
} }
} }
} }

@ -8,6 +8,8 @@ typedef struct Tile{
int x; int x;
int y; int y;
int z; int z;
int offsetX;
int offsetY;
} Tile; } Tile;
#endif #endif

Binary file not shown.

Binary file not shown.

BIN
game.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
list.o

Binary file not shown.

BIN
main.o

Binary file not shown.

BIN
spiel

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tile.o

Binary file not shown.
Loading…
Cancel
Save