Skip to content

Commit 4ede88b

Browse files
committed
Mac: Fix mac compability with OpenGL, glew, glm and ENet.
Updated glm.
1 parent fc681e8 commit 4ede88b

File tree

268 files changed

+57060
-55945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+57060
-55945
lines changed

EntityPlayer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ void EntityPlayer::update(float delta, const Uint8* keyCode)
9696
if(keyCode[SDL_SCANCODE_D])
9797
velocity.x += acceleration;
9898

99-
if(std::abs(velocity.x) > maxSpeed)
99+
if(abs(velocity.x) > maxSpeed)
100100
{
101101
if(velocity.x > 0)
102102
velocity.x = maxSpeed;
103103
else if(velocity.x < 0)
104104
velocity.x = -maxSpeed;
105105
}
106106

107-
if(std::abs(velocity.y) > maxSpeed)
107+
if(abs(velocity.y) > maxSpeed)
108108
{
109109
if(velocity.y > 0)
110110
velocity.y = maxSpeed;
@@ -140,15 +140,15 @@ void EntityPlayer::update(float delta, const Uint8* keyCode)
140140

141141
void EntityPlayer::update2(float delta)
142142
{
143-
if(std::abs(velocity.x) > maxSpeed)
143+
if(abs(velocity.x) > maxSpeed)
144144
{
145145
if(velocity.x > 0)
146146
velocity.x = maxSpeed;
147147
else if(velocity.x < 0)
148148
velocity.x = -maxSpeed;
149149
}
150150

151-
if(std::abs(velocity.y) > maxSpeed)
151+
if(abs(velocity.y) > maxSpeed)
152152
{
153153
if(velocity.y > 0)
154154
velocity.y = maxSpeed;

GL_utilities.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
extern "C" {
66
#endif
77

8-
#include <GL/glew.h>
8+
#ifdef __APPLE__
9+
#include "glew.h"
10+
#include <OpenGL/gl3.h>
11+
#else
12+
#include <GL/glew.h>
13+
#endif
914

1015
void printError(const char *functionName);
1116
GLuint loadShaders(const char *vertFileName, const char *fragFileName);

Game.cpp

+11-26
Original file line numberDiff line numberDiff line change
@@ -227,26 +227,11 @@ void Game::loadJson(void)
227227

228228
void Game::loadSettings(void)
229229
{
230-
std::string settingsChunkPath = "../assets/config/settings/chunk.json";
231-
std::string settingsEnginePath = "../assets/config/settings/engine.json";
232-
std::string settingsGraphicPath = "../assets/config/settings/graphic.json";
233-
std::string settingsPlayerPath = "../assets/config/settings/player.json";
234-
std::string settingsTilePath = "../assets/config/settings/tile.json";
235-
#ifdef __APPLE__
236-
CFBundleRef mainBundle = CFBundleGetMainBundle();
237-
CFURLRef resourceURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
238-
char p[PATH_MAX];
239-
if(!CFURLGetFileSystemRepresentation(resourceURL, TRUE, (UInt8 *)p, PATH_MAX))
240-
std::cout << "ERROROROROR" << std::endl;
241-
CFRelease(resourceURL);
242-
243-
chdir(p);
244-
245-
std::string path = p;
246-
247-
std::string texturePath = path + "/" + texturePath;
248-
std::string playerPath = path + "/" + playerPath;
249-
#endif
230+
std::string settingsEnginePath = Utility::getBasePath() + "assets/config/settings/engine.json";
231+
std::string settingsGraphicPath = Utility::getBasePath() + "assets/config/settings/graphic.json";
232+
std::string settingsPlayerPath = Utility::getBasePath() + "assets/config/settings/player.json";
233+
std::string settingsTilePath = Utility::getBasePath() + "assets/config/settings/tile.json";
234+
250235
rapidjson::Document doc;
251236
std::cout << "--------------------Loading Settings--------------------" << std::endl;
252237
std::cout << "----------Loading engine.json----------" << std::endl;
@@ -295,7 +280,7 @@ void Game::loadSettings(void)
295280
playerType.size = glm::vec2(doc["size"]["width"].GetInt(), doc["size"]["height"].GetInt());
296281

297282
assert(doc["texture"].IsString());
298-
playerType.texture = std::string("../assets/config/settings/")+doc["texture"].GetString();
283+
playerType.texture = std::string("assets/config/settings/")+doc["texture"].GetString();
299284

300285
assert(doc["acceleration"].IsDouble());
301286
playerType.acceleration = (float)doc["acceleration"].GetDouble();
@@ -324,7 +309,7 @@ void Game::loadSettings(void)
324309

325310
void Game::loadTiles(void)
326311
{
327-
std::string path = "../assets/config/tiles/";
312+
std::string path = Utility::getBasePath() + "assets/config/tiles/";
328313

329314
DIR* dir;
330315
struct dirent* ent;
@@ -368,10 +353,10 @@ void Game::loadTiles(void)
368353

369354
void Game::loadItems(void)
370355
{
371-
std::string clothingPath = "../assets/config/items/clothing/";
372-
std::string consumablesPath = "../assets/config/items/consumables/";
373-
std::string materialPath = "../assets/config/items/materials/";
374-
std::string weaponPath = "../assets/config/items/weapons/";
356+
std::string clothingPath = Utility::getBasePath() + "assets/config/items/clothing/";
357+
std::string consumablesPath = Utility::getBasePath() + "assets/config/items/consumables/";
358+
std::string materialPath = Utility::getBasePath() + "assets/config/items/materials/";
359+
std::string weaponPath = Utility::getBasePath() + "assets/config/items/weapons/";
375360

376361
DIR* dir;
377362
struct dirent* ent;

Game.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
#ifdef __APPLE__
55
#include <SDL2_mixer/SDL_mixer.h>
6+
#include <dirent.h>
67
#else
78
#include "SDL_mixer.h"
9+
#include "dirent.h"
810
#endif
911

1012
#include <cstdio>
@@ -14,7 +16,7 @@
1416
#include <iostream>
1517
#include <memory>
1618

17-
#include "dirent.h"
19+
1820
#include "lib/rapidjson/document.h"
1921
#include "lib/rapidjson/filestream.h"
2022

@@ -37,6 +39,7 @@
3739
#include "TypeMaterial.h"
3840
#include "TypeWeapon.h"
3941
#include "Chat.h"
42+
#include "Utility.h"
4043

4144
class Game
4245
{

Graphics.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
Graphics::Graphics(void)
44
{
5-
6-
//SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_OPENGL, &win, &renderer);
7-
8-
9-
win = SDL_CreateWindow("Project Z", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Settings::Graphics::screenWidth, Settings::Graphics::screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); // create window
10-
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
11-
12-
context = SDL_GL_CreateContext(win);
13-
SDL_GL_MakeCurrent(win, context);
14-
15-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); // specify OpenGL version
5+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); // specify OpenGL version
166
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); // 3.2
177
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
188
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
199
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
2010
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
2111

12+
win = SDL_CreateWindow("Project Z", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Settings::Graphics::screenWidth, Settings::Graphics::screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); // create window
13+
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
14+
15+
16+
17+
18+
19+
20+
21+
2222
SDL_GL_SetSwapInterval(1); // Vsync
2323

2424
glewExperimental = GL_TRUE;
@@ -30,8 +30,10 @@ Graphics::Graphics(void)
3030
std::cout << "Using GLEW: " << glewGetString(GLEW_VERSION) << std::endl;
3131
std::cout << "Using OpenGL: " << (char*)glGetString(GL_VERSION) << std::endl;
3232

33-
//glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
34-
33+
34+
context = SDL_GL_CreateContext(win);
35+
SDL_GL_MakeCurrent(win, context);
36+
3537
printError("Graphics|Graphics");
3638
}
3739

ModelSquare.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
ModelSquare::ModelSquare(std::string vert, std::string frag)
44
{
5+
vert = Utility::getBasePath() + vert;
6+
frag = Utility::getBasePath() + frag;
57
prog = loadShaders(vert.c_str(), frag.c_str());
68
glGenVertexArrays(1, &vertexArrayObj);
79

ModelSquare.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "GL_utilities.h"
1212
#include "Defines.h"
13+
#include "Utility.h"
1314

1415
enum class BUFFTYPE
1516
{

Network.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Network::Network(const char* ipChar)
2828

2929
ENetEvent event;
3030

31-
if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT)
31+
if(enet_host_service(client, &event, 1000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT)
3232
{
3333
std::cout << "Successfully connected to server" << std::endl;
3434
success = true;

0 commit comments

Comments
 (0)