Sfoglia il codice sorgente

WGDefault -> DefaultWorldGen

opengl-renderer-broken
Martin Dørum 4 anni fa
parent
commit
253c24148e

+ 1
- 1
core.mod/CMakeLists.txt Vedi File

add_library(core.mod SHARED add_library(core.mod SHARED
src/main.cc src/main.cc
src/WGDefault.cc
src/DefaultWorldGen.cc
src/entities/EntPlayer.cc src/entities/EntPlayer.cc
src/entities/EntItemStack.cc) src/entities/EntItemStack.cc)
set_target_properties(core.mod PROPERTIES OUTPUT_NAME mod PREFIX "") set_target_properties(core.mod PROPERTIES OUTPUT_NAME mod PREFIX "")

core.mod/src/WGDefault.cc → core.mod/src/DefaultWorldGen.cc Vedi File

#include "WGDefault.h"
#include "DefaultWorldGen.h"


#include <algorithm> #include <algorithm>


return (int)(perlin.noise(x / 50.0, 10) * 10) + 10; return (int)(perlin.noise(x / 50.0, 10) * 10) + 10;
} }


void WGDefault::drawBackground(const Swan::Context &ctx, Swan::Win &win, Swan::Vec2 pos) {
void DefaultWorldGen::drawBackground(const Swan::Context &ctx, Swan::Win &win, Swan::Vec2 pos) {
int texmin = 10; int texmin = 10;
int texmax = 20; int texmax = 20;


} }
} }


SDL_Color WGDefault::backgroundColor(Swan::Vec2 pos) {
SDL_Color DefaultWorldGen::backgroundColor(Swan::Vec2 pos) {
float y = pos.y; float y = pos.y;
return Swan::Draw::linearGradient(y, { return Swan::Draw::linearGradient(y, {
{ 0, { 128, 220, 250, 255 } }, { 0, { 128, 220, 250, 255 } },
{ 1000, { 65, 10, 10, 255 } } }); { 1000, { 65, 10, 10, 255 } } });
} }


Swan::Tile::ID WGDefault::genTile(Swan::TilePos pos) {
Swan::Tile::ID DefaultWorldGen::genTile(Swan::TilePos pos) {
int grass_level = grassLevel(perlin_, pos.x); int grass_level = grassLevel(perlin_, pos.x);
int stone_level = stoneLevel(perlin_, pos.x); int stone_level = stoneLevel(perlin_, pos.x);


return tAir_; return tAir_;
} }


void WGDefault::genChunk(Swan::WorldPlane &plane, Swan::Chunk &chunk) {
void DefaultWorldGen::genChunk(Swan::WorldPlane &plane, Swan::Chunk &chunk) {
for (int cx = 0; cx < Swan::CHUNK_WIDTH; ++cx) { for (int cx = 0; cx < Swan::CHUNK_WIDTH; ++cx) {
int tilex = chunk.pos_.x * Swan::CHUNK_WIDTH + cx; int tilex = chunk.pos_.x * Swan::CHUNK_WIDTH + cx;


} }
} }


Swan::BodyTrait::HasBody *WGDefault::spawnPlayer(Swan::WorldPlane &plane) {
Swan::BodyTrait::HasBody *DefaultWorldGen::spawnPlayer(Swan::WorldPlane &plane) {
int x = 0; int x = 0;
return dynamic_cast<Swan::BodyTrait::HasBody *>( return dynamic_cast<Swan::BodyTrait::HasBody *>(
plane.spawnEntity("core::player", Swan::SRFFloatArray{ plane.spawnEntity("core::player", Swan::SRFFloatArray{

core.mod/src/WGDefault.h → core.mod/src/DefaultWorldGen.h Vedi File



#include <PerlinNoise/PerlinNoise.hpp> #include <PerlinNoise/PerlinNoise.hpp>


class WGDefault: public Swan::WorldGen {
class DefaultWorldGen: public Swan::WorldGen {
public: public:
class Factory: public Swan::WorldGen::Factory { class Factory: public Swan::WorldGen::Factory {
public: public:
WorldGen *create(Swan::World &world) override { return new WGDefault(world); }
WorldGen *create(Swan::World &world) override { return new DefaultWorldGen(world); }
}; };


WGDefault(Swan::World &world):
DefaultWorldGen(Swan::World &world):
tGrass_(world.getTileID("core::grass")), tGrass_(world.getTileID("core::grass")),
tDirt_(world.getTileID("core::dirt")), tDirt_(world.getTileID("core::dirt")),
tStone_(world.getTileID("core::stone")), tStone_(world.getTileID("core::stone")),

+ 2
- 2
core.mod/src/main.cc Vedi File

#include <swan/swan.h> #include <swan/swan.h>


#include "WGDefault.h"
#include "DefaultWorldGen.h"
#include "entities/EntPlayer.h" #include "entities/EntPlayer.h"
#include "entities/EntItemStack.h" #include "entities/EntItemStack.h"


.image = "core::tree-trunk", .image = "core::tree-trunk",
}); });


mod.registerWorldGen("default", std::make_unique<WGDefault::Factory>());
mod.registerWorldGen("default", std::make_unique<DefaultWorldGen::Factory>());


mod.registerEntity("player", std::make_unique<EntPlayer::Factory>()); mod.registerEntity("player", std::make_unique<EntPlayer::Factory>());
mod.registerEntity("item-stack", std::make_unique<EntItemStack::Factory>()); mod.registerEntity("item-stack", std::make_unique<EntItemStack::Factory>());

+ 2
- 2
libswan/src/drawutil.cc Vedi File

y = (y * win.zoom_) * -factor; y = (y * win.zoom_) * -factor;
SDL_Rect rect{ SDL_Rect rect{
0, 0, 0, 0,
(int)(srcrect->w * win.zoom_),
(int)(srcrect->h * win.zoom_),
(int)((float)srcrect->w * win.zoom_),
(int)((float)srcrect->h * win.zoom_),
}; };


rect.x = (int)std::floor((int)x % rect.w); rect.x = (int)std::floor((int)x % rect.w);

Loading…
Annulla
Salva