Esempio n. 1
0
void GfxBody::destroy (void)
{
    if (dead) THROW_DEAD(className);
    destroyGraphics();
    setFirstPerson(false);  // Remove it from the set.
    GfxFertileNode::destroy();
}
Esempio n. 2
0
/*
=====================
	destroySystem
=====================
*/
BOOL destroySystem() {
	TCHAR szPath[MAX_PATH] = {0};

	//end all running games
	endAllGames();
	
	botDestroy();
	
	N_CloseTrace();

	//destroy graphics resources
	destroyGraphics( LEFTGAME );
	destroyGraphics( NEUTRAL );

	//winmm
	timeEndPeriod( 1 );
	
	//delete left skin
	if( k_system.hSkinBitmapLeft )
		DeleteObject( k_system.hSkinBitmapLeft );
	
	if( k_system.hSkinBitmapRight )
		DeleteObject( k_system.hSkinBitmapRight );

	if( k_system.pPaths ) {
		N_Free( k_system.pPaths );
	}
	
	if( k_system.pMaps ) {
		N_Free( k_system.pMaps );
	}
	if( k_system.pBots ) {
		N_Free( k_system.pBots );
	}
	
	cfDestroyTable();
	UnbindKeys();
	
#ifdef DEBUG_COMPILE
	N_Sprintf( szPath, MAX_PATH, TEXT( "%s\\leaks.txt" ),
		k_system.szStartDir );
	outputDebugInfo( szPath );
#endif

	return TRUE;
}
Esempio n. 3
0
void GfxBody::reinitialise (void)
{
    APP_ASSERT(mesh->isLoaded());

    destroyGraphics();

    for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) {
        Ogre::SubMesh *sm = mesh->getSubMesh(i);
        Sub* sub = new Sub(this, sm);
        subList.push_back(sub);
        GFX_MAT_SYNC;
        std::string matname = apply_map(initialMaterialMap, sm->getMaterialName());
        if (!gfx_material_has(matname)) {
            CERR << "Mesh \"/"<<mesh->getName()<<"\" references non-existing material "
                 << "\""<<matname<<"\""<<std::endl;
            matname = "/system/FallbackMaterial";
        }
        sub->material = gfx_material_get(matname);
    }


    if (!mesh->getSkeleton().isNull()) {
        skeleton = OGRE_NEW Ogre::SkeletonInstance(mesh->getSkeleton());
        skeleton->load();
        numBoneMatrixes = skeleton->getNumBones();
        boneMatrixes      = static_cast<Ogre::Matrix4*>(OGRE_MALLOC_SIMD(sizeof(Ogre::Matrix4) * numBoneMatrixes, Ogre::MEMCATEGORY_ANIMATION));
        boneWorldMatrixes = static_cast<Ogre::Matrix4*>(OGRE_MALLOC_SIMD(sizeof(Ogre::Matrix4) * numBoneMatrixes, Ogre::MEMCATEGORY_ANIMATION));

        mesh->_initAnimationState(&animationState);
    } else {
        skeleton = NULL;
        numBoneMatrixes = 0;
        boneMatrixes      = NULL;
        boneWorldMatrixes = NULL;
    }

    updateBones();
}
Esempio n. 4
0
int main(int argc, char** argv) {
    (void) argc;
    (void) argv;
    /*srand(time(NULL));*/
#ifdef WIN32
    {
        LARGE_INTEGER divisor;
        QueryPerformanceFrequency(&divisor);
        clockDivisor = divisor.QuadPart;
    }
#else
    clockDivisor = CLOCKS_PER_SEC;
#endif
    printf("Starting\nClock divisor: %lu\n", clockDivisor);

    struct graphics g = {
#ifdef SHOWKEYS
        .width = 100, .height = 100,
#else
        .width = 1200,
        .height = 900,
#endif
    };
    initiateGraphics(&g, "Test window");

    if(!g.window) goto CLEANUP;
    /*thread t;*/
    /*newThread(test, NULL, &t);*/

    clockType frameStart, frameEnd, gameStart;
    getClockTime(&frameStart);

    initLogic();
    loadEntities();
    loadTileTextures();
    initializeWorld();
    initializeBullets();
    initializeItems();
    initializeItemFunctions();
    luaStart();

    getClockTime(&gameStart);

    while(1){
        cameraTick();
        renderGraphics(&g);

        oldMouseState = mouseState;
        mouseState = SDL_GetMouseState(&mouseX, &mouseY);
        if(oldMouseState != mouseState){
            mouseEvent();
        }
        for(SDL_Event event; SDL_PollEvent(&event);){
            switch(event.type){
            case SDL_QUIT:
                goto CLEANUP;
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                if(event.key.keysym.scancode == 0x14) goto CLEANUP; //TODO
                keyEvent(event.key);
            break;
            }
        }

        getClockTime(&frameEnd);
        frameTime = getDiffClock(frameStart, frameEnd);
        appTime = getDiffClock(gameStart, frameEnd);
        frameStart = frameEnd;
        gameUpdate();
    }
CLEANUP:

    luaEnd();
    uninitializeItems();
    uninitializeItemFunctions();
    uninitializeBullets();
    uninitializeWorld();
    unloadTileTextures();
    unloadEntities();
    destroyGraphics(&g);

    return 0;
}

