ソースを参照

randomness

opengl-renderer-broken
Martin Dørum 4年前
コミット
e7437ef94c
5個のファイルの変更17行の追加7行の削除
  1. 2
    2
      CMakeLists.txt
  2. 6
    0
      core.mod/src/entities/EntItemStack.cc
  3. 3
    3
      libswan/include/swan/Win.h
  4. 4
    1
      libswan/include/swan/World.h
  5. 2
    1
      libswan/src/Game.cc

+ 2
- 2
CMakeLists.txt ファイルの表示

@@ -5,8 +5,8 @@ find_package(SFML 2.5 COMPONENTS graphics system window REQUIRED)

set(CMAKE_CXX_CLANG_TIDY
clang-tidy
-header-filter=.*
-checks=-*,-checks=bugprone-*,cert-*,performance-*,clang-analyzer-*,-cert-dcl16-c,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall)
--header-filter=.*
--checks=-*,bugprone-*,cert-*,performance-*,clang-analyzer-*,-cert-dcl16-c,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall)

add_compile_options(-std=c++2a -Wall -Wextra -Wpedantic -Wno-unused-parameter)
if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL "")

+ 6
- 0
core.mod/src/entities/EntItemStack.cc ファイルの表示

@@ -1,9 +1,15 @@
#include "EntItemStack.h"

#include <random>

EntItemStack::EntItemStack(const Swan::Context &ctx, const Swan::SRF &params):
PhysicsEntity(SIZE, MASS) {

readSRF(ctx, params);

static std::uniform_real_distribution dis(-0.2f, 0.2f);

body_.pos_ += Swan::Vec2{ dis(ctx.world.random_), dis(ctx.world.random_) };
}

void EntItemStack::draw(const Swan::Context &ctx, Swan::Win &win) {

+ 3
- 3
libswan/include/swan/Win.h ファイルの表示

@@ -6,9 +6,6 @@ namespace Swan {

class Win {
public:
float scale_ = 2;
Vec2 cam_;

Win(sf::RenderWindow *win): window_(win) {}

void setPos(const Vec2 &pos) {
@@ -26,6 +23,9 @@ public:
return Vec2(v.x, v.y) / (TILE_SIZE * scale_);
}

float scale_ = 2;
Vec2 cam_;

private:
sf::RenderWindow *window_;
sf::Transform transform_;

+ 4
- 1
libswan/include/swan/World.h ファイルの表示

@@ -3,6 +3,7 @@
#include <memory>
#include <vector>
#include <string>
#include <random>

#include "common.h"
#include "Asset.h"
@@ -18,7 +19,7 @@ class Game;

class World {
public:
World(Game *game): game_(game) {}
World(Game *game, unsigned long rand_seed): game_(game), random_(rand_seed) {}

WorldPlane &addPlane(const std::string &gen);
WorldPlane &addPlane() { return addPlane(default_world_gen_); }
@@ -50,6 +51,8 @@ public:
Entity *player_;
Game *game_;

std::mt19937 random_;

private:
class ChunkRenderer {
public:

+ 2
- 1
libswan/src/Game.cc ファイルの表示

@@ -3,6 +3,7 @@
#include <dlfcn.h>
#include <math.h>
#include <SFML/Window/Mouse.hpp>
#include <time.h>

#include "Tile.h"
#include "Asset.h"
@@ -30,7 +31,7 @@ void Game::loadMod(const std::string &path) {
}

void Game::createWorld(const std::string &worldgen) {
world_.reset(new World(this));
world_.reset(new World(this, time(NULL)));
for (auto &mod: registered_mods_) {
world_->registerTile(std::shared_ptr<Tile>(Tile::createInvalid()));


読み込み中…
キャンセル
保存