diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Decals.cpp | 3 | ||||
-rw-r--r-- | src/Decals.h | 5 | ||||
-rw-r--r-- | src/Files.cpp | 159 | ||||
-rw-r--r-- | src/Files.h | 37 | ||||
-rw-r--r-- | src/Game.h | 6 | ||||
-rw-r--r-- | src/GameDraw.cpp | 1 | ||||
-rw-r--r-- | src/GameInitDispose.cpp | 16 | ||||
-rw-r--r-- | src/GameLoop.cpp | 3 | ||||
-rw-r--r-- | src/GameTick.cpp | 18 | ||||
-rw-r--r-- | src/Models.cpp | 20 | ||||
-rw-r--r-- | src/Models.h | 2 | ||||
-rw-r--r-- | src/Person.cpp | 7 | ||||
-rw-r--r-- | src/Serialize.cpp | 104 | ||||
-rw-r--r-- | src/Serialize.h | 13 | ||||
-rw-r--r-- | src/Skeleton.cpp | 4 | ||||
-rw-r--r-- | src/Skeleton.h | 5 | ||||
-rw-r--r-- | src/Sprites.cpp | 4 | ||||
-rw-r--r-- | src/Sprites.h | 7 | ||||
-rw-r--r-- | src/Support.cpp | 169 | ||||
-rw-r--r-- | src/Text.cpp | 3 | ||||
-rw-r--r-- | src/Text.h | 1 | ||||
-rw-r--r-- | src/misc.zig | 38 |
22 files changed, 65 insertions, 560 deletions
diff --git a/src/Decals.cpp b/src/Decals.cpp index 60014b3..74fe379 100644 --- a/src/Decals.cpp +++ b/src/Decals.cpp @@ -1,4 +1,7 @@ +#include "Camera.h" +#include "Constants.h" #include "Decals.h" +#include "Fog.h" extern float multiplier; extern bool slomo; diff --git a/src/Decals.h b/src/Decals.h index c4e3a5a..f37f523 100644 --- a/src/Decals.h +++ b/src/Decals.h @@ -22,11 +22,8 @@ #ifndef BLACKSHADES_DECALS_H #define BLACKSHADES_DECALS_H -#include "Files.h" -#include "Quaternions.h" -#include "Camera.h" #include "Models.h" -#include "Fog.h" +#include "Quaternions.h" #define maxdecals 120 diff --git a/src/Files.cpp b/src/Files.cpp deleted file mode 100644 index 84da8d4..0000000 --- a/src/Files.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "Files.h" - -short Files::OpenFile(Str255 Name) -{ - short volume; - char filename[33]; - short tFile; - tFile=-1; - Point ptOrigin = { 0, 0 }; - volume = 0; - sprintf (filename, "%s", Name); - SetVol( nil, volume ); - CtoPstr( filename ); - FSOpen( (Pstr) filename, volume,&tFile ); - PtoCstr( (Pstr) filename ); - sFile=tFile; - return( tFile ); -} - -short Files::OpenNewFile( SFReply *psfReply, - OSType osTypeCreator, - OSType osTypeType ) -{ - sFile = 0; - OSErr osErr; - - SetVol( nil, psfReply->vRefNum ); - osErr = Create( psfReply->fName, psfReply->vRefNum, osTypeCreator, osTypeType ); - - if ( osErr == dupFNErr ) - { - FSDelete( psfReply->fName, psfReply->vRefNum ); - Create( psfReply->fName, psfReply->vRefNum, osTypeCreator, osTypeType ); - } - - FSOpen( psfReply->fName, psfReply->vRefNum, &sFile ); - - return( sFile ); -} - -short Files::PromptForSaveAS( short sPromptID, - short sNameID, - Str255 str255NamePrompt, - OSType osTypeCreator, - OSType osTypeType, - SFReply *psfReply ) -{ - Str255 str255Prompt; - Str255 str255Name; - sFile = 0; - Point ptOrigin = { 0, 0 }; - - GetIndString( str255Prompt, FILE_STRINGS, sPromptID ); - - if ( !str255NamePrompt ) - GetIndString( str255Name, FILE_STRINGS, sNameID ); - - else - memcpy( str255Name, str255NamePrompt, *str255NamePrompt + 1 ); - - SFPutFile( ptOrigin, str255Prompt, str255Name, nil, psfReply ); - - if ( psfReply->good ) - { - sFile = OpenNewFile( psfReply, osTypeCreator, osTypeType ); - } - - return( sFile ); -} - -short Files::OpenSavedGame(Str255 Name) -{ - Point ptOrigin = { 0, 0 }; - sSavedGameVolume = 0; - sprintf (szSavedGameName, "%s", Name); - SetVol( nil, sSavedGameVolume ); - CtoPstr( szSavedGameName ); - FSOpen( (Pstr) szSavedGameName, sSavedGameVolume,&sFile ); - PtoCstr( (Pstr) szSavedGameName ); - return( sFile ); -} - -short Files::OpenFileDialog() -{ - Point ptOrigin = { 0, 0 }; - sFile = 0; - SFReply sfReply; - SFTypeList sfTypeList = { 'DMAP', '\p', '\p', '\p' }; - SFGetFile( ptOrigin, "\p", nil, 1, sfTypeList, nil, &sfReply ); - - if ( sfReply.good ) - { - PtoCstr( sfReply.fName ); - strcpy( szSavedGameName, (Cstr) sfReply.fName ); - } - - if ( sfReply.good ) - { - sSavedGameVolume = sfReply.vRefNum; - SetVol( nil, sSavedGameVolume ); - - CtoPstr( szSavedGameName ); - - FSOpen( (Pstr) szSavedGameName, sSavedGameVolume,&sFile ); - - PtoCstr( (Pstr) szSavedGameName ); - } - - return( sFile ); -} - -void Files::StartSave() -{ - int x,y; - SFReply sfReply; - sFile = 0; - long lSize; - long lLongSize = sizeof( long ); - - CtoPstr( szSavedGameName ); - - sFile = PromptForSaveAS( SAVE_GAME_STRING, 0, (Pstr)szSavedGameName,'DAVD', 'DMAP', &sfReply ); - - PtoCstr((Pstr) szSavedGameName ); - - if ( sFile ) - { - sSavedGameVolume = sfReply.vRefNum; - PtoCstr( sfReply.fName ); - strcpy( szSavedGameName, (Cstr)sfReply.fName ); - } - - else - { - sfReply.vRefNum = sSavedGameVolume; - strcpy( (Cstr) sfReply.fName, szSavedGameName ); - CtoPstr( (Cstr)sfReply.fName ); - - sFile = OpenNewFile( &sfReply, 'GLF2', 'SKLT' ); - } - -} - -void Files::EndSave() -{ - int x,y; - SFReply sfReply; - long lSize; - long lLongSize = sizeof( long ); - - if ( sFile ) - FSClose( sFile ); -} - -void Files::EndLoad() -{ - if (sFile) - FSClose( sFile ); -} diff --git a/src/Files.h b/src/Files.h deleted file mode 100644 index c8dbb8e..0000000 --- a/src/Files.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _FILES_H_ -#define _FILES_H_ - -#include <iostream> -#include <fstream> - -#include "Support.h" - -#define FILE_STRINGS 130 -#define Pstr unsigned char * -#define Cstr char * - -#define FILE_NAME_SIZE 32 - -/**> Files Opening <**/ -class Files -{ - public: - char szSavedGameName[FILE_NAME_SIZE + 1]; - short sSavedGameVolume; - int sFile; - - int OpenFile(Str255 Name); - Files() : sFile(-1) { } - short OpenSavedGame(Str255 Name); - short OpenFileDialog(); - void LoadNamedMap(Str255 Name); - void LoadGame(Str255 Name, int animnum); - - void LoadMap(); - void StartSave(); - void EndSave(); - void StartLoad(); - void EndLoad(); -}; - -#endif diff --git a/src/Game.h b/src/Game.h index 81bba21..39fdcbc 100644 --- a/src/Game.h +++ b/src/Game.h @@ -27,19 +27,18 @@ #include "config.h" #ifdef __cplusplus -#include <GL/gl.h> -#include <GL/glu.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <cstdarg> + #include <AL/al.h> +#include <GL/gl.h> #include "Quaternions.h" #include "Camera.h" #include "Skeleton.h" -#include "Files.h" #include "Models.h" #include "Text.h" #include "Fog.h" @@ -101,7 +100,6 @@ public: Model path; Model blocksimple; XYZ boundingpoints[8]; - Files files; Text text; int goodkills; int badkills; diff --git a/src/GameDraw.cpp b/src/GameDraw.cpp index abb0919..5403d3f 100644 --- a/src/GameDraw.cpp +++ b/src/GameDraw.cpp @@ -20,6 +20,7 @@ // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. #include "Game.h" +#include "Support.h" extern int thirdperson; extern float multiplier; diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index 8c9ea72..bd8a05f 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -20,11 +20,17 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. +#include <fstream> + +#include <time.h> + #include <AL/alc.h> +#include <GL/glu.h> #include "config.h" #include "misc.h" #include "Game.h" +#include "Support.h" extern unsigned int gSourceID[37]; extern unsigned int gSampleSet[37]; @@ -88,11 +94,11 @@ Game* makeGame(Config config) game->debug = config.debug; // TODO: Read high score - ifstream ipstream2 {"highscore.txt"}; + std::ifstream ipstream2 {"highscore.txt"}; if (!ipstream2) { - ofstream opstream("highscore.txt"); - opstream << (game->highscore = 0) << endl; - opstream << (game->beatgame = 0) << endl; + std::ofstream opstream("highscore.txt"); + opstream << (game->highscore = 0) << std::endl; + opstream << (game->beatgame = 0) << std::endl; opstream.close(); } else { ipstream2 >> game->highscore; @@ -250,7 +256,7 @@ void initGame(Game* game) game->timeremaining = 50; game->difficulty= 0.8f; - ifstream ipstream {"data/customlevels.txt"}; + std::ifstream ipstream {"data/customlevels.txt"}; if (ipstream) { ipstream.ignore(256,'\n');//ignore descriptive text ipstream >> game->nummissions; diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index e89eb2e..2cd0c5c 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -19,8 +19,9 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. -#include "Game.h" #include "misc.h" +#include "Game.h" +#include "Support.h" extern float multiplier; extern int thirdperson; diff --git a/src/GameTick.cpp b/src/GameTick.cpp index 4e75895..fd9dad5 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -21,9 +21,13 @@ // // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. +// +#include <algorithm> +#include <fstream> -#include "Game.h" #include "misc.h" +#include "Game.h" +#include "Support.h" extern float multiplier; extern int thirdperson; @@ -90,7 +94,7 @@ void Game::saveHighScore() if (score > highscore) { highscore = score; /* TODO */ - ofstream opstream("highscore.txt"); + std::ofstream opstream("highscore.txt"); opstream << highscore; opstream << "\n"; opstream << beatgame; @@ -341,7 +345,7 @@ void look(Game* game, double xpos, double ypos) player.playerrotation = 180 - camera.rotation; camera.rotation2 = camera.rotation2 * 0.7 + camera.oldrotation2 * 0.3; - camera.rotation2 = min(max(camera.rotation2, -89.0f), 89.0f); + camera.rotation2 = std::min(std::max(camera.rotation2, -89.0f), 89.0f); camera.oldrotation2 = camera.rotation2; if (game->zoom || visions || player.aimamount <= 0 @@ -351,10 +355,10 @@ void look(Game* game, double xpos, double ypos) camera.visrotation = camera.rotation; camera.visrotation2 = camera.rotation2; } else { - camera.visrotation = min(camera.rotation + 7, - max(camera.rotation - 7, camera.visrotation)); - camera.visrotation2 = min(camera.rotation2 + 15, - max(camera.rotation2 - 15, camera.visrotation2)); + camera.visrotation = std::min(camera.rotation + 7, + std::max(camera.rotation - 7, camera.visrotation)); + camera.visrotation2 = std::min(camera.rotation2 + 15, + std::max(camera.rotation2 - 15, camera.visrotation2)); } } diff --git a/src/Models.cpp b/src/Models.cpp index 6d8eecf..8f3dc37 100644 --- a/src/Models.cpp +++ b/src/Models.cpp @@ -1,3 +1,5 @@ +#include <algorithm> + #include "Models.h" #include "misc.h" @@ -90,28 +92,12 @@ void Model::load(const char* path) boundingsphereradius = 0; for (auto&& v : vertex) - boundingsphereradius = max(boundingsphereradius, + boundingsphereradius = std::max(boundingsphereradius, findDistancefast(average, v)); boundingsphereradius = sqrt(boundingsphereradius); CalculateNormals(); } -void Model::save(const char* path) -{ - auto f = fopen(path, "w"); - fprintf(f, "%d %d 0\n", vertexNum, TriangleNum); - for (int i = 0; i < vertexNum; ++i) - fprintf(f, "%.3f %.3f %.3f\n", - vertex[i].x, vertex[i].y, vertex[i].z); - for (int i = 0; i < TriangleNum; ++i) - fprintf(f, "3 %d %d %d %.3f %.3f %.3f\n", - Triangles[i].vertex[0], - Triangles[i].vertex[1], - Triangles[i].vertex[2], - Triangles[i].r, Triangles[i].g, Triangles[i].b); - fclose(f); -} - void Model::Scale(float xscale,float yscale,float zscale) { int i; diff --git a/src/Models.h b/src/Models.h index 2e37a9b..5cbc53c 100644 --- a/src/Models.h +++ b/src/Models.h @@ -6,10 +6,8 @@ // Model Maximums // #include <GL/gl.h> -#include <GL/glu.h> #include "Quaternions.h" -#include "Files.h" #include "Constants.h" #define max_textured_triangle 400 // maximum number of texture-filled triangles in a model diff --git a/src/Person.cpp b/src/Person.cpp index f5eb314..3789865 100644 --- a/src/Person.cpp +++ b/src/Person.cpp @@ -17,9 +17,12 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. +#include <algorithm> + #include <GLFW/glfw3.h> #include "Person.h" +#include "Support.h" #include "misc.h" extern float multiplier; @@ -62,7 +65,7 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){ float distancemax = 0.0f; for (auto& joint : skeleton.joints) - distancemax = max(distancemax, + distancemax = std::max(distancemax, findDistancefast(average, joint.position)); distancemax = sqrt(distancemax); @@ -615,7 +618,7 @@ void Person::DoAnimationslite(int who) * animation[targetanimation].speed[targetframe]; else target += speed * multiplier - * max(animation[currentanimation].speed[currentframe], + * std::max(animation[currentanimation].speed[currentframe], animation[targetanimation].speed[currentframe]); if ((currentanimation == crouchanim) ^ (targetanimation == crouchanim)) diff --git a/src/Serialize.cpp b/src/Serialize.cpp deleted file mode 100644 index c07a5db..0000000 --- a/src/Serialize.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include <unistd.h> - -#include "Models.h" -#include "Quaternions.h" -#include "Serialize.h" - -/* these all read big-endian data */ - -int ReadBool(int fd, int count, bool *b) -{ - while (count--) { - unsigned char buf[1]; - - if (read(fd, buf, 1) != 1) { - } - - *b = (buf[0] != 0) ? true : false; - - b++; - } - - return 1; -} - -int ReadShort(int fd, int count, short *s) -{ - while (count--) { - unsigned char buf[2]; - - if (read(fd, buf, 2) != 2) { - } - - *s = (short)((buf[0] << 8) | buf[1]); - - s++; - } - - return 1; -} - -int ReadInt(int fd, int count, int *s) -{ - while (count--) { - unsigned char buf[4]; - - if (read(fd, buf, 4) != 4) { - } - - *s = (int)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); - - s++; - } - - return 1; -} - -union intfloat { - int i; - float f; -} intfloat; - -int ReadFloat(int fd, int count, float *f) -{ - union intfloat infl; - - while (count--) { - ReadInt(fd, 1, &(infl.i)); - - *f = infl.f; - - f++; - } - - return 1; -} - -int ReadXYZ(int fd, int count, XYZ *xyz) -{ - while (count--) { - ReadFloat(fd, 1, &(xyz->x)); - ReadFloat(fd, 1, &(xyz->y)); - ReadFloat(fd, 1, &(xyz->z)); - - xyz++; - } - - return 1; -} - -int ReadTexturedTriangle(int fd, int count, TexturedTriangle *tt) -{ - while (count--) { - short pad; - ReadShort(fd, 3, tt->vertex); - ReadShort(fd, 1, &pad); /* crud */ - ReadFloat(fd, 1, &(tt->r)); - ReadFloat(fd, 1, &(tt->g)); - ReadFloat(fd, 1, &(tt->b)); - - tt++; - } - - return count; -} diff --git a/src/Serialize.h b/src/Serialize.h deleted file mode 100644 index 4ecb46d..0000000 --- a/src/Serialize.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef SERIALIZE_H -#define SERIALIZE_H - -/* these all read big-endian data */ - -int ReadBool(int fd, int count, bool *b); -int ReadShort(int fd, int count, short *s); -int ReadInt(int fd, int count, int *s); -int ReadFloat(int fd, int count, float *f); -int ReadXYZ(int fd, int count, XYZ *xyz); -int ReadTexturedTriangle(int fd, int count, TexturedTriangle *tt); - -#endif diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp index ba27aa4..6aa3508 100644 --- a/src/Skeleton.cpp +++ b/src/Skeleton.cpp @@ -1,6 +1,6 @@ /**> HEADER FILES <**/ +#include "Camera.h" #include "Skeleton.h" -#include "Serialize.h" #include "misc.h" extern float multiplier; @@ -133,7 +133,7 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) joints[i].velocity.z *= 0.3; } - offset = 0.2; + offset = true; if (whichtri != -1 && collide->normals[whichtri].y <= 0.8) { normalrotated = DoRotation(collide->normals[whichtri], 0, rotation, 0); diff --git a/src/Skeleton.h b/src/Skeleton.h index 31ece37..7687610 100644 --- a/src/Skeleton.h +++ b/src/Skeleton.h @@ -7,9 +7,7 @@ #include "Quaternions.h" #include "Constants.h" -#include "Files.h" #include "Models.h" -#include "Camera.h" #define boneconnect 0 #define constraint 1 @@ -84,7 +82,6 @@ class Muscle class Animation { public: - Files files; size_t numframes; bool canbeoverridden; bool ismodified[max_joints][max_frames]; @@ -123,8 +120,6 @@ class Skeleton bool free; - Files files; - void DoConstraints(); void DoConstraints(Model *collide, XYZ *move, float rotation); void DoGravity(); diff --git a/src/Sprites.cpp b/src/Sprites.cpp index 574bc0e..fa43ae8 100644 --- a/src/Sprites.cpp +++ b/src/Sprites.cpp @@ -1,4 +1,8 @@ +#include "Camera.h" +#include "Fog.h" +#include "Models.h" #include "Sprites.h" +#include "Support.h" extern float multiplier; extern bool slomo; diff --git a/src/Sprites.h b/src/Sprites.h index 734c71c..28a7958 100644 --- a/src/Sprites.h +++ b/src/Sprites.h @@ -1,4 +1,4 @@ -// Model structure +// Sprites // Copyright (C) 2002 David Rosen // Copyright (C) 2003 Steven Fuller // Copyright (C) 2003 Zachary Jack Slater @@ -23,13 +23,8 @@ #define BLACKSHADES_SPRITES_H #include <GL/gl.h> -#include <GL/glu.h> -#include "Files.h" #include "Quaternions.h" -#include "Camera.h" -#include "Models.h" -#include "Fog.h" #define maxsprites 2000 diff --git a/src/Support.cpp b/src/Support.cpp index 2b033f5..850d0bb 100644 --- a/src/Support.cpp +++ b/src/Support.cpp @@ -1,18 +1,13 @@ -#include <dirent.h> -#include <fcntl.h> +#include <stdbool.h> +#include <stdlib.h> #include <GLFW/glfw3.h> #include "Support.h" -#include "Files.h" int Random() { -#if RAND_MAX >= 65535 return (rand() % 65535) - 32767; -#else -#error please fix this for your platform -#endif } bool IsKeyDown(int key) @@ -20,163 +15,3 @@ bool IsKeyDown(int key) const auto window = glfwGetCurrentContext(); return glfwGetKey(window, key) == GLFW_PRESS; } - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -#ifndef MAX_PATH -#define MAX_PATH 256 -#endif - -static int find_filename(char *filename) -{ - char *ptr; - char *cur; - char *next; - DIR *dir; - struct dirent *dirent; - - if (access(filename, R_OK) == 0) { - return 1; - } - - ptr = filename; - - while (*ptr) { - if (ptr == filename || *ptr == '/') { - if (*ptr == '/') { - cur = ptr+1; - } else { - cur = ptr; - } - - if (*cur == 0) { - /* hit the end */ - break; - } - - next = strchr(cur, '/'); - - if (ptr != filename) { - *ptr = 0; - } - - if (next) { - *next = 0; - } - - if (ptr == filename && *ptr == '/') { - dir = opendir("/"); - } else { - dir = opendir(filename); - } - - if (dir == NULL) { - if (ptr != filename) { - *ptr = '/'; - } - - if (next) { - *next = 0; - } - - return 0; - } - - while ((dirent = readdir(dir)) != NULL) { - if (strcasecmp(cur, dirent->d_name) == 0) { - strcpy(cur, dirent->d_name); - break; - } - } - - closedir(dir); - - if (ptr != filename) { - *ptr = '/'; - } - - if (next) { - *next = '/'; - ptr = next; - } else { - ptr++; - } - } else { - ptr++; - } - } - - if (access(filename, R_OK) == 0) { - return 1; - } - - return 0; -} - -static void fix_filename(const char *original, char *fixed) -{ - const char *start; - int i; - int len; - - start = original; - if (original[0] == ':') { - start = &original[1]; - } - - fixed[MAX_PATH-1] = 0; - - strncpy(fixed, start, MAX_PATH); - - /* check to see if strncpy overwrote the terminator */ - if (fixed[MAX_PATH-1] != 0) { - fixed[MAX_PATH-1] = 0; - - fprintf(stderr, "ERROR: file truncation error: %s -> %s\n", - original, fixed); - } - - len = strlen(fixed); - for (i = 0; i < len; i++) { - if (fixed[i] == ':') { - fixed[i] = '/'; - } - } - - /* - here we would try to see if the file is available (game dir), - else try another dir - - really, this function also needs a flag to indicate whether - it should only go to local (write) or both (read) - */ - - if (find_filename(fixed) == 0) { - fprintf(stderr, "find failed: %s\n", fixed); - } -} - -/* -Convenient Filename Hacks -*/ - -int Files::OpenFile(Str255 Name) -{ - char filename1[MAX_PATH]; - - fix_filename((char *)Name, filename1); - - sFile = open(filename1, O_RDONLY | O_BINARY); - return sFile; -} - -void Files::EndLoad() -{ - if (sFile != -1) { - FSClose( sFile ); - } - - sFile = -1; -} diff --git a/src/Text.cpp b/src/Text.cpp index 1123bfd..afb6fe2 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1,4 +1,5 @@ -/**> HEADER FILES <**/ +#include <string.h> + #include "Text.h" void Text::BuildFont() // Build Our Font Display List diff --git a/src/Text.h b/src/Text.h index f284e43..6fa4e35 100644 --- a/src/Text.h +++ b/src/Text.h @@ -25,7 +25,6 @@ #include <GL/gl.h> #include <GL/glu.h> -#include "Files.h" #include "Quaternions.h" class Text{ diff --git a/src/misc.zig b/src/misc.zig index 7ff4680..fc428b2 100644 --- a/src/misc.zig +++ b/src/misc.zig @@ -75,32 +75,28 @@ export fn loadAnimation(name: [*:0]const u8) extern struct { }) catch unreachable; defer allocator.free(anim_file); const length = count(u8, anim_file, "\t") - 1; - const frames = allocator.alloc(Frame, length) catch unreachable; - var anim = tokenize(anim_file, "\n"); _ = anim.next().?; // ignore field names - var i = @as(usize, 0); - while (i < length) : (i += 1) { + + const frames = allocator.alloc(Frame, length) catch unreachable; + for (frames) |*frame| { var values = tokenize(anim.next().?, "\t"); const frame_file = readFile(dir, "{s}{c}frames{c}{s}.tsv", .{ name, sep, sep, values.next().?, // $animation/frames/$frame.tsv }) catch unreachable; defer allocator.free(frame_file); + frame.speed = parseFloat(f32, values.next().?) catch unreachable; - var frame = tokenize(frame_file, "\n"); - _ = frame.next().?; // ignore field names - var j = @as(usize, 0); - while (frame.next()) |position| { - var coordinates = tokenize(position, "\t"); - frames[i].joints[j].x = parseFloat(f32, coordinates.next().?) - catch unreachable; - frames[i].joints[j].y = parseFloat(f32, coordinates.next().?) - catch unreachable; - frames[i].joints[j].z = parseFloat(f32, coordinates.next().?) - catch unreachable; - j += 1; + var joints = tokenize(frame_file, "\n"); + _ = joints.next().?; // ignore field names + for (frame.joints) |*joint| { + var coordinates = tokenize(joints.next().?, "\t"); + joint.* = .{ + .x = parseFloat(f32, coordinates.next().?) catch unreachable, + .y = parseFloat(f32, coordinates.next().?) catch unreachable, + .z = parseFloat(f32, coordinates.next().?) catch unreachable, + }; } - frames[i].speed = parseFloat(f32, values.next().?) catch unreachable; } return .{ .ptr = frames.ptr, .len = frames.len }; } @@ -144,10 +140,8 @@ export fn loadJoints(joints: [*]Joint) void { var tsv = tokenize(@embedFile("joints.tsv"), "\n"); _ = tsv.next().?; // ignore field names var i = @as(u8, 0); - while (tsv.next()) |row| { + while (tsv.next()) |row| : (i += 1) joints[i].load(row) catch unreachable; - i += 1; - } } const Vertex = extern struct { @@ -265,10 +259,8 @@ export fn loadMuscles(muscles: [*]Muscle) void { var tsv = tokenize(@embedFile("muscles.tsv"), "\n"); _ = tsv.next().?; // ignore field names var i = @as(u8, 0); - while (tsv.next()) |row| { + while (tsv.next()) |row| : (i += 1) muscles[i].load(row) catch unreachable; - i += 1; - } } /// Load audio file into an OpenAL buffer and return it. |