reworking distrib & Scene to work together

git-svn-id: svn://anubis/fart/trunk@226 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-04-06 18:38:30 +00:00
1 parent fdf34009bf
commit 33f554d714
5 files changed
+133 -34

No files matched your search

+66 -23
View File
@@ -125,34 +125,77 @@ Scene::~Scene()
void Scene::render()
{
if (m_verbose && m_server)
if (m_server)
{
cout << " *** Beginning scene render ***" << endl;
cout << "Parameters:" << endl;
cout << "----------------------------------------" << endl;
cout << " Width: " << m_width << endl;
cout << " Height: " << m_height << endl;
cout << " Multisample Level: " << m_multisample_level << endl;
cout << " Vertical Field of View: " << m_vfov << endl;
cout << "----------------------------------------" << endl;
}
m_data = new unsigned char[m_width * m_height * 3];
for (int i = 0; i < m_height; i++)
{
for (int j = 0; j < m_width; j++)
/* server version */
if (m_verbose)
{
renderPixel(j, i, &m_data[3 * (m_width * i + j)]);
cout << " *** Beginning scene render ***" << endl;
cout << "Parameters:" << endl;
cout << "----------------------------------------" << endl;
cout << " Width: " << m_width << endl;
cout << " Height: " << m_height << endl;
cout << " Multisample Level: " << m_multisample_level << endl;
cout << " Vertical Field of View: " << m_vfov << endl;
cout << "----------------------------------------" << endl;
}
}
if (m_verbose && m_server)
{
cout << " *** Ending scene render ***" << endl;
cout << "Writing output file '" << m_output_file_name << '\'' << endl;
m_data = new unsigned char[m_width * m_height * 3]; /* 24bpp */
if (m_distrib.getNumClients() < 1)
{
for (int i = 0; i < m_height; i++)
{
for (int j = 0; j < m_width; j++)
{
renderPixel(j, i, &m_data[3 * (m_width * i + j)]);
}
}
}
else
{
m_distrib.set_data(m_data);
/* work on tasks in this thread until there are no more */
taskLoop();
}
if (m_verbose)
{
cout << " *** Ending scene render ***" << endl;
cout << "Writing output file '" << m_output_file_name
<< '\'' << endl;
}
BMP outputImage(m_output_file_name.c_str(), m_width, m_height, m_data);
}
else
{
/* client version */
taskLoop();
}
}
void Scene::taskLoop()
{
for (;;)
{
int task_id = m_distrib.getTask();
if (task_id < 0)
break;
unsigned char data[3 * UNIT_TASK_SIZE];
int i = task_id / m_width;
int j = task_id % m_width;
for (int t = 0; t < UNIT_TASK_SIZE; t++)
{
renderPixel(j, i, &data[3 * t]);
j++;
if (j == m_width)
{
j = 0;
i++;
}
}
m_distrib.send_data(task_id, data, 3 * UNIT_TASK_SIZE);
}
BMP outputImage(m_output_file_name.c_str(), m_width, m_height, m_data);
}
void Scene::renderPixel(int x, int y, unsigned char * pixel)
+2
View File
@@ -23,6 +23,7 @@
#include "Light.h"
#define SCENE_FACTOR_THRESHOLD 0.02
#define UNIT_TASK_SIZE 50
class Scene
{
@@ -49,6 +50,7 @@ class Scene
const Vector & surfaceNormal);
Color calculateLightContribution(const Ray & toLight,
refptr<Light> light);
void taskLoop();
/* In Scene-load.cc */
void load(const char * filename);
+4 -4
View File
@@ -124,11 +124,11 @@ int main(int argc, char * argv[])
{
cout << " (";
if (days)
cout << days << " days, ";
cout << days << (days == 1 ? " day, " : " days, ");
if (days || hours)
cout << hours << " hours, ";
cout << minutes << " minutes, ";
cout << seconds << " seconds)";
cout << hours << (hours == 1 ? " hour, " : " hours, ");
cout << minutes << (minutes == 1 ? " minute, " : " minutes, ");
cout << seconds << (seconds == 1 ? " second)" : " seconds)");
}
cout << endl;
}