From: <at...@us...> - 2007-11-05 17:05:51
|
Revision: 526 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=526&view=rev Author: atani Date: 2007-11-05 09:05:44 -0800 (Mon, 05 Nov 2007) Log Message: ----------- avoid realloc in Buffer if there is enough space in the buffer for the new data. preallocate Buffer when reading the response to an http request. reorganize NDS init (also now uses TIKI_INIT_FLAGS) added TIKI_INIT_DEBUG_* flags to enable the debug console (enabled by default), use TIKI_INIT_DEFAULTS_NODEBUG to enable the defaults without the debug console. Note that this will waste some cycles when calling Tiki::Debug::printf() when the console is not enabled. Modified Paths: -------------- tiki/include/Tiki/net/buffer.h tiki/include/Tiki/tiki.h tiki/nds/src/init_shutdown.cpp tiki/nds/src/platnet.cpp tiki/src/base/debug.cpp tiki/src/gl/gl.cpp tiki/src/net/http/useragent.cpp tiki/win32/src/platgl.cpp tiki/win32/src/platnet.cpp Modified: tiki/include/Tiki/net/buffer.h =================================================================== --- tiki/include/Tiki/net/buffer.h 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/include/Tiki/net/buffer.h 2007-11-05 17:05:44 UTC (rev 526) @@ -70,14 +70,19 @@ } void append(Buffer *buf) { - uint8 * newbuf = new uint8[ m_dataLen + buf->getDataLen() ]; - memset(newbuf, '\0', m_dataLen + buf->getDataLen()); - if(m_data != NULL) { - memcpy(newbuf, m_data, m_usedDataLen); + if(m_dataLen - m_usedDataLen > buf->getUsedDataLen()) { + memcpy(m_data + getUsedDataLen(), buf->getData(), buf->getUsedDataLen()); } - memcpy(newbuf + m_usedDataLen, buf->getData(), buf->getUsedDataLen()); - delete [] m_data; - m_data = newbuf; + else { + uint8 * newbuf = new uint8[ m_dataLen + buf->getDataLen() ]; + memset(newbuf, '\0', m_dataLen + buf->getDataLen()); + if(m_data != NULL) { + memcpy(newbuf, m_data, m_usedDataLen); + } + memcpy(newbuf + m_usedDataLen, buf->getData(), buf->getUsedDataLen()); + delete [] m_data; + m_data = newbuf; + } m_dataLen += buf->getDataLen(); m_usedDataLen += buf->getUsedDataLen(); } Modified: tiki/include/Tiki/tiki.h =================================================================== --- tiki/include/Tiki/tiki.h 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/include/Tiki/tiki.h 2007-11-05 17:05:44 UTC (rev 526) @@ -83,8 +83,13 @@ TIKI_INIT_AUDIO_DEFAULT = TIKI_INIT_AUDIO_STREAM | TIKI_INIT_AUDIO_SFX, TIKI_INIT_AUDIO_MASK = 0x00FF0000, + TIKI_INIT_DEBUG_CONSOLE = 0x01000000, + TIKI_INIT_DEBUG_DEFAULT = TIKI_INIT_DEBUG_CONSOLE, + TIKI_INIT_DEBUG_MASK = 0xFF000000, + TIKI_INIT_NOTHING = 0x00000000, - TIKI_INIT_DEFAULTS = TIKI_INIT_HID_DEFAULT | TIKI_INIT_VIDEO_DEFAULT | TIKI_INIT_AUDIO_DEFAULT, + TIKI_INIT_DEFAULTS = TIKI_INIT_HID_DEFAULT | TIKI_INIT_VIDEO_DEFAULT | TIKI_INIT_AUDIO_DEFAULT | TIKI_INIT_DEBUG_DEFAULT, + TIKI_INIT_DEFAULTS_NODEBUG = TIKI_INIT_HID_DEFAULT | TIKI_INIT_VIDEO_DEFAULT | TIKI_INIT_AUDIO_DEFAULT, } TIKI_INIT_FLAGS_ENUM; } Modified: tiki/nds/src/init_shutdown.cpp =================================================================== --- tiki/nds/src/init_shutdown.cpp 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/nds/src/init_shutdown.cpp 2007-11-05 17:05:44 UTC (rev 526) @@ -1,133 +1,134 @@ -/* - Tiki - - init_shutdown.cpp - - Copyright (C)2005 Atani Software -*/ - -#include "pch.h" - -#include "Tiki/sound.h" -#include "Tiki/stream.h" -#include "Tiki/hid.h" - -#include <nds.h> -#include <fat.h> -#include <dswifi9.h> -#include <dssoundstream.h> - -// notification function to send fifo message to arm7 -void arm9_synctoarm7() { // send fifo message - SendCommandToArm7( 0x87654321 ); -} -// wifi timer function, to update internals of sgIP -void Timer_50ms( void ) { - Wifi_Timer( 50 ); -} -namespace Tiki { - -bool init( int argc, char **argv ) { - // Turn on everything - powerON( POWER_ALL ); - - lcdMainOnTop(); - - consoleDemoInit(); - - // Setup the Main screen for 3D - videoSetMode( MODE_0_3D ); - vramSetBankA( VRAM_A_TEXTURE ); - - Tiki::Debug::printf("Enabling IRQs\n"); - // IRQ basic setup - irqInit(); - irqSet(IRQ_VBLANK, 0); - - Tiki::Debug::printf("Enabling GL\n"); - - // initialize the geometry engine - glInit(); - glEnable(GL_TEXTURE_2D); - - // enable antialiasing - glEnable(GL_ANTIALIAS); - glClearColor(0,0,0,31); // BG must be opaque for AA to work - glClearPolyID(63); // BG must have a unique polygon ID for AA to work - glClearDepth( 0x7FFF ); - // Set our viewport to be the same size as the screen - glViewport(0,0,255,191); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(70, 256.0 / 192.0, 0.1, 100); - - - glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0),0); - glLight(1, RGB15(31,31,31) , 0,0,floattov10(-1.0)); - glLight(2, RGB15(31,31,31) , 0,0,floattov10(1.0)); - - //need to set up some material properties since DS does not have them set by default - glMaterialf(GL_AMBIENT, RGB15(16,16,16)); - glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); - glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); - glMaterialf(GL_EMISSION, RGB15(16,16,16)); - - //ds uses a table for shinyness..this generates a half-ass one - glMaterialShinyness(); - - glPolyFmt(POLY_ALPHA(31) | POLY_CULL_FRONT | POLY_FORMAT_LIGHT0| POLY_FORMAT_LIGHT1| POLY_FORMAT_LIGHT2 ); - - glMatrixMode(GL_MODELVIEW); - - // set a default color. - glColor3f(1, 1, 1); - - Tiki::Debug::printf("Enabling libFAT\n"); - // initialize libfat +/* + Tiki + + init_shutdown.cpp + + Copyright (C)2005 Atani Software +*/ + +#include "pch.h" + +#include "Tiki/sound.h" +#include "Tiki/stream.h" +#include "Tiki/hid.h" + +#include <nds.h>s +#include <fat.h> +#include <dswifi9.h> +#include <dssoundstream.h> + +// notification function to send fifo message to arm7 +void arm9_synctoarm7() { // send fifo message + SendCommandToArm7( 0x87654321 ); +} + +namespace Tiki { + +bool init( int argc, char **argv ) { + // Turn on everything + powerON( POWER_ALL ); + + lcdMainOnTop(); + + if(g_tiki_init_flags & TIKI_INIT_DEBUG_CONSOLE) { + consoleDemoInit(); + } + + // Setup the Main screen for 3D + videoSetMode( MODE_0_3D ); + vramSetBankA( VRAM_A_TEXTURE ); + + Tiki::Debug::printf("Enabling IRQs\n"); + // IRQ basic setup + irqInit(); + + Tiki::Debug::printf("Enabling GL\n"); + // initialize the geometry engine + glInit(); + glEnable(GL_TEXTURE_2D); + + // enable antialiasing + glEnable(GL_ANTIALIAS); + glClearColor(0,0,0,31); // BG must be opaque for AA to work + glClearPolyID(63); // BG must have a unique polygon ID for AA to work + glClearDepth( 0x7FFF ); + // Set our viewport to be the same size as the screen + glViewport(0,0,255,191); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(70, 256.0 / 192.0, 0.1, 100); + + glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0),0); + glLight(1, RGB15(31,31,31) , 0,0,floattov10(-1.0)); + glLight(2, RGB15(31,31,31) , 0,0,floattov10(1.0)); + + //need to set up some material properties since DS does not have them set by default + glMaterialf(GL_AMBIENT, RGB15(16,16,16)); + glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); + glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); + glMaterialf(GL_EMISSION, RGB15(16,16,16)); + + //ds uses a table for shinyness..this generates a half-ass one + glMaterialShinyness(); + + glPolyFmt(POLY_ALPHA(31) | POLY_CULL_FRONT | POLY_FORMAT_LIGHT0| POLY_FORMAT_LIGHT1| POLY_FORMAT_LIGHT2 ); + + glMatrixMode(GL_MODELVIEW); + + // set a default color. + glColor3f(1, 1, 1); + + Tiki::Debug::printf("Enabling libFAT\n"); fatInitDefault(); - - // initialize parallax - Tiki::Debug::printf("Enabling Sound\n"); - Audio::Stream::initGlobal(); - Hid::init(); - - irqSet( IRQ_TIMER3, Timer_50ms ); // setup timer IRQ - irqEnable( IRQ_TIMER3 ); - Tiki::Debug::printf("Enabling Wifi\n"); - { // send fifo message to initialize the arm7 wifi - REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // enable & clear FIFO - - u32 Wifi_pass = Wifi_Init( WIFIINIT_OPTION_USELED ); - REG_IPC_FIFO_TX = 0x12345678; - REG_IPC_FIFO_TX = Wifi_pass; - irqEnable( IRQ_FIFO_NOT_EMPTY ); - - REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; // enable FIFO IRQ - - Wifi_SetSyncHandler( arm9_synctoarm7 ); // tell wifi lib to use our handler to notify arm7 - - // set timer3 - *( ( volatile u16 * ) 0x0400010C ) = -6553; // 6553.1 * 256 cycles = ~50ms; - *( ( volatile u16 * ) 0x0400010E ) = 0x00C2; // enable, irq, 1/256 clock - - while ( Wifi_CheckInit() == 0 ) { // wait for arm7 to be initted successfully - swiWaitForVBlank(); - } - - } // wifi init complete - wifi lib can now be used! - - return true; -} - -void shutdown() { - Hid::shutdown(); -} - -void setName( const char *windowName, const char *iconName ) {} - -namespace GL { -void showCursor( bool visible ) {} -} - -} + + if(g_tiki_init_flags & TIKI_INIT_AUDIO_MASK) { + if(g_tiki_init_flags & TIKI_INIT_AUDIO_STREAM) { + Tiki::Debug::printf("Enabling SoundStream\n"); + Audio::Stream::initGlobal(); + } + } + if(g_tiki_init_flags & TIKI_INIT_HID_MASK ) { + Tiki::Debug::printf("Enabling HID\n"); + Hid::init(); + } + + Tiki::Debug::printf("Initializing ARM7\n"); + // enable & clear FIFO + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; + + // setup some basic options for the wifi lib + u32 Wifi_pass = Wifi_Init( WIFIINIT_OPTION_USELED ); + REG_IPC_FIFO_TX = 0x12345678; + REG_IPC_FIFO_TX = Wifi_pass; + irqEnable( IRQ_FIFO_NOT_EMPTY ); + + // enable FIFO IRQ + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; + + // tell wifi lib to use our handler to notify arm7 + Wifi_SetSyncHandler( arm9_synctoarm7 ); + + // wait for arm7 to be initted successfully + while ( Wifi_CheckInit() == 0 ) { + swiWaitForVBlank(); + } + return true; +} + +void shutdown() { + if(g_tiki_init_flags & TIKI_INIT_HID_MASK ) { + Hid::shutdown(); + } + if(g_tiki_init_flags & TIKI_INIT_HID_MASK ) { + Audio::Stream::shutdownGlobal(); + } +} + +void setName( const char *windowName, const char *iconName ) {} + +namespace GL { +void showCursor( bool visible ) {} +} + +} Modified: tiki/nds/src/platnet.cpp =================================================================== --- tiki/nds/src/platnet.cpp 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/nds/src/platnet.cpp 2007-11-05 17:05:44 UTC (rev 526) @@ -1,52 +1,64 @@ -/* - Tiki - - platnet.cpp - - Copyright (C)2007 Atani Software -*/ - -#include "Tiki/tiki.h" -#include "Tiki/net.h" - -namespace Tiki { - -namespace Net { - -void init() { -} - -void shutdown() { -} - -bool connect() { +/* + Tiki + + platnet.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "Tiki/tiki.h" +#include "Tiki/net.h" + +// wifi timer function, to update internals of sgIP +void Timer_50ms( void ) { + Wifi_Timer( 50 ); +} + +namespace Tiki { + +namespace Net { + +void init() { + Tiki::Debug::printf("Enabling Wifi\n"); + irqSet( IRQ_TIMER3, Timer_50ms ); // setup timer IRQ + irqEnable( IRQ_TIMER3 ); + + // set timer3 + *( ( volatile u16 * ) 0x0400010C ) = -6553; // 6553.1 * 256 cycles = ~50ms; + *( ( volatile u16 * ) 0x0400010E ) = 0x00C2; // enable, irq, 1/256 clock +} + +void shutdown() { +} + +bool connect() { if(!isConnected()) { - Tiki::Debug::printf("Connecting to Wifi\n"); - Wifi_AutoConnect(); - while(1) { - switch(Wifi_AssocStatus()) { - case ASSOCSTATUS_ASSOCIATED: - return true; - case ASSOCSTATUS_CANNOTCONNECT: - return false; - } - } - } - - return true; -} - -bool isConnected() { - return (Wifi_AssocStatus() == ASSOCSTATUS_ASSOCIATED); -} - -void disconnect() { + Tiki::Debug::printf("Connecting to Wifi\n"); + Wifi_AutoConnect(); + while(1) { + switch(Wifi_AssocStatus()) { + case ASSOCSTATUS_ASSOCIATED: + return true; + case ASSOCSTATUS_CANNOTCONNECT: + return false; + } + } + } + + return true; +} + +bool isConnected() { + return (Wifi_AssocStatus() == ASSOCSTATUS_ASSOCIATED); +} + +void disconnect() { if(isConnected()) { - Tiki::Debug::printf("Disconnecting Wifi\n"); - Wifi_DisconnectAP(); - } -} - -} // namespace Net - -} // namespace Tiki + Tiki::Debug::printf("Disconnecting Wifi\n"); + Wifi_DisconnectAP(); + } +} + +} // namespace Net + +} // namespace Tiki Modified: tiki/src/base/debug.cpp =================================================================== --- tiki/src/base/debug.cpp 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/src/base/debug.cpp 2007-11-05 17:05:44 UTC (rev 526) @@ -15,36 +15,36 @@ using namespace Tiki::Debug; int Debug::printf( const char * fmt, ... ) { - // This unfortunately has to go elsewhere for Win32 since it chops off any - // console output in a GUI app. + if(g_tiki_init_flags & TIKI_INIT_DEBUG_CONSOLE) { #if TIKI_PLAT == TIKI_WIN32 - va_list args; - char buffer[ 16 * 1024 ]; - va_start( args, fmt ); - int i = vsprintf( buffer, fmt, args ); - va_end( args ); + va_list args; + char buffer[ 16 * 1024 ]; + va_start( args, fmt ); + int i = vsprintf( buffer, fmt, args ); + va_end( args ); - OutputDebugString( buffer ); + OutputDebugString( buffer ); - return i; + return i; #elif TIKI_PLAT == TIKI_NDS - va_list args; - char buffer[ 1024 ]; - va_start( args, fmt ); - int i = vsprintf( buffer, fmt, args ); - va_end( args ); + va_list args; + char buffer[ 1024 ]; + va_start( args, fmt ); + int i = vsprintf( buffer, fmt, args ); + va_end( args ); - iprintf(buffer); - return i; + iprintf(buffer); + return i; #else + va_list args; - va_list args; + va_start( args, fmt ); + int i = vprintf( fmt, args ); + va_end( args ); - va_start( args, fmt ); - int i = vprintf( fmt, args ); - va_end( args ); - - return i; + return i; #endif + } + return 0; } Modified: tiki/src/gl/gl.cpp =================================================================== --- tiki/src/gl/gl.cpp 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/src/gl/gl.cpp 2007-11-05 17:05:44 UTC (rev 526) @@ -42,7 +42,7 @@ Tiki::Math::Vector screen = getScreenExtents(); - glViewport( 0, 0, screen.x, screen.y ); + glViewport( 0, 0, (GLsizei)screen.x, (GLsizei)screen.y ); glClearDepth( 0.0f ); #if TIKI_PLAT != TIKI_DC glClear( GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT + GL_STENCIL_BUFFER_BIT ); Modified: tiki/src/net/http/useragent.cpp =================================================================== --- tiki/src/net/http/useragent.cpp 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/src/net/http/useragent.cpp 2007-11-05 17:05:44 UTC (rev 526) @@ -350,7 +350,15 @@ } } - Buffer *fullBuf = new Buffer(1); + Buffer *fullBuf; + if(responseSize == -1) + { + fullBuf = new Buffer(1); + } + else + { + fullBuf = new Buffer(responseSize); + } if(!response->getHeaderParam("Transfer-Encoding").compare("chunked")) { Tiki::Debug::printf("Encoding is chunked\n"); @@ -384,8 +392,18 @@ if(chunkBuf->getUsedDataLen() < sizeDecoded) { size_t needed = sizeDecoded - chunkBuf->getUsedDataLen(); + Buffer *chunkBuf2; + if(needed > 4096) { + chunkBuf2 = new Buffer(4096); + } + else { + chunkBuf2 = new Buffer(needed); + } while(needed > 0) { - Buffer *chunkBuf2 = new Buffer(needed); + if(needed < chunkBuf2->getDataLen()) { + delete chunkBuf2; + chunkBuf2 = new Buffer(needed); + } socket->recv(chunkBuf2); chunkBuf->append(chunkBuf2); if(chunkBuf2->getUsedDataLen() > 0) { @@ -394,9 +412,9 @@ emit( "progressUpdate", progress ); delete progress; } - needed -= chunkBuf2->getUsedDataLen(); - delete chunkBuf2; + needed -= chunkBuf2->getUsedDataLen(); } + delete chunkBuf2; } totalSize += chunkBuf->getUsedDataLen(); fullBuf->append(chunkBuf); @@ -417,8 +435,18 @@ if(chunkBuf->getUsedDataLen() < sizeDecoded) { sizeDecoded -= chunkBuf->getUsedDataLen(); + Buffer *chunkBuf2; + if(sizeDecoded > 4096) { + chunkBuf2 = new Buffer(4096); + } + else { + chunkBuf2 = new Buffer(sizeDecoded); + } while(sizeDecoded > 0) { - Buffer *chunkBuf2 = new Buffer(sizeDecoded); + if(sizeDecoded < chunkBuf2->getDataLen()) { + delete chunkBuf2; + chunkBuf2 = new Buffer(sizeDecoded); + } socket->recv(chunkBuf2); chunkBuf->append(chunkBuf2); if(chunkBuf2->getUsedDataLen() > 0) { @@ -428,10 +456,11 @@ delete progress; } sizeDecoded -= chunkBuf2->getUsedDataLen(); - delete chunkBuf2; } + delete chunkBuf2; } fullBuf->append(chunkBuf); + delete chunkBuf; } else { Modified: tiki/win32/src/platgl.cpp =================================================================== --- tiki/win32/src/platgl.cpp 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/win32/src/platgl.cpp 2007-11-05 17:05:44 UTC (rev 526) @@ -382,12 +382,3 @@ // the frame proper e.g. loading textures will not work. // wglMakeCurrent(NULL, NULL); } - - - - - - - - - Modified: tiki/win32/src/platnet.cpp =================================================================== --- tiki/win32/src/platnet.cpp 2007-11-04 17:20:24 UTC (rev 525) +++ tiki/win32/src/platnet.cpp 2007-11-05 17:05:44 UTC (rev 526) @@ -15,7 +15,7 @@ namespace Net { - DWORD connectionFlags; +DWORD connectionFlags; void init() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |