From 924574b0a1dc9e947f4d6b08d9f5a9c392241c9a Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Fri, 2 Oct 2009 14:33:05 +0000 Subject: [PATCH] Erwan - Some cleanup in JGE --- JGE/Makefile | 4 +- JGE/include/JRenderer.h | 5 +- JGE/include/JTypes.h | 13 -- JGE/include/vram.h | 54 ----- JGE/src/JGfx.cpp | 61 ++--- JGE/src/vram.c | 277 ----------------------- projects/mtg/Makefile | 2 +- projects/mtg/src/GameStateDeckViewer.cpp | 3 +- projects/mtg/src/GameStateDuel.cpp | 1 - projects/mtg/src/GameStateMenu.cpp | 4 +- projects/mtg/src/GameStateOptions.cpp | 1 - projects/mtg/src/GameStateShop.cpp | 1 - 12 files changed, 21 insertions(+), 405 deletions(-) delete mode 100644 JGE/include/vram.h delete mode 100644 JGE/src/vram.c diff --git a/JGE/Makefile b/JGE/Makefile index ae384bd78..62c5b622b 100644 --- a/JGE/Makefile +++ b/JGE/Makefile @@ -15,7 +15,7 @@ GENERIC_OBJS = src/JApp.o src/JGBKFont.o \ src/tinyxml/tinystr.o src/tinyxml/tinyxml.o \ src/tinyxml/tinyxmlparser.o src/tinyxml/tinyxmlerror.o \ src/Encoding.o src/JTTFont.o \ - src/JMD2Model.o src/JOBJModel.o src/vram.o + src/JMD2Model.o src/JOBJModel.o PSP_OBJS = src/JSocket.o src/JGfx.o src/JSfx.o src/JAudio.o src/JMP3.o src/decoder_prx.o src/main.o LINUX_OBJS = src/linux/JGfx.o src/linux/JSfx.o src/Xmain.o @@ -76,7 +76,6 @@ TARGET_HGE = libhgetools.a INCDIR = include/psp include/psp/freetype2 CXXFLAGS += -G0 LIBDIR = lib/psp -LIBS = -lgif -lfreetype -ljpeg -lpng -lz -lmikmod -lpsppower -lpspmpeg -lpspaudiocodec -lpspaudiolib -lpspaudio -lpspgum -lpspgu -lpsprtc -lm -lstdc++ endif ifeq ($(TARGET_ARCHITECTURE),linux) OBJS = $(GENERIC_OBJS) $(LINUX_OBJS) @@ -89,7 +88,6 @@ LIBDIR = lib/linux endif # Set definitive values for variables. -LDFLAGS = $(LIBS) TARGET_LIB := $(LIBDIR)/$(TARGET_LIB) TARGET_HGE := $(LIBDIR)/$(TARGET_HGE) diff --git a/JGE/include/JRenderer.h b/JGE/include/JRenderer.h index 7d148f162..588e167d6 100644 --- a/JGE/include/JRenderer.h +++ b/JGE/include/JRenderer.h @@ -541,9 +541,7 @@ private: #else - - u32 mVideoBufferStart; - //u32 mCurrentPointer; + void *fbp0, *fbp1, *zbp; PIXEL_TYPE* mVRAM; int mCurrentTex; int mCurrentBlend; @@ -558,7 +556,6 @@ private: int mSwizzle; int mTexCounter; - //int mTexFilter; int mCurrentTextureFilter; diff --git a/JGE/include/JTypes.h b/JGE/include/JTypes.h index ca5be11da..1270800a1 100644 --- a/JGE/include/JTypes.h +++ b/JGE/include/JTypes.h @@ -87,20 +87,7 @@ #include "../Dependencies/include/fmod.h" - //#include "../HGE/include/hge.h" - //#include "../HGE/include/hgeSprite.h" - //#define u8 BYTE - //#define u16 WORD - //#define u32 DWORD -/* - typedef signed char s8; - typedef signed short s16; - typedef signed long s32; - typedef unsigned char u8; - typedef unsigned short u16; - typedef unsigned long u32; -*/ typedef int8_t s8; typedef int16_t s16; typedef int32_t s32; diff --git a/JGE/include/vram.h b/JGE/include/vram.h deleted file mode 100644 index 66cf93284..000000000 --- a/JGE/include/vram.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Helper for use with the PSP Software Development Kit - http://www.pspdev.org - * ----------------------------------------------------------------------- - * Licensed under GPL - * - * vram.c - Standard C high performance VRAM allocation routines. - * - * Copyright (c) 2007 Alexander Berl 'Raphael' - * http://wordpress.fx-world.org - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#ifndef vram_h__ -#define vram_h__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void* vrelptr( void *ptr ); // make a pointer relative to memory base address (ATTENTION: A NULL rel ptr is not illegal/invalid!) -void* vabsptr( void *ptr ); // make a pointer absolute (default return type of valloc) - -void* valloc( size_t size ); -void vfree( void* ptr ); -size_t vmemavail(); -size_t vlargestblock(); - - -#ifdef _DEBUG -// Debug printf (to stdout) a trace of the current Memblocks -void __memwalk(); -#endif - - -#ifdef __cplusplus -} -#endif - -#endif // ifdef vram_h__ diff --git a/JGE/src/JGfx.cpp b/JGE/src/JGfx.cpp index 5d785bf3d..2a6830d91 100644 --- a/JGE/src/JGfx.cpp +++ b/JGE/src/JGfx.cpp @@ -18,7 +18,8 @@ #include #include #include - +#include +#include #ifdef __cplusplus extern "C" { @@ -33,7 +34,6 @@ extern "C" { #include "../include/JGE.h" #include "../include/JRenderer.h" #include "../include/JFileSystem.h" -#include "../include/vram.h" static unsigned int __attribute__((aligned(16))) list[262144]; @@ -83,13 +83,6 @@ void JQuad::SetColor(PIXEL_TYPE color) } -// void JQuad::SetColor(JColor color) -// { -// for (int i=0;i<4;i++) -// mColor[i].color = color.color; -// } - - void JQuad::SetHotSpot(float x, float y) { mHotSpotX = x; @@ -173,15 +166,13 @@ JRenderer::~JRenderer() void JRenderer::ResetPrivateVRAM() { - //mCurrentPointer = mVideoBufferStart; } void JRenderer::InitRenderer() { - if (m3DEnabled) - mCurrentRenderMode = MODE_2D; + mCurrentRenderMode = MODE_2D; #ifdef USING_MATH_TABLE for (int i=0;i<360;i++) @@ -191,6 +182,9 @@ void JRenderer::InitRenderer() } #endif + mCurrTexBlendSrc = BLEND_SRC_ALPHA; + mCurrTexBlendDest = BLEND_ONE_MINUS_SRC_ALPHA; + mSwizzle = 1; mVsync = false; @@ -203,29 +197,25 @@ void JRenderer::InitRenderer() mImageFilter = NULL; - //mTexFilter = GU_NEAREST; mCurrentTextureFilter = TEX_FILTER_LINEAR; sceGuInit(); + fbp0 = ( u32* ) vrelptr ( valloc ( FRAME_BUFFER_SIZE ) ); + fbp1 = ( u32* ) vrelptr ( valloc ( FRAME_BUFFER_SIZE ) ); + zbp = NULL; + // setup GU sceGuStart(GU_DIRECT,list); - mVideoBufferStart = 0; - sceGuDrawBuffer(BUFFER_FORMAT, (void *)mVideoBufferStart, FRAME_BUFFER_WIDTH); - mVideoBufferStart += FRAME_BUFFER_SIZE; - valloc(FRAME_BUFFER_SIZE); - sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void *)mVideoBufferStart, FRAME_BUFFER_WIDTH); - mVideoBufferStart += FRAME_BUFFER_SIZE; - valloc(FRAME_BUFFER_SIZE); + + sceGuDrawBuffer(BUFFER_FORMAT, fbp0, FRAME_BUFFER_WIDTH); + sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, fbp1, FRAME_BUFFER_WIDTH); if (m3DEnabled) { - sceGuDepthBuffer((void *)mVideoBufferStart, FRAME_BUFFER_WIDTH); - mVideoBufferStart += (FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*2); // 16bit depth buffer - - valloc(FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*2); + zbp = ( u16* ) vrelptr ( valloc ( FRAME_BUFFER_WIDTH*SCREEN_HEIGHT*2) ); + sceGuDepthBuffer(zbp, FRAME_BUFFER_WIDTH); } - //mCurrentPointer = mVideoBufferStart; sceGuOffset(2048 - (SCREEN_WIDTH/2), 2048 - (SCREEN_HEIGHT/2)); sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT); @@ -431,28 +421,7 @@ void JRenderer::FillRect(float x, float y, float width, float height, PIXEL_TYPE vertices[3].x = x + width; vertices[3].y = y + height; vertices[3].z = 0.0f; -/* - vertices[0].color = colors[0]; - vertices[0].x = x; - vertices[0].y = y; - vertices[0].z = 0.0f; - - vertices[1].color = colors[1]; - vertices[1].x = x; - vertices[1].y = y + height; - vertices[1].z = 0.0f; - - vertices[2].color = colors[2]; - vertices[2].x = x + width; - vertices[2].y = y + height; - vertices[2].z = 0.0f; - - vertices[3].color = colors[3]; - vertices[3].x = x + width; - vertices[3].y = y; - vertices[3].z = 0.0f; -*/ sceGuDisable(GU_TEXTURE_2D); sceGuShadeModel(GU_SMOOTH); sceGuAmbientColor(0xffffffff); diff --git a/JGE/src/vram.c b/JGE/src/vram.c deleted file mode 100644 index e59654b8b..000000000 --- a/JGE/src/vram.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Helper for use with the PSP Software Development Kit - http://www.pspdev.org - * ----------------------------------------------------------------------- - * Licensed under GPL - * - * vram.c - Standard C high performance VRAM allocation routines. - * - * Copyright (c) 2007 Alexander Berl 'Raphael' - * http://wordpress.fx-world.org - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "../include/vram.h" -#include - -// Configure the memory to be managed -#define __MEM_SIZE 0x00200000 -#define __MEM_START 0x04000000 - -// Configure the block size the memory gets subdivided into (page size) -// __MEM_SIZE/__BLOCK_SIZE may not exceed 2^15 = 32768 -// The block size also defines the alignment of allocations -// Larger block sizes perform better, because the blocktable is smaller and therefore fits better into cache -// however the overhead is also bigger and more memory is wasted -#define __BLOCK_SIZE 512 -#define __MEM_BLOCKS (__MEM_SIZE/__BLOCK_SIZE) -#define __BLOCKS(x) ((x+__BLOCK_SIZE-1)/__BLOCK_SIZE) -#define __BLOCKSIZE(x) ((x+__BLOCK_SIZE-1)&~(__BLOCK_SIZE-1)) - - -// A MEMORY BLOCK ENTRY IS MADE UP LIKE THAT: -// bit: 31 32 30 - 15 14-0 -// free block prev size -// -// bit 31: free bit, indicating if block is allocated or not -// bit 30: blocked bit, indicating if block is part of a larger block (0) - used for error resilience -// bit 30-15: block index of previous block -// bit 14- 0: size of current block -// -// This management can handle a max amount of 2^15 = 32768 blocks, which resolves to 32MB at blocksize of 1024 bytes -// -#define __BLOCK_GET_SIZE(x) ((x & 0x7FFF)) -#define __BLOCK_GET_PREV(x) ((x >> 15) & 0x7FFF) -#define __BLOCK_GET_FREE(x) ((x >> 31)) -#define __BLOCK_GET_BLOCK(x) ((x >> 30) & 0x1) -#define __BLOCK_SET_SIZE(x,y) x=((x & ~0x7FFF) | ((y) & 0x7FFF)) -#define __BLOCK_ADD_SIZE(x,y) x=((x & ~0x7FFF) | (((x & 0x7FFF)+((y) & 0x7FFF)) & 0x7FFF)) -#define __BLOCK_SET_PREV(x,y) x=((x & ~0x3FFF8000) | (((y) & 0x7FFF)<<15)) -#define __BLOCK_SET_FREE(x,y) x=((x & 0x7FFFFFFF) | (((y) & 0x1)<<31)) -#define __BLOCK_SET_BLOCK(x,y) x=((x & 0xBFFFFFFF) | (((y) & 0x1)<<30)) -#define __BLOCK_MAKE(s,p,f,n) (((f & 0x1)<<31) | ((n & 0x1)<<30) | (((p) & 0x7FFF)<<15) | ((s) & 0x7FFF)) -#define __BLOCK_GET_FREEBLOCK(x) ((x>>30) & 0x3) // returns 11b if block is a starting block and free, 10b if block is a starting block and allocated, 0xb if it is a non-starting block (don't change) -#define __BLOCK0 ((__MEM_BLOCKS) | (1<<31) | (1<<30)) - - -unsigned int __mem_blocks[__MEM_BLOCKS] = { 0 }; - - -static int __largest_update = 0; -static int __largest_block = __MEM_BLOCKS; -static int __mem_free = __MEM_BLOCKS; - - -inline void* vrelptr( void *ptr ) -{ - return (void*)((unsigned int)ptr & ~__MEM_START); -} - -inline void* vabsptr( void *ptr ) -{ - return (void*)((unsigned int)ptr | __MEM_START); -} - - -static void __find_largest_block() -{ - int i = 0; - __largest_block = 0; - while (i<__MEM_BLOCKS) - { - int csize = __BLOCK_GET_SIZE(__mem_blocks[i]); - if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>__largest_block) - __largest_block = csize; - i += csize; - } - __largest_update = 0; -} - -#ifdef _DEBUG -void __memwalk() -{ - int i = 0; - if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0; - while (i<__MEM_BLOCKS) - { - printf("BLOCK %i:\n", i); - printf(" free: %i\n", __BLOCK_GET_FREEBLOCK(__mem_blocks[i])); - printf(" size: %i\n", __BLOCK_GET_SIZE(__mem_blocks[i])); - printf(" prev: %i\n", __BLOCK_GET_PREV(__mem_blocks[i])); - i+=__BLOCK_GET_SIZE(__mem_blocks[i]); - } -} -#endif - -void* valloc( size_t size ) -{ - // Initialize memory block, if not yet done - if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0; - - int i = 0; - int j = 0; - int bsize = __BLOCKS(size); - - if (__largest_update==0 && __largest_block=bsize) - { - if (csizebsize && next<__MEM_BLOCKS) - { - __mem_blocks[next] = __BLOCK_MAKE(csize-bsize,i,1,1); - int nextnext = i+csize; - if (nextnext<__MEM_BLOCKS) - { - __BLOCK_SET_PREV(__mem_blocks[nextnext], next); - } - } - - __mem_free -= bsize; - if (__largest_block==csize) // if we just allocated from one of the largest blocks - { - if ((csize-bsize)>(__mem_free/2)) - __largest_block = (csize-bsize); // there can't be another largest block - else - __largest_update = 1; - } - return ((void*)(__MEM_START + (i*__BLOCK_SIZE))); -} - - -void vfree( void* ptr ) -{ - if (ptr==0) return; - - //ptr -= 0x40000000; // @_@: - - int block = ((unsigned int)ptr - __MEM_START)/__BLOCK_SIZE; - if (block<0 || block>__MEM_BLOCKS) - { - #ifdef _DEBUG - printf("Block is out of range: %i (0x%x)\n", block, (int)ptr); - #endif - return; - } - int csize = __BLOCK_GET_SIZE(__mem_blocks[block]); - #ifdef _DEBUG - printf("freeing block %i (0x%x), size: %i\n", block, (int)ptr, csize); - #endif - - if (__BLOCK_GET_FREEBLOCK(__mem_blocks[block])!=1 || csize==0) - { - #ifdef _DEBUG - printf("Block was not allocated!\n"); - #endif - return; - } - - // Mark block as free - __BLOCK_SET_FREE(__mem_blocks[block],1); - __mem_free += csize; - - int next = block+csize; - // Merge with previous block if possible - int prev = __BLOCK_GET_PREV(__mem_blocks[block]); - if (prevResetPrivateVRAM(); - //mEngine->EnableVSync(true); + currentCard = NULL; loadIndexes(currentCard); last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1; diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 01bf9d7c1..897f96e77 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -63,7 +63,6 @@ GameStateDuel::~GameStateDuel() { void GameStateDuel::Start() { JRenderer * renderer = JRenderer::GetInstance(); - renderer->ResetPrivateVRAM(); renderer->EnableVSync(true); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index b90af3eda..3dd2dc315 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -127,6 +127,7 @@ void GameStateMenu::Destroy() } void GameStateMenu::Start(){ + JRenderer::GetInstance()->EnableVSync(true); subMenuController = NULL; if (GameApp::HasMusic && !GameApp::music && options[Options::MUSICVOLUME].number > 0){ @@ -150,8 +151,7 @@ void GameStateMenu::Start(){ mBg->SetHotSpot(105,50); mMovingW->SetHotSpot(72,16); - JRenderer::GetInstance()->ResetPrivateVRAM(); - JRenderer::GetInstance()->EnableVSync(true); + //How many cards total ? PlayerData * playerdata = NEW PlayerData(mParent->collection); diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index a7270943c..2856c3a46 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -22,7 +22,6 @@ void GameStateOptions::Start() { timer = 0; mState = SHOW_OPTIONS; - JRenderer::GetInstance()->ResetPrivateVRAM(); JRenderer::GetInstance()->EnableVSync(true); OptionsList * optionsList; diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index 585878ed8..e24a49a88 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -48,7 +48,6 @@ void GameStateShop::Start() menuFont = resources.GetJLBFont(Constants::MENU_FONT); itemFont = resources.GetJLBFont(Constants::MAIN_FONT); - JRenderer::GetInstance()->ResetPrivateVRAM(); JRenderer::GetInstance()->EnableVSync(true);