void KrEncoder::IsoToSource( GlFixed x, GlFixed y, GlFixed isoWidth, GlFixed sourceW, GlFixed sourceH, GlFixed* sourceX, GlFixed* sourceY, int rotation, GlFixed increment ) { // x, y are in iso coordinates. GlFixed isoHeight = isoWidth / 2; switch( rotation ) { case 90: { *sourceX = (sourceW - increment) - x * sourceW / ( isoWidth ) - y * sourceH / ( isoHeight ); *sourceY = x * sourceW / ( isoWidth ) - y * sourceH / ( isoHeight ); } break; case 180: { *sourceX = (sourceW - increment) - x * sourceW / ( isoWidth ) + y * sourceH / ( isoHeight ); *sourceY = (sourceH - increment) - x * sourceW / ( isoWidth ) - y * sourceH / ( isoHeight ); } break; case 270: { *sourceX = x * sourceW / ( isoWidth ) + y * sourceH / ( isoHeight ); *sourceY = (sourceH-increment) - x * sourceW / ( isoWidth ) + y * sourceH / ( isoHeight ); } break; default: { GLASSERT( x <= isoWidth ); GLASSERT( y <= isoHeight ); *sourceX = x * sourceW / ( isoWidth ) - y * sourceH / ( isoHeight ); *sourceY = x * sourceW / ( isoWidth ) + y * sourceH / ( isoHeight ); } break; } }
void KrDom::ReadTileAttributes( const TiXmlNode* node, KrDom::Tile* frame ) { TiXmlElement* ele = node->ToElement(); GLASSERT( ele ); if ( !ele ) return; ele->Attribute( "x", &frame->x ); ele->Attribute( "y", &frame->y ); ele->Attribute( "size", &frame->size ); }
void BemGame::SetupLeftWindow() { GlFixed scale = 0.3; // Set window #3 to be cached scaled. Cached scaling doesn't // do anything good for an alpha channel, so selectively cache. KrResource* resource = engine->Vault()->GetResource( KYRATAG_SPRITE, BEM_ROOM | BEM_FLOOR ); GLASSERT( resource ); resource->CacheScale( scale, scale ); resource = engine->Vault()->GetResource( KYRATAG_TILE, BEM_SPACE ); GLASSERT( resource ); resource->CacheScale( scale, scale ); resource = engine->Vault()->GetResource( KYRATAG_SPRITE, BEM_ROOM | BEM_PLASMA_PLANT ); GLASSERT( resource ); resource->CacheScale( scale, scale ); resource = engine->Vault()->GetResource( KYRATAG_SPRITE, BEM_BRAIN ); GLASSERT( resource ); resource->CacheScale( scale, scale ); resource = engine->Vault()->GetResource( KYRATAG_SPRITE, BEM_DRONE ); GLASSERT( resource ); resource->CacheScale( scale, scale ); canvas->SetVisible( false, 3 ); int x, y; GlFixed fx, fy; isoMath->TileToScreen( MAPX/2, MAPY/2, 0, &x, &y ); fx = x; fy = y; fx *= scale; fy *= scale; engine->Tree()->Root()->SetPos( -fx.ToInt() + engine->ScreenBounds(3).Width() / 2, -fy.ToInt() + engine->ScreenBounds(3).Height() / 2, 3 ); engine->Tree()->Root()->SetScale( scale, scale, 3 ); }
void KrButton::PlaceText() { GLASSERT( Engine() ); if ( scheme.font ) { textBox = new KrTextBox( scheme.font, width, scheme.font->FontHeight(), 0, KrTextBox::CENTER ); textBox->SetPos( 0, ( height - scheme.font->FontHeight() ) / 2 ); textBox->SetText( text, 0 ); //maks Engine()->Tree()->AddNode( holder, textBox ); textBox->SetZDepth( TEXT_DEPTH ); } }
PyObject * _wrap_smpeg_render_final (PyObject *self, PyObject *args) { PyObject *py_s; PyObject *py_v; int x, y; if (!PyArg_ParseTuple (args, "OOii:render_final", &py_s, &py_v, &x, &y)) return NULL; GLASSERT (py_s && py_s != Py_None); GLASSERT (py_v && py_v != Py_None); SMPEG *smpeg = AS_PTR(SMPEG, py_s); GLASSERT (smpeg); SDL_Surface *surface = AS_PTR(SDL_Surface, py_v); GLASSERT (surface); SMPEG_renderFinal (smpeg, surface, x, y); RETURN_NONE; }
bool KrConsole::HandleWidgetEvent( KrWidget* source, U32 event, U32 data, const SDL_Event* key, const char* command, const char* arg ) { GLASSERT( source == commandLine ); if ( event == IKrWidgetListener::ACTIVATED ) { ProcessEnterKey(); } return true; // A console handles all keys. }
GlPerformance::~GlPerformance() { #ifdef _WIN32 QueryPerformanceCounter( (LARGE_INTEGER*) (&end) ); #else end = SDL_GetTicks(); #endif S64 delta = ( end - start ); GLASSERT( delta >= 0 ); data->totalTime += delta; }
void DebugDelete( void* mem, bool arrayType ) { #ifdef GRINLIZ_DEBUG_MEM_DEEP MemHeapCheck(); #endif if ( mem ) { MemCheckHead* head = (MemCheckHead*)((unsigned char*)mem-sizeof(MemCheckHead)); MemCheckTail* tail = (MemCheckTail*)((unsigned char*)mem+head->size); // For debugging, so if the asserts do fire, we still have a copy of the values. MemCheckHead aHead = *head; MemCheckTail aTail = *tail; GLASSERT( head->magic == MEM_MAGIC0 ); GLASSERT( tail->magic == MEM_MAGIC1 ); // A bug in the OpenGL driver on Mac fires this. #if !defined( __APPLE__ ) GLASSERT( head->arrayType == arrayType ); #endif if ( head->prev ) head->prev->next = head->next; else root = head->next; if ( head->next ) head->next->prev = head->prev; if ( checking ) { ++memDeleteCount; memTotal -= head->size; } head->magic = MEM_DELETED0; tail->magic = MEM_DELETED1; free(head); } }
void GLDrawWork::onDraw(GLTexture** src, int number, GLvboBuffer* vs, GLvboBuffer* ts) { GLASSERT(NULL!=vs); GLASSERT(NULL!=ts); GLASSERT(NULL!=src); GLASSERT(number == mInputPos.size()); mProgram->use(); this->onSetupVertex(); this->onSetupFragment(); for (int i=0; i<number; ++i) { GLASSERT(NULL!=src[i]); src[i]->use(mInputPos[i], i); } vs->use(mVertexPos); ts->use(mTextureCorderPos); for (auto iter:mUniforms) { GLProgram::setUniform(iter.second, iter.first); } vs->draw(); }
GLWorkThread* OpenGLWorker::getInstance() { if (NULL == gInstance) { GLAutoLock _l(gLock); if (NULL == gInstance) { gInstance = new OpenGLWorker; } } GLASSERT(NULL!=gInstance); return gInstance->mThread; }
NS_GL_BEGIN static BOOL VerifyMultiSample(PIXELFORMATDESCRIPTOR& pfd, int& pixelFormat) { HWND hWnd = CreateWindow(L"BUTTON", NULL, WS_POPUP, 0, 0, 0, 0, GetDesktopWindow(), NULL, NULL, NULL); GLASSERT(hWnd != NULL); HDC hDC = GetDC(hWnd); pixelFormat = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, pixelFormat, &pfd); HGLRC hGL = wglCreateContext(hDC); wglMakeCurrent(hDC, hGL); BOOL success = FALSE; typedef BOOL (WINAPI* pfnChooseProc)(HDC, const int*, const float*, UINT, int*, UINT*); pfnChooseProc wglChoose = (pfnChooseProc)wglGetProcAddress("wglChoosePixelFormatARB"); if (wglChoose == NULL) goto Cleanup; UINT nFormats; float fAttr[] = {0, 0}; int iAttr[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, WGL_COLOR_BITS_ARB, 32, WGL_ALPHA_BITS_ARB, 8, WGL_DEPTH_BITS_ARB, 24, WGL_STENCIL_BITS_ARB, 8, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, WGL_SAMPLES_ARB, 4, 0, 0 }; if (wglChoose(hDC, iAttr, fAttr, 1, &pixelFormat, &nFormats) && nFormats >= 1) { success = TRUE; goto Cleanup; } iAttr[19] = 2; success = wglChoose(hDC, iAttr, fAttr, 1, &pixelFormat, &nFormats) && nFormats >= 1; Cleanup: wglMakeCurrent(hDC, 0); wglDeleteContext(hGL); ReleaseDC(hWnd, hDC); DestroyWindow(hWnd); return success; }
PyObject * _wrap_tile_size (PyObject *self, PyObject *args) { PyObject *py_r; if (!PyArg_ParseTuple (args, "O:size", &py_r)) return NULL; KrTile *t = AS_PTR (KrTile, py_r); GLASSERT (t); int size = t->Size(); return PyInt_FromLong (size); }
PyObject * _wrap_video_del (PyObject *self, PyObject *args) { PyObject *py_v; if (!PyArg_ParseTuple (args, "O:del", &py_v)) return NULL; SDL_Surface *s = AS_PTR (SDL_Surface, py_v); GLASSERT (s); SDL_Quit (); RETURN_NONE; }
void TestBlitter::CalcColorChannelFixed( U8 newColor, U8 newAlpha, U8 surfaceColor, U8 cformM, U8 cformB, U8 cformAlpha, GlFixed* c ) { GlFixed fix1 = 1; GlFixed fix255 = 255; GlFixed alpha = newAlpha / fix255 * cformAlpha / fix255; GLASSERT( alpha >= 0 ); GLASSERT( alpha <= 1 ); GlFixed fNewColor = newColor; GlFixed fSurfaceColor = surfaceColor; GlFixed fCformM = cformM; GlFixed fCformB = cformB; *c = alpha * ( fNewColor / fix255 * fCformM + fCformB ) + ( fix1 - alpha ) * fSurfaceColor; }
PyObject * _wrap_tile_set_rotation (PyObject *self, PyObject *args) { PyObject *py_r; int angle; if (!PyArg_ParseTuple (args, "Oi:set_rotation", &py_r, &angle)) return NULL; KrTile *t = AS_PTR (KrTile, py_r); GLASSERT (t); t->SetRotation(angle); RETURN_NONE; }
void EdStateMovie::FrameTick() { KrImNode* image = shared->Engine()->Tree()->FindNodeById( 0 ); GLASSERT( image ); KrSprite* sprite = image->ToSprite(); GLASSERT( sprite ); sprite->DoStep(); int x = sprite->CompositeXForm(0).x.ToInt(); int y = sprite->CompositeXForm(0).y.ToInt(); KrRect screen = shared->Engine()->ScreenBounds(); GlFixed scale = movieNode->XScale(); GlFixed inverse = GlFixed( 1 ) / scale; if ( x < 0 ) sprite->SetPos( (inverse * screen.Width()).ToInt(), sprite->Y() ); if ( x > screen.Width() ) sprite->SetPos( 0, sprite->Y() ); if ( y < 0 ) sprite->SetPos( sprite->X(), (inverse*screen.Height()).ToInt() ); if ( y > screen.Height() ) sprite->SetPos( sprite->X(), 0 ); }
void KrTile::Draw( KrPaintInfo* paintInfo, const KrRect& clip ) { GLASSERT( IsVisible() ); if ( bounds.Intersect( clip ) ) { resource->Draw( paintInfo, CompositeXForm(), rotation, CompositeCForm(), clip, CompositeQuality(), TreeDepth() ); } }
void TransformXY( int x0, int y0, int* x1, int* y1 ) { // As a way to do scaling outside of the core, translate all // the mouse coordinates so that they are reported in opengl // window coordinates. if ( rotation == 0 ) { *x1 = x0; *y1 = screenHeight-1-y0; } else if ( rotation == 1 ) { *x1 = x0; *y1 = screenHeight-1-y0; } else { GLASSERT( 0 ); } }
PyObject * _wrap_tile_del (PyObject *self, PyObject *args) { PyObject *py_r; if (!PyArg_ParseTuple (args, "O:del", &py_r)) return NULL; KrTile *t = AS_PTR (KrTile, py_r); GLASSERT (t); if (t->GetUserData() != KrTile_TYPE) { RETURN_NONE; } delete t; RETURN_1; }
PyObject * _wrap_sprite_del (PyObject *self, PyObject *args) { PyObject *py_r; if (!PyArg_ParseTuple (args, "O:del", &py_r)) return NULL; KrSprite *r = AS_PTR (KrSprite, py_r); GLASSERT (r); if (r->GetUserData() != KrSprite_TYPE) { RETURN_NONE; } delete r; RETURN_1; }
bool KrEncoder::EndDat() { StartTag( KYRATAG_END ); EndTag(); SDL_RWseek( stream, numRlePos, SEEK_SET ); GLASSERT( numRGBA >= numSegment ); //GLASSERT( numSegment >= numLine ); //maks: Is be possible (GE_N.bmp) SDL_WriteLE32( stream, numRGBA ); SDL_WriteLE32( stream, numLine ); SDL_WriteLE32( stream, numSegment ); #ifdef DEBUG GLOUTPUT( "Tally count: rgba=%d line=%d segment=%d\n", numRGBA, numLine, numSegment ); #endif cachedWrite.Flush(); return true; }
void ScalingTest::AddBackground() { int i, j, k; KrCanvasResource* back[3]; for( k=0; k<3; ++k ) { back[k] = new KrCanvasResource( "backgroundRes", 100, 100, false ); engine->Vault()->AddResource( back[k] ); for ( i=0; i<100; i++ ) { for( j=0; j<100; j++ ) { KrRGBA* pixel = back[k]->Pixels() + i + j*back[k]->Width(); if ( ( ( i / 10 ) & 0x01 ) == ( ( j / 10 ) & 0x01 ) ) pixel->array[KrRGBA::START + k] = 100; else pixel->array[KrRGBA::START + k] = 160; } } back[k]->Refresh(); } int w = engine->ScreenBounds().Width(); int h = engine->ScreenBounds().Height(); int count = 0; for ( i=0; i <= w / 100; i++ ) { for ( j=0; j <= h / 100; j++ ) { KrCanvas* canvas = new KrCanvas( back[count%3] ); canvas->SetPos( i*canvas->Width(), j*canvas->Height() ); GLASSERT( canvas ); engine->Tree()->AddNode( 0, canvas ); ++count; } } }
PyObject * _wrap_sprite_get_bounding_box (PyObject *self, PyObject *args) { PyObject *py_e; int window; if (!PyArg_ParseTuple (args, "Oi:get_bounding_box", &py_e, &window)) return NULL; KrSprite *e = AS_PTR (KrSprite, py_e); GLASSERT (e); KrRect rect; e->GetBoundingBox(&rect, window); PyObject *t = PyTuple_New (4); PyTuple_SetItem (t, 0, PyInt_FromLong (rect.xmin)); PyTuple_SetItem (t, 1, PyInt_FromLong (rect.ymin)); PyTuple_SetItem (t, 2, PyInt_FromLong (rect.xmax)); PyTuple_SetItem (t, 3, PyInt_FromLong (rect.ymax)); return t; }
unsigned GlPrime( unsigned close, int relationship ) { static unsigned count = 0; if ( count == 0 ) { // Get the size of the table. while ( gPrime[count] ) ++count; } unsigned low = 0; unsigned high = count - 1; unsigned pivot = ( high + low ) >> 1; while ( high > low ) { if ( close > gPrime[ pivot ] ) low = pivot + 1; else high = pivot - 1; pivot = ( high + low ) >> 1; } GLASSERT( low == high ); if ( relationship < 0 ) { while ( low > 0 && gPrime[ low ] > close ) --low; } else if ( relationship > 0 ) { while ( low < count && gPrime[ low ] < close ) ++low; } return gPrime[ low ]; }
bool KrEncoder::EncodeFont( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console ) { GLASSERT( surface->format->BytesPerPixel == 4 ); // Create or locate the font. if ( vault.GetFontResource( allInfo.name ) ) { gedString aux(allInfo.name); console->Print( "ERROR: Font %s encoded twice.\n", aux.c_str() ); return false; } int type = KrFontResource::FIXED; if ( allInfo.subType == SUBTYPE_SFONT ) type = KrFontResource::SFONT; if ( type == KrFontResource::FIXED && allInfo.fontLength == 0 ) { console->Print( "ERROR: Fixed font created without the 'length' attribute.\n" ); return false; } KrPaintInfo info( surface ); KrFontResource* fontRes = new KrFontResource( allInfo.name, &info, allInfo.fontStart, allInfo.space, type, allInfo.fontLength ); vault.AddResource( fontRes ); gedString aux(allInfo.name); console->Print( "Font: %s\n", aux.c_str() ); return true; }
KrConsole::KrConsole( int _width, int _height, int _lineSpacing, const KrScheme& scheme ) : KrWidget( scheme ) { // cursorPos = 0; // defaultHandler = 0; commandBufSize = 0; commandBufNode = 0; background = 0; backgroundRes = 0; font = scheme.font; GLASSERT( font ); width = _width; height = _height; lineSpacing = _lineSpacing; commandLine = 0; // Create the cursor, as a child of the textbox. // cursorRes = new KrCanvasResource( "cursor", // CURSOR_WIDTH, // font->FontHeight(), // false ); // int i, j; // KrRGBA* pixels = cursorRes->Pixels(); // KrRGBA white; // white.Set( 255, 255, 255, 255 ); // // for( j=0; j<font->FontHeight(); j++ ) // { // for ( i=0; i<CURSOR_WIDTH; i++ ) // { // pixels[ i + j*cursorRes->Width() ] = white; // } // } }
void BemGame::ProcessMap( Actor* act ) { // Check the current map location and calculate the next. // Turn if we need to. int nX, nY; // Advance the x and y to reflect current map coordinates: switch ( act->dir ) { case NORTH: act->mapY++; break; case SOUTH: act->mapY--; break; case EAST: act->mapX++; break; case WEST: act->mapX--; break; default: GLASSERT( 0 ); } // See where we are going next: int sign = 1; if ( tick & 0x01 ) sign = -1; while ( !NextMap( act->dir, act->mapX, act->mapY, &nX, &nY ) ) { act->dir += sign; act->dir &= 3; } act->sprite->SetAction( dirMap[ act->dir ] ); }
void SharedStateData::SetCurrentTile( EdWidget* tile ) { if ( currentFrame ) currentFrame->Select( false ); if ( currentAction ) currentAction->Select( false ); if ( currentSprite ) currentSprite->Select( false ); if ( currentTile ) currentTile->Select( false ); currentObject = TILE; if ( tile ) { GLASSERT( tile->Type() == EdWidget::TILE ); currentTile = (EdWidgetTile*) tile; currentTile->Select( true ); } else { currentTile = 0; } currentFrame = 0; currentAction = 0; currentSprite = 0; SetInfoBox( true ); }
bool BemGame::NextMap( int dir, int x, int y, int* nx, int* ny ) { *nx = x; *ny = y; switch ( dir ) { case NORTH: *ny = y+1; break; case SOUTH: *ny = y-1; break; case EAST: *nx = x+1; break; case WEST: *nx = x-1; break; default: GLASSERT( 0 ); } return map[*ny][*nx] != 0; }
PyObject * _wrap_smpeg_new (PyObject *self, PyObject *args) { PyObject *py_e; PyObject *py_v; char *filename; int audio; if (!PyArg_ParseTuple (args, "OOsi:new", &py_e, &py_v, &filename, &audio)) return NULL; GLASSERT (py_e && py_e != Py_None); GLASSERT (py_v && py_v != Py_None); GLASSERT (filename); KrEngine *engine = AS_PTR(KrEngine, py_e); GLASSERT (engine); SDL_Surface *surface = AS_PTR(SDL_Surface, py_v); GLASSERT (surface); SMPEG_Info info; SMPEG *smpeg = SMPEG_new (filename, &info, 0); GLASSERT (smpeg); if (audio) { SDL_AudioSpec spec; SMPEG_enableaudio (smpeg, 0); Mix_QuerySpec (&spec.freq, &spec.format, (int *)&spec.channels); SMPEG_actualSpec(smpeg, &spec); Mix_HookMusic (SMPEG_playAudioSDL, smpeg); SMPEG_enableaudio (smpeg, 1); } else { SMPEG_enableaudio (smpeg, 0); } SMPEG_setdisplay (smpeg, surface, NULL, NULL); return PyCObject_FromVoidPtr (smpeg, NULL); }