float normalRandomFloat(){
    return ((float) rand()) / ((float) RAND_MAX);
}

float randomFloat(float a, float b){
    float diff = b - a;
    return a + normalRandomFloat() * diff;
}
Esempio n. 5
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) {
	wchar_t progname[] = L"CerealBox";


	windata.gameoutput.graphic.width = 1920/2;
	windata.gameoutput.graphic.height = 1080/2;

	windata.running = ootrue;
	windata.gameMemory = (void *) calloc((size_t)gameMemorySize(), 1L);

	oouint audioBufferSize = win32AudioBufferSize();
    windata.gameoutput.audio.buffer = (ooshort *) calloc((size_t)audioBufferSize, 1L);
	oouint audioFramesPerSecond = win32AudioFramesPerSecond();

	WNDCLASSEXW winclass;
	ZeroMemory(&winclass, sizeof(WNDCLASSEXW));

	
	MSG msg;

	winclass.cbSize = sizeof(WNDCLASSEXW);
	winclass.style = CS_DBLCLKS;
	winclass.lpfnWndProc = &winproc;
	winclass.cbClsExtra = 0;
	winclass.cbWndExtra = 0;
	winclass.hInstance = hInst;
	winclass.hIcon = LoadIcon(NULL,IDI_WINLOGO);
	winclass.hCursor = LoadCursor(NULL,IDC_ARROW);
	winclass.lpszClassName = progname;


	if(!RegisterClassExW(&winclass)) {
		return 0;
	}

	oouint startX = 100;
	oouint startY = 100;

	DWORD windowStyle =  WS_SYSMENU|WS_CAPTION|WS_BORDER|WS_OVERLAPPED|WS_VISIBLE|WS_MINIMIZEBOX;

#ifdef OO_FULLSCREEN
	windowStyle = WS_EX_TOPMOST | WS_POPUP;
	win32GetScreenResolution(&windata.gameoutput.graphic.width, &windata.gameoutput.graphic.height);
	startX = 0;
	startY = 0;
#endif
	RECT wr = {0, 0, windata.gameoutput.graphic.width, windata.gameoutput.graphic.height};
	AdjustWindowRect(&wr, windowStyle, FALSE);

	windata.window = CreateWindowW(
		progname,
		progname,
		windowStyle,
		startX,
		startY,
		wr.right - wr.left,
		wr.bottom - wr.top,
		NULL,
		NULL,
		hInst,
		NULL);

	initGraphics(&windata);
	win32AudioInit(windata.window);

	ShowWindow(windata.window,nCmdShow);
	UpdateWindow(windata.window);

	LARGE_INTEGER timeFrequency;
	QueryPerformanceFrequency(&timeFrequency);

	LARGE_INTEGER lastTime;
	ZeroMemory(&lastTime, sizeof(LARGE_INTEGER) );
	LARGE_INTEGER time;
	windata.gameinput.dt = 1.f/60.f;

	windata.windowDC = GetDC(windata.window);

	ooint monitorRefreshHz = 60;
	oofloat frameMs = 1.f / (oofloat)monitorRefreshHz;
	ooint win32RefreshRate = GetDeviceCaps(windata.windowDC, VREFRESH);
	if( win32RefreshRate>1 ) {
		monitorRefreshHz = win32RefreshRate;
		frameMs = 1.f / (oofloat)monitorRefreshHz;
	}

	while( windata.running ) {
		PeekMessage(&msg,NULL,0,0,PM_REMOVE);
		if(msg.message == WM_QUIT) {
			break;
		}


		TranslateMessage(&msg);
		DispatchMessage(&msg);

		win32ProcessMouseEvents(windata.window, &windata);

		QueryPerformanceCounter(&time);
		if( lastTime.QuadPart>0 ) {
			windata.gameinput.dt = (oofloat)(time.QuadPart - lastTime.QuadPart);
			windata.gameinput.dt /= timeFrequency.QuadPart;

			windata.gameoutput.audio.framesToWrite = (oouint)(windata.gameinput.dt*audioFramesPerSecond);
			if(windata.gameoutput.audio.framesToWrite>audioBufferSize) {
				windata.gameoutput.audio.framesToWrite = audioBufferSize;
			}

			advanceGame(windata.gameMemory,&windata.gameinput,&windata.gameoutput);

			win32AudioOutput(windata.gameoutput.audio.buffer, windata.gameoutput.audio.framesToWrite);
			renderGraphics(&windata);
		}
		
		lastTime = time;
		
	}

	ReleaseDC(windata.window, windata.windowDC);

	destroyGraphics(&windata);
	win32AudioDestroy();
	free(windata.gameMemory);
	free(windata.gameoutput.audio.buffer);

	return (msg.wParam);
}