Browse Source

chunk stuff and such

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
3517204077
11 changed files with 73 additions and 6 deletions
  1. 2
    2
      Makefile
  2. 10
    0
      src/Chunk.cc
  3. 14
    0
      src/Chunk.h
  4. 10
    0
      src/Game.cc
  5. 8
    0
      src/Game.h
  6. 4
    2
      src/Player.h
  7. 10
    0
      src/Tile.h
  8. 1
    1
      src/WorldPlane.cc
  9. 9
    0
      src/WorldPlane.h
  10. 3
    1
      src/common.h
  11. 2
    0
      src/main.cc

+ 2
- 2
Makefile View File

@@ -3,8 +3,8 @@
PROJNAME = cpplat
PROJTYPE = exe

SRCS = src/Body.cc src/Game.cc src/main.cc src/Player.cc src/WorldPlane.cc
HDRS = src/Body.h src/common.h src/Game.h src/Player.h src/WorldPlane.h
SRCS = src/Body.cc src/Chunk.cc src/Game.cc src/main.cc src/Player.cc src/WorldPlane.cc
HDRS = src/Body.h src/Chunk.h src/common.h src/Game.h src/Player.h src/Tile.h src/WorldPlane.h
OBJS = $(patsubst src/%,$(BUILD)/obj/%.o,$(SRCS))
DEPS = $(patsubst src/%,$(BUILD)/dep/%.d,$(SRCS))
PUBLICHDRS =

+ 10
- 0
src/Chunk.cc View File

@@ -0,0 +1,10 @@
#include "Chunk.h"

#include <string.h>

void Chunk::clear() {
memset(tiles_, 0, sizeof(tiles_));
}

void Chunk::draw(Win &win) {
}

+ 14
- 0
src/Chunk.h View File

@@ -0,0 +1,14 @@
#pragma once

#include "common.h"
#include "Tile.h"

class Chunk {
public:
int x_;
int y_;
Tile::TileID tiles_[CHUNK_HEIGHT][CHUNK_WIDTH];

void clear();
void draw(Win &win);
};

+ 10
- 0
src/Game.cc View File

@@ -1,5 +1,15 @@
#include "Game.h"

void Game::registerTile(std::string &name, Tile &tile) {
Tile::TileID id = registered_tiles_.size();
registered_tiles_.push_back(tile);
tile_id_map_[name] = id;
}

Tile::TileID Game::getTileID(std::string &name) {
return tile_id_map_[name];
}

void Game::draw(Win &win) {
for (WorldPlane *plane: planes_)
plane->draw(win);

+ 8
- 0
src/Game.h View File

@@ -1,16 +1,24 @@
#pragma once

#include <vector>
#include <map>
#include <string>

#include "common.h"
#include "WorldPlane.h"
#include "Player.h"
#include "Tile.h"

class Game {
public:
Player *player_;
WorldPlane *current_plane_;
std::vector<WorldPlane *> planes_;
std::vector<Tile> registered_tiles_;
std::map<std::string, Tile::TileID> tile_id_map_;

void registerTile(std::string &name, Tile &tile);
Tile::TileID getTileID(std::string &name);

void draw(Win &win);
void update(float dt);

+ 4
- 2
src/Player.h View File

@@ -8,7 +8,7 @@
class Player {
public:
Player(Vec2 pos):
body_(pos, Vec2(1, 1), mass) {}
body_(pos, Vec2(width, height), mass) {}

void draw(Win &win);
void update(float dt);
@@ -16,7 +16,9 @@ public:
private:
static constexpr float force = 600;
static constexpr float friction = 100;
static constexpr float mass = 50;
static constexpr float mass = 80;
static constexpr float width = 1;
static constexpr float height = 2;

Body body_;
};

+ 10
- 0
src/Tile.h View File

@@ -0,0 +1,10 @@
#pragma once

#include <stdint.h>

class Tile {
public:
using TileID = uint16_t;

Tile(std::string name);
};

+ 1
- 1
src/WorldPlane.cc View File

@@ -6,5 +6,5 @@ void WorldPlane::draw(Win &win) {
void WorldPlane::update(float dt) {
}

void tick() {
void WorldPlane::tick() {
}

+ 9
- 0
src/WorldPlane.h View File

@@ -1,9 +1,18 @@
#pragma once

#include <vector>

#include "common.h"
#include "Chunk.h"

class WorldPlane {
public:
std::vector<Chunk> chunks_;
int max_chunk_x_ = 0;
int min_chunk_x_ = 0;
int max_chunk_y_ = 0;
int min_chunk_y_ = 0;

void draw(Win &win);
void update(float dt);
void tick();

+ 3
- 1
src/common.h View File

@@ -3,8 +3,10 @@
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics.hpp>

#define UNIT_SIZE 32.0
#define UNIT_SIZE 12.0
#define TICK_RATE 20
#define CHUNK_HEIGHT 32
#define CHUNK_WIDTH 32

class Vec2: public sf::Vector2<float> {
public:

+ 2
- 0
src/main.cc View File

@@ -28,6 +28,8 @@ int main() {

Game game;
game.player_ = new Player(Vec2(1, 1));
game.current_plane_ = new WorldPlane();
game.planes_.push_back(game.current_plane_);

double prevtime = getTime();
double fpsAcc = 0;

Loading…
Cancel
Save