卡马克算法-代码研究

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

// @ CIRCULAR DIRTY BUFFER CIRCULAR DIRTY BUFFER CIRCULAR DIRTY BUFFER

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 

    
static   int  _oldLevelX;

    
static   int  _oldLevelY;

    
static   int  _lastTileX;

    
static   int  _lastTileY;

 

    
static   int  _vp_x;

    
static   int  _vp_y;

    
static   int  _vp_w;

    
static   int  _vp_h;

 

    
static  Image _imgCDB;

    
static  Graphics _gCDB;

 

 

    
static   void  CDB_Init()  {

        _imgCDB 
= Image.createImage(DEF.CDB_W, DEF.CDB_H);

        _gCDB 
= _imgCDB.getGraphics();

 

        _lastTileX 
= -1;

        _lastTileY 
= -1;

 

        _oldLevelX 
= -1;

        _oldLevelY 
= -1;

 

        _vp_x 
= DEF.SV_X;

        _vp_y 
= DEF.SV_Y;

 

        _vp_w 
= DEF.SV_W;

        _vp_h 
= DEF.SV_H;

    }


 

    
static   void  CDB_Free()  {

        _gCDB 
= null;

        _imgCDB 
= null;

    }


 

////

 

 

    
static   void  CDB_UpdateGameView( int  x,  int  y)  {

        
int lx = x >> 4// x / GAME.G_TILE_W;

        
int ly = y >> 4// y / GAME.G_TILE_H;

 

        
int olx = _oldLevelX >> 4// _oldLevelX / GAME.G_TILE_W;

        
int oly = _oldLevelY >> 4// _oldLevelY / GAME.G_TILE_H;

 

        
if ((lx == _lastTileX) && (ly == _lastTileY)) {

            _oldLevelX 
= x;

            _oldLevelY 
= y;

            
return;

        }


 

        
if ((_lastTileX == -1 && _lastTileY == -1||

            (Abs(lx 
- olx) >= DEF.CDB_TW) || (Abs(ly - oly) >= DEF.CDB_TH)) {

            CDB_InvalidateTiles(lx, ly, lx 
+ DEF.CDB_TW, ly + DEF.CDB_TH);

        }
 else {

            
int minX, maxX, minY, maxY;

            
int x1, x2, y1, y2;

 

            minX 
= ((x >= _oldLevelX) ? olx : lx);

            minY 
= ((y >= _oldLevelY) ? oly : ly);

            maxX 
= lx + olx - minX;

            maxY 
= ly + oly - minY;

 

            x1 
= (_oldLevelX < x) ? (minX + DEF.CDB_TW) : minX;

            x2 
= (x1 - minX + maxX);

 

            
if (x1 == x2) {

                
if (x > _oldLevelX) {

                    x1
--;

                }
 else if (x < _oldLevelX) {

                    x2
++;

                }


            }


 

            y1 
= (_oldLevelY <= y) ? maxY : minY;

            y2 
= y1 + DEF.CDB_TH;

 

            CDB_InvalidateTiles(x1, y1, x2, y2);

 

            x1 
= maxX;

            x2 
= minX + DEF.CDB_TW;

 

            y1 
= (_oldLevelY < y) ? (minY + DEF.CDB_TH) : minY;

            y2 
= (_oldLevelY < y) ? (maxY + DEF.CDB_TH) : maxY;

 

            
if (y1 == y2) {

                
if (y > _oldLevelY) {

                    y1
--;

                }
 else if (y < _oldLevelY) {

                    y2
++;

                }


            }


 

            CDB_InvalidateTiles(x1, y1, x2, y2);

        }


 

        
// record level coords (for not redrawin every time ...)

        _lastTileX 
= lx;

        _lastTileY 
= ly;

 

        _oldLevelX 
= x;

        _oldLevelY 
= y;

 

    }


 

////

//  Repaint a portion of game background into the circular dirty buffer

 

    
static   void  CDB_InvalidateTiles( int  minX,  int  minY,  int  maxX,  int  maxY)  {

        
int x, y;

 

        
if (maxX > map_sizeX)

            maxX 
= map_sizeX;

        
if (maxY > map_sizeY)

            maxY 
= map_sizeY;

 

        
if (minX == maxX || minY == maxY)

            
return;

 

        _gCDB.setClip(
00, DEF.CDB_W, DEF.CDB_H);

 

        
for (x = minX; x < maxX; x++{

            
for (y = minY; y < maxY; y++{

                
int t = x + y * map_sizeX;

                
int x1 = (x * DEF.TILE_W) % DEF.CDB_W;

                
int y1 = (y * DEF.TILE_H) % DEF.CDB_H;

 

                DrawTile(_gCDB, t, x1, y1);

 

            }


        }


 

    }


 

 

////

//  CDB -> Screen

 

    
static   void  CDB_DrawGameView()  {

        
int bb_pos_x =  (s_camX % DEF.CDB_W);

        
int bb_pos_y =  (s_camY %  DEF.CDB_H);

 

        
int widthR = (DEF.CDB_W - bb_pos_x);

        
int widthL = (DEF.CDB_W - widthR);

        
int heightB = (DEF.CDB_H - bb_pos_y);

        
int heightT = (DEF.CDB_H - heightB);

 

        
// blit backbuffer on screen ...

        
// ************* top left *************

        CDB_Copy2Screen(DEF.SV_X, DEF.SV_Y, widthR, heightB,

                        DEF.SV_X 
- bb_pos_x, DEF.SV_Y - bb_pos_y);

        
// ************* top right *************

        CDB_Copy2Screen(DEF.SV_X 
+ widthR, DEF.SV_Y, widthL, heightB,

                        DEF.SV_X 
+ widthR, DEF.SV_Y - bb_pos_y);

        
// ************* bottom left *************

        CDB_Copy2Screen(DEF.SV_X, DEF.SV_Y 
+ heightB, widthR, heightT,

                        DEF.SV_X 
- bb_pos_x, DEF.SV_Y + heightB);

        
// ************* bottom right *************

        CDB_Copy2Screen(DEF.SV_X 
+ widthR, DEF.SV_Y + heightB, widthL, heightT,

                        DEF.SV_X 
+ widthR, DEF.SV_Y + heightB);

    }


 

////

 

    
private   static   void  CDB_Copy2Screen( int  x,  int  y,  int  w,  int  h,  int  xx,

                                        
int  yy)  {

 

        
//clip viewport

        
if (x < _vp_x) {

            w 
= w - _vp_x + x;

            x 
= _vp_x;

        }


        
if (y < _vp_y) {

            h 
= h - _vp_y + y;

            y 
= _vp_y;

        }


        
if (x + w > _vp_x + _vp_w) {

            w 
= _vp_x + _vp_w - x;

        }


        
if (y + h > _vp_y + _vp_h) {

            h 
= _vp_y + _vp_h - y;

        }


 

        
if (w <= 0 || h <= 0)

            
return;

 

 

        s_g.setClip(x, y, w, h);

        s_g.drawImage( _imgCDB, xx, yy, Graphics.LEFT 
| Graphics.TOP);

    }


 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This is the complete source code for winquake, glquake, quakeworld, and glquakeworld. The projects have been tested with visual C++ 6.0, but masm is also required to build the assembly language files. It is possible to change a #define and build with only C code, but the software rendering versions lose almost half its speed. The OpenGL versions will not be effected very much. The gas2masm tool was created to allow us to use the same source for the dos, linux, and windows versions, but I don't really recommend anyone mess with the asm code. The original dos version of Quake should also be buildable from these sources, but we didn't bother trying. The code is all licensed under the terms of the GPL (gnu public license). You should read the entire license, but the gist of it is that you can do anything you want with the code, including sell your new version. The catch is that if you distribute new binary versions, you are required to make the entire source code available for free to everyone. Our previous code releases have been under licenses that preclude commercial exploitation, but have no clause forcing sharing of source code. There have been some unfortunate losses to the community as a result of mod teams keeping their sources closed (and sometimes losing them). If you are going to publicly release modified versions of this code, you must also make source code available. I would encourage teams to even go a step farther and investigate using public CVS servers for development where possible. The primary intent of this release is for entertainment and educational purposes, but the GPL does allow commercial exploitation if you obey the full license. If you want to do something commercial and you just can't bear to have your source changes released, we could still negotiate a separate license agreement (for $$$), but I would encourage you to just live with the GPL. All of the Quake data files remain copyrighted and licensed under the original terms, so you cannot redistribute data from the original game, but if you do a true total conversion, you can create a standalone game based on this code. I will see about having the license changed on the shareware episode of quake to allow it to be duplicated more freely (for linux distributions, for example), but I can't give a timeframe for it. You can still download one of the original quake demos and use that data with the code, but there are restrictions on the redistribution of the demo data. If you never actually bought a complete version of Quake, you might want to rummage around in a local software bargain bin for one of the originals, or perhaps find a copy of the "Quake: the offering" boxed set with both mission packs. Thanks to Dave "Zoid" Kirsh and Robert Duffy for doing the grunt work of building this release. John Carmack Id Software

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值