示例#1
0
文件: main.c 项目: kbrafford/ModernGL
void make_world(Map *map, int p, int q) {
    int pad = 1;
    for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) {
        for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) {
            int x = p * CHUNK_SIZE + dx;
            int z = q * CHUNK_SIZE + dz;
            float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
            float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2);
            int mh = g * 32 + 16;
            int h = f * mh;
            int w = 1;
            int t = 12;
            if (h <= t) {
                h = t;
                w = 2;
            }
            if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) {
                w = -1;
            }
            for (int y = 0; y < h; y++) {
                map_set(map, x, y, z, w);
            }
        }
    }
    db_update_chunk(map, p, q);
}
示例#2
0
文件: simplex.c 项目: cbasasif/bart
/*
 * maximize c^T x subject to Ax <= b and x >= 0
 */
void (simplex)(unsigned int D, unsigned int N, float x[N], const float c[N], const float b[D], const float A[D][N])
{
	// 1. Step: slack variables
	// max c^T x      Ax + z = b    x,z >= 0

	float A2[D + 1][N + D + 1];

	for (unsigned int i = 0; i < N + D + 1; i++) {

		A2[0][i] = (i < N) ? -c[i] : 0.;

		for (unsigned int j = 0; j < D; j++) {

			if (i < N) 
				A2[1 + j][i] = A[j][i];
			else if (i == N + D)
				A2[1 + j][i] = b[j];
			else
				A2[1 + j][i] = (i - N == j) ? 1. : 0.;
		}
	}

	simplex2(D, N + D, A2);

	// extract results:
	float x2[D + N];
	solution(D, D + N, x2, A2);

	for (unsigned int i = 0; i < N; i++)
		x[i] = x2[i];
}
示例#3
0
文件: main.c 项目: jukajunior/Craft
void make_world(Map *map, int p, int q) {
    int pad = 1;
    for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) {
        for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) {
            int x = p * CHUNK_SIZE + dx;
            int z = q * CHUNK_SIZE + dz;
            float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
            float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2);
            int mh = g * 32 + 16;
            int h = f * mh;
            int w = 1;
            int t = 12;
            if (h <= t) {
                h = t;
                w = 2;
            }
            if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) {
                w = -1;
            }
            for (int y = 0; y < h; y++) {
                map_set(map, x, y, z, w);
            }
            if (w == 1) {
                if (simplex2(-x * 0.1, z * 0.1, 4, 0.8, 2) > 0.6) {
                    map_set(map, x, h, z, 17);
                }
                if (simplex2(x * 0.05, -z * 0.05, 4, 0.8, 2) > 0.7) {
                    int w = 18 + simplex2(x * 0.1, z * 0.1, 4, 0.8, 2) * 7;
                    map_set(map, x, h, z, w);
                }
            }
            for (int y = 64; y < 72; y++) {
                if (simplex3(x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75) {
                    map_set(map, x, y, z, 16);
                }
            }
        }
    }
}
示例#4
0
文件: world.c 项目: lowagner/home
void create_world1(int p, int q, world_func func, void *arg) {
    for (int dx = -CHUNK_PAD; dx < CHUNK_SIZE + CHUNK_PAD; dx++) {
        for (int dz = -CHUNK_PAD; dz < CHUNK_SIZE + CHUNK_PAD; dz++) {
            int flag = 1;
            if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) {
                flag = -1;
            }
            int x = p * CHUNK_SIZE + dx;
            int z = q * CHUNK_SIZE + dz;
            float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
            float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2);
            int mh = g * 32 + 16;
            int h = f * mh;
            unsigned int material = M_GRASS;
            int t = 12;
            if (h <= t) {
                h = t;
                material = M_SAND;
            }
            int w = (W){.shape=flag*S_CUBE, .material=material, .color=0}.value;
            // sand and grass terrain
            for (int y = 0; y < h; y++) {
                func(x, y, z, w, arg);
            }
            if (material == M_GRASS) {
                if (SHOW_PLANTS) {
                    // grass
                    if (simplex2(-x * 0.1, z * 0.1, 4, 0.8, 2) > 0.6) {
                        func(x, h, z, (W){.shape=flag*S_PLANT, 
                                .material=M_PLANT_GRASS, .color=0, .action=0}.value,
                            arg);
                    }
                    // flowers
                    if (simplex2(x * 0.05, -z * 0.05, 4, 0.8, 2) > 0.7) {
                        func(x, h, z, (W){.shape=flag*S_PLANT, 
                            .material=(M_RED_FLOWER
                                + M_FLOWER_COUNT * simplex2(x * 0.1, z * 0.1, 4, 0.8, 2)), 
                            .color=0, .action=0}.value, arg);
                    }
示例#5
0
文件: world.c 项目: burt041498/craft
void biome1(int x, int z, int flag, world_func func, void *arg) {
    int lo = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2) * 8 + 8;
    int hi = simplex2(-x * 0.01, -z * 0.01, 4, 0.5, 2) * 32 + 32;
    int lookup[] = {3, 6, 11, 12, 13};
    for (int y = 0; y < lo; y++) {
        func(x, y, z, 6 * flag, arg);
    }
    for (int y = lo; y < hi; y++) {
        int i = simplex3(-x * 0.01, -y * 0.01, -z * 0.01, 4, 0.5, 2) * 10;
        int w = lookup[i % 5];
        if (simplex3(x * 0.01, y * 0.01, z * 0.01, 4, 0.5, 2) > 0.5) {
            func(x, y, z, w * flag, arg);
        }
    }
    if (SHOW_CLOUDS) {
        for (int y = 64; y < 72; y++) {
            if (simplex3(
                x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75)
            {
                func(x, y, z, 16 * flag, arg);
            }
        }
    }
}
示例#6
0
文件: world.c 项目: burt041498/craft
void create_world2(int p, int q, world_func func, void *arg) {
    int pad = 1;
    for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) {
        for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) {
            int flag = 1;
            if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) {
                flag = -1;
            }
            int x = p * CHUNK_SIZE + dx;
            int z = q * CHUNK_SIZE + dz;
            int i = simplex2(-x * 0.001, -z * 0.001, 8, 0.5, 2) * 2;
            if (i == 0) biome0(x, z, flag, func, arg);
            else biome1(x, z, flag, func, arg);
        }
    }
}
示例#7
0
文件: main.c 项目: kanitaoru/Craft
void make_world(Map *map, int p, int q) {
    int pad = 1;
    for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) {
        for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) {
            int x = p * CHUNK_SIZE + dx;
            int z = q * CHUNK_SIZE + dz;
            float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
            float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2);
            int mh = g * 32 + 16;
            int h = f * mh;
            int w = 1;
            int t = 12;
            if (h <= t) {
                h = t;
                w = 2;
            }
            if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) {
                w = -1;
            }
            // sand and grass terrain
            for (int y = 0; y < h; y++) {
                map_set(map, x, y, z, w);
            }
            // TODO: w = -1 if outside of chunk
            if (w == 1) {
                // grass
                if (simplex2(-x * 0.1, z * 0.1, 4, 0.8, 2) > 0.6) {
                    map_set(map, x, h, z, 17);
                }
                // flowers
                if (simplex2(x * 0.05, -z * 0.05, 4, 0.8, 2) > 0.7) {
                    int w = 18 + simplex2(x * 0.1, z * 0.1, 4, 0.8, 2) * 7;
                    map_set(map, x, h, z, w);
                }
                // trees
                int ok = 1;
                if (dx - 4 < 0 || dz - 4 < 0 ||
                    dx + 4 >= CHUNK_SIZE || dz + 4 >= CHUNK_SIZE)
                {
                    ok = 0;
                }
                if (ok && simplex2(x, z, 6, 0.5, 2) > 0.84) {
                    for (int y = h + 3; y < h + 8; y++) {
                        for (int ox = -3; ox <= 3; ox++) {
                            for (int oz = -3; oz <= 3; oz++) {
                                int d = (ox * ox) + (oz * oz) +
                                    (y - (h + 4)) * (y - (h + 4));
                                if (d < 11) {
                                    map_set(map, x + ox, y, z + oz, 15);
                                }
                            }
                        }
                    }
                    for (int y = h; y < h + 7; y++) {
                        map_set(map, x, y, z, 5);
                    }
                }
            }
            // clouds
            for (int y = 64; y < 72; y++) {
                if (simplex3(x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75) {
                    map_set(map, x, y, z, 16);
                }
            }
        }
    }
}
示例#8
0
文件: world.c 项目: burt041498/craft
void biome0(int x, int z, int flag, world_func func, void *arg) {
    float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
    float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2);
    int mh = g * 32 + 16;
    int h = f * mh;
    int w = 1;
    int t = 12;
    if (h <= t) {
        h = t;
        w = 2;
    }
    // sand and grass terrain
    for (int y = 0; y < h; y++) {
        func(x, y, z, w * flag, arg);
    }
    if (w == 1) {
        if (SHOW_PLANTS) {
            // grass
            if (simplex2(-x * 0.1, z * 0.1, 4, 0.8, 2) > 0.6) {
                func(x, h, z, 17 * flag, arg);
            }
            // flowers
            if (simplex2(x * 0.05, -z * 0.05, 4, 0.8, 2) > 0.7) {
                int w = 18 + simplex2(x * 0.1, z * 0.1, 4, 0.8, 2) * 7;
                func(x, h, z, w * flag, arg);
            }
        }
        // trees
        int ok = 0;//SHOW_TREES;
        // if (dx - 4 < 0 || dz - 4 < 0 ||
        //     dx + 4 >= CHUNK_SIZE || dz + 4 >= CHUNK_SIZE)
        // {
        //     ok = 0;
        // }
        if (ok && simplex2(x, z, 6, 0.5, 2) > 0.84) {
            for (int y = h + 3; y < h + 8; y++) {
                for (int ox = -3; ox <= 3; ox++) {
                    for (int oz = -3; oz <= 3; oz++) {
                        int d = (ox * ox) + (oz * oz) +
                            (y - (h + 4)) * (y - (h + 4));
                        if (d < 11) {
                            func(x + ox, y, z + oz, 15, arg);
                        }
                    }
                }
            }
            for (int y = h; y < h + 7; y++) {
                func(x, y, z, 5, arg);
            }
        }
    }
    // clouds
    if (SHOW_CLOUDS) {
        for (int y = 64; y < 72; y++) {
            if (simplex3(
                x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75)
            {
                func(x, y, z, 16 * flag, arg);
            }
        }
    }
}