Skip to content

Commit

Permalink
Some mac ports, floating point stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
BSVino committed Jan 25, 2016
1 parent 3277df4 commit 1998349
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Makefile.osx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CC=gcc
CXX=g++
RM=rm -f
CPPFLAGS=-g -O2
CPPFLAGS=-g #-O2
LDFLAGS=-Llib/osx
LDLIBS=-lglfw -framework OpenGL -framework ApplicationServices
INCLUDES=-I. -Icommon -Imath -Iinclude
Expand Down
79 changes: 42 additions & 37 deletions game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON A
#include <stdlib.h>
#endif

#include <float.h>
#include <assert.h>

#include "mtrand.h"

#include "main.h"
Expand All @@ -36,64 +39,66 @@ using std::vector;

int main(int argc, char* argv[])
{
mtsrand(0);

int max_frames = 10000;
int particles = 10000;

struct timeb t1, t2;

printf("Creating particles...\n\n");

ParticleSystem s;
s.Initialize();

for (int k = 0; k < particles; k++)
s.SpawnParticle();

#if 1
s.m_first_with_gravity = particles/2;
for (int k = 0; k < s.m_first_with_gravity; k++)
s.m_particles[k].m_gravity = false;
for (int k = s.m_first_with_gravity; k < particles; k++)
s.m_particles[k].m_gravity = true;
#else
for (int k = 0; k < particles; k++)
s.m_particles[k].m_gravity = mtrand()%2;
#endif

long elapsed_ms;
{
float b = 1000.0f;
float a = 0.00001f;

printf("Simulating particles...\n\n");
float c = a + b;

ftime(&t1);
printf("%f\n", c);
}

for (int k = 0; k < max_frames; k++)
{
g_current_time += g_frame_time;
float b = 1000.0f;
float a = 0.0001f;
float c = -999.999f;

float d1 = (a + b) + c;
float d2 = a + (b + c);

s.Update();
printf("%f %f\n", d1, d2);
}

ftime(&t2);
{
float a = -1;
float b = 0;

elapsed_ms = (long)(t2.time - t1.time) * 1000 + (t2.millitm - t1.millitm);
float c = a / b;

printf("Time: %ldms\n", elapsed_ms);
printf("Simulation time: %f\n", g_current_time);
float max = FLT_MAX;

return 0;
if (c > max)
printf("Bigger!\n");
else
printf("Smaller!\n");

float d = 5;

float e = d / c;

printf("%f\n", c);
}

{
float a = 0;
float b = 0;

float c = a / b;

if (c == c)
printf("True\n");
else
printf("False\n");

assert(c == c); // Make sure c is not a NaN.

printf("%f\n", c);
}


return 0;

mtsrand(0);

// Create a game
CGame game(argc, argv);
Expand Down
51 changes: 0 additions & 51 deletions game/main.h
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
#pragma once

double g_current_time = 0;
double g_frame_time = 1/30.0f;
Vector g_gravity = Vector(0, 0, -9.8);

float RandFloat(float min, float max)
{
return ((float)mtrand()) * (max-min) /MTRAND_MAX + min;
}

struct Particle
{
Vector m_position;
Vector m_velocity;
bool m_gravity;
};

struct ParticleSystem
{
vector<Particle> m_particles;
int m_first_with_gravity;

void Initialize()
{
m_particles.reserve(1024*10);
}

void SpawnParticle()
{
m_particles.push_back(Particle());
Particle* new_particle = &m_particles[m_particles.size()-1];

new_particle->m_position.x = 0;
new_particle->m_position.y = 0;
new_particle->m_position.z = 0;

new_particle->m_velocity.x = RandFloat(-1, 1);
new_particle->m_velocity.y = RandFloat(-1, 1);
new_particle->m_velocity.z = 1;
}

void Update()
{
int particles = m_particles.size();

for (size_t i = 0; i < particles; i++)
{
Particle* p = &m_particles[i];

p->m_position = p->m_position + p->m_velocity * g_frame_time;
if (p->m_gravity)
p->m_velocity = p->m_velocity + g_gravity;
}
}
};

Binary file added libglfw.dylib
Binary file not shown.
19 changes: 19 additions & 0 deletions mfgd.sublime-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
{
"build_systems":
[
{
"encoding": "cp850",
"file_regex": "^(.*?)\\(([0-9]+),?([0-9]+)?\\) (.*)",
"name": "MakeOSX",
"osx":
{
"cmd":
[
"make",
"-f",
"Makefile.osx"
],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path}"
}
}
],
"folders":
[
{
Expand Down
6 changes: 5 additions & 1 deletion renderer/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ CApplication::CApplication(int argc, char** argv)

void CApplication::OpenWindow(size_t iWidth, size_t iHeight, bool bFullscreen, bool bResizeable)
{
glfwInit();
if (!glfwInit())
{
printf("glfwInit failed\n");
exit(1);
}

m_bFullscreen = bFullscreen;

Expand Down

0 comments on commit 1998349

Please sign in to comment.