From d2e952fb8898163e75967d08d9d69c2f615ca17e Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 26 Feb 2013 15:47:56 +0000 Subject: [PATCH] [Change] Just some C correctiveness. --- src/ai.h | 8 ++++---- src/colour.h | 2 +- src/faction.c | 2 +- src/faction.h | 6 +++--- src/font.h | 3 ++- src/input.c | 2 +- src/music.c | 2 +- src/opengl.h | 4 ++-- src/outfit.h | 4 ++-- src/pack.h | 2 +- src/physics.h | 10 ++++------ src/pilot.h | 14 +++++++------- src/player.c | 8 ++++---- src/player.h | 2 +- src/ship.h | 8 ++++---- src/sound.c | 2 +- src/sound.h | 2 +- src/space.c | 2 +- src/space.h | 8 ++++---- src/toolkit.c | 8 ++++---- src/weapon.c | 6 +++--- 21 files changed, 52 insertions(+), 53 deletions(-) diff --git a/src/ai.h b/src/ai.h index 1e70c68..79aee65 100644 --- a/src/ai.h +++ b/src/ai.h @@ -9,11 +9,11 @@ // Max number of AI timers. #define MAX_AI_TIMERS 2 -typedef enum { TYPE_NULL, TYPE_INT, TYPE_PTR } TaskData; +typedef enum TaskData_ { TYPE_NULL, TYPE_INT, TYPE_PTR } TaskData; // Basic task. -typedef struct Task { - struct Task* next; +typedef struct Task_ { + struct Task_* next; char* name; TaskData dtype; @@ -24,7 +24,7 @@ typedef struct Task { } Task; // Ai profile. -typedef struct { +typedef struct AI_Profile_ { char* name; lua_State* L; } AI_Profile; diff --git a/src/colour.h b/src/colour.h index b9f3792..5524795 100644 --- a/src/colour.h +++ b/src/colour.h @@ -1,7 +1,7 @@ #pragma once // Colours. -typedef struct { +typedef struct glColour_ { double r, g, b, a; } glColour; diff --git a/src/faction.c b/src/faction.c index 754a4a1..8168352 100644 --- a/src/faction.c +++ b/src/faction.c @@ -20,7 +20,7 @@ Faction* faction_stack = NULL; int nfactions = 0; // Save alliance. -typedef struct { +typedef struct Alliance_ { char* name; Faction** factions; int nfactions; diff --git a/src/faction.h b/src/faction.h index c239fb9..a55f8d0 100644 --- a/src/faction.h +++ b/src/faction.h @@ -1,11 +1,11 @@ #pragma once -typedef struct Faction { +typedef struct Faction_ { char* name; - struct Faction** enemies; + struct Factiona_** enemies; int nenemies; - struct Faction** allies; + struct Faction_** allies; int nallies; } Faction; diff --git a/src/font.h b/src/font.h index 4b8ece5..514c56b 100644 --- a/src/font.h +++ b/src/font.h @@ -2,12 +2,13 @@ #include "opengl.h" // Font info. -typedef struct { +typedef struct glFont_ { int h; // Height. int* w; GLuint* textures; GLuint list_base; } glFont; + extern glFont gl_defFont; // Default font. extern glFont gl_smallFont; // Small font. diff --git a/src/input.c b/src/input.c index aadac5e..8ca8f00 100644 --- a/src/input.c +++ b/src/input.c @@ -10,7 +10,7 @@ #define KEY_RELEASE (-1.) // Keybind structure. -typedef struct { +typedef struct Keybind_ { char* name; // Keybinding name, taken from keybindNames[] KeybindType type; // type, defined in player.h. unsigned int key; // Key/axis/button event number. diff --git a/src/music.c b/src/music.c index c07727e..89d14c2 100644 --- a/src/music.c +++ b/src/music.c @@ -24,7 +24,7 @@ extern SDL_mutex* sound_lock; // Saves the music to ram in this structure. -typedef struct { +typedef struct alMusic_ { char name[32]; // Name. Packfile file; OggVorbis_File stream; diff --git a/src/opengl.h b/src/opengl.h index d846e27..fe1d931 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -25,7 +25,7 @@ #define OPENGL_AA_LINE (1<<3) #define OPENGL_AA_POLYGON (1<<4) #define gl_has(f) (gl_screen.flags & (f)) // Check for the flag. -typedef struct { +typedef struct glInfo_ { int w, h; // Window dimensions. int depth; // Depth in bpp. int r, g, b, a; // Framebuffer values in bits. @@ -36,7 +36,7 @@ extern glInfo gl_screen; // Local structure set with gl_init etc. #define COLOUR(x) glColor4d((x).r, (x).g, (x).b, (x).a) // Spritesheet info. -typedef struct { +typedef struct glTexture_ { double w, h; // Real size of the image (excluding POT buffer. double rw, rh; // Size of POT surface. double sx, sy; // Number of sprites on x and y axes. diff --git a/src/outfit.h b/src/outfit.h index 99921de..7649e36 100644 --- a/src/outfit.h +++ b/src/outfit.h @@ -7,7 +7,7 @@ #define OUTFIT_PROP_WEAP_SECONDARY (1<<0) // Outfit types. -typedef enum { +typedef enum OutfitType_ { OUTFIT_TYPE_NULL = 0, OUTFIT_TYPE_BOLT = 1, OUTFIT_TYPE_BEAM = 2, @@ -24,7 +24,7 @@ typedef enum { } OutfitType; // An outfit depends a lot on the type. -typedef struct { +typedef struct Outfit_ { char* name; // General specs. diff --git a/src/pack.h b/src/pack.h index 111b815..bdfd436 100644 --- a/src/pack.h +++ b/src/pack.h @@ -5,7 +5,7 @@ #endif #include -typedef struct { +typedef struct Packfile_ { #ifdef _POSIX_SOURCE int fd; // File descriptor. #else diff --git a/src/physics.h b/src/physics.h index 5ba2cb9..c36f6d3 100644 --- a/src/physics.h +++ b/src/physics.h @@ -17,7 +17,7 @@ double angle_diff(const double ref, double a); // Base of 2D vectors. -typedef struct { +typedef struct Vec2_ { double x, y; // Cartesian values. double mod, angle; // Polar values. } Vec2; @@ -33,13 +33,11 @@ double vect_angle(const Vec2* ref, const Vec2* v); void vect_cadd(Vec2* v, const double x, const double y); // Describe any solid in 2D space. -struct Solid { +typedef struct Solid_ { double mass, dir, dir_vel; // Properties. Vec2 vel, pos, force; // Position/velocity vectors. - void(*update)(struct Solid*, const double); // Update method. -}; - -typedef struct Solid Solid; + void(*update)(struct Solid_*, const double); // Update method. +} Solid; // Solid manipulation. void solid_init(Solid* dest, const double mass, const double dir, diff --git a/src/pilot.h b/src/pilot.h index 4ebd010..155659d 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -36,14 +36,14 @@ #define pilot_isPlayer(p) ((p)->flags & PILOT_PLAYER) #define pilot_isDisabled(p) ((p)->flags & PILOT_DISABLED) -typedef struct { +typedef struct PilotOutfit_ { Outfit* outfit; // Associated outfit. unsigned int quantity; // Number of outfits of this type that the pilot has. unsigned int timer; // Used to store last used weapon time. } PilotOutfit; // Primary pilot structure. -typedef struct Pilot { +typedef struct Pilot_ { unsigned int id; // Pilots id. char* name; // Pilot's name (if unique). @@ -58,9 +58,9 @@ typedef struct Pilot { double armour_max, shield_max, energy_max; double fuel; // Used only for jumps. TODO: make it do something. - void (*think)(struct Pilot*); // AI thinking for the pilot. - void (*update)(struct Pilot*, const double); // Update the pilot. - void (*render)(struct Pilot*); // Rendering the pilot. + void (*think)(struct Pilot_*); // AI thinking for the pilot. + void (*update)(struct Pilot_*, const double); // Update the pilot. + void (*render)(struct Pilot_*); // Rendering the pilot. // Outfit management. PilotOutfit* outfits; @@ -80,13 +80,13 @@ typedef struct Pilot { } Pilot; // Fleets. -typedef struct { +typedef struct FleetPilot_ { Ship* ship; // Ship that the pilot is flying. char* name; // For special 'unique' names. int chance; // Chance of this pilot appearing in the fleet. } FleetPilot; -typedef struct { +typedef struct Fleet_ { char* name; // Fleet name, used as an identifier. Faction* faction; // Faction of the fleet. diff --git a/src/player.c b/src/player.c index 780eb7b..19e29ee 100644 --- a/src/player.c +++ b/src/player.c @@ -53,7 +53,7 @@ extern int pilots; extern StarSystem* systems; // GUI crap. -typedef struct { +typedef struct Radar_ { double x,y; // Position. double w,h; // Dimensions. RadarShape shape; @@ -66,12 +66,12 @@ typedef struct { #define RADAR_RES_INTERVAL 10. #define RADAR_RES_DEFAULT 40. -typedef struct { +typedef struct Rect_ { double x,y; double w,h; } Rect; -typedef struct { +typedef struct GUI_ { // Graphics. glTexture* gfx_frame; glTexture* gfx_targetPilot, *gfx_targetPlanet; @@ -98,7 +98,7 @@ double gui_yoff = 0.; #define MSG_SIZE_MAX 80 int msg_timeout = 5000; int msg_max = 5; // Max messages on screen. -typedef struct { +typedef struct Msg_ { char str[MSG_SIZE_MAX]; unsigned int t; } Msg; diff --git a/src/player.h b/src/player.h index 6a4269f..10f927f 100644 --- a/src/player.h +++ b/src/player.h @@ -21,7 +21,7 @@ extern unsigned int player_flags; extern unsigned int credits; extern unsigned int combat_rating; -typedef enum { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions. +typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions. // Creation. void player_new(void); diff --git a/src/ship.h b/src/ship.h index 7b7a377..8c71d22 100644 --- a/src/ship.h +++ b/src/ship.h @@ -7,7 +7,7 @@ #define SHIP_TARGET_W 128 #define SHIP_TARGET_H 96 -typedef enum { +typedef enum ShipClass_ { SHIP_CLASS_NULL = 0, SHIP_CLASS_CIV_LIGHT = 1, SHIP_CLASS_CIV_MEDIUM = 2, @@ -15,15 +15,15 @@ typedef enum { } ShipClass; // Small wrapper for the outfits. -typedef struct ShipOutfit { - struct ShipOutfit* next; // Linked list. +typedef struct ShipOutfit_ { + struct ShipOutfit_* next; // Linked list. Outfit* data; // Data itself. int quantity; } ShipOutfit; // Ship structure. -typedef struct { +typedef struct Ship_ { char* name; // Ship name. ShipClass class; // Ship class. diff --git a/src/sound.c b/src/sound.c index 575bb52..5ccbffb 100644 --- a/src/sound.c +++ b/src/sound.c @@ -22,7 +22,7 @@ #define SOUND_SUFFIX ".wav" // Give the buffers a name. -typedef struct { +typedef struct alSound_ { char* name; // Buffers name. ALuint buffer; // Associated OpenAL buffer. } alSound; diff --git a/src/sound.h b/src/sound.h index a83a73e..bb1eb1c 100644 --- a/src/sound.h +++ b/src/sound.h @@ -6,7 +6,7 @@ #define SOUND_MAX_DIST 1000. // Virtual voice. -typedef struct { +typedef struct alVoice_ { ALuint source; // Source itself, 0 if not set. ALuint buffer; // Buffer. diff --git a/src/space.c b/src/space.c index 63319c5..063f229 100644 --- a/src/space.c +++ b/src/space.c @@ -44,7 +44,7 @@ char* stardate = "Stardate"; unsigned int date = 0; // time since epoch. #define STAR_BUF 100 // Area to leave around screen, more = less repitition. -typedef struct { +typedef struct Star_ { double x, y; // Position. It is simpler ligher to use two doubles than the physics. double brightness; } Star; diff --git a/src/space.h b/src/space.h index 9c0380e..cf5908b 100644 --- a/src/space.h +++ b/src/space.h @@ -7,7 +7,7 @@ #define MAX_HYPERSPACE_VEL 25 // Planet types. I didn't take them from Star Trek, I promise. -typedef enum { +typedef enum PlanetClass_ { PLANET_CLASS_NULL = 0, PLANET_CLASS_A, // Geothermal. PLANET_CLASS_B, // Geomorteus. @@ -41,7 +41,7 @@ typedef enum { #define PLANET_SERVICE_SHIPYARD (1<<3) #define planet_hasService(p,s) ((p)->services & s) -typedef struct { +typedef struct Planet_ { char* name; // Planet name Vec2 pos; // Position in star system. @@ -56,12 +56,12 @@ typedef struct { } Planet; // Star systems. -typedef struct { +typedef struct SystemFleet_ { Fleet* fleet; // Fleet to appear. int chance; // Chance of fleet appearing in the system. } SystemFleet; -typedef struct { +typedef struct StarSystem_ { char* name; // Star system identifier. Vec2 pos; // Position. int stars, asteroids; // Un numero! diff --git a/src/toolkit.c b/src/toolkit.c index 345bd98..b3921a8 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -3,7 +3,7 @@ #include "opengl.h" #include "toolkit.h" -typedef enum { +typedef enum WidgetType_ { WIDGET_NULL, WIDGET_BUTTON, WIDGET_TEXT, @@ -11,13 +11,13 @@ typedef enum { WIDGET_LIST } WidgetType; -typedef enum { +typedef enum WidgetStatus_ { WIDGET_STATUS_NORMAL, WIDGET_STATUS_MOUSEOVER, WIDGET_STATUS_MOUSEDOWN, } WidgetStatus; -typedef struct { +typedef struct Widget_ { char* name; // Widget name. WidgetType type; // type.. @@ -52,7 +52,7 @@ typedef struct { }; } Widget; -typedef struct { +typedef struct Window_ { unsigned int id; // Unique identifier. char* name; diff --git a/src/weapon.c b/src/weapon.c index 69b08b4..4f5c116 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -24,7 +24,7 @@ extern int pilots; // Ai stuff. extern void ai_attacked(Pilot* attacked, const unsigned int attacker); -typedef struct Weapon { +typedef struct Weapon_ { Solid* solid; // Actually has its own solid. :D unsigned int parent; // The pilot that just shot at you! @@ -35,8 +35,8 @@ typedef struct Weapon { alVoice* voice; // Virtual voise. // Update position and render. - void(*update)(struct Weapon*, const double, WeaponLayer); // Position update and render. - void(*think)(struct Weapon*); // Some missiles need to be inteligent. + void(*update)(struct Weapon_*, const double, WeaponLayer); // Position update and render. + void(*think)(struct Weapon_*); // Some missiles need to be inteligent. } Weapon; // Behind Pilot layer.