Skip to content

Commit

Permalink
Not dead...
Browse files Browse the repository at this point in the history
Have you ever realized that you have done something incredibly stupid, not just once, but hundreds of times?  Yea, I just found out that "new" doesn't spit out NULL on failure, making hundreds of lines of CHKPTR useless.  You may see a considerable speedup from this code, because I removed all of the CHKPTR stuff.  I also changed the include directives to use quotation marks instead of less than or greater than signs.

I'll also partition main.cpp to more manageable chunks next revision.  In the past month I had started a code project for which I had to write my code in a certain way that I found to work very well, so I'll apply it to all the code, present and future.
  • Loading branch information
penguin673 committed Mar 1, 2009
1 parent 167c27d commit 95d0c86
Show file tree
Hide file tree
Showing 53 changed files with 367 additions and 384 deletions.
6 changes: 3 additions & 3 deletions echo_char_joints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_char_joints.h>
#include <echo_debug.h>
#include <echo_error.h>
#include "echo_char_joints.h"
#include "echo_debug.h"
#include "echo_error.h"

/** Set all joints to zero
* @param joints Joints to set to zero
Expand Down
2 changes: 1 addition & 1 deletion echo_char_joints.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_debug.h>
#include "echo_debug.h"

#ifndef __ECHO_CHAR_JOINTS__
#define __ECHO_CHAR_JOINTS__
Expand Down
32 changes: 16 additions & 16 deletions echo_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@

/** L-Echo libraries (not grids)
*/
#include <echo_platform.h>
#include <echo_sys.h>
#include <echo_gfx.h>
#include <echo_debug.h>
#include <echo_math.h>
#include <echo_ns.h>
#include <echo_character.h>
#include <echo_char_joints.h>
#include <echo_stage.h>
#include "echo_platform.h"
#include "echo_sys.h"
#include "echo_gfx.h"
#include "echo_debug.h"
#include "echo_math.h"
#include "echo_ns.h"
#include "echo_character.h"
#include "echo_char_joints.h"
#include "echo_stage.h"

/** Grids; just launchers and holes are discriminated against, because
* the character is responsible for flying and falling
*/
#include <launcher.h>
#include <grid.h>
#include <hole.h>
#include "launcher.h"
#include "grid.h"
#include "hole.h"

/// Need to measure the body sizes in order to do IK correctly
#include <gen/gen.h>
#include "gen/gen.h"

/// Convenience macro to draw at a particular vector3f
#define DRAW_VEC(vec) draw((vec)->x, (vec)->y, (vec)->z)
Expand Down Expand Up @@ -193,7 +193,7 @@ void echo_char::initialize_launching(vector3f* pos, vector3f* direction)
if(direction == NULL)
{
direction = new vector3f(fly_direction->x, fly_direction->y, fly_direction->z);
CHKPTR(direction);

}
/// Get the length of the direction...
const float dir_length = sqrt(direction->x * direction->x + direction->z * direction->z);
Expand Down Expand Up @@ -463,7 +463,7 @@ void echo_char::step()
vector3f* next_absolute_pos = new vector3f(absolute_pos->x,
absolute_pos->y + speed * WAIT / 1000,
absolute_pos->z);
CHKPTR(next_absolute_pos);


/// Checking for grids to fall on

Expand Down Expand Up @@ -527,7 +527,7 @@ void echo_char::step()
vector3f* next_absolute_pos = new vector3f(absolute_pos->x + x_speed * WAIT / 1000,
absolute_pos->y + speed * WAIT / 1000,
absolute_pos->z + z_speed * WAIT / 1000);
CHKPTR(next_absolute_pos);


grid* fall_grid = NULL;

Expand Down
8 changes: 4 additions & 4 deletions echo_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_math.h>
#include <grid.h>
#include <echo_stage.h>
#include <echo_char_joints.h>
#include "echo_math.h"
#include "grid.h"
#include "echo_stage.h"
#include "echo_char_joints.h"

#ifndef __ECHO_CHARACTER_SPEED__
#define __ECHO_CHARACTER_SPEED__
Expand Down
2 changes: 1 addition & 1 deletion echo_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_platform.h>
#include "echo_platform.h"

#ifdef DEBUG
#ifdef ECHO_NDS
Expand Down
4 changes: 2 additions & 2 deletions echo_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <cstdlib>

/// Needed for printing
#include <echo_debug.h>
#include <echo_error.h>
#include "echo_debug.h"
#include "echo_error.h"

/** Report an error while loading
* @param msg The error message
Expand Down
16 changes: 8 additions & 8 deletions echo_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_platform.h>
#include <echo_math.h>
#include <echo_debug.h>
#include <echo_char_joints.h>
#include <echo_error.h>
#include <echo_gfx.h>
#include <echo_math.h>
#include "echo_platform.h"
#include "echo_math.h"
#include "echo_debug.h"
#include "echo_char_joints.h"
#include "echo_error.h"
#include "echo_gfx.h"
#include "echo_math.h"

#include <cstdlib>
#include <iostream>
Expand All @@ -40,7 +40,7 @@
#include <GL/glut.h>
#endif

#include <grid.h>
#include "grid.h"

#ifdef ECHO_NDS
#define POP_MATRIX glPopMatrix(1)
Expand Down
6 changes: 3 additions & 3 deletions echo_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

/// Various L-Echo libraries
#include <echo_char_joints.h>
#include <echo_math.h>
#include <echo_platform.h>
#include "echo_char_joints.h"
#include "echo_math.h"
#include "echo_platform.h"

/// Need NDS library for the definition of v16
#ifdef ECHO_NDS
Expand Down
44 changes: 22 additions & 22 deletions echo_ingame_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

/// Various echo libraries
#include <echo_platform.h>
#include <echo_debug.h>
#include <echo_error.h>
#include <echo_stage.h>
#include <echo_loader.h>
#include <echo_ingame_loader.h>
#include "echo_platform.h"
#include "echo_debug.h"
#include "echo_error.h"
#include "echo_stage.h"
#include "echo_loader.h"
#include "echo_ingame_loader.h"

/// Standard libraries
#include <cstdlib>
Expand Down Expand Up @@ -64,7 +64,7 @@ STATUS echo_genroot(char** save)
if(save != NULL)
{
*save = new char[2];
CHKPTR(*save);

(*save)[0] = '/';
(*save)[1] = '\0';
return(WIN);
Expand Down Expand Up @@ -141,12 +141,12 @@ STATUS echo_prefsfile(char** save)
{
#ifdef ECHO_NDS
*save = new char[strlen("/apps/n-echo/prefs.xml") + 1];
CHKPTR(*save);

strcpy(*save, "/apps/n-echo/prefs.xml");
return(WIN);
#else
char** path = new(char*);
CHKPTR(path);

if(echo_execdir(path) == WIN)
{
*save = echo_merge(*path, "prefs.xml");
Expand All @@ -169,7 +169,7 @@ STATUS echo_currentdir(char** save)
char* pwd = getenv("PWD");
/// Copy results over
*save = new char[strlen(pwd) + 1];
CHKPTR(*save);

strcpy(*save, pwd);
return(WIN);
}
Expand All @@ -193,7 +193,7 @@ STATUS echo_parentdir(const char* path, char** save)
if(len > 0)
{
*save = new char[len + 1];
CHKPTR(*save);

/// Cut off last '/' and after
strncpy(*save, path, len);
return(WIN);
Expand All @@ -205,7 +205,7 @@ STATUS echo_parentdir(const char* path, char** save)
const char* dir = dirname(const_cast<char*>(path));
/// Copy it over
*save = new char[strlen(dir) + 1];
CHKPTR(*save);

strcpy(*save, dir);
return(WIN);
#endif
Expand Down Expand Up @@ -264,7 +264,7 @@ char* echo_merge(const char* arg1, const char* arg2)
{
/// Besides tehe string lengths, 1 char is for the null-char
ret = new char[strlen(arg1) + strlen(arg2) + 1];
CHKPTR(ret);

/// Just concat it
strcat(strcpy(ret, arg1), arg2);
}
Expand All @@ -273,7 +273,7 @@ char* echo_merge(const char* arg1, const char* arg2)
{
/// Besides the string lengths, 1 char is for the slash or backslash, and another char is for the null-char
ret = new char[strlen(arg1) + strlen(arg2) + 2];
CHKPTR(ret);

#ifdef ECHO_WIN
strcat(strcat(strcpy(ret, arg1), "\\"), arg2);
#else
Expand Down Expand Up @@ -317,7 +317,7 @@ char* echo_merge(const char* arg1, const char* arg2)
const int fd = open(fname, O_RDONLY);
/// Get a new file structure
struct stat* file_stat = new(struct stat);
CHKPTR(file_stat);

/// File up the file descriptor
const int exists = !fstat(fd, file_stat);
/// Don't need the file descriptor anymore
Expand Down Expand Up @@ -384,7 +384,7 @@ char* echo_merge(const char* arg1, const char* arg2)
DIR* dir = opendir(dirname);
/// Get a new structure
echo_files* ret = new(echo_files);
CHKPTR(ret);

/// Fill out the fields
ret->num_files = 0;
ret->current_dir = const_cast<char*>(dirname);
Expand All @@ -398,7 +398,7 @@ char* echo_merge(const char* arg1, const char* arg2)
}
/// Initialize the filename array
ret->file_names = new char*[ret->num_files];
CHKPTR(ret->file_names);

/// "..", or previous directory, is always first
ret->file_names[0] = "..";
/// Initialize the index
Expand All @@ -413,7 +413,7 @@ char* echo_merge(const char* arg1, const char* arg2)
{
/// New string
ret->file_names[each] = new char[strlen(each_ent->d_name) + 1];
CHKPTR(ret->file_names[each]);

/// Null the string
memset(ret->file_names[each], 0
, strlen(each_ent->d_name) + 1);
Expand Down Expand Up @@ -462,7 +462,7 @@ char* echo_merge(const char* arg1, const char* arg2)
{
/// New file structure
echo_files* ret = new(echo_files);
CHKPTR(ret);


/// Set fields
ret->num_files = 0;
Expand All @@ -473,7 +473,7 @@ char* echo_merge(const char* arg1, const char* arg2)
struct stat each_ent;
/// Buffer to save file names
char* filename = new char[MAXPATHLEN];
CHKPTR(filename);

while(dirnext(dir, filename, &each_ent) == 0)
{
/// If the file is not "."
Expand All @@ -489,7 +489,7 @@ char* echo_merge(const char* arg1, const char* arg2)
}
/// Make a new array
ret->file_names = new char*[ret->num_files];
CHKPTR(ret->file_names);

/// First file always ".."
ret->file_names[0] = "..";
/** each_dir is the directory index (1 because ".." is already filled)
Expand Down Expand Up @@ -521,7 +521,7 @@ char* echo_merge(const char* arg1, const char* arg2)
}
/// Copy the file name over
ret->file_names[each] = new char[strlen(filename) + 1];
CHKPTR(ret->file_names[each]);

memset(ret->file_names[each], 0
, strlen(filename) + 1);
strcpy(ret->file_names[each], filename);
Expand Down
6 changes: 3 additions & 3 deletions echo_ingame_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/

#include <echo_platform.h>
#include <echo_stage.h>
#include <echo_loader.h>
#include "echo_platform.h"
#include "echo_stage.h"
#include "echo_loader.h"

#ifndef __ECHO_INTERNAL_FILES__
#define __ECHO_INTERNAL_FILES__
Expand Down
Loading

0 comments on commit 95d0c86

Please sign in to comment.