Before I learned the ++ ..

Started by
7 comments, last by wintertime 10 years, 5 months ago

Last modified January 2001, good old days.. ^^


// Global
struct Global
{
	// Windows stuff
	HINSTANCE					hInstance;
	HWND						hWnd;
	HDC							hDC;
	HGLRC						hRC;
	bool						active_app;
	bool						pressed_keys[256];
	bool						old_keys[256];
	
	// Direct Input
	//LPDIRECTINPUT7				di;
	//LPDIRECTINPUTDEVICE7		di_keyboard;
	//BYTE						di_buffer[256];
	
	// Screen info
	GLushort					screen_width;
	GLushort					screen_height;
	GLushort					bit_depth;
	
	// Loop done
	GLboolean					done;
	
	// Controls
	GLboolean					forward_pressed;
	GLboolean					backward_pressed;
	GLboolean					left_pressed;
	GLboolean					right_pressed;
	
	GLfloat						turn_angle;
	GLfloat						look_angle;
	
	GLboolean					new_left_button;
	GLboolean					new_right_button;
	
	GLboolean					left_button_pressed;
	GLboolean					left_button_was_pressed;
	GLboolean					right_button_pressed;
	GLboolean					right_button_was_pressed;
	
	GLboolean					shift_pressed;
	
	GLshort						mouse_x;
	GLshort						mouse_y;
	GLshort						mouse_x_start;
	GLshort						mouse_y_start;
	GLfloat						mouse_x_fraction;
	GLfloat						mouse_y_fraction;
	GLfloat						mouse_x_start_fraction;
	GLfloat						mouse_y_start_fraction;
	
	// FPS
	GLfloat						fps;
	
	// Global time (in milliseconds)
	unsigned long				time;
	
	// Trig tables
	GLfloat						cosTable[36000];
	GLfloat						sinTable[36000];
	
	// Main menu
	GLshort						main_menu_selection;
	GLshort						main_menu_which_menu;
	GLshort						main_menu_selection_red_change;
	GLshort						main_menu_selection_green_change;
	GLfloat						main_menu_selection_red;
	GLfloat						main_menu_selection_green;
	GLfloat						main_menu_x_move;
	GLfloat						main_menu_y_move;
	GLfloat						main_menu_points_x[11][11];
	GLfloat						main_menu_points_y[11][11];
	
	GLboolean					main_menu_up_pressed;
	GLboolean					main_menu_down_pressed;
	GLboolean					main_menu_confirm_pressed;
	
	GLfloat						angle;
	
	// Game state
	GLshort						game_state;
	GLboolean					end_game;
	
	// Camera
	GLfloat						camera_offset_x;
	GLfloat						camera_offset_y;
	GLfloat						camera_offset_z;
	GLfloat						camera_rot_x;
	GLfloat						camera_rot_y;
	GLfloat						camera_rot_z;
	
	// Textures
	GLuint						*textures;
	GLushort					texture_count;
	GLshort						at_texture;
	TextureFilePtr				texture_files;
	GLshort						current_texture;
	GLshort						added_textures;
	GLshort						num_global_textures;
	
	// Global textures
	GLshort						font_texture;
	GLshort						button_mark_texture;
	GLshort						selection_texture;
	GLshort						statusbar_texture;
	GLshort						buildbar_texture;
	GLshort						minimap_texture;
	
	GLshort						blood_texture;
	
	GLshort						gys_barracks_selection_texture;
	GLshort						gys_bc_selection_texture;
	GLshort						gys_utsatt_selection_texture;
	
	GLshort						cancel_button_texture;
	
	GLshort						grass_texture;
	GLshort						main_menu_texture;
	
	GLshort						single_texture;
	GLshort						host_texture;
	GLshort						join_texture;
	GLshort						options_texture;
	GLshort						quit_texture;
	
	// Sky dome
	GLshort						skydome_texture;
	GLshort						cloud_texture;
	GLshort						sky_box_start_texture;
	
	// Floor/wall textures
	GLshort						floor_texture;
	GLshort						wall_texture;
	
	// Players
	PlayerPtr					players;
	PlayerPtr					camera_player;
	
