Commit 055200a5 authored by Marco Foco's avatar Marco Foco Committed by Gargaj
Browse files

Pan's Cleanup

* More const correctness
* Converted "map.insert(make_pair(a,b))" pattern into "map[a] = b".
* removed some warnings (e.g. double->float conversions and sign mismatch)
parent 4371354b
......@@ -2,3 +2,4 @@ Bonzomatic
.obj
tmp
build
.vs
......@@ -7,7 +7,7 @@ namespace Misc
void InitKeymaps();
void GetKeymapName( char * sz );
bool ExecuteCommand( char * cmd, char * param );
bool ExecuteCommand( const char * cmd, const char * param );
bool FileExists(const char * path);
const char * GetDefaultFontPath();
......
......@@ -428,7 +428,7 @@ void SurfaceImpl::MeasureWidths(Font & font, const char *str, int len, float *po
stbtt_Font* realFont = (stbtt_Font*)font.GetID();
float position = 0;
char * p = (char*)str;
const char * p = str;
while (len-- > 0)
{
unsigned int c = *p;
......@@ -446,7 +446,7 @@ void SurfaceImpl::MeasureWidths(Font & font, const char *str, int len, float *po
stbtt_GetCodepointHMetrics(&realFont->fontinfo, c, &advance, &leftBearing);
position += advance;
for (int i=0; i<charLength; i++) // we need to loop here because UTF8 characters count as multiple unless their position is the same
for (unsigned int i=0; i<charLength; i++) // we need to loop here because UTF8 characters count as multiple unless their position is the same
*positions++ = position*realFont->scale;
p += charLength;
......
......@@ -16,8 +16,8 @@ typedef struct
namespace Renderer
{
extern char * defaultShaderFilename;
extern char defaultShader[65536];
extern const char * defaultShaderFilename;
extern const char defaultShader[65536];
extern int nWidth;
extern int nHeight;
......@@ -31,9 +31,9 @@ namespace Renderer
void RenderFullscreenQuad();
bool ReloadShader( char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize );
void SetShaderConstant( char * szConstName, float x );
void SetShaderConstant( char * szConstName, float x, float y );
bool ReloadShader( const char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize );
void SetShaderConstant( const char * szConstName, float x );
void SetShaderConstant( const char * szConstName, float x, float y );
void StartTextRendering();
void SetTextRenderingViewport( Scintilla::PRectangle rect );
......@@ -56,11 +56,11 @@ namespace Renderer
TEXTURETYPE type;
};
Texture * CreateRGBA8TextureFromFile( char * szFilename );
Texture * CreateA8TextureFromData( int w, int h, unsigned char * data );
Texture * CreateRGBA8TextureFromFile( const char * szFilename );
Texture * CreateA8TextureFromData( int w, int h, const unsigned char * data );
Texture * Create1DR32Texture( int w );
bool UpdateR32Texture( Texture * tex, float * data );
void SetShaderTexture( char * szTextureName, Texture * tex );
void SetShaderTexture( const char * szTextureName, Texture * tex );
void BindTexture( Texture * tex ); // temporary function until all the quad rendering is moved to the renderer
void ReleaseTexture( Texture * tex );
struct Vertex
......
......@@ -234,7 +234,7 @@ void ShaderEditor::Paint()
Scintilla::Editor::Paint( surfaceWindow, GetClientRectangle() );
}
void ShaderEditor::SetText( char * buf )
void ShaderEditor::SetText( const char * buf )
{
WndProc( SCI_SETREADONLY, false, NULL );
WndProc( SCI_CLEARALL, false, NULL );
......
......@@ -98,7 +98,7 @@ public:
void FineTickerStart(TickReason, int, int);
void FineTickerCancel(TickReason);
void SetText( char * buf );
void SetText( const char * buf );
void GetText( char * buf, int len );
void Paint();
......
......@@ -41,7 +41,7 @@ void ReplaceTokens( std::string &sDefShader, const char * sTokenBegin, const cha
}
}
int main(int argc, char *argv[])
int main(int argc, const char *argv[])
{
Misc::PlatformStartup();
......@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
std::map<std::string, jsonxx::Value*> tex = options.get<jsonxx::Object>("textures").kv_map();
for (std::map<std::string, jsonxx::Value*>::iterator it = tex.begin(); it != tex.end(); it++)
{
char * fn = (char*)it->second->string_value_->c_str();
const char * fn = it->second->string_value_->c_str();
printf("* %s...\n",fn);
Renderer::Texture * tex = Renderer::CreateRGBA8TextureFromFile( fn );
if (!tex)
......@@ -140,7 +140,7 @@ int main(int argc, char *argv[])
printf("Renderer::CreateRGBA8TextureFromFile(%s) failed\n",fn);
return -1;
}
textures.insert( std::make_pair( it->first, tex ) );
textures[it->first] = tex;
}
}
if (options.has<jsonxx::Object>("font"))
......@@ -181,7 +181,7 @@ int main(int argc, char *argv[])
std::map<std::string, jsonxx::Value*> tex = options.get<jsonxx::Object>("midi").kv_map();
for (std::map<std::string, jsonxx::Value*>::iterator it = tex.begin(); it != tex.end(); it++)
{
midiRoutes.insert( std::make_pair( it->second->number_value_, it->first ) );
midiRoutes[it->second->number_value_] = it->first;
}
}
if (options.has<jsonxx::String>("postExitCmd"))
......@@ -286,7 +286,7 @@ int main(int argc, char *argv[])
bool bShowGui = true;
Timer::Start();
float fNextTick = 0.1;
float fNextTick = 0.1f;
while (!Renderer::WantsToQuit())
{
bool newShader = false;
......@@ -380,7 +380,7 @@ int main(int argc, char *argv[])
for (std::map<int,std::string>::iterator it = midiRoutes.begin(); it != midiRoutes.end(); it++)
{
Renderer::SetShaderConstant( (char*)it->second.c_str(), MIDI::GetCCValue( it->first ) );
Renderer::SetShaderConstant( it->second.c_str(), MIDI::GetCCValue( it->first ) );
}
......@@ -410,7 +410,7 @@ int main(int argc, char *argv[])
for (std::map<std::string, Renderer::Texture*>::iterator it = textures.begin(); it != textures.end(); it++)
{
Renderer::SetShaderTexture( (char*)it->first.c_str(), it->second );
Renderer::SetShaderTexture( it->first.c_str(), it->second );
}
Renderer::RenderFullscreenQuad();
......@@ -499,7 +499,7 @@ int main(int argc, char *argv[])
if ( !sPostExitCmd.empty() )
{
Misc::ExecuteCommand( (char*)sPostExitCmd.c_str(), Renderer::defaultShaderFilename );
Misc::ExecuteCommand( sPostExitCmd.c_str(), Renderer::defaultShaderFilename );
}
Misc::PlatformShutdown();
......
......@@ -117,8 +117,8 @@ const char * shaderBuiltin =
namespace Renderer
{
char * defaultShaderFilename = "shader.glsl";
char defaultShader[65536] =
const char * defaultShaderFilename = "shader.glsl";
const char defaultShader[65536] =
"#version 410 core\n"
"\n"
"uniform float fGlobalTime; // in seconds\n"
......@@ -306,7 +306,7 @@ namespace Renderer
glhVertexShader = glCreateShader( GL_VERTEX_SHADER );
char * szVertexShader =
const char * szVertexShader =
"#version 410 core\n"
"in vec3 in_pos;\n"
"in vec2 in_texcoord;\n"
......@@ -334,7 +334,7 @@ namespace Renderer
#define GUIQUADVB_SIZE (1024 * 6)
char * defaultGUIVertexShader =
const char * defaultGUIVertexShader =
"#version 410 core\n"
"in vec3 in_pos;\n"
"in vec4 in_color;\n"
......@@ -353,7 +353,7 @@ namespace Renderer
" out_texcoord = in_texcoord;\n"
" out_factor = in_factor;\n"
"}\n";
char * defaultGUIPixelShader =
const char * defaultGUIPixelShader =
"#version 410 core\n"
"uniform sampler2D tex;\n"
"in vec4 out_color;\n"
......@@ -599,7 +599,7 @@ namespace Renderer
glUseProgram(NULL);
}
bool ReloadShader( char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize )
bool ReloadShader( const char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize )
{
GLuint prg = glCreateProgram();
GLuint shd = glCreateShader(GL_FRAGMENT_SHADER);
......@@ -637,7 +637,7 @@ namespace Renderer
return true;
}
void SetShaderConstant( char * szConstName, float x )
void SetShaderConstant( const char * szConstName, float x )
{
GLint location = glGetUniformLocation( theShader, szConstName );
if ( location != -1 )
......@@ -646,7 +646,7 @@ namespace Renderer
}
}
void SetShaderConstant( char * szConstName, float x, float y )
void SetShaderConstant( const char * szConstName, float x, float y )
{
GLint location = glGetUniformLocation( theShader, szConstName );
if ( location != -1 )
......@@ -662,12 +662,12 @@ namespace Renderer
};
int textureUnit = 0;
Texture * CreateRGBA8TextureFromFile( char * szFilename )
Texture * CreateRGBA8TextureFromFile( const char * szFilename )
{
int comp = 0;
int width = 0;
int height = 0;
unsigned char * c = stbi_load( szFilename, (int*)&width, (int*)&height, &comp, STBI_rgb_alpha );
unsigned char * c = stbi_load( szFilename, &width, &height, &comp, STBI_rgb_alpha );
if (!c) return NULL;
GLuint glTexId = 0;
......@@ -724,7 +724,7 @@ namespace Renderer
return tex;
}
void SetShaderTexture( char * szTextureName, Texture * tex )
void SetShaderTexture( const char * szTextureName, Texture * tex )
{
if (!tex)
return;
......@@ -751,7 +751,7 @@ namespace Renderer
return true;
}
Texture * CreateA8TextureFromData( int w, int h, unsigned char * data )
Texture * CreateA8TextureFromData( int w, int h, const unsigned char * data )
{
GLuint glTexId = 0;
glGenTextures(1, &glTexId);
......
......@@ -42,7 +42,7 @@ void Misc::GetKeymapName(char* sz)
strncpy(sz,"<native>",7);
}
bool Misc::ExecuteCommand( char * cmd, char * param )
bool Misc::ExecuteCommand( const char * cmd, const char * param )
{
return false;
}
......
......@@ -29,7 +29,7 @@ namespace Clipboard
return 0;
HANDLE hData = GetClipboardData(CF_TEXT);
char * buffer = (char*)GlobalLock( hData );
const char * buffer = (const char*)GlobalLock( hData );
int n = strlen(buffer);
CloseClipboard();
......@@ -44,7 +44,7 @@ namespace Clipboard
return;
HANDLE hData = GetClipboardData(CF_TEXT);
char * buffer = (char*)GlobalLock( hData );
const char * buffer = (const char*)GlobalLock( hData );
strncpy( data, buffer, len );
CloseClipboard();
......
......@@ -62,7 +62,7 @@ namespace MIDI
float GetCCValue( unsigned char cc )
{
return nCCValues[cc] / 127.0;
return nCCValues[cc] / 127.0f;
}
};
\ No newline at end of file
......@@ -40,7 +40,7 @@ namespace Misc
LONG resultKey = RegQueryValueExA( hkSub, "Layout Text", NULL, &type, szValue, &nValue );
CharLowerA( szKeyName );
keymaps.insert( std::make_pair( szKeyName, (char*)szValue ) );
keymaps[szKeyName] = (const char*)szValue;
}
idx++;
}
......@@ -54,7 +54,7 @@ namespace Misc
strncpy( sz, keymaps.count(szCode) ? keymaps[szCode].c_str() : "<unknown>" ,255);
}
bool ExecuteCommand( char * cmd, char * param )
bool ExecuteCommand( const char * cmd, const char * param )
{
HINSTANCE hI = ShellExecute( NULL, NULL, cmd, param, NULL, SW_SHOW );
return (int)hI >= 32;
......
......@@ -100,8 +100,8 @@ const char * shaderBuiltin =
namespace Renderer
{
char * defaultShaderFilename = "shader.dx11.hlsl";
char defaultShader[65536] =
const char * defaultShaderFilename = "shader.dx11.hlsl";
const char defaultShader[65536] =
"{%textures:begin%}" // leave off \n here
"Texture2D {%textures:name%};\n"
"{%textures:end%}" // leave off \n here
......@@ -392,7 +392,7 @@ namespace Renderer
DXGI_MODE_DESC * pModes = new DXGI_MODE_DESC[ nModeCount ];
pOutput->GetDisplayModeList( format, DXGI_ENUM_MODES_INTERLACED | DXGI_ENUM_MODES_SCALING, &nModeCount, pModes);
for (int i=0; i<nModeCount; i++)
for (unsigned int i=0; i<nModeCount; i++)
{
if (pModes[i].Width == pSetup->nWidth && pModes[i].Height == pSetup->nHeight)
{
......@@ -819,14 +819,14 @@ namespace Renderer
}
ID3D11ShaderReflectionConstantBuffer * pCBuf = NULL;
bool ReloadShader( char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize )
bool ReloadShader( const char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize )
{
ID3DBlob * pCode = NULL;
ID3DBlob * pErrors = NULL;
if (D3DCompile( szShaderCode, nShaderCodeSize, NULL, NULL, NULL, "main", "ps_4_0", NULL, NULL, &pCode, &pErrors ) != S_OK)
{
memset( szErrorBuffer, 0, nErrorBufferSize );
strncpy( szErrorBuffer, (char*)pErrors->GetBufferPointer(), nErrorBufferSize - 1 );
strncpy( szErrorBuffer, (const char*)pErrors->GetBufferPointer(), nErrorBufferSize - 1 );
return false;
}
......@@ -854,7 +854,7 @@ namespace Renderer
pContext->Unmap( pFullscreenQuadConstantBuffer, NULL );
}
void SetShaderConstant( char * szConstName, float x )
void SetShaderConstant( const char * szConstName, float x )
{
ID3D11ShaderReflectionVariable * pCVar = pCBuf->GetVariableByName( szConstName );
D3D11_SHADER_VARIABLE_DESC pDesc;
......@@ -866,7 +866,7 @@ namespace Renderer
__UpdateConstants();
}
void SetShaderConstant( char * szConstName, float x, float y )
void SetShaderConstant( const char * szConstName, float x, float y )
{
ID3D11ShaderReflectionVariable * pCVar = pCBuf->GetVariableByName(szConstName);
D3D11_SHADER_VARIABLE_DESC pDesc;
......@@ -907,12 +907,12 @@ namespace Renderer
}
int textureUnit = 0;
Texture * CreateRGBA8TextureFromFile( char * szFilename )
Texture * CreateRGBA8TextureFromFile( const char * szFilename )
{
int comp = 0;
int width = 0;
int height = 0;
unsigned char * c = stbi_load( szFilename, (int*)&width, (int*)&height, &comp, STBI_rgb_alpha );
unsigned char * c = stbi_load( szFilename, &width, &height, &comp, STBI_rgb_alpha );
if (!c) return NULL;
D3D11_TEXTURE2D_DESC desc;
......@@ -974,7 +974,7 @@ namespace Renderer
return tex;
}
void SetShaderTexture( char * szTextureName, Texture * tex )
void SetShaderTexture( const char * szTextureName, Texture * tex )
{
D3D11_SHADER_INPUT_BIND_DESC desc;
if (pShaderReflection->GetResourceBindingDescByName( szTextureName, &desc ) == S_OK)
......@@ -995,7 +995,7 @@ namespace Renderer
return true;
}
Texture * CreateA8TextureFromData( int w, int h, unsigned char * data )
Texture * CreateA8TextureFromData( int w, int h, const unsigned char * data )
{
D3D11_TEXTURE2D_DESC desc;
ZeroMemory(&desc,sizeof(D3D11_TEXTURE2D_DESC));
......@@ -1107,7 +1107,7 @@ namespace Renderer
*(unsigned int *)(f++) = v.c;
*(f++) = v.u;
*(f++) = v.v;
*(f++) = lastTexture ? 0.0 : 1.0;
*(f++) = lastTexture ? 0.0f : 1.0f;
bufferPointer++;
}
void BindTexture( Texture * tex )
......
......@@ -99,8 +99,8 @@ const char * shaderBuiltin =
namespace Renderer
{
char * defaultShaderFilename = "shader.dx9.hlsl";
char defaultShader[65536] =
const char * defaultShaderFilename = "shader.dx9.hlsl";
const char defaultShader[65536] =
"texture texTFFT; sampler1D texFFT = sampler_state { Texture = <texTFFT>; }; \n"
"// towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq\n"
"texture texFFTSmoothedT; sampler1D texFFTSmoothed = sampler_state { Texture = <texFFTSmoothedT>; }; \n"
......@@ -566,7 +566,7 @@ namespace Renderer
pDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
}
bool ReloadShader( char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize )
bool ReloadShader( const char * szShaderCode, int nShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize )
{
LPD3DXBUFFER pShader = NULL;
LPD3DXBUFFER pErrors = NULL;
......@@ -574,7 +574,7 @@ namespace Renderer
if (D3DXCompileShader( szShaderCode, nShaderCodeSize, NULL, NULL, "main", "ps_3_0", NULL, &pShader, &pErrors, &pConstantTable ) != D3D_OK)
{
memset( szErrorBuffer, 0, nErrorBufferSize );
strncpy( szErrorBuffer, (char*)pErrors->GetBufferPointer(), nErrorBufferSize - 1 );
strncpy( szErrorBuffer, (const char*)pErrors->GetBufferPointer(), nErrorBufferSize - 1 );
return false;
}
......@@ -592,12 +592,12 @@ namespace Renderer
return true;
}
void SetShaderConstant( char * szConstName, float x )
void SetShaderConstant( const char * szConstName, float x )
{
pConstantTable->SetFloat( pDevice, szConstName, x );
}
void SetShaderConstant( char * szConstName, float x, float y )
void SetShaderConstant( const char * szConstName, float x, float y )
{
pConstantTable->SetVector( pDevice, szConstName, &D3DXVECTOR4(x, y, 0, 0) );
}
......@@ -608,7 +608,7 @@ namespace Renderer
};
int textureUnit = 0;
Texture * CreateRGBA8TextureFromFile( char * szFilename )
Texture * CreateRGBA8TextureFromFile( const char * szFilename )
{
LPDIRECT3DTEXTURE9 pTex = NULL;
D3DXIMAGE_INFO info;
......@@ -660,7 +660,7 @@ namespace Renderer
return tex;
}
void SetShaderTexture( char * szTextureName, Texture * tex )
void SetShaderTexture( const char * szTextureName, Texture * tex )
{
int idx = pConstantTable->GetSamplerIndex( szTextureName );
if (idx >= 0)
......@@ -684,7 +684,7 @@ namespace Renderer
return true;
}
Texture * CreateA8TextureFromData( int w, int h, unsigned char * data )
Texture * CreateA8TextureFromData( int w, int h, const unsigned char * data )
{
LPDIRECT3DTEXTURE9 pTex = NULL;
pDevice->CreateTexture( w, h, 0, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTex, NULL );
......@@ -694,11 +694,11 @@ namespace Renderer
D3DLOCKED_RECT rect;
pTex->LockRect( 0, &rect, NULL, NULL );
unsigned char * src = data;
const unsigned char * src = data;
unsigned char * dst = (unsigned char *)rect.pBits;
for (int i=0; i<h; i++)
{
unsigned char * srcLine = src;
const unsigned char * srcLine = src;
unsigned int * dstLine = (unsigned int *)dst;
for (int j=0; j<w; j++)
{
......
......@@ -24,7 +24,7 @@ void Misc::GetKeymapName(char* sz)
strncpy(sz,"<native>",7);
}
bool Misc::ExecuteCommand( char * cmd, char * param )
bool Misc::ExecuteCommand( const char * cmd, const char * param )
{
return false;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment