Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/vanilla' into vanilla
Browse files Browse the repository at this point in the history
  • Loading branch information
Northfear committed Jun 26, 2021
2 parents 9fdc8e8 + 6aca357 commit 8860827
Show file tree
Hide file tree
Showing 111 changed files with 766 additions and 530 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Binary releases of the latest commit are available from [here](https://github.co

Copy the Vanilla executable (`vanillatd.exe` or `vanillara.exe`) to your legacy game directory, on Windows also copy `SDL2.dll` and `OpenAL32.dll`.

For Tiberian Dawn the final freeware Gold CD release ([GDI](https://www.fileplanet.com/archive/p-63497/Command-Conquer-Gold), [NOD](https://www.fileplanet.com/archive/p-8778/Command-Conquer-Gold)) works fine.
For Tiberian Dawn the final freeware Gold CD release ([GDI](https://www.moddb.com/games/cc-gold/downloads/command-conquer-gold-free-game-gdi-iso), [NOD](https://www.moddb.com/games/cc-gold/downloads/command-conquer-gold-free-game-nod-iso)) works fine.

For Red Alert the freeware [CD release](https://web.archive.org/web/20080901183216/http://www.ea.com/redalert/news-detail.jsp?id=62) works fine as well.
The official [Red Alert demo](https://www.moddb.com/games/cc-red-alert/downloads/command-conquer-red-alert-demo) is also fully playable.
Expand Down
6 changes: 3 additions & 3 deletions common/blowfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ void BlowfishEngine::Submit_Key(void const* key, int length)
** working 64 bit number is carried into this process from the previous
** operation.
*/
for (auto& sbox_index : bf_S) {
for (int sbox_index = 0; sbox_index < 4; sbox_index++) {
for (int ss_index = 0; ss_index < UCHAR_MAX + 1; ss_index += 2) {
Sub_Key_Encrypt(left, right);
sbox_index[ss_index] = left;
sbox_index[ss_index + 1] = right;
bf_S[sbox_index][ss_index] = left;
bf_S[sbox_index][ss_index + 1] = right;
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/ccfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ unsigned long Seek_File(int handle, long offset, int starting)

void WWDOS_Shutdown(void)
{
for (CCFileClass& Handle : Handles) {
Handle.Set_Name(NULL);
for (int index = 0; index < 10; index++) {
Handles[index].Set_Name(NULL);
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/filepcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,5 @@ void Write_Pcx_ScanLine(int file_handle, int scansize, unsigned char* ptr)
}
}

Write_File(file_handle, pool, (intptr_t)file_ptr - (intptr_t)pool);
Write_File(file_handle, pool, unsigned((intptr_t)file_ptr - (intptr_t)pool));
}
2 changes: 2 additions & 0 deletions common/fixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
class fixed
{
static constexpr unsigned int PRECISION = 1 << 16;
friend class Pipe;
friend class Straw;

public:
// The default constructor must not touch the data members in any way.
Expand Down
22 changes: 22 additions & 0 deletions common/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// TiberianDawn.DLL and RedAlert.dll and corresponding source code 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 3 of the License, or (at your option) any later version.

// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
// in the hope that it will be useful, but with permitted additional restrictions
// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
// distributed with this program. You should have received a copy of the
// GNU General Public License along with permitted additional restrictions
// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection

#ifndef COMMON_MACROS_H
#define COMMON_MACROS_H

/*
** This macro serves as a general way to determine the number of elements
** within an array.
*/
#define ARRAY_SIZE(x) int(sizeof(x) / sizeof(x[0]))

#endif /* COMMON_MACROS_H */
2 changes: 1 addition & 1 deletion common/mixfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ bool MixFileClass<T>::Offset(char const* filename, void** realptr, MixFileClass*
char filename_upper[_MAX_PATH];
strcpy(filename_upper, filename);
strupr(filename_upper);
int32_t crc = Calculate_CRC(strupr(filename_upper), strlen(filename_upper));
int32_t crc = Calculate_CRC(strupr(filename_upper), int(strlen(filename_upper)));
SubBlock key;
key.CRC = crc;

Expand Down
6 changes: 3 additions & 3 deletions common/mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ void XMP_Decode_ASCII(char const* str, digit* mpn, int precision)
*/
if (!str)
return;
int i = strlen(str);
int i = (int)strlen(str);
if (i == 0)
return;

Expand Down Expand Up @@ -2203,8 +2203,8 @@ bool XMP_Small_Divisors_Test(const digit* candidate, int precision)
{
digit quotient[MAX_UNIT_PRECISION];

for (unsigned short i : primeTable) {
if (XMP_Unsigned_Div_Int(quotient, candidate, i, precision) == 0)
for (unsigned i = 0; i < ARRAY_SIZE(primeTable); i++) {
if (XMP_Unsigned_Div_Int(quotient, candidate, primeTable[i], precision) == 0)
return (false);
}
return (true);
Expand Down
4 changes: 1 addition & 3 deletions common/mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifndef MP_H
#define MP_H

#include "macros.h"
#include "straw.h"
#include <stdlib.h>
#include <stdint.h>
Expand All @@ -50,9 +51,6 @@ extern uint16_t primeTable[3511];
#define SEMI_MASK ((uint16_t)~0)
#define MAX_BIT_PRECISION 2048
#define MAX_UNIT_PRECISION (MAX_BIT_PRECISION / UNITSIZE)
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#endif

int XMP_Significance(const digit* r, int precision);
void XMP_Inc(digit* r, int precision);
Expand Down
8 changes: 4 additions & 4 deletions common/palettec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ PaletteClass const& PaletteClass::CurrentPalette = *(PaletteClass*)&::CurrentPal
*=============================================================================================*/
PaletteClass::PaletteClass(RGBClass const& rgb)
{
for (RGBClass& index : Palette) {
index = rgb;
for (int index = 0; index < COLOR_COUNT; index++) {
Palette[index] = rgb;
}
}

Expand Down Expand Up @@ -141,8 +141,8 @@ PaletteClass& PaletteClass::operator=(PaletteClass const& palette)
*=============================================================================================*/
void PaletteClass::Adjust(int ratio)
{
for (RGBClass& index : Palette) {
index.Adjust(ratio, BlackColor);
for (int index = 0; index < COLOR_COUNT; index++) {
Palette[index].Adjust(ratio, BlackColor);
}
}

Expand Down
78 changes: 61 additions & 17 deletions common/pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,10 @@
#ifndef PIPE_H
#define PIPE_H

#include "endianness.h"
#include "fixed.h"
#include <stddef.h>

/*
** The "bool" integral type was defined by the C++ committee in
** November of '94. Until the compiler supports this, use the following
** definition.
*/
#ifndef __BORLANDC__
#ifndef TRUE_FALSE_DEFINED
#define TRUE_FALSE_DEFINED
enum
{
false = 0,
true = 1
};
typedef int bool;
#endif
#endif
#include <stdint.h>

/*
** A "push through" pipe interface abstract class used for such purposes as compression
Expand Down Expand Up @@ -83,6 +69,64 @@ class Pipe
}
virtual int Put(void const* source, int slen);

/*
** Write fixed width data to the stream.
*/
void Put(int8_t val)
{
uint8_t data = val;
Put(&data, sizeof(data));
}

void Put(uint8_t val)
{
uint8_t data = val;
Put(&data, sizeof(data));
}

void Put(int16_t val)
{
uint16_t data = htole16(val);
Put(&data, sizeof(data));
}

void Put(uint16_t val)
{
uint16_t data = htole16(val);
Put(&data, sizeof(data));
}

void Put(int32_t val)
{
uint32_t data = htole32(val);
Put(&data, sizeof(data));
}

void Put(uint32_t val)
{
uint32_t data = htole32(val);
Put(&data, sizeof(data));
}

void Put(int64_t val)
{
uint64_t data = htole64(val);
Put(&data, sizeof(data));
}

void Put(uint64_t val)
{
uint64_t data = htole64(val);
Put(&data, sizeof(data));
}

void Put(const fixed& val)
{
uint32_t data = htole32(val.Data.Raw);
static_assert(sizeof(data) == sizeof(val.Data.Raw), "Fixed point data does not match written data size.");
Put(&data, sizeof(data));
}

/*
** Pointer to the next pipe segment in the chain.
*/
Expand Down
4 changes: 2 additions & 2 deletions common/sha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ int SHAEngine::Result(void* result) const
Process_Block(&partial[0], acc);

memcpy((char*)&FinalResult, &acc, sizeof(acc));
for (unsigned int index : FinalResult.Long) {
for (int index = 0; index < sizeof(FinalResult) / sizeof(int32_t); index++) {
// for (int index = 0; index < SRC_BLOCK_SIZE/sizeof(int32_t); index++) {
(int32_t&)index = htobe32(index);
(int32_t&)FinalResult.Long[index] = htobe32(FinalResult.Long[index]);
}
(bool&)IsCached = true;
memcpy(result, &FinalResult, sizeof(FinalResult));
Expand Down
6 changes: 4 additions & 2 deletions common/smartptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#pragma once

#include <stdint.h>

template <class T> class SmartPtr
{
public:
Expand All @@ -39,9 +41,9 @@ template <class T> class SmartPtr
return (Pointer);
}

operator long(void) const
operator intptr_t(void) const
{
return ((long)Pointer);
return ((intptr_t)Pointer);
}

SmartPtr<T> operator++(int)
Expand Down
16 changes: 9 additions & 7 deletions common/soundio_openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ int File_Stream_Sample_Vol(char const* filename, int volume, bool real_time_star
if (FileStreamBuffer == nullptr) {
FileStreamBuffer = malloc((unsigned long)(LockedData.StreamBufferSize * LockedData.StreamBufferCount));

for (SampleTrackerType& i : LockedData.SampleTracker) {
i.FileBuffer = FileStreamBuffer;
for (int i = 0; i < MAX_SAMPLE_TRACKERS; ++i) {
LockedData.SampleTracker[i].FileBuffer = FileStreamBuffer;
}
}

Expand Down Expand Up @@ -844,8 +844,8 @@ bool Audio_Init(int bits_per_sample, bool stereo, int rate, bool reverse_channel
}

// Create placback buffers for all trackers.
for (SampleTrackerType& i : LockedData.SampleTracker) {
SampleTrackerType* st = &i;
for (int i = 0; i < MAX_SAMPLE_TRACKERS; ++i) {
SampleTrackerType* st = &LockedData.SampleTracker[i];

// Gen buffers on audio start?
// alGenBuffers(OPENAL_BUFFER_COUNT, st->AudioBuffers);
Expand Down Expand Up @@ -1157,9 +1157,11 @@ int Set_Score_Vol(int volume)
int old = LockedData.ScoreVolume;
LockedData.ScoreVolume = volume;

for (SampleTrackerType& st : LockedData.SampleTracker) {
if (st.IsScore & st.Active) {
alSourcef(st.OpenALSource, AL_GAIN, ((LockedData.ScoreVolume * st.Volume) / 256) / 256.0f);
for (int i = 0; i < MAX_SAMPLE_TRACKERS; ++i) {
SampleTrackerType* st = &LockedData.SampleTracker[i];

if (st->IsScore & st->Active) {
alSourcef(st->OpenALSource, AL_GAIN, ((LockedData.ScoreVolume * st->Volume) / 256) / 256.0f);
}
}

Expand Down
Loading

0 comments on commit 8860827

Please sign in to comment.