	// Structures/units
	UnitPtr						units;
	StructurePtr				structures;
	SelectionPtr				selection;
	char						*mouse_target;
	char						*highlighted_target;
	
	unsigned int				next_unit_id;
	unsigned int				next_structure_id;
	
	BloodSourcePtr				blood_sources;
	BloodPtr					blood;
	ProjectilePtr				projectiles;
	TerrainEffectPtr			terrain_effects;
	
	// Models
	SMPtr						model_gys_utsatt;
	SMPtr						model_gys_bc;
	SMPtr						model_gys_barracks;
	SMPtr						model_gys_arm;
	SMPtr						model_gys_leg;
	SMPtr						model_gys_torso;
	SMPtr						model_gys_head;
	
	// Resources
	GLshort						minerals;
	GLshort						gas;
	
	// Chat
	ChatMPtr					chat_messages;
	GLboolean					chatting;
	GLshort						chat_message_length;
	GLubyte						chat_message[256];
	
	// Button marks
	ButtonMarkPtr				button_marks;
	
	// Network
	Server						server;
	Client						client;
	GLshort						net_type;
	MessagePtr					messages;
	
	GLshort						ip_string_length;
	GLubyte						ip_string[256];
	
	// World
	GLfloat						world_y[101][101];
	GLfloat						world_shade[101][101];
	GLfloat						bottom_y;
	GLfloat						world_y_change[101][101];
	WorldTriangle				world_triangles[100][100][2];
	
	char						text[256];
	char						text2[256];
	GLboolean					do_it;
	
	FILE						*log_file;
	
	GLboolean					compressed;
};
typedef struct Global Global;

At least functions had representative names..


void Draw3DModelFast(SMPtr model, float offset_x, float offset_y, float offset_z,
					float rotation_x, float rotation_y, float rotation_z)
{
	BonePtr					bone = 0;
	int						i;
	int						j;
	float					x;
	float					y;
	float					z;
	float					shade;
	
	//glEnable(GL_DEPTH_TEST);
	//glCullFace(GL_BACK);
	//glEnable(GL_CULL_FACE);
	//glEnable(GL_TEXTURE_2D);
	
	for(i=0;i<model->triCount;i++)
	{
		if(g.current_texture != (model->triList[i].texture+model->firstTexture))
		{
			glBindTexture(GL_TEXTURE_2D, g.textures[model->triList[i].texture+model->firstTexture]);
			g.current_texture = model->triList[i].texture + model->firstTexture;
		}
		
		glBegin(GL_TRIANGLES);
		for(j=0;j<3;j++)
		{
			x = model->vertexList[model->triList[i].vertex[j]].point.x;
			y = model->vertexList[model->triList[i].vertex[j]].point.y;
			z = model->vertexList[model->triList[i].vertex[j]].point.z;
			
			shade = model->vertexList[model->triList[i].vertex[j]].shade;
			glColor4f(shade, shade, shade, 1.0f);
			
			glTexCoord2f(model->vertexList[model->triList[i].vertex[j]].u,
							model->vertexList[model->triList[i].vertex[j]].v);
			
			RotatePt(&x, &y, &z, rotation_x, rotation_y, rotation_z);
			
			x += offset_x;
			y += offset_y;
			z += offset_z;
			
			glVertex3f(x, y, z);
		}
		
		glEnd();
	}
}// Draw3DModelFast
Advertisement

C++ with functions, eh? ;)

Beginner in Game Development?  Read here. And read here.

 

Aww, that looks a bit like you had switched away from COBOL shortly before.huh.png

It's not that bad. E.g. there's only one global variable wink.png

Haha true :) The real wtf is what I could possibly have compared it with when I named that function Draw3DModelFast :)

A sin table and a cos table?! Precision to the 100th degree? You must have had quite a bit of ram back then to afford such luxuries.

A sin table and a cos table?! Precision to the 100th degree? You must have had quite a bit of ram back then to afford such luxuries.

Hehe, I doubt those were even a speed gain in 2001, probably a remnant from my 75mhz Mac :)

Ouch, I'm doing that right now for my JavaScript...

Previously "Krohm"

You know, arithmetic is getting faster and faster, but memory reads improve much slower, especially when having a large, likely uncached table.

This topic is closed to new replies.

Advertisement