Browse Source

WGDefault -> DefaultWorldGen

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
253c24148e

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

@@ -1,6 +1,6 @@
add_library(core.mod SHARED
src/main.cc
src/WGDefault.cc
src/DefaultWorldGen.cc
src/entities/EntPlayer.cc
src/entities/EntItemStack.cc)
set_target_properties(core.mod PROPERTIES OUTPUT_NAME mod PREFIX "")

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

@@ -1,4 +1,4 @@
#include "WGDefault.h"
#include "DefaultWorldGen.h"

#include <algorithm>

@@ -10,7 +10,7 @@ static int stoneLevel(const siv::PerlinNoise &perlin, int x) {
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 texmax = 20;

@@ -28,7 +28,7 @@ void WGDefault::drawBackground(const Swan::Context &ctx, Swan::Win &win, Swan::V
}
}

SDL_Color WGDefault::backgroundColor(Swan::Vec2 pos) {
SDL_Color DefaultWorldGen::backgroundColor(Swan::Vec2 pos) {
float y = pos.y;
return Swan::Draw::linearGradient(y, {
{ 0, { 128, 220, 250, 255 } },
@@ -40,7 +40,7 @@ SDL_Color WGDefault::backgroundColor(Swan::Vec2 pos) {
{ 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 stone_level = stoneLevel(perlin_, pos.x);

@@ -58,7 +58,7 @@ Swan::Tile::ID WGDefault::genTile(Swan::TilePos pos) {
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) {
int tilex = chunk.pos_.x * Swan::CHUNK_WIDTH + cx;

@@ -72,7 +72,7 @@ void WGDefault::genChunk(Swan::WorldPlane &plane, Swan::Chunk &chunk) {
}
}

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

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

@@ -4,14 +4,14 @@

#include <PerlinNoise/PerlinNoise.hpp>

class WGDefault: public Swan::WorldGen {
class DefaultWorldGen: public Swan::WorldGen {
public:
class Factory: public Swan::WorldGen::Factory {
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")),
tDirt_(world.getTileID("core::dirt")),
tStone_(world.getTileID("core::stone")),

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

@@ -1,6 +1,6 @@
#include <swan/swan.h>

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

@@ -65,7 +65,7 @@ extern "C" void mod_init(Swan::Mod &mod) {
.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("item-stack", std::make_unique<EntItemStack::Factory>());

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

@@ -73,8 +73,8 @@ void parallaxBackground(
y = (y * win.zoom_) * -factor;
SDL_Rect rect{
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);

Loading…
Cancel
Save