rayzor

changeset 22:5380ff64e83f tip

minor changes from dos, and line endings cleanup
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 02 May 2014 14:32:58 +0300
parents 8c4859442200
children
files src/m3drast.c src/material.h src/modeller.cc src/raytrace.cc src/raytrace.h src/stl/vector.h src/swapbuf.asm src/timer.c src/timer.h
diffstat 9 files changed, 375 insertions(+), 353 deletions(-) [+]
line diff
     1.1 --- a/src/m3drast.c	Tue Apr 15 20:52:05 2014 +0300
     1.2 +++ b/src/m3drast.c	Fri May 02 14:32:58 2014 +0300
     1.3 @@ -1,56 +1,56 @@
     1.4 -#include "m3dimpl.h"
     1.5 -#include "lines.h"
     1.6 -
     1.7 -
     1.8 -void m3d_draw_point(struct min3d_vertex *v)
     1.9 -{
    1.10 -	int x = v->pos[0] + 0.5;
    1.11 -	int y = v->pos[1] + 0.5;
    1.12 -	int xsz = m3dctx->cbuf->xsz;
    1.13 -	m3dctx->cbuf->pixels[y * xsz + x] = v->color;
    1.14 -}
    1.15 -
    1.16 -void m3d_draw_line(struct min3d_vertex *v)
    1.17 -{
    1.18 -	int x0, y0, x1, y1;
    1.19 -
    1.20 -	x0 = v[0].pos[0];
    1.21 -	y0 = v[0].pos[1];
    1.22 -	x1 = v[1].pos[0];
    1.23 -	y1 = v[1].pos[1];
    1.24 -
    1.25 -	if(clip_line2d(&x0, &y0, &x1, &y1, m3dctx->vport)) {
    1.26 -		draw_line(m3dctx->cbuf->pixels, m3dctx->cbuf->xsz, v->color, x0, y0, x1, y1);
    1.27 -	}
    1.28 -}
    1.29 -
    1.30 -void m3d_draw_poly(struct min3d_vertex *v, int numv)
    1.31 -{
    1.32 -	int i;
    1.33 -	struct min3d_vertex last[2];
    1.34 -
    1.35 -	if(ENABLED(M3D_CULL_FACE)) {
    1.36 -		float a[2], b[2], crossz = 0;
    1.37 -
    1.38 -		for(i=1; i<numv - 1; i++) {
    1.39 -			int n = i + 1;
    1.40 -			a[0] = v[i].pos[0] - v[0].pos[0];
    1.41 -			a[1] = v[i].pos[1] - v[0].pos[1];
    1.42 -
    1.43 -			b[0] = v[n].pos[0] - v[0].pos[0];
    1.44 -			b[1] = v[n].pos[1] - v[0].pos[1];
    1.45 -
    1.46 -			crossz += a[0] * b[1] - a[1] * b[0];
    1.47 -		}
    1.48 -
    1.49 -		if(crossz > 0) return;
    1.50 -	}
    1.51 -
    1.52 -	last[0] = v[numv - 1];
    1.53 -	last[1] = v[0];
    1.54 -
    1.55 -	for(i=0; i<numv - 1; i++) {
    1.56 -		m3d_draw_line(v++);
    1.57 -	}
    1.58 -	m3d_draw_line(last);
    1.59 -}
    1.60 +#include "m3dimpl.h"
    1.61 +#include "lines.h"
    1.62 +
    1.63 +
    1.64 +void m3d_draw_point(struct min3d_vertex *v)
    1.65 +{
    1.66 +	int x = v->pos[0] + 0.5;
    1.67 +	int y = v->pos[1] + 0.5;
    1.68 +	int xsz = m3dctx->cbuf->xsz;
    1.69 +	m3dctx->cbuf->pixels[y * xsz + x] = v->color;
    1.70 +}
    1.71 +
    1.72 +void m3d_draw_line(struct min3d_vertex *v)
    1.73 +{
    1.74 +	int x0, y0, x1, y1;
    1.75 +
    1.76 +	x0 = v[0].pos[0];
    1.77 +	y0 = v[0].pos[1];
    1.78 +	x1 = v[1].pos[0];
    1.79 +	y1 = v[1].pos[1];
    1.80 +
    1.81 +	if(clip_line2d(&x0, &y0, &x1, &y1, m3dctx->vport)) {
    1.82 +		draw_line(m3dctx->cbuf->pixels, m3dctx->cbuf->xsz, v->color, x0, y0, x1, y1);
    1.83 +	}
    1.84 +}
    1.85 +
    1.86 +void m3d_draw_poly(struct min3d_vertex *v, int numv)
    1.87 +{
    1.88 +	int i;
    1.89 +	struct min3d_vertex last[2];
    1.90 +
    1.91 +	if(ENABLED(M3D_CULL_FACE)) {
    1.92 +		float a[2], b[2], crossz = 0;
    1.93 +
    1.94 +		for(i=1; i<numv - 1; i++) {
    1.95 +			int n = i + 1;
    1.96 +			a[0] = v[i].pos[0] - v[0].pos[0];
    1.97 +			a[1] = v[i].pos[1] - v[0].pos[1];
    1.98 +
    1.99 +			b[0] = v[n].pos[0] - v[0].pos[0];
   1.100 +			b[1] = v[n].pos[1] - v[0].pos[1];
   1.101 +
   1.102 +			crossz += a[0] * b[1] - a[1] * b[0];
   1.103 +		}
   1.104 +
   1.105 +		if(crossz > 0) return;
   1.106 +	}
   1.107 +
   1.108 +	last[0] = v[numv - 1];
   1.109 +	last[1] = v[0];
   1.110 +
   1.111 +	for(i=0; i<numv - 1; i++) {
   1.112 +		m3d_draw_line(v++);
   1.113 +	}
   1.114 +	m3d_draw_line(last);
   1.115 +}
     2.1 --- a/src/material.h	Tue Apr 15 20:52:05 2014 +0300
     2.2 +++ b/src/material.h	Fri May 02 14:32:58 2014 +0300
     2.3 @@ -1,22 +1,22 @@
     2.4 -#ifndef MATERIAL_H_
     2.5 -#define MATERIAL_H_
     2.6 -
     2.7 -#include "vmath.h"
     2.8 -
     2.9 -class Material {
    2.10 -public:
    2.11 -	Vector3 diffuse, specular;
    2.12 -	float roughness;
    2.13 -	float reflect, refract;
    2.14 -	float ior;
    2.15 -
    2.16 -	Material()
    2.17 -		: diffuse(0.75, 0.75, 0.75), specular(1, 1, 1)
    2.18 -	{
    2.19 -		roughness = 1.0;
    2.20 -		reflect = refract = 0.0;
    2.21 -		ior = 1.0;
    2.22 -	}
    2.23 -};
    2.24 -
    2.25 -#endif	// MATERIAL_H_
    2.26 +#ifndef MATERIAL_H_
    2.27 +#define MATERIAL_H_
    2.28 +
    2.29 +#include "vmath.h"
    2.30 +
    2.31 +class Material {
    2.32 +public:
    2.33 +	Vector3 diffuse, specular;
    2.34 +	float roughness;
    2.35 +	float reflect, refract;
    2.36 +	float ior;
    2.37 +
    2.38 +	Material()
    2.39 +		: diffuse(0.75, 0.75, 0.75), specular(1, 1, 1)
    2.40 +	{
    2.41 +		roughness = 1.0;
    2.42 +		reflect = refract = 0.0;
    2.43 +		ior = 1.0;
    2.44 +	}
    2.45 +};
    2.46 +
    2.47 +#endif	// MATERIAL_H_
     3.1 --- a/src/modeller.cc	Tue Apr 15 20:52:05 2014 +0300
     3.2 +++ b/src/modeller.cc	Fri May 02 14:32:58 2014 +0300
     3.3 @@ -8,6 +8,7 @@
     3.4  #include "keyb.h"
     3.5  #include "scrman.h"
     3.6  #include "logger.h"
     3.7 +#include "timer.h"
     3.8  
     3.9  struct ModellerImpl {
    3.10  	int mx, my;
    3.11 @@ -18,6 +19,9 @@
    3.12  
    3.13  	bool bnstate[8];
    3.14  	int prev_x, prev_y;
    3.15 +
    3.16 +	float orig_theta;
    3.17 +	bool screensaver;
    3.18  };
    3.19  
    3.20  static void draw_grid(float size, float spacing);
    3.21 @@ -69,6 +73,10 @@
    3.22  
    3.23  void Modeller::draw() const
    3.24  {
    3.25 +	if(mod->screensaver) {
    3.26 +		mod->cam_theta = get_msec() / 100.0f;
    3.27 +	}
    3.28 +
    3.29  	m3d_clear(M3D_COLOR_BUFFER_BIT);
    3.30  
    3.31  	m3d_matrix_mode(M3D_MODELVIEW);
    3.32 @@ -173,6 +181,15 @@
    3.33  			}
    3.34  			break;
    3.35  
    3.36 +		case KB_F1:
    3.37 +			mod->screensaver = !mod->screensaver;
    3.38 +			if(mod->screensaver) {
    3.39 +				mod->orig_theta = mod->cam_theta;
    3.40 +			} else {
    3.41 +				mod->cam_theta = mod->orig_theta;
    3.42 +			}
    3.43 +			break;
    3.44 +
    3.45  		default:
    3.46  			break;
    3.47  		}
     4.1 --- a/src/raytrace.cc	Tue Apr 15 20:52:05 2014 +0300
     4.2 +++ b/src/raytrace.cc	Fri May 02 14:32:58 2014 +0300
     4.3 @@ -1,78 +1,78 @@
     4.4 -#include <assert.h>
     4.5 -#include <float.h>
     4.6 -#include "raytrace.h"
     4.7 -#include "rayzor.h"
     4.8 -#include "scene.h"
     4.9 -#include "logger.h"
    4.10 -
    4.11 -Vector3 ray_trace(const Ray &ray, int iter)
    4.12 -{
    4.13 -	RayHit hit;
    4.14 -	if(!scene->intersect(ray, &hit)) {
    4.15 -		return scene->get_background(ray);
    4.16 -	}
    4.17 -
    4.18 -	return shade(hit, iter);
    4.19 -}
    4.20 -
    4.21 -static inline float positive(float x)
    4.22 -{
    4.23 -	return x < 0.0f ? 0.0f : x;
    4.24 -}
    4.25 -
    4.26 -Vector3 shade(const RayHit &hit, int iter)
    4.27 -{
    4.28 -	const Material &mtl = hit.obj->mtl;
    4.29 -
    4.30 -	Vector3 pos = hit.ray.origin + hit.ray.dir * hit.dist;
    4.31 -	Vector3 norm = hit.obj->hit_normal(hit);
    4.32 -	norm = normalize(transform(normal_matrix(hit.obj->get_matrix()), norm));
    4.33 -	Vector3 vdir = -normalize(hit.ray.dir);
    4.34 -
    4.35 -	float ior = mtl.ior;
    4.36 -
    4.37 -	if(dot(norm, hit.ray.dir) > 0.0) {
    4.38 -		norm = -norm;
    4.39 -		ior = 1.0 / mtl.ior;
    4.40 -	}
    4.41 -
    4.42 -	Vector3 color = scene->get_ambient();
    4.43 -
    4.44 -	// for each light, calculate local illumination
    4.45 -	int num_lights = scene->get_light_count();
    4.46 -	for(int i=0; i<num_lights; i++) {
    4.47 -		const Light *lt = scene->get_light(i);
    4.48 -		Vector3 ldir = lt->get_position() - pos;
    4.49 -		Vector3 lcol = lt->get_color(pos);
    4.50 -
    4.51 -		RayHit hit;
    4.52 -		if(!scene->intersect(Ray(pos, ldir), &hit) || hit.dist > 1.0) {
    4.53 -			// if we can see the light, calculate and add its contribution
    4.54 -			ldir.normalize();
    4.55 -			float ndotl = positive(dot(norm, ldir));
    4.56 -			Vector3 diffuse = mtl.diffuse * lcol * ndotl;
    4.57 -
    4.58 -			Vector3 hdir = normalize(ldir + vdir);
    4.59 -			float ndoth = positive(dot(norm, hdir));
    4.60 -			Vector3 specular = mtl.specular * lcol * pow(ndoth, mtl.roughness * 128.0);
    4.61 -
    4.62 -			color = color + lerp(specular, diffuse, mtl.roughness);
    4.63 -		}
    4.64 -	}
    4.65 -
    4.66 -	if(mtl.reflect > 1e-4 && iter < 6) {
    4.67 -		Ray reflray(pos, reflect(vdir, norm));
    4.68 -
    4.69 -		Vector3 rcol = ray_trace(reflray, iter + 1) * mtl.specular * mtl.reflect;
    4.70 -		color = color + rcol;
    4.71 -	}
    4.72 -
    4.73 -	if(mtl.refract > 1e-4 && iter < 6) {
    4.74 -		Ray refrray(pos, refract(vdir, norm,  ior));
    4.75 -
    4.76 -		Vector3 rcol = ray_trace(refrray, iter + 1) * mtl.specular * mtl.refract;
    4.77 -		color = color + rcol;
    4.78 -	}
    4.79 -
    4.80 -	return color;
    4.81 -}
    4.82 +#include <assert.h>
    4.83 +#include <float.h>
    4.84 +#include "raytrace.h"
    4.85 +#include "rayzor.h"
    4.86 +#include "scene.h"
    4.87 +#include "logger.h"
    4.88 +
    4.89 +Vector3 ray_trace(const Ray &ray, int iter)
    4.90 +{
    4.91 +	RayHit hit;
    4.92 +	if(!scene->intersect(ray, &hit)) {
    4.93 +		return scene->get_background(ray);
    4.94 +	}
    4.95 +
    4.96 +	return shade(hit, iter);
    4.97 +}
    4.98 +
    4.99 +static inline float positive(float x)
   4.100 +{
   4.101 +	return x < 0.0f ? 0.0f : x;
   4.102 +}
   4.103 +
   4.104 +Vector3 shade(const RayHit &hit, int iter)
   4.105 +{
   4.106 +	const Material &mtl = hit.obj->mtl;
   4.107 +
   4.108 +	Vector3 pos = hit.ray.origin + hit.ray.dir * hit.dist;
   4.109 +	Vector3 norm = hit.obj->hit_normal(hit);
   4.110 +	norm = normalize(transform(normal_matrix(hit.obj->get_matrix()), norm));
   4.111 +	Vector3 vdir = -normalize(hit.ray.dir);
   4.112 +
   4.113 +	float ior = mtl.ior;
   4.114 +
   4.115 +	if(dot(norm, hit.ray.dir) > 0.0) {
   4.116 +		norm = -norm;
   4.117 +		ior = 1.0 / mtl.ior;
   4.118 +	}
   4.119 +
   4.120 +	Vector3 color = scene->get_ambient();
   4.121 +
   4.122 +	// for each light, calculate local illumination
   4.123 +	int num_lights = scene->get_light_count();
   4.124 +	for(int i=0; i<num_lights; i++) {
   4.125 +		const Light *lt = scene->get_light(i);
   4.126 +		Vector3 ldir = lt->get_position() - pos;
   4.127 +		Vector3 lcol = lt->get_color(pos);
   4.128 +
   4.129 +		RayHit hit;
   4.130 +		if(!scene->intersect(Ray(pos, ldir), &hit) || hit.dist > 1.0) {
   4.131 +			// if we can see the light, calculate and add its contribution
   4.132 +			ldir.normalize();
   4.133 +			float ndotl = positive(dot(norm, ldir));
   4.134 +			Vector3 diffuse = mtl.diffuse * lcol * ndotl;
   4.135 +
   4.136 +			Vector3 hdir = normalize(ldir + vdir);
   4.137 +			float ndoth = positive(dot(norm, hdir));
   4.138 +			Vector3 specular = mtl.specular * lcol * pow(ndoth, mtl.roughness * 128.0);
   4.139 +
   4.140 +			color = color + lerp(specular, diffuse, mtl.roughness);
   4.141 +		}
   4.142 +	}
   4.143 +
   4.144 +	if(mtl.reflect > 1e-4 && iter < 6) {
   4.145 +		Ray reflray(pos, reflect(vdir, norm));
   4.146 +
   4.147 +		Vector3 rcol = ray_trace(reflray, iter + 1) * mtl.specular * mtl.reflect;
   4.148 +		color = color + rcol;
   4.149 +	}
   4.150 +
   4.151 +	if(mtl.refract > 1e-4 && iter < 6) {
   4.152 +		Ray refrray(pos, refract(vdir, norm,  ior));
   4.153 +
   4.154 +		Vector3 rcol = ray_trace(refrray, iter + 1) * mtl.specular * mtl.refract;
   4.155 +		color = color + rcol;
   4.156 +	}
   4.157 +
   4.158 +	return color;
   4.159 +}
     5.1 --- a/src/raytrace.h	Tue Apr 15 20:52:05 2014 +0300
     5.2 +++ b/src/raytrace.h	Fri May 02 14:32:58 2014 +0300
     5.3 @@ -1,20 +1,20 @@
     5.4 -#ifndef RAYTRACE_H_
     5.5 -#define RAYTRACE_H_
     5.6 -
     5.7 -#include "vmath.h"
     5.8 -#include "vmathray.h"
     5.9 -
    5.10 -class Object;
    5.11 -
    5.12 -struct RayHit {
    5.13 -	Ray ray;			// the ray in world coordinates
    5.14 -	Ray lray;			// the local coordinate system ray
    5.15 -	float dist;			// parametric distance along the ray
    5.16 -	const Object *obj;	// pointer to the object that has been hit
    5.17 -	const void *subobj;	// object-specific subobject pointer (can be null).
    5.18 -};
    5.19 -
    5.20 -Vector3 ray_trace(const Ray &ray, int iter = 0);
    5.21 -Vector3 shade(const RayHit &hit, int iter);
    5.22 -
    5.23 -#endif	// RAYTRACE_H_
    5.24 +#ifndef RAYTRACE_H_
    5.25 +#define RAYTRACE_H_
    5.26 +
    5.27 +#include "vmath.h"
    5.28 +#include "vmathray.h"
    5.29 +
    5.30 +class Object;
    5.31 +
    5.32 +struct RayHit {
    5.33 +	Ray ray;			// the ray in world coordinates
    5.34 +	Ray lray;			// the local coordinate system ray
    5.35 +	float dist;			// parametric distance along the ray
    5.36 +	const Object *obj;	// pointer to the object that has been hit
    5.37 +	const void *subobj;	// object-specific subobject pointer (can be null).
    5.38 +};
    5.39 +
    5.40 +Vector3 ray_trace(const Ray &ray, int iter = 0);
    5.41 +Vector3 shade(const RayHit &hit, int iter);
    5.42 +
    5.43 +#endif	// RAYTRACE_H_
     6.1 --- a/src/stl/vector.h	Tue Apr 15 20:52:05 2014 +0300
     6.2 +++ b/src/stl/vector.h	Fri May 02 14:32:58 2014 +0300
     6.3 @@ -1,127 +1,127 @@
     6.4 -/* vi:set ft=cpp: */
     6.5 -#ifndef VECTOR_H_
     6.6 -#define VECTOR_H_
     6.7 -
     6.8 -#include <stdlib.h>
     6.9 -
    6.10 -template <class T>
    6.11 -class vector {
    6.12 -private:
    6.13 -	T *data;
    6.14 -	size_t num_items, max_items;
    6.15 -
    6.16 -public:
    6.17 -	vector()
    6.18 -	{
    6.19 -		data = 0;
    6.20 -		num_items = max_items = 0;
    6.21 -	}
    6.22 -
    6.23 -	vector(const vector &v)
    6.24 -	{
    6.25 -		data = 0;
    6.26 -		num_items = max_items = 0;
    6.27 -		resize(v.size());
    6.28 -
    6.29 -		for(size_t i=0; i<v.size(); i++) {
    6.30 -			data[i] = v.data[i];
    6.31 -		}
    6.32 -	}
    6.33 -
    6.34 -	vector &operator =(const vector &v)
    6.35 -	{
    6.36 -		if(&v != this) {
    6.37 -			clear();
    6.38 -			resize(v.size());
    6.39 -
    6.40 -			for(size_t i=0; i<v.size(); i++) {
    6.41 -				data[i] = v.data[i];
    6.42 -			}
    6.43 -		}
    6.44 -		return *this;
    6.45 -	}
    6.46 -
    6.47 -	~vector()
    6.48 -	{
    6.49 -		clear();
    6.50 -	}
    6.51 -
    6.52 -	void clear()
    6.53 -	{
    6.54 -		delete [] data;
    6.55 -		data = 0;
    6.56 -		max_items = num_items = 0;
    6.57 -	}
    6.58 -
    6.59 -	bool empty() const
    6.60 -	{
    6.61 -		return num_items == 0;
    6.62 -	}
    6.63 -
    6.64 -	size_t size() const
    6.65 -	{
    6.66 -		return num_items;
    6.67 -	}
    6.68 -
    6.69 -	void resize(size_t nsz)
    6.70 -	{
    6.71 -		if(nsz > 0) {
    6.72 -			T *newdata = new T[nsz];
    6.73 -			if(!newdata) return;
    6.74 -
    6.75 -			size_t num = num_items < nsz ? num_items : nsz;
    6.76 -			for(size_t i=0; i<num; i++) {
    6.77 -				newdata[i] = data[i];
    6.78 -			}
    6.79 -
    6.80 -			delete [] data;
    6.81 -			data = newdata;
    6.82 -			max_items = nsz;
    6.83 -			num_items = num;
    6.84 -		} else {
    6.85 -			delete [] data;
    6.86 -			max_items = num_items = 0;
    6.87 -		}
    6.88 -	}
    6.89 -
    6.90 -	void push_back(const T &item)
    6.91 -	{
    6.92 -		if(num_items >= max_items) {
    6.93 -			resize(max_items > 0 ? max_items * 2 : 8);
    6.94 -		}
    6.95 -		data[num_items++] = item;
    6.96 -	}
    6.97 -
    6.98 -	void pop_back()
    6.99 -	{
   6.100 -		if(--num_items <= 0) {
   6.101 -			num_items = 0;
   6.102 -		}
   6.103 -
   6.104 -		if(num_items < max_items / 3) {
   6.105 -			resize(max_items / 2);
   6.106 -		}
   6.107 -	}
   6.108 -
   6.109 -	T &back()
   6.110 -	{
   6.111 -		return data[num_items - 1];
   6.112 -	}
   6.113 -
   6.114 -	const T &back() const
   6.115 -	{
   6.116 -		return data[num_items - 1];
   6.117 -	}
   6.118 -
   6.119 -	T &operator [](int idx)
   6.120 -	{
   6.121 -		return data[idx];
   6.122 -	}
   6.123 -
   6.124 -	const T &operator [](int idx) const
   6.125 -	{
   6.126 -		return data[idx];
   6.127 -	}
   6.128 -};
   6.129 -
   6.130 -#endif	// VECTOR_H_
   6.131 +/* vi:set ft=cpp: */
   6.132 +#ifndef VECTOR_H_
   6.133 +#define VECTOR_H_
   6.134 +
   6.135 +#include <stdlib.h>
   6.136 +
   6.137 +template <class T>
   6.138 +class vector {
   6.139 +private:
   6.140 +	T *data;
   6.141 +	size_t num_items, max_items;
   6.142 +
   6.143 +public:
   6.144 +	vector()
   6.145 +	{
   6.146 +		data = 0;
   6.147 +		num_items = max_items = 0;
   6.148 +	}
   6.149 +
   6.150 +	vector(const vector &v)
   6.151 +	{
   6.152 +		data = 0;
   6.153 +		num_items = max_items = 0;
   6.154 +		resize(v.size());
   6.155 +
   6.156 +		for(size_t i=0; i<v.size(); i++) {
   6.157 +			data[i] = v.data[i];
   6.158 +		}
   6.159 +	}
   6.160 +
   6.161 +	vector &operator =(const vector &v)
   6.162 +	{
   6.163 +		if(&v != this) {
   6.164 +			clear();
   6.165 +			resize(v.size());
   6.166 +
   6.167 +			for(size_t i=0; i<v.size(); i++) {
   6.168 +				data[i] = v.data[i];
   6.169 +			}
   6.170 +		}
   6.171 +		return *this;
   6.172 +	}
   6.173 +
   6.174 +	~vector()
   6.175 +	{
   6.176 +		clear();
   6.177 +	}
   6.178 +
   6.179 +	void clear()
   6.180 +	{
   6.181 +		delete [] data;
   6.182 +		data = 0;
   6.183 +		max_items = num_items = 0;
   6.184 +	}
   6.185 +
   6.186 +	bool empty() const
   6.187 +	{
   6.188 +		return num_items == 0;
   6.189 +	}
   6.190 +
   6.191 +	size_t size() const
   6.192 +	{
   6.193 +		return num_items;
   6.194 +	}
   6.195 +
   6.196 +	void resize(size_t nsz)
   6.197 +	{
   6.198 +		if(nsz > 0) {
   6.199 +			T *newdata = new T[nsz];
   6.200 +			if(!newdata) return;
   6.201 +
   6.202 +			size_t num = num_items < nsz ? num_items : nsz;
   6.203 +			for(size_t i=0; i<num; i++) {
   6.204 +				newdata[i] = data[i];
   6.205 +			}
   6.206 +
   6.207 +			delete [] data;
   6.208 +			data = newdata;
   6.209 +			max_items = nsz;
   6.210 +			num_items = num;
   6.211 +		} else {
   6.212 +			delete [] data;
   6.213 +			max_items = num_items = 0;
   6.214 +		}
   6.215 +	}
   6.216 +
   6.217 +	void push_back(const T &item)
   6.218 +	{
   6.219 +		if(num_items >= max_items) {
   6.220 +			resize(max_items > 0 ? max_items * 2 : 8);
   6.221 +		}
   6.222 +		data[num_items++] = item;
   6.223 +	}
   6.224 +
   6.225 +	void pop_back()
   6.226 +	{
   6.227 +		if(--num_items <= 0) {
   6.228 +			num_items = 0;
   6.229 +		}
   6.230 +
   6.231 +		if(num_items < max_items / 3) {
   6.232 +			resize(max_items / 2);
   6.233 +		}
   6.234 +	}
   6.235 +
   6.236 +	T &back()
   6.237 +	{
   6.238 +		return data[num_items - 1];
   6.239 +	}
   6.240 +
   6.241 +	const T &back() const
   6.242 +	{
   6.243 +		return data[num_items - 1];
   6.244 +	}
   6.245 +
   6.246 +	T &operator [](int idx)
   6.247 +	{
   6.248 +		return data[idx];
   6.249 +	}
   6.250 +
   6.251 +	const T &operator [](int idx) const
   6.252 +	{
   6.253 +		return data[idx];
   6.254 +	}
   6.255 +};
   6.256 +
   6.257 +#endif	// VECTOR_H_
     7.1 --- a/src/swapbuf.asm	Tue Apr 15 20:52:05 2014 +0300
     7.2 +++ b/src/swapbuf.asm	Fri May 02 14:32:58 2014 +0300
     7.3 @@ -1,46 +1,46 @@
     7.4 -; vim:set ft=nasm:
     7.5 -	segment code use32
     7.6 -
     7.7 -	; void swap_buffers_asm(void *dest, void *src, int xsz, int ysz, int bpp)
     7.8 -	; dest	-> eax
     7.9 -	; src	-> edx
    7.10 -	; xsz	-> ebx
    7.11 -	; ysz	-> ecx
    7.12 -	; bpp	-> [ebp + 8] (after pushing ebp)
    7.13 -	global swap_buffers_asm_
    7.14 -swap_buffers_asm_:
    7.15 -	push ebp
    7.16 -	mov ebp, esp
    7.17 -
    7.18 -	mov edi, eax	; let's hold dest ptr in edi, frees up eax
    7.19 -	mov esi, edx	; let's hold src ptr in esi, frees up edx
    7.20 -	; calculate pixel count -> ecx, frees up ebx
    7.21 -	mov eax, ebx
    7.22 -	mul ecx
    7.23 -	mov ecx, eax	; now ecx = xsz * ysz	
    7.24 -	
    7.25 -	mov eax, [ebp + 8]	; eax <- bpp
    7.26 -	cmp eax, 32
    7.27 -	je .bpp32
    7.28 -	cmp eax, 24
    7.29 -	je .bpp24
    7.30 -	cmp eax, 16
    7.31 -	je .bpp16
    7.32 -	; invalid bpp, ignore
    7.33 -	jmp .done
    7.34 -
    7.35 -.bpp32:				; 32bit block transfer, no conversion
    7.36 -	rep movsd		; esi, edi, and ecx already loaded, just go...
    7.37 -	jmp .done
    7.38 -	
    7.39 -.bpp24:				; 32bpp -> 24bpp conversion (LSB-first), 1 byte overrun!
    7.40 -	movsd			; transfer a full 32bit chunk and inc esi,edi by 4
    7.41 -	dec edi			; backtrack dest one byte after last transfer
    7.42 -	dec ecx
    7.43 -	jnz .bpp24
    7.44 -	jmp .done
    7.45 -
    7.46 -.bpp16:				; fuck 16bpp for now (TODO)
    7.47 -.done:
    7.48 -	pop ebp
    7.49 -	ret	
    7.50 +; vim:set ft=nasm:
    7.51 +	segment code use32
    7.52 +
    7.53 +	; void swap_buffers_asm(void *dest, void *src, int xsz, int ysz, int bpp)
    7.54 +	; dest	-> eax
    7.55 +	; src	-> edx
    7.56 +	; xsz	-> ebx
    7.57 +	; ysz	-> ecx
    7.58 +	; bpp	-> [ebp + 8] (after pushing ebp)
    7.59 +	global swap_buffers_asm_
    7.60 +swap_buffers_asm_:
    7.61 +	push ebp
    7.62 +	mov ebp, esp
    7.63 +
    7.64 +	mov edi, eax	; let's hold dest ptr in edi, frees up eax
    7.65 +	mov esi, edx	; let's hold src ptr in esi, frees up edx
    7.66 +	; calculate pixel count -> ecx, frees up ebx
    7.67 +	mov eax, ebx
    7.68 +	mul ecx
    7.69 +	mov ecx, eax	; now ecx = xsz * ysz	
    7.70 +	
    7.71 +	mov eax, [ebp + 8]	; eax <- bpp
    7.72 +	cmp eax, 32
    7.73 +	je .bpp32
    7.74 +	cmp eax, 24
    7.75 +	je .bpp24
    7.76 +	cmp eax, 16
    7.77 +	je .bpp16
    7.78 +	; invalid bpp, ignore
    7.79 +	jmp .done
    7.80 +
    7.81 +.bpp32:				; 32bit block transfer, no conversion
    7.82 +	rep movsd		; esi, edi, and ecx already loaded, just go...
    7.83 +	jmp .done
    7.84 +	
    7.85 +.bpp24:				; 32bpp -> 24bpp conversion (LSB-first), 1 byte overrun!
    7.86 +	movsd			; transfer a full 32bit chunk and inc esi,edi by 4
    7.87 +	dec edi			; backtrack dest one byte after last transfer
    7.88 +	dec ecx
    7.89 +	jnz .bpp24
    7.90 +	jmp .done
    7.91 +
    7.92 +.bpp16:				; fuck 16bpp for now (TODO)
    7.93 +.done:
    7.94 +	pop ebp
    7.95 +	ret	
     8.1 --- a/src/timer.c	Tue Apr 15 20:52:05 2014 +0300
     8.2 +++ b/src/timer.c	Fri May 02 14:32:58 2014 +0300
     8.3 @@ -1,6 +1,6 @@
     8.4  /*
     8.5 -256-color 3D graphics hack for real-mode DOS.
     8.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
     8.7 +pit8254 timer code for DOS programs.
     8.8 +Copyright (C) 2011-2014  John Tsiombikas <nuclear@member.fsf.org>
     8.9  
    8.10  This program is free software: you can redistribute it and/or modify
    8.11  it under the terms of the GNU General Public License as published by
    8.12 @@ -22,6 +22,10 @@
    8.13  #include <i86.h>
    8.14  #include "pit8254.h"
    8.15  
    8.16 +#ifdef BORLANDC
    8.17 +#error borland unsupported
    8.18 +#endif
    8.19 +
    8.20  #define PIT_TIMER_INTR	8
    8.21  #define DOS_TIMER_INTR	0x1c
    8.22  
     9.1 --- a/src/timer.h	Tue Apr 15 20:52:05 2014 +0300
     9.2 +++ b/src/timer.h	Fri May 02 14:32:58 2014 +0300
     9.3 @@ -1,6 +1,6 @@
     9.4  /*
     9.5 -256-color 3D graphics hack for real-mode DOS.
     9.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
     9.7 +pit8254 timer code for DOS programs.
     9.8 +Copyright (C) 2011-2014  John Tsiombikas <nuclear@member.fsf.org>
     9.9  
    9.10  This program is free software: you can redistribute it and/or modify
    9.11  it under the terms of the GNU General Public License as published by
    9.12 @@ -29,6 +29,7 @@
    9.13  
    9.14  void reset_timer(void);
    9.15  unsigned long get_msec(void);
    9.16 +unsigned long get_ticks(void);
    9.17  
    9.18  #ifdef __cplusplus
    9.19  }