void sSetColor2D(sInt colid,sU32 color) { sVERIFY(colid>=0 && colid<MAX_COLORS); if(Color[colid][1] != color) { XColor col; col.red = ((color>>16) & 0xff)*0x101; col.green = ((color>> 8) & 0xff)*0x101; col.blue = ((color>> 0) & 0xff)*0x101; col.flags = DoRed|DoGreen|DoBlue; if(!XAllocColor(sXDisplay(),sXColMap,&col)) sFatal(L"XAllocColor failed"); Color[colid][0] = col.pixel; Color[colid][1] = color; XRenderColor rc; rc.red = col.red; rc.green = col.green; rc.blue = col.blue; rc.alpha = 0xffff; if(!XftColorAllocValue(sXDisplay(),sXVisual,sXColMap,&rc,&ColorXFT[colid])) sFatal(L"XftColorAllocValue failed"); }
sThreadLock::~sThreadLock() { sASSERT(lock); if(pthread_mutex_destroy((pthread_mutex_t *)lock)) sFatal("pthread_mutex_destroy failed"); delete (pthread_mutex_t *) lock; }
bool sThreadLock::TryLock() { int err = pthread_mutex_lock((pthread_mutex_t *)lock); if(err==EBUSY) return 0; if(err) sFatal("pthread_mutex_lock failed"); return 1; }
void sRender2DBegin(sInt xs,sInt ys) { HDC screendc; sVERIFY(Render2DMode==0); sVERIFY(WMPaintDC==0) WMPaintDC = sGDIDC; Render2DMode = 1; Render2DSizeX = xs; Render2DSizeY = ys; screendc = GetDC(0); sGDIDC = CreateCompatibleDC(screendc); if(sGDIDC==0) sFatal(L"could not create GDI-DC for bitmap rendering"); Render2DBM = CreateCompatibleBitmap(screendc,xs,ys); if(Render2DBM==0) sFatal(L"could not create GDI-BM for bitmap rendering"); ReleaseDC(0,screendc); SelectObject(sGDIDC,Render2DBM); }
void Rem(void *ptr) { if(Active==0) Init(); if(Active==2) return; // find node uint hash = sChecksumCRC32((const uint8 *)&ptr,sizeof(void *)) & (HashSize-1); Leak **np; Leak *n; MemLeakLock->Lock(); np = &Hash[hash]; for(;;) { n = *np; if(!n) { sFatal("tried to free() memory that was not allocated!"); } if(n->Ptr == ptr) { // remove from list *np = n->Next; LeakCount--; // add to free list n->Next = Free; Free = n; // done break; } np = &n->Next; } MemLeakLock->Unlock(); }
void InitGDI() { ClipboardFormat = RegisterClipboardFormatW(L"Altona Clipboard Object"); if(ClipboardFormat==0) sFatal(L"failed to register clipboard format"); // if(sGetSystemFlags() & sISF_2D) { sU32 color = GDICOL(0); for(sInt i=0;i<MAX_BRUSHES;i++) { BrushColor[i] = color; BrushHandle[i] = CreateSolidBrush(color); BrushPen[i] = CreatePen(PS_SOLID,0,color); } for(sInt i=0;i<MAX_CLIPS;i++) { ClipStack[i] = CreateRectRgn(0,0,0,0); } static const LPCWSTR cursormap[] = { 0, IDC_ARROW, IDC_WAIT, IDC_CROSS, IDC_HAND, IDC_IBEAM, IDC_NO, IDC_SIZEALL, IDC_SIZENS, IDC_SIZEWE, IDC_SIZENWSE, IDC_SIZENESW, }; Cursors[0] = 0; for(sInt i=1;i<sMP_MAX;i++) Cursors[i] = LoadCursorW(0,cursormap[i]); } }
void sThreadLock::Unlock() { if(pthread_mutex_unlock((pthread_mutex_t *)lock)) sFatal("pthread_mutex_unlock failed"); }
sThreadLock::sThreadLock() { lock = new pthread_mutex_t; if(pthread_mutex_init((pthread_mutex_t *)lock,0)) sFatal("pthread_mutex_init failed"); }
sBool sAppHandler(sInt code,sDInt value) { sInt beat; static const sU8 *data; sViewport vp,clearvp; sInt i,max; sF32 curfps; static sF32 oldfps; static sInt FirstTime,ThisTime,LastTime; static sInt framectr=0; sRect r; KOp *root; switch(code) { case sAPPCODE_CONFIG: #if !LINKEDIN data = PtrTable[0]; //#if !sINTRO if(((sInt)data)==0x54525450) { data = sSystem->LoadFile(sSystem->GetCmdLine()); if(data==0) { data = sSystem->LoadFile("id08.kx"); if(data==0) sSystem->Abort("need data file"); } } //#endif #else data = DebugData; #endif #if sCONFIGDIALOG { sChar *name = 0; if(data[0]&1) name = (sChar *)(data+4); return ConfigDialog(101,name) == 1; } #endif break; case sAPPCODE_INIT: #if !sCONFIGDIALOG #if !LINKEDIN data = PtrTable[0]; if(((sInt)data)==0x54525450) { data = sSystem->LoadFile(sSystem->GetCmdLine()); if(!data) sFatal("need data file"); } #else data = DebugData; #endif #endif Document = new KDoc; Document->Init(data); Environment = new KEnvironment; Sound = 0; // low texture size: only for texture quality setting "normal" GenBitmapTextureSizeOffset = (IntroTexQuality >= 1) ? 0 : -1; GenBitmapDefaultFormat = (IntroTexQuality >= 2) ? sTF_A8R8G8B8 : sTF_DXT1; sInitPerlin(); // determine render viewport vp.Init(); DetermineTargetViewport(vp); RenderTargetManager = new RenderTargetManager_; RenderTargetManager->SetMasterViewport(vp); // preallocate some rendertargets Engine = new Engine_; RenderTargetManager->Add(0x00010000,0,0); RenderTargetManager->Add(0x00020010,512,256); // glare temp 1 RenderTargetManager->Add(0x00020011,256,128); // glare temp 2 GenOverlayInit(); GenOverlayManager->SetMasterViewport(vp); if(!IntroShadows) Engine->SetUsageMask(~(1<<ENGU_SHADOW)); #if sLINK_KKRIEGER Game = new KKriegerGame; Game->Init(); #else Game = 0; #endif #if LOADERTUNE // start loader tune Player = new sViruz2; Player->Load(LoaderTune,LoaderTuneSize); Player->Start(0); sSystem->SetSoundHandler(MusicPlayerHandler,SOUNDALIGN,Player); #endif sFloatFix(); i = sSystem->GetTime(); Environment->Splines = &Document->Splines.Array; Environment->SplineCount = Document->Splines.Count; Environment->Game = Game; Environment->InitView(); Environment->InitFrame(0,0); Document->Precalc(Environment); Environment->ExitFrame(); // stop loader tune #if LOADERTUNE sSystem->SetSoundHandler(0,0,0); delete Player; Player = 0; #endif #if WAITFORKEY sSystem->WaitForKey(); #endif if(Document->SongSize) { #if sINTRO Sound = new CV2MPlayer; #if sLINK_KKRIEGER if(Document->SampleSize) RenderSoundEffects(Document,Document->SampleData); #endif Sound->Init(); Sound->Open(Document->SongData); Sound->Play(0); SoundTimer = 0; sSystem->SetSoundHandler(IntroSoundHandler,SOUNDALIGN); #else // !sINTRO #if sLINK_OGG Player = new sOGGDecoder; #else Player = new sViruz2; #endif Player->Load(Document->SongData,Document->SongSize); Player->Start(0); sSystem->SetSoundHandler(MusicPlayerHandler,SOUNDALIGN,Player); #endif } #if sLINK_KKRIEGER Game->ResetRoot(Environment,Document->RootOps[Document->CurrentRoot],1); #endif FirstTime = sSystem->GetTime(); LastTime = 0; oldfps = 0.0f; #if sNOCRT sDPrintF("memory allocated: %d bytes\n",MallocSize); #endif break; #if !sINTRO case sAPPCODE_EXIT: sSystem->SetSoundHandler(0,0,0); if(Sound) { CV2MPlayer *old; old = Sound; Sound = 0; delete old; } delete Player; delete Environment; #if sLINK_KKRIEGER Game->Exit(); delete Game; #endif Document->Exit(); delete Document; delete RenderTargetManager; delete Engine; GenOverlayExit(); break; #endif case sAPPCODE_PAINT: // tick processing (moved up to reduce input lag by 1 frame) ThisTime = sSystem->GetTime() - FirstTime; #if sLINK_KKRIEGER beat = sMulDiv(ThisTime,Document->SongBPM,60000); #else if(Document->BuzzTiming) { sInt sample; sample = Document->SongSize ? sSystem->GetCurrentSample() : sMulDiv(ThisTime,44100,1000); beat = sDivShift(sample,60*44100/((Document->SongBPM>>16)*8)) / 8; } else
static void InitXLib() { for(sInt i=0;i<MAX_CLIPS;i++) ClipStack[i] = XCreateRegion(); EmptyRegion = XCreateRegion(); UpdateRegion = XCreateRegion(); static const int shapeInd[] = { 0, XC_left_ptr, XC_watch, XC_crosshair, XC_hand2, XC_xterm, XC_X_cursor, XC_fleur, XC_sb_v_double_arrow, XC_sb_h_double_arrow, XC_bottom_right_corner, // poor match! XC_bottom_left_corner, // poor match! }; Cursors[0] = 0; for(sInt i=1;i<sMP_MAX;i++) Cursors[i] = XCreateFontCursor(sXDisplay(),shapeInd[i]); if(sGetSystemFlags() & sISF_2D) { XRenderColor rc; XftColor blackColor; sClear(rc); rc.alpha = 0xffff; XftColorAllocValue(sXDisplay(),sXVisual,sXColMap,&rc,&blackColor); for(sInt i=0;i<MAX_COLORS;i++) { Color[i][0] = Color[i][1] = 0; ColorXFT[i] = blackColor; } XDraw = XftDrawCreate(sXDisplay(),sXWnd,DefaultVisual(sXDisplay(),sXScreen),sXColMap); if(!XDraw) sFatal(L"XftDrawCreate failed!"); // initialize x render extension int major,minor; XRenderQueryVersion(sXDisplay(),&major,&minor); sLogF(L"xlib",L"XRender %d.%d found\n",major,minor); XRenderPictFormat *fmt = XRenderFindVisualFormat(sXDisplay(),sXVisual); if(!fmt) sFatal(L"XRenderFindVisualFormat failed on default visual!"); XRenderPictureAttributes attr; attr.graphics_exposures = False; XPict = XRenderCreatePicture(sXDisplay(),sXWnd,fmt,CPGraphicsExposure,&attr); if(!XPict) sFatal(L"XRenderCreatePicture for main picture failed!"); XFmtARGB = XRenderFindStandardFormat(sXDisplay(),PictStandardARGB32); if(!XFmtARGB) sFatal(L"XRenderFindStandardFormat failed on display!"); } ForegroundCol = -1; }
sU8 *sFile::MapAll() { sFatal(L"not implemented"); }
void sTriggerEvent(sInt) { sFatal(L"not implemented"); }
void sThreadLock::Unlock() { sFatal(L"not implemented"); }