Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
many bugs go squish!
Browse files Browse the repository at this point in the history
  • Loading branch information
aidinabedi committed Dec 14, 2009
1 parent 0cfb423 commit 6d7f985
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 28 deletions.
10 changes: 10 additions & 0 deletions Samples/MainLoop/MainLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,26 @@ void CheckPhysicsRaycast() {
PROFILE_END();
}


//-----------------------------------------------------------------------------

PROFILE_SHARED_DEFINE(Animations);

void UpdateAllCharacters() {

PROFILE_BEGIN(Gamelogic);

PROFILE_BEGIN(AI);
CheckPhysicsRaycast();

PROFILE_SHARED_BEGIN(Animations);
PROFILE_END();

PROFILE_END();

PROFILE_BEGIN(Player);
PROFILE_SHARED_BEGIN(Animations);
PROFILE_END();
PROFILE_END();

PROFILE_END();
Expand Down
3 changes: 3 additions & 0 deletions Shiny.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_Recursion", "Samples\R
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_MainLoop", "Samples\MainLoop\Demo_MainLoop.vcproj", "{23595110-7DBF-45AE-95B6-A1A888AED9BF}"
ProjectSection(ProjectDependencies) = postProject
{D44CCFEB-7FC2-46E6-8290-E0B00D06A636} = {D44CCFEB-7FC2-46E6-8290-E0B00D06A636}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
12 changes: 2 additions & 10 deletions include/ShinyMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,11 @@ applications, and to alter it and redistribute it freely, subject to the followi
//-----------------------------------------------------------------------------
// public preprocessor

#define PROFILE_SHARED_GLOBAL( name ) \
#define PROFILE_SHARED_EXTERN( name ) \
\
_PROFILE_ZONE_DECLARE(extern, _PROFILE_ID_ZONE_SHARED(name))


//-----------------------------------------------------------------------------
// public preprocessor

#define PROFILE_SHARED_MEMBER( name ) \
\
_PROFILE_ZONE_DECLARE(static, _PROFILE_ID_ZONE_SHARED(name))


//-----------------------------------------------------------------------------
// public preprocessor

Expand Down Expand Up @@ -217,7 +209,7 @@ applications, and to alter it and redistribute it freely, subject to the followi

#define _PROFILE_ZONE_BEGIN( id ) \
{ \
static ProfileNodeCache cache = \
static ShinyNodeCache cache = \
&_ShinyNode_dummy; \
\
ShinyManager_lookupAndBeginNode(&Shiny_instance, &cache, &id); \
Expand Down
12 changes: 6 additions & 6 deletions include/ShinyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct {

uint32_t _tableMask; // = _tableSize - 1

ProfileNodeTable* _nodeTable;
ShinyNodeTable* _nodeTable;

#if SHINY_LOOKUP_RATE == TRUE
uint64_t _lookupCount;
Expand Down Expand Up @@ -95,15 +95,15 @@ SHINY_INLINE void _ShinyManager_appendTicksToCurNode(ShinyManager *self) {
self->_lastTick = curTick;
}

ShinyNode* _ShinyManager_lookupNode(ShinyManager *self, ProfileNodeCache* a_cache, ShinyZone* a_zone);
ShinyNode* _ShinyManager_lookupNode(ShinyManager *self, ShinyNodeCache* a_cache, ShinyZone* a_zone);

void _ShinyManager_createNodeTable(ShinyManager *self, uint32_t a_count);
void _ShinyManager_resizeNodeTable(ShinyManager *self, uint32_t a_count);

void _ShinyManager_createNodePool(ShinyManager *self, uint32_t a_count);
void _ShinyManager_resizeNodePool(ShinyManager *self, uint32_t a_count);

ShinyNode* _ShinyManager_createNode(ShinyManager *self, ProfileNodeCache* a_cache, ShinyZone* a_pZone);
ShinyNode* _ShinyManager_createNode(ShinyManager *self, ShinyNodeCache* a_cache, ShinyZone* a_pZone);
void _ShinyManager_insertNode(ShinyManager *self, ShinyNode* a_pNode);

SHINY_INLINE void _ShinyManager_init(ShinyManager *self) {
Expand Down Expand Up @@ -152,7 +152,7 @@ SHINY_INLINE void ShinyManager_beginNode(ShinyManager *self, ShinyNode* a_node)
self->_curNode = a_node;
}

SHINY_INLINE void ShinyManager_lookupAndBeginNode(ShinyManager *self, ProfileNodeCache* a_cache, ShinyZone* a_zone) {
SHINY_INLINE void ShinyManager_lookupAndBeginNode(ShinyManager *self, ShinyNodeCache* a_cache, ShinyZone* a_zone) {
#if SHINY_HAS_ENABLED == TRUE
if (!self->enabled) return;
#endif
Expand Down Expand Up @@ -195,13 +195,13 @@ void ShinyManager_outputToStream(ShinyManager *self, FILE *stream);
#if __cplusplus
} // end of extern "C"

std::string ShinyManager_outputNodesToString(ShinyManager *self) {
SHINY_INLINE std::string ShinyManager_outputNodesToString(ShinyManager *self) {
const char* error = ShinyManager_getOutputErrorString(self);
if (!error) return ShinyNodesToString(&self->rootNode, self->nodeCount);
else return error;
}

std::string ShinyManager_outputZonesToString(ShinyManager *self) {
SHINY_INLINE std::string ShinyManager_outputZonesToString(ShinyManager *self) {
const char* error = ShinyManager_getOutputErrorString(self);
if (!error) return ShinyZonesToString(&self->rootZone, self->zoneCount);
else return error;
Expand Down
4 changes: 2 additions & 2 deletions include/ShinyNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef struct _ShinyNode {
uint32_t childCount;
uint32_t entryLevel;

ProfileNodeCache* _cache;
ShinyNodeCache* _cache;

ShinyData data;

Expand All @@ -72,7 +72,7 @@ SHINY_INLINE void ShinyNode_addChild(ShinyNode* self, ShinyNode* a_child) {
}
}

SHINY_INLINE void ShinyNode_init(ShinyNode* self, ShinyNode* a_parent, struct _ShinyZone* a_zone, ProfileNodeCache* a_cache) {
SHINY_INLINE void ShinyNode_init(ShinyNode* self, ShinyNode* a_parent, struct _ShinyZone* a_zone, ShinyNodeCache* a_cache) {
// NOTE: all member variables are assumed to be zero when allocated

self->zone = a_zone;
Expand Down
4 changes: 2 additions & 2 deletions include/ShinyPrereqs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ applications, and to alter it and redistribute it freely, subject to the followi
struct _ShinyNode;
struct _ShinyZone;

typedef struct _ShinyNode* ProfileNodeCache;
typedef struct _ShinyNode* ProfileNodeTable;
typedef struct _ShinyNode* ShinyNodeCache;
typedef struct _ShinyNode* ShinyNodeTable;
#endif


Expand Down
4 changes: 2 additions & 2 deletions include/ShinyZone.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ SHINY_INLINE float ShinyZone_compare(ShinyZone *a, ShinyZone *b) {
return b->data.selfTicks.avg - a->data.selfTicks.avg;
}

void ShinyZone_clear(ShinyZone* self);

void ShinyZone_enumerateZones(const ShinyZone* a_zone, void (*a_func)(const ShinyZone*));

/*
#if __cplusplus
} // end of extern "C"

Expand All @@ -86,7 +87,6 @@ void ShinyZone_enumerateZones(const ShinyZone* a_zone, T* a_this, void (T::*a_fu

extern "C" { // end of c++
#endif
*/

#endif // if SHINY_COMPILED == TRUE

Expand Down
37 changes: 31 additions & 6 deletions src/ShinyManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ShinyNode* _ShinyManager_dummyNodeTable[] = { NULL };

#if SHINY_COMPILER == SHINY_COMPILER_MSVC
# pragma warning (push)
# pragma warning(disable: 4311)
# pragma warning (disable: 4311)
#endif

// primary hash function
Expand Down Expand Up @@ -142,6 +142,22 @@ void ShinyManager_update(ShinyManager *self) {
}


//-----------------------------------------------------------------------------

void ShinyManager_updateClean(ShinyManager *self) {
#if SHINY_HAS_ENABLED == TRUE
if (!enabled) return;
#endif

_ShinyManager_appendTicksToCurNode(self);
ShinyZone_preUpdateChain(&self->rootZone);

self->_firstUpdate = FALSE;
ShinyNode_updateTreeClean(&self->rootNode);
ShinyZone_updateChainClean(&self->rootZone);
}


//-----------------------------------------------------------------------------

void ShinyManager_clear(ShinyManager *self) {
Expand All @@ -161,7 +177,7 @@ void ShinyManager_destroy(ShinyManager *self) {

//-----------------------------------------------------------------------------

ShinyNode* _ShinyManager_lookupNode(ShinyManager *self, ProfileNodeCache* a_cache, ShinyZone* a_zone) {
ShinyNode* _ShinyManager_lookupNode(ShinyManager *self, ShinyNodeCache* a_cache, ShinyZone* a_zone) {
uint32_t nHash = hash_value(self->_curNode, a_zone);
uint32_t nIndex = nHash & self->_tableMask;
ShinyNode* pNode = self->_nodeTable[nIndex];
Expand Down Expand Up @@ -256,7 +272,7 @@ void _ShinyManager_insertNode(ShinyManager *self, ShinyNode* a_pNode) {

//-----------------------------------------------------------------------------

ShinyNode* _ShinyManager_createNode(ShinyManager *self, ProfileNodeCache* a_cache, ShinyZone* a_pZone) {
ShinyNode* _ShinyManager_createNode(ShinyManager *self, ShinyNodeCache* a_cache, ShinyZone* a_pZone) {
ShinyNode* pNewNode = ShinyNodePool_newItem(self->_lastNodePool);
ShinyNode_init(pNewNode, self->_curNode, a_pZone, a_cache);

Expand Down Expand Up @@ -289,7 +305,7 @@ void _ShinyManager_createNodeTable(ShinyManager *self, uint32_t a_nCount) {
self->_tableSize = a_nCount;
self->_tableMask = a_nCount - 1;

self->_nodeTable = (ProfileNodeTable*)
self->_nodeTable = (ShinyNodeTable*)
malloc(sizeof(ShinyNode) * a_nCount);

memset(self->_nodeTable, 0, a_nCount * sizeof(ShinyNode*));
Expand Down Expand Up @@ -352,14 +368,19 @@ void ShinyManager_destroyNodes(ShinyManager *self) {
//-----------------------------------------------------------------------------

const char* ShinyManager_getOutputErrorString(ShinyManager *self) {
if (self->_firstUpdate) return "!!! Profile data not updated !!!";
else if (!self->_initialized) return "!!! No profile was collected !!!";
if (self->_firstUpdate) return "!!! Profile data must first be updated !!!";
else if (!self->_initialized) return "!!! No profiles where executed !!!";
else return NULL;
}


//-----------------------------------------------------------------------------

#if SHINY_COMPILER == SHINY_COMPILER_MSVC
# pragma warning (push)
# pragma warning (disable: 4996)
#endif

int ShinyManager_outputToFile(ShinyManager *self, const char *a_filename) {
FILE *file = fopen(a_filename, "w");

Expand All @@ -369,6 +390,10 @@ int ShinyManager_outputToFile(ShinyManager *self, const char *a_filename) {
return TRUE;
}

#if SHINY_COMPILER == SHINY_COMPILER_MSVC
# pragma warning (pop)
#endif


//-----------------------------------------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions src/ShinyZone.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ applications, and to alter it and redistribute it freely, subject to the followi

#include "ShinyZone.h"

#include <memory.h>

#if SHINY_COMPILED == TRUE

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -160,6 +162,14 @@ ShinyZone* ShinyZone_sortChain(ShinyZone *first) {
}
}


//-----------------------------------------------------------------------------

void ShinyZone_clear(ShinyZone* self) {
memset(self, 0, sizeof(ShinyZone));
}


//-----------------------------------------------------------------------------

void ShinyZone_enumerateZones(const ShinyZone* a_zone, void (*a_func)(const ShinyZone*)) {
Expand Down

0 comments on commit 6d7f985

Please sign in to comment.