Hi, I'm trying to make a very basic minecraft isometric 10x10x10 world on hte arduino using the TVOut library, but the problem when placing or breaking blocks is that the entire world need to be draw again, and it's really slow because I've made the block sprites in 2 dimensional arrays, and every block in the world is saved in a 3 dimensional array (the position in the array is the y, z and x position, and the number saved in the array is the block type).
I've already tried to make it faster using straight up C code, but it isn't fast enough,
The world drawing was fast, but now the code needs to read every integer on the world array, and that slowed it a lot, but i need the world array to keep track where every block is, because before i was just drawing the blocks with a premade code that cannot be changed during the code execution.
Heres the code:
#include <TVout.h>
#include <fontALL.h>
#include <avr/io.h>
#include <util/delay.h>
TVout TV;
int gb[16][16]={{2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2}, //Grass Block
{2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,2},
{2,2,2,1,1,1,1,0,0,1,1,1,1,2,2,2},
{2,1,1,1,1,0,0,0,0,0,0,1,1,1,1,2},
{1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1},
{1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1},
{1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1},
{1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1},
{1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1},
{1,0,0,0,1,0,0,1,1,1,0,0,1,0,0,1},
{1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1},
{2,1,1,0,0,0,0,1,1,0,0,0,0,1,1,2},
{2,2,2,1,1,0,0,1,1,0,0,1,1,2,2,2},
{2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,2},
{2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2}};
int nb[16][16]={{2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2}, //Testing Block
{2,2,2,2,2,1,1,0,0,1,1,2,2,2,2,2},
{2,2,2,1,1,0,0,0,0,0,0,1,1,2,2,2},
{2,1,1,0,0,0,0,0,0,0,0,0,0,1,1,2},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,2,2,2,2,2},
{2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2}};
int WD[11][11][11]={0}; //World Array
void drawCube(int t, int x, int y, int z) { //Drawing the cube pixel by pixel
for(int i=0; i<16; ++i) {
for(int j=0; j<16; ++j) {
if(t==1) { //check the block type
if(gb[j][i] == 1) { //if the block type is a valid one it starts to read every integer from the array (1 if white, 0 if black, 2 if transparent)
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,WHITE);
}
else if(gb[j][i] == 0) {
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,BLACK);
}
}
else if(t==2) {
if(db[j][i] == 1) {
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,WHITE);
}
else if(db[j][i] == 0) {
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,BLACK);
}
}
else if(t==3) {
if(sb[j][i] == 1) {
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,WHITE);
}
else if(sb[j][i] == 0) {
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,BLACK);
}
}
else if(t==4) {
if(bb[j][i] == 1) {
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,WHITE);
}
else if(bb[j][i] == 0) {
TV.set_pixel((x*8)-(z*8)+i,(x*4)+(z*4)+(y*8)+j,BLACK);
}
}
}
}
}
void generateWorld() { //Generating the world
for(int i=10; i>0; --i) {
for(int j=0; j<10; ++j) {
for(int k=0; k<10; ++k) {
if(i==9){
WD[i][j][k] = 4;
}
else if(i==8){
WD[i][j][k] = 3;
}
else if(i==7){
WD[i][j][k] = 3;
}
else if(i==6){
WD[i][j][k] = 2;
}
else if(i==5){
WD[i][j][k] = 1;
}
else if(i==5){
WD[i][j][k] = 1;
}
}
}
}
}
int main() {
TV.begin(PAL,170,96);
generateWorld();
TV.delay_frame(1);
while(1) {
for(int i=10; i>=0; --i) { //Start drawing the world from the bottom, so blocks don't overlap when drawing
for(int j=0; j<10; ++j) {
for(int k=0; k<10; ++k) {
if(WD[i-1][j][k] == 0 or WD[i][j+1][k] == 0 or WD[i][j][k+1] == 0) { //Checking if block is not covered
if(WD[i][j][k] == 1) { //If in the world array the block is 1 it's going to draw a grass block on the display
drawCube(1,k+5,i-3,j-5);
}
else if(WD[i][j][k] == 2) {
drawCube(2,k+5,i-3,j-5);
}
else if(WD[i][j][k] == 3) {
drawCube(3,k+5,i-3,j-5);
}
else if(WD[i][j][k] == 4) {
drawCube(4,k+5,i-3,j-5);
}
}
}
}
}
_delay_ms(1000); //Wait 1 second before redrawing the world (temporary)
TV.clear_screen(); //Clear the screen to eliminate excess pixels
}
return 0;
}```
(I'm italian so sorry for my english)
Thanks!

