2021-09-24 10:15:43 -04:00
|
|
|
#ifndef ENGINE_H__
|
|
|
|
#define ENGINE_H__
|
|
|
|
#include "define.h"
|
|
|
|
#include "openglcontext.h"
|
|
|
|
#include "texture.h"
|
2021-09-27 10:20:58 -04:00
|
|
|
#include "transformation.h"
|
2021-10-26 17:28:37 -04:00
|
|
|
#include "shader.h"
|
2021-09-27 13:15:57 -04:00
|
|
|
#include "player.h"
|
2021-10-11 11:37:58 -04:00
|
|
|
#include "chunk.h"
|
2021-10-12 15:58:54 -04:00
|
|
|
#include "skybox.h"
|
2021-10-19 10:27:59 -04:00
|
|
|
#include "audio.h"
|
2021-10-26 17:28:37 -04:00
|
|
|
#include "textureatlas.h"
|
2021-10-31 00:31:08 -04:00
|
|
|
#include "blockinfo.h"
|
|
|
|
#include "array2d.h"
|
2021-11-15 20:58:13 -05:00
|
|
|
#include "world.h"
|
2021-09-24 10:15:43 -04:00
|
|
|
|
2021-11-15 20:58:13 -05:00
|
|
|
class Engine : public OpenglContext {
|
2021-09-24 10:15:43 -04:00
|
|
|
public:
|
|
|
|
Engine();
|
|
|
|
virtual ~Engine();
|
|
|
|
virtual void Init();
|
|
|
|
virtual void DeInit();
|
|
|
|
virtual void LoadResource();
|
|
|
|
virtual void UnloadResource();
|
|
|
|
virtual void Render(float elapsedTime);
|
|
|
|
virtual void KeyPressEvent(unsigned char key);
|
|
|
|
virtual void KeyReleaseEvent(unsigned char key);
|
|
|
|
virtual void MouseMoveEvent(int x, int y);
|
|
|
|
virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y);
|
|
|
|
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool LoadTexture(Texture& texture, const std::string& filename, bool stopOnError = true);
|
2021-10-26 17:28:37 -04:00
|
|
|
void DrawHud(float elapsedTime);
|
|
|
|
void PrintText(unsigned int x, unsigned int y, const std::string& t);
|
|
|
|
int GetFps(float elapsedTime) const;
|
2021-11-26 11:59:02 -05:00
|
|
|
bool GenerateChunk(int chx, int chy);
|
|
|
|
void UpdateWorld(int& generates, int& updates, int chx, int chy);
|
|
|
|
|
|
|
|
void GetBlockAtCursor(BlockType blocktype);
|
2021-09-24 10:15:43 -04:00
|
|
|
|
|
|
|
bool m_wireframe = false;
|
2021-11-26 11:59:02 -05:00
|
|
|
bool m_renderer = false;
|
|
|
|
|
|
|
|
int m_renderCount = 0;
|
2021-09-24 10:15:43 -04:00
|
|
|
|
2021-10-31 00:31:08 -04:00
|
|
|
BlockInfo* m_blockinfo[BTYPE_LAST];
|
|
|
|
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
|
2021-11-15 20:58:13 -05:00
|
|
|
World m_world = World();
|
2021-10-31 00:31:08 -04:00
|
|
|
|
2021-11-26 11:59:02 -05:00
|
|
|
|
2021-09-24 10:15:43 -04:00
|
|
|
Texture m_textureFloor;
|
2021-09-27 10:20:58 -04:00
|
|
|
Texture m_textureSkybox;
|
2021-10-26 17:28:37 -04:00
|
|
|
Texture m_textureFont;
|
|
|
|
Texture m_textureCrosshair;
|
2021-10-04 12:29:10 -04:00
|
|
|
Texture m_textureCube1;
|
2021-10-31 00:31:08 -04:00
|
|
|
|
2021-10-12 15:58:54 -04:00
|
|
|
Skybox m_skybox;
|
2021-10-11 11:37:58 -04:00
|
|
|
Shader m_shader01;
|
2021-10-25 10:50:08 -04:00
|
|
|
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
|
2021-10-19 10:27:59 -04:00
|
|
|
|
2021-11-27 14:14:05 -05:00
|
|
|
Player m_player = Player(Vector3f(CHUNK_SIZE_X * WORLD_SIZE_X / 2, CHUNK_SIZE_Y + 1.7f, CHUNK_SIZE_Z * WORLD_SIZE_X / 2));
|
2021-09-27 13:15:57 -04:00
|
|
|
|
2021-09-24 10:15:43 -04:00
|
|
|
bool m_keyW = false;
|
|
|
|
bool m_keyA = false;
|
|
|
|
bool m_keyS = false;
|
|
|
|
bool m_keyD = false;
|
2021-10-04 12:29:10 -04:00
|
|
|
bool m_keylshift = false;
|
2021-10-01 10:52:33 -04:00
|
|
|
bool m_keySpace = false;
|
2021-11-26 11:59:02 -05:00
|
|
|
bool m_mouseL = false;
|
|
|
|
bool m_mouseR = false;
|
|
|
|
bool m_mouseC = false;
|
|
|
|
bool m_mouseWU = false;
|
|
|
|
bool m_mouseWD = false;
|
2021-11-27 13:35:39 -05:00
|
|
|
|
|
|
|
bool m_block = false;
|
2021-09-24 10:15:43 -04:00
|
|
|
};
|
|
|
|
|
2021-11-26 11:59:02 -05:00
|
|
|
template <class T>
|
2021-11-27 13:35:39 -05:00
|
|
|
static bool EqualWithEpsilon(const T& v1, const T& v2, T epsilon = T(0.0001)) { return (fabs(v2 - v1) < epsilon); }
|
2021-11-26 11:59:02 -05:00
|
|
|
|
|
|
|
template <class T>
|
2021-11-27 13:35:39 -05:00
|
|
|
static bool InRangeWithEpsilon(const T& v, const T& vinf, const T& vsup, T epsilon = T(0.0001)) { return (v >= vinf - epsilon && v <= vsup + epsilon); }
|
2021-11-26 11:59:02 -05:00
|
|
|
|
2021-09-24 10:15:43 -04:00
|
|
|
#endif // ENGINE_H__
|