Moved program parameters to win.h, more cleanup, comments added.

This commit is contained in:
Shamus Young 2009-05-05 07:43:50 +00:00
parent e5a507289b
commit 7eee6e143d
10 changed files with 65 additions and 90 deletions

View File

@ -26,6 +26,7 @@
#include "random.h"
#include "texture.h"
#include "world.h"
#include "win.h"
//This is used by the recursive roof builder to decide what items may be added.
enum
@ -143,7 +144,7 @@ void CBuilding::RenderFlat (bool colored)
if (colored)
glColor3fv (&_color.red);
//_mesh_flat->Render ();
_mesh_flat->Render ();
}

View File

@ -34,6 +34,7 @@
#include "texture.h"
#include "world.h"
#include "visible.h"
#include "win.h"
static GLvector direction[] =
{

View File

@ -26,6 +26,7 @@
#include "texture.h"
#include "world.h"
#include "visible.h"
#include "win.h"
struct entity
{
@ -224,36 +225,6 @@ void EntityUpdate ()
}
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
void xEntityRender ()
{
int i;
bool wireframe;
int polymode[2];
glGetIntegerv (GL_POLYGON_MODE, &polymode[0]);
wireframe = polymode[0] != GL_FILL;
for (i = 0; i < entity_count; i++) {
if (Visible (entity_list[i].object->Center ())) {
glBindTexture(GL_TEXTURE_2D, entity_list[i].object->Texture ());
entity_list[i].object->Render ();
}
}
glBindTexture(GL_TEXTURE_2D, 0);
glColor3f (0,0,0);
for (i = 0; i < entity_count; i++) {
if (Visible (entity_list[i].object->Center ())) {
entity_list[i].object->RenderFlat (wireframe);
}
}
}
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/

View File

@ -66,6 +66,7 @@ LINK32=link.exe
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
@ -78,7 +79,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /profile /debug /machine:I386
!ENDIF

View File

@ -24,6 +24,7 @@
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <math.h>
@ -101,9 +102,9 @@ enum
EFFECT_BLOOM_RADIAL,
EFFECT_COLOR_CYCLE,
EFFECT_GLASS_CITY,
EFFECT_COUNT,
EFFECT_DEBUG,
EFFECT_DEBUG_OVERBLOOM,
EFFECT_COUNT
};
#else
enum
@ -128,12 +129,10 @@ static int render_height;
static bool letterbox;
static int letterbox_offset;
static int effect;
static int max_texture;
static unsigned next_fps;
static unsigned current_fps;
static unsigned frames;
static bool show_wireframe;
static bool bloom;
static bool flat;
static bool show_fps;
static bool show_fog;
@ -260,7 +259,7 @@ static void do_effects (int type)
//Psychedelic bloom
glEnable (GL_BLEND);
glBegin (GL_QUADS);
color = WorldBloomColor () * BLOOM_SCALING;
color = WorldBloomColor () * BLOOM_SCALING * 2;
glColor3fv (&color.red);
for (i = 0; i <= 100; i+=10) {
glTexCoord2f (0, 0); glVertex2i (-i, i + render_height);
@ -519,12 +518,17 @@ void RenderInit (void)
SelectObject(hDC, oldfont);
DeleteObject(font);
}
//If the program is running for the first time, set the defaults.
if (!IniInt ("SetDefaults")) {
IniIntSet ("SetDefaults", 1);
IniIntSet ("Effect", EFFECT_BLOOM);
IniIntSet ("ShowFog", 1);
}
//load in our settings
letterbox = IniInt ("Letterbox") != 0;
show_wireframe = IniInt ("Wireframe") != 0;
show_fps = IniInt ("ShowFPS") != 0;
show_fog = IniInt ("ShowFog") != 0;
bloom = IniInt ("Bloom") != 0;
effect = IniInt ("Effect");
flat = IniInt ("Flat") != 0;
fog_distance = WORLD_HALF;
@ -720,7 +724,7 @@ void RenderUpdate (void)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glLoadIdentity();
glLineWidth (2.0f);
glLineWidth (1.0f);
pos = CameraPosition ();
angle = CameraAngle ();
glRotatef (angle.x, 1.0f, 0.0f, 0.0f);

View File

@ -24,6 +24,7 @@
#include "math.h"
#include "visible.h"
#include "world.h"
#include "win.h"
static bool vis_grid[GRID_SIZE][GRID_SIZE];
@ -67,7 +68,7 @@ void VisibleUpdate (void)
float angle_diff;
float target_x, target_z;
LIMIT_INTERVAL (50);
LIMIT_INTERVAL (10);
//Clear the visibility table
ZeroMemory (vis_grid, sizeof (vis_grid));
//Calculate which cell the camera is in

18
Win.cpp
View File

@ -56,11 +56,12 @@ static POINT mouse_pos;
static bool quit;
static HINSTANCE instance;
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
void CenterCursor ()
static void CenterCursor ()
{
int center_x;
@ -80,7 +81,7 @@ void CenterCursor ()
-----------------------------------------------------------------------------*/
void MoveCursor (int x, int y)
static void MoveCursor (int x, int y)
{
int center_x;
@ -230,17 +231,6 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
HINSTANCE WinInstance ()
{
return instance;
}
/*-----------------------------------------------------------------------------
n o t e
-----------------------------------------------------------------------------*/
@ -369,8 +359,6 @@ bool WinInit (void)
}
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/

44
Win.h
View File

@ -1,7 +1,43 @@
#define APP_TITLE "PixelCity"
#define APP "pixelcity"
#define SCREENSAVER 0
//Versioning info
#define APP_TITLE "PixelCity"
#define APP "pixelcity"
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_REVISION 5
//Best to disable screensaver mode when working on the program.
#define SCREENSAVER 1
//Controls the density of cars.
#define CARS 500
//The "dead zone" along the edge of the world, with super-low detail.
#define WORLD_EDGE 200
//How often to rebuild the city
#define RESET_INTERVAL (SCREENSAVER ? 120 : 999)//seconds
//How long the screen fade takes when transitioning to a new city
#define FADE_TIME (SCREENSAVER ? 1500 : 1) //milliseconds
//Debug ground texture that shows traffic lanes
#define SHOW_DEBUG_GROUND 0
//Controls the ammount of space available for buildings.
//Other code is wrtten assuming this will be a power of two.
#define WORLD_SIZE 1024
#define WORLD_HALF (WORLD_SIZE / 2)
//Bitflags used to track how world space is being used.
#define CLAIM_ROAD 1
#define CLAIM_WALK 2
#define CLAIM_BUILDING 4
#define MAP_ROAD_NORTH 8
#define MAP_ROAD_SOUTH 16
#define MAP_ROAD_EAST 32
#define MAP_ROAD_WEST 64
//Random SATURATED color
#define RANDOM_COLOR (glRgbaFromHsl ((float)RandomVal (255)/255,1.0f, 0.75f))
//Used in orienting roads and cars
enum
{
NORTH,
EAST,
SOUTH,
WEST
};
HWND WinHwnd (void);
void WinPopup (char* message, ...);

View File

@ -14,15 +14,6 @@
#define HUE_COUNT (sizeof(hue_list)/sizeof(float))
#define LIGHT_COLOR_COUNT (sizeof(light_colors)/sizeof(HSL))
#define CARS 600
#define WORLD_EDGE 200
#if SCREENSAVER
#define RESET_INTERVAL 120 //seconds
#define FADE_TIME 500 //milliseconds
#else
#define RESET_INTERVAL 999 //seconds
#define FADE_TIME 1500 //milliseconds
#endif
#include <windows.h>
#include <gl\gl.h>
@ -45,6 +36,7 @@
#include "sky.h"
#include "texture.h"
#include "visible.h"
#include "win.h"
#include "world.h"
struct plot
@ -400,7 +392,7 @@ static void do_reset (void)
GLrgba building_color;
float west_street, north_street, east_street, south_street;
//Re-init Random to make the same city each time. Good for debugging.
//Re-init Random to make the same city each time. Helpful when running tests.
//RandomInit (6);
reset_needed = false;
broadway_done = false;
@ -643,9 +635,9 @@ void WorldReset (void)
void WorldRender ()
{
//Cheap - render the crappy one-texture streets
if (!SHOW_DEBUG_GROUND)
return;
//Render a single texture over the city that shows traffic lanes
glDepthMask (false);
glDisable (GL_CULL_FACE);
glDisable (GL_BLEND);
@ -660,6 +652,7 @@ void WorldRender ()
glEnd ();
glDepthMask (true);
}

21
World.h
View File

@ -1,24 +1,3 @@
#define SHOW_DEBUG_GROUND 0
#define WORLD_SIZE 1024
#define WORLD_HALF (WORLD_SIZE / 2)
#define CLAIM_ROAD 1
#define CLAIM_WALK 2
#define CLAIM_BUILDING 4
#define MAP_ROAD_NORTH 8
#define MAP_ROAD_SOUTH 16
#define MAP_ROAD_EAST 32
#define MAP_ROAD_WEST 64
#define RANDOM_COLOR (glRgbaFromHsl ((float)RandomVal (255)/255,1.0f, 0.75f))
enum
{
NORTH,
EAST,
SOUTH,
WEST
};
GLrgba WorldBloomColor ();
char WorldCell (int x, int